From: azv Date: Fri, 30 Nov 2018 07:55:07 +0000 (+0300) Subject: [Code coverage SketchPlugin]: Increase coverage of Arc, Split and Trim features X-Git-Tag: End2018~129 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=751dc40d602e05d2b810ffe1345b74f88ceca03f;p=modules%2Fshaper.git [Code coverage SketchPlugin]: Increase coverage of Arc, Split and Trim features --- diff --git a/src/ModelAPI/ModelAPI_CompositeFeature.cpp b/src/ModelAPI/ModelAPI_CompositeFeature.cpp index 8fc0c819a..b9227b043 100644 --- a/src/ModelAPI/ModelAPI_CompositeFeature.cpp +++ b/src/ModelAPI/ModelAPI_CompositeFeature.cpp @@ -25,12 +25,6 @@ ModelAPI_CompositeFeature::~ModelAPI_CompositeFeature() } -void ModelAPI_CompositeFeature::exchangeIDs( - std::shared_ptr theFeature1, std::shared_ptr theFeature2) -{ - // by default nothing is in the implementation -} - void ModelAPI_CompositeFeature::erase() { // erase all sub-features diff --git a/src/ModelAPI/ModelAPI_CompositeFeature.h b/src/ModelAPI/ModelAPI_CompositeFeature.h index 1011b350b..29276b544 100644 --- a/src/ModelAPI/ModelAPI_CompositeFeature.h +++ b/src/ModelAPI/ModelAPI_CompositeFeature.h @@ -55,10 +55,6 @@ public: /// structures of the owner (the remove from the document will be done outside just after) virtual void removeFeature(std::shared_ptr theFeature) = 0; - /// Exchanges IDs of two given features: needed for more correct naming in some cases (issue 769) - MODELAPI_EXPORT virtual void exchangeIDs(std::shared_ptr theFeature1, - std::shared_ptr theFeature2); - /// in addition removes all subs MODELAPI_EXPORT virtual void erase(); }; diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 8a17e7fed..fd6cd6381 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -208,6 +208,7 @@ ADD_UNIT_TESTS( TestConstraintParallel.py TestConstraintPerpendicular.py TestConstraintRadius.py + TestConstraintRadiusFailure.py TestConstraintTangent.py TestConstraintVertical.py TestCreateArcByCenterStartEnd.py @@ -249,9 +250,12 @@ ADD_UNIT_TESTS( TestRemoveSketch.py TestSignedDistancePointLine.py TestSignedDistancePointPoint.py + TestSketchDrawer.py TestSketchPointLine.py TestSnowflake.py TestSplit.py + TestSplitLine.py + TestSplitPreview.py TestTrimArc01.py TestTrimArc02.py TestTrimArc03.py @@ -267,7 +271,8 @@ ADD_UNIT_TESTS( TestTrimCircleAndArc01.py TestTrimLine01.py TestTrimLine02.py - TestSketchDrawer.py + TestTrimLine03.py + TestTrimPreview.py ) if(${SKETCHER_CHANGE_RADIUS_WHEN_MOVE}) diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 368f4452c..92fb4fcc5 100755 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -370,9 +370,3 @@ std::shared_ptr SketchPlugin_Sketch::plane(SketchPlugin_Sketch* the return std::shared_ptr(new GeomAPI_Ax3(anOrigin->pnt(), aDirX->dir(), aNorm->dir())); } - -void SketchPlugin_Sketch::exchangeIDs( - std::shared_ptr theFeature1, std::shared_ptr theFeature2) -{ - reflist(SketchPlugin_Sketch::FEATURES_ID())->exchange(theFeature1, theFeature2); -} diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index 57dde7c5c..310001a81 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -206,11 +206,6 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature, public GeomAPI_ICu SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); - /// Exchanges IDs of two given features: needed for fillet feature better naming (issue 769) - SKETCHPLUGIN_EXPORT virtual void exchangeIDs(std::shared_ptr theFeature1, - std::shared_ptr theFeature2); - - /// \brief Create a result for the point in the attribute if the attribute is initialized /// \param theFeature a source feature /// \param theSketch a sketch intance diff --git a/src/SketchPlugin/SketchPlugin_Split.cpp b/src/SketchPlugin/SketchPlugin_Split.cpp index d9e0cc252..48162af13 100644 --- a/src/SketchPlugin/SketchPlugin_Split.cpp +++ b/src/SketchPlugin/SketchPlugin_Split.cpp @@ -713,23 +713,6 @@ GeomShapePtr SketchPlugin_Split::getSubShape(const std::string& theObjectAttribu return aBaseShape; } -std::shared_ptr SketchPlugin_Split::getPointOfRefAttr( - const AttributePtr& theAttribute) -{ - AttributePoint2DPtr aPointAttribute; - - if (theAttribute->attributeType() == ModelAPI_AttributeRefAttr::typeId()) { - AttributeRefAttrPtr aRefAttr = - std::dynamic_pointer_cast(theAttribute); - if (aRefAttr.get() && aRefAttr->isInitialized()) { - AttributePtr anAttribute = aRefAttr->attr(); - if (anAttribute.get() && anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) - aPointAttribute = std::dynamic_pointer_cast(anAttribute); - } - } - return aPointAttribute; -} - void SketchPlugin_Split::getFeaturePoints(const FeaturePtr& theFeature, AttributePoint2DPtr& theStartPointAttr, AttributePoint2DPtr& theEndPointAttr) @@ -1566,6 +1549,7 @@ std::shared_ptr SketchPlugin_Split::getFeatureResult( return aResult; } +#ifdef _DEBUG std::set > SketchPlugin_Split::getEdgeAttributes( const std::shared_ptr& theFeature) { @@ -1585,6 +1569,7 @@ std::set > SketchPlugin_Split::getEdgeAttrib return anAttributes; } +#endif std::shared_ptr SketchPlugin_Split::getPointAttribute (const bool isFirstAttribute) diff --git a/src/SketchPlugin/SketchPlugin_Split.h b/src/SketchPlugin/SketchPlugin_Split.h index 363db3645..a52428b79 100644 --- a/src/SketchPlugin/SketchPlugin_Split.h +++ b/src/SketchPlugin/SketchPlugin_Split.h @@ -149,11 +149,6 @@ private: std::shared_ptr& theStartPointAttr, std::shared_ptr& theEndPointAttr); - /// Returns cast of attribute to geometrical point if the attribute is a ref attr attribute - /// \param theAttribute an attribute - /// \param geom point 2D or NULL - std::shared_ptr getPointOfRefAttr(const AttributePtr& theAttribute); - /// Obtains those constraints of the feature that should be modified. output maps contain /// point of coincidence and attribute id to be modified after split /// \param theFeaturesToDelete [out] constrains that will be deleted after split diff --git a/src/SketchPlugin/SketchPlugin_Trim.cpp b/src/SketchPlugin/SketchPlugin_Trim.cpp index 387f3a8b4..64b4a2252 100644 --- a/src/SketchPlugin/SketchPlugin_Trim.cpp +++ b/src/SketchPlugin/SketchPlugin_Trim.cpp @@ -1197,20 +1197,6 @@ void SketchPlugin_Trim::fillAttribute(const AttributePtr& theModifiedAttribute, if (aModifiedAttribute.get() && aSourceAttribute.get()) aModifiedAttribute->setValue(aSourceAttribute->value()); } - else if (anAttributeType == ModelAPI_AttributeRefAttr::typeId()) { - AttributeRefAttrPtr aRefAttributeToFill = std::dynamic_pointer_cast( - theModifiedAttribute); - AttributeRefAttrPtr aSourceRefAttr = std::dynamic_pointer_cast( - theSourceAttribute); - if (!aSourceRefAttr.get()) - aRefAttributeToFill->setAttr(theSourceAttribute); - else { - if (aSourceRefAttr->isObject()) - aRefAttributeToFill->setObject(aSourceRefAttr->object()); - else - aRefAttributeToFill->setAttr(aSourceRefAttr->attr()); - } - } } FeaturePtr SketchPlugin_Trim::createLineFeature(const FeaturePtr& theBaseFeature, diff --git a/src/SketchPlugin/Test/TestConstraintRadiusFailure.py b/src/SketchPlugin/Test/TestConstraintRadiusFailure.py new file mode 100644 index 000000000..c989fc917 --- /dev/null +++ b/src/SketchPlugin/Test/TestConstraintRadiusFailure.py @@ -0,0 +1,34 @@ +## Copyright (C) 2018-20xx 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 +## + +from salome.shaper import model + +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")) +SketchLine_1 = Sketch_1.addLine(-30, 0, -10, 0) +SketchConstraintRadius_1 = Sketch_1.setRadius(SketchLine_1.result(), 20) +model.do() + +assert(SketchConstraintRadius_1.feature().error() != "") + +model.end() diff --git a/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py b/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py index 0e4464774..92666b178 100644 --- a/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py +++ b/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py @@ -272,6 +272,116 @@ verifyPointOnCircle(aStart, aPrevArc) model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 6) model.testNbSubFeatures(aSketch, "SketchConstraintTangent", 0) +#========================================================================= +# Test 5. Create another arc by center and points coincident to other features +#========================================================================= +# create new arc +aSession.startOperation() +anArc = aSketchFeature.addFeature("SketchMacroArc") +aCenter = geomDataAPI_Point2D(anArc.attribute("center_point")) +aCenterRef = anArc.refattr("center_point_ref") +aStart = geomDataAPI_Point2D(anArc.attribute("start_point_1")) +aStartRef = anArc.refattr("start_point_ref") +aEnd = geomDataAPI_Point2D(anArc.attribute("end_point_1")) +aEndRef = anArc.refattr("end_point_ref") +anArcType = anArc.string("arc_type") +# initialize attributes +anArcType.setValue("by_center_and_points") +aCenterRef.setObject(aLine.lastResult()) +aCenter.setValue(aLineStartPoint.pnt()) +aStartRef.setObject(aLine.lastResult()) +aStart.setValue(aLineEndPoint.pnt()) +aEndRef.setObject(aPrevArc.lastResult()) +aEnd.setValue(aPrevArcStart.pnt()) +aSession.finishOperation() +assert (aSketchFeature.numberOfSubs() == 16), "Number of subs {}".format(aSketchFeature.numberOfSubs()) +# check connected features do not change their positions +model.assertArc(aPrevArc, aPrevArcCenterXY, aPrevArcStartXY, aPrevArcEndXY) +model.assertLine(aLine, aLineStart, aLineEnd) +# verify newly created arc +anArc = model.lastSubFeature(aSketchFeature, "SketchArc") +aCenter = geomDataAPI_Point2D(anArc.attribute("center_point")) +aStart = geomDataAPI_Point2D(anArc.attribute("start_point")) +aEnd = geomDataAPI_Point2D(anArc.attribute("end_point")) +verifyPointOnLine(aCenter, aLine) +verifyPointOnLine(aStart, aLine) +verifyPointOnCircle(aEnd, aPrevArc) +model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 9) +model.testNbSubFeatures(aSketch, "SketchConstraintTangent", 0) + +#========================================================================= +# Test 6. Create one more arc by center and points coincident to other features +#========================================================================= +# get previous arc +aPrevArc = model.lastSubFeature(aSketchFeature, "SketchArc") +aPrevArcCenter = geomDataAPI_Point2D(aPrevArc.attribute("center_point")) +aPrevArcStart = geomDataAPI_Point2D(aPrevArc.attribute("start_point")) +aPrevArcEnd = geomDataAPI_Point2D(aPrevArc.attribute("end_point")) +aPrevArcCenterXY = [aPrevArcCenter.x(), aPrevArcCenter.y()] +aPrevArcStartXY = [aPrevArcStart.x(), aPrevArcStart.y()] +aPrevArcEndXY = [aPrevArcEnd.x(), aPrevArcEnd.y()] +# create new arc +aSession.startOperation() +anArc = aSketchFeature.addFeature("SketchMacroArc") +aCenter = geomDataAPI_Point2D(anArc.attribute("center_point")) +aCenterRef = anArc.refattr("center_point_ref") +aStart = geomDataAPI_Point2D(anArc.attribute("start_point_1")) +aStartRef = anArc.refattr("start_point_ref") +aEnd = geomDataAPI_Point2D(anArc.attribute("end_point_1")) +aEndRef = anArc.refattr("end_point_ref") +anArcType = anArc.string("arc_type") +# initialize attributes +anArcType.setValue("by_center_and_points") +delta = [aPrevArcEndXY[0] - aPrevArcCenterXY[0], aPrevArcEndXY[1] - aPrevArcCenterXY[1]] +aCenter.setValue(aPrevArcCenterXY[0] + 2 * delta[0], aPrevArcCenterXY[1] + 2 * delta[1]) +aStart.setValue(aPrevArcCenterXY[0] + 2 * delta[0] - 0.9 * delta[1], aPrevArcCenterXY[1] + 2 * delta[1] + 0.9 * delta[0]) +aEndRef.setObject(aPrevArc.lastResult()) +aEnd.setValue(aPrevArcCenterXY[0] + 1.1 * delta[0], aPrevArcCenterXY[1] + 1.1 * delta[1]) +aSession.finishOperation() +assert (aSketchFeature.numberOfSubs() == 18), "Number of subs {}".format(aSketchFeature.numberOfSubs()) +# verify newly created arc +anArc = model.lastSubFeature(aSketchFeature, "SketchArc") +aCenter = geomDataAPI_Point2D(anArc.attribute("center_point")) +aStart = geomDataAPI_Point2D(anArc.attribute("start_point")) +aEnd = geomDataAPI_Point2D(anArc.attribute("end_point")) +verifyPointOnCircle(aEnd, aPrevArc) +model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 10) +model.testNbSubFeatures(aSketch, "SketchConstraintTangent", 0) + +#========================================================================= +# Test 7. Create one more arc by center and points coincident to other features +#========================================================================= +aPrevArcCenterXY = [aPrevArcCenter.x(), aPrevArcCenter.y()] +aPrevArcStartXY = [aPrevArcStart.x(), aPrevArcStart.y()] +aPrevArcEndXY = [aPrevArcEnd.x(), aPrevArcEnd.y()] +# create new arc +aSession.startOperation() +anArc = aSketchFeature.addFeature("SketchMacroArc") +aCenter = geomDataAPI_Point2D(anArc.attribute("center_point")) +aCenterRef = anArc.refattr("center_point_ref") +aStart = geomDataAPI_Point2D(anArc.attribute("start_point_1")) +aStartRef = anArc.refattr("start_point_ref") +aEnd = geomDataAPI_Point2D(anArc.attribute("end_point_1")) +aEndRef = anArc.refattr("end_point_ref") +anArcType = anArc.string("arc_type") +# initialize attributes +anArcType.setValue("by_center_and_points") +delta = [aPrevArcEndXY[0] - aPrevArcCenterXY[0], aPrevArcEndXY[1] - aPrevArcCenterXY[1]] +aCenter.setValue(aPrevArcCenterXY[0] + 2 * delta[0], aPrevArcCenterXY[1] + 2 * delta[1]) +aStart.setValue(aPrevArcCenterXY[0] + 2 * delta[0] - delta[1], aPrevArcCenterXY[1] + 2 * delta[1] + delta[0]) +aEndRef.setObject(aPrevArc.lastResult()) +aEnd.setValue(aPrevArcCenterXY[0] + delta[0], aPrevArcCenterXY[1] + delta[1]) +aSession.finishOperation() +assert (aSketchFeature.numberOfSubs() == 20), "Number of subs {}".format(aSketchFeature.numberOfSubs()) +# verify newly created arc +anArc = model.lastSubFeature(aSketchFeature, "SketchArc") +aCenter = geomDataAPI_Point2D(anArc.attribute("center_point")) +aStart = geomDataAPI_Point2D(anArc.attribute("start_point")) +aEnd = geomDataAPI_Point2D(anArc.attribute("end_point")) +verifyPointOnCircle(aEnd, aPrevArc) +model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 11) +model.testNbSubFeatures(aSketch, "SketchConstraintTangent", 0) + #========================================================================= # End of test #========================================================================= diff --git a/src/SketchPlugin/Test/TestSplitLine.py b/src/SketchPlugin/Test/TestSplitLine.py new file mode 100644 index 000000000..bdabae161 --- /dev/null +++ b/src/SketchPlugin/Test/TestSplitLine.py @@ -0,0 +1,59 @@ +## Copyright (C) 2018-20xx 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 +## + +from SketchAPI import * + +from salome.shaper import model +from salome.shaper import geom + +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")) +SketchLine_1 = Sketch_1.addLine(-38.2842712474619, 18.28427124746191, -10, -10) +SketchLine_2 = Sketch_1.addLine(-10, -10, -10, 20) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchLine_3 = Sketch_1.addLine(-10, 20, -25, 5) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_1.result()) +SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), 40) +SketchConstraintMirror_1 = Sketch_1.addMirror(SketchLine_2.result(), [SketchLine_1.result(), SketchLine_3.result()]) +[SketchLine_4, SketchLine_5] = SketchConstraintMirror_1.mirrored() +model.do() + +model.testNbSubFeatures(Sketch_1, "SketchLine", 5) +model.testNbSubFeatures(Sketch_1, "SketchConstraintCoincidence", 3) +model.testNbSubFeatures(Sketch_1, "SketchConstraintLength", 1) +model.testNbSubFeatures(Sketch_1, "SketchConstraintMirror", 1) + +#perform split +SketchSplit = Sketch_1.addSplit(SketchLine_1, geom.Pnt2d(-12, -8)) +SketchSplit.execute() +model.do() + +model.testNbSubFeatures(Sketch_1, "SketchLine", 6) +model.testNbSubFeatures(Sketch_1, "SketchConstraintCoincidence", 5) +model.testNbSubFeatures(Sketch_1, "SketchConstraintLength", 1) +model.testNbSubFeatures(Sketch_1, "SketchConstraintMirror", 0) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestSplitPreview.py b/src/SketchPlugin/Test/TestSplitPreview.py new file mode 100644 index 000000000..ac59f9613 --- /dev/null +++ b/src/SketchPlugin/Test/TestSplitPreview.py @@ -0,0 +1,88 @@ +## Copyright (C) 2018-20xx 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 +## + +from salome.shaper import model + +from ModelAPI import * +from GeomDataAPI import * + +# base sketch +model.begin() +partSet = model.moduleDocument() +Part = model.addPart(partSet) +Part_doc = Part.document() +Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY")) +SketchLine_1 = Sketch.addLine(0, 20, 100, 20) +SketchLine_2 = Sketch.addLine(20, 0, 20, 40) +SketchLine_3 = Sketch.addLine(80, 0, 80, 40) +SketchCircle_1 = Sketch.addCircle(50, 50, 50) +SketchPoint_1 = Sketch.addPoint(20, 20) +SketchConstraintCoincidence_1 = Sketch.setCoincident(SketchPoint_1.coordinates(), SketchLine_2.result()) +SketchConstraintCoincidence_2 = Sketch.setCoincident(SketchPoint_1.coordinates(), SketchLine_1.result()) +SketchPoint_2 = Sketch.addPoint(80, 20) +SketchConstraintCoincidence_3 = Sketch.setCoincident(SketchPoint_2.coordinates(), SketchLine_1.result()) +SketchConstraintCoincidence_4 = Sketch.setCoincident(SketchPoint_2.coordinates(), SketchLine_3.result()) +SketchPoint_3 = Sketch.addPoint(20, 10) +SketchConstraintCoincidence_5 = Sketch.setCoincident(SketchPoint_3.coordinates(), SketchCircle_1.results()[1]) +SketchConstraintCoincidence_6 = Sketch.setCoincident(SketchPoint_3.coordinates(), SketchLine_2.result()) +SketchPoint_4 = Sketch.addPoint(80, 10) +SketchConstraintCoincidence_7 = Sketch.setCoincident(SketchPoint_4.coordinates(), SketchCircle_1.results()[1]) +SketchConstraintCoincidence_8 = Sketch.setCoincident(SketchPoint_4.coordinates(), SketchLine_3.result()) +model.do() +model.end() + +aSession = ModelAPI_Session.get() +aSketchFeature = featureToCompositeFeature(Sketch.feature()) + +# Create Split feature for a line +aSession.startOperation() +aSplit = aSketchFeature.addFeature("SketchSplit") +aSelectedObj = aSplit.reference("SelectedObject") +aSelectedObj.setValue(SketchLine_1.feature()) +aSelectedPoint = geomDataAPI_Point2D(aSplit.attribute("SelectedPoint")) +aSelectedPoint.setValue(50, 20) +aPreviewObj = aSplit.reference("PreviewObject") +aPreviewObj.setValue(SketchLine_1.feature()) +aPreviewPoint = geomDataAPI_Point2D(aSplit.attribute("PreviewPoint")) +aPreviewPoint.setValue(aSelectedPoint.pnt()) +aSession.finishOperation() + +model.testNbSubFeatures(Sketch, "SketchArc", 0) +model.testNbSubFeatures(Sketch, "SketchCircle", 1) +model.testNbSubFeatures(Sketch, "SketchLine", 5) +model.testNbSubFeatures(Sketch, "SketchConstraintCoincidence", 12) + +# Create Split feature for a circle to perform its substitution by an arc +aSession.startOperation() +aSplit = aSketchFeature.addFeature("SketchSplit") +aSelectedObj = aSplit.reference("SelectedObject") +aSelectedObj.setValue(SketchCircle_1.feature()) +aSelectedPoint = geomDataAPI_Point2D(aSplit.attribute("SelectedPoint")) +aSelectedPoint.setValue(50, 0) +aPreviewObj = aSplit.reference("PreviewObject") +aPreviewObj.setValue(SketchCircle_1.feature()) +aPreviewPoint = geomDataAPI_Point2D(aSplit.attribute("PreviewPoint")) +aPreviewPoint.setValue(aSelectedPoint.pnt()) +aSession.finishOperation() + +model.testNbSubFeatures(Sketch, "SketchArc", 2) +model.testNbSubFeatures(Sketch, "SketchCircle", 0) +model.testNbSubFeatures(Sketch, "SketchLine", 5) +model.testNbSubFeatures(Sketch, "SketchConstraintCoincidence", 16) diff --git a/src/SketchPlugin/Test/TestTrimLine03.py b/src/SketchPlugin/Test/TestTrimLine03.py new file mode 100644 index 000000000..acc9201ae --- /dev/null +++ b/src/SketchPlugin/Test/TestTrimLine03.py @@ -0,0 +1,59 @@ +## Copyright (C) 2018-20xx 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 +## + +from SketchAPI import * + +from salome.shaper import model +from salome.shaper import geom + +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")) +SketchLine_1 = Sketch_1.addLine(-38.2842712474619, 18.28427124746191, -10, -10) +SketchLine_2 = Sketch_1.addLine(-10, -10, -10, 20) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchLine_3 = Sketch_1.addLine(-10, 20, -25, 5) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_1.result()) +SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), 40) +SketchConstraintMirror_1 = Sketch_1.addMirror(SketchLine_2.result(), [SketchLine_1.result(), SketchLine_3.result()]) +[SketchLine_4, SketchLine_5] = SketchConstraintMirror_1.mirrored() +model.do() + +model.testNbSubFeatures(Sketch_1, "SketchLine", 5) +model.testNbSubFeatures(Sketch_1, "SketchConstraintCoincidence", 3) +model.testNbSubFeatures(Sketch_1, "SketchConstraintLength", 1) +model.testNbSubFeatures(Sketch_1, "SketchConstraintMirror", 1) + +#perform trim +SketchTrim = Sketch_1.addTrim(SketchLine_1, geom.Pnt2d(-12, -8)) +SketchTrim.execute() +model.do() + +model.testNbSubFeatures(Sketch_1, "SketchLine", 5) +model.testNbSubFeatures(Sketch_1, "SketchConstraintCoincidence", 2) +model.testNbSubFeatures(Sketch_1, "SketchConstraintLength", 1) +model.testNbSubFeatures(Sketch_1, "SketchConstraintMirror", 0) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestTrimPreview.py b/src/SketchPlugin/Test/TestTrimPreview.py new file mode 100644 index 000000000..8f5a641a4 --- /dev/null +++ b/src/SketchPlugin/Test/TestTrimPreview.py @@ -0,0 +1,76 @@ +## Copyright (C) 2018-20xx 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 +## + +from salome.shaper import model + +from ModelAPI import * +from GeomDataAPI import * + +# base sketch +model.begin() +partSet = model.moduleDocument() +Part = model.addPart(partSet) +Part_doc = Part.document() +Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY")) +SketchLine_1 = Sketch.addLine(0, 20, 100, 20) +SketchLine_2 = Sketch.addLine(20, 0, 20, 40) +SketchLine_3 = Sketch.addLine(80, 0, 80, 40) +SketchCircle_1 = Sketch.addCircle(50, 50, 50) +model.do() +model.end() + +aSession = ModelAPI_Session.get() +aSketchFeature = featureToCompositeFeature(Sketch.feature()) + +# Create Trim feature for a line +aSession.startOperation() +aTrim = aSketchFeature.addFeature("SketchTrim") +aSelectedObj = aTrim.reference("SelectedObject") +aSelectedObj.setValue(SketchLine_1.feature()) +aSelectedPoint = geomDataAPI_Point2D(aTrim.attribute("SelectedPoint")) +aSelectedPoint.setValue(50, 20) +aPreviewObj = aTrim.reference("PreviewObject") +aPreviewObj.setValue(SketchLine_1.feature()) +aPreviewPoint = geomDataAPI_Point2D(aTrim.attribute("PreviewPoint")) +aPreviewPoint.setValue(aSelectedPoint.pnt()) +aSession.finishOperation() + +model.testNbSubFeatures(Sketch, "SketchArc", 0) +model.testNbSubFeatures(Sketch, "SketchCircle", 1) +model.testNbSubFeatures(Sketch, "SketchLine", 4) +model.testNbSubFeatures(Sketch, "SketchConstraintCoincidence", 2) + +# Create Trim feature for a circle to perform its substitution by an arc +aSession.startOperation() +aTrim = aSketchFeature.addFeature("SketchTrim") +aSelectedObj = aTrim.reference("SelectedObject") +aSelectedObj.setValue(SketchCircle_1.feature()) +aSelectedPoint = geomDataAPI_Point2D(aTrim.attribute("SelectedPoint")) +aSelectedPoint.setValue(50, 0) +aPreviewObj = aTrim.reference("PreviewObject") +aPreviewObj.setValue(SketchCircle_1.feature()) +aPreviewPoint = geomDataAPI_Point2D(aTrim.attribute("PreviewPoint")) +aPreviewPoint.setValue(aSelectedPoint.pnt()) +aSession.finishOperation() + +model.testNbSubFeatures(Sketch, "SketchArc", 1) +model.testNbSubFeatures(Sketch, "SketchCircle", 0) +model.testNbSubFeatures(Sketch, "SketchLine", 4) +model.testNbSubFeatures(Sketch, "SketchConstraintCoincidence", 4)