CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

相关分类

突出显示子实体

2023-1-1 04:35| 发布者: admin| 查看: 350| 评论: 0|来自: AutoCAD

获取所选实体的子实体路径后,此过程最困难的部分就完成了。现在,您只需要调用函数并传入子实体路径。如果在没有任何参数的情况下调用函数,则默认设置是突出显示整个实体。highlight()highlight()

以下示例代码演示了用于选择实体、获取子实体路径以及突出显示与 GS 标记关联的不同类型的子实体所描述的步骤。此代码还演示了另一个有用的子实体函数:

virtual AcDbEntity* 
AcDbEntity::subentPtr(const AcDbFullSubentPath& id) const;

此函数返回指向指定路径描述的子实体副本的指针,然后可以将其添加到数据库中(如示例中所示)。

注意:当您创建新的子类时,您应该为它们提供自己的实现,并通过覆盖相应的虚函数,并分别(请参阅从 AcDbEntity 派生)。但是,该函数是在级别实现的,通常不会被覆盖。但是,如果它被重写,则此函数的任何新实现都必须调用以执行突出显示。AcDbEntitygetSubentPathsAtGsMarker()getGsMarkersAtSubentPath(),subentPtr()subGetSubentPathsAtGsMarker()subGetGsMarkersAtSubentPath(),subSubentPtr()highlight()AcDbEntityAcDbEntity::highlight()

