1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #ifndef _DXFENTRD_HXX
25 #define _DXFENTRD_HXX
26
27 #include <dxfgrprd.hxx>
28 #include <dxfvec.hxx>
29
30 #include <deque>
31
32 typedef std::deque< Point > DXFPointArray;
33
34 //------------------------------------------------------------------------------
35 //------------------------- Art eines Entity -----------------------------------
36 //------------------------------------------------------------------------------
37
38 enum DXFEntityType {
39 DXF_LINE,
40 DXF_POINT,
41 DXF_CIRCLE,
42 DXF_ARC,
43 DXF_TRACE,
44 DXF_SOLID,
45 DXF_TEXT,
46 DXF_SHAPE,
47 DXF_INSERT,
48 DXF_ATTDEF,
49 DXF_ATTRIB,
50 DXF_POLYLINE,
51 DXF_VERTEX,
52 DXF_SEQEND,
53 DXF_3DFACE,
54 DXF_DIMENSION,
55 DXF_LWPOLYLINE,
56 DXF_HATCH,
57 DXF_ELLIPSE,
58 DXF_SPLINE
59 };
60
61 //------------------------------------------------------------------------------
62 //---------------------- Basisklasse fuer ein Entity ---------------------------
63 //------------------------------------------------------------------------------
64
65 class DXFBasicEntity {
66
67 public:
68
69 DXFBasicEntity * pSucc;
70 // Zeiger auf naechstes Entity (in der Liste DXFEntities.pFirst)
71
72 DXFEntityType eType;
73 // Art des Entitys (Linie oder Kreis oder was)
74
75 // Eigenschaftenm, die alle Entities besitzen, jeweils
76 // durch den Gruppencode kommentiert:
77 char sLayer[DXF_MAX_STRING_LEN+1]; // 8
78 char sLineType[DXF_MAX_STRING_LEN+1]; // 6
79 double fElevation; // 38
80 double fThickness; // 39
81 long nColor; // 62
82 long nSpace; // 67
83 DXFVector aExtrusion; // 210,220,230
84
85 protected:
86
87 DXFBasicEntity(DXFEntityType eThisType);
88 // Konstruktoren der Entities initialiseren immer mit Defaultwerten.
89
90 public:
91
92 virtual ~DXFBasicEntity();
93 virtual void Read(DXFGroupReader & rDGR);
94 // Liest die Prameter ein, bis zur naechten 0-Gruppe
95
96 protected:
97
98 virtual void EvaluateGroup(DXFGroupReader & rDGR);
99 // Diese Methode wird durch Read() fuer jeden Parameter (bzw. fuer jede
100 // Gruppe) aufgerufen.
101 // Sofern der Gruppencode dem Entity bekannt ist, wird der entsprechende
102 // Parameter geholt.
103
104 };
105
106 //------------------------------------------------------------------------------
107 //---------------- die verschiedenen Arten von Entyties ------------------------
108 //------------------------------------------------------------------------------
109
110 //--------------------------Line------------------------------------------------
111
112 class DXFLineEntity : public DXFBasicEntity {
113
114 public:
115
116 DXFVector aP0; // 10,20,30
117 DXFVector aP1; // 11,21,31
118
119 DXFLineEntity();
120
121 protected:
122
123 virtual void EvaluateGroup(DXFGroupReader & rDGR);
124 };
125
126 //--------------------------Point-----------------------------------------------
127
128 class DXFPointEntity : public DXFBasicEntity {
129
130 public:
131
132 DXFVector aP0; // 10,20,30
133
134 DXFPointEntity();
135
136 protected:
137
138 virtual void EvaluateGroup(DXFGroupReader & rDGR);
139 };
140
141 //--------------------------Circle----------------------------------------------
142
143 class DXFCircleEntity : public DXFBasicEntity {
144
145 public:
146
147 DXFVector aP0; // 10,20,30
148 double fRadius; // 40
149
150 DXFCircleEntity();
151
152 protected:
153
154 virtual void EvaluateGroup(DXFGroupReader & rDGR);
155 };
156
157 //--------------------------Arc-------------------------------------------------
158
159 class DXFArcEntity : public DXFBasicEntity {
160
161 public:
162
163 DXFVector aP0; // 10,20,30
164 double fRadius; // 40
165 double fStart; // 50
166 double fEnd; // 51
167
168 DXFArcEntity();
169
170 protected:
171
172 virtual void EvaluateGroup(DXFGroupReader & rDGR);
173 };
174
175 //--------------------------Trace-----------------------------------------------
176
177 class DXFTraceEntity : public DXFBasicEntity {
178
179 public:
180
181 DXFVector aP0; // 10,20,30
182 DXFVector aP1; // 11,21,31
183 DXFVector aP2; // 12,22,32
184 DXFVector aP3; // 13,23,33
185
186 DXFTraceEntity();
187
188 protected:
189
190 virtual void EvaluateGroup(DXFGroupReader & rDGR);
191 };
192
193 //--------------------------Solid-----------------------------------------------
194
195 class DXFSolidEntity : public DXFBasicEntity {
196
197 public:
198
199 DXFVector aP0; // 10,20,30
200 DXFVector aP1; // 11,21,31
201 DXFVector aP2; // 12,22,32
202 DXFVector aP3; // 13,23,33
203
204 DXFSolidEntity();
205
206 protected:
207
208 virtual void EvaluateGroup(DXFGroupReader & rDGR);
209 };
210
211 //--------------------------Text------------------------------------------------
212
213 class DXFTextEntity : public DXFBasicEntity {
214
215 public:
216
217 DXFVector aP0; // 10,20,30
218 double fHeight; // 40
219 char sText[DXF_MAX_STRING_LEN+1]; // 1
220 double fRotAngle; // 50
221 double fXScale; // 41
222 double fOblAngle; // 42
223 char sStyle[DXF_MAX_STRING_LEN+1]; // 7
224 long nGenFlags; // 71
225 long nHorzJust; // 72
226 long nVertJust; // 73
227 DXFVector aAlign; // 11,21,31
228
229 DXFTextEntity();
230
231 protected:
232
233 virtual void EvaluateGroup(DXFGroupReader & rDGR);
234 };
235
236 //--------------------------Shape-----------------------------------------------
237
238 class DXFShapeEntity : public DXFBasicEntity {
239
240 public:
241
242 DXFVector aP0; // 10,20,30
243 double fSize; // 40
244 char sName[DXF_MAX_STRING_LEN+1]; // 2
245 double fRotAngle; // 50
246 double fXScale; // 41
247 double fOblAngle; // 51
248
249 DXFShapeEntity();
250
251 protected:
252
253 virtual void EvaluateGroup(DXFGroupReader & rDGR);
254 };
255
256 //--------------------------Insert----------------------------------------------
257
258 class DXFInsertEntity : public DXFBasicEntity {
259
260 public:
261
262 long nAttrFlag; // 66
263 char sName[DXF_MAX_STRING_LEN+1]; // 2
264 DXFVector aP0; // 10,20,30
265 double fXScale; // 41
266 double fYScale; // 42
267 double fZScale; // 43
268 double fRotAngle; // 50
269 long nColCount; // 70
270 long nRowCount; // 71
271 double fColSpace; // 44
272 double fRowSpace; // 45
273
274 DXFInsertEntity();
275
276 protected:
277
278 virtual void EvaluateGroup(DXFGroupReader & rDGR);
279 };
280
281 //--------------------------AttDef----------------------------------------------
282
283 class DXFAttDefEntity : public DXFBasicEntity {
284
285 public:
286
287 DXFVector aP0; // 10,20,30
288 double fHeight; // 40
289 char sDefVal[DXF_MAX_STRING_LEN+1]; // 1
290 char sPrompt[DXF_MAX_STRING_LEN+1]; // 3
291 char sTagStr[DXF_MAX_STRING_LEN+1]; // 2
292 long nAttrFlags; // 70
293 long nFieldLen; // 73
294 double fRotAngle; // 50
295 double fXScale; // 41
296 double fOblAngle; // 51
297 char sStyle[DXF_MAX_STRING_LEN+1]; // 7
298 long nGenFlags; // 71
299 long nHorzJust; // 72
300 long nVertJust; // 74
301 DXFVector aAlign; // 11,21,31
302
303 DXFAttDefEntity();
304
305 protected:
306
307 virtual void EvaluateGroup(DXFGroupReader & rDGR);
308 };
309
310 //--------------------------Attrib----------------------------------------------
311
312 class DXFAttribEntity : public DXFBasicEntity {
313
314 public:
315
316 DXFVector aP0; // 10,20,30
317 double fHeight; // 40
318 char sText[DXF_MAX_STRING_LEN+1]; // 1
319 char sTagStr[DXF_MAX_STRING_LEN+1]; // 2
320 long nAttrFlags; // 70
321 long nFieldLen; // 73
322 double fRotAngle; // 50
323 double fXScale; // 41
324 double fOblAngle; // 51
325 char sStyle[DXF_MAX_STRING_LEN+1]; // 7
326 long nGenFlags; // 71
327 long nHorzJust; // 72
328 long nVertJust; // 74
329 DXFVector aAlign; // 11,21,31
330
331 DXFAttribEntity();
332
333 protected:
334
335 virtual void EvaluateGroup(DXFGroupReader & rDGR);
336 };
337
338 //--------------------------PolyLine--------------------------------------------
339
340 class DXFPolyLineEntity : public DXFBasicEntity {
341
342 public:
343
344 double fElevation; // 30
345 long nFlags; // 70
346 double fSWidth; // 40
347 double fEWidth; // 41
348 long nMeshMCount; // 71
349 long nMeshNCount; // 72
350 long nMDensity; // 73
351 long nNDensity; // 74
352 long nCSSType; // 75
353
354 DXFPolyLineEntity();
355
356 protected:
357
358 virtual void EvaluateGroup(DXFGroupReader & rDGR);
359 };
360
361 class DXFLWPolyLineEntity : public DXFBasicEntity
362 {
363 sal_Int32 nIndex;
364
365 public :
366
367 sal_Int32 nCount; // 90
368 sal_Int32 nFlags; // 70 1 = closed, 128 = plinegen
369 double fConstantWidth; // 43 (optional - default: 0, not used if fStartWidth and/or fEndWidth is used)
370 double fStartWidth; // 40
371 double fEndWidth; // 41
372
373 DXFVector* pP;
374 double* pBulge; // 42 (per vertex; parallel to pP, 0.0 = straight segment)
375
376 DXFLWPolyLineEntity();
377 ~DXFLWPolyLineEntity();
378
379 protected :
380
381 virtual void EvaluateGroup( DXFGroupReader & rDGR );
382
383 };
384
385 //-------------------------- Hatch ---------------------------------------------
386
387 struct DXFEdgeType
388 {
389 sal_Int32 nEdgeType;
390
~DXFEdgeTypeDXFEdgeType391 virtual ~DXFEdgeType(){};
EvaluateGroupDXFEdgeType392 virtual sal_Bool EvaluateGroup( DXFGroupReader & /*rDGR*/ ){ return sal_True; };
393
394 protected :
395
DXFEdgeTypeDXFEdgeType396 DXFEdgeType( sal_Int32 EdgeType ):nEdgeType(EdgeType){};
397 };
398 struct DXFEdgeTypeLine : public DXFEdgeType
399 {
400 DXFVector aStartPoint; // 10,20
401 DXFVector aEndPoint; // 11,21
402 DXFEdgeTypeLine();
403 virtual ~DXFEdgeTypeLine();
404 virtual sal_Bool EvaluateGroup( DXFGroupReader & rDGR );
405 };
406 struct DXFEdgeTypeCircularArc : public DXFEdgeType
407 {
408 DXFVector aCenter; // 10,20
409 double fRadius; // 40
410 double fStartAngle; // 50
411 double fEndAngle; // 51
412 sal_Int32 nIsCounterClockwiseFlag; // 73
413 DXFEdgeTypeCircularArc();
414 virtual ~DXFEdgeTypeCircularArc();
415 virtual sal_Bool EvaluateGroup( DXFGroupReader & rDGR );
416 };
417 struct DXFEdgeTypeEllipticalArc : public DXFEdgeType
418 {
419 DXFVector aCenter; // 10,20
420 DXFVector aEndPoint; // 11,21
421 double fLength; // 40
422 double fStartAngle; // 50
423 double fEndAngle; // 51
424 sal_Int32 nIsCounterClockwiseFlag; // 73
425
426 DXFEdgeTypeEllipticalArc();
427 virtual ~DXFEdgeTypeEllipticalArc();
428 virtual sal_Bool EvaluateGroup( DXFGroupReader & rDGR );
429 };
430 struct DXFEdgeTypeSpline : public DXFEdgeType
431 {
432 sal_Int32 nDegree; // 94
433 sal_Int32 nRational; // 73
434 sal_Int32 nPeriodic; // 74
435 sal_Int32 nKnotCount; // 75
436 sal_Int32 nControlCount; // 76
437
438 DXFEdgeTypeSpline();
439 virtual ~DXFEdgeTypeSpline();
440 virtual sal_Bool EvaluateGroup( DXFGroupReader & rDGR );
441 };
442
443 typedef std::deque< DXFEdgeType* > DXFEdgeTypeArray;
444
445 struct DXFBoundaryPathData
446 {
447 sal_Int32 nFlags; // 92
448 sal_Int32 nHasBulgeFlag; // 72
449 sal_Int32 nIsClosedFlag; // 73
450 sal_Int32 nPointCount; // 93
451 double fBulge; // 42
452 sal_Int32 nSourceBoundaryObjects; // 97
453 sal_Int32 nEdgeCount; // 93
454
455 sal_Bool bIsPolyLine;
456 sal_Int32 nPointIndex;
457
458 DXFVector* pP;
459 DXFEdgeTypeArray aEdges;
460
461 DXFBoundaryPathData();
462 ~DXFBoundaryPathData();
463
464 sal_Bool EvaluateGroup( DXFGroupReader & rDGR );
465 };
466
467 class DXFHatchEntity : public DXFBasicEntity
468 {
469 sal_Bool bIsInBoundaryPathContext;
470 sal_Int32 nCurrentBoundaryPathIndex;
471 sal_Bool bPatternLineOffsetSet; // transient parse state (first 45/46 captured)
472
473 public :
474
475 DXFVector aElevationPoint;
476 sal_Int32 nFlags; // 70 (solid fill = 1, pattern fill = 0)
477 sal_Int32 nAssociativityFlag; // 71 (associative = 1, non-associative = 0)
478 sal_Int32 nBoundaryPathCount; // 91
479 sal_Int32 nHatchStyle; // 75 (odd parity = 0, outmost area = 1, entire area = 2 )
480 sal_Int32 nHatchPatternType; // 76 (user defined = 0, predefined = 1, custom = 2)
481 double fHatchPatternAngle; // 52 (pattern fill only)
482 double fHatchPatternScale; // 41 (pattern fill only:scale or spacing)
483 sal_Int32 nHatchDoubleFlag; // 77 (pattern fill only:double = 1, not double = 0)
484 sal_Int32 nHatchPatternDefinitionLines; // 78
485 double fPixelSize; // 47
486 sal_Int32 nNumberOfSeedPoints; // 98
487
488 // First pattern-definition line (78 block). Enough to drive a VCL Hatch
489 // (single/double/triple): the line angle (53) and the inter-line offset
490 // (45/46) give on-page angle + spacing; multi-line patterns collapse to
491 // this line's geometry plus the style from nHatchPatternDefinitionLines.
492 sal_Bool bHasPatternLine; // a 53 line angle was parsed
493 double fPatternLineAngle; // 53
494 double fPatternLineOffsetX; // 45
495 double fPatternLineOffsetY; // 46
496
497 DXFBoundaryPathData* pBoundaryPathData;
498
499 DXFHatchEntity();
500 ~DXFHatchEntity();
501
502 protected :
503
504 virtual void EvaluateGroup( DXFGroupReader & rDGR );
505 };
506
507
508 //--------------------------Ellipse---------------------------------------------
509
510 class DXFEllipseEntity : public DXFBasicEntity {
511
512 public:
513
514 DXFVector aP0; // 10,20,30 center
515 DXFVector aP1; // 11,21,31 endpoint of the major axis, relative to center
516 double fRatio; // 40 ratio of minor axis to major axis
517 double fStart; // 41 start parameter (radians; 0 for a full ellipse)
518 double fEnd; // 42 end parameter (radians; 2*pi for a full ellipse)
519
520 DXFEllipseEntity();
521
522 protected:
523
524 virtual void EvaluateGroup(DXFGroupReader & rDGR);
525 };
526
527 //--------------------------Spline----------------------------------------------
528
529 class DXFSplineEntity : public DXFBasicEntity {
530
531 public:
532
533 long nFlags; // 70 bit 1=closed, 2=periodic, 4=rational, 8=planar
534 long nDegree; // 71
535 long nKnotCount; // 72
536 long nCtrlCount; // 73
537 long nFitCount; // 74
538
539 double * pfKnots; // 40 (nKnotCount entries)
540 DXFVector * pControlPts; // 10,20,30 (nCtrlCount entries)
541
542 DXFSplineEntity();
543 ~DXFSplineEntity();
544
545 protected:
546
547 virtual void EvaluateGroup(DXFGroupReader & rDGR);
548
549 private:
550
551 long nKnotIndex;
552 long nCtrlIndex;
553 };
554
555 //--------------------------Vertex----------------------------------------------
556
557 class DXFVertexEntity : public DXFBasicEntity {
558
559 public:
560
561 DXFVector aP0; // 10,20,30
562 double fSWidth; // 40 (Wenn <0.0, dann gilt DXFPolyLine::fSWidth)
563 double fEWidth; // 41 (Wenn <0.0, dann gilt DXFPolyLine::fEWidth)
564 double fBulge; // 42
565 long nFlags; // 70
566 double fCFTDir; // 50
567
568 DXFVertexEntity();
569
570 protected:
571
572 virtual void EvaluateGroup(DXFGroupReader & rDGR);
573 };
574
575 //--------------------------SeqEnd----------------------------------------------
576
577 class DXFSeqEndEntity : public DXFBasicEntity {
578
579 public:
580
581 DXFSeqEndEntity();
582 };
583
584 //--------------------------3DFace----------------------------------------------
585
586 class DXF3DFaceEntity : public DXFBasicEntity {
587
588 public:
589
590 DXFVector aP0; // 10,20,30
591 DXFVector aP1; // 11,21,31
592 DXFVector aP2; // 12,22,32
593 DXFVector aP3; // 13,23,33
594 long nIEFlags; // 70
595
596 DXF3DFaceEntity();
597
598 protected:
599
600 virtual void EvaluateGroup(DXFGroupReader & rDGR);
601 };
602
603 //--------------------------Dimension-------------------------------------------
604
605 class DXFDimensionEntity : public DXFBasicEntity {
606
607 public:
608
609 char sPseudoBlock[DXF_MAX_STRING_LEN+1]; // 2
610
611 DXFDimensionEntity();
612
613 protected:
614
615 virtual void EvaluateGroup(DXFGroupReader & rDGR);
616 };
617
618 //------------------------------------------------------------------------------
619 //----------- Eine Menge von Entities lesen und repraesentieren ----------------
620 //------------------------------------------------------------------------------
621
622 class DXFEntities {
623
624 public:
625
626 DXFEntities();
627 ~DXFEntities();
628
629 DXFBasicEntity * pFirst; // Liste von Entities, READ ONLY!
630
631 void Read(DXFGroupReader & rDGR);
632 // Liest Entitis per rGDR aus einer DXF-Datei bis zu
633 // einem ENDBLK, ENDSEC oder EOF (der Gruppe 0).
634 // (Alle unbekannten Dinge werden uebersprungen)
635
636 void Clear();
637 // Loescht alle Entities
638 };
639
640 // True when an entity's stored coordinates are already in WCS, so the OCS
641 // "arbitrary axis" (extrusion) transform must NOT be applied to them. Used by
642 // BOTH the renderer (DrawEntities) and the bounding-box pass (CalcBoundingBox) so
643 // they stay consistent: flat/planar entities (CIRCLE, ARC, TEXT, 2D POLYLINE,
644 // LWPOLYLINE, INSERT, ...) are OCS and DO need the extrusion; inherently-3D
645 // entities (LINE, POINT, 3DFACE, and a 3D polyline / mesh) carry WCS coordinates.
646 sal_Bool DXFCoordsAreWCS(const DXFBasicEntity & rE);
647
648 //------------------------------------------------------------------------------
649 //--------------------------------- inlines ------------------------------------
650 //------------------------------------------------------------------------------
651
DXFEntities()652 inline DXFEntities::DXFEntities()
653 {
654 pFirst=NULL;
655 }
656
657
~DXFEntities()658 inline DXFEntities::~DXFEntities()
659 {
660 Clear();
661 }
662
663
664 #endif
665