]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
authormpv <mpv@opencascade.com>
Wed, 25 Mar 2015 09:00:51 +0000 (12:00 +0300)
committermpv <mpv@opencascade.com>
Wed, 25 Mar 2015 09:00:51 +0000 (12:00 +0300)
Conflicts:
src/SketchPlugin/SketchPlugin_Sketch.cpp

112 files changed:
src/Config/plugins.xml
src/ConstructionPlugin/axis_widget.xml
src/ConstructionPlugin/plane_widget.xml
src/FeaturesPlugin/FeaturesPlugin_Placement.cpp
src/FeaturesPlugin/FeaturesPlugin_Placement.h
src/FeaturesPlugin/extrusion_widget.xml
src/FeaturesPlugin/placement_widget.xml
src/GeomAPI/GeomAPI_AISObject.cpp
src/GeomAPI/GeomAPI_Ax3.cpp
src/GeomAPI/GeomAPI_Ax3.h
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/GeomAPI/GeomAPI_PlanarEdges.cpp
src/GeomAPI/GeomAPI_PlanarEdges.h
src/GeomAlgoAPI/GeomAlgoAPI_Placement.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Placement.h
src/GeomData/GeomData_Dir.cpp
src/GeomData/GeomData_Dir.h
src/GeomDataAPI/GeomDataAPI_Dir.h
src/GeomValidators/CMakeLists.txt
src/GeomValidators/GeomValidators_ConstructionComposite.cpp [new file with mode: 0644]
src/GeomValidators/GeomValidators_ConstructionComposite.h [new file with mode: 0644]
src/GeomValidators/GeomValidators_Edge.cpp [new file with mode: 0644]
src/GeomValidators/GeomValidators_Edge.h [new file with mode: 0644]
src/GeomValidators/GeomValidators_EdgeOrVertex.cpp [new file with mode: 0644]
src/GeomValidators/GeomValidators_EdgeOrVertex.h [new file with mode: 0644]
src/GeomValidators/GeomValidators_Face.cpp [new file with mode: 0644]
src/GeomValidators/GeomValidators_Face.h [new file with mode: 0644]
src/GeomValidators/GeomValidators_Tools.cpp [new file with mode: 0644]
src/GeomValidators/GeomValidators_Tools.h [new file with mode: 0644]
src/Model/Model_AttributeRefList.cpp
src/Model/Model_AttributeReference.cpp
src/Model/Model_AttributeSelection.cpp
src/ModelAPI/CMakeLists.txt
src/ModelAPI/ModelAPI_RefAttrValidator.h [deleted file]
src/ModelAPI/ModelAPI_ResultValidator.h [deleted file]
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_ValidatorFace.cpp [deleted file]
src/ModuleBase/ModuleBase_ValidatorFace.h [deleted file]
src/ModuleBase/ModuleBase_ValidatorLinearEdge.cpp [deleted file]
src/ModuleBase/ModuleBase_ValidatorLinearEdge.h [deleted file]
src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.cpp [deleted file]
src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.h [deleted file]
src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.cpp [deleted file]
src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.h [deleted file]
src/ModuleBase/ModuleBase_WidgetLineEdit.h
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/ModuleBase/ModuleBase_WidgetValidated.cpp
src/ModuleBase/ModuleBase_WidgetValidated.h
src/ParametersPlugin/CMakeLists.txt [new file with mode: 0644]
src/ParametersPlugin/ParametersPlugin.h [new file with mode: 0644]
src/ParametersPlugin/ParametersPlugin_Parameter.cpp [new file with mode: 0644]
src/ParametersPlugin/ParametersPlugin_Parameter.h [new file with mode: 0644]
src/ParametersPlugin/ParametersPlugin_Plugin.cpp [new file with mode: 0644]
src/ParametersPlugin/ParametersPlugin_Plugin.h [new file with mode: 0644]
src/ParametersPlugin/plugin-Parameters.xml [new file with mode: 0644]
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Validators.cpp
src/PartSet/PartSet_Validators.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/PartSet/icons/tangent.png
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_Arc.cpp
src/SketchPlugin/SketchPlugin_Circle.cpp
src/SketchPlugin/SketchPlugin_Line.cpp
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_Point.cpp
src/SketchPlugin/SketchPlugin_ResultValidators.cpp [deleted file]
src/SketchPlugin/SketchPlugin_ResultValidators.h [deleted file]
src/SketchPlugin/SketchPlugin_ShapeValidator.cpp
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_Sketch.h
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/SketchPlugin_Validators.h
src/SketchPlugin/plugin-Sketch.xml
src/SketchSolver/SketchSolver_ConstraintGroup.cpp
src/SketchSolver/SketchSolver_ConstraintGroup.h
src/SketcherPrs/CMakeLists.txt
src/SketcherPrs/SketcherPrs_Equal.cpp
src/SketcherPrs/SketcherPrs_Equal.h
src/SketcherPrs/SketcherPrs_Factory.h
src/SketcherPrs/SketcherPrs_HVDirection.cpp
src/SketcherPrs/SketcherPrs_HVDirection.h
src/SketcherPrs/SketcherPrs_Parallel.cpp
src/SketcherPrs/SketcherPrs_Parallel.h
src/SketcherPrs/SketcherPrs_Perpendicular.cpp
src/SketcherPrs/SketcherPrs_Perpendicular.h
src/SketcherPrs/SketcherPrs_PositionMgr.cpp
src/SketcherPrs/SketcherPrs_PositionMgr.h
src/SketcherPrs/SketcherPrs_Rigid.cpp
src/SketcherPrs/SketcherPrs_Rigid.h
src/SketcherPrs/SketcherPrs_SensitivePoint.cpp [new file with mode: 0644]
src/SketcherPrs/SketcherPrs_SensitivePoint.h [new file with mode: 0644]
src/SketcherPrs/SketcherPrs_SymbolPrs.cpp
src/SketcherPrs/SketcherPrs_SymbolPrs.h
src/SketcherPrs/SketcherPrs_Tangent.cpp
src/SketcherPrs/SketcherPrs_Tangent.h
src/XGUI/XGUI_pictures.qrc
src/XGUI/pictures/expression.png [new file with mode: 0644]

index 212647ecebe1226f313e2423781aa2d9d96fc084..623b8097394293d4479c6302bf8282185a5b657b 100644 (file)
@@ -9,6 +9,7 @@
   <plugin library="FeaturesPlugin" configuration="plugin-Features.xml"/>
   <plugin library="ExchangePlugin" configuration="plugin-Exchange.xml"/>
   <plugin script="ConnectorPlugin" configuration="plugin-Connector.xml" dependency="Geometry"/>
+  <plugin library="ParametersPlugin" configuration="plugin-Parameters.xml"/>
   <plugin library="SketchSolver"/>
   <plugin library="GeomValidators"/>
   <plugin library="DFBrowser" internal="true"/>
index 435a2e7b38242583d3debda97a558b9f9dcf111d..38638ecf59aca9a4297041c2ef54a9aca7d4dddf 100644 (file)
@@ -8,14 +8,14 @@
         icon=":icons/point.png"
         tooltip="Select a first point"
         shape_types="vertex">
-        <validator id="ModuleBase_ValidatorNoConstructionSubShapes"/>
+        <validator id="GeomValidators_ConstructionComposite"/>
       </shape_selector>
       <shape_selector id="SecondPoint"
         label="Second point"
         icon=":icons/point.png"
         tooltip="Select a second point"
         shape_types="vertex">
-        <validator id="ModuleBase_ValidatorNoConstructionSubShapes"/>
+        <validator id="GeomValidators_ConstructionComposite"/>
         <validator id="PartSet_DifferentShapes"/>
       </shape_selector>
     </box>
index 193bfe01913791cdd4715e10e503606fc5eefcfe..4300f5f6f2538f51c5796168ba46dd8cea26f874 100644 (file)
@@ -7,7 +7,7 @@
                       label="Plane face"
                       tooltip="Select a planar face"
                       shape_types="face">
-        <validator id="ModuleBase_ValidatorFace" parameters="plane"/>
+        <validator id="GeomValidators_Face" parameters="plane"/>
       </shape_selector>
       <doublevalue id="distance" 
                    label="Distance" 
index 44ad7523e4f6330e8853cec73da101699c1def22..f97b3248d112e95131995ef81d7cc5a9ec3429bd 100644 (file)
@@ -9,7 +9,9 @@
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeBoolean.h>
 
+#include <GeomAPI_Edge.h>
 #include <GeomAPI_Face.h>
 #include <GeomAPI_Pln.h>
 #include <GeomAlgoAPI_Placement.h>
@@ -24,48 +26,50 @@ 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());
 }
 
 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();
@@ -78,20 +82,37 @@ 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;
+      }
+    }
   }
 
-  std::shared_ptr<GeomAPI_Pln> aBasePlane = aBaseFace1->getPlane();
-  std::shared_ptr<GeomAPI_Pln> aSlavePlane = aSlaveFace1->getPlane();
+  // Flags of the Placement
+  AttributeBooleanPtr aBoolAttr = std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(
+      data()->attribute(FeaturesPlugin_Placement::REVERSE_ID()));
+  bool isReverse = aBoolAttr->value();
+  aBoolAttr = std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(
+      data()->attribute(FeaturesPlugin_Placement::CENTERING_ID()));
+  bool isCentering = aBoolAttr->value();
 
   std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
-  GeomAlgoAPI_Placement aFeature(aSlaveObject, aSlavePlane, aBasePlane);
+  GeomAlgoAPI_Placement aFeature(aSlaveObject, aBaseObject, aSlaveShape, aBaseShape, isReverse, isCentering);
   if(!aFeature.isDone()) {
     static const std::string aFeatureError = "Placement algorithm failed";
     setError(aFeatureError);
index e96541de32bf43b44a7b147077f6d97ac611a45a..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,29 @@ 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()
+  {
+    static const std::string MY_REVERSE_ID("placement_reverse_direction");
+    return MY_REVERSE_ID;
+  }
+  /// attribute name of flag of centering position
+  inline static const std::string& CENTERING_ID()
+  {
+    static const std::string MY_CENTERING_ID("placement_centering");
+    return MY_CENTERING_ID;
   }
 
   /// Returns the kind of a feature
index 1109883fb1629417b689814a97b8ac81ab5194ec..adbe17b11541e5971ca8a5724a65584af036ddc2 100644 (file)
@@ -6,7 +6,7 @@
     icon=":icons/sketch.png"
     tooltip="Select a sketch face"
     type_choice="Faces">
-    <validator id="PartSet_SketchEntityValidator"/>
+    <validator id="PartSet_SketchEntityValidator" parameters="Sketch"/>
   </multi_selector>
   <doublevalue
     id="size"
index fd4924fa027d7f1625c9c85a286d534acd9e573f..109d0d62cf7f4fa3f97fefe89734e455fa5a12c1 100644 (file)
@@ -1,18 +1,26 @@
 <!-- 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
-               icon=":icons/cut_shape.png" 
-               tooltip="Select a face of moved object" 
-               shape_types="face
-               concealment="true" >
-       <validator id="PartSet_DifferentObjects"/>
+  <shape_selector id="placement_attractable_object
+    label="Select an object
+    icon=":icons/cut_shape.png" 
+    tooltip="Select an element of moved object" 
+    shape_types="face edge vertex
+    concealment="true" >
+    <validator id="PartSet_DifferentObjects"/>
   </shape_selector>
+  <boolvalue id="placement_reverse_direction"
+    label="Reverse"
+    default="false"
+    tooltip="Reverse placement direction"/>
+  <boolvalue id="placement_centering"
+    label="Centering"
+    default="false"
+    tooltip="Center faces under placement"/>
 </source>
index f4ae420490bada6d8d4b177459ba93c67198fb94..8f053f7cf90a838a5741d17fb442dc9d6e85ee29 100644 (file)
@@ -311,9 +311,9 @@ void GeomAPI_AISObject::getColor(int& theR, int& theG, int& theB)
     return;
 
   Quantity_Color aColor = anAIS->Color();
-  theR = aColor.Red()*255.;
-  theG = aColor.Green()*255.;
-  theB = aColor.Blue()*255.;
+  theR = (int)(aColor.Red()*255.);
+  theG = (int)(aColor.Green()*255.);
+  theB = (int)(aColor.Blue()*255.);
 }
 
 bool GeomAPI_AISObject::empty() const
index d7950b585126717c0e96d409e92ceb1a7d877d5c..892869a4c9a7f4593af69285648478443bb49e07 100644 (file)
@@ -25,13 +25,11 @@ GeomAPI_Ax3::GeomAPI_Ax3()
 
 GeomAPI_Ax3::GeomAPI_Ax3(std::shared_ptr<GeomAPI_Pnt> theOrigin,
                          std::shared_ptr<GeomAPI_Dir> theDirX,
-                         std::shared_ptr<GeomAPI_Dir> theDirY,
                          std::shared_ptr<GeomAPI_Dir> theNorm)
 : GeomAPI_Interface(new gp_Ax3(theOrigin->impl<gp_Pnt>(), 
                                theNorm->impl<gp_Dir>(), 
                                theDirX->impl<gp_Dir>()))
  {
-   MY_AX3->SetYDirection(theDirY->impl<gp_Dir>());
  }
 
 void GeomAPI_Ax3::setOrigin(const std::shared_ptr<GeomAPI_Pnt>& theOrigin)
index 67bde43efd50a2b1e331ffe33202901c295e5df9..6a554e2b393b3f2516cd7ed9a368fccb92524bf5 100644 (file)
@@ -29,7 +29,6 @@ public:
   /// \param theNorm direction of normal vector
   GeomAPI_Ax3(std::shared_ptr<GeomAPI_Pnt> theOrigin,
               std::shared_ptr<GeomAPI_Dir> theDirX,
-              std::shared_ptr<GeomAPI_Dir> theDirY,
               std::shared_ptr<GeomAPI_Dir> theNorm);
 
   /// Sets origin point
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 f7757cf7e94b7b32a3ad5f0a23067ece92cd4381..619716256d1b81865122b9a0122b880216a5c1b8 100644 (file)
@@ -93,8 +93,7 @@ std::shared_ptr<GeomAPI_Dir> GeomAPI_PlanarEdges::norm() const
 
 void GeomAPI_PlanarEdges::setPlane(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
                                    const std::shared_ptr<GeomAPI_Dir>& theDirX,
-                                   const std::shared_ptr<GeomAPI_Dir>& theDirY,
                                    const std::shared_ptr<GeomAPI_Dir>& theNorm)
 {
-  myPlane = std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(theOrigin, theDirX, theDirY, theNorm));
+  myPlane = std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(theOrigin, theDirX, theNorm));
 }
\ No newline at end of file
index 1eddd16c899ca9bb59c39d39eb34a33eafe47820..c26ad2505e180e386ff739d3852b85012581ab52 100644 (file)
@@ -61,7 +61,6 @@ class GeomAPI_PlanarEdges : public GeomAPI_Shape
   /// \param theNorm normal direction of the plane axis
   GEOMAPI_EXPORT void setPlane(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
                                const std::shared_ptr<GeomAPI_Dir>& theDirX,
-                               const std::shared_ptr<GeomAPI_Dir>& theDirY,
                                const std::shared_ptr<GeomAPI_Dir>& theNorm);
 
 private:
index 3cc4f85aedc6bea31cedcd8ecf2e713996ef2a54..9933454463b8291eeb282c427c6cda2f7708dcc0 100644 (file)
 #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>
 #include <gp_Quaternion.hxx>
 #include <TopExp_Explorer.hxx>
 #include <BRepCheck_Analyzer.hxx>
+#include <BRepClass3d_SolidClassifier.hxx>
 #include <GProp_GProps.hxx>
 #include <BRepGProp.hxx>
 #include <Precision.hxx>
+
 #define DEB_PLACEMENT 1
 GeomAlgoAPI_Placement::GeomAlgoAPI_Placement(
-    std::shared_ptr<GeomAPI_Shape> theAttractiveFace,
-    std::shared_ptr<GeomAPI_Pln> theSourcePlane,
-    std::shared_ptr<GeomAPI_Pln> theDestPlane)
+    std::shared_ptr<GeomAPI_Shape> theSourceSolid,
+    std::shared_ptr<GeomAPI_Shape> theDestSolid,
+    std::shared_ptr<GeomAPI_Shape> theSourceShape,
+    std::shared_ptr<GeomAPI_Shape> theDestShape,
+    bool theIsReverse,
+    bool theIsCentering)
   : myDone(false),
     myShape(new GeomAPI_Shape())
 {
-  build(theAttractiveFace, theSourcePlane, theDestPlane);
+  build(theSourceSolid, theDestSolid, theSourceShape, theDestShape, theIsReverse, theIsCentering);
 }
 
 void GeomAlgoAPI_Placement::build(
-    const std::shared_ptr<GeomAPI_Shape>& theAttractiveShape,
-    const std::shared_ptr<GeomAPI_Pln>& theSourcePlane,
-    const std::shared_ptr<GeomAPI_Pln>& theDestPlane)
+    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,
+    bool theIsReverse,
+    bool theIsCentering)
 {
-  std::shared_ptr<GeomAPI_Dir> aSourceDir = theSourcePlane->direction();
-  std::shared_ptr<GeomAPI_Pnt> aSourceLoc = theSourcePlane->location();
-  std::shared_ptr<GeomAPI_Dir> aDestDir = theDestPlane->direction();
-  std::shared_ptr<GeomAPI_Pnt> aDestLoc = theDestPlane->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();
+  }
+
+  // Initial shapes
+  const TopoDS_Shape& aSourceShape = theSourceSolid->impl<TopoDS_Shape>();
+  const TopoDS_Shape& aDestShape = theDestSolid->impl<TopoDS_Shape>();
+  // Check the material of the solids to be on the correct side
+  BRepClass3d_SolidClassifier aClassifier;
+  static const double aTransStep = 10. * Precision::Confusion();
+  if (hasNormal[0]) {
+    aClassifier.Load(aSourceShape);
+    gp_Pnt aPoint = aSrcDstPoints[0];
+    aPoint.Translate(aSrcDstNormals[0] * aTransStep);
+    aClassifier.Perform(aPoint, Precision::Confusion());
+    if ((aClassifier.State() == TopAbs_OUT && !theIsReverse) ||
+        (aClassifier.State() == TopAbs_IN && theIsReverse))
+      aSrcDstNormals[0].Reverse();
+  }
+  if (hasNormal[1]) {
+    aClassifier.Load(aDestShape);
+    gp_Pnt aPoint = aSrcDstPoints[1];
+    aPoint.Translate(aSrcDstNormals[1] * aTransStep);
+    aClassifier.Perform(aPoint, Precision::Confusion());
+    if (aClassifier.State() == TopAbs_IN)
+      aSrcDstNormals[1].Reverse();
+  }
+
+  // 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);
+        aSrcDstNormals[1].Normalize();
+        if (aSrcDstDirections[0].Dot(aSrcDstDirections[1]) < -Precision::Confusion())
+          aSrcDstNormals[1].Reverse();
+      } 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];
+      }
+    }
+  }
+
+  // Reverse the normal if it was not done before
+  if (!hasNormal[0] && theIsReverse)
+    aSrcDstNormals[0].Reverse();
 
   // 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];
+  gp_Vec aSrcDir = aSrcDstNormals[0];
+  gp_Vec aDstDir = aSrcDstNormals[1];
+  // Calculate rotation
   gp_Quaternion aRot(aSrcDir, aDstDir);
   aTrsf.SetRotation(aRot);
-  gp_Vec aSrcCenter(aSourceLoc->x(), aSourceLoc->y(), aSourceLoc->z());
-  aSrcCenter.Transform(aTrsf);
-  gp_Vec aTrans(aDestLoc->x() - aSrcCenter.X(),
-                aDestLoc->y() - aSrcCenter.Y(),
-                aDestLoc->z() - aSrcCenter.Z());
+  // Calculate translation
+  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);
+  gp_Vec aTrans = aDstLoc - aSrcLoc;
   aTrsf.SetTransformation(aRot, aTrans);
 
   // Transform the shape with copying it
