X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPythonAPI%2Fmodel%2Fsketcher%2Ftests.py;h=388f448f9573d098a0a7e47b787c40fd43eed794;hb=ca95b8880b63f9998cb09d3ea7d91716f3ea4390;hp=75217d0658f3cbbc4dfe59879b9d61b70729aa31;hpb=be3eee3bc693e26956b8625236076f3a70fd8491;p=modules%2Fshaper.git diff --git a/src/PythonAPI/model/sketcher/tests.py b/src/PythonAPI/model/sketcher/tests.py index 75217d065..388f448f9 100644 --- a/src/PythonAPI/model/sketcher/tests.py +++ b/src/PythonAPI/model/sketcher/tests.py @@ -1,22 +1,21 @@ -## Copyright (C) 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 -## +# Copyright (C) 2017-2020 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 ModelAPI import * from GeomDataAPI import * @@ -109,3 +108,89 @@ def checkSketchErrorDegenerated(theSketch): errorValue = theSketch.solverError().value() assert(errorValue != "") assert(errorValue.find("degenerated") >= 0) + + +def compareSketches(theReference, theSketch, TOLERANCE = 1.e-5): + """ Compare sketches for the sequence of features + """ + errors = "" + + # compare sketches degree of freedom + if tools.dof(theReference) != tools.dof(theSketch): + errors += "\nError in DoF (actual = {}, expected = {})".format(tools.dof(theSketch), tools.dof(theReference)) + + # compare sketch solver error + if theReference.solverError().value() != theSketch.solverError().value(): + errors += "\nError in solver message (actual = '{}', expected = '{}')".format(theSketch.solverError().value(), theReference.solverError().value()) + + aRefSketch = featureToCompositeFeature(theReference.feature()) + anActualSketch = featureToCompositeFeature(theSketch.feature()) + + # compare number of subs + aRefNbSubs = aRefSketch.numberOfSubs() + anActualNbSubs = anActualSketch.numberOfSubs() + if aRefNbSubs != anActualNbSubs: + errors += "\nError in number of sub-features (actual = {}, expected = {})".format(anActualNbSubs, aRefNbSubs) + + for index in range(min(aRefNbSubs, anActualNbSubs)): + aRefFeature = aRefSketch.subFeature(index) + aFeature = anActualSketch.subFeature(index) + # compare types of subs + if aFeature.getKind() != aRefFeature.getKind(): + errors += "\nWrong sketch feature (actual = '{}', expected = '{}')".format(aFeature.name(), aRefFeature.name()) + continue + # compare attributes + aRefAttrs = aRefFeature.data().attributes("") + anAttrs = aFeature.data().attributes("") + for ref, attr in zip(aRefAttrs, anAttrs): + if ref.attributeType() != attr.attributeType(): + errors += "\nWrong sequence of attributes (feature = '{}', reference = '{}')".format(aFeature.name(), aRefFeature.name()) + elif not attr.isInitialized() or not ref.isInitialized(): + if attr.isInitialized() != ref.isInitialized(): + errors += "\nAttribute '{}' initialization is different (feature = '{}', reference = '{}'): actual = {}, expected = {}".format(attr.id(), aFeature.name(), aRefFeature.name(), attr.isInitialized(), ref.isInitialized()) + elif ref.attributeType() == GeomDataAPI_Point2D.typeId(): + aRefPoint = geomDataAPI_Point2D(ref) + aPoint = geomDataAPI_Point2D(attr) + if tools.distancePointPoint(aPoint, aRefPoint) > TOLERANCE: + errors += "\nWrong coordinates '{}' (feature = '{}', reference = '{}'): actual = ({}, {}), expected = ({}, {})".format(attr.id(), aFeature.name(), aRefFeature.name(), aPoint.x(), aPoint.y(), aRefPoint.x(), aRefPoint.y()) + elif ref.attributeType() == GeomDataAPI_Point2DArray.typeId(): + aRefPoints = geomDataAPI_Point2DArray(ref) + aPoints = geomDataAPI_Point2DArray(attr) + for pInd in range(aRefPoints.size()): + aRefPoint = aRefPoints.pnt(pInd) + aPoint = aPoints.pnt(pInd) + if tools.distancePointPoint(aPoint, aRefPoint) > TOLERANCE: + errors += "\nWrong coordinates '{}', index {} (feature = '{}', reference = '{}'): actual = ({}, {}), expected = ({}, {})".format(attr.id(), pInd, aFeature.name(), aRefFeature.name(), aPoint.x(), aPoint.y(), aRefPoint.x(), aRefPoint.y()) + elif ref.attributeType() == ModelAPI_AttributeBoolean.typeId(): + aRefVal = modelAPI_AttributeBoolean(ref).value() + aVal = modelAPI_AttributeBoolean(attr).value() + if aVal != aRefVal: + errors += "\nWrong boolean value '{}' (feature = '{}', reference = '{}'): actual = {}, expected = {}".format(attr.id(), aFeature.name(), aRefFeature.name(), aVal, aRefVal) + elif ref.attributeType() == ModelAPI_AttributeDouble.typeId(): + aRefVal = modelAPI_AttributeDouble(ref).value() + aVal = modelAPI_AttributeDouble(attr).value() + if math.fabs(aVal - aRefVal) > TOLERANCE: + errors += "\nWrong real value '{}' (feature = '{}', reference = '{}'): actual = {}, expected = {}".format(attr.id(), aFeature.name(), aRefFeature.name(), aVal, aRefVal) + elif ref.attributeType() == ModelAPI_AttributeDoubleArray.typeId(): + aRefArray = modelAPI_AttributeDoubleArray(ref) + anArray = modelAPI_AttributeDoubleArray(attr) + for vInd in range(aRefArray.size()): + aRefVal = aRefArray.value(vInd) + aVal = anArray.value(vInd) + if math.fabs(aVal - aRefVal) > TOLERANCE: + errors += "\nWrong real value '{}' index {} (feature = '{}', reference = '{}'): actual = {}, expected = {}".format(attr.id(), vInd, aFeature.name(), aRefFeature.name(), aVal, aRefVal) + elif ref.attributeType() == ModelAPI_AttributeInteger.typeId(): + aRefVal = modelAPI_AttributeInteger(ref).value() + aVal = modelAPI_AttributeInteger(attr).value() + if aVal != aRefVal: + errors += "\nWrong integer value '{}' (feature = '{}', reference = '{}'): actual = {}, expected = {}".format(attr.id(), aFeature.name(), aRefFeature.name(), aVal, aRefVal) + elif ref.attributeType() == ModelAPI_AttributeIntArray.typeId(): + aRefArray = modelAPI_AttributeIntArray(ref) + anArray = modelAPI_AttributeIntArray(attr) + for vInd in range(aRefArray.size()): + aRefVal = aRefArray.value(vInd) + aVal = anArray.value(vInd) + if aVal != aRefVal: + errors += "\nWrong integer value '{}' index {} (feature = '{}', reference = '{}'): actual = {}, expected = {}".format(attr.id(), vInd, aFeature.name(), aRefFeature.name(), aVal, aRefVal) + + return errors