]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1649: Added options to create plane by three points;
authordbv <dbv@opencascade.com>
Wed, 13 Jul 2016 12:21:33 +0000 (15:21 +0300)
committerdbv <dbv@opencascade.com>
Thu, 14 Jul 2016 09:20:33 +0000 (12:20 +0300)
Added option to create plane by line and point.

18 files changed:
src/ConstructionAPI/ConstructionAPI_Plane.cpp
src/ConstructionAPI/ConstructionAPI_Plane.h
src/ConstructionPlugin/ConstructionPlugin_Plane.cpp
src/ConstructionPlugin/ConstructionPlugin_Plane.h
src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp
src/ConstructionPlugin/ConstructionPlugin_Point.cpp
src/ConstructionPlugin/ConstructionPlugin_Validators.cpp
src/ConstructionPlugin/ConstructionPlugin_Validators.h
src/ConstructionPlugin/plane_widget.xml
src/GeomAPI/GeomAPI_Face.cpp
src/GeomAPI/GeomAPI_Lin.cpp
src/GeomAPI/GeomAPI_Lin.h
src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp
src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h
src/InitializationPlugin/InitializationPlugin_Plugin.cpp
src/PartSet/PartSet_PreviewPlanes.cpp
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/SketchPlugin/SketchPlugin_Sketch.cpp

index a248e71d1350250473907b864af272bf30112c14..b33d4d74611c3d39ee3ae8d7c6cb9cdf1756f83d 100644 (file)
@@ -49,7 +49,7 @@ void ConstructionAPI_Plane::setFaceAndDistance(
     const ModelHighAPI_Double & theDistance)
 {
   fillAttribute("PlaneByFaceAndDistance", mycreationMethod);
-  fillAttribute(theFace, myface);
+  fillAttribute(theFace, myplane);
   fillAttribute(theDistance, mydistance);
 
   execute();
index 75936094e7af3a705de01a725b04074d8df854d4..7713d19cde41bffe197151aabc79f1f10669ca81 100644 (file)
@@ -45,19 +45,19 @@ public:
   virtual ~ConstructionAPI_Plane();
 
   INTERFACE_7(ConstructionPlugin_Plane::ID(),
-              creationMethod, ConstructionPlugin_Plane::METHOD(), ModelAPI_AttributeString, /** Creation method */,
-              face, ConstructionPlugin_Plane::FACE(), ModelAPI_AttributeSelection, /** Plane face */,
-              distance, ConstructionPlugin_Plane::DISTANCE(), ModelAPI_AttributeDouble, /** Distance */,
+              creationMethod, ConstructionPlugin_Plane::CREATION_METHOD(), ModelAPI_AttributeString, /** Creation method */,
               A, ConstructionPlugin_Plane::A(), ModelAPI_AttributeDouble, /** Parameter A for general equation */,
               B, ConstructionPlugin_Plane::B(), ModelAPI_AttributeDouble, /** Parameter B for general equation */,
               C, ConstructionPlugin_Plane::C(), ModelAPI_AttributeDouble, /** Parameter C for general equation */,
-              D, ConstructionPlugin_Plane::D(), ModelAPI_AttributeDouble, /** Parameter D for general equation */
-  )
+              D, ConstructionPlugin_Plane::D(), ModelAPI_AttributeDouble, /** Parameter D for general equation */,
+              plane, ConstructionPlugin_Plane::PLANE(), ModelAPI_AttributeSelection, /** Plane face */,
+              distance, ConstructionPlugin_Plane::DISTANCE(), ModelAPI_AttributeDouble, /** Distance */
+ )
 
   /// Set face and distance
   CONSTRUCTIONAPI_EXPORT
-  void setFaceAndDistance(const ModelHighAPI_Selection & theFace,
-                          const ModelHighAPI_Double & theDistance);
+  void setFaceAndDistance(const ModelHighAPI_Selection& theFace,
+                          const ModelHighAPI_Double& theDistance);
 
   /// Set GeneralEquation parameters of the feature
   CONSTRUCTIONAPI_EXPORT
index 07a223b44e5053d8e6180e69eea43f56ca6ddda1..40529c0c9e23998ced6a4851620ddf7422091af6 100644 (file)
@@ -8,57 +8,93 @@
 
 #include <Config_PropManager.h>
 
-#include <ModelAPI_AttributeSelection.h>
+#include <GeomAlgoAPI_FaceBuilder.h>
+#include <GeomAlgoAPI_ShapeTools.h>
+
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Pln.h>
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Vertex.h>
+
 #include <ModelAPI_AttributeDouble.h>
-#include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeString.h>
+#include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
-#include <GeomAlgoAPI_FaceBuilder.h>
 
-#include <GeomAPI_Pnt2d.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);
 
+//==================================================================================================
 ConstructionPlugin_Plane::ConstructionPlugin_Plane()
 {
 }
 
