/* Extract entities out of a selection set and add them to the * appropriate list. */ int SampleEnts(ads_name selset, ExportMode expMode) { char layer[64], type[16]; long int num, numtot; ads_name ename; ADSResBuf *edata; DLL_LIST list; if (ads_sslength(selset, &numtot) != RTNORM) return 0; for (num = 0; num < numtot; num++) { if (num % 20 == 0) ads_printf("Sampling entities: %ld/%ld\r", num, numtot); if (ads_ssname(selset, num, ename) != RTNORM) return 0; if ((edata = ads_entget(ename)) == NULL) { WarnMsg("SampleEnts: can't get ent: %lx", ename); return 0; } if (strcmp(RBSearch(edata, 0)->resval.rstring, "INSERT") == 0) { if ((list = DllNewList(entListsSetup)) == NULL) { WarnMsg("SampleEnts: can't make block entity list"); return 0; } (void)DllPushF(list, NewADSName(ename), NULL); AddToBlockList(list); ads_relrb(edata); continue; } if (!IsValidEntType(GetEntType(edata, type))) { ads_relrb(edata); continue; } if ((list = DllNewList(entListsSetup)) == NULL) { WarnMsg("SampleEnts: can't make entity list"); ads_relrb(edata); return 0; } (void)DllPushF(list, NewADSName(ename), NULL); switch (expMode) { case EXP_BYCOLOR: if (!AddEntToColorLists(list, GetColorVal(edata, NULL, 0))) return 0; break; case EXP_BYLAYER: if (!GetLayerVal(layer, edata, list, 0)) return 0; if (!AddEntToLayerLists(list, layer)) return 0; break; default: ads_fail("SampleEnts: unknown export mode."); } ads_relrb(edata); } ads_printf("Sampling entities: %ld/%ld\n", num, numtot); return RTNORM; }
/* Get the entities out of a block and add them to the appropriate * lists: if a block, back to blockList - if an entity onto the * the entity list according to samplemode. */ static int SampleBlock(DLL_LIST blist) { ADSResBuf *ri, *rb1, *rb2, *edata; char layer[64], type[16]; ads_name ename; ads_namep blent; DLL_LIST newList = NULL; #ifdef DEBUG fprintf(stderr, "SampleBlock(%p)\n", blist); #endif blent = DllFirst(blist, NULL); rb1 = ads_entget(blent); rb2 = ads_tblsearch("BLOCK", RBSearch(rb1, 2)->resval.rstring, 1); ads_relrb(rb1); ads_name_set(RBSearch(rb2, -2)->resval.rlname, ename); ads_relrb(rb2); do { edata = ads_entget(ename); ri = RBSearch(edata, 0); if (strcmp(ri->resval.rstring, "INSERT") == 0) { if (!(newList = DllCopyList(blist, entListsSetup, CopyNameProc, NULL, NULL))) return 0; (void)DllPushF(newList, NewADSName(ename), NULL); AddToBlockList(newList); ads_relrb(edata); continue; } if (strcmp(ri->resval.rstring, "ENDBLK") == 0) { ads_relrb(edata); break; } if (!IsValidEntType(GetEntType(edata, type))) { ads_relrb(edata); continue; } if (!(newList = DllCopyList(blist, entListsSetup, CopyNameProc, NULL, NULL))) return 0; if (!DllPushF(newList, NewADSName(ename), NULL)) return 0; switch (options.exportMode) { case EXP_BYCOLOR: AddEntToColorLists(newList, GetColorVal(edata, newList, 0)); break; case EXP_BYLAYER: GetLayerVal(layer, edata, newList, 0); AddEntToLayerLists(newList, layer); break; default: ads_fail("SampleBlock: bad export mode\n"); } ads_relrb(edata); if (ads_usrbrk()) return 0; } while (ads_entnext(ename, ename) == RTNORM); return 1; }
/* retreive displayed color */ int GetColorVal(ADSResBuf *data, DLL_LIST contblks, int level) { int color = 0; char layer[64]; ads_namep bname; ADSResBuf *l_rb = NULL, *c_rb = NULL; #ifdef DEBUG ads_printf(" GetColorVal(%p, %d) reached.\n", data, level); #endif /* bylayer: get color of entities layer. */ if ((RBGetInt(&color, data, 62) == NULL) || (color == BYLAYER)) { if (!GetLayerVal(layer, data, contblks, ++level)) { WarnMsg("GetColorVal: can't get layer"); return RTERROR; } if ((l_rb = ads_tblsearch("LAYER", layer, FALSE)) != NULL) { if (RBGetInt(&color, l_rb, 62) == NULL) color = WHITE; ads_relrb(l_rb); } else color = WHITE; } if (color == BYBLOCK) { /* byblock: get color of encapsulating block(s) */ if (contblks && (bname = DllRank(contblks, level, NULL))) { if ((c_rb = ads_entget(bname)) != NULL) { color = GetColorVal(c_rb, contblks, ++level); ads_relrb(c_rb); } else color = WHITE; } else color = WHITE; } #ifdef DEBUG ads_printf("GetColorVal = %d\n", color); #endif return color; } /* GetColorVal */
AecUiPrBase::Status AecUiPrEntitySet::go() { m_selSet.setLogicalLength(0); // reset to null set getLockedLayers(); getAllowableClassTypes(); if (verifyPickfirstSet(Adesk::kFalse)) return AecUiPrBase::kOk; resbuf* filter = buildSelSetFilter(); m_ss.setKeywordCallback(_DNT(_T("FIlter _ FIlter")), AecUiPrEntitySet::keywordCallback); m_currentPromptObj = this; // hack way to get back from keyword callback AecAcadSelSet::SelSetStatus stat; // if supplied prompt, pass it on to selection set AecRmCString promptStr(message()); if (promptStr.IsEmpty() == FALSE) { AecRmCString tmpPrompt; tmpPrompt.Format(_DNT(_T("\n%s: ")), static_cast<LPCTSTR>(promptStr)); stat = m_ss.userSelect(tmpPrompt, NULL, filter); } // no prompt supplied, use regular ssget prompts else { stat = m_ss.userSelect(filter); } m_currentPromptObj = NULL; if (filter) ads_relrb(filter); if (stat != AecAcadSelSet::kSelected) { if (stat == AecAcadSelSet::kNone) return AecUiPrBase::kNone; else return AecUiPrBase::kCancel; } m_ss.asArray(m_selSet); if (m_selSet.isEmpty()) { AEC_ASSERT(0); // should have return kNone already return AecUiPrBase::kNone; } else return AecUiPrBase::kOk; }
/* retrieve floating layer */ int GetLayerVal(char layer[], ADSResBuf *data, DLL_LIST contblks, int level) { ads_namep bname; ADSResBuf *c_rb = NULL; if (RBGetStr(layer, data, 8) == NULL) { WarnMsg("GetLayerVal: no layer found"); return 0; } if ((strcmp(layer, "0") == 0) && (contblks && (bname = DllRank(contblks, level, NULL)))) { c_rb = ads_entget(bname); GetLayerVal(layer, c_rb, contblks, ++level); /* next level */ ads_relrb(c_rb); } return RTNORM; }
int ads_perror() { struct resbuf *argl, errval; argl = ads_getargs(); if (ads_getfuncode() != 0) /* This is the ONLY function here */ return RSRSLT; if (ads_getvar("ERRNO", &errval) == RTERROR) return RSRSLT; if ((errval.resval.rint < 1) || (errval.resval.rint > ELEMENTS(errmsg) #ifdef MAX_OL_ERRNO || errval.resval.rint > MAX_OL_ERRNO #endif )) return RSRSLT; if (argl && argl->restype == RTSTR && strlen(argl->resval.rstring)) ads_printf("%s: ", argl->resval.rstring); ads_printf("%s\n", errmsg[errval.resval.rint - 1]); ads_relrb(argl); ads_retvoid(); return RSRSLT; }
void GetEntXForm(ADSResBuf *edata, Matrix4 mx) { double xscl = 1.0, yscl = 1.0, zscl = 1.0, rotang = 0.0; Vector3 zaxis, *zaxis_p = NULL; Point3 inpt, *inpt_p = NULL; Point3 bpt, *bpt_p = NULL; ADSResBuf *bdata, *rb; int isinsert = 0; rb = RBGetPoint3(&zaxis, edata, 210); if(rb != NULL && V3Normalize(&zaxis) != 0.0) zaxis_p = &zaxis; if (strcmp(RBSearch(edata, 0)->resval.rstring, "INSERT") == 0) { isinsert = 1; if(RBGetPoint3(&inpt, edata, 10) != NULL) inpt_p = &inpt; (void)RBGetDouble(&rotang, edata, 50); (void)RBGetDouble(&xscl, edata, 41); (void)RBGetDouble(&yscl, edata, 42); (void)RBGetDouble(&zscl, edata, 43); /* the block base point */ bdata = ads_tblsearch("BLOCK", RBSearch(edata, 2)->resval.rstring, 1); if(bdata) { rb = RBGetPoint3(&bpt, bdata, 10); if (rb != NULL) bpt_p = &bpt; ads_relrb(bdata); } } M4GetAcadXForm(mx, zaxis_p, isinsert, inpt_p, rotang, xscl, yscl, zscl, bpt_p); #ifdef DEBUG fprintf(stderr, "GetEntXForm: bpt: %f %f %f\n", bpt.x, bpt.y, bpt.z); M4Print(stderr, mx); fprintf(stderr, "GetEntXForm: inpt: %f %f %f\n", inpt.x, inpt.y, inpt.z); fprintf(stderr, "GetEntXForm: pt: %f %f %f\n", pt.x, pt.y, pt.z); #endif }
/* fill layer list with all visible layers (not frozen or off) */ void VisLayList () { DLL_LIST list; char *lay; ADSResBuf *rb; int i62, i70; for (rb = ads_tblnext("LAYER", TRUE); rb; rb = ads_tblnext("LAYER", FALSE)) { (void)RBGetInt(&i62, rb, 62); (void)RBGetInt(&i70, rb, 70); if ((0 < i62) && (0 == (1 & i70))) { lay = RBGetNewStr(rb, 2); if ((list = DllNewList(entListsSetup)) == NULL) { WarnMsg("VisLayList: Can't make entity list for layer %s", lay); free(lay); continue; } DllInsert(exportLayerLists, lay, list); } ads_relrb(rb); } }
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; }
AecUiPrBase::Status AecUiPrSubentity::go() { m_selSet.setLogicalLength(0); // reset to null set m_isValidssnamexData = Adesk::kFalse; getLockedLayers(); getAllowableClassTypes(); m_disallowPickfirstSet = Adesk::kTrue; // don't allow pickfirst set because we need the gsmarkers cleanPickfirstSet(); resbuf* filter = buildSelSetFilter(); m_ss.setKeywordCallback(_DNT(_T("FIlter _ FIlter")), AecUiPrEntitySetSingle::keywordCallback); m_currentPromptObj = this; // hack way to get back from keyword callback m_ss.setAllowSingleOnly(Adesk::kTrue, Adesk::kFalse); m_ss.setAllAtPickBox(Adesk::kTrue); // enable selection of more than 1. Filter will do the rest. If not, it will work // like normal anyway by taking the first one and they can turn on object cycling // if they want to be exact. AecRmCString promptStr(message()); AecAcadSelSet::SelSetStatus stat = AecAcadSelSet::kNone; int errNum = 0; while (1) { Aecu::setSysVar(AcadVar::adserr, 0); // reset fresh // if supplied prompt, pass it on to selection set if (promptStr.IsEmpty() == FALSE) { AecRmCString tmpPrompt; tmpPrompt.Format(_DNT(_T("\n%s: ")), static_cast<LPCTSTR>(promptStr)); stat = m_ss.userSelect(tmpPrompt, NULL, filter); } // no prompt supplied, use regular ssget prompts else { stat = m_ss.userSelect(filter); } // got some kind of response, if its a NULL response, only // allow it if allowNone flag is set or if they have already // picked some sub-entities if (stat == AecAcadSelSet::kNone) { if (Aecu::getSysVar(AcadVar::adserr, errNum) == Acad::eOk) { if (errNum != OL_ENTSELNULL) { // this means they missed hitting an entity Aec::ads_printf(GetAecUiBaseApp(), AECU_STR_NO_SELECTION); continue; } } if ((m_allowNone) || (m_mainEnt != AcDbObjectId::kNull)) { // if they have already picked one, final return value should // be selected, not NONE if (m_mainEnt != AcDbObjectId::kNull) stat = AecAcadSelSet::kSelected; break; } else continue; } else if (stat == AecAcadSelSet::kSelected) { if (retrievePickDataAt(0L)) { // bail early if we only allow a single edgeId if (m_allowMultipleSelect == Adesk::kFalse) break; } } else break; } doUnHighlight(m_mainEnt); // leave object unhighlighted when we leave the prompt m_currentPromptObj = NULL; if (filter) ads_relrb(filter); if (stat != AecAcadSelSet::kSelected) { if (stat == AecAcadSelSet::kNone) return AecUiPrBase::kNone; else return AecUiPrBase::kCancel; } if (m_selSet.isEmpty()) { AEC_ASSERT(0); // should have return kNone already return AecUiPrBase::kCancel; } else return AecUiPrBase::kOk; }
AecUiPrBase::Status AecUiPrEntitySetSingle::go() { m_selSet.setLogicalLength(0); // reset to null set getLockedLayers(); getAllowableClassTypes(); if (verifyPickfirstSet(Adesk::kTrue)) return AecUiPrBase::kOk; resbuf* filter = buildSelSetFilter(); m_ss.setKeywordCallback(_DNT(_T("FIlter _ FIlter")), AecUiPrEntitySetSingle::keywordCallback); m_currentPromptObj = this; // hack way to get back from keyword callback m_ss.setAllowSingleOnly(Adesk::kTrue, Adesk::kTrue); m_ss.setAllAtPickBox(Adesk::kTrue); // enable selection of more than 1. Filter will do the rest. If not, it will work // like normal anyway by taking the first one and they can turn on object cycling // if they want to be exact. AecRmCString promptStr(message()); AecAcadSelSet::SelSetStatus stat = AecAcadSelSet::kNone; while (1) { // if supplied prompt, pass it on to selection set if (promptStr.IsEmpty() == FALSE) { AecRmCString tmpPrompt; tmpPrompt.Format(_DNT(_T("\n%s: ")), static_cast<LPCTSTR>(promptStr)); stat = m_ss.userSelect(tmpPrompt, NULL, filter); } // no prompt supplied, use regular ssget prompts else { stat = m_ss.userSelect(filter); } if (stat == AecAcadSelSet::kNone) { if (m_allowNone) break; else continue; } else break; } m_currentPromptObj = NULL; if (filter) ads_relrb(filter); if (stat != AecAcadSelSet::kSelected) { if (stat == AecAcadSelSet::kNone) return AecUiPrBase::kNone; else return AecUiPrBase::kCancel; } m_ss.asArray(m_selSet); if (m_selSet.isEmpty()) { AEC_ASSERT(0); // should have return kNone already return AecUiPrBase::kCancel; } else return AecUiPrBase::kOk; }