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;
}
Пример #2
0
Acad::ErrorStatus
AcDbXmlPoly::xmlOut(
    AcDbObject* pObj,
    AcDbXmlOutFiler* pFiler)
{
    Acad::ErrorStatus es = eOk;

    AsdkPoly* pPoly = AsdkPoly::cast(pObj);
    if (!pPoly)
        return eInvalidInput;

    AcUtXMLDOMNode* pNode = NULL;
    AcUtXMLDOMElement* pElement = NULL;
    AcUtXMLDOMAttribute* pAttribute = NULL;

    try {
        es = pFiler->pushNode(L"asdk:Poly", MY_SCHEMA, pNode);
        if (es != eOk)
            throw es;

        pElement = new AcUtXMLDOMElement(pNode);
        if (pElement == NULL)
            throw eOutOfMemory;

        es = superXmlOut(pObj, pFiler);
        if (es != eOk)
            throw es;

        es = pFiler->appendAttribute(pPoly->numSides(), L"numSides", 
            pElement);
        if (es != eOk)
            throw es;

        AcUtString name=pPoly->name();
        es = pFiler->appendAttribute(name, L"name", pElement);
        if (es != eOk)
            throw es;

        AcGePoint2d pt2d = pPoly->center();
        AcGePoint3d centerPt(pt2d.x, pt2d.y, pPoly->elevation());

        // Convert the point from ECS to WCS
        acdbEcs2Wcs(asDblArray(centerPt), asDblArray(centerPt),
            asDblArray(pPoly->normal()), true);

        es = pFiler->writePoint(L"dxml:CenterPoint", centerPt);
        if (es != eOk)
            throw es;

        pt2d = pPoly->startPoint();
        AcGePoint3d startPt(pt2d.x, pt2d.y, pPoly->elevation());
        // Convert the point from ECS to WCS
        acdbEcs2Wcs(asDblArray(startPt), asDblArray(startPt),
            asDblArray(pPoly->normal()), true);

        es = pFiler->writePoint(L"dxml:StartPoint", startPt);
        if (es != eOk)
            throw es;

        es = pFiler->writeNormalVector(pPoly->normal());
        if (es != eOk)
            throw es;

        es = pFiler->writeHardPointerId(L"acdb:TextStyleTableRecordId", 
            pPoly->styleId());
        if (es != eOk)
            throw es;

        es = pFiler->popNode();
        if (es != eOk)
            throw es;
    }

    catch (Acad::ErrorStatus thrownEs) {
        es = thrownEs;
    }

    if (pAttribute)
        delete pAttribute;
    if (pElement)
        delete pElement;
    if (pNode && pNode != pFiler->getCurrentNode())
        delete pNode;

    return es;
}
Пример #3
0
//-----------------------------------------------------------------------------
// Constructor that accepts a reference to a CRectInfo class which
// contains all the information need to initialize the polyline entitiy
// that will be used for dragging and ultimately be the polyline that
// gets to the database if all goes well. 
//
AsdkRectangleJig::AsdkRectangleJig()
{ 
    m_pLWPoly = new AcDbPolyline();
    samplerCorner = AcGePoint3d();
    plineInfo.m_cornerTreatment = plineInfo.m_first != 0.0
        || plineInfo.m_second != 0.0
        || plineInfo.m_radius != 0.0;

    // Now need to get the current UCS Z-Axis to be used as the normal vector 
    // for the rectangle. At the same time, we get the x and y unit direction 
    // vectors used later.
    //
    if(inPaperSpace()) {
      m_vecUnitX = acdbHostApplicationServices()->workingDatabase()->pucsxdir();
      m_vecUnitY = acdbHostApplicationServices()->workingDatabase()->pucsydir();
    } else {
      m_vecUnitX = acdbHostApplicationServices()->workingDatabase()->ucsxdir();
      m_vecUnitY = acdbHostApplicationServices()->workingDatabase()->ucsydir();
    }

    m_vecUnitZ = m_vecUnitX.crossProduct(m_vecUnitY);

    // Convert the incomming UCS point to ECS coordinate system
    //
    acdbUcs2Ecs(asDblArray(plineInfo.m_topLeftCorner), 
        asDblArray(m_TopLeftCorner), asDblArray(m_vecUnitZ), Adesk::kFalse);
    acdbUcs2Ecs(asDblArray(plineInfo.m_topLeftCorner), 
        asDblArray(plineInfo.m_topLeftCorner), asDblArray(m_vecUnitZ),
        Adesk::kFalse);
    AcGePoint2d initPoint;
    initPoint = AcGePoint2d(m_TopLeftCorner[X], m_TopLeftCorner[Y]);

    // If the user has set the elev option from the main command prompt,
    // then this will be the default until the user again sets it to 0.0.
    // If however the user simply picks a point with or without an object
    // snap, then use the Z value of the first point picked.
    //
    if (plineInfo.m_elevHandSet == TRUE)
        m_pLWPoly->setElevation(plineInfo.m_elev);
    else
        m_pLWPoly->setElevation(m_TopLeftCorner[Z]);

    // If we are indeed filleting or chamfering the corners, then
    // we'll add the extra verticies here to have their bulges and
    // distances from the real corner changed on the fly.
    // 
    if (plineInfo.m_cornerTreatment == TRUE) {
        for (int i = 0 ; i < 8; i++)
                m_pLWPoly->addVertexAt(i, initPoint);
    } else {
        for (int i = 0 ; i < 4; i++)
                m_pLWPoly->addVertexAt(i, initPoint);
    }

    m_pLWPoly->setNormal(m_vecUnitZ);
    m_pLWPoly->setClosed(Adesk::kTrue);
    m_pLWPoly->setThickness(plineInfo.m_thick);
    m_pLWPoly->setConstantWidth(plineInfo.m_width);
    // Get the current default linetype scale
    m_pLWPoly->setLinetypeScale(acdbHostApplicationServices()
        ->workingDatabase()->celtscale());
    // Now for jig dragger purposes, convert the point back to world
    // coordinates.
    //
    acdbEcs2Wcs(asDblArray(m_TopLeftCorner), 
        asDblArray(m_TopLeftCorner), asDblArray(m_vecUnitZ), Adesk::kFalse);
    acdbEcs2Wcs(asDblArray(plineInfo.m_topLeftCorner), 
        asDblArray(plineInfo.m_topLeftCorner), asDblArray(m_vecUnitZ),
        Adesk::kFalse);
}