libopencad
cadgeometry.h
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 
32 #ifndef CADGEOMETRIES_H
33 #define CADGEOMETRIES_H
34 
35 #include "cadobjects.h"
36 #include "cadcolors.h"
37 
38 using namespace std;
39 
40 class CADAttrib;
41 class CADAttdef;
42 
47 {
48  public:
49  CADGeometry();
50  virtual ~CADGeometry();
55  {
56  UNDEFINED = 0,
57  POINT,
58  CIRCLE,
59  LWPOLYLINE,
60  ELLIPSE,
61  LINE,
62  POLYLINE3D,
63  TEXT,
64  ARC,
65  SPLINE,
66  SOLID,
67  RAY,
68  HATCH, // NOT IMPLEMENTED
69  IMAGE,
70  MTEXT,
71  MLINE,
72  XLINE,
73  FACE3D,
74  POLYLINE_PFACE,
75  ATTRIB,
76  ATTDEF
77  };
78 
79  enum GeometryType getType() const;
80  double getThickness() const;
81  void setThickness(double thicknes);
82  RGBColor getColor() const;
83  void setColor(int ACIColorIndex);// TODO: in 2004+ ACI is not the only way to set the color.
84 
85  virtual void print () const = 0;
86 
87  void addAttribute( CADAttdef* );
88  void addAttribute( CADAttrib* );
89  map< string, CADAttdef> getAttributes();
90 protected:
91  enum GeometryType geometryType;
92  double thickness;
93  RGBColor geometry_color;
94  map< string, CADAttdef> mapstAttributes;
95 };
96 
100 class CADPoint3D : public CADGeometry
101 {
102 public:
103  CADPoint3D ();
104  CADPoint3D (const CADVector &positionIn, double thicknessIn);
105  CADVector getPosition() const;
106  void setPosition(const CADVector &value);
107 
108  CADVector getExtrusion() const;
109  void setExtrusion(const CADVector &value);
110 
111  double getXAxisAng() const;
112  void setXAxisAng(double value);
113 
114  virtual void print () const override;
115 protected:
116  CADVector position;
117  CADVector extrusion;
118  double xAxisAng;
119 };
120 
124 class CADLine : public CADGeometry
125 {
126 public:
127  CADLine();
128  CADLine(const CADPoint3D& startIn, const CADPoint3D& endIn);
129  CADPoint3D getStart() const;
130  void setStart(const CADPoint3D &value);
131 
132  CADPoint3D getEnd() const;
133  void setEnd(const CADPoint3D &value);
134 
135  virtual void print () const override;
136 
137 protected:
138  CADPoint3D start;
139  CADPoint3D end;
140 };
141 
142 
147 {
148 public:
149  CADPolyline3D();
150  void addVertex(const CADVector& vertex);
151  size_t getVertexCount() const;
152  CADVector& getVertex(size_t index);
153  virtual void print () const override;
154 protected:
155  vector<CADVector> vertexes;
156 };
157 
163 {
164 public:
165  CADLWPolyline ();
166  virtual void print () const override;
167  double getConstWidth() const;
168  void setConstWidth(double value);
169 
170  double getElevation() const;
171  void setElevation(double value);
172 
173  CADVector getVectExtrusion() const;
174  void setVectExtrusion(const CADVector &value);
175 
176  vector<pair<double, double> > getWidths() const;
177  void setWidths(const vector<pair<double, double> > &value);
178 
179 protected:
180  double constWidth;
181  double elevation;
182  CADVector vectExtrusion;
183  vector< pair< double, double > > widths; // start, end.
184 };
185 
189 class CADCircle : public CADPoint3D
190 {
191 public:
192  CADCircle ();
193 
194  double getRadius() const;
195  void setRadius(double value);
196  virtual void print () const override;
197 
198 protected:
199  double radius;
200 };
201 
205 class CADText : public CADPoint3D
206 {
207 public:
208  CADText();
209  string getTextValue() const;
210  void setTextValue(const string &value);
211 
212  double getHeight() const;
213  void setHeight(double value);
214 
215  double getRotationAngle() const;
216  void setRotationAngle(double value);
217 
218  double getObliqueAngle() const;
219  void setObliqueAngle(double value);
220  virtual void print () const override;
221 
222 protected:
223  double obliqueAngle;
224  double rotationAngle;
225  double height;
226  string textValue;
227 };
228 
232 class CADArc : public CADCircle
233 {
234 public:
235  CADArc();
236 
237  double getStartingAngle() const;
238  void setStartingAngle(double value);
239 
240  double getEndingAngle() const;
241  void setEndingAngle(double value);
242  virtual void print () const override;
243 
244 protected:
245  double startingAngle;
246  double endingAngle;
247 };
248 
252 class CADEllipse : public CADArc
253 {
254 public:
255  CADEllipse();
256  double getAxisRatio() const;
257  void setAxisRatio(double value);
258  virtual void print () const override;
259 
260 protected:
261  double axisRatio;
262 };
263 
267 class CADSpline : public CADGeometry
268 {
269 public:
270  CADSpline();
271  virtual void print () const override;
272  long getScenario() const;
273  void setScenario(long value);
274 
275  bool getRational() const;
276  void setRational(bool value);
277 
278  bool getClosed() const;
279  void setClosed(bool value);
280 
281  void addControlPointsWeight(double weight);
282  void addControlPoint(const CADVector& point);
283  void addFitPoint(const CADVector& point);
284  bool getWeight() const;
285  void setWeight(bool value);
286 
287  double getFitTollerance() const;
288  void setFitTollerance(double value);
289 
290 protected:
291  long scenario;
292  bool rational;
293  bool closed;
294  bool weight;
295  double fitTollerance;
296 
297  std::vector < double > ctrlPointsWeight;
298  std::vector < CADVector > avertCtrlPoints;
299  std::vector < CADVector > averFitPoints;
300 };
301 
305 class CADSolid : public CADPoint3D
306 {
307 public:
308  CADSolid();
309  virtual void print () const override;
310  double getElevation() const;
311  void setElevation(double value);
312  void addAverCorner(const CADVector& corner);
313 protected:
314  double elevation;
315  vector < CADVector > avertCorners;
316 };
317 
321 class CADRay : public CADPoint3D
322 {
323 public:
324  CADRay();
325  CADVector getVectVector() const;
326  void setVectVector(const CADVector &value);
327  virtual void print () const override;
328 };
329 
333 class CADHatch : public CADGeometry
334 {
335 public:
336  CADHatch();
337 };
338 
342 class CADImage : public CADGeometry
343 {
344 public:
345  CADImage();
346  CADVector getVertInsertionPoint() const;
347  void setVertInsertionPoint(const CADVector &value);
348 
349  CADVector getImageSize() const;
350  void setImageSize(const CADVector &value);
351 
352 
353  CADVector getImageSizeInPx() const;
354  void setImageSizeInPx(const CADVector &value);
355 
356  CADVector getPixelSizeInACADUnits() const;
357  void setPixelSizeInACADUnits(const CADVector &value);
358 
359  short getClippingBoundaryType() const;
360  void setClippingBoundaryType(short value);
361 
362  unsigned char getResolutionUnits() const;
363  void setResolutionUnits(unsigned char value);
364 
365  string getFilePath() const;
366  void setFilePath(const string &value);
367 
368  void setOptions(bool transparency, bool clip,
369  unsigned char brightness, unsigned char contrast);
370  virtual void print () const override;
371  void addClippingPoint(const CADVector &pt);
372 protected:
373  CADVector vertInsertionPoint;
374  //CADVector vectUDirection;
375  //CADVector vectVDirection;
376  CADVector imageSize;
377  //bool bShow;
378  //bool bShowWhenNotAlignedWithScreen;
379  //bool bUseClippingBoundary;
380  bool bTransparency;
381  bool bClipping;
382  unsigned char dBrightness;
383  unsigned char dContrast;
384  //char dFade;
385 
386  CADVector imageSizeInPx;
387  string filePath;
388  //bool bIsLoaded;
389  unsigned char resolutionUnits; // 0 == none, 2 == centimeters, 5 == inches;
390  CADVector pixelSizeInACADUnits;
391 
392  short clippingBoundaryType; // 1 == rect, 2 == polygon
393  vector < CADVector > avertClippingPolygon;
394 };
395 
399 class CADMText : public CADText
400 {
401 public:
402  CADMText();
403 
404  double getRectWidth() const;
405  void setRectWidth(double value);
406 
407  double getExtents() const;
408  void setExtents(double value);
409 
410  double getExtentsWidth() const;
411  void setExtentsWidth(double value);
412 
413  virtual void print () const override;
414 
415 protected:
416  double rectWidth;
417  double extents;
418  double extentsWidth;
419  // TODO: do we need this here?
420  //short dDrawingDir;
421  //short dLineSpacingStyle;
422  //short dLineSpacingFactor;
423  //long dBackgroundFlags; // R2004+
424  //long dBackgroundScaleFactor;
425  //short dBackgroundColor;
426  //long dBackgroundTransparency;
427 };
428 
432 class CADFace3D : public CADGeometry
433 {
434 public:
435  CADFace3D();
436  void addCorner(const CADVector &corner);
437  CADVector getCorner( size_t index );
438  virtual void print () const override;
439 
440  short getInvisFlags() const;
441  void setInvisFlags(short value);
442 
443 protected:
444  vector < CADVector > avertCorners;
445  short invisFlags;
446 };
447 
452 {
453 public:
455  virtual void print () const override;
456  void addVertex(const CADVector& vertex);
457 protected:
458  vector < CADVector > vertexes;
459 };
460 
464 class CADXLine : public CADRay
465 {
466 public:
467  CADXLine();
468  virtual void print () const override;
469 };
470 
474 class CADMLine : public CADPoint3D
475 {
476 public:
477  CADMLine();
478  virtual void print () const override;
479  double getScale() const;
480  void setScale(double value);
481 
482  bool getOpened() const;
483  void setOpened(bool value);
484 
485  void addVertex(const CADVector& vertex);
486 protected:
487  double scale;
488  //char dJust;
489  bool opened; // 1 == open, 0 == close
490  // TODO: do we need more properties here?
491  vector < CADVector > avertVertexes;
492 };
493 
497 class CADAttrib : public CADText
498 {
499 public:
500  CADAttrib();
501  virtual void print () const override;
502 
503  double getElevation() const;
504  void setElevation( double );
505 
506  string getTag() const;
507  void setTag( const string& );
508 
509  CADVector getAlignmentPoint() const;
510  void setAlignmentPoint( const CADVector& );
511 
512  bool isPositionLocked() const;
513  void setPositionLocked( bool );
514 protected:
515  CADVector vertAlignmentPoint;
516  double dfElevation;
517  string sTag;
518  bool bLockPosition;
519 };
520 
524 class CADAttdef : public CADAttrib
525 {
526 public:
527  CADAttdef();
528  virtual void print () const override;
529 
530  string getPrompt() const;
531  void setPrompt( const string& );
532 
533 protected:
534  string sPrompt;
535 };
536 
537 
538 //class EXTERN LineType
539 //{
540 //public:
541 // std::string sEntryName;
542 // std::string sDescription;
543 // double dfPatternLen;
544 // char dAlignment;
545 // char nNumDashes;
546 // struct Dash
547 // {
548 // double dfLength;
549 // short dComplexShapecode;
550 // double dfXOffset;
551 // double dfYOffset;
552 // double dfScale;
553 // double dfRotation;
554 // short dShapeflag;
555 // };
556 // std::vector < char > abyTextArea; // TODO: what is it?
557 // std::vector < CADHandle > hShapefiles; // TODO: one for each dash?
558 //};
559 
560 //class EXTERN Block
561 //{
562 //public:
563 // Block(CADFile * pCADFile)
564 // {
565 // pstCADFile_m = pCADFile;
566 // }
567 //
568 // std::string sBlockName;
569 //
570 // CADFile * pstCADFile_m;
571 //
572 // std::vector < std::pair < long long, short > > astAttachedGeometries;
573 //};
574 
575 
576 #endif // CADGEOMETRIES_H
Geometry class which represents Arc.
Definition: cadgeometry.h:232
Geometry class which represents Hatch.
Definition: cadgeometry.h:333
Base CAD geometry class.
Definition: cadgeometry.h:46
Geometry class which represents Circle.
Definition: cadgeometry.h:189
Definition: cadobjects.h:39
GeometryType
The CAD geometry types enum.
Definition: cadgeometry.h:54
Geometry class which represents Image (Raster Image)
Definition: cadgeometry.h:342
Geometry class which represents Spline.
Definition: cadgeometry.h:267
Definition: cadcolors.h:34
Geometry class which represents MText.
Definition: cadgeometry.h:399
Geometry class which represents Ray.
Definition: cadgeometry.h:321
Geometry class which represents Polyline (PFace)
Definition: cadgeometry.h:451
Geometry class which represents LWPolyline.
Definition: cadgeometry.h:162
Geometry class which represents a simple Line.
Definition: cadgeometry.h:124
Geometry class which represents Attribute.
Definition: cadgeometry.h:497
Geometry class which represents Ellipse.
Definition: cadgeometry.h:252
Geometry class which a single Point.
Definition: cadgeometry.h:100
Geometry class which represents MLine.
Definition: cadgeometry.h:474
Geometry class which represents Attribute definition.
Definition: cadgeometry.h:524
Geometry class which represents Polyline 3D.
Definition: cadgeometry.h:146
Geometry class which represents Text.
Definition: cadgeometry.h:205
Geometry class which represents XLine.
Definition: cadgeometry.h:464
Geometry class which represents 3DFace.
Definition: cadgeometry.h:432
Geometry class which represents Solid.
Definition: cadgeometry.h:305