// This function calls getObjectAndGsMarker() to get the
// object ID of a solid and its gsmarker. It then calls
// highlightEdge(), highlightFaces(), and highlightAll() to
// highlight the selected edge, all faces surrounding that
// edge, and then the whole solid.
//
void
highlightTest()
{
    AcDbObjectId objId;
    int marker;
    if (getObjectAndGsMarker(objId, marker) != Acad::eOk)
        return;
    highlightEdge(objId, marker);
    highlightFaces(objId, marker);
    highlightAll(objId);
}
// This function uses acedSSGet() to let the user select a
// single entity.  It then passes this selection set to
// acedSSNameX() to get the gsmarker. Finally, the entity name
// in the selection set is used to obtain the object ID of
// the selected entity.
//
Acad::ErrorStatus
getObjectAndGsMarker(AcDbObjectId& objId, int& marker)
{
    ads_name sset;
    if (acedSSGet("_:S", NULL, NULL, NULL, sset) != RTNORM) {
        acutPrintf("\nacedSSGet has failed");
        return Acad::eInvalidAdsName;
    }
    // Get the entity from the selection set and its
    // subentity ID. This code assumes that the user
    // selected only one item, a solid.
    //
    struct resbuf *pRb;
    if (acedSSNameX(&pRb, sset, 0) != RTNORM) {
        acedSSFree(sset);
        return Acad::eAmbiguousOutput;
    }
    acedSSFree(sset);
    // Walk the list to the third item, which is the selected
    // entity's entity name.
    //
    struct resbuf *pTemp;
    int i;
    for (i=1, pTemp = pRb;i<3;i++, pTemp = pTemp->rbnext)
        { ; }
    ads_name ename;
    ads_name_set(pTemp->resval.rlname, ename);
    // Move on to the fourth list element, which is the gsmarker.
    //
    pTemp = pTemp->rbnext;
    marker = pTemp->resval.rint;
    acutRelRb(pRb);
    acdbGetObjectId(objId, ename);
    return Acad::eOk;
}
// This function accepts an object ID and a gsmarker.
// The object is opened, the gsmarker is used to get the
// AcDbFullSubentIdPath, which is then used to highlight
// and unhighlight the edge used to select the object.
// Next, the object's subentPtr() function is used to get
// a copy of the edge. This copy is then added to the
// database. Finally, the object is closed.
// 
// Since the copy of the subentity was added to the database 
// as a new AcDbLine entity, it remains visible in the drawing 
// editor after the command exits and will be reported by the 
// AutoCAD LIST command.
// 
void
highlightEdge(const AcDbObjectId& objId, const int marker)
{
    char dummy[133]; // space for acedGetString pauses below
    AcDbEntity *pEnt;
    acdbOpenAcDbEntity(pEnt, objId, AcDb::kForRead);
    // Get the subentity ID for the edge that is picked
    //
    AcGePoint3d pickpnt;
    AcGeMatrix3d xform;
    int numIds;
    AcDbFullSubentPath *subentIds;
    pEnt->getSubentPathsAtGsMarker(AcDb::kEdgeSubentType,
        marker, pickpnt, xform, numIds, subentIds);
    // At this point the subentId's variable contains the
    // address of an array of AcDbFullSubentPath objects.
    // The array should be one element long, so the picked
    // edge's AcDbFullSubentPath is in subentIds[0].
    //
    // For objects with no edges (such as a sphere), the
    // code to highlight an edge is meaningless and must
    // be skipped.
    //
    if (numIds > 0) {
        // Highlight the edge.
        //
        pEnt->highlight(subentIds[0]);
        // Pause to let user see the effect.
        //
        acedGetString(0, "\npress <RETURN> to continue...",
            dummy);
        // Unhighlight the picked edge.
        //
        pEnt->unhighlight(subentIds[0]);
        // Get a copy of the edge, and add it to the database.
        //
        AcDbEntity *pEntCpy = pEnt->subentPtr(subentIds[0]);
        AcDbObjectId objId;
        addToModelSpace(objId, pEntCpy);
    }
    delete []subentIds;
    pEnt->close();
}
// This function accepts an object ID and a gsmarker.
// The object is opened, the gsmarker is used to get the
// AcDbFullSubentIdPath, which is then used to highlight
// and unhighlight faces that share the edge used to
// select the object. The object is then closed.
//
void
highlightFaces(const AcDbObjectId& objId, const int marker)
{
    char dummy[133];
    AcDbEntity *pEnt;
    acdbOpenAcDbEntity(pEnt, objId, AcDb::kForRead);
    // Get the subentIds for the faces.
    //
    AcGePoint3d pickpnt;
    AcGeMatrix3d xform;
    int numIds;
    AcDbFullSubentPath *subentIds;
    pEnt->getSubentPathsAtGsMarker(AcDb::kFaceSubentType,
        marker, pickpnt, xform, numIds, subentIds);
    // Walk the subentIds list, highlighting each face subentity.
    //
    for (int i = 0;i < numIds; i++) {
        pEnt->highlight(subentIds[i]); // Highlight face.
        // Pause to let the user see the effect.
        //
        acedGetString(0, "\npress <RETURN> to continue...",
            dummy);
        pEnt->unhighlight(subentIds[i]);
    }
    delete []subentIds;
    pEnt->close();
}
// This function accepts an object ID. The object is opened,
// and its highlight() and unhighlight() functions are
// used with no parameters, to highlight and
// unhighlight the edge used to select the object. The
// object is then closed.
//
void
highlightAll(const AcDbObjectId& objId)
{
    char dummy[133];
    AcDbEntity *pEnt;
    acdbOpenAcDbEntity(pEnt, objId, AcDb::kForRead);
    // Highlight the whole solid.
    //
    pEnt->highlight();
    // Pause to let user see the effect.
    //
    acedGetString(0, "\npress <RETURN> to continue...",
        dummy);
    pEnt->unhighlight();
    pEnt->close();
}
Acad::ErrorStatus
addToModelSpace(AcDbObjectId &objId, AcDbEntity* pEntity)
{
    AcDbBlockTable *pBlockTable;
    AcDbBlockTableRecord *pSpaceRecord;
    acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pBlockTable, AcDb::kForRead);
    pBlockTable->getAt(ACDB_MODEL_SPACE, pSpaceRecord,
        AcDb::kForWrite);
    pSpaceRecord->appendAcDbEntity(objId, pEntity);
    pBlockTable->close();
    pEntity->close();
    pSpaceRecord->close();
    return Acad::eOk;
}

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 12:44

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部