-  const TopoDS_Shape& aShape = theAttractiveShape->impl<TopoDS_Shape>();
-  BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aShape, aTrsf, true);
+  BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, aTrsf, true);
   if(aBuilder) {
     setImpl(aBuilder);
     myDone = aBuilder->IsDone() == Standard_True;
index 7bebf97c991277d85bf28dbdffffad328b9bc7e7..1e1e88e49c1e045a0fb968ce331dec0ec2b4ef95 100644 (file)
 #include <GeomAlgoAPI.h>
 #include <GeomAPI_Shape.h>
 #include <GeomAPI_Dir.h>
-#include <GeomAPI_Pln.h>
+#include <GeomAPI_Face.h>
 #include <GeomAlgoAPI_MakeShape.h>
 #include <GeomAPI_DataMapOfShapeShape.h>
 #include <memory>
 
 /**\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] theAttractiveShape shape to be moved
-   *  \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> theAttractiveShape,
-                                           std::shared_ptr<GeomAPI_Pln> theSourcePlane,
-                                           std::shared_ptr<GeomAPI_Pln> theDestPlane);
+  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,
+                                           bool theIsReverse = false,
+                                           bool theIsCentering = false);
 
   /// Returns True if algorithm succeed
   GEOMALGOAPI_EXPORT const bool isDone() const
@@ -56,9 +62,12 @@ public:
 
 private:
   /// builds resulting shape
-  void build(const std::shared_ptr<GeomAPI_Shape>& theAttractiveShape,
-             const std::shared_ptr<GeomAPI_Pln>& theSourcePlane,
-             const std::shared_ptr<GeomAPI_Pln>& theDestPlane);
+  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,
+             bool theIsReverse,
+             bool theIsCentering);
 
   /// fields
   bool myDone;
index d36e8a8f5c84685b7b3d6fbc879ee6aa03ca2fa2..d5272dda21f432786c2ca04ff8e983b99a7a5108 100644 (file)
@@ -5,7 +5,8 @@
 // Author:      Mikhail PONIKAROV
 
 #include "GeomData_Dir.h"
-#include "GeomAPI_Dir.h"
+#include <GeomAPI_Dir.h>
+#include <GeomAPI_XYZ.h>
 #include <gp_Dir.hxx>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Data.h>
@@ -49,6 +50,12 @@ std::shared_ptr<GeomAPI_Dir> GeomData_Dir::dir()
       new GeomAPI_Dir(myCoords->Value(0), myCoords->Value(1), myCoords->Value(2)));
 }
 
+std::shared_ptr<GeomAPI_XYZ> GeomData_Dir::xyz()
+{
+  return std::shared_ptr<GeomAPI_XYZ>(
+      new GeomAPI_XYZ(myCoords->Value(0), myCoords->Value(1), myCoords->Value(2)));
+}
+
 GeomData_Dir::GeomData_Dir(TDF_Label& theLabel)
 {
   myIsInitialized = theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords) == Standard_True;
index 0080ffbc6df16c357a0c95ff11475b592b34b861..debd400552702b68455955f17d775b3f6f97d8ae 100644 (file)
@@ -14,6 +14,7 @@
 #include <memory>
 
 class GeomAPI_Dir;
+class GeomAPI_XYZ;
 
 /**\class GeomData_Dir
  * \ingroup DataModel
@@ -36,6 +37,8 @@ class GeomData_Dir : public GeomDataAPI_Dir
   GEOMDATA_EXPORT virtual double z() const;
   /// Returns the direction of this attribute
   GEOMDATA_EXPORT virtual std::shared_ptr<GeomAPI_Dir> dir();
+  /// Returns the coordinates of this attribute
+  GEOMDATA_EXPORT virtual std::shared_ptr<GeomAPI_XYZ> xyz();
 
  protected:
   /// Initializes attributes
index 968edb2325670112dc8e008c5afb2bb9c383ea1e..85d4b3a8c433706c41f92d0fb9580b719664c364 100644 (file)
@@ -11,6 +11,7 @@
 #include <ModelAPI_Attribute.h>
 
 class GeomAPI_Dir;
+class GeomAPI_XYZ;
 
 /**\class GeomDataAPI_Dir
  * \ingroup DataModel
@@ -33,6 +34,8 @@ class GeomDataAPI_Dir : public ModelAPI_Attribute
   virtual double z() const = 0;
   /// Returns the direction of this attribute
   virtual std::shared_ptr<GeomAPI_Dir> dir() = 0;
+  /// Returns the coordinates of this attribute
+  virtual std::shared_ptr<GeomAPI_XYZ> xyz() = 0;
 
   /// Returns the type of this class of attributes
   static inline std::string type()
index 51263163459b727449b3e67f666bd782e0b76c3a..3a07a17cbbf265f6c6f072ceb97ada89bbcfea0c 100644 (file)
@@ -4,27 +4,41 @@ INCLUDE(Common)
 
 SET(PROJECT_HEADERS
     GeomValidators.h
+    GeomValidators_ConstructionComposite.h
+    GeomValidators_Edge.h
+    GeomValidators_EdgeOrVertex.h
+    GeomValidators_Face.h
     GeomValidators_Positive.h
+    GeomValidators_Tools.h
 )
 
 SET(PROJECT_SOURCES
+    GeomValidators_ConstructionComposite.cpp
+    GeomValidators_Edge.cpp
+    GeomValidators_EdgeOrVertex.cpp
+    GeomValidators_Face.cpp
     GeomValidators_Positive.cpp
+    GeomValidators_Tools.cpp
 )
 
 SET(PROJECT_LIBRARIES
     ModelAPI 
-    Events 
+    Events
+    GeomAPI
 )
 
 
 
-ADD_DEFINITIONS(-DGEOMVALIDATORS_EXPORTS)
+ADD_DEFINITIONS(-DGEOMVALIDATORS_EXPORTS ${CAS_DEFINITIONS})
 ADD_LIBRARY(GeomValidators SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
 TARGET_LINK_LIBRARIES(GeomValidators ${PROJECT_LIBRARIES})
 
 INCLUDE_DIRECTORIES(
-  ../ModelAPI
-  ../Events
+  ${CAS_INCLUDE_DIRS}
+  ${CMAKE_SOURCE_DIR}/src/ModelAPI
+  ${CMAKE_SOURCE_DIR}/src/Events
+  ${CMAKE_SOURCE_DIR}/src/GeomAPI
+  ${CMAKE_SOURCE_DIR}/src/GeomDataAPI
 )
 
 INSTALL(TARGETS GeomValidators DESTINATION plugins)
diff --git a/src/GeomValidators/GeomValidators_ConstructionComposite.cpp b/src/GeomValidators/GeomValidators_ConstructionComposite.cpp
new file mode 100644 (file)
index 0000000..fea2319
--- /dev/null
@@ -0,0 +1,48 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#include "GeomValidators_ConstructionComposite.h"
+
+#include "ModelAPI_AttributeSelection.h"
+#include "ModelAPI_ResultConstruction.h"
+#include "ModelAPI_CompositeFeature.h"
+
+bool GeomValidators_ConstructionComposite::isValid(const AttributePtr& theAttribute,
+                                              const std::list<std::string>& theArguments) const
+{
+  bool aValid = false;
+  AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+                                                                (theAttribute);
+  if (aSelectionAttr.get() == NULL)
+    return aValid;
+
+  ResultPtr aResult = aSelectionAttr->context();
+  GeomShapePtr aShape = aSelectionAttr->value();
+  // global selection should be ignored, the filter processes only selected sub-shapes
+  // that means, that the shape of the context result is equal to the shape value
+  ///*ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
+  if (aResult.get() != NULL) {
+    GeomShapePtr aShapePtr = aResult->shape();
+    // it is important to call isEqual of the shape of result.
+    // It is a GeomAPI_Vertex shape for the point. The shape of the parameter is 
+    // GeomAPI_Shape. It is important to use the realization of the isEqual method from
+    // GeomAPI_Vertex class
+    aValid = aShapePtr.get() != NULL && aShapePtr->isEqual(aShape);
+  }
+  if (!aValid) {
+    ResultConstructionPtr aConstr =
+                            std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
+    if (aConstr != NULL) {
+      // it provides selection only on compositie features, construction without composite
+      // feature is not selectable
+      FeaturePtr aFeature = ModelAPI_Feature::feature(aConstr);
+      CompositeFeaturePtr aComposite = 
+                             std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
+      aValid = aComposite && aComposite->numberOfSubs() > 0;
+    }
+    else {
+      // non-construction results should be accepted by this filter, e.g. body results
+      aValid = true;
+    }
+  }
+  return aValid;
+}
diff --git a/src/GeomValidators/GeomValidators_ConstructionComposite.h b/src/GeomValidators/GeomValidators_ConstructionComposite.h
new file mode 100644 (file)
index 0000000..abe123f
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomValidators_ConstructionComposite.h
+// Created:     20 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef GeomValidators_ConstructionComposite_H
+#define GeomValidators_ConstructionComposite_H
+
+#include "GeomValidators.h"
+#include "ModelAPI_AttributeValidator.h"
+
+/**
+* \ingroup Validators
+* A validator of selection
+*/
+class GeomValidators_ConstructionComposite : public ModelAPI_AttributeValidator
+{
+ public:
+   GEOMVALIDATORS_EXPORT GeomValidators_ConstructionComposite() {}
+  //! returns true if attribute is valid
+  //! \param theAttribute the checked attribute
+  //! \param theArguments arguments of the attribute
+  GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+                                             const std::list<std::string>& theArguments) const;
+};
+
+#endif
diff --git a/src/GeomValidators/GeomValidators_Edge.cpp b/src/GeomValidators/GeomValidators_Edge.cpp
new file mode 100644 (file)
index 0000000..0518f4a
--- /dev/null
@@ -0,0 +1,65 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+
+#include "GeomValidators_Edge.h"
+#include "GeomValidators_Tools.h"
+
+#include <GeomAPI_Curve.h>
+#include <Events_Error.h>
+#include <ModelAPI_Result.h>
+
+#include <StdSelect_TypeOfEdge.hxx>
+
+#include <string>
+#include <map>
+
+
+typedef std::map<std::string, GeomValidators_Edge::TypeOfEdge> EdgeTypes;
+static EdgeTypes MyEdgeTypes;
+
+GeomValidators_Edge::TypeOfEdge GeomValidators_Edge::edgeType(const std::string& theType)
+{
+  if (MyEdgeTypes.size() == 0) {
+    MyEdgeTypes["line"] = Line;
+    MyEdgeTypes["circle"] = Circle;
+  }
+  std::string aType = std::string(theType.c_str());
+  if (MyEdgeTypes.find(aType) != MyEdgeTypes.end())
+    return MyEdgeTypes[aType];
+  
+  Events_Error::send("Edge type defined in XML is not implemented!");
+  return AnyEdge;
+}
+
+bool GeomValidators_Edge::isValid(const AttributePtr& theAttribute,
+                                  const std::list<std::string>& theArguments) const
+{
+  bool aValid = false;
+
+  TypeOfEdge anEdgeType = AnyEdge;
+  if (theArguments.size() == 1) {
+    std::string anArgument = theArguments.front();
+    anEdgeType = edgeType(anArgument);
+  }
+
+  ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute);
+  if (anObject.get() != NULL) {
+    FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+    if (aResult.get() != NULL) {
+      GeomShapePtr aShape = aResult->shape();
+      if (aShape.get() != NULL && aShape->isEdge()) {
+        aValid = anEdgeType == AnyEdge;
+        if (!aValid) {
+          bool isCircle = GeomAPI_Curve(aShape).isCircle();
+          aValid = (isCircle && anEdgeType == Circle) ||
+                   (!isCircle && anEdgeType == Line);
+        }
+      }
+    }
+  }
+  else {
+    //AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+  }
+  return aValid;
+}
diff --git a/src/GeomValidators/GeomValidators_Edge.h b/src/GeomValidators/GeomValidators_Edge.h
new file mode 100644 (file)
index 0000000..5b29a82
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomValidators_Edge.h
+// Created:     19 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef GeomValidators_Edge_H
+#define GeomValidators_Edge_H
+
+#include "GeomValidators.h"
+#include "ModelAPI_AttributeValidator.h"
+
+#include <string>
+
+/**
+* \ingroup Validators
+* A validator of selection
+*/
+class GeomValidators_Edge : public ModelAPI_AttributeValidator
+{
+ public:
+  //  the edge type
+  enum TypeOfEdge
+  {
+    AnyEdge,
+    Line,
+    Circle
+  };
+
+ public:
+   GEOMVALIDATORS_EXPORT GeomValidators_Edge() {}
+  //! returns true if attribute is valid
+  //! \param theAttribute the checked attribute
+  //! \param theArguments arguments of the attribute
+  GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+                                             const std::list<std::string>& theArguments) const;
+protected:
+  /// Convert string to TypeOfEdge value
+  /// \param theType a string value
+  static TypeOfEdge edgeType(const std::string& theType);
+};
+
+#endif
diff --git a/src/GeomValidators/GeomValidators_EdgeOrVertex.cpp b/src/GeomValidators/GeomValidators_EdgeOrVertex.cpp
new file mode 100644 (file)
index 0000000..642d1cd
--- /dev/null
@@ -0,0 +1,62 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+
+#include "GeomValidators_EdgeOrVertex.h"
+#include "GeomValidators_Tools.h"
+#include "GeomValidators_Edge.h"
+
+#include "ModelAPI_AttributeRefAttr.h"
+#include "ModelAPI_Result.h"
+
+#include <ModelAPI_Session.h>
+
+#include <GeomAPI_Curve.h>
+#include <GeomDataAPI_Point2D.h>
+
+#include <Events_Error.h>
+
+#include <StdSelect_TypeOfEdge.hxx>
+
+#include <QString>
+#include <QMap>
+
+
+bool GeomValidators_EdgeOrVertex::isValid(const AttributePtr& theAttribute,
+                                          const std::list<std::string>& theArguments) const
+{
+  bool aValid = false;
+
+  // 1. check whether the attribute is a linear edge
+    // there is a check whether the feature contains a point and a linear edge or two point values
+  SessionPtr aMgr = ModelAPI_Session::get();
+  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+
+  const GeomValidators_Edge* aLinearEdgeValidator =
+    dynamic_cast<const GeomValidators_Edge*>(aFactory->validator("GeomValidators_Edge"));
+
+  std::list<std::string> anArguments;
+  anArguments.push_back("line");
+  aValid = aLinearEdgeValidator->isValid(theAttribute, anArguments);
+  if (!aValid) {
+    //2. check whether the attribute is a vertex
+    ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute);
+    if (anObject.get() != NULL) {
+      FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+      ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+      if (aResult.get() != NULL) {
+        GeomShapePtr aShape = aResult->shape();
+        if (aShape.get() != NULL) {
+          aValid = aShape->isVertex();
+        }
+      }
+    }
+    else {
+      AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+      if (anAttr.get() != NULL) {
+        AttributePtr aRefAttr = anAttr->attr();
+        aValid = aRefAttr.get() != NULL && aRefAttr->attributeType() == GeomDataAPI_Point2D::type();
+      }
+    }
+  }
+  return aValid;
+}
diff --git a/src/GeomValidators/GeomValidators_EdgeOrVertex.h b/src/GeomValidators/GeomValidators_EdgeOrVertex.h
new file mode 100644 (file)
index 0000000..52b7add
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomValidators_EdgeOrVertex.h
+// Created:     19 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef GeomValidators_EdgeOrVertex_H
+#define GeomValidators_EdgeOrVertex_H
+
+#include "GeomValidators.h"
+#include "ModelAPI_AttributeValidator.h"
+
+#include <StdSelect_TypeOfEdge.hxx>
+
+/**
+* \ingroup Validators
+* A validator of selection
+*/
+class GeomValidators_EdgeOrVertex : public ModelAPI_AttributeValidator
+{
+ public:
+   GEOMVALIDATORS_EXPORT GeomValidators_EdgeOrVertex() {}
+  //! returns true if attribute is valid
+  //! \param theAttribute the checked attribute
+  //! \param theArguments arguments of the attribute
+  GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+                                             const std::list<std::string>& theArguments) const;
+};
+
+#endif
diff --git a/src/GeomValidators/GeomValidators_Face.cpp b/src/GeomValidators/GeomValidators_Face.cpp
new file mode 100644 (file)
index 0000000..821b45c
--- /dev/null
@@ -0,0 +1,65 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+
+#include "GeomValidators_Face.h"
+#include "GeomValidators_Tools.h"
+
+#include "ModelAPI_AttributeSelection.h"
+
+#include <GeomAPI_Face.h>
+
+#include <Events_Error.h>
+
+#include <QString>
+#include <QMap>
+
+typedef std::map<std::string, GeomAbs_SurfaceType> FaceTypes;
+static FaceTypes MyFaceTypes;
+
+GeomAbs_SurfaceType GeomValidators_Face::faceType(const std::string& theType)
+{
+  if (MyFaceTypes.size() == 0) {
+    MyFaceTypes["plane"] = GeomAbs_Plane;
+    MyFaceTypes["cylinder"] = GeomAbs_Cylinder;
+  }
+  std::string aType = std::string(theType.c_str());
+  if (MyFaceTypes.find(aType) != MyFaceTypes.end())
+    return MyFaceTypes[aType];
+  
+  Events_Error::send("Face type defined in XML is not implemented!");
+  return GeomAbs_Plane;
+}
+
+bool GeomValidators_Face::isValid(const AttributePtr& theAttribute,
+                                  const std::list<std::string>& theArguments) const
+{
+  bool aValid = false;
+
+  GeomAbs_SurfaceType aFaceType = GeomAbs_Plane;
+  if (theArguments.size() == 1) {
+    std::string anArgument = theArguments.front();
+    aFaceType = faceType(anArgument);
+  }
+
+  ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute);
+  if (anObject.get() != NULL) {
+    AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+                                                                 (theAttribute);
+    std::shared_ptr<GeomAPI_Shape> aGeomShape = aSelectionAttr->value();
+    std::shared_ptr<GeomAPI_Face> aGeomFace(new GeomAPI_Face(aGeomShape));
+    if (aGeomFace.get() != NULL) {
+      switch(aFaceType) {
+          case GeomAbs_Plane:
+            aValid = aGeomFace->isPlanar();
+            break;
+          case GeomAbs_Cylinder:
+            break;
+          default:
+            break;
+      }
+    }
+  }
+  else
+    aValid = true; // an empty face selected is valid.
+  return aValid;
+}
diff --git a/src/GeomValidators/GeomValidators_Face.h b/src/GeomValidators/GeomValidators_Face.h
new file mode 100644 (file)
index 0000000..2ff4955
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomValidators_Face.h
+// Created:     20 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef GeomValidators_Face_H
+#define GeomValidators_Face_H
+
+#include "GeomValidators.h"
+#include "ModelAPI_AttributeValidator.h"
+
+#include <GeomAbs_SurfaceType.hxx>
+
+/**
+* \ingroup Validators
+* A validator of selection
+*/
+class GeomValidators_Face : public ModelAPI_AttributeValidator
+{
+ public:
+   GEOMVALIDATORS_EXPORT GeomValidators_Face() {}
+  //! returns true if attribute is valid
+  //! \param theAttribute the checked attribute
+  //! \param theArguments arguments of the attribute
+  GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+                                             const std::list<std::string>& theArguments) const;
+protected:
+  /// Convert string to TypeOfFace value
+  /// \param theType a string value
+  GEOMVALIDATORS_EXPORT static GeomAbs_SurfaceType faceType(const std::string& theType);
+};
+
+#endif
diff --git a/src/GeomValidators/GeomValidators_Tools.cpp b/src/GeomValidators/GeomValidators_Tools.cpp
new file mode 100644 (file)
index 0000000..f98088e
--- /dev/null
@@ -0,0 +1,36 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomValidators_Tools.cpp
+// Created:     06 Aug 2014
+// Author:      Vitaly Smetannikov
+
+#include "GeomValidators_Tools.h"
+
+#include "ModelAPI_AttributeRefAttr.h"
+#include "ModelAPI_AttributeSelection.h"
+#include "ModelAPI_AttributeReference.h"
+
+namespace GeomValidators_Tools {
+
+  ObjectPtr getObject(const AttributePtr& theAttribute)
+  {
+    ObjectPtr anObject;
+    std::string anAttrType = theAttribute->attributeType();
+    if (anAttrType == ModelAPI_AttributeRefAttr::type()) {
+      AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+      if (anAttr != NULL && anAttr->isObject())
+        anObject = anAttr->object();
+    }
+    if (anAttrType == ModelAPI_AttributeSelection::type()) {
+      AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+      if (anAttr != NULL && anAttr->isInitialized())
+        anObject = anAttr->context();
+    }
+    if (anAttrType == ModelAPI_AttributeReference::type()) {
+      AttributeReferencePtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
+      if (anAttr.get() != NULL && anAttr->isInitialized())
+        anObject = anAttr->value();
+    }
+    return anObject;
+  }
+}
diff --git a/src/GeomValidators/GeomValidators_Tools.h b/src/GeomValidators/GeomValidators_Tools.h
new file mode 100644 (file)
index 0000000..bb1db66
--- /dev/null
@@ -0,0 +1,23 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomValidators_Tools.h
+// Created:     23 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef GeomValidators_Tools_HeaderFile
+#define GeomValidators_Tools_HeaderFile
+
+#include "GeomValidators.h"
+#include "ModelAPI_Object.h"
+#include "ModelAPI_Attribute.h"
+
+
+namespace GeomValidators_Tools
+{
+  // Returns the object from the attribute
+  /// \param theObj an object 
+  GEOMVALIDATORS_EXPORT ObjectPtr getObject(const AttributePtr& theAttribute);
+
+};
+
+#endif
index effa56db232cb21a0989fc801baad662fcf283a1..c9722835887b00258b8e1acbac9797dac0dd06c1 100644 (file)
@@ -16,6 +16,12 @@ void Model_AttributeRefList::append(ObjectPtr theObject)
 {
   std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theObject->data());
   myRef->Append(aData->label().Father());  // store label of the object
