Пример #1
0
Acad::ErrorStatus
ArxDbgDbEntity::setNormal(const AcGeVector3d& nvec)
{
    if (nvec.isZeroLength()) {
        ASSERT(0);
        return Acad::eInvalidInput;
    }

    if (nvec != m_zDir) {
        assertWriteEnabled();

        AcGeVector3d txdir, tydir;
        AcGeVector3d txdiro, tydiro;

        ArxDbgUtils::getEcsXAxis(nvec, txdir);       // get AutoCAD's arbitrary X-Axis for this normal
        ArxDbgUtils::getEcsXAxis(m_zDir, txdiro);    // get AutoCAD's arbitrary X-Axis for this normal

        tydir = nvec.crossProduct(txdir);
        tydir.normalize();

        tydiro = m_zDir.crossProduct(txdiro);
        tydiro.normalize();

        AcGeMatrix3d mat;
        mat.setToAlignCoordSys(m_origin, txdiro, tydiro, m_zDir,
                               m_origin, txdir,  tydir,  nvec);

        m_xDir.transformBy(mat);
        m_zDir.transformBy(mat);
        m_origin.transformBy(mat);
    }

    return Acad::eOk;
}
void
ArxDbgUtils::getEcsToWcsMatrix(const AcGePoint3d& origin,
                    const AcGeVector3d& zAxis, AcGeMatrix3d& mat)
{
    const double kArbBound = 0.015625;         //  1/64th

        // short circuit if in WCS already
    if (zAxis == AcGeVector3d::kZAxis) {
        mat.setToIdentity();
        return;
    }

    AcGeVector3d xAxis, yAxis;

    ASSERT(zAxis.isUnitLength());

    if ((fabs(zAxis.x) < kArbBound) && (fabs(zAxis.y) < kArbBound))
        xAxis = AcGeVector3d::kYAxis.crossProduct(zAxis);
    else
        xAxis = AcGeVector3d::kZAxis.crossProduct(zAxis);

    xAxis.normalize();
    yAxis = zAxis.crossProduct(xAxis);
    yAxis.normalize();

    mat.setCoordSystem(AcGePoint3d::kOrigin, xAxis, yAxis, zAxis);
}
Пример #3
0
void
createSmiley()
{
    AcGePoint3d cen;
    struct resbuf rbFrom, rbTo;

    ads_getpoint( NULL, "\nCenter point: ", asDblArray( cen ));

    rbFrom.restype = RTSHORT;
    rbFrom.resval.rint = 1; // from UCS
    rbTo.restype = RTSHORT;
    rbTo.resval.rint = 0; // to WCS

    ads_trans( asDblArray( cen ), &rbFrom, &rbTo, Adesk::kFalse, asDblArray( cen ));

    AcGeVector3d x = acdbHostApplicationServices()->workingDatabase()->ucsxdir();
    AcGeVector3d y = acdbHostApplicationServices()->workingDatabase()->ucsydir();

    AcGeVector3d normalVec = x.crossProduct( y );
    normalVec.normalize();

    SmileyJig jig( cen, normalVec );

    jig.start();
}
Пример #4
0
AcGeVector3d PDEcone::getFaceVect() const
{
    assertReadEnabled();
    AcGeVector3d centerVect = m_ptEnd - m_ptStart;
	AcGeVector3d tmpV1 = centerVect.crossProduct(m_vect);
	return m_vect.crossProduct(tmpV1).normal();
}
Пример #5
0
AcGePoint3d PDEcone::getEndPtOrthoInStartPtPlane()const
{
	assertReadEnabled();

	AcGeVector3d centerVect = m_ptEnd - m_ptStart;
	AcGeVector3d tmpV = centerVect.crossProduct(m_vect);
	tmpV = m_vect.crossProduct(tmpV);
	return m_ptEnd.orthoProject(AcGePlane(m_ptStart, tmpV));
}
Пример #6
0
AcGeVector3d DoubleArcTunnelDraw::getEndPointInExtendAngle() const
{
    AcGeCircArc3d arc( m_startPt, m_thirdPt, m_endPt );
    AcGePoint3d cenPt = arc.center();
    AcGeVector3d v = m_endPt - cenPt;
    AcGeVector3d v2 = m_startPt - m_endPt;
    AcGeVector3d v3 = v.crossProduct( v2 );
    int c = ( v3.z > 0 ? 1 : -1 );
    v.rotateBy( c * PI / 2, AcGeVector3d::kZAxis );
    return v;
}
// This function uses the AcEdJig mechanism to create and
// drag an ellipse entity.  The creation criteria are
// slightly different from the AutoCAD command.  In this
// case, the user selects an ellipse center point and then,
// drags to visually select the major and minor axes
// lengths.  This sample is somewhat limited; if the
// minor axis ends up longer than the major axis, then the
// ellipse will just be round because the radius ratio
// cannot be greater than 1.0.
//
void
createEllipse()
{
    // First, have the user select the ellipse center point.
    // We don't use the jig for this because there is
    // nothing to see yet.
    //
    AcGePoint3d tempPt;
    struct resbuf rbFrom, rbTo;

    acedGetPoint(NULL, _T("\nEllipse center point: "),
        asDblArray(tempPt));

    // The point we just got is in UCS coordinates, but
    // AcDbEllipse works in WCS, so convert the point.
    //
    rbFrom.restype = RTSHORT;
    rbFrom.resval.rint = 1; // from UCS
    rbTo.restype = RTSHORT;
    rbTo.resval.rint = 0; // to WCS

    acedTrans(asDblArray(tempPt), &rbFrom, &rbTo,
        Adesk::kFalse, asDblArray(tempPt));

    // Now you need to get the current UCS z-Axis to be used
    // as the normal vector for the ellipse.
    //
    AcGeVector3d x = acdbHostApplicationServices()->workingDatabase()
                     ->ucsxdir();
    AcGeVector3d y = acdbHostApplicationServices()->workingDatabase()
                     ->ucsydir();
    AcGeVector3d normalVec = x.crossProduct(y);
    normalVec.normalize();

    // Create an AsdkEllipseJig object passing in the
    // center point just selected by the user and the normal
    // vector just calculated.
    //
    AsdkEllipseJig *pJig
        = new AsdkEllipseJig(tempPt, normalVec);

    // Now start up the jig to interactively get the major
    // and minor axes lengths.
    //
    pJig->doIt();

    // Now delete the jig object, since it is no longer needed.
    //
    delete pJig;
}
Пример #8
0
void DoubleArcTunnelDraw::extendByLength( double length )
{
    AcGeCircArc3d arc( m_startPt, m_thirdPt, m_endPt );
    AcGePoint3d cenPt = arc.center();
    double radius = arc.radius();
    AcGeVector3d v = m_endPt - cenPt;
    AcGeVector3d v2 = m_startPt - m_endPt;
    AcGeVector3d v3 = v.crossProduct( v2 );
    int c = ( v3.z > 0 ? 1 : -1 );

    v.rotateBy( c * length / radius, AcGeVector3d::kZAxis );

    m_endPt = cenPt + v; // 修改圆弧的末点
}
Пример #9
0
AcGeVector3d  
AcRectangle::setDimValueCbackFunc(AcDbDimData* pThis, 
                                  AcDbEntity* pEnt, 
                                  double value,
								  const AcGeVector3d& offset)
{
    if ((pThis == NULL) || (pEnt == NULL))
        return offset;
	
    pEnt->assertWriteEnabled();

    AppData *pDimAppData = (AppData*)pThis->appData();
    if (pDimAppData == NULL)
        return offset;

    int dimId = pDimAppData->index();
    if ((dimId < 1) || (dimId > 10))
        return offset;

    AcRectangle *pRect = AcRectangle::cast(pEnt);
    if (pRect == NULL)
        return offset;

    AcGePoint3d pt1, pt2, pt3, pt4, dimPt;
    AcGeVector3d diaVec;
    AcGeVector3d mHorizDir = pRect->horizDir();
    AcGeVector3d mNormal = pRect->normal();
    AcGeVector3d vertDir = mNormal.crossProduct(mHorizDir);
    AcGePoint3d mCenter = pRect->center();
    double mWidth = pRect->width();
    double mHeight = pRect->height();
    pt1 = mCenter + 0.5 * mWidth * mHorizDir + 0.5 * mHeight * vertDir;
    pt2 = mCenter - 0.5 * mWidth * mHorizDir + 0.5 * mHeight * vertDir;
    pt3 = mCenter - 0.5 * mWidth * mHorizDir - 0.5 * mHeight * vertDir;
    pt4 = mCenter + 0.5 * mWidth * mHorizDir - 0.5 * mHeight * vertDir;

    switch (dimId) {
    case 1:
        mCenter = mCenter + value * mHorizDir;
        pRect->setCenter(mCenter);
        break;

    case 2:
        mCenter = mCenter + value * vertDir;
        pRect->setCenter(mCenter);
        break;
        
    case 3:
        pt1 = pt2 + value * mHorizDir;
        diaVec = pt1 - pt3;
        mCenter = pt3 + 0.5 * diaVec;
        mWidth = fabs(diaVec.dotProduct(mHorizDir));
        mHeight = fabs(diaVec.dotProduct(vertDir));
        pRect->setCenter(mCenter);
        pRect->setWidth(mWidth);
        pRect->setHeight(mHeight);
        break;

    case 4:
        pt1 = pt4 + value * vertDir;
        diaVec = pt1 - pt3;
        mCenter = pt3 + 0.5 * diaVec;
        mWidth = fabs(diaVec.dotProduct(mHorizDir));
        mHeight = fabs(diaVec.dotProduct(vertDir));
        pRect->setCenter(mCenter);
        pRect->setWidth(mWidth);
        pRect->setHeight(mHeight);
        break;

    case 5:
        pt2 = pt1 - value * mHorizDir;
        diaVec = pt2 - pt4;
        mCenter = pt4 + 0.5 * diaVec;
        mWidth = fabs(diaVec.dotProduct(mHorizDir));
        mHeight = fabs(diaVec.dotProduct(vertDir));
        pRect->setCenter(mCenter);
        pRect->setWidth(mWidth);
        pRect->setHeight(mHeight);
        break;

    case 6:
        pt2 = pt3 + value * vertDir;
        diaVec = pt2 - pt4;
        mCenter = pt4 + 0.5 * diaVec;
        mWidth = fabs(diaVec.dotProduct(mHorizDir));
        mHeight = fabs(diaVec.dotProduct(vertDir));
        pRect->setCenter(mCenter);
        pRect->setWidth(mWidth);
        pRect->setHeight(mHeight);
        break;

    case 7:
        pt3 = pt2 - value * vertDir;
        diaVec = pt3 - pt1;
        mCenter = pt1 + 0.5 * diaVec;
        mWidth = fabs(diaVec.dotProduct(mHorizDir));
        mHeight = fabs(diaVec.dotProduct(vertDir));
        pRect->setCenter(mCenter);
        pRect->setWidth(mWidth);
        pRect->setHeight(mHeight);
        break;

    case 8:
        pt3 = pt4 - value * mHorizDir;
        diaVec = pt3 - pt1;
        mCenter = pt1 + 0.5 * diaVec;
        mWidth = fabs(diaVec.dotProduct(mHorizDir));
        mHeight = fabs(diaVec.dotProduct(vertDir));
        pRect->setCenter(mCenter);
        pRect->setWidth(mWidth);
        pRect->setHeight(mHeight);
        break;

    case 9:
        pt4 = pt3 + value * mHorizDir;
        diaVec = pt4 - pt2;
        mCenter = pt2 + 0.5 * diaVec;
        mWidth = fabs(diaVec.dotProduct(mHorizDir));
        mHeight = fabs(diaVec.dotProduct(vertDir));
        pRect->setCenter(mCenter);
        pRect->setWidth(mWidth);
        pRect->setHeight(mHeight);
        break;

    case 10:
        pt4 = pt1 - value * vertDir;
        diaVec = pt4 - pt2;
        mCenter = pt2 + 0.5 * diaVec;
        mWidth = fabs(diaVec.dotProduct(mHorizDir));
        mHeight = fabs(diaVec.dotProduct(vertDir));
        pRect->setCenter(mCenter);
        pRect->setWidth(mWidth);
        pRect->setHeight(mHeight);
        break;
	}

    return offset;
}
Пример #10
0
void
AcRectangle::gripDimensionCbackFuncGuts(AcDbGripData* pGrip, 
                                        const AcDbObjectId& objId,
                                        double dimScale,
                                        AcDbDimDataPtrArray& dimDataArr,
                                        bool isHover)
{
    if (pGrip == NULL)
        return;

    AppData *pAppData = (AppData*)pGrip->appData();
    int gripID = pAppData ? pAppData->index() : -1;
    if ((gripID < 0) || (gripID > 4))
        return;

    AcDbEntity *pEnt = NULL;
	if (acdbOpenAcDbEntity(pEnt, objId, AcDb::kForRead) != Acad::eOk)
        return;

    AcRectangle *pRect = AcRectangle::cast(pEnt);
    if (pRect == NULL) {
        pEnt->close();
        return;
    }

    AcGeVector3d mHorizDir = pRect->horizDir();
    AcGeVector3d mNormal = pRect->normal();
    AcGeVector3d vertDir = mNormal.crossProduct(mHorizDir);
    AcGePoint3d mCenter = pRect->center();
    double mWidth = pRect->width();
    double mHeight = pRect->height();
    double mElevation = pRect->elevation();
    pRect->close();

    int dimIndex1 = 0, dimIndex2 = 0;
    AcGePoint3d pt1, pt2, pt3, pt4, dimPt1, dimPt2;
    double horizRot = userToLocalAngle(mNormal, mHorizDir);
    pt1 = mCenter + 0.5 * mWidth * mHorizDir + 0.5 * mHeight * vertDir;
    pt2 = mCenter - 0.5 * mWidth * mHorizDir + 0.5 * mHeight * vertDir;
    pt3 = mCenter - 0.5 * mWidth * mHorizDir - 0.5 * mHeight * vertDir;
    pt4 = mCenter + 0.5 * mWidth * mHorizDir - 0.5 * mHeight * vertDir;

    AcDbAlignedDimension *pAlnDim1 = new AcDbAlignedDimension();
    pAlnDim1->setDatabaseDefaults();
    pAlnDim1->setNormal(mNormal);
    pAlnDim1->setElevation(mElevation);
    //pAlnDim1->setDimtad(1);
    pAlnDim1->setHorizontalRotation(-horizRot);

    AcDbAlignedDimension *pAlnDim2 = new AcDbAlignedDimension();
    pAlnDim2->setDatabaseDefaults();
    pAlnDim2->setNormal(mNormal);
    pAlnDim2->setElevation(mElevation);
    //pAlnDim2->setDimtad(1);
    pAlnDim2->setHorizontalRotation(-horizRot);

    if (isHover) {
        AcCmColor dimColor;
        dimColor.setColorIndex(8);  // gray    
        pAlnDim1->setDimclrd(dimColor);
        pAlnDim1->setDimclre(dimColor);
        pAlnDim1->setDimclrt(dimColor);
        pAlnDim2->setDimclrd(dimColor);
        pAlnDim2->setDimclre(dimColor);
        pAlnDim2->setDimclrt(dimColor);
	}

    switch (gripID) {
    case 1:
        dimIndex1 = 3;
        dimPt1 = mCenter + (0.5 * mHeight + 0.5 * dimScale) * vertDir;
        pAlnDim1->setXLine1Point(pt1);
        pAlnDim1->setXLine2Point(pt2);
        pAlnDim1->setDimLinePoint(dimPt1);

        dimIndex2 = 4;  
        dimPt2 = mCenter + (0.5 * mWidth + 0.5 * dimScale) * mHorizDir;
        pAlnDim2->setXLine1Point(pt1);
        pAlnDim2->setXLine2Point(pt4);
        pAlnDim2->setDimLinePoint(dimPt2);
        break;

    case 2:
        dimIndex1 = 5;
        dimPt1 = mCenter + (0.5 * mHeight + 0.5 * dimScale) * vertDir;
        pAlnDim1->setXLine1Point(pt1);
        pAlnDim1->setXLine2Point(pt2);
        pAlnDim1->setDimLinePoint(dimPt1);

        dimIndex2 = 6;
        dimPt2 = mCenter - (0.5 * mWidth + 0.5 * dimScale) * mHorizDir;
        pAlnDim2->setXLine1Point(pt2);
        pAlnDim2->setXLine2Point(pt3);
        pAlnDim2->setDimLinePoint(dimPt2);
        break;

    case 3:
        dimIndex1 = 7;
        dimPt1 = mCenter - (0.5 * mWidth + 0.5 * dimScale) * mHorizDir;
        pAlnDim1->setXLine1Point(pt2);
        pAlnDim1->setXLine2Point(pt3);
        pAlnDim1->setDimLinePoint(dimPt1);

        dimIndex2 = 8;
        dimPt2 = mCenter - (0.5 * mHeight + 0.5 * dimScale) * vertDir;
        pAlnDim2->setXLine1Point(pt3);
        pAlnDim2->setXLine2Point(pt4);
        pAlnDim2->setDimLinePoint(dimPt2);
        break;

    case 4:
        dimIndex1 = 9;
        dimPt1 = mCenter - (0.5 * mHeight + 0.5 * dimScale) * vertDir;
        pAlnDim1->setXLine1Point(pt3);
        pAlnDim1->setXLine2Point(pt4);
        pAlnDim1->setDimLinePoint(dimPt1);

        dimIndex2 = 10;
        dimPt2 = mCenter + (0.5 * mWidth + 0.5 * dimScale) * mHorizDir;
        pAlnDim2->setXLine1Point(pt4);
        pAlnDim2->setXLine2Point(pt1);
        pAlnDim2->setDimLinePoint(dimPt2);
        break;
    }
	unsigned int ibitFlags = AcDbDimData::kDimFocal & ~AcDbDimData::kDimEditable ;
    AcDbDimData *dimData1 = new AcDbDimData(pAlnDim1);
    AppData *pDimAppData1 = new AppData(dimIndex1, dimScale);
    dimData1->setAppData(pDimAppData1);
    dimData1->setOwnerId(objId);
    dimData1->setDimFocal(true);
	  //dimData1->setBitFlags(ibitFlags);	
    dimData1->setDimEditable(false);
	dimData1->setDimValueFunc(AcRectangle::setDimValueCbackFunc);

    AcDbDimData *dimData2 = new AcDbDimData(pAlnDim2);
    AppData *pDimAppData2 = new AppData(dimIndex2, dimScale);
    dimData2->setAppData(pDimAppData2);
    dimData2->setOwnerId(objId);
	dimData2->setDimFocal(true);
    dimData2->setDimEditable(false);
	dimData2->setDimHideIfValueIsZero(true);
	dimData2->setDimValueFunc(setDimValueCbackFunc);

    dimDataArr.append(dimData1);
    dimDataArr.append(dimData2);

    if(pAppData) {
        pAppData->resetDimData();
        pAppData->appendDimData(dimData1);
        pAppData->appendDimData(dimData2);
    }
}
Пример #11
0
AcBr::ErrorStatus
faceDump(const AcBrFace& faceEntity)
{ 
    AcBr::ErrorStatus returnValue = AcBr::eOk;

	// Verify that AcBr was explicitly and not implicitly loaded,
	// by testing ObjectARX functions (which are unavailable unless
	// explicitly loaded)
    if (faceEntity.isA() == NULL) {
        acutPrintf(ACRX_T("\n faceDump: AcBrEntity::isA() failed\n"));
        return returnValue;
    }
    if (!faceEntity.isKindOf(AcBrFace::desc())) {
        acutPrintf(ACRX_T("\n faceDump: AcBrEntity::isKindOf() failed\n"));
        return returnValue;
    }
	AcBrEntity* entClass = (AcBrEntity*)&faceEntity;
	AcBrEdge* pEdge = AcBrEdge::cast(entClass);  
	if (pEdge != NULL) {
		acutPrintf(ACRX_T("\n faceDump: AcBrEntity::cast() failed\n"));
        return (AcBrErrorStatus)Acad::eNotThatKindOfClass;
	} 

	AcGe::EntityId entId;
	returnValue = faceEntity.getSurfaceType(entId);  
	if (returnValue != AcBr::eOk) {
		acutPrintf(ACRX_T("\n Error in AcBrFace::getSurfaceType:"));
		errorReport(returnValue);
        return returnValue;
	}

	AcGeSurface* surfaceGeometry = NULL;
    AcGeSurface* nativeGeometry = NULL;

	// NOTE: ignore unsupported geometry types for now, since we already know
	// that elliptic cylinders and elliptic cones are rejected by AcGe, but we
	// can still perform useful evaluations on the external bounded surface.
	returnValue = getNativeSurface(faceEntity, surfaceGeometry, nativeGeometry);  
	if ((returnValue != AcBr::eOk) && (returnValue
		!= (AcBrErrorStatus)Acad::eInvalidInput)) {
		acutPrintf(ACRX_T("\n Error in getNativeSurface:"));
		errorReport(returnValue);
        delete surfaceGeometry;
        delete nativeGeometry;
        return returnValue;
	}

	switch (entId) {
	case(kPlane):
	{ 
		acutPrintf(ACRX_T("\nSurface Type: Plane\n"));
        AcGePlane* planeGeometry = (AcGePlane*)nativeGeometry;
        AcGePoint3d pt = planeGeometry->pointOnPlane();
        AcGeVector3d normal = planeGeometry->normal();
		acutPrintf(ACRX_T("\nSurface Definition Data Begin:\n"));
		acutPrintf(ACRX_T(" Point on Plane is ("));
		acutPrintf (ACRX_T("%lf , "), pt.x);	
		acutPrintf (ACRX_T("%lf , "), pt.y);
		acutPrintf (ACRX_T("%lf "), pt.z);
		acutPrintf(ACRX_T(")\n"));	
		acutPrintf(ACRX_T(" Plane normal direction is ("));
		acutPrintf (ACRX_T("%lf , "), normal.x);	
		acutPrintf (ACRX_T("%lf , "), normal.y);
		acutPrintf (ACRX_T("%lf "), normal.z);
		acutPrintf(ACRX_T(")\n"));	
		acutPrintf(ACRX_T("Surface Definition Data End\n"));
		break;
    } 
	
	case(kSphere):
    {
		acutPrintf(ACRX_T("\nSurface Type: Sphere\n"));
        AcGeSphere* sphereGeometry = (AcGeSphere*)nativeGeometry;
        AcGePoint3d centre = sphereGeometry->center();
		double ang1, ang2, ang3, ang4;
        sphereGeometry->getAnglesInU(ang1, ang2);
        sphereGeometry->getAnglesInV(ang3, ang4);
        AcGePoint3d north = sphereGeometry->northPole();
        AcGePoint3d south = sphereGeometry->southPole();
		acutPrintf(ACRX_T("\nSurface Definition Data Begin:\n"));
		acutPrintf(ACRX_T(" Sphere centre is ("));
		acutPrintf (ACRX_T("%lf , "), centre.x);	
		acutPrintf (ACRX_T("%lf , "), centre.y);
		acutPrintf (ACRX_T("%lf "), centre.z);
		acutPrintf(ACRX_T(")\n"));	
		acutPrintf(ACRX_T(" Sphere radius is %lf\n"), sphereGeometry->radius());
		acutPrintf(ACRX_T(" Sphere start angle in U is %lf\n"), ang1);
		acutPrintf(ACRX_T(" Sphere end angle in U is %lf\n"), ang2);
		acutPrintf(ACRX_T(" Sphere start angle in V is %lf\n"), ang3);
		acutPrintf(ACRX_T(" Sphere end angle in V is %lf\n"), ang4);
		acutPrintf(ACRX_T(" Sphere north pole is ("));
		acutPrintf (ACRX_T("%lf , "), north.x);	
		acutPrintf (ACRX_T("%lf , "), north.y);
		acutPrintf (ACRX_T("%lf "), north.z);
		acutPrintf(ACRX_T(")\n"));	
		acutPrintf(ACRX_T(" Sphere south pole is ("));
		acutPrintf (ACRX_T("%lf , "), south.x);	
		acutPrintf (ACRX_T("%lf , "), south.y);
		acutPrintf (ACRX_T("%lf "), south.z);
		acutPrintf(ACRX_T(")\n"));	
		acutPrintf(ACRX_T("Surface Definition Data End\n"));
		break;
    }
	
	case(kTorus):
    {
		acutPrintf(ACRX_T("\nSurface Type: Torus\n"));
        AcGeTorus* torusGeometry = (AcGeTorus*)nativeGeometry;
        AcGePoint3d centre = torusGeometry->center();
		double ang1, ang2, ang3, ang4;
        torusGeometry->getAnglesInU(ang1, ang2);
        torusGeometry->getAnglesInV(ang3, ang4);
		acutPrintf(ACRX_T("\nSurface Definition Data Begin:\n"));
		acutPrintf(ACRX_T(" Torus centre is ("));
		acutPrintf (ACRX_T("%lf , "), centre.x);	
		acutPrintf (ACRX_T("%lf , "), centre.y);
		acutPrintf (ACRX_T("%lf "), centre.z);
		acutPrintf(ACRX_T(")\n"));	
		acutPrintf(ACRX_T(" Torus major radius is %lf\n"), torusGeometry->majorRadius());
		acutPrintf(ACRX_T(" Torus minor radius is %lf\n"), torusGeometry->minorRadius());
		acutPrintf(ACRX_T(" Torus start angle in U is %lf\n"), ang1);
		acutPrintf(ACRX_T(" Torus end angle in U is %lf\n"), ang2);
		acutPrintf(ACRX_T(" Torus start angle in V is %lf\n"), ang3);
		acutPrintf(ACRX_T(" Torus end angle in V is %lf\n"), ang4);
		acutPrintf(ACRX_T("Surface Definition Data End\n"));
		break;	
	}	
	
	case(kCylinder):
    {
		acutPrintf(ACRX_T("\nSurface Type: Circular Cylinder\n"));
        AcGeCylinder* cylinderGeometry = (AcGeCylinder*)nativeGeometry;
        AcGePoint3d origin = cylinderGeometry->origin();
		double ang1, ang2;
        cylinderGeometry->getAngles(ang1, ang2);
        AcGeInterval ht;
        cylinderGeometry->getHeight(ht);
        double height = ht.upperBound() - ht.lowerBound();
        AcGeVector3d refAxis = cylinderGeometry->refAxis();
        AcGeVector3d symAxis = cylinderGeometry->axisOfSymmetry();
		acutPrintf(ACRX_T("\nSurface Definition Data Begin:\n"));
		acutPrintf(ACRX_T(" Circular Cylinder origin is ("));
		acutPrintf (ACRX_T("%lf , "), origin.x);	
		acutPrintf (ACRX_T("%lf , "), origin.y);
		acutPrintf (ACRX_T("%lf "), origin.z);
		acutPrintf(ACRX_T(")\n"));	
		acutPrintf(ACRX_T(" Circular Cylinder radius is %lf\n"), cylinderGeometry->radius());
		acutPrintf(ACRX_T(" Circular Cylinder start angle is %lf\n"), ang1);
		acutPrintf(ACRX_T(" Circular Cylinder end angle is %lf\n"), ang2);
		if (cylinderGeometry->isClosedInU())
			acutPrintf(ACRX_T(" Circular Cylinder height is %lf\n"), height);
        else acutPrintf(ACRX_T(" Circular Cylinder is not closed in U\n"));
		acutPrintf(ACRX_T(" Circular Cylinder reference axis is ("));
		acutPrintf (ACRX_T("%lf , "), refAxis.x);	
		acutPrintf (ACRX_T("%lf , "), refAxis.y);
		acutPrintf (ACRX_T("%lf "), refAxis.z);
		acutPrintf(ACRX_T(")\n"));	
		acutPrintf(ACRX_T(" Circular Cylinder axis of symmetry is ("));
		acutPrintf (ACRX_T("%lf , "), symAxis.x);	
		acutPrintf (ACRX_T("%lf , "), symAxis.y);
		acutPrintf (ACRX_T("%lf "), symAxis.z);
		acutPrintf(ACRX_T(")\n"));	
		acutPrintf(ACRX_T("Surface Definition Data End\n"));
		break;
    }

	case(kCone):
    {
		acutPrintf(ACRX_T("\nSurface Type: Circular Cone\n"));
        AcGeCone* coneGeometry = (AcGeCone*)nativeGeometry;
        AcGePoint3d centre = coneGeometry->baseCenter();
		double ang1, ang2;
        coneGeometry->getAngles(ang1, ang2);
        AcGeVector3d axis1 = coneGeometry->axisOfSymmetry();
        AcGeVector3d axis2 = coneGeometry->refAxis();
        AcGePoint3d apex = coneGeometry->apex();
		double cosAng, sinAng;
        coneGeometry->getHalfAngle(cosAng, sinAng);
        AcGeInterval ht;
        coneGeometry->getHeight(ht);
        double height = ht.upperBound() - ht.lowerBound();
		acutPrintf(ACRX_T("\nSurface Definition Data Begin:\n"));
		acutPrintf(ACRX_T(" Circular Cone base centre is ("));
		acutPrintf (ACRX_T("%lf , "), centre.x);	
		acutPrintf (ACRX_T("%lf , "), centre.y);
		acutPrintf (ACRX_T("%lf "), centre.z);
		acutPrintf(ACRX_T(")\n"));	
		acutPrintf(ACRX_T(" Circular Cone base radius is %lf\n"), coneGeometry->baseRadius());
		acutPrintf(ACRX_T(" Circular Cone start angle is %lf\n"), ang1);
		acutPrintf(ACRX_T(" Circular Cone end angle is %lf\n"), ang2);
		acutPrintf(ACRX_T(" Circular Cone axis of symmetry is ("));
		acutPrintf (ACRX_T("%lf , "), axis1.x);	
		acutPrintf (ACRX_T("%lf , "), axis1.y);
		acutPrintf (ACRX_T("%lf "), axis1.z);
		acutPrintf(ACRX_T(")\n"));	
		acutPrintf(ACRX_T(" Circular Cone reference axis is ("));
		acutPrintf (ACRX_T("%lf , "), axis2.x);	
		acutPrintf (ACRX_T("%lf , "), axis2.y);
		acutPrintf (ACRX_T("%lf "), axis2.z);
		acutPrintf(ACRX_T(")\n"));	
		acutPrintf(ACRX_T(" Circular Cone apex is ("));
		acutPrintf (ACRX_T("%lf , "), apex.x);	
		acutPrintf (ACRX_T("%lf , "), apex.y);
		acutPrintf (ACRX_T("%lf "), apex.z);
		acutPrintf(ACRX_T(")\n"));	
		acutPrintf(ACRX_T(" Circular Cone cosine of major half-angle is %lf\n"), cosAng);
		acutPrintf(ACRX_T(" Circular Cone sine of major half-angle is %lf\n"), sinAng);
		if (coneGeometry->isClosedInU())
			acutPrintf(ACRX_T(" Circular Cone height is %lf\n"), height);
        else acutPrintf(ACRX_T(" Circular Cone is not closed in U\n"));
		acutPrintf(ACRX_T("Surface Definition Data End\n"));
		break;
    }
	
	case(kNurbSurface):
    {
		acutPrintf(ACRX_T("\nSurface Type: NURB Surface\n"));
        AcGeNurbSurface* nurbGeometry = (AcGeNurbSurface*)nativeGeometry;
		int nCtrlPtsU = nurbGeometry->numControlPointsInU();
		int nCtrlPtsV = nurbGeometry->numControlPointsInV();
		int nKnotsU = nurbGeometry->numKnotsInU();
		int nKnotsV = nurbGeometry->numKnotsInV();
		acutPrintf(ACRX_T("\nSurface Definition Data Begin:\n"));
		acutPrintf(ACRX_T(" NURB Surface degree in U is %d\n"), nurbGeometry->degreeInU());
		acutPrintf(ACRX_T(" NURB Surface degree in V is %d\n"), nurbGeometry->degreeInV());
		acutPrintf(ACRX_T(" NURB Surface number of control points in U is %d\n"), nCtrlPtsU);
		acutPrintf(ACRX_T(" NURB Surface number of control points in V is %d\n"), nCtrlPtsV);
		acutPrintf(ACRX_T(" NURB Surface number of knots in U is %d\n"), nKnotsU);
		acutPrintf(ACRX_T(" NURB Surface number of knots in V is %d\n"), nKnotsV);
		acutPrintf(ACRX_T("Surface Definition Data End\n"));
		break;
    }
	
	// NOTE: This surface is not yet supported in AcGe, so we infer the definition
	// data by analysing evaluated data on the external bounded surface.
	case(kEllipCylinder):
	{
		acutPrintf(ACRX_T("\nSurface Type: Elliptic Cylinder\n"));
        AcGePoint3d p0 = surfaceGeometry->evalPoint(AcGePoint2d(0.0, 0.0));
        AcGePoint3d p1 = surfaceGeometry->evalPoint(AcGePoint2d(0.0, kPi));
        AcGePoint3d p2 = surfaceGeometry->evalPoint(AcGePoint2d(0.0, kHalfPi));
        AcGePoint3d origin(((p0.x + p1.x) / 2.0),
			               ((p0.y + p1.y) / 2.0),
						   ((p0.z + p1.z) / 2.0));
        AcGeVector3d majAxis = p0 - origin;
        AcGeVector3d minAxis = p2 - origin;
        AcGeVector3d symAxis = (majAxis.crossProduct(minAxis)).normalize();
		acutPrintf(ACRX_T("\nSurface Definition Data Begin:\n"));
		acutPrintf(ACRX_T(" Elliptic Cylinder origin is ("));
		acutPrintf (ACRX_T("%lf , "), origin.x);	
		acutPrintf (ACRX_T("%lf , "), origin.y);
		acutPrintf (ACRX_T("%lf "), origin.z);
		acutPrintf(ACRX_T(")\n"));	
		acutPrintf(ACRX_T(" Elliptic Cylinder major radius is %lf\n"), majAxis.length());
		acutPrintf(ACRX_T(" Elliptic Cylinder minor radius is %lf\n"), minAxis.length());
		acutPrintf(ACRX_T(" Elliptic Cylinder major axis is ("));
		acutPrintf (ACRX_T("%lf , "), majAxis.x);	
		acutPrintf (ACRX_T("%lf , "), majAxis.y);
		acutPrintf (ACRX_T("%lf "), majAxis.z);
		acutPrintf(ACRX_T(")\n"));	
		acutPrintf(ACRX_T(" Elliptic Cylinder minor axis is ("));
		acutPrintf (ACRX_T("%lf , "), minAxis.x);	
		acutPrintf (ACRX_T("%lf , "), minAxis.y);
		acutPrintf (ACRX_T("%lf "), minAxis.z);
		acutPrintf(ACRX_T(")\n"));	
		acutPrintf(ACRX_T(" Elliptic Cylinder axis of symmetry is ("));
		acutPrintf (ACRX_T("%lf , "), symAxis.x);	
		acutPrintf (ACRX_T("%lf , "), symAxis.y);
		acutPrintf (ACRX_T("%lf "), symAxis.z);
		acutPrintf(ACRX_T(")\n"));	
		acutPrintf(ACRX_T("Surface Definition Data End\n"));
		break;
	}

	// NOTE: This surface is not yet supported in AcGe, so we infer the definition
	// data by analysing evaluated data on the external bounded surface.
	case(kEllipCone):
	{
		acutPrintf(ACRX_T("\nSurface Type: Elliptic Cone\n"));
        AcGePoint3d p0 = surfaceGeometry->evalPoint(AcGePoint2d(0.0, 0.0));
        AcGePoint3d p1 = surfaceGeometry->evalPoint(AcGePoint2d(0.0, kPi));
        AcGePoint3d p2 = surfaceGeometry->evalPoint(AcGePoint2d(0.0, kHalfPi));
        AcGePoint3d p3 = surfaceGeometry->evalPoint(AcGePoint2d(1.0, 0.0));
        AcGePoint3d centre(((p0.x + p1.x) / 2.0),
			               ((p0.y + p1.y) / 2.0),
						   ((p0.z + p1.z) / 2.0));
        AcGeVector3d majAxis = p0 - centre;
        AcGeVector3d minAxis = p2 - centre;
        AcGeVector3d symAxis = (majAxis.crossProduct(minAxis)).normalize();
		double halfAng = kHalfPi - majAxis.angleTo(p3 - p0);
		acutPrintf(ACRX_T("\nSurface Definition Data Begin:\n"));
		acutPrintf(ACRX_T(" Elliptic Cone base centre is ("));
		acutPrintf (ACRX_T("%lf , "), centre.x);	
		acutPrintf (ACRX_T("%lf , "), centre.y);
		acutPrintf (ACRX_T("%lf "), centre.z);
		acutPrintf(ACRX_T(")\n"));	
		acutPrintf(ACRX_T(" Elliptic Cone base major radius is %lf\n"), majAxis.length());
		acutPrintf(ACRX_T(" Elliptic Cone base minor radius is %lf\n"), minAxis.length());
		acutPrintf(ACRX_T(" Elliptic Cone major axis is ("));
		acutPrintf (ACRX_T("%lf , "), majAxis.x);	
		acutPrintf (ACRX_T("%lf , "), majAxis.y);
		acutPrintf (ACRX_T("%lf "), majAxis.z);
		acutPrintf(ACRX_T(")\n"));	
		acutPrintf(ACRX_T(" Elliptic Cone minor axis is ("));
		acutPrintf (ACRX_T("%lf , "), minAxis.x);	
		acutPrintf (ACRX_T("%lf , "), minAxis.y);
		acutPrintf (ACRX_T("%lf "), minAxis.z);
		acutPrintf(ACRX_T(")\n"));	
		acutPrintf(ACRX_T(" Elliptic Cone axis of symmetry is ("));
		acutPrintf (ACRX_T("%lf , "), symAxis.x);	
		acutPrintf (ACRX_T("%lf , "), symAxis.y);
		acutPrintf (ACRX_T("%lf "), symAxis.z);
		acutPrintf(ACRX_T(")\n"));	
		acutPrintf(ACRX_T(" Elliptic Cone cosine of major half-angle is %lf\n"), cos(halfAng));
		acutPrintf(ACRX_T(" Elliptic Cone sine of major half-angle is %lf\n"), sin(halfAng));
		acutPrintf(ACRX_T("Surface Definition Data End\n"));
		break;
	}

	default:
		acutPrintf(ACRX_T("\nSurface Type: Unexpected Non Surface\n"));
		return (AcBrErrorStatus)Acad::eInvalidInput;
	} // end switch(entId)	
    
	delete nativeGeometry;

	// Evaluate the surface - note that the u,v bounds will not consider any
	// holes in the surface. To compute a u,v zone of exclusion for evaluation,
	// check for additional (i.e., inner) loops and get the bounding boxes for
	// the loops, then convert those to parameter space boxes. There is no
	// particular guarantee that outer loop(s) are the first in the face-loop
	// list, however, and we currently have no way to query a loop to find out
	// which type it is. Still, the maximal u,v parameter range will be useful
	// for most surfaces and most evaluation purposes.
	AcGeInterval uParam;
	AcGeInterval vParam;
	((AcGeExternalBoundedSurface*)surfaceGeometry)->getEnvelope(uParam, vParam);
    // Make sure the u,v values are legal and the envelope is bounded
    if ((uParam.isBounded()) && (vParam.isBounded())) {
		AcGePoint2d midRange;
		midRange.x = uParam.lowerBound() + (uParam.length() / 2.0);
		midRange.y = vParam.lowerBound() + (vParam.length() / 2.0);
		AcGePoint3d pointOnSurface =
			((AcGeExternalBoundedSurface*)surfaceGeometry)->evalPoint(midRange);
		acutPrintf(ACRX_T("\nSurface Evaluation Begin:\n"));
		acutPrintf(ACRX_T(" Parameter space bounds are (("));
        acutPrintf(ACRX_T("%lf, "), uParam.lowerBound());
        acutPrintf(ACRX_T("%lf "), uParam.upperBound());
        acutPrintf(ACRX_T("), (\n"));
        acutPrintf(ACRX_T("%lf, "), vParam.lowerBound());
        acutPrintf(ACRX_T("%lf "), vParam.upperBound());
        acutPrintf(ACRX_T("))\n"));
		acutPrintf(ACRX_T(" Parameter space mid-range is ("));
        acutPrintf(ACRX_T(" %lf, "), midRange.x);
        acutPrintf(ACRX_T("%lf "), midRange.y);
        acutPrintf(ACRX_T(")\n"));
		acutPrintf(ACRX_T(" Point on surface is ("));
		acutPrintf (ACRX_T("%lf , "), pointOnSurface.x);	
		acutPrintf (ACRX_T("%lf , "), pointOnSurface.y);
		acutPrintf (ACRX_T("%lf "), pointOnSurface.z);
		acutPrintf(ACRX_T(")\n"));	
		acutPrintf(ACRX_T("Surface Evaluation End\n"));
    }
	delete surfaceGeometry;

	Adesk::Boolean oriented;
	returnValue = faceEntity.getOrientToSurface(oriented);
	if (returnValue != AcBr::eOk) {
		acutPrintf(ACRX_T("\n Error in AcBrFace::getOrientToSurface:"));
        errorReport(returnValue);
		return returnValue;
	} 
	oriented ? acutPrintf(ACRX_T("\nSurface Orientation is Positive\n"))
	    : acutPrintf(ACRX_T("\nSurface Orientation is Negative\n"));

	return returnValue;
}
Пример #12
0
Adesk::Boolean
AsdkTextStyleSamp::worldDraw(AcGiWorldDraw* pW)
{
    AcGePoint3d pos(4.0, 4.0, 0.0);
    AcGeVector3d norm(0.0, 0.0, 1.0);
    AcGeVector3d dir(-1.0, -0.2, 0.0);
    char *pStr = "This is a percent, '%%%'.";
    int len = strlen(pStr);
    AcGiTextStyle style;

    AcGeVector3d vec = norm;
    vec = vec.crossProduct(dir);
    dir = vec.crossProduct(norm);

    style.setFileName("txt.shx");
    style.setBigFontFileName("");
    int status;
    if (!((status = style.loadStyleRec()) & 1))
        pStr = "Font not found.";

    pW->geometry().text(pos, norm, dir, pStr, len,
        Adesk::kFalse, style);

    pos.y += 2.0;

    style.setTrackingPercent(0.8); 
	style.setObliquingAngle(0.5);

    AcGePoint2d ext = style.extents(pStr, Adesk::kFalse,
        strlen(pStr), Adesk::kFalse);

    pW->geometry().text(pos, norm, dir, pStr, len,
        Adesk::kFalse, style);

    // Draw a rectangle around the last text drawn.
    // First you have to create a polyline the size of the
    // bounding box, then you have to transform it to the
    // correct orientation, and then to the location of the
    // text.
    
    // Compute the matrix that orients the box.
    //
    AcGeMatrix3d textMat;
    norm.normalize();
    dir.normalize();
    AcGeVector3d yAxis = norm;
    yAxis = yAxis.crossProduct(dir);
    yAxis.normalize();
    textMat.setCoordSystem(AcGePoint3d(0.0, 0.0, 0.0), dir,
        yAxis, norm);

    // Create the bounding box and enlarge it somewhat.
    //
    double offset = ext.y / 2.0;
    AcGePoint3d verts[5];
    verts[0] = verts[4] = AcGePoint3d(-offset, -offset, 0.0);
    verts[1] = AcGePoint3d(ext.x + offset, -offset, 0.0);
    verts[2] = AcGePoint3d(ext.x + offset, ext.y + offset, 0.0);
    verts[3] = AcGePoint3d(-offset, ext.y + offset, 0.0);

    // Orient and then translate each point in the
    // bounding box.
    //
    for (int i = 0; i < 5; i++) {
        verts[i].transformBy(textMat);
        verts[i].x += pos.x;
        verts[i].y += pos.y;
        verts[i].z += pos.z;
    }
    pW->geometry().polyline(5, verts);

    return Adesk::kTrue;
}
Пример #13
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();
}