dbMPolygon.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2015 Autodesk, Inc. All rights reserved.
  4. //
  5. // Use of this software is subject to the terms of the Autodesk license
  6. // agreement provided at the time of installation or download, or which
  7. // otherwise accompanies this software in either electronic or hard copy form.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. //
  11. #pragma once
  12. #undef ACAD_OBJID_INLINE_INTERNAL
  13. #include "dbhatch.h"
  14. #include <tchar.h>
  15. class AcDbCircle;
  16. class AcDb2dPolyline;
  17. class AcDbPolyline;
  18. class AcDbMPolygonCrossingArray;
  19. class AcDbMPolygonNode;
  20. const double AcDbMPolygonCrossingFuzz = 1E-6;
  21. #ifndef _ADESK_MAC_
  22. #ifndef ACMPOLYGON_PORT
  23. #ifdef ACMPOLYGON_API
  24. #define ACMPOLYGON_PORT _declspec(dllexport)
  25. #else
  26. #define ACMPOLYGON_PORT _declspec(dllimport)
  27. #endif
  28. #endif
  29. #else
  30. // On OS X, we will export all symbols by default and will use GCC
  31. // attributes to exclude symbols we don't want to export.
  32. #define ACBASE_PORT
  33. #endif // _ADESK_MAC_
  34. class AcDbMPolygon : public AcDbEntity {
  35. public:
  36. enum loopDir {
  37. kExterior = 0, // counter clockwise
  38. kInterior, // clockwise
  39. kAnnotation // text
  40. };
  41. // Constructors and Destructors
  42. //
  43. ACMPOLYGON_PORT AcDbMPolygon();
  44. ACMPOLYGON_PORT virtual ~AcDbMPolygon();
  45. ACRX_DECLARE_MEMBERS_EXPIMP(AcDbMPolygon, ACMPOLYGON_PORT);
  46. //*************************************************************************
  47. // Methods specific to AcDbMPolygon
  48. //*************************************************************************
  49. // Mpolygon hatch member access methods.
  50. //
  51. ACMPOLYGON_PORT virtual AcDbHatch * hatch();
  52. // Hatch Plane Methods
  53. //
  54. ACMPOLYGON_PORT virtual double elevation() const;
  55. ACMPOLYGON_PORT virtual Acad::ErrorStatus setElevation(double elevation);
  56. ACMPOLYGON_PORT virtual AcGeVector3d normal() const;
  57. ACMPOLYGON_PORT virtual Acad::ErrorStatus setNormal(const AcGeVector3d& normal);
  58. // Hatch Graphics Display Control Methods
  59. //
  60. ACMPOLYGON_PORT virtual Acad::ErrorStatus evaluateHatch(bool bUnderestimateNumLines = false);
  61. // Hatch Pattern Methods
  62. //
  63. ACMPOLYGON_PORT virtual AcDbHatch::HatchPatternType patternType() const;
  64. ACMPOLYGON_PORT virtual const TCHAR* patternName() const;
  65. ACMPOLYGON_PORT virtual Acad::ErrorStatus setPattern(AcDbHatch::HatchPatternType patType,
  66. const TCHAR* patName);
  67. ACMPOLYGON_PORT virtual double patternAngle() const;
  68. ACMPOLYGON_PORT virtual Acad::ErrorStatus setPatternAngle(double angle);
  69. ACMPOLYGON_PORT virtual double patternSpace() const;
  70. ACMPOLYGON_PORT virtual Acad::ErrorStatus setPatternSpace(double space);
  71. ACMPOLYGON_PORT virtual double patternScale() const;
  72. ACMPOLYGON_PORT virtual Acad::ErrorStatus setPatternScale(double scale);
  73. ACMPOLYGON_PORT virtual bool patternDouble() const;
  74. ACMPOLYGON_PORT virtual Acad::ErrorStatus setPatternDouble(bool isDouble);
  75. ACMPOLYGON_PORT virtual int numPatternDefinitions() const;
  76. ACMPOLYGON_PORT virtual Acad::ErrorStatus getPatternDefinitionAt(int index,
  77. double& angle,
  78. double& baseX,
  79. double& baseY,
  80. double& offsetX,
  81. double& offsetY,
  82. AcGeDoubleArray& dashes)
  83. const;
  84. // Hatch Gradient support
  85. ACMPOLYGON_PORT Acad::ErrorStatus setGradientAngle(double angle);
  86. ACMPOLYGON_PORT Acad::ErrorStatus setGradientShift( float shiftValue );
  87. ACMPOLYGON_PORT Acad::ErrorStatus setGradientOneColorMode( Adesk::Boolean oneColorMode );
  88. ACMPOLYGON_PORT Acad::ErrorStatus setGradientColors( unsigned int count,
  89. AcCmColor* colors,
  90. float* values );
  91. ACMPOLYGON_PORT Acad::ErrorStatus setGradient(AcDbHatch::GradientPatternType gradType,
  92. const TCHAR* gradName);
  93. // Mpolygon access methods.
  94. //
  95. ACMPOLYGON_PORT virtual AcCmColor patternColor() const;
  96. ACMPOLYGON_PORT virtual Acad::ErrorStatus setPatternColor(const AcCmColor& pc);
  97. ACMPOLYGON_PORT virtual double getArea() const;
  98. ACMPOLYGON_PORT virtual double getPerimeter() const;
  99. ACMPOLYGON_PORT virtual bool isBalanced() const;
  100. ACMPOLYGON_PORT virtual AcGeVector2d getOffsetVector() const;
  101. ACMPOLYGON_PORT virtual Acad::ErrorStatus getMPolygonTree(AcDbMPolygonNode*& loopNode) const;
  102. ACMPOLYGON_PORT virtual void deleteMPolygonTree(AcDbMPolygonNode* loopNode) const;
  103. // Mpolygon loop quiry and manipulation methods.
  104. //
  105. ACMPOLYGON_PORT virtual Acad::ErrorStatus appendLoopFromBoundary(const AcDbCircle* pCircle,
  106. bool excludeCrossing = true, double tol = AcDbMPolygonCrossingFuzz);
  107. ACMPOLYGON_PORT virtual Acad::ErrorStatus appendLoopFromBoundary(const AcDbPolyline* pPoly,
  108. bool excludeCrossing = true, double tol = AcDbMPolygonCrossingFuzz);
  109. ACMPOLYGON_PORT virtual Acad::ErrorStatus appendLoopFromBoundary(const AcDb2dPolyline* pPoly,
  110. bool excludeCrossing = true, double tol = AcDbMPolygonCrossingFuzz);
  111. ACMPOLYGON_PORT virtual int numMPolygonLoops() const;
  112. ACMPOLYGON_PORT virtual Acad::ErrorStatus getMPolygonLoopAt(int loopIndex, AcGePoint2dArray& vertices,
  113. AcGeDoubleArray& bulges) const;
  114. ACMPOLYGON_PORT virtual Acad::ErrorStatus insertMPolygonLoopAt(int loopIndex,
  115. const AcGePoint2dArray& vertices, const AcGeDoubleArray& bulges,
  116. bool excludeCrossing = true, double tol = AcDbMPolygonCrossingFuzz);
  117. ACMPOLYGON_PORT virtual Acad::ErrorStatus appendMPolygonLoop(const AcGePoint2dArray& vertices,
  118. const AcGeDoubleArray& bulges, bool excludeCrossing = true,
  119. double tol = AcDbMPolygonCrossingFuzz);
  120. ACMPOLYGON_PORT virtual Acad::ErrorStatus removeMPolygonLoopAt(int loopIndex);
  121. ACMPOLYGON_PORT virtual Acad::ErrorStatus balanceTree();
  122. ACMPOLYGON_PORT virtual Acad::ErrorStatus balanceDisplay();
  123. ACMPOLYGON_PORT virtual Acad::ErrorStatus getLoopDirection(int lindex, AcDbMPolygon::loopDir& dir) const;
  124. ACMPOLYGON_PORT virtual Acad::ErrorStatus setLoopDirection(int lindex, AcDbMPolygon::loopDir dir);
  125. ACMPOLYGON_PORT virtual Acad::ErrorStatus getLoopAtGsMarker(int gsMark, int &loop) const;
  126. ACMPOLYGON_PORT virtual void getChildLoops(int curLoop, AcGeIntArray& selectedLoopIndexes) const;
  127. ACMPOLYGON_PORT virtual int getParentLoop(int curLoop) const;
  128. ACMPOLYGON_PORT virtual int getClosestLoopTo(const AcGePoint3d& worldPt) const;
  129. // Mpolyon loop crossing and inside methods.
  130. //
  131. ACMPOLYGON_PORT virtual int isPointInsideMPolygon(const AcGePoint3d& worldPt, AcGeIntArray& loopsArray,
  132. double tol = AcDbMPolygonCrossingFuzz) const;
  133. ACMPOLYGON_PORT virtual bool isPointOnLoopBoundary(const AcGePoint3d& worldPt, int loop,
  134. double tol = AcDbMPolygonCrossingFuzz) const;
  135. ACMPOLYGON_PORT virtual Acad::ErrorStatus loopCrossesItself(bool& crosses, bool findAll,
  136. AcDbMPolygonCrossingArray& crossingsArray,
  137. const AcGePoint2dArray& vertexPts,
  138. const AcGeDoubleArray& vertexBulges,
  139. double tol = AcDbMPolygonCrossingFuzz) const;
  140. ACMPOLYGON_PORT virtual bool loopCrossesItself(const AcGePoint2dArray& vertexPts,
  141. const AcGeDoubleArray& vertexBulges,
  142. double tol = AcDbMPolygonCrossingFuzz) const;
  143. ACMPOLYGON_PORT virtual Acad::ErrorStatus loopCrossesMPolygon(bool& crosses, bool findAll,
  144. AcDbMPolygonCrossingArray& crossingsArray,
  145. const AcGePoint2dArray& testVertexPts,
  146. const AcGeDoubleArray& testVertexBulges,
  147. double tol = AcDbMPolygonCrossingFuzz) const;
  148. ACMPOLYGON_PORT virtual bool selfCrosses(const AcGePoint2dArray& vertexPts,
  149. const AcGeDoubleArray& vertexBulges,
  150. double tol = AcDbMPolygonCrossingFuzz) const;
  151. ACMPOLYGON_PORT virtual bool includesTouchingLoops(double tol = AcDbMPolygonCrossingFuzz) const;
  152. //*************************************************************************
  153. // Overridden methods from AcDbEntity
  154. //*************************************************************************
  155. ACMPOLYGON_PORT virtual Acad::ErrorStatus subGetClassID( CLSID* pClsid) const;
  156. ACMPOLYGON_PORT virtual Adesk::Boolean subWorldDraw(AcGiWorldDraw* mode);
  157. ACMPOLYGON_PORT virtual void saveAs(AcGiWorldDraw* mode, AcDb::SaveType st);
  158. ACMPOLYGON_PORT virtual Acad::ErrorStatus subGetSubentPathsAtGsMarker(
  159. AcDb::SubentType type,
  160. Adesk::GsMarker gsMark,
  161. const AcGePoint3d& pickPoint,
  162. const AcGeMatrix3d& viewXform,
  163. int& numPaths,
  164. AcDbFullSubentPath*& subentPaths,
  165. int numInserts = 0,
  166. AcDbObjectId* entAndInsertStack
  167. = NULL) const;
  168. ACMPOLYGON_PORT virtual Acad::ErrorStatus subGetGsMarkersAtSubentPath(
  169. const AcDbFullSubentPath& subPath,
  170. AcArray<Adesk::GsMarker>& gsMarkers) const;
  171. ACMPOLYGON_PORT virtual AcDbEntity* subSubentPtr(const AcDbFullSubentPath& id) const;
  172. ACMPOLYGON_PORT virtual Acad::ErrorStatus subIntersectWith(
  173. const AcDbEntity* ent,
  174. AcDb::Intersect intType,
  175. AcGePoint3dArray& points,
  176. Adesk::GsMarker thisGsMarker = 0,
  177. Adesk::GsMarker otherGsMarker = 0)
  178. const;
  179. ACMPOLYGON_PORT virtual Acad::ErrorStatus subIntersectWith(
  180. const AcDbEntity* ent,
  181. AcDb::Intersect intType,
  182. const AcGePlane& projPlane,
  183. AcGePoint3dArray& points,
  184. Adesk::GsMarker thisGsMarker = 0,
  185. Adesk::GsMarker otherGsMarker = 0)
  186. const;
  187. ACMPOLYGON_PORT virtual Acad::ErrorStatus subGetOsnapPoints(
  188. AcDb::OsnapMode osnapMode,
  189. Adesk::GsMarker gsSelectionMark,
  190. const AcGePoint3d& pickPoint,
  191. const AcGePoint3d& lastPoint,
  192. const AcGeMatrix3d& viewXform,
  193. AcGePoint3dArray& snapPoints,
  194. AcDbIntArray& geomIds) const;
  195. ACMPOLYGON_PORT virtual Acad::ErrorStatus subGetGripPoints(AcGePoint3dArray& gripPoints,
  196. AcDbIntArray& osnapModes,
  197. AcDbIntArray& geomIds) const;
  198. ACMPOLYGON_PORT virtual Acad::ErrorStatus subMoveGripPointsAt(const AcDbIntArray& indices,
  199. const AcGeVector3d& offset);
  200. ACMPOLYGON_PORT virtual Acad::ErrorStatus subGetStretchPoints(AcGePoint3dArray& stretchPoints) const;
  201. ACMPOLYGON_PORT virtual Acad::ErrorStatus subMoveStretchPointsAt( const AcDbIntArray& indices,
  202. const AcGeVector3d& offset);
  203. ACMPOLYGON_PORT virtual Acad::ErrorStatus subTransformBy(const AcGeMatrix3d& xform);
  204. ACMPOLYGON_PORT virtual Acad::ErrorStatus subGetGeomExtents(AcDbExtents& extents) const;
  205. ACMPOLYGON_PORT virtual void subList() const;
  206. ACMPOLYGON_PORT virtual Acad::ErrorStatus subExplode( AcDbVoidPtrArray& entitySet) const;
  207. //*************************************************************************
  208. // Overridden methods from AcDbObject
  209. //*************************************************************************
  210. ACMPOLYGON_PORT virtual Acad::ErrorStatus dwgInFields(AcDbDwgFiler* filer);
  211. ACMPOLYGON_PORT virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler* filer) const;
  212. ACMPOLYGON_PORT virtual Acad::ErrorStatus dxfInFields(AcDbDxfFiler* filer);
  213. ACMPOLYGON_PORT virtual Acad::ErrorStatus dxfOutFields(AcDbDxfFiler* filer) const;
  214. ACMPOLYGON_PORT virtual Acad::ErrorStatus audit(AcDbAuditInfo* );
  215. ACMPOLYGON_PORT virtual Acad::ErrorStatus decomposeForSave(AcDb::AcDbDwgVersion ver,
  216. AcDbObject*& replaceObj, AcDbObjectId& replaceId,
  217. Adesk::Boolean& exchangeXData);
  218. // Batch Mpolygon creation (it should have no loops)
  219. //
  220. ACMPOLYGON_PORT virtual Acad::ErrorStatus createLoopsFromBoundaries (const AcDbObjectIdArray &ids,
  221. AcDbIntArray &rejectedObjs,
  222. bool excludeCrossing = true, double tol = AcDbMPolygonCrossingFuzz);
  223. ACMPOLYGON_PORT virtual Acad::ErrorStatus createLoops (const AcArray<AcGePoint2dArray,AcArrayObjectCopyReallocator<AcGePoint2dArray> > &vertices,
  224. const AcArray<AcGeDoubleArray,AcArrayObjectCopyReallocator<AcGeDoubleArray> > &bulges, AcDbIntArray &rejectedObjs,
  225. bool excludeCrossing = true, double tol = AcDbMPolygonCrossingFuzz);
  226. private:
  227. friend class AcDbImpMPolygon;
  228. void* pImp;
  229. };
  230. // This class is used during loop editing to store loops.
  231. // The MpolygonUI.arx application uses this during dragging
  232. // while in the MPEDT Move command.
  233. class AcDbMpolygonLoops {
  234. public:
  235. AcDbMpolygonLoops(int lindex, int gindex = 0, int gcnt = 0);
  236. int mLoopIndex; // AcDbHatch loop index.
  237. bool mIsText; // Annotation Loop?
  238. int mGripIndex; // Base grip index for this loop (grip editing only.)
  239. int mGripCount; // Number of hot grips in the loop (grip editing only.)
  240. AcGePoint2dArray mVertexPoints;
  241. AcGeDoubleArray mVertexBulges;
  242. };
  243. inline
  244. AcDbMpolygonLoops::AcDbMpolygonLoops(int lindex, int gindex, int gcnt)
  245. {
  246. mLoopIndex = lindex;
  247. mGripIndex = gindex;
  248. mGripCount = gcnt;
  249. }
  250. // This class is used to store one mpolygon loop crossing point.
  251. class AcDbMPolygonCrossing {
  252. public:
  253. ACMPOLYGON_PORT AcDbMPolygonCrossing();
  254. ACMPOLYGON_PORT ~AcDbMPolygonCrossing();
  255. ACMPOLYGON_PORT int getLoopIndex() const; // Crossing loop index
  256. ACMPOLYGON_PORT void setLoopIndex(int index);
  257. ACMPOLYGON_PORT int getEdgeIndex() const; // Starting vertex index of loop edge
  258. ACMPOLYGON_PORT void setEdgeIndex(int index);
  259. ACMPOLYGON_PORT AcGePoint2d getCrossingPoint() const; // Loop crossing point
  260. ACMPOLYGON_PORT void setCrossingPoint(const AcGePoint2d& pt);
  261. private:
  262. void* pImp;
  263. };
  264. // An Array of class AcDbMPolygonCrossing (loop crossing points).
  265. class AcDbMPolygonCrossingArray {
  266. public:
  267. ~AcDbMPolygonCrossingArray();
  268. AcArray<AcDbMPolygonCrossing *> mCrossingArray;
  269. };
  270. inline
  271. AcDbMPolygonCrossingArray::~AcDbMPolygonCrossingArray()
  272. {
  273. AcDbMPolygonCrossing* pCrossing;
  274. int numCross = mCrossingArray.length();
  275. for (int i = numCross - 1; i >= 0; i--) {
  276. pCrossing = mCrossingArray[i];
  277. mCrossingArray.removeAt(i);
  278. if (pCrossing != NULL)
  279. delete pCrossing;
  280. }
  281. }
  282. // The following class is used by the getMPolygonTree API to
  283. // return the internal tree ordered loops.
  284. class AcDbMPolygonNode {
  285. public:
  286. // Constructor
  287. AcDbMPolygonNode();
  288. public:
  289. AcDbMPolygonNode * mParent;
  290. AcArray<AcDbMPolygonNode*> mChildren;
  291. int mLoopIndex; // MPolygon loop index.
  292. };
  293. inline
  294. AcDbMPolygonNode::AcDbMPolygonNode()
  295. : mLoopIndex(-1), mParent(NULL)
  296. {
  297. }