+  // do it before the transaction finish to make just created/removed objects know dependencies
+  // and reference from composite feature is removed automatically
+  FeaturePtr anOwnerFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(owner());
+  if (anOwnerFeature.get()) {
+    aData->addBackReference(anOwnerFeature, id());
+  }
 
   owner()->data()->sendAttributeUpdated(this);
 }
index 43bbabe658fff74259890026c982b1302d55670c..91de64eb567de9f94889a6274c98f8ae8c6dcebc 100644 (file)
@@ -22,9 +22,9 @@ void Model_AttributeReference::setValue(ObjectPtr theObject)
   if(!theObject)
     return;
   if (!myIsInitialized || value() != theObject) {
-      std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(
-          theObject->data());
-      TDF_Label anObjLab = aData->label().Father(); // object label
+    std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(
+        theObject->data());
+    TDF_Label anObjLab = aData->label().Father(); // object label
 
     if (owner()->document() == theObject->document()) { // same document, use reference attribute
 
@@ -41,6 +41,12 @@ void Model_AttributeReference::setValue(ObjectPtr theObject)
       TDF_Tool::Entry(anObjLab, anEntry);
       TDataStd_AsciiString::Set(myRef->Label(), anEntry);
     }
+    // do it before the transaction finish to make just created/removed objects know dependencies
+    // and reference from composite feature is removed automatically
+    FeaturePtr anOwnerFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(owner());
+    if (anOwnerFeature.get()) {
+      aData->addBackReference(anOwnerFeature, id());
+    }
 
     owner()->data()->sendAttributeUpdated(this);
   }
index c09fff9920d521959be52a8b9072d5a0c4e47abe..f1cf7fa5b42f4b8266c9cfac080b76ed11ed2e57 100644 (file)
@@ -85,6 +85,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 44602ce1c17ab5e8dbff136c9bab23e62280acb5..d20cb1d0577efcce3100ed7fca8f90172b2c6b96 100644 (file)
@@ -28,14 +28,12 @@ SET(PROJECT_HEADERS
     ModelAPI_FeatureValidator.h
     ModelAPI_Object.h
     ModelAPI_Plugin.h
-    ModelAPI_RefAttrValidator.h 
     ModelAPI_Result.h
     ModelAPI_ResultBody.h
     ModelAPI_ResultConstruction.h
     ModelAPI_ResultGroup.h
     ModelAPI_ResultParameters.h
     ModelAPI_ResultPart.h
-    ModelAPI_ResultValidator.h
     ModelAPI_Session.h
     ModelAPI_Tools.h
     ModelAPI_ShapeValidator.h
diff --git a/src/ModelAPI/ModelAPI_RefAttrValidator.h b/src/ModelAPI/ModelAPI_RefAttrValidator.h
deleted file mode 100644 (file)
index 087cff4..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        ModelAPI_RefAttrValidator.h
-// Created:     5 Aug 2014
-// Author:      Vitaly SMETANNIKOV
-
-#ifndef ModelAPI_RefAttrValidator_H
-#define ModelAPI_RefAttrValidator_H
-
-#include <ModelAPI_Feature.h>
-#include <ModelAPI_Object.h>
-#include <ModelAPI_Attribute.h>
-#include <ModelAPI_AttributeValidator.h>
-
-/**\class ModelAPI_RefAttrValidator
- * \ingroup DataModel
- * Used for filtering out the object that can be used for reference attribute value
- */
-class ModelAPI_RefAttrValidator : public ModelAPI_AttributeValidator
-{
-public:
-};
-
-#endif
diff --git a/src/ModelAPI/ModelAPI_ResultValidator.h b/src/ModelAPI/ModelAPI_ResultValidator.h
deleted file mode 100644 (file)
index 01d73ea..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        ModelAPI_ResultValidators.h
-// Created:     23 July 2014
-// Author:      Vitaly SMETANNIKOV
-
-#ifndef ModelAPI_ResultValidators_H
-#define ModelAPI_ResultValidators_H
-
-#include "ModelAPI_Validator.h"
-#include "ModelAPI_Object.h"
-
-/**\class ModelAPI_ResultValidator
- * \ingroup DataModel
- * \brief The base class for selection filter for results of features.
- *
- * The referenced arguments of feature is normally results displayed in the viewer or by the 
- * selection attribute. This filter allows to filter out the results not usable as this argument.
- */
-class ModelAPI_ResultValidator : public ModelAPI_Validator
-{
-public:
-  /// The abstract method for implementation in the specific validator.
-  /// \param theObject the checked object as an argument
-  /// \returns true if object is OK for this filter
-  virtual bool isValid(const ObjectPtr theObject) const = 0;
-};
-
-#endif
index 5dcc4090847854c573fe73a7cb3cdbec443a0ad8..b623713fc7ef550ae99d708c8e438e319631705e 100644 (file)
@@ -37,10 +37,6 @@ SET(PROJECT_HEADERS
        ModuleBase_IViewer.h
        ModuleBase_WidgetLineEdit.h
        ModuleBase_WidgetMultiSelector.h
-       ModuleBase_ValidatorFace.h
-       ModuleBase_ValidatorLinearEdge.h
-       ModuleBase_ValidatorLinearEdgeOrVertex.h
-       ModuleBase_ValidatorNoConstructionSubShapes.h
        ModuleBase_ViewerFilters.h
        ModuleBase_ResultPrs.h
        ModuleBase_IViewWindow.h
@@ -84,10 +80,6 @@ SET(PROJECT_SOURCES
        ModuleBase_DoubleSpinBox.cpp
        ModuleBase_WidgetLineEdit.cpp
        ModuleBase_WidgetMultiSelector.cpp
-       ModuleBase_ValidatorFace.cpp
-       ModuleBase_ValidatorLinearEdge.cpp
-       ModuleBase_ValidatorLinearEdgeOrVertex.cpp
-       ModuleBase_ValidatorNoConstructionSubShapes.cpp
        ModuleBase_ViewerFilters.cpp
        ModuleBase_ResultPrs.cpp
        ModuleBase_WidgetLabel.cpp
@@ -108,6 +100,7 @@ SET(PROJECT_LIBRARIES
        ModelAPI
        GeomAPI
        GeomAlgoAPI
+       GeomValidators
        ${QT_LIBRARIES}
        ${CAS_VIEWER}
        ${CAS_KERNEL}
@@ -135,6 +128,7 @@ INCLUDE_DIRECTORIES(
     ${CMAKE_SOURCE_DIR}/src/GeomDataAPI
     ${CMAKE_SOURCE_DIR}/src/GeomAPI
     ${CMAKE_SOURCE_DIR}/src/GeomAlgoAPI
+    ${CMAKE_SOURCE_DIR}/src/GeomValidators
     ${SUIT_INCLUDE}
 )
 
diff --git a/src/ModuleBase/ModuleBase_ValidatorFace.cpp b/src/ModuleBase/ModuleBase_ValidatorFace.cpp
deleted file mode 100644 (file)
index fbc389b..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-
-#include "ModuleBase_ValidatorFace.h"
-#include "ModuleBase_WidgetShapeSelector.h"
-
-#include "ModelAPI_AttributeSelection.h"
-
-#include <GeomAPI_Face.h>
-
-#include <Events_Error.h>
-
-#include <QString>
-#include <QMap>
-
-typedef QMap<QString, GeomAbs_SurfaceType> FaceTypes;
-static FaceTypes MyFaceTypes;
-
-GeomAbs_SurfaceType ModuleBase_ValidatorFace::faceType(const std::string& theType)
-{
-  if (MyFaceTypes.count() == 0) {
-    MyFaceTypes["plane"] = GeomAbs_Plane;
-    MyFaceTypes["cylinder"] = GeomAbs_Cylinder;
-  }
-  QString aType = QString(theType.c_str()).toLower();
-  if (MyFaceTypes.contains(aType))
-    return MyFaceTypes[aType];
-  
-  Events_Error::send("Face type defined in XML is not implemented!");
-  return GeomAbs_Plane;
-}
-
-bool ModuleBase_ValidatorFace::isValid(const AttributePtr& theAttribute,
-                                       const std::list<std::string>& theArguments) const
-{
-  bool aValid = false;
-
-  GeomAbs_SurfaceType aFaceType = GeomAbs_Plane;
-  if (theArguments.size() == 1) {
-    std::string anArgument = theArguments.front();
-    aFaceType = faceType(anArgument);
-  }
-
-  ObjectPtr anObject = ModuleBase_WidgetShapeSelector::getObject(theAttribute);
-  if (anObject.get() != NULL) {
-    AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
-                                                                 (theAttribute);
-    std::shared_ptr<GeomAPI_Shape> aGeomShape = aSelectionAttr->value();
-    std::shared_ptr<GeomAPI_Face> aGeomFace(new GeomAPI_Face(aGeomShape));
-    if (aGeomFace.get() != NULL) {
-      switch(aFaceType) {
-          case GeomAbs_Plane:
-            aValid = aGeomFace->isPlanar();
-            break;
-          case GeomAbs_Cylinder:
-            break;
-          default:
-            break;
-      }
-    }
-  }
-  return aValid;
-}
diff --git a/src/ModuleBase/ModuleBase_ValidatorFace.h b/src/ModuleBase/ModuleBase_ValidatorFace.h
deleted file mode 100644 (file)
index 9923c9c..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        ModuleBase_ValidatorFace.h
-// Created:     20 Mar 2015
-// Author:      Natalia ERMOLAEVA
-
-#ifndef ModuleBase_ValidatorFace_H
-#define ModuleBase_ValidatorFace_H
-
-#include "ModuleBase.h"
-#include "ModelAPI_AttributeValidator.h"
-
-#include <GeomAbs_SurfaceType.hxx>
-
-/**
-* \ingroup Validators
-* A validator of selection
-*/
-class ModuleBase_ValidatorFace : public ModelAPI_AttributeValidator
-{
- public:
-   MODULEBASE_EXPORT ModuleBase_ValidatorFace() {}
-  //! returns true if attribute is valid
-  //! \param theAttribute the checked attribute
-  //! \param theArguments arguments of the attribute
-  MODULEBASE_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
-                                         const std::list<std::string>& theArguments) const;
-protected:
-  /// Convert string to TypeOfFace value
-  /// \param theType a string value
-  static GeomAbs_SurfaceType faceType(const std::string& theType);
-};
-
-#endif
diff --git a/src/ModuleBase/ModuleBase_ValidatorLinearEdge.cpp b/src/ModuleBase/ModuleBase_ValidatorLinearEdge.cpp
deleted file mode 100644 (file)
index cf2d280..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-
-#include "ModuleBase_ValidatorLinearEdge.h"
-#include "ModuleBase_WidgetShapeSelector.h"
-
-#include <GeomAPI_Curve.h>
-
-#include <Events_Error.h>
-
-#include <StdSelect_TypeOfEdge.hxx>
-
-#include <QString>
-#include <QMap>
-
-
-typedef QMap<QString, ModuleBase_ValidatorLinearEdge::TypeOfEdge> EdgeTypes;
-static EdgeTypes MyEdgeTypes;
-
-ModuleBase_ValidatorLinearEdge::TypeOfEdge ModuleBase_ValidatorLinearEdge::edgeType(const std::string& theType)
-{
-  if (MyEdgeTypes.count() == 0) {
-    MyEdgeTypes["line"] = Line;
-    MyEdgeTypes["circle"] = Circle;
-  }
-  QString aType = QString(theType.c_str()).toLower();
-  if (MyEdgeTypes.contains(aType))
-    return MyEdgeTypes[aType];
-  
-  Events_Error::send("Edge type defined in XML is not implemented!");
-  return AnyEdge;
-}
-
-bool ModuleBase_ValidatorLinearEdge::isValid(const AttributePtr& theAttribute,
-                                             const std::list<std::string>& theArguments) const
-{
-  bool aValid = false;
-
-  TypeOfEdge anEdgeType = AnyEdge;
-  if (theArguments.size() == 1) {
-    std::string anArgument = theArguments.front();
-    anEdgeType = edgeType(anArgument);
-  }
-
-  ObjectPtr anObject = ModuleBase_WidgetShapeSelector::getObject(theAttribute);
-  if (anObject.get() != NULL) {
-    FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
-    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
-    if (aResult.get() != NULL) {
-      GeomShapePtr aShape = aResult->shape();
-      if (aShape.get() != NULL && aShape->isEdge()) {
-        aValid = anEdgeType == AnyEdge;
-        if (!aValid) {
-          bool isCircle = GeomAPI_Curve(aShape).isCircle();
-          aValid = (isCircle && anEdgeType == Circle) ||
-                   (!isCircle && anEdgeType == Line);
-        }
-      }
-    }
-  }
-  else {
-    //AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
-  }
-  return aValid;
-}
diff --git a/src/ModuleBase/ModuleBase_ValidatorLinearEdge.h b/src/ModuleBase/ModuleBase_ValidatorLinearEdge.h
deleted file mode 100644 (file)
index a2b3159..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        ModuleBase_ValidatorLinearEdge.h
-// Created:     19 Mar 2015
-// Author:      Natalia ERMOLAEVA
-
-#ifndef ModuleBase_ValidatorLinearEdge_H
-#define ModuleBase_ValidatorLinearEdge_H
-
-#include "ModuleBase.h"
-#include "ModelAPI_AttributeValidator.h"
-
-/**
-* \ingroup Validators
-* A validator of selection
-*/
-class ModuleBase_ValidatorLinearEdge : public ModelAPI_AttributeValidator
-{
- public:
-  //  the edge type
-  enum TypeOfEdge
-  {
-    AnyEdge,
-    Line,
-    Circle
-  };
-
- public:
-   MODULEBASE_EXPORT ModuleBase_ValidatorLinearEdge() {}
-  //! returns true if attribute is valid
-  //! \param theAttribute the checked attribute
-  //! \param theArguments arguments of the attribute
-  MODULEBASE_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
-                                         const std::list<std::string>& theArguments) const;
-protected:
-  /// Convert string to TypeOfEdge value
-  /// \param theType a string value
-  static TypeOfEdge edgeType(const std::string& theType);
-};
-
-#endif
diff --git a/src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.cpp b/src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.cpp
deleted file mode 100644 (file)
index b9c8ce1..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-
-#include "ModuleBase_ValidatorLinearEdgeOrVertex.h"
-#include "ModuleBase_WidgetShapeSelector.h"
-#include "ModuleBase_ValidatorLinearEdge.h"
-
-#include "ModelAPI_AttributeRefAttr.h"
-
-#include <ModelAPI_Session.h>
-
-#include <GeomAPI_Curve.h>
-#include <GeomDataAPI_Point2D.h>
-
-#include <Events_Error.h>
-
-#include <StdSelect_TypeOfEdge.hxx>
-
-#include <QString>
-#include <QMap>
-
-
-bool ModuleBase_ValidatorLinearEdgeOrVertex::isValid(const AttributePtr& theAttribute,
-                                             const std::list<std::string>& theArguments) const
-{
-  bool aValid = false;
-
-  // 1. check whether the attribute is a linear edge
-    // there is a check whether the feature contains a point and a linear edge or two point values
-  SessionPtr aMgr = ModelAPI_Session::get();
-  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
-
-  const ModuleBase_ValidatorLinearEdge* aLinearEdgeValidator =
-    dynamic_cast<const ModuleBase_ValidatorLinearEdge*>(aFactory->validator("ModuleBase_ValidatorLinearEdge"));
-
-  std::list<std::string> anArguments;
-  anArguments.push_back("line");
-  aValid = aLinearEdgeValidator->isValid(theAttribute, anArguments);
-  if (!aValid) {
-    //2. check whether the attribute is a vertex
-    ObjectPtr anObject = ModuleBase_WidgetShapeSelector::getObject(theAttribute);
-    if (anObject.get() != NULL) {
-      FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
-      ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
-      if (aResult.get() != NULL) {
-        GeomShapePtr aShape = aResult->shape();
-        if (aShape.get() != NULL) {
-          aValid = aShape->isVertex();
-        }
-      }
-    }
-    else {
-      AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
-      if (anAttr.get() != NULL) {
-        AttributePtr aRefAttr = anAttr->attr();
-        aValid = aRefAttr.get() != NULL && aRefAttr->attributeType() == GeomDataAPI_Point2D::type();
-      }
-    }
-  }
-  return aValid;
-}
diff --git a/src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.h b/src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.h
deleted file mode 100644 (file)
index 0df6c88..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        ModuleBase_ValidatorLinearEdgeOrVertex.h
-// Created:     19 Mar 2015
-// Author:      Natalia ERMOLAEVA
-
-#ifndef ModuleBase_ValidatorLinearEdgeOrVertex_H
-#define ModuleBase_ValidatorLinearEdgeOrVertex_H
-
-#include "ModuleBase.h"
-#include "ModelAPI_AttributeValidator.h"
-
-#include <StdSelect_TypeOfEdge.hxx>
-
-/**
-* \ingroup Validators
-* A validator of selection
-*/
-class ModuleBase_ValidatorLinearEdgeOrVertex : public ModelAPI_AttributeValidator
-{
- public:
-   MODULEBASE_EXPORT ModuleBase_ValidatorLinearEdgeOrVertex() {}
-  //! returns true if attribute is valid
-  //! \param theAttribute the checked attribute
-  //! \param theArguments arguments of the attribute
-  MODULEBASE_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
-                                         const std::list<std::string>& theArguments) const;
-};
-
-#endif
diff --git a/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.cpp b/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.cpp
deleted file mode 100644 (file)
index 7a6ab98..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-#include "ModuleBase_ValidatorNoConstructionSubShapes.h"
-
-#include "ModelAPI_AttributeSelection.h"
-#include "ModelAPI_ResultConstruction.h"
-#include "ModelAPI_CompositeFeature.h"
-
-bool ModuleBase_ValidatorNoConstructionSubShapes::isValid(const AttributePtr& theAttribute,
-                                              const std::list<std::string>& theArguments) const
-{
-  bool aValid = false;
-  AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
-                                                                (theAttribute);
-  if (aSelectionAttr.get() == NULL)
-    return aValid;
-
-  ResultPtr aResult = aSelectionAttr->context();
-  GeomShapePtr aShape = aSelectionAttr->value();
-  // global selection should be ignored, the filter processes only selected sub-shapes
-  // that means, that the shape of the context result is equal to the shape value
-  ///*ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
-  if (aResult.get() != NULL) {
-    GeomShapePtr aShapePtr = aResult->shape();
-    // it is important to call isEqual of the shape of result.
-    // It is a GeomAPI_Vertex shape for the point. The shape of the parameter is 
-    // GeomAPI_Shape. It is important to use the realization of the isEqual method from
-    // GeomAPI_Vertex class
-    aValid = aShapePtr.get() != NULL && aShapePtr->isEqual(aShape);
-  }
-  if (!aValid) {
-    ResultConstructionPtr aConstr =
-                            std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
-    if (aConstr != NULL) {
-      // it provides selection only on compositie features, construction without composite
-      // feature is not selectable
-      FeaturePtr aFeature = ModelAPI_Feature::feature(aConstr);
-      CompositeFeaturePtr aComposite = 
-                             std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
-      aValid = aComposite && aComposite->numberOfSubs() > 0;
-    }
-    else {
-      // non-construction results should be accepted by this filter, e.g. body results
-      aValid = true;
-    }
-  }
-  return aValid;
-}
diff --git a/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.h b/src/ModuleBase/ModuleBase_ValidatorNoConstructionSubShapes.h
deleted file mode 100644 (file)
index 1338fce..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        ModuleBase_ValidatorNoConstructionSubShapes.h
-// Created:     20 Mar 2015
-// Author:      Natalia ERMOLAEVA
-
-#ifndef ModuleBase_ValidatorNoConstructionSubShapes_H
-#define ModuleBase_ValidatorNoConstructionSubShapes_H
-
-#include "ModuleBase.h"
-#include "ModelAPI_AttributeValidator.h"
-
-/**
-* \ingroup Validators
-* A validator of selection
-*/
-class ModuleBase_ValidatorNoConstructionSubShapes : public ModelAPI_AttributeValidator
-{
- public:
-   MODULEBASE_EXPORT ModuleBase_ValidatorNoConstructionSubShapes() {}
-  //! returns true if attribute is valid
-  //! \param theAttribute the checked attribute
-  //! \param theArguments arguments of the attribute
-  MODULEBASE_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
-                                         const std::list<std::string>& theArguments) const;
-};
-
-#endif
index 965049db6cc8d0ed5cb69559b4e2e079ca06705e..067185cdd2ee565a70355eb7698a403237150ba9 100644 (file)
@@ -31,7 +31,7 @@ class MODULEBASE_EXPORT ModuleBase_WidgetLineEdit : public ModuleBase_ModelWidge
  public:
   /// Constructor
   /// \param theParent the parent object
