]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 25 Mar 2015 07:27:11 +0000 (10:27 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 25 Mar 2015 07:27:11 +0000 (10:27 +0300)
24 files changed:
src/FeaturesPlugin/FeaturesPlugin_Placement.cpp
src/FeaturesPlugin/FeaturesPlugin_Placement.h
src/FeaturesPlugin/placement_widget.xml
src/GeomAPI/GeomAPI_Edge.cpp
src/GeomAPI/GeomAPI_Edge.h
src/GeomAPI/GeomAPI_Lin.cpp
src/GeomAPI/GeomAPI_Lin.h
src/GeomAPI/GeomAPI_Lin2d.cpp
src/GeomAPI/GeomAPI_Lin2d.h
src/GeomAlgoAPI/GeomAlgoAPI_Placement.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Placement.h
src/GeomValidators/GeomValidators_Face.cpp
src/Model/Model_AttributeSelection.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/ModuleBase/ModuleBase_WidgetValidated.cpp
src/ModuleBase/ModuleBase_WidgetValidated.h
src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp
src/PartSet/PartSet_WidgetConstraintShapeSelector.h
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/PartSet/PartSet_WidgetShapeSelector.h
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/PartSet/PartSet_WidgetSketchLabel.h
src/SketchPlugin/plugin-Sketch.xml

index fd59eb3867880427717fb2d801961f83cce6d43e..f97b3248d112e95131995ef81d7cc5a9ec3429bd 100644 (file)
@@ -11,6 +11,7 @@
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeBoolean.h>
 
+#include <GeomAPI_Edge.h>
 #include <GeomAPI_Face.h>
 #include <GeomAPI_Pln.h>
 #include <GeomAlgoAPI_Placement.h>
@@ -25,8 +26,8 @@ FeaturesPlugin_Placement::FeaturesPlugin_Placement()
 
 void FeaturesPlugin_Placement::initAttributes()
 {
-  data()->addAttribute(FeaturesPlugin_Placement::BASE_FACE_ID(), ModelAPI_AttributeSelection::type());
-  data()->addAttribute(FeaturesPlugin_Placement::ATTRACT_FACE_ID(), ModelAPI_AttributeSelection::type());
+  data()->addAttribute(FeaturesPlugin_Placement::BASE_OBJECT_ID(), ModelAPI_AttributeSelection::type());
+  data()->addAttribute(FeaturesPlugin_Placement::ATTRACT_OBJECT_ID(), ModelAPI_AttributeSelection::type());
   data()->addAttribute(FeaturesPlugin_Placement::REVERSE_ID(), ModelAPI_AttributeBoolean::type());
   data()->addAttribute(FeaturesPlugin_Placement::CENTERING_ID(), ModelAPI_AttributeBoolean::type());
 }
@@ -34,41 +35,41 @@ void FeaturesPlugin_Placement::initAttributes()
 void FeaturesPlugin_Placement::execute()
 {
   // Verify the base face
-  std::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = std::dynamic_pointer_cast<
-    ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Placement::BASE_FACE_ID()));
-  if (!aFaceRef)
+  std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = std::dynamic_pointer_cast<
+    ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Placement::BASE_OBJECT_ID()));
+  if (!anObjRef)
     return;
 
-  std::shared_ptr<GeomAPI_Shape> aBaseFace = 
-    std::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->value());
-  if (!aBaseFace)
+  std::shared_ptr<GeomAPI_Shape> aBaseShape = 
+    std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
+  if (!aBaseShape)
     return;
 
-  std::shared_ptr<GeomAPI_Shape> aBaseFaceContext;
-  ResultPtr aContextRes = aFaceRef->context();
+  std::shared_ptr<GeomAPI_Shape> aBaseObject;
+  ResultPtr aContextRes = anObjRef->context();
   if (aContextRes) {
     if (aContextRes->groupName() == ModelAPI_ResultBody::group())
-      aBaseFaceContext = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContextRes)->shape();
+      aBaseObject = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContextRes)->shape();
     else if (aContextRes->groupName() == ModelAPI_ResultConstruction::group())
-      aBaseFaceContext = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes)->shape();
+      aBaseObject = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes)->shape();
   }
-  if (!aBaseFaceContext) {
+  if (!aBaseObject) {
     static const std::string aContextError = "The selection context is bad";
     setError(aContextError);
     return;
   }
 
   // Verify the attractive face
-  aFaceRef = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(
-      data()->attribute(FeaturesPlugin_Placement::ATTRACT_FACE_ID()));
+  anObjRef = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(
+      data()->attribute(FeaturesPlugin_Placement::ATTRACT_OBJECT_ID()));
 
-  std::shared_ptr<GeomAPI_Shape> aSlaveObjectFace = 
-    std::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->value());
-  if (!aSlaveObjectFace)
+  std::shared_ptr<GeomAPI_Shape> aSlaveShape = 
+    std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
+  if (!aSlaveShape)
     return;
 
   std::shared_ptr<GeomAPI_Shape> aSlaveObject;
-  aContextRes = aFaceRef->context();
+  aContextRes = anObjRef->context();
   if (aContextRes) {
     if (aContextRes->groupName() == ModelAPI_ResultBody::group())
       aSlaveObject = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContextRes)->shape();
@@ -81,13 +82,25 @@ void FeaturesPlugin_Placement::execute()
     return;
   }
 
-  // Verify faces planarity
-  std::shared_ptr<GeomAPI_Face> aBaseFace1(new GeomAPI_Face(aBaseFace));
-  std::shared_ptr<GeomAPI_Face> aSlaveFace1(new GeomAPI_Face(aSlaveObjectFace));
-  if (!aBaseFace1->isPlanar() || !aSlaveFace1->isPlanar()) {
-    static const std::string aPlanarityError = "One of selected face is not planar";
-    setError(aPlanarityError);
-    return;
+  // Verify planarity of faces and linearity of edges
+  std::shared_ptr<GeomAPI_Shape> aShapes[2] = {aBaseShape, aSlaveShape};
+  for (int i = 0; i < 2; i++) {
+    if (aShapes[i]->isFace()) {
+      std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aShapes[i]));
+      if (!aFace->isPlanar()) {
+        static const std::string aPlanarityError = "One of selected faces is not planar";
+        setError(aPlanarityError);
+        return;
+      }
+    }
+    else if (aShapes[i]->isEdge()) {
+      std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShapes[i]));
+      if (!anEdge->isLine()) {
+        static const std::string aLinearityError = "One of selected endges is not linear";
+        setError(aLinearityError);
+        return;
+      }
+    }
   }
 
   // Flags of the Placement
