- UID
- 59465
- 积分
- 267
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-6-18
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2003-8-11 14:21:21
|
显示全部楼层
好久不见,谢谢先
嗯,现在改的差不多了~
下面是完整的代码:
- [FONT=courier new]
- //逐点标注
- void gradDim()
- {
- ads_point stpt,pt1,pt2,enpt,prept,dimpt;
- ads_name ssname,entres,EntityName;
- struct resbuf pRb,*pointlist;
- AcDbObjectId objId,objId1,LayerId,dimStyleId;
- AcDbEntity *pEnt,*pEnt1;
- Adesk::Boolean KeepPick = Adesk::kTrue;
- AcDbPolyline *polyline;
- Acad::ErrorStatus es;
- int retCode = ads_getpoint(NULL,"\n点取<逐点标注>起始点<退出>:",stpt);
- if(retCode != RTNORM) return;
- retCode = ads_getpoint(stpt,"\n点取结束点<退出>:",enpt);
- if(retCode != RTNORM) return;
- pt1[X] = enpt[X];
- pt1[Y] = stpt[Y];
-
- pt2[X] = enpt[X];
- pt2[Y] = stpt[Y];
-
- //获取选择集过滤List(由实体名称过滤)
- pointlist = ads_buildlist(RTPOINT,stpt, RTPOINT,pt1,RTPOINT,enpt,RTPOINT,pt2,0);
- char sbuf[50]; // Buffers to hold strings
- pRb.restype = 0; //实体名称
- strcpy(sbuf, "LWPOLYLINE");
- strupr(sbuf);
- pRb.resval.rstring = sbuf;
- pRb.rbnext = NULL;
- //初步拾取选择集
- retCode = ads_ssget("CP",pointlist,NULL,&pRb,ssname);
- if(retCode != RTNORM)
- return;
-
- //取得选择实体个数
- long NumOfEntity;
- retCode = ads_sslength(ssname,&NumOfEntity);
-
- //再次过滤,取得符合条件的实体
- for(long i = 0 ; i < NumOfEntity; i++)
- {
- ads_ssname(ssname,i,EntityName);
-
- acdbGetObjectId(objId,EntityName);
-
- if(acdbOpenObject(pEnt,objId,AcDb::kForRead)!=Acad::eOk)
- {
- ads_printf("\n打开实体时出错!");
- return;
- }
- polyline = AcDbPolyline::cast(pEnt);
- int iNum = polyline->numVerts();
- AcGePoint2d p0,p1,p2,p3;
- AcGeVector2d v1,v2,v3;
- AcGeTol aTol;
-
- aTol.setEqualVector(0.001);
-
- //取得polyline上各点
- polyline->getPointAt(0,p0);
- polyline->getPointAt(1,p1);
- polyline->getPointAt(2,p2);
- polyline->getPointAt(3,p3);
-
- polyline->close();
- //取得各分段向量
- v1 = p1 - p0;
- v2 = p2 - p1;
- v3 = p3 - p2;
-
- //设置过滤条件,"rectang"
- if(iNum == 4)
- {
- if((p0.x == p1.x || p0.y == p1.y)&&(abs(v1.dotProduct(v2)/(v1.length()*v2.length()))<=0.001)&&
- (abs(v2.dotProduct(v3)/(v2.length()*v3.length()))<=0.001))
- {
- pEnt->highlight();
- pEnt->close();
- }
- else
- {
- pEnt->close();
- ads_ssdel(EntityName,ssname);
- }
-
- }
- else
- {
- pEnt->close();
- ads_ssdel(EntityName,ssname);
- }
-
- }
- //选择不需要标注的线
- while(KeepPick)
- {
- retCode = ads_entsel("\n选择不需要标注的线<无>:",entres,prept);
- if(retCode == RTNORM)
- {
- acdbGetObjectId(objId1,entres);
- acdbOpenAcDbEntity(pEnt1,objId1,AcDb::kForRead);
- pEnt1->unhighlight();
- pEnt1->close();
- ads_ssdel(entres,ssname);
-
- }
- else
- {
- //关闭亮显
- for(i = 0 ; i < NumOfEntity; i++)
- {
- ads_ssname(ssname,i,EntityName);
-
- acdbGetObjectId(objId,EntityName);
-
- if(acdbOpenObject(pEnt,objId,AcDb::kForRead)!=Acad::eOk)
- {
- ads_printf("\n打开实体时出错!");
- return;
- }
- pEnt->unhighlight();
- pEnt->close();
-
- }
- KeepPick = Adesk::kFalse;
- break;
- }
- }
- //构造直线
- AcGePoint3dArray ptArr;
- AcGeVector3d vec, vec1(1,0,0);
- AcGePoint3d Cenpt,stPt,enPt,Cenpt1;
- stPt = asPnt3d(stpt);
- enPt = asPnt3d(enpt);
- vec = enPt - stPt;
- //取得直线倾角
- double dAngle = vec1.angleTo(vec);
- //取得两选点的中点
- getCenpt(stPt,enPt,Cenpt);
- AcGeVector3d Lvec(1,0,0);
- Cenpt1[X] = Cenpt[X]*2;
- Cenpt1[Y] = Cenpt[Y];
-
- if((dAngle >= PI/4 && dAngle <= 3*PI/4)||(dAngle >= 5*PI/4 && dAngle <= 7*PI/4))
- {
- Lvec.rotateBy(PI/2,AcGeVector3d(0,0,1));
- Cenpt1[X] = Cenpt[X];
- Cenpt1[Y] = Cenpt[Y]*2;
- }
- AcDbLine *pLine = new AcDbLine(Cenpt,Cenpt1);
- AcGeLine3d ple(Cenpt,Lvec);
- double DimLen;
-
- //取得尺寸线位置
- retCode = ads_getpoint(asDblArray(Cenpt),"\n点取尺寸线的位置<原位标注>:",dimpt);
- if(retCode != RTNORM) return;
- DimLen = ple.distanceTo(asPnt3d(dimpt));
-
- //取得直线pLine和选择集里面实体的交点集
- retCode = ads_sslength(ssname,&NumOfEntity);
- for(i = 0 ; i < NumOfEntity; i++)
- {
- AcGePoint3dArray ptArrAdd;
- ads_ssname(ssname,i,EntityName);
-
- acdbGetObjectId(objId,EntityName);
-
- if(acdbOpenObject(pEnt,objId,AcDb::kForRead)!=Acad::eOk)
- {
- ads_printf("\n打开实体时出错!");
- return;
- }
- es = pLine->intersectWith(pEnt,AcDb::kExtendBoth,ptArrAdd);
-
- for(int k = 0; k < ptArrAdd.length(); k++)
- {
- ptArr.append(ptArrAdd.at(k));
- }
- pEnt->close();
- ads_ssfree(EntityName);
- }
- //把取得的点集排序
- if((dAngle >= PI/4 && dAngle <= 3*PI/4)||(dAngle >= 5*PI/4 && dAngle <= 7*PI/4))
- {
- //按各点的Y值排序
- sort(ptArr,2);
- }
- else
- //按各点的X值排序
- sort(ptArr,1);
- //创建Dim层
- gCyz_ArxBegin();
- //取得层的ID,如果层不存在则创建然后取得层的ID
- LayerId = gConfig.GetLayerId(LBIAOZHU);
- //取得DimensionStyle的ID,如果DimensionStyle不存在则创建然后取得DimensionStyle的ID
- dimStyleId=gConfig.GetDimStyleId();
- gCyz_ArxEnd();
- AcGePoint3d sPt,ePt,DimPt;
- double DimDist;
- int iDist;
- CString str;
- AcDbObjectId retId;
- //创建标注
- for(i = 0 ; i < ptArr.length() - 1; i++)
- {
- AcDbAlignedDimension *pNewDim = new AcDbAlignedDimension;
- sPt = ptArr.at(i);
- ePt = ptArr.at(i+1);
- //取得长度值
- DimDist = sPt.distanceTo(ePt);
- iDist = (int)DimDist;
- if((DimDist - iDist) > 0.5) iDist += 1;
- str.Format("%d",iDist);
- DimPt.set((sPt.x + ePt.x)/2,(sPt.y + ePt.y)/2,0);
- Lvec.normalize();
-
- if(asPnt3d(dimpt).x <= Cenpt.x || asPnt3d(dimpt).y > Cenpt.y )
- DimPt += (Lvec.perpVector())*DimLen;
- else
- DimPt -= (Lvec.perpVector())*DimLen;
- pNewDim->setXLine1Point(ptArr.at(i));
- pNewDim->setXLine2Point(ptArr.at(i+1));
- pNewDim->setDimensionStyle(dimStyleId);
- pNewDim->setDimLinePoint(DimPt);
- pNewDim->setLayer(LayerId);
- pNewDim->setDimensionText(str);
-
- //把实体加入到数据库中
- addToModelSpace(retId,pNewDim);
- pNewDim->close();
- }
- pLine->close();
- ads_relrb(pointlist);
- ads_ssfree(ssname);
- }
- [/FONT]
|
|