Salome HOME
Change icons for chamfer
[modules/shaper.git] / src / ConstructionPlugin / ConstructionPlugin_Plane.cpp
index 52e2920353d9dc3709d4b6e3d9ecf746ea94bd60..5b4338a983bf1eef77a9a72d69247038d2bad767 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  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
 //
 // 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
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "ConstructionPlugin_Plane.h"
@@ -46,6 +45,7 @@
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
 
+
 static GeomShapePtr faceByThreeVertices(const std::shared_ptr<GeomAPI_Vertex> theV1,
                                         const std::shared_ptr<GeomAPI_Vertex> theV2,
                                         const std::shared_ptr<GeomAPI_Vertex> theV3);
@@ -181,7 +181,9 @@ std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByGeneralEquation
            aC = anAttrC->value(), aD = anAttrD->value();
     std::shared_ptr<GeomAPI_Pln> aPlane =
       std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
-    double aSize = Config_PropManager::integer(SKETCH_TAB_NAME, "planes_size");
+    double aSize = Config_PropManager::real(SKETCH_TAB_NAME, "planes_size");
+    if (aSize <= 1.e-7)
+      aSize = 200;  // Set default value
     aSize *= 4.;
     aPlaneFace = GeomAlgoAPI_FaceBuilder::squareFace(aPlane, aSize);
   }
@@ -237,6 +239,8 @@ std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByLineAndPoint()
     GeomAPI_ShapeIterator anIt(aLineShape);
     anEdge = anIt.current()->edge();
   }
+  if (!anEdge)
+    return GeomShapePtr();
 
   // Get point.
   AttributeSelectionPtr aPointSelection = selection(POINT());
@@ -282,7 +286,7 @@ std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByDistanceFromOth
     bool anIsReverse = boolean(REVERSE())->value();
     if(anIsReverse) aDist = -aDist;
     GeomShapePtr aShape = aFaceAttr->value();
-    if (!aShape.get()) {
+    if (!aShape.get() && aFaceAttr->context()) {
       aShape = aFaceAttr->context()->shape();
     }
 
@@ -298,6 +302,8 @@ std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByDistanceFromOth
       GeomAPI_ShapeIterator anIt(aShape);
       aFace = anIt.current()->face();
     }
+    if (!aFace)
+      return GeomShapePtr();
 
     std::shared_ptr<GeomAPI_Pln> aPln = aFace->getPlane();
     std::shared_ptr<GeomAPI_Pnt> aOrig = aPln->location();
@@ -335,7 +341,9 @@ std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByCoincidentPoint
   if(!aPointShape.get()) {
     aPointShape = aPointSelection->context()->shape();
   }
-  std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aPointShape));
+  std::shared_ptr<GeomAPI_Vertex> aVertex = aPointShape->vertex();
+  if (!aVertex)
+    return GeomShapePtr();
 
   std::shared_ptr<GeomAPI_Pnt> anOrig = aVertex->point();
   std::shared_ptr<GeomAPI_Pln> aPln = aFace->getPlane();
@@ -363,6 +371,8 @@ std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByRotation()
     GeomAPI_ShapeIterator anIt(aFaceShape);
     aFace = anIt.current()->face();
   }
+  if (!aFace)
+    return GeomShapePtr();
   aFace = makeRectangularFace(aFace, aFace->getPlane());
 
   // Get axis.
@@ -379,6 +389,8 @@ std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByRotation()
     GeomAPI_ShapeIterator anIt(anAxisShape);
     anEdge = anIt.current()->edge();
   }
+  if (!anEdge)
+    return GeomShapePtr();
 
   std::shared_ptr<GeomAPI_Ax1> anAxis =
     std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
@@ -419,6 +431,8 @@ std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByTwoParallelPlan
     GeomAPI_ShapeIterator anIt(aFaceShape1);
     aFace1 = anIt.current()->face();
   }
+  if (!aFace1)
+    return GeomShapePtr();
   std::shared_ptr<GeomAPI_Pln> aPln1 = aFace1->getPlane();
 
   // Get plane 2.
@@ -435,6 +449,8 @@ std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByTwoParallelPlan
     GeomAPI_ShapeIterator anIt(aFaceShape2);
     aFace2 = anIt.current()->face();
   }
+  if (!aFace2)
+    return GeomShapePtr();
   std::shared_ptr<GeomAPI_Pln> aPln2 = aFace2->getPlane();
 
   std::shared_ptr<GeomAPI_Pnt> anOrig1 = aPln1->location();