]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Added option to create Construction Point by distance on edge. Fixed tests.
authordbv <dbv@opencascade.com>
Fri, 1 Jul 2016 09:33:37 +0000 (12:33 +0300)
committerdbv <dbv@opencascade.com>
Fri, 1 Jul 2016 09:33:37 +0000 (12:33 +0300)
27 files changed:
src/ConstructionAPI/ConstructionAPI_Point.cpp
src/ConstructionAPI/ConstructionAPI_Point.h
src/ConstructionAPI/Test/TestPoint.py
src/ConstructionPlugin/CMakeLists.txt
src/ConstructionPlugin/ConstructionPlugin_Point.cpp
src/ConstructionPlugin/ConstructionPlugin_Point.h
src/ConstructionPlugin/Test/TestAxisCreation.py
src/ConstructionPlugin/Test/TestPointName.py
src/ConstructionPlugin/icons/distance_value.png [new file with mode: 0644]
src/ConstructionPlugin/icons/edge.png [new file with mode: 0644]
src/ConstructionPlugin/icons/point_by_distance_on_edge_32x32.png [new file with mode: 0644]
src/ConstructionPlugin/icons/point_by_xyz_32x32.png [new file with mode: 0644]
src/ConstructionPlugin/icons/x_size.png [new file with mode: 0644]
src/ConstructionPlugin/icons/y_size.png [new file with mode: 0644]
src/ConstructionPlugin/icons/z_size.png [new file with mode: 0644]
src/ConstructionPlugin/point_widget.xml
src/FeaturesPlugin/icons/dimension_up_32x32.png
src/FeaturesPlugin/icons/dimension_up_down_32x32.png
src/GeomAPI/GeomAPI_Edge.cpp
src/GeomAPI/GeomAPI_Edge.h
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h
src/GeomValidators/GeomValidators_Finite.cpp
src/InitializationPlugin/InitializationPlugin_Plugin.cpp
src/ModelAPI/Test/TestUndoRedo.py
src/SketchPlugin/Test/TestConstraintCoincidence.py
src/SketchPlugin/Test/TestConstraintMiddlePoint.py

index ff5a89de3686ed1d515502f8d602c6cafa9f7692..c982cc2a7fb42c094efed78d4b23193bb4d43c89 100644 (file)
@@ -4,39 +4,54 @@
 // History:
 // 29/03/16 - Sergey POKHODENKO - Creation of the file
 
-//--------------------------------------------------------------------------------------
 #include "ConstructionAPI_Point.h"
-//--------------------------------------------------------------------------------------
+
 #include <ModelHighAPI_Tools.h>
-//--------------------------------------------------------------------------------------
-ConstructionAPI_Point::ConstructionAPI_Point(
-    const std::shared_ptr<ModelAPI_Feature> & theFeature)
+
+//==================================================================================================
+ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature)
 : ModelHighAPI_Interface(theFeature)
 {
   initialize();
 }
 
-ConstructionAPI_Point::ConstructionAPI_Point(
-    const std::shared_ptr<ModelAPI_Feature> & theFeature,
-    const ModelHighAPI_Double & theX,
-    const ModelHighAPI_Double & theY,
-    const ModelHighAPI_Double & theZ)
+//==================================================================================================
+ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                             const ModelHighAPI_Double& theX,
+                                             const ModelHighAPI_Double& theY,
+                                             const ModelHighAPI_Double& theZ)
+: ModelHighAPI_Interface(theFeature)
+{
+  if(initialize()) {
+    setByXYZ(theX, theY, theZ);
+  }
+}
+
+//==================================================================================================
+ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                             const ModelHighAPI_Selection& theEdge,
+                                             const ModelHighAPI_Double& theDistanceValue,
+                                             const bool theDistancePercent,
+                                             const bool theReverse)
 : ModelHighAPI_Interface(theFeature)
 {
-  if (initialize())
-    setPoint(theX, theY, theZ);
+  if(initialize()) {
+    setByDistanceOnEdge(theEdge, theDistanceValue, theDistancePercent, theReverse);
+  }
 }
 
+//==================================================================================================
 ConstructionAPI_Point::~ConstructionAPI_Point()
 {
 
 }
 
