热卖商品
新闻详情
计算AcDbBlockReference准确的包围盒|二次开发objectarx-lisp|...
来自 : www.mjgw.org/thread-8737-1...h
发布时间:2021-03-25
AcDbBlockReference* pRef;
if (acdbOpenObject(pRef,id,AcDb::kForRead)==Acad::eOk)
{
if (Acad::eOk==getBlockRefGeomExtents(pRef,extents))
{
//just display the 2d box
AcGePoint2d minpt(extents.minPoint()[X],extents.minPoint()[Y]);
AcGePoint2d maxpt(extents.maxPoint()[X],extents.maxPoint()[Y]);
AcGePoint2dArray points;
points.append(minpt);
AcGePoint2d pt(maxpt[X],minpt[Y]);
points.append(pt);
points.append(maxpt);
pt.set(minpt[X],maxpt[Y]);
points.append(pt);
AcDbPolyline* pPline;
if ((pPline=makeSimplePline(points))!=NULL){
pPline- setClosed(Adesk::kTrue);
AcDbObjectId id;
postToDb(pPline,id);
}
} else
acutPrintf( \\nCannot calculate accurate extents
pRef- close();
}
}
//creates a polyline with 0 width, without bulges
AcDbPolyline* makeSimplePline(const AcGePoint2dArray points)
{
AcDbPolyline* pPline = new AcDbPolyline(points.length());
if (pPline==NULL)
return pPline;
for (int i=0;i points.length();i++)
if (pPline- addVertexAt(i,points i )!=Acad::eOk)
{
delete pPline;
pPline = NULL;
break;
}
return pPline;
}//explodes a 2dpolyline by first converting it to a new polyline
Acad::ErrorStatus explodeAcDb2dPolyline(const AcDb2dPolyline*
p2d,AcDbVoidPtrArray ents){
if (p2d==NULL)
return Acad::eInvalidInput;
AcDbPolyline* pPline;
if ((pPline=new AcDbPolyline)==NULL)
return Acad::eOutOfMemory;
Acad::ErrorStatus es;
if ((es=pPline- convertFrom((AcDbEntity* )p2d,Adesk::kFalse))==Acad::eOk)
{
es=pPline- explode(ents);
}
return es;
}Acad::ErrorStatus getBlockRefGeomExtents(AcDbBlockReference* pRef, AcDbExtents
extents, const AcGeMatrix3d mat)
{
Acad::ErrorStatus es;
AcGeMatrix3d xform;
AcDbEntity* pCopy;
AcDbEntity* pE;
xform=mat*pRef- blockTransform();
AcDbObjectId idBlock = pRef- blockTableRecord();
AcDbBlockTableRecord* pBlock;
if ((es=acdbOpenObject(pBlock,idBlock,AcDb::kForRead))==Acad::eOk){
AcDbBlockTableRecordIterator* pIter;
if ((es=pBlock- newIterator(pIter))==Acad::eOk){
for (pIter- start();!pIter- done();pIter- step()){
AcDbExtents ext;
if ((es=pIter- getEntity(pE,AcDb::kForRead))==Acad::eOk)
{
AcDbBlockReference* pRefNested;
if ((pRefNested=AcDbBlockReference::cast(pE))!=NULL)
{
if ((es=getBlockRefGeomExtents(pRefNested,ext,xform))!=Acad::eOk)
{
pE- close();
break;
}
}
else
{
AcRxClass* pDesc = pE- isA();
if (pDesc==AcDbPolyline::desc() ||
pDesc==AcDb2dPolyline::desc() ||
pDesc==AcDbMText::desc())
{
//need explode
AcDbVoidPtrArray array;
if (pDesc==AcDbPolyline::desc())
es=pE- explode(array);
if (pDesc==AcDbMText::desc())
es=pE- explode(array); if (pDesc==AcDb2dPolyline::desc())
es=explodeAcDb2dPolyline(AcDb2dPolyline::cast(pE),array); if (es==Acad::eOk)
{
for(int i=0;i array.length();i++)
{
AcDbExtents ext2;
AcDbEntity* pPart = ((AcDbEntity*)(array i
if((es=pPart- getTransformedCopy(xform,pCopy))==Acad::eOk)
{
es=pCopy- getGeomExtents(ext2);
delete pCopy;
}
if (es!=Acad::eOk)
{
delete pPart;
if (es==Acad::eNullExtents)
continue;
else
break;
}
delete pPart;
ext.addExt(ext2);
}
}
}
else
{
if((es=pE- getTransformedCopy(xform,pCopy))==Acad::eOk)
{
es=pCopy- getGeomExtents(ext);
delete pCopy;
}
}
}
if (es!=Acad::eOk)
{
pE- close();
if (es==Acad::eNullExtents)
continue;
else
break;
}
extents.addExt(ext);
pE- close();
}
}
delete pIter;
}
}
pBlock- close();
//add non constant attributes
AcDbObjectIterator* pIter;
if ((pIter=pRef- attributeIterator())==NULL)
return Acad::eOutOfMemory;
for (pIter- start();!pIter- done();pIter- step())
{
AcDbExtents ext;
if((es=acdbOpenObject(pE,pIter- objectId(),AcDb::kForRead))==Acad::eOk)
{
pE- getGeomExtents(ext);
if (es!=Acad::eOk)
{
pE- close();
if (es==Acad::eNullExtents)
continue;
else
break;
}
extents.addExt(ext);
pE- close();
}
}
delete pIter;
return es;
}//Posts an entity to the database
//
Acad::ErrorStatus postToDb(AcDbEntity* ent, AcDbObjectId objId)
{
Acad::ErrorStatus es;
AcDbBlockTable* pBlockTable;
AcDbBlockTableRecord*pSpaceRecord;
if (NULL == ent)
return Acad::eNullObjectPointer;
if (NULL == acdbHostApplicationServices()- workingDatabase())
return Acad::eNoDatabase;
if ((es = acdbHostApplicationServices()- workingDatabase()- getBlockTable(pBlockTable, AcDb::kForRead))!= Acad::eOk)
return es;
if ((es = pBlockTable- getAt(ACDB_MODEL_SPACE,pSpaceRecord,AcDb::kForWrite))!= Acad::eOk)
{
pBlockTable- close();
return es;
}
pBlockTable- close();
if ((es = pSpaceRecord- appendAcDbEntity(objId, ent)) != Acad::eOk)
{
pSpaceRecord- close();
return es;
}
pSpaceRecord- close();
return ent- close();
if (acdbOpenObject(pRef,id,AcDb::kForRead)==Acad::eOk)
{
if (Acad::eOk==getBlockRefGeomExtents(pRef,extents))
{
//just display the 2d box
AcGePoint2d minpt(extents.minPoint()[X],extents.minPoint()[Y]);
AcGePoint2d maxpt(extents.maxPoint()[X],extents.maxPoint()[Y]);
AcGePoint2dArray points;
points.append(minpt);
AcGePoint2d pt(maxpt[X],minpt[Y]);
points.append(pt);
points.append(maxpt);
pt.set(minpt[X],maxpt[Y]);
points.append(pt);
AcDbPolyline* pPline;
if ((pPline=makeSimplePline(points))!=NULL){
pPline- setClosed(Adesk::kTrue);
AcDbObjectId id;
postToDb(pPline,id);
}
} else
acutPrintf( \\nCannot calculate accurate extents
pRef- close();
}
}
//creates a polyline with 0 width, without bulges
AcDbPolyline* makeSimplePline(const AcGePoint2dArray points)
{
AcDbPolyline* pPline = new AcDbPolyline(points.length());
if (pPline==NULL)
return pPline;
for (int i=0;i points.length();i++)
if (pPline- addVertexAt(i,points i )!=Acad::eOk)
{
delete pPline;
pPline = NULL;
break;
}
return pPline;
}//explodes a 2dpolyline by first converting it to a new polyline
Acad::ErrorStatus explodeAcDb2dPolyline(const AcDb2dPolyline*
p2d,AcDbVoidPtrArray ents){
if (p2d==NULL)
return Acad::eInvalidInput;
AcDbPolyline* pPline;
if ((pPline=new AcDbPolyline)==NULL)
return Acad::eOutOfMemory;
Acad::ErrorStatus es;
if ((es=pPline- convertFrom((AcDbEntity* )p2d,Adesk::kFalse))==Acad::eOk)
{
es=pPline- explode(ents);
}
return es;
}Acad::ErrorStatus getBlockRefGeomExtents(AcDbBlockReference* pRef, AcDbExtents
extents, const AcGeMatrix3d mat)
{
Acad::ErrorStatus es;
AcGeMatrix3d xform;
AcDbEntity* pCopy;
AcDbEntity* pE;
xform=mat*pRef- blockTransform();
AcDbObjectId idBlock = pRef- blockTableRecord();
AcDbBlockTableRecord* pBlock;
if ((es=acdbOpenObject(pBlock,idBlock,AcDb::kForRead))==Acad::eOk){
AcDbBlockTableRecordIterator* pIter;
if ((es=pBlock- newIterator(pIter))==Acad::eOk){
for (pIter- start();!pIter- done();pIter- step()){
AcDbExtents ext;
if ((es=pIter- getEntity(pE,AcDb::kForRead))==Acad::eOk)
{
AcDbBlockReference* pRefNested;
if ((pRefNested=AcDbBlockReference::cast(pE))!=NULL)
{
if ((es=getBlockRefGeomExtents(pRefNested,ext,xform))!=Acad::eOk)
{
pE- close();
break;
}
}
else
{
AcRxClass* pDesc = pE- isA();
if (pDesc==AcDbPolyline::desc() ||
pDesc==AcDb2dPolyline::desc() ||
pDesc==AcDbMText::desc())
{
//need explode
AcDbVoidPtrArray array;
if (pDesc==AcDbPolyline::desc())
es=pE- explode(array);
if (pDesc==AcDbMText::desc())
es=pE- explode(array); if (pDesc==AcDb2dPolyline::desc())
es=explodeAcDb2dPolyline(AcDb2dPolyline::cast(pE),array); if (es==Acad::eOk)
{
for(int i=0;i array.length();i++)
{
AcDbExtents ext2;
AcDbEntity* pPart = ((AcDbEntity*)(array i
if((es=pPart- getTransformedCopy(xform,pCopy))==Acad::eOk)
{
es=pCopy- getGeomExtents(ext2);
delete pCopy;
}
if (es!=Acad::eOk)
{
delete pPart;
if (es==Acad::eNullExtents)
continue;
else
break;
}
delete pPart;
ext.addExt(ext2);
}
}
}
else
{
if((es=pE- getTransformedCopy(xform,pCopy))==Acad::eOk)
{
es=pCopy- getGeomExtents(ext);
delete pCopy;
}
}
}
if (es!=Acad::eOk)
{
pE- close();
if (es==Acad::eNullExtents)
continue;
else
break;
}
extents.addExt(ext);
pE- close();
}
}
delete pIter;
}
}
pBlock- close();
//add non constant attributes
AcDbObjectIterator* pIter;
if ((pIter=pRef- attributeIterator())==NULL)
return Acad::eOutOfMemory;
for (pIter- start();!pIter- done();pIter- step())
{
AcDbExtents ext;
if((es=acdbOpenObject(pE,pIter- objectId(),AcDb::kForRead))==Acad::eOk)
{
pE- getGeomExtents(ext);
if (es!=Acad::eOk)
{
pE- close();
if (es==Acad::eNullExtents)
continue;
else
break;
}
extents.addExt(ext);
pE- close();
}
}
delete pIter;
return es;
}//Posts an entity to the database
//
Acad::ErrorStatus postToDb(AcDbEntity* ent, AcDbObjectId objId)
{
Acad::ErrorStatus es;
AcDbBlockTable* pBlockTable;
AcDbBlockTableRecord*pSpaceRecord;
if (NULL == ent)
return Acad::eNullObjectPointer;
if (NULL == acdbHostApplicationServices()- workingDatabase())
return Acad::eNoDatabase;
if ((es = acdbHostApplicationServices()- workingDatabase()- getBlockTable(pBlockTable, AcDb::kForRead))!= Acad::eOk)
return es;
if ((es = pBlockTable- getAt(ACDB_MODEL_SPACE,pSpaceRecord,AcDb::kForWrite))!= Acad::eOk)
{
pBlockTable- close();
return es;
}
pBlockTable- close();
if ((es = pSpaceRecord- appendAcDbEntity(objId, ent)) != Acad::eOk)
{
pSpaceRecord- close();
return es;
}
pSpaceRecord- close();
return ent- close();
本文链接: http://acdb.immuno-online.com/view-762056.html
发布于 : 2021-03-25
阅读(0)
最新动态
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25