-  /// \param theData the widget configuation. The attribute of the model widget is obtained from
+  /// \param theData the widget configuration.
   /// \param theParentId is Id of a parent of the current attribute
   ModuleBase_WidgetLineEdit(QWidget* theParent,
                                 const Config_WidgetAPI* theData,
index 8fc20d6b94e1bd76b76f13f82d4f26c8ce5b487f..ff8bafdea6a8746a9ca85a9063af9e2cc62cbe73 100644 (file)
@@ -122,7 +122,20 @@ void ModuleBase_WidgetMultiSelector::deactivate()
 bool ModuleBase_WidgetMultiSelector::storeValueCustom() const
 {
   // the value is stored on the selection changed signal processing 
-  return true;
+  // A rare case when plugin was not loaded. 
+  if(!myFeature)
+    return false;
+  DataPtr aData = myFeature->data();
+  AttributeSelectionListPtr aSelectionListAttr = 
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+
+  if (aSelectionListAttr) {
+    // Store shapes type
+     TopAbs_ShapeEnum aCurrentType =
+           ModuleBase_WidgetShapeSelector::shapeType(myTypeCombo->currentText());
+     aSelectionListAttr->setSelectionType(myTypeCombo->currentText().toStdString());
+  }   
+   return true;
 }
 
 //********************************************************************
@@ -138,7 +151,7 @@ bool ModuleBase_WidgetMultiSelector::restoreValue()
   if (aSelectionListAttr) {
     // Restore shape type
     setCurrentShapeType(
-      ModuleBase_WidgetShapeSelector::shapeType(aSelectionListAttr->selectionType().c_str()));
+         ModuleBase_WidgetShapeSelector::shapeType(aSelectionListAttr->selectionType().c_str()));
     updateSelectionList(aSelectionListAttr);
     return true;
   }
index 9708a6ccdade9d7fd5a44d6020a909fedad023cb..7fc40261487056aa53dd9085efdb0b54e9cc8d69 100644 (file)
@@ -18,6 +18,7 @@
 #include <Events_Message.h>
 #include <GeomAPI_Interface.h>
 #include <GeomAPI_Shape.h>
+#include <GeomValidators_Tools.h>
 
 #include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_Data.h>
@@ -33,7 +34,6 @@
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_Validator.h>
-#include <ModelAPI_ResultValidator.h>
 #include <ModelAPI_AttributeValidator.h>
 #include <ModelAPI_ShapeValidator.h>
 
@@ -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);
@@ -272,29 +272,6 @@ bool ModuleBase_WidgetShapeSelector::acceptSubShape(std::shared_ptr<GeomAPI_Shap
   return false;
 }
 
-ObjectPtr ModuleBase_WidgetShapeSelector::getObject(const AttributePtr& theAttribute)
-{
-  ObjectPtr anObject;
-  std::string anAttrType = theAttribute->attributeType();
-  if (anAttrType == ModelAPI_AttributeRefAttr::type()) {
-    AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
-    if (anAttr != NULL && anAttr->isObject())
-      anObject = anAttr->object();
-  }
-  if (anAttrType == ModelAPI_AttributeSelection::type()) {
-    AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
-    if (anAttr != NULL && anAttr->isInitialized())
-      anObject = anAttr->context();
-  }
-  if (anAttrType == ModelAPI_AttributeReference::type()) {
-    AttributeReferencePtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
-    if (anAttr.get() != NULL && anAttr->isInitialized())
-      anObject = anAttr->value();
-  }
-  return anObject;
-}
-
-
 //********************************************************************
 GeomShapePtr ModuleBase_WidgetShapeSelector::getShape() const
 {
@@ -324,7 +301,7 @@ void ModuleBase_WidgetShapeSelector::updateSelectionName()
     isNameUpdated = true;
   }
   if (!isNameUpdated) {
-    ObjectPtr anObject = getObject(myFeature->attribute(attributeID()));
+    ObjectPtr anObject = GeomValidators_Tools::getObject(myFeature->attribute(attributeID()));
     if (anObject.get() != NULL) {
       std::string aName = anObject->data()->name();
       myTextLine->setText(QString::fromStdString(aName));
@@ -399,7 +376,7 @@ void ModuleBase_WidgetShapeSelector::backupAttributeValue(const bool isBackup)
   AttributePtr anAttribute = myFeature->attribute(attributeID());
 
   if (isBackup) {
-    myObject = getObject(anAttribute);
+    myObject = GeomValidators_Tools::getObject(anAttribute);
     myShape = getShape();
     myRefAttribute = NULL;
     myIsObject = false;
@@ -408,6 +385,7 @@ void ModuleBase_WidgetShapeSelector::backupAttributeValue(const bool isBackup)
       myIsObject = aRefAttr->isObject();
       myRefAttribute = aRefAttr->attr();
     }
+    myExternalObject = NULL;
   }
   else {
     storeAttributeValues(myObject, myShape);
@@ -416,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);
+      }
+    }
   }
 }
 
@@ -427,7 +412,7 @@ bool ModuleBase_WidgetShapeSelector::setSelection(const Handle_SelectMgr_EntityO
   ModuleBase_ViewerPrs aPrs;
   myWorkshop->selection()->fillPresentation(aPrs, theOwner);
   ObjectPtr aObject = aPrs.object();
-  ObjectPtr aCurrentObject = getObject(myFeature->attribute(attributeID()));
+  ObjectPtr aCurrentObject = GeomValidators_Tools::getObject(myFeature->attribute(attributeID()));
   if ((!aCurrentObject) && (!aObject))
     return false;
 
index 2c5e253b3dbd08a32c957f5083346cd3ff5099b1..34c4c0212545a75448215b15b2ef7ea6cdce03f6 100644 (file)
@@ -89,10 +89,6 @@ Q_OBJECT
   /// The methiod called when widget is deactivated
   virtual void deactivate();
 
-  // Get the object from the attribute
-  /// \param theObj an object 
-  static ObjectPtr getObject(const AttributePtr& theAttribute);
-
  public slots:
 
   /// Activate or deactivate selection
@@ -138,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:
@@ -168,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 88c587aff5ee622c0b7db7bc3aa08ee678b2a07a..506eeca2a858427465374e62b80fc41f18cc8bb5 100644 (file)
@@ -6,7 +6,6 @@
 
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
-#include <ModelAPI_ResultValidator.h>
 #include <ModelAPI_AttributeValidator.h>
 
 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
@@ -25,6 +24,7 @@ ModuleBase_WidgetValidated::~ModuleBase_WidgetValidated()
 {
 }
 
+//********************************************************************
 bool ModuleBase_WidgetValidated::setSelection(ModuleBase_ViewerPrs theValue)
 {
   bool isDone = false;
@@ -38,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;
@@ -80,74 +86,14 @@ bool ModuleBase_WidgetValidated::isValidAttribute() const
   return aValid;
 }
 
-//********************************************************************
-bool ModuleBase_WidgetValidated::isValid(ObjectPtr theObj, GeomShapePtr theShape) const
-{
-  SessionPtr aMgr = ModelAPI_Session::get();
-  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
-  std::list<ModelAPI_Validator*> aValidators;
-  std::list<std::list<std::string> > anArguments;
-  aFactory->validators(parentID(), attributeID(), aValidators, anArguments);
-
-  // Check the type of selected object
-  std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
-  bool isValid = true;
-  for (; aValidator != aValidators.end(); aValidator++) {
-    const ModelAPI_ResultValidator* aResValidator =
-        dynamic_cast<const ModelAPI_ResultValidator*>(*aValidator);
-    if (aResValidator) {
-      isValid = false;
-      if (aResValidator->isValid(theObj)) {
-        isValid = true;
-        break;
-      }
-    }
-  }
-  return isValid;
-}
-
-#define VALIDATOR_FILTER
 void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorkshop,
                                                  const bool toActivate) const
 {
   ModuleBase_IViewer* aViewer = theWorkshop->viewer();
 
-#ifdef VALIDATOR_FILTER
   Handle(SelectMgr_Filter) aSelFilter = theWorkshop->validatorFilter();
   if (toActivate)
     aViewer->addSelectionFilter(aSelFilter);
   else
     aViewer->removeSelectionFilter(aSelFilter);
-#else
-  // apply filters loaded from the XML definition of the widget
-  ModuleBase_FilterFactory* aFactory = theWorkshop->selectionFilters();
-  SelectMgr_ListOfFilter aFactoryFilters;
-  aFactory->filters(parentID(), attributeID(), aFactoryFilters);
-  SelectMgr_ListIteratorOfListOfFilter aFactoryIt(aFactoryFilters);
-  for (; aFactoryIt.More(); aFactoryIt.Next()) {
-    Handle(SelectMgr_Filter) aSelFilter = aFactoryIt.Value();
-    if (aSelFilter.IsNull())
-      continue;
-    if (toActivate)
-      aViewer->addSelectionFilter(aSelFilter);
-    else
-      aViewer->removeSelectionFilter(aSelFilter);
-  }
-#endif
-}
-
-void ModuleBase_WidgetValidated::selectionFilters(ModuleBase_IWorkshop* theWorkshop,
-                                                  SelectMgr_ListOfFilter& theFilters) const
-{
-  ModuleBase_FilterFactory* aFactory = theWorkshop->selectionFilters();
-  SelectMgr_ListOfFilter aFilters;
-  aFactory->filters(parentID(), attributeID(), aFilters);
-  SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
-  for (; aIt.More(); aIt.Next()) {
-    Handle(SelectMgr_Filter) aSelFilter = aIt.Value();
-    if (aSelFilter.IsNull())
-      continue;
-
-    theFilters.Append(aSelFilter);
-  }
 }
index fdb0941120ba0b647e9f0633492747b967f9423a..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);
 
@@ -64,21 +66,10 @@ protected:
   // \return true if all validators return that the attribute is valid
   bool isValidAttribute() const;
 
-  /// Check the selected with validators if installed
-  /// \param theObj the object for checking
-  /// \param theShape the shape for checking
-  virtual bool isValid(ObjectPtr theObj, GeomShapePtr theShape) const;
-
   /// It obtains selection filters from the workshop and activates them in the active viewer
   /// \param theWorkshop an active workshop
   /// \param toActivate a flag about activation or deactivation the filters
   virtual void activateFilters(ModuleBase_IWorkshop* theWorkshop, const bool toActivate) const;
-
-  /// Fills the given list with all widget filters.
-  /// \param theWorkshop an active workshop
-  /// \param theFilters a list of filters
-  void selectionFilters(ModuleBase_IWorkshop* theWorkshop,
-                        SelectMgr_ListOfFilter& theFilters) const;
 };
 
 #endif /* MODULEBASE_WIDGETVALIDATED_H_ */
diff --git a/src/ParametersPlugin/CMakeLists.txt b/src/ParametersPlugin/CMakeLists.txt
new file mode 100644 (file)
index 0000000..287e84b
--- /dev/null
@@ -0,0 +1,35 @@
+INCLUDE(Common)
+
+INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Events
+                    ${PROJECT_SOURCE_DIR}/src/Config
+                    ${PROJECT_SOURCE_DIR}/src/ModelAPI
+) 
+
+SET(PROJECT_HEADERS
+    ParametersPlugin.h
+    ParametersPlugin_Plugin.h
+    ParametersPlugin_Parameter.h
+)
+SET(PROJECT_SOURCES
+    ParametersPlugin_Plugin.cpp
+    ParametersPlugin_Parameter.cpp
+)
+
+SET(XML_RESOURCES
+    plugin-Parameters.xml
+)
+
+SET(PROJECT_LIBRARIES
+    Events
+    Config
+    ModelAPI
+)
+
+ADD_DEFINITIONS(-DPARAMETERSPLUGIN_EXPORTS)
+ADD_LIBRARY(ParametersPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES})
+
+TARGET_LINK_LIBRARIES(ParametersPlugin ${PROJECT_LIBRARIES})
+
+INSTALL(TARGETS ParametersPlugin DESTINATION plugins)
+INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins)
diff --git a/src/ParametersPlugin/ParametersPlugin.h b/src/ParametersPlugin/ParametersPlugin.h
new file mode 100644 (file)
index 0000000..7d223f4
--- /dev/null
@@ -0,0 +1,21 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#ifndef PARAMETERSPLUGIN_H
+#define PARAMETERSPLUGIN_H
+
+#if defined PARAMETERSPLUGIN_EXPORTS
+#if defined WIN32
+#define PARAMETERSPLUGIN_EXPORT              __declspec( dllexport )
+#else
+#define PARAMETERSPLUGIN_EXPORT
+#endif
+#else
+#if defined WIN32
+#define PARAMETERSPLUGIN_EXPORT              __declspec( dllimport )
+#else
+#define PARAMETERSPLUGIN_EXPORT
+#endif
+#endif
+
+#endif
+
diff --git a/src/ParametersPlugin/ParametersPlugin_Parameter.cpp b/src/ParametersPlugin/ParametersPlugin_Parameter.cpp
new file mode 100644 (file)
index 0000000..498b83d
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        ParametersPlugin_Parameter.cpp
+// Created:     23 MArch 2015
+// Author:      sbh
+
+#include "ParametersPlugin_Parameter.h"
+#include <ModelAPI_AttributeString.h>
+
+ParametersPlugin_Parameter::ParametersPlugin_Parameter()
+{
+}
+
+void ParametersPlugin_Parameter::initAttributes()
+{
+  data()->addAttribute(ParametersPlugin_Parameter::VARIABLE_ID(), ModelAPI_AttributeString::type());
+  data()->addAttribute(ParametersPlugin_Parameter::EXPRESSION_ID(), ModelAPI_AttributeString::type());
+}
+
+void ParametersPlugin_Parameter::execute()
+{
+}
diff --git a/src/ParametersPlugin/ParametersPlugin_Parameter.h b/src/ParametersPlugin/ParametersPlugin_Parameter.h
new file mode 100644 (file)
index 0000000..e7574fd
--- /dev/null
@@ -0,0 +1,54 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        ParametersPlugin_Parameter.h
+// Created:     23 MArch 2015
+// Author:      sbh
+
+#ifndef PARAMETERSPLUGIN_PARAMETER_H_
+#define PARAMETERSPLUGIN_PARAMETER_H_
+
+#include "ParametersPlugin.h"
+#include <ModelAPI_Feature.h>
+
+class ParametersPlugin_Parameter : public ModelAPI_Feature
+{
+ public:
+  /// Extrusion kind
+  inline static const std::string& ID()
+  {
+    static const std::string MY_EXTRUSION_ID("Parameter");
+    return MY_EXTRUSION_ID;
+  }
+  /// attribute name of references sketch entities list, it should contain a sketch result or
+  /// a pair a sketch result to sketch face
+  inline static const std::string& VARIABLE_ID()
+  {
+    static const std::string MY_VARIABLE_ID("variable");
+    return MY_VARIABLE_ID;
+  }
+
+  /// attribute name of extrusion size
+  inline static const std::string& EXPRESSION_ID()
+  {
+    static const std::string MY_EXPRESSION_ID("expression");
+    return MY_EXPRESSION_ID;
+  }
+
+  /// Returns the kind of a feature
+  PARAMETERSPLUGIN_EXPORT virtual const std::string& getKind()
+  {
+    static std::string MY_KIND = ParametersPlugin_Parameter::ID();
+    return MY_KIND;
+  }
+
+  /// Creates a new part document if needed
+  PARAMETERSPLUGIN_EXPORT virtual void execute();
+
+  /// Request for initialization of data model of the feature: adding all attributes
+  PARAMETERSPLUGIN_EXPORT virtual void initAttributes();
+
+  /// Use plugin manager for features creation
+  ParametersPlugin_Parameter();
+};
+
+#endif
diff --git a/src/ParametersPlugin/ParametersPlugin_Plugin.cpp b/src/ParametersPlugin/ParametersPlugin_Plugin.cpp
new file mode 100644 (file)
index 0000000..9affdd7
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#include <ParametersPlugin_Plugin.h>
+#include <ParametersPlugin_Parameter.h>
+
+#include <ModelAPI_Session.h>
+
+#include <memory>
+
+// the only created instance of this plugin
+static ParametersPlugin_Plugin* MY_PARAMETERSPLUGIN_INSTANCE = new ParametersPlugin_Plugin();
+
+ParametersPlugin_Plugin::ParametersPlugin_Plugin()
+{
+  // register this plugin
+  SessionPtr aSession = ModelAPI_Session::get();
+  aSession->registerPlugin(this);
+}
+
+FeaturePtr ParametersPlugin_Plugin::createFeature(std::string theFeatureID)
+{
+  // TODO: register some features
+  if (theFeatureID == ParametersPlugin_Parameter::ID()) {
+    return FeaturePtr(new ParametersPlugin_Parameter);
+  }
+  return FeaturePtr();
+}
+
diff --git a/src/ParametersPlugin/ParametersPlugin_Plugin.h b/src/ParametersPlugin/ParametersPlugin_Plugin.h
new file mode 100644 (file)
index 0000000..d82198f
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#ifndef PARAMETERSPLUGIN_PLUGIN_H_
+#define PARAMETERSPLUGIN_PLUGIN_H_
+
+#include <ParametersPlugin.h>
+#include <ModelAPI_Plugin.h>
+#include <ModelAPI_Feature.h>
+
+/**\class ParametersPlugin_Plugin
+ * TODO: Add documentation
+ */
+class PARAMETERSPLUGIN_EXPORT ParametersPlugin_Plugin : public ModelAPI_Plugin
+{
+ public:
+  /// Creates the feature object of this plugin by the feature string ID
+  virtual FeaturePtr createFeature(std::string theFeatureID);
+
+ public:
+  ParametersPlugin_Plugin();
+};
+
+#endif
+
diff --git a/src/ParametersPlugin/plugin-Parameters.xml b/src/ParametersPlugin/plugin-Parameters.xml
new file mode 100644 (file)
index 0000000..63ba2ab
--- /dev/null
@@ -0,0 +1,12 @@
+<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+<plugin>
+  <workbench id="Part">
+    <group id="Parameters">
+      <feature id="Parameter" title="New Variable" tooltip="Creates a variable" icon=":pictures/expression.png">
+        <stringvalue id="variable" label="Name"/>
+        <stringvalue id="expression" icon="Value"/>
+      </feature>
+    </group>
+  </workbench>
+</plugin>
index 326fb1c617c8d63001749973073fd1fca40ed34d..bdbc48c5208fccb1cd8dc26216aa923d43269dc8 100644 (file)
@@ -46,6 +46,7 @@ SET(PROJECT_LIBRARIES
     ModuleBase
     Config
     GeomAPI
+    GeomValidators
     ${QT_LIBRARIES}
     ${CAS_KERNEL}
     ${CAS_SHAPE}
@@ -78,6 +79,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/XGUI
                     ${CMAKE_SOURCE_DIR}/src/SketchPlugin
                     ${CMAKE_SOURCE_DIR}/src/FeaturesPlugin
                     ${CMAKE_SOURCE_DIR}/src/GeomAPI
+                    ${CMAKE_SOURCE_DIR}/src/GeomValidators
                     ${CMAKE_SOURCE_DIR}/src/AppElements
                     ${CAS_INCLUDE_DIRS}
                                        ${SUIT_INCLUDE}
index 6299ff04ad4fed863865986c61b67f69adbab122..0b2e410b160e640a4df884d4605cbb9cb6701534 100644 (file)
 #include <ModuleBase_FilterMulti.h>
 #include <ModuleBase_FilterCustom.h>
 #include <ModuleBase_FilterNoConsructionSubShapes.h>
-#include <ModuleBase_ValidatorLinearEdge.h>
-#include <ModuleBase_ValidatorLinearEdgeOrVertex.h>
-#include <ModuleBase_ValidatorFace.h>
-#include <ModuleBase_ValidatorNoConstructionSubShapes.h>
+#include <GeomValidators_Edge.h>
+#include <GeomValidators_EdgeOrVertex.h>
+#include <GeomValidators_Face.h>
+#include <GeomValidators_ConstructionComposite.h>
 
 #include <PartSet_FilterSketchEntity.h>
 
@@ -130,15 +130,14 @@ void PartSet_Module::registerValidators()
   aFactory->registerValidator("PartSet_RigidValidator", new PartSet_RigidValidator);
   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
   aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
-  aFactory->registerValidator("PartSet_SketchValidator", new PartSet_SketchValidator);
 
-  aFactory->registerValidator("ModuleBase_ValidatorLinearEdge", new ModuleBase_ValidatorLinearEdge);
-  aFactory->registerValidator("ModuleBase_ValidatorLinearEdgeOrVertex",
-                              new ModuleBase_ValidatorLinearEdgeOrVertex);
-  aFactory->registerValidator("ModuleBase_ValidatorFace", new ModuleBase_ValidatorFace);
+  aFactory->registerValidator("GeomValidators_Edge", new GeomValidators_Edge);
+  aFactory->registerValidator("GeomValidators_EdgeOrVertex",
+                              new GeomValidators_EdgeOrVertex);
+  aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
 
-  aFactory->registerValidator("ModuleBase_ValidatorNoConstructionSubShapes",
-                              new ModuleBase_ValidatorNoConstructionSubShapes);
+  aFactory->registerValidator("GeomValidators_ConstructionComposite",
+                              new GeomValidators_ConstructionComposite);
 
   aFactory->registerValidator("PartSet_SketchEntityValidator",
                               new PartSet_SketchEntityValidator);
index 56f1ac3fc83708bdb32db18c07286b58c225aa4b..f7c4ab57f0c6fde0261324b1410766d0acf8a20b 100644 (file)
@@ -99,8 +99,9 @@ Handle(V3d_View) theView,
 
   std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
       aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
-  std::shared_ptr<GeomDataAPI_Dir> anY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-      aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
+  std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+      aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+  std::shared_ptr<GeomAPI_XYZ> anY = aNorm->xyz()->cross(aX->xyz());
 
   gp_Pnt anOriginPnt(anOrigin->x(), anOrigin->y(), anOrigin->z());
   gp_Vec aVec(anOriginPnt, thePoint);
@@ -138,13 +139,14 @@ std::shared_ptr<GeomAPI_Pnt> PartSet_Tools::convertTo3D(const double theX, const
       aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
   std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
       aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
-  std::shared_ptr<GeomDataAPI_Dir> aY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-      aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
+  std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+      aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+  std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
 
   std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = 
     std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY));
 
