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(); }
//This is used to get the value for an element in a group. //The element is identified by the dwCookie parameter STDMETHODIMP CComPolygon::GetElementValue( /* [in] */ DISPID dispID, /* [in] */ DWORD dwCookie, /* [out] */ VARIANT * pVarOut) { CHECKOUTPARAM(pVarOut); if (dispID >= DISPID_NORMAL && dispID <= DISPID_STARTPOINT) { try { if (dwCookie>2) throw Acad::eInvalidInput; Acad::ErrorStatus es; AcAxObjectRefPtr<AsdkPoly> pPoly(&m_objRef,AcDb::kForRead,Adesk::kTrue); if((es=pPoly.openStatus()) != Acad::eOk) throw es; AcAxPoint3d pt; Adesk::Boolean bAsVector=Adesk::kFalse; if (dispID == DISPID_NORMAL) { pt = pPoly->normal(); //translate from wcs to ucs acdbWcs2Ucs(asDblArray(pt),asDblArray(pt),Adesk::kTrue); ::VariantCopy(pVarOut,&CComVariant(pt[dwCookie])); } else { AcAxPoint2d pt2d; 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); ::VariantCopy(pVarOut,&CComVariant(pt[dwCookie])); } } 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; }
// 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; }
void Jig3d::engage(void) throw(CmdException) { char* prompt = "\nSpecify displacement or [Base point/X/Y/Z/Exit]:"; AcEdJig::DragStatus status; do { setDispPrompt(prompt); status = drag(); switch (status) { case AcEdJig::kKW1: if (m_mode == kMove) acedGetPoint(asDblArray(m_refPoint),"Specify base point:",asDblArray(m_refPoint)); else { apply(); status = AcEdJig::kCancel; } break; case AcEdJig::kKW2: assert(m_mode == kMove); m_mode = kRotateX; prompt = "Specify rotation around X axis or [Exit]:"; break; case AcEdJig::kKW3: assert(m_mode == kMove); m_mode = kRotateY; prompt = "Specify rotation around Y axis [Exit]:"; break; case AcEdJig::kKW4: assert(m_mode == kMove); m_mode = kRotateZ; prompt = "Specify rotation around Z axis [Exit]:"; break; case AcEdJig::kKW5: apply(); status = AcEdJig::kCancel; break; default: m_xform = m_xformTemp*m_xform; if (m_mode == kMove) m_refPoint+=m_xformTemp.translation(); m_mode = kMove; prompt = "\nSpecify displacement or [Base point/X/Y/Z/Exit]:"; break; } } while (status != AcEdJig::kCancel); }
BOOL TWBlockRefenceTool::Insert( IN const CString& strBlockName, IN const AcGePoint3d& PtIns, IN double dScale, IN double dRat, AcDbDatabase* pDb /*= NULL */ ) { /* 使用简单的实现方法 */ ads_name entPre = { 0, 0 }; ads_entlast( entPre ); resbuf rbOld; resbuf rbNew; rbNew.restype = RTSHORT; rbNew.resval.rint = 0; acedGetVar( _T("ATTREQ"), &rbOld ); acedSetVar( _T("ATTREQ"), &rbNew ); ads_command( RTSTR, _T("insert"), RTSTR, strBlockName, RT3DPOINT, asDblArray(PtIns), RTREAL, 1.0, RTSTR, _T(""), RTREAL, 0.0, 0 ); acedSetVar( _T("ATTREQ"), &rbOld ); ads_name ent = { 0 ,0 }; ads_entlast( ent ); //判定是否正确生成块参照 if( ads_name_equal(ent, entPre) ) return FALSE; acdbGetObjectId( m_IdblockRef, ent ); return IsValid(); }
// This is the main function of this app. It allows the // user to select an entity. It then checks to see if the // entity is a 2d-polyline. If so, then it calls iterate // passing in the objectId of the pline. // void listPline() { int rc; ads_name en; AcGePoint3d pt; rc = acedEntSel(_T("\nSelect a polyline: "), en, asDblArray(pt)); if (rc != RTNORM) { acutPrintf(_T("\nError during object selection")); return; } AcDbObjectId eId; acdbGetObjectId(eId, en); AcDbObject *pObj; acdbOpenObject(pObj, eId, AcDb::kForRead); if (pObj->isKindOf(AcDb2dPolyline::desc())) { pObj->close(); iterate(eId); } else { pObj->close(); acutPrintf(_T("\nSelected entity is not an AcDb2dPolyline. \nMake sure the setvar PLINETYPE is set to 0 before createing a polyline")); } }
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; }
AcEdJig::DragStatus Jig3d::sampler() { setSpecialCursorType(AcEdJig::kRubberBand); AcGePoint3d pt; AcEdJig::DragStatus status; double angle; if (m_mode == kMove){ setKeywordList("Base X Y Z Exit"); status = acquirePoint(pt,m_refPoint); } else { setKeywordList("Exit"); //acquireAngle seems to have a defect //I'm applying the following temporary //workaround: status = acquirePoint(pt,m_refPoint); angle = acutAngle(asDblArray(pt),asDblArray(m_refPoint)); } if (pt == m_LastPoint) // if there is no work to be done, return status; // exit early! m_LastPoint = pt; if (status == AcEdJig::kNormal){ switch (m_mode) { case kMove: m_xformTemp = AcGeMatrix3d::translation(pt-m_refPoint); m_int.setTransform(m_xformTemp*m_xform); break; case kRotateX: m_xformTemp = AcGeMatrix3d::rotation(angle,AcGeVector3d::kXAxis,m_refPoint); m_int.setTransform(m_xformTemp*m_xform); break; case kRotateY: m_xformTemp = AcGeMatrix3d::rotation(angle,AcGeVector3d::kYAxis,m_refPoint); m_int.setTransform(m_xformTemp*m_xform); break; case kRotateZ: m_xformTemp = AcGeMatrix3d::rotation(angle,AcGeVector3d::kZAxis,m_refPoint); m_int.setTransform(m_xformTemp*m_xform); break; } m_pModel->onModified(&m_int, m_MSBObjectID.asOldId()); } return status; }
virtual void subViewportDraw(AcGiViewportDraw* vportDrawContext) { // Calculate the size of the glyph in WCS (use for text height factor) int glyphPixels = acdbCustomOsnapManager()->osnapGlyphSize(); AcGePoint2d glyphSize; vportDrawContext->viewport().getNumPixelsInUnitSquare( m_center, glyphSize ); double glyphHeight = glyphPixels / glyphSize[ Y ]; // Get the extents of the glyph text, so we can centre it AcGiTextStyle style; AcGePoint2d ptExt = style.extents( ASDK_GLYPH_TEXT, Adesk::kFalse, -1, Adesk::kFalse ); struct resbuf rbFrom, rbTo; rbFrom.restype = RTSHORT; rbFrom.resval.rint = 2; // From DCS rbTo.restype = RTSHORT; rbTo.resval.rint = 0; // To WCS // Translate the X-axis of the DCS to WCS co-ordinates (as a displacement vector) AcGeVector3d ptDir; acedTrans( asDblArray( AcGeVector3d::kXAxis ), &rbFrom, &rbTo, 1, asDblArray( ptDir )); // Translate the centre of the glyph from DCS to WCS co-ordinates AcGePoint3d ptPos, ptCen; AcGeVector3d vecExt( ptExt[ X ] / 2, ptExt[ Y ] / 2, 0 ); ptPos = m_center - vecExt / 2; if ( RTNORM != acedTrans( asDblArray( ptPos ), &rbFrom, &rbTo, 0, asDblArray( ptCen ))) ptCen = m_center; // Draw the centred text representing the glyph vportDrawContext->geometry().text( ptCen, vportDrawContext->viewport().viewDir(), ptDir, glyphHeight, 1.0, 0.0, ASDK_GLYPH_TEXT ); }
bool CMakeBlkFile::GetBasePt() { int nRet = acedGetPoint(NULL, _T("\n请选择插入点"), asDblArray(m_insertPt)); if (nRet != RTNORM) { return false; } return true; }
//----------------------------------------------------------------------------- //----- This is used as the key for our custom //----- dictionary. Note the registered developer id 'OARX' //----- at the beginning void lab9Command () { OarxEmployee *p =NULL ; try { //----- Start transaction for the db operations in this command actrTransactionManager->startTransaction () ; //----- Prompt the use for the an id int id ; ADSOK ( acedGetInt ("Enter employee's ID:", &id) ) ; //----- Before continuing, we should verify if that Employee is already registered if ( EmployeeService->isEmployeeExist (id) != Adesk::kTrue ) { //----- Continue data acquisition int cubeNumber ; char strFirstName [133] ; char strLastName [133] ; AcGePoint3d position ; ADSOK ( acedGetInt ("Enter cube number:", &cubeNumber) ) ; ADSOK ( acedGetString (0, "Enter employee's first name:", strFirstName) ) ; ADSOK ( acedGetString (0, "Enter employee's last name:", strLastName) ) ; ADSOK ( acedGetPoint (asDblArray (position), NULL, asDblArray (position)) ) ; p =EmployeeService->createEmployee (id, position, cubeNumber,strFirstName, strLastName) ; if ( p == NULL ) throw Acad::eOutOfMemory ; } //----- Stop transaction actrTransactionManager->endTransaction () ; } catch (const Acad::ErrorStatus es) { if ( p != NULL && p->objectId () == AcDbObjectId::kNull ) delete p ; //----- Abort, rollback all db operations actrTransactionManager->abortTransaction () ; //----- Check if the user has cancelled us, then we don't report anything if ( es != Acad::eUserBreak ) acutPrintf ("***Error: %s\n", acadErrorStatusText (es)) ; } }
AcGePoint2d ArxDbgUtils::ucsToDcs(const AcGePoint3d& pt) { resbuf fromRb, toRb; ads_point newPt; fromRb.restype = RTSHORT; fromRb.resval.rint = AcDb::kUserCS; toRb.restype = RTSHORT; toRb.resval.rint = AcDb::kCurDisplayCS; short result = acedTrans(asDblArray(pt), &fromRb, &toRb, FALSE, newPt); ASSERT(result == RTNORM); return asPnt2d(newPt); }
ArxDbgUiPrBase::Status ArxDbgUiPrAngleDef::go() { CString prompt; char defStr[512]; int initFlag; // set up prompt acdbAngToS(m_default, m_unit, m_precision, defStr); prompt.Format(_T("\n%s<%s>: "), message(), defStr); // set up init flag if (m_angType == kNoZero) initFlag = RSG_NOZERO; else initFlag = 0; int result; while (1) { acedInitGet(initFlag, keyWords()); if (m_useBasePt) result = acedGetOrient(asDblArray(m_basePt), prompt, &m_value); else result = acedGetOrient(NULL, prompt, &m_value); if (result == RTNORM) { if (inRange()) return ArxDbgUiPrBase::kOk; } else if(result == RTKWORD) { acedGetInput(m_keyWordPicked.GetBuffer(512)); m_keyWordPicked.ReleaseBuffer(); return ArxDbgUiPrBase::kKeyWord; } else if (result == RTNONE) { if (m_angType == ArxDbgUiPrAngle::kRange) { ASSERT(m_minVal != m_maxVal); // make sure they set ranges! ASSERT((m_default >= m_minVal) && (m_default <= m_maxVal)); } m_value = m_default; return ArxDbgUiPrBase::kOk; } else return ArxDbgUiPrBase::kCancel; } }
ArxDbgUiPrBase::Status ArxDbgUiPrAngle::go() { CString prompt; int initFlag = 0; // set up prompt prompt.Format(_T("\n%s: "), message()); // set up init flag if (m_allowNone == false) initFlag += RSG_NONULL; if (m_angType == kNoZero) initFlag += RSG_NOZERO; int result; while (1) { acedInitGet(initFlag, keyWords()); if (m_useBasePt) result = acedGetOrient(asDblArray(m_basePt), prompt, &m_value); else result = acedGetOrient(NULL, prompt, &m_value); if (result == RTNORM) { if (inRange()) return ArxDbgUiPrBase::kOk; } else if (result == RTKWORD) { acedGetInput(m_keyWordPicked.GetBuffer(512)); m_keyWordPicked.ReleaseBuffer(); return ArxDbgUiPrBase::kKeyWord; } else if (result == RTNONE) { if (inRange()) return ArxDbgUiPrBase::kOk; } else return ArxDbgUiPrBase::kCancel; } }
void pointContainment() { AcBr::ErrorStatus returnValue = AcBr::eOk; // Select the entity by type AcBrEntity* pEnt = NULL; AcDb::SubentType subType = AcDb::kNullSubentType; returnValue = selectEntityByType(pEnt, subType); if (returnValue != AcBr::eOk) { acutPrintf(ACRX_T("\n Error in selectEntityByType:")); errorReport(returnValue); delete pEnt; return; } // Query the point by AutoCAD pick AcGePoint3d testPt; acedGetPoint(NULL, ACRX_T("\n Pick point for containment test: \n"), asDblArray(testPt)); AcGe::PointContainment containment = AcGe::kOutside; AcBrEntity* container = NULL; returnValue = pEnt->getPointContainment(testPt, containment, container); if (returnValue != AcBr::eOk) { acutPrintf(ACRX_T("\n Error in AcBrEntity::getPointContainment:")); errorReport(returnValue); delete pEnt; return; } ptContainmentReport(containment, container); delete container; delete pEnt; return; }
resbuf* ptArrayToResbuf(const AcGePoint3dArray& ptArray) { resbuf* ptList = NULL; // overall list resbuf* lastRb = NULL; // place holder to end of list resbuf* rb; int len = ptArray.length(); for (int i=0;i<len;i++) { if ((rb = acutNewRb(RT3DPOINT)) == NULL) { acutRelRb(ptList); return NULL; } copyAdsPt(rb->resval.rpoint, asDblArray(ptArray.at(i))); if (ptList == NULL) { ptList = rb; lastRb = rb; } else { lastRb->rbnext = rb; lastRb = rb; } } return ptList; }
// ----- AsdkSelectionFilterUI_Rings command (do not rename) static void AsdkSelectionFilterUI_Rings(void) { //Create the custom entity (Rings) AcGePoint3d cen; ads_point pt; ads_real radius_1; acedGetPoint(NULL, "\nClick to select center of circles: ", asDblArray( cen )); pt[X] = cen[0]; pt[Y]=cen[1]; pt[Z]=cen[2]; acedGetDist(pt, "\nDrag line to indicate radius of smallest circle: ", &radius_1); // Add new custom (Rings) entity pRings = new AsdkRings(cen,(double) radius_1); pRings ->setDatabaseDefaults(); AppendEnt((AcDbEntity *)pRings); pRings ->close(); }
//---------------------------------------------------------------------------- // XML protocol extension implementation Acad::ErrorStatus AcDbXmlPoly::xmlIn( AcDbObject* pObj, AcDbXmlInFiler* pFiler) { if (pObj == NULL || pFiler == NULL) return eInvalidInput; AsdkPoly* pPoly = AsdkPoly::cast(pObj); if (pPoly == NULL) return eInvalidInput; AcUtXMLDOMNode* pFirstNode = pFiler->getCurrentNode(); // don't delete if (pFirstNode == NULL) return eInvalidInput; AcUtXMLDOMNode* pCurrent = NULL; AcUtXMLDOMNode* pChild = NULL; AcUtXMLDOMElement* pElement = NULL; AcUtXMLDOMResult hr; Acad::ErrorStatus es = eOk; AcGePoint2d centerPt; AcGePoint3d centerPt3d; AcGePoint2d startPt; AcGePoint3d startPt3d; AcGeVector3d normal; AcDbObjectId textStyleId; AcUtString name; int numSides; double elevation = 0; AcUtString nodeName = pFiler->getCurrentNodeName(); try { // first child should be asdk:Poly hr = pFirstNode->get_firstChild(pCurrent); if (hr != S_OK) throw eInvalidInput; // make it current pFiler->setCurrentNode(pCurrent); // verify node name is Poly nodeName = pFiler->getCurrentNodeName(); if (nodeName.compare(L"asdk:Poly") != 0) throw eInvalidInput; // Get the numSides and name atributes pElement = new AcUtXMLDOMElement(pCurrent); if (pElement == NULL) throw eOutOfMemory; es = pFiler->readAttribute(pElement, L"numSides", numSides); if (es != eOk) throw es; es = pFiler->readAttribute(pElement, L"name", name); if (es != eOk) throw es; // Get the first child element of the asdk:Poly hr = pCurrent->get_firstChild(pChild); if (hr != S_OK) throw eInvalidInput; // Make it current pFiler->setCurrentNode(pChild); delete pCurrent; pCurrent = pChild; pChild = NULL; nodeName = pFiler->getCurrentNodeName(); // This first child node might be an optional acdb:Entity if (nodeName.compare(AcUtString(L"acdb:Entity")) == 0) { // Read the acdb:Entity node es = superXmlIn(pObj, pFiler); if (es != eOk) throw es; hr = pCurrent->get_nextSibling(pChild); if (hr != S_OK) throw eInvalidInput; pFiler->setCurrentNode(pChild); delete pCurrent; pCurrent = pChild; pChild = NULL; } // Expect the current node to be a dxml:CenterPoint. es = pFiler->readPoint(L"dxml:CenterPoint", centerPt3d); if (es != eOk) throw es; // Get the next sibiling to the circle - expect StartPoint. hr = pCurrent->get_nextSibling(pChild); if (hr != S_OK) throw eInvalidInput; pFiler->setCurrentNode(pChild); delete pCurrent; pCurrent = pChild; pChild = NULL; es = pFiler->readPoint(L"dxml:StartPoint", startPt3d); if (es != eOk) throw es; // Get the next sibiling to the circle - expect NormalVector. hr = pCurrent->get_nextSibling(pChild); if (hr != S_OK) throw eInvalidInput; pFiler->setCurrentNode(pChild); delete pCurrent; pCurrent = pChild; pChild = NULL; es = pFiler->readNormalVector(normal); if (es != eOk) throw es; // Get the next sibiling to the circle - expect TextStyleTableRecordId. hr = pCurrent->get_nextSibling(pChild); if (hr != S_OK) throw eInvalidInput; pFiler->setCurrentNode(pChild); delete pCurrent; pCurrent = pChild; pChild = NULL; es = pFiler->readObjectId(L"acdb:TextStyleTableRecordId", textStyleId); if (es != eOk) throw es; es = pPoly->setTextStyle(textStyleId); if (es != eOk) throw es; // Convert the center point from WCS to ECS acdbWcs2Ecs(asDblArray(centerPt3d), asDblArray(centerPt3d), asDblArray(normal), true); centerPt.x = centerPt3d.x; centerPt.y = centerPt3d.y; elevation = centerPt3d.z; // Convert the start point from WCS to ECS acdbWcs2Ecs(asDblArray(startPt3d), asDblArray(startPt3d), asDblArray(normal), true); startPt.x = startPt3d.x; startPt.y = startPt3d.y; es = pPoly->set(centerPt, startPt, numSides, normal, name, elevation); if (es != eOk) throw es; } catch (Acad::ErrorStatus thrownEs) { es = thrownEs; } // restore first node pFiler->setCurrentNode(pFirstNode); if (pElement) delete pElement; if (pCurrent && pCurrent != pFiler->getCurrentNode()) delete pCurrent; if (pChild) delete pChild; return es; }
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; }
void mkraddobjects() { AcGePoint3d pt; if (RTNORM != acedGetPoint( NULL, "\nEnter position:", asDblArray (pt) )) return; AsdkMkrEntity* pEnt = new AsdkMkrEntity; if (NULL == pEnt) return; pEnt->setPos( pt ); if (!append( pEnt )) { delete pEnt; return; } AcDbObjectId objId; AsdkMkrObject *pObj = new AsdkMkrObject; if (NULL == pObj) { pEnt->erase(); pEnt->close(); return; } #ifdef DIRECT acdbHostApplicationServices()->workingDatabase() ->addAcDbObject( objId, pObj ); pObj->close(); #else #ifdef NOD AcDbDictionary* pMyDict = getDict( /*NOXLATE*/"ASDK_MYDICT", AcDb::kForWrite ); if (NULL != pMyDict) pMyDict->setMergeStyle(AcDb::kDrcMangleName); #else AcDbDictionary* pMyDict = getExtDict( pEnt, /*NOXLATE*/"ASDK_MYDICT", AcDb::kForWrite ); #endif // NOD if (NULL == pMyDict) { delete pObj; pEnt->erase(); pEnt->close(); return; } Acad::ErrorStatus es; if (pMyDict->has( /*NOXLATE*/"MYENTRY" )) es = pMyDict->setAt( "*", pObj, objId ); else es = pMyDict->setAt( /*NOXLATE*/"MYENTRY", pObj, objId ); pMyDict->close(); if (Acad::eOk == es) pObj->close(); else { delete pObj; pEnt->erase(); pEnt->close(); return; } #endif // DIRECT pEnt->setId( objId ); pEnt->close(); acutPrintf( "\nEv'rything OK\n" ); }
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; }
void lineContainment() { AcBr::ErrorStatus returnValue = AcBr::eOk; // Select the entity by type AcBrEntity* pEnt = NULL; AcDb::SubentType subType = AcDb::kNullSubentType; returnValue = selectEntityByType(pEnt, subType); if (returnValue != AcBr::eOk) { acutPrintf("\n Error in selectEntityByType:"); errorReport(returnValue); delete pEnt; return; } // Query the line by AutoCAD pick AcGePoint3d startPt, endPt; int hitCount = 0; acutPrintf("\n Pick line for containment test, by selecting two points: \n"); acedGetPoint(NULL, "\n Pick origin of line: \n", asDblArray(startPt)); acedGetPoint(NULL, "\n Pick another point on line: \n", asDblArray(endPt)); acedGetInt("\n Number of hits wanted: ", &hitCount); // Query the line type const AcGeLinearEnt3d* line = NULL; char opt[128]; while (Adesk::kTrue) { acutPrintf("\nEnter Line Type: "); acedInitGet(NULL, "Infinite Ray Segment"); if (acedGetKword("Infinite/Ray/<Segment>: ", opt) == RTCAN) return; // Map the user input to a valid line type if ((strcmp(opt, "Segment") == 0) || (strcmp(opt, "") == 0)) { line = new AcGeLineSeg3d(startPt, endPt); break; } else if (strcmp(opt, "Ray") == 0) { line = new AcGeRay3d(startPt,endPt); break; } else if (strcmp(opt, "Infinite") == 0) { line = new AcGeLine3d(startPt, endPt); break; } } if (line == NULL) { acutPrintf("\n lineContainment: unable to allocate memory for line\n"); delete pEnt; return; } Adesk::UInt32 numHitsWanted = (Adesk::UInt32)hitCount; Adesk::UInt32 numHitsFound = 0; AcBrHit* hits = NULL; returnValue = pEnt->getLineContainment(*line, numHitsWanted, numHitsFound, hits); if (returnValue != AcBr::eOk) { acutPrintf("\n Error in AcBrEntity::getLineContainment:"); errorReport(returnValue); delete pEnt; return; } acutPrintf("\n Number of hits found: %d", numHitsFound); for (Adesk::UInt32 i = 0; i < numHitsFound; i++) { AcBrEntity* entityAssociated = NULL; returnValue = hits[i].getEntityAssociated(entityAssociated); if (returnValue != AcBr::eOk) { acutPrintf("\n Error in AcBrHit::getEntityAssociated:"); errorReport(returnValue); delete entityAssociated; break; } if (!pEnt->isEqualTo(entityAssociated)) { acutPrintf("\n lineContainment: Hit owner is not the entity we checked line containment against!"); delete entityAssociated; break; } AcGePoint3d pt; returnValue = hits[i].getPoint(pt); if (returnValue != AcBr::eOk) { acutPrintf("\n Error in AcBrHit::getPoint:"); errorReport(returnValue); break; } AcBrEntity* entityHit = NULL; returnValue = hits[i].getEntityHit(entityHit); if (returnValue != AcBr::eOk) { acutPrintf("\n Error in AcBrHit::getEntityHit:"); errorReport(returnValue); delete entityHit; break; } AcBrEntity* entityEntered = NULL; returnValue = hits[i].getEntityEntered(entityEntered); if (returnValue != AcBr::eOk) { acutPrintf("\n Error in AcBrHit::getEntityEntered:"); errorReport(returnValue); delete entityHit; delete entityEntered; break; } lnContainmentReport(i, pt, entityHit, entityEntered); delete entityHit; delete entityEntered; } delete pEnt; delete[] hits; return; }
void generateInventarTable(std::map<std::wstring, AcGePoint3d>& m_points, double textHeight) { Acad::ErrorStatus es; AcGePoint3d insertionPoint; AcDbObjectId objectID; AcDbTable* pTable = nullptr; AcDbDictionary* pDic = nullptr; AcDbBlockTable* pBT = nullptr; AcDbBlockTableRecord* pBTR = nullptr; AcDbDatabase*pDb = nullptr; u_int nrRows = m_points.size() + 2; double headerHeight = textHeight + ((textHeight * HEADERPERCENT) / 100); double titleHeight = textHeight + ((textHeight * TITLEPERCENT) / 100); double nrpctWidth = 0.0; int ret = acedGetPoint(NULL, _T("\nSelecteaza punctul de insertie al tabelului "), asDblArray(insertionPoint)); AcDbObjectId textID = Utils::NewTextStyle(_T("TableStyle"), titleHeight); pDb = acdbHostApplicationServices()->workingDatabase(); pBTR = new AcDbBlockTableRecord; pDb->getSymbolTable(pBT, AcDb::kForRead); pBT->getAt(ACDB_MODEL_SPACE, pBTR, AcDb::kForWrite); pBT->close(); es = pDb->getTableStyleDictionary(pDic, AcDb::kForWrite); es = pDic->getAt(_T("Standard"), objectID); es = pDic->close(); pTable = new AcDbTable; pTable->setTableStyle(objectID); pTable->setSize(nrRows, NUM_COL); pTable->setAlignment(AcDb::kMiddleCenter); pTable->setTextHeight( titleHeight,AcDb::kTitleRow); pTable->setTextHeight(headerHeight, AcDb::kHeaderRow); pTable->setTextHeight(textHeight, AcDb::kDataRow); //pTable->setTextStyle(objectID); pTable->setTextStyle(0, 0, textID); pTable->setTextString(0, 0, _T("Inventar de coordonate")); double tableWidth = Utils::GetTextWidth(_T("Inventar@de@coordonate"), _T("TableStyle")); pTable->setWidth(tableWidth + (tableWidth * 15) / 100); pTable->setTextString(1, 0, _T("Nr.\npct.")); pTable->setTextStyle(1,0, textID); nrpctWidth = Utils::GetTextWidth(_T("NRPCT"), _T("TableStyle")); pTable->setColumnWidth(0,nrpctWidth); pTable->setTextStyle(1, 1, textID); pTable->setTextString(1, 1, _T("X[m]")); pTable->setTextStyle(1, 2, textID); pTable->setTextString(1, 2, _T("Y[m]")); std::map<std::wstring, AcGePoint3d>::iterator it = m_points.begin(); for (u_int row = 0; row < nrRows; row++) { //double tempWidth = Utils::GetTextWidth(Utils::int_To_wstring(row + 1).c_str(),_T("TableStyle")); //if (tempWidth > nrpctWidth) //{ // nrpctWidth = tempWidth; // pTable->setColumnWidth(0, nrpctWidth); //} pTable->setTextStyle(row + 2, 0, textID); pTable->setTextString(row + 2, 0, Utils::int_To_wstring(row+1).c_str()); //nr. curent pTable->setTextStyle(row + 2, 1, textID); pTable->setTextString(row + 2, 1, Utils::real_To_wstring(it->second.y).c_str()); // valoare X pTable->setTextStyle(row + 2, 2, textID); pTable->setTextString(row + 2, 2, Utils::real_To_wstring(it->second.x).c_str()); // valoare Y it++; } pTable->generateLayout(); pTable->setPosition(insertionPoint); pBTR->appendAcDbEntity(pTable); pBTR->close(); pTable->close(); }
static Acad::ErrorStatus extractSolidFromBlock(ads_name ename, const AcDb::SubentType& subType, const short& marker, const AcGePoint3d& pickpnt, AcDbFullSubentPath& subPath) { Acad::ErrorStatus acadReturnValue = Acad::eOk; struct resbuf* insertStack; ads_matrix adsMatrix; int errStat = RTERROR; errStat = acedNEntSelP(NULL, ename, asDblArray(pickpnt), Adesk::kTrue, adsMatrix, &insertStack); if (errStat != RTNORM) { acutPrintf(ACRX_T("\n %d nentselp failed\n"), errStat); return acadReturnValue; } // ename should be the solid AcDbObjectId objId; acadReturnValue = acdbGetObjectId(objId, ename); if (acadReturnValue != Acad::eOk) { acutPrintf(ACRX_T("\n acdbGetObjectId failed\n")); errorReport((AcBr::ErrorStatus)acadReturnValue); return acadReturnValue; } // Use an existing transaction if there is one; // else open a new one Adesk::Boolean ownTransaction = Adesk::kFalse; acadReturnValue = dbOpenTransaction(ownTransaction); if (acadReturnValue != Acad::eOk) { acutPrintf(ACRX_T("\n Error in dbOpenTransaction:")); errorReport((AcBr::ErrorStatus)acadReturnValue); return acadReturnValue; } // Open the object for read-only AcDbObject* pObj = NULL; acadReturnValue = actrTransactionManager->getObject( pObj, objId, AcDb::kForRead); if (acadReturnValue != Acad::eOk) { dbAbortTransaction(ownTransaction); acutPrintf(ACRX_T("\n Error in getPath:")); errorReport((AcBr::ErrorStatus)acadReturnValue); return acadReturnValue; } int count = 0; AcDbObjectId* idArray = new AcDbObjectId[100]; idArray[count++] = objId; while (insertStack != NULL) { ename[0] = insertStack->resval.rlname[0]; ename[1] = insertStack->resval.rlname[1]; acadReturnValue = acdbGetObjectId(objId, ename); if (acadReturnValue != Acad::eOk) { acutPrintf(ACRX_T("\n acdbGetObjectId failed\n")); errorReport((AcBr::ErrorStatus)acadReturnValue); dbCloseTransaction(ownTransaction); return acadReturnValue; } idArray[count++] = objId; insertStack = insertStack->rbnext; } // Invert the list AcDbObjectIdArray objIdList; for (int j=(count-1); j>=0; j--) objIdList.append(idArray[j]); acadReturnValue = makeSubentPath(pObj, objIdList, subType, marker, pickpnt, subPath); if (acadReturnValue != Acad::eOk) { acutPrintf(ACRX_T("\n makeSubentPath failed\n")); dbCloseTransaction(ownTransaction); return acadReturnValue; } // Close the transaction dbCloseTransaction(ownTransaction); return acadReturnValue; }
Acad::ErrorStatus selectEntity(const AcDb::SubentType& subType, AcDbFullSubentPath& subPath) { Acad::ErrorStatus acadReturnValue = Acad::eOk; int errStat = RTERROR; ads_name sset; AcGePoint3d pickPnt; struct resbuf org_osnap; acedGetVar(ACRX_T("OSMODE"), &org_osnap); struct resbuf new_osnap = org_osnap; new_osnap.resval.rint = 0; acedSetVar(ACRX_T("OSMODE"), &new_osnap); while ((errStat != RTNORM) && (errStat != RTCAN) && (errStat != RTREJ) && (errStat != RTNONE)) { ads_name ent_name; switch(subType) { case AcDb::kNullSubentType: errStat = acedEntSel(ACRX_T("\n Pick a solid\n"), ent_name, asDblArray(pickPnt)); break; case AcDb::kFaceSubentType: errStat = acedEntSel(ACRX_T("\n Pick a face\n"), ent_name, asDblArray(pickPnt)); break; case AcDb::kEdgeSubentType: errStat = acedEntSel(ACRX_T("\n Pick an edge\n"), ent_name, asDblArray(pickPnt)); break; default: acutPrintf(ACRX_T("\n getPath: unsupported subentity type: %d\n"), subType); return Acad::eInvalidInput; } if (errStat == RTERROR) { struct resbuf buf_errno; acedGetVar(ACRX_T("ERRNO"), &buf_errno); if (buf_errno.resval.rint == OL_ENTSELNULL) errStat = RTNONE; } } if (errStat == RTNORM) { errStat = acedSSGet(NULL, asDblArray(pickPnt), NULL, NULL, sset); } acedSetVar(ACRX_T("OSMODE"), &org_osnap); if (errStat != RTNORM) return Acad::eAmbiguousInput; // Get the entity name struct resbuf* rb; errStat = acedSSNameX(&rb, sset, 0L); if (errStat != RTNORM) { acedSSFree(sset); return Acad::eAmbiguousInput; } // Free the selection set acedSSFree(sset); // The selected entity is the final entry in the resbuf int i; struct resbuf* pTemp; for (i=1, pTemp=rb; i<3; i++, pTemp=pTemp->rbnext) ; ads_name ename; ads_name_set(pTemp->resval.rlname, ename); // Get the GsMarker pTemp = pTemp->rbnext; short marker = pTemp->resval.rint; // Free the rb resbuf entity acutRelRb(rb); // Get the object ID of the selected entity AcDbObjectId objId; acadReturnValue = acdbGetObjectId(objId, ename); if (acadReturnValue != Acad::eOk) { acutPrintf(ACRX_T("\n acdbGetObjectId failed\n")); return acadReturnValue; } // Use an existing transaction if there is one; // else open a new one Adesk::Boolean ownTransaction = Adesk::kFalse; acadReturnValue = dbOpenTransaction(ownTransaction); if (acadReturnValue != Acad::eOk) { acutPrintf(ACRX_T("\n Error in dbOpenTransaction:")); errorReport((AcBr::ErrorStatus)acadReturnValue); return acadReturnValue; } // Open the object for read-only AcDbObject* pObj = NULL; acadReturnValue = actrTransactionManager->getObject( pObj, objId, AcDb::kForRead); if (acadReturnValue != Acad::eOk) { dbAbortTransaction(ownTransaction); acutPrintf(ACRX_T("\n Error in getPath:")); errorReport((AcBr::ErrorStatus)acadReturnValue); return acadReturnValue; } if (AcDbBlockReference::cast(pObj) != NULL) { acadReturnValue = extractSolidFromBlock(ename, subType, marker, pickPnt, subPath); if (acadReturnValue != Acad::eOk) { dbCloseTransaction(ownTransaction); acutPrintf(ACRX_T("\n extractSolidFromBlock failed\n")); return acadReturnValue; } } else { AcDbObjectIdArray objIdList; objIdList.append(objId); acadReturnValue = makeSubentPath(pObj, objIdList, subType, marker, pickPnt, subPath); if (acadReturnValue != Acad::eOk) { dbCloseTransaction(ownTransaction); acutPrintf(ACRX_T("\n makeSubentPath failed\n")); return acadReturnValue; } } // Close the transaction dbCloseTransaction(ownTransaction); return acadReturnValue; }
//----------------------------------------------------------------------------- // This function uses the AcEdJig mechanism to create and // drag the polyline entity. // void createRect() { // First have the user select the first corner point. // We don't use the Jig for this because there is // nothing to see yet. // int stat, oldOrthoMode; int terminated = FALSE; char keyWord[10]; plineInfo.m_elevHandSet = plineInfo.m_elev != 0.0; // Since it looks quite strange to have orthomode on while trying to draw a // rectangle, we'll temporarily turn it off. Remembering the current setting // and resetting it when we leave. // oldOrthoMode = getIntSysVar(/*NOXLATE*/"ORTHOMODE"); setIntSysVar(/*NOXLATE*/"ORTHOMODE", 0); // Flip to the graphic screen // acedGraphScr(); // Add value line. if ((plineInfo.m_first != 0.0 && plineInfo.m_second != 0 && plineInfo.m_radius == 0.0) || (plineInfo.m_elev != 0) ||(plineInfo.m_radius != 0)||(plineInfo.m_thick != 0) || (plineInfo.m_width != 0)) { acutPrintf("\nRectangle modes: "); if (plineInfo.m_first != 0.0 && plineInfo.m_second != 0. && plineInfo.m_radius == 0.0) { acutPrintf("Chamfer=%.16q0 x %.16q0 ", plineInfo.m_first, plineInfo.m_second); } if (plineInfo.m_elev != 0.) acutPrintf("Elevation=%.16q0 ", plineInfo.m_elev); if (plineInfo.m_radius != 0.) acutPrintf("Fillet=%.16q0 ", plineInfo.m_radius); if (plineInfo.m_thick != 0.) acutPrintf("Thickness=%.16q0 ", plineInfo.m_thick); if (plineInfo.m_width != 0.) acutPrintf("Width=%.16q0 ", plineInfo.m_width); acutPrintf("\n"); } while(!terminated) { // Main prompt for user input. // acedInitGet(RSG_NONULL, "Chamfer Elevation Fillet Thickness Width"); if ((stat = acedGetPoint(NULL, "\nChamfer/Elevation/Fillet/Thickness/Width/<First corner>: ", asDblArray(plineInfo.m_topLeftCorner)))== RTKWORD) { acedGetInput(keyWord); } else { if (stat == RTCAN) terminated = TRUE; break; } switch(indexOfKeyWord(keyWord, "Chamfer Elevation Fillet Thickness Width")) { // Chamfer; case 0: // Retrieve the first chamfer distance. // acutPrintf("\nFirst chamfer distance for rectangles <%.16q0>: ", plineInfo.m_first == 0.0 ? plineInfo.m_radius : plineInfo.m_first); if ((stat = acedGetDist(NULL, NULL, &plineInfo.m_first)) == RTCAN) { terminated = TRUE; break; } else if (stat == RTNONE && plineInfo.m_first == 0.0) plineInfo.m_second = plineInfo.m_radius; // Retrieve the second chamfer distance. // acutPrintf("\nSecond chamfer distance for rectangles <%.16q0>: ", plineInfo.m_second == 0.0 ? plineInfo.m_first : plineInfo.m_second); if ((stat = acedGetDist(NULL, NULL, &plineInfo.m_second)) == RTCAN) { plineInfo.m_first = 0.0; plineInfo.m_second= 0.0; terminated = TRUE; } else { if (stat == RTNONE && plineInfo.m_second == 0.0) plineInfo.m_second = plineInfo.m_first; // If we actually set the chamfer distances, then zero out the // radius and bulge. // plineInfo.m_radius = 0.0; plineInfo.m_bulge = 0.0; } break; // Elevation; case 1: // Retrieve the radius to apply to the filleting of the corners. // acutPrintf("\nElevation for rectangles <%.16q0>: ", plineInfo.m_elev); if ((stat = acedGetDist(NULL, NULL, &plineInfo.m_elev)) == RTCAN) terminated = TRUE; plineInfo.m_elevHandSet = (plineInfo.m_elev == 0.0) ? FALSE : TRUE; break; // Fillet; case 2: // Retrieve the radius to apply to the filleting of the corners. // If the user has previously used the chamfer, then use the // first disance as the default for the radius. // acutPrintf("\nFillet radius for rectangles <%.16q0>: ", plineInfo.m_radius == 0.0 ? plineInfo.m_first : plineInfo.m_radius); if ((stat = acedGetDist(NULL, NULL, &plineInfo.m_radius)) == RTCAN) { terminated = TRUE; } else { if (stat == RTNONE && plineInfo.m_radius == 0.0) plineInfo.m_radius = plineInfo.m_first; plineInfo.m_second = plineInfo.m_first = plineInfo.m_radius; // Bulge is tangent of 1/4 of the included angle. // We'll assume normal[Z] > 0. & clock wise for now, // hence the '-'. plineInfo.m_bulge = -tan(PI / 8.0); } break; // Thickness; case 3: // Retrieve the thickness to apply to the polyline. // acutPrintf("\nThickness for rectangles <%.16q0>: ", plineInfo.m_thick); if ((stat = acedGetDist(NULL, NULL, &plineInfo.m_thick)) == RTCAN) { terminated = TRUE; } break; // Width; case 4: // Retrieve the width to apply to the polyline. // acutPrintf("\nWidth for rectangles <%.16q0>: ", plineInfo.m_width); if ((stat = acedGetDist(NULL, NULL, &plineInfo.m_width)) == RTCAN) { terminated = TRUE; } break; // Just in case; default: terminated = TRUE; break; } } if (!terminated) { if (plineInfo.m_first != 0.0) { // If we are treating the corners, then calculate the unit vector // of the corners. Note for filleting the angle is 45 degrees. // plineInfo.m_chamfDirUnitVec = AcGeVector3d(plineInfo.m_second, plineInfo.m_first, plineInfo.m_elev); univec(plineInfo.m_chamfDirUnitVec, plineInfo.m_chamfDirUnitVec); } // Create an AsdkRectangleJig object passing in the CRectInfo sturcture // filled during the users input // AsdkRectangleJig* pJig = new AsdkRectangleJig(); // Now start up the jig to interactively get the opposite corner. // pJig->doRectangle(); // Now delete the jig object since it's no longer needed // delete pJig; } // Be nice and reset it now. // setIntSysVar(/*NOXLATE*/"ORTHOMODE", oldOrthoMode); return; }
void addBlockWithAttributes() { // Get an insertion point for the block reference, // definition, and attribute definition. // AcGePoint3d basePoint; if (acedGetPoint(NULL, "\nEnter insertion point: ", asDblArray(basePoint)) != RTNORM) return; // Get the rotation angle for the attribute definition. // double textAngle; if (acedGetAngle(asDblArray(basePoint), "\nEnter rotation angle: ", &textAngle) != RTNORM) return; // Define the height used for the attribute definition text. // double textHeight; if (acedGetDist(asDblArray(basePoint), "\nEnter text height: ", &textHeight) != RTNORM) return; // Build the block definition to be inserted. // AcDbObjectId blockId; defineBlockWithAttributes(blockId, basePoint, textHeight, textAngle); // Step 1: Allocate a block reference object. // AcDbBlockReference *pBlkRef = new AcDbBlockReference; // Step 2: Set up the block reference to the newly // created block definition. // pBlkRef->setBlockTableRecord(blockId); // Give it the current UCS normal. // struct resbuf to, from; from.restype = RTSHORT; from.resval.rint = 1; // UCS to.restype = RTSHORT; to.resval.rint = 0; // WCS AcGeVector3d normal(0.0, 0.0, 1.0); acedTrans(&(normal.x), &from, &to, Adesk::kTrue, &(normal.x)); // Set the insertion point for the block reference. // pBlkRef->setPosition(basePoint); // Indicate the LCS 0.0 angle, not necessarily the UCS 0.0 angle. // pBlkRef->setRotation(0.0); pBlkRef->setNormal(normal); // Step 3: Open the current database's model space // block Table Record. // AcDbBlockTable *pBlockTable; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable, AcDb::kForRead); AcDbBlockTableRecord *pBlockTableRecord; pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite); pBlockTable->close(); // Append the block reference to the model space // block Table Record. // AcDbObjectId newEntId; pBlockTableRecord->appendAcDbEntity(newEntId, pBlkRef); pBlockTableRecord->close(); // Step 4: Open the block definition for read. // AcDbBlockTableRecord *pBlockDef; acdbOpenObject(pBlockDef, blockId, AcDb::kForRead); // Set up a block table record iterator to iterate // over the attribute definitions. // AcDbBlockTableRecordIterator *pIterator; pBlockDef->newIterator(pIterator); AcDbEntity *pEnt; AcDbAttributeDefinition *pAttdef; for (pIterator->start(); !pIterator->done(); pIterator->step()) { // Get the next entity. // pIterator->getEntity(pEnt, AcDb::kForRead); // Make sure the entity is an attribute definition // and not a constant. // pAttdef = AcDbAttributeDefinition::cast(pEnt); if (pAttdef != NULL && !pAttdef->isConstant()) { // We have a non-constant attribute definition, // so build an attribute entity. // AcDbAttribute *pAtt = new AcDbAttribute(); pAtt->setPropertiesFrom(pAttdef); pAtt->setInvisible(pAttdef->isInvisible()); // Translate the attribute by block reference. // To be really correct, the entire block // reference transform should be applied here. // basePoint = pAttdef->position(); basePoint += pBlkRef->position().asVector(); pAtt->setPosition(basePoint); pAtt->setHeight(pAttdef->height()); pAtt->setRotation(pAttdef->rotation()); pAtt->setTag("Tag"); pAtt->setFieldLength(25); char *pStr = pAttdef->tag(); pAtt->setTag(pStr); free(pStr); pAtt->setFieldLength(pAttdef->fieldLength()); // The database column value should be displayed. // INSERT prompts for this. // pAtt->setTextString("Assigned Attribute Value"); AcDbObjectId attId; pBlkRef->appendAttribute(attId, pAtt); pAtt->close(); } pEnt->close(); // use pEnt... pAttdef might be NULL } delete pIterator; pBlockDef->close(); pBlkRef->close(); }
void AcDbDoubleClickEditPline::startEdit(AcDbEntity *pEnt, AcGePoint3d clickpt) { // Implement the startEdit notification handler to catch when // a user double-clicks a 'POLYLINE' entity // Get the Current Document AcApDocument *pDoc=acDocManager->curDocument(); AcDbPolyline *pLine; // Cast the AcDbEntity pointer to AcDbPolyline if(pEnt->isKindOf(AcDbPolyline::desc()) == Adesk::kTrue) pLine=AcDbPolyline::cast(pEnt); else { acutPrintf("Error: Invalid AcDbPolyline Object"); return; } acDocManager->lockDocument(pDoc,AcAp::kWrite); // Upgrade to write if(pLine->upgradeOpen()!=Acad::eOk) { acutPrintf("Error: Could Not open AcDbPolyline Object"); return; } // iterate through all the vertices to find which // segment was clicked on, and place a vertex there. for(unsigned int c=0;c<pLine->numVerts()-1;c++) { AcGePoint3d pt1,pt2; pLine->getPointAt(c,pt1); pLine->getPointAt(c+1,pt2); AcGeVector3d lineVec(pt2-pt1),clickVec(clickpt-pt1), clickVec2(pt2-clickpt); double ang=lineVec.angleTo(clickVec); // This is the filter... // .05 (5% of lineVec length) is an arbitrary length... if((sin(ang)*clickVec.length()<.05*lineVec.length()) && clickVec.length()<lineVec.length() && clickVec2.length()<lineVec.length()) { // Add the point Here! ads_point outPt; acdbWcs2Ecs(asDblArray(clickpt),outPt,asDblArray(pLine->normal()),Adesk::kFalse); pLine->addVertexAt(c+1,asPnt2d(outPt)); break; } } pLine->close(); acDocManager->unlockDocument(pDoc); // invoking acedSSSetFirst(NULL,NULL) here will clear the // pickfirst selection, if desired (not With pline though). //acedSSSetFirst(NULL,NULL); // Update the graphics... pLine->draw(); actrTransactionManager->flushGraphics(); acedUpdateDisplay(); }
//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; }
//----------------------------------------------------------------------------- // 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); }