天气与日历 切换到窄版

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

arx布局裁图

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
  1. #pragma once

  2. // ----------------------------------------------------------------------------------------------------------------
  3. // Summary: 布局裁图
  4. // ----------------------------------------------------------------------------------------------------------------
  5. class CLayoutCutDrawing
  6. {
  7. public:
  8.     CLayoutCutDrawing(void);
  9.     ~CLayoutCutDrawing(void);

  10.     // --------------------------------------------------------------------------------------------
  11. // Summary: 绘制布局裁图
  12. // Parameters:
  13. //     pt1                -    裁图区域所在的外包最小点
  14. //     pt2                -    裁图区域所在的外包最大点
  15. //     ptInsertTopLeft    -    视口的左下脚点
  16. //     dScaleFactor        -    缩放比例
  17. //     dAngle                -    裁图角度
  18. //     pBoundary            -    裁图边界
  19. // Returns:
  20. //     成功返回 Acad::eOk, 否则返回 Acad::ErrorStatus 错误状态
  21. // --------------------------------------------------------------------------------------------
  22.     static Acad::ErrorStatus DrawLayout(const AcGePoint3d& pt1, const AcGePoint3d& pt2, const AcGePoint3d& ptInsertBottomLeft, LPCTSTR lpszLayoutName, double dScaleFactor, double dAngle, AcDbPolyline* pBoundary);

  23.     // --------------------------------------------------------------------------------------------
  24. // Summary: 创建新布局
  25. // Parameters:
  26. //     lpszName        -    布局的名称
  27. //     layoutId        -    布局id
  28. //     blkTabRecId    -    布局块表记录
  29. // Returns:
  30. //     成功返回 Acad::eOk, 否则返回 Acad::ErrorStatus 错误状态
  31. // --------------------------------------------------------------------------------------------
  32.     static Acad::ErrorStatus CreateNewLayout(LPCTSTR lpszName, AcDbObjectId& layoutId, AcDbObjectId& blkTabRecId);

  33. protected:

  34.     // --------------------------------------------------------------------------------------------
  35. // Summary: 遍历所有布局
  36. // --------------------------------------------------------------------------------------------
  37.     Acad::ErrorStatus AllLayout();

  38.     // --------------------------------------------------------------------------------------------
  39. // Summary: 查找指定名称的布局
  40. // Parameters:
  41. //     lpszName        -    布局的名称
  42. //     layoutId        -    布局id
  43. //     blkTabRecId    -    布局块表记录
  44. // Returns:
  45. //     成功返回 Acad::eOk, 否则返回 Acad::ErrorStatus 错误状态
  46. // --------------------------------------------------------------------------------------------
  47.     static Acad::ErrorStatus FindLayout(LPCTSTR lpszName, AcDbObjectId& layoutId, AcDbObjectId& blkTabRecId);
  48. };

  49. CLayoutCutDrawing::CLayoutCutDrawing(void)
  50. {
  51. }

  52. CLayoutCutDrawing::~CLayoutCutDrawing(void)
  53. {
  54. }

  55. Acad::ErrorStatus CLayoutCutDrawing::DrawLayout(const AcGePoint3d& pt1, const AcGePoint3d& pt2, const AcGePoint3d& ptInsertBottomLeft, LPCTSTR lpszLayoutName, double dScaleFactor/* = 1.0*/, double dAngle /*= 0.0*/, AcDbPolyline* pBoundary /*= NULL*/)
  56. {
  57.      AcGeMatrix3d mat;
  58. //     mat.setToScaling(1 / dScaleFactor, pt1);
  59.      mat *= AcGeMatrix3d::translation(ptInsertBottomLeft - pt1);

  60.     AcGeVector3d dirRotate = AcGeVector3d::kXAxis;
  61.     dirRotate.rotateBy(dAngle, AcGeVector3d::kZAxis);

  62.     AcDbExtents ext(pt1, pt2);
  63.     AcGePoint3d ptGeoMid = AcGePoint3d((pt2.x + pt1.x) / 2.0, (pt2.y + pt1.y) / 2.0, 0.0);
  64.     AcGePoint3d ptModelCenter = ptGeoMid;

  65.     mat *= AcGeMatrix3d::rotation(-dAngle, AcGeVector3d::kZAxis, ptModelCenter);

  66.     if (NULL == pBoundary)
  67.     {
  68.         return Acad::eNotImplementedYet;
  69.     }

  70.     AcDbObjectId layerId = pBoundary->layerId();
  71.     AcDbObjectIdArray layerIdArr;
  72.     layerIdArr.append(layerId);

  73.     actrTransactionManager->startTransaction();
  74.     try
  75.     {
  76.         // 新建布局
  77.         AcDbObjectId viewportId;
  78.         AcDbObjectId layoutId;
  79.         AcDbObjectId blkTabRecId;
  80.         AcDbObjectId plineId;

  81.         FindLayout(lpszLayoutName, layoutId, blkTabRecId);

  82.         // 新建视口
  83.         AcDbViewport* pViewPort = new AcDbViewport;
  84.         pViewPort->setCustomScale(dScaleFactor);
  85.         pViewPort->setCenterPoint(/*ptTKCen*/ptModelCenter);

  86.         // 设置视口属性
  87.         double dHeight = fabs(ext.maxPoint().y - ext.minPoint().y);
  88.         pViewPort->setWidth(fabs(ext.maxPoint().x - ext.minPoint().x));
  89.         pViewPort->setHeight(dHeight);
  90.     //    pViewPort->setLayer(m_ComLayer_BuJuShiKou);
  91.         pViewPort->setTwistAngle(-dAngle);
  92.         pViewPort->setViewTarget(ptModelCenter);// 设置视口目标
  93.         pViewPort->setViewHeight(dHeight);
  94.         pViewPort->setCustomScale(dScaleFactor);
  95.         pViewPort->freezeLayersInViewport(layerIdArr);    // 在当前视口中冻结裁图线所在的图层

  96.         {
  97.             // 在图纸空间中加入视口
  98.             AcDbObjectPointer<AcDbBlockTableRecord> spBlk(blkTabRecId, AcDb::kForWrite);
  99.             EOK_RETURN_ERROR(spBlk.openStatus());
  100.             spBlk->appendAcDbEntity(viewportId, pViewPort);

  101.             Acad::ErrorStatus es = pViewPort->setOn();
  102.         }

  103.         {
  104.             // 在图纸空间中加入闭合多边形pline线
  105.             AcDbPolyline* pTempLine = AcDbPolyline::cast(pBoundary->clone()) ;
  106.             pTempLine->setClosed(Adesk::kTrue);

  107.             AcDbObjectPointer<AcDbBlockTableRecord> spBlk(blkTabRecId, AcDb::kForWrite);
  108.             EOK_RETURN_ERROR(spBlk.openStatus());
  109.             spBlk->appendAcDbEntity(plineId, pTempLine);

  110.             pTempLine->transformBy(mat);

  111.             pTempLine->close();
  112.         }
  113.         
  114.         pViewPort->transformBy(mat);
  115.         EOK_RETURN_ERROR(pViewPort->setNonRectClipEntityId(plineId));
  116.         EOK_RETURN_ERROR(pViewPort->setNonRectClipOn());
  117.         EOK_RETURN_ERROR(pViewPort->setLocked());
  118.         EOK_RETURN_ERROR(pViewPort->close());
  119.     }
  120.     catch (const Acad::ErrorStatus err)
  121.     {
  122.         actrTransactionManager->endTransaction();
  123.     }
  124.     catch (...)
  125.     {
  126.         acutPrintf(_T("未知错误!"));
  127.         actrTransactionManager->endTransaction();
  128.     }

  129.     actrTransactionManager->endTransaction();

  130.     // 有时生成的裁图在视口以外的地方,需要缩放才能看到
  131.   // 但是每生成一副裁图,就要闪烁,先屏蔽了, 放在命令结束时做一次缩放
  132.   // acedCommand(RTSTR, _T("ZOOM"), RTSTR, _T("E"), 0);
  133.     ads_regen();

  134.     return Acad::eOk;
  135. }

  136. Acad::ErrorStatus CLayoutCutDrawing::CreateNewLayout(LPCTSTR lpszName, AcDbObjectId& layoutId, AcDbObjectId& blkTabRecId)
  137. {
  138.     AcApLayoutManager* pLayMan = (AcApLayoutManager *) acdbHostApplicationServices()->layoutManager();
  139.     if (!pLayMan)
  140.     {
  141.         return Acad::eNotImplementedYet;
  142.     }

  143.     AcDbLayout* pLayout = NULL;
  144.     if (pLayout = pLayMan->findLayoutNamed(lpszName))
  145.     {
  146.         layoutId = pLayout->objectId();
  147.         blkTabRecId = pLayout->getBlockTableRecordId();

  148.         pLayMan->setCurrentLayoutId(layoutId);

  149.         return Acad::eNotImplementedYet;
  150.     }
  151.     else
  152.     {
  153. //         pLayMan->createLayout(lpszName, layoutId, blkTabRecId);
  154. //         pLayMan->updateLayoutTabs();
  155. //         pLayMan->setCurrentLayoutId(layoutId);

  156.         Acad::ErrorStatus es = Acad::eOk;
  157.         AcDbBlockTable*    pBlockTable;
  158.         es = acdbCurDwg()->getSymbolTable(pBlockTable,AcDb::kForWrite);
  159.         EOK_RETURN_ERROR(es);

  160.         AcDbBlockTableRecord* pBlockTableRecord = new AcDbBlockTableRecord;
  161.         pBlockTableRecord->setName(_T("*Paper_Space"));
  162.         pBlockTable->add(blkTabRecId, pBlockTableRecord);
  163.         pBlockTable->close();
  164.         pBlockTableRecord->close();

  165.         pLayout = new AcDbLayout;
  166.         if(!pLayout)
  167.         {
  168.             return es;
  169.         }
  170.         es = pLayout->setLayoutName(lpszName);            
  171.         if (es != Acad::eOk)
  172.         {
  173.             delete pLayout;
  174.             return es;
  175.         }

  176.         es = pLayout->addToLayoutDict(acdbCurDwg(), blkTabRecId);            
  177.         if (es != Acad::eOk)
  178.         {
  179.             delete pLayout;
  180.             return es;
  181.         }

  182.         pLayout->close();
  183.         pLayMan->updateLayoutTabs();
  184.         pLayMan->setCurrentLayout(lpszName);
  185.     }

  186.     return Acad::eOk;
  187. }

  188. Acad::ErrorStatus CLayoutCutDrawing::AllLayout()
  189. {
  190.     //遍历所有布局
  191.     {
  192.         //获得布局字典,布局字典里包含了模型和布局
  193.         AcDbDictionary *pLayoutDic=NULL;
  194.         Acad::ErrorStatus es=acdbHostApplicationServices()
  195.             ->workingDatabase()->getLayoutDictionary(pLayoutDic,AcDb::kForRead);
  196.         if(es != Acad::eOk)
  197.         {
  198.             pLayoutDic->close();
  199.             acutPrintf(_T("\n获取图纸空间字典错误"));
  200.             return Acad::eOk;
  201.         }
  202.         if(pLayoutDic->numEntries()==0)
  203.         {
  204.             pLayoutDic->close();
  205.             acutPrintf(_T("\n当前图形不存在图纸空间"));
  206.             return Acad::eOk;
  207.         }

  208.         //创建布局字典遍历器
  209.         AcDbDictionaryIterator *pLayoutDicItr=pLayoutDic->newIterator();
  210.         
  211.         //创建循环,遍历布局
  212.         for(int i = 1; !pLayoutDicItr->done(); pLayoutDicItr->next())
  213.         {
  214.             acutPrintf(_T("\n第[ %d ]个布局,布局名称为[ %s ]"),i,pLayoutDicItr->name());
  215.             i++;
  216.         }
  217.         delete pLayoutDicItr;    //删除遍历器对象
  218.         pLayoutDic->close();
  219.     }

  220.     return Acad::eOk;
  221. }

  222. Acad::ErrorStatus CLayoutCutDrawing::FindLayout(LPCTSTR lpszName, AcDbObjectId& layoutId, AcDbObjectId& blkTabRecId)
  223. {
  224.     AcApLayoutManager* pLayMan = (AcApLayoutManager *) acdbHostApplicationServices()->layoutManager();
  225.     if (!pLayMan)
  226.     {
  227.         return Acad::eNotImplementedYet;
  228.     }

  229.     AcDbLayout* pLayout = NULL;
  230.     if (pLayout = pLayMan->findLayoutNamed(lpszName))
  231.     {
  232.         layoutId = pLayout->objectId();
  233.         blkTabRecId = pLayout->getBlockTableRecordId();

  234.         pLayMan->setCurrentLayoutId(layoutId);

  235.         return Acad::eOk;
  236.     }

  237.     return Acad::eNotImplementedYet;
  238. }
复制代码

 

 

 

 

arx布局裁图
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-11-1 12:26 , Processed in 0.157982 second(s), 28 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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