-//--------------------------------------------------------------------------------------
-void ConstructionAPI_Point::setPoint(const ModelHighAPI_Double & theX,
-                                     const ModelHighAPI_Double & theY,
-                                     const ModelHighAPI_Double & theZ)
+//==================================================================================================
+void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX,
+                                     const ModelHighAPI_Double& theY,
+                                     const ModelHighAPI_Double& theZ)
 {
+  fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
   fillAttribute(theX, myx);
   fillAttribute(theY, myy);
   fillAttribute(theZ, myz);
@@ -44,14 +59,40 @@ void ConstructionAPI_Point::setPoint(const ModelHighAPI_Double & theX,
   execute();
 }
 
-//--------------------------------------------------------------------------------------
-PointPtr addPoint(
-    const std::shared_ptr<ModelAPI_Document> & thePart,
-    const ModelHighAPI_Double& theX,
-    const ModelHighAPI_Double& theY,
-    const ModelHighAPI_Double& theZ)
+//==================================================================================================
+void ConstructionAPI_Point::setByDistanceOnEdge(const ModelHighAPI_Selection& theEdge,
+                                                const ModelHighAPI_Double& theDistanceValue,
+                                                const bool theDistancePercent,
+                                                const bool theReverse)
+{
+  fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE(), mycreationMethod);
+  fillAttribute(theEdge, myedge);
+  fillAttribute(theDistanceValue, mydistanceValue);
+  fillAttribute(theDistancePercent, mydistancePercent);
+  fillAttribute(theReverse, myreverse);
+
+  execute();
+}
+
+//==================================================================================================
+PointPtr addPoint(const std::shared_ptr<ModelAPI_Document>& thePart,
+                  const ModelHighAPI_Double& theX,
+                  const ModelHighAPI_Double& theY,
+                  const ModelHighAPI_Double& theZ)
 {
   // TODO(spo): check that thePart is not empty
   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
   return PointPtr(new ConstructionAPI_Point(aFeature, theX, theY, theZ));
 }
+
+//==================================================================================================
+PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
+                  const ModelHighAPI_Selection& theEdge,
+                  const ModelHighAPI_Double& theDistanceValue,
+                  const bool theDistancePercent,
+                  const bool theReverse)
+{
+  // TODO(spo): check that thePart is not empty
+  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
+  return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theDistanceValue, theDistancePercent, theReverse));
+}
index d2af332986b9a2c43d25bee8ccd1fd9e702a7aef..3e67ce80ee76ba397b534ee1424480c2692eead0 100644 (file)
@@ -7,63 +7,89 @@
 #ifndef SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_POINT_H_
 #define SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_POINT_H_
 
-//--------------------------------------------------------------------------------------
 #include "ConstructionAPI.h"
 
 #include <ConstructionPlugin_Point.h>
 
 #include <ModelHighAPI_Interface.h>
 #include <ModelHighAPI_Macro.h>
-//--------------------------------------------------------------------------------------
+
 class ModelAPI_AttributeDouble;
 class ModelAPI_Document;
 class ModelHighAPI_Double;
-//--------------------------------------------------------------------------------------
-/**\class ConstructionAPI_Point
- * \ingroup CPPHighAPI
- * \brief Interface for Point feature
- */
-class ConstructionAPI_Point : public ModelHighAPI_Interface
+
+/// \class ConstructionAPI_Point
+/// \ingroup CPPHighAPI
+/// \brief Interface for Point feature
+class ConstructionAPI_Point: public ModelHighAPI_Interface
 {
 public:
   /// Constructor without values
   CONSTRUCTIONAPI_EXPORT
-  explicit ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature> & theFeature);
+  explicit ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature);
+
+  /// Constructor with values
+  CONSTRUCTIONAPI_EXPORT
+  ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                        const ModelHighAPI_Double& theX,
+                        const ModelHighAPI_Double& theY,
+                        const ModelHighAPI_Double& theZ);
+
   /// Constructor with values
   CONSTRUCTIONAPI_EXPORT
-  ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature> & theFeature,
-                        const ModelHighAPI_Double & theX,
-                        const ModelHighAPI_Double & theY,
-                        const ModelHighAPI_Double & theZ);
+  ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                        const ModelHighAPI_Selection& theEdge,
+                        const ModelHighAPI_Double& theDistanceValue,
+                        const bool theDistancePercent = false,
+                        const bool theReverse = false);
+
   /// Destructor
   CONSTRUCTIONAPI_EXPORT
   virtual ~ConstructionAPI_Point();
 