+//==================================================================================================
 void ConstructionPlugin_Plane::initAttributes()
 {
-  data()->addAttribute(ConstructionPlugin_Plane::METHOD(), ModelAPI_AttributeString::typeId());
-  // Face & Distance
-  data()->addAttribute(ConstructionPlugin_Plane::FACE(),  ModelAPI_AttributeSelection::typeId());
-  data()->addAttribute(ConstructionPlugin_Plane::DISTANCE(), ModelAPI_AttributeDouble::typeId());
-  // General equation
-  data()->addAttribute(ConstructionPlugin_Plane::A(),  ModelAPI_AttributeDouble::typeId());
-  data()->addAttribute(ConstructionPlugin_Plane::B(),  ModelAPI_AttributeDouble::typeId());
-  data()->addAttribute(ConstructionPlugin_Plane::C(),  ModelAPI_AttributeDouble::typeId());
-  data()->addAttribute(ConstructionPlugin_Plane::D(),  ModelAPI_AttributeDouble::typeId());
-
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ConstructionPlugin_Plane::A());
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ConstructionPlugin_Plane::B());
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ConstructionPlugin_Plane::C());
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ConstructionPlugin_Plane::D());
+  data()->addAttribute(ConstructionPlugin_Plane::CREATION_METHOD(), ModelAPI_AttributeString::typeId());
+
+  // By general equation.
+  data()->addAttribute(A(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(B(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(C(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(D(), ModelAPI_AttributeDouble::typeId());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), A());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), B());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), C());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), D());
+
+  // By three points.
+  data()->addAttribute(POINT1(), ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(POINT2(), ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(POINT3(), ModelAPI_AttributeSelection::typeId());
+
+  // By line and point.
+  data()->addAttribute(LINE(), ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(POINT(), ModelAPI_AttributeSelection::typeId());
+
+  // By other plane.
+  data()->addAttribute(CREATION_METHOD_BY_OTHER_PLANE_OPTION(), ModelAPI_AttributeString::typeId());
+  data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(DISTANCE(), ModelAPI_AttributeDouble::typeId());
 }
 
+//==================================================================================================
 void ConstructionPlugin_Plane::execute()
 {
-  AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Plane::METHOD());
-  std::string aMethodType = aMethodTypeAttr->value();
-  std::shared_ptr<GeomAPI_Shape> aPlaneFace;
-  if (aMethodType == "PlaneByFaceAndDistance") {
-    aPlaneFace = createPlaneByFaceAndDistance();
-  } else if (aMethodType == "PlaneByGeneralEquation") {
-    aPlaneFace = createPlaneByGeneralEquation();
+  GeomShapePtr aShape;
+
+  std::string aCreationMethod = string(CREATION_METHOD())->value();
+  if(aCreationMethod == CREATION_METHOD_BY_GENERAL_EQUATION()) {
+    aShape = createByGeneralEquation();
+  } else if(aCreationMethod == CREATION_METHOD_BY_THREE_POINTS()) {
+    aShape = createByThreePoints();
+  } else if(aCreationMethod == CREATION_METHOD_BY_LINE_AND_POINT()) {
+    aShape = createByLineAndPoint();
+  } else if(aCreationMethod == CREATION_METHOD_BY_OTHER_PLANE()) {
+    std::string aCreationMethodOption = string(CREATION_METHOD_BY_OTHER_PLANE_OPTION())->value();
+    if(aCreationMethodOption == CREATION_METHOD_BY_DISTANCE_FROM_OTHER()) {
+      aShape = createByDistanceFromOther();
+    }
   }
-  if (!aPlaneFace.get())
+
+
+  if(!aShape.get()) {
     return;
+  }
+
   ResultConstructionPtr aConstr = document()->createConstruction(data());
   aConstr->setInfinite(true);
-  aConstr->setShape(aPlaneFace);
+  aConstr->setShape(aShape);
   setResult(aConstr);
 }
 
+//==================================================================================================
 bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
                                                      std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
 {
@@ -85,9 +121,93 @@ bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObj
   return isCustomized;
 }
 
-std::shared_ptr<GeomAPI_Shape>  ConstructionPlugin_Plane::createPlaneByFaceAndDistance()
+//==================================================================================================
+std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByGeneralEquation()
 {
-  AttributeSelectionPtr aFaceAttr = data()->selection(ConstructionPlugin_Plane::FACE());
+  AttributeDoublePtr anAttrA = real(ConstructionPlugin_Plane::A());
+  AttributeDoublePtr anAttrB = real(ConstructionPlugin_Plane::B());
+  AttributeDoublePtr anAttrC = real(ConstructionPlugin_Plane::C());
+  AttributeDoublePtr anAttrD = real(ConstructionPlugin_Plane::D());
+  std::shared_ptr<GeomAPI_Shape> aPlaneFace;
+  if ((anAttrA.get() != NULL) && (anAttrB.get() != NULL) &&
+      (anAttrC.get() != NULL) && (anAttrD.get() != NULL) &&
+      anAttrA->isInitialized() && anAttrB->isInitialized() &&
+      anAttrC->isInitialized() && anAttrD->isInitialized() ) {
+    double aA = anAttrA->value(), aB = anAttrB->value(),
+           aC = anAttrC->value(), aD = anAttrD->value();
+    std::shared_ptr<GeomAPI_Pln> aPlane = 
+      std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
+    std::string kDefaultPlaneSize = "200";
+    double aSize = Config_PropManager::integer("Sketch planes", "planes_size", kDefaultPlaneSize);
+    aSize *= 4.;
+    aPlaneFace = GeomAlgoAPI_FaceBuilder::squareFace(aPlane, aSize);
+  }
+  return aPlaneFace;
+}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByThreePoints()
+{
+  // Get first point.
+  AttributeSelectionPtr aPointSelection1 = selection(POINT1());
+  GeomShapePtr aPointShape1 = aPointSelection1->value();
+  if(!aPointShape1.get()) {
+    aPointShape1 = aPointSelection1->context()->shape();
+  }
+  std::shared_ptr<GeomAPI_Vertex> aVertex1(new GeomAPI_Vertex(aPointShape1));
+
+  // Get second point.
+  AttributeSelectionPtr aPointSelection2 = selection(POINT2());
+  GeomShapePtr aPointShape2 = aPointSelection2->value();
+  if(!aPointShape2.get()) {
+    aPointShape2 = aPointSelection2->context()->shape();
+  }
+  std::shared_ptr<GeomAPI_Vertex> aVertex2(new GeomAPI_Vertex(aPointShape2));
+
+  // Get third point.
+  AttributeSelectionPtr aPointSelection3 = selection(POINT3());
+  GeomShapePtr aPointShape3 = aPointSelection3->value();
+  if(!aPointShape3.get()) {
+    aPointShape3 = aPointSelection3->context()->shape();
+  }
+  std::shared_ptr<GeomAPI_Vertex> aVertex3(new GeomAPI_Vertex(aPointShape3));
+
+  GeomShapePtr aRes = faceByThreeVertices(aVertex1, aVertex2, aVertex3);
+
+  return aRes;
+}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createByLineAndPoint()
+{
+  // Get edge.
+  AttributeSelectionPtr anEdgeSelection = selection(LINE());
+  GeomShapePtr aLineShape = anEdgeSelection->value();
+  if(!aLineShape.get()) {
+    aLineShape = anEdgeSelection->context()->shape();
+  }
+  std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aLineShape));
+  std::shared_ptr<GeomAPI_Vertex> aV1, aV2;
+  GeomAlgoAPI_ShapeTools::findBounds(anEdge, aV1, aV2);
+
+
+  // Get point.
+  AttributeSelectionPtr aPointSelection = selection(POINT());
+  GeomShapePtr aPointShape = aPointSelection->value();
+  if(!aPointShape.get()) {
+    aPointShape = aPointSelection->context()->shape();
+  }
+  std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aPointShape));
+
+  GeomShapePtr aRes = faceByThreeVertices(aV1, aV2, aVertex);
+
+  return aRes;
+}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Shape>  ConstructionPlugin_Plane::createByDistanceFromOther()
+{
+  AttributeSelectionPtr aFaceAttr = data()->selection(ConstructionPlugin_Plane::PLANE());
   AttributeDoublePtr aDistAttr = data()->real(ConstructionPlugin_Plane::DISTANCE());
   std::shared_ptr<GeomAPI_Shape> aPlane;
   if ((aFaceAttr.get() != NULL) &&
@@ -100,70 +220,67 @@ std::shared_ptr<GeomAPI_Shape>  ConstructionPlugin_Plane::createPlaneByFaceAndDi
       aShape = aFaceAttr->context()->shape();
     }
 
-    if (aShape.get() != NULL) {
-      std::shared_ptr<GeomAPI_Pln> aPln = GeomAlgoAPI_FaceBuilder::plane(aShape);
-      std::shared_ptr<GeomAPI_Pnt> aOrig = aPln->location();
-      std::shared_ptr<GeomAPI_Dir> aDir = aPln->direction();
-
-      aOrig->translate(aDir, aDist);
-      std::shared_ptr<GeomAPI_Pln> aNewPln = std::shared_ptr<GeomAPI_Pln>(
-          new GeomAPI_Pln(aOrig, aDir));
-
-      // Create rectangular face close to the selected
-      double aXmin, aYmin, Zmin, aXmax, aYmax, Zmax;
-      aShape->computeSize(aXmin, aYmin, Zmin, aXmax, aYmax, Zmax);
-
-      // use all 8 points of the bounding box to find the 2D bounds
-      bool isFirst = true;
-      double aMinX2d, aMaxX2d, aMinY2d, aMaxY2d;
-      for(int aXIsMin = 0; aXIsMin < 2; aXIsMin++) {
-        for(int aYIsMin = 0; aYIsMin < 2; aYIsMin++) {
-          for(int aZIsMin = 0; aZIsMin < 2; aZIsMin++) {
-            std::shared_ptr<GeomAPI_Pnt> aPnt = std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(
-              aXIsMin ? aXmin : aXmax, aYIsMin ? aYmin : aYmax, aZIsMin ? Zmin : Zmax));
-            std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = aPnt->to2D(aNewPln);
-            if (isFirst || aPnt2d->x() < aMinX2d)
-              aMinX2d = aPnt2d->x();
-            if (isFirst || aPnt2d->y() < aMinY2d)
-              aMinY2d = aPnt2d->y();
-            if (isFirst || aPnt2d->x() > aMaxX2d)
-              aMaxX2d = aPnt2d->x();
-            if (isFirst || aPnt2d->y() > aMaxY2d)
-              aMaxY2d = aPnt2d->y();
-            if (isFirst)
-              isFirst = !isFirst;
-          }
+    if(!aShape.get()) {
+      return aPlane;
+    }
+
+    std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aShape));
+
+    std::shared_ptr<GeomAPI_Pln> aPln = GeomAlgoAPI_FaceBuilder::plane(aFace);
+    std::shared_ptr<GeomAPI_Pnt> aOrig = aPln->location();
+    std::shared_ptr<GeomAPI_Dir> aDir = aPln->direction();
+
+    aOrig->translate(aDir, aDist);
+    std::shared_ptr<GeomAPI_Pln> aNewPln(new GeomAPI_Pln(aOrig, aDir));
+
+    // Create rectangular face close to the selected
+    double aXmin, aYmin, Zmin, aXmax, aYmax, Zmax;
+    aFace->computeSize(aXmin, aYmin, Zmin, aXmax, aYmax, Zmax);
+
+    // use all 8 points of the bounding box to find the 2D bounds
+    bool isFirst = true;
+    double aMinX2d, aMaxX2d, aMinY2d, aMaxY2d;
+    for(int aXIsMin = 0; aXIsMin < 2; aXIsMin++) {
+      for(int aYIsMin = 0; aYIsMin < 2; aYIsMin++) {
+        for(int aZIsMin = 0; aZIsMin < 2; aZIsMin++) {
+          std::shared_ptr<GeomAPI_Pnt> aPnt(new GeomAPI_Pnt(
+            aXIsMin ? aXmin : aXmax, aYIsMin ? aYmin : aYmax, aZIsMin ? Zmin : Zmax));
+          std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = aPnt->to2D(aNewPln);
+          if (isFirst || aPnt2d->x() < aMinX2d)
+            aMinX2d = aPnt2d->x();
+          if (isFirst || aPnt2d->y() < aMinY2d)
+            aMinY2d = aPnt2d->y();
+          if (isFirst || aPnt2d->x() > aMaxX2d)
+            aMaxX2d = aPnt2d->x();
+          if (isFirst || aPnt2d->y() > aMaxY2d)
+            aMaxY2d = aPnt2d->y();
+          if (isFirst)
+            isFirst = !isFirst;
         }
       }
-      double aWgap = (aMaxX2d - aMinX2d) * 0.1;
-      double aHgap = (aMaxY2d - aMinY2d) * 0.1;
-      aPlane = GeomAlgoAPI_FaceBuilder::planarFace(aNewPln,
-        aMinX2d - aWgap, aMinY2d - aHgap, aMaxX2d - aMinX2d + 2. * aWgap, aMaxY2d - aMinY2d + 2. * aHgap);
     }
+    double aWgap = (aMaxX2d - aMinX2d) * 0.1;
+    double aHgap = (aMaxY2d - aMinY2d) * 0.1;
+    aPlane = GeomAlgoAPI_FaceBuilder::planarFace(aNewPln,
+      aMinX2d - aWgap, aMinY2d - aHgap, aMaxX2d - aMinX2d + 2. * aWgap, aMaxY2d - aMinY2d + 2. * aHgap);
+
   }
   return aPlane;
 }
 
