1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
| #include "StdAfx.h" #include "CustomEntity1.h"
const double PI = 3.1415926; Adesk::UInt32 CustomEntity1::kCurrentVersionNumber =1 ;
ACRX_DXF_DEFINE_MEMBERS ( CustomEntity1, AcDbEntity, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, AcDbProxyEntity::kNoOperation, USTOMENTITY1, LHMYCUSTOMENTITYAPP |Product Desc: A description for your object |Company: Your company name |WEB Address: Your company WEB site address )
CustomEntity1::CustomEntity1 () : AcDbEntity () { this->center = AcGePoint3d(0, 0, 0); this->R1 = 1000; this->R2 = 50; this->N = 8; }
CustomEntity1::~CustomEntity1 () {}
void CustomEntity1::set(AcGePoint3d center, double R1, double R2, int N){ this->center = center; this->R1 = R1; this->R2 = R2; this->N = N; }
Acad::ErrorStatus CustomEntity1::dwgOutFields (AcDbDwgFiler *pFiler) const { assertReadEnabled(); Acad::ErrorStatus es = AcDbEntity::dwgOutFields(pFiler); if (es != Acad::eOk) return (es); if ((es = pFiler->writeUInt32(CustomEntity1::kCurrentVersionNumber)) != Acad::eOk) return (es); es = pFiler->writeDouble(R1); if (Acad::eOk != es) return es; es = pFiler->writeDouble(R2); if (Acad::eOk != es) return es; es = pFiler->writeInt32(N); if (Acad::eOk != es) return es; es = pFiler->writePoint3d(center); if (Acad::eOk != es) return es; return (pFiler->filerStatus()); }
Acad::ErrorStatus CustomEntity1::dwgInFields (AcDbDwgFiler *pFiler) { assertWriteEnabled(); Acad::ErrorStatus es = AcDbEntity::dwgInFields(pFiler); if (es != Acad::eOk) return (es); Adesk::UInt32 version = 0; if ((es = pFiler->readUInt32(&version)) != Acad::eOk) return (es); if (version > CustomEntity1::kCurrentVersionNumber) return (Acad::eMakeMeProxy); es = pFiler->readDouble(&R1); if (Acad::eOk != es) return es; es = pFiler->readDouble(&R2); if (Acad::eOk != es) return es; es = pFiler->readInt32(&N); if (Acad::eOk != es) return es; es = pFiler->readPoint3d(¢er); if (Acad::eOk != es) return es; return (pFiler->filerStatus()); }
Adesk::Boolean CustomEntity1::subWorldDraw (AcGiWorldDraw *mode) { assertReadEnabled(); mode->geometry().circle(center, R1, AcGeVector3d(0, 0, 1)); for (int i = 0; i < N; i++) { double x1 = center.x + R1 * cos(2 * PI / N * i); double y1 = center.y + R1 * sin(2 * PI / N * i); mode->geometry().circle(AcGePoint3d(x1, y1, 0), R2, AcGeVector3d(0, 0, 1)); } AcDbText* text = new AcDbText(); text->setPosition(center); text->setTextString(L"测试"); text->setHeight(R1 / 10); text->setColorIndex(1); text->worldDraw(mode); return Adesk::kTrue; }
Acad::ErrorStatus CustomEntity1::subGetGeomExtents(AcDbExtents& extents) const { assertReadEnabled(); for (int i = 0; i < N; i++) { double x1 = center.x + R1 * cos(2 * PI / N * i); double y1 = center.y + R1 * sin(2 * PI / N * i); extents.addPoint(AcGePoint3d(x1 + R2, y1 + R2, 0)); extents.addPoint(AcGePoint3d(x1 + R2, y1 - R2, 0)); extents.addPoint(AcGePoint3d(x1 - R2, y1 + R2, 0)); extents.addPoint(AcGePoint3d(x1 - R2, y1 - R2, 0)); } AcDbText* text = new AcDbText(); text->setPosition(center); text->setTextString(L"测试"); text->setHeight(R1 / 10); text->setColorIndex(1); AcDbExtents ext; text->getGeomExtents(ext); extents.addExt(ext); return Acad::eOk; }
Acad::ErrorStatus CustomEntity1::subTransformBy(const AcGeMatrix3d& xform) { assertWriteEnabled(); center.transformBy(xform); double scale = xform.scale(); R1 *= scale; R2 *= scale; return Acad::eOk; }
Acad::ErrorStatus CustomEntity1::subGetGripPoints(AcGePoint3dArray& gripPoints, AcDbIntArray& osnapModes, AcDbIntArray& geomIds) const { assertReadEnabled(); gripPoints.append(center); return Acad::eOk; }
Acad::ErrorStatus CustomEntity1::subMoveGripPointsAt(const AcDbIntArray& indices, const AcGeVector3d& offset) { assertWriteEnabled(); for (int i = 0; i < indices.length(); i++) { switch (indices[i]) { case 0: center += offset; break; } } return Acad::eOk; }
Acad::ErrorStatus CustomEntity1::subExplode(AcDbVoidPtrArray& entitySet) const { assertReadEnabled(); AcDbCircle* circle = new AcDbCircle(center, AcGeVector3d(0, 0, 1), R1); entitySet.append(circle); for (int i = 0; i < N; i++) { double x1 = center.x + R1 * cos(2 * PI / N * i); double y1 = center.y + R1 * sin(2 * PI / N * i); AcDbCircle* subCircle = new AcDbCircle(AcGePoint3d(x1, y1, 0), AcGeVector3d(0, 0, 1), R2); entitySet.append(subCircle); } AcDbText* text = new AcDbText(); text->setPosition(center); text->setTextString(L"测试"); text->setHeight(R1 / 10); text->setColorIndex(1); entitySet.append(text); return Acad::eOk; }
|