Salome HOME
Debug and optimization of selection of elements of the sketch.
authormpv <mpv@opencascade.com>
Thu, 18 Oct 2018 08:30:32 +0000 (11:30 +0300)
committermpv <mpv@opencascade.com>
Mon, 19 Nov 2018 08:45:52 +0000 (11:45 +0300)
src/Model/Model_AttributeSelection.cpp
src/Model/Model_ResultConstruction.cpp
src/Model/Model_SelectionNaming.cpp
src/PartSet/PartSet_OverconstraintListener.cpp
src/PartSet/PartSet_PreviewSketchPlane.cpp
src/PartSet/PartSet_ResultSketchPrs.cpp
src/PartSet/PartSet_SketcherMgr.cpp
src/PartSet/PartSet_Tools.cpp
src/SketcherPrs/SketcherPrs_Coincident.cpp
src/XGUI/XGUI_Displayer.cpp

index 17120173be44d4a53d24551876438d059fe27540..148dbb9b6e5e50af4ab54ee65e60f54fcbadf2d8 100644 (file)
@@ -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<ModelAPI_CompositeFeature>(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<std::shared_ptr<ModelAPI_Result> >& aResults = aSub->results();
+          std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRes = aResults.cbegin();
+          for (; aRes != aResults.cend(); aRes++) {
+            if ((*aRes)->data()->name() == aCompName) {
+              theValue = std::dynamic_pointer_cast<Model_Data>((*aRes)->data())->shapeLab();
+            }
+          }
+        }
+      }
+    }
+  }
+
   /* to find the latest lower result that keeps given shape
   bool aFindNewContext = true;
   while(aFindNewContext && aCont.get()) {
index 07fa238251502f6308d940b1e95480870936a680..b60c6f01263dd644228cf557111a6713a4661edf 100644 (file)
@@ -192,9 +192,11 @@ void Model_ResultConstruction::storeShape(std::shared_ptr<GeomAPI_Shape> theShap
 {
   std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(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<Model_Document> aMyDoc =
@@ -204,7 +206,6 @@ void Model_ResultConstruction::storeShape(std::shared_ptr<GeomAPI_Shape> 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<GeomAPI_Shape> 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<GeomAPI_Shape> 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<TopoDS_Face>::Iterator anUnordered(anUnorderedFaces);
index d16fdf724553e3cd0157c95e90d3605504695b9d..78c167e9f4628d7147a77ef3a4a16119f14a3d92 100644 (file)
@@ -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");
index 640af398ae868f252f563d34e61c89562c30fe6b..f532eab0472c5739e7dfb7e01a21017c2de37749 100755 (executable)
@@ -162,7 +162,8 @@ void PartSet_OverconstraintListener::processEvent(
       PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(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<ResultPtr> aResults = aFeature->results();
index 56f6c33f6c0f1a2281fde3e7e0922c997068b56b..808de929f96e6d9d29585f539fd17362759407aa 100644 (file)
@@ -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;
index b600306b92cf5f5ed26f09d9dacf6e0ac6473950..c1f7bd1f0f05d5108c585b6f3316e8096cc6bf22 100755 (executable)
@@ -285,7 +285,8 @@ void PartSet_ResultSketchPrs::fillShapes(TopoDS_Shape& theResultShape,
   CompositeFeaturePtr aSketchFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>
                                                                           (aResultFeature);
   std::list<ResultPtr> 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<ResultPtr> aResults = aFeature->results();
index a67aa0f36fc60f44ea18a9a3eb13156a6ea66440..eadd126f05ea7fdbc342f7a8cf2227c5c3868562 100755 (executable)
@@ -970,7 +970,8 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
   // Remove invalid sketch entities
   std::set<FeaturePtr> 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<ResultPtr> aResults = aFeature->results();
       std::list<ResultPtr>::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<XGUI_ModuleConnector*>(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);
index 16a0d0faaf09c0ab942858d44edc5a4b472be7ea..020c47a27c9ef3b1e01e5ec8f2f90ebc2bd45529 100755 (executable)
@@ -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);
index acf5d24a7d3a93df5e5b9582523b5c81c5b89178..c123960a59a9cc91c36655a5f4ef54ffb485fe61 100644 (file)
@@ -124,7 +124,8 @@ void SketcherPrs_Coincident::Compute(
     std::shared_ptr<GeomAPI_Pnt2d> aPnt = getCoincidencePoint(myConstraint);
     std::shared_ptr<GeomAPI_Pnt2d> 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) {
index 7910ec06a677458604f8f7decec0eb1604e80ffb..202afd6b2c7d6253e1a0075e0ec7f1825162bd37 100644 (file)
@@ -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<ModelAPI_ResultBody>(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;