@@ -99,7 +112,7 @@ void FeaturesPlugin_Placement::execute()
   bool isCentering = aBoolAttr->value();
 
   std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
-  GeomAlgoAPI_Placement aFeature(aSlaveObject, aBaseFaceContext, aSlaveFace1, aBaseFace1, isReverse, isCentering);
+  GeomAlgoAPI_Placement aFeature(aSlaveObject, aBaseObject, aSlaveShape, aBaseShape, isReverse, isCentering);
   if(!aFeature.isDone()) {
     static const std::string aFeatureError = "Placement algorithm failed";
     setError(aFeatureError);
index bf74f1364ce4c7f56d42f5485a25d6d9edad51c7..8039f37e2c84db33e0dd46c78f0dcf7e2f043a3f 100644 (file)
@@ -18,9 +18,9 @@ class GeomAPI_Shape;
  * \ingroup Plugins
  * \brief Feature for applying of placement operation: relative movement of Solid.
  *
- * Locates the selected attractable_face of the solid in the middle of the selected
- * placement_base face. Faces must be planar. Orientation of the placed solid is
- * depended on the underlied planes of both faces.
+ * Locates the selected placement_attractable_object (face, edge, vertex) of the solid into 
+ * the selected placement_base_object. Faces must be planar, edges must be linear.
+ * Orientation of the placed solid depends on the underlied planes of both faces.
  */
 class FeaturesPlugin_Placement : public ModelAPI_Feature
 {
@@ -31,17 +31,17 @@ class FeaturesPlugin_Placement : public ModelAPI_Feature
     static const std::string MY_PLACEMENT_ID("Placement");
     return MY_PLACEMENT_ID;
   }
-  /// attribute name of referenced face
-  inline static const std::string& BASE_FACE_ID()
+  /// attribute name of referenced object
+  inline static const std::string& BASE_OBJECT_ID()
   {
-    static const std::string MY_BASE_FACE_ID("placement_base_face");
-    return MY_BASE_FACE_ID;
+    static const std::string MY_BASE_OBJECT_ID("placement_base_object");
+    return MY_BASE_OBJECT_ID;
   }
   /// attribute name of attractable face
-  inline static const std::string& ATTRACT_FACE_ID()
+  inline static const std::string& ATTRACT_OBJECT_ID()
   {
-    static const std::string MY_ATTRACT_FACE_ID("placement_attractable_face");
-    return MY_ATTRACT_FACE_ID;
+    static const std::string MY_ATTRACT_OBJECT_ID("placement_attractable_object");
+    return MY_ATTRACT_OBJECT_ID;
   }
   /// attribute name of flag of reverse direction
   inline static const std::string& REVERSE_ID()
index 4a8832004b43d339540bc395cccd6a9f966820e0..109d0d62cf7f4fa3f97fefe89734e455fa5a12c1 100644 (file)
@@ -1,17 +1,17 @@
 <!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
 
 <source>
-  <shape_selector id="placement_base_face
-    label="Select a face
+  <shape_selector id="placement_base_object
+    label="Select an object
     icon=":icons/cut_shape.png" 
-    tooltip="Select a destination face"
-    shape_types="face"
+    tooltip="Select a destination element"
+    shape_types="face edge vertex"
   />
-  <shape_selector id="placement_attractable_face
-    label="Select a face
+  <shape_selector id="placement_attractable_object
+    label="Select an object
     icon=":icons/cut_shape.png" 
-    tooltip="Select a face of moved object" 
-    shape_types="face" 
+    tooltip="Select an element of moved object" 
+    shape_types="face edge vertex
     concealment="true" >
     <validator id="PartSet_DifferentObjects"/>
   </shape_selector>
index 4b758eb90da225df14b56d7a9cf0e3c519de3ec1..f9572daa79949e4da668fc374466dc078f598de2 100644 (file)
@@ -8,6 +8,7 @@
 #include<GeomAPI_Pnt.h>
 #include<GeomAPI_Circ.h>
 #include<GeomAPI_Dir.h>
+#include<GeomAPI_Lin.h>
 
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Edge.hxx>
@@ -107,6 +108,26 @@ std::shared_ptr<GeomAPI_Circ> GeomAPI_Edge::circle()
   return std::shared_ptr<GeomAPI_Circ>(); // not circle
 }
 