-std::shared_ptr<GeomAPI_Shape> ConstructionPlugin_Plane::createPlaneByGeneralEquation()
+//==================================================================================================
+GeomShapePtr faceByThreeVertices(const std::shared_ptr<GeomAPI_Vertex> theV1,
+                                 const std::shared_ptr<GeomAPI_Vertex> theV2,
+                                 const std::shared_ptr<GeomAPI_Vertex> theV3)
 {
-  AttributeDoublePtr anAttrA = real(ConstructionPlugin_Plane::A());
-  AttributeDoublePtr anAttrB = real(ConstructionPlugin_Plane::B());
-  AttributeDoublePtr anAttrC = real(ConstructionPlugin_Plane::C());
-  AttributeDoublePtr anAttrD = real(ConstructionPlugin_Plane::D());
-  std::shared_ptr<GeomAPI_Shape> aPlaneFace;
-  if ((anAttrA.get() != NULL) && (anAttrB.get() != NULL) &&
-      (anAttrC.get() != NULL) && (anAttrD.get() != NULL) &&
-      anAttrA->isInitialized() && anAttrB->isInitialized() &&
-      anAttrC->isInitialized() && anAttrD->isInitialized() ) {
-    double aA = anAttrA->value(), aB = anAttrB->value(),
-           aC = anAttrC->value(), aD = anAttrD->value();
-    std::shared_ptr<GeomAPI_Pln> aPlane = 
-      std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
-    std::string kDefaultPlaneSize = "200";
-    double aSize = Config_PropManager::integer("Sketch planes", "planes_size", kDefaultPlaneSize);
-    aSize *= 4.;
-    aPlaneFace = GeomAlgoAPI_FaceBuilder::square(aPlane, aSize);
-  }
-  return aPlaneFace;
-}
+  std::shared_ptr<GeomAPI_Face> aFace = GeomAlgoAPI_FaceBuilder::planarFaceByThreeVertices(theV1, theV2, theV3);
 
+  ListOfShape anObjects;
+  anObjects.push_back(theV1);
+  anObjects.push_back(theV2);
+  anObjects.push_back(theV3);
+  std::list<std::shared_ptr<GeomAPI_Pnt> > aBoundingPoints = GeomAlgoAPI_ShapeTools::getBoundingBox(anObjects, 1.0);
+  GeomShapePtr aRes = GeomAlgoAPI_ShapeTools::fitPlaneToBox(aFace, aBoundingPoints);
+
+  return aRes;
+}
index b82f1e8c3f8b238b1fd2b804618c5e096ded9923..3bfecc7a71a526afd1097e6c9baf804b42b30cb7 100644 (file)
 #define ConstructionPlugin_Plane_H
 
 #include "ConstructionPlugin.h"
+
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Result.h>
 #include <GeomAPI_ICustomPrs.h>
 