-  return aPnt2d->to3D(aC->pnt(), aX->dir(), aY->dir());
+  return aPnt2d->to3D(aC->pnt(), aX->dir(), aY);
 }
 
 ObjectPtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView,
@@ -417,14 +419,16 @@ std::shared_ptr<GeomAPI_Pnt> PartSet_Tools::point3D(std::shared_ptr<GeomAPI_Pnt2
   if (!theSketch || !thePoint2D)
     return aPoint;
 
+  DataPtr aData = theSketch->data();
   std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
-      theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+      aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
   std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-      theSketch->data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
-  std::shared_ptr<GeomDataAPI_Dir> aY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-      theSketch->data()->attribute(SketchPlugin_Sketch::DIRY_ID()));
+      aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
+  std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+      aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+  std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
 
-  return thePoint2D->to3D(aC->pnt(), aX->dir(), aY->dir());
+  return thePoint2D->to3D(aC->pnt(), aX->dir(), aY);
 }
 
 ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShape, 
index 305647650d0372de3edb8be328155e8e5f92fe00..85b0dd3eca700f983f09cbb2d8d32fabdfe70932 100644 (file)
@@ -11,6 +11,7 @@
 #include <BRep_Tool.hxx>
 #include <GeomAdaptor_Curve.hxx>
 #include <GeomAbs_CurveType.hxx>
+#include <GeomValidators_Tools.h>
 #include <ModuleBase_ISelection.h>
 #include <ModuleBase_WidgetShapeSelector.h>
 
@@ -119,7 +120,7 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute
 
   // 1. check whether the object of the attribute is not among the feature attributes
   // find the attribute's object
-  ObjectPtr anObject =  ModuleBase_WidgetShapeSelector::getObject(theAttribute);
+  ObjectPtr anObject =  GeomValidators_Tools::getObject(theAttribute);
 
   // check whether the object is not among other feature attributes
   if (anObject.get() != NULL) {
@@ -132,7 +133,7 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute
       // the function parameter attribute should be skipped
       if (anAttr.get() == NULL || anAttr->id() == theAttribute->id())
         continue;
-      ObjectPtr aCurObject =  ModuleBase_WidgetShapeSelector::getObject(anAttr);
+      ObjectPtr aCurObject =  GeomValidators_Tools::getObject(anAttr);
       if (aCurObject  && aCurObject == anObject)
         return false;
     }
@@ -192,29 +193,41 @@ bool PartSet_DifferentObjectsValidator::featureHasReferences(const AttributePtr&
 bool PartSet_SketchEntityValidator::isValid(const AttributePtr& theAttribute,
                                             const std::list<std::string>& theArguments) const
 {
-  AttributeSelectionListPtr aSelectionListAttr = 
-                    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
-
-  // it filters only selection list attributes
-  if (aSelectionListAttr.get() == NULL)
-    return true;
-
-  std::string aType = aSelectionListAttr->selectionType().c_str();
-
-  // all context objects should be sketch entities
   bool isSketchEntities = true;
-  int aSize = aSelectionListAttr->size();
-  for (int i = 0; i < aSelectionListAttr->size(); i++) {
-    AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
-    ObjectPtr anObject = aSelectAttr->context();
-    FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
-    isSketchEntities = aFeature->getKind() == SketchPlugin_Sketch::ID();
+  std::set<std::string> anEntityKinds;
+  std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
+  for (; anIt != aLast; anIt++) {
+    anEntityKinds.insert(*anIt);
   }
-  return isSketchEntities;
-}
 
-bool PartSet_SketchValidator::isValid(const ObjectPtr theObject) const
-{
-  FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
-  return aFeature->getKind() == SketchPlugin_Sketch::ID();
+  std::string anAttributeType = theAttribute->attributeType();
+  if (anAttributeType == ModelAPI_AttributeSelectionList::type()) {
+    AttributeSelectionListPtr aSelectionListAttr = 
+                      std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+    // it filters only selection list attributes
+    std::string aType = aSelectionListAttr->selectionType().c_str();
+    // all context objects should be sketch entities
+    int aSize = aSelectionListAttr->size();
+    for (int i = 0; i < aSelectionListAttr->size() && isSketchEntities; i++) {
+      AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
+      ObjectPtr anObject = aSelectAttr->context();
+      FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+      isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end();
+    }
+  }
+  if (anAttributeType == ModelAPI_AttributeRefAttr::type()) {
+    std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
+                     std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+    isSketchEntities = false;
+    if (aRef->isObject()) {
+      ObjectPtr anObject = aRef->object();
+      if (anObject.get() != NULL) {
+        FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+        if (aFeature.get() != NULL)
+          isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end();
+      }
+    }
+  }
+
+  return isSketchEntities;
 }
index 556c2ce06d4e15888c25c59c964d14ddb7913f6c..389cc4fa20def49b2048b0aa4707063d680465a1 100644 (file)
@@ -11,8 +11,7 @@
 
 #include <ModuleBase_SelectionValidator.h>
 #include <ModuleBase_ISelection.h>
-#include <ModelAPI_RefAttrValidator.h>
-#include <ModelAPI_ResultValidator.h>
+#include <ModelAPI_AttributeValidator.h>
 
 /*
  * Selector validators
@@ -70,7 +69,7 @@ class PartSet_RigidValidator : public ModuleBase_SelectionValidator
 * \ingroup Validators
 * A validator which checks that objects selected for feature attributes are different (not the same)
 */
-class PartSet_DifferentObjectsValidator : public ModelAPI_RefAttrValidator
+class PartSet_DifferentObjectsValidator : public ModelAPI_AttributeValidator
 {
  public:
   //! Returns true if the attribute is good for the feature attribute
@@ -95,7 +94,7 @@ protected:
 * \ingroup Validators
 * A validator which checks that objects selected for feature attributes are different (not the same)
 */
-class PartSet_SketchEntityValidator : public ModelAPI_RefAttrValidator
+class PartSet_SketchEntityValidator : public ModelAPI_AttributeValidator
 {
  public:
   //! Returns true if the attribute is good for the feature attribute
@@ -105,16 +104,4 @@ class PartSet_SketchEntityValidator : public ModelAPI_RefAttrValidator
                        const std::list<std::string>& theArguments) const;
 };
 
-/**
-* \ingroup Validators
-* A Validator which validates tha selected object is a Sketch
-*/
-class PartSet_SketchValidator : public ModelAPI_ResultValidator
-{
- public:
-   /// Returns True if the given object is a sketch
-   /// \param theObject an object
-  virtual bool isValid(const ObjectPtr theObject) const;
-};
-
 #endif
\ No newline at end of file
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 726f8c160dcca63d3f3a8dc8636cf65febfc59bb..a7ada4a646c433a8f79b2a82c518debf7ff881c2 100644 (file)
@@ -9,13 +9,11 @@
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
-#include <ModelAPI_RefAttrValidator.h>
-#include <ModelAPI_ResultValidator.h>
 
 #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;
@@ -32,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 96435f627a95826200c5ed20017793ba04989e46..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();
 }
@@ -287,9 +336,6 @@ std::shared_ptr<GeomAPI_Dir> PartSet_WidgetSketchLabel::setSketchPlane(const Top
   std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
       aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
   aDirX->setValue(aXDir);
-  std::shared_ptr<GeomDataAPI_Dir> aDirY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-      aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
-  aDirY->setValue(aYDir);
   std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
   return aDir;
 }
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 9cc2c73ea6190a14e1828bfd5efdff01fbce7791..4ca486e87c9a76f65b3061579dbc94a98ff77567 100644 (file)
Binary files a/src/PartSet/icons/tangent.png and b/src/PartSet/icons/tangent.png differ
index 2984571336bda4ddd527db36df7b537f8d02b198..22ce7d27eda3dce82e05a8039a73bad2c22198c1 100644 (file)
@@ -30,7 +30,6 @@ SET(PROJECT_HEADERS
     SketchPlugin_ConstraintFillet.h
     SketchPlugin_ShapeValidator.h
     SketchPlugin_Validators.h
-    SketchPlugin_ResultValidators.h 
 )
 
 SET(PROJECT_SOURCES
@@ -58,13 +57,13 @@ SET(PROJECT_SOURCES
     SketchPlugin_ConstraintFillet.cpp
     SketchPlugin_ShapeValidator.cpp
     SketchPlugin_Validators.cpp
-    SketchPlugin_ResultValidators.cpp
 )
 
 SET(PROJECT_LIBRARIES
     Config
     GeomAPI
     GeomAlgoAPI
+    GeomValidators
     ModelAPI
     SketcherPrs
     ${CAS_KERNEL}
@@ -86,6 +85,7 @@ INCLUDE_DIRECTORIES(
   ../GeomAPI
   ../GeomAlgoAPI
   ../GeomDataAPI
+  ../GeomValidators
   ../SketcherPrs
 )
 
index f4bc7f93e3e5aca6c75a8b88e3d620cbcc6ab5fd..0cb74987a0e63c5a060f709a26142415cdce9834 100644 (file)
@@ -190,7 +190,7 @@ double SketchPlugin_Arc::distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& t
 }
 
 bool SketchPlugin_Arc::isFixed() {
-  return data()->selection(EXTERNAL_ID())->context().get();
+  return data()->selection(EXTERNAL_ID())->context().get() != NULL;
 }
 
 bool SketchPlugin_Arc::isFeatureValid()
index 50b387414b82402e10bec366908b2d2d856f24fa..934f40a04eb331cf8a0fb0a37ba044140e29b9c7 100644 (file)
@@ -101,7 +101,7 @@ double SketchPlugin_Circle::distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>
 }
 
 bool SketchPlugin_Circle::isFixed() {
-  return data()->selection(EXTERNAL_ID())->context().get();
+  return data()->selection(EXTERNAL_ID())->context().get() != NULL;
 }
 
 void SketchPlugin_Circle::attributeChanged(const std::string& theID) {
index f0c76538a92ff0973a46813f32945c8299bf854c..ea5d0a42b1e57039053e2a7ff2c63b1d0b34d0c5 100644 (file)
@@ -101,7 +101,7 @@ double SketchPlugin_Line::distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>&
 }
 
 bool SketchPlugin_Line::isFixed() {
-  return data()->selection(EXTERNAL_ID())->context().get();
+  return data()->selection(EXTERNAL_ID())->context().get() != NULL;
 }
 
 void SketchPlugin_Line::attributeChanged(const std::string& theID) {
index 9bcc299bf59d46bee2b8bf2b158e9d9311f60d3c..04347759e5655848a0831c73ab5977e2abbc211d 100644 (file)
@@ -20,7 +20,6 @@
 #include <SketchPlugin_ConstraintTangent.h>
 #include <SketchPlugin_ConstraintVertical.h>
 #include <SketchPlugin_Validators.h>
-#include <SketchPlugin_ResultValidators.h>
 #include <SketchPlugin_ShapeValidator.h>
 
 #include <Events_Loop.h>
@@ -54,9 +53,7 @@ SketchPlugin_Plugin::SketchPlugin_Plugin()
                               new SketchPlugin_DistanceAttrValidator);  
   //aFactory->registerValidator("SketchPlugin_DifferentObjects",
   //                            new SketchPlugin_DifferentObjectsValidator);
-  aFactory->registerValidator("SketchPlugin_ResultPoint", new SketchPlugin_ResultPointValidator);
-  aFactory->registerValidator("SketchPlugin_ResultLine", new SketchPlugin_ResultLineValidator);
-  aFactory->registerValidator("SketchPlugin_ResultArc", new SketchPlugin_ResultArcValidator);
+
   aFactory->registerValidator("SketchPlugin_ShapeValidator",
                               new SketchPlugin_ShapeValidator);
 
index 798140611b2755a7b86248a055617fa84aed4e44..036fde19db093340f6a632a0b73b2f860e7e26a7 100644 (file)
@@ -73,7 +73,7 @@ double SketchPlugin_Point::distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>&
 }
 
 bool SketchPlugin_Point::isFixed() {
-  return data()->selection(EXTERNAL_ID())->context().get();
+  return data()->selection(EXTERNAL_ID())->context().get() != NULL;
 }
 
 void SketchPlugin_Point::attributeChanged(const std::string& theID) {
diff --git a/src/SketchPlugin/SketchPlugin_ResultValidators.cpp b/src/SketchPlugin/SketchPlugin_ResultValidators.cpp
deleted file mode 100644 (file)
index 15f8554..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File:        Model_ResultValidators.cpp
-// Created:     23 July 2014
-// Author:      Vitaly SMETANNIKOV
-
-#include "SketchPlugin_ResultValidators.h"
-
-#include <ModelAPI_Result.h>
-#include <ModelAPI_Tools.h>
-#include <GeomAPI_Curve.h>
-
-ResultPtr result(const ObjectPtr theObject)
-{
-  return std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-}
-
-bool SketchPlugin_ResultPointValidator::isValid(const ObjectPtr theObject) const
-{
-  ResultPtr aResult = result(theObject);
-  if (!aResult)
-    return false;
-  std::shared_ptr<GeomAPI_Shape> aShape = ModelAPI_Tools::shape(aResult);
-  return aShape && aShape->isVertex();
-}
-
-bool SketchPlugin_ResultLineValidator::isValid(const ObjectPtr theObject) const
-{
-  ResultPtr aResult = result(theObject);
-  if (!aResult)
-    return false;
-  std::shared_ptr<GeomAPI_Shape> aShape = ModelAPI_Tools::shape(aResult);
-  return aShape && aShape->isEdge() && GeomAPI_Curve(aShape).isLine();
-}
-
-bool SketchPlugin_ResultArcValidator::isValid(const ObjectPtr theObject) const
-{
-  ResultPtr aResult = result(theObject);
-  if (!aResult)
-    return false;
-  std::shared_ptr<GeomAPI_Shape> aShape = ModelAPI_Tools::shape(aResult);
-  return aShape && aShape->isEdge() && GeomAPI_Curve(aShape).isCircle();
-}
diff --git a/src/SketchPlugin/SketchPlugin_ResultValidators.h b/src/SketchPlugin/SketchPlugin_ResultValidators.h
deleted file mode 100644 (file)
index 6e328b1..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File:        Model_ResultValidators.h
-// Created:     23 July 2014
-// Author:      Vitaly SMETANNIKOV
-
-#ifndef Model_ResultValidators_H
-#define Model_ResultValidators_H
-
-#include <SketchPlugin.h>
-#include <ModelAPI_ResultValidator.h>
-#include <ModelAPI_Object.h>
-
-/**\class SketchPlugin_ResultPointValidator
- * \ingroup Validators
- * \brief Validator for the points selection
- *
- * Allows to select points only.
- */
-class SketchPlugin_ResultPointValidator : public ModelAPI_ResultValidator
-{
-public:
-  /// Returns true if theObject is a point
-  SKETCHPLUGIN_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
-};
-
-/**\class SketchPlugin_ResultLineValidator
- * \ingroup Validators
- * \brief Validator for the linear segments selection
- *
- * Allows to select linear segments only.
- */
-class SketchPlugin_ResultLineValidator : public ModelAPI_ResultValidator
-{
-public:
-  /// Returns true if theObject is a line
-  SKETCHPLUGIN_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
-};
-
-/**\class SketchPlugin_ResultArcValidator
- * \ingroup Validators
- * \brief Validator for the circular segments selection
- *
- * Allows to select circular segments only.
- */
-class SketchPlugin_ResultArcValidator : public ModelAPI_ResultValidator
-{
- public:
-  /// Returns true if theObject is an arc
-  SKETCHPLUGIN_EXPORT virtual bool isValid(const ObjectPtr theObject) const;
-};
-
-#endif
index e1dacf811bc9702ef7eb0563741e86130ffce78b..0722ce1b3fd36877c2282c67127ef5801954aa19 100644 (file)
@@ -11,7 +11,6 @@
 #include <ModelAPI_Result.h>
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_AttributeRefAttr.h>
-#include <ModelAPI_ResultValidator.h>
 
 bool SketchPlugin_ShapeValidator::isValid(const AttributePtr& theAttribute,
                                           const std::list<std::string>& theArguments) const
index 2736bd84806caec3856fbf9d6500ac61c84f5807..b57c1e3ba21e7b587c0a4fd950c6a516fa3d082b 100644 (file)
@@ -46,7 +46,6 @@ void SketchPlugin_Sketch::initAttributes()
 {
   data()->addAttribute(SketchPlugin_Sketch::ORIGIN_ID(), GeomDataAPI_Point::type());
   data()->addAttribute(SketchPlugin_Sketch::DIRX_ID(), GeomDataAPI_Dir::type());
-  data()->addAttribute(SketchPlugin_Sketch::DIRY_ID(), GeomDataAPI_Dir::type());
   data()->addAttribute(SketchPlugin_Sketch::NORM_ID(), GeomDataAPI_Dir::type());
   data()->addAttribute(SketchPlugin_Sketch::FEATURES_ID(), ModelAPI_AttributeRefList::type());
   // the selected face, base for the sketcher plane, not obligatory
@@ -66,8 +65,6 @@ void SketchPlugin_Sketch::execute()
       data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
   std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
       data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
-  std::shared_ptr<GeomDataAPI_Dir> aDirY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-      data()->attribute(SketchPlugin_Sketch::DIRY_ID()));
   std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
       data()->attribute(SketchPlugin_Sketch::NORM_ID()));
 
@@ -117,7 +114,7 @@ void SketchPlugin_Sketch::execute()
   for (; aShapeIt != aFeaturesPreview.end(); ++aShapeIt) {
     aBigWire->addEdge(*aShapeIt);
   }