+std::shared_ptr<GeomAPI_Lin> GeomAPI_Edge::line()
+{
+  const TopoDS_Shape& aShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
+  double aFirst, aLast;
+  Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast);
+  if (aCurve) {
+    Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aCurve);
+    if (aLine) {
+      gp_Pnt aStartPnt = aLine->Value(aFirst);
+      std::shared_ptr<GeomAPI_Pnt> aStart(
+          new GeomAPI_Pnt(aStartPnt.X(), aStartPnt.Y(), aStartPnt.Z()));
+      gp_Pnt aEndPnt = aLine->Value(aLast);
+      std::shared_ptr<GeomAPI_Pnt> aEnd(
+          new GeomAPI_Pnt(aEndPnt.X(), aEndPnt.Y(), aEndPnt.Z()));
+      return std::shared_ptr<GeomAPI_Lin>(new GeomAPI_Lin(aStart, aEnd));
+    }
+  }
+  return std::shared_ptr<GeomAPI_Lin>(); // not circle
+}
+
 
 bool GeomAPI_Edge::isEqual(const std::shared_ptr<GeomAPI_Shape> theEdge) const
 {
index 1c4802ecc687b10585a3ea5c8c761bec5c0b3057..1ecbde0fc6797b1c08beda0b7377ca23e34b6171 100644 (file)
@@ -11,6 +11,7 @@
 
 class GeomAPI_Pnt;
 class GeomAPI_Circ;
+class GeomAPI_Lin;
 
 /**\class GeomAPI_Edge
 * \ingroup DataModel
@@ -41,9 +42,12 @@ public:
   /// Returns the Last vertex coordinates of the edge 
   std::shared_ptr<GeomAPI_Pnt> lastPoint();
 
-  /// Returns a circle if edge is based on the cirsle curve
+  /// Returns a circle if edge is based on the circle curve
   std::shared_ptr<GeomAPI_Circ> circle();
 
+  /// Returns a line if edge is based on the linear curve
+  std::shared_ptr<GeomAPI_Lin> line();
+
   /// Returns true if the current edge is geometrically equal to the given edge
   bool isEqual(const std::shared_ptr<GeomAPI_Shape> theEdge) const;
 };
index 27bd3e0e297fdee97d63db8ed18e4d9ed2661d41..8b64190ba21c78a21df5824d9c4d04d5161122e9 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <GeomAPI_Lin.h>
 #include <GeomAPI_Pnt.h>
+#include <GeomAPI_Dir.h>
 
 #include <gp_Dir.hxx>
 #include <gp_Lin.hxx>
@@ -42,6 +43,18 @@ GeomAPI_Lin::GeomAPI_Lin(const std::shared_ptr<GeomAPI_Pnt>& theStart,
 {
 }
 
+std::shared_ptr<GeomAPI_Pnt> GeomAPI_Lin::location()
+{
+  gp_Pnt aLoc = impl<gp_Lin>().Location();
+  return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
+}
+
+std::shared_ptr<GeomAPI_Dir> GeomAPI_Lin::direction()
+{
+  const gp_Dir& aDir = impl<gp_Lin>().Direction();
+  return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
+}
+
 double GeomAPI_Lin::distance(const std::shared_ptr<GeomAPI_Pnt>& thePoint) const
 {
   return MY_LIN->Distance(thePoint->impl<gp_Pnt>());
index feefca2383551ba3ac06ece65fd4e772456d1b90..cb7a73847d67cfbd413acc41913cbeb2bed34181 100644 (file)
@@ -10,6 +10,7 @@
 #include <GeomAPI_Interface.h>
 #include <memory>
 
+class GeomAPI_Dir;
 class GeomAPI_Pnt;
 
 /**\class GeomAPI_Lin
@@ -27,6 +28,12 @@ class GEOMAPI_EXPORT GeomAPI_Lin : public GeomAPI_Interface
   GeomAPI_Lin(const std::shared_ptr<GeomAPI_Pnt>& theStart,
               const std::shared_ptr<GeomAPI_Pnt>& theEnd);
 
+  /// Returns point on the line (first point)
+  std::shared_ptr<GeomAPI_Pnt> location();
+
+  /// Returns a line direction
+  std::shared_ptr<GeomAPI_Dir> direction();
+
   /// Distance between two points
   double distance(const std::shared_ptr<GeomAPI_Pnt>& thePoint) const;
   /// Intersection of two lines
index 0a65590fa789f6f1a22ded9f7b1688563170cdb7..3c784eefdbd7eb0c3b1ca1215aad9fea5128c5c5 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <GeomAPI_Lin2d.h>
 #include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Dir2d.h>
 
 #include <gp_Dir2d.hxx>
 #include <gp_Lin2d.hxx>
@@ -36,6 +37,18 @@ GeomAPI_Lin2d::GeomAPI_Lin2d(const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
 {
 }
 
+std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Lin2d::location()
+{
+  gp_Pnt2d aLoc = impl<gp_Lin2d>().Location();
+  return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aLoc.X(), aLoc.Y()));
+}
+
+std::shared_ptr<GeomAPI_Dir2d> GeomAPI_Lin2d::direction()
+{
+  const gp_Dir2d& aDir = impl<gp_Lin2d>().Direction();
+  return std::shared_ptr<GeomAPI_Dir2d>(new GeomAPI_Dir2d(aDir.X(), aDir.Y()));
+}
+
 double GeomAPI_Lin2d::distance(const std::shared_ptr<GeomAPI_Pnt2d>& theOther) const
 {
   return MY_LIN2D->Distance(theOther->impl<gp_Pnt2d>());
index 5f6a02244d33033e2552701ae1c16600984cdd9a..abb04bba8e7fc9e35e48044a6cf7647b3728b720 100644 (file)
@@ -10,6 +10,7 @@
 #include <GeomAPI_Interface.h>
 #include <memory>
 
+class GeomAPI_Dir2d;
 class GeomAPI_Pnt2d;
 
 /**\class GeomAPI_Lin2d
@@ -27,6 +28,12 @@ class GEOMAPI_EXPORT GeomAPI_Lin2d : public GeomAPI_Interface
   GeomAPI_Lin2d(const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
                 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd);
 
+  /// Returns point on the line (first point)
+  std::shared_ptr<GeomAPI_Pnt2d> location();
+
+  /// Returns a line direction
+  std::shared_ptr<GeomAPI_Dir2d> direction();
+
   /// Distance between two points
   double distance(const std::shared_ptr<GeomAPI_Pnt2d>& theOther) const;
   /// Intersection of two lines
index e5714a22e789ff59934315f5f9f0fa09b32c5bea..d2ab51bd555e31e6f16ef7b0b896bb97842eb4be 100644 (file)
@@ -7,8 +7,12 @@
 #include <GeomAlgoAPI_Placement.h>
 #include <GeomAlgoAPI_DFLoader.h>
 
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Lin.h>
 #include <GeomAPI_Pnt.h>
 #include <GeomAPI_Pln.h>
+#include <GeomAPI_Vertex.h>
+#include <GeomAPI_XYZ.h>
 
 #include <BRepBuilderAPI_Transform.hxx>
 #include <gp_Trsf.hxx>
 
 #define DEB_PLACEMENT 1
 GeomAlgoAPI_Placement::GeomAlgoAPI_Placement(
+    std::shared_ptr<GeomAPI_Shape> theSourceSolid,
+    std::shared_ptr<GeomAPI_Shape> theDestSolid,
     std::shared_ptr<GeomAPI_Shape> theSourceShape,
     std::shared_ptr<GeomAPI_Shape> theDestShape,
-    std::shared_ptr<GeomAPI_Face> theSourcePlane,
-    std::shared_ptr<GeomAPI_Face> theDestPlane,
     bool theIsReverse,
     bool theIsCentering)
   : myDone(false),
     myShape(new GeomAPI_Shape())
 {
-  build(theSourceShape, theDestShape, theSourcePlane, theDestPlane, theIsReverse, theIsCentering);
+  build(theSourceSolid, theDestSolid, theSourceShape, theDestShape, theIsReverse, theIsCentering);
 }
 
 void GeomAlgoAPI_Placement::build(
+    const std::shared_ptr<GeomAPI_Shape>& theSourceSolid,
+    const std::shared_ptr<GeomAPI_Shape>& theDestSolid,
     const std::shared_ptr<GeomAPI_Shape>& theSourceShape,
     const std::shared_ptr<GeomAPI_Shape>& theDestShape,
-    const std::shared_ptr<GeomAPI_Face>& theSourcePlane,
-    const std::shared_ptr<GeomAPI_Face>& theDestPlane,
     bool theIsReverse,
     bool theIsCentering)
 {
-  std::shared_ptr<GeomAPI_Pln> aSourcePlane = theSourcePlane->getPlane();
-  std::shared_ptr<GeomAPI_Pln> aDestPlane = theDestPlane->getPlane();
-  std::shared_ptr<GeomAPI_Dir> aSourceDir = aSourcePlane->direction();
-  std::shared_ptr<GeomAPI_Pnt> aSourceLoc = aSourcePlane->location();
-  std::shared_ptr<GeomAPI_Dir> aDestDir = aDestPlane->direction();
-  std::shared_ptr<GeomAPI_Pnt> aDestLoc = aDestPlane->location();
+  // Filling the parameters of the objects
+  static const int aNbObjects = 2;
+  gp_Pnt aSrcDstPoints[aNbObjects]; // points on the selected objects (0 - source, 1 - destination)
+  gp_Vec aSrcDstNormals[aNbObjects]; // normal vectors, if planar faces are selected
+  gp_Vec aSrcDstDirections[aNbObjects]; // directions of linear edges
+  bool hasNormal[aNbObjects];
+  bool hasDirection[aNbObjects];
+  std::shared_ptr<GeomAPI_Shape> aShapes[aNbObjects] = {theSourceShape, theDestShape};
+
+  for (int i = 0; i < aNbObjects; i++) {
+    if (aShapes[i]->isFace()) {
+      std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aShapes[i]));
+      std::shared_ptr<GeomAPI_Pln> aPlane = aFace->getPlane();
+      std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
+      std::shared_ptr<GeomAPI_Pnt> aLoc = aPlane->location();
+      aSrcDstPoints[i].SetCoord(aLoc->x(), aLoc->y(), aLoc->z());
+      aSrcDstNormals[i].SetCoord(aDir->x(), aDir->y(), aDir->z());
+    } else if (aShapes[i]->isEdge()) {
+      std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShapes[i]));
+      std::shared_ptr<GeomAPI_Lin> aLine = anEdge->line();
+      std::shared_ptr<GeomAPI_Dir> aDir = aLine->direction();
+      std::shared_ptr<GeomAPI_Pnt> aFirstPnt = anEdge->firstPoint();
+      std::shared_ptr<GeomAPI_Pnt> aLastPnt = anEdge->lastPoint();
+      std::shared_ptr<GeomAPI_XYZ> aLoc = aFirstPnt->xyz()->added(aLastPnt->xyz())->multiplied(0.5);
+      aSrcDstPoints[i].SetCoord(aLoc->x(), aLoc->y(), aLoc->z());
+      aSrcDstDirections[i].SetCoord(aDir->x(), aDir->y(), aDir->z());
+    } else if (aShapes[i]->isVertex()) {
+      std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aShapes[i]));
+      std::shared_ptr<GeomAPI_Pnt> aPnt = aVertex->point();
+      aSrcDstPoints[i].SetCoord(aPnt->x(), aPnt->y(), aPnt->z());
+    } else // something goes wrong
+      return;
+    hasNormal[i] = aSrcDstNormals[i].SquareMagnitude() >= Precision::SquareConfusion();
+    hasDirection[i] = aSrcDstDirections[i].SquareMagnitude() >= Precision::SquareConfusion();
+  }
+
+  // Calculate directions, which comply the normal, for vertices and edges
+  if (!hasNormal[0] || !hasNormal[1]) {
+    if (hasNormal[0] || hasNormal[1]) { // plane with line or vertex
+      if (hasDirection[0] || hasDirection[1]) { // plane - line
+        int anInd = hasDirection[0] ? 0 : 1;
+        gp_Vec aVec = aSrcDstNormals[1 - anInd].Crossed(aSrcDstDirections[anInd]);
+        if (aVec.SquareMagnitude() < Precision::SquareConfusion()) { // normal and direction are collinear
+          aVec = aSrcDstNormals[1 - anInd].Crossed(
+              gp_Vec(aSrcDstPoints[1 - anInd], aSrcDstPoints[anInd]));
+          if (aVec.SquareMagnitude() < Precision::SquareConfusion()) { // normal and points direction are collinear
+            if (Abs(aSrcDstNormals[1 - anInd].Y()) >= Precision::Confusion() || 
+                Abs(aSrcDstNormals[1 - anInd].Z()) >= Precision::Confusion())
+              aVec = gp::DX();
+            else
+              aVec = gp::DY();
+          }
+        }
+        aSrcDstNormals[anInd] = aSrcDstDirections[anInd].Crossed(aVec).Normalized();
+      } else { // plane - point
+        int anInd = hasNormal[0] ? 1 : 0;
+        aSrcDstNormals[anInd] = aSrcDstNormals[1 - anInd];
+      }
+    } else {
+      if (hasDirection[0] && hasDirection[1]) { // line - line
+        gp_Vec aVec = aSrcDstDirections[0].Crossed(aSrcDstDirections[1]);
+        if (aVec.SquareMagnitude() < Precision::SquareConfusion()) { // lines are parallel
+          aVec = aSrcDstDirections[0].Crossed(gp_Vec(aSrcDstPoints[0], aSrcDstPoints[1]));
+          if (aVec.SquareMagnitude() < Precision::SquareConfusion()) { // lines are equal
+            if (Abs(aSrcDstDirections[0].Y()) >= Precision::Confusion() ||
+                Abs(aSrcDstDirections[0].Z()) >= Precision::Confusion())
+              aVec = gp::DX();
+            else
+              aVec = gp::DY();
+          }
+        }
+        aSrcDstNormals[0] = aSrcDstDirections[0].Crossed(aVec);
+        aSrcDstNormals[0].Normalize();
+        aSrcDstNormals[1] = aSrcDstDirections[1].Crossed(aVec).Reversed();
+        aSrcDstNormals[1].Normalize();
+      } else if (!hasDirection[0] && !hasDirection[1]) { // point - point
+        aSrcDstNormals[0] = gp_Vec(aSrcDstPoints[0], aSrcDstPoints[1]);
+        aSrcDstNormals[0].Normalize();
+        aSrcDstNormals[1] = -aSrcDstNormals[0];
+      } else { // line - point
+        int anInd = hasDirection[0] ? 0 : 1;
+        gp_Vec aVec(aSrcDstPoints[anInd], aSrcDstPoints[1 - anInd]);
+        aVec.Cross(aSrcDstDirections[anInd]);
+        if (aVec.SquareMagnitude() < Precision::SquareConfusion()) { // point is on line
+          if (Abs(aSrcDstDirections[1 - anInd].Y()) >= Precision::Confusion() || 
+              Abs(aSrcDstDirections[1 - anInd].Z()) >= Precision::Confusion())
+            aVec = gp::DX();
+          else
+            aVec = gp::DY();
+        }
+        aSrcDstNormals[anInd] = aSrcDstDirections[anInd].Crossed(aVec).Normalized();
+        aSrcDstNormals[1 - anInd] = aSrcDstNormals[anInd];
+      }
+    }
+  }
 
   // Initial shapes
-  const TopoDS_Shape& aSourceShape = theSourceShape->impl<TopoDS_Shape>();
-  const TopoDS_Shape& aDestShape = theDestShape->impl<TopoDS_Shape>();
+  const TopoDS_Shape& aSourceShape = theSourceSolid->impl<TopoDS_Shape>();
+  const TopoDS_Shape& aDestShape = theDestSolid->impl<TopoDS_Shape>();
 
   // Calculate transformation
   gp_Trsf aTrsf;
-  gp_Vec aSrcDir(aSourceDir->x(), aSourceDir->y(), aSourceDir->z());
-  gp_Vec aDstDir(aDestDir->x(), aDestDir->y(), aDestDir->z());
+  gp_Vec aSrcDir = aSrcDstNormals[0];
+  gp_Vec aDstDir = aSrcDstNormals[1];
   // Check the material of the solids to be on the correct side
   BRepClass3d_SolidClassifier aClassifier;
-  aClassifier.Load(aSourceShape);
   static const double aTransStep = 10. * Precision::Confusion();
-  gp_Pnt aPoint(aSourceLoc->x(), aSourceLoc->y(), aSourceLoc->z());
-  aPoint.Translate(aSrcDir * aTransStep);
-  aClassifier.Perform(aPoint, Precision::Confusion());
-  if ((aClassifier.State() == TopAbs_OUT && !theIsReverse) ||
-      (aClassifier.State() == TopAbs_IN && theIsReverse))
+  if (hasNormal[0]) {
+    aClassifier.Load(aSourceShape);
+    gp_Pnt aPoint = aSrcDstPoints[0];
+    aPoint.Translate(aSrcDir * aTransStep);
+    aClassifier.Perform(aPoint, Precision::Confusion());
+    if ((aClassifier.State() == TopAbs_OUT && !theIsReverse) ||
+        (aClassifier.State() == TopAbs_IN && theIsReverse))
+      aSrcDir.Reverse();
+  } else if (theIsReverse)
     aSrcDir.Reverse();
-  aClassifier.Load(aDestShape);
-  aPoint.SetCoord(aDestLoc->x(), aDestLoc->y(), aDestLoc->z());
-  aPoint.Translate(aDstDir * aTransStep);
-  aClassifier.Perform(aPoint, Precision::Confusion());
-  if (aClassifier.State() == TopAbs_IN)
-    aDstDir.Reverse();
+  if (hasNormal[1]) {
+    aClassifier.Load(aDestShape);
+    gp_Pnt aPoint = aSrcDstPoints[1];
+    aPoint.Translate(aDstDir * aTransStep);
+    aClassifier.Perform(aPoint, Precision::Confusion());
+    if (aClassifier.State() == TopAbs_IN)
+      aDstDir.Reverse();
+  }
   // Calculate rotation
   gp_Quaternion aRot(aSrcDir, aDstDir);
   aTrsf.SetRotation(aRot);
   // Calculate translation
-  gp_Vec aSrcLoc(aSourceLoc->x(), aSourceLoc->y(), aSourceLoc->z());
-  gp_Vec aDstLoc(aDestLoc->x(), aDestLoc->y(), aDestLoc->z());
+  gp_Vec aSrcLoc(aSrcDstPoints[0].XYZ());
+  gp_Vec aDstLoc(aSrcDstPoints[1].XYZ());
   if (!theIsCentering)
     aDstLoc = aSrcLoc + gp_Vec(aDstDir) * (aDstLoc-aSrcLoc).Dot(aDstDir);
   aSrcLoc.Transform(aTrsf);
index 703f609c159c6f7a23dc45d209e34ac34555d797..1e1e88e49c1e045a0fb968ce331dec0ec2b4ef95 100644 (file)
 
 /**\class GeomAlgoAPI_Placement
  * \ingroup DataAlgo
- * \brief Creates the copied object which face is placed on the given plane
+ * \brief Creates the copied object which sub-element is placed on the given element
  */
 class GeomAlgoAPI_Placement : public GeomAPI_Interface
 {
 public:
   /** \brief Creates an object which is obtained from current object by transformation calculated
-   *         as a movement of the source plane to be coincident with the destination plane
-   *  \param[in] theSourceShape  shape to be moved
-   *  \param[in] theDestShape    invariabt shape
-   *  \param[in] theSourcePlane  plane on the shape to be made coincident with destination plane
-   *  \param[in] theDestPlane    destination plane
+   *         as a movement of the source object to be coincident with the destination object
+   *  \param[in] theSourceSolid  a shape to be moved
+   *  \param[in] theDestSolid    invariant shape
+   *  \param[in] theSourceShape  a shape on the solid to be made coincident with destination object
+   *  \param[in] theDestShape    destination object
    *  \param[in] theIsReverse    indicates that the solid materials should be on the same side against the destination plane
    *  \param[in] theIsCentering  indicates the planes should be centered
    */
-  GEOMALGOAPI_EXPORT GeomAlgoAPI_Placement(std::shared_ptr<GeomAPI_Shape> theSourceShape,
+  GEOMALGOAPI_EXPORT GeomAlgoAPI_Placement(std::shared_ptr<GeomAPI_Shape> theSourceSolid,
+                                           std::shared_ptr<GeomAPI_Shape> theDestSolid,
+                                           std::shared_ptr<GeomAPI_Shape> theSourceShape,
                                            std::shared_ptr<GeomAPI_Shape> theDestShape,
-                                           std::shared_ptr<GeomAPI_Face> theSourcePlane,
-                                           std::shared_ptr<GeomAPI_Face> theDestPlane,
                                            bool theIsReverse = false,
                                            bool theIsCentering = false);
 
@@ -62,10 +62,10 @@ public:
 
 private:
   /// builds resulting shape
-  void build(const std::shared_ptr<GeomAPI_Shape>& theSourceShape,
+  void build(const std::shared_ptr<GeomAPI_Shape>& theSourceSolid,
+             const std::shared_ptr<GeomAPI_Shape>& theDestSolid,
+             const std::shared_ptr<GeomAPI_Shape>& theSourceShape,
              const std::shared_ptr<GeomAPI_Shape>& theDestShape,
-             const std::shared_ptr<GeomAPI_Face>& theSourcePlane,
-             const std::shared_ptr<GeomAPI_Face>& theDestPlane,
              bool theIsReverse,
              bool theIsCentering);
 
index 6f260861836fdba6a22847f0a77ffce16e55a4dc..821b45cb0755d58d8e11b839b9167a4817beb3d1 100644 (file)
@@ -31,7 +31,7 @@ GeomAbs_SurfaceType GeomValidators_Face::faceType(const std::string& theType)
 }
 
 bool GeomValidators_Face::isValid(const AttributePtr& theAttribute,
-                                       const std::list<std::string>& theArguments) const
+                                  const std::list<std::string>& theArguments) const
 {
   bool aValid = false;
 
@@ -59,5 +59,7 @@ bool GeomValidators_Face::isValid(const AttributePtr& theAttribute,
       }
     }
   }
+  else
+    aValid = true; // an empty face selected is valid.
   return aValid;
 }
