-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathCViewUtil.cpp
More file actions
186 lines (152 loc) · 4.58 KB
/
CViewUtil.cpp
File metadata and controls
186 lines (152 loc) · 4.58 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include "stdafx.h"
#include "CViewUtil.h"
#include "dbapserv.h"
#include "AcDbLMgr.h"
CViewUtil::CViewUtil()
{
}
CViewUtil::~CViewUtil()
{
}
void CViewUtil::GetCurrentView(AcDbViewTableRecord & view)
{
resbuf rb;
resbuf wcs, ucs, dcs;
wcs.restype = RTSHORT;
wcs.resval.rint = 0;
ucs.restype = RTSHORT;
ucs.resval.rint = 1;
dcs.restype = RTSHORT;
dcs.resval.rint = 2;
//获得当前适口的“查看”模式
acedGetVar(_T("VIEWMODE"), &rb);
view.setPerspectiveEnabled((rb.resval.rint & 1) != 0);
view.setFrontClipEnabled((rb.resval.rint & 2) != 0);
view.setBackClipEnabled((rb.resval.rint & 4) != 0);
view.setFrontClipAtEye((rb.resval.rint & 16) == 0);
//当前视口中视图的中心点
acedGetVar(_T("VIEWCTR"), &rb);
acedTrans(rb.resval.rpoint, &ucs, &dcs, 0, rb.resval.rpoint);
view.setCenterPoint(AcGePoint2d(rb.resval.rpoint[X], rb.resval.rpoint[Y]));
//........
//.......
}
void CViewUtil::Create4ViewPort()
{
AcDbViewportTable *pViewPortTable = NULL;
acdbHostApplicationServices()->workingDatabase()->getViewportTable(pViewPortTable, AcDb::kForWrite);
AcGePoint2d p1(0, 0);
AcGePoint2d p2(0.5, 0.5);
AcDbViewportTableRecord *pViewPortRecord1 =new AcDbViewportTableRecord();
pViewPortRecord1->setLowerLeftCorner(p1);
pViewPortRecord1->setUpperRightCorner(p2);
p1.set(0.5, 0);
p1.set(1, 0.5);
AcDbViewportTableRecord *pViewPortRecord2 = new AcDbViewportTableRecord();
pViewPortRecord2->setLowerLeftCorner(p1);
pViewPortRecord2->setUpperRightCorner(p2);
p1.set(0, 0.5);
p1.set(0.5,1);
AcDbViewportTableRecord *pViewPortRecord3 = new AcDbViewportTableRecord();
pViewPortRecord3->setLowerLeftCorner(p1);
pViewPortRecord3->setUpperRightCorner(p2);
p1.set(0.5, 0.5);
p1.set(1, 1);
AcDbViewportTableRecord *pViewPortRecord4 = new AcDbViewportTableRecord();
pViewPortRecord4->setLowerLeftCorner(p1);
pViewPortRecord4->setUpperRightCorner(p2);
pViewPortTable->add(pViewPortRecord1);
pViewPortTable->add(pViewPortRecord2);
pViewPortTable->add(pViewPortRecord3);
pViewPortTable->add(pViewPortRecord4);
pViewPortTable->close();
pViewPortRecord1->close();
pViewPortRecord2->close();
pViewPortRecord3->close();
pViewPortRecord4->close();
//判断当前空间
resbuf rb;
acedGetVar(_T("TILEMODE"), &rb);
//当前工作空间是模型空间
if (rb.resval.rint==1)
{
}
else
{
}
}
void CViewUtil::CreateViewPortInSpace()
{
Acad::ErrorStatus es;
es = acdbHostApplicationServices()->layoutManager()->setCurrentLayout(_T("布局1"));
if (es!=Acad::eOk)
{
return;
}
AcDbBlockTable *pBlockTable = NULL;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord = NULL;
pBlockTable->getAt(ACDB_PAPER_SPACE, pBlockTableRecord,AcDb::kForWrite);
AcDbViewport *pViewPort = new AcDbViewport();
pViewPort->setCenterPoint(AcGePoint3d(100, 50, 0));
pViewPort->setHeight(80);
pViewPort->setWidth(120);
AcDbObjectId objectid;
pBlockTableRecord->appendAcDbEntity(objectid, pViewPort);
pBlockTable->close();
pBlockTableRecord->close();
pViewPort->close();
//将新建的视图作为当前视图
AcDbViewport *pVP = NULL;
if (acdbOpenObject(pVP,objectid,AcDb::kForWrite)==Acad::eOk)
{
pVP->setOn();
acedSetCurrentVPort(pVP);
pVP->close();
}
}
void CViewUtil::NewUCS()
{
TCHAR UCSName[40];
if (acedGetString(NULL,_T("输入要创建的UCS名称: "),UCSName)!=RTNORM)
{
return;
}
AcDbUCSTable *pUCSTable = NULL;
acdbHostApplicationServices()->workingDatabase()->getUCSTable(pUCSTable,AcDb::kForWrite);
AcDbUCSTableRecord *pUCSTableRecord = new AcDbUCSTableRecord();
AcGePoint3d OriginPoint(0, 0, 0);
AcGeVector3d Xaxis(1, 1, 0);
AcGeVector3d Yaxis(-1, 1, 0);
pUCSTableRecord->setName(UCSName);
pUCSTableRecord->setOrigin(OriginPoint);
pUCSTableRecord->setXAxis(Xaxis);
pUCSTableRecord->setYAxis(Yaxis);
pUCSTable->add(pUCSTableRecord);
pUCSTable->close();
pUCSTableRecord->close();
}
void CViewUtil::SetCurrentUCS()
{
TCHAR UCSName[40];
if (acedGetString(NULL,_T("输入要设置为当前UCS坐标系的名称: "),UCSName)!=RTNORM)
{
return;
}
AcDbUCSTable *pUCSTable = NULL;
acdbHostApplicationServices()->workingDatabase()->getUCSTable(pUCSTable, AcDb::kForRead);
if (pUCSTable->has(UCSName))
{
AcDbUCSTableRecord *pUCSTableRecord = NULL;
pUCSTable->getAt(UCSName, pUCSTableRecord, AcDb::kForWrite);
AcGePoint3d OriginPoint = pUCSTableRecord->origin();
AcGeVector3d XAxis = pUCSTableRecord->xAxis();
AcGeVector3d YAxis = pUCSTableRecord->yAxis();
AcGeVector3d ZAxis = XAxis.crossProduct(YAxis);
pUCSTableRecord->close();
AcGeMatrix3d mat;
mat.setCoordSystem(OriginPoint, XAxis, YAxis, ZAxis);
acedGetCurrentUCS(mat);
}
pUCSTable->close();
}