-  INTERFACE_3(ConstructionPlugin_Point::ID(),
+  INTERFACE_8(ConstructionPlugin_Point::ID(),
+              creationMethod, ConstructionPlugin_Point::CREATION_METHOD(), ModelAPI_AttributeString, /** Creation method */,
               x, ConstructionPlugin_Point::X(), ModelAPI_AttributeDouble, /** X attribute */,
               y, ConstructionPlugin_Point::Y(), ModelAPI_AttributeDouble, /** Y attribute */,
-              z, ConstructionPlugin_Point::Z(), ModelAPI_AttributeDouble, /** Z attribute */
+              z, ConstructionPlugin_Point::Z(), ModelAPI_AttributeDouble, /** Z attribute */,
+              edge, ConstructionPlugin_Point::EDGE(), ModelAPI_AttributeSelection, /** Edge attribute */,
+              distanceValue, ConstructionPlugin_Point::DISTANCE_VALUE(), ModelAPI_AttributeDouble, /** Distance value attribute */,
+              distancePercent, ConstructionPlugin_Point::DISTANCE_PERCENT(), ModelAPI_AttributeBoolean, /** Distance percent attribute */,
+              reverse, ConstructionPlugin_Point::REVERSE(), ModelAPI_AttributeBoolean, /** Reverse attribute */
   )
 
   /// Set point values
   CONSTRUCTIONAPI_EXPORT
-  void setPoint(const ModelHighAPI_Double & theX,
+  void setByXYZ(const ModelHighAPI_Double & theX,
                 const ModelHighAPI_Double & theY,
                 const ModelHighAPI_Double & theZ);
+
+  /// Set edge and distance on it for point
+  CONSTRUCTIONAPI_EXPORT
+  void setByDistanceOnEdge(const ModelHighAPI_Selection& theEdge,
+                           const ModelHighAPI_Double& theDistanceValue,
+                           const bool theDistancePercent = false,
+                           const bool theReverse = false);
 };
 
-//! Pointer on Point object
+/// Pointer on Point object
 typedef std::shared_ptr<ConstructionAPI_Point> PointPtr;
 
-/**\ingroup CPPHighAPI
- * \brief Create Point feature
- */
+/// \ingroup CPPHighAPI
+/// \brief Create Point feature
 CONSTRUCTIONAPI_EXPORT
 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
                   const ModelHighAPI_Double & theX,
                   const ModelHighAPI_Double & theY,
                   const ModelHighAPI_Double & theZ);
 
-//--------------------------------------------------------------------------------------
-//--------------------------------------------------------------------------------------
+/// \ingroup CPPHighAPI
+/// \brief Create Point feature
+CONSTRUCTIONAPI_EXPORT
+PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
+                  const ModelHighAPI_Selection& theEdge,
+                  const ModelHighAPI_Double& theDistanceValue,
+                  const bool theDistancePercent = false,
+                  const bool theReverse = false);
+
 #endif /* SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_POINT_H_ */ 
index 7c184c5c52f7261fee2bd9eeb6504b4cecfb8d06..2ed6c9f05078c0b19b820341f153d05c12730f98 100644 (file)
@@ -28,7 +28,7 @@ class PointTestCase(unittest.TestCase):
         self.assertEqual(0, point.y().value())
         self.assertEqual(0, point.z().value())
 
-        point.setPoint(10, "20", "x + 30")
+        point.setByXYZ(10, "20", "x + 30")
         self.assertEqual(10, point.x().value())
         self.assertEqual("20", point.y().text())
         self.assertEqual("x + 30", point.z().text())
