Debian Codegraph @

ogr/ogrsf_frmts/dwg/createdgnv8testfile.cpp

raw
1 /******************************************************************************
2 *
3 * Project: OpenGIS Simple Features Reference Implementation
4 * Purpose: Generate a test .dgn file
5 * Author: Even Rouault <even.rouault at spatialys.com>
6 *
7 ******************************************************************************
8 * Copyright (c) 2017, Even Rouault <even.rouault at spatialys.com>
9 *
10 * SPDX-License-Identifier: MIT
11 ****************************************************************************/
12
13 #include "createdgnv8testfile_headers.h"
14
15 const double DEG_TO_RAD = 3.141592653589793 / 180.0;
16
17 /************************************************************************/
18 /* OGRDGNV8Services */
19 /* */
20 /* Services implementation for OGR. Eventually we should */
21 /* override the OdExDgnSystemServices IO to use VSI*L. */
22 /************************************************************************/
23
24 class OGRDGNV8Services : public OdExDgnSystemServices,
25 public OdExDgnHostAppServices
26 {
27 protected:
28 ODRX_USING_HEAP_OPERATORS(OdExDgnSystemServices);
29 };
30
31 static OdStaticRxObject<OGRDGNV8Services> oServices;
32
33 int main()
34 {
35 odrxInitialize(&oServices);
36 oServices.disableProgressMeterOutput(true);
37 ::odrxDynamicLinker()->loadModule(L"TG_Db", false);
38
39 OdDgDatabasePtr pDb = oServices.createDatabase();
40
41 OdDgModelPtr pModel = pDb->getActiveModelId().openObject(OdDg::kForWrite);
42 pModel->setWorkingUnit(OdDgModel::kWuMasterUnit);
43 pModel->setName("my_model");
44 pModel->setDescription("my_description");
45
46 // Add font
47 OdDgFontTablePtr pFontTable =
48 pModel->database()->getFontTable(OdDg::kForWrite);
49 {
50 OdDgFontTableRecordPtr pFont = OdDgFontTableRecord::createObject();
51 pFont->setName("Arial");
52 pFont->setType(kFontTypeTrueType);
53
54 pFontTable->add(pFont);
55 }
56
57 // Read as point by OGR
58 {
59 OdDgLine3dPtr line = OdDgLine3d::createObject();
60 pModel->addElement(line);
61 OdGePoint3d point;
62 point.x = 0;
63 point.y = 1;
64 point.z = 2;
65 line->setStartPoint(point);
66 line->setEndPoint(point);
67
68 line->setLevelEntryId(1);
69 line->setGraphicsGroupEntryId(2);
70 line->setColorIndex(3);
71 line->setLineStyleEntryId(4);
72 line->setLineWeight(5);
73 }
74
75 // Read as point by OGR
76 {
77 OdDgLine2dPtr line = OdDgLine2d::createObject();
78 pModel->addElement(line);
79 OdGePoint2d point;
80 point.x = 0;
81 point.y = 1;
82 line->setStartPoint(point);
83 line->setEndPoint(point);
84 }
85
86 {
87 OdDgLine3dPtr line = OdDgLine3d::createObject();
88 pModel->addElement(line);
89 OdGePoint3d point;
90 point.x = 0;
91 point.y = 1;
92 point.z = 2;
93 line->setStartPoint(point);
94 point.x = 3;
95 point.y = 4;
96 point.z = 5;
97 line->setEndPoint(point);
98 }
99
100 {
101 OdDgLine2dPtr line = OdDgLine2d::createObject();
102 pModel->addElement(line);
103 OdGePoint2d point;
104 point.x = 0;
105 point.y = 1;
106 line->setStartPoint(point);
107 point.x = 2;
108 point.y = 3;
109 line->setEndPoint(point);
110 }
111
112 {
113 OdDgText2dPtr text = OdDgText2d::createObject();
114 pModel->addElement(text);
115 OdGePoint2d point;
116 point.x = 0;
117 point.y = 1;
118 text->setOrigin(point);
119 text->setText(L"myT\u00e9.xt");
120 text->setRotation(-45 * DEG_TO_RAD);
121 text->setHeightMultiplier(1.0);
122 text->setLengthMultiplier(1.0);
123 OdUInt32 nIdx = OdDgColorTable::getColorIndexByRGB(
124 text->database(), ODRGB(255, 200, 150));
125 text->setColorIndex(nIdx);
126
127 OdDgElementId idFont = pFontTable->getAt("Arial");
128 if (!idFont.isNull())
129 {
130 OdDgFontTableRecordPtr pFont = idFont.openObject(OdDg::kForRead);
131 OdUInt32 uFontEntryId = pFont->getNumber();
132 text->setFontEntryId(uFontEntryId);
133 }
134 }
135
136 {
137 OdDgText3dPtr text = OdDgText3d::createObject();
138 pModel->addElement(text);
139 OdGePoint3d point;
140 point.x = 0;
141 point.y = 1;
142 point.z = 2;
143 text->setOrigin(point);
144 text->setText("x");
145 text->setHeightMultiplier(1.0);
146 text->setLengthMultiplier(1.0);
147 }
148
149 {
150 OdDgTextNode2dPtr textNode = OdDgTextNode2d::createObject();
151 pModel->addElement(textNode);
152
153 OdDgText2dPtr text = OdDgText2d::createObject();
154 textNode->add(text);
155 OdGePoint2d point;
156 point.x = 0;
157 point.y = 1;
158 text->setOrigin(point);
159 text->setText("z");
160 text->setHeightMultiplier(1.0);
161 text->setLengthMultiplier(1.0);
162 }
163
164 {
165 OdDgTextNode3dPtr textNode = OdDgTextNode3d::createObject();
166 pModel->addElement(textNode);
167
168 OdDgText3dPtr text = OdDgText3d::createObject();
169 textNode->add(text);
170 OdGePoint3d point;
171 point.x = 0;
172 point.y = 1;
173 point.z = 2;
174 text->setOrigin(point);
175 text->setText("z");
176 text->setHeightMultiplier(1.0);
177 text->setLengthMultiplier(1.0);
178 }
179
180 {
181 OdDgLineString3dPtr line = OdDgLineString3d::createObject();
182 pModel->addElement(line);
183 OdGePoint3d point;
184 point.x = 0;
185 point.y = 1;
186 point.z = 2;
187 line->addVertex(point);
188 point.x = 3;
189 point.y = 4;
190 point.z = 5;
191 line->addVertex(point);
192 point.x = 6;
193 point.y = 7;
194 point.z = 8;
195 line->addVertex(point);
196 }
197
198 {
199 OdDgLineString2dPtr line = OdDgLineString2d::createObject();
200 pModel->addElement(line);
201 OdGePoint2d point;
202 point.x = 0;
203 point.y = 1;
204 line->addVertex(point);
205 point.x = 3;
206 point.y = 4;
207 line->addVertex(point);
208 point.x = 6;
209 point.y = 7;
210 line->addVertex(point);
211 }
212
213 {
214 OdDgPointString2dPtr line = OdDgPointString2d::createObject();
215 pModel->addElement(line);
216 OdGePoint2d point;
217 point.x = 0;
218 point.y = 1;
219 line->addVertex(point, OdGeMatrix2d::rotation(0));
220 point.x = 3;
221 point.y = 4;
222 line->addVertex(point, OdGeMatrix2d::rotation(0));
223 }
224
225 {
226 OdDgPointString3dPtr line = OdDgPointString3d::createObject();
227 pModel->addElement(line);
228 OdGePoint3d point;
229 point.x = 0;
230 point.y = 1;
231 point.z = 2;
232 line->addVertex(point, OdGeQuaternion(1., 0., 0., 0.));
233 point.x = 3;
234 point.y = 4;
235 line->addVertex(point, OdGeQuaternion(1., 0., 0., 0.));
236 }
237
238 {
239 OdDgMultilinePtr multiline = OdDgMultiline::createObject();
240 pModel->addElement(multiline);
241 OdDgMultilinePoint multilinePoint;
242 OdGePoint3d point;
243 point.x = 0;
244 point.y = 1;
245 point.z = 2;
246 multilinePoint.setPoint(point);
247 multiline->addPoint(multilinePoint);
248 }
249
250 // True ellipse
251 {
252 OdDgEllipse2dPtr ellipse = OdDgEllipse2d::createObject();
253 pModel->addElement(ellipse);
254 ellipse->setPrimaryAxis(1);
255 ellipse->setSecondaryAxis(2);
256 OdGePoint2d point;
257 point.x = 0;
258 point.y = 1;
259 ellipse->setOrigin(point);
260 }
261
262 // Circle
263 {
264 OdDgEllipse2dPtr ellipse = OdDgEllipse2d::createObject();
265 pModel->addElement(ellipse);
266 ellipse->setPrimaryAxis(1);
267 ellipse->setSecondaryAxis(1);
268 ellipse->setRotationAngle(45 * DEG_TO_RAD);
269 OdGePoint2d point;
270 point.x = 0;
271 point.y = 1;
272 ellipse->setOrigin(point);
273 }
274
275 // Circle
276 {
277 OdDgEllipse3dPtr ellipse = OdDgEllipse3d::createObject();
278 pModel->addElement(ellipse);
279 ellipse->setPrimaryAxis(1);
280 ellipse->setSecondaryAxis(1);
281 OdGePoint3d point;
282 point.x = 0;
283 point.y = 1;
284 point.z = 2;
285 ellipse->setOrigin(point);
286 }
287
288 // True arc
289 {
290 OdDgArc2dPtr arc = OdDgArc2d::createObject();
291 pModel->addElement(arc);
292 arc->setPrimaryAxis(1);
293 arc->setSecondaryAxis(2);
294 OdGePoint2d point;
295 point.x = 0;
296 point.y = 1;
297 arc->setOrigin(point);
298 arc->setStartAngle(10 * DEG_TO_RAD);
299 arc->setSweepAngle(180 * DEG_TO_RAD);
300 }
301
302 // Circle arc
303 {
304 OdDgArc2dPtr arc = OdDgArc2d::createObject();
305 pModel->addElement(arc);
306 arc->setPrimaryAxis(1);
307 arc->setSecondaryAxis(1);
308 arc->setRotationAngle(45 * DEG_TO_RAD);
309 OdGePoint2d point;
310 point.x = 0;
311 point.y = 1;
312 arc->setOrigin(point);
313 arc->setStartAngle(10 * DEG_TO_RAD);
314 arc->setSweepAngle(180 * DEG_TO_RAD);
315 }
316
317 // Circle arc
318 {
319 OdDgArc3dPtr arc = OdDgArc3d::createObject();
320 pModel->addElement(arc);
321 arc->setPrimaryAxis(1);
322 arc->setSecondaryAxis(1);
323 OdGePoint3d point;
324 point.x = 0;
325 point.y = 1;
326 point.z = 2;
327 arc->setOrigin(point);
328 arc->setStartAngle(10 * DEG_TO_RAD);
329 arc->setSweepAngle(180 * DEG_TO_RAD);
330 }
331
332 {
333 OdDgCurve2dPtr curve = OdDgCurve2d::createObject();
334 pModel->addElement(curve);
335 OdGePoint2d point;
336 point.x = 0;
337 point.y = 0;
338 curve->addVertex(point);
339 point.x = 0;
340 point.y = 1;
341 curve->addVertex(point);
342 point.x = 1;
343 point.y = 1;
344 curve->addVertex(point);
345 point.x = 1;
346 point.y = 0;
347 curve->addVertex(point);
348
349 point.x = 0;
350 point.y = 0;
351 curve->addVertex(point);
352 point.x = 0;
353 point.y = 1;
354 curve->addVertex(point);
355 point.x = 1;
356 point.y = 1;
357 curve->addVertex(point);
358 point.x = 1;
359 point.y = 0;
360 curve->addVertex(point);
361 }
362
363 {
364 OdDgCurve3dPtr curve = OdDgCurve3d::createObject();
365 pModel->addElement(curve);
366 OdGePoint3d point;
367 point.x = 0;
368 point.y = 0;
369 point.z = 1;
370 curve->addVertex(point);
371 point.x = 0;
372 point.y = 1;
373 curve->addVertex(point);
374 point.x = 1;
375 point.y = 1;
376 curve->addVertex(point);
377 point.x = 1;
378 point.y = 0;
379 curve->addVertex(point);
380
381 point.x = 0;
382 point.y = 0;
383 curve->addVertex(point);
384 point.x = 0;
385 point.y = 1;
386 curve->addVertex(point);
387 point.x = 1;
388 point.y = 1;
389 curve->addVertex(point);
390 point.x = 1;
391 point.y = 0;
392 curve->addVertex(point);
393 }
394
395 {
396 OdDgBSplineCurve3dPtr curve = OdDgBSplineCurve3d::createObject();
397 pModel->addElement(curve);
398
399 OdGePoint3dArray arrCtrlPts;
400 OdGePoint3d center;
401 double major = 1.0;
402 double minor = 0.5;
403 arrCtrlPts.push_back(center +
404 OdGeVector3d(-1. * major, 1. * minor, 0.));
405 arrCtrlPts.push_back(center +
406 OdGeVector3d(-1. * major, 2. * minor, 0.));
407 arrCtrlPts.push_back(center +
408 OdGeVector3d(-2. * major, 2. * minor, 0.));
409 arrCtrlPts.push_back(center +
410 OdGeVector3d(-2. * major, 1. * minor, 0.));
411 arrCtrlPts.push_back(center +
412 OdGeVector3d(-1. * major, 1. * minor, 0.));
413 arrCtrlPts.push_back(center + OdGeVector3d(1. * major, 1. * minor, 0.));
414 arrCtrlPts.push_back(center + OdGeVector3d(2. * major, 1. * minor, 0.));
415 arrCtrlPts.push_back(center + OdGeVector3d(2. * major, 2. * minor, 0.));
416 arrCtrlPts.push_back(center + OdGeVector3d(1. * major, 2. * minor, 0.));
417 arrCtrlPts.push_back(center + OdGeVector3d(1. * major, 1. * minor, 0.));
418 arrCtrlPts.push_back(center +
419 OdGeVector3d(1. * major, -1. * minor, 0.));
420 arrCtrlPts.push_back(center +
421 OdGeVector3d(1. * major, -2. * minor, 0.));
422 arrCtrlPts.push_back(center +
423 OdGeVector3d(2. * major, -2. * minor, 0.));
424 arrCtrlPts.push_back(center +
425 OdGeVector3d(2. * major, -1. * minor, 0.));
426 arrCtrlPts.push_back(center +
427 OdGeVector3d(1. * major, -1. * minor, 0.));
428 arrCtrlPts.push_back(center +
429 OdGeVector3d(-1. * major, -1. * minor, 0.));
430 arrCtrlPts.push_back(center +
431 OdGeVector3d(-2. * major, -1. * minor, 0.));
432 arrCtrlPts.push_back(center +
433 OdGeVector3d(-2. * major, -2. * minor, 0.));
434 arrCtrlPts.push_back(center +
435 OdGeVector3d(-1. * major, -2. * minor, 0.));
436 arrCtrlPts.push_back(center +
437 OdGeVector3d(-1. * major, -1. * minor, 0.));
438 arrCtrlPts.push_back(center +
439 OdGeVector3d(-1. * major, 1. * minor, 0.));
440
441 OdGeKnotVector vrKnots;
442 OdGeDoubleArray arrWeights;
443
444 curve->setNurbsData(4, false, true, arrCtrlPts, vrKnots, arrWeights);
445 }
446
447 {
448 OdDgBSplineCurve2dPtr curve = OdDgBSplineCurve2d::createObject();
449 pModel->addElement(curve);
450
451 OdGePoint2dArray arrCtrlPts;
452 OdGePoint2d center;
453 double major = 1.0;
454 double minor = 0.5;
455 arrCtrlPts.push_back(center + OdGeVector2d(-1. * major, 1. * minor));
456 arrCtrlPts.push_back(center + OdGeVector2d(-1. * major, 2. * minor));
457 arrCtrlPts.push_back(center + OdGeVector2d(-2. * major, 2. * minor));
458 arrCtrlPts.push_back(center + OdGeVector2d(-2. * major, 1. * minor));
459 arrCtrlPts.push_back(center + OdGeVector2d(-1. * major, 1. * minor));
460 arrCtrlPts.push_back(center + OdGeVector2d(1. * major, 1. * minor));
461 arrCtrlPts.push_back(center + OdGeVector2d(2. * major, 1. * minor));
462 arrCtrlPts.push_back(center + OdGeVector2d(2. * major, 2. * minor));
463 arrCtrlPts.push_back(center + OdGeVector2d(1. * major, 2. * minor));
464 arrCtrlPts.push_back(center + OdGeVector2d(1. * major, 1. * minor));
465 arrCtrlPts.push_back(center + OdGeVector2d(1. * major, -1. * minor));
466 arrCtrlPts.push_back(center + OdGeVector2d(1. * major, -2. * minor));
467 arrCtrlPts.push_back(center + OdGeVector2d(2. * major, -2. * minor));
468 arrCtrlPts.push_back(center + OdGeVector2d(2. * major, -1. * minor));
469 arrCtrlPts.push_back(center + OdGeVector2d(1. * major, -1. * minor));
470 arrCtrlPts.push_back(center + OdGeVector2d(-1. * major, -1. * minor));
471 arrCtrlPts.push_back(center + OdGeVector2d(-2. * major, -1. * minor));
472 arrCtrlPts.push_back(center + OdGeVector2d(-2. * major, -2. * minor));
473 arrCtrlPts.push_back(center + OdGeVector2d(-1. * major, -2. * minor));
474 arrCtrlPts.push_back(center + OdGeVector2d(-1. * major, -1. * minor));
475 arrCtrlPts.push_back(center + OdGeVector2d(-1. * major, 1. * minor));
476
477 OdGeKnotVector vrKnots;
478 OdGeDoubleArray arrWeights;
479
480 curve->setNurbsData(4, false, true, arrCtrlPts, vrKnots, arrWeights);
481 }
482
483 // ComplexString
484 {
485 OdDgComplexStringPtr complex = OdDgComplexString::createObject();
486 pModel->addElement(complex);
487
488 OdDgLine2dPtr line = OdDgLine2d::createObject();
489 complex->add(line);
490 OdGePoint2d point;
491 point.x = 0;
492 point.y = 1;
493 line->setStartPoint(point);
494 point.x = 2;
495 point.y = 3;
496 line->setEndPoint(point);
497
498 line = OdDgLine2d::createObject();
499 complex->add(line);
500 point.x = 2;
501 point.y = 3;
502 line->setStartPoint(point);
503 point.x = 4;
504 point.y = 5;
505 line->setEndPoint(point);
506 }
507
508 // ComplexString
509 {
510 OdDgComplexStringPtr complex = OdDgComplexString::createObject();
511 pModel->addElement(complex);
512
513 OdDgLine3dPtr line = OdDgLine3d::createObject();
514 complex->add(line);
515 OdGePoint3d point;
516 point.x = 0;
517 point.y = 1;
518 point.z = 2;
519 line->setStartPoint(point);
520 point.x = 2;
521 point.y = 3;
522 line->setEndPoint(point);
523
524 line = OdDgLine3d::createObject();
525 complex->add(line);
526 point.x = 2;
527 point.y = 3;
528 line->setStartPoint(point);
529 point.x = 4;
530 point.y = 5;
531 line->setEndPoint(point);
532 }
533
534 // ComplexString
535 {
536 OdDgComplexStringPtr complex = OdDgComplexString::createObject();
537 pModel->addElement(complex);
538
539 OdDgLine2dPtr line = OdDgLine2d::createObject();
540 complex->add(line);
541 OdGePoint2d point;
542 point.x = 0;
543 point.y = 1;
544 line->setStartPoint(point);
545 point.x = 2;
546 point.y = 1;
547 line->setEndPoint(point);
548
549 OdDgArc2dPtr arc = OdDgArc2d::createObject();
550 complex->add(arc);
551 arc->setPrimaryAxis(1);
552 arc->setSecondaryAxis(1);
553 point.x = 3;
554 point.y = 1;
555 arc->setOrigin(point);
556 arc->setStartAngle(180 * DEG_TO_RAD);
557 arc->setSweepAngle(180 * DEG_TO_RAD);
558 }
559
560 // Polygon 2D
561 {
562 OdDgShape2dPtr shape = OdDgShape2d::createObject();
563 pModel->addElement(shape);
564 OdGePoint2d point;
565 point.x = 0;
566 point.y = 0;
567 shape->addVertex(point);
568 point.x = 0;
569 point.y = 1;
570 shape->addVertex(point);
571 point.x = 1;
572 point.y = 1;
573 shape->addVertex(point);
574 point.x = 0;
575 point.y = 0;
576 shape->addVertex(point);
577
578 OdDgFillColorLinkagePtr fillColor =
579 OdDgFillColorLinkage::createObject();
580 OdUInt32 nIdx = OdDgColorTable::getColorIndexByRGB(
581 shape->database(), ODRGB(200, 255, 150));
582 fillColor->setColorIndex(nIdx);
583 shape->addLinkage(fillColor->getPrimaryId(), fillColor.get());
584 }
585
586 // Polygon 3D
587 {
588 OdDgShape3dPtr shape = OdDgShape3d::createObject();
589 pModel->addElement(shape);
590 OdGePoint3d point;
591 point.x = 0;
592 point.y = 0;
593 point.z = 1;
594 shape->addVertex(point);
595 point.x = 0;
596 point.y = 1;
597 shape->addVertex(point);
598 point.x = 1;
599 point.y = 1;
600 shape->addVertex(point);
601 point.x = 0;
602 point.y = 0;
603 shape->addVertex(point);
604 }
605
606 // Polygon 2D with hole
607 {
608 OdDgCellHeader2dPtr pCell = OdDgCellHeader2d::createObject();
609 pModel->addElement(pCell);
610
611 OdDgShape2dPtr shape = OdDgShape2d::createObject();
612 pCell->add(shape);
613 OdGePoint2d point;
614 point.x = 0;
615 point.y = 0;
616 shape->addVertex(point);
617 point.x = 0;
618 point.y = 1;
619 shape->addVertex(point);
620 point.x = 1;
621 point.y = 1;
622 shape->addVertex(point);
623 point.x = 0;
624 point.y = 0;
625 shape->addVertex(point);
626
627 shape = OdDgShape2d::createObject();
628 shape->setHbitFlag(true);
629 pCell->add(shape);
630 point.x = 0.1;
631 point.y = 0.1;
632 shape->addVertex(point);
633 point.x = 0.1;
634 point.y = 0.9;
635 shape->addVertex(point);
636 point.x = 0.9;
637 point.y = 0.9;
638 shape->addVertex(point);
639 point.x = 0.1;
640 point.y = 0.1;
641 shape->addVertex(point);
642 }
643
644 // Polygon 3D with hole
645 {
646 OdDgCellHeader3dPtr pCell = OdDgCellHeader3d::createObject();
647 pModel->addElement(pCell);
648
649 OdDgShape3dPtr shape = OdDgShape3d::createObject();
650 pCell->add(shape);
651 OdGePoint3d point;
652 point.x = 0;
653 point.y = 0;
654 point.z = 1;
655 shape->addVertex(point);
656 point.x = 0;
657 point.y = 1;
658 shape->addVertex(point);
659 point.x = 1;
660 point.y = 1;
661 shape->addVertex(point);
662 point.x = 0;
663 point.y = 0;
664 shape->addVertex(point);
665
666 shape = OdDgShape3d::createObject();
667 shape->setHbitFlag(true);
668 pCell->add(shape);
669 point.x = 0.1;
670 point.y = 0.1;
671 shape->addVertex(point);
672 point.x = 0.1;
673 point.y = 0.9;
674 shape->addVertex(point);
675 point.x = 0.9;
676 point.y = 0.9;
677 shape->addVertex(point);
678 point.x = 0.1;
679 point.y = 0.1;
680 shape->addVertex(point);
681 }
682
683 // ComplexShape
684 {
685 OdDgComplexShapePtr complex = OdDgComplexShape::createObject();
686 pModel->addElement(complex);
687
688 OdDgLine2dPtr line = OdDgLine2d::createObject();
689 complex->add(line);
690 OdGePoint2d point;
691 point.x = 0;
692 point.y = 0;
693 line->setStartPoint(point);
694 point.x = 0;
695 point.y = 1;
696 line->setEndPoint(point);
697
698 line = OdDgLine2d::createObject();
699 complex->add(line);
700 point.x = 1;
701 point.y = 1;
702 line->setStartPoint(point);
703 point.x = 1;
704 point.y = 0;
705 line->setEndPoint(point);
706
707 line = OdDgLine2d::createObject();
708 complex->add(line);
709 point.x = 1;
710 point.y = 0;
711 line->setStartPoint(point);
712 point.x = 0;
713 point.y = 0;
714 line->setEndPoint(point);
715 }
716
717 // ComplexShape
718 {
719 OdDgComplexShapePtr complex = OdDgComplexShape::createObject();
720 pModel->addElement(complex);
721
722 OdDgLine2dPtr line = OdDgLine2d::createObject();
723 complex->add(line);
724 OdGePoint2d point;
725 point.x = 0;
726 point.y = 0;
727 line->setStartPoint(point);
728 point.x = 0;
729 point.y = 1;
730 line->setEndPoint(point);
731
732 OdDgArc2dPtr arc = OdDgArc2d::createObject();
733 complex->add(arc);
734 arc->setPrimaryAxis(0.5);
735 arc->setSecondaryAxis(0.5);
736 point.x = 0.5;
737 point.y = 1;
738 arc->setOrigin(point);
739 arc->setStartAngle(180 * DEG_TO_RAD);
740 arc->setSweepAngle(-180 * DEG_TO_RAD);
741
742 line = OdDgLine2d::createObject();
743 complex->add(line);
744 point.x = 1;
745 point.y = 1;
746 line->setStartPoint(point);
747 point.x = 0;
748 point.y = 0;
749 line->setEndPoint(point);
750 }
751
752 // ComplexShape (out of order rings, we handle that, not sure this is legal
753 // though)
754 {
755 OdDgComplexShapePtr complex = OdDgComplexShape::createObject();
756 pModel->addElement(complex);
757
758 OdDgLine2dPtr line = OdDgLine2d::createObject();
759 complex->add(line);
760 OdGePoint2d point;
761 point.x = 0;
762 point.y = 0;
763 line->setStartPoint(point);
764 point.x = 0;
765 point.y = 1;
766 line->setEndPoint(point);
767
768 line = OdDgLine2d::createObject();
769 complex->add(line);
770 point.x = 1;
771 point.y = 0;
772 line->setStartPoint(point);
773 point.x = 0;
774 point.y = 0;
775 line->setEndPoint(point);
776
777 line = OdDgLine2d::createObject();
778 complex->add(line);
779 point.x = 1;
780 point.y = 1;
781 line->setStartPoint(point);
782 point.x = 1;
783 point.y = 0;
784 line->setEndPoint(point);
785 }
786
787 // create a definition and reference
788 {
789 OdDgSharedCellDefinitionPtr definition;
790 OdDgSharedCellDefinitionTablePtr table =
791 pDb->getSharedCellDefinitionTable(OdDg::kForWrite);
792
793 definition = OdDgSharedCellDefinition::createObject();
794 definition->setName("Named definition");
795 table->add(definition);
796
797 OdDgEllipse3dPtr ellipse;
798 ellipse = OdDgEllipse3d::createObject();
799 ellipse->setPrimaryAxis(1.);
800 ellipse->setSecondaryAxis(1.);
801 definition->add(ellipse);
802
803 OdDgSharedCellReferencePtr reference;
804
805 reference = OdDgSharedCellReference::createObject();
806 reference->setDefinitionName("Named definition");
807 OdGePoint3d point;
808 point.x = 0;
809 point.y = 1;
810 point.z = 2;
811 reference->setOrigin(point);
812 pModel->addElement(reference);
813 }
814
815 // Unhandled element.
816 {
817 OdDgTagElementPtr tag = OdDgTagElement::createObject();
818 pModel->addElement(tag);
819 }
820
821 pModel->fitToView();
822 pDb->writeFile("test_dgnv8.dgn");
823 pDb = nullptr;
824
825 ::odrxUninitialize();
826
827 return 0;
828 }