You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1342 lines
41 KiB

  1. /******************************************************************************
  2. ** libDXFrw - Library to read/write DXF files (ascii & binary) **
  3. ** **
  4. ** Copyright (C) 2011 Rallaz, rallazz@gmail.com **
  5. ** **
  6. ** This library is free software, licensed under the terms of the GNU **
  7. ** General Public License as published by the Free Software Foundation, **
  8. ** either version 2 of the License, or (at your option) any later version. **
  9. ** You should have received a copy of the GNU General Public License **
  10. ** along with this program. If not, see <http://www.gnu.org/licenses/>. **
  11. ******************************************************************************/
  12. #ifndef DRW_ENTITIES_H
  13. #define DRW_ENTITIES_H
  14. #include <string>
  15. #include <vector>
  16. #include "drw_base.h"
  17. class dxfReader;
  18. class DRW_Polyline;
  19. namespace DRW {
  20. // ! Entity's type.
  21. enum ETYPE
  22. {
  23. POINT,
  24. LINE,
  25. CIRCLE,
  26. ARC,
  27. ELLIPSE,
  28. TRACE,
  29. SOLID,
  30. BLOCK,
  31. INSERT,
  32. LWPOLYLINE,
  33. POLYLINE,
  34. VERTEX,
  35. SPLINE,
  36. HATCH,
  37. TEXT,
  38. MTEXT,
  39. E3DFACE,
  40. IMAGE,
  41. LEADER,
  42. DIMENSION,
  43. DIMALIGNED,
  44. DIMLINEAR,
  45. DIMRADIAL,
  46. DIMDIAMETRIC,
  47. DIMANGULAR,
  48. DIMANGULAR3P,
  49. DIMORDINATE,
  50. // OVERLAYBOX,
  51. // CONSTRUCTIONLINE,
  52. RAY,
  53. XLINE,
  54. VIEWPORT,
  55. UNKNOWN
  56. };
  57. }
  58. // ! Base class for entities
  59. /*!
  60. * Base class for entities
  61. * @author Rallaz
  62. */
  63. class DRW_Entity
  64. {
  65. public:
  66. // initializes default values
  67. DRW_Entity()
  68. {
  69. eType = DRW::UNKNOWN;
  70. lineType = "BYLAYER";
  71. color = 256; // default BYLAYER (256)
  72. ltypeScale = 1.0;
  73. visible = true;
  74. layer = "0";
  75. lWeight = DRW_LW_Conv::widthByLayer; // default BYLAYER (dxf -1, dwg 29)
  76. handleBlock = space = 0; // default ModelSpace (0) & handleBlock = no handle (0)
  77. haveExtrusion = false;
  78. color24 = -1; // default -1 not set
  79. handle = 0;
  80. curr = NULL;
  81. }
  82. virtual ~DRW_Entity()
  83. {
  84. for( std::vector<DRW_Variant*>::iterator it = extData.begin(); it!=extData.end(); ++it )
  85. delete *it;
  86. extData.clear();
  87. }
  88. DRW_Entity( const DRW_Entity& d )
  89. {
  90. eType = d.eType;
  91. handle = d.handle;
  92. handleBlock = d.handleBlock;
  93. layer = d.layer;
  94. lineType = d.lineType;
  95. color = d.color;
  96. color24 = d.color24;
  97. colorName = d.colorName;
  98. ltypeScale = d.ltypeScale;
  99. visible = d.visible;
  100. lWeight = d.lWeight;
  101. space = d.space;
  102. haveExtrusion = d.haveExtrusion;
  103. curr = NULL;
  104. }
  105. virtual void applyExtrusion() = 0;
  106. protected:
  107. void parseCode( int code, dxfReader* reader );
  108. void calculateAxis( DRW_Coord extPoint );
  109. void extrudePoint( DRW_Coord extPoint, DRW_Coord* point );
  110. public:
  111. enum DRW::ETYPE eType; /*!< enum: entity type, code 0 */
  112. int handle; /*!< entity identifier, code 5 */
  113. int handleBlock; /*!< Soft-pointer ID/handle to owner BLOCK_RECORD object, code 330 */
  114. UTF8STRING layer; /*!< layer name, code 8 */
  115. UTF8STRING lineType; /*!< line type, code 6 */
  116. int color; /*!< entity color, code 62 */
  117. enum DRW_LW_Conv::lineWidth lWeight; /*!< entity lineweight, code 370 */
  118. double ltypeScale; /*!< linetype scale, code 48 */
  119. bool visible; /*!< entity visibility, code 60 */
  120. int color24; /*!< 24-bit color, code 420 */
  121. std::string colorName; /*!< color name, code 430 */
  122. int space; /*!< space indicator 0 = model, 1 paper, code 67*/
  123. bool haveExtrusion; /*!< set to true if the entity have extrusion*/
  124. std::vector<DRW_Variant*> extData; /*!< FIFO list of extended data, codes 1000 to 1071*/
  125. private:
  126. DRW_Coord extAxisX;
  127. DRW_Coord extAxisY;
  128. DRW_Variant* curr;
  129. };
  130. // ! Class to handle point entity
  131. /*!
  132. * Class to handle point entity
  133. * @author Rallaz
  134. */
  135. class DRW_Point : public DRW_Entity
  136. {
  137. public:
  138. DRW_Point()
  139. {
  140. eType = DRW::POINT;
  141. basePoint.z = extPoint.x = extPoint.y = 0;
  142. extPoint.z = 1;
  143. thickness = 0;
  144. }
  145. virtual void applyExtrusion() override {}
  146. void parseCode( int code, dxfReader* reader );
  147. public:
  148. DRW_Coord basePoint; /*!< base point, code 10, 20 & 30 */
  149. double thickness; /*!< thickness, code 39 */
  150. DRW_Coord extPoint; /*!< Dir extrusion normal vector, code 210, 220 & 230 */
  151. };
  152. // ! Class to handle line entity
  153. /*!
  154. * Class to handle line entity
  155. * @author Rallaz
  156. */
  157. class DRW_Line : public DRW_Point
  158. {
  159. public:
  160. DRW_Line()
  161. {
  162. eType = DRW::LINE;
  163. secPoint.z = 0;
  164. }
  165. virtual void applyExtrusion() override {}
  166. void parseCode( int code, dxfReader* reader );
  167. public:
  168. DRW_Coord secPoint; /*!< second point, code 11, 21 & 31 */
  169. };
  170. // ! Class to handle ray entity
  171. /*!
  172. * Class to handle ray entity
  173. * @author Rallaz
  174. */
  175. class DRW_Ray : public DRW_Line
  176. {
  177. public:
  178. DRW_Ray()
  179. {
  180. eType = DRW::RAY;
  181. }
  182. };
  183. // ! Class to handle xline entity
  184. /*!
  185. * Class to handle xline entity
  186. * @author Rallaz
  187. */
  188. class DRW_Xline : public DRW_Line
  189. {
  190. public:
  191. DRW_Xline()
  192. {
  193. eType = DRW::XLINE;
  194. }
  195. };
  196. // ! Class to handle circle entity
  197. /*!
  198. * Class to handle circle entity
  199. * @author Rallaz
  200. */
  201. class DRW_Circle : public DRW_Point
  202. {
  203. public:
  204. DRW_Circle()
  205. {
  206. eType = DRW::CIRCLE;
  207. radious = 0.0;
  208. }
  209. virtual void applyExtrusion() override;
  210. void parseCode( int code, dxfReader* reader );
  211. public:
  212. double radious; /*!< radius, code 40 */
  213. };
  214. // ! Class to handle arc entity
  215. /*!
  216. * Class to handle arc entity
  217. * @author Rallaz
  218. */
  219. class DRW_Arc : public DRW_Circle
  220. {
  221. public:
  222. DRW_Arc()
  223. {
  224. eType = DRW::ARC;
  225. isccw = 1;
  226. staangle = 0.0;
  227. endangle = 0.0;
  228. }
  229. virtual void applyExtrusion() override;
  230. void parseCode( int code, dxfReader* reader );
  231. public:
  232. double staangle; /*!< start angle, code 50 in radians*/
  233. double endangle; /*!< end angle, code 51 in radians */
  234. int isccw; /*!< is counter clockwise arc?, only used in hatch, code 73 */
  235. };
  236. // ! Class to handle ellipse entity
  237. /*!
  238. * Class to handle ellipse and elliptic arc entity
  239. * Note: start/end parameter are in radians for ellipse entity but
  240. * for hatch boundary are in degrees
  241. * @author Rallaz
  242. */
  243. class DRW_Ellipse : public DRW_Line
  244. {
  245. public:
  246. DRW_Ellipse()
  247. {
  248. eType = DRW::ELLIPSE;
  249. isccw = 1;
  250. ratio = 1.0;
  251. staparam = endparam = 0;
  252. }
  253. void parseCode( int code, dxfReader* reader );
  254. void toPolyline( DRW_Polyline* pol, int parts = 128 );
  255. virtual void applyExtrusion() override;
  256. void correctAxis();
  257. public:
  258. double ratio; /*!< ratio, code 40 */
  259. double staparam; /*!< start parameter, code 41, 0.0 for full ellipse*/
  260. double endparam; /*!< end parameter, code 42, 2*PI for full ellipse */
  261. int isccw; /*!< is counter clockwise arc?, only used in hatch, code 73 */
  262. };
  263. // ! Class to handle trace entity
  264. /*!
  265. * Class to handle trace entity
  266. * @author Rallaz
  267. */
  268. class DRW_Trace : public DRW_Line
  269. {
  270. public:
  271. DRW_Trace()
  272. {
  273. eType = DRW::TRACE;
  274. thirdPoint.z = 0;
  275. fourPoint.z = 0;
  276. }
  277. virtual void applyExtrusion() override;
  278. void parseCode( int code, dxfReader* reader );
  279. public:
  280. DRW_Coord thirdPoint; /*!< third point, code 12, 22 & 32 */
  281. DRW_Coord fourPoint; /*!< four point, code 13, 23 & 33 */
  282. };
  283. // ! Class to handle solid entity
  284. /*!
  285. * Class to handle solid entity
  286. * @author Rallaz
  287. */
  288. class DRW_Solid : public DRW_Trace
  289. {
  290. public:
  291. DRW_Solid()
  292. {
  293. eType = DRW::SOLID;
  294. }
  295. void parseCode( int code, dxfReader* reader );
  296. };
  297. // ! Class to handle 3dface entity
  298. /*!
  299. * Class to handle 3dface entity
  300. * @author Rallaz
  301. */
  302. class DRW_3Dface : public DRW_Trace
  303. {
  304. public:
  305. DRW_3Dface()
  306. {
  307. eType = DRW::E3DFACE;
  308. invisibleflag = 0;
  309. }
  310. virtual void applyExtrusion() override {}
  311. void parseCode( int code, dxfReader* reader );
  312. public:
  313. int invisibleflag; /*!< invisible edge flag, code 70 */
  314. };
  315. // ! Class to handle block entries
  316. /*!
  317. * Class to handle block entries
  318. * @author Rallaz
  319. */
  320. class DRW_Block : public DRW_Point
  321. {
  322. public:
  323. DRW_Block()
  324. {
  325. eType = DRW::BLOCK;
  326. layer = "0";
  327. flags = 0;
  328. name = "*U0";
  329. }
  330. virtual void applyExtrusion() override {}
  331. void parseCode( int code, dxfReader* reader );
  332. public:
  333. UTF8STRING name; /*!< block name, code 2 */
  334. int flags; /*!< block type, code 70 */
  335. };
  336. // ! Class to handle insert entries
  337. /*!
  338. * Class to handle insert entries
  339. * @author Rallaz
  340. */
  341. class DRW_Insert : public DRW_Point
  342. {
  343. public:
  344. DRW_Insert()
  345. {
  346. eType = DRW::INSERT;
  347. xscale = 1;
  348. yscale = 1;
  349. zscale = 1;
  350. angle = 0;
  351. colcount = 1;
  352. rowcount = 1;
  353. colspace = 0;
  354. rowspace = 0;
  355. }
  356. virtual void applyExtrusion() override { DRW_Point::applyExtrusion(); }
  357. void parseCode( int code, dxfReader* reader );
  358. public:
  359. UTF8STRING name; /*!< block name, code 2 */
  360. double xscale; /*!< x scale factor, code 41 */
  361. double yscale; /*!< y scale factor, code 42 */
  362. double zscale; /*!< z scale factor, code 43 */
  363. double angle; /*!< rotation angle, code 50 */
  364. int colcount; /*!< column count, code 70 */
  365. int rowcount; /*!< row count, code 71 */
  366. double colspace; /*!< column space, code 44 */
  367. double rowspace; /*!< row space, code 45 */
  368. };
  369. // ! Class to handle lwpolyline entity
  370. /*!
  371. * Class to handle lwpolyline entity
  372. * @author Rallaz
  373. */
  374. class DRW_LWPolyline : public DRW_Entity
  375. {
  376. public:
  377. DRW_LWPolyline()
  378. {
  379. eType = DRW::LWPOLYLINE;
  380. elevation = thickness = width = 0.0;
  381. flags = 0;
  382. extPoint.x = extPoint.y = 0;
  383. extPoint.z = 1;
  384. vertex = NULL;
  385. vertexnum = 0;
  386. }
  387. ~DRW_LWPolyline()
  388. {
  389. while( !vertlist.empty() )
  390. {
  391. vertlist.pop_back();
  392. }
  393. }
  394. virtual void applyExtrusion() override;
  395. void addVertex( DRW_Vertex2D v )
  396. {
  397. DRW_Vertex2D* vert = new DRW_Vertex2D();
  398. vert->x = v.x;
  399. vert->y = v.y;
  400. vert->stawidth = v.stawidth;
  401. vert->endwidth = v.endwidth;
  402. vert->bulge = v.bulge;
  403. vertlist.push_back( vert );
  404. }
  405. DRW_Vertex2D* addVertex()
  406. {
  407. DRW_Vertex2D* vert = new DRW_Vertex2D();
  408. vert->stawidth = 0;
  409. vert->endwidth = 0;
  410. vert->bulge = 0;
  411. vertlist.push_back( vert );
  412. return vert;
  413. }
  414. void parseCode( int code, dxfReader* reader );
  415. public:
  416. int vertexnum; /*!< number of vertex, code 90 */
  417. int flags; /*!< polyline flag, code 70, default 0 */
  418. double width; /*!< constant width, code 43 */
  419. double elevation; /*!< elevation, code 38 */
  420. double thickness; /*!< thickness, code 39 */
  421. DRW_Coord extPoint; /*!< Dir extrusion normal vector, code 210, 220 & 230 */
  422. DRW_Vertex2D* vertex; /*!< current vertex to add data */
  423. std::vector<DRW_Vertex2D*> vertlist; /*!< vertex list */
  424. };
  425. // ! Class to handle insert entries
  426. /*!
  427. * Class to handle insert entries
  428. * @author Rallaz
  429. */
  430. class DRW_Text : public DRW_Line
  431. {
  432. public:
  433. // ! Vertical alignments.
  434. enum VAlign
  435. {
  436. VBaseLine = 0, /*!< Top = 0 */
  437. VBottom, /*!< Bottom = 1 */
  438. VMiddle, /*!< Middle = 2 */
  439. VTop /*!< Top = 3 */
  440. };
  441. // ! Horizontal alignments.
  442. enum HAlign
  443. {
  444. HLeft = 0, /*!< Left = 0 */
  445. HCenter, /*!< Centered = 1 */
  446. HRight, /*!< Right = 2 */
  447. HAligned, /*!< Aligned = 3 (if VAlign==0) */
  448. HMiddle, /*!< middle = 4 (if VAlign==0) */
  449. HFit /*!< fit into point = 5 (if VAlign==0) */
  450. };
  451. DRW_Text()
  452. {
  453. eType = DRW::TEXT;
  454. angle = 0;
  455. widthscale = 1;
  456. oblique = 0;
  457. style = "STANDARD";
  458. textgen = 0;
  459. alignH = HLeft;
  460. alignV = VBaseLine;
  461. height = 0.0;
  462. }
  463. virtual void applyExtrusion() override {}
  464. void parseCode( int code, dxfReader* reader );
  465. public:
  466. double height; /*!< height text, code 40 */
  467. UTF8STRING text; /*!< text string, code 1 */
  468. double angle; /*!< rotation angle in degrees (360), code 50 */
  469. double widthscale; /*!< width factor, code 41 */
  470. double oblique; /*!< oblique angle, code 51 */
  471. UTF8STRING style; /*!< style name, code 7 */
  472. int textgen; /*!< text generation, code 71 */
  473. enum HAlign alignH; /*!< horizontal align, code 72 */
  474. enum VAlign alignV; /*!< vertical align, code 73 */
  475. };
  476. // ! Class to handle insert entries
  477. /*!
  478. * Class to handle insert entries
  479. * @author Rallaz
  480. */
  481. class DRW_MText : public DRW_Text
  482. {
  483. public:
  484. // ! Attachments.
  485. enum Attach
  486. {
  487. TopLeft = 1,
  488. TopCenter,
  489. TopRight,
  490. MiddleLeft,
  491. MiddleCenter,
  492. MiddleRight,
  493. BottomLeft,
  494. BottomCenter,
  495. BottomRight
  496. };
  497. DRW_MText()
  498. {
  499. eType = DRW::MTEXT;
  500. interlin = 1;
  501. alignV = (VAlign) TopLeft;
  502. textgen = 1;
  503. haveXAxis = false; // if true needed to recalculate angle
  504. }
  505. void parseCode( int code, dxfReader* reader );
  506. void updateAngle(); // recalculate angle if 'haveXAxis' is true
  507. public:
  508. double interlin; /*!< width factor, code 44 */
  509. private:
  510. bool haveXAxis;
  511. };
  512. // ! Class to handle vertex
  513. /*!
  514. * Class to handle vertex for polyline entity
  515. * @author Rallaz
  516. */
  517. class DRW_Vertex : public DRW_Point
  518. {
  519. public:
  520. DRW_Vertex()
  521. {
  522. eType = DRW::VERTEX;
  523. stawidth = endwidth = bulge = 0;
  524. vindex1 = vindex2 = vindex3 = vindex4 = 0;
  525. flags = identifier = 0;
  526. tgdir = 0.0;
  527. }
  528. DRW_Vertex( double sx, double sy, double sz, double b )
  529. {
  530. stawidth = endwidth = 0;
  531. vindex1 = vindex2 = vindex3 = vindex4 = 0;
  532. flags = identifier = 0;
  533. basePoint.x = sx;
  534. basePoint.y = sy;
  535. basePoint.z = sz;
  536. bulge = b;
  537. tgdir = 0.0;
  538. }
  539. void parseCode( int code, dxfReader* reader );
  540. public:
  541. double stawidth; /*!< Start width, code 40 */
  542. double endwidth; /*!< End width, code 41 */
  543. double bulge; /*!< bulge, code 42 */
  544. int flags; /*!< vertex flag, code 70, default 0 */
  545. double tgdir; /*!< curve fit tangent direction, code 50 */
  546. int vindex1; /*!< polyface mesh vertex index, code 71, default 0 */
  547. int vindex2; /*!< polyface mesh vertex index, code 72, default 0 */
  548. int vindex3; /*!< polyface mesh vertex index, code 73, default 0 */
  549. int vindex4; /*!< polyface mesh vertex index, code 74, default 0 */
  550. int identifier; /*!< vertex identifier, code 91, default 0 */
  551. };
  552. // ! Class to handle polyline entity
  553. /*!
  554. * Class to handle polyline entity
  555. * @author Rallaz
  556. */
  557. class DRW_Polyline : public DRW_Point
  558. {
  559. public:
  560. DRW_Polyline()
  561. {
  562. eType = DRW::POLYLINE;
  563. defstawidth = defendwidth = 0.0;
  564. basePoint.x = basePoint.y = 0.0;
  565. flags = vertexcount = facecount = 0;
  566. smoothM = smoothN = curvetype = 0;
  567. }
  568. ~DRW_Polyline()
  569. {
  570. while( !vertlist.empty() )
  571. {
  572. vertlist.pop_back();
  573. }
  574. }
  575. void addVertex( const DRW_Vertex& v )
  576. {
  577. DRW_Vertex* vert = new DRW_Vertex();
  578. vert->basePoint.x = v.basePoint.x;
  579. vert->basePoint.y = v.basePoint.y;
  580. vert->basePoint.z = v.basePoint.z;
  581. vert->stawidth = v.stawidth;
  582. vert->endwidth = v.endwidth;
  583. vert->bulge = v.bulge;
  584. vertlist.push_back( vert );
  585. }
  586. void appendVertex( DRW_Vertex* v )
  587. {
  588. vertlist.push_back( v );
  589. }
  590. void parseCode( int code, dxfReader* reader );
  591. public:
  592. int flags; /*!< polyline flag, code 70, default 0 */
  593. double defstawidth; /*!< Start width, code 40, default 0 */
  594. double defendwidth; /*!< End width, code 41, default 0 */
  595. int vertexcount; /*!< polygon mesh M vertex or polyface vertex num, code 71, default 0 */
  596. int facecount; /*!< polygon mesh N vertex or polyface face num, code 72, default 0 */
  597. int smoothM; /*!< smooth surface M density, code 73, default 0 */
  598. int smoothN; /*!< smooth surface M density, code 74, default 0 */
  599. int curvetype; /*!< curves & smooth surface type, code 75, default 0 */
  600. std::vector<DRW_Vertex*> vertlist; /*!< vertex list */
  601. };
  602. // ! Class to handle spline entity
  603. /*!
  604. * Class to handle spline entity
  605. * @author Rallaz
  606. */
  607. class DRW_Spline : public DRW_Entity
  608. {
  609. public:
  610. DRW_Spline()
  611. {
  612. eType = DRW::SPLINE;
  613. flags = nknots = ncontrol = nfit = 0;
  614. ex = ey = 0.0;
  615. ez = 1.0;
  616. tolknot = tolcontrol = tolfit = 0.0000001;
  617. tgsx = tgsy = tgsz = tgex = tgey = tgez = 0.0;
  618. degree = 0;
  619. controlpoint = 0;
  620. fitpoint = 0;
  621. }
  622. ~DRW_Spline()
  623. {
  624. while( !controllist.empty() )
  625. {
  626. controllist.pop_back();
  627. }
  628. while( !fitlist.empty() )
  629. {
  630. fitlist.pop_back();
  631. }
  632. }
  633. virtual void applyExtrusion() override {}
  634. void parseCode( int code, dxfReader* reader );
  635. public:
  636. double ex; /*!< normal vector x coordinate, code 210 */
  637. double ey; /*!< normal vector y coordinate, code 220 */
  638. double ez; /*!< normal vector z coordinate, code 230 */
  639. double tgsx; /*!< start tangent x coordinate, code 12 */
  640. double tgsy; /*!< start tangent y coordinate, code 22 */
  641. double tgsz; /*!< start tangent z coordinate, code 32 */
  642. double tgex; /*!< end tangent x coordinate, code 13 */
  643. double tgey; /*!< end tangent y coordinate, code 23 */
  644. double tgez; /*!< end tangent z coordinate, code 33 */
  645. int flags; /*!< spline flag, code 70 */
  646. int degree; /*!< degree of the spline, code 71 */
  647. int nknots; /*!< number of knots, code 72, default 0 */
  648. int ncontrol; /*!< number of control points, code 73, default 0 */
  649. int nfit; /*!< number of fit points, code 74, default 0 */
  650. double tolknot; /*!< knot tolerance, code 42, default 0.0000001 */
  651. double tolcontrol; /*!< control point tolerance, code 43, default 0.0000001 */
  652. double tolfit; /*!< fit point tolerance, code 44, default 0.0000001 */
  653. std::vector<double> knotslist; /*!< knots list, code 40 */
  654. std::vector<DRW_Coord*> controllist; /*!< control points list, code 10, 20 & 30 */
  655. std::vector<DRW_Coord*> fitlist; /*!< fit points list, code 11, 21 & 31 */
  656. private:
  657. DRW_Coord* controlpoint; /*!< current control point to add data */
  658. DRW_Coord* fitpoint; /*!< current fit point to add data */
  659. };
  660. // ! Class to handle hatch loop
  661. /*!
  662. * Class to handle hatch loop
  663. * @author Rallaz
  664. */
  665. class DRW_HatchLoop
  666. {
  667. public:
  668. DRW_HatchLoop( int t )
  669. {
  670. type = t;
  671. numedges = 0;
  672. }
  673. ~DRW_HatchLoop()
  674. {
  675. /* while (!pollist.empty()) {
  676. * pollist.pop_back();
  677. * }*/
  678. while( !objlist.empty() )
  679. {
  680. objlist.pop_back();
  681. }
  682. }
  683. void update()
  684. {
  685. numedges = objlist.size();
  686. }
  687. public:
  688. int type; /*!< boundary path type, code 92, polyline=2, default=0 */
  689. int numedges; /*!< number of edges (if not a polyline), code 93 */
  690. // TODO: store lwpolylines as entities
  691. // std::vector<DRW_LWPolyline *> pollist; /*!< polyline list */
  692. std::vector<DRW_Entity*> objlist; /*!< entities list */
  693. };
  694. // ! Class to handle hatch entity
  695. /*!
  696. * Class to handle hatch entity
  697. * @author Rallaz
  698. */
  699. // TODO: handle lwpolylines, splines and ellipses
  700. class DRW_Hatch : public DRW_Point
  701. {
  702. public:
  703. DRW_Hatch()
  704. {
  705. eType = DRW::HATCH;
  706. angle = scale = 0.0;
  707. basePoint.x = basePoint.y = basePoint.z = 0.0;
  708. loopsnum = hstyle = associative = 0;
  709. solid = hpattern = 1;
  710. deflines = doubleflag = 0;
  711. loop = NULL;
  712. clearEntities();
  713. ispol = false;
  714. }
  715. ~DRW_Hatch()
  716. {
  717. while( !looplist.empty() )
  718. {
  719. looplist.pop_back();
  720. }
  721. }
  722. void appendLoop( DRW_HatchLoop* v )
  723. {
  724. looplist.push_back( v );
  725. }
  726. virtual void applyExtrusion() override {}
  727. void parseCode( int code, dxfReader* reader );
  728. public:
  729. UTF8STRING name; /*!< hatch pattern name, code 2 */
  730. int solid; /*!< solid fill flag, code 70, solid=1, pattern=0 */
  731. int associative; /*!< associativity, code 71, associatve=1, non-assoc.=0 */
  732. int hstyle; /*!< hatch style, code 75 */
  733. int hpattern; /*!< hatch pattern type, code 76 */
  734. int doubleflag; /*!< hatch pattern double flag, code 77, double=1, single=0 */
  735. int loopsnum; /*!< namber of boundary paths (loops), code 91 */
  736. double angle; /*!< hatch pattern angle, code 52 */
  737. double scale; /*!< hatch pattern scale, code 41 */
  738. int deflines; /*!< number of pattern definition lines, code 78 */
  739. std::vector<DRW_HatchLoop*> looplist; /*!< polyline list */
  740. private:
  741. void clearEntities()
  742. {
  743. pt = line = NULL;
  744. pline = NULL;
  745. arc = NULL;
  746. ellipse = NULL;
  747. spline = NULL;
  748. plvert = NULL;
  749. }
  750. void addLine()
  751. {
  752. clearEntities();
  753. if( loop )
  754. {
  755. pt = line = new DRW_Line;
  756. loop->objlist.push_back( line );
  757. }
  758. }
  759. void addArc()
  760. {
  761. clearEntities();
  762. if( loop )
  763. {
  764. pt = arc = new DRW_Arc;
  765. loop->objlist.push_back( arc );
  766. }
  767. }
  768. void addEllipse()
  769. {
  770. clearEntities();
  771. if( loop )
  772. {
  773. pt = ellipse = new DRW_Ellipse;
  774. loop->objlist.push_back( ellipse );
  775. }
  776. }
  777. void addSpline()
  778. {
  779. clearEntities();
  780. if( loop )
  781. {
  782. pt = NULL;
  783. spline = new DRW_Spline;
  784. loop->objlist.push_back( spline );
  785. }
  786. }
  787. DRW_HatchLoop* loop; /*!< current loop to add data */
  788. DRW_Line* line;
  789. DRW_Arc* arc;
  790. DRW_Ellipse* ellipse;
  791. DRW_Spline* spline;
  792. DRW_LWPolyline* pline;
  793. DRW_Point* pt;
  794. DRW_Vertex2D* plvert;
  795. bool ispol;
  796. };
  797. // ! Class to handle image entity
  798. /*!
  799. * Class to handle image entity
  800. * @author Rallaz
  801. */
  802. class DRW_Image : public DRW_Line
  803. {
  804. public:
  805. DRW_Image()
  806. {
  807. eType = DRW::IMAGE;
  808. vz = fade = clip = 0;
  809. brightness = contrast = 50;
  810. vx = vy = sizeu = sizev = dz = 0.0;
  811. }
  812. void parseCode( int code, dxfReader* reader );
  813. public:
  814. std::string ref; /*!< Hard reference to imagedef object, code 340 */
  815. double vx; /*!< V-vector of single pixel, x coordinate, code 12 */
  816. double vy; /*!< V-vector of single pixel, y coordinate, code 22 */
  817. double vz; /*!< V-vector of single pixel, z coordinate, code 32 */
  818. double sizeu; /*!< image size in pixels, U value, code 13 */
  819. double sizev; /*!< image size in pixels, V value, code 23 */
  820. double dz; /*!< z coordinate, code 33 */
  821. int clip; /*!< Clipping state, code 280, 0=off 1=on */
  822. int brightness; /*!< Brightness value, code 281, (0-100) default 50 */
  823. int contrast; /*!< Brightness value, code 282, (0-100) default 50 */
  824. int fade; /*!< Brightness value, code 283, (0-100) default 0 */
  825. };
  826. // ! Base class for dimension entity
  827. /*!
  828. * Base class for dimension entity
  829. * @author Rallaz
  830. */
  831. class DRW_Dimension : public DRW_Entity
  832. {
  833. public:
  834. DRW_Dimension()
  835. {
  836. eType = DRW::DIMENSION;
  837. linesty = 1;
  838. linefactor = extPoint.z = 1.0;
  839. angle = oblique = rot = 0.0;
  840. align = 5;
  841. style = "STANDARD";
  842. defPoint.z = extPoint.x = extPoint.y = 0;
  843. textPoint.z = rot = 0;
  844. clonePoint.x = clonePoint.y = clonePoint.z = 0;
  845. type = 0;
  846. length = 0.0;
  847. }
  848. DRW_Dimension( const DRW_Dimension& d ) : DRW_Entity( d )
  849. {
  850. eType = DRW::DIMENSION;
  851. type = d.type;
  852. name = d.name;
  853. defPoint = d.defPoint;
  854. textPoint = d.textPoint;
  855. text = d.text;
  856. style = d.style;
  857. align = d.align;
  858. linesty = d.linesty;
  859. linefactor = d.linefactor;
  860. rot = d.rot;
  861. extPoint = d.extPoint;
  862. clonePoint = d.clonePoint;
  863. def1 = d.def1;
  864. def2 = d.def2;
  865. angle = d.angle;
  866. oblique = d.oblique;
  867. arcPoint = d.arcPoint;
  868. circlePoint = d.circlePoint;
  869. length = d.length;
  870. }
  871. virtual ~DRW_Dimension() {}
  872. void parseCode( int code, dxfReader* reader );
  873. virtual void applyExtrusion() override {}
  874. DRW_Coord getDefPoint() const { return defPoint; } /*!< Definition point, code 10, 20 & 30 */
  875. void setDefPoint( const DRW_Coord& p ) { defPoint = p; }
  876. DRW_Coord getTextPoint() const { return textPoint; } /*!< Middle point of text, code 11, 21 & 31 */
  877. void setTextPoint( const DRW_Coord& p ) { textPoint = p; }
  878. std::string getStyle() const { return style; } /*!< Dimension style, code 3 */
  879. void setStyle( const std::string& s ) { style = s; }
  880. int getAlign() const { return align; } /*!< attachment point, code 71 */
  881. void setAlign( const int a ) { align = a; }
  882. int getTextLineStyle() const { return linesty; } /*!< Dimension text line spacing style, code 72, default 1 */
  883. void setTextLineStyle( const int l ) { linesty = l; }
  884. std::string getText() const { return text; } /*!< Dimension text explicitly entered by the user, code 1 */
  885. void setText( const std::string& t ) { text = t; }
  886. double getTextLineFactor() const { return linefactor; } /*!< Dimension text line spacing factor, code 41, default 1? */
  887. void setTextLineFactor( const double l ) { linefactor = l; }
  888. double getDir() const { return rot; } /*!< rotation angle of the dimension text, code 53 (optional) default 0 */
  889. void setDir( const double d ) { rot = d; }
  890. DRW_Coord getExtrusion() { return extPoint; } /*!< extrusion, code 210, 220 & 230 */
  891. void setExtrusion( const DRW_Coord& p ) { extPoint = p; }
  892. std::string getName() { return name; } /*!< Name of the block that contains the entities, code 2 */
  893. void setName( const std::string& s ) { name = s; }
  894. // int getType(){ return type;} /*!< Dimension type, code 70 */
  895. protected:
  896. DRW_Coord getPt2() const { return clonePoint; }
  897. void setPt2( const DRW_Coord& p ) { clonePoint = p; }
  898. DRW_Coord getPt3() const { return def1; }
  899. void setPt3( const DRW_Coord& p ) { def1 = p; }
  900. DRW_Coord getPt4() const { return def2; }
  901. void setPt4( const DRW_Coord& p ) { def2 = p; }
  902. DRW_Coord getPt5() const { return circlePoint; }
  903. void setPt5( const DRW_Coord& p ) { circlePoint = p; }
  904. DRW_Coord getPt6() const { return arcPoint; }
  905. void setPt6( const DRW_Coord& p ) { arcPoint = p; }
  906. double getAn50() const { return angle; } /*!< Angle of rotated, horizontal, or vertical dimensions, code 50 */
  907. void setAn50( const double d ) { angle = d; }
  908. double getOb52() const { return oblique; } /*!< oblique angle, code 52 */
  909. void setOb52( const double d ) { oblique = d; }
  910. double getRa40() const { return length; } /*!< Leader length, code 40 */
  911. void setRa40( const double d ) { length = d; }
  912. public:
  913. int type; /*!< Dimension type, code 70 */
  914. private:
  915. std::string name; /*!< Name of the block that contains the entities, code 2 */
  916. DRW_Coord defPoint; /*!< definition point, code 10, 20 & 30 (WCS) */
  917. DRW_Coord textPoint; /*!< Middle point of text, code 11, 21 & 31 (OCS) */
  918. UTF8STRING text; /*!< Dimension text explicitly entered by the user, code 1 */
  919. UTF8STRING style; /*!< Dimension style, code 3 */
  920. int align; /*!< attachment point, code 71 */
  921. int linesty; /*!< Dimension text line spacing style, code 72, default 1 */
  922. double linefactor; /*!< Dimension text line spacing factor, code 41, default 1? (value range 0.25 to 4.00*/
  923. double rot; /*!< rotation angle of the dimension text, code 53 */
  924. DRW_Coord extPoint; /*!< extrusion normal vector, code 210, 220 & 230 */
  925. // double hdir; /*!< horizontal direction for the dimension, code 51, default ? */
  926. DRW_Coord clonePoint; /*!< Insertion point for clones (Baseline & Continue), code 12, 22 & 32 (OCS) */
  927. DRW_Coord def1; /*!< Definition point 1for linear & angular, code 13, 23 & 33 (WCS) */
  928. DRW_Coord def2; /*!< Definition point 2, code 14, 24 & 34 (WCS) */
  929. double angle; /*!< Angle of rotated, horizontal, or vertical dimensions, code 50 */
  930. double oblique; /*!< oblique angle, code 52 */
  931. DRW_Coord circlePoint; /*!< Definition point for diameter, radius & angular dims code 15, 25 & 35 (WCS) */
  932. DRW_Coord arcPoint; /*!< Point defining dimension arc, x coordinate, code 16, 26 & 36 (OCS) */
  933. double length; /*!< Leader length, code 40 */
  934. };
  935. // ! Class to handle aligned dimension entity
  936. /*!
  937. * Class to handle aligned dimension entity
  938. * @author Rallaz
  939. */
  940. class DRW_DimAligned : public DRW_Dimension
  941. {
  942. public:
  943. DRW_DimAligned()
  944. {
  945. eType = DRW::DIMALIGNED;
  946. }
  947. DRW_DimAligned( const DRW_Dimension& d ) : DRW_Dimension( d )
  948. {
  949. eType = DRW::DIMALIGNED;
  950. }
  951. DRW_Coord getClonepoint() const { return getPt2(); } /*!< Insertion for clones (Baseline & Continue), 12, 22 & 32 */
  952. void setClonePoint( DRW_Coord& c ) { setPt2( c ); }
  953. DRW_Coord getDimPoint() const { return getDefPoint(); } /*!< dim line location point, code 10, 20 & 30 */
  954. void setDimPoint( const DRW_Coord& p ) { setDefPoint( p ); }
  955. DRW_Coord getDef1Point() const { return getPt3(); } /*!< Definition point 1, code 13, 23 & 33 */
  956. void setDef1Point( const DRW_Coord& p ) { setPt3( p ); }
  957. DRW_Coord getDef2Point() const { return getPt4(); } /*!< Definition point 2, code 14, 24 & 34 */
  958. void setDef2Point( const DRW_Coord& p ) { setPt4( p ); }
  959. };
  960. // ! Class to handle linear or rotated dimension entity
  961. /*!
  962. * Class to handle linear or rotated dimension entity
  963. * @author Rallaz
  964. */
  965. class DRW_DimLinear : public DRW_DimAligned
  966. {
  967. public:
  968. DRW_DimLinear()
  969. {
  970. eType = DRW::DIMLINEAR;
  971. }
  972. DRW_DimLinear( const DRW_Dimension& d ) : DRW_DimAligned( d )
  973. {
  974. eType = DRW::DIMLINEAR;
  975. }
  976. double getAngle() const { return getAn50(); } /*!< Angle of rotated, horizontal, or vertical dimensions, code 50 */
  977. void setAngle( const double d ) { setAn50( d ); }
  978. double getOblique() const { return getOb52(); } /*!< oblique angle, code 52 */
  979. void setOblique( const double d ) { setOb52( d ); }
  980. };
  981. // ! Class to handle radial dimension entity
  982. /*!
  983. * Class to handle aligned, linear or rotated dimension entity
  984. * @author Rallaz
  985. */
  986. class DRW_DimRadial : public DRW_Dimension
  987. {
  988. public:
  989. DRW_DimRadial()
  990. {
  991. eType = DRW::DIMRADIAL;
  992. }
  993. DRW_DimRadial( const DRW_Dimension& d ) : DRW_Dimension( d )
  994. {
  995. eType = DRW::DIMRADIAL;
  996. }
  997. DRW_Coord getCenterPoint() const { return getDefPoint(); } /*!< center point, code 10, 20 & 30 */
  998. void setCenterPoint( const DRW_Coord& p ) { setDefPoint( p ); }
  999. DRW_Coord getDiameterPoint() const { return getPt5(); } /*!< Definition point for radius, code 15, 25 & 35 */
  1000. void setDiameterPoint( const DRW_Coord& p ) { setPt5( p ); }
  1001. double getLeaderLength() const { return getRa40(); } /*!< Leader length, code 40 */
  1002. void setLeaderLength( const double d ) { setRa40( d ); }
  1003. };
  1004. // ! Class to handle radial dimension entity
  1005. /*!
  1006. * Class to handle aligned, linear or rotated dimension entity
  1007. * @author Rallaz
  1008. */
  1009. class DRW_DimDiametric : public DRW_Dimension
  1010. {
  1011. public:
  1012. DRW_DimDiametric()
  1013. {
  1014. eType = DRW::DIMDIAMETRIC;
  1015. }
  1016. DRW_DimDiametric( const DRW_Dimension& d ) : DRW_Dimension( d )
  1017. {
  1018. eType = DRW::DIMDIAMETRIC;
  1019. }
  1020. DRW_Coord getDiameter1Point() const { return getPt5(); } /*!< First definition point for diameter, code 15, 25 & 35 */
  1021. void setDiameter1Point( const DRW_Coord& p ) { setPt5( p ); }
  1022. DRW_Coord getDiameter2Point() const { return getDefPoint(); } /*!< Oposite point for diameter, code 10, 20 & 30 */
  1023. void setDiameter2Point( const DRW_Coord& p ) { setDefPoint( p ); }
  1024. double getLeaderLength() const { return getRa40(); } /*!< Leader length, code 40 */
  1025. void setLeaderLength( const double d ) { setRa40( d ); }
  1026. };
  1027. // ! Class to handle angular dimension entity
  1028. /*!
  1029. * Class to handle angular dimension entity
  1030. * @author Rallaz
  1031. */
  1032. class DRW_DimAngular : public DRW_Dimension
  1033. {
  1034. public:
  1035. DRW_DimAngular()
  1036. {
  1037. eType = DRW::DIMANGULAR;
  1038. }
  1039. DRW_DimAngular( const DRW_Dimension& d ) : DRW_Dimension( d )
  1040. {
  1041. eType = DRW::DIMANGULAR;
  1042. }
  1043. DRW_Coord getFirstLine1() const { return getPt3(); } /*!< Definition point line 1-1, code 13, 23 & 33 */
  1044. void setFirstLine1( const DRW_Coord& p ) { setPt3( p ); }
  1045. DRW_Coord getFirstLine2() const { return getPt4(); } /*!< Definition point line 1-2, code 14, 24 & 34 */
  1046. void setFirstLine2( const DRW_Coord& p ) { setPt4( p ); }
  1047. DRW_Coord getSecondLine1() const { return getPt5(); } /*!< Definition point line 2-1, code 15, 25 & 35 */
  1048. void setSecondLine1( const DRW_Coord& p ) { setPt5( p ); }
  1049. DRW_Coord getSecondLine2() const { return getDefPoint(); } /*!< Definition point line 2-2, code 10, 20 & 30 */
  1050. void setSecondLine2( const DRW_Coord& p ) { setDefPoint( p ); }
  1051. DRW_Coord getDimPoint() const { return getPt6(); } /*!< Dimension definition point, code 16, 26 & 36 */
  1052. void setDimPoint( const DRW_Coord& p ) { setPt6( p ); }
  1053. };
  1054. // ! Class to handle angular 3p dimension entity
  1055. /*!
  1056. * Class to handle angular 3p dimension entity
  1057. * @author Rallaz
  1058. */
  1059. class DRW_DimAngular3p : public DRW_Dimension
  1060. {
  1061. public:
  1062. DRW_DimAngular3p()
  1063. {
  1064. eType = DRW::DIMANGULAR3P;
  1065. }
  1066. DRW_DimAngular3p( const DRW_Dimension& d ) : DRW_Dimension( d )
  1067. {
  1068. eType = DRW::DIMANGULAR3P;
  1069. }
  1070. DRW_Coord getFirstLine() const { return getPt3(); } /*!< Definition point line 1, code 13, 23 & 33 */
  1071. void setFirstLine( const DRW_Coord& p ) { setPt3( p ); }
  1072. DRW_Coord getSecondLine() const { return getPt4(); } /*!< Definition point line 2, code 14, 24 & 34 */
  1073. void setSecondLine( const DRW_Coord& p ) { setPt4( p ); }
  1074. DRW_Coord getVertexPoint() const { return getPt5(); } /*!< Vertex point, code 15, 25 & 35 */
  1075. void SetVertexPoint( const DRW_Coord& p ) { setPt5( p ); }
  1076. DRW_Coord getDimPoint() const { return getDefPoint(); } /*!< Dimension definition point, code 10, 20 & 30 */
  1077. void setDimPoint( const DRW_Coord& p ) { setDefPoint( p ); }
  1078. };
  1079. // ! Class to handle ordinate dimension entity
  1080. /*!
  1081. * Class to handle ordinate dimension entity
  1082. * @author Rallaz
  1083. */
  1084. class DRW_DimOrdinate : public DRW_Dimension
  1085. {
  1086. public:
  1087. DRW_DimOrdinate()
  1088. {
  1089. eType = DRW::DIMORDINATE;
  1090. }
  1091. DRW_DimOrdinate( const DRW_Dimension& d ) : DRW_Dimension( d )
  1092. {
  1093. eType = DRW::DIMORDINATE;
  1094. }
  1095. DRW_Coord getOriginPoint() const { return getDefPoint(); } /*!< Origin definition point, code 10, 20 & 30 */
  1096. void setOriginPoint( const DRW_Coord& p ) { setDefPoint( p ); }
  1097. DRW_Coord getFirstLine() const { return getPt3(); } /*!< Feature location point, code 13, 23 & 33 */
  1098. void setFirstLine( const DRW_Coord& p ) { setPt3( p ); }
  1099. DRW_Coord getSecondLine() const { return getPt4(); } /*!< Leader end point, code 14, 24 & 34 */
  1100. void setSecondLine( const DRW_Coord& p ) { setPt4( p ); }
  1101. };
  1102. // ! Class to handle leader entity
  1103. /*!
  1104. * Class to handle leader entity
  1105. * @author Rallaz
  1106. */
  1107. class DRW_Leader : public DRW_Entity
  1108. {
  1109. public:
  1110. DRW_Leader()
  1111. {
  1112. eType = DRW::LEADER;
  1113. flag = 3;
  1114. hookflag = vertnum = leadertype = 0;
  1115. extrusionPoint.x = extrusionPoint.y = 0.0;
  1116. arrow = 1;
  1117. extrusionPoint.z = 1.0;
  1118. hookline = 0;
  1119. textheight = textwidth = 0.0;
  1120. coloruse = 0;
  1121. vertexpoint = NULL;
  1122. }
  1123. ~DRW_Leader()
  1124. {
  1125. while( !vertexlist.empty() )
  1126. {
  1127. vertexlist.pop_back();
  1128. }
  1129. }
  1130. virtual void applyExtrusion() override {}
  1131. void parseCode( int code, dxfReader* reader );
  1132. public:
  1133. UTF8STRING style; /*!< Dimension style name, code 3 */
  1134. int arrow; /*!< Arrowhead flag, code 71, 0=Disabled; 1=Enabled */
  1135. int leadertype; /*!< Leader path type, code 72, 0=Straight line segments; 1=Spline */
  1136. int flag; /*!< Leader creation flag, code 73, default 3 */
  1137. int hookline; /*!< Hook line direction flag, code 74, default 1 */
  1138. int hookflag; /*!< Hook line flag, code 75 */
  1139. double textheight; /*!< Text annotation height, code 40 */
  1140. double textwidth; /*!< Text annotation width, code 41 */
  1141. int vertnum; /*!< Number of vertices, code 76 */
  1142. int coloruse; /*!< Color to use if leader's DIMCLRD = BYBLOCK, code 77 */
  1143. std::string handle; /*!< Hard reference to associated annotation, code 340 */
  1144. DRW_Coord extrusionPoint; /*!< Normal vector, code 210, 220 & 230 */
  1145. DRW_Coord horizdir; /*!< "Horizontal" direction for leader, code 211, 221 & 231 */
  1146. DRW_Coord offsetblock; /*!< Offset of last leader vertex from block, code 212, 222 & 232 */
  1147. DRW_Coord offsettext; /*!< Offset of last leader vertex from annotation, code 213, 223 & 233 */
  1148. std::vector<DRW_Coord*> vertexlist; /*!< vertex points list, code 10, 20 & 30 */
  1149. private:
  1150. DRW_Coord* vertexpoint; /*!< current control point to add data */
  1151. };
  1152. // ! Class to handle viewport entity
  1153. /*!
  1154. * Class to handle viewport entity
  1155. * @author Rallaz
  1156. */
  1157. class DRW_Viewport : public DRW_Point
  1158. {
  1159. public:
  1160. DRW_Viewport()
  1161. {
  1162. eType = DRW::VIEWPORT;
  1163. vpID = vpstatus = 0;
  1164. pswidth = 205;
  1165. psheight = 156;
  1166. centerPX = 128.5;
  1167. centerPY = 97.5;
  1168. }
  1169. virtual void applyExtrusion() override {}
  1170. void parseCode( int code, dxfReader* reader );
  1171. public:
  1172. double pswidth; /*!< Width in paper space units, code 40 */
  1173. double psheight; /*!< Height in paper space units, code 41 */
  1174. int vpstatus; /*!< Viewport status, code 68 */
  1175. int vpID; /*!< Viewport ID, code 69 */
  1176. double centerPX; /*!< view center piont X, code 12 */
  1177. double centerPY; /*!< view center piont Y, code 22 */
  1178. };
  1179. #endif
  1180. // EOF