 Author Topic: How do I Convert a AcGeCompositeCurve3d to a AcDbPolyline?  (Read 2521 times)

0 Members and 1 Guest are viewing this topic. How do I Convert a AcGeCompositeCurve3d to a AcDbPolyline?
« on: July 21, 2010, 10:51:18 AM »
This is my code.
Code: [Select]
AcDbPolyline * AcGeCurveToAcDbCurve(const AcGeCompositeCurve3d * pGe)

AcGePoint3d startPnt,endPnt;
if(pGe->hasEndPoint(endPnt) == Adesk ::kFalse || pGe->hasStartPoint(startPnt) == Adesk::kFalse)
return NULL;
AcGePlane plane;
pGe->isPlanar(plane);

AcGePoint2d pt;
AcDbPolyline *pPoly = new AcDbPolyline();
AcGeVoidPointerArray curveList;
pGe->getCurveList(curveList);
AcGeCurve3d *pCurve = NULL;
AcGeLine3d *pLine = NULL;
AcGeCircArc3d *arc = NULL;

int i;
for(i = 0;i < curveList.length();i++)
{
pCurve  =  (AcGeCurve3d *) (curveList[i]);
pCurve->hasStartPoint(startPnt);
pt = startPnt.convert2d(plane);
if (pCurve->isKindOf(AcGe::kLineSeg3d))
{
}
else if (pCurve->isKindOf(AcGe::kCircArc3d))
{
arc = (AcGeCircArc3d *)(pCurve);
double b = tan(0.25*(arc->endAng() - arc->startAng()))*(arc->normal().z);
}
}
return pPoly;
}

but when  the normal of AcGeCompositeCurve3d isn't (0 0 1),it works incorrectly. what's the matter?
I am a bilingualist,Chinese and Chinglish. Re: How do I Convert a AcGeCompositeCurve3d to a AcDbPolyline?
« Reply #1 on: July 21, 2010, 10:56:05 AM »

This is the code that can convert a AcDbPolyline to AcGeCompositeCurve3d. it does work.
Code: [Select]
// POLYLINE
AcGeCompositeCurve3d * AcDbCurveToAcGeCurve(const AcDbPolyline * pPoly)
{
AcGeLineSeg3d *pLine = NULL;
AcGeCircArc3d *pArc = NULL;
AcGeVoidPointerArray GeCurves;

for( int i = 0; i < pPoly->numVerts(); i++ )
{
if( pPoly->segType(i) == AcDbPolyline::kLine )
{
pLine = new AcGeLineSeg3d;
pPoly->getLineSegAt(i, *pLine);
GeCurves.append(pLine);
}
else if( pPoly->segType(i) == AcDbPolyline::kArc )
{
pArc = new AcGeCircArc3d;
pPoly->getArcSegAt(i, *pArc);
GeCurves.append(pArc);
}
}
return  new AcGeCompositeCurve3d(GeCurves);
}
I am a bilingualist,Chinese and Chinglish. Re: How do I Convert a AcGeCompositeCurve3d to a AcDbPolyline?
« Reply #2 on: July 22, 2010, 10:27:36 AM »
OK,I found a way to solve this problem. It looks a little clumsy. Does anyone have a easier way?
Code: [Select]
AcDbPolyline * AcGeCurveToAcDbCurve(const AcGeCompositeCurve3d * pGe)

AcGePoint3d startPnt,endPnt;
if( pGe->hasEndPoint(endPnt) == Adesk ::kFalse ||
{
return NULL;
}

//get the plane of Curve3d
AcGePlane plane;
AcGeLine3d line;
AcGePoint3d p1,p2,p3;
if(pGe->isPlanar(plane))
{
if(pGe->isLinear(line))    //Oh,it's a little tricky!
{
line.getPerpPlane(startPnt,plane);
plane.get(p1,p2,p3);
plane.set(p2,p3-p2);
}
plane.get(p1,p2,p3);
}
else
{
return NULL;
}

//Creat a polyline
AcDbPolyline *pPoly = new AcDbPolyline();
AcGeVoidPointerArray curveList;
pGe->getCurveList(curveList);
AcGeCurve3d *pCurve = NULL;
AcGeCircArc3d *pArc = NULL;

int i;
double b;
AcGePoint2d pt;
for(i = 0;i < curveList.length();i++)
{
pCurve  =  (AcGeCurve3d *) (curveList[i]);
pCurve->hasStartPoint(startPnt);
pt = startPnt.convert2d(plane);

if (pCurve->isKindOf(AcGe::kCircArc3d))
{
pArc = (AcGeCircArc3d *)(pCurve);
b = tan(0.25*(pArc->endAng() - pArc->startAng()));
if (pArc->normal().z < 0.0)
{
}
else
{
}
}
else
{
}
}

if(!pGe->isClosed())
{
pt = endPnt.convert2d(plane);
}
else
{
}

//the most important step;
AcGeMatrix3d xform;
AcGeVector3d XAxis = p1-p2;
AcGeVector3d YAxis = p3-p2;
AcGeVector3d ZAxis = XAxis.crossProduct(YAxis);
xform.setCoordSystem(p2,XAxis,YAxis,ZAxis);
pPoly->transformBy(xform);

return pPoly;
}
I am a bilingualist,Chinese and Chinglish.