From: azv Date: Thu, 6 Dec 2018 13:08:16 +0000 (+0300) Subject: [Code coverage FeaturesPlugin]: Test AIS presentation of Measurement feature X-Git-Tag: End2018~109 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e39fd49c0bdb7aa56982660ff4038da62eca3a6a;p=modules%2Fshaper.git [Code coverage FeaturesPlugin]: Test AIS presentation of Measurement feature --- diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index b2f130270..ce8169b38 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -272,6 +272,7 @@ ADD_UNIT_TESTS(TestExtrusion.py TestMeasurementRadius.py TestMeasurementAngle.py TestMeasurementAngle3Points.py + TestMeasurementPresentation.py TestFusionFaces.py Test1379.py Test1922.py diff --git a/src/FeaturesPlugin/FeaturesPlugin_Measurement.cpp b/src/FeaturesPlugin/FeaturesPlugin_Measurement.cpp index 5deb05c69..7d04b88d6 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Measurement.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Measurement.cpp @@ -323,6 +323,13 @@ AISObjectPtr FeaturesPlugin_Measurement::getAISObject(AISObjectPtr thePrevious) if ((aValues->size() == 0) || (aValues->value(0) <= Precision::Confusion())) return AISObjectPtr(); + if (!myScreenPlane) { + // initialize a default plane for dimension + GeomPointPtr anOrigin(new GeomAPI_Pnt(0., 0., 0.)); + GeomDirPtr aNormal(new GeomAPI_Dir(0., 0., 1.)); + myScreenPlane = GeomPlanePtr(new GeomAPI_Pln(anOrigin, aNormal)); + } + AISObjectPtr anAIS; std::string aKind = string(MEASURE_KIND())->value(); if (aKind == MEASURE_LENGTH()) @@ -342,8 +349,6 @@ AISObjectPtr FeaturesPlugin_Measurement::getAISObject(AISObjectPtr thePrevious) AISObjectPtr FeaturesPlugin_Measurement::lengthDimension(AISObjectPtr thePrevious) { AISObjectPtr aAISObj; - if (!myScreenPlane.get()) - return aAISObj; AttributeSelectionPtr aSelectedFeature = selection(EDGE_FOR_LENGTH_ID()); @@ -404,8 +409,6 @@ AISObjectPtr FeaturesPlugin_Measurement::lengthDimension(AISObjectPtr thePreviou AISObjectPtr FeaturesPlugin_Measurement::distanceDimension(AISObjectPtr thePrevious) { AISObjectPtr aAISObj; - if (!myScreenPlane.get()) - return aAISObj; AttributeSelectionPtr aFirstFeature = selection(DISTANCE_FROM_OBJECT_ID()); AttributeSelectionPtr aSecondFeature = selection(DISTANCE_TO_OBJECT_ID()); diff --git a/src/FeaturesPlugin/Test/TestMeasurementPresentation.py b/src/FeaturesPlugin/Test/TestMeasurementPresentation.py new file mode 100644 index 000000000..c64660c8a --- /dev/null +++ b/src/FeaturesPlugin/Test/TestMeasurementPresentation.py @@ -0,0 +1,83 @@ +## 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 ConfigAPI import * +Config_PropManager().registerProp("Visualization", "dimension_value_size", "Dimension value size", Config_Prop.IntSpin, "16") +Config_PropManager().registerProp("Visualization", "dimension_arrow_size", "Dimension arrow size", Config_Prop.IntSpin, "16") +Config_PropManager().registerProp("Visualization", "dimension_font", "Dimension font", Config_Prop.String, "Times-bold") +Config_PropManager().registerProp("Visualization", "sketch_dimension_color", "Dimension color", Config_Prop.Color, "64,128,225") + +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(-15.79157881408318, 17.46869043106789, -28.20135254460625, -14.21916935022164) +SketchLine_2 = Sketch_1.addLine(-28.20135254460625, -14.21916935022164, 5.332188506333114, -12.56026625936245) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchArc_1 = Sketch_1.addArc(-8.886980843888518, -0.1184930779185158, 5.332188506333114, -12.56026625936245, -15.79157881408318, 17.46869043106789, False) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchArc_1.startPoint()) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchArc_1.endPoint()) +model.do() +model.end() + +from ModelAPI import * + +aSession = ModelAPI_Session.get() +aSession.startOperation() +aMeasurement = Part_1_doc.addFeature("Measurement") +aMeasurement.string("MeasureKind").setValue("Length") +aMeasurement.selection("edge_for_length").selectSubShape("EDGE", "Sketch_1/SketchLine_1") +assert(featureToPresentation(aMeasurement).getAISObject(None) is not None) +aSession.finishOperation() + +aSession.startOperation() +aMeasurement = Part_1_doc.addFeature("Measurement") +aMeasurement.string("MeasureKind").setValue("Distance") +aMeasurement.selection("distance_from").selectSubShape("VERTEX", "Sketch_1/SketchLine_1_StartVertex") +aMeasurement.selection("distance_to").selectSubShape("EDGE", "Sketch_1/SketchLine_2") +assert(featureToPresentation(aMeasurement).getAISObject(None) is not None) +aSession.finishOperation() + +aSession.startOperation() +aMeasurement = Part_1_doc.addFeature("Measurement") +aMeasurement.string("MeasureKind").setValue("Radius") +aMeasurement.selection("circular").selectSubShape("EDGE", "Sketch_1/SketchArc_1_2") +assert(featureToPresentation(aMeasurement).getAISObject(None) is not None) +aSession.finishOperation() + +aSession.startOperation() +aMeasurement = Part_1_doc.addFeature("Measurement") +aMeasurement.string("MeasureKind").setValue("Angle") +aMeasurement.selection("angle_from").selectSubShape("EDGE", "Sketch_1/SketchLine_1") +aMeasurement.selection("angle_to").selectSubShape("EDGE", "Sketch_1/SketchLine_2") +assert(featureToPresentation(aMeasurement).getAISObject(None) is not None) +aSession.finishOperation() + +aSession.startOperation() +aMeasurement = Part_1_doc.addFeature("Measurement") +aMeasurement.string("MeasureKind").setValue("AngleBy3Points") +aMeasurement.selection("angle_point_1").selectSubShape("VERTEX", "Sketch_1/SketchLine_1_StartVertex") +aMeasurement.selection("angle_point_2").selectSubShape("VERTEX", "Sketch_1/SketchLine_1_EndVertex") +aMeasurement.selection("angle_point_3").selectSubShape("VERTEX", "Sketch_1/SketchLine_2_EndVertex") +assert(featureToPresentation(aMeasurement).getAISObject(None) is not None) +aSession.finishOperation()