From b91d2ac3b9986005d94823a3c502c8a7ff5ec7db Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 18 Oct 2018 11:30:32 +0300 Subject: [PATCH] Debug and optimization of selection of elements of the sketch. --- src/Model/Model_AttributeSelection.cpp | 23 +++++++++++++++++++ src/Model/Model_ResultConstruction.cpp | 6 +++-- src/Model/Model_SelectionNaming.cpp | 2 ++ .../PartSet_OverconstraintListener.cpp | 3 ++- src/PartSet/PartSet_PreviewSketchPlane.cpp | 3 ++- src/PartSet/PartSet_ResultSketchPrs.cpp | 3 ++- src/PartSet/PartSet_SketcherMgr.cpp | 14 +++++++---- src/PartSet/PartSet_Tools.cpp | 3 ++- src/SketcherPrs/SketcherPrs_Coincident.cpp | 3 ++- src/XGUI/XGUI_Displayer.cpp | 5 ++-- 10 files changed, 51 insertions(+), 14 deletions(-) diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index 17120173b..148dbb9b6 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -1636,6 +1636,29 @@ bool Model_AttributeSelection::restoreContext(std::string theName, static const ResultPtr anEmpty; theValue = aDoc->findNamingName(aSubShapeName, anUniqueContext ? aCont : anEmpty); + // sketch sub-component shape and name is located in separated feature label, try the sub-name + if (theValue.IsNull() && aCont->groupName() == ModelAPI_ResultConstruction::group()) { + std::string::size_type aSlash = aSubShapeName.rfind('/'); + if (aSlash != std::string::npos) { + std::string aCompName = aSubShapeName.substr(aSlash + 1); + CompositeFeaturePtr aComposite = + std::dynamic_pointer_cast(aDoc->feature(aCont)); + if (aComposite.get() && aComposite->numberOfSubs()) { + const int aSubNum = aComposite->numberOfSubs(); + for (int a = 0; a < aSubNum; a++) { + FeaturePtr aSub = aComposite->subFeature(a); + const std::list >& aResults = aSub->results(); + std::list >::const_iterator aRes = aResults.cbegin(); + for (; aRes != aResults.cend(); aRes++) { + if ((*aRes)->data()->name() == aCompName) { + theValue = std::dynamic_pointer_cast((*aRes)->data())->shapeLab(); + } + } + } + } + } + } + /* to find the latest lower result that keeps given shape bool aFindNewContext = true; while(aFindNewContext && aCont.get()) { diff --git a/src/Model/Model_ResultConstruction.cpp b/src/Model/Model_ResultConstruction.cpp index 07fa23825..b60c6f012 100644 --- a/src/Model/Model_ResultConstruction.cpp +++ b/src/Model/Model_ResultConstruction.cpp @@ -192,9 +192,11 @@ void Model_ResultConstruction::storeShape(std::shared_ptr theShap { std::shared_ptr aData = std::dynamic_pointer_cast(data()); if (aData && aData->isValid()) { + std::string aMyName = data()->name(); TDF_Label& aShapeLab = aData->shapeLab(); if (!theShape.get() || theShape->isNull()) { aShapeLab.ForgetAllAttributes(); + TDataStd_Name::Set(aShapeLab, aMyName.c_str()); // restore name forgotten return; } std::shared_ptr aMyDoc = @@ -204,7 +206,6 @@ void Model_ResultConstruction::storeShape(std::shared_ptr theShap aShapeLab.ForgetAllAttributes(); // clear all previously stored TNaming_Builder aBuilder(aShapeLab); aBuilder.Generated(aShape); - std::string aMyName = data()->name(); TDataStd_Name::Set(aShapeLab, aMyName.c_str()); aMyDoc->addNamingName(aShapeLab, aMyName); } else if (aShape.ShapeType() == TopAbs_EDGE) { // store sub-vertices on sub-labels @@ -221,7 +222,6 @@ void Model_ResultConstruction::storeShape(std::shared_ptr theShap TDataStd_Name::Set(aSubLab, aVertexName.c_str()); aMyDoc->addNamingName(aSubLab, aVertexName); } - std::string aMyName = data()->name(); TDataStd_Name::Set(aShapeLab, aMyName.c_str()); aMyDoc->addNamingName(aShapeLab, aMyName); } else { // this is probably sketch, so, work with it as with composite @@ -327,8 +327,10 @@ void Model_ResultConstruction::storeShape(std::shared_ptr theShap } } aShapeLab.ForgetAllAttributes(); // clear all previously stored + TDataStd_Name::Set(aShapeLab, aMyName.c_str()); // restore name forgotten TNaming_Builder aBuilder(aShapeLab); // store the compound to get it ready on open of document aBuilder.Generated(aShape); + aMyDoc->addNamingName(aShapeLab, aMyName); // set new faces to the labels int aCurrentTag = 1; NCollection_List::Iterator anUnordered(anUnorderedFaces); diff --git a/src/Model/Model_SelectionNaming.cpp b/src/Model/Model_SelectionNaming.cpp index d16fdf724..78c167e9f 100644 --- a/src/Model/Model_SelectionNaming.cpp +++ b/src/Model/Model_SelectionNaming.cpp @@ -806,6 +806,8 @@ std::string Model_SelectionNaming::shortName( aName.erase(std::remove(aName.begin(), aName.end(), '-'), aName.end()); aName.erase(std::remove(aName.begin(), aName.end(), '/'), aName.end()); aName.erase(std::remove(aName.begin(), aName.end(), '&'), aName.end()); + if (aName.empty()) + return ""; // remove the last 's', 'e', 'f' and 'r' symbols: // they are used as markers of start/end/forward/rewersed indicators static const std::string aSyms("sefr"); diff --git a/src/PartSet/PartSet_OverconstraintListener.cpp b/src/PartSet/PartSet_OverconstraintListener.cpp index 640af398a..f532eab04 100755 --- a/src/PartSet/PartSet_OverconstraintListener.cpp +++ b/src/PartSet/PartSet_OverconstraintListener.cpp @@ -162,7 +162,8 @@ void PartSet_OverconstraintListener::processEvent( PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); CompositeFeaturePtr aSketch = aModule->sketchMgr()->activeSketch(); if (aSketch.get()) { - for (int i = 0; i < aSketch->numberOfSubs(); i++) { + int aNumberOfSubs = aSketch->numberOfSubs(); + for (int i = 0; i < aNumberOfSubs; i++) { FeaturePtr aFeature = aSketch->subFeature(i); aModifiedObjects.insert(aFeature); // is necessary to redisplay presentations std::list aResults = aFeature->results(); diff --git a/src/PartSet/PartSet_PreviewSketchPlane.cpp b/src/PartSet/PartSet_PreviewSketchPlane.cpp index 56f6c33f6..808de929f 100644 --- a/src/PartSet/PartSet_PreviewSketchPlane.cpp +++ b/src/PartSet/PartSet_PreviewSketchPlane.cpp @@ -143,7 +143,8 @@ bool PartSet_PreviewSketchPlane::getDefaultSizeOfView( return false; Bnd_Box aBox; - for (int aSubFeatureId = 0; aSubFeatureId < theSketch->numberOfSubs(); aSubFeatureId++) { + int aNumberOfSubs = theSketch->numberOfSubs(); + for (int aSubFeatureId = 0; aSubFeatureId < aNumberOfSubs; aSubFeatureId++) { FeaturePtr aFeature = theSketch->subFeature(aSubFeatureId); if (!aFeature.get()) continue; diff --git a/src/PartSet/PartSet_ResultSketchPrs.cpp b/src/PartSet/PartSet_ResultSketchPrs.cpp index b600306b9..c1f7bd1f0 100755 --- a/src/PartSet/PartSet_ResultSketchPrs.cpp +++ b/src/PartSet/PartSet_ResultSketchPrs.cpp @@ -285,7 +285,8 @@ void PartSet_ResultSketchPrs::fillShapes(TopoDS_Shape& theResultShape, CompositeFeaturePtr aSketchFeature = std::dynamic_pointer_cast (aResultFeature); std::list anAuxiliaryResults; - for (int i = 0; i < aSketchFeature->numberOfSubs(); i++) { + int aNumberOfSubs = aSketchFeature->numberOfSubs(); + for (int i = 0; i < aNumberOfSubs; i++) { FeaturePtr aFeature = aSketchFeature->subFeature(i); if (PartSet_Tools::isAuxiliarySketchEntity(aFeature)) { std::list aResults = aFeature->results(); diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index a67aa0f36..eadd126f0 100755 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -970,7 +970,8 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation) // Remove invalid sketch entities std::set anInvalidFeatures; ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators(); - for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) { + int aNumberOfSubs = myCurrentSketch->numberOfSubs(); + for (int i = 0; i < aNumberOfSubs; i++) { FeaturePtr aFeature = myCurrentSketch->subFeature(i); if (aFeature.get()) { if (!aFactory->validate(aFeature)) @@ -1011,7 +1012,8 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation) QStringList anInfo; Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY); const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); - for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) { + aNumberOfSubs = myCurrentSketch->numberOfSubs(); + for (int i = 0; i < aNumberOfSubs; i++) { FeaturePtr aFeature = myCurrentSketch->subFeature(i); #ifdef DEBUG_SKETCHER_ENTITIES anInfo.append(ModuleBase_Tools::objectInfo(aFeature)); @@ -1081,7 +1083,8 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) } else { // Hide all sketcher sub-Objects - for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) { + int aNumberOfSubs = myCurrentSketch->numberOfSubs(); + for (int i = 0; i < aNumberOfSubs; i++) { FeaturePtr aFeature = myCurrentSketch->subFeature(i); std::list aResults = aFeature->results(); std::list::const_iterator aIt; @@ -1479,7 +1482,7 @@ bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject); if (anObjectFeature.get()) { int aSize = myCurrentSketch->numberOfSubs(); - for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) { + for (int i = 0; i < aSize && !isFoundObject; i++) { FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i); isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature; } @@ -1900,7 +1903,8 @@ void PartSet_SketcherMgr::updateBySketchParameters( if (aPrevState != theState) { ModuleBase_IWorkshop* aWorkshop = myModule->workshop(); XGUI_ModuleConnector* aConnector = dynamic_cast(aWorkshop); - for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) { + int aNumberOfSubs = myCurrentSketch->numberOfSubs(); + for (int i = 0; i < aNumberOfSubs; i++) { FeaturePtr aSubFeature = myCurrentSketch->subFeature(i); bool aProcessed = false; bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, theType, aProcessed); diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 16a0d0faa..020c47a27 100755 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -664,7 +664,8 @@ void PartSet_Tools::sendSubFeaturesEvent(const CompositeFeaturePtr& theComposite return; static Events_Loop* aLoop = Events_Loop::loop(); - for (int i = 0; i < theComposite->numberOfSubs(); i++) { + int aNumberOfSubs = theComposite->numberOfSubs(); + for (int i = 0; i < aNumberOfSubs; i++) { FeaturePtr aSubFeature = theComposite->subFeature(i); static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); aECreator->sendUpdated(aSubFeature, theEventId); diff --git a/src/SketcherPrs/SketcherPrs_Coincident.cpp b/src/SketcherPrs/SketcherPrs_Coincident.cpp index acf5d24a7..c123960a5 100644 --- a/src/SketcherPrs/SketcherPrs_Coincident.cpp +++ b/src/SketcherPrs/SketcherPrs_Coincident.cpp @@ -124,7 +124,8 @@ void SketcherPrs_Coincident::Compute( std::shared_ptr aPnt = getCoincidencePoint(myConstraint); std::shared_ptr aP; FeaturePtr aSub; - for (int i = 0; i < mySketch->numberOfSubs(); i++) { + int aNumberOfSubs = mySketch->numberOfSubs(); + for (int i = 0; i < aNumberOfSubs; i++) { aSub = mySketch->subFeature(i); if (aSub->getKind() == SketchPlugin_ConstraintCoincidence::ID() && aSub.get() != myConstraint) { diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 7910ec06a..202afd6b2 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -454,8 +454,9 @@ bool XGUI_Displayer::isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& th if (!aVisible && aResult.get() && aResult->groupName() == ModelAPI_ResultBody::group()) { ResultBodyPtr aCompsolidResult = std::dynamic_pointer_cast(aResult); if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids - bool anAllSubsVisible = aCompsolidResult->numberOfSubs() > 0; - for(int i = 0; i < aCompsolidResult->numberOfSubs() && anAllSubsVisible; i++) { + int aNumberOfSubs = aCompsolidResult->numberOfSubs(); + bool anAllSubsVisible = aNumberOfSubs > 0; + for(int i = 0; i < aNumberOfSubs && anAllSubsVisible; i++) { anAllSubsVisible = theDisplayer->isVisible(aCompsolidResult->subResult(i)); } aVisible = anAllSubsVisible; -- 2.39.2