]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix the naming problems for the sketch edges
authormpv <mpv@opencascade.com>
Fri, 15 Dec 2017 06:37:21 +0000 (09:37 +0300)
committermpv <mpv@opencascade.com>
Fri, 15 Dec 2017 06:37:39 +0000 (09:37 +0300)
src/FeaturesPlugin/Test/TestBooleanFillWithPlane.py
src/Model/Model_AttributeSelection.cpp
src/Model/Model_ResultConstruction.cpp
src/Model/Model_SelectionNaming.cpp

index 61f040a44e54e7720bd5c5303cd9e68713ad240c..eeb22406402956a5b299d6f40175f0e17548a016 100644 (file)
@@ -52,8 +52,10 @@ SketchConstraintVertical_4 = Sketch_1.setVertical(SketchLine_8.result())
 model.do()
 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), 100, 0)
 Boolean_1 = model.addFill(Part_1_doc, [model.selection("SOLID", "Extrusion_1_1_2")], [model.selection("FACE", "PartSet/YOZ")])
-Group_1 = model.addGroup(Part_1_doc, [model.selection("FACE", "Boolean_1_1_4/Modified_Face_5"), model.selection("FACE", "Boolean_1_1_4/Modified_Face_2"), model.selection("FACE", "Boolean_1_1_4/Modified_Face_1"), model.selection("FACE", "Extrusion_1_1/Generated_Face_7"), model.selection("FACE", "Boolean_1_1_4/Modified_Face_4"), model.selection("FACE", "Boolean_1_1_4/Modified_Face_3"), model.selection("FACE", "Boolean_1_1_4/Modified_Face_5"), model.selection("FACE", "Extrusion_1_1/Generated_Face_10"), model.selection("FACE", "Extrusion_1_1/Generated_Face_9"), model.selection("FACE", "Boolean_1_1_3/Modified_Face_5"), model.selection("FACE", "Boolean_1_1_1/Modified_Face_1"), model.selection("FACE", "Extrusion_1_1/Generated_Face_7"), model.selection("FACE", "Boolean_1_1_1/Modified_Face_2"), model.selection("FACE", "Boolean_1_1_3/Modified_Face_4"), model.selection("FACE", "Extrusion_1_1/Generated_Face_11"), model.selection("FACE", "Boolean_1_1_4/Modified_Face_4"), model.selection("FACE", "Extrusion_1_1/Generated_Face_12"), model.selection("FACE", "Extrusion_1_1/Generated_Face_5"), model.selection("FACE", "Boolean_1_1_3/Modified_Face_5"), model.selection("FACE", "Boolean_1_1_3/Modified_Face_2"), model.selection("FACE", "Boolean_1_1_3/Modified_Face_3"), model.selection("FACE", "Boolean_1_1_4/Modified_Face_1"), model.selection("FACE", "Boolean_1_1_3/Modified_Face_4"), model.selection("FACE", "Extrusion_1_1/Generated_Face_4"), model.selection("FACE", "Extrusion_1_1/Generated_Face_4"), model.selection("FACE", "Extrusion_1_1/To_Face_3"), model.selection("FACE", "Extrusion_1_1/Generated_Face_3"), model.selection("FACE", "Extrusion_1_1/From_Face_3"), model.selection("FACE", "Extrusion_1_1/Generated_Face_1"), model.selection("FACE", "Extrusion_1_1/Generated_Face_2")])
 model.do()
+
+model.testHaveNamingSubshapes(Boolean_1, model, Part_1_doc)
+
 model.end()
 
 from GeomAPI import  GeomAPI_Shape
index 916e933280dfb49290fa517130868785f85f2863..3f4ee57be9dd039b918f6116e176463dd9b22564 100644 (file)
@@ -865,6 +865,19 @@ void Model_AttributeSelection::selectSubShape(
           }
         }
       }
+      // if compsolid is context, try to take sub-solid as context: like in GUI and scripts
+      if (aCont.get() && aShapeToBeSelected.get()) {
+        ResultCompSolidPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aCont);
+        if (aComp && aComp->numberOfSubs()) {
+          for(int aSubNum = aComp->numberOfSubs() - 1; aSubNum >= 0; aSubNum--) {
+            ResultPtr aSub = aComp->subResult(aSubNum);
+            if (aSub && aSub->shape().get() && aSub->shape()->isSubShape(aShapeToBeSelected)) {
+              aCont = aSub;
+              break;
+            }
+          }
+        }
+      }
       // try to find the latest active result that must be used instead of the selected
       // to set the active context (like in GUI selection), not concealed one
       bool aFindNewContext = true;
