Line data Source code
1 : /*******************************************************************************
2 : * Project: libopencad
3 : * Purpose: OpenSource CAD formats support library
4 : * Author: Alexandr Borzykh, mush3d at gmail.com
5 : * Author: Dmitry Baryshnikov, bishop.dev@gmail.com
6 : * Language: C++
7 : *******************************************************************************
8 : * The MIT License (MIT)
9 : *
10 : * Copyright (c) 2016 Alexandr Borzykh
11 : * Copyright (c) 2016 NextGIS, <info@nextgis.com>
12 : *
13 : * SPDX-License-Identifier: MIT
14 : *******************************************************************************/
15 : #ifndef CADGEOMETRIES_H
16 : #define CADGEOMETRIES_H
17 :
18 : #include "cadobjects.h"
19 : #include "cadcolors.h"
20 :
21 : #include <array>
22 :
23 : class CADAttdef;
24 : class CADAttrib;
25 :
26 : /**
27 : * @brief The Matrix class
28 : */
29 : class Matrix
30 : {
31 : public:
32 0 : Matrix() = default;
33 : void translate( const CADVector& vector );
34 : void rotate( double rotation );
35 : void scale( const CADVector& vector );
36 : CADVector multiply( const CADVector& vector ) const;
37 : protected:
38 : std::array<double, 9> matrix = {{1.0, 0.0, 0.0,
39 : 0.0, 1.0, 0.0,
40 : 0.0, 0.0, 1.0}};
41 : };
42 :
43 : /**
44 : * @brief Base CAD geometry class
45 : */
46 0 : class OCAD_EXTERN CADGeometry
47 : {
48 : public:
49 : CADGeometry();
50 : virtual ~CADGeometry();
51 8 : CADGeometry(const CADGeometry&) = default;
52 : CADGeometry& operator=(const CADGeometry&) = default;
53 0 : CADGeometry(CADGeometry&&) = default;
54 : CADGeometry& operator=(CADGeometry&&) = default;
55 :
56 : /**
57 : * @brief The CAD geometry types enum
58 : */
59 : enum GeometryType
60 : {
61 : UNDEFINED = 0,
62 : POINT,
63 : CIRCLE,
64 : LWPOLYLINE,
65 : ELLIPSE,
66 : LINE,
67 : POLYLINE3D,
68 : TEXT,
69 : ARC,
70 : SPLINE,
71 : SOLID,
72 : RAY,
73 : HATCH, // NOT IMPLEMENTED
74 : IMAGE,
75 : MTEXT,
76 : MLINE,
77 : XLINE,
78 : FACE3D,
79 : POLYLINE_PFACE,
80 : ATTRIB,
81 : ATTDEF
82 : };
83 :
84 : enum GeometryType getType() const;
85 : double getThickness() const;
86 : void setThickness( double thickness );
87 : RGBColor getColor() const;
88 : void setColor( RGBColor color ); // TODO: In 2004+ ACI is not the only way to set the color.
89 :
90 : std::vector<CADAttrib> getBlockAttributes() const;
91 : void setBlockAttributes( const std::vector<CADAttrib>& value );
92 :
93 : std::vector<std::string> getEED() const;
94 : void setEED( const std::vector<std::string>& eed );
95 :
96 : virtual void print() const = 0;
97 : virtual void transform( const Matrix& matrix ) = 0;
98 : protected:
99 : std::vector<CADAttrib> blockAttributes; // Attributes of block reference this geometry is attached to.
100 :
101 : std::vector<std::string> asEED;
102 : enum GeometryType geometryType;
103 : double m_thickness;
104 : RGBColor geometry_color;
105 : };
106 :
107 : /**
108 : * @brief Geometry class which represents Unhandled geometry (means that library can't read it yet)
109 : */
110 : class CADUnknown : public CADGeometry
111 : {
112 : public:
113 : CADUnknown();
114 :
115 : virtual void print() const override;
116 : void transform( const Matrix& matrix ) override;
117 : };
118 :
119 : /**
120 : * @brief Geometry class which a single Point
121 : */
122 : class OCAD_EXTERN CADPoint3D : public CADGeometry
123 : {
124 : public:
125 : CADPoint3D();
126 : CADPoint3D( const CADVector& positionIn, double thicknessIn );
127 :
128 : CADVector getPosition() const;
129 : void setPosition( const CADVector& value );
130 :
131 : CADVector getExtrusion() const;
132 : void setExtrusion( const CADVector& value );
133 :
134 : double getXAxisAng() const;
135 : void setXAxisAng( double value );
136 :
137 : virtual void print() const override;
138 : virtual void transform( const Matrix& matrix ) override;
139 : protected:
140 : CADVector position;
141 : CADVector extrusion;
142 : double xAxisAng;
143 : };
144 :
145 : /**
146 : * @brief Geometry class which represents a simple Line
147 : */
148 : class OCAD_EXTERN CADLine : public CADGeometry
149 : {
150 : public:
151 : CADLine();
152 : CADLine( const CADPoint3D& startIn, const CADPoint3D& endIn );
153 :
154 : CADPoint3D getStart() const;
155 : void setStart( const CADPoint3D& value );
156 :
157 : CADPoint3D getEnd() const;
158 : void setEnd( const CADPoint3D& value );
159 :
160 : virtual void print() const override;
161 : virtual void transform( const Matrix& matrix ) override;
162 : protected:
163 : CADPoint3D start;
164 : CADPoint3D end;
165 : };
166 :
167 : /**
168 : * @brief Geometry class which represents Polyline 3D
169 : */
170 : class OCAD_EXTERN CADPolyline3D : public CADGeometry
171 : {
172 : public:
173 : CADPolyline3D();
174 :
175 : void addVertex( const CADVector& vertex );
176 : size_t getVertexCount() const;
177 : CADVector& getVertex( size_t index );
178 :
179 : virtual void print() const override;
180 : virtual void transform( const Matrix& matrix ) override;
181 : protected:
182 : std::vector<CADVector> vertices;
183 : };
184 :
185 : /**
186 : * @brief Geometry class which represents LWPolyline
187 : */
188 :
189 : class OCAD_EXTERN CADLWPolyline : public CADPolyline3D
190 : {
191 : public:
192 : CADLWPolyline();
193 :
194 : double getConstWidth() const;
195 : void setConstWidth( double value );
196 :
197 : double getElevation() const;
198 : void setElevation( double value );
199 :
200 : CADVector getVectExtrusion() const;
201 : void setVectExtrusion( const CADVector& value );
202 :
203 : std::vector<std::pair<double, double> > getWidths() const;
204 : void setWidths( const std::vector<std::pair<double, double> >& value );
205 :
206 : std::vector<double> getBulges() const;
207 : void setBulges( const std::vector<double>& value );
208 :
209 : bool isClosed() const;
210 : void setClosed( bool state );
211 :
212 : virtual void print() const override;
213 : protected:
214 : bool bClosed;
215 : double constWidth;
216 : double elevation;
217 : CADVector vectExtrusion;
218 : std::vector<double> bulges;
219 : std::vector<std::pair<double, double> > widths; // Start & end.
220 : };
221 :
222 : /**
223 : * @brief Geometry class which represents Circle
224 : */
225 : class OCAD_EXTERN CADCircle : public CADPoint3D
226 : {
227 : public:
228 : CADCircle();
229 :
230 : double getRadius() const;
231 : void setRadius( double value );
232 :
233 : virtual void print() const override;
234 : protected:
235 : double radius;
236 : };
237 :
238 : /**
239 : * @brief Geometry class which represents Text
240 : */
241 : class OCAD_EXTERN CADText : public CADPoint3D
242 : {
243 : public:
244 : CADText();
245 :
246 : std::string getTextValue() const;
247 : void setTextValue( const std::string& value );
248 :
249 : double getHeight() const;
250 : void setHeight( double value );
251 :
252 : double getRotationAngle() const;
253 : void setRotationAngle( double value );
254 :
255 : double getObliqueAngle() const;
256 : void setObliqueAngle( double value );
257 :
258 : virtual void print() const override;
259 : protected:
260 : double obliqueAngle;
261 : double rotationAngle;
262 : double height;
263 : std::string textValue;
264 : };
265 :
266 : /**
267 : * @brief Geometry class which represents Arc
268 : */
269 : class OCAD_EXTERN CADArc : public CADCircle
270 : {
271 : public:
272 : CADArc();
273 :
274 : double getStartingAngle() const;
275 : void setStartingAngle( double value );
276 :
277 : double getEndingAngle() const;
278 : void setEndingAngle( double value );
279 :
280 : virtual void print() const override;
281 : protected:
282 : double startingAngle;
283 : double endingAngle;
284 : };
285 :
286 : /**
287 : * @brief Geometry class which represents Ellipse
288 : */
289 : class OCAD_EXTERN CADEllipse : public CADArc
290 : {
291 : public:
292 : CADEllipse();
293 :
294 : double getAxisRatio() const;
295 : void setAxisRatio( double value );
296 :
297 : CADVector getSMAxis();
298 : void setSMAxis( const CADVector& vectSMA );
299 :
300 : virtual void print() const override;
301 : protected:
302 : CADVector vectSMAxis;
303 : double axisRatio;
304 : };
305 :
306 : /**
307 : * @brief Geometry class which represents Spline
308 : */
309 : class OCAD_EXTERN CADSpline : public CADGeometry
310 : {
311 : public:
312 : CADSpline();
313 :
314 : long getScenario() const;
315 : void setScenario( long value );
316 :
317 : bool isRational() const;
318 : void setRational( bool value );
319 :
320 : bool isClosed() const;
321 : void setClosed( bool value );
322 :
323 : std::vector<CADVector>& getControlPoints();
324 : std::vector<CADVector>& getFitPoints();
325 : std::vector<double> & getControlPointsWeights();
326 :
327 : void addControlPointsWeight( double p_weight );
328 : void addControlPoint( const CADVector& point );
329 : void addFitPoint( const CADVector& point );
330 :
331 : bool getWeight() const;
332 : void setWeight( bool value );
333 :
334 : double getFitTolerance() const;
335 : void setFitTolerance( double value );
336 :
337 : long getDegree() const;
338 : void setDegree( long value );
339 :
340 : virtual void print() const override;
341 : virtual void transform( const Matrix& matrix ) override;
342 : protected:
343 : long scenario;
344 : bool rational;
345 : bool closed;
346 : bool weight;
347 : double fitTolerance;
348 : long degree;
349 :
350 : std::vector<double> ctrlPointsWeight;
351 : std::vector<CADVector> avertCtrlPoints;
352 : std::vector<CADVector> averFitPoints;
353 : };
354 :
355 : /**
356 : * @brief Geometry class which represents Solid
357 : */
358 : class OCAD_EXTERN CADSolid : public CADPoint3D
359 : {
360 : public:
361 : CADSolid();
362 :
363 : double getElevation() const;
364 : void setElevation( double value );
365 : void addCorner( const CADVector& corner );
366 : std::vector<CADVector> getCorners();
367 :
368 : virtual void print() const override;
369 : virtual void transform( const Matrix& matrix ) override;
370 : protected:
371 : double elevation;
372 : std::vector<CADVector> avertCorners;
373 : };
374 :
375 : /**
376 : * @brief Geometry class which represents Ray
377 : */
378 : class OCAD_EXTERN CADRay : public CADPoint3D
379 : {
380 : public:
381 : CADRay();
382 :
383 : CADVector getVectVector() const;
384 : void setVectVector( const CADVector& value );
385 :
386 : virtual void print() const override;
387 : };
388 :
389 : /**
390 : * @brief Geometry class which represents Hatch
391 : */
392 0 : class OCAD_EXTERN CADHatch : public CADGeometry
393 : {
394 : public:
395 : CADHatch();
396 : ~CADHatch() override;
397 : };
398 :
399 : /**
400 : * @brief Geometry class which represents Image (Raster Image)
401 : */
402 : class OCAD_EXTERN CADImage : public CADGeometry
403 : {
404 : public:
405 : /**
406 : * @brief enum which describes in which units Image resolutions is present
407 : */
408 : enum ResolutionUnit
409 : {
410 : NONE = 0, CENTIMETER = 2, INCH = 5
411 : };
412 :
413 0 : static bool IsValidResolutionUnit(int nVal)
414 : {
415 0 : return nVal == ResolutionUnit::NONE ||
416 0 : nVal == ResolutionUnit::CENTIMETER ||
417 0 : nVal == ResolutionUnit::INCH;
418 : }
419 :
420 : CADImage();
421 :
422 : CADVector getVertInsertionPoint() const;
423 : void setVertInsertionPoint( const CADVector& value );
424 :
425 : CADVector getImageSize() const;
426 : void setImageSize( const CADVector& value );
427 :
428 : CADVector getImageSizeInPx() const;
429 : void setImageSizeInPx( const CADVector& value );
430 :
431 : CADVector getPixelSizeInACADUnits() const;
432 : void setPixelSizeInACADUnits( const CADVector& value );
433 :
434 : short getClippingBoundaryType() const;
435 : void setClippingBoundaryType( short value );
436 :
437 : enum ResolutionUnit getResolutionUnits() const;
438 : void setResolutionUnits( enum ResolutionUnit value );
439 :
440 : std::string getFilePath() const;
441 : void setFilePath( const std::string& value );
442 :
443 : void setOptions( bool transparency, bool clip, unsigned char brightness,
444 : unsigned char contrast );
445 :
446 : void addClippingPoint( const CADVector& pt );
447 :
448 : virtual void print() const override;
449 : virtual void transform( const Matrix& matrix ) override;
450 : protected:
451 : CADVector vertInsertionPoint;
452 : //CADVector vectUDirection;
453 : //CADVector vectVDirection;
454 : CADVector imageSize;
455 : //bool bShow;
456 : //bool bShowWhenNotAlignedWithScreen;
457 : //bool bUseClippingBoundary;
458 : bool bTransparency;
459 : bool bClipping;
460 : unsigned char dBrightness;
461 : unsigned char dContrast;
462 : //char dFade;
463 :
464 : CADVector imageSizeInPx;
465 : std::string filePath;
466 : //bool bIsLoaded;
467 : enum ResolutionUnit resolutionUnits;
468 : //unsigned char resolutionUnit; // 0 == none, 2 == centimeters, 5 == inches;
469 : CADVector pixelSizeInACADUnits;
470 :
471 : short clippingBoundaryType; // 1 == rect, 2 == polygon
472 : std::vector<CADVector> avertClippingPolygon;
473 : };
474 :
475 : /**
476 : * @brief Geometry class which represents MText
477 : */
478 : class OCAD_EXTERN CADMText : public CADText
479 : {
480 : public:
481 : CADMText();
482 :
483 : double getRectWidth() const;
484 : void setRectWidth( double value );
485 :
486 : double getExtents() const;
487 : void setExtents( double value );
488 :
489 : double getExtentsWidth() const;
490 : void setExtentsWidth( double value );
491 :
492 : virtual void print() const override;
493 : protected:
494 : double rectWidth;
495 : double extents;
496 : double extentsWidth;
497 : // TODO: do we need this here?
498 : //short dDrawingDir;
499 : //short dLineSpacingStyle;
500 : //short dLineSpacingFactor;
501 : //long dBackgroundFlags; // R2004+
502 : //long dBackgroundScaleFactor;
503 : //short dBackgroundColor;
504 : //long dBackgroundTransparency;
505 : };
506 :
507 : /**
508 : * @brief Geometry class which represents 3DFace
509 : */
510 : class OCAD_EXTERN CADFace3D : public CADGeometry
511 : {
512 : public:
513 : CADFace3D();
514 :
515 : void addCorner( const CADVector& corner );
516 : CADVector getCorner( size_t index );
517 :
518 : short getInvisFlags() const;
519 : void setInvisFlags( short value );
520 :
521 : virtual void print() const override;
522 : virtual void transform( const Matrix& matrix ) override;
523 : protected:
524 : std::vector<CADVector> avertCorners;
525 : short invisFlags;
526 : };
527 :
528 : /**
529 : * @brief Geometry class which represents Polyline (PFace)
530 : */
531 : class OCAD_EXTERN CADPolylinePFace : public CADGeometry
532 : {
533 : public:
534 : CADPolylinePFace();
535 :
536 : void addVertex( const CADVector& vertex );
537 :
538 : virtual void print() const override;
539 : virtual void transform( const Matrix& matrix ) override;
540 : protected:
541 : std::vector<CADVector> vertices;
542 : };
543 :
544 : /**
545 : * @brief Geometry class which represents XLine
546 : */
547 : class OCAD_EXTERN CADXLine : public CADRay
548 : {
549 : public:
550 : CADXLine();
551 :
552 : virtual void print() const override;
553 : };
554 :
555 : /**
556 : * @brief Geometry class which represents MLine
557 : */
558 : class OCAD_EXTERN CADMLine : public CADPoint3D
559 : {
560 : public:
561 : CADMLine();
562 :
563 : double getScale() const;
564 : void setScale( double value );
565 :
566 : bool isOpened() const;
567 : void setOpened( bool value );
568 :
569 : void addVertex( const CADVector& vertex );
570 :
571 : virtual void print() const override;
572 : virtual void transform( const Matrix& matrix ) override;
573 : protected:
574 : double scale;
575 : //char dJust;
576 : bool opened; // 1 == open, 0 == close
577 : // TODO: do we need more properties here?
578 : std::vector<CADVector> avertVertices;
579 : };
580 :
581 : /**
582 : * @brief Geometry class which represents Attribute
583 : */
584 : class OCAD_EXTERN CADAttrib : public CADText
585 : {
586 : public:
587 : CADAttrib();
588 :
589 : double getElevation() const;
590 : void setElevation( double );
591 :
592 : std::string getTag() const;
593 : void setTag( const std::string& );
594 :
595 : CADVector getAlignmentPoint() const;
596 : void setAlignmentPoint( const CADVector& );
597 :
598 : bool isPositionLocked() const;
599 : void setPositionLocked( bool );
600 :
601 : virtual void print() const override;
602 : virtual void transform( const Matrix& matrix ) override;
603 : protected:
604 : CADVector vertAlignmentPoint;
605 : double dfElevation;
606 : std::string sTag;
607 : bool bLockPosition;
608 : };
609 :
610 : /**
611 : * @brief Geometry class which represents Attribute definition
612 : */
613 : class OCAD_EXTERN CADAttdef : public CADAttrib
614 : {
615 : public:
616 : CADAttdef();
617 :
618 : std::string getPrompt() const;
619 : void setPrompt( const std::string& );
620 :
621 : virtual void print() const override;
622 : protected:
623 : std::string sPrompt;
624 : };
625 :
626 : //class EXTERN LineType
627 : //{
628 : //public:
629 : // std::string sEntryName;
630 : // std::string sDescription;
631 : // double dfPatternLen;
632 : // char dAlignment;
633 : // char nNumDashes;
634 : // struct Dash
635 : // {
636 : // double dfLength;
637 : // short dComplexShapecode;
638 : // double dfXOffset;
639 : // double dfYOffset;
640 : // double dfScale;
641 : // double dfRotation;
642 : // short dShapeflag;
643 : // };
644 : // std::vector < char > abyTextArea; // TODO: what is it?
645 : // std::vector < CADHandle > hShapefiles; // TODO: one for each dash?
646 : //};
647 :
648 : //class EXTERN Block
649 : //{
650 : //public:
651 : // Block(CADFile * pCADFile)
652 : // {
653 : // pstCADFile_m = pCADFile;
654 : // }
655 : //
656 : // std::string sBlockName;
657 : //
658 : // CADFile * pstCADFile_m;
659 : //
660 : // std::vector < std::pair < long long, short > > astAttachedGeometries;
661 : //};
662 :
663 :
664 : #endif // CADGEOMETRIES_H
|