-
-
-/**\class ConstructionPlugin_Plane
- * \ingroup Plugins
- * \brief Feature for creation of the new planar surface in PartSet.
- */
-class ConstructionPlugin_Plane : public ModelAPI_Feature, public GeomAPI_ICustomPrs
+/// \class ConstructionPlugin_Plane
+/// \ingroup Plugins
+/// \brief Feature for creation of the new planar surface in PartSet.
+class ConstructionPlugin_Plane: public ModelAPI_Feature, public GeomAPI_ICustomPrs
 {
- public:
-  /// Returns the kind of a feature
+public:
+  /// \return the kind of a feature.
   CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getKind()
   {
     static std::string MY_KIND = ConstructionPlugin_Plane::ID();
     return MY_KIND;
   }
 
-  /// default color for a plane
+  /// Default color for a plane.
   inline static const std::string& DEFAULT_COLOR()
   {
     static const std::string CONSTRUCTION_PLANE_COLOR("150,150,180");
     return CONSTRUCTION_PLANE_COLOR;
   }
 
-  /// Plane kind
+  /// Plane kind.
   inline static const std::string& ID()
   {
     static const std::string CONSTRUCTION_PLANE_KIND("Plane");
     return CONSTRUCTION_PLANE_KIND;
   }
 
-  /// attribute name for first point
-  inline static const std::string& METHOD()
+  /// Attribute name for creation method.
+  inline static const std::string& CREATION_METHOD()
+  {
+    static const std::string MY_CREATION_METHOD_ID("creation_method");
+    return MY_CREATION_METHOD_ID;
+  }
+
+  /// Attribute name for creation method.
+  inline static const std::string& CREATION_METHOD_BY_GENERAL_EQUATION()
+  {
+    static const std::string MY_CREATION_METHOD_ID("by_general_equation");
+    return MY_CREATION_METHOD_ID;
+  }
+
+  /// Attribute name for creation method.
+  inline static const std::string& CREATION_METHOD_BY_THREE_POINTS()
+  {
+    static const std::string MY_CREATION_METHOD_ID("by_three_points");
+    return MY_CREATION_METHOD_ID;
+  }
+
+  /// Attribute name for creation method.
+  inline static const std::string& CREATION_METHOD_BY_LINE_AND_POINT()
+  {
+    static const std::string MY_CREATION_METHOD_ID("by_line_and_point");
+    return MY_CREATION_METHOD_ID;
+  }
+
+  /// Attribute name for creation method.
+  inline static const std::string& CREATION_METHOD_BY_OTHER_PLANE()
+  {
+    static const std::string MY_CREATION_METHOD_ID("by_other_plane");
+    return MY_CREATION_METHOD_ID;
+  }
+
+  /// Attribute name for creation method.
+  inline static const std::string& CREATION_METHOD_BY_OTHER_PLANE_OPTION()
+  {
+    static const std::string MY_CREATION_METHOD_ID("by_other_plane_option");
+    return MY_CREATION_METHOD_ID;
+  }
+
+  /// Attribute name for creation method.
+  inline static const std::string& CREATION_METHOD_BY_DISTANCE_FROM_OTHER()
+  {
+    static const std::string MY_CREATION_METHOD_ID("by_distance_from_other");
+    return MY_CREATION_METHOD_ID;
+  }
+
+  /// Attribute name for creation method.
+  inline static const std::string& CREATION_METHOD_BY_COINCIDENT_TO_POINT()
   {
-    static const std::string METHOD_ATTR("CreationMethod");
-    return METHOD_ATTR;
+    static const std::string MY_CREATION_METHOD_ID("by_coincident_to_point");
+    return MY_CREATION_METHOD_ID;
   }
 
-  /// attribute name for base face
-  inline static const std::string& FACE()
+  /// Attribute name for creation method.
+  inline static const std::string& CREATION_METHOD_BY_ROTATION()
   {
-    static const std::string FACE_ATTR("planeFace");
-    return FACE_ATTR;
+    static const std::string MY_CREATION_METHOD_ID("by_rotation");
+    return MY_CREATION_METHOD_ID;
   }
-  /// attribute name for distance
+
+  /// Attribute name for creation method.
+  inline static const std::string& CREATION_METHOD_BY_TWO_PARALLEL_PLANES()
+  {
+    static const std::string MY_CREATION_METHOD_ID("by_two_parallel_planes");
+    return MY_CREATION_METHOD_ID;
+  }
+
+  /// Attribute name for first point.
+  inline static const std::string& POINT1()
+  {
+    static const std::string ATTR_ID("point1");
+    return ATTR_ID;
+  }
+
+  /// Attribute name for second point.
+  inline static const std::string& POINT2()
+  {
+    static const std::string ATTR_ID("point2");
+    return ATTR_ID;
+  }
+
+  /// Attribute name for third point.
+  inline static const std::string& POINT3()
+  {
+    static const std::string ATTR_ID("point3");
+    return ATTR_ID;
+  }
+
+  /// Attribute name for line.
+  inline static const std::string& LINE()
+  {
+    static const std::string ATTR_ID("line");
+    return ATTR_ID;
+  }
+
+  /// Attribute name for point.
+  inline static const std::string& POINT()
+  {
+    static const std::string ATTR_ID("point");
+    return ATTR_ID;
+  }
+
+  /// Attribute name for selected plane.
+  inline static const std::string& PLANE()
+  {
+    static const std::string ATTR_ID("plane");
+    return ATTR_ID;
+  }
+
+  /// Attribute name for distance.
   inline static const std::string& DISTANCE()
   {
-    static const std::string DISTANCE_ATTR("distance");
-    return DISTANCE_ATTR;
+    static const std::string ATTR_ID("distance");
+    return ATTR_ID;
   }
 
-  /// the a parameter for the general equation of a plane (ax+by+cz+d=0)
+  /// Attribute name for a parameter for the general equation of a plane (ax+by+cz+d=0)
   inline static const std::string& A()
   {
-    static const std::string PARAM_A_ATTR("A");
-    return PARAM_A_ATTR;
+    static const std::string ATTR_ID("A");
+    return ATTR_ID;
   }
-  /// the b parameter for the general equation of a plane (ax+by+cz+d=0)
+  /// Attribute name for b parameter for the general equation of a plane (ax+by+cz+d=0)
   inline static const std::string& B()
   {
-    static const std::string PARAM_B_ATTR("B");
-    return PARAM_B_ATTR;
+    static const std::string ATTR_ID("B");
+    return ATTR_ID;
   }
-  /// the c parameter for the general equation of a plane (ax+by+cz+d=0)
+  /// Attribute name for c parameter for the general equation of a plane (ax+by+cz+d=0)
   inline static const std::string& C()
   {
-    static const std::string PARAM_C_ATTR("C");
-    return PARAM_C_ATTR;
+    static const std::string ATTR_ID("C");
+    return ATTR_ID;
   }
-  /// the d parameter for the general equation of a plane (ax+by+cz+d=0)
+  /// Attribute name for d parameter for the general equation of a plane (ax+by+cz+d=0)
   inline static const std::string& D()
   {
-    static const std::string PARAM_D_ATTR("D");
-    return PARAM_D_ATTR;
+    static const std::string ATTR_ID("D");
+    return ATTR_ID;
   }
 
   /// Creates a new part document if needed
@@ -103,12 +200,14 @@ class ConstructionPlugin_Plane : public ModelAPI_Feature, public GeomAPI_ICustom
   virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
                                      std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs);
 
- protected:
+protected:
+  /// Creates a new plane by general equation.
+  std::shared_ptr<GeomAPI_Shape> createByGeneralEquation();
+  std::shared_ptr<GeomAPI_Shape> createByThreePoints();
+  std::shared_ptr<GeomAPI_Shape> createByLineAndPoint();
   /// Creates a new plane by copy of face plane with translation along the normal
   /// to the specified distance.
-  std::shared_ptr<GeomAPI_Shape> createPlaneByFaceAndDistance();
-  /// Creates a new plane by general equation.
-  std::shared_ptr<GeomAPI_Shape> createPlaneByGeneralEquation();
+  std::shared_ptr<GeomAPI_Shape> createByDistanceFromOther();
 };
 
 #endif
index e9f202998ff660e70e8717db21e5cac216ced14c..521873f11424443df74a1481c02f3f575eace3ce 100644 (file)
@@ -24,6 +24,10 @@ ConstructionPlugin_Plugin::ConstructionPlugin_Plugin()
                               new ConstructionPlugin_ValidatorPointLines());
   aFactory->registerValidator("ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel",
                               new ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel());
+  aFactory->registerValidator("ConstructionPlugin_ValidatorPlaneThreePoints",
+                              new ConstructionPlugin_ValidatorPlaneThreePoints());
+  aFactory->registerValidator("ConstructionPlugin_ValidatorPlaneLinePoint",
+                              new ConstructionPlugin_ValidatorPlaneLinePoint());
 
   // register this plugin
   ModelAPI_Session::get()->registerPlugin(this);