@@ -883,8 +896,9 @@ void Model_AttributeSelection::selectSubShape(
           // search the feature result that contains sub-shape selected
           std::list<std::shared_ptr<ModelAPI_Result> > aResults;
           ModelAPI_Tools::allResults(aRefFeat, aResults);
-          std::list<std::shared_ptr<ModelAPI_Result> >::iterator aResIter = aResults.begin();
-          for(; aResIter != aResults.end(); aResIter++) {
+          std::list<std::shared_ptr<ModelAPI_Result> >::reverse_iterator aResIter =
+            aResults.rbegin(); // iterate from the end to find the sub-solid first than compsolid
+          for(; aResIter != aResults.rend(); aResIter++) {
             if (!aResIter->get() || !(*aResIter)->data()->isValid() || (*aResIter)->isDisabled())
               continue;
             GeomShapePtr aShape = (*aResIter)->shape();
index 4962932bfe818400699161dfd0739184f385f08c..127507249a61b7fa02d5fbc3cd17719f253643b1 100644 (file)
@@ -267,9 +267,36 @@ std::string fullName(CompositeFeaturePtr theComposite, const TopoDS_Shape& theSu
 }
 
 // stores shape and name on sub-label of the main stored shape
-static void saveSubName(TDF_Label& theLab, const bool isSelectionMode, const TopoDS_Shape& aSub,
+static void saveSubName(CompositeFeaturePtr theComposite,
+  TDF_Label& theLab, const bool isSelectionMode, TopoDS_Shape aSub,
   std::shared_ptr<Model_Document> theDoc, std::string theFullName)
 {
+  // trying to store the edge of composite result, not sketch sub as it is
+  if (aSub.ShapeType() == TopAbs_EDGE) {
+    ResultPtr aRes = theComposite->firstResult();
+    ResultConstructionPtr aConstr = std::dynamic_pointer_cast<Model_ResultConstruction>(aRes);
+    if (aConstr.get()) {
+      Standard_Real aSubFirst, aSubLast;
+      TopoDS_Edge aSubEdge = TopoDS::Edge(aSub);
+      Handle(Geom_Curve) aSubCurve = BRep_Tool::Curve(aSubEdge, aSubFirst, aSubLast);
+      for(int aFaceIndex = 0; aFaceIndex < aConstr->facesNum(); aFaceIndex++) {
+        GeomShapePtr aGFace = aConstr->face(aFaceIndex);
+        TopoDS_Shape aFace = aGFace->impl<TopoDS_Shape>();
+        for(TopExp_Explorer anExp(aFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
+          TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
+          Standard_Real aFirst, aLast;
+          Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+          if (aCurve == aSubCurve &&
+              ((fabs(aFirst - aSubFirst) < 1.e-9 &&  fabs(aLast - aSubLast) < 1.e-9)) ||
+              (fabs(aFirst - aSubLast) < 1.e-9 &&  fabs(aLast - aSubFirst) < 1.e-9)) {
+            aSub = anEdge;
+            break;
+          }
+        }
+      }
+    }
+  }
+
   TNaming_Builder aBuilder(theLab);
   if (isSelectionMode)
     aBuilder.Select(aSub, aSub);
@@ -447,7 +474,8 @@ int Model_ResultConstruction::select(const std::shared_ptr<GeomAPI_Shape>& theSu
                     TDF_Label aSubLab = aLab.FindChild(anID);
                     TDF_Label aShapeSubLab = aLab.FindChild(aSubLabId++);
                     std::string aFullNameSub = fullName(aComposite, anEdge);
-                    saveSubName(aShapeSubLab, isSelectionMode, anEdge, aMyDoc, aFullNameSub);
+                    saveSubName(aComposite,
+                      aShapeSubLab, isSelectionMode, anEdge, aMyDoc, aFullNameSub);
 
                     int anOrient = Model_SelectionNaming::edgeOrientation(aSubShape, anEdge);
                     if (anOrient != 0) {
@@ -463,7 +491,8 @@ int Model_ResultConstruction::select(const std::shared_ptr<GeomAPI_Shape>& theSu
                     TopoDS_Vertex aV = TopoDS::Vertex(anEdgeExp.Current());
                     TDF_Label aShapeSubLab = aLab.FindChild(aSubLabId++);
                     std::string aFullNameSub = fullName(aComposite, aV);
-                    saveSubName(aShapeSubLab, isSelectionMode, aV, aMyDoc, aFullNameSub);
+                    saveSubName(aComposite,
+                      aShapeSubLab, isSelectionMode, aV, aMyDoc, aFullNameSub);
                 }
               }
             }
index 7d4c36cc0f5c78528c88944066bf402977eeddb5..8c794c3dcde8d39521997822d8df98a6ba0d8904 100644 (file)
@@ -885,7 +885,16 @@ bool Model_SelectionNaming::selectSubShape(const std::string& theType,
             aFaceContext = aDoc->findByName(aContName, *it, anUniqueContext);
           }
         }
-        const TopoDS_Shape aFace = findFaceByName(*it, aDoc, aFaceContext, anUniqueContext);
+        TopoDS_Shape aFace = findFaceByName(*it, aDoc, aFaceContext, anUniqueContext);
+        if (aFace.IsNull() && aFaceContext.get() &&
+            aFaceContext->groupName() == ModelAPI_ResultConstruction::group() ) {
+          // search the construction sub-elements for the intersection if they are in the tree
+          size_t aSlash = it->find("/");
+          if (aSlash != std::string::npos) {
+            std::string aSubShapeName = it->substr(aSlash + 1);
+            aFace = findFaceByName(aSubShapeName, aDoc, aFaceContext, true);
+          }
+        }
         if(!aFace.IsNull())
           aList.Append(aFace);
       }
@@ -894,7 +903,7 @@ bool Model_SelectionNaming::selectSubShape(const std::string& theType,
   }
   // in case of construction, there is no registered names for all sub-elements,
   // even for the main element; so, trying to find them by name (without "&" intersections)
-  if (aN < 2) {
+  if (aSelection.IsNull() && aN < 2) {
     size_t aConstrNamePos = aSubShapeName.find("/");
     bool isFullName = aConstrNamePos == std::string::npos;
     std::string anEmpty, aContrName = aContName;