-  aBigWire->setPlane(anOrigin->pnt(), aDirX->dir(), aDirY->dir(), aNorm->dir());
+  aBigWire->setPlane(anOrigin->pnt(), aDirX->dir(), aNorm->dir());
   std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
   aConstr->setShape(aBigWire);
   setResult(aConstr);
@@ -195,13 +192,14 @@ std::shared_ptr<GeomAPI_Pnt> SketchPlugin_Sketch::to3D(const double theX, const
 {
   std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
       data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+  std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+      data()->attribute(SketchPlugin_Sketch::NORM_ID()));
   std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
       data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
-  std::shared_ptr<GeomDataAPI_Dir> aY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-      data()->attribute(SketchPlugin_Sketch::DIRY_ID()));
+  std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
 
   std::shared_ptr<GeomAPI_XYZ> aSum = aC->pnt()->xyz()->added(aX->dir()->xyz()->multiplied(theX))
-      ->added(aY->dir()->xyz()->multiplied(theY));
+      ->added(aY->xyz()->multiplied(theY));
 
   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum));
 }
@@ -211,11 +209,12 @@ std::shared_ptr<GeomAPI_Pnt2d> SketchPlugin_Sketch::to2D(
 {
   std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
       data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+  std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+      data()->attribute(SketchPlugin_Sketch::NORM_ID()));
   std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
       data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
-  std::shared_ptr<GeomDataAPI_Dir> aY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-      data()->attribute(SketchPlugin_Sketch::DIRY_ID()));
-  return thePnt->to2D(aC->pnt(), aX->dir(), aY->dir());
+  std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
+  return thePnt->to2D(aC->pnt(), aX->dir(), aY);
 }
 
 
@@ -247,12 +246,10 @@ std::shared_ptr<GeomAPI_Ax3> SketchPlugin_Sketch::coordinatePlane() const
     aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
   std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
     aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
-  std::shared_ptr<GeomDataAPI_Dir> aY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-    aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
   std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
     aData->attribute(SketchPlugin_Sketch::NORM_ID()));
 
-  return std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(aC->pnt(), aX->dir(), aY->dir(), aNorm->dir()));
+  return std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(aC->pnt(), aX->dir(), aNorm->dir()));
 }
 
 void SketchPlugin_Sketch::erase()
@@ -306,9 +303,6 @@ void SketchPlugin_Sketch::attributeChanged(const std::string& theID) {
         std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
           data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
         aDirX->setValue(aXDir);
-        std::shared_ptr<GeomDataAPI_Dir> aDirY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-          data()->attribute(SketchPlugin_Sketch::DIRY_ID()));
-        aDirY->setValue(aYDir);
         std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
       }
     }
index 43a6e370792dc38e1d020ee6808fe739d6b5e04f..0c88f0d8f097c59f2dff814f9344ac942f343de9 100644 (file)
@@ -44,12 +44,6 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature//, public GeomAPI_I
     static const std::string MY_DIRX_ID("DirX");
     return MY_DIRX_ID;
   }
