|
- static void deepCloneEntity ( AcDbObjectIdArray sourceObjectList, AcDbObjectIdArray& descObjectList )
- {
- //----不清空输出数组的元素,仅仅将克隆得到的实体追加输出
- // if ( descObjectList.length() > 0 )
- // {
- //清空目的对象数组
- // descObjectList.removeSubArray(0,descObjectList.length()-1);
- // }
- //----获取模型空间的对象ID
- AcDbBlockTable *pBlockTable = NULL;
- if ( acdbCurDwg()->getBlockTable ( pBlockTable, AcDb::kForRead ) != Acad::eOk )
- return ;
- AcDbObjectId modelSpaceId;
- pBlockTable->getAt ( ACDB采用MODEL采用SPACE, modelSpaceId );
- pBlockTable->close();
- //----克隆实体
- //----不能使用单个克隆的方案,否则sourceObjectList内实体间的引用关系得不到相应克隆
- AcDbIdMapping idMap;
- if ( acdbCurDwg()->deepCloneObjects ( sourceObjectList, modelSpaceId, idMap ) != Acad::eOk )
- return ;
- //----对新生成的对象参考输入顺序排序
- AcDbIdMappingIter iter ( idMap );
- AcDbIdPair idPair;
- AcDbObjectId id;
- for ( int i = 0; i < sourceObjectList.length(); i++ )
- {
- id = sourceObjectList.at ( i );
- for ( iter.start(); !iter.done(); iter.next() )
- {
- iter.getMap ( idPair );
- if ( id == idPair.key() )
- {
- if ( idPair.isCloned() )
- descObjectList.append ( idPair.value() );
- break;
- }
- }
- }
- }
- //transformByMatrix(entityArray,newUCS.inverse());
- static void transformByMatrix(AcDbObjectIdArray& entityArray,AcGeMatrix3d matrixTran,short flag=1)
- {
- AcDbObjectIdArray newObjectArray;
- if(flag)
- {
- //deep clone entity
- deepCloneEntity(entityArray,newObjectArray);
- entityArray=newObjectArray;
- }
- // else
- // {
- // newObjectArray=entityArray;
- // }
- for(int i=0;i<entityArray.length();i++)
- {
- AcDbObject* pObj1=NULL;
- Acad::ErrorStatus es;
- if((es = acdbOpenAcDbObject(pObj1, entityArray[i],AcDb::kForWrite))!=Acad::eOk)
- {
- continue;
- }
- AcDbEntity* pEnt;
- pEnt=AcDbEntity::cast(pObj1);
- if(pEnt!=NULL)
- {
- //根据需要转化
- pEnt->transformBy(matrixTran);
- }
- pObj1->close();
- }
- }
- static AcGeMatrix3d getTransMatrix3d(AcGePoint3d startPoint,AcGePoint3d endPoint)
- {
- AcGePoint3d tolerancePt;
- tolerancePt[0]=startPoint[0];
- tolerancePt[1]=startPoint[1];
- tolerancePt[2]=startPoint[2];
- if( fabs(startPoint.z-endPoint.z) < 1e-7)//g采用tolerance管件误差
- {
- tolerancePt.z = startPoint.z + 5000.0;
- }
- else
- {
- //tolerancePt.x = insert采用pt.x + 5000.0;
- AcGeVector3d dirction1=endPoint-startPoint;
- if(dirction1.x==0 && dirction1.y==0)
- {
- //这种情况属于平行z轴方向的插入
- tolerancePt.x = startPoint.x + 5000.0;
- }
- else
- {
- //在插入点与延伸点为空间两点时确定y轴点
- AcGeVector3d dirciton2=AcGeVector3d(dirction1.x,dirction1.y,0);
- AcGeVector3d dirciton3=dirciton2.crossProduct(dirction1);
- AcGeVector3d dirciton4=dirciton3.crossProduct(dirction1);
- tolerancePt=startPoint+dirciton4;
- }
- }
- //得到转化阵列
- AcGeMatrix3d oldUCS,newUCS;
- oldUCS=setUCS(startPoint,endPoint,tolerancePt);
- acedGetCurrentUCS(newUCS);
- acedSetCurrentUCS(oldUCS);
- return newUCS;
- }
-
- //本函数代替ucs 3p
- static AcGeMatrix3d setUCS(AcGePoint3d orient,AcGePoint3d xPoint,AcGePoint3d yPoint)
- {
- //将ucs中点转化到wcs
- AcGeMatrix3d oldUCS;
- // AcDbDatabase* currDatabase=acdbHostApplicationServices()->workingDatabase();
- // acdbUcsMatrix(oldUCS,currDatabase);//当前坐标系
- acedGetCurrentUCS(oldUCS);
- //将ucs中点转化到wcs
- wcsToucs(orient);
- wcsToucs(xPoint);
- wcsToucs(yPoint);
- //计算新的z抽向量,
- AcGeVector3d vec1=AcGeVector3d(xPoint[0]-orient[0],
- xPoint[1]-orient[1],
- xPoint[2]-orient[2]);
- AcGeVector3d vec2=AcGeVector3d(yPoint[0]-orient[0],
- yPoint[1]-orient[1],
- yPoint[2]-orient[2]);
- AcGeVector3d xAxis=vec1;
- AcGeVector3d zAxis=xAxis.crossProduct(vec2);
- AcGeVector3d yAxis=zAxis.crossProduct(xAxis);
- xAxis.normalize();
- yAxis.normalize();
- zAxis.normalize();
- AcGeMatrix3d newUCS;
- newUCS.setCoordSystem(orient,xAxis,yAxis,zAxis);
- Acad::ErrorStatus es=acedSetCurrentUCS(newUCS);
- return oldUCS;
- }
- static int wcsToucs(ads采用point& pt)
- {
- struct resbuf wcs;
- wcs.restype=RTSHORT;
- wcs.resval.rint=0;
- struct resbuf ucs;
- ucs.restype=RTSHORT;
- ucs.resval.rint=1;
- return acedTrans(pt,&ucs,&wcs,false,pt);
- }
- static int wcsToucs(AcGePoint3d& pt)
- {
- ads采用point tp={pt[0],pt[1],pt[2]};
- int ret = wcsToucs(tp);
- pt=AcGePoint3d(tp[0],tp[1],tp[2]);
- return ret;
- }
复制代码 |
|