-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWallAdapter.cpp
More file actions
472 lines (379 loc) · 16.1 KB
/
WallAdapter.cpp
File metadata and controls
472 lines (379 loc) · 16.1 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
#include "WallAdapter.hpp"
#include "IAttributeProxy.hpp"
#include "APICommon.h"
WallAdapter::WallAdapter (GSAPI::IAPIOutputManager* manager, GSAPI::IAPIOutputAdapterFactory* factory) :
GSAPI::IAPIOutputAdapter<API_WallType> (manager, factory)
{
}
WallAdapter::WallAdapter (const WallAdapter& adapter) :
GSAPI::IAPIOutputAdapter<API_WallType> (adapter)
{
}
WallAdapter::~WallAdapter ()
{
}
WallAdapter& WallAdapter::operator= (const WallAdapter& adapter)
{
static_cast<GSAPI::IAPIOutputAdapter<API_WallType>&> (*this) = adapter;
return (*this);
}
//
bool getZ (API_Gable g, double length, API_Coord3D& o, GS::OChannel& oChannel)
{
double l1, l2, lmin, lmax;
API_Vector origX, begL, endL;
origX.x = 1;
origX.y = 0;
begL.x = g.nx * g.xb;
begL.y = g.ny * g.xb;
endL.x = g.nx * g.xe;
endL.y = g.ny * g.xe;
// get the intersection distance along wall refline from origin to vertical limit plane
l1 = abs(g.xb) / ((origX.x * begL.x + origX.y * begL.y) /
(sqrt(pow(origX.x, 2) + pow(origX.y, 2)) * sqrt(pow(begL.x,2) + pow(begL.y,2))));
l2 = abs(g.xe) / ((origX.x * endL.x + origX.y * endL.y) /
(sqrt(pow(origX.x, 2) + pow(origX.y, 2)) * sqrt(pow(endL.x,2) + pow(endL.y,2))));
// sort limits
lmin = l1 <= l2 ? l1 : l2;
lmax = l1 >= l2 ? l1 : l2;
// get angle between vectors
// oChannel << "angle: " << RADDEG * acos((origX.x * begL.x + origX.y * begL.y) /
// (sqrt(pow(origX.x, 2) + pow(origX.y, 2)) * sqrt(pow(begL.x,2) + pow(begL.y,2)))) << "\n";
// get the intersection distance along wall refline from origin to vertical limit plane
// oChannel << "beg length: " << abs(g.xb) / ((origX.x * begL.x + origX.y * begL.y) /
// (sqrt(pow(origX.x, 2) + pow(origX.y, 2)) * sqrt(pow(begL.x,2) + pow(begL.y,2)))) << "\n";
// oChannel << "end length: " << abs(g.xe) / ((origX.x * endL.x + origX.y * endL.y) /
// (sqrt(pow(origX.x, 2) + pow(origX.y, 2)) * sqrt(pow(endL.x,2) + pow(endL.y,2)))) << "\n";
/*
// check if the point is lay in limits
if (length < lmin or length > lmax)
{
return false;
}
*/
// the point on the refline
o.x = length;
// the point is always lay on wall ref line
o.y = 0;
// get z-value of the plain in specified x,y coordinates;
o.z = (g.a * o.x + g.b * o.y - g.d) / -g.c;
return true;
}
double getPosOnRefline (double nx, double ny, double len)
{
API_Vector origX, begL;
origX.x = 1;
origX.y = 0;
begL.x = nx * len;
begL.y = ny * len;
return abs(len) / ((origX.x * begL.x + origX.y * begL.y) /
(sqrt(pow(origX.x, 2) + pow(origX.y, 2)) * sqrt(pow(begL.x,2) + pow(begL.y,2))));
}
double getPositionZ (API_Gable g, double pos)
{
// get z-value of the plain in specified x = pos, y=0 coordinates;
return (g.a * pos + g.b * 0 - g.d) / -g.c;
}
double getPositionX (API_Gable g, double height)
{
// get z-value of the plain in specified z = height, y=0 coordinates;
return (g.d - g.b * 0 - g.c * height) / g.a;
}
// get the intersection point of gable limits with wall refline and check pos to be in limits
bool checkPosGableLimit(API_Gable g, double pos)
{
double l1, l2, lmin, lmax;
API_Vector origX, begL, endL;
origX.x = 1;
origX.y = 0;
begL.x = g.nx * g.xb;
begL.y = g.ny * g.xb;
endL.x = g.nx * g.xe;
endL.y = g.ny * g.xe;
// get the intersection distance along wall refline from origin to vertical limit plane
l1 = abs(g.xb) / ((origX.x * begL.x + origX.y * begL.y) /
(sqrt(pow(origX.x, 2) + pow(origX.y, 2)) * sqrt(pow(begL.x,2) + pow(begL.y,2))));
l2 = abs(g.xe) / ((origX.x * endL.x + origX.y * endL.y) /
(sqrt(pow(origX.x, 2) + pow(origX.y, 2)) * sqrt(pow(endL.x,2) + pow(endL.y,2))));
// sort limits
lmin = l1 <= l2 ? l1 : l2;
lmax = l1 >= l2 ? l1 : l2;
// check if the point is lay in limits
if (pos < lmin or pos > lmax)
{
return false;
}
return true;
}
// convert point in local coordinate system to world coordinate system
// http://mathhelpplanet.com/static.php?p=pryeobrazovaniya-pryamougolnyh-koordinat
API_Coord3D localPointToWCS (API_Coord origin, double angle, API_Coord3D point)
{
API_Coord3D res;
res.x = origin.x + point.x * cos(angle) - point.y * sin(angle);
res.y = origin.y + point.x * sin(angle) + point.y * cos(angle);
res.z = point.z;
return res;
}
void WallAdapter::Output (GS::OChannel& oChannel)
{
if ((DBERROR (outputManager == nullptr)) || (DBERROR (outputAdapterFactory == nullptr)) || (DBERROR (element == nullptr)) || (DBERROR (dbInfo == nullptr))) {
return;
}
const API_PenType& pen = attributeProxy->GetProxiedAttribute (*dbInfo, API_PenID, element->contPen).pen;
API_ElementMemo memo;
GSErrCode err;
Int32 nGable = 0, nCoords, i, j, k;
BNZeroMemory (&memo, sizeof (API_ElementMemo));
err = ACAPI_Element_GetMemo (element->head.guid, &memo, APIMemoMask_Gables);
if (err != NoError) {
return;
}
//oChannel << "flipped: " << element->flipped << "\n";
if (memo.gables != nullptr) {
nGable = BMGetHandleSize ((GSHandle) memo.gables) / sizeof (API_Gable);
}
//oChannel << "nGable: " << nGable << "\n";
if (nGable > 0) {
double length;
GS::Array<API_Coord3D> coords, coordsTemp, coordsTempSorted;
// wall length
length = sqrt(pow(element->endC.x - element->begC.x, 2) + pow(element->endC.y - element->begC.y, 2));
// double a1, b1, c1, d1, a2, b2, c2, d2, z, x, x0, y0, z0, x1, y1, z1;
// a1 = (*memo.gables)[0].a;
// b1 = (*memo.gables)[0].b;
// c1 = (*memo.gables)[0].c;
// d1 = (*memo.gables)[0].d;
// a2 = (*memo.gables)[1].a;
// b2 = (*memo.gables)[1].b;
// c2 = (*memo.gables)[1].c;
// d2 = (*memo.gables)[1].d;
// x = (c1 * (-d2) - c2 * (-d1)) / (a1 * c2 - a2 * c1);
// z = (a2 * (-d1) - a1 * (-d2)) / (a1 * c2 - a2 * c1);
//z = (-d2 * a1 - a2 * (-d1))/(-a2 * (-c1) + c2 * a1);
// oChannel << "x: " << x << " z: " << z << "\n";
// x0 = 0;
// y0 = 0;
// z0 = (a2 * x0 + b2 * y0 - d2) / -c2;
// oChannel << "x0: " << x0 << " z0: " << z0 << "\n";
// x1 = length;
// y1 = 0;
// z1 = (a2 * x1 + b2 * y1 - d2) / -c2;
// oChannel << "x1: " << x1 << " z1: " << z1 << "\n";
// begin top coordinate world
API_Coord3D begT;
begT.x = element->begC.x;
begT.y = element->begC.y;
begT.z = element->height;
for (i = 0; i < nGable; i++) {
API_Coord3D o;
//oChannel << "g" << i << "\n";
//oChannel << getZ((*memo.gables)[i], 0, o, oChannel) << " z: " << o.z << "\n";
if (getZ((*memo.gables)[i], 0, o, oChannel))
{
if (o.z < begT.z)
begT.z = o.z;
}
}
// end top coordinate world
API_Coord3D endT;
endT.x = element->endC.x;
endT.y = element->endC.y;
endT.z = element->height;
for (i = 0; i < nGable; i++) {
API_Coord3D o;
//oChannel << "g" << i << "\n";
//oChannel << getZ((*memo.gables)[i], length, o, oChannel) << " z: " << o.z << "\n";
if (getZ((*memo.gables)[i], length, o, oChannel))
{
if (o.z < endT.z)
endT.z = o.z;
}
}
//
// loop over each gable and add points of gable limits to points array (checking for wall limits)
//
//oChannel << "wall length:" << length << "\n";
for (i = 0; i < nGable; i++) {
double xbRef, xeRef, xbRefZ, xeRefZ;
//oChannel << "g_" << i << ":\n";
//oChannel << "nx:" << (*memo.gables)[i].nx << "\n";
//oChannel << "ny:" << (*memo.gables)[i].ny << "\n";
//oChannel << "xb:" << (*memo.gables)[i].xb << "\n";
//oChannel << "xe:" << (*memo.gables)[i].xe << "\n";
xbRef = getPosOnRefline((*memo.gables)[i].nx, (*memo.gables)[i].ny, (*memo.gables)[i].xb);
//oChannel << "xbRef: " << xbRef << "\n";
if (xbRef > 0 and xbRef < length)
{
xbRefZ = getPositionZ((*memo.gables)[i], xbRef);
//oChannel << "xbRefZ: " << xbRefZ << "\n";
if (xbRefZ > element->bottomOffset and xbRefZ < element->height)
{
// add point to points array
//oChannel << "xbRef add\n";
API_Coord3D cT;
cT.x = xbRef;
cT.y = 0;
cT.z = xbRefZ;
coordsTemp.Push(cT);
}
}
xeRef = getPosOnRefline((*memo.gables)[i].nx, (*memo.gables)[i].ny, (*memo.gables)[i].xe);
//oChannel << "xeRef: " << xeRef << "\n";
if (xeRef > 0 and xeRef < length)
{
xeRefZ = getPositionZ((*memo.gables)[i], xeRef);
//oChannel << "xeRefZ: " << xeRefZ << "\n";
if (xeRefZ > element->bottomOffset and xeRefZ < element->height)
{
// add point to points array
//oChannel << "xeRef add\n";
API_Coord3D cT;
cT.x = xeRef;
cT.y = 0;
cT.z = xeRefZ;
coordsTemp.Push(cT);
}
}
}
//
// intersect height of the wall with each gable
for (i = 0; i < nGable; i++) {
double hx;
hx = getPositionX ((*memo.gables)[i], element->height);
// check position for wall limits
if (hx > 0 and hx < length)
{
// check position for gable limits
//oChannel << "checkPosGableLimit: " << checkPosGableLimit((*memo.gables)[i], hx) << "\n";
// if pos in limits add to points array
if(checkPosGableLimit((*memo.gables)[i], hx))
{
//oChannel << "hx add\n";
API_Coord3D cT;
cT.x = hx;
cT.y = 0;
cT.z = element->height;
coordsTemp.Push(cT);
}
}
}
// change coordinate systems
API_Vector vecU;
// TODO: check divide by zero
vecU.x = (element->endC.x-element->begC.x) / length;
vecU.y = (element->endC.y-element->begC.y) / length;
// oChannel << "wdC: " << wdC.x << " " << wdC.y << "\n";
//a = atan2d(x1*y2-y1*x2,x1*x2+y1*y2); // from web
// angle of the wall releted to horizontal unit vector -> x = 1
double aRad = atan2(1 * vecU.y - 0 * vecU.x, 1 * vecU.x + 0 * vecU.y);
// double aDeg = aRad * RADDEG;
// add begin point to array
coords.Push(begT);
// sort coordsTemp array
// coordsTempSorted
while (!coordsTemp.IsEmpty())
{
double tempX = coordsTemp[0].x;
int tempIndex = 0;
for (i = 1; i < coordsTemp.GetSize(); i++)
{
if (tempX > coordsTemp[i].x)
{
tempX = coordsTemp[i].x;
tempIndex = i;
}
}
//coordsTempSorted.Push(coordsTemp[tempIndex]);
//oChannel << "point x: " << coordsTemp[tempIndex].x << " y:" << coordsTemp[tempIndex].y << " z:" << coordsTemp[tempIndex].z << "\n";
// check point if it is near begin or end of the wall and skip it if so
// also check z value
if ((coordsTemp[tempIndex].x > 0.02 and coordsTemp[tempIndex].x < length - 0.02) or
(coordsTemp[tempIndex].x < 0.02 and abs(coordsTemp[tempIndex].z-begT.z) > 0.1) or
(coordsTemp[tempIndex].x > length - 0.02 and abs(coordsTemp[tempIndex].z-endT.z) > 0.1))
{
coords.Push(localPointToWCS(element->begC, aRad, coordsTemp[tempIndex]));
}
coordsTemp.Delete(tempIndex);
}
// add end point to array
coords.Push(endT);
//oChannel << "coords size: " << coords.GetSize() << "\n";
for (i = 0; i < coords.GetSize()-1; i++)
{
oChannel << "<line>\n" <<
"<asset refid=\"l1\"/>\n" <<
"<type>default_wall</type>\n" <<
"<points>" <<
coords[i].x << " " << coords[i].y * -1 << " " << element->bottomOffset << " " <<
coords[i+1].x << " " << coords[i+1].y * -1 << " " << element->bottomOffset << "," <<
coords[i].x << " " << coords[i].y * -1 << " " << element->bottomOffset+coords[i].z << " " <<
coords[i+1].x << " " << coords[i+1].y * -1 << " " << element->bottomOffset+coords[i+1].z << "</points>\n" <<
"<thickness>" << element->thickness << "</thickness>\n";
oChannel << "<balance>";
switch (element->referenceLineLocation)
{
case APIWallRefLine_Outside:
oChannel << (element->flipped ? "1" : "0");
break;
case APIWallRefLine_Inside:
oChannel << (element->flipped ? "0" : "1");
break;
case APIWallRefLine_Center:
default:
oChannel << "0.5";
break;
}
oChannel << "</balance>\n";
oChannel << "<color>#000000</color>\n" <<
"</line>\n";
}
}
else
{
/*
for (int i = (*memo.pends) [1-1] + 1; i < (*memo.pends) [1]; i++) {
oChannel <<
(*memo.coords) [i].x << " " << (*memo.coords) [i].y << "\n";
}
*/
oChannel << "<line>\n" <<
"<asset refid=\"l1\"/>\n" <<
"<type>default_wall</type>\n" <<
"<points>" <<
element->begC.x << " " << element->begC.y * -1 << " " << element->bottomOffset << " " <<
element->endC.x << " " << element->endC.y * -1 << " " << element->bottomOffset << "," <<
element->begC.x << " " << element->begC.y * -1 << " " << element->bottomOffset+element->height << " " <<
element->endC.x << " " << element->endC.y * -1 << " " << element->bottomOffset+element->height << "</points>\n" <<
"<thickness>" << element->thickness << "</thickness>\n";
oChannel << "<balance>";
switch (element->referenceLineLocation)
{
case APIWallRefLine_Outside:
oChannel << (element->flipped ? "1" : "0");
break;
case APIWallRefLine_Inside:
oChannel << (element->flipped ? "0" : "1");
break;
case APIWallRefLine_Center:
default:
oChannel << "0.5";
break;
}
oChannel << "</balance>\n";
oChannel << "<color>#000000</color>\n" <<
"</line>\n";
/*
oChannel << "Wall (guid:" << APIGuid2GSGuid (element->head.guid).ToUniString ().ToCStr () <<
" begC:(" << element->begC.x << ", " << element->begC.y << ")" <<
" endC:(" << element->endC.x << ", " << element->endC.y << ")" <<
" color:(R" << static_cast<int> (pen.rgb.f_red * 255.0) <<
", G" << static_cast<int> (pen.rgb.f_green * 255.0) <<
", B" << static_cast<int> (pen.rgb.f_blue * 255.0) << "))\n";
*/
}
}
void WallAdapter::operator>> (GS::OChannel& oChannel)
{
Output (oChannel);
}