Adesk::Boolean pickViewport (AcDbViewport *&pVp) {
    ads_point p1, p2 ;
    
    if ( acedGetPoint (NULL, ACRX_T("\nPlease enter point 1: "), p1) != RTNORM )
        return (Adesk::kFalse) ;
    if ( acedGetPoint (p1, ACRX_T("\nPlease enter point 2: "), p2) != RTNORM )
        return (Adesk::kFalse) ;
    acdbUcs2Wcs (p1, p1, Adesk::kFalse ) ;
    acdbUcs2Wcs (p2, p2, Adesk::kFalse ) ;

    int frontClip =AfxMessageBox (ACRX_T("Would you like to clip at the front?"), MB_YESNO) ;
    int backClip =AfxMessageBox (ACRX_T("Would you like to clip at the back?"), MB_YESNO) ;
    
    pVp =new AcDbViewport ;
    pVp->setViewTarget (asPnt3d (p2)) ;
    pVp->setViewDirection (asPnt3d (p1) - asPnt3d (p2)) ;

    pVp->setFrontClipDistance (asPnt3d (p1).distanceTo (asPnt3d (p2))) ;
    pVp->setBackClipDistance (0) ;
    
    acutPrintf (ACRX_T("\nFront Clipping is %d"), pVp->isFrontClipOn ()) ;
    if ( frontClip == IDYES )
        pVp->setFrontClipOn () ;
    acutPrintf (ACRX_T("\nFront Clipping is %d"), pVp->isFrontClipOn ()) ;
    
    acutPrintf (ACRX_T("\nBack Clipping is %d"), pVp->isBackClipOn ()) ;
    if ( backClip == IDYES )
        pVp->setBackClipOn () ;
    acutPrintf(ACRX_T("\nBack Clipping is %d"), pVp->isBackClipOn ()) ;
    
    return (Adesk::kTrue) ;
}
ArxDbgUiPrBase::Status
ArxDbgUiPrCorner::go()
{
    CString prompt;
    int result;
    ads_point adsPt;
    int initFlag = RSG_NONULL;

    if (m_noLimCheck == true)
        initFlag += RSG_NOLIM;
    if (m_useDashedLine == true)
        initFlag += RSG_DASH;

    prompt.Format(_T("\n%s: "), message());

    acedInitGet(initFlag, keyWords());
    result = acedGetCorner(asDblArray(m_basePt), prompt, adsPt);

    if (result == RTNORM) {
        m_value = asPnt3d(adsPt);
        return ArxDbgUiPrBase::kOk;
    }
    else if (result == RTKWORD) {
        const size_t kBufSize = 512;
        acedGetInput(m_keyWordPicked.GetBuffer(kBufSize), kBufSize);
        m_keyWordPicked.ReleaseBuffer();
        return ArxDbgUiPrBase::kKeyWord;
    }
    else
        return ArxDbgUiPrBase::kCancel;
}
Ejemplo n.º 3
0
void jig3d()
{
    
    try
    {
        struct resbuf rb;
        acedGetVar("cvport", &rb);
        if (rb.resval.rint==1)
            throw CmdException("3djig cannot be used in layout mode");
        ads_name ename;
        ads_point pt;
		int rt;
        if ((rt = acedEntSel("Select object:",ename,pt))==RTCAN)
			return;
		if (rt!=RTNORM)
			throw CmdException(Acad::eInvalidInput,"Invalid selection. Try again!");
        AcDbObjectId id;
        acdbGetObjectId(id,ename);

        Jig3d jig;
        jig.init(id, asPnt3d(pt), rb.resval.rint);
        jig.engage();
    }
    catch(CmdException e)
    {
        const char* strDesc = e.description();
        if (strDesc == NULL)
            strDesc = "No description.";
        acutPrintf("ERROR:%s (es=%s)",strDesc,acadErrorStatusText(e.errorStatus()));
    }
}
Ejemplo n.º 4
0
AcGePoint3d CCalculation::PolarPoint(const AcGePoint3d& pt, double angle, double distance)
{ 
	ads_point ptForm, ptTo; 
	ptForm[X] = pt.x; 
	ptForm[Y] = pt.y; 
	ptForm[Z] = pt.z; 
	acutPolar(ptForm, angle, distance, ptTo); 
	return asPnt3d(ptTo); 
}
Ejemplo n.º 5
0
//----- DxfIn implemented to support non order dependant DXF code
Acad::ErrorStatus OarxEmployee::dxfInFields (AcDbDxfFiler *pFiler) {
	//----- Make sure the object is open is write mode
	//----- And enable UNDO resolution
	assertWriteEnabled () ;
	//----- Call parent class implementation for header
	AcDbEntity::dxfInFields (pFiler) ;
	//----- Move to our class pointer in the DXF file (Dxf code: 100)
	Adesk::Boolean bResult ;
	if ( (bResult =pFiler->atSubclassData ("OarxEmployee")) != Adesk::kTrue )
		return (Acad::eMissingDxfField) ;
	//----- Read the version number
	Acad::ErrorStatus es ;
	struct resbuf rb ;
	if ( (es =pFiler->readResBuf (&rb)) != Acad::eOk )
		return (es) ;
	if ( rb.restype != AcDb::kDxfInt32 || (unsigned long)rb.resval.rlong != mVersion )
		return (Acad::eMakeMeProxy) ;
	//----- Read datas in a non dependant order
	while ( pFiler->readResBuf (&rb) == Acad::eOk ) {
		if ( (es =pFiler->readItem (&rb)) != Acad::eOk )
			return (es) ;
		switch ( rb.restype ) {
			case AcDb::kDxfInt32:
				mID =rb.resval.rlong ;
				break ;
			case AcDb::kDxfInt32 + 1:
				mCubeNumber =rb.resval.rlong ;
				break ;
			case AcDb::kDxfXTextString:
				setFirstName (rb.resval.rstring) ;
				acdbFree (rb.resval.rstring) ;
				rb.resval.rstring =NULL ;
				break ;
			case AcDb::kDxfXTextString + 1:
				setLastName (rb.resval.rstring) ;
				acdbFree (rb.resval.rstring) ;
				rb.resval.rstring =NULL ;
				break ;
			case AcDb::kDxfXCoord:
				mCenter =asPnt3d (rb.resval.rpoint) ;
				break ;
			default:
				pFiler->pushBackItem () ;
				break ;
		}
	}
	if ( mID == -1 || mCubeNumber == -1 || mLastName == NULL || mFirstName == NULL ) //----- No way to test mCenter
		return (Acad::eMissingDxfField) ;
	return (pFiler->filerStatus ()) ;
}
AcGePoint3d
ArxDbgUtils::dcsToUcs(const AcGePoint2d& pt)
{
    resbuf fromRb, toRb;
    ads_point newPt;

    fromRb.restype = RTSHORT;
    fromRb.resval.rint = AcDb::kCurDisplayCS;

    toRb.restype = RTSHORT;
    toRb.resval.rint = AcDb::kUserCS;

    short result = acedTrans(asDblArray(pt), &fromRb, &toRb, FALSE, newPt);
    ASSERT(result == RTNORM);

    return asPnt3d(newPt);
}
Ejemplo n.º 7
0
Acad::ErrorStatus PDSphere::dxfInFields(AcDbDxfFiler* filer)
{
	assertWriteEnabled();
	Acad::ErrorStatus es = Acad::eOk;
	struct resbuf rb;

	if ((PDPrimary3D::dxfInFields(filer) != Acad::eOk)
		|| !filer->atSubclassData(_T("PDSphere")))
	{
		return filer->filerStatus();
	}

	// Read version number.
	Adesk::UInt16 version;
	filer->readItem(&rb);
	if (rb.restype != AcDb::kDxfInt16) {
		filer->pushBackItem();
		filer->setError(Acad::eInvalidDxfCode,
			_T("nError: expected object version group code %d"),
			AcDb::kDxfInt16);
		return filer->filerStatus();
	} 
	else {
		version = rb.resval.rint;
		if (version > VERSION_PDSPHERE)
			return Acad::eMakeMeProxy;
	}

	// Read the data members.
	switch (version){
	case (1):
		while ((es == Acad::eOk) && ((es = filer->readResBuf(&rb)) == Acad::eOk)){

			switch (rb.restype){
	case AcDb::kDxfXCoord:
		m_ptCenter = asPnt3d(rb.resval.rpoint);
		break;

	case AcDb::kDxfReal:
		m_dRadius=rb.resval.rreal;
		break;

	case AcDb::kDxfInt32:
		m_nprecision=rb.resval.rlong;
		break;

	default:
		// An unrecognized group. Push it back so that
		// the subclass can read it again.
		filer->pushBackItem();
		es = Acad::eEndOfFile;
		break;
			}
		}
		break;
	}

#ifdef _USEAMODELER_
	if(m_3dGeom.isNull())
		createBody();
#endif

	// At this point the es variable must contain eEndOfFile
	// - either from readResBuf() or from pushback. If not,
	// it indicates that an error happened and we should
	// return immediately.
	//
	if (es != Acad::eEndOfFile)
		return Acad::eInvalidResBuf;

	return filer->filerStatus();
}
Ejemplo n.º 8
0
ArxDbgUiPrBase::Status
ArxDbgUiPrEntity::go()
{
    CString prompt;
    int result;
    int errNum;
    ads_point adsPt;
    ads_name ent;
    AcDbObjectId tmpId;
    AcDbEntity* tmpEnt;
    Acad::ErrorStatus es;

    prompt.Format(_T("\n%s: "), message());

    while (1) {
        acedInitGet(0, keyWords());
        result = acedEntSel(prompt, ent, adsPt);

        if (result == RTNORM) {
            ArxDbgUtils::enameToObjId(ent, tmpId);
            es = acdbOpenAcDbEntity(tmpEnt, tmpId, AcDb::kForRead);
            if (es == Acad::eOk) {
                    // if its correct class and we are not filtering locked layers its ok,
                    // or if we are filtering locked layers and this one isn't on a locked layer
                if (correctClass(tmpEnt)) {     // correctClass() will print error msg
                    if ((!m_filterLockedLayers) ||
                        (ArxDbgUtils::isOnLockedLayer(tmpEnt, true) == false)) {    // isOnLockedLayer() will print error msg
                        tmpEnt->close();
                        m_pickPt = asPnt3d(adsPt);
                        m_objId = tmpId;
                        return ArxDbgUiPrBase::kOk;
                    }
                }
                tmpEnt->close();    // close and loop again until they get it right!
            }
            else {
                ASSERT(0);
                ArxDbgUtils::rxErrorMsg(es);
                return ArxDbgUiPrBase::kCancel;
            }
        }
        else if (result == RTERROR) {
            getSysVar(AcadVar::adserr, errNum);
            if (errNum == OL_ENTSELPICK)            // picked but didn't get anything
                acutPrintf(_T("\nNothing selected."));
            else if (errNum == OL_ENTSELNULL) {     // hit RETURN or SPACE
                if (m_allowNone)
                    return ArxDbgUiPrBase::kNone;      // prompt specifically wants to know about None
                else
                    return ArxDbgUiPrBase::kCancel;    // prompt wants to bail on None
            }
            else
                acutPrintf(_T("\nNothing selected."));
        }
        else if (result == RTKWORD)
		{
            acedGetInput(m_keyWordPicked.GetBuffer(512));
            m_keyWordPicked.ReleaseBuffer();
            return ArxDbgUiPrBase::kKeyWord;
        }
		else if (result == RTNONE)
		{
			return ArxDbgUiPrBase::kNone;
		}
        else
            return ArxDbgUiPrBase::kCancel;
    }
}
Ejemplo n.º 9
0
Acad::ErrorStatus newLine()
{
//Mark the leftmost cubicle as unusable by putting a red diagonal
//line from the lower left to upper right corners
//Use the first parameter of acedGetPoint to rubberband to the second point
//Prompt the user to select the line's endpoints
	ads_point pt1, pt2;
	int retval;
//{{BEGIN_LEVEL_ADVANCED
	
	try 
	{
		//get the first point from the user.  Do not specify a base point.
		//...
//{{BEGIN_LEVEL_INTERMEDIATE
		if ((retval = acedGetPoint(NULL, "\nSelect lower left:  ", pt1)) != RTNORM) 
			throw retval;
//{{END_LEVEL_INTERMEDIATE
		//get the second point from the user, using the first point as a base point.
		//...
//{{BEGIN_LEVEL_INTERMEDIATE
		if ((retval = acedGetPoint(pt1, "\nSelect upper right:  ", pt2)) != RTNORM)
			throw retval;
//{{END_LEVEL_INTERMEDIATE
	}
	catch (int e)
	{
		if (e == RTCAN)
			return Acad::eUserBreak;
		if (e == RTERROR)
			return Acad::eInvalidInput;
	}
//{{END_LEVEL_ADVANCED
	
//Instantiate an AcDbLine pointer.  Use the two user-chosen 
//points as endpoints.
//Since AcDbLine's constructor uses AcGePoint2d, but acedGetPoint returns ads_point,
//you must find a way to translate old style to new style.  This can be done either by
//assigning each array member individually, or by calling asPnt3d() from geassign.h
//{{BEGIN_LEVEL_ADVANCED
//...
//{{BEGIN_LEVEL_INTERMEDIATE

	AcDbLine* pLine = new AcDbLine(asPnt3d(pt1), asPnt3d(pt2));
//{{END_LEVEL_INTERMEDIATE
//Make sure you created the line...
	if (!pLine)
	{
		acedAlert("Not enough memory to create a Line!");
		return Acad::eOutOfMemory;
	}
//{{END_LEVEL_ADVANCED
//Prompt the user to enter a new color
//Then change the color property of the new line to this value.
//{{BEGIN_LEVEL_ADVANCED
//...
//{{BEGIN_LEVEL_INTERMEDIATE
	int color;
	acedGetInt("\nEnter AutoCAD color number:  ", &color);
	if (pLine->setColorIndex(color) != Acad::eOk)
	{
		acutPrintf("\nInvalid color chosen.\n");
	}
//{{END_LEVEL_INTERMEDIATE
//{{END_LEVEL_ADVANCED

//Post the new entity to the database
//{{BEGIN_LEVEL_ADVANCED
	AcDbObjectId id;
	return postToDatabase(pLine, id);
//{{END_LEVEL_ADVANCED
}
void asdktest1 () {
    //----- Select the entities
    ads_name ss, en ;
    if ( acedSSGet (NULL, NULL, NULL, NULL, ss) != RTNORM )
        return ;

    //----- Append entity IDs to the collector
    long n ;
    AcDbObjectId id ;
    AsdkHlrCollector collector ;
    collector.setDeleteState (true) ;
    acedSSLength (ss, &n) ;
    for ( int i =0 ; i < n ; i++ ) {
        acedSSName (ss, i, en) ;
        acdbGetObjectId (id, en) ;
        collector.addEntity (id) ;
    }
    acedSSFree (ss) ;

    //----- Get current viewport settings
    struct resbuf rb;
    acedGetVar(ACRX_T(/*NOXLATE*/"viewdir"), &rb);
    ads_point dirPt;
    acdbUcs2Wcs (rb.resval.rpoint, dirPt, Adesk::kTrue) ;
    acedGetVar(ACRX_T(/*NOXLATE*/"target"), &rb);
    ads_point tarPt;
    acdbUcs2Wcs (rb.resval.rpoint, tarPt, Adesk::kFalse) ;

    //----- Ask if non-visible edges should be created
    int hidLines =AfxMessageBox (ACRX_T("Would you like to see hidden lines?"), MB_YESNO) ;
    int honorInt =AfxMessageBox (ACRX_T("Would you like to honor internal visibility of polyface meshes or ACIS objects?"), MB_YESNO) ;
    int meshSils =AfxMessageBox (ACRX_T("Would you like to calculate silhouettes of polyface meshes?"), MB_YESNO) ;
    int unit =AfxMessageBox (ACRX_T("Would you like to unit solid before processing?"), MB_YESNO) ;

    //----- Process hidden line removal
    AsdkHlrEngine hlr (
        asPnt3d (tarPt), asVec3d (dirPt),
        kEntity | kBlock | kSubentity | kProgress
        | (honorInt == IDYES ? kHonorInternals : 0)
        | (hidLines == IDYES ? kShowAll : 0)
        | (meshSils == IDYES ? kMeshSilhouettes : 0)
        | (unit == IDYES ? kUnite : 0)
    ) ;
    hlr.setAcisConversionProgressCallBack (progress1) ;
    hlr.setAhlProgressCallBack (progress2) ;
    hlr.setAcadConversionProgressCallBack (progress3) ;

    acedSetStatusBarProgressMeter (ACRX_T("HLR running: "), 0, 300) ;
    hlr.run (collector) ;
    acedRestoreStatusBar () ;

    //----- Assign color to the resulting entities
    //----- red for visible edges
    //----- blue for non-visible edges
    //----- yellow for internal edges
    n =collector.mOutputData.logicalLength () ;
    for (int i =0 ; i < n ; i++ ) {
        AsdkHlrData *p =collector.mOutputData [i] ;

        AcDbEntity *pEnt =p->getResultEntity () ;
        AsdkHlrData::Visibility vis =p->getVisibility () ;
        if ( vis == AsdkHlrData::kVisible ) {
            pEnt->setColorIndex (1) ; //----- Read
        } else if ( vis == AsdkHlrData::kInternallyHidden ) {
            if ( p->getHlrVisibility () == AsdkHlrData::kVisible )
                pEnt->setColorIndex (2) ; //----- Yellow
            else
                pEnt->setColorIndex (3) ; //----- Green
        } else {
            pEnt->setColorIndex (5) ; //----- Blue
        }

        if ( postToDatabase (NULL, pEnt, id) != Acad::eOk ) {
            acutPrintf (_T("Failed to add entity to current space.\n")) ;
            break ;
        }
        if ( acdbOpenAcDbEntity (pEnt, id, AcDb::kForRead) != Acad::eOk ) {
            acutPrintf (_T("Failed to open last added outputed curve.\n")) ;
            break ;
        }

        //----- Entity originator path for block reference entities
        AcDbObjectIdArray ids =p->getObjectIds () ;
        if ( ids.logicalLength () > 0 ) {
            acutPrintf (ACRX_T("\n%lx, "), pEnt->objectId ().asOldId ()) ;
            if ( p->getSubentId ().type () != AcDb::kNullSubentType )
                acutPrintf (ACRX_T("[%ld, %ld], "), p->getSubentId ().type (), p->getSubentId ().index ()) ;
            for ( int j =0 ; j < ids.logicalLength () ; j++ )
                acutPrintf (ACRX_T("%lx, "), ids.at (j).asOldId ()) ;
            AcDbObjectId id =ids.last () ;
            if ( !id.isNull () ) {
                AcDbEntity *ent =NULL ;
                acdbOpenAcDbEntity (ent, id, AcDb::kForRead) ;
                id =ent->linetypeId () ;
                ent->close () ;
                if ( pEnt->upgradeOpen () == Acad::eOk )
                pEnt->setLinetype (id) ;
            }
        }

        pEnt->close () ;
    }
}
void asdktest4 () {
    //----- Select the entities
    ads_name ss, en ;
    if ( acedSSGet (NULL, NULL, NULL, NULL, ss) != RTNORM )
        return ;

    //----- Append entity IDs to the collector
    long n ;
    AcDbObjectId id ;
    AsdkHlrCollector collector ;
    acedSSLength (ss, &n) ;
    for ( int i =0 ; i < n ; i++ ) {
        acedSSName (ss, i, en) ;
        acdbGetObjectId (id, en) ;
        collector.addEntity (id) ;
    }
    acedSSFree (ss) ;

    //----- Get current viewport settings
    struct resbuf rb;
    acedGetVar(ACRX_T(/*NOXLATE*/"target"), &rb);
    ads_point tarPt;
    acdbUcs2Wcs (rb.resval.rpoint, tarPt, Adesk::kFalse) ;

    //----- Ask if non-visible edges should be created
    int hidLines =AfxMessageBox (ACRX_T("Would you like to see hidden lines?"), MB_YESNO) ;
    int honorInt =AfxMessageBox (ACRX_T("Would you like to honor internal visibility of polyface meshes or ACIS objects?"), MB_YESNO) ;
    int meshSils =AfxMessageBox (ACRX_T("Would you like to calculate silhouettes of polyface meshes?"), MB_YESNO) ;
    int unit =AfxMessageBox (ACRX_T("Would you like to unit solid before processing?"), MB_YESNO) ;

    //----- *** First view will be front view ***

    //----- Process hidden line removal
    AsdkHlrEngine hlrFront (
        asPnt3d (tarPt), AcGeVector3d (0, -1, 0),//AcGeVector3d (0, 0, -1),
        kProject| kEntity | kBlock | kReuse //----- Do not use 'kCleanup'
        | (honorInt == IDYES ? kHonorInternals : 0)
        | (hidLines == IDYES ? kShowAll : 0)
        | (meshSils == IDYES ? kMeshSilhouettes : 0)
        | (unit == IDYES ? kUnite : 0)
    ) ;
    hlrFront.run (collector) ;
    AddEntityToLayer (collector, ACRX_T("FontView")) ;

    //----- *** Second view will be left view ***

    //----- Process hidden line removal

    AsdkHlrEngine hlrLeft (
        asPnt3d (tarPt), AcGeVector3d (1, 0, 0),//, AcGeVector3d (1, 0, 0),
        kProject| kEntity | kBlock | kReuse //----- Do not use 'kCleanup'
        | (honorInt == IDYES ? kHonorInternals : 0)
        | (hidLines == IDYES ? kShowAll : 0)
        | (meshSils == IDYES ? kMeshSilhouettes : 0)
        | (unit == IDYES ? kUnite : 0)
    ) ;
    hlrLeft.run (collector) ;
    AddEntityToLayer (collector, ACRX_T("LeftView")) ;

    //----- *** Third view will be top view ***

    //----- Process hidden line removal

    AsdkHlrEngine hlrTop (
        asPnt3d (tarPt), AcGeVector3d (0, 0, 1),//, AcGeVector3d (0, -1, 0),
        kProject| kEntity | kBlock | kReuse //----- Do not use 'kCleanup'
        | (honorInt == IDYES ? kHonorInternals : 0)
        | (hidLines == IDYES ? kShowAll : 0)
        | (meshSils == IDYES ? kMeshSilhouettes : 0)
        | (unit == IDYES ? kUnite : 0)
    ) ;
    hlrTop.run (collector) ;
    AddEntityToLayer (collector, ACRX_T("TopView")) ;
}
Ejemplo n.º 12
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);
}
void AcDbDoubleClickEditSpline::startEdit(AcDbEntity *pEnt, AcGePoint3d clickpt)
{
	// Implement the startEdit notification handler to catch when
	// a user double-clicks a 'SPLINE' entity
	
	// Get the Current Document
	AcApDocument *pDoc=acDocManager->curDocument();
	AcDbSpline *pLine;
	
	// Cast the AcDbEntity pointer to AcDbSpline		
	if(pEnt->isKindOf(AcDbSpline::desc()) == Adesk::kTrue)
		pLine=AcDbSpline::cast(pEnt);
	else
	{
		acutPrintf("Error: Invalid AcDbSpline Entity");
		return;
	}
	
	acDocManager->lockDocument(pDoc,AcAp::kWrite);
	
	//Upgrade to write
	if(pLine->upgradeOpen()!=Acad::eOk)
	{
		acutPrintf("Error: Could Not open AcDbSpline Entity");
		return;
	}

	// iterate through all the vertices to find which
	// segment was clicked on, and place a fit-point there.
	for(int c=0;c<pLine->numFitPoints()-1;c++)
	{
		AcGePoint3d pt1,pt2;
		pLine->getFitPointAt(c,pt1);
		pLine->getFitPointAt(c+1,pt2);
		AcGeVector3d lineVec(pt2-pt1),clickVec(clickpt-pt1),
			clickVec2(pt2-clickpt);
		double ang=lineVec.angleTo(clickVec);
		
		// This is the filter...
		// .20 (20% of lineVec length) is an arbitrary length...
		if((sin(ang)*clickVec.length()<.2*lineVec.length()) && 
			clickVec.length()<lineVec.length() && 
			clickVec2.length()<lineVec.length()) 
		{
			// Add the fit-point
			ads_point outPt;
			AcGeVector3d norm(0,0,1);
			acdbWcs2Ecs(asDblArray(clickpt),outPt,asDblArray(norm),Adesk::kFalse);	
			pLine->insertFitPointAt(c+1,asPnt3d(outPt));
			break;
		}
	}
	
	pLine->close();

	acDocManager->unlockDocument(pDoc);

	// invoking acedSSSetFirst(NULL,NULL) here will clear the
	// pickfirst selection, if desired (not With spline though).
	//acedSSSetFirst(NULL,NULL);
	
	// Update the graphics...
	pLine->draw();
	actrTransactionManager->flushGraphics();
	acedUpdateDisplay();
}