index 03ccb8984e47be420ea1d0c204d1374a0dc98cda..4e1f21b91afd30e2121a6e55db511d24dd1566cf 100644 (file)
@@ -86,6 +86,13 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext,
   TDF_Label aSelLab = selectionLabel();
   aSelLab.ForgetAttribute(kSIMPLE_REF_ID);
   aSelLab.ForgetAttribute(kCONSTUCTION_SIMPLE_REF_ID);
+  if (!theContext.get()) {
+    // to keep the reference attribute label
+    TDF_Label aRefLab = myRef.myRef->Label();
+    aSelLab.ForgetAllAttributes(true);
+    myRef.myRef = TDF_Reference::Set(aSelLab, aSelLab);
+    return;
+  }
   if (theContext->groupName() == ModelAPI_ResultBody::group()) {
     // do not select the whole shape for body:it is already must be in the data framework
     if (theContext->shape().get() && theContext->shape()->isEqual(theSubShape)) {
index d88a844102c216ab4cacd0b1cb9cf20a324d1dc5..0cf9b6e44299bc9c7f0ebd1fceacd12d1b4d9d8d 100644 (file)
@@ -133,7 +133,7 @@ bool ModuleBase_WidgetShapeSelector::storeValueCustom() const
 
 //********************************************************************
 bool ModuleBase_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject,
-                                                          GeomShapePtr theShape) const
+                                                          GeomShapePtr theShape)
 {
   bool isChanged = false;
   FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theSelectedObject);
