void asdktest5 () { //----- Select the entities ads_name ss, en ; if ( acedSSGet (NULL, NULL, NULL, NULL, ss) != RTNORM ) return ; //----- Append entity IDs to the collector long n ; AcDbObjectId id ; AsdkHlrCollector collector ; acedSSLength (ss, &n) ; for ( int i =0 ; i < n ; i++ ) { acedSSName (ss, i, en) ; acdbGetObjectId (id, en) ; collector.addEntity (id) ; } acedSSFree (ss) ; //----- Display a dialog box to select HLR controls, the user wants to apply to the HLR engine AfxSetResourceHandle (_hdllInstance) ; CControlsDlg dlg ; dlg.mnControls =kProject | kEntity | kBlock | kHonorInternals ; if ( dlg.DoModal () != IDOK ) { AfxSetResourceHandle (acedGetAcadResourceInstance ()) ; return ; } AfxSetResourceHandle (acedGetAcadResourceInstance ()) ; int control =dlg.mnControls ; acutPrintf (ACRX_T("\nAbout to call hidden Line calculation")) ; acutPrintf (ACRX_T("\nCalling with %d Entities"), collector.getInputEntityIds ().logicalLength ()) ; acutPrintf (ACRX_T("\nkProject %s "), control & kProject ? ACRX_T("On") : ACRX_T("Off")) ; acutPrintf (ACRX_T("\nkShowAll %s "), control & kShowAll ? ACRX_T("On") : ACRX_T("Off")) ; acutPrintf (ACRX_T("\nkEntity %s "), control & kEntity ? ACRX_T("On") : ACRX_T("Off")) ; acutPrintf (ACRX_T("\nkBlock %s "), control & kBlock ? ACRX_T("On") : ACRX_T("Off")) ; acutPrintf (ACRX_T("\nkSubentity %s "), control & kSubentity ? ACRX_T("On") : ACRX_T("Off")) ; acutPrintf (ACRX_T("\nkHideTangents %s "), control & kHideTangents ? ACRX_T("On") : ACRX_T("Off")) ; acutPrintf (ACRX_T("\nkCleanup %s "), control & kCleanup ? ACRX_T("On") : ACRX_T("Off")) ; acutPrintf (ACRX_T("\nkIsolines %s "), control & kIsolines ? ACRX_T("On") : ACRX_T("Off")) ; acutPrintf (ACRX_T("\nkUnite %s "), control & kUnite ? ACRX_T("On") : ACRX_T("Off")) ; acutPrintf (ACRX_T("\nkReuse %s "), control & kReuse ? ACRX_T("On") : ACRX_T("Off")) ; acutPrintf (ACRX_T("\nkProgress %s "), control & kProgress ? ACRX_T("On") : ACRX_T("Off")) ; acutPrintf (ACRX_T("\nkHandlePoints %s "), control & kHandlePoints ? ACRX_T("On") : ACRX_T("Off")) ; acutPrintf (ACRX_T("\nkHonorInternals %s "), control & kHonorInternals ? ACRX_T("On") : ACRX_T("Off")) ; acutPrintf (ACRX_T("\nkMeshSilhouettes %s "), control & kMeshSilhouettes ? ACRX_T("On") : ACRX_T("Off")) ; //----- Ask for virtual viewport settings AcDbViewport *pVp =NULL ; if ( !pickViewport (pVp) ) return ; //----- Process hidden line removal AsdkHlrEngine hlr (pVp, control) ; hlr.run (collector) ; delete pVp ; //----- The following code will collect the color of the originator entity of an edge //----- and will assign it to the resulting entity. actrTransactionManager->startTransaction () ; int nOutput =collector.mOutputData.logicalLength () ; acutPrintf (ACRX_T("\nHlr returned %d curves"), nOutput) ; for ( int j =0 ; j < nOutput ; j++ ) { AsdkHlrData *pResult =collector.mOutputData [j] ; AcDbEntity *pResultEntity =pResult->getResultEntity () ; AcDbObjectId id ; if ( postToDatabase (NULL, pResultEntity, id) != Acad::eOk ) { acutPrintf (_T("Failed to add entity to current space.\n")) ; break ; } actrTransactionManager->getObject ((AcDbObject *&)pResultEntity, id, AcDb::kForWrite) ; AcDbObjectIdArray ids =pResult->getObjectIds () ; int last =ids.logicalLength () - 1 ; AcCmColor color ; AcDbObjectId layerId ; color.setColorIndex (0) ; while ( last >= 0 && color.colorIndex () == 0 ) { AcDbObjectId innerId =ids.at (last) ; AcDbObject *pObj ; actrTransactionManager->getObject (pObj, innerId, AcDb::kForRead) ; AcDbEntity *pEnt =AcDbEntity::cast (pObj) ; color =pEnt->color () ; layerId =pEnt->layerId () ; last-- ; } if ( layerId != AcDbObjectId::kNull ) { pResultEntity->setColor (color) ; pResultEntity->setLayer (layerId) ; } else { AcDbEntity *pEnt =pResult->getEntity () ; if ( pEnt != NULL ) { pResultEntity->setColor (pEnt->color ()) ; pResultEntity->setLayer (pEnt->layer ()) ; } } pResultEntity->close () ; } actrTransactionManager->endTransaction(); }
//When an new entity is added, set its draw order based on the draw order of other entities on the same layer. void adskMyDbReactor::objectAppended(const AcDbDatabase* db, const AcDbObject* pObj) { AcDbEntity * pEnt = AcDbEntity::cast(pObj); Acad::ErrorStatus es; if (pEnt != NULL) { AcDbBlockTable *pBT = NULL; AcDbBlockTableRecord *pBTR = NULL; //use transaction since the datbase is still open for write here. es=actrTransactionManager->enableGraphicsFlush(true); AcTransaction *pTrans = actrTransactionManager->startTransaction() ; if(!pTrans) { acutPrintf("\nCan't start transaction!"); return; } AcDbObject *pObj = NULL ; AcDbDatabase *pDb = NULL; AcDbObjectId modelSpaceId; pDb = AcDbDatabase::cast(db); //get AcDbBlockTable for read if(Acad::eOk != pDb->getBlockTable(pBT, AcDb::kForRead)) { acutPrintf("can't open block table for read"); actrTransactionManager->abortTransaction(); return; } //get the model space object id if(Acad::eOk != pBT->getAt( ACDB_MODEL_SPACE, modelSpaceId)) { acutPrintf("\ncan't get model space Id"); actrTransactionManager->abortTransaction(); pBT->close(); return; } pBT->close(); //get model space block record for write from transaction if (Acad::eOk != pTrans->getObject((AcDbObject*&)pBTR, modelSpaceId, AcDb::kForWrite)) { acutPrintf("\ncan't open model space block table record for write"); actrTransactionManager->abortTransaction(); return; } AcDbObjectIdArray eIds; //get AcDbSortEntsTable AcDbSortentsTable *pSortTab = NULL; if(Acad::eOk != pBTR->getSortentsTable(pSortTab, AcDb::kForWrite, false)) { acutPrintf("\ncan't get AcDbSortEntsTable for write"); actrTransactionManager->abortTransaction(); return; } //put objectIds of all the entities in an Id array.The order of objectIds in the array is the //same as their draworders from bottom to top.The newly created entity is always at the top and the last item //in the array if(Acad::eOk != pSortTab->getFullDrawOrder(eIds)) { acutPrintf("\ncan't get full draworder"); pSortTab->close(); actrTransactionManager->abortTransaction(); return; } AcDbEntity *pRefEnt = NULL; //iterate through the entities in the order of their draworders. If an entity on the same layer is found //insert the newly created entity before it. int i; for(i =0; i<eIds.length(); i++) { es = pTrans->getObject((AcDbObject*&)pRefEnt, eIds.at(i), AcDb::kForRead); if(pRefEnt->layerId() == pEnt->layerId()) break; } eIds.insertAt(i, pEnt->objectId()); //remove the newly created entity from the end of the array eIds.removeLast(); //reset draworder es = pSortTab->setRelativeDrawOrder(eIds); pSortTab->close(); es=actrTransactionManager->endTransaction(); actrTransactionManager->flushGraphics(); //set flag for regen gbDraworderChanged = true; } }
bool Additional_Class::Get_LayerLW( CString LayerName, double &Length, double &Width ) { AcDbLayerTable *pLayerTbl = NULL; acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLayerTbl,AcDb::kForRead); if (!pLayerTbl->has(LayerName)) { //acutPrintf("\n木有%s层!", LayerName); //SetError("THERE ISN`T"+LayerName+"LATYER!", "Get_LayerLW"); pLayerTbl->close(); return false; } AcDbObjectId layerId; pLayerTbl->getAt(LayerName, layerId); pLayerTbl->close(); AcDbBlockTable *pBlkTbl = NULL; ////获得当前数据库块表 acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl,AcDb::kForWrite); ////获得模型空间块表记录 AcDbBlockTableRecord *pBlkTblRcd = NULL; pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForRead); pBlkTbl->close(); ////创建块表记录遍历器 AcDbBlockTableRecordIterator *pltr; pBlkTblRcd->newIterator(pltr); AcDbEntity *pEnt; //AcDbEntityPointer pEnt_Ptr; ////AcDbObjectPointer<AcDbPolyline> pPolyLine_Ptr; AcDbPolyline *pPolyLine = NULL; AcDbObjectIdArray PolyLineID_List; for (pltr->start(); !pltr->done(); pltr->step()) { pltr->getEntity(pEnt, AcDb::kForRead); // //pEnt_Ptr.acquire(pEnt); if (pEnt->layerId()==layerId) { if (pEnt->isKindOf(AcDbPolyline::desc())) { pPolyLine = AcDbPolyline::cast(pEnt); if (pPolyLine != NULL) { if (PolyLineIfRectangle(pPolyLine)==true) { PolyLineID_List.append(pPolyLine->objectId()); } } } } } if (PolyLineID_List.length() >1) { acutPrintf(_T("Bom Error 1002\n"));// 有很多矩形 delete pltr; pEnt->close(); pPolyLine->close(); pBlkTblRcd->close(); return false; } ////pPolyLine.open(PolyLineID_List[0], AcDb::kForRead); acdbOpenAcDbEntity(pEnt,PolyLineID_List[0], AcDb::kForRead); //error! pPolyLine = AcDbPolyline::cast(pEnt); Get_RectangleLW(pPolyLine, Length, Width); pBlkTblRcd->close(); pPolyLine->close(); pEnt->close(); delete pltr; return true; }
bool Additional_Class::LaylerFilter( CString LaylerName, AcDbObjectIdArray &EntityID_Array, bool(*Filter)(AcDbEntity*, AcDbObjectId&) ) { AcDbLayerTable *pLayerTbl; acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl,AcDb::kForWrite); if (false == (pLayerTbl->has(LaylerName))) { //acutPrintf("\n木有%s层!", LaylerName); //SetError("THERE ISTN`T"+LaylerName+"LAYER!", "LaylerFilter"); pLayerTbl->close(); return false; } AcDbObjectId layerId; pLayerTbl->getAt(LaylerName,layerId); AcDbBlockTable *pBlkTbl; //获得当前数据库块表 acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl,AcDb::kForWrite); //获得模型空间块表记录 AcDbBlockTableRecord *pBlkTblRcd; pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForWrite); //创建块表记录遍历器 AcDbBlockTableRecordIterator *pltr; pBlkTblRcd->newIterator(pltr); AcDbEntity *pEnt; AcDbObjectId temp_layerId; AcDbObjectId entityID; //pBlkTblRcd->close(); //pBlkTbl->close(); //pLayerTbl->close(); for (pltr->start(); !pltr->done(); pltr->step()) { if(Acad::eOk ==pltr->getEntity(pEnt, AcDb::kForRead, false)) { //if (200>Check_Entity(pEnt)>=100) //{ temp_layerId = pEnt->layerId(); if (temp_layerId == layerId) // 在当前图层中 { entityID = pEnt->objectId(); if (Filter(pEnt, entityID) == true) // 符合过滤条件 { EntityID_Array.append(entityID); } } //} pEnt->close(); } } int Len = EntityID_Array.length(); if (Len == 0) { pBlkTbl->close(); pLayerTbl->close(); pBlkTblRcd->close(); return false; } pBlkTbl->close(); pLayerTbl->close(); pBlkTblRcd->close(); return true; }
Adesk::Boolean AecUiPrEntitySet::verifyPickfirstSet(Adesk::Boolean singleSelect) { if (m_disallowPickfirstSet) { cleanPickfirstSet(); return Adesk::kFalse; } // if the set is already selected, verify that it has // the right stuff in it. AecBaseEditorReactor* edReact = AecUiBaseServices::getEditorReactor(); if (edReact == NULL) { AEC_ASSERT(0); cleanPickfirstSet(); return Adesk::kFalse; } m_selSet.setLogicalLength(0); // reset to null set AcDbEntity* ent; Acad::ErrorStatus es; int filteredBecauseOfClass = 0; int filteredBecauseOfLockedLayer = 0; const AcDbObjectIdArray& pickSet = edReact->pickfirstSet(); int len = pickSet.length(); // if only allowing single select, bail if more than 1 item // in the pickfirst set. if (singleSelect && (len > 1)) { ads_printf(_DNT(_T("\n"))); // make sure we get to a new line AecRmCString tmpStr(GetAecUiBaseAppName(), AECU_STR_VERIFYPICKFIRSTSET_AECUIPRENTITYSET_TOO_MANY_OBJECTS, TRUE); ads_printf(tmpStr); //~ "Too many objects in the pickfirst set, please select again.\n" cleanPickfirstSet(); return Adesk::kFalse; } for (int i=0; i<len; i++) { es = acdbOpenAcDbEntity(ent, pickSet[i], AcDb::kForRead); if (es == Acad::eOk) { if (isCorrectClassType(ent->isA()) == Adesk::kFalse) { filteredBecauseOfClass++; ent->close(); continue; } if (m_filterLockedLayers && m_lockedLayerCache.contains(ent->layerId())) { filteredBecauseOfLockedLayer++; ent->close(); continue; } ent->close(); m_selSet.append(pickSet[i]); } else { Aec::ads_printf(GetAecUiBaseAppName(), AECU_STR_VERIFYPICKFIRSTSET_AECUIPRENTITYSET_COULD_NOT_OPEN_ENTITY_FOR_READ, Aec::rxErrorStr(es)); //~ "\nCould not open entity for read: %s" } } ads_printf(_DNT(_T("\n"))); // make sure we get to a new line if (filteredBecauseOfClass == 1) { AecRmCString tmpStr(GetAecUiBaseAppName(), AECU_STR_VERIFYPICKFIRSTSET_AECUIPRENTITYSET_OBJECT_WAS, TRUE); ads_printf(tmpStr); // NOTE: leave \n's at end so you can see message before dialog comes up (jma) //~ "1 object was of the wrong type.\n" } else if (filteredBecauseOfClass > 1) { Aec::ads_printf(GetAecUiBaseAppName(), AECU_STR_VERIFYPICKFIRSTSET_AECUIPRENTITYSET_OBJECTS_WERE_OF_THE_WRONG_TYPE, filteredBecauseOfClass); //~ "%ld objects were of the wrong type.\n" } if (filteredBecauseOfLockedLayer == 1) { AecRmCString tmpStr(GetAecUiBaseAppName(), AECU_STR_VERIFYPICKFIRSTSET_AECUIPRENTITYSET_OBJECT_WAS_0, TRUE); ads_printf(tmpStr); //~ "1 object was on a locked layer.\n" } else if (filteredBecauseOfLockedLayer > 1) { Aec::ads_printf(GetAecUiBaseAppName(), AECU_STR_VERIFYPICKFIRSTSET_AECUIPRENTITYSET_OBJECTS_WERE_ON_LOCKED_LAYER, filteredBecauseOfLockedLayer); //~"%ld objects were on a locked layer.\n" } if ((len > 0) && m_selSet.isEmpty()) { AecRmCString tmpStr(GetAecUiBaseAppName(), AECU_STR_VERIFYPICKFIRSTSET_AECUIPRENTITYSET_ALL_OBJECTS_IN, TRUE); ads_printf(tmpStr); //~ "All objects in the pickfirst set were filtered out, please select again.\n" } cleanPickfirstSet(); return !m_selSet.isEmpty(); }