]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix for the issue #2689 : Groups in error after loading a python script
authormpv <mpv@opencascade.com>
Mon, 29 Oct 2018 14:03:47 +0000 (17:03 +0300)
committermpv <mpv@opencascade.com>
Mon, 29 Oct 2018 14:04:07 +0000 (17:04 +0300)
src/FeaturesPlugin/CMakeLists.txt
src/FeaturesPlugin/Test/Test2689.py [new file with mode: 0644]
src/Model/Model_AttributeSelection.cpp
src/Selector/Selector_Selector.cpp

index 72fa774000c89cc3246d0406b438278f986b4bb7..858cfae26c8a40e912f7d0399afc0ed2877f0d55 100644 (file)
@@ -380,4 +380,5 @@ ADD_UNIT_TESTS(TestExtrusion.py
                Test2650.py
                Test2681.py
                Test2686.py
+               Test2689.py
 )
diff --git a/src/FeaturesPlugin/Test/Test2689.py b/src/FeaturesPlugin/Test/Test2689.py
new file mode 100644 (file)
index 0000000..76986e7
--- /dev/null
@@ -0,0 +1,100 @@
+## Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+##
+## This library is free software; you can redistribute it and/or
+## modify it under the terms of the GNU Lesser General Public
+## License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+##
+## This library is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public
+## License along with this library; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+## See http:##www.salome-platform.org/ or
+## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+##
+
+# -*- coding: utf-8 -*-
+
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+model.addParameter(partSet, "hh", "20")
+Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY"))
+SketchLine_1 = Sketch_1.addLine(-14.44396674123619, 36.663, -34.44396674123619, 36.663)
+SketchLine_2 = Sketch_1.addLine(-34.44396674123619, 36.663, -34.44396674123619, 14.29964516129033)
+SketchLine_3 = Sketch_1.addLine(-34.44396674123619, 14.29964516129033, -14.44396674123619, 14.29964516129033)
+SketchLine_4 = Sketch_1.addLine(-14.44396674123619, 14.29964516129033, -14.44396674123619, 36.663)
+SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
+SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
+SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
+SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
+SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
+SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
+SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result())
+SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result())
+SketchLine_5 = Sketch_1.addLine(34.94274193548387, 39.45841935483872, 18.60029032258063, 39.45841935483872)
+SketchLine_6 = Sketch_1.addLine(18.60029032258063, 39.45841935483872, 18.60029032258063, 13.00945161290323)
+SketchLine_7 = Sketch_1.addLine(18.60029032258063, 13.00945161290323, 34.94274193548387, 13.00945161290323)
+SketchLine_8 = Sketch_1.addLine(34.94274193548387, 13.00945161290323, 34.94274193548387, 39.45841935483872)
+SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_8.endPoint(), SketchLine_5.startPoint())
+SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
+SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_7.startPoint())
+SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint())
+SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_5.result())
+SketchConstraintVertical_3 = Sketch_1.setVertical(SketchLine_6.result())
+SketchConstraintHorizontal_4 = Sketch_1.setHorizontal(SketchLine_7.result())
+SketchConstraintVertical_4 = Sketch_1.setVertical(SketchLine_8.result())
+SketchLine_9 = Sketch_1.addLine(-7.633645161290328, -5.05325806451613, -33.00745161290323, -5.05325806451613)
+SketchLine_10 = Sketch_1.addLine(-33.00745161290323, -5.05325806451613, -33.00745161290323, -31.71725806451613)
+SketchLine_11 = Sketch_1.addLine(-33.00745161290323, -31.71725806451613, -7.633645161290328, -31.71725806451613)
+SketchLine_12 = Sketch_1.addLine(-7.633645161290328, -31.71725806451613, -7.633645161290328, -5.05325806451613)
+SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_12.endPoint(), SketchLine_9.startPoint())
+SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchLine_9.endPoint(), SketchLine_10.startPoint())
+SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchLine_10.endPoint(), SketchLine_11.startPoint())
+SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchLine_11.endPoint(), SketchLine_12.startPoint())
+SketchConstraintHorizontal_5 = Sketch_1.setHorizontal(SketchLine_9.result())
+SketchConstraintVertical_5 = Sketch_1.setVertical(SketchLine_10.result())
+SketchConstraintHorizontal_6 = Sketch_1.setHorizontal(SketchLine_11.result())
+SketchConstraintVertical_6 = Sketch_1.setVertical(SketchLine_12.result())
+SketchLine_13 = Sketch_1.addLine(36.44796774193549, -7.848677419354839, 19.46041935483872, -7.848677419354839)
+SketchLine_14 = Sketch_1.addLine(19.46041935483872, -7.848677419354839, 19.46041935483872, -34.29764516129033)
+SketchLine_15 = Sketch_1.addLine(19.46041935483872, -34.29764516129033, 36.44796774193549, -34.29764516129033)
+SketchLine_16 = Sketch_1.addLine(36.44796774193549, -34.29764516129033, 36.44796774193549, -7.848677419354839)
+SketchConstraintCoincidence_13 = Sketch_1.setCoincident(SketchLine_16.endPoint(), SketchLine_13.startPoint())
+SketchConstraintCoincidence_14 = Sketch_1.setCoincident(SketchLine_13.endPoint(), SketchLine_14.startPoint())
+SketchConstraintCoincidence_15 = Sketch_1.setCoincident(SketchLine_14.endPoint(), SketchLine_15.startPoint())
+SketchConstraintCoincidence_16 = Sketch_1.setCoincident(SketchLine_15.endPoint(), SketchLine_16.startPoint())
+SketchConstraintHorizontal_7 = Sketch_1.setHorizontal(SketchLine_13.result())
+SketchConstraintVertical_7 = Sketch_1.setVertical(SketchLine_14.result())
+SketchConstraintHorizontal_8 = Sketch_1.setHorizontal(SketchLine_15.result())
+SketchConstraintVertical_8 = Sketch_1.setVertical(SketchLine_16.result())
+SketchCircle_1 = Sketch_1.addCircle(-24.6211935483871, 23.331, 4.515677419354841)
+SketchCircle_2 = Sketch_1.addCircle(27.20158064516131, 20.96564516129033, 4.091267733479863)
+SketchCircle_3 = Sketch_1.addCircle(-16.23493548387097, -18.60029032258065, 7.50151366286372)
+SketchCircle_4 = Sketch_1.addCircle(27.84667741935485, -22.90093548387097, 5.414373911476542)
+SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), "hh")
+model.do()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+model.addParameter(Part_1_doc, "hh", "15")
+model.addParameter(Part_1_doc, "hh_1", "26")
+Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "PartSet/Sketch_1/Face-SketchLine_1r-SketchLine_2f-SketchLine_3f-SketchLine_4f-SketchCircle_1_2r")], model.selection(), "hh", 0)
+Extrusion_2_objects = [model.selection("WIRE", "PartSet/Sketch_1/Face-SketchLine_1r-SketchLine_2f-SketchLine_3f-SketchLine_4f-SketchCircle_1_2r_wire"), model.selection("FACE", "PartSet/Sketch_1/Face-SketchLine_5f-SketchLine_6f-SketchLine_7f-SketchLine_8f-SketchCircle_2_2r"), model.selection("FACE", "PartSet/Sketch_1/Face-SketchLine_13f-SketchLine_14f-SketchLine_15f-SketchLine_16f-SketchCircle_4_2r"), model.selection("FACE", "PartSet/Sketch_1/Face-SketchLine_9f-SketchLine_10f-SketchLine_11f-SketchLine_12f-SketchCircle_3_2r")]
+Extrusion_2 = model.addExtrusion(Part_1_doc, Extrusion_2_objects, model.selection(), 10, "hh_1")
+Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Extrusion_2_4"), model.selection("SOLID", "Extrusion_1_1")], model.selection("EDGE", "PartSet/OX"), 40)
+Fuse_1_objects_1 = [model.selection("SOLID", "Translation_1_2"), model.selection("SOLID", "Translation_1_1"), model.selection("SOLID", "Extrusion_2_1")]
+Fuse_1 = model.addFuse(Part_1_doc, Fuse_1_objects_1)
+Translation_2 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Extrusion_2_3")], model.selection("EDGE", "PartSet/OX"), 30)
+Common_1 = model.addCommon(Part_1_doc, [model.selection("SOLID", "Extrusion_2_2"), model.selection("SOLID", "Translation_2_1")])
+model.do()
+model.testHaveNamingSubshapes(Fuse_1, model, Part_1_doc)
+model.testHaveNamingSubshapes(Common_1, model, Part_1_doc)
+model.end()
+
+assert(model.checkPythonDump())
index c26ad0b702864765ad4bcc8e14e9980823c26bed..bc5d28d942d3ec62c7ffd3e7c87b4901eabdfebe 100644 (file)
@@ -92,6 +92,8 @@ Standard_GUID kELLIPSE_CENTER1("f70df04c-3168-4dc9-87a4-f1f840c1275d");
 Standard_GUID kELLIPSE_CENTER2("1395ae73-8e02-4cf8-b204-06ff35873a32");
 // reference to the external sketch face
 Standard_GUID kEXT_SKETCH_FACE("ba32aa31-bde7-422f-80b4-79c757c77b49");