@@ -385,6 +385,7 @@ void ModuleBase_WidgetShapeSelector::backupAttributeValue(const bool isBackup)
       myIsObject = aRefAttr->isObject();
       myRefAttribute = aRefAttr->attr();
     }
+    myExternalObject = NULL;
   }
   else {
     storeAttributeValues(myObject, myShape);
@@ -393,6 +394,13 @@ void ModuleBase_WidgetShapeSelector::backupAttributeValue(const bool isBackup)
       if (!myIsObject)
         aRefAttr->setAttr(myRefAttribute);
     }
+    if (myExternalObject.get()) {
+      /*DocumentPtr aDoc = myExternalObject->document();
+      FeaturePtr aFeature = ModelAPI_Feature::feature(myExternalObject);
+      if (aFeature.get() != NULL) {
+        aDoc->removeFeature(aFeature);
+      }*/
+    }
   }
 }
 
index bcf13cbf1d0393192223d4c8131964f3694e94ad..34c4c0212545a75448215b15b2ef7ea6cdce03f6 100644 (file)
@@ -134,7 +134,7 @@ Q_OBJECT
   /// the specific type and set the given values
   /// \param theSelectedObject an object
   /// \param theShape a selected shape, which is used in the selection attribute
-  virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const;
+  virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape);
 
   //----------- Class members -------------
   protected:
