222 lines
6.0 KiB
C++
222 lines
6.0 KiB
C++
#include "stdafx.h"
|
|
|
|
// extern TARCH_IMPEXP int GetClipBoundary1(XPoly2D &poly2d);
|
|
|
|
void CutDrawing()
|
|
{
|
|
XPoint pt1, pt3;
|
|
Entity lastent;
|
|
XPoly2D poly(1);
|
|
if (GetClipBoundary1(poly)!=RTNORM)
|
|
return;
|
|
pt1=*poly[0];
|
|
RBList rbPolygon=poly.Polygon();
|
|
|
|
PickSet ss0(SS_FREE), Ssent(SS_FREE);
|
|
if (ss0.Get(_T("CP"), rbPolygon, NULL, NULL)!=RTNORM)
|
|
return;
|
|
|
|
//轴标跟随
|
|
ss0.BaseExclude(RBList(RTDXF0,_T("TCH_AXIS_LABEL"),NULL));//不手工选轴号
|
|
PickSet ssAxis(SS_FREE),ssLabelSet(SS_FREE);
|
|
ssLabelSet.IncludeBegin();
|
|
ssAxis.Get(_T("CP"),rbPolygon,NULL,RBList(RTDXF0,_T("LINE,ARC"),8,LAY_AXIS,NULL));
|
|
XPoint ptMin,ptMax;
|
|
ssAxis.GetExtend(ptMin,ptMax);
|
|
double nOffset=GetPickBoxWcs();
|
|
ptMin.x-=nOffset;
|
|
ptMin.y-=nOffset;
|
|
ptMax.x+=nOffset;
|
|
ptMax.y+=nOffset;
|
|
AssureOnScreen(ptMin,ptMax);
|
|
poly.TransUCS(Groups(1),Groups(0));
|
|
|
|
for(long n=0;n<ssAxis.Length();n++)
|
|
{
|
|
Entity ent=ssAxis[n];
|
|
XCurveSegment cv(ent);
|
|
DList<XCurveSegment> ss,ssIn,ssOut;
|
|
ss.Append(new XCurveSegment(cv));
|
|
PolyClip(ss,poly,ssIn,ssOut);
|
|
if (ssIn.Length()==1)
|
|
{
|
|
XCurveSegment cvNew=*ssIn[0L];
|
|
|
|
PickSet ssOnStart(SS_FREE),ssOnEnd(SS_FREE),ssLabelSet0(SS_FREE);
|
|
XPoint ptOffset(nOffset, nOffset);
|
|
XPoint pt1=cv.StartPoint()+ptOffset;
|
|
XPoint pt2=cv.StartPoint() - ptOffset;
|
|
if (ssOnStart.Get(_T("C"), Wcs2Ucs(pt1), Wcs2Ucs(pt2), RBList(RTDXF0, _T("TCH_AXIS_LABEL"), NULL))==RTNORM)
|
|
ssLabelSet0 += ssOnStart;
|
|
pt1=cv.EndPoint()+ptOffset;
|
|
pt2=cv.EndPoint() - ptOffset;
|
|
if (ssOnEnd.Get(_T("C"), Wcs2Ucs(pt1), Wcs2Ucs(pt2), RBList(RTDXF0, _T("TCH_AXIS_LABEL"), NULL))==RTNORM)
|
|
ssLabelSet0+= ssOnEnd;
|
|
|
|
for(long i=0;i<ssLabelSet0.Length();i++)
|
|
{
|
|
Entity ent=ssLabelSet0[i];
|
|
OPENOBJ_BEGIN(ent,AcDb::kForRead,TDbAxisLabelSet,pSet)
|
|
if (pSet!=NULL)
|
|
{
|
|
XString sLabel;
|
|
int idx=pSet->HitLabel(cv,sLabel);
|
|
if (idx >= 0)
|
|
{
|
|
XCurveSegment cvOld=pSet->GetAxis(idx);
|
|
if (idx<pSet->GetAxisNum())
|
|
{
|
|
TDbAxisLabelSet *pNewSet=(TDbAxisLabelSet*)pSet->clone();
|
|
for(long j=pNewSet->GetAxisNum()-1;j>idx;j--)
|
|
pNewSet->RemoveLabel(j,FALSE);
|
|
while(pNewSet->GetAxisNum()>1)
|
|
pNewSet->RemoveLabel(0,FALSE);
|
|
|
|
if (fabs(cvOld.Direction(cvNew.StartPoint())-cvNew.Direction(cvNew.StartPoint()))>1E-3)
|
|
cvNew.Reverse();
|
|
|
|
pNewSet->SetFirstAxis(cvNew);
|
|
AddToCurrentSpace(pNewSet,Adesk::kTrue);
|
|
}
|
|
}
|
|
}
|
|
OPENOBJ_END()
|
|
}
|
|
}
|
|
}
|
|
ssLabelSet.IncludeEnd();
|
|
|
|
ss0+=ssLabelSet;
|
|
|
|
Ssent.IncludeBegin();
|
|
adsout<<_T("\n请点取插入位置:");
|
|
XPushVar<int> tVar(_T("OSMODE"), 0);
|
|
extern TARCH_IMPEXP BOOL g_bAllowSubCopy;//是否允许复制从属实体(如门窗)
|
|
XPushMemVar<BOOL> vTemp1(g_bAllowSubCopy,FALSE);//保证未选的门窗不会被复制
|
|
// Zyu modify on 100721,支持64位
|
|
//if(ads_command(RTSTR,_T(".COPY"),RTPICKS,(long *)ss0, RTSTR, _T(""),
|
|
// RT3DPOINT, &pt1, RTSTR,_T("\\"),RTNONE)!=RTNORM)
|
|
if(ads_command(RTSTR,_T(".COPY"),RTPICKS,(TLong_ptr *)ss0, RTSTR, _T(""),
|
|
RT3DPOINT, &pt1, RTSTR,_T("\\"),RTNONE)!=RTNORM)
|
|
{
|
|
Ssent.IncludeEnd();
|
|
ssLabelSet.Erase();
|
|
return;
|
|
}
|
|
Ssent.IncludeEnd();
|
|
|
|
ssLabelSet.Erase();
|
|
|
|
|
|
XPoint lastpt;
|
|
//判断按下的最后一个键是否为ESC
|
|
xg_getvar(_T("LASTPOINT"),lastpt);
|
|
pt1=Ucs2Wcs(pt1);
|
|
lastpt=Ucs2Wcs(lastpt);
|
|
if (pt1 == lastpt)
|
|
return;
|
|
ads_matrix mat;
|
|
pt1.GetMoveMatrix(lastpt, mat);
|
|
XPoly2D polyNew(poly), poly2;
|
|
polyNew.TransUCS(mat);
|
|
polyNew.Make();
|
|
ads_entlast(lastent);
|
|
|
|
if (polyNew.PathArea()>0.0)
|
|
polyNew.Reverse();
|
|
if (polyNew.Offset(50.0, poly2)!=RTNORM)
|
|
return;
|
|
AcDbPolyline pline;
|
|
PolyConvert(poly2,pline);
|
|
|
|
Adesk::Int32 length(0);
|
|
ads_sslength(Ssent,&length);
|
|
AcGePoint3dArray intersectPtlist;
|
|
Entity ent;
|
|
for (long i=0;i<length;i++)
|
|
{
|
|
ads_ssname(Ssent,i,ent); // 从选择集中得到实体名3
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, AcDbCurve, pCurve);
|
|
if (pCurve)
|
|
{
|
|
TDbCurveEntity *pTchCurve=TDbCurveEntity::cast(pCurve);
|
|
if (pTchCurve!=NULL)// 实体是上华对象
|
|
{
|
|
// modify by xly on 101220 切割标注时,去掉原图中没有的标注部分
|
|
// 注:原有的方法是通过切割命令实现的,修改后的方法是根据标注对象分析标注对象的点是否在切割线的范围之内
|
|
if (!pCurve->isKindOf(TDbDimension2::desc()))//上华尺寸要裁剪
|
|
continue;
|
|
else
|
|
{
|
|
// 选择的实体是上华的标注类型
|
|
TDbDimension2 *pDim = TDbDimension2::cast(pCurve);
|
|
|
|
// 获得标注的Seg
|
|
TGGePoly3D polyTemp(1);
|
|
pDim->GetPolySegOnDimLine(polyTemp);
|
|
int nLen = polyTemp.Length();
|
|
|
|
// 打开实体
|
|
pDim->upgradeOpen();
|
|
for(int i=0; i<nLen; i++)
|
|
{
|
|
// 获得标注中的所有点
|
|
XPoint ptTemp;
|
|
ptTemp = polyTemp.GetPointListAt(i)->AsAcGePoint3d();
|
|
|
|
// 比较标注中的点是否在裁剪线的范围之内
|
|
if((ptTemp&poly2) == PR_OUTSIDE)// 在范围外
|
|
{
|
|
// 移除切割线外部的点
|
|
pDim->FindAndRemoveSegment(ptTemp);
|
|
if(pDim->GetSegmentNum()==0)// 如果对象没有点点范围内,删除对象
|
|
{
|
|
pDim->erase();
|
|
}
|
|
}
|
|
}
|
|
pDim->downgradeOpen();
|
|
continue;
|
|
}
|
|
}
|
|
pCurve->intersectWith(&pline,AcDb::kOnBothOperands,intersectPtlist);
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
long len=intersectPtlist.length();
|
|
for (int j=0;j<len;j++)
|
|
{
|
|
XPoint ispt=intersectPtlist[j];
|
|
ispt = Wcs2Ucs(ispt);
|
|
ads_command(RTSTR,_T(".TRIM"),RTENAME,lastent.name,RTSTR,_T(""),RTLB,RTENAME,ent.name,RT3DPOINT,&ispt,RTLE,RTSTR,_T(""),RTNONE);
|
|
}
|
|
|
|
for (int n=0;n<len;n++)
|
|
intersectPtlist.removeFirst();
|
|
}
|
|
lastent.Erase();
|
|
|
|
//没有g_bAllowSubCopy变量前用它来删除门窗,但有随机性的不明错误。
|
|
//polyNew.GetExtend(ptMin,ptMax);
|
|
//ptMin.x-=nOffset;
|
|
//ptMin.y-=nOffset;
|
|
//ptMax.x+=nOffset;
|
|
//ptMax.y+=nOffset;
|
|
//AssureOnScreen(ptMin,ptMax);
|
|
//PickSet SS(SS_FREE);
|
|
//Entity ent2;
|
|
//polyNew.TransUCS(Groups(0),Groups(1));
|
|
//polyNew.SetElevation(0);
|
|
// RBList rbPolygonNew=polyNew.Polygon();
|
|
//Ssent.BaseExclude(RBList(RTDXF0,_T("TCH_AXIS_LABEL"),NULL));
|
|
//if (SS.Get(_T("CP"), rbPolygonNew, NULL, NULL)==RTNORM)
|
|
//{
|
|
// Ssent-=SS;
|
|
// Ssent.Erase();
|
|
//}
|
|
|
|
TDbSymbCut *pCut=new TDbSymbCut;
|
|
pCut->SetOutline(polyNew);
|
|
AcDbObjectId id=pCut->AddToMSpace(Adesk::kTrue);
|
|
}
|