-
Notifications
You must be signed in to change notification settings - Fork 41
/
CPolylineUtil.cpp
85 lines (73 loc) · 2.29 KB
/
CPolylineUtil.cpp
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
#include "stdafx.h"
#include "CPolylineUtil.h"
#include "CDwgDatebaseUtil.h"
#include <cmath>
#include "CEntityUtil.h"
#define PI 3.1415926
CPolylineUtil::CPolylineUtil()
{
}
CPolylineUtil::~CPolylineUtil()
{
}
AcDbObjectId CPolylineUtil::add(const AcGePoint2dArray & Points, double width)
{
int numVertices = Points.length();
AcDbPolyline *pPolyline = new AcDbPolyline(numVertices);
for (int i = 0; i < numVertices; i )
{
pPolyline->addVertexAt(i, Points.at(i), 0, width, width);
}
return CDwgDatebaseUtil::PostToModelSpace(pPolyline);
}
AcDbObjectId CPolylineUtil::add(const AcGePoint3dArray & Points)
{
AcGePoint3dArray verts = Points;
AcDb3dPolyline *pPolyline = new AcDb3dPolyline(AcDb::k3dSimplePoly, verts);
return CDwgDatebaseUtil::PostToModelSpace(pPolyline);
}
AcDbObjectId CPolylineUtil::addPolygon(AcGePoint2d & pCenterPoint, int number, double radius, double ratation, double width)
{
double angle = 2 * PI / number;
AcGePoint2dArray Points;
for (int i = 0; i < number; i )
{
AcGePoint2d pt;
pt.x = pCenterPoint.x radius * cos(i*angle);
pt.y = pCenterPoint.y radius * sin(i*angle);
Points.append(pt);
}
AcDbObjectId Polyid = add(Points, width);
AcDbEntity *pEntity;
Acad::ErrorStatus es;
es = acdbOpenObject(pEntity, Polyid, AcDb::kForWrite);
if (Acad::eOk==es)
{
if (pEntity->isKindOf(AcDbPolyline::desc()) == Adesk::kTrue)
{
AcDbPolyline *pPolyline = AcDbPolyline::cast(pEntity);
pPolyline->setClosed(Adesk::kTrue);
}
pEntity->close();
}
CEntityUtil::Rotate(Polyid, pCenterPoint, ratation);
return Polyid;
}
AcDbObjectId CPolylineUtil::addRect(const AcGePoint2d & Point1, const AcGePoint2d & Point2, double width)
{
double x1 = min(Point1.x, Point2.x);
double x2 = max(Point1.x, Point2.x);
double y1 = min(Point1.y, Point2.y);
double y2 = max(Point1.y, Point2.y);
AcGePoint2d LeftButtom(x1, y1);
AcGePoint2d LeftTop(x1, y2);
AcGePoint2d RightTop(x2, y2);
AcGePoint2d RightButtom(x2, y1);
AcDbPolyline *pPolyline = new AcDbPolyline(4);
pPolyline->addVertexAt(0, LeftButtom, 0, width, width);
pPolyline->addVertexAt(1, LeftTop, 0, width, width);
pPolyline->addVertexAt(2, RightTop, 0, width, width);
pPolyline->addVertexAt(3, RightButtom, 0, width, width);
pPolyline->setClosed(Adesk::kTrue);
return CDwgDatebaseUtil::PostToModelSpace(pPolyline);
}