天气与日历 切换到窄版

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

[每日一码] 获取块的XCLIP边界

[复制链接]
  • TA的每日心情
    开心
    半小时前
  • 签到天数: 20 天

    [LV.4]偶尔看看III

    115

    主题

    11

    回帖

    1393

    积分

    管理员

    积分
    1393
    QQ
    发表于 2024-3-14 20:56:29 | 显示全部楼层 |阅读模式
    1. static BOOL drawAPlineWithPropertiesFromBlockRef(AcGePoint2dArray pts,
    2.                  AcDbBlockReference* ref, double elevation, AcGeVector3d& normal)
    3.   {
    4.     AcDbPolyline *pl = new AcDbPolyline;
    5.     AcDbObjectId owner;
    6.     pl->setDatabaseDefaults();
    7.     pl->setClosed(Adesk::kTrue);
    8.     pl->setThickness(0.0);
    9.     if (ref != NULL) {
    10.         owner=ref->ownerId();
    11.         pl->setPropertiesFrom(ref);
    12.     }
    13.     pl->setNormal(normal);
    14.     for (int i=0; i < pts.length(); i++)
    15.     {
    16.         pl->addVertexAt(i, pts);
    17.     }
    18.     pl->setElevation(elevation);
    19.     pl->setColorIndex(1); // Red
    20.     AcDbBlockTableRecord *rec=NULL;
    21.     acdbOpenObject(rec, owner, AcDb::kForWrite);
    22.     if (rec != NULL)
    23.     {
    24.         AcDbObjectId id;
    25.         rec->appendAcDbEntity(id, pl);
    26.         pl->close();
    27.         rec->close();
    28.     }
    29.     else
    30.     {
    31.         delete pl;
    32.         return false;
    33.     }
    34.     return true;
    35.   } // End of drawAPlineWithPropertiesFromBlockRef()
    36.   // Get the boundary from a Block Reference given by the blk parameter.
    37.   // Transform that boundary to the WCS.
    38.   //-------------------------------------------------------------------
    39.   static BOOL GetBlockClippingPolyline(ads采用name blk)
    40.   {
    41.     BOOL ret = FALSE;
    42.     AcDbBlockReference *ref = NULL;
    43.     AcDbObjectId insId = AcDbObjectId::kNull;
    44.     acdbGetObjectId(insId, blk);
    45.     if (acdbOpenObject(ref, insId, AcDb::kForRead) != Acad::eOk)
    46.       return ret;
    47.     // Find the clipping object (AcDbSpatialFilter) in the ExtDict of the BlockRef
    48.     AcDbObjectId extDicId = ref->extensionDictionary();
    49.     if( extDicId == AcDbObjectId::kNull )
    50.       return ret;
    51.     AcDbDictionary *extDict=NULL, *acadFilterDict=NULL;
    52.     if (acdbOpenObject(extDict, extDicId, AcDb::kForRead) != Acad::eOk)
    53.         return ret;
    54.     Acad::ErrorStatus err = extDict->getAt(采用T("ACAD采用FILTER"), (AcDbObject*&)acadFilterDict, AcDb::kForRead);
    55.     extDict->close();
    56.     if( err != Acad::eOk )
    57.         return ret;
    58.     AcDbSpatialFilter *filter=NULL;
    59.     err = acadFilterDict->getAt(采用T("SPATIAL"), (AcDbObject*&)filter, AcDb::kForRead);
    60.     acadFilterDict->close();
    61.     if ( err != Acad::eOk)
    62.       return ret;
    63.     // Get the transform matrix stored in the XClip boundary
    64.     AcGeMatrix3d xformInBoundary = filter->getClipSpaceToWCSMatrix( xformInBoundary );
    65.     // and the transform of the BlockRef at the time when the Filter was set
    66.     AcGeMatrix3d xformRefOrig = filter->getOriginalInverseBlockXform( xformRefOrig );
    67.     // Get the transform matrix that the current BlockRef has, so, we can find the difference
    68.     //   with the xformRefOrig
    69.     AcGeMatrix3d refMatrix = ref->blockTransform();
    70.     refMatrix = refMatrix.postMultBy(xformRefOrig );
    71.     // Calculate the final transform matrix which applies to the points
    72.     // returned from filter->getDefinition().
    73.     AcGeMatrix3d finalMatrix = refMatrix.postMultBy(xformInBoundary);
    74.     AcGePoint2dArray pts;
    75.     AcGePoint3dArray pts3d;
    76.     AcGeVector3d normal;
    77.     double elevation = 0, frontClip = 0, backClip = 0;
    78.     Adesk::Boolean enabled  = false;
    79.     // Get all boundary points
    80.     if (filter->getDefinition(pts, normal, elevation, frontClip, backClip, enabled) == Acad::eOk)
    81.     {
    82.       // Rectanglar boundary
    83.       if (pts.length() == 2)
    84.       {
    85.         AcGePoint2d p1(pts[1].x, pts[0].y);
    86.         AcGePoint2d p3(pts[0].x, pts[1].y);
    87.         pts.insertAt(1, p1);
    88.         pts.insertAt(3, p3);
    89.       }
    90.       // Transform all points with the transform matrix we calculated
    91.       for(int i=0; i<pts.length(); i++)
    92.       {
    93.         AcGePoint2d pt2d;
    94.         AcGePoint3d pt3d;
    95.         pt2d = pts;
    96.         pt3d[0] = pt2d[0]; pt3d[1] = pt2d[1]; pt3d[2] = 0;
    97.         pt3d.transformBy(finalMatrix);
    98.         pts3d.append(pt3d);
    99.       }
    100.     }
    101.     // Get the new normal and new ECS information for the polyline.
    102.     AcGeVector3d xfnorm = normal.transformBy(finalMatrix);
    103.     AcGeMatrix3d plineECS;
    104.     AcDbPolyline* pline = new AcDbPolyline();
    105.     pline->setNormal(xfnorm);
    106.     pline->getEcs(plineECS);
    107.     delete pline; pline = NULL;
    108.     AcGeMatrix3d plineECSInv = plineECS.inverse();
    109.     double xfelev = 0.0;
    110.     for (int i = 0; i < pts.length(); i++)
    111.     {
    112.       pts.x = pts3d.x;
    113.       pts.y = pts3d.y;
    114.       if (i == 0)
    115.         xfelev = pts3d.z;
    116.       // Should be identical to within roundoff
    117.       assert(fabs(xfelev - pts3d.z) < 1.0e-10);
    118.     }
    119.     // Show the boundary
    120.     drawAPlineWithPropertiesFromBlockRef(pts, ref, xfelev, xfnorm);
    121.     filter->close();
    122.     ref->close();
    123.     return true;
    124.   } // End of GetBlockClippingPolyline()
    125. 本帖隐藏的内容
    126. // "MClip" test command for the GetBlockClippingPolyline() function.
    127. static void MMRCplusplus采用MClip(void)
    128.   {
    129.     ads采用name en;
    130.     AcGePoint3d pt;
    131.     if (acedEntSel(采用T("\nSelect an INSERT clipped by XCLIP command: "), en, asDblArray(pt)) != RTNORM)
    132.     {
    133.       acutPrintf(采用T("\nNothing selected"));
    134.       return;
    135.     }
    136.     assert(GetBlockClippingPolyline(en)==TRUE);
    137.   }
    复制代码

     

     

     

     

    [每日一码] 获取块的XCLIP边界
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

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

    GMT+8, 2024-11-5 06:11 , Processed in 0.148595 second(s), 28 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

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