index 5fd66b7b8311b65a473ac87317b31fe5058529d6..bdbc15f8536a4626df324adcb418ed465caf446e 100644 (file)
@@ -7,15 +7,15 @@ SET(PROJECT_HEADERS
     ConstructionPlugin.h
     ConstructionPlugin_Plugin.h
     ConstructionPlugin_Point.h
-       ConstructionPlugin_Axis.h
-       ConstructionPlugin_Plane.h
+    ConstructionPlugin_Axis.h
+    ConstructionPlugin_Plane.h
 )
 
 SET(PROJECT_SOURCES
     ConstructionPlugin_Plugin.cpp
     ConstructionPlugin_Point.cpp
-       ConstructionPlugin_Axis.cpp
-       ConstructionPlugin_Plane.cpp
+    ConstructionPlugin_Axis.cpp
+    ConstructionPlugin_Plane.cpp
 )
 
 SET(XML_RESOURCES
index c164e44a40225855d89111b0ed14b17be1a45e2e..c7b4f1d444a44ef351e0d2f928115d78605bfea0 100644 (file)
 // Author:      Mikhail PONIKAROV
 
 #include "ConstructionPlugin_Point.h"
-#include "ModelAPI_Session.h"
-#include "ModelAPI_Document.h"
-#include "ModelAPI_Data.h"
-#include "ModelAPI_AttributeDouble.h"
+
+#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeString.h>
 #include <ModelAPI_ResultConstruction.h>
-#include <GeomAlgoAPI_PointBuilder.h>
-#include <GeomAPI_Pnt.h>
 
-#include <Config_PropManager.h>
+#include <GeomAlgoAPI_PointBuilder.h>
+#include <GeomAlgoAPI_ShapeTools.h>
 
-using namespace std;
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Pnt.h>
 
+//==================================================================================================
 ConstructionPlugin_Point::ConstructionPlugin_Point()
 {
 }
 
+//==================================================================================================
 const std::string& ConstructionPlugin_Point::getKind()
 {
   static std::string MY_KIND = ConstructionPlugin_Point::ID();
   return MY_KIND;
 }
 
+//==================================================================================================
 void ConstructionPlugin_Point::initAttributes()
 {
-  data()->addAttribute(ConstructionPlugin_Point::X(), ModelAPI_AttributeDouble::typeId());
-  data()->addAttribute(ConstructionPlugin_Point::Y(), ModelAPI_AttributeDouble::typeId());
-  data()->addAttribute(ConstructionPlugin_Point::Z(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(X(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(Y(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(Z(), ModelAPI_AttributeDouble::typeId());
+
+  data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
+
+  data()->addAttribute(EDGE(), ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(DISTANCE_VALUE(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(DISTANCE_PERCENT(), ModelAPI_AttributeBoolean::typeId());
+  data()->addAttribute(REVERSE(), ModelAPI_AttributeBoolean::typeId());
 }
 
+//==================================================================================================
 void ConstructionPlugin_Point::execute()
 {
-  std::shared_ptr<GeomAPI_Pnt> aPnt(
-      new GeomAPI_Pnt(data()->real(ConstructionPlugin_Point::X())->value(),
-                      data()->real(ConstructionPlugin_Point::Y())->value(),
-                      data()->real(ConstructionPlugin_Point::Z())->value()));
-
-  std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
-  aConstr->setShape(GeomAlgoAPI_PointBuilder::point(aPnt));
-  setResult(aConstr);
+  GeomShapePtr aShape;
+
+  std::string aCreationMethod = string(CREATION_METHOD())->value();
+  if(aCreationMethod == CREATION_METHOD_BY_XYZ()) {
+    aShape = createByXYZ();
+  } else if(aCreationMethod == CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
+    aShape = createByDistanceOnEdge();
+  }
+
+  if(aShape.get()) {
+    std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
+    aConstr->setShape(aShape);
+    setResult(aConstr);
+  }
 }
 
-bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult, 
+//==================================================================================================
+bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult,
                                                      AISObjectPtr thePrs,
-                               std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
+                                                     std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
 {
   bool isCustomized = theDefaultPrs.get() != NULL &&
                       theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
   //thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
   return true;
 }
+
+//==================================================================================================
+GeomShapePtr ConstructionPlugin_Point::createByXYZ()
+{
+  return GeomAlgoAPI_PointBuilder::point(real(X())->value(),
+                                         real(Y())->value(),
+                                         real(Z())->value());
+}
+
+//==================================================================================================
+GeomShapePtr ConstructionPlugin_Point::createByDistanceOnEdge()
+{
+  // Get edge.
+  AttributeSelectionPtr anEdgeSelection = selection(EDGE());
+  GeomShapePtr aShape = anEdgeSelection->value();
+  if(!aShape.get()) {
+    aShape = anEdgeSelection->context()->shape();
+  }
+  std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShape));
+
+  // Get distance value and percent flag.
+  double aValue = real(DISTANCE_VALUE())->value();
+  bool anIsPercent = boolean(DISTANCE_PERCENT())->value();
+
+  // Get reverse flag.
+  bool anIsReverse = boolean(REVERSE())->value();
+
+  return GeomAlgoAPI_ShapeTools::findVertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse);
+}
index d1f15287f64d62d6e50bc67a555eac16a8e23ee9..956eeeb0069ae108010c8acf3374dcdec5ba3f7c 100644 (file)
 #define ConstructionPlugin_Point_H_
 
 #include "ConstructionPlugin.h"
+
+#include <GeomAPI_ICustomPrs.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Result.h>
-#include <GeomAPI_ICustomPrs.h>
 
-/**\class ConstructionPlugin_Point
- * \ingroup Plugins
- * \brief Feature for creation of the new part in PartSet.
- */
-class ConstructionPlugin_Point : public ModelAPI_Feature, public GeomAPI_ICustomPrs
+/// \class ConstructionPlugin_Point
+/// \ingroup Plugins
+/// \brief Feature for creation of the new part in PartSet.
+class ConstructionPlugin_Point: public ModelAPI_Feature, public GeomAPI_ICustomPrs
 {
- public:
-  /// Returns the kind of a feature
+public:
+  /// Returns the kind of a feature.
   CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getKind();
 
-  /// Point kind
+  /// Point kind.
   inline static const std::string& ID()
   {
     static const std::string CONSTRUCTION_POINT_KIND("Point");
     return CONSTRUCTION_POINT_KIND;
   }
 
-  /// attribute name for X coordinate
+  /// Attribute name for creation method.
+  inline static const std::string& CREATION_METHOD()
+  {
+    static const std::string MY_CREATION_METHOD_ID("creation_method");
+    return MY_CREATION_METHOD_ID;
+  }
+
+  /// Attribute name for creation method.
+  inline static const std::string& CREATION_METHOD_BY_XYZ()
+  {
+    static const std::string MY_CREATION_METHOD_ID("by_xyz");
+    return MY_CREATION_METHOD_ID;
+  }
+
+  /// Attribute name for creation method.
+  inline static const std::string& CREATION_METHOD_BY_DISTANCE_ON_EDGE()
+  {
+    static const std::string MY_CREATION_METHOD_ID("by_distance_on_edge");
+    return MY_CREATION_METHOD_ID;
+  }
+
+  /// Attribute name for X coordinate.
   inline static const std::string& X()
   {
     static const std::string POINT_ATTR_X("x");
     return POINT_ATTR_X;
   }
-  /// attribute name for Y coordinate
+
+  /// Attribute name for Y coordinate.
   inline static const std::string& Y()
   {
     static const std::string POINT_ATTR_Y("y");
     return POINT_ATTR_Y;
   }
-  /// attribute name for Z coordinate
+
+  /// Attribute name for Z coordinate.
   inline static const std::string& Z()
   {
     static const std::string POINT_ATTR_Z("z");
     return POINT_ATTR_Z;
   }
 
-  /// Creates a new part document if needed
+  /// Attribute name for seleted edge.
+  inline static const std::string& EDGE()
+  {
+    static const std::string ATTR_ID("edge");
+    return ATTR_ID;
+  }
+
+  /// Attribute name for distance.
+  inline static const std::string& DISTANCE_VALUE()
+  {
+    static const std::string ATTR_ID("value");
+    return ATTR_ID;
+  }
+
+  /// Attribute name for percent flag.
+  inline static const std::string& DISTANCE_PERCENT()
+  {
+    static const std::string ATTR_ID("percent");
+    return ATTR_ID;
+  }
+
+  /// Attribute name for reverse flag.
+  inline static const std::string& REVERSE()
+  {
+    static const std::string ATTR_ID("reverse");
+    return ATTR_ID;
+  }
+
+  /// Creates a new part document if needed.
   CONSTRUCTIONPLUGIN_EXPORT virtual void execute();
 
-  /// Request for initialization of data model of the feature: adding all attributes
+  /// Request for initialization of data model of the feature: adding all attributes.
   CONSTRUCTIONPLUGIN_EXPORT virtual void initAttributes();
 
-  /// Construction result is allways recomuted on the fly
+  /// Construction result is allways recomuted on the fly.
   CONSTRUCTIONPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
 
   /// Use plugin manager for features creation
@@ -63,6 +114,11 @@ class ConstructionPlugin_Point : public ModelAPI_Feature, public GeomAPI_ICustom
   /// Customize presentation of the feature
   virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
                                      std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs);
+
+private:
+  std::shared_ptr<GeomAPI_Shape> createByXYZ();
+  std::shared_ptr<GeomAPI_Shape> createByDistanceOnEdge();
+
 };
 
 #endif
index 34039691e7eeabd4403339a8da507f73ae871ffd..35885a872134c6090ef1e64ff3ee1cc1f68319f4 100644 (file)
@@ -26,6 +26,7 @@ aSession.startOperation()
 aPointFeature = aPart.addFeature("Point")
 aPointFeatureData = aPointFeature.data()
 assert(aPointFeatureData is not None)
+aPointFeatureData.string("creation_method").setValue("by_xyz")
 aPointFeatureData.real("x").setValue(0.)
 aPointFeatureData.real("y").setValue(0.)
 aPointFeatureData.real("z").setValue(0.)
@@ -40,6 +41,7 @@ aSession.startOperation()
 aPointFeature = aPart.addFeature("Point")
 aPointFeatureData = aPointFeature.data()
 assert(aPointFeatureData is not None)
+aPointFeatureData.string("creation_method").setValue("by_xyz")
 aPointFeatureData.real("x").setValue(0.)
 aPointFeatureData.real("y").setValue(0.)
 aPointFeatureData.real("z").setValue(100.)
index 43a942db002cc648a1d7099ea4ae222ef731e8f2..274c931b29f8ea1514fce4de2da8663177b422e0 100644 (file)
@@ -7,6 +7,7 @@ aSession.startOperation()
 aFeature = aDoc.addFeature("Point")
 aFeatureData = aFeature.data()
 assert(aFeatureData is not None)
+aFeatureData.string("creation_method").setValue("by_xyz")
 aFeatureData.real("x").setValue(0.)
 aFeatureData.real("y").setValue(0.)
 aFeatureData.real("z").setValue(0.)
diff --git a/src/ConstructionPlugin/icons/distance_value.png b/src/ConstructionPlugin/icons/distance_value.png
new file mode 100644 (file)
index 0000000..b40da2e
Binary files /dev/null and b/src/ConstructionPlugin/icons/distance_value.png differ
diff --git a/src/ConstructionPlugin/icons/edge.png b/src/ConstructionPlugin/icons/edge.png
new file mode 100644 (file)
index 0000000..53dbb08
Binary files /dev/null and b/src/ConstructionPlugin/icons/edge.png differ
diff --git a/src/ConstructionPlugin/icons/point_by_distance_on_edge_32x32.png b/src/ConstructionPlugin/icons/point_by_distance_on_edge_32x32.png
new file mode 100644 (file)
index 0000000..121f239
Binary files /dev/null and b/src/ConstructionPlugin/icons/point_by_distance_on_edge_32x32.png differ
diff --git a/src/ConstructionPlugin/icons/point_by_xyz_32x32.png b/src/ConstructionPlugin/icons/point_by_xyz_32x32.png
new file mode 100644 (file)
index 0000000..663ba95
Binary files /dev/null and b/src/ConstructionPlugin/icons/point_by_xyz_32x32.png differ
diff --git a/src/ConstructionPlugin/icons/x_size.png b/src/ConstructionPlugin/icons/x_size.png
new file mode 100644 (file)
index 0000000..8f292c7
Binary files /dev/null and b/src/ConstructionPlugin/icons/x_size.png differ
diff --git a/src/ConstructionPlugin/icons/y_size.png b/src/ConstructionPlugin/icons/y_size.png
new file mode 100644 (file)
index 0000000..9d3e5f9
Binary files /dev/null and b/src/ConstructionPlugin/icons/y_size.png differ
diff --git a/src/ConstructionPlugin/icons/z_size.png b/src/ConstructionPlugin/icons/z_size.png
new file mode 100644 (file)
index 0000000..c1f108a
Binary files /dev/null and b/src/ConstructionPlugin/icons/z_size.png differ
index 5ce9fe1fb092330f74c6a6db4557f72bba254e28..4557509f39f119ebdd77c3dd2699fc6f846a5eda 100644 (file)
@@ -1,7 +1,53 @@
 <!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
 
 <source>
-  <doublevalue id="x" label="X " tooltip="X coordinate" default="0"/>
-  <doublevalue id="y" label="Y " tooltip="Y coordinate" default="0"/>
-  <doublevalue id="z" label="Z " tooltip="Z coordinate" default="0"/>
+  <toolbox id="creation_method">
+    <box id="by_xyz"
+         title="By X, Y, Z"
+         tooltip="Point at a given distance from the origin."
+         icon="icons/Construction/point_by_xyz_32x32.png">
+      <doublevalue id="x"
+                   label="X "
+                   tooltip="X coordinate."
+                   icon="icons/Construction/x_size.png"
+                   default="0"/>
+      <doublevalue id="y"
+                   label="Y "
+                   tooltip="Y coordinate."
+                   icon="icons/Construction/y_size.png"
+                   default="0"/>
+      <doublevalue id="z"
+                   label="Z "
+                   tooltip="Z coordinate."
+                   icon="icons/Construction/z_size.png"
+                   default="0"/>
+    </box>
+    <box id="by_distance_on_edge"
+         title="By distance on edge"
+         tooltip="Point on an edge, at a given distance of one of its end."
+         icon="icons/Construction/point_by_distance_on_edge_32x32.png">
+      <shape_selector id="edge"
+                      label="Edge"
+                      tooltip="Edge for creating point on it."
+                      icon="icons/Construction/edge.png"
+                      shape_types="edge">
+        <validator id="GeomValidators_Finite"/>
+      </shape_selector>
+      <groupbox title="Distance">
+        <doublevalue id="value"
+                     label="Value"
+                     tooltip="Distance value."
+                     icon="icons/Construction/distance_value.png"
+                     default="50"/>
+        <boolvalue id="percent"
+                   label="Percent(%)"
+                   tooltip="Distance in percent from length."
+                   default="true"/>
+      </groupbox>
+      <boolvalue id="reverse"
+           label="Reverse"
+           tooltip="Distance from edge end point."
+           default="false"/>
+    </box>
+  </toolbox>
 </source>
index 8b6ad7ce587466cddec83ea11e6a9ce260ea2e77..4b4c35fa3c719ef483716446237a3de7925b029d 100644 (file)
Binary files a/src/FeaturesPlugin/icons/dimension_up_32x32.png and b/src/FeaturesPlugin/icons/dimension_up_32x32.png differ
index adee89f65f9f7e8988a05d3c9d355d0d631d2088..b081893cdad1b7b983bc32a22e28fd89def52b93 100644 (file)
Binary files a/src/FeaturesPlugin/icons/dimension_up_down_32x32.png and b/src/FeaturesPlugin/icons/dimension_up_down_32x32.png differ
index 594829f8cbb90c0af9422be90d989aa6770f2e18..84f63b17f011665b7b868ce1383c14eaf1cef059 100644 (file)
@@ -11,6 +11,8 @@
 #include<GeomAPI_Dir.h>
 #include<GeomAPI_Lin.h>
 
+#include <BRepAdaptor_Curve.hxx>
+
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Edge.hxx>
 #include <TopoDS.hxx>
@@ -23,6 +25,8 @@
 #include <gp_Ax1.hxx>
 #include <gp_Pln.hxx>
 
+#include <GCPnts_AbscissaPoint.hxx>
+
 GeomAPI_Edge::GeomAPI_Edge()
 {
   TopoDS_Edge* anEdge = new TopoDS_Edge;
@@ -219,3 +223,9 @@ bool GeomAPI_Edge::isInPlane(std::shared_ptr<GeomAPI_Pln> thePlane) const
   }
   return inPlane;
 }
+
+double GeomAPI_Edge::length() const
+{
+  const TopoDS_Edge& anEdge = TopoDS::Edge(impl<TopoDS_Shape>());
+  return GCPnts_AbscissaPoint::Length(BRepAdaptor_Curve(anEdge));
+}
index e4dfcf2a8201208ab78b576f073c0d57b3ddbed6..afe8243eaf3b5edee49122aeb07ad38d5f78d4ad 100644 (file)
@@ -69,6 +69,10 @@ public:
   /// Returns true, if the edge is fully placed in the specified plane
   GEOMAPI_EXPORT
   bool isInPlane(const std::shared_ptr<GeomAPI_Pln> thePlane) const;
+
+  /// Returns edge length.
+  GEOMAPI_EXPORT
+  double length() const;
 };
 
 #endif
index f1c9569aa27021bc8431c21a3b93ab8f643a2070..029743117c77fbd33550558955e1d989b3782406 100644 (file)
 #include <BRepBuilderAPI_FindPlane.hxx>
 #include <BRepBuilderAPI_MakeEdge.hxx>
 #include <BRepBuilderAPI_MakeFace.hxx>
+#include <BRepBuilderAPI_MakeVertex.hxx>
 #include <BRepCheck_Analyzer.hxx>
 #include <BRepExtrema_DistShapeShape.hxx>
 #include <BRepExtrema_ExtCF.hxx>
 #include <BRepGProp.hxx>
 #include <BRepTools.hxx>
 #include <BRepTopAdaptor_FClass2d.hxx>
+#include <GCPnts_AbscissaPoint.hxx>
 #include <Geom_Curve.hxx>
 #include <Geom2d_Curve.hxx>
 #include <BRepLib_CheckCurveOnSurface.hxx>
@@ -665,3 +667,46 @@ bool GeomAlgoAPI_ShapeTools::isParallel(const std::shared_ptr<GeomAPI_Edge> theE
   BRepExtrema_ExtCF anExt(anEdge, aFace);
   return anExt.IsParallel() == Standard_True;
 }
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_ShapeTools::findVertexOnEdge(const std::shared_ptr<GeomAPI_Edge> theEdge,
+                                                                         const double theValue,
+                                                                         const bool theIsPercent,
+                                                                         const bool theIsReverse)
+{
+  std::shared_ptr<GeomAPI_Vertex> aVertex;
+
+  if(!theEdge.get()) {
+    return aVertex;
+  }
+
+  double aValue = theValue;
+  if(theIsPercent) {
+    aValue = theEdge->length() / 100.0 * aValue;
+  }
+
+  const TopoDS_Edge& anEdge = TopoDS::Edge(theEdge->impl<TopoDS_Shape>());
+  Standard_Real aUFirst, aULast;
+  Handle(Geom_Curve) anEdgeCurve = BRep_Tool::Curve(anEdge, aUFirst, aULast);
+
+  if(!anEdgeCurve.IsNull() ) {
+    Handle(Geom_Curve) aReOrientedCurve = anEdgeCurve;
+
+    if(theIsReverse) {
+      aReOrientedCurve = anEdgeCurve->Reversed();
+      aUFirst = anEdgeCurve->ReversedParameter(aULast);
+    }
+
+    // Get the point by length
+    GeomAdaptor_Curve anAdapCurve = GeomAdaptor_Curve(aReOrientedCurve);
+    GCPnts_AbscissaPoint anAbsPnt(anAdapCurve, aValue, aUFirst);
+    Standard_Real aParam = anAbsPnt.Parameter();
+    gp_Pnt aPnt = anAdapCurve.Value(aParam);
+    BRepBuilderAPI_MakeVertex aMkVertex(aPnt);
+    const TopoDS_Vertex& aShape = aMkVertex.Vertex();
+    aVertex.reset(new GeomAPI_Vertex());
+    aVertex->setImpl(new TopoDS_Vertex(aShape));
+  }
+
+  return aVertex;
+}
index 01b1e73669e6ba4826bec044e3e5601fa6561cca..f1814c750d873fe10bdcf840c312b4d29d2c4108 100644 (file)
@@ -103,6 +103,17 @@ public:
   GEOMALGOAPI_EXPORT static bool isParallel(const std::shared_ptr<GeomAPI_Edge> theEdge,
                                             const std::shared_ptr<GeomAPI_Face> theFace);
 
+  /// \brief Creates vertex by edge and distance on it.
+  /// \param[in] theEdge edge.
+  /// \param[in] theValue distance value.
+  /// \param[in] theIsPercent if true theValue will be treated as a percentage of theEdge total length.
+  /// \param[in] theIsReverse if true the distance will be measured from the edge end point.
+  /// \ return created vertex.
+  GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Vertex> findVertexOnEdge(const std::shared_ptr<GeomAPI_Edge> theEdge,
+                                                                             const double theValue,
+                                                                             const bool theIsPercent = false,
+                                                                             const bool theIsReverse = false);
+
 };
 
 #endif
index 6668b8bbae9b06bba33d9c59088899b9dc69fcd7..67f8d70c94687efd4e836ed10ad9d8589e9928ea 100755 (executable)
@@ -17,7 +17,17 @@ bool GeomValidators_Finite::isValid(const AttributePtr& theAttribute,
 {
   bool aValid = true;
 
-  if (theAttribute->attributeType() == ModelAPI_AttributeSelectionList::typeId()) {
+  const std::string anAttributeType = theAttribute->attributeType();
+
+  if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
+    AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+    ResultPtr aResult = aSelectionAttr->context();
+    ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aResult);
+    if (aConstruction.get() && aConstruction->isInfinite()) {
+      aValid = false;
+      theError = "Infinite result is selected.";
+    }
+  } else if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
     AttributeSelectionListPtr aSelectionListAttr = 
                       std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
     for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize; i++) {
index 0c47e2a52586263d639d9e850d9f6a053846ee9c..cdfe868ac68de7481cfc758ff4a61e9e7d084eda 100644 (file)
@@ -119,6 +119,7 @@ FeaturePtr InitializationPlugin_Plugin::createPoint(DocumentPtr theDoc, const st
                                                     double theX, double theY, double theZ)
 {
   std::shared_ptr<ModelAPI_Feature> aPoint = theDoc->addFeature("Point");
+  aPoint->string("creation_method")->setValue("by_xyz");
   aPoint->real("x")->setValue(theX);
   aPoint->real("y")->setValue(theY);
   aPoint->real("z")->setValue(theZ);
index 1df119f97c26d77e4162708edad5e582ba9892e3..b9701a1b9639fe0e3a627af6be6dc563bcfd0d36 100644 (file)
@@ -8,6 +8,7 @@ aSession.startOperation()
 aFeature = aDoc.addFeature("Point")\r
 # Since validators are introduced we have to initialize all\r
 # the feature's attributes\r
+aFeature.string("creation_method").setValue("by_xyz")\r
 aFeature.real("x").setValue(1.)\r
 aFeature.real("y").setValue(-1.)\r
 aFeature.real("z").setValue(0.)\r
index a0a7bc3ccf2d8c18be78188bafda28e0761a8c60..c7ba672dacf33e0a5bddb32dcda1f3d48a8d598a 100644 (file)
@@ -1,7 +1,7 @@
 """
     TestConstraintCoincidence.py
     Unit test of SketchPlugin_ConstraintCoincidence class
-    
+
     SketchPlugin_Constraint
         static const std::string MY_CONSTRAINT_VALUE("ConstraintValue");
         static const std::string MY_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt");
@@ -9,7 +9,7 @@
         static const std::string MY_ENTITY_B("ConstraintEntityB");
         static const std::string MY_ENTITY_C("ConstraintEntityC");
         static const std::string MY_ENTITY_D("ConstraintEntityD");
-        
+
     SketchPlugin_ConstraintCoincidence
         static const std::string MY_CONSTRAINT_COINCIDENCE_ID("SketchConstraintCoincidence");
         data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
@@ -61,6 +61,7 @@ aDocument = aSession.moduleDocument()
 # add an origin
 aSession.startOperation()
 aFeature = aDocument.addFeature("Point")
+aFeature.string("creation_method").setValue("by_xyz")
 aFeature.real("x").setValue(0.)
 aFeature.real("y").setValue(0.)
 aFeature.real("z").setValue(0.)
index 09506082bc58b0dce6c238d9ee2413e58521f972..42e2138934bb041114c57dea6fe09ff36b5b4aeb 100644 (file)
@@ -1,7 +1,7 @@
 """
     TestConstraintCoincidence.py
     Unit test of SketchPlugin_ConstraintCoincidence class
-    
+
     SketchPlugin_Constraint
         static const std::string MY_CONSTRAINT_VALUE("ConstraintValue");
         static const std::string MY_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt");
@@ -9,7 +9,7 @@
         static const std::string MY_ENTITY_B("ConstraintEntityB");
         static const std::string MY_ENTITY_C("ConstraintEntityC");
         static const std::string MY_ENTITY_D("ConstraintEntityD");
-        
+
     SketchPlugin_ConstraintCoincidence
         static const std::string MY_CONSTRAINT_COINCIDENCE_ID("SketchConstraintCoincidence");
         data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
@@ -45,6 +45,7 @@ aDocument = aSession.moduleDocument()
 # add an origin
 aSession.startOperation()
 aFeature = aDocument.addFeature("Point")
+aFeature.string("creation_method").setValue("by_xyz")
 aFeature.real("x").setValue(0.)
 aFeature.real("y").setValue(0.)
 aFeature.real("z").setValue(0.)