Salome HOME
Adding tests for "Box" primitive.
authorClarisse Genrault <clarisse.genrault@cea.fr>
Mon, 6 Feb 2017 15:19:55 +0000 (16:19 +0100)
committerClarisse Genrault <clarisse.genrault@cea.fr>
Mon, 6 Feb 2017 15:19:55 +0000 (16:19 +0100)
src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp
src/GeomAlgoAPI/Test/TestAPI_Box.py
src/PrimitivesAPI/Test/TestBox.py
src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp
src/PrimitivesPlugin/box_widget.xml

index 97c13ddde1c6bedd5c3da86cc4645df0794d2f0c..05b15667fd4f9b091b81b96bff6dc6fdecb18333 100644 (file)
@@ -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 {
index 01103fafe81a33bf044ed30b077ea373960c21c2..c3d445d5fa70b4b9e6292fbbf018c12c48c0d9c2 100644 (file)
@@ -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() + ")"
+  
index 08b2d9f273080af26876cc6cf81a27d581529724..a88f6c2d47cf1dfe0fd06f91fb038f344c0c1b3f 100644 (file)
@@ -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()
index 554e7012bab8424fca68e51a1f6cec91e053f027..e863e20caad01f11e14363ab505ce346e63f81c7 100644 (file)
@@ -15,6 +15,7 @@
 #include <GeomAlgoAPI_PointBuilder.h>
 
 #include <memory>
+#include <iostream>
 
 //=================================================================================================
 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;
   }
 
index 4ec2cda6759fb69721f6a512d068d40cd95e0b55..8f0f205d5f2239d02a79281c7b1800eeffd83679 100644 (file)
@@ -11,7 +11,6 @@
         min = "0.0"
         icon=""
         tooltip="Dimension in X">
-        <validator id="GeomValidators_Positive"/>
       </doublevalue>
       <doublevalue
         id="dy"
@@ -21,7 +20,6 @@
         min = "0.0"
         icon=""
         tooltip="Dimension in Y">
-        <validator id="GeomValidators_Positive"/>
       </doublevalue>
       <doublevalue
         id="dz"
@@ -31,7 +29,6 @@
         min = "0.0"
         icon=""
         tooltip="Dimension in Z">
-        <validator id="GeomValidators_Positive"/>
       </doublevalue>
     </box>
     <box id="BoxByTwoPoints" title="By two points" icon="icons/Primitives/box_2pt_32x32.png">
         icon="icons/Primitives/point.png"
         tooltip="Select a first point"
         shape_types="vertex">
-        <validator id="GeomValidators_ShapeType" parameters="vertex"/>
       </shape_selector>
       <shape_selector id="SecondPoint"
         label="Second point"
         icon="icons/Primitives/point.png"
         tooltip="Select a second point"
         shape_types="vertex">
-        <validator id="GeomValidators_ShapeType" parameters="vertex"/>
-        <validator id="GeomValidators_DifferentShapes"/>
       </shape_selector>
     </box>
   </toolbox>