index c3866c52d629e6cb054fc0606364b5ed7b9fbccb..00ae6f7381c18e72f70e4d5377a29ac83e24c139 100644 (file)
@@ -33,12 +33,12 @@ const std::string& ConstructionPlugin_Point::getKind()
 //==================================================================================================
 void ConstructionPlugin_Point::initAttributes()
 {
+  data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
+
   data()->addAttribute(X(), ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(Y(), ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(Z(), ModelAPI_AttributeDouble::typeId());
 
-  data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
-
   data()->addAttribute(EDGE(), ModelAPI_AttributeSelection::typeId());
   data()->addAttribute(DISTANCE_VALUE(), ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(DISTANCE_PERCENT(), ModelAPI_AttributeBoolean::typeId());
@@ -72,11 +72,13 @@ void ConstructionPlugin_Point::execute()
     aShape = createByLineAndPlaneIntersection();
   }
 
-  if(aShape.get()) {
-    std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
-    aConstr->setShape(aShape);
-    setResult(aConstr);
+  if(!aShape.get()) {
+    return;
   }
+
+  std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
+  aConstr->setShape(aShape);
+  setResult(aConstr);
 }
 
 //==================================================================================================
@@ -152,7 +154,7 @@ std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLinesIntersect
   }
   std::shared_ptr<GeomAPI_Edge> aFirstEdge(new GeomAPI_Edge(aFirstLineShape));
 
-  // Get first line.
+  // Get second line.
   AttributeSelectionPtr aSecondLineSelection= selection(SECOND_LINE());
   GeomShapePtr aSecondLineShape = aSecondLineSelection->value();
   if(!aSecondLineShape.get()) {
index 7c8fd6751849ab5fe53528bb4ecf45458cc65357..9cf88ccd9b1a4e4bc2091c763d6fb8c00bb01bc5 100644 (file)
@@ -10,6 +10,7 @@
 #include <GeomAPI_Face.h>
 #include <GeomAPI_Lin.h>
 #include <GeomAPI_Pln.h>
+#include <GeomAPI_Vertex.h>
 
 #include <ModelAPI_AttributeSelection.h>
 
@@ -17,6 +18,7 @@
 
 static std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape);
 static std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape);
+static std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape);
 
 //==================================================================================================
 bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttribute,
@@ -127,7 +129,129 @@ bool ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel::isValid(
   return true;
 }
 
-static std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape)
+//==================================================================================================
+bool ConstructionPlugin_ValidatorPlaneThreePoints::isValid(const AttributePtr& theAttribute,
+                                                           const std::list<std::string>& theArguments,
+                                                           Events_InfoMessage& theError) const
+{
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+
+  AttributeSelectionPtr aPointAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+  AttributeSelectionPtr aPointAttribute2 = aFeature->selection(theArguments.front());
+  AttributeSelectionPtr aPointAttribute3 = aFeature->selection(theArguments.back());
+
+  GeomShapePtr aPointShape1 = aPointAttribute1->value();
+  ResultPtr aContext1 = aPointAttribute1->context();
+  if(!aContext1.get()) {
+    theError = "One of the attribute not initialized.";
+    return false;
+  }
+  if(!aPointShape1.get()) {
+    aPointShape1 = aContext1->shape();
+  }
+  if(!aPointShape1->isVertex()) {
+    theError = "One of the selected shapes not a vertex.";
+    return false;
+  }
+
+  GeomShapePtr aPointShape2 = aPointAttribute2->value();
+  ResultPtr aContext2 = aPointAttribute2->context();
+  if(!aContext2.get()) {
+    return true;
+  }
+  if(!aPointShape2.get()) {
+    aPointShape2 = aContext2->shape();
+  }
+  if(!aPointShape2->isVertex()) {
+    theError = "One of the selected shapes not a vertex.";
+    return false;
+  }
+
+  GeomShapePtr aPointShape3 = aPointAttribute3->value();
+  ResultPtr aContext3 = aPointAttribute3->context();
+  if(!aContext3.get()) {
+    return true;
+  }
+  if(!aPointShape3.get()) {
+    aPointShape3 = aContext3->shape();
+  }
+  if(!aPointShape3->isVertex()) {
+    theError = "One of the selected shapes not a vertex.";
+    return false;
+  }
+
+  std::shared_ptr<GeomAPI_Vertex> aVertex1(new GeomAPI_Vertex(aPointShape1));
+  std::shared_ptr<GeomAPI_Vertex> aVertex2(new GeomAPI_Vertex(aPointShape2));
+  std::shared_ptr<GeomAPI_Vertex> aVertex3(new GeomAPI_Vertex(aPointShape3));
+
+  std::shared_ptr<GeomAPI_Pnt> aPnt1 = aVertex1->point();
+  std::shared_ptr<GeomAPI_Pnt> aPnt2 = aVertex2->point();
+  std::shared_ptr<GeomAPI_Pnt> aPnt3 = aVertex3->point();
+
+  std::shared_ptr<GeomAPI_Lin> aLin(new GeomAPI_Lin(aPnt1, aPnt2));
+
+  if(aLin->contains(aPnt3)) {
+    theError = "Selected points lie on a line.";
+    return false;
+  }
+
+  return true;
+}
+
+//==================================================================================================
+bool ConstructionPlugin_ValidatorPlaneLinePoint::isValid(
+    const AttributePtr& theAttribute,
+    const std::list<std::string>& theArguments,
+    Events_InfoMessage& theError) const
+{
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+
+  AttributeSelectionPtr anAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+  AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
+
+  std::shared_ptr<GeomAPI_Lin> aLin;
+  std::shared_ptr<GeomAPI_Pnt> aPnt;
+
+  GeomShapePtr aShape1 = anAttribute1->value();
+  ResultPtr aContext1 = anAttribute1->context();
+  if(!aContext1.get()) {
+    theError = "One of the attribute not initialized.";
+    return false;
+  }
+  if(!aShape1.get()) {
+    aShape1 = aContext1->shape();
+  }
+
+  GeomShapePtr aShape2 = anAttribute2->value();
+  ResultPtr aContext2 = anAttribute2->context();
+  if(!aContext2.get()) {
+    return true;
+  }
+  if(!aShape2.get()) {
+    aShape2 = aContext2->shape();
+  }
+
+  aLin = getLin(aShape1);
+  aPnt = getPnt(aShape2);
+  if(!aLin.get() || !aPnt.get()) {
+    aLin = getLin(aShape2);
+    aPnt = getPnt(aShape1);
+  }
+
+  if(!aLin.get() || !aPnt.get()) {
+    theError = "Wrong shape types selected.";
+    return false;
+  }
+
+  if(aLin->contains(aPnt)) {
+    theError = "Point lies on the line.";
+    return false;
+  }
+
+  return true;
+}
+
+std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape)
 {
   std::shared_ptr<GeomAPI_Lin> aLin;
 
@@ -146,7 +270,7 @@ static std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape)
   return aLin;
 }
 
-static std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape)
+std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape)
 {
   std::shared_ptr<GeomAPI_Pln> aPln;
 
@@ -164,3 +288,18 @@ static std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape)
 
   return aPln;
 }
+
+std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape)
+{
+  std::shared_ptr<GeomAPI_Pnt> aPnt;
+
+  if(!theShape->isVertex()) {
+    return aPnt;
+  }
+
+  std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(theShape));
+
+  aPnt = aVertex->point();
+
+  return aPnt;
+}
index 65fb54be5d0b07a3ead7800a9d425f52a74f6b6f..9bbb6f950b0d797f71fe27a402d79892c988ffe1 100644 (file)
@@ -26,7 +26,7 @@ public:
 
 /// \class ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel
 /// \ingroup Validators
-/// \brief A validator for selection line and plane for point by intersection..
+/// \brief A validator for selection line and plane for point by intersection.
 class ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel: public ModelAPI_AttributeValidator
 {
 public:
@@ -39,4 +39,34 @@ public:
                         Events_InfoMessage& theError) const;
 };
 
