天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 120|回复: 0

OBJECT ARX 绘制道路横切面 实例

[复制链接]
  • TA的每日心情
    开心
    昨天 06:36
  • 签到天数: 15 天

    [LV.4]偶尔看看III

    105

    主题

    11

    回帖

    1308

    积分

    管理员

    积分
    1308
    QQ
    发表于 2024-5-2 22:42:33 | 显示全部楼层 |阅读模式
    1. //-----------------------------------------------------------------------------
    2. //----- acrxEntryPoint.cpp
    3. //-----------------------------------------------------------------------------
    4. #include "StdAfx.h"
    5. #include "resource.h"
    6. //-----------------------------------------------------------------------------
    7. #define szRDS 采用RXST("HY")
    8. const double BORDEROFFSET = 5 ;边线距离端点2mm
    9. const double BANDER1PTCOUNT = 4;//1块板交点数量
    10. const double BANDER2PTCOUNT = 6;//2块板交点数量
    11. const double BANDER3PTCOUNT = 8;//3块板交点数量
    12. const double BANDER4PTCOUNT = 10;//4块板交点数量
    13. const double PI = 3.1415926536;
    14. //-----------------------------------------------------------------------------
    15. //----- ObjectARX EntryPoint
    16. class CArxProject3App : public AcRxArxApp
    17. {
    18. public:
    19. CArxProject3App () : AcRxArxApp () {}
    20. virtual AcRx::AppRetCode On采用kInitAppMsg (void *pkt)
    21. {
    22. // TODO: Load dependencies here.
    23. // You *must* call On采用kInitAppMsg here
    24. AcRx::AppRetCode retCode =AcRxArxApp::On采用kInitAppMsg (pkt) ;
    25. // TODO: Add your initialization code here
    26. return (retCode) ;
    27. }
    28. virtual AcRx::AppRetCode On采用kUnloadAppMsg (void *pkt)
    29. {
    30. // TODO: Add your code here
    31. // You *must* call On采用kUnloadAppMsg here
    32. AcRx::AppRetCode retCode =AcRxArxApp::On采用kUnloadAppMsg (pkt) ;
    33. // TODO: Unload dependencies here
    34. return (retCode) ;
    35. }
    36. virtual void RegisterServerComponents ()
    37. {
    38. }
    39. //加载一个实体到数据库,返回实体ID,是否关闭实体
    40. static AcDbObjectId LoadEntity(AcDbEntity* entity,bool autoClose)
    41. {
    42. AcDbBlockTable* pBlockTable;
    43. acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable,AcDb::kForRead);
    44. AcDbBlockTableRecord* pBlockTableRecord;
    45. pBlockTable->getAt(ACDB采用MODEL采用SPACE,pBlockTableRecord,AcDb::kForWrite);
    46. AcDbObjectId Id;
    47. pBlockTableRecord->appendAcDbEntity(Id,entity);
    48. pBlockTable->close();
    49. pBlockTableRecord->close();
    50. if(autoClose)
    51. {
    52. entity->close();
    53. }
    54. return Id;
    55. }
    56. 插入文字
    57. 参数依次为:X,Y,Z坐标
    58. 要插入的文字
    59. 文字大小
    60. static void InsertText(double x,double y,double z,CString strTxt,double weight)
    61. {
    62. 默认不做旋转不加粗
    63. InsertText(x,y,z,strTxt,weight,0,0,AcDb::TextHorzMode::kTextMid,AcDb::TextVertMode::kTextBottom);
    64. }
    65. 插入文字
    66. 参数依次为:X,Y,Z坐标
    67. 要插入的文字
    68. 文字高度
    69. 文字旋转角度
    70. 文字加粗大小
    71. 横向显示的模式
    72. 纵向显示模式
    73. static void InsertText(double x,double y,double z,CString strTxt,double height,double rotation,
    74. double size,AcDb::TextHorzMode hm,AcDb::TextVertMode vm)
    75. {
    76. AcGePoint3d ptInsert(x,y,z);
    77. AcDbText* pText = new AcDbText(ptInsert,strTxt,AcDbObjectId::kNull,height,rotation);
    78. 注意这里的先后顺序,要先设置停靠的模式后设置停靠坐标,否则赋值不上去
    79. pText->setHorizontalMode(hm);
    80. pText->setVerticalMode(vm);
    81. pText->setAlignmentPoint(ptInsert);
    82. 设置加粗比例
    83. pText->setWidthFactor(size);
    84. LoadEntity(pText,true);
    85. }
    86. //显示道路的详细信息
    87. 参数依次:道路宽度数组,道路名称,显示比例
    88. static void ShowRoadDetail(AcGeDoubleArray& roadArr,const CString& strName,double ratio)
    89. {
    90. 选择显示的位置
    91. ads采用point ptInput;
    92. if(acedGetPoint(NULL,采用T("\n选择显示断面符号的位置"),ptInput) != RTNORM)
    93. {
    94. return;
    95. }
    96. AcGePoint2d ptDetail;
    97. ptDetail = asPnt2d(ptInput);
    98. AcDbPolyline* pl = new AcDbPolyline();绘制表格上部分
    99. AcDbPolyline* pl2 = new AcDbPolyline();表格中间部分
    100. AcDbPolyline* plMid = new AcDbPolyline();表格中间线
    101. AcDbPolyline* pl3 = new AcDbPolyline();表格底部直线
    102. double totalRoad = 0.0;
    103. int len = roadArr.length();
    104. for (int i = 0;i < len; i++)
    105. {
    106. roadArr.setAt(i,roadArr.at(i) * ratio);
    107. }
    108. pl->addVertexAt(0,ptDetail);
    109. 左边斜线
    110. ptDetail.set(ptDetail[X] + BORDEROFFSET,ptDetail[Y] - BORDEROFFSET);
    111. pl->addVertexAt(1,ptDetail);
    112. 左边竖线
    113. ptDetail.set(ptDetail[X] ,ptDetail[Y] - 2 * BORDEROFFSET);
    114. pl->addVertexAt(2,ptDetail);
    115. int index = 2;
    116. bool isUp = true;先高后低
    117. for(int i = 0;i < len;i ++)
    118. {
    119. double road = roadArr.at(i);
    120. totalRoad += road;
    121. index ++;
    122. ptDetail.set(ptDetail[X] + road,ptDetail[Y]);
    123. pl->addVertexAt(index,ptDetail);
    124. if(i != len - 1)
    125. {
    126. index ++;
    127. if(isUp)凹进去
    128. {
    129. ptDetail.set(ptDetail[X],ptDetail[Y] - BORDEROFFSET / 4);
    130. pl->addVertexAt(index,ptDetail);
    131. isUp = false;
    132. }
    133. else凸起来
    134. {
    135. ptDetail.set(ptDetail[X],ptDetail[Y] + BORDEROFFSET / 4);
    136. pl->addVertexAt(index,ptDetail);
    137. isUp = true;
    138. }
    139. }
    140. }
    141. index++;
    142. 右边竖线
    143. ptDetail.set(ptDetail[X],ptDetail[Y] + 2* BORDEROFFSET);
    144. pl->addVertexAt(index,ptDetail);
    145. index ++;
    146. 右边斜线
    147. ptDetail.set(ptDetail[X] + BORDEROFFSET,ptDetail[Y] + BORDEROFFSET);
    148. pl->addVertexAt(index,ptDetail);
    149. //绘制表格中部---------------
    150. ptDetail.set(ptDetail[X] - BORDEROFFSET,ptDetail[Y] - 3.5 * BORDEROFFSET);
    151. pl2->addVertexAt(0,ptDetail);
    152. index = 1;
    153. for(int i = 0;i < len; i++)
    154. {
    155. double road = roadArr.at(len - i - 1);
    156. 右边线
    157. ptDetail.set(ptDetail[X],ptDetail[Y] - 3 * BORDEROFFSET);
    158. pl2->addVertexAt(index,ptDetail);
    159. index ++;
    160. 车道
    161. ptDetail.set(ptDetail[X]-road,ptDetail[Y]);
    162. pl2->addVertexAt(index,ptDetail);
    163. index++;
    164. 左边线
    165. ptDetail.set(ptDetail[X],ptDetail[Y] + 3 * BORDEROFFSET);
    166. pl2->addVertexAt(index,ptDetail);
    167. index ++;
    168. }
    169. //绘制中间线---------两边各多出1BORDEROFFSET----------
    170. ptDetail.set(ptDetail[X]- BORDEROFFSET,ptDetail[Y] - 3 * BORDEROFFSET);
    171. plMid->addVertexAt(0,ptDetail);
    172. ptDetail.set(ptDetail[X]+ 2 * BORDEROFFSET + totalRoad,ptDetail[Y]);
    173. plMid->addVertexAt(1,ptDetail);
    174. //绘制文字-------距离底部.25border文字宽度0.5BORDER---------------------
    175. double fontSize = BORDEROFFSET * 0.3;
    176. ptDetail.set(ptDetail[X] - BORDEROFFSET,ptDetail[Y] + 0.5 * BORDEROFFSET);
    177. double curRoad = 0.0;
    178. double latRoad = 0.0;
    179. double offset = 0.0;
    180. for(int i = 0;i < len;i ++)
    181. {
    182. latRoad = curRoad;
    183. curRoad = roadArr.at(len - i - 1);
    184. double offset = (curRoad + latRoad) / 2;
    185. CString strSize;
    186. double r = curRoad/ratio;
    187. strSize.Format(采用T("%.1f"),r);
    188. ptDetail.set(ptDetail[X] - offset,ptDetail[Y]);
    189. InsertText(ptDetail[X],ptDetail[Y],0,strSize,fontSize);
    190. }
    191. //绘制底线-------高度2border----------------
    192. double fstRoad = roadArr.at(0);
    193. ptDetail.set(ptDetail[X] - fstRoad/ 2 - BORDEROFFSET ,ptDetail[Y] - 2.25 * BORDEROFFSET);
    194. pl3->addVertexAt(0,ptDetail);
    195. ptDetail.set(ptDetail[X] + BORDEROFFSET,ptDetail[Y]);
    196. pl3->addVertexAt(1,ptDetail);
    197. ptDetail.set(ptDetail[X],ptDetail[Y] + 2 * BORDEROFFSET);
    198. pl3->addVertexAt(2,ptDetail);
    199. ptDetail.set(ptDetail[X],ptDetail[Y] - 2 * BORDEROFFSET);
    200. pl3->addVertexAt(3,ptDetail);
    201. ptDetail.set(ptDetail[X] + totalRoad,ptDetail[Y]);
    202. pl3->addVertexAt(4,ptDetail);
    203. ptDetail.set(ptDetail[X],ptDetail[Y] + 2 * BORDEROFFSET);
    204. pl3->addVertexAt(5,ptDetail);
    205. ptDetail.set(ptDetail[X],ptDetail[Y] - 2 * BORDEROFFSET);
    206. pl3->addVertexAt(6,ptDetail);
    207. ptDetail.set(ptDetail[X] + BORDEROFFSET,ptDetail[Y]);
    208. pl3->addVertexAt(7,ptDetail);
    209. 绘制底部文字
    210. ptDetail.set(ptDetail[X]- BORDEROFFSET - (totalRoad) / 2 ,ptDetail[Y] + 0.5 * BORDEROFFSET);
    211. CString strTotal;
    212. strTotal.Format(采用T("%.1f"),totalRoad/ratio);
    213. InsertText(ptDetail[X],ptDetail[Y],0,strTotal,fontSize);
    214. 最下面,显示出截面的名称
    215. CString str;
    216. str.Format(采用T("%s-%s"),strName,strName);
    217. ptDetail.set(ptDetail[X] ,ptDetail[Y] - 2.25 * BORDEROFFSET);
    218. InsertText(ptDetail[X],ptDetail[Y],0,str, 4 * fontSize,0,1,AcDb::TextHorzMode::kTextMid,AcDb::TextVertMode::kTextBottom);
    219. LoadEntity(pl,true);
    220. LoadEntity(pl2,true);
    221. LoadEntity(plMid,true);
    222. LoadEntity(pl3,true);
    223. }
    224. 遍历曲线实体,取出XDATA,判断strName是否已存在其他曲线的XDATA中
    225. static bool XDataIsExist(const CString& strName)
    226. {
    227. ads采用name ssName;选择集名称
    228. 添加过滤条件
    229. resbuf* filter = acutBuildList(-3, 1001, 采用T("RNAME"), 0);
    230. acedSSGet(采用T("X"),NULL,NULL,filter,ssName);
    231. long len = 0;
    232. acedSSLength(ssName,&len);
    233. ads采用name entName;
    234. AcDbObjectId id;
    235. AcDbEntity* pEnt = NULL;
    236. AcDbCurve* pCur = NULL;
    237. CString outS;
    238. for (int i=0;i<len;i++)
    239. {
    240. if (acedSSName(ssName, i, entName) != RTNORM)
    241. {
    242. continue;
    243. }
    244. acdbGetObjectId(id,entName);
    245. 以读模式打开,根据ID索引到对象,并打开ENTITY
    246. acdbOpenObject(pEnt,id,AcDb::OpenMode::kForRead);
    247. if (!pEnt->isKindOf(AcDbCurve::desc()))
    248. {
    249. continue;
    250. }
    251. pCur = (AcDbCurve*)pEnt;
    252. struct resbuf* rb;
    253. rb = pCur->xData(采用T("RNAME"));
    254. if(rb == NULL)
    255. {
    256. continue;
    257. }
    258. struct resbuf* pTemp;
    259. pTemp = rb;
    260. 首先要跳过应用程序名称
    261. pTemp = pTemp->rbnext;
    262. if(pTemp!= NULL && pTemp->restype ==  AcDb::kDxfXdAsciiString && pTemp->resval.rstring !=NULL)
    263. {
    264. CString str1(pTemp->resval.rstring);
    265. if(str1.Compare(strName) == 0)
    266. {
    267. return true;
    268. }
    269. }
    270. acutRelRb(rb);
    271. pCur->close();
    272. }
    273. acedSSFree(ssName);
    274. return false;
    275. }
    276. //把横截面名称保存到扩展数据中
    277. 参数:多段线实体,名称
    278. static void SavePlineXData(AcDbCurve* pLine,const CString strName)
    279. {
    280. //扩展数据的内容
    281. struct resbuf* pRb;
    282. 注册应用程序名称
    283. acdbRegApp(采用T("RNAME"));
    284. CString strAppName(采用T("RNAME"));
    285. 创建结果缓冲区链表
    286. pRb = acutBuildList(
    287. AcDb::kDxfRegAppName,strAppName,
    288. kDxfXdAsciiString,strName,
    289. RTNONE);
    290. 添加扩展数据
    291. struct resbuf* pTemp ;
    292. pTemp = pLine->xData(采用T("RNAME"));
    293. //如果已经包含扩展数据,不再重复添加
    294. if (pTemp != NULL)
    295. {
    296. acutRelRb(pTemp);
    297. acutPrintf(采用T("它已经包含了扩展数据"));
    298. }
    299. else
    300. {
    301. pLine->setXData(pRb);
    302. acutPrintf(采用T("\n扩展数据已赋值"));
    303. }
    304. acutRelRb(pRb);
    305. }
    306. 显示扩展数据
    307. 参数:多段线实体
    308. static void ViewPlineXData(AcDbCurve* pLine)
    309. {
    310. struct resbuf* pRb;
    311. pRb = pLine->xData(采用T("RNAME"));
    312. if (pRb != NULL)
    313. {
    314. 在命令行显示所有的扩展数据
    315. struct resbuf* pTemp;
    316. pTemp = pRb;
    317. 首先要跳过应用程序名称
    318. pTemp = pTemp->rbnext;
    319. acutPrintf(采用T("\n横截面的名称是:%s\n"),pTemp->resval.rstring);
    320. acutRelRb(pRb);
    321. }
    322. else
    323. {
    324. acutPrintf(采用T("\n此实体没有任何扩展数据.\n"));
    325. }
    326. }
    327. 给图形实体,返回与选择的点之间的,与这个直线实体相交的交点数组、直线方向向量
    328. 参数:曲线实体,指定选择的点集,放到resbuf里面,2dpoint数组,三维向量
    329. static void GetLineNum(AcDbCurve* pLine,resbuf* ptLst,AcGePoint3dArray& ptArr,AcGeVector3d& v,double& roadWidth,bool& success)
    330. {
    331. 遍历所有实体
    332. ads采用name ssName;选择集名称
    333. acedSSGet(采用T("F"),ptLst,NULL,NULL,ssName);
    334. long len = 0;
    335. acedSSLength(ssName,&len);
    336. if(len == 0)
    337. {
    338. success = false;
    339. return;
    340. }
    341. ads采用name entName;
    342. AcDbObjectId id;
    343. AcDbEntity* pEnt = NULL;
    344. AcDbCurve* pCur = NULL;
    345. AcGePoint3dArray ptSecArr;交点集合
    346. AcGePoint3d ptMin(0,0,0);
    347. AcGePoint3d ptMax(0,0,0);
    348. AcDbCurve* pMaxCur = NULL;
    349. for (int i=0;i<len;i++)
    350. {
    351. if (acedSSName(ssName, i, entName) != RTNORM)
    352. {
    353. continue;
    354. }
    355. 根据名称得到ID
    356. acdbGetObjectId(id,entName);
    357. 以读模式打开,根据ID索引到对象,并打开ENTITY
    358. acdbOpenObject(pEnt,id,AcDb::OpenMode::kForRead);
    359. if (pEnt == NULL || !pEnt->isKindOf(AcDbCurve::desc()))
    360. {
    361. continue;
    362. }
    363. pCur = (AcDbCurve*)pEnt;
    364. pCur->intersectWith(pLine,AcDb::Intersect::kOnBothOperands,ptSecArr);
    365. if (ptSecArr.length() <= 0)
    366. {
    367. continue;
    368. }
    369. 拿出第一个交点(两直线相交只可能有这一个交点)
    370. AcGePoint3d pt3d (ptSecArr.at(0));
    371. 添加交点
    372. ptArr.append(pt3d);
    373. ptSecArr.removeAll();
    374. pCur->getFirstDeriv(pt3d,v);
    375. if(i == 0)
    376. {
    377. ptMin = ptArr.at(0);
    378. ptMax = ptArr.at(0);
    379. pMaxCur = pCur;
    380. }
    381. else
    382. {
    383. if(ptMin[X] > pt3d[X])
    384. {
    385. ptMin = pt3d;
    386. }
    387. else if(ptMin[X] == pt3d[X])
    388. {
    389. if(ptMin[Y] > pt3d[Y])
    390. {
    391. ptMin = pt3d;
    392. }
    393. }
    394. if(ptMax[X] < pt3d[X])
    395. {
    396. ptMax = pt3d;
    397. pMaxCur = pCur;
    398. }
    399. else if(ptMax[X] == pt3d[X])
    400. {
    401. if(ptMax[Y] < pt3d[Y])
    402. {
    403. ptMax = pt3d;
    404. pMaxCur = pCur;
    405. }
    406. }
    407. }
    408. }
    409. pMaxCur->getClosestPointTo(ptMin,ptMax);
    410. roadWidth = ptMax.distanceTo(ptMin);
    411. acutPrintf(采用T("road width is %.2f"),roadWidth);
    412. pMaxCur->close();
    413. success = true;
    414. 要及时释放选择集,一共只能同时打开128个选择集
    415. acedSSFree(ssName);
    416. }
    417. 对2dpoint数组排序,默认为X坐标从左到右,如果竖直,Y坐标从下到上
    418. static void Sort2dArr(AcGePoint3dArray& arr,bool isHorizon)
    419. {
    420. double len = arr.length();
    421. 对于竖直情况,对Y坐标进行排序
    422. if(!isHorizon)
    423. {
    424. for (int i = len - 1;i > 0; i --)
    425. {
    426. for(int j = 0;j < i; j++)
    427. {
    428. double preY = arr.at(j)[Y];
    429. double latY = arr.at(j + 1)[Y];
    430. if(preY > latY)
    431. {
    432. arr.swap(j,j+1);
    433. }
    434. }
    435. }
    436. }
    437. else
    438. {
    439. for (int i = len - 1;i > 0; i --)
    440. {
    441. for(int j = 0;j < i; j++)
    442. {
    443. double preX = arr.at(j)[X];
    444. double latX = arr.at(j + 1)[X];
    445. if(preX > latX)
    446. {
    447. arr.swap(j,j+1);
    448. }
    449. }
    450. }
    451. }
    452. }
    453. 画道路测试命令
    454. static void TESTroadcmd()
    455. {
    456. 输入坐标部分==============================
    457. ads采用point inputStart;
    458. ads采用point inputEnd;
    459. AcGePoint2d ptStart;
    460. AcGePoint2d ptEnd;
    461. 用户输入要画的坐标
    462. if (acedGetPoint(NULL,采用T("\n起始点:"),inputStart) != RTNORM)
    463. {
    464. acutPrintf(采用T("\n未指定起始点"));
    465. return;
    466. }
    467. ptStart = asPnt2d(inputStart);
    468. if (acedGetPoint(NULL,采用T("\n终点:"),inputEnd) != RTNORM)
    469. {
    470. acutPrintf(采用T("\n未指定终点"));
    471. return;
    472. }
    473. ptEnd = asPnt2d(inputEnd);
    474. resbuf* ptList = NULL;
    475. ptList = acutBuildList(RTPOINT,ptStart,RTPOINT,ptEnd,NULL);
    476. 这条线求交点,不用画出来
    477. AcDbPolyline* pLine = new AcDbPolyline();
    478. pLine->addVertexAt(0,ptStart);
    479. pLine->addVertexAt(1,ptEnd);
    480. AcGePoint3dArray pntArr;交点的数组
    481. AcGeVector3d v1;道路方向
    482. 道路宽度
    483. double roadWidth;
    484. bool isSuc = false;是否成功取到了交点
    485. GetLineNum(pLine,ptList,pntArr,v1,roadWidth,isSuc);
    486. if(!isSuc)
    487. {
    488. acutPrintf(采用T("\n交点数量不合法"));
    489. acutRelRb(ptList);
    490. delete pLine;
    491. return;
    492. }
    493. delete pLine;
    494. int ptCount = pntArr.length();交点数量
    495. 如果交点数量不合法,退出
    496. if(ptCount != BANDER1PTCOUNT  && ptCount != BANDER2PTCOUNT
    497. && ptCount != BANDER3PTCOUNT && ptCount != BANDER4PTCOUNT )
    498. {
    499. acutPrintf(采用T("\n两点之间的直线数须为{4,6,8,10}."));
    500. return;
    501. }
    502. acutPrintf(采用T("\n交点个数:%d"),ptCount);
    503. //输入名称部分,改用xData判断========================
    504. CString strName;
    505. AcDbObjectId pVerLineId = NULL;
    506. ads采用name name;
    507. while (true)
    508. {
    509. if(acedGetString(0,采用T("\n输入横断面名称:\n"),strName.GetBuffer(20))!= RTNORM)
    510. {
    511. return;
    512. }
    513. 用完buffer记得release!!
    514. strName.ReleaseBuffer();
    515. if(strName.GetLength() > 2)
    516. {
    517. acutPrintf(采用T("\n输入的字符数太多,请重新输入"));
    518. continue;
    519. }
    520. if(!XDataIsExist(strName))
    521. {
    522. break;
    523. }
    524. else
    525. {
    526. acutPrintf(采用T("\n已存在名称,请重新输入"));
    527. }
    528. }
    529. ///=========画垂线部分=============================
    530. AcGeVector3d v2;横截面直线的方向向量
    531. if(v1[X] == 0)竖直
    532. {
    533. Sort2dArr(pntArr,true);
    534. v2.set(1,0,0);
    535. }
    536. else
    537. {
    538. if(v1[Y] == 0)
    539. {
    540. Sort2dArr(pntArr,false);
    541. v2.set(0,1,0);
    542. }
    543. else
    544. {
    545. Sort2dArr(pntArr,true);
    546. v2.set(1,-v1[X] / v1[Y],0);
    547. }
    548. }
    549. AcGePoint3d ptSecFst = pntArr.at(0);第一个交点
    550. 计算单位向量
    551. AcGeVector3d vNorm = v2.normalize();
    552. vNorm[X] = abs(vNorm[X]);
    553. vNorm[Y] = vNorm[Y];
    554. double len = 3 * BORDEROFFSET;
    555. AcGePoint3d ptEnd1;
    556. AcGePoint3d ptEnd2;
    557. ptEnd1 = ptSecFst - 3*BORDEROFFSET * vNorm;
    558. ptEnd2 = ptSecFst + (3 * BORDEROFFSET + roadWidth) * vNorm ;
    559. AcGePoint3dArray arr;
    560. arr.append(ptEnd1);
    561. arr.append(ptEnd2);
    562. AcDb3dPolyline* plVer = new AcDb3dPolyline(AcDb::Poly3dType::k3dSimplePoly,arr);
    563. plVer->setLineWeight(AcDb::LineWeight::kLnWt030);
    564. AcDbObjectId lineId = LoadEntity(plVer,true);
    565. ================绘制详细信息部分============================
    566. acdbOpenObject(plVer,lineId,AcDb::OpenMode::kForWrite);因为要添加扩展数据  所以要以写模式再次打开
    567. //获得垂线与道路的交点集合
    568. AcGePoint3dArray pntVerArr;
    569. bool isOk = false;
    570. GetLineNum(plVer,ptList,pntVerArr,v1,roadWidth,isOk);
    571. 释放链表空间
    572. acutRelRb(ptList);
    573. if(!isOk)
    574. {
    575. acutPrintf(采用T("\n垂线交点数量不合法"));
    576. plVer->close();
    577. return;
    578. }
    579. acutPrintf(采用T("\n垂线交点个数%d"),pntVerArr.length());
    580. if(v2[X] == 0)
    581. {
    582. Sort2dArr(pntVerArr,false);
    583. }
    584. else
    585. {
    586. Sort2dArr(pntVerArr,true);
    587. }
    588. int ptVerCount = pntVerArr.length();
    589. AcGeDoubleArray roadArr;
    590. double roadLen;
    591. AcGePoint3d prePt;
    592. AcGePoint3d latPt;
    593. for(int i = 0;i < ptVerCount - 1;i ++)
    594. {
    595. prePt = pntVerArr.at(i);
    596. latPt = pntVerArr.at(i + 1);
    597. roadLen = prePt.distanceTo(latPt);
    598. roadArr.append(roadLen);
    599. }
    600. 显示详细信息表格,宽度比例1:2,1:1时会导致字符超出边
    601. ShowRoadDetail(roadArr,strName,2);
    602. // //绘制横断面名称===============
    603. double fontSize = 2 * BORDEROFFSET;
    604. LocateWords(plVer,strName,fontSize,1);
    605. 保存扩展数据
    606. SavePlineXData(plVer,strName);
    607. 查看一下保存的扩展数据
    608. ViewPlineXData(plVer);
    609. 最后记得关闭polyline3d
    610. plVer->close();
    611. }
    612. 放置截面名称的文字
    613. 参数:多段线实体,文字,文字高度,文字加粗大小
    614. static void LocateWords(AcDbCurve* plVer,const CString& strName,double height,double fontSize)
    615. {
    616. AcGePoint3d plPtS;
    617. plVer->getStartPoint(plPtS);
    618. AcGePoint3d plPtE;
    619. plVer->getEndPoint(plPtE);
    620. AcGeVector3d v;
    621. plVer->getFirstDeriv(plPtS,v);
    622. AcGeVector3d vX(1,0,0);
    623. AcGeVector3d vZ(0,0,1);
    624. double angle = v.angleTo(vX,vZ);
    625. acutPrintf(采用T("\nangle is %.2f"),angle);
    626. InsertText(plPtS[X],plPtS[Y],0,strName,height,-angle,fontSize,AcDb::TextHorzMode::kTextLeft,AcDb::TextVertMode::kTextBottom);
    627. InsertText(plPtE[X],plPtE[Y],0,strName,height, -angle,fontSize,AcDb::TextHorzMode::kTextRight,AcDb::TextVertMode::kTextBottom);
    628. }
    629. static void TESTnormcmd()
    630. {
    631. }
    632. static void TESTtestcmd()
    633. {
    634. ads采用real num;
    635. if(RTNORM != acedGetReal(采用T("放大倍数"),&num))
    636. {
    637. return;
    638. }
    639. ads采用real angle;
    640. if(RTNORM != acedGetReal(采用T("旋转角度"),&angle))
    641. {
    642. return;
    643. }
    644. ads采用point pt;
    645. if(RTNORM!= acedGetPoint(NULL,采用T("选择一点"),pt))
    646. {
    647. acutPrintf(采用T("\nerror select"));
    648. return;
    649. }
    650. InsertText(pt[X],pt[Y],0,采用T("aaa"),num * BORDEROFFSET,angle,3,AcDb::TextHorzMode::kTextRight,AcDb::TextVertMode::kTextBottom);
    651. }
    652. } ;
    653. //-----------------------------------------------------------------------------
    654. IMPLEMENT采用ARX采用ENTRYPOINT(CArxProject3App)
    655. ACED采用ARXCOMMAND采用ENTRY采用AUTO(CArxProject3App, TEST, roadcmd, roadcmd, ACRX采用CMD采用MODAL, NULL)
    656. ACED采用ARXCOMMAND采用ENTRY采用AUTO(CArxProject3App, TEST, testcmd, testcmd, ACRX采用CMD采用MODAL, NULL)
    657. ACED采用ARXCOMMAND采用ENTRY采用AUTO(CArxProject3App, TEST, normcmd, normcmd, ACRX采用CMD采用MODAL, NULL)
    复制代码

     

     

     

     

    OBJECT ARX 绘制道路横切面 实例
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

    GMT+8, 2024-11-1 08:06 , Processed in 0.156904 second(s), 28 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表