From 06db9386492f6281c9f747c597ea68d591117a48 Mon Sep 17 00:00:00 2001 From: azv Date: Sun, 17 Dec 2017 18:11:23 +0300 Subject: [PATCH] Change algorithm of placing to data model's labels of shapes which have several parts after a modification --- src/Model/Model_BodyBuilder.cpp | 53 +++++++++++++++++++++------------ src/ModelAPI/Test/Test1757.py | 2 +- test.models/case24.py | 16 +++++----- test.models/clothespin.py | 4 +-- 4 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/Model/Model_BodyBuilder.cpp b/src/Model/Model_BodyBuilder.cpp index fb54d8f1a..d17fb8bd6 100755 --- a/src/Model/Model_BodyBuilder.cpp +++ b/src/Model/Model_BodyBuilder.cpp @@ -372,17 +372,14 @@ void Model_BodyBuilder::loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS, // Keep only the shapes with minimal shape type static void keepTopLevelShapes(ListOfShape& theShapes, const TopoDS_Shape& theRoot, - const GeomShapePtr& theResultShape) + const GeomShapePtr& theResultShape = GeomShapePtr()) { GeomAPI_Shape::ShapeType aKeepShapeType = GeomAPI_Shape::SHAPE; ListOfShape::iterator anIt = theShapes.begin(); while (anIt != theShapes.end()) { TopoDS_Shape aNewShape = (*anIt)->impl(); - GeomShapePtr aGeomNewShape(new GeomAPI_Shape()); - aGeomNewShape->setImpl(new TopoDS_Shape(aNewShape)); - if (theRoot.IsSame(aNewShape) || !theResultShape->isSubShape(aGeomNewShape, false) || - theResultShape->isSame(*anIt)) - { + if (theRoot.IsSame(aNewShape) || (theResultShape && + (!theResultShape->isSubShape(*anIt, false) || theResultShape->isSame(*anIt)))) { ListOfShape::iterator aRemoveIt = anIt++; theShapes.erase(aRemoveIt); } else { @@ -452,9 +449,29 @@ void Model_BodyBuilder::loadAndOrientModifiedShapes ( int aBuilderTag = aTag; if (!theIsStoreSeparate) aSameParentShapes++; + + static const int THE_ANCHOR_TAG = 100000; + int aCurShapeType = (int)((*anIt)->shapeType()); + bool needSuffix = false; // suffix for the name based on the shape type if (aSameParentShapes > 0) { // store in other label - aBuilderTag = 100000 - aSameParentShapes * 10 - aTag; + aBuilderTag = THE_ANCHOR_TAG - aSameParentShapes * 10 - aCurShapeType; + needSuffix = true; + } else if (aCurShapeType != theKindOfShape) { + // modified shape has different type => set another tag + // to avoid shapes of different types on the same label + aBuilderTag = THE_ANCHOR_TAG - aCurShapeType; + needSuffix = true; + } + std::string aSuffix; + if (needSuffix) { + switch (aCurShapeType) { + case GeomAPI_Shape::VERTEX: aSuffix = "_v"; break; + case GeomAPI_Shape::EDGE: aSuffix = "_e"; break; + case GeomAPI_Shape::FACE: aSuffix = "_f"; break; + default: break; + } } + if(theIsStoreAsGenerated) { // Here we store shapes as generated, to avoid problem when one parent shape produce // several child shapes. In this case naming could not determine which shape to select. @@ -463,21 +480,20 @@ void Model_BodyBuilder::loadAndOrientModifiedShapes ( builder(aBuilderTag)->Modify(aRoot, aNewShape); } if(isBuilt) { - if(theIsStoreSeparate) { - aStream.str(std::string()); - aStream.clear(); - aStream << theName << "_" << anIndex++; - aName = aStream.str(); - } + aStream.str(std::string()); + aStream.clear(); + aStream << theName; + if(theIsStoreSeparate) + aStream << "_" << anIndex++; + if (aSameParentShapes > 0) { aStream.str(std::string()); aStream.clear(); aStream << aName << "_" << aSameParentShapes << "divided"; - std::string aNameDiv = aStream.str(); - buildName(aBuilderTag, aNameDiv); - } else { - buildName(aBuilderTag, aName); } + + aStream << aSuffix; + buildName(aBuilderTag, aStream.str()); } if(theIsStoreSeparate) { aTag++; @@ -506,7 +522,6 @@ void Model_BodyBuilder::loadAndOrientGeneratedShapes ( TopTools_MapOfShape aView; bool isBuilt = !theName.empty(); TopExp_Explorer aShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape); - GeomShapePtr aResultShape = shape(); for (; aShapeExplorer.More(); aShapeExplorer.Next ()) { const TopoDS_Shape& aRoot = aShapeExplorer.Current (); if (!aView.Add(aRoot)) continue; @@ -516,7 +531,7 @@ void Model_BodyBuilder::loadAndOrientGeneratedShapes ( std::shared_ptr aRShape(new GeomAPI_Shape()); aRShape->setImpl((new TopoDS_Shape(aRoot))); theMS->generated(aRShape, aList); - keepTopLevelShapes(aList, aRoot, aResultShape); + keepTopLevelShapes(aList, aRoot); std::list >::const_iterator anIt = aList.begin(), aLast = aList.end(); for (; anIt != aLast; anIt++) { diff --git a/src/ModelAPI/Test/Test1757.py b/src/ModelAPI/Test/Test1757.py index af3b4a53e..8418bdc89 100644 --- a/src/ModelAPI/Test/Test1757.py +++ b/src/ModelAPI/Test/Test1757.py @@ -125,6 +125,6 @@ import ModelAPI assert(ModelAPI.ModelAPI_Session.get().validators().validate(Sketch_4.feature())) assert(ModelAPI.ModelAPI_Session.get().validators().validate(ExtrusionCut_2.feature())) -assert(Sketch_3.feature().selection("External").namingName() == "ExtrusionCut_3_1/Modfied_3") +assert(Sketch_3.feature().selection("External").namingName() == "ExtrusionCut_3_1/Modfied_5") assert(model.checkPythonDump()) diff --git a/test.models/case24.py b/test.models/case24.py index cefee7d8f..247658ae5 100644 --- a/test.models/case24.py +++ b/test.models/case24.py @@ -648,7 +648,7 @@ Sketch_10 = model.addSketch(Part_1_doc, model.selection("FACE", "PartSet/XOY")) SketchLine_77 = Sketch_10.addLine(64, 20, 89, 20) SketchLine_77.setName("SketchLine_76") SketchLine_77.result().setName("SketchLine_76") -SketchPoint_4 = Sketch_10.addPoint(model.selection("VERTEX", "RevolutionFuse_2_1/Modfied_9&RevolutionFuse_2_1/Modfied_12&RevolutionFuse_3_1/Modfied_12&RevolutionFuse_3_1/Modfied_1divided_1")) +SketchPoint_4 = Sketch_10.addPoint(model.selection("VERTEX", "RevolutionFuse_2_1/Modfied_9&RevolutionFuse_2_1/Modfied_12&RevolutionFuse_3_1/Modfied_12&RevolutionFuse_3_1/Modfied_1divided_f_1")) SketchConstraintCoincidence_122 = Sketch_10.setCoincident(SketchLine_77.startPoint(), SketchPoint_4.result()) SketchConstraintCoincidence_122.setName("SketchConstraintCoincidence_120") SketchPoint_5 = Sketch_10.addPoint(model.selection("VERTEX", "Sketch_1/Vertex-SketchLine_1s-SketchLine_8e-SketchLine_4e")) @@ -657,7 +657,7 @@ SketchConstraintCoincidence_123.setName("SketchConstraintCoincidence_121") SketchLine_78 = Sketch_10.addLine(64, -20, 89, -20) SketchLine_78.setName("SketchLine_77") SketchLine_78.result().setName("SketchLine_77") -SketchPoint_6 = Sketch_10.addPoint(model.selection("VERTEX", "RevolutionFuse_1_1/Modfied_4&RevolutionFuse_1_1/Modfied_10&RevolutionFuse_3_1/Modfied_13&RevolutionFuse_3_1/Modfied_1divided_2")) +SketchPoint_6 = Sketch_10.addPoint(model.selection("VERTEX", "RevolutionFuse_1_1/Modfied_4&RevolutionFuse_1_1/Modfied_10&RevolutionFuse_3_1/Modfied_13&RevolutionFuse_3_1/Modfied_1divided_f_2")) SketchConstraintCoincidence_124 = Sketch_10.setCoincident(SketchLine_78.startPoint(), SketchPoint_6.result()) SketchConstraintCoincidence_124.setName("SketchConstraintCoincidence_122") SketchPoint_7 = Sketch_10.addPoint(model.selection("VERTEX", "ExtrusionFuse_2_1/Modfied_3&RevolutionFuse_1_1/Modfied_4&ExtrusionFuse_2_1/Modfied_4&RevolutionFuse_3_1/Modfied_13")) @@ -683,7 +683,7 @@ SketchConstraintCoincidence_129 = Sketch_10.setCoincident(SketchArc_11.startPoin SketchConstraintCoincidence_129.setName("SketchConstraintCoincidence_127") SketchConstraintTangent_19 = Sketch_10.setTangent(SketchArc_11.results()[1], SketchLine_78.result()) SketchConstraintTangent_19.setName("SketchConstraintTangent_24") -SketchPoint_8 = Sketch_10.addPoint(model.selection("VERTEX", "RevolutionFuse_3_1/Modfied_7&RevolutionFuse_3_1/Modfied_1divided_2&ExtrusionCut_2_1/Modfied_4&RevolutionFuse_3_1/Modfied_3divided_1&RevolutionFuse_3_1/Modfied_15")) +SketchPoint_8 = Sketch_10.addPoint(model.selection("VERTEX", "RevolutionFuse_1_1/Modfied_10&RevolutionFuse_3_1/Modfied_7&RevolutionFuse_3_1/Modfied_1divided_f_2")) SketchConstraintCoincidence_130 = Sketch_10.setCoincident(SketchArc_11.endPoint(), SketchPoint_8.result()) SketchConstraintCoincidence_130.setName("SketchConstraintCoincidence_128") SketchArc_12 = Sketch_10.addArc(64.00001789135865, 23.01137360115889, 64, 20, 61.15622559702543, 22.02080994708722, True) @@ -694,7 +694,7 @@ SketchConstraintCoincidence_131 = Sketch_10.setCoincident(SketchArc_12.startPoin SketchConstraintCoincidence_131.setName("SketchConstraintCoincidence_129") SketchConstraintTangent_20 = Sketch_10.setTangent(SketchArc_12.results()[1], SketchLine_77.result()) SketchConstraintTangent_20.setName("SketchConstraintTangent_25") -SketchPoint_9 = Sketch_10.addPoint(model.selection("VERTEX", "RevolutionFuse_3_1/Modfied_4&RevolutionFuse_3_1/Modfied_1divided_1&ExtrusionCut_2_1/Modfied_4&RevolutionFuse_3_1/Modfied_1divided_5&RevolutionFuse_3_1/Modfied_15")) +SketchPoint_9 = Sketch_10.addPoint(model.selection("VERTEX", "RevolutionFuse_2_1/Modfied_12&RevolutionFuse_3_1/Modfied_4&RevolutionFuse_3_1/Modfied_1divided_f_1")) SketchConstraintCoincidence_132 = Sketch_10.setCoincident(SketchArc_12.endPoint(), SketchPoint_9.result()) SketchConstraintCoincidence_132.setName("SketchConstraintCoincidence_130") SketchLine_79 = Sketch_10.addLine(61.15622559702543, 22.02080994708722, 59.81204392543111, 22.0208099470871) @@ -788,7 +788,7 @@ ExtrusionCut_4 = model.addExtrusionCut(Part_1_doc, [model.selection("WIRE", "Ske # Test reexecution after parameter change Parameter_R.setValue(5) model.do() -model.testResultsVolumes(ExtrusionCut_4, [502615.944655187719035893678665161]) +model.testResultsVolumes(ExtrusionCut_4, [502616.749082866765093058347702026]) Parameter_R.setValue(3) model.end() @@ -798,8 +798,8 @@ model.testNbResults(ExtrusionCut_4, 1) model.testNbSubResults(ExtrusionCut_4, [0]) model.testNbSubShapes(ExtrusionCut_4, GeomAPI_Shape.SOLID, [1]) model.testNbSubShapes(ExtrusionCut_4, GeomAPI_Shape.FACE, [81]) -model.testNbSubShapes(ExtrusionCut_4, GeomAPI_Shape.EDGE, [406]) -model.testNbSubShapes(ExtrusionCut_4, GeomAPI_Shape.VERTEX, [812]) -model.testResultsVolumes(ExtrusionCut_4, [502902.431481667619664222002029419]) +model.testNbSubShapes(ExtrusionCut_4, GeomAPI_Shape.EDGE, [410]) +model.testNbSubShapes(ExtrusionCut_4, GeomAPI_Shape.VERTEX, [820]) +model.testResultsVolumes(ExtrusionCut_4, [502903.236060981987975537776947021]) assert(model.checkPythonDump()) diff --git a/test.models/clothespin.py b/test.models/clothespin.py index 896242153..a7f26c547 100644 --- a/test.models/clothespin.py +++ b/test.models/clothespin.py @@ -465,7 +465,7 @@ SketchLine_56.setName("SketchLine_58") SketchLine_56.result().setName("SketchLine_58") model.do() ExtrusionFuse_1 = model.addExtrusionFuse(Part_1_doc, [model.selection("COMPOUND", "Sketch_6")], model.selection(), model.selection("FACE", "Sketch_1/Face-SketchLine_1f-SketchLine_3f-SketchLine_4f-SketchLine_5f-SketchLine_7f-SketchArc_1_2f-SketchLine_8f-SketchLine_9f-SketchLine_10r-SketchLine_11r-SketchLine_12r-SketchLine_14r-SketchArc_2_2r"), 0, model.selection(), 0, [model.selection("SOLID", "ExtrusionCut_5_1")]) -Sketch_7 = model.addSketch(Part_1_doc, model.selection("FACE", "ExtrusionCut_2_1/Modfied_1divided_3")) +Sketch_7 = model.addSketch(Part_1_doc, model.selection("FACE", "ExtrusionCut_2_1/Modfied_9")) SketchLine_64 = Sketch_7.addLine(50.25000000000001, -4.5, 31.24999999998802, -4.499999999999997) SketchLine_64.setName("SketchLine_76") SketchLine_64.result().setName("SketchLine_76") @@ -1396,7 +1396,7 @@ SketchLine_162.setName("SketchLine_58") SketchLine_162.result().setName("SketchLine_58") model.do() ExtrusionFuse_2 = model.addExtrusionFuse(Part_2_doc, [model.selection("COMPOUND", "Sketch_6")], model.selection(), model.selection("FACE", "Sketch_1/Face-SketchLine_1f-SketchLine_3f-SketchLine_4f-SketchLine_5f-SketchLine_7f-SketchArc_1_2f-SketchLine_8f-SketchLine_9f-SketchLine_10r-SketchLine_11r-SketchLine_12r-SketchLine_14r-SketchArc_2_2r"), 0, model.selection(), 0, [model.selection("SOLID", "ExtrusionCut_5_1")]) -Sketch_17 = model.addSketch(Part_2_doc, model.selection("FACE", "ExtrusionCut_2_1/Modfied_1divided_3")) +Sketch_17 = model.addSketch(Part_2_doc, model.selection("FACE", "ExtrusionCut_2_1/Modfied_9")) SketchLine_170 = Sketch_17.addLine(50.25000000000001, -4.5, 31.24999999998802, -4.499999999999997) SketchLine_170.setName("SketchLine_76") SketchLine_170.result().setName("SketchLine_76") -- 2.39.2