From: Clarisse Genrault Date: Mon, 6 Feb 2017 15:19:55 +0000 (+0100) Subject: Adding tests for "Box" primitive. X-Git-Tag: V_2.7.0~289 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6ebb9744bc16a770e3189b691632a32f25a09f92;p=modules%2Fshaper.git Adding tests for "Box" primitive. --- diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp index 97c13ddde..05b15667f 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp @@ -37,22 +37,22 @@ bool GeomAlgoAPI_Box::check() { if (myMethodType == MethodType::BOX_DIM) { if (myDx < Precision::Confusion()) { - myError = "Box builder with dimensions :: Dx is null."; + myError = "Box builder with dimensions :: Dx is null or negative."; return false; } else if (myDy < Precision::Confusion()) { - myError = "Box builder with dimensions :: Dy is null."; + myError = "Box builder with dimensions :: Dy is null or negative."; return false; } else if (myDz < Precision::Confusion()) { - myError = "Box builder with dimensions :: Dz is null."; + myError = "Box builder with dimensions :: Dz is null or negative."; return false; } } else if (myMethodType == MethodType::BOX_POINTS) { if (!myFirstPoint.get()) { - myError = "Box builder with points :: the first point is not a correct"; + myError = "Box builder with points :: the first point is not correct."; return false; } if (!mySecondPoint.get()) { - myError = "Box builder with points :: the second point is not a correct"; + myError = "Box builder with points :: the second point is not correct."; return false; } if (myFirstPoint->distance(mySecondPoint) < Precision::Confusion()) { @@ -66,7 +66,7 @@ bool GeomAlgoAPI_Box::check() fabs(aDiffY) < Precision::Confusion() || fabs(aDiffZ) < Precision::Confusion()) { myError = - "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes"; + "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes."; return false; } } else { diff --git a/src/GeomAlgoAPI/Test/TestAPI_Box.py b/src/GeomAlgoAPI/Test/TestAPI_Box.py index 01103fafe..c3d445d5f 100644 --- a/src/GeomAlgoAPI/Test/TestAPI_Box.py +++ b/src/GeomAlgoAPI/Test/TestAPI_Box.py @@ -10,38 +10,112 @@ from GeomAPI import GeomAPI_Pnt as pnt # Create a box with dimensions try : - box1 = shaperpy.makeBox(5.,15.,5.) + box1 = shaperpy.makeBox(10.,10.,10.) + print "box1 : ok" except myExcept,ec: - print ec.what() + print "box1 : ko (" + ec.what() + ")" + +try : + box2 = shaperpy.makeBox(0.,10.,10.) + print "box2 : ok" + +except myExcept,ec: + print "box2 : ko (" + ec.what() + ")" + +try : + box3 = shaperpy.makeBox(10.,0.,10.) + print "box3 : ok" + +except myExcept,ec: + print "box3 : ko (" + ec.what() + ")" + +try : + box4 = shaperpy.makeBox(10.,10.,0.) + print "box4 : ok" + +except myExcept,ec: + print "box4 : ko (" + ec.what() + ")" + +try : + box5 = shaperpy.makeBox(-10.,10.,10.) + print "box5 : ok" + +except myExcept,ec: + print "box5 : ko (" + ec.what() + ")" + +try : + box6 = shaperpy.makeBox(10.,-10.,10.) + print "box6 : ok" + +except myExcept,ec: + print "box6 : ko (" + ec.what() + ")" + +try : + box7 = shaperpy.makeBox(10.,10.,-10.) + print "box7 : ok" + +except myExcept,ec: + print "box7 : ko (" + ec.what() + ")" # Create a box with two points defining the diagonal try : pnt1 = pnt(0.,0.,0.) - pnt2 = pnt(10.,10.,10.) - box2 = shaperpy.makeBox(pnt1,pnt2) + pnt2 = pnt(50.,50.,50.) + box8 = shaperpy.makeBox(pnt1,pnt2) + print "box8 : ok" + +except myExcept,ec: + print "box8 : ko (" + ec.what() + ")" + +try : + pnt1 = pnt(0.,0.,0.) + box9 = shaperpy.makeBox(pnt1,pnt1) + print "box9 : ok" except myExcept,ec: - print ec.what() + print "box9 : ko (" + ec.what() + ")" -# Create a box with null dimensions try : - box3 = shaperpy.makeBox(0.,0.,0.) + pnt1 = pnt(0.,0.,0.) + pnt2 = pnt(0.,50.,50.) + box10 = shaperpy.makeBox(pnt1,pnt2) + print "box10 : ok" except myExcept,ec: - print ec.what() + print "box10 : ko (" + ec.what() + ")" -# Create a box with negative dimensions try : - box4 = shaperpy.makeBox(-5.,15.,5.) + pnt1 = pnt(0.,0.,0.) + pnt2 = pnt(50.,0.,50.) + box11 = shaperpy.makeBox(pnt1,pnt2) + print "box11 : ok" except myExcept,ec: - print ec.what() + print "box11 : ko (" + ec.what() + ")" -# Create a box with two same points try : pnt1 = pnt(0.,0.,0.) - box5 = shaperpy.makeBox(pnt1,pnt1) + pnt2 = pnt(50.,50.,0.) + box12 = shaperpy.makeBox(pnt1,pnt2) + print "box12 : ok" + +except myExcept,ec: + print "box12 : ko (" + ec.what() + ")" + +try : + pnt1 = pnt(50.,50.,50.) + box13 = shaperpy.makeBox(pnt1,None) + print "box13 : ok" except myExcept,ec: - print ec.what() \ No newline at end of file + print "box13 : ko (" + ec.what() + ")" + +try : + pnt2 = pnt(50.,50.,50.) + box14 = shaperpy.makeBox(None,pnt2) + print "box14 : ok" + +except myExcept,ec: + print "box14 : ko (" + ec.what() + ")" + diff --git a/src/PrimitivesAPI/Test/TestBox.py b/src/PrimitivesAPI/Test/TestBox.py index 08b2d9f27..a88f6c2d4 100644 --- a/src/PrimitivesAPI/Test/TestBox.py +++ b/src/PrimitivesAPI/Test/TestBox.py @@ -20,34 +20,141 @@ aSession.finishOperation() # Create a box with dimensions aSession.startOperation() aBox1 = model.addBox(aDocument, 10, 10, 10).result() -aSession.finishOperation() assert (aBox1 is not None) +print "box1 : ok" +aSession.finishOperation() + +aSession.startOperation() +aBox2 = model.addBox(aDocument, 0, 10, 10) +assert (len(aBox2.results()) == 0) +print "box2 : ko (" + aBox2.feature().error() + ")" +aSession.finishOperation() -# Create a first point aSession.startOperation() -aFirstPoint = model.addPoint(aDocument, 0, 0, 0).result() +aBox3 = model.addBox(aDocument, 10, 0, 10) +assert (len(aBox3.results()) == 0) +print "box3 : ko (" + aBox3.feature().error() + ")" aSession.finishOperation() -# Create a second point aSession.startOperation() -aSecondPoint = model.addPoint(aDocument, 50, 50, 50).result() +aBox4 = model.addBox(aDocument, 10, 10, 0) +assert (len(aBox4.results()) == 0) +print "box4 : ko (" + aBox4.feature().error() + ")" +aSession.finishOperation() + +aSession.startOperation() +aBox5 = model.addBox(aDocument, -10, 10, 10) +assert (len(aBox5.results()) == 0) +print "box5 : ko (" + aBox5.feature().error() + ")" +aSession.finishOperation() + +aSession.startOperation() +aBox6 = model.addBox(aDocument, 10, -10, 10) +assert (len(aBox6.results()) == 0) +print "box6 : ko (" + aBox6.feature().error() + ")" +aSession.finishOperation() + +aSession.startOperation() +aBox7 = model.addBox(aDocument, 10, 10, -10) +assert (len(aBox7.results()) == 0) +print "box7 : ko (" + aBox7.feature().error() + ")" aSession.finishOperation() # Create a box with 2 points aSession.startOperation() -aBox2 = model.addBox(aDocument, aFirstPoint, aSecondPoint).result() +aPoint1 = model.addPoint(aDocument, 0, 0, 0).result() +aPoint2 = model.addPoint(aDocument, 50, 50, 50).result() +aBox8 = model.addBox(aDocument, aPoint1, aPoint2).result() +assert (aBox8 is not None) +print "box8 : ok" + +aSession.startOperation() +aPoint1 = model.addPoint(aDocument, 0, 0, 0).result() +aBox9 = model.addBox(aDocument, aPoint1, aPoint1) +assert (len(aBox9.results()) == 0) +print "box9 : ko (" + aBox9.feature().error() + ")" +aSession.finishOperation() + +aSession.startOperation() +aPoint1 = model.addPoint(aDocument, 0, 0, 0).result() +aPoint2 = model.addPoint(aDocument, 0, 50, 50).result() +aBox10 = model.addBox(aDocument, aPoint1, aPoint2) +assert (len(aBox10.results()) == 0) +print "box10 : ko (" + aBox10.feature().error() + ")" aSession.finishOperation() -assert (aBox2 is not None) -# Create a box with dimensions (error) aSession.startOperation() -aBox3 = model.addBox(aDocument, -10, 10, 10).result() +aPoint1 = model.addPoint(aDocument, 0, 0, 0).result() +aPoint2 = model.addPoint(aDocument, 50, 0, 50).result() +aBox11 = model.addBox(aDocument, aPoint1, aPoint2) +assert (len(aBox11.results()) == 0) +print "box11 : ko (" + aBox11.feature().error() + ")" aSession.finishOperation() -assert (aBox3 is not None) -# Create a box with 2 points (error) aSession.startOperation() -aBox4 = model.addBox(aDocument, aFirstPoint, aFirstPoint).result() +aPoint1 = model.addPoint(aDocument, 0, 0, 0).result() +aPoint2 = model.addPoint(aDocument, 50, 50, 0).result() +aBox12 = model.addBox(aDocument, aPoint1, aPoint2) +assert (len(aBox12.results()) == 0) +print "box12 : ko (" + aBox12.feature().error() + ")" aSession.finishOperation() -assert (aBox4 is not None) +aSession.startOperation() +aPoint1 = model.selection("VERTEX", "point1") +aPoint2 = model.addPoint(aDocument, 50, 50, 0).result() +aBox13 = model.addBox(aDocument, aPoint1, aPoint2) +assert (len(aBox13.results()) == 0) +print "box13 : ko (" + aBox13.feature().error() + ")" +aSession.finishOperation() + +aSession.startOperation() +aPoint1 = model.addPoint(aDocument, 0, 0, 0).result() +aPoint2 = model.selection("VERTEX", "point2") +aBox14 = model.addBox(aDocument, aPoint1, aPoint2) +assert (len(aBox14.results()) == 0) +print "box14 : ko (" + aBox14.feature().error() + ")" +aSession.finishOperation() + +aSession.startOperation() +Sketch_1 = model.addSketch(aDocument, model.defaultPlane("XOY")) +Sketch_2 = model.addSketch(aDocument, model.defaultPlane("YOZ")) +SketchLine_1 = Sketch_1.addLine(20, 10, 40, 10) +SketchLine_2 = Sketch_1.addLine(40, 10, 40, 20) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchLine_3 = Sketch_1.addLine(40, 20, 20, 20) +SketchLine_4 = Sketch_1.addLine(20, 20, 20, 10) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_4.endPoint()) +SketchLine_5 = Sketch_2.addLine(20, 10, 40, 10) +SketchLine_6 = Sketch_2.addLine(40, 10, 40, 20) +SketchConstraintCoincidence_1 = Sketch_2.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint()) +SketchLine_7 = Sketch_2.addLine(40, 20, 20, 20) +SketchLine_8 = Sketch_2.addLine(20, 20, 20, 10) +SketchConstraintCoincidence_3 = Sketch_2.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint()) +SketchConstraintCoincidence_4 = Sketch_2.setCoincident(SketchLine_5.startPoint(), SketchLine_8.endPoint()) +aSession.finishOperation() + +aSession.startOperation() +aBox15 = model.addBox(aDocument, model.selection("VERTEX", "Sketch_1/Vertex-SketchLine_1s-SketchLine_4e"), + model.selection("VERTEX", "Sketch_2/Vertex-SketchLine_7s-SketchLine_6e")) +assert (aBox15 is not None) +print "box15 : ok" +aSession.finishOperation() + +aSession.startOperation() +Extrusion_1 = model.addExtrusion(aDocument, [model.selection("COMPOUND", "Sketch_1")], model.selection("EDGE", "PartSet/OZ"), 100, 0) +Extrusion_2 = model.addExtrusion(aDocument, [model.selection("COMPOUND", "Sketch_2")], model.selection("EDGE", "PartSet/OX"), 100, 0) +aBox16 = model.addBox(aDocument, model.selection("VERTEX", "Extrusion_1_1/Generated_Face_3&Extrusion_1_1/Generated_Face_2&Extrusion_1_1/To_Face_1"), + model.selection("VERTEX", "Extrusion_2_1/Generated_Face_2&Extrusion_2_1/Generated_Face_1&Extrusion_2_1/To_Face_1")) +assert (aBox16 is not None) +print "box16 : ok" +aSession.finishOperation() + +aSession.startOperation() + +Vertex_1 = model.addVertex(aDocument, [model.selection("VERTEX", "Sketch_1/Vertex-SketchLine_1s-SketchLine_4e")]) +Vertex_2 = model.addVertex(aDocument, [model.selection("VERTEX", "Sketch_2/Vertex-SketchLine_7s-SketchLine_6e")]) +aBox17 = model.addBox(aDocument, model.selection("VERTEX", "Vertex_1_1"), model.selection("VERTEX", "Vertex_2_1")) +assert (aBox17 is not None) +print "box17 : ok" +aSession.finishOperation() diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp b/src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp index 554e7012b..e863e20ca 100644 --- a/src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp @@ -15,6 +15,7 @@ #include #include +#include //================================================================================================= PrimitivesPlugin_Box::PrimitivesPlugin_Box() // Nothing to do during instantiation @@ -61,8 +62,7 @@ void PrimitivesPlugin_Box::createBoxByDimensions() // These checks should be made to the GUI for the feature but // the corresponding validator does not exist yet. if (!aBoxAlgo->check()) { - // The error is not displayed in a popup window. It must be in the status bar. - setError(aBoxAlgo->getError(), false); + setError(aBoxAlgo->getError()); return; } @@ -110,8 +110,7 @@ void PrimitivesPlugin_Box::createBoxByTwoPoints() // These checks should be made to the GUI for the feature but // the corresponding validator does not exist yet. if (!aBoxAlgo->check()) { - // The error is not displayed in a popup window. It must be in the message console. - setError(aBoxAlgo->getError(), false); + setError(aBoxAlgo->getError()); return; } @@ -121,12 +120,12 @@ void PrimitivesPlugin_Box::createBoxByTwoPoints() // Check if the creation of the box if(!aBoxAlgo->isDone()) { // The error is not displayed in a popup window. It must be in the message console. - setError(aBoxAlgo->getError(), false); + setError(aBoxAlgo->getError()); return; } if(!aBoxAlgo->checkValid("Box builder with two points")) { // The error is not displayed in a popup window. It must be in the message console. - setError(aBoxAlgo->getError(), false); + setError(aBoxAlgo->getError()); return; } diff --git a/src/PrimitivesPlugin/box_widget.xml b/src/PrimitivesPlugin/box_widget.xml index 4ec2cda67..8f0f205d5 100644 --- a/src/PrimitivesPlugin/box_widget.xml +++ b/src/PrimitivesPlugin/box_widget.xml @@ -11,7 +11,6 @@ min = "0.0" icon="" tooltip="Dimension in X"> - - - @@ -40,15 +37,12 @@ icon="icons/Primitives/point.png" tooltip="Select a first point" shape_types="vertex"> - - -