// Queries the user for Yes/No answer // static Adesk::Boolean getYorN(const TCHAR* pStr) { TCHAR yorn_str[132]; // specific prompt. // acutPrintf(_T("\n%s"), pStr); acedInitGet(0, _T("No Yes")); yorn_str[0] = _T('Y'); yorn_str[1] = _T('\0'); switch (acedGetString(Adesk::kFalse, _T(" -- No/<Yes>: "), yorn_str)) { case RTKWORD: acedGetInput(yorn_str); /* Deliberate fallthrough */ default: break; } return (!((yorn_str[0] == _T('N')) || (yorn_str[0] == _T('n')))); }
// Queries the user for Yes/No answer // static Adesk::Boolean getYorN(const char* pStr) { char yorn_str[132]; // specific prompt. // acutPrintf("\n%s", pStr); acedInitGet(0, "No Yes"); yorn_str[0] = 'Y'; yorn_str[1] = '\0'; switch (acedGetString(Adesk::kFalse, " -- No/<Yes>: ", yorn_str)) { case RTKWORD: acedGetInput(yorn_str); /* Deliberate fallthrough */ default: break; } return (!((yorn_str[0] == 'N') || (yorn_str[0] == 'n'))); }
//use this command to control whether this app gets loaded on startup or not. void cmdCommandCount() { char reply[50]; char prompt[255]; sprintf(prompt, "\nLoad CmdCount on start up? <%s>: ", getStartUpLoad() ? "Y" : "N"); //"Load command count on start up?" acedInitGet(0, "Yes No _ Yes No"); if ( acedGetKword(prompt, reply) == RTNORM ) setStartUpLoad(!strcmp(reply, "Yes")); }
void GetCoordInventory() { std::map<std::wstring, AcGePoint3d> m_3dPoints; u_int startIndex = 1; ads_real textHeightResult = 1; ads_real pointSizeResult = 0.25; ACHAR stringResult[2]; ACHAR prompt[100]; AcDbObjectId pObj; selectObject(pObj); if (pObj) { acedInitGet(RSG_NONULL | RSG_NOZERO | RSG_NONEG, NULL); acedGetReal(_T("\nIntroduceti inaltime text: "), &textHeightResult); acedGetReal(_T("\nIntroduceti dimensiunea punctului: "), &pointSizeResult); extractVertexCoords(pObj, m_3dPoints); if (m_3dPoints.size() > 0) { if (insertPoints(m_3dPoints, 32, pointSizeResult, textHeightResult)) { acedInitGet(RSG_NONULL, _T("Y N")); acedGetKword(_T("\nInseram tabel de coordonate? [Yes No]:"), stringResult); if (wcscmp(stringResult, _T("N"))) generateInventarTable(m_3dPoints,textHeightResult); //swprintf(prompt, _T("\nExportam fisier de coordonate? [Y/N]<stringResult=%s>: "), stringResult); acedInitGet(RSG_NONULL, _T("Y N")); acedGetKword(_T("\nExportam fisier de coordonate? [Yes No]: " ), stringResult); if (wcscmp(stringResult, _T("N"))) { struct resbuf* result = NULL; if (acedGetFileNavDialog(_T("Save coordonates file"), NULL, _T("csv;txt"), _T("Save Dialog"), 1, &result) != RTERROR) { ExportClass* csvExport = new ExportClass(result->resval.rstring); csvExport->exportInventarCSV(m_3dPoints, startIndex); //*****Release memory area*****/ acutRelRb(result); delete csvExport; } } } } } else { acutPrintf(_T("\nError nici un obiect selectat!")); } }
Acad::ErrorStatus getYOrN(char* promptStr, Adesk::Boolean defaultY, Adesk::Boolean& yes,Adesk::Boolean& interrupted) { char option[256]; yes = Adesk::kTrue; acedInitGet(0, "Yes No"); int as = acedGetKword(promptStr, option); switch (as) { case RTNORM: if (strcmp(option, "Yes") == 0) yes = Adesk::kTrue; else yes = Adesk::kFalse; break; case RTNONE: if (defaultY) yes = Adesk::kTrue; else yes = Adesk::kFalse; break; case RTCAN: interrupted = Adesk::kTrue; break; default: break; } return Acad::eOk; }
// // NAME: selectDocument // // REMARKS: Simple utility to have the user choose an open document to // perform some action on. // // // // RETURNS: // void static AcApDocument* selectDocument() { AcApDocument* documentArray[10]; AcApDocument* pDoc; AcApDocumentIterator* pDocIter; int nDocs = 0;; pDocIter = acDocManager->newAcApDocumentIterator(); for ( ; !pDocIter->done(); pDocIter->step(), nDocs++) { pDoc = pDocIter->document(); documentArray[nDocs] = pDoc; acutPrintf("%d. %s\n", nDocs + 1, pDoc->fileName()); } delete pDocIter; acedInitGet(RSG_NOZERO | RSG_NONEG, NULL); int iSelection; int inputStatus = acedGetInt("Which document should this command execute in: ", &iSelection); if (inputStatus == RTNORM && iSelection <= nDocs) { return documentArray[iSelection - 1]; } else { return NULL; } }
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; }
static AcDb::SubentType subtype() { // Query the subentity type AcDb::SubentType subType = AcDb::kNullSubentType; ACHAR opt[128]; while (Adesk::kTrue) { acutPrintf(ACRX_T("\nEnter Subent Type: ")); acedInitGet(NULL, ACRX_T("Edge Face Brep")); if (acedGetKword(ACRX_T("Edge/Face/<Brep>: "), opt) == RTCAN) { subType = AcDb::kNullSubentType; break; } // Map the user input to a valid subentity type if ((_tcscmp(opt, ACRX_T("Brep")) == 0) || (_tcscmp(opt, ACRX_T("")) == 0)) { subType = AcDb::kNullSubentType; break; } else if (_tcscmp(opt, ACRX_T("Face")) == 0) { subType = AcDb::kFaceSubentType; break; } else if (_tcscmp(opt, ACRX_T("Edge")) == 0) { subType = AcDb::kEdgeSubentType; break; } } return subType; }
// The selectObject() function prompts the user to select an // entity or enter an object's handle. It then proceeds to // open the object/entity and return a pointer to it. // AcDbObject* selectObject(AcDb::OpenMode openMode) { ads_name en; ads_point pt; char handleStr[132]; AcDbObjectId eId; Acad::ErrorStatus retStat; int ss; // Allow user to either pick an entity, // or type in the object handle. // acedInitGet(RSG_OTHER, "_Handle Handle"); ss = acedEntSel("\nSelect an Entity or enter" " 'H' to enter its handle: ", en, pt); switch (ss) { case RTNORM: // got it! break; case RTKWORD: if ((acedGetString(Adesk::kFalse, "Enter Valid Object Handle: ", handleStr) == RTNORM) && (acdbHandEnt(handleStr, en) == RTNORM)) { break; } // Fall-through intentional // default: acutPrintf("Nothing Selected, Return Code==%d\n", ss); return NULL; } // Now, exchange the ads_name for the object Id... // retStat = acdbGetObjectId(eId, en); if (retStat != Acad::eOk) { acutPrintf("\nacdbGetObjectId failed"); acutPrintf("\nen==(%lx,%lx), retStat==%d\n", en[0], en[1], eId); return NULL; } AcDbObject* pObj; if ((retStat = acdbOpenObject(pObj, eId, openMode)) != Acad::eOk) { acutPrintf("acdbOpenEntity failed: ename:" "(%lx,%lx), mode:%d retStat:%d", en[0], en[1], openMode, retStat); return NULL; } return pObj; }
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; } }
void trimSurface() { AcBr::ErrorStatus returnValue = AcBr::eOk; Acad::ErrorStatus acadReturnValue = eOk; // Get the subentity path for a face AcDbFullSubentPath subPath(kNullSubent); acadReturnValue = selectEntity(AcDb::kFaceSubentType, subPath); if (acadReturnValue != eOk) { acutPrintf(ACRX_T("\n Error in getPath: %d"), acadReturnValue); return; } // Make a face entity to access the surface AcBrFace faceEntity; returnValue = faceEntity.set(subPath); if (returnValue != AcBr::eOk) { acutPrintf(ACRX_T("\n Error in AcBrFace::set:")); errorReport(returnValue); return; } // Query the style for trimmed surface dump Adesk::Boolean trimmed = Adesk::kTrue; ACHAR opt[128]; while (Adesk::kTrue) { acutPrintf(ACRX_T("\nSelect Style for Trimmed Surface Dump: ")); acedInitGet(NULL, ACRX_T("Nurb Trimmed")); if (acedGetKword(ACRX_T("Nurb/<Trimmed>: "), opt) == RTCAN) return; // Map the user input to a valid dump style if ((_tcscmp(opt, ACRX_T("Trimmed")) == 0) || (_tcscmp(opt, ACRX_T("")) == 0)) { trimmed = Adesk::kTrue; break; } else if ((_tcscmp(opt, ACRX_T("Nurb")) == 0)) { trimmed = Adesk::kFalse; break; } } (trimmed) ? faceToTrimmedSurface(faceEntity) : faceToNurbSurface(faceEntity); return; }
// get yes or no choice from the user bool getYorN(char *msg) { int res, retcode; char kw[4]; acutPrintf("\n %s [Yes/No]", msg); do { acedInitGet(RSG_NONULL, "Yes No"); retcode = acedGetInt(NULL, &res); switch (retcode) { case RTKWORD: if(acedGetInput(kw) != RTNORM) { acutPrintf("\nError getting Yes/No choice"); return false; } if(strcmp(kw, "Yes") == 0) { return true; } else if(strcmp(kw, "No") == 0) { return false; } else { acutPrintf("\nKeyword Error!!"); return false; } break; default: acutPrintf("\n Enter <Yes/No> :"); break; } } while(retcode != RTKWORD); return true; }
AcBr::ErrorStatus brepDump(const AcBrBrep& brepEntity) { AcBr::ErrorStatus returnValue = AcBr::eOk; // Validate the brep vs. the brep "owner" AcBrBrep brepOwner; returnValue = brepEntity.getBrep(brepOwner); if (returnValue != AcBr::eOk) { acutPrintf("\n Error in AcBrBrep::getBrep:"); errorReport(returnValue); return returnValue; } if (!brepEntity.isEqualTo(&brepOwner)) { acutPrintf("\n Brep owner is out of sync with brep!"); return (AcBr::ErrorStatus)Acad::eAmbiguousOutput; } // Query traversal direction for brep dump Adesk::Boolean downwards = Adesk::kTrue; char opt[128]; while (Adesk::kTrue) { acutPrintf("\nSelect Traversal Direction for Brep Dump: "); acedInitGet(NULL, "Upwards Downwards"); if (acedGetKword("Upwards/<Downwards>: ", opt) == RTCAN) return returnValue; // Map the user input to a valid traversal direction if ((strcmp(opt, "Downwards") == 0) || (strcmp(opt, "") == 0)) { downwards = Adesk::kTrue; break; } else if ((strcmp(opt, "Upwards") == 0)) { downwards = Adesk::kFalse; break; } } // Switchable dump based on upwards vs. downwards traversal if (downwards) brepDumpDown(brepEntity); else brepDumpUp(brepEntity); return returnValue; }
ArxDbgUiPrBase::Status ArxDbgUiPrInt::go() { CString prompt; int initFlag; // set up prompt prompt.Format(_T("\n%s: "), message()); // set up init flag if (m_intType == kNoZero) initFlag = RSG_NONULL+RSG_NOZERO; else if (m_intType == kNoNeg) initFlag = RSG_NONULL+RSG_NONEG; else if (m_intType == kNoNegNoZero) initFlag = RSG_NONULL+RSG_NOZERO+RSG_NONEG; else if (m_intType == kNoNegNoZeroAllowNone) initFlag = RSG_NOZERO+ RSG_NONEG; else initFlag = RSG_NONULL; while (1) { acedInitGet(initFlag, keyWords()); int result = acedGetInt(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) { return ArxDbgUiPrBase::kNone; } 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 PDFConverter(BOOL bDwg) { // test(); resbuf* rb = getFileNameInput(); resbuf* pRb = rb; AcStringArray arrFileName; while (pRb) { arrFileName.append(pRb->resval.rstring); pRb = pRb->rbnext; } acutRelRb(rb); rb = NULL; int page = 0; if (arrFileName.length() == 1) { acedInitGet(4, NULL); // use resource for multi langeage. // modify by yhl, 2016/6/29. CString strPrompt; CAcModuleResourceOverride rs; strPrompt.LoadString(IDS_ASKFORPAGENUMBER); int rc = acedGetInt(strPrompt, &page); // int rc = acedGetInt(_T("\nPlease input the page number, 0 for all <1>: "), &page); if (RTNONE == rc) { page = 1; } else if (RTNORM != rc) { return; } } for (int i=0; i<arrFileName.length(); i++) { convertFile(arrFileName[i], page, bDwg); } }
static Adesk::Boolean localContext() { // Query local vs. database context for model Adesk::Boolean context = Adesk::kFalse; ACHAR opt[128]; while (Adesk::kTrue) { acutPrintf(ACRX_T("\nSelect Local Entity vs. Database Entity: ")); acedInitGet(NULL, ACRX_T("Local Database")); if (acedGetKword(ACRX_T("Local/<Database>: "), opt) == RTCAN) break; if ((_tcscmp(opt, ACRX_T("Database")) == 0) || (_tcscmp(opt, ACRX_T("")) == 0)) { context = Adesk::kFalse; break; } else if ((_tcscmp(opt, ACRX_T("Local")) == 0)) { context = Adesk::kTrue; break; } } return context; }
static AcBr::ValidationLevel validationLevel() { // Query validation level for model AcBr::ValidationLevel vlevel = AcBr::kFullValidation; ACHAR opt[128]; while (Adesk::kTrue) { acutPrintf(ACRX_T("\nSelect No Validation vs. Full Validation: ")); acedInitGet(NULL, ACRX_T("None Full")); if (acedGetKword(ACRX_T("None/<Full>: "), opt) == RTCAN) break; if ((_tcscmp(opt, ACRX_T("Full")) == 0) || (_tcscmp(opt, ACRX_T("")) == 0)) { vlevel = AcBr::kFullValidation; break; } else if ((_tcscmp(opt, ACRX_T("None")) == 0)) { vlevel = AcBr::kNoValidation; break; } } return vlevel; }
void commandStats() { char option_str[132]; // specific prompt. acedInitGet(0, "Cumulative Session"); option_str[0] = 'S'; option_str[1] = '\0'; switch (acedGetKword("\nCumulative/<Session>:", option_str)) { case RTKWORD: acedGetInput(option_str); /* Deliberate fallthrough */ default: break; } if (((option_str[0] == 'C') || (option_str[0] == 'c'))) { // record this command's duration now, so updateCumulativeStats will // wipe it out. How this didn't cause continual crashes before is // beyond me. WCA 7/15/98 After this call, the current doc command // stack should also be empty. recordCommandDuration(NULL); if (!updateCumulativeStats()) { acutPrintf("\nA Command or LISP expression is active"); acutPrintf(" in at least one document,"); acutPrintf("\nSession Statistics may not be printed or saved now.\n"); return; } acutPrintf("\n\nCumulative Command Usage Statistics"); printStats(cumulativeStats); acutPrintf("\nNOTE: Session Statistics have been recorded and reset.\n"); delete cumulativeStats; cumulativeStats = NULL; } else { acutPrintf("\n\nCurrent Session Command Usage Statistics"); printStats(sessionStats); } }
static Acad::ErrorStatus getEditOption(char* option, Adesk::Boolean& interrupted) { Acad::ErrorStatus es = Acad::eOk; int as = RTNORM; acedInitGet(0, "Grow Shrink More Less Thicken Flatten Name EXit X"); as = acedGetKword("\nEnter an option [Grow/Shrink/More/Less/Thicken/Flatten/Name/eXit]: ", option); switch (as) { case RTNORM: if (strcmp(option, "X") == 0) { strcpy(option, "EXit"); } break; default: interrupted = Adesk::kTrue; break; } return es; }
ArxDbgUiPrBase::Status ArxDbgUiPrKeyWordDef::go() { CString prompt; prompt.Format(_T("\n%s<%s>: "), message(), m_default); acedInitGet(0, keyWords()); const size_t kBufSize = 512; int result = acedGetKword(prompt, m_keyWordPicked.GetBuffer(kBufSize), kBufSize); m_keyWordPicked.ReleaseBuffer(); if (result == RTNORM) { return ArxDbgUiPrBase::kOk; } else if (result == RTNONE) { if (keyWordMatch() == Adesk::kTrue) return ArxDbgUiPrBase::kOk; else return ArxDbgUiPrBase::kCancel; } else return ArxDbgUiPrBase::kCancel; }
void meshModel() { AcBr::ErrorStatus returnValue = AcBr::eOk; // Query the mesh dump style Adesk::Boolean displayElements = Adesk::kTrue; ACHAR opt[128]; while (Adesk::kTrue) { acutPrintf(ACRX_T("\nSelect Style for Mesh Dump: ")); acedInitGet(NULL, ACRX_T("Coordinates Polylines")); if (acedGetKword(ACRX_T("Coordinates/<Polylines>: "), opt) == RTCAN) return; // Map the user input to a valid dump style if ((_tcscmp(opt, ACRX_T("Polylines")) == 0) || (_tcscmp(opt, ACRX_T("")) == 0)) { displayElements = Adesk::kTrue; break; } else if ((_tcscmp(opt, ACRX_T("Coordinates")) == 0)) { displayElements = Adesk::kFalse; break; } } // 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; } // Call the appropriate subentity mesh routine switch (subType) { case AcDb::kNullSubentType: // brep returnValue = brepMesh((const AcBrBrep&)(*pEnt), displayElements); if (returnValue != AcBr::eOk) { acutPrintf(ACRX_T("\n Error in brepMesh:")); errorReport(returnValue); } break; case AcDb::kFaceSubentType: // face returnValue = faceMesh((const AcBrFace&)(*pEnt), displayElements); if (returnValue != AcBr::eOk) { acutPrintf(ACRX_T("\n Error in faceMesh:")); errorReport(returnValue); } break; default: acutPrintf(ACRX_T("\n meshModel: unsupported subentity type: %d\n"), subType); break; } delete pEnt; return; }
Acad::ErrorStatus createEntity(AcDbEntity*& pEntity) { Acad::ErrorStatus acadReturnValue = Acad::eOk; // Make a blank solid pEntity = new AcDb3dSolid(); if (pEntity == NULL) { acutPrintf(ACRX_T("\n createEntity: unable to allocate memory\n")); acadReturnValue = Acad::eOutOfMemory; return acadReturnValue; } // Query the solid primitive type int entType = 0; ACHAR opt[128]; while (Adesk::kTrue) { acutPrintf(ACRX_T("\nEnter Solid Primitive Type: ")); acedInitGet(NULL, ACRX_T("Box Wedge Frustum Sphere Torus")); if (acedGetKword(ACRX_T("Box/Wedge/Frustum/Sphere/<Torus>: "), opt) == RTCAN) { entType = 0; break; } // Map the user input to a valid solid primitive type if ((_tcscmp(opt, ACRX_T("Torus")) == 0) || (_tcscmp(opt, ACRX_T("")) == 0)) { entType = 1; break; } else if (_tcscmp(opt, ACRX_T("Sphere")) == 0) { entType = 2; break; } else if (_tcscmp(opt, ACRX_T("Frustum")) == 0) { entType = 3; break; } else if (_tcscmp(opt, ACRX_T("Wedge")) == 0) { entType = 4; break; } else if (_tcscmp(opt, ACRX_T("Box")) == 0) { entType = 5; break; } } // Set the solid to the selected primitive type, created at the // origin using unit size. switch (entType) { case 0: case 1: ((AcDb3dSolid*)pEntity)->createTorus(1.0, 0.1); break; case 2: ((AcDb3dSolid*)pEntity)->createSphere(1.0); break; case 3: ((AcDb3dSolid*)pEntity)->createFrustum(1.0, 0.3, 0.2, 0.1); break; case 4: ((AcDb3dSolid*)pEntity)->createWedge(1.0, 0.9, 0.8); break; case 5: ((AcDb3dSolid*)pEntity)->createBox(1.0, 0.9, 0.8); break; default: acutPrintf(ACRX_T("\n createEntity: unsupported solid primitive type: %d\n"), entType); acadReturnValue = Acad::eWrongObjectType; return acadReturnValue; } return acadReturnValue; }
// input may either return RTNORM (from command line) or RTMODELESS (from OPM) // if it is RTMODELSS, the entity already has that value set. // if it not RTMODELSS, we process as before, setting the value on m_pPoly void CPolyCommand::getInput() { ads_point tmpc; char tmpBuf[133]; if (!m_pPolyCmd->GotNumSides()) { int nSides; acedInitGet(INP_NNEG, ""); if ((m_retval = acedGetInt("\nEnter number of sides: ", &nSides)) == RTNORM) { if (nSides < 3) { acutPrintf("\nNeed at least 3 sides."); return; } m_pPoly->put_NumSides(nSides); } } else if (!m_pPolyCmd->GotCenter()) { if ((m_retval = acedGetPoint(NULL, "\nLocate center of polygon: ", tmpc)) == RTNORM) { AcAxPoint2d pt2d(tmpc[0],tmpc[1]); m_pPoly->put_Center(*pt2d.asVariantPtr()); } } else if (!m_pPolyCmd->GotStartPoint()) { AcAxPoint2d pt2dCtr(0.0,0.0); VARIANT *pVar = pt2dCtr.asVariantPtr(); m_pPoly->get_Center(pVar); pt2dCtr = pVar; ads_point cp = { pt2dCtr.x, pt2dCtr.y }; if ((m_retval = acedGetPoint(cp, "\nLocate start point of polygon: ", tmpc)) == RTNORM) { AcAxPoint2d pt2d(tmpc[0],tmpc[1]); if (pt2dCtr == pt2d) { acutPrintf("\nPick a point different from the center."); return; } m_pPoly->put_StartPoint(*pt2d.asVariantPtr()); } } else if (!m_pPolyCmd->GotTextString()) { if ((m_retval = acedGetString(Adesk::kTrue, "\nEnter polygon name: ",tmpBuf)) == RTNORM) { m_pPoly->put_TextString(_bstr_t(tmpBuf)); } } else if (!m_pPolyCmd->GotTextStyleName()) { if ((m_retval = acedGetString(Adesk::kTrue, "\nEnter text style: ", tmpBuf)) == RTNORM) { AcDbObjectId tsId; if (tmpBuf[0] == '\0' ) { // Get default text style struct resbuf result ; if ( acedGetVar ("TEXTSTYLE", &result) != RTNORM ) { acutPrintf( "\nError while reading default AutoCAD text style setting"); fail(); return; } strcpy (tmpBuf, result.resval.rstring) ; acdbFree (result.resval.rstring) ; } if ( rx_getTextStyleId(tmpBuf, acdbHostApplicationServices()->workingDatabase(), tsId) != Acad::eOk) { acutPrintf("\nInvalid text style name"); fail(); return; } m_pPoly->put_TextStyleName(_bstr_t(tmpBuf)); } } else m_bDone = true; if (m_retval != RTNORM && m_retval != RTMODELESS) fail(); }
// 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); }
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; } }
//----------------------------------------------------------------------------- // 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 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; }