+/// \class ConstructionPlugin_ValidatorPlaneThreePoints
+/// \ingroup Validators
+/// \brief A validator for selection three points for plane.
+class ConstructionPlugin_ValidatorPlaneThreePoints: public ModelAPI_AttributeValidator
+{
+public:
+  //! \return True if the attribute is valid.
+  //! \param[in] theAttribute the checked attribute.
+  //! \param[in] theArguments arguments of the attribute.
+  //! \param[out] theError error message.
+   virtual bool isValid(const AttributePtr& theAttribute,
+                        const std::list<std::string>& theArguments,
+                        Events_InfoMessage& theError) const;
+};
+
+/// \class ConstructionPlugin_ValidatorPlaneLinePoint
+/// \ingroup Validators
+/// \brief A validator for selection line and point for plane.
+class ConstructionPlugin_ValidatorPlaneLinePoint: public ModelAPI_AttributeValidator
+{
+public:
+  //! \return True if the attribute is valid.
+  //! \param[in] theAttribute the checked attribute.
+  //! \param[in] theArguments arguments of the attribute.
+  //! \param[out] theError error message.
+   virtual bool isValid(const AttributePtr& theAttribute,
+                        const std::list<std::string>& theArguments,
+                        Events_InfoMessage& theError) const;
+};
+
 #endif
\ No newline at end of file
index 938850f418b74be477fe8970a14e27139a4e8041..299e6ae358c3edca5193db7f6e9003a31c071026 100644 (file)
@@ -1,8 +1,95 @@
 <!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
 
 <source>
-  <switch id="CreationMethod">
-    <case id="PlaneByFaceAndDistance" title="On some distance from a face">
+  <toolbox id="creation_method">
+    <box id="by_three_points"
+         title="By three points"
+         tooltip="Plane by three points."
+         icon="icons/Construction/plane_by_three_points_32x32.png">
+      <shape_selector id="point1"
+                      label="1st point"
+                      tooltip="First point."
+                      icon="icons/Construction/point.png"
+                      shape_types="vertex">
+        <validator id="ConstructionPlugin_ValidatorPlaneThreePoints" parameters="point2,point3"/>
+      </shape_selector>
+      <shape_selector id="point2"
+                      label="2nd point"
+                      tooltip="Second point."
+                      icon="icons/Construction/point.png"
+                      shape_types="vertex">
+        <validator id="ConstructionPlugin_ValidatorPlaneThreePoints" parameters="point1,point3"/>
+      </shape_selector>
+      <shape_selector id="point3"
+                      label="3rd point"
+                      tooltip="Third point."
+                      icon="icons/Construction/point.png"
+                      shape_types="vertex">
+        <validator id="ConstructionPlugin_ValidatorPlaneThreePoints" parameters="point1,point2"/>
+      </shape_selector>
+    </box>
+    <box id="by_line_and_point"
+         title="By line and point"
+         tooltip="Plane by line and point."
+         icon="icons/Construction/plane_by_line_and_point_32x32.png">
+      <shape_selector id="line"
+                      label="Line"
+                      tooltip="Select line."
+                      icon="icons/Construction/edge.png"
+                      shape_types="edge">
+        <validator id="GeomValidators_ShapeType" parameters="line"/>
+        <validator id="ConstructionPlugin_ValidatorPlaneLinePoint" parameters="point"/>
+      </shape_selector>
+      <shape_selector id="point"
+                      label="Point"
+                      tooltip="Select point."
+                      icon="icons/Construction/point.png"
+                      shape_types="vertex">
+        <validator id="ConstructionPlugin_ValidatorPlaneLinePoint" parameters="line"/>
+      </shape_selector>
+    </box>
+    <box id="by_other_plane"
+         title="By other plane"
+         tooltip="Plane by other plane with different options."
+         icon="icons/Construction/plane_by_other_plane_32x32.png">
+      <shape_selector id="plane"
+                      label="Plane"
+                      tooltip="Select a planar face."
+                      icon="icons/Construction/face.png"
+                      shape_types="face">
+        <validator id="GeomValidators_Face" parameters="plane"/>
+      </shape_selector>
+      <toolbox id="by_other_plane_option">
+        <box id="by_distance_from_other"
+             title="By distance from other"
+             tooltip="Plane by distance from other plane."
+             icon="icons/Construction/plane_by_distance_from_other_32x32.png">
+          <doublevalue id="distance"
+                       label="Distance"
+                       tooltip="Distance from selected face to plane."
+                       icon="icons/Construction/distance_value.png"
+                       default="0"/>
+        </box>
+        <box id="by_coincident_to_point"
+             title="By coincident to point"
+             tooltip="Plane by coincident to point."
+             icon="icons/Construction/plane_by_coincident_to_point_32x32.png">
+        </box>
+        <box id="by_rotation"
+             title="By rotation"
+             tooltip="Plane by rotation around axis."
+             icon="icons/Construction/plane_by_rotation_32x32.png">
+        </box>
+      </toolbox>
+    </box>
+    <box id="by_two_parallel_planes"
+         title="By two parallel planes"
+         tooltip="Plane equidistant from 2 parallel planes."
+         icon="icons/Construction/plane_by_two_parallel_planes_32x32.png">
+    </box>
+
+
+    <!--<box id="PlaneByFaceAndDistance" title="On some distance from a face">
       <shape_selector id="planeFace"
                       label="Plane face"
                       tooltip="Select a planar face"
                    label="Distance" 
                    tooltip="Distance from selected face to plane" 
                default="0" />
-    </case>
-  </switch>
+    </box>-->
+
+  </toolbox>
 </source>
index e47070176a383be1533f3eb7723aecac0099c71e..6c3894ba7b256142140a414ea5280aef1cf84ffa 100644 (file)
@@ -32,6 +32,9 @@ GeomAPI_Face::GeomAPI_Face(const std::shared_ptr<GeomAPI_Shape>& theShape)
 
 bool GeomAPI_Face::isEqual(std::shared_ptr<GeomAPI_Shape> theFace) const
 {
+  if (!theFace.get())
+    return false;
+
   if (!theFace->isFace())
     return false;
 
index b76131aa32695a01c70e5b2f54010de1b78dc173..9ccc30f2bca5aca396bda13bc1055f856cf3b76e 100644 (file)
@@ -105,6 +105,15 @@ const std::shared_ptr<GeomAPI_Pnt> GeomAPI_Lin::project(
   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aResult.X(), aResult.Y(), aResult.Z()));
 }
 
