void aSquare() { AsdkSquare* mySquare = new AsdkSquare(); if( !mySquare ) { acutPrintf("\n Memory allocation error."); return; } ads_point pt1, pt2, pt3; struct resbuf UCS, WCS; WCS.restype = RTSHORT; WCS.resval.rint = 0; UCS.restype = RTSHORT; UCS.resval.rint = 1; acedGetPoint(NULL, "\nPick a point for the center: ", pt1); acedGetPoint(pt1, "\nPick a direction for corner and size: ", pt2); pt2[X] = pt2[X] - pt1[X]; pt2[Y] = pt2[Y] - pt1[Y]; pt2[Z] = pt2[Z] - pt1[Z]; pt3[X] = pt3[Y] = 0.0; pt3[Z] = 1.0; acedTrans(pt1, &UCS, &WCS, 0, pt1); acedTrans(pt2, &UCS, &WCS, 1, pt2); acedTrans(pt3, &UCS, &WCS, 1, pt3); mySquare->setSquareCenter(AcGePoint3d(pt1[X],pt1[Y],pt1[Z])); mySquare->setSquareOrient(AcGeVector3d(pt2[X],pt2[Y],pt2[Z])); mySquare->setSquareNormal(AcGeVector3d(pt3[X],pt3[Y],pt3[Z])); append(mySquare); mySquare->close(); return; }
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) ; }
bool CMakeBlkFile::GetBasePt() { int nRet = acedGetPoint(NULL, _T("\n请选择插入点"), asDblArray(m_insertPt)); if (nRet != RTNORM) { return false; } return true; }
// 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); }
void AsdkAcUiDialogSample::OnButtonPoint() { // Hide the dialog and give control to the editor BeginEditorCommand(); ads_point pt; // Get a point if (acedGetPoint(NULL, "\nPick a point: ", pt) == RTNORM) { // If the point is good, continue CompleteEditorCommand(); m_strXPt.Format("%g", pt[X]); m_strYPt.Format("%g", pt[Y]); m_strZPt.Format("%g", pt[Z]); DisplayPoint(); } else { // otherwise cancel the command (including the dialog) CancelEditorCommand(); } }
//----------------------------------------------------------------------------- //----- 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)) ; } }
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; }
// ----- 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(); }
// Invoked by the command - DRAGPOLY // void dragPolyCommand() { int nSides = 0; ads_point center, startPt, normal; if (acedGetPoint(NULL, "\nLocate center of polygon: ", center) != RTNORM) return; char nameBuf[133]; if (acedGetString(Adesk::kTrue, "\nEnter polygon name: ", nameBuf) != RTNORM) return; AcDbObjectId tsId = 0; char styleBuf[133], msg[133]; // Get default text style struct resbuf result ; if ( acedGetVar ("TEXTSTYLE", &result) != RTNORM ) { acutPrintf("\nError while reading default AutoCAD text style setting"); return ; } strcpy (styleBuf, result.resval.rstring) ; sprintf (msg, "\nEnter text style <%s>: ", result.resval.rstring) ; acdbFree (result.resval.rstring) ; if (acedGetString(Adesk::kTrue, msg, styleBuf) != RTNORM) return; if ( styleBuf[0] == '\0' ) { // Get default text style struct resbuf result ; if ( acedGetVar ("TEXTSTYLE", &result) != RTNORM ) { acutPrintf("\nError while reading default AutoCAD text style setting"); return ; } strcpy (styleBuf, result.resval.rstring) ; acdbFree (result.resval.rstring) ; } if ( rx_getTextStyleId(styleBuf, acdbHostApplicationServices()->workingDatabase(), tsId) != Acad::eOk) { acutPrintf("\nInvalid text style name"); return; } // Set the normal to the plane of the polygon to be the same as the // z direction of the current ucs, i.e. (0, 0, 1) since we also got the // center and start point in the current UCS. (acedGetPoint() returns in // the current UCS.) normal[X] = 0.0; normal[Y] = 0.0; normal[Z] = 1.0; acdbUcs2Wcs(normal, normal, Adesk::kTrue); acdbUcs2Ecs(center, center, normal, Adesk::kFalse); acdbUcs2Ecs(startPt, startPt, normal, Adesk::kFalse); double elev = center[2]; AcGePoint2d cen = asPnt2d(center), start = asPnt2d(startPt); AcGeVector3d norm = asVec3d(normal); AsdkPolyJig* pJig = new AsdkPolyJig(); pJig->acquire(cen, norm, nameBuf, tsId, elev); delete pJig; }
void CMyDlg::OnSeekPath() { // TODO: Add your control notification handler code here acDocManager->lockDocument(curDoc()); ads_point fromPnt, toPnt; CSearchGraph sGraph; ShowWindow(SW_HIDE); sGraph.Init(); bool flag1 = false; bool flag2 = false; if (m_lLineCnt > 0) { do { if (RTNORM == acedGetPoint(NULL, _T("选择一个点\n"), fromPnt)) { //选择的点必须是线段的起点或终点、或两线段的交点 for (vector<stPoint>::iterator it = sGraph.m_Points.begin(); it != sGraph.m_Points.end(); ++it) { if ((fromPnt[X] == (*it).pnt[X]) && (fromPnt[Y] == (*it).pnt[Y])) { flag1 = true; break; } } } if (!flag1) { acutPrintf("选择的点必须是线段的起点或终点、或两线段的交点\n"); } } while (!flag1); do { if (RTNORM == acedGetPoint(fromPnt, _T("选择第二个点\n"), toPnt)) { for (vector<stPoint>::iterator it = sGraph.m_Points.begin(); it != sGraph.m_Points.end(); ++it) { if ((toPnt[X] == (*it).pnt[X]) && (toPnt[Y] == (*it).pnt[Y])) { flag2 = true; break; } } } if (!flag1) { acutPrintf("选择的点必须是线段的起点或终点、或两线段的交点\n"); } } while (!flag2); } // SearchPath(); acDocManager->unlockDocument(curDoc()); }
//----------------------------------------------------------------------------- // 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; }
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 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; }
// 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 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" ); }
// 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(); }
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 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(); }