Acad::ErrorStatus 
rx_makeArc(const AcGePoint3d    pt1, 
           const AcGePoint3d    pt2, 
                 double         bulge,
           const AcGeVector3d   entNorm,
                 AcGeCircArc3d& arc)
{
    Acad::ErrorStatus es = Acad::eOk;

    // The points that are coming in are in ECS. These are actually
    // 2d points, may be with an elevation in the z coord.
    //
    // Therefore, let's create a 2d arc from these values and transform
    // the relevant data of the arc for creating a 3d arc.

    AcGeCircArc2d arc2d;
    AcGePoint2d p1, p2;

    assert(fabs(pt1[Z] - pt2[Z]) < 1.0e-10);

    p1.set(pt1[X], pt1[Y]); p2.set(pt2[X], pt2[Y]);
    arc2d.set(p1, p2, bulge);

    AcGePoint3d center((arc2d.center())[X], (arc2d.center())[Y], pt1[Z]);
    AcGePoint3d startPnt((arc2d.startPoint())[X], 
                         (arc2d.startPoint())[Y], pt1[Z]);
    AcGePoint3d endPnt((arc2d.endPoint())[X], (arc2d.endPoint())[Y], pt1[Z]);

    // If the arc is CW, flip the normal.

    AcGeVector3d norm;

    if (arc2d.startAng() > arc2d.endAng()) {
	norm.set(0, 0, -1);
    } else {
	norm.set(0, 0, 1);
    }

    double incAng = fabs(arc2d.endAng() - arc2d.startAng());

    // Transform all the data to WCS.

    acdbEcs2Wcs(asDblArray(center), asDblArray(center), asDblArray(entNorm), 
							    Adesk::kFalse);
    acdbEcs2Wcs(asDblArray(startPnt), asDblArray(startPnt), asDblArray(entNorm), 
							    Adesk::kFalse);
    acdbEcs2Wcs(asDblArray(endPnt), asDblArray(endPnt), asDblArray(entNorm), 
							    Adesk::kFalse);
    acdbEcs2Wcs(asDblArray(norm), asDblArray(norm), asDblArray(entNorm), 
							    Adesk::kTrue);

    arc.set(center, norm, norm.perpVector(),
	(startPnt - center).length(), 0, incAng);

    return es;
}
Exemple #2
0
void
AcCircle::gripDimensionCbackfn(				AcDbGripData* pThis,
											const AcDbObjectId& entId,
											double dimScale,
											AcDbDimDataPtrArray& dimData)
{
		std::string *pszAppData  = static_cast<std::string *>(pThis->appData());

		
		AcDbEntity *pEnt = NULL;
		Acad::ErrorStatus es(Acad::eNotImplementedYet);

		if( Acad::eOk != acdbOpenAcDbEntity(pEnt,entId,AcDb::kForRead) ){
			acutPrintf("\n Error in returning valid pointer to an Entity");
			return;
		}
		
		AcCircle   *pCircle = static_cast<AcCircle *>(pEnt);
		mentId = entId;
		
		AcGeVector3d mNormal = pCircle->normal();

		AcGeVector3d NormalDir    = pCircle->normal();
		
		AcGeVector3d horizDir =		mNormal.perpVector();
		AcGeVector3d vertDir =		mNormal.crossProduct(horizDir);
		
		AcGePoint3d  center	  = pCircle->Center();
		double		 radius	      = pCircle->radius();
        int          dimIndex1(0);




		AcGePoint3d points[5] =
		{
			center,
			center + radius * horizDir,
			center + radius * vertDir,
			center - radius * horizDir,
			center - radius * vertDir
		};

		AcGePoint3d dimPt1,dimPt2;


	    AcDb2LineAngularDimension *pDim1 = new  AcDb2LineAngularDimension ();
		pDim1->setDatabaseDefaults();

		pDim1->setNormal(NormalDir);


		if( *pszAppData == "First")
		{
		      dimIndex1 =1;
		      dimPt1 = center + (1.5 * radius + 0.5 * dimScale) * horizDir;

		      pDim1->setXLine1Start(points[0]);
	      	  pDim1->setXLine1End(points[1]);
		      pDim1->setXLine2Start(points[0]);
		      pDim1->setXLine2End(points[2]);
		      pDim1->setArcPoint(dimPt1);
		}
		else if( *pszAppData == "Second")
		{
            dimIndex1=2;
			dimPt1 =  center + (1.5* radius + 0.5 * dimScale) * vertDir;
			pDim1->setXLine1Start(points[0]);
			pDim1->setXLine1End(points[2]);

			pDim1->setXLine2Start(center);
			pDim1->setXLine2End(points[3]);
			pDim1->setArcPoint(dimPt1);

		}
		else if(*pszAppData == "Third")
		{
			dimIndex1=3;
			dimPt1 =  center -  (1.5*radius + 0.5 * dimScale) * horizDir;
			pDim1->setXLine1Start(points[0]);
			pDim1->setXLine1End(points[3]);

			pDim1->setXLine2Start(points[0]);
			pDim1->setXLine2End(points[4]);
			pDim1->setArcPoint(dimPt1);
		}
		else if( *pszAppData == "Fourth")

		{
			dimIndex1=4;
			dimPt1 =  center - (1.5 * radius + 0.5 * dimScale) * vertDir;
			pDim1->setXLine1Start(points[0]);
			pDim1->setXLine1End(points[4]);

			pDim1->setXLine2Start(points[0]);
			pDim1->setXLine2End(points[1]);
			pDim1->setArcPoint(dimPt1);
		}

		unsigned int bitFlags(0);
		unsigned int bitRetFlags(0);
		AcDbDimData *pdimData1=NULL;
		pdimData1 = new AcDbDimData();
		es =pdimData1->setDimension(pDim1);
		bitFlags = AcDbDimData::kDimEditable;			
		es =pdimData1->setBitFlags(bitFlags);
		
		es =pdimData1->setAppData(&dimIndex1);
		es =pdimData1->setOwnerId(mentId);
		dimData.append(pdimData1);
		pCircle->close();
}