+bool GeomAPI_Lin::contains(const std::shared_ptr<GeomAPI_Pnt> thePoint, const double theLinearTolerance) const
+{
+  if(!thePoint.get()) {
+    return false;
+  }
+
+  return MY_LIN->Contains(thePoint->impl<gp_Pnt>(), theLinearTolerance) == Standard_True;
+}
+
 bool GeomAPI_Lin::isParallel(const std::shared_ptr<GeomAPI_Lin> theLin) const
 {
   return MY_LIN->Direction().IsParallel(theLin->impl<gp_Lin>().Direction(), Precision::Confusion()) == Standard_True;
index c62215bbcc0a32fc0fbe357e365b314e74dae4e6..e9e35296a91dc2ec4ce26602168278898605f706 100644 (file)
@@ -54,6 +54,11 @@ class GeomAPI_Lin : public GeomAPI_Interface
   const std::shared_ptr<GeomAPI_Pnt> project(
       const std::shared_ptr<GeomAPI_Pnt>& thePoint) const;
 
+  /// \return true if this line contains thePoint, that is, if the distance between thePoint and this line
+  ///         is less than or equal to theLinearTolerance.
+  GEOMAPI_EXPORT
+  bool contains(const std::shared_ptr<GeomAPI_Pnt> thePoint, const double theLinearTolerance = 1.e-7) const;
+
   /// \return true if lines are parallel.
   GEOMAPI_EXPORT
   bool isParallel(const std::shared_ptr<GeomAPI_Lin> theLin) const;
index 8e108ebfa01d4f3423bba3c23f8a617500c69d60..7a625131054247ae5fa6778a66ccb5b391de4929 100644 (file)
@@ -4,19 +4,28 @@
 // Created:     23 Apr 2014
 // Author:      Mikhail PONIKAROV
 
-#include <GeomAlgoAPI_FaceBuilder.h>
-#include <gp_Pln.hxx>
-#include <BRepBuilderAPI_MakeFace.hxx>
-#include <TopoDS_Face.hxx>
-#include <TopoDS.hxx>
+#include "GeomAlgoAPI_FaceBuilder.h"
+
+#include <GeomAPI_Face.h>
+#include <GeomAPI_Dir.h>
+#include <GeomAPI_Pln.h>
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Shape.h>
+#include <GeomAPI_Vertex.h>
+
 #include <BRep_Tool.hxx>
+#include <BRepBuilderAPI_MakeFace.hxx>
+#include <GC_MakePlane.hxx>
 #include <Geom_Plane.hxx>
 #include <GeomLib_IsPlanarSurface.hxx>
+#include <gp_Pln.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Face.hxx>
 
-
-std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
-    std::shared_ptr<GeomAPI_Pnt> theCenter, std::shared_ptr<GeomAPI_Dir> theNormal,
-    const double theSize)
+//==================================================================================================
+std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_FaceBuilder::squareFace(const std::shared_ptr<GeomAPI_Pnt> theCenter,
+                                                                  const std::shared_ptr<GeomAPI_Dir> theNormal,
+                                                                  const double theSize)
 {
   const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
   const gp_Dir& aDir = theNormal->impl<gp_Dir>();
@@ -24,27 +33,79 @@ std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
   // half of the size in each direction from the center
   BRepBuilderAPI_MakeFace aFaceBuilder(aPlane, -theSize / 2., theSize / 2., -theSize / 2.,
                                        theSize / 2.);
-  std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
-  aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face()));
+  std::shared_ptr<GeomAPI_Face> aRes(new GeomAPI_Face());
+  aRes->setImpl(new TopoDS_Face(aFaceBuilder.Face()));
   return aRes;
 }
 
-std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
-    std::shared_ptr<GeomAPI_Pln> thePlane,
-    const double theSize)
+//==================================================================================================
+std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_FaceBuilder::squareFace(const std::shared_ptr<GeomAPI_Pln> thePlane,
+                                                                  const double theSize)
 {
   // half of the size in each direction from the center
   BRepBuilderAPI_MakeFace aFaceBuilder(thePlane->impl<gp_Pln>(),
                                        -theSize / 2., theSize / 2.,
                                        -theSize / 2., theSize / 2.);
-  std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
-  TopoDS_Shape aFace = aFaceBuilder.Face();
-  aRes->setImpl(new TopoDS_Shape(aFace/*aFaceBuilder.Face()*/));
+  std::shared_ptr<GeomAPI_Face> aRes(new GeomAPI_Face());
+  const TopoDS_Face& aFace = aFaceBuilder.Face();
+  aRes->setImpl(new TopoDS_Face(aFace));
+  return aRes;
+}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_FaceBuilder::planarFace(const std::shared_ptr<GeomAPI_Pnt> theCenter,
+                                                                  const std::shared_ptr<GeomAPI_Dir> theNormal)
+{
+  const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
+  const gp_Dir& aDir = theNormal->impl<gp_Dir>();
+  gp_Pln aPlane(aCenter, aDir);
+  BRepBuilderAPI_MakeFace aFaceBuilder(aPlane);
+  std::shared_ptr<GeomAPI_Face> aRes(new GeomAPI_Face());
+  aRes->setImpl(new TopoDS_Face(aFaceBuilder.Face()));
+  return aRes;
+}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_FaceBuilder::planarFace(const std::shared_ptr<GeomAPI_Pln> thePlane,
+                                                                  const double theX, const double theY,
+                                                                  const double theWidth, const double theHeight)
+{
+  double aA, aB, aC, aD;
+  thePlane->coefficients(aA, aB, aC, aD);
+  gp_Pln aPlane(aA, aB, aC, aD);
+
+  // half of the size in each direction from the center
+  BRepBuilderAPI_MakeFace aFaceBuilder(aPlane, theX, theX + theWidth, 
+                                       theY, theY + theHeight);
+  std::shared_ptr<GeomAPI_Face> aRes(new GeomAPI_Face());
+  aRes->setImpl(new TopoDS_Face(aFaceBuilder.Face()));
   return aRes;
 }
 
-std::shared_ptr<GeomAPI_Pln> GeomAlgoAPI_FaceBuilder::plane(
-    std::shared_ptr<GeomAPI_Shape> theFace)
+//==================================================================================================
+std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_FaceBuilder::planarFaceByThreeVertices(
+    const std::shared_ptr<GeomAPI_Vertex> theVertex1,
+    const std::shared_ptr<GeomAPI_Vertex> theVertex2,
+    const std::shared_ptr<GeomAPI_Vertex> theVertex3)
+{
+  gp_Pnt aPnt1 = theVertex1->point()->impl<gp_Pnt>();
+  gp_Pnt aPnt2 = theVertex2->point()->impl<gp_Pnt>();
+  gp_Pnt aPnt3 = theVertex3->point()->impl<gp_Pnt>();
+
+  std::shared_ptr<GeomAPI_Face> aFace;
+  GC_MakePlane aMakePlane(aPnt1, aPnt2, aPnt3);
+  if(!aMakePlane.IsDone()) {
+    return aFace;
+  }
+
+  BRepBuilderAPI_MakeFace aMakeFace(aMakePlane.Value()->Pln());
+  aFace.reset(new GeomAPI_Face());
+  aFace->setImpl(new TopoDS_Face(aMakeFace.Face()));
+  return aFace;
+}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Pln> GeomAlgoAPI_FaceBuilder::plane(const std::shared_ptr<GeomAPI_Face> theFace)
 {
   std::shared_ptr<GeomAPI_Pln> aResult;
   if (!theFace)
@@ -75,32 +136,4 @@ std::shared_ptr<GeomAPI_Pln> GeomAlgoAPI_FaceBuilder::plane(
   }
   aResult = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
   return aResult;
-}
-
-std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::planarFace(std::shared_ptr<GeomAPI_Pnt> theCenter,
-                                                                   std::shared_ptr<GeomAPI_Dir> theNormal)
-{
-  const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
-  const gp_Dir& aDir = theNormal->impl<gp_Dir>();
-  gp_Pln aPlane(aCenter, aDir);
-  BRepBuilderAPI_MakeFace aFaceBuilder(aPlane);
-  std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
-  aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face()));
-  return aRes;
-}
-
-std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::planarFace(std::shared_ptr<GeomAPI_Pln> thePlane,
-             double theX, double theY,
-             double theWidth, double theHeight)
-{
-  double aA, aB, aC, aD;
-  thePlane->coefficients(aA, aB, aC, aD);
-  gp_Pln aPlane(aA, aB, aC, aD);
-
-  // half of the size in each direction from the center
-  BRepBuilderAPI_MakeFace aFaceBuilder(aPlane, theX, theX + theWidth, 
-                                       theY, theY + theHeight);
-  std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
-  aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face()));
-  return aRes;
-}
+}
\ No newline at end of file
index 49ec19c3084da7dea685cc74fd7bcfd497f60111..603ed4620f3aa8d353bb98a5b7cbccad51bc368f 100644 (file)
@@ -7,42 +7,48 @@
 #ifndef GeomAlgoAPI_FaceBuilder_H_
 #define GeomAlgoAPI_FaceBuilder_H_
 