@@ -164,6 +164,8 @@ Q_OBJECT
   AttributePtr myRefAttribute;
   /// A boolean value whether refAttr uses reference of object
   bool myIsObject;
+  /// An external object
+  ObjectPtr myExternalObject;
 };
 
 #endif
index 97723530bd21371533a04ec5474ced4baa4936f1..506eeca2a858427465374e62b80fc41f18cc8bb5 100644 (file)
@@ -24,6 +24,7 @@ ModuleBase_WidgetValidated::~ModuleBase_WidgetValidated()
 {
 }
 
+//********************************************************************
 bool ModuleBase_WidgetValidated::setSelection(ModuleBase_ViewerPrs theValue)
 {
   bool isDone = false;
@@ -37,13 +38,19 @@ bool ModuleBase_WidgetValidated::setSelection(ModuleBase_ViewerPrs theValue)
   return isDone;
 }
 
+//********************************************************************
 bool ModuleBase_WidgetValidated::isValid(const Handle_SelectMgr_EntityOwner& theOwner)
 {
+  // stores the current values of the widget attribute
   backupAttributeValue(true);
 
+  // saves the owner value to the widget attribute
   setSelection(theOwner);
+
+  // checks the attribute validity
   bool aValid = isValidAttribute();
 
+  // restores the current values of the widget attribute
   backupAttributeValue(false);
 
   return aValid;
index db28807d15628b0c08222dd74b23ea29cf7530db..eea1bca0fa2707b69a799cce4d13a3bed144a662 100644 (file)
@@ -45,6 +45,8 @@ class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidg
 
   /// Set the given wrapped value to the current widget
   /// This value should be processed in the widget according to the needs
+  /// The method is called by the current operation to process the operation preselection.
+  /// It is redefined to check the value validity and if it is, fill the attribute with by value
   /// \param theValue the wrapped widget value
   virtual bool setSelection(ModuleBase_ViewerPrs theValue);
 
index e559fa608b8e464b67a2490b2526c5577ac50ae7..f54e0fbc338c6903339998bfad411f606ee88b05 100644 (file)
@@ -12,7 +12,7 @@
 #include <PartSet_Tools.h>
 #include <SketchPlugin_Feature.h>
 
-bool PartSet_WidgetConstraintShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const
+bool PartSet_WidgetConstraintShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape)
 {
   ObjectPtr aSelectedObject = theSelectedObject;
 
@@ -25,6 +25,7 @@ bool PartSet_WidgetConstraintShapeSelector::storeAttributeValues(ObjectPtr theSe
                                                                   aSelectedObject, mySketch);
       if (aObj) {
         aSelectedObject = aObj;
+        myExternalObject = aObj;
       } else 
         return false;
     }