+// reference to the external sketch wire
+Standard_GUID kEXT_SKETCH_WIRE("ba32aa31-bde7-422f-80b4-79c757c77b46");
 // reference to the external sketch edge
 Standard_GUID kEXT_SKETCH_EDGE("ba32aa31-bde7-422f-80b4-79c757c77b48");
 // reference to the external sketch vertex
@@ -143,6 +145,7 @@ bool Model_AttributeSelection::setValue(const ObjectPtr& theContext,
   aSelLab.ForgetAttribute(kELLIPSE_CENTER1);
   aSelLab.ForgetAttribute(kELLIPSE_CENTER2);
   aSelLab.ForgetAttribute(kEXT_SKETCH_FACE);
+  aSelLab.ForgetAttribute(kEXT_SKETCH_WIRE);
   aSelLab.ForgetAttribute(kEXT_SKETCH_EDGE);
   aSelLab.ForgetAttribute(kEXT_SKETCH_VERT);
 
@@ -390,6 +393,15 @@ std::shared_ptr<GeomAPI_Shape> Model_AttributeSelection::internalValue(CenterTyp
       if (aSelLab.FindAttribute(kEXT_SKETCH_FACE, anIndex)) {
         return aConstr->face(anIndex->Get());
       }
+      if (aSelLab.FindAttribute(kEXT_SKETCH_WIRE, anIndex)) {
+        GeomShapePtr aFace = aConstr->face(anIndex->Get());
+        if (aFace.get()) {
+          GeomAPI_ShapeExplorer aFaceExp(aFace, GeomAPI_Shape::WIRE);
+          if (aFaceExp.more()) {
+            return aFaceExp.current();
+          }
+        }
+      }
       if (aSelLab.FindAttribute(kEXT_SKETCH_EDGE, anIndex) ||
           aSelLab.FindAttribute(kEXT_SKETCH_VERT, anIndex)) {
         bool isVert = anIndex->ID() == kEXT_SKETCH_VERT; // vertex is selected
@@ -661,7 +673,8 @@ bool Model_AttributeSelection::update()
     if (!aConstructionContext->isInfinite()) {
       // external sketch face
       Handle(TDataStd_Integer) anIndex;
-      if (aSelLab.FindAttribute(kEXT_SKETCH_FACE, anIndex)) {
+      if (aSelLab.FindAttribute(kEXT_SKETCH_FACE, anIndex) ||
+          aSelLab.FindAttribute(kEXT_SKETCH_WIRE, anIndex)) {
         return setInvalidIfFalse(aSelLab, anIndex->Get() < aConstructionContext->facesNum());
       }
       if (aSelLab.FindAttribute(kEXT_SKETCH_EDGE, anIndex) ||
@@ -717,20 +730,35 @@ void Model_AttributeSelection::selectBody(
     TopoDS_Shape aNewSub = theSubShape->impl<TopoDS_Shape>();
     FeaturePtr aFeatureOwner = std::dynamic_pointer_cast<ModelAPI_Feature>(owner());
     if (aFeatureOwner->document() != theContext->document()) { // reference to the sketch face
-      if (theSubShape->shapeType() == GeomAPI_Shape::FACE) { // sketch face
+      if (theSubShape->shapeType() == GeomAPI_Shape::FACE ||
+          theSubShape->shapeType() == GeomAPI_Shape::WIRE) { // sketch face or sketch face wire
         ResultConstructionPtr aConstr =
           std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theContext);
         int aFaceIndex = -1, aFacesNum = aConstr->facesNum();
         for(int a = 0; a < aFacesNum; a++) {
-          if (aConstr->face(a)->isEqual(theSubShape)) {
+          bool isEqual = false;
+          GeomShapePtr aFace = aConstr->face(a);
+          if (!aFace.get() || aFace->isNull())
+            continue;
+          if (theSubShape->shapeType() == GeomAPI_Shape::FACE) {
+            isEqual = aFace->isEqual(theSubShape);
+          } else {
+            GeomAPI_ShapeExplorer anExp(aFace, GeomAPI_Shape::WIRE);
+            if (anExp.more())
+              isEqual = anExp.current()->isEqual(theSubShape);
+          }
+          if (isEqual) {
             aFaceIndex = a;
             break;
           }
         }
         if (aFaceIndex >= 0) {
-          TDataStd_Integer::Set(aSelLab, kEXT_SKETCH_FACE, aFaceIndex); // store index of the face
+          TDataStd_Integer::Set(aSelLab, theSubShape->shapeType() == GeomAPI_Shape::FACE ?
+            kEXT_SKETCH_FACE : kEXT_SKETCH_WIRE, aFaceIndex); // store index of the face
           return;
         }
+      } else if (theSubShape->shapeType() == GeomAPI_Shape::WIRE) {
+
       } else if (theSubShape->shapeType() == GeomAPI_Shape::EDGE ||// sketch result edge (full one)
                  theSubShape->shapeType() == GeomAPI_Shape::VERTEX) { // or start/end vertex
         bool isVertex = theSubShape->shapeType() == GeomAPI_Shape::VERTEX;
@@ -908,6 +936,7 @@ std::string Model_AttributeSelection::namingName(const std::string& theDefaultNa
       // external sketch face
       Handle(TDataStd_Integer) anIndex;
       if (aSelLab.FindAttribute(kEXT_SKETCH_FACE, anIndex) ||
+          aSelLab.FindAttribute(kEXT_SKETCH_WIRE, anIndex) ||
           aSelLab.FindAttribute(kEXT_SKETCH_EDGE, anIndex) ||
           aSelLab.FindAttribute(kEXT_SKETCH_VERT, anIndex)) {
         std::shared_ptr<Model_Document> anExtDoc =
@@ -1737,7 +1766,7 @@ ResultPtr Model_AttributeSelection::newestContext(
         }
       }
     }
-    if (theAnyValue) { // only for neighbours for now
+    if (theAnyValue) { // only for neighbors for now
       // try to find modification of sub-shapes: the best number of matches
       std::map<ResultPtr, int> aMatches; // result -> number of matches of shapes to find the best
       TDF_Label aResLab = std::dynamic_pointer_cast<Model_Data>(aResult->data())->shapeLab();
@@ -1828,7 +1857,7 @@ ResultPtr Model_AttributeSelection::newestContext(
           GeomShapePtr aShape = (*aResIter)->shape();
           if (aShape.get() && (theAnyValue || aShape->isSubShape(aSelectedShape, false))) {
             aResult = *aResIter; // found new context (produced from this) with same subshape
-            aFindNewContext = true; // continue searching futher
+            aFindNewContext = true; // continue searching further
             break;
           }
         }
index 704e200b05fdd224d1759c566f4638db21040ea4..a87af7fc86b2890029eba75d2f26ccbdd80819f5 100644 (file)
@@ -44,7 +44,7 @@
 
 #include <list>
 
-/// type of the selection, integerm keeps the Selector_Type value
+/// type of the selection, integer keeps the Selector_Type value
 static const Standard_GUID kSEL_TYPE("db174d59-c2e3-4a90-955e-55544df090d6");
 /// type of the shape, stored in case it is intersection or container
 static const Standard_GUID kSHAPE_TYPE("864b3267-cb9d-4107-bf58-c3ce1775b171");
@@ -482,12 +482,12 @@ bool Selector_Selector::select(const TopoDS_Shape theContext, const TopoDS_Shape
       myFinal = aModifList.First()->Label();
       TopoDS_ListOfShape aCommon;
       findModificationResult(aCommon);
-      // trying to search by neighbours
+      // trying to search by neighbors
       if (aCommon.Extent() > 1) { // more complicated selection
         if (!theUseNeighbors)
           return false;
 
-        // searching by neighbours
+        // searching by neighbors
         std::list<std::pair<TopoDS_Shape, int> > aNBs;//neighbor sub-shape -> level of neighborhood
         for(int aLevel = 1; true; aLevel++) {
           TopTools_MapOfShape aNewNB;
@@ -522,7 +522,7 @@ bool Selector_Selector::select(const TopoDS_Shape theContext, const TopoDS_Shape
             return true;
           }
         }
-        // filter by neighbours did not help
+        // filter by neighbors did not help
         if (aCommon.Extent() > 1) { // weak naming between the common results
           Selector_NExplode aNexp(aCommon);
           myWeakIndex = aNexp.index(theValue);
@@ -1058,7 +1058,7 @@ TDF_Label Selector_Selector::restoreByName(
         return TDF_Label(); // invalid parentheses
     }
     return aContext;
-  } else if (theName[0] == '(') { // filter by neighbours
+  } else if (theName[0] == '(') { // filter by neighbors
     myType = SELTYPE_FILTER_BY_NEIGHBOR;
     TDF_Label aContext;
     for(size_t aStart = 0; aStart != std::string::npos;
@@ -1077,7 +1077,7 @@ TDF_Label Selector_Selector::restoreByName(
         } else {
           aContext = aSubContext;
         }
-        if (!aContext.IsNull()) // for filters by neighbour the latest context shape is vital
+        if (!aContext.IsNull()) // for filters by neighbor the latest context shape is vital
           aContext = theNameGenerator->newestContext(aContext);
 
         // searching for the level index
@@ -1112,7 +1112,7 @@ TDF_Label Selector_Selector::restoreByName(
       theNameGenerator->restoreContext(aContextName, aContext, myFinal);
     }
     return aContext;
-  } else if (theName.find('&') == std::string::npos) { // wihtout '&' it can be only primitive
+  } else if (theName.find('&') == std::string::npos) { // without '&' it can be only primitive
     myType = SELTYPE_PRIMITIVE;
     TDF_Label aContext;
     if (theNameGenerator->restoreContext(theName, aContext, myFinal)) {