void hilitPoly() { Adesk::Boolean interrupted = Adesk::kFalse; ads_printf("\nSelect a poly"); AsdkPoly *poly = NULL; AcDbEntity *ent = NULL; AcDbObjectId polyId; ads_name ename, sset; for (;;) { switch (ads_ssget(NULL, NULL, NULL, NULL, sset)) { case RTNORM: // Get the poly from the selection set and do some subentity // highlighting testing. // // This code assumes that the user selected only one item. { struct resbuf *rb; if (ads_ssnamex(&rb, sset, 0) != RTNORM) { ads_ssfree(sset); return; } int sel_method; ads_name subname; short marker; AcGePoint3d pickpnt; AcGeVector3d pickvec; if (!extractEntityInfo(rb, sel_method, ename, subname, marker, pickpnt, pickvec)) { ads_ssfree(sset); return; } AOK(acdbGetObjectId(polyId, ename)); AOK(acdbOpenAcDbEntity(ent, polyId, AcDb::kForRead)); assert(ent != NULL); poly = AsdkPoly::cast(ent); if (poly == NULL) { ads_printf("\nNot a polygon."); AOK(ent->close()); ads_ssfree(sset); continue; } // Get the subentity and highlight it. int numPaths; AcDbFullSubentPath* subentPaths; AcGeMatrix3d xform; poly->getSubentPathsAtGsMarker( AcDb::kEdgeSubentType, marker, pickpnt, xform, numPaths, subentPaths); if(numPaths == 1) { // Highlight and unhighlight the subentity. // ads_printf("\nHighlighting the subentity"); poly->highlight(subentPaths[0]); pressEnterToContinue(); poly->unhighlight(subentPaths[0]); } else { // No path, user selected a section without a marker, // the text label for example // ads_printf("\nNo subentity to highlight"); } // Highlight and unhighlight the whole entity. // ads_printf("\nHighlighting the whole entity"); poly->highlight(); pressEnterToContinue(); poly->unhighlight(); delete []subentPaths; ads_ssfree(sset); } break; case RTNONE: case RTCAN: return; default: continue; } ads_ssfree(sset); break; } AOK(ent->close()); return; }
void hilitSolid() { Adesk::Boolean interrupted = Adesk::kFalse; ads_printf("\nSelect a solid"); Acad::ErrorStatus es = Acad::eOk; AcDb3dSolid *solid = NULL; AcDbEntity *ent = NULL; AcDbObjectId solidId; ads_name ename, sset; for (;;) { switch (ads_ssget(NULL, NULL, NULL, NULL, sset)) { case RTNORM: { struct resbuf *rb; if (ads_ssnamex(&rb, sset, 0) != RTNORM) { ads_ssfree(sset); return; } int sel_method; ads_name subname; short marker; AcGePoint3d pickpnt; AcGeVector3d pickvec; if (!extractEntityInfo(rb, sel_method, ename, subname, marker, pickpnt, pickvec)) { ads_ssfree(sset); return; } AOK(acdbGetObjectId(solidId, ename)); AOK(acdbOpenAcDbEntity(ent, solidId, AcDb::kForRead)); assert(ent != NULL); solid = AcDb3dSolid::cast(ent); if (solid == NULL) { ads_printf("\nNot a solid."); AOK(ent->close()); ads_ssfree(sset); continue; } int numPaths; AcDbFullSubentPath* subentPaths; AcGeMatrix3d xform; es = solid->getSubentPathsAtGsMarker( AcDb::kEdgeSubentType, marker, pickpnt, xform, numPaths, subentPaths); // For objects with no edges (such as a sphere) the code to // highlight an edge is meaningless and must be skipped. // if (numPaths > 0) { // Highlight and unhighlight the selected edge of the solid. // ads_printf("\nHighlighting the selected edge."); es = solid->highlight(subentPaths[0]); pressEnterToContinue(); es = solid->unhighlight(subentPaths[0]); } else ads_printf("\nNo edges to highlight."); delete []subentPaths; // Highlight and unhighlight the faces corresponding to the // first edge of the solid. // es = solid->getSubentPathsAtGsMarker( AcDb::kFaceSubentType, marker, pickpnt, xform, numPaths, subentPaths); for (int i = 0; i < numPaths; i++) { ads_printf("\nHighlighting face %d of %d", i + 1, numPaths); es = solid->highlight(subentPaths[i]); pressEnterToContinue(); es = solid->unhighlight(subentPaths[i]); } delete []subentPaths; ads_ssfree(sset); // Highlight the entire solid, then unhighlight it. // ads_printf("\nHighlighting the entire solid"); es = solid->highlight(); pressEnterToContinue(); es = solid->unhighlight(); } break; case RTNONE: case RTCAN: return; default: continue; } ads_ssfree(sset); break; } AOK(ent->close()); return; }
void hilitInsert() { Adesk::Boolean interrupted = Adesk::kFalse; ads_printf("\nSelect an insert"); Acad::ErrorStatus es = Acad::eOk; AcDbEntity *ent = NULL; AcDbEntity *ent2 = NULL; AcDbBlockReference *blRef = NULL; AcDbObjectId objectId, blRefId; ads_name ename, sset; for (;;) { switch (ads_ssget(NULL, NULL, NULL, NULL, sset)) { case RTNORM: { struct resbuf *rb; if (ads_ssnamex(&rb, sset, 0) != RTNORM) { ads_printf("\nads_ssnamex failed"); ads_ssfree(sset); return; } int sel_method; ads_name subname; short marker; AcGePoint3d pickpnt; AcGeVector3d pickvec; if (!extractEntityInfo(rb, sel_method, ename, subname, marker, pickpnt, pickvec)) { ads_printf("\nextractEntityInfo failed"); ads_ssfree(sset); return; } ads_ssfree(sset); assert(marker != 0); if (marker == 0) { ads_printf("\nmarker == 0"); return; } // Get the insert first. // AOK(acdbGetObjectId(blRefId, ename)); AOK(acdbOpenAcDbEntity(ent, blRefId, AcDb::kForRead)); assert(ent != NULL); blRef = AcDbBlockReference::cast(ent); if (blRef == NULL) { ads_printf("\nNot an insert."); AOK(ent->close()); continue; } struct resbuf *insStack; ads_point pickpoint; ads_matrix adsmat; pickpoint[0] = pickpnt[0]; pickpoint[1] = pickpnt[1]; pickpoint[2] = pickpnt[2]; // Now get details on the entity that was // selected. // if (ads_nentselp(NULL, ename, pickpoint, TRUE, adsmat, &insStack) != RTNORM) { ads_printf("\nFailure in ads_nentselp"); return; } assert(insStack != NULL); AOK(acdbGetObjectId(objectId, ename)); AOK(acdbOpenAcDbEntity(ent2, objectId, AcDb::kForRead)); assert(ent2 != NULL); // Make an array of AcDbObjectIds from the // insertStack. Don't use the "smart array" // AcDbObjectIdArray class, because the // getSubentPathsAtGsMarker() function expects argument // eight to be of type AcDbObjectId*. Just // make room for approximately 100 IDs in the array. // AcDbObjectId *idArray = new AcDbObjectId[100]; int count = 0; struct resbuf *rbIter = insStack; AcDbObjectId objId; acdbGetObjectId(objId, ename); idArray[count++] = objId; while (rbIter != NULL) { ename[0] = rbIter->resval.rlname[0]; ename[1] = rbIter->resval.rlname[1]; acdbGetObjectId(objId, ename); idArray[count++] = objId; rbIter = rbIter->rbnext; } count--; ads_relrb(insStack); // First, we'll highlight an edge. // int numPaths; AcDbFullSubentPath *subentPaths; AcGeMatrix3d xform; es = blRef->getSubentPathsAtGsMarker( AcDb::kEdgeSubentType, marker, pickpnt, xform, numPaths, subentPaths, count, idArray); assert(numPaths == 1); // Highlight and unhighlight the selected edge. // ads_printf("\nHighlighting the first edge."); es = blRef->highlight(subentPaths[0]); pressEnterToContinue(); es = blRef->unhighlight(subentPaths[0]); // If this is a solid, it will have faces. // In this case, let's highlight them. // if(ent2->isKindOf(AcDb3dSolid::desc())) { es = blRef->getSubentPathsAtGsMarker( AcDb::kFaceSubentType, marker, pickpnt, xform, numPaths, subentPaths, count, idArray); assert(numPaths == 2); // Highlight and unhighlight the selected // faces. // ads_printf("\nHighlighting the first" " face."); es = blRef->highlight(subentPaths[0]); pressEnterToContinue(); es = blRef->unhighlight(subentPaths[0]); ads_printf("\nHighlighting the next face."); es = blRef->highlight(subentPaths[1]); pressEnterToContinue(); es = blRef->unhighlight(subentPaths[1]); } delete []subentPaths; // Now, let's highlight the whole entity. // ads_printf("\nHighlighting the entire entity"); AcDbFullSubentPath subPath; for (int i = count; i >= 0; i--) { subPath.objectIds().append(idArray[i]); } es = blRef->highlight(subPath); pressEnterToContinue(); es = blRef->unhighlight(subPath); // Finally, let's highlight each enclosing // insert. // for (i = count -1; i >= 0; i --) { subPath.objectIds().removeAt( subPath.objectIds().length() - 1); ads_printf("\nHighlighting insert layer %d", i + 1); blRef->highlight(subPath); pressEnterToContinue(); es = blRef->unhighlight(subPath); } } // case RTNORM break; case RTNONE: case RTCAN: return; default: continue; } // switch break; } //for (;;) AOK(ent->close()); AOK(ent2->close()); return; }
Adesk::Boolean AecUiPrSubentity::retrievePickDataAt(long index) { AecRmCString hardErrMsg(GetAecUiBaseAppName(), AECU_STR_RETRIEVEPICKDATAAT_AECUIPRSUBENTITY_ERROR_COULD_NOT, TRUE); //~ "\nERROR: could not retreive pick data!" resbuf* rb; ads_name selSet; m_ss.asAdsName(selSet); if (ads_ssnamex(&rb, selSet, index) != RTNORM) return Adesk::kFalse; // find out the objectId of the item picked AcDbObjectId mainId; ads_name ent; ads_ssname(selSet, index, ent); if (Aec::enameToObjId(ent, mainId) != Acad::eOk) { ads_printf(hardErrMsg); return Adesk::kFalse; } resbuf* tmp = rb; if ((tmp == NULL) || (tmp->restype != RTLB)) { // should start with this AEC_ASSERT(0); ads_relrb(rb); ads_printf(hardErrMsg); return Adesk::kFalse; } // second element is selection method, which should always be pickPt=1 tmp = tmp->rbnext; if ((tmp == NULL) || (tmp->restype != RTSHORT) || (tmp->resval.rint != 1)) { AEC_ASSERT(0); ads_relrb(rb); ads_printf(hardErrMsg); return Adesk::kFalse; } // third element is entity name of object selected tmp = tmp->rbnext; if ((tmp == NULL) || (tmp->restype != RTENAME)) { AEC_ASSERT(0); ads_relrb(rb); ads_printf(hardErrMsg); return Adesk::kFalse; } // fourth element is the gsMarker tmp = tmp->rbnext; if ((tmp == NULL) || (tmp->restype != RTSHORT)) { AEC_ASSERT(0); ads_relrb(rb); ads_printf(hardErrMsg); return Adesk::kFalse; } int gsMarker = tmp->resval.rint; // fifth element is start of list for pickPt tmp = tmp->rbnext; if ((tmp == NULL) || (tmp->restype != RTLB)) { AEC_ASSERT(0); ads_relrb(rb); ads_printf(hardErrMsg); return Adesk::kFalse; } // sixth element is point descriptor tmp = tmp->rbnext; if ((tmp == NULL) || (tmp->restype != RTSHORT)) { AEC_ASSERT(0); ads_relrb(rb); ads_printf(hardErrMsg); return Adesk::kFalse; } // seventh element is pick point tmp = tmp->rbnext; if ((tmp == NULL) || (tmp->restype != RT3DPOINT)) { AEC_ASSERT(0); ads_relrb(rb); ads_printf(hardErrMsg); return Adesk::kFalse; } AcGePoint3d pickPt(tmp->resval.rpoint[0], tmp->resval.rpoint[1], tmp->resval.rpoint[2]); // eigth element is either end of list or the direction vector tmp = tmp->rbnext; if (tmp == NULL) { AEC_ASSERT(0); ads_relrb(rb); ads_printf(hardErrMsg); return Adesk::kFalse; } AcGeVector3d pickVector; if (tmp->restype == RT3DPOINT) pickVector.set(tmp->resval.rpoint[0], tmp->resval.rpoint[1], tmp->resval.rpoint[2]); else pickVector.set(0.0, 0.0, 1.0); // WCS Z-axis ads_relrb(rb); // if this is the first time its picked, set mainId to this objectId. // All subsequent picks must match this id if (m_mainEnt == AcDbObjectId::kNull) { m_mainEnt = mainId; // add this to the "set" of objects selected (which in our case is 1 item) m_selSet.setLogicalLength(0); // reset array m_selSet.append(mainId); } else { // must be from same entity! if (m_mainEnt != mainId) { AecRmCString msg; msg.LoadString(GetAecUiBaseAppName(), AECU_STR_SUBENT_MUST_BE_FROM_MAINENT); ads_printf(msg); return Adesk::kFalse; } } // unhighlight any existing edges doUnHighlight(m_mainEnt); // if the same edge is picked twice, remove it out of the set int atIndex; if (m_gsMarkers.find(gsMarker, atIndex)) { m_gsMarkers.removeAt(atIndex); m_pickPts.removeAt(atIndex); m_pickVecs.removeAt(atIndex); DEBUG_ONLY(ads_printf(_DNT(_T("\nAecUiPrSubentity:: removed gsmarker: %d")), gsMarker)); } else { m_isValidssnamexData = Adesk::kTrue; // this isn't really accurate Nth time thru loop m_gsMarkers.append(gsMarker); m_pickPts.append(pickPt); m_pickVecs.append(pickVector); DEBUG_ONLY(ads_printf(_DNT(_T("\nAecUiPrSubentity:: added gsmarker: %d")), gsMarker)); } // re-highlight with new data doHighlight(m_mainEnt); return Adesk::kTrue; }