-  /// Vector Y inside of the sketch plane
-  inline static const std::string& DIRY_ID()
-  {
-    static const std::string MY_DIRY_ID("DirY");
-    return MY_DIRY_ID;
-  }
   /// Vector Z, normal to the sketch plane
   inline static const std::string& NORM_ID()
   {
index e69dce246f6b1ff333720f7bca8b8716dfcb474e..32a0b30b57cc3028c1311c8b1c5935d5c46841c8 100644 (file)
@@ -8,10 +8,12 @@
 #include "SketchPlugin_ConstraintDistance.h"
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Validator.h>
-#include <ModelAPI_ResultValidator.h>
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_Session.h>
+
+#include <GeomValidators_Edge.h>
+
 #include <GeomDataAPI_Point2D.h>
 
 bool SketchPlugin_DistanceAttrValidator::isValid(
@@ -33,20 +35,24 @@ bool SketchPlugin_DistanceAttrValidator::isValid(
   } else {
     // 1. check whether the references object is a linear
     ObjectPtr anObject = aRefAttr->object();
-    const ModelAPI_ResultValidator* anArcValidator =
-        dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultArc"));
-    bool anArcValid = anArcValidator->isValid(anObject);
-    if (anArcValid)
-      return false;
 
-    // If the object is not a line then it is accepted. It can be a point feature selected
-    const ModelAPI_ResultValidator* aLineValidator =
-        dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultLine"));
-    bool aLineValid = aLineValidator->isValid(anObject);
-    if (!aLineValid)
+    const ModelAPI_AttributeValidator* anEdgeValidator = 
+      dynamic_cast<const GeomValidators_Edge*>(aFactory->validator("GeomValidators_Edge"));
+    std::list<std::string> anArguments;
+    anArguments.push_back("circle");
+    bool anEdgeValid = anEdgeValidator->isValid(aRefAttr, anArguments);
+    // the circle line is not a valid case
+    if (anEdgeValid)
+      return false;
+      
+    anArguments.clear();
+    anArguments.push_back("line");
+    anEdgeValid = anEdgeValidator->isValid(aRefAttr, anArguments);
+    // if the attribute value is not a line, that means it is a vertex. A vertex is always valid
+    if (!anEdgeValid)
       return true;
-    FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
 
+    FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
     // If it is a line then we have to check that first attribute id not a line
     std::shared_ptr<GeomDataAPI_Point2D> aPoint = getFeaturePoint(aFeature->data(), aParamA);
     if (aPoint)
@@ -54,65 +60,3 @@ bool SketchPlugin_DistanceAttrValidator::isValid(
   }
   return false;
 }
-
-//bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
-//                                                 const std::list<std::string>& theArguments,
-//                                                 const ObjectPtr& theObject) const
-//{
-//  std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = 
-//    theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
-//  std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
-//  for(; anAttr != anAttrs.end(); anAttr++) {
-//    if (*anAttr) {
-//      std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
-//        std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
-//      // check the object is already presented
-//      if (aRef->isObject() && aRef->object() == theObject)
-//        return false;
-//    }
-//  }
-//  return true;
-//}
-
-//bool SketchPlugin_DifferentObjectsValidator::isValid(
-//  const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
-//{
-//  std::shared_ptr<ModelAPI_AttributeRefAttr> anOrigAttr = 
-//    std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
-//  if (anOrigAttr && anOrigAttr->isObject()) {
-//    const ObjectPtr& anObj = theAttribute->owner();
-//    const FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
-//
-//    std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = 
-//      aFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
-//    std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
-//    for(; anAttr != anAttrs.end(); anAttr++) {
-//      if (*anAttr && *anAttr != theAttribute) {
-//        std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
-//          std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
-//        // check the object is already presented
-//        if (aRef->isObject() && aRef->object() == anOrigAttr->object())
-//          return false;
-//      }
-//    }
-//  }
-//  return true;
-//}
-
-//bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
-//  const std::list<std::string>& theArguments, const AttributePtr& theAttribute) const
-//{
-//  std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = 
-//    theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
-//  std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
-//  for(; anAttr != anAttrs.end(); anAttr++) {
-//    if (*anAttr) {
-//      std::shared_ptr<ModelAPI_AttributeRefAttr> aRef = 
-//        std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
-//      // check the object is already presented
-//      if (!aRef->isObject() && aRef->attr() == theAttribute)
-//        return false;
-//    }
-//  }
-//  return true;
-//}
index 9b732adee3c456ac7dfcc70bc4e20b0f8d5c15df..f686d3e6ebe97a5e75cefcee21b313b3fd2b7f04 100644 (file)
@@ -8,7 +8,7 @@
 #define SketchPlugin_Validators_H
 
 #include "SketchPlugin.h"
-#include <ModelAPI_RefAttrValidator.h>
+#include <ModelAPI_AttributeValidator.h>
 
 /**\class SketchPlugin_DistanceAttrValidator
  * \ingroup Validators
  *
  * It just checks that distance is greater than zero.
  */
-class SketchPlugin_DistanceAttrValidator : public ModelAPI_RefAttrValidator
+class SketchPlugin_DistanceAttrValidator : public ModelAPI_AttributeValidator
 {
  public:
   //! returns true if attribute is valid
   //! \param theAttribute the checked attribute
   //! \param theArguments arguments of the attribute
-  virtual bool isValid(
-    const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const;
+  virtual bool isValid(const AttributePtr& theAttribute,
+                       const std::list<std::string>& theArguments) const;
 };
 
-/**\class SketchPlugin_DifferentObjectsValidator
- * \ingroup Validators
- *
- * Check that there is no same object was already selected in the feature.
- * For an example: to avoid perpendicularity on line and the same line.
- */
-// Use PartSet_DifferentObjectsValidator
-//class SketchPlugin_DifferentObjectsValidator : public ModelAPI_RefAttrValidator
-//{
-// public:
-//  //! returns true if attribute is valid
-//  //! \param theAttribute the checked attribute
-//  //! \param theArguments arguments of the attribute
-//  virtual bool isValid(
-//    const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const;
-//  //! Returns true if object is good for the feature attribute
-//  virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
-//                       const ObjectPtr& theObject) const;
-//  //! Returns true if the attribute is good for the feature attribute
-//  virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
-//                       const AttributePtr& theAttribute) const;
-//};
-
 #endif
index 8d69365e2c628f33406c0d5529bda96f5066c4dc..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">
@@ -56,7 +58,7 @@
               tooltip="Select point, line end point, line, center of circle or arc."
               shape_types="edge vertex">
           <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
-          <validator id="ModuleBase_ValidatorLinearEdgeOrVertex"/>
+          <validator id="GeomValidators_EdgeOrVertex"/>
         </sketch_shape_selector>/>
         <sketch_shape_selector 
           id="ConstraintEntityB" 
@@ -66,7 +68,7 @@
           <validator id="PartSet_DifferentObjects"/>
           <validator id="SketchPlugin_DistanceAttr" parameters="ConstraintEntityA"/>
           <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
-          <validator id="ModuleBase_ValidatorLinearEdgeOrVertex"/>
+          <validator id="GeomValidators_EdgeOrVertex"/>
         </sketch_shape_selector>
         
         <sketch-2dpoint_selector id="ConstraintFlyoutValuePnt"  default="computed" internal="1" obligatory="0"/>
@@ -82,9 +84,7 @@
         <label title="Select a line on which to calculate length" tooltip="Select a line on which to calculate length"/>
         <shape_selector id="ConstraintEntityA" label="Line" tooltip="Select an line" 
             shape_types="edge" >
-            <validator id="SketchPlugin_ResultLine"/>
-            <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
-      <validator id="SketchPlugin_ResultLine"/>
+        <validator id="GeomValidators_Edge" parameters="line"/>
     </shape_selector>
         <sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" default="computed" internal="1" obligatory="0"/>
         <doublevalue_editor label="Value" tooltip="Length" id="ConstraintValue" default="computed">
@@ -97,8 +97,7 @@
         <label title="Select a circle or an arc on which to calculate radius" tooltip="Select a circle or an arc on which to calculate radius"/>
         <shape_selector id="ConstraintEntityA" label="Circle or Arc" tooltip="Select a circle or an arc" 
             shape_types="edge">
-            <validator id="SketchPlugin_ResultArc"/>
-            <validator id="ModuleBase_ValidatorLinearEdge" parameters="circle"/>
+            <validator id="GeomValidators_Edge" parameters="circle"/>
         </shape_selector>
         <sketch-2dpoint_selector id="ConstraintFlyoutValuePnt"  default="computed" internal="1" obligatory="0"/>
         <doublevalue_editor label="Value" tooltip="Radius" id="ConstraintValue" default="computed"/>
       <feature id="SketchConstraintParallel" title="Parallel" tooltip="Create constraint defining two parallel lines" icon=":icons/parallel.png">
         <sketch_constraint_shape_selector id="ConstraintEntityA" 
             label="First line" tooltip="Select a line" shape_types="edge">
-            <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
+            <validator id="GeomValidators_Edge" parameters="line"/>
             <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
         </sketch_constraint_shape_selector>
         
         <sketch_constraint_shape_selector id="ConstraintEntityB" label="Last line" tooltip="Select a line" 
             shape_types="edge">
-            <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
+            <validator id="GeomValidators_Edge" parameters="line"/>
             <validator id="PartSet_DifferentObjects"/>
             <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityA"/>
         </sketch_constraint_shape_selector>
             label="First line" tooltip="Select an line" 
             shape_types="edge">
           <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
-            <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
+            <validator id="GeomValidators_Edge" parameters="line"/>
         </sketch_constraint_shape_selector>
         
         <sketch_constraint_shape_selector id="ConstraintEntityB" 
             shape_types="edge">
             <validator id="PartSet_DifferentObjects"/>
           <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityA"/>
-            <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
+            <validator id="GeomValidators_Edge" parameters="line"/>
         </sketch_constraint_shape_selector>
         <validator id="PartSet_PerpendicularValidator"/>
       </feature>
       <feature id="SketchConstraintRigid" title="Fixed" tooltip="Fix an object" icon=":icons/fixed.png">
         <shape_selector id="ConstraintEntityA" label="Object" tooltip="Select an object" 
             shape_types="edge vertex">
-            <validator id="SketchPlugin_ResultPoint"/>
-            <validator id="SketchPlugin_ResultLine"/>
-            <validator id="SketchPlugin_ResultArc"/>
+          <validator id="PartSet_SketchEntityValidator" parameters="SketchPoint,SketchLine,SketchCircle,SketchArc"/>
         </shape_selector>
         <validator id="PartSet_RigidValidator"/>
       </feature>
       <feature id="SketchConstraintHorizontal" title="Horizontal" tooltip="Create constraint defining horizontal line" icon=":icons/horisontal.png">
         <sketch_constraint_shape_selector id="ConstraintEntityA" 
             label="Line" tooltip="Select a line" shape_types="edge">
-            <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
+            <validator id="GeomValidators_Edge" parameters="line"/>
         </sketch_constraint_shape_selector>
       </feature>
     <!--  SketchConstraintVertical  -->
       <feature id="SketchConstraintVertical" title="Vertical" tooltip="Create constraint defining vertical line" icon=":icons/vertical.png">
         <sketch_constraint_shape_selector id="ConstraintEntityA" 
             label="Line" tooltip="Select a line" shape_types="edge">
-            <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
+            <validator id="GeomValidators_Edge" parameters="line"/>
         </sketch_constraint_shape_selector>
       </feature>
     <!--  SketchConstraintEqual  -->
index c1f07f72be58b70d0ab6f1a543c578e2083b4d75..b650cbdabee544b8d56a85a3242adaf72f912dda 100644 (file)
@@ -1299,14 +1299,15 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntityFeature(FeaturePtr theEnt
 //  Purpose:  create/update the normal of workplane
 // ============================================================================
 Slvs_hEntity SketchSolver_ConstraintGroup::changeNormal(
-    std::shared_ptr<ModelAPI_Attribute> theDirX, std::shared_ptr<ModelAPI_Attribute> theDirY,
+    std::shared_ptr<ModelAPI_Attribute> theDirX,
     std::shared_ptr<ModelAPI_Attribute> theNorm)
 {
+  std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(theNorm);
   std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(theDirX);
-  std::shared_ptr<GeomDataAPI_Dir> aDirY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(theDirY);
-  if (!aDirX || !aDirY || (fabs(aDirX->x()) + fabs(aDirX->y()) + fabs(aDirX->z()) < tolerance)
-      || (fabs(aDirY->x()) + fabs(aDirY->y()) + fabs(aDirY->z()) < tolerance))
+  if (!aDirX || (fabs(aDirX->x()) + fabs(aDirX->y()) + fabs(aDirX->z()) < tolerance))
     return SLVS_E_UNKNOWN;
+  // calculate Y direction
+  std::shared_ptr<GeomAPI_Dir> aDirY(new GeomAPI_Dir(aNorm->dir()->cross(aDirX->dir())));
 
   // quaternion parameters of normal vector
   double qw, qx, qy, qz;
@@ -1370,14 +1371,12 @@ bool SketchSolver_ConstraintGroup::updateWorkplane()
   // Get parameters of workplane
   std::shared_ptr<ModelAPI_Attribute> aDirX = mySketch->data()->attribute(
       SketchPlugin_Sketch::DIRX_ID());
-  std::shared_ptr<ModelAPI_Attribute> aDirY = mySketch->data()->attribute(
-      SketchPlugin_Sketch::DIRY_ID());
   std::shared_ptr<ModelAPI_Attribute> aNorm = mySketch->data()->attribute(
       SketchPlugin_Sketch::NORM_ID());
   std::shared_ptr<ModelAPI_Attribute> anOrigin = mySketch->data()->attribute(
       SketchPlugin_Sketch::ORIGIN_ID());
   // Transform them into SolveSpace format
-  Slvs_hEntity aNormalWP = changeNormal(aDirX, aDirY, aNorm);
+  Slvs_hEntity aNormalWP = changeNormal(aDirX, aNorm);
   if (!aNormalWP)
     return false;
   Slvs_hEntity anOriginWP = changeEntity(anOrigin);
index 5c6f965e33b54d4344ddb5acff661dac4a11463f..e24d93a7d2bf0e6814e89de8e5cbebe7e24a4e28 100644 (file)
@@ -156,12 +156,10 @@ protected:
    *  on the plane transversed to created normal.
    *
    *  \param[in] theDirX first coordinate axis of the plane
-   *  \param[in] theDirY second coordinate axis of the plane
    *  \param[in] theNorm attribute for the normal (used to identify newly created entity)
    *  \return identifier of created or updated normal
    */
   Slvs_hEntity changeNormal(std::shared_ptr<ModelAPI_Attribute> theDirX,
-                            std::shared_ptr<ModelAPI_Attribute> theDirY,
                             std::shared_ptr<ModelAPI_Attribute> theNorm);
 
   /** \brief Adds or updates a parameter in the group
index 5fe8b8437c12587826fa5990fada21a98b4d95e7..4af59f94d163cd719712004c7759a863678d44a2 100644 (file)
@@ -13,6 +13,7 @@ SET(PROJECT_HEADERS
        SketcherPrs_HVDirection.h
        SketcherPrs_Equal.h
        SketcherPrs_Tangent.h
+       SketcherPrs_SensitivePoint.h
 )
 
 SET(PROJECT_SOURCES
@@ -27,6 +28,7 @@ SET(PROJECT_SOURCES
        SketcherPrs_HVDirection.cpp
        SketcherPrs_Equal.cpp
        SketcherPrs_Tangent.cpp
+       SketcherPrs_SensitivePoint.cpp
 )
 
 SET(PROJECT_LIBRARIES
@@ -38,8 +40,16 @@ SET(PROJECT_LIBRARIES
     ${CAS_VIEWER}
     ${CAS_SHAPE}
     ${CAS_TKTopAlgo}
+    ${CAS_TKOpenGl}
 )
 
+IF(WIN32) 
+    SET(PROJECT_LIBRARIES ${PROJECT_LIBRARIES} opengl32)
+ELSE()
+    SET(PROJECT_LIBRARIES ${PROJECT_LIBRARIES} GL)
+ENDIF()
+
+
 SET(PROJECT_PICTURES
     icons/parallel.png
     icons/perpendicular.png
@@ -50,7 +60,7 @@ SET(PROJECT_PICTURES
        icons/tangent.png
 )
 
-ADD_DEFINITIONS(-DCONSTRAINTS_EXPORTS ${CAS_DEFINITIONS})
+ADD_DEFINITIONS(-DSKETCHERPRS_EXPORTS ${CAS_DEFINITIONS})
 ADD_LIBRARY(SketcherPrs SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
 
 INCLUDE_DIRECTORIES(
index d6fa639d9aec9d5a010354210e1e7dccaca129b9..7ba9a3f65ab9dddab53078881a589da978d0923a 100644 (file)
@@ -28,32 +28,21 @@ SketcherPrs_Equal::SketcherPrs_Equal(SketchPlugin_Constraint* theConstraint,
   myPntArray->AddVertex(0., 0., 0.);
 }  
 
-void SketcherPrs_Equal::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
-                                   const Handle(Prs3d_Presentation)& thePresentation, 
-                                   const Standard_Integer theMode)
+bool SketcherPrs_Equal::updatePoints(double theStep) const
 {
-  prepareAspect();
-
   ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
   ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
+  if (SketcherPrs_Tools::getShape(aObj1).get() == NULL)
+    return false;
+  if (SketcherPrs_Tools::getShape(aObj2).get() == NULL)
+    return false;
 
-  std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
-  if (aLine1.get() == NULL)
-    return;
-
-  std::shared_ptr<GeomAPI_Shape> aLine2 = SketcherPrs_Tools::getShape(aObj2);
-  if (aLine2.get() == NULL)
-    return;
-  
   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
-  gp_Pnt aP1 = aMgr->getPosition(aObj1, this);
-  gp_Pnt aP2 = aMgr->getPosition(aObj2, this);
-
-  Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
-  aGroup->SetPrimitivesAspect(myAspect);
+  gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep);
+  gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep);
   myPntArray->SetVertice(1, aP1);
   myPntArray->SetVertice(2, aP2);
-  aGroup->AddPrimitiveArray(myPntArray);
+  return true;
 }
 
 void SketcherPrs_Equal::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
index 90beb8c048e11c258a345ece1963930f50c9327d..4bd1a86ab53a3ec4937a923d145a7383056dd4a3 100644 (file)
@@ -30,13 +30,14 @@ public:
                                        const std::shared_ptr<GeomAPI_Ax3>& thePlane);
   DEFINE_STANDARD_RTTI(SketcherPrs_Equal)
 protected:
-  /// Redefinition of virtual function
-  Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
-    const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
 
   virtual const char* iconName() const { return "equal.png"; }
 
   virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
+
+  /// Update myPntArray according to presentation positions
+  /// \return true in case of success
+  virtual bool updatePoints(double theStep) const;
 };
 
 #endif
\ No newline at end of file
index 1d3f7335d66145c103603ffdf02b106e94f293f4..b6feedebc887265e3cd1a0d789999b8d32d05026 100644 (file)
@@ -16,7 +16,7 @@ class SketchPlugin_Constraint;
 
 #define GET_CONSTRAINT_PRS(NAME) \
   static AISObjectPtr NAME(SketchPlugin_Constraint* theConstraint, \
-                           const std::shared_ptr<GeomAPI_Ax3>& thePlane); \
+                           const std::shared_ptr<GeomAPI_Ax3>& thePlane);
 
 
 /**
index 2c0e892dd0973e70dd28ecab984a2d776c72af9a..5992db2fd4ed128240514a711feb824ea15ec785 100644 (file)
@@ -29,24 +29,16 @@ SketcherPrs_HVDirection::SketcherPrs_HVDirection(SketchPlugin_Constraint* theCon
   myPntArray->AddVertex(0., 0., 0.);
 }  
 
-void SketcherPrs_HVDirection::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
-                                   const Handle(Prs3d_Presentation)& thePresentation, 
-                                   const Standard_Integer theMode)
+bool SketcherPrs_HVDirection::updatePoints(double theStep) const 
 {
-  prepareAspect();
-
-  ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
-  std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
-  if (aLine1.get() == NULL)
-    return;
+  ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+  if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
+    return false;
 
   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
-  gp_Pnt aP1 = aMgr->getPosition(aObj1, this);
-
-  Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
-  aGroup->SetPrimitivesAspect(myAspect);
+  gp_Pnt aP1 = aMgr->getPosition(aObj, this, theStep);
   myPntArray->SetVertice(1, aP1);
-  aGroup->AddPrimitiveArray(myPntArray);
+  return true;
 }
 
 void SketcherPrs_HVDirection::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
index 84e993b05af9fb2ab7e05d38588de1abe40ce71b..96432d23071a59be989deb477bde3205a5333bed 100644 (file)
@@ -32,10 +32,6 @@ public:
 
   DEFINE_STANDARD_RTTI(SketcherPrs_HVDirection)
 protected:
-  /// Redefinition of virtual function
-  Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
-    const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
-
   virtual const char* iconName() const { return myIsHorisontal? "horisontal.png" : "vertical.png"; }
 
   /// Redefine this function in order to add additiona lines of constraint base
@@ -43,6 +39,10 @@ protected:
   /// \param theColor a color of additiona lines
   virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
 
+  /// Update myPntArray according to presentation positions
+  /// \return true in case of success
+  virtual bool updatePoints(double theStep) const;
+
 private:
   bool myIsHorisontal;
 };
index 6b7e071946cb9f67986edadae00d4f49ab2b7965..71f97ceda2329387a90395a3e714b81038f2c1e4 100644 (file)
@@ -26,37 +26,28 @@ SketcherPrs_Parallel::SketcherPrs_Parallel(SketchPlugin_Constraint* theConstrain
 {
   myPntArray = new Graphic3d_ArrayOfPoints(2);
   myPntArray->AddVertex(0., 0., 0.);
-  myPntArray->AddVertex(0. ,0., 0.);
+  myPntArray->AddVertex(0.0., 0.);
 }  
 
-void SketcherPrs_Parallel::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
-                                   const Handle(Prs3d_Presentation)& thePresentation, 
-                                   const Standard_Integer theMode)
-{
-  prepareAspect();
 
+bool SketcherPrs_Parallel::updatePoints(double theStep) const
+{
   ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
   ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
+  if (SketcherPrs_Tools::getShape(aObj1).get() == NULL)
+    return false;
+  if (SketcherPrs_Tools::getShape(aObj2).get() == NULL)
+    return false;
 
-  std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
-  if (aLine1.get() == NULL)
-    return;
-
-  std::shared_ptr<GeomAPI_Shape> aLine2 = SketcherPrs_Tools::getShape(aObj2);
-  if (aLine2.get() == NULL)
-    return;
-  
   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
-  gp_Pnt aP1 = aMgr->getPosition(aObj1, this);
-  gp_Pnt aP2 = aMgr->getPosition(aObj2, this);
-
-  Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
-  aGroup->SetPrimitivesAspect(myAspect);
+  gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep);
+  gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep);
   myPntArray->SetVertice(1, aP1);
   myPntArray->SetVertice(2, aP2);
-  aGroup->AddPrimitiveArray(myPntArray);
+  return true;
 }
 
+
 void SketcherPrs_Parallel::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
 {
   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
index 63aa6afc3efb87649cf038240badac9d5d4b1665..d0126d30b0e0e8197cff4c5f669c04ad76901493 100644 (file)
@@ -30,13 +30,13 @@ public:
                                        const std::shared_ptr<GeomAPI_Ax3>& thePlane);
   DEFINE_STANDARD_RTTI(SketcherPrs_Parallel)
 protected:
-  /// Redefinition of virtual function
-  Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
-    const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
-
   virtual const char* iconName() const { return "parallel.png"; }
 
   virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
+
+  /// Update myPntArray according to presentation positions
+  /// \return true in case of success
+  virtual bool updatePoints(double theStep) const;
 };
 
 #endif
\ No newline at end of file
index d27cf03e57cb1b28e4876ec9d52b7c11ac05f67b..e00b23d7df1b38283f920035608c9b48ed0c8d54 100644 (file)
@@ -29,34 +29,25 @@ SketcherPrs_Perpendicular::SketcherPrs_Perpendicular(SketchPlugin_Constraint* th
   myPntArray->AddVertex(0., 0., 0.);
 }  
 
-void SketcherPrs_Perpendicular::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
-                                   const Handle(Prs3d_Presentation)& thePresentation, 
-                                   const Standard_Integer theMode)
-{
-  prepareAspect();
 
+bool SketcherPrs_Perpendicular::updatePoints(double theStep) const
+{
   ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
   ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
-
-  std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
-  if (aLine1.get() == NULL)
-    return;
-
-  std::shared_ptr<GeomAPI_Shape> aLine2 = SketcherPrs_Tools::getShape(aObj2);
-  if (aLine2.get() == NULL)
-    return;
+  if (SketcherPrs_Tools::getShape(aObj1).get() == NULL)
+    return false;
+  if (SketcherPrs_Tools::getShape(aObj2).get() == NULL)
+    return false;
 
   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
-  gp_Pnt aP1 = aMgr->getPosition(aObj1, this);
-  gp_Pnt aP2 = aMgr->getPosition(aObj2, this);
-
-  Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
-  aGroup->SetPrimitivesAspect(myAspect);
+  gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep);
+  gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep);
   myPntArray->SetVertice(1, aP1);
   myPntArray->SetVertice(2, aP2);
-  aGroup->AddPrimitiveArray(myPntArray);
+  return true;
 }
 
+
 void SketcherPrs_Perpendicular::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
 {
   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
index 87a620ab13d06e4ebfd4499cd1d1ec9acd916ca5..c77a09203bcdb3f0a80ab550f3227845cc301ec4 100644 (file)
@@ -30,16 +30,16 @@ public:
 
   DEFINE_STANDARD_RTTI(SketcherPrs_Perpendicular)
 protected:
-  /// Redefinition of virtual function
-  Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
-    const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
-
   virtual const char* iconName() const { return "perpendicular.png"; }
 
   /// Redefine this function in order to add additiona lines of constraint base
   /// \param thePrs a presentation
   /// \param theColor a color of additiona lines
   virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
+
+  /// Update myPntArray according to presentation positions
+  /// \return true in case of success
+  virtual bool updatePoints(double theStep) const;
 };
 
 #endif
\ No newline at end of file
index 03fb8a9b2ef333d6c9248baf19e45732e22c2df0..2e0a66ae4f245386e223f2a2976b976518685e36 100644 (file)
@@ -12,8 +12,6 @@
 #include <GeomAPI_Vertex.h>
 #include <GeomAPI_Dir.h>
 
-static const int MyStep = 20;
-
 static SketcherPrs_PositionMgr* MyPosMgr = NULL;
 
 
@@ -50,7 +48,8 @@ int SketcherPrs_PositionMgr::getPositionIndex(ObjectPtr theLine,
 }
 
 gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape, 
-                                            Handle(SketcherPrs_SymbolPrs) thePrs)
+                                            Handle(SketcherPrs_SymbolPrs) thePrs,
+                                            double theStep)
 {
   std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(theShape);
   gp_Pnt aP; // Central point
@@ -91,7 +90,7 @@ gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape,
   }
   gp_Vec aShift = aVec1.Crossed(thePrs->plane()->norm()->impl<gp_Dir>());
   aShift.Normalize();
-  aShift.Multiply(MyStep);
+  aShift.Multiply(theStep);
 
   int aPos = getPositionIndex(theShape, thePrs);
   int aM = 1;
@@ -117,7 +116,7 @@ gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape,
   if (aPos > 1) {
     // Normalize vector along the line
     aVec1.Normalize();
-    aVec1.Multiply(MyStep);
+    aVec1.Multiply(theStep);
     aP.Translate(aVec1.Multiplied(aM));
   }
   return aP;
index 65a2aa06827c3407fe1e780c5fddb95b70d48f58..fd61fa64ffe90c6e6da3e29e427066ee8b4e7699 100644 (file)
@@ -29,7 +29,8 @@ public:
   /// Returns position of symbol for the given presentation
   /// \param theLine constrained object 
   /// \param thePrs a presentation of constraint
-  gp_Pnt getPosition(ObjectPtr theLine, Handle(SketcherPrs_SymbolPrs) thePrs);
+  /// \param theStep step between symbols
+  gp_Pnt getPosition(ObjectPtr theLine, Handle(SketcherPrs_SymbolPrs) thePrs, double theStep = 20);
 
   /// Deletes constraint object from internal structures. Has to be called on constraint delete.
   /// \param thePrs a constraint presentation
index 9c3d812ea7cb26a15695642e78e66fb9a1946ca3..84a36d3c017943d0afa10f58739fc211261ecc17 100644 (file)
@@ -32,7 +32,9 @@
 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Rigid, SketcherPrs_SymbolPrs);
 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Rigid, SketcherPrs_SymbolPrs);
 
-static Handle(Image_AlienPixMap) MyPixMap;
+static Handle(Image_AlienPixMap) MyPixMap; 
+
+
 
 SketcherPrs_Rigid::SketcherPrs_Rigid(SketchPlugin_Constraint* theConstraint, 
                                            const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
@@ -42,26 +44,20 @@ SketcherPrs_Rigid::SketcherPrs_Rigid(SketchPlugin_Constraint* theConstraint,
   myPntArray->AddVertex(0., 0., 0.);
 }  
 
-void SketcherPrs_Rigid::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
-                                   const Handle(Prs3d_Presentation)& thePresentation, 
-                                   const Standard_Integer theMode)
-{
-  prepareAspect();
 
-  ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
-  std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
-  if (aLine1.get() == NULL)
-    return;
+bool SketcherPrs_Rigid::updatePoints(double theStep) const 
+{
+  ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+  if (SketcherPrs_Tools::getShape(aObj).get() == NULL)
+    return false;
 
   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
-  gp_Pnt aP1 = aMgr->getPosition(aObj1, this);
-
-  Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
-  aGroup->SetPrimitivesAspect(myAspect);
+  gp_Pnt aP1 = aMgr->getPosition(aObj, this, theStep);
   myPntArray->SetVertice(1, aP1);
-  aGroup->AddPrimitiveArray(myPntArray);
+  return true;
 }
 
+
 void SketcherPrs_Rigid::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
 {
   ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
index 29ed4544a47d8dc0d5190895b021d8bcaf21183c..5328210773228b7eb49ae2d97703f7bc83f675fb 100644 (file)
@@ -8,6 +8,7 @@
 #define SketcherPrs_Rigid_H
 
 #include "SketcherPrs_SymbolPrs.h"
+#include <ModelAPI_Object.h>
 
 class SketchPlugin_Constraint;
 class SketchPlugin_Sketch;
@@ -29,18 +30,20 @@ public:
   Standard_EXPORT SketcherPrs_Rigid(SketchPlugin_Constraint* theConstraint, 
                                        const std::shared_ptr<GeomAPI_Ax3>& thePlane);
 
+
   DEFINE_STANDARD_RTTI(SketcherPrs_Rigid)
 protected:
-  /// Redefinition of virtual function
-  Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
-    const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
-
   virtual const char* iconName() const { return "anchor.png"; }
 
   /// Redefine this function in order to add additiona lines of constraint base
   /// \param thePrs a presentation
   /// \param theColor a color of additiona lines
   virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
+
+  /// Update myPntArray according to presentation positions
+  /// \return true in case of success
+  virtual bool updatePoints(double theStep) const;
+
 };
 
 #endif
\ No newline at end of file
diff --git a/src/SketcherPrs/SketcherPrs_SensitivePoint.cpp b/src/SketcherPrs/SketcherPrs_SensitivePoint.cpp
new file mode 100644 (file)
index 0000000..ac89d78
--- /dev/null
@@ -0,0 +1,124 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        SketcherPrs_SensitivePoint.cpp
+// Created:     24 March 2015
+// Author:      Vitaly SMETANNIKOV
+
+
+#include "SketcherPrs_SensitivePoint.h"
+
+#include <Select3D_Projector.hxx>
+#include <Bnd_Box2d.hxx>
+#include <CSLib_Class2d.hxx>
+#include <ElCLib.hxx>
+#include <TopLoc_Location.hxx>
+#include <SelectBasics_ListOfBox2d.hxx>
+
+IMPLEMENT_STANDARD_HANDLE(SketcherPrs_SensitivePoint, Select3D_SensitiveEntity);
+IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_SensitivePoint, Select3D_SensitiveEntity);
+
+SketcherPrs_SensitivePoint::SketcherPrs_SensitivePoint(const Handle(SelectBasics_EntityOwner)& anOwner,
+                                                        const Handle(Graphic3d_ArrayOfPoints)& thePntArray, 
+                                                        int theId)
+:Select3D_SensitiveEntity(anOwner), myId(theId), myPntArray(thePntArray)
+{
+  SetSensitivityFactor(4.);
+}
+
+void SketcherPrs_SensitivePoint::Project (const Handle(Select3D_Projector)& aProj)
+{
+  gp_Pnt2d aPoint2d;
+  gp_Pnt aPnt = Point();
+  if(!HasLocation())
+    aProj->Project(aPnt, aPoint2d);
+  else
+  {
+    gp_Pnt aP(aPnt.X(), aPnt.Y(), aPnt.Z());
+    aProj->Project(aP.Transformed(Location().Transformation()), aPoint2d);
+  }
+  myprojpt = aPoint2d;
+}
+
+void SketcherPrs_SensitivePoint::Areas(SelectBasics_ListOfBox2d& boxes)
+{
+  Bnd_Box2d abox;
+  abox.Set(myprojpt);
+  boxes.Append(abox);
+}
+
+Standard_Boolean SketcherPrs_SensitivePoint::Matches(const SelectBasics_PickArgs& thePickArgs,
+                                                      Standard_Real& theMatchDMin,
+                                                      Standard_Real& theMatchDepth)
+{
+  // check coordinate matching
+  Standard_Real aDist = gp_Pnt2d (thePickArgs.X(), thePickArgs.Y()).Distance (myprojpt);
+  if (aDist > thePickArgs.Tolerance() * SensitivityFactor())
+  {
+    return Standard_False;
+  }
+
+  Standard_Real aDepth = ComputeDepth (thePickArgs.PickLine());
+  if (thePickArgs.IsClipped (aDepth))
+  {
+    return Standard_False;
+  }
+
+  theMatchDMin = aDist;
+  theMatchDepth = aDepth;
+  return Standard_True;
+}
+
+Standard_Boolean SketcherPrs_SensitivePoint::Matches(const Standard_Real XMin,
+                                                     const Standard_Real YMin,
+                                                     const Standard_Real XMax,
+                                                     const Standard_Real YMax,
+                                                     const Standard_Real aTol)
+{
+  Bnd_Box2d B;
+  B.Update(Min(XMin,XMax),Min(YMin,YMax),Max(XMin,XMax),Max(YMin,YMax));
+  B.Enlarge(aTol);
+  return !B.IsOut(myprojpt);
+}
+
+Standard_Boolean SketcherPrs_SensitivePoint::Matches(const TColgp_Array1OfPnt2d& aPoly,
+                                                     const Bnd_Box2d& aBox,
+                                                     const Standard_Real aTol)
+{
+  Standard_Real Umin,Vmin,Umax,Vmax;
+  aBox.Get(Umin,Vmin,Umax,Vmax);
+  CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
+
+  Standard_Integer RES = aClassifier2d.SiDans(myprojpt);
+  if(RES==1) return Standard_True;
+
+  return Standard_False;
+}
+
+gp_Pnt SketcherPrs_SensitivePoint::Point() const
+{
+  return myPntArray->Vertice(myId);
+}
+
+Handle(Select3D_SensitiveEntity) SketcherPrs_SensitivePoint::GetConnected(const TopLoc_Location& aLoc)
+{
+  Handle(SketcherPrs_SensitivePoint) NiouEnt = new SketcherPrs_SensitivePoint(myOwnerId,myPntArray,myId);
+  if(HasLocation()) NiouEnt->SetLocation(Location());
+  NiouEnt->UpdateLocation(aLoc);
+  return NiouEnt;
+}
+
+void SketcherPrs_SensitivePoint::Dump(Standard_OStream& S,const Standard_Boolean /*FullDump*/) const
+{
+  gp_Pnt aPnt = Point();
+  S<<"\tSensitivePoint 3D :";
+  if(HasLocation())
+    S<<"\t\tExisting Location"<<endl;
+
+  S<<"\t\t P3d [ "<<aPnt.X()<<" , "<<aPnt.Y()<<" , "<<aPnt.Z()<<" ]"<<endl;
+  S<<"\t\t P2d [ "<<myprojpt.x<<" , "<<myprojpt.y<<" ]"<<endl;
+}
+
+Standard_Real SketcherPrs_SensitivePoint::ComputeDepth(const gp_Lin& EyeLine) const
+{
+  return ElCLib::Parameter(EyeLine, Point());
+}
diff --git a/src/SketcherPrs/SketcherPrs_SensitivePoint.h b/src/SketcherPrs/SketcherPrs_SensitivePoint.h
new file mode 100644 (file)
index 0000000..bc3628b
--- /dev/null
@@ -0,0 +1,61 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        SketcherPrs_SensitivePoint.h
+// Created:     24 March 2015
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef SketcherPrs_SensitivePoint_H
+#define SketcherPrs_SensitivePoint_H
+
+#include <Select3D_SensitiveEntity.hxx>
+#include <Graphic3d_ArrayOfPoints.hxx>
+#include <Select3D_Pnt2d.hxx>
+#include <Standard_DefineHandle.hxx>
+
+
+DEFINE_STANDARD_HANDLE(SketcherPrs_SensitivePoint, Select3D_SensitiveEntity)
+
+class SketcherPrs_SensitivePoint : public Select3D_SensitiveEntity
+{
+public: 
+  //! Constructs a sensitive point object defined by the
+  //! owner OwnerId and the point Point.
+  Standard_EXPORT SketcherPrs_SensitivePoint(const Handle(SelectBasics_EntityOwner)& OwnerId, 
+    const Handle(Graphic3d_ArrayOfPoints)& thePntArray, int theId);
+  
+  //! Converts the stored 3D point into a 2D point according
+  //! to <aProjector> ; this method is called by the selection Manager.
+  Standard_EXPORT   void Project (const Handle(Select3D_Projector)& aProjector) ;
+  
+  //! stores in <aresult> the 2D sensitive box which represents
+  //! the point area in the selection process.
+  Standard_EXPORT   void Areas (SelectBasics_ListOfBox2d& aresult) ;
+  
+  Standard_EXPORT   Handle(Select3D_SensitiveEntity) GetConnected (const TopLoc_Location& aLocation) ;
+  
+  //! Checks whether the sensitive entity matches the picking
+  //! detection area (close to the picking line).
+  //! For details please refer to base class declaration.
+  Standard_EXPORT   Standard_Boolean Matches (const SelectBasics_PickArgs& thePickArgs, Standard_Real& theMatchDMin, Standard_Real& theMatchDepth) ;
+  
+  Standard_EXPORT   Standard_Boolean Matches (const Standard_Real XMin, const Standard_Real YMin, const Standard_Real XMax, const Standard_Real YMax, const Standard_Real aTol) ;
+  
+  Standard_EXPORT virtual   Standard_Boolean Matches (const TColgp_Array1OfPnt2d& Polyline, const Bnd_Box2d& aBox, const Standard_Real aTol) ;
+  
+  Standard_EXPORT   Standard_Real ComputeDepth (const gp_Lin& EyeLine)  const;
+  
+  //! Returns the point used at the time of construction.
+  Standard_EXPORT   gp_Pnt Point()  const;
+
+  Standard_EXPORT virtual   void Dump (Standard_OStream& S, const Standard_Boolean FullDump = Standard_True)  const;
+
+  DEFINE_STANDARD_RTTI(SketcherPrs_SensitivePoint)
+
+private: 
+  int myId;
+  Handle(Graphic3d_ArrayOfPoints) myPntArray;
+  Select3D_Pnt2d myprojpt;
+};
+
+
+#endif
\ No newline at end of file
index b953501fa8b509abe938eb6182df85e9aa36e199..699bbab1f55e350c8c65f1dc6435a91ea40f3538 100644 (file)
 #include <GeomAPI_Edge.h>
 
 #include <Graphic3d_ArrayOfSegments.hxx>
+#include <Graphic3d_BndBox4f.hxx>
 
 #include <SelectMgr_Selection.hxx>
-#include <SelectMgr_EntityOwner.hxx>
 #include <Select3D_SensitivePoint.hxx>
+#include <TopLoc_Location.hxx>
+#include <AIS_InteractiveContext.hxx>
+#include <V3d_Viewer.hxx>
+#include <Prs3d_Root.hxx>
 
+#include <OpenGl_Element.hxx>
+#include <OpenGl_GraphicDriver.hxx>
+#include <OpenGl_Context.hxx>
+#include <OpenGl_View.hxx>
+#include <OpenGl_PointSprite.hxx>
+#include <OpenGl_VertexBuffer.hxx>
+#include <OpenGl_ShaderManager.hxx>
+#include <OpenGl_VertexBufferCompat.hxx>
+#include <OpenGl_GraphicDriver.hxx>
 
 #ifdef WIN32
 # define FSEP "\\"
 # define FSEP "/"
 #endif
 
+/// Step between icons
+static const double MyDist = 0.03;
+
+/// Function to convert opengl data type
+GLenum toGlDataType (const Graphic3d_TypeOfData theType, GLint& theNbComp)
+{
+  switch (theType) {
+    case Graphic3d_TOD_USHORT:
+      theNbComp = 1;
+      return GL_UNSIGNED_SHORT;
+    case Graphic3d_TOD_UINT:
+      theNbComp = 1;
+      return GL_UNSIGNED_INT;
+    case Graphic3d_TOD_VEC2:
+      theNbComp = 2;
+      return GL_FLOAT;
+    case Graphic3d_TOD_VEC3:
+      theNbComp = 3;
+      return GL_FLOAT;
+    case Graphic3d_TOD_VEC4:
+      theNbComp = 4;
+      return GL_FLOAT;
+    case Graphic3d_TOD_VEC4UB:
+      theNbComp = 4;
+      return GL_UNSIGNED_BYTE;
+  }
+  theNbComp = 0;
+  return GL_NONE;
+}
+
+
+//*******************************************************************
+//! Auxiliary class for Vertex buffer with interleaved attributes.
+class SketcherPrs_VertexBuffer : public OpenGl_VertexBuffer
+{
+
+public:
+
+  //! Create uninitialized VBO..
+  SketcherPrs_VertexBuffer (const Graphic3d_Attribute* theAttribs,
+                        const Standard_Integer     theStride)
+  : Stride (theStride), NbAttributes(1)
+  {
+
+    memcpy (Attribs, theAttribs, sizeof(Graphic3d_Attribute) * NbAttributes);
+  }
+
+  //! Create uninitialized VBO.
+  SketcherPrs_VertexBuffer (const Graphic3d_Buffer& theAttribs)
+  : Stride (theAttribs.Stride), NbAttributes(1)
+  {
+    memcpy (Attribs, theAttribs.AttributesArray(), sizeof(Graphic3d_Attribute) * NbAttributes);
+  }
+
+  virtual bool HasColorAttribute() const
+  {
+    for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter) {
+      const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter];
+      if (anAttrib.Id == Graphic3d_TOA_COLOR) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  virtual bool HasNormalAttribute() const
+  {
+    for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter) {
+      const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter];
+      if (anAttrib.Id == Graphic3d_TOA_NORM) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  virtual void BindPositionAttribute (const Handle(OpenGl_Context)& theGlCtx) const
+  {
+    if (!OpenGl_VertexBuffer::IsValid()) {
+      return;
+    }
+
+    OpenGl_VertexBuffer::Bind (theGlCtx);
+    GLint aNbComp;
+    const GLubyte* anOffset = OpenGl_VertexBuffer::myOffset;
+    for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter) {
+      const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter];
+      const GLenum   aDataType = toGlDataType (anAttrib.DataType, aNbComp);
+      if (aDataType == GL_NONE) {
+        continue;
+      } else if (anAttrib.Id == Graphic3d_TOA_POS) {
+        OpenGl_VertexBuffer::bindAttribute (theGlCtx, Graphic3d_TOA_POS, aNbComp, aDataType, Stride, anOffset);
+        break;
+      }
+
+      anOffset += Graphic3d_Attribute::Stride (anAttrib.DataType);
+    }
+  }
+
+  virtual void BindAllAttributes (const Handle(OpenGl_Context)& theGlCtx) const
+  {
+    if (!OpenGl_VertexBuffer::IsValid())
+      return;
+
+    OpenGl_VertexBuffer::Bind (theGlCtx);
+    GLint aNbComp;
+    const GLubyte* anOffset = OpenGl_VertexBuffer::myOffset;
+    for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter)
+    {
+      const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter];
+      const GLenum   aDataType = toGlDataType (anAttrib.DataType, aNbComp);
+      if (aDataType == GL_NONE)
+        continue;
+
+      OpenGl_VertexBuffer::bindAttribute (theGlCtx, anAttrib.Id, aNbComp, aDataType, Stride, anOffset);
+      anOffset += Graphic3d_Attribute::Stride (anAttrib.DataType);
+    }
+  }
+
+  virtual void UnbindAllAttributes (const Handle(OpenGl_Context)& theGlCtx) const
+  {
+    if (!OpenGl_VertexBuffer::IsValid())
+      return;
+    OpenGl_VertexBuffer::Unbind (theGlCtx);
+
+    for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter) {
+      const Graphic3d_Attribute& anAttrib = Attribs[anAttribIter];
+      OpenGl_VertexBuffer::unbindAttribute (theGlCtx, anAttrib.Id);
+    }
+  }
+
+public:
+
+  Graphic3d_Attribute Attribs[1];
+  Standard_Integer    Stride;
+  Standard_Integer NbAttributes;
+};
+
+//**************************************************************
+//! Redefinition of OpenGl_Element
+class SketcherPrs_Element: public OpenGl_Element
+{
+public:
+  SketcherPrs_Element(const Handle(SketcherPrs_SymbolPrs)& theObj) : 
+  OpenGl_Element(), myObj(theObj) {}
+
+  virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const
+  {
+    if (!myObj.IsNull())
+      myObj->Render(theWorkspace);
+  }
+
+  virtual void Release (OpenGl_Context* theContext) 
+  {
+    if (!myObj.IsNull())
+      myObj->Release(theContext);
+  }
+
+private:
+  Handle(SketcherPrs_SymbolPrs) myObj;
+};
+
+
+//**************************************************************
+//! Definition of call back
+OpenGl_Element* SymbolPrsCallBack(const CALL_DEF_USERDRAW * theUserDraw)
+{
+  Handle(SketcherPrs_SymbolPrs) anIObj = (SketcherPrs_SymbolPrs*)theUserDraw->Data;
+  if (anIObj.IsNull()) {
+    std::cout << "VUserDrawCallback error: null object passed, the custom scene element will not be rendered" << std::endl;
+  }
+  return new SketcherPrs_Element(anIObj);
+}
+
+
+//*****************************************************************************
 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_SymbolPrs, AIS_InteractiveObject);
 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_SymbolPrs, AIS_InteractiveObject);
 
