From: azv Date: Tue, 4 Dec 2018 15:53:12 +0000 (+0300) Subject: [Code coverage SketchPlugin]: Increase coverage for Distance, Trim and Split features X-Git-Tag: End2018~119 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=17a92ca96c8ead228aece7abea515e54a2c1c11a;p=modules%2Fshaper.git [Code coverage SketchPlugin]: Increase coverage for Distance, Trim and Split features --- diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index ce0c7406a..4d399b188 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -264,6 +264,7 @@ ADD_UNIT_TESTS( TestTrimArc05.py TestTrimArc06.py TestTrimArc07.py + TestTrimArc08.py TestTrimCircle01.py TestTrimCircle02.py TestTrimCircle03.py diff --git a/src/SketchPlugin/Test/TestConstraintDistance.py b/src/SketchPlugin/Test/TestConstraintDistance.py index 46ce2e4d1..a36c17835 100644 --- a/src/SketchPlugin/Test/TestConstraintDistance.py +++ b/src/SketchPlugin/Test/TestConstraintDistance.py @@ -171,6 +171,25 @@ assert (refattrB.isInitialized()) assert (aDistance.isInitialized()) assert math.fabs(aDistance.value() - aDist) < 1.e-4, "Distance values are different: {0} != {1}".format(aDistance.value(), aDist) assert (model.dof(aSketchFeature) == 5) + +#========================================================================= +# Swap point and line in the distance +#========================================================================= +aSession.startOperation() +refattrA.setAttr(aSketchPointCoords) +refattrB.setObject(aLineResult) +aSession.finishOperation() +assert (model.dof(aSketchFeature) == 5) +# set flyout point then abort operation, after that check the Distance is correct +aSession.startOperation() +aFlyoutPoint = geomDataAPI_Point2D(aConstraint.attribute("ConstraintFlyoutValuePnt")) +aFlyoutPoint.setValue(100.0, 100.0) +aSession.abortOperation() +assert (refattrA.isInitialized()) +assert (refattrB.isInitialized()) +assert (aDistance.isInitialized()) +assert math.fabs(aDistance.value() - aDist) < 1.e-4, "Distance values are different: {0} != {1}".format(aDistance.value(), aDist) +assert (model.dof(aSketchFeature) == 5) #========================================================================= # Change distance value #========================================================================= diff --git a/src/SketchPlugin/Test/TestPresentation.py b/src/SketchPlugin/Test/TestPresentation.py index 499d97ad2..f4ebf9eb5 100644 --- a/src/SketchPlugin/Test/TestPresentation.py +++ b/src/SketchPlugin/Test/TestPresentation.py @@ -20,12 +20,13 @@ """ TestPresentation.py - Test AIS presentations for constraints + Test AIS presentations for constraints and macro-features """ from salome.shaper import model from GeomAPI import * from ModelAPI import * +from GeomDataAPI import * from ConfigAPI import * Config_PropManager().registerProp("Visualization", "dimension_value_size", "Dimension value size", Config_Prop.IntSpin, "16") @@ -98,4 +99,32 @@ aFillet.refattr("fillet_point").setAttr(SketchLine_1.endPoint()); assert(featureToPresentation(aFillet).getAISObject(None) is not None) aSession.finishOperation() +# Test presentation for MacroCircle on low-level +aSession.startOperation() +aCircle = aSketchFeature.addFeature("SketchMacroCircle") +aCirclePnt1 = geomDataAPI_Point2D(aCircle.attribute("first_point")) +aCirclePnt2 = geomDataAPI_Point2D(aCircle.attribute("second_point")) +aCirclePnt3 = geomDataAPI_Point2D(aCircle.attribute("third_point")) +aCircleType = aCircle.string("circle_type") +aCircleType.setValue("circle_type_by_three_points") +aCirclePnt1.setValue(10, 0) +aCirclePnt2.setValue(-10, 0) +aCirclePnt3.setValue(0, 10) +assert(featureToPresentation(aCircle).getAISObject(None) is not None) +aSession.finishOperation() + +# Test presentation for MacroArc on low-level +aSession.startOperation() +anArc = aSketchFeature.addFeature("SketchMacroArc") +anArcPnt1 = geomDataAPI_Point2D(anArc.attribute("start_point_2")) +anArcPnt2 = geomDataAPI_Point2D(anArc.attribute("end_point_2")) +anArcPnt3 = geomDataAPI_Point2D(anArc.attribute("passed_point")) +anArcType = anArc.string("arc_type") +anArcType.setValue("by_three_points") +anArcPnt1.setValue(5, 0) +anArcPnt2.setValue(-5, 0) +anArcPnt3.setValue(0, 5) +assert(featureToPresentation(anArc).getAISObject(None) is not None) +aSession.finishOperation() + model.end() diff --git a/src/SketchPlugin/Test/TestSplitPreview.py b/src/SketchPlugin/Test/TestSplitPreview.py index ac59f9613..c4bb13798 100644 --- a/src/SketchPlugin/Test/TestSplitPreview.py +++ b/src/SketchPlugin/Test/TestSplitPreview.py @@ -62,6 +62,7 @@ aPreviewObj = aSplit.reference("PreviewObject") aPreviewObj.setValue(SketchLine_1.feature()) aPreviewPoint = geomDataAPI_Point2D(aSplit.attribute("PreviewPoint")) aPreviewPoint.setValue(aSelectedPoint.pnt()) +assert(featureToPresentation(aSplit).getAISObject(None) is not None) aSession.finishOperation() model.testNbSubFeatures(Sketch, "SketchArc", 0) @@ -80,6 +81,7 @@ aPreviewObj = aSplit.reference("PreviewObject") aPreviewObj.setValue(SketchCircle_1.feature()) aPreviewPoint = geomDataAPI_Point2D(aSplit.attribute("PreviewPoint")) aPreviewPoint.setValue(aSelectedPoint.pnt()) +assert(featureToPresentation(aSplit).getAISObject(None) is not None) aSession.finishOperation() model.testNbSubFeatures(Sketch, "SketchArc", 2) diff --git a/src/SketchPlugin/Test/TestTrimArc08.py b/src/SketchPlugin/Test/TestTrimArc08.py new file mode 100644 index 000000000..fbf25849f --- /dev/null +++ b/src/SketchPlugin/Test/TestTrimArc08.py @@ -0,0 +1,68 @@ +## 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 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(12, -8, -12, -8) +SketchLine_2 = Sketch_1.addLine(-12, -8, -12, 20) +SketchLine_3 = Sketch_1.addLine(-12, 20, 12, 20) +SketchLine_4 = Sketch_1.addLine(12, 20, 12, -8) +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()) +SketchArc_1 = Sketch_1.addArc(0, -3, 20, -3, -20, -3, False) +SketchLine_5 = Sketch_1.addLine(20, -3, 20, -30) +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_5.startPoint()) +SketchLine_6 = Sketch_1.addLine(20, 17, 50, 17) +SketchConstraintTangent_1 = Sketch_1.setTangent(SketchLine_5.result(), SketchArc_1.results()[1]) +SketchConstraintTangent_2 = Sketch_1.setTangent(SketchLine_6.result(), SketchArc_1.results()[1]) +model.do() + +model.testNbSubFeatures(Sketch_1, "SketchArc", 1) +model.testNbSubFeatures(Sketch_1, "SketchLine", 6) +model.testNbSubFeatures(Sketch_1, "SketchConstraintCoincidence", 5) +model.testNbSubFeatures(Sketch_1, "SketchConstraintTangent", 2) +model.testNbSubFeatures(Sketch_1, "SketchConstraintEqual", 0) + +# perform trim +SketchTrim = Sketch_1.addTrim(SketchArc_1, geom.Pnt2d(0, 17)) +SketchTrim.execute() +model.do() + +model.testNbSubFeatures(Sketch_1, "SketchArc", 2) +model.testNbSubFeatures(Sketch_1, "SketchLine", 6) +model.testNbSubFeatures(Sketch_1, "SketchConstraintCoincidence", 8) +model.testNbSubFeatures(Sketch_1, "SketchConstraintTangent", 2) +model.testNbSubFeatures(Sketch_1, "SketchConstraintEqual", 1) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestTrimPreview.py b/src/SketchPlugin/Test/TestTrimPreview.py index 8f5a641a4..0f018cf18 100644 --- a/src/SketchPlugin/Test/TestTrimPreview.py +++ b/src/SketchPlugin/Test/TestTrimPreview.py @@ -50,6 +50,7 @@ aPreviewObj = aTrim.reference("PreviewObject") aPreviewObj.setValue(SketchLine_1.feature()) aPreviewPoint = geomDataAPI_Point2D(aTrim.attribute("PreviewPoint")) aPreviewPoint.setValue(aSelectedPoint.pnt()) +assert(featureToPresentation(aTrim).getAISObject(None) is not None) aSession.finishOperation() model.testNbSubFeatures(Sketch, "SketchArc", 0) @@ -68,6 +69,7 @@ aPreviewObj = aTrim.reference("PreviewObject") aPreviewObj.setValue(SketchCircle_1.feature()) aPreviewPoint = geomDataAPI_Point2D(aTrim.attribute("PreviewPoint")) aPreviewPoint.setValue(aSelectedPoint.pnt()) +assert(featureToPresentation(aTrim).getAISObject(None) is not None) aSession.finishOperation() model.testNbSubFeatures(Sketch, "SketchArc", 1)