From c7c9b0ce694a1e7e48a669ccd821b803d9c25f82 Mon Sep 17 00:00:00 2001 From: azv Date: Tue, 17 Sep 2019 15:57:31 +0300 Subject: [PATCH] Task 2.12. New entities: ellipses and arcs of ellipses (issue #3003) Testing possibility to remove full ellipse and all its construction elements. --- .../ModelHighAPI_FeatureStore.cpp | 6 + src/ModelHighAPI/ModelHighAPI_Tools.cpp | 5 +- src/SketchAPI/SketchAPI_Ellipse.cpp | 67 ++++++----- src/SketchPlugin/CMakeLists.txt | 1 + src/SketchPlugin/SketchPlugin_Line.cpp | 3 + src/SketchPlugin/SketchPlugin_Line.h | 7 ++ .../SketchPlugin_MacroEllipse.cpp | 54 ++++++--- src/SketchPlugin/SketchPlugin_MacroEllipse.h | 7 +- src/SketchPlugin/SketchPlugin_Point.cpp | 4 + src/SketchPlugin/SketchPlugin_Point.h | 6 + src/SketchPlugin/Test/TestRemoveEllipse.py | 106 ++++++++++++++++++ 11 files changed, 219 insertions(+), 47 deletions(-) create mode 100644 src/SketchPlugin/Test/TestRemoveEllipse.py diff --git a/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp b/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp index 09e944d4e..adba12994 100644 --- a/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp +++ b/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp @@ -281,6 +281,12 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) { std::list aResList; // list of resulting strings for(std::list::iterator aL = aList.begin(); aL != aList.end(); aL++) { if (aL->get()) { + if (isSketchFeatures) { + // do not control construction features of an ellipse and other + FeaturePtr aFeature = ModelAPI_Feature::feature(*aL); + if (aFeature->getKind() == "SketchConstraintCoincidenceInternal") + continue; // skip internal constraints + } aResList.push_back((*aL)->data()->name()); } else if (!isSketchFeatures) { aResList.push_back("__empty__"); diff --git a/src/ModelHighAPI/ModelHighAPI_Tools.cpp b/src/ModelHighAPI/ModelHighAPI_Tools.cpp index 0b6f6fc39..c61974d3b 100644 --- a/src/ModelHighAPI/ModelHighAPI_Tools.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Tools.cpp @@ -403,6 +403,10 @@ std::string storeFeatures(const std::string& theDocName, DocumentPtr theDoc, std::list::iterator allIter = allObjects.begin(); for(; allIter != allObjects.end(); allIter++) { ObjectPtr anObject = *allIter; + FeaturePtr aFeature = std::dynamic_pointer_cast(anObject); + if (aFeature->getKind() == "SketchConstraintCoincidenceInternal") + continue; // no need to dump and check internal constraints + if (theCompare) { std::map::iterator anObjFind = aDocFind->second.find(anObject->data()->name()); @@ -420,7 +424,6 @@ std::string storeFeatures(const std::string& theDocName, DocumentPtr theDoc, theStore[theDocName][anObject->data()->name()] = ModelHighAPI_FeatureStore(anObject); } - FeaturePtr aFeature = std::dynamic_pointer_cast(anObject); if (aFeature) { // iterate all results of this feature std::list allResults; diff --git a/src/SketchAPI/SketchAPI_Ellipse.cpp b/src/SketchAPI/SketchAPI_Ellipse.cpp index 7b005014e..b87dc52cb 100644 --- a/src/SketchAPI/SketchAPI_Ellipse.cpp +++ b/src/SketchAPI/SketchAPI_Ellipse.cpp @@ -177,17 +177,24 @@ static void createInternalConstraint(const CompositeFeaturePtr& theSketch, } static FeaturePtr createPoint(const CompositeFeaturePtr& theSketch, - const AttributePtr& theCoincident, + const FeaturePtr& theEllipse, + const std::string& theCoincident, const std::string& theAuxOrName) { - AttributePoint2DPtr anElPoint = std::dynamic_pointer_cast(theCoincident); + AttributePoint2DPtr anElPoint = std::dynamic_pointer_cast( + theEllipse->attribute(theCoincident)); FeaturePtr aPointFeature = theSketch->addFeature(SketchPlugin_Point::ID()); AttributePoint2DPtr aCoord = std::dynamic_pointer_cast( aPointFeature->attribute(SketchPlugin_Point::COORD_ID())); aCoord->setValue(anElPoint->x(), anElPoint->y()); + aPointFeature->reference(SketchPlugin_Point::PARENT_ID())->setValue(theEllipse); aPointFeature->execute(); + std::string aName = theEllipse->name() + "_" + theCoincident; + aPointFeature->data()->setName(aName); + aPointFeature->lastResult()->data()->setName(aName); + if (theAuxOrName == AUXILIARY_VALUE) aPointFeature->boolean(SketchPlugin_Point::AUXILIARY_ID())->setValue(true); else if (!theAuxOrName.empty()) { @@ -201,14 +208,15 @@ static FeaturePtr createPoint(const CompositeFeaturePtr& theSketch, } static FeaturePtr createAxis(const CompositeFeaturePtr& theSketch, - const AttributePtr& theCoincidentStart, - const AttributePtr& theCoincidentEnd, + const FeaturePtr& theEllipse, + const std::string& theCoincidentStart, + const std::string& theCoincidentEnd, const std::string& theAuxOrName) { AttributePoint2DPtr aStartPoint = - std::dynamic_pointer_cast(theCoincidentStart); + std::dynamic_pointer_cast(theEllipse->attribute(theCoincidentStart)); AttributePoint2DPtr aEndPoint = - std::dynamic_pointer_cast(theCoincidentEnd); + std::dynamic_pointer_cast(theEllipse->attribute(theCoincidentEnd)); FeaturePtr aLineFeature = theSketch->addFeature(SketchPlugin_Line::ID()); AttributePoint2DPtr aLineStart = std::dynamic_pointer_cast( @@ -217,10 +225,17 @@ static FeaturePtr createAxis(const CompositeFeaturePtr& theSketch, AttributePoint2DPtr aLineEnd = std::dynamic_pointer_cast( aLineFeature->attribute(SketchPlugin_Line::END_ID())); aLineEnd->setValue(aEndPoint->x(), aEndPoint->y()); + aLineFeature->reference(SketchPlugin_Point::PARENT_ID())->setValue(theEllipse); aLineFeature->execute(); + std::string aName = theEllipse->name() + "_" + + (theCoincidentStart == SketchPlugin_Ellipse::MAJOR_AXIS_START_ID() ? + "major_axis" : "minor_axis"); + aLineFeature->data()->setName(aName); + aLineFeature->lastResult()->data()->setName(aName); + if (theAuxOrName == AUXILIARY_VALUE) - aLineFeature->boolean(SketchPlugin_Point::AUXILIARY_ID())->setValue(true); + aLineFeature->boolean(SketchPlugin_Line::AUXILIARY_ID())->setValue(true); else if (!theAuxOrName.empty()) { aLineFeature->data()->setName(theAuxOrName); aLineFeature->lastResult()->data()->setName(theAuxOrName); @@ -248,42 +263,40 @@ std::list > SketchAPI_Ellipse::construct std::list anEntities; if (!center.empty()) { - AttributePtr aCenterAttr = anEllipse->attribute(SketchPlugin_Ellipse::CENTER_ID()); - anEntities.push_back(createPoint(aSketch, aCenterAttr, center)); + anEntities.push_back( + createPoint(aSketch, anEllipse, SketchPlugin_Ellipse::CENTER_ID(), center)); } if (!firstFocus.empty()) { - AttributePtr aFocusAttr = anEllipse->attribute(SketchPlugin_Ellipse::FIRST_FOCUS_ID()); - anEntities.push_back(createPoint(aSketch, aFocusAttr, firstFocus)); + anEntities.push_back( + createPoint(aSketch, anEllipse, SketchPlugin_Ellipse::FIRST_FOCUS_ID(), firstFocus)); } if (!secondFocus.empty()) { - AttributePtr aFocusAttr = anEllipse->attribute(SketchPlugin_Ellipse::SECOND_FOCUS_ID()); - anEntities.push_back(createPoint(aSketch, aFocusAttr, secondFocus)); + anEntities.push_back( + createPoint(aSketch, anEllipse, SketchPlugin_Ellipse::SECOND_FOCUS_ID(), secondFocus)); } if (!majorAxisStart.empty()) { - AttributePtr aStartAttr = anEllipse->attribute(SketchPlugin_Ellipse::MAJOR_AXIS_START_ID()); - anEntities.push_back(createPoint(aSketch, aStartAttr, majorAxisStart)); + anEntities.push_back( + createPoint(aSketch, anEllipse, SketchPlugin_Ellipse::MAJOR_AXIS_START_ID(), majorAxisStart)); } if (!majorAxisEnd.empty()) { - AttributePtr aEndAttr = anEllipse->attribute(SketchPlugin_Ellipse::MAJOR_AXIS_END_ID()); - anEntities.push_back(createPoint(aSketch, aEndAttr, majorAxisEnd)); + anEntities.push_back( + createPoint(aSketch, anEllipse, SketchPlugin_Ellipse::MAJOR_AXIS_END_ID(), majorAxisEnd)); } if (!minorAxisStart.empty()) { - AttributePtr aStartAttr = anEllipse->attribute(SketchPlugin_Ellipse::MINOR_AXIS_START_ID()); - anEntities.push_back(createPoint(aSketch, aStartAttr, minorAxisStart)); + anEntities.push_back( + createPoint(aSketch, anEllipse, SketchPlugin_Ellipse::MINOR_AXIS_START_ID(), minorAxisStart)); } if (!minorAxisEnd.empty()) { - AttributePtr aEndAttr = anEllipse->attribute(SketchPlugin_Ellipse::MINOR_AXIS_END_ID()); - anEntities.push_back(createPoint(aSketch, aEndAttr, minorAxisEnd)); + anEntities.push_back( + createPoint(aSketch, anEllipse, SketchPlugin_Ellipse::MINOR_AXIS_END_ID(), minorAxisEnd)); } if (!majorAxis.empty()) { - AttributePtr aStartAttr = anEllipse->attribute(SketchPlugin_Ellipse::MAJOR_AXIS_START_ID()); - AttributePtr aEndAttr = anEllipse->attribute(SketchPlugin_Ellipse::MAJOR_AXIS_END_ID()); - anEntities.push_back(createAxis(aSketch, aStartAttr, aEndAttr, majorAxis)); + anEntities.push_back(createAxis(aSketch, anEllipse, SketchPlugin_Ellipse::MAJOR_AXIS_START_ID(), + SketchPlugin_Ellipse::MAJOR_AXIS_END_ID(), majorAxis)); } if (!minorAxis.empty()) { - AttributePtr aStartAttr = anEllipse->attribute(SketchPlugin_Ellipse::MINOR_AXIS_START_ID()); - AttributePtr aEndAttr = anEllipse->attribute(SketchPlugin_Ellipse::MINOR_AXIS_END_ID()); - anEntities.push_back(createAxis(aSketch, aStartAttr, aEndAttr, minorAxis)); + anEntities.push_back(createAxis(aSketch, anEllipse, SketchPlugin_Ellipse::MINOR_AXIS_START_ID(), + SketchPlugin_Ellipse::MINOR_AXIS_END_ID(), minorAxis)); } return SketchAPI_SketchEntity::wrap(anEntities); diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 80b68f571..b7074675b 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -263,6 +263,7 @@ ADD_UNIT_TESTS( TestProjectionIntoResult.py TestProjectionUpdate.py TestRectangle.py + TestRemoveEllipse.py TestRemoveSketch.py TestSignedDistancePointLine.py TestSignedDistancePointPoint.py diff --git a/src/SketchPlugin/SketchPlugin_Line.cpp b/src/SketchPlugin/SketchPlugin_Line.cpp index f01a332f2..e52847193 100644 --- a/src/SketchPlugin/SketchPlugin_Line.cpp +++ b/src/SketchPlugin/SketchPlugin_Line.cpp @@ -47,6 +47,9 @@ void SketchPlugin_Line::initAttributes() /// new attributes should be added to end of the feature in order to provide /// correct attribute values in previous saved studies data()->addAttribute(LENGTH_ID(), ModelAPI_AttributeDouble::typeId()); + + data()->addAttribute(PARENT_ID(), ModelAPI_AttributeReference::typeId()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PARENT_ID()); } void SketchPlugin_Line::initDerivedClassAttributes() diff --git a/src/SketchPlugin/SketchPlugin_Line.h b/src/SketchPlugin/SketchPlugin_Line.h index 7a23944ae..73ad43107 100644 --- a/src/SketchPlugin/SketchPlugin_Line.h +++ b/src/SketchPlugin/SketchPlugin_Line.h @@ -63,6 +63,13 @@ class SketchPlugin_Line : public SketchPlugin_SketchEntity, return MY_LENGTH; } + /// Reference to the parent feature + inline static const std::string& PARENT_ID() + { + static const std::string& MY_PARENT_ID("ParentFeature"); + return MY_PARENT_ID; + } + /// Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind(); diff --git a/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp b/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp index fc6e03453..99910ceba 100644 --- a/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp +++ b/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp @@ -295,44 +295,58 @@ FeaturePtr SketchPlugin_MacroEllipse::createEllipseFeature() aEllipseFeature->execute(); // create auxiliary points - createAuxiliaryPoint(aEllipseFeature->attribute(SketchPlugin_Ellipse::CENTER_ID())); - createAuxiliaryPoint(aEllipseFeature->attribute(SketchPlugin_Ellipse::FIRST_FOCUS_ID())); - createAuxiliaryPoint(aEllipseFeature->attribute(SketchPlugin_Ellipse::SECOND_FOCUS_ID())); - createAuxiliaryPoint(aEllipseFeature->attribute(SketchPlugin_Ellipse::MAJOR_AXIS_START_ID())); - createAuxiliaryPoint(aEllipseFeature->attribute(SketchPlugin_Ellipse::MAJOR_AXIS_END_ID())); - createAuxiliaryPoint(aEllipseFeature->attribute(SketchPlugin_Ellipse::MINOR_AXIS_START_ID())); - createAuxiliaryPoint(aEllipseFeature->attribute(SketchPlugin_Ellipse::MINOR_AXIS_END_ID())); + createAuxiliaryPoint(aEllipseFeature, SketchPlugin_Ellipse::CENTER_ID()); + createAuxiliaryPoint(aEllipseFeature, SketchPlugin_Ellipse::FIRST_FOCUS_ID()); + createAuxiliaryPoint(aEllipseFeature, SketchPlugin_Ellipse::SECOND_FOCUS_ID()); + createAuxiliaryPoint(aEllipseFeature, SketchPlugin_Ellipse::MAJOR_AXIS_START_ID()); + createAuxiliaryPoint(aEllipseFeature, SketchPlugin_Ellipse::MAJOR_AXIS_END_ID()); + createAuxiliaryPoint(aEllipseFeature, SketchPlugin_Ellipse::MINOR_AXIS_START_ID()); + createAuxiliaryPoint(aEllipseFeature, SketchPlugin_Ellipse::MINOR_AXIS_END_ID()); // create auxiliary axes - createAuxiliaryAxis(aEllipseFeature->attribute(SketchPlugin_Ellipse::MAJOR_AXIS_START_ID()), - aEllipseFeature->attribute(SketchPlugin_Ellipse::MAJOR_AXIS_END_ID())); - createAuxiliaryAxis(aEllipseFeature->attribute(SketchPlugin_Ellipse::MINOR_AXIS_START_ID()), - aEllipseFeature->attribute(SketchPlugin_Ellipse::MINOR_AXIS_END_ID())); + createAuxiliaryAxis(aEllipseFeature, + SketchPlugin_Ellipse::MAJOR_AXIS_START_ID(), + SketchPlugin_Ellipse::MAJOR_AXIS_END_ID()); + createAuxiliaryAxis(aEllipseFeature, + SketchPlugin_Ellipse::MINOR_AXIS_START_ID(), + SketchPlugin_Ellipse::MINOR_AXIS_END_ID()); return aEllipseFeature; } -void SketchPlugin_MacroEllipse::createAuxiliaryPoint(const AttributePtr& theEllipsePoint) +void SketchPlugin_MacroEllipse::createAuxiliaryPoint(const FeaturePtr& theEllipseFeature, + const std::string& theEllipsePoint) { FeaturePtr aPointFeature = sketch()->addFeature(SketchPlugin_Point::ID()); aPointFeature->boolean(SketchPlugin_Point::AUXILIARY_ID())->setValue(true); + aPointFeature->reference(SketchPlugin_Point::PARENT_ID())->setValue(theEllipseFeature); - AttributePoint2DPtr anElPoint = std::dynamic_pointer_cast(theEllipsePoint); + AttributePoint2DPtr anElPoint = std::dynamic_pointer_cast( + theEllipseFeature->attribute(theEllipsePoint)); AttributePoint2DPtr aCoord = std::dynamic_pointer_cast( aPointFeature->attribute(SketchPlugin_Point::COORD_ID())); aCoord->setValue(anElPoint->x(), anElPoint->y()); + aPointFeature->execute(); + std::string aName = theEllipseFeature->name() + "_" + theEllipsePoint; + aPointFeature->data()->setName(aName); + aPointFeature->lastResult()->data()->setName(aName); + createInternalConstraint(anElPoint, aCoord); } -void SketchPlugin_MacroEllipse::createAuxiliaryAxis(const AttributePtr& theStartPoint, - const AttributePtr& theEndPoint) +void SketchPlugin_MacroEllipse::createAuxiliaryAxis(const FeaturePtr& theEllipseFeature, + const std::string& theStartPoint, + const std::string& theEndPoint) { FeaturePtr aLineFeature = sketch()->addFeature(SketchPlugin_Line::ID()); aLineFeature->boolean(SketchPlugin_Point::AUXILIARY_ID())->setValue(true); + aLineFeature->reference(SketchPlugin_Point::PARENT_ID())->setValue(theEllipseFeature); - AttributePoint2DPtr aStartPoint = std::dynamic_pointer_cast(theStartPoint); - AttributePoint2DPtr aEndPoint = std::dynamic_pointer_cast(theEndPoint); + AttributePoint2DPtr aStartPoint = std::dynamic_pointer_cast( + theEllipseFeature->attribute(theStartPoint)); + AttributePoint2DPtr aEndPoint = std::dynamic_pointer_cast( + theEllipseFeature->attribute(theEndPoint)); AttributePoint2DPtr aLineStart = std::dynamic_pointer_cast( aLineFeature->attribute(SketchPlugin_Line::START_ID())); @@ -342,6 +356,12 @@ void SketchPlugin_MacroEllipse::createAuxiliaryAxis(const AttributePtr& theStart aLineFeature->attribute(SketchPlugin_Line::END_ID())); aLineEnd->setValue(aEndPoint->x(), aEndPoint->y()); + aLineFeature->execute(); + std::string aName = theEllipseFeature->name() + "_" + + (theStartPoint == SketchPlugin_Ellipse::MAJOR_AXIS_START_ID() ? "major_axis" : "minor_axis"); + aLineFeature->data()->setName(aName); + aLineFeature->lastResult()->data()->setName(aName); + createInternalConstraint(aStartPoint, aLineStart); createInternalConstraint(aEndPoint, aLineEnd); } diff --git a/src/SketchPlugin/SketchPlugin_MacroEllipse.h b/src/SketchPlugin/SketchPlugin_MacroEllipse.h index 2b92f7f2a..4bea22221 100644 --- a/src/SketchPlugin/SketchPlugin_MacroEllipse.h +++ b/src/SketchPlugin/SketchPlugin_MacroEllipse.h @@ -162,8 +162,11 @@ private: FeaturePtr createEllipseFeature(); - void createAuxiliaryPoint(const AttributePtr& theEllipsePoint); - void createAuxiliaryAxis(const AttributePtr& theStartPoint, const AttributePtr& theEndPoint); + void createAuxiliaryPoint(const FeaturePtr& theEllipseFeature, + const std::string& theEllipsePoint); + void createAuxiliaryAxis(const FeaturePtr& theEllipseFeature, + const std::string& theStartPoint, + const std::string& theEndPoint); void createInternalConstraint(const AttributePtr& thePoint1, const AttributePtr& thePoint2); diff --git a/src/SketchPlugin/SketchPlugin_Point.cpp b/src/SketchPlugin/SketchPlugin_Point.cpp index c53006489..9a6358053 100644 --- a/src/SketchPlugin/SketchPlugin_Point.cpp +++ b/src/SketchPlugin/SketchPlugin_Point.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -41,6 +42,9 @@ void SketchPlugin_Point::initDerivedClassAttributes() data()->addAttribute(SketchPlugin_Point::COORD_ID(), GeomDataAPI_Point2D::typeId()); data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID()); + + data()->addAttribute(PARENT_ID(), ModelAPI_AttributeReference::typeId()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PARENT_ID()); } void SketchPlugin_Point::execute() diff --git a/src/SketchPlugin/SketchPlugin_Point.h b/src/SketchPlugin/SketchPlugin_Point.h index 1cdcae05f..5111ce0a8 100644 --- a/src/SketchPlugin/SketchPlugin_Point.h +++ b/src/SketchPlugin/SketchPlugin_Point.h @@ -44,6 +44,12 @@ class SketchPlugin_Point : public SketchPlugin_SketchEntity static const std::string MY_COORD_ID("PointCoordinates"); return MY_COORD_ID; } + /// Reference to the parent feature + inline static const std::string& PARENT_ID() + { + static const std::string& MY_PARENT_ID("ParentFeature"); + return MY_PARENT_ID; + } /// Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() { diff --git a/src/SketchPlugin/Test/TestRemoveEllipse.py b/src/SketchPlugin/Test/TestRemoveEllipse.py new file mode 100644 index 000000000..7a8d3c481 --- /dev/null +++ b/src/SketchPlugin/Test/TestRemoveEllipse.py @@ -0,0 +1,106 @@ +# Copyright (C) 2019 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 +# + +""" + Test removing ellipse and its construstion elements +""" + +from salome.shaper import model +from ModelAPI import * + +def assertNbSubs(theSketch, theNbPoints, theNbLines, theNbEllipses, theNbInternalConstraints): + model.testNbSubFeatures(theSketch, "SketchPoint", theNbPoints) + model.testNbSubFeatures(theSketch, "SketchLine", theNbLines) + model.testNbSubFeatures(theSketch, "SketchEllipse", theNbEllipses) + model.testNbSubFeatures(theSketch, "SketchConstraintCoincidenceInternal", theNbInternalConstraints) + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchEllipse_1 = Sketch_1.addEllipse(40, 30, 70, 40, 20) +[Center, Focus1, Focus2, MajorAxisStart, MajorAxisEnd, MinorAxisStart, MinorAxisEnd, MajorAxisLine, MinorAxisLine] = SketchEllipse_1.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux") +model.do() +model.end() + +DEFAULT_DOF = 5 +DEFAULT_POINTS = 7 +DEFAULT_LINES = 2 +DEFAULT_ELLIPSES = 1 +DEAFULT_INTERNALS = 11 + +assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES, DEFAULT_ELLIPSES, DEAFULT_INTERNALS) +assert(model.dof(Sketch_1) == DEFAULT_DOF) + +# Test 1. Remove auxiliary points one by one. +points = [Center, Focus1, Focus2, MajorAxisStart, MajorAxisEnd, MinorAxisStart, MinorAxisEnd] +for pnt in points: + model.begin() + removeFeaturesAndReferences(FeatureSet([pnt.feature()])) + model.end() + + assertNbSubs(Sketch_1, DEFAULT_POINTS - 1, DEFAULT_LINES, DEFAULT_ELLIPSES, DEAFULT_INTERNALS - 1) + assert(model.dof(Sketch_1) == DEFAULT_DOF) + model.undo() + assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES, DEFAULT_ELLIPSES, DEAFULT_INTERNALS) + assert(model.dof(Sketch_1) == DEFAULT_DOF) + +# Test 2. Remove auxiliary axes one by one. +lines = [MajorAxisLine, MinorAxisLine] +for ln in lines: + model.begin() + removeFeaturesAndReferences(FeatureSet([ln.feature()])) + model.end() + + assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES - 1, DEFAULT_ELLIPSES, DEAFULT_INTERNALS - 2) + assert(model.dof(Sketch_1) == DEFAULT_DOF) + model.undo() + assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES, DEFAULT_ELLIPSES, DEAFULT_INTERNALS) + assert(model.dof(Sketch_1) == DEFAULT_DOF) + +# Test 3. Remove the ellipse. +model.begin() +removeFeaturesAndReferences(FeatureSet([SketchEllipse_1.feature()])) +model.end() + +assertNbSubs(Sketch_1, 0, 0, 0, 0) +assert(model.dof(Sketch_1) == 0) +model.undo() +assertNbSubs(Sketch_1, DEFAULT_POINTS, DEFAULT_LINES, DEFAULT_ELLIPSES, DEAFULT_INTERNALS) +assert(model.dof(Sketch_1) == DEFAULT_DOF) + +# Test 4. Remove some construction elements, make non-auxiliary a couple of the rest and check the dumping. +model.begin() +Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchEllipse_2 = Sketch_2.addEllipse(40, -30, 70, 0, 10) +[Center, Focus1, Focus2, MajorAxisStart, MajorAxisEnd, MinorAxisStart, MinorAxisEnd, MajorAxisLine, MinorAxisLine] = SketchEllipse_2.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux") +model.do() +model.end() + +model.begin() +removeFeaturesAndReferences(FeatureSet([MajorAxisLine.feature(), Focus2.feature()])) +Focus1.setAuxiliary(False) +MinorAxisEnd.setAuxiliary(False) +model.end() + +assertNbSubs(Sketch_2, DEFAULT_POINTS - 1, DEFAULT_LINES - 1, DEFAULT_ELLIPSES, DEAFULT_INTERNALS - 3) +assert(model.dof(Sketch_2) == DEFAULT_DOF) + +assert(model.checkPythonDump()) -- 2.39.2