@@ -111,18 +300,127 @@ void SketcherPrs_SymbolPrs::HilightOwnerWithColor(const Handle(PrsMgr_Presentati
     thePM->AddToImmediateList(aHilightPrs);
 }
 
+void SketcherPrs_SymbolPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+                                   const Handle(Prs3d_Presentation)& thePresentation, 
+                                   const Standard_Integer theMode)
+{
+  prepareAspect();
+
+  Handle(AIS_InteractiveContext) aCtx = GetContext();
+  Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast(aCtx->CurrentViewer()->Driver());
+  if (!aDriver.IsNull()) {
+    // register the custom element factory function
+    aDriver->UserDrawCallback() = SymbolPrsCallBack;
+  }
+
+  if (!updatePoints(20))
+    return;
+
+  int aNbVertex = myPntArray->VertexNumber();
+  if (myOwner.IsNull()) {
+    myOwner = new SelectMgr_EntityOwner(this);
+    for (int i = 1; i <= aNbVertex; i++) {
+      Handle(SketcherPrs_SensitivePoint) aSP = new SketcherPrs_SensitivePoint(myOwner, myPntArray, i);
+      mySPoints.Append(aSP);
+    }
+  }
+
+  Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePresentation);
+  aGroup->SetPrimitivesAspect(myAspect);
+
+  Graphic3d_BndBox4f& aBnd = aGroup->ChangeBoundingBox();
+  gp_Pnt aVert;
+  aBnd.Clear();
+  for (int i = 1; i <= myPntArray->ItemNumber(); i++) {
+    aVert = myPntArray->Vertice(i);
+    aBnd.Add (Graphic3d_Vec4((float)aVert.X(), (float)aVert.Y(), (float)aVert.Z(), 1.0f));
+  }
+
+  aGroup->UserDraw(this, true);
+  //aGroup->AddPrimitiveArray(myPntArray);
+}
+
 
 
 void SketcherPrs_SymbolPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
                                             const Standard_Integer aMode)
 {
   ClearSelected();
+  for (int i = 1; i <= mySPoints.Length(); i++)
+    aSelection->Add(mySPoints.Value(i));
+}
+
 
-  if (!myPntArray.IsNull()) {
-    Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this);
-    for (int i = 1; i <= myPntArray->VertexNumber(); i++) {
-      Handle(Select3D_SensitivePoint) aSP = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(i));
-      aSelection->Add(aSP);
+void SketcherPrs_SymbolPrs::Render(const Handle(OpenGl_Workspace)& theWorkspace) const
+{
+  const OpenGl_AspectMarker* anAspectMarker = theWorkspace->AspectMarker(Standard_True);
+  const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
+  Handle(OpenGl_View) aView = theWorkspace->ActiveView();
+  
+  double aScale = aView->Camera()->Scale();
+  if (!updatePoints(MyDist * aScale))
+    return;
+
+  Handle(Graphic3d_Buffer) aAttribs = myPntArray->Attributes();
+
+  if (myVboAttribs.IsNull()) {
+    myVboAttribs = new SketcherPrs_VertexBuffer(*aAttribs);
+  }
+
+  if (!myVboAttribs->init(aCtx, 0, aAttribs->NbElements, aAttribs->Data(), GL_NONE, aAttribs->Stride)) {
+    myVboAttribs->Release (aCtx.operator->());
+    myVboAttribs.Nullify();
+    return;
+  }
+    
+  Handle(OpenGl_Texture) aTextureBack = theWorkspace->DisableTexture();
+
+  const Handle(OpenGl_PointSprite)& aSpriteNorm = anAspectMarker->SpriteRes(aCtx);
+      
+  if (!aSpriteNorm.IsNull() && !aSpriteNorm->IsDisplayList()) {
+    const bool toHilight = (theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT) != 0;
+    const Handle(OpenGl_PointSprite)& aSprite = (toHilight && anAspectMarker->SpriteHighlightRes(aCtx)->IsValid())
+                                              ? anAspectMarker->SpriteHighlightRes(aCtx)
+                                              : aSpriteNorm;
+    theWorkspace->EnableTexture (aSprite);
+    aCtx->ShaderManager()->BindProgram(anAspectMarker, aSprite, Standard_False, Standard_False, anAspectMarker->ShaderProgramRes(aCtx));
+    const TEL_COLOUR* aLineColor  =  &anAspectMarker->Color();
+    if (theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT)
+      aLineColor = theWorkspace->HighlightColor;
+
+    aCtx->SetColor4fv(*(const OpenGl_Vec4* )(aLineColor->rgb));
+
+
+    myVboAttribs->BindAllAttributes(aCtx);
+    // Textured markers will be drawn with the point sprites
+    aCtx->SetPointSize (anAspectMarker->MarkerSize());
+    aCtx->core11fwd->glEnable (GL_ALPHA_TEST);
+    aCtx->core11fwd->glAlphaFunc (GL_GEQUAL, 0.1f);
+
+    aCtx->core11fwd->glEnable (GL_BLEND);
+    aCtx->core11fwd->glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+    aCtx->core11fwd->glDrawArrays (0, 0, myVboAttribs->GetElemsNb());
+
+    aCtx->core11fwd->glDisable (GL_BLEND);
+    aCtx->core11fwd->glDisable (GL_ALPHA_TEST);
+    aCtx->SetPointSize (1.0f);
+  }
+  theWorkspace->EnableTexture (aTextureBack);
+  aCtx->BindProgram (NULL);
+
+  // Update selection position
+  GetContext()->RecomputeSelectionOnly(this);
+}
+
+
+void SketcherPrs_SymbolPrs::Release (OpenGl_Context* theContext)
+{
+  if (!myVboAttribs.IsNull()) {
+    if (theContext) {
+      theContext->DelayedRelease (myVboAttribs);
     }
+    myVboAttribs.Nullify();
   }
 }
+
index 3fe2086996917b60e2e590adf4e4c99d8e7e7b7b..c087ff6bade584393590f52a2ff4c26a1d6c5046 100644 (file)
@@ -7,16 +7,23 @@
 #ifndef SketcherPrs_SymbolPrs_H
 #define SketcherPrs_SymbolPrs_H
 
+#include "SketcherPrs_SensitivePoint.h"
+
 #include <AIS_InteractiveObject.hxx>
 #include <GeomAPI_Ax3.h>
 #include <Graphic3d_ArrayOfPoints.hxx>
 #include <Graphic3d_AspectMarker3d.hxx>
 #include <Image_AlienPixMap.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+#include <Select3D_SensitiveEntitySequence.hxx>
 
 #include <Standard_DefineHandle.hxx>
 #include <map>
 
+#include <OpenGl_Workspace.hxx>
+
 class SketchPlugin_Constraint;
+class OpenGl_Context;
 
 
 DEFINE_STANDARD_HANDLE(SketcherPrs_SymbolPrs, AIS_InteractiveObject)
@@ -52,9 +59,19 @@ public:
 
   Standard_EXPORT SketchPlugin_Constraint* feature() const { return myConstraint; }
 
+
+  Handle(Graphic3d_ArrayOfPoints) pointsArray() const { return myPntArray; }
+
+  void Render(const Handle(OpenGl_Workspace)& theWorkspace) const;
+
+  void Release (OpenGl_Context* theContext);
+
   DEFINE_STANDARD_RTTI(SketcherPrs_SymbolPrs)
 
 protected:
+  /// Redefinition of virtual function
+  Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+    const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
 
   /// Redefinition of virtual function
   Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
@@ -80,6 +97,10 @@ protected:
   /// \param theColor a color of additiona lines
   virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const {}
 
+  /// Update myPntArray according to presentation positions
+  /// \return true in case of success
+  virtual bool updatePoints(double theStep) const { return true; }
+
 protected:
   /// Constraint feature
   SketchPlugin_Constraint* myConstraint;
@@ -91,12 +112,17 @@ protected:
   Handle(Graphic3d_AspectMarker3d) myAspect;
 
   /// Array of symbols positions
-  Handle(Graphic3d_ArrayOfPoints) myPntArray;
+  mutable Handle(Graphic3d_ArrayOfPoints) myPntArray;
+
+  Handle(SelectMgr_EntityOwner) myOwner;
 
 private: 
   /// Static map to collect constraints icons {IconName : IconPixMap}
   static std::map<const char*, Handle(Image_AlienPixMap)> myIconsMap;
 
+  mutable Handle(OpenGl_VertexBuffer) myVboAttribs;
+
+  Select3D_SensitiveEntitySequence mySPoints;
 };
 
 #endif
\ No newline at end of file
index 88dcd35c3fd45b27b56196ccb1e4f7ad9daef8a6..bbee898f92e735037e25243449d0f4a4991b4497 100644 (file)
@@ -32,32 +32,21 @@ SketcherPrs_Tangent::SketcherPrs_Tangent(SketchPlugin_Constraint* theConstraint,
   myPntArray->AddVertex(0., 0., 0.);
 }  
 
-void SketcherPrs_Tangent::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
-                                   const Handle(Prs3d_Presentation)& thePresentation, 
-                                   const Standard_Integer theMode)
+bool SketcherPrs_Tangent::updatePoints(double theStep) const
 {
-  prepareAspect();
-
   ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
   ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
+  if (SketcherPrs_Tools::getShape(aObj1).get() == NULL)
+    return false;
+  if (SketcherPrs_Tools::getShape(aObj2).get() == NULL)
+    return false;
 
-  std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getShape(aObj1);
-  if (aLine1.get() == NULL)
-    return;
-
-  std::shared_ptr<GeomAPI_Shape> aLine2 = SketcherPrs_Tools::getShape(aObj2);
-  if (aLine2.get() == NULL)
-    return;
-  
   SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
-  gp_Pnt aP1 = aMgr->getPosition(aObj1, this);
-  gp_Pnt aP2 = aMgr->getPosition(aObj2, this);
-
-  Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
-  aGroup->SetPrimitivesAspect(myAspect);
+  gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep);
+  gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep);
   myPntArray->SetVertice(1, aP1);
   myPntArray->SetVertice(2, aP2);
-  aGroup->AddPrimitiveArray(myPntArray);
+  return true;
 }
 
 void SketcherPrs_Tangent::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
index e1faefe2175e8085fe4b770bf32142f8de343eb4..335006da59e1cf682ef42b1167390826a387d561 100644 (file)
@@ -28,15 +28,17 @@ public:
   /// \param thePlane a coordinate plane of current sketch
   Standard_EXPORT SketcherPrs_Tangent(SketchPlugin_Constraint* theConstraint, 
                                        const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+
   DEFINE_STANDARD_RTTI(SketcherPrs_Tangent)
 protected:
-  /// Redefinition of virtual function
-  Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
-    const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
 
   virtual const char* iconName() const { return "tangent.png"; }
 
   virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
+
+  /// Update myPntArray according to presentation positions
+  /// \return true in case of success
+  virtual bool updatePoints(double theStep) const;
 };
 
 #endif
\ No newline at end of file
index 3176442f64049a911497746232d405bbe7f120aa..022b1c356d5683aa876bb84a5907b51c09a2452c 100644 (file)
@@ -44,5 +44,6 @@
      <file>pictures/module.png</file>
      <file>pictures/shading.png</file>
      <file>pictures/wireframe.png</file>
+     <file>pictures/expression.png</file>
  </qresource>
  </RCC>
diff --git a/src/XGUI/pictures/expression.png b/src/XGUI/pictures/expression.png
new file mode 100644 (file)
index 0000000..39dd556
Binary files /dev/null and b/src/XGUI/pictures/expression.png differ