index 29ca68dafd55b2ae67611c81cc77d4765e8cdec8..ea8bbaa9e7a1a2b0eb657e29f897a22826e15b16 100644 (file)
@@ -47,7 +47,7 @@ protected:
   /// the specific type and set the given values
   /// \param theSelectedObject an object
   /// \param theShape a selected shape, which is used in the selection attribute
-  virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const;
+  virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape);
 
 private:
   /// Pointer to a sketch 
index 45fe790e76675c38f733199dba43de5e6853eeb2..a7ada4a646c433a8f79b2a82c518debf7ff881c2 100644 (file)
@@ -13,7 +13,7 @@
 #include <PartSet_Tools.h>
 #include <SketchPlugin_Feature.h>
 
-bool PartSet_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const
+bool PartSet_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape)
 {
   ObjectPtr aSelectedObject = theSelectedObject;
   GeomShapePtr aShape = theShape;
@@ -30,6 +30,7 @@ bool PartSet_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObje
     if (aObj) {
       PartSet_WidgetShapeSelector* that = (PartSet_WidgetShapeSelector*) this;
       aSelectedObject = aObj;
+      myExternalObject = aObj;
     } else 
       return false;
   } else {
index bae13ae921be71b9add95ce466d7746dd707adf1..f7d075b48cfa3436574e11db2fb3c8fd15df71cb 100644 (file)
@@ -47,7 +47,7 @@ protected:
   /// the specific type and set the given values
   /// \param theSelectedObject an object
   /// \param theShape a selected shape, which is used in the selection attribute
-  virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const;
+  virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape);
 
 private:
   /// Pointer to a sketch 
index d47fadecdcdc159462422c6fffc9261e4f09d327..9f41c9453966513889e52b16646b6e50adf9ceda 100644 (file)
@@ -19,6 +19,7 @@
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_ViewerPrs.h>
 #include <ModuleBase_Tools.h>
+#include <ModuleBase_IModule.h>
 
 #include <GeomAlgoAPI_FaceBuilder.h>
 #include <GeomDataAPI_Point.h>
@@ -46,7 +47,7 @@
 PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent,
                                                      const Config_WidgetAPI* theData,
                                                      const std::string& theParentId)
