示例#1
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);
}
示例#2
0
// Invoked by the command - POLY
//
void 
polyCommand()
{
    int nSides = 0;
    
    while (nSides < 3) {
        
        acedInitGet(INP_NNEG, "");
        switch (acedGetInt("\nEnter number of sides: ", &nSides)) {
            
        case RTNORM:
            if (nSides < 3)
                acutPrintf("\nNeed at least 3 sides.");
            break;
        default:
            return;
        }
    }
    
    ads_point center, startPt, normal;
    
    if (acedGetPoint(NULL, "\nLocate center of polygon: ", center) != RTNORM)
        return;
    
    startPt[0] = center[0]; startPt[1] = center[1]; startPt[2] = center[2];
    while (asPnt3d(startPt) == asPnt3d(center)) {
        switch (acedGetPoint(center, "\nLocate start point of polygon: ", 
            startPt)) {
        case RTNORM:
            if (asPnt3d(center) == asPnt3d(startPt))
                acutPrintf("\nPick a point different from the center.");
            break;
        default:
            return;
        }
    }
    
    char nameBuf[133];
    if (acedGetString(Adesk::kTrue, "\nEnter polygon name: ", nameBuf) != RTNORM)
        return;
    
    AcDbObjectId tsId = 0;
    char styleBuf[133], msg[133];
	// Get default text style
	struct resbuf result ;
	if ( acedGetVar ("TEXTSTYLE", &result) != RTNORM ) {
		acutPrintf("\nError while reading default AutoCAD text style setting");
		return ;
	}
	strcpy (styleBuf, result.resval.rstring) ;
	sprintf (msg, "\nEnter text style <%s>: ", result.resval.rstring) ;
	acdbFree (result.resval.rstring) ;

    if (acedGetString(Adesk::kTrue, "\nEnter text style: ", styleBuf) != RTNORM)
        return;
    
    if ( styleBuf[0] == '\0' ) {
		// Get default text style
		struct resbuf result ;
		if ( acedGetVar ("TEXTSTYLE", &result) != RTNORM ) {
			acutPrintf("\nError while reading default AutoCAD text style setting");
			return ;
		}
		strcpy (styleBuf, result.resval.rstring) ;
		acdbFree (result.resval.rstring) ;
	}

    if ( rx_getTextStyleId(styleBuf, 
                         acdbHostApplicationServices()->workingDatabase(), 
                         tsId) != Acad::eOk)
	{
		acutPrintf("\nInvalid text style name");
		return;
	}
    
    
    // Set the normal to the plane of the polygon to be the same as the
    // z direction of the current ucs, i.e. (0, 0, 1) since we also got the
    // center and start point in the current UCS. (acedGetPoint() returns in
    // the current UCS.)
    
    normal[X] = 0.0; normal[Y] = 0.0; normal[Z] = 1.0;

    acdbUcs2Wcs(normal, normal, Adesk::kTrue);    
    acdbUcs2Ecs(center, center,normal, Adesk::kFalse);
    acdbUcs2Ecs(startPt, startPt,normal, Adesk::kFalse);
    double elev = center[2];
    AcGePoint2d cen = asPnt2d(center), start = asPnt2d(startPt);
    AcGeVector3d norm = asVec3d(normal);
    
    AsdkPoly* poly = new AsdkPoly;
    if (poly==NULL){
        acutPrintf("\nOut of memory.");
        return;
    }
    
    if (poly->set(cen, start, nSides, norm, nameBuf, tsId, elev)!=Acad::eOk){
        delete poly;
        acutPrintf("\nCannot create AsdkPoly with given parameters.");
        return;
    }
    
    poly->setDatabaseDefaults(acdbHostApplicationServices()->workingDatabase());
    postToDb(poly);
}
//This is used to set the value for an element in a group.
//The element is identified by the dwCookie parameter
STDMETHODIMP CComPolygon::SetElementValue(
	/* [in] */ DISPID dispID,
	/* [in] */ DWORD dwCookie,
	/* [in] */ VARIANT VarIn)
{
    if (dispID >= DISPID_NORMAL && dispID <= DISPID_STARTPOINT)
    {
        try
        {
            if (dwCookie>2)
                throw Acad::eInvalidInput;
            Acad::ErrorStatus es;
            AcAxObjectRefPtr<AsdkPoly> pPoly(&m_objRef,AcDb::kForWrite,Adesk::kTrue);
	        if((es=pPoly.openStatus()) != Acad::eOk)
                throw es;

            AcAxPoint3d pt;
			AcAxPoint2d pt2d;
			if (dispID == DISPID_NORMAL)
            {
                pt = pPoly->normal();
                //translate from wcs to ucs
                acdbEcs2Ucs(asDblArray(pt),asDblArray(pt),asDblArray(pPoly->normal()),Adesk::kTrue);
            } else {
			    switch (dispID)
			    {
			    case DISPID_CENTER:
				    pt2d = pPoly->center();
				    break;
			    case DISPID_STARTPOINT:
				    pt2d = pPoly->startPoint();
				    break;
			    default:
				    throw Acad::eInvalidInput;
			    }
                pt.set(pt2d.x,pt2d.y,pPoly->elevation());
                //translate from wcs to ucs
                acdbEcs2Ucs(asDblArray(pt),asDblArray(pt),asDblArray(pPoly->normal()),Adesk::kFalse);
            }
	        pt[dwCookie] = V_R8(&VarIn);

            if (dispID == DISPID_NORMAL) {
                acdbUcs2Wcs(asDblArray(pt),asDblArray(pt),Adesk::kTrue);
                if ((es=pPoly->setNormal(pt.asVector()))!=Acad::eOk)
                    throw es;    
            }else { 
                acdbUcs2Ecs(asDblArray(pt),asDblArray(pt),asDblArray(pPoly->normal()),Adesk::kFalse);
                pt2d.set(pt.x,pt.y);
                pPoly->setElevation(pt.z);
                if (dispID == DISPID_CENTER)
                    if ((es=pPoly->setCenter(pt2d))!=Acad::eOk)
                        throw es;            
                if (dispID == DISPID_STARTPOINT)
                    if ((es=pPoly->setStartPoint(pt2d))!=Acad::eOk)
                        throw es;            
            }
            Fire_Notification(dispID);
        }
        catch(const Acad::ErrorStatus)
        {
            return Error(L"Failed to open object",IID_IComPolygon,E_FAIL);
        }
        catch(const HRESULT hr)
        {
            return Error(L"Invalid argument.",IID_IComPolygon,hr);
        }

    }
	return S_OK;
}
示例#4
0
// Invoked by the command - DRAGPOLY
//
void 
dragPolyCommand()
{
    int nSides = 0;
    
    ads_point center, startPt, normal;
    
    if (acedGetPoint(NULL, "\nLocate center of polygon: ", center) != RTNORM)
        return;
    
    char nameBuf[133];
    if (acedGetString(Adesk::kTrue, "\nEnter polygon name: ", nameBuf) != RTNORM)
        return;
    
    AcDbObjectId tsId = 0;
    char styleBuf[133], msg[133];
	// Get default text style
	struct resbuf result ;
	if ( acedGetVar ("TEXTSTYLE", &result) != RTNORM ) {
		acutPrintf("\nError while reading default AutoCAD text style setting");
		return ;
	}
	strcpy (styleBuf, result.resval.rstring) ;
	sprintf (msg, "\nEnter text style <%s>: ", result.resval.rstring) ;
	acdbFree (result.resval.rstring) ;

    if (acedGetString(Adesk::kTrue, msg, styleBuf) != RTNORM)
        return;
    
    if ( styleBuf[0] == '\0' ) {
		// Get default text style
		struct resbuf result ;
		if ( acedGetVar ("TEXTSTYLE", &result) != RTNORM ) {
			acutPrintf("\nError while reading default AutoCAD text style setting");
			return ;
		}
		strcpy (styleBuf, result.resval.rstring) ;
		acdbFree (result.resval.rstring) ;
	}

    if ( rx_getTextStyleId(styleBuf, 
                             acdbHostApplicationServices()->workingDatabase(), 
                             tsId) != Acad::eOk)
    {
        acutPrintf("\nInvalid text style name");
        return;
    }
    
    
    // Set the normal to the plane of the polygon to be the same as the
    // z direction of the current ucs, i.e. (0, 0, 1) since we also got the
    // center and start point in the current UCS. (acedGetPoint() returns in
    // the current UCS.)
    
    normal[X] = 0.0; normal[Y] = 0.0; normal[Z] = 1.0;

    acdbUcs2Wcs(normal, normal, Adesk::kTrue);
    acdbUcs2Ecs(center, center, normal, Adesk::kFalse);
    acdbUcs2Ecs(startPt, startPt, normal, Adesk::kFalse);
    double elev = center[2];
    AcGePoint2d cen = asPnt2d(center), start = asPnt2d(startPt);
    AcGeVector3d norm = asVec3d(normal);
    
    AsdkPolyJig* pJig = new AsdkPolyJig();
    pJig->acquire(cen, norm, nameBuf, tsId, elev);
    
    delete pJig;
}