- UID
- 2299
- 积分
- 465
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-31
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2002-9-17 23:30:52
|
显示全部楼层
-
- // convert AcDbLine to AcGeLineSeg3d
- AcGeLineSeg3d* LineDb2GE(AcDbLine* pDbLine)
- {
- return(new AcGeLineSeg3d(pDbLine->startPoint(), pDbLine->endPoint()));
- }
- // convert AcDbArc to AcGeCircArc3d
- AcGeCircArc3d* ArcDb2Ge( AcDbArc* pDbArc)
- {
- return(new AcGeCircArc3d(
- pDbArc->center(),
- pDbArc->normal(),
- pDbArc->normal().perpVector(),
- pDbArc->radius(),
- pDbArc->startAngle(),
- pDbArc->endAngle()));
- }
- // convert AcDbCircle to AcGeCircArc3d
- AcGeCircArc3d* CircleDb2Ge(AcDbCircle* pDbCircle)
- {
- return(new AcGeCircArc3d(
- pDbCircle->center(),
- pDbCircle->normal(),
- pDbCircle->radius()));
- }
- // convert AcDbSpline to AcGeNurbCurve3d
- AcGeNurbCurve3d* SplineDb2Ge(AcDbSpline* pDbSpline)
- {
- AcGeNurbCurve3d* pGeSpline;
- AcGePoint3dArray fitPoints;
- int degree;
- double fitTolerance;
- Adesk::Boolean tangentsExist;
- AcGeVector3d startTangent, endTangent;
- AcGeTol tol;
- Adesk::Boolean rational, closed, periodic;
- AcGePoint3dArray controlPoints;
- AcGeDoubleArray knots, weights;
- double controlPtTol, knotTol;
- if (pDbSpline->hasFitData()) {
- pDbSpline->getFitData(fitPoints, degree, fitTolerance,
- tangentsExist,startTangent, endTangent);
-
- tol.setEqualPoint(fitTolerance);
- pGeSpline=new AcGeNurbCurve3d(fitPoints, startTangent,
- endTangent, tangentsExist, tangentsExist,tol);
- }else{
- pDbSpline->getNurbsData(degree, rational, closed, periodic,
- controlPoints, knots, weights, controlPtTol, knotTol);
- pGeSpline=new AcGeNurbCurve3d(degree, knots, controlPoints,
- weights, periodic);
- if (closed==Adesk::kTrue)
- pGeSpline->makeClosed();
- };
- return(pGeSpline);
- }
- // convert AcDbEllipse to AcGeEllipArc3d
- AcGeEllipArc3d* EllipseDb2Ge(AcDbEllipse* pDbEllise)
- {
- return(new AcGeEllipArc3d(
- pDbEllise->center(),
- pDbEllise->majorAxis(),
- pDbEllise->minorAxis(),
- pDbEllise->majorAxis().length(),
- pDbEllise->minorAxis().length(),
- pDbEllise->startAngle(),
- pDbEllise->endAngle()));
- }
- //转换AcGeCompositeCurve3d到AcDbPolyline, This routine only called by GetRegionBoundaryPolyline
- AcDbPolyline* convertGeCurveToPolyline(AcGeCompositeCurve3d* pCurve)
- {
- AcGeVoidPointerArray resultCurves;
- AcDbPolyline* pResultPolyline;
- AcGeCurve3d* pThisCurve;
- AcGeCircArc3d* pArc;
- AcGeLineSeg3d* pLine;
- AcGePoint3d startPt,endPt;
-
- int nCurves,i,j;
- double bulge, ang;
- pCurve->getCurveList(resultCurves );
-
- bool bCannotConvert=false;
- nCurves = resultCurves.length();
- for(i=0;i< nCurves;i++){
- pThisCurve = (AcGeCurve3d*)(resultCurves[i]);
- if (pThisCurve->isKindOf(AcGe::kSplineEnt3d) || pThisCurve->isKindOf(AcGe::kEllipArc3d)){
- bCannotConvert=true;
- break;
- }
- };
- if (bCannotConvert) {
- for(i=0;i< nCurves;i++)
- delete (AcGeCurve3d*)(resultCurves[i]);
- acedPrompt("\nCon't Convert to Polyline.");
- return(NULL);
- };
-
- AcGeIntArray isArcs;
- AcGePoint3dArray Vertexes;//存放每一线段的起点和终点
- AcGeDoubleArray bulges;
- for(i=0;i< nCurves;i++){
- pThisCurve = (AcGeCurve3d*)(resultCurves[i]);
-
- if(pThisCurve->isKindOf(AcGe::kCircArc3d)){
- pArc = (AcGeCircArc3d*)pThisCurve;
- isArcs.append(1);
- Vertexes.append(pArc->startPoint());
- Vertexes.append(pArc->endPoint());
- ang = 0.25 * (pArc->endAng() - pArc->startAng());
- bulge = tan(ang);
- bulges.append(bulge);
- }
- else if(pThisCurve->isKindOf( AcGe::kLineSeg3d)){
- pLine = (AcGeLineSeg3d*)pThisCurve;
- isArcs.append(0);
- Vertexes.append(pLine->startPoint());
- Vertexes.append(pLine->endPoint());
- bulges.append(0.0);
- }
- //else nothing, This routine only called by GetRegionBoundaryPolyline
- delete pThisCurve;//Ge对象不再有用,删掉
- }
- j=-1;
- for (i=0;i< nCurves;i++){
- if (isArcs[i]==0){//找到第一条直线
- j=i;
- break;
- }
- }
- pResultPolyline = new AcDbPolyline(nCurves);
- bool bClockWise=false;
- if (j==-1) {//polyline全部由arc构成
- if (Vertexes[0]==Vertexes[3]) bClockWise=true;
- if (bClockWise){
- for(i=0;nCurves;i++)
- pResultPolyline->addVertexAt(i, AcGePoint2d(Vertexes[2*i+1].x,Vertexes[2*i+1].y), -bulges[i]);
- }else{
- for(i=0;nCurves;i++)
- pResultPolyline->addVertexAt(i, AcGePoint2d(Vertexes[2*i].x,Vertexes[2*i].y), bulges[i]);
- }
- }else{
- for(i=j+1;i< nCurves;i++){
- if ((isArcs[i]==1)&&(Vertexes[2*i]!=Vertexes[2*i-1])){
- //当前圆弧的起点不等于上一线段的终点
- startPt=Vertexes[2*i+1];
- endPt=Vertexes[2*i];
- Vertexes[2*i+1]=endPt;
- Vertexes[2*i]=startPt;
- bulges[i]=-bulges[i];
- }
- };
- for(i=j-1;i >=0;i--){
- if ((isArcs[i]==1)&&(Vertexes[2*i+1]!=Vertexes[2*(i+1)])){
- //当前圆弧的终点不等于下一线段的起点
- startPt=Vertexes[2*i+1];
- endPt=Vertexes[2*i];
- Vertexes[2*i+1]=endPt;
- Vertexes[2*i]=startPt;
- bulges[i]=-bulges[i];
- }
- };
- for(i=0;nCurves;i++)
- pResultPolyline->addVertexAt(i, AcGePoint2d(Vertexes[2*i].x,Vertexes[2*i].y), bulges[i]);
- }
- pResultPolyline->close();
- return(pResultPolyline);
- }
- //获取Region的边界PolyLines/Circles/Ellipses/Splines, 返回环的数目
- int GetRegionBoundaryPolyline(AcDbRegion *pRegion, AcDbVoidPtrArray*& pPolylines)
- {
- AcDbVoidPtrArray subEntityArray;
- AcGeVoidPointerArray tmpGeCurves;
- int i, count=0;;
- if (pRegion->explode(subEntityArray)!=Acad::eOk){
- for (i=0;i< subEntityArray.length();i++)
- delete (AcDbObject*)subEntityArray[i];//To XDSoft: 需要手工删除
- return 0;
- }
- AcDbCurve* pDbCurve;
- for (i=0;i< subEntityArray.length();i++){
- pDbCurve=(AcDbCurve*)subEntityArray[i];
- if (pDbCurve->isClosed()){
- //this curve(Circle/Spline/Ellipse) is closed, then return the boundary(Circle/Spline/Ellipse)
- pPolylines->append(pDbCurve);
- count++;
- }else{
- if(pDbCurve->isKindOf(AcDbLine::desc()))
- tmpGeCurves.append(LineDb2GE(AcDbLine::cast(pDbCurve)));
- else if(pDbCurve->isKindOf(AcDbArc::desc()))
- tmpGeCurves.append(ArcDb2Ge(AcDbArc::cast(pDbCurve)));
- else if(pDbCurve->isKindOf(AcDbSpline::desc()))
- tmpGeCurves.append(AcDbSpline::cast(pDbCurve));
- else if(pDbCurve->isKindOf(AcDbEllipse::desc()))
- tmpGeCurves.append(AcDbEllipse::cast(pDbCurve));
- //else I don't know
- delete pDbCurve;
- }
- };
- AcGeIntArray isOwnerOfCurves;
- AcGeCompositeCurve3d* pGeCompositeCurve;
- AcDbPolyline *pPloyline;
- while (tmpGeCurves.length()>0){
- isOwnerOfCurves.setLogicalLength(0);
- for (i=0;i< tmpGeCurves.length();i++)
- isOwnerOfCurves.append(1);
- pGeCompositeCurve=new AcGeCompositeCurve3d(tmpGeCurves,isOwnerOfCurves);
- if (pGeCompositeCurve==NULL){
- for (i=0;i< tmpGeCurves.length();i++)
- delete (AcGeCurve3d*)tmpGeCurves[i];
- count=-count;//负数表示有部分边界被获得,但出错
- break;
- }
- pPloyline=convertGeCurveToPolyline(pGeCompositeCurve);
- delete pGeCompositeCurve;//连带删除tmpGecurve
- if (pPloyline!=NULL){
- pPolylines->append(pPloyline);
- count++;
- }
- }
- return(count);
- }
复制代码 [/FONT] |
|