-#include <GeomAlgoAPI.h>
-#include <GeomAPI_Shape.h>
-#include <GeomAPI_Pnt.h>
-#include <GeomAPI_Pln.h>
-#include <GeomAPI_Dir.h>
+#include "GeomAlgoAPI.h"
+
 #include <memory>
 
-/**\class GeomAlgoAPI_FaceBuilder
- * \ingroup DataAlgo
- * \brief Allows to create face-shapes by different parameters
- */
+class GeomAPI_Dir;
+class GeomAPI_Face;
+class GeomAPI_Pln;
+class GeomAPI_Pnt;
+class GeomAPI_Vertex;
 
+/// \class GeomAlgoAPI_FaceBuilder
+/// \ingroup DataAlgo
+/// \brief Allows to create face-shapes by different parameters
 class GEOMALGOAPI_EXPORT GeomAlgoAPI_FaceBuilder
 {
  public:
   /// Creates square planar face by given point of the center,
   /// normal to the plane and size of square
-  static std::shared_ptr<GeomAPI_Shape> square(std::shared_ptr<GeomAPI_Pnt> theCenter,
-                                                 std::shared_ptr<GeomAPI_Dir> theNormal,
-                                                 const double theSize);
+  static std::shared_ptr<GeomAPI_Face> squareFace(const std::shared_ptr<GeomAPI_Pnt> theCenter,
+                                                  const std::shared_ptr<GeomAPI_Dir> theNormal,
+                                                  const double theSize);
   /// Creates square planar face by given point of the center,
   /// normal to the plane and size of square
-  static std::shared_ptr<GeomAPI_Shape> square(std::shared_ptr<GeomAPI_Pln> thePlane,
-                                               const double theSize);
-
-  /// Returns the plane of the planar face. If it is not planar, returns empty ptr.
-  static std::shared_ptr<GeomAPI_Pln> plane(std::shared_ptr<GeomAPI_Shape> theFace);
+  static std::shared_ptr<GeomAPI_Face> squareFace(const std::shared_ptr<GeomAPI_Pln> thePlane,
+                                                  const double theSize);
 
   /// Creates the planar face by given point of the center and normal to the plane.
-  static std::shared_ptr<GeomAPI_Shape> planarFace(std::shared_ptr<GeomAPI_Pnt> theCenter,
-                                                   std::shared_ptr<GeomAPI_Dir> theNormal);
+  static std::shared_ptr<GeomAPI_Face> planarFace(const std::shared_ptr<GeomAPI_Pnt> theCenter,
+                                                  const std::shared_ptr<GeomAPI_Dir> theNormal);
 
   /// Creates a planar face by given plane, left lower point and size.
-  static std::shared_ptr<GeomAPI_Shape> planarFace(std::shared_ptr<GeomAPI_Pln> thePlane,
-                                                   double theX, double theY,
-                                                   double theWidth, double theHeight);
+  static std::shared_ptr<GeomAPI_Face> planarFace(const std::shared_ptr<GeomAPI_Pln> thePlane,
+                                                  const double theX, const double theY,
+                                                  const double theWidth, const double theHeight);
+
+  /// Creates a planar face by three vertices.
+  static std::shared_ptr<GeomAPI_Face> planarFaceByThreeVertices(const std::shared_ptr<GeomAPI_Vertex> theVertex1,
+                                                                 const std::shared_ptr<GeomAPI_Vertex> theVertex2,
+                                                                 const std::shared_ptr<GeomAPI_Vertex> theVertex3);
+
+  /// Returns the plane of the planar face. If it is not planar, returns empty ptr.
+  static std::shared_ptr<GeomAPI_Pln> plane(const std::shared_ptr<GeomAPI_Face> theFace);
 };
 
 #endif
index cdfe868ac68de7481cfc758ff4a61e9e7d084eda..3b3ba3c3b268d2e07bd20d4a43a581be03d22132 100644 (file)
@@ -15,6 +15,8 @@
 
 #include <memory>
 
+#define NESTED_TOOLBOX_FIX
+
 // the only created instance of this plugin
 static InitializationPlugin_Plugin* MY_INITIALIZATIONPLUGIN_INSTANCE =
     new InitializationPlugin_Plugin();
@@ -89,7 +91,11 @@ FeaturePtr InitializationPlugin_Plugin::createPlane(DocumentPtr theDoc, double t
                                                     double theZ)
 {
   FeaturePtr aPlane = theDoc->addFeature("Plane");
-  aPlane->string("CreationMethod")->setValue("PlaneByGeneralEquation");
+  aPlane->string("creation_method")->setValue("by_general_equation");
+#ifdef NESTED_TOOLBOX_FIX
+  aPlane->string("by_other_plane_option")->setValue("by_distance_from_other");
+  aPlane->real("distance")->setValue(0);
+#endif
   aPlane->real("A")->setValue(theX);
   aPlane->real("B")->setValue(theY);
   aPlane->real("C")->setValue(theZ);
index e7210b0ce4cd4ea70de9e93cc64c43c9762a4c24..53e4cebfd00eab49ccbea0205dfc0521e530b06c 100755 (executable)
@@ -124,7 +124,7 @@ AISObjectPtr PartSet_PreviewPlanes::createPreviewPlane(std::shared_ptr<GeomAPI_P
                                                        const int theRGB[3])
 {
   double aSize = Config_PropManager::integer("Sketch planes", "planes_size", PLANE_SIZE);
-  std::shared_ptr<GeomAPI_Shape> aFace = GeomAlgoAPI_FaceBuilder::square(theOrigin, theNorm, aSize);
+  std::shared_ptr<GeomAPI_Shape> aFace = GeomAlgoAPI_FaceBuilder::squareFace(theOrigin, theNorm, aSize);
   AISObjectPtr aAIS = AISObjectPtr(new GeomAPI_AISObject());
   aAIS->createShape(aFace);
   aAIS->setWidth(Config_PropManager::integer("Sketch planes", "planes_thickness", SKETCH_WIDTH));
index 74a7ee5e3074f3b350543905bab37d561f2442da..c09625924e83a1b377cf08caee693ce665b489b8 100644 (file)
@@ -257,7 +257,8 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs
   }
   if (aGShape.get() != NULL) {
     // get plane parameters
-    std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
+    std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aGShape));
+    std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aFace);
     std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
     gp_XYZ aXYZ = aDir->impl<gp_Dir>().XYZ();
     double aTwist = 0.0;
@@ -487,7 +488,8 @@ std::shared_ptr<GeomAPI_Dir> PartSet_WidgetSketchLabel::setSketchPlane(const Fea
 
 
   // get plane parameters
-  std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
+  std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aGShape));
+  std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aFace);
   if (!aPlane.get())
     return std::shared_ptr<GeomAPI_Dir>();
 
index 22b3257ef7e9ca73b3db750d1555158bacd2efd0..ef2ef9c691327934c4f4cf171008ffb5fd1b3842 100755 (executable)
@@ -216,7 +216,8 @@ void SketchPlugin_Sketch::attributeChanged(const std::string& theID) {
       data()->selection(SketchPlugin_SketchEntity::EXTERNAL_ID())->value();
     if (aSelection) { // update arguments due to the selection value
       // update the sketch plane
-      std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aSelection);
+      std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aSelection));
+      std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aFace);
       if (aPlane) {
         double anA, aB, aC, aD;
         aPlane->coefficients(anA, aB, aC, aD);