-    : ModuleBase_ModelWidget(theParent, theData, theParentId),
+    : ModuleBase_WidgetValidated(theParent, theData, theParentId),
       myPreviewDisplayed(false),
       myWorkshop(NULL)
 {
@@ -81,41 +82,43 @@ QList<QWidget*> PartSet_WidgetSketchLabel::getControls() const
 
 void PartSet_WidgetSketchLabel::onPlaneSelected()
 {
+
   XGUI_Selection* aSelection = myWorkshop->selector()->selection();
   QList<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
   if (!aSelected.empty()) {
     ModuleBase_ViewerPrs aPrs = aSelected.first();
-    TopoDS_Shape aShape = aPrs.shape();
-    if (!aShape.IsNull()) {
-      std::shared_ptr<GeomAPI_Dir> aDir = setSketchPlane(aShape);
-      if (aDir) {
-        erasePreviewPlanes();
+    Handle(SelectMgr_EntityOwner) anOwner = aSelected.first().owner();
+    if (isValid(anOwner)) {
+      setSelection(anOwner);
 
-        if (aPrs.object() && (feature() != aPrs.object())) {
-          DataPtr aData = feature()->data();
-          AttributeSelectionPtr aSelAttr = 
-            std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
-            (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
-          if (aSelAttr) {
-            ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aPrs.object());
-            if (aRes) {
-              GeomShapePtr aShapePtr(new GeomAPI_Shape());
-              aShapePtr->setImpl(new TopoDS_Shape(aShape));
-              aSelAttr->setValue(aRes, aShapePtr);
-            }
+      TopoDS_Shape aShape = aPrs.shape();
+      if (!aShape.IsNull()) {
+        erasePreviewPlanes();
+        DataPtr aData = feature()->data();
+        AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+                                  (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+        if (aSelAttr) {
+          GeomShapePtr aShapePtr = aSelAttr->value();
+          if (aShapePtr.get() == NULL || aShapePtr->isNull()) {
+            std::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
+            aGShape->setImpl(new TopoDS_Shape(aShape));
+            // get plane parameters
+            std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
+            std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
+
+            myWorkshop->viewer()->setViewProjection(aDir->x(), aDir->y(), aDir->z());
           }
-        } else
-          myWorkshop->viewer()->setViewProjection(aDir->x(), aDir->y(), aDir->z());
+        }
 
         // Clear text in the label
         myLabel->setText("");
         myLabel->setToolTip("");
         disconnect(myWorkshop->selector(), SIGNAL(selectionChanged()), 
                    this, SLOT(onPlaneSelected()));
+        activateFilters(myWorkshop->module()->workshop(), false);
 
         // Clear selection mode and define sketching mode
-        XGUI_Displayer* aDisp = myWorkshop->displayer();
-        aDisp->removeSelectionFilter(myFaceFilter);
+        //XGUI_Displayer* aDisp = myWorkshop->displayer();
         //aDisp->closeLocalContexts();
         emit planeSelected(plane());
         setSketchingMode();
@@ -147,12 +150,61 @@ void PartSet_WidgetSketchLabel::enableFocusProcessing()
   myLabel->installEventFilter(this);
 }
 
+void PartSet_WidgetSketchLabel::backupAttributeValue(const bool isBackup)
+{
+  // it is not necessary to save the previous plane value because the plane is chosen once
+  if (!isBackup) {
+    DataPtr aData = feature()->data();
+    AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+      (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+    if (aSelAttr) {
+      ResultPtr anEmptyResult;
+      GeomShapePtr anEmptyShape;
+      aSelAttr->setValue(anEmptyResult, anEmptyShape);
+    }
+  }
+}
+
+bool PartSet_WidgetSketchLabel::setSelection(const Handle_SelectMgr_EntityOwner& theOwner)
+{
+  bool isOwnerSet = false;
+
+  ModuleBase_ViewerPrs aPrs;
+  myWorkshop->selector()->selection()->fillPresentation(aPrs, theOwner);
+
+  const TopoDS_Shape& aShape = aPrs.shape();
+  std::shared_ptr<GeomAPI_Dir> aDir;
+
+  if (aPrs.object() && (feature() != aPrs.object())) {
+    DataPtr aData = feature()->data();
+    AttributeSelectionPtr aSelAttr = 
+      std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+      (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+    if (aSelAttr) {
+      ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aPrs.object());
+      if (aRes) {
+        GeomShapePtr aShapePtr(new GeomAPI_Shape());
+        aShapePtr->setImpl(new TopoDS_Shape(aShape));
+        aSelAttr->setValue(aRes, aShapePtr);
+        isOwnerSet = true;
+      }
+    }
+  }
+  else if (!aShape.IsNull()) {
+    aDir = setSketchPlane(aShape);
+    isOwnerSet = aDir;
+  }
+  return isOwnerSet;
+}
+
 void PartSet_WidgetSketchLabel::activateCustom()
 {
   std::shared_ptr<GeomAPI_Pln> aPlane = plane();
   if (aPlane) {
     //setSketchingMode();
     // In order to avoid Opening/Closing of context too often
+    // it can be useful for a delay on the property panel filling
+    // it is possible that it is not necessary anymore, but it requires a check
     mySelectionTimer->start(20);
   } else {
     // We have to select a plane before any operation
@@ -161,9 +213,6 @@ void PartSet_WidgetSketchLabel::activateCustom()
     XGUI_Displayer* aDisp = myWorkshop->displayer();
     //aDisp->openLocalContext();
     //aDisp->activateObjects(QIntList());
-    if (myFaceFilter.IsNull())
-      myFaceFilter = new StdSelect_FaceFilter(StdSelect_Plane);
-    aDisp->addSelectionFilter(myFaceFilter);
     QIntList aModes;
     aModes << TopAbs_FACE;
     aDisp->activateObjects(aModes);
@@ -172,6 +221,8 @@ void PartSet_WidgetSketchLabel::activateCustom()
     myLabel->setToolTip(myTooltip);
 
     connect(myWorkshop->selector(), SIGNAL(selectionChanged()), this, SLOT(onPlaneSelected()));
+    activateFilters(myWorkshop->module()->workshop(), true);
+
     aDisp->updateViewer();
   }
 }
@@ -180,9 +231,7 @@ void PartSet_WidgetSketchLabel::deactivate()
 {
   // Do not set selection mode if the widget was activated for a small moment 
   mySelectionTimer->stop();
-  XGUI_Displayer* aDisp = myWorkshop->displayer();
-  aDisp->removeSelectionFilter(myFaceFilter);
-  //aDisp->removeSelectionFilter(mySketchFilter);
+  //XGUI_Displayer* aDisp = myWorkshop->displayer();
   //aDisp->closeLocalContexts();
   erasePreviewPlanes();
 }
index 9da513f5d2a3bc2527cf0eebc9b3693d5627716b..3e277c68ddd585b59468e6ce4cc2335259eebc3c 100644 (file)
@@ -9,14 +9,13 @@
 
 #include "PartSet.h"
 
-#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_WidgetValidated.h>
 #include <ModuleBase_ViewerFilters.h>
 
 #include <GeomAPI_Pnt.h>
 #include <GeomAPI_Dir.h>
 #include <GeomAPI_AISObject.h>
 
-#include <StdSelect_FaceFilter.hxx>
 #include <TopoDS_Shape.hxx>
 
 class QLabel;
@@ -35,7 +34,7 @@ class XGUI_Workshop;
 * A model widget implementation for a label which provides specific behaviour 
 * for sketcher starting and launching operations
 */
-class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_ModelWidget
+class PARTSET_EXPORT PartSet_WidgetSketchLabel : public ModuleBase_WidgetValidated
 {
 Q_OBJECT
  public:
@@ -80,6 +79,17 @@ signals:
   void planeSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
 
 protected:
+  /// Creates a backup of the current values of the attribute
+  /// It should be realized in the specific widget because of different
+  /// parameters of the current attribute
+  /// \param isBackup a boolean flag, if true, store values from the attribute
+  /// to backup, otherwise set the backed up values to the attribute
+  virtual void backupAttributeValue(const bool isBackup);
+
+  /// Fills the attribute with the value of the selected owner
+  /// \param theOwner a selected owner
+  virtual bool setSelection(const Handle_SelectMgr_EntityOwner& theOwner);
+
   /// Saves the internal parameters to the given feature
   /// \return True in success
   virtual bool storeValueCustom() const
@@ -128,8 +138,6 @@ protected:
   AISObjectPtr myXYPlane;
   bool myPreviewDisplayed;
 
-  Handle(StdSelect_FaceFilter) myFaceFilter;
-
   QTimer* mySelectionTimer;
 };
 
index 1c7974d6db8ce0a37dc876c5c85e93ddcb342c42..4abd354b0ffa3a276aaa14c40a299ba977ea6c51 100644 (file)
@@ -10,7 +10,9 @@
         title="Sketch"
         tooltip="Create a new sketch"
         icon=":icons/sketch.png">
-        <sketch-start-label title="Select a plane on which to create a sketch" tooltip="Select a plane on which to create a sketch"/> 
+        <sketch-start-label id="External" title="Select a plane on which to create a sketch" tooltip="Select a plane on which to create a sketch">
+          <validator id="GeomValidators_Face" parameters="plane"/>
+        </sketch-start-label>
       <!--icon=":pictures/x_point.png"-->
       </feature>
       <feature id="SketchPoint" title="Point" tooltip="Create a new point" icon=":icons/point.png">