sg2D.h
Upload User: kairuinn
Upload Date: 2009-02-07
Package Size: 2922k
Code Size: 8k
Category:

Graph program

Development Platform:

Visual C++

  1. #ifndef  __sg2D__
  2. #define  __sg2D__
  3. /************************************************************************/
  4. /* POINT                                                                */
  5. /************************************************************************/
  6. class sgCore_API   sgCPoint : public sgCObject
  7. {
  8. private:
  9. sgCPoint();
  10. sgCPoint(SG_OBJ_HANDLE);
  11. virtual    ~sgCPoint();
  12. public:
  13. static   sgCPoint*    Create(double pX,double pY,double pZ);
  14. const    SG_POINT*    GetGeometry() const; 
  15. PRIVATE_ACCESS
  16. };
  17. #define  sgCreatePoint  sgCPoint::Create
  18. /************************************************************************/
  19. /* BASE CLASS FOR 2D OBJECTS                                            */
  20. /************************************************************************/
  21. class sgCContour;
  22. class sgCore_API   sgC2DObject : public sgCObject
  23. {
  24. protected:
  25. sgC2DObject();
  26. sgC2DObject(SG_OBJ_HANDLE);
  27. SG_VECTOR      m_plane_normal;
  28. double         m_plane_D;
  29. public:
  30. virtual  bool        IsClosed() const =0;
  31. virtual  bool        IsPlane(SG_VECTOR*,double*) const =0;
  32. virtual  bool        IsLinear() const =0;
  33. virtual  bool        IsSelfIntersecting()  const =0;
  34. sgCContour*  GetEquidistantContour(double h1, double h2, bool toRound);
  35. typedef enum
  36. {
  37. OO_ERROR=0,
  38. OO_CLOCKWISE,
  39. OO_ANTICLOCKWISE
  40. } SG_2D_OBJECT_ORIENT;
  41. SG_2D_OBJECT_ORIENT  GetOrient(const SG_VECTOR& planeNormal) const;
  42. bool                 ChangeOrient();
  43. SG_POINT             GetPointFromCoefficient(double coeff) const;
  44. static   bool        IsObjectsOnOnePlane(const sgC2DObject& obj1, 
  45. const sgC2DObject& obj2);
  46. static   bool        IsObjectsIntersecting(const sgC2DObject& obj1, 
  47. const sgC2DObject& obj2);
  48. static   bool        IsFirstObjectInsideSecondObject(const sgC2DObject& obj1, 
  49. const sgC2DObject& obj2);
  50. };
  51. /************************************************************************/
  52. /* LINE                                                                 */
  53. /************************************************************************/
  54. class sgCore_API   sgCLine : public sgC2DObject
  55. {
  56. private:
  57. sgCLine();
  58. sgCLine(SG_OBJ_HANDLE);
  59. virtual    ~sgCLine();
  60. public:
  61. static   sgCLine*    Create(double pX1, double pY1, double pZ1,
  62. double pX2, double pY2, double pZ2);
  63. const    SG_LINE*    GetGeometry() const; 
  64. virtual  bool        IsClosed() const;
  65. virtual  bool        IsPlane(SG_VECTOR*,double*) const;
  66. virtual  bool        IsLinear() const;
  67. virtual  bool        IsSelfIntersecting()  const;
  68. PRIVATE_ACCESS
  69. };
  70. #define  sgCreateLine  sgCLine::Create
  71. /************************************************************************/
  72. /* CIRCLE                                                                 */
  73. /************************************************************************/
  74. struct sgCore_API  SG_CIRCLE
  75. {
  76. double    radius;
  77. SG_VECTOR  normal;          // Normal
  78. SG_POINT   center;
  79. bool    FromCenterRadiusNormal(const SG_POINT& cen, double rad, const SG_VECTOR& nor);
  80. bool    FromThreePoints(const SG_POINT& p1, const SG_POINT& p2, const SG_POINT& p3);
  81. bool    Draw(SG_DRAW_LINE_FUNC) const;
  82. };
  83. class sgCore_API   sgCCircle : public sgC2DObject
  84. {
  85. private:
  86. sgCCircle();
  87. sgCCircle(SG_OBJ_HANDLE);
  88. virtual    ~sgCCircle();
  89. SG_POINT*   m_points;
  90. int         m_points_count;
  91. public:
  92. static   sgCCircle*   Create(const SG_CIRCLE&);
  93. const    SG_CIRCLE*   GetGeometry() const; 
  94. int       GetPointsCount() const;
  95. const    SG_POINT*    GetPoints() const;
  96. virtual  bool   ApplyTempMatrix();
  97. virtual  bool         IsClosed() const;
  98. virtual  bool         IsPlane(SG_VECTOR*,double*) const;
  99. virtual  bool         IsLinear() const;
  100. virtual  bool         IsSelfIntersecting()  const;
  101. PRIVATE_ACCESS
  102. };
  103. #define  sgCreateCircle  sgCCircle::Create
  104. /************************************************************************/
  105. /* ARC                                                                 */
  106. /************************************************************************/
  107. struct sgCore_API SG_ARC
  108. {
  109. double   radius;
  110. SG_VECTOR normal; 
  111. SG_POINT  center;
  112. SG_POINT  begin;
  113. SG_POINT  end;
  114. double    begin_angle;
  115. double    angle;
  116. // angle in degree = Arc->angle*180.0/PI
  117.     bool    FromThreePoints(const SG_POINT& begP,const SG_POINT& endP,
  118. const SG_POINT& midP,bool invert);
  119. bool    FromCenterBeginEnd(const SG_POINT& cenP,const SG_POINT& begP,
  120. const SG_POINT& endP, bool invert);
  121. bool    FromBeginEndNormalRadius(const SG_POINT& begP, const SG_POINT& endP,
  122. const SG_VECTOR& nrmlV, double rad, bool invert);
  123. bool    FromCenterBeginNormalAngle(const SG_POINT& cenP, const SG_POINT& begP,
  124. const SG_VECTOR& nrmlV, double ang);
  125. bool    FromBeginEndNormalAngle(const SG_POINT& begP, const SG_POINT& endP,
  126. const SG_VECTOR& nrmlV, double ang);
  127. bool    Draw(SG_DRAW_LINE_FUNC) const;
  128. };
  129. class sgCore_API   sgCArc : public sgC2DObject
  130. {
  131. private:
  132. sgCArc();
  133. sgCArc(SG_OBJ_HANDLE);
  134. virtual    ~sgCArc();
  135. SG_POINT*   m_points;
  136. int         m_points_count;
  137. public:
  138. static   sgCArc*      Create(const SG_ARC&);
  139. const    SG_ARC*      GetGeometry() const; 
  140. int               GetPointsCount() const;
  141. const    SG_POINT*    GetPoints() const;
  142. virtual  bool       ApplyTempMatrix();
  143. virtual  bool         IsClosed() const;
  144. virtual  bool         IsPlane(SG_VECTOR*,double*) const;
  145. virtual  bool         IsLinear() const;
  146. virtual  bool         IsSelfIntersecting()  const;
  147. PRIVATE_ACCESS
  148. };
  149. #define  sgCreateArc  sgCArc::Create
  150. /************************************************************************/
  151. /* SPLINE                                                               */
  152. /************************************************************************/
  153. class  sgCore_API SG_SPLINE
  154. {
  155. friend class sgCSpline;
  156. void*        m_handle;
  157. SG_POINT*    m_points;
  158. int  m_points_count;
  159. SG_POINT*    m_knots;
  160. int  m_knots_count;
  161. private:
  162. SG_SPLINE();
  163. SG_SPLINE(void*);
  164. ~SG_SPLINE();
  165. void                   Recalc();
  166. public:
  167. static   SG_SPLINE*    Create();
  168. static   void          Delete(SG_SPLINE*);
  169. bool                   AddKnot(const SG_POINT& pnt, int nmbr);
  170. bool                   MoveKnot(int nmbr, const SG_POINT& pnt);
  171. bool                   DeleteKnot(int nmbr);
  172. bool                   IsClosed() const;
  173. bool                   Close();
  174. bool                   UnClose(int);
  175. const    SG_POINT*     GetPoints() const;
  176. int                    GetPointsCount() const;
  177. const    SG_POINT*     GetKnots() const;
  178. int                    GetKnotsCount() const;
  179. };
  180. class sgCore_API   sgCSpline : public sgC2DObject
  181. {
  182. private:
  183. sgCSpline();
  184. sgCSpline(SG_OBJ_HANDLE);
  185. virtual    ~sgCSpline();
  186. private:
  187. SG_SPLINE*    m_spline_geo;
  188. public:
  189. static   sgCSpline*   Create(const SG_SPLINE&);
  190. const    SG_SPLINE*   GetGeometry() const;
  191. virtual  bool         IsClosed() const;
  192. virtual  bool         IsPlane(SG_VECTOR*,double*) const;
  193. virtual  bool         IsLinear() const;
  194. virtual  bool         IsSelfIntersecting()  const;
  195. virtual  bool   ApplyTempMatrix();
  196. PRIVATE_ACCESS
  197. };
  198. #define  sgCreateSpline  sgCSpline::Create
  199. /************************************************************************/
  200. /* Contour                                                                */
  201. /************************************************************************/
  202. class sgCore_API   sgCContour : public sgC2DObject
  203. {
  204. private:
  205. sgCContour();
  206. sgCContour(SG_OBJ_HANDLE);
  207. virtual    ~sgCContour();
  208. static   bool         TopologySort(sgCObject**, int);
  209. IObjectsList*         m_children;
  210. public:
  211. IObjectsList*         GetChildrenList() const;
  212. virtual  bool         SetAttribute(SG_OBJECT_ATTR_ID, unsigned short);
  213. virtual  bool       ApplyTempMatrix();
  214. virtual  bool         IsClosed() const;
  215. virtual  bool         IsPlane(SG_VECTOR*,double*) const;
  216. virtual  bool         IsLinear() const;
  217. virtual  bool         IsSelfIntersecting()  const;
  218. static   sgCContour*  CreateContour(sgCObject** objcts, int cnt);
  219. bool                  BreakContour(sgCObject** objcts);
  220. PRIVATE_ACCESS
  221. };
  222. #endif