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