]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Horizontal and vertical distances now show positive value (but store signed value...
authorazv <azv@opencascade.com>
Tue, 24 Oct 2017 14:07:54 +0000 (17:07 +0300)
committerazv <azv@opencascade.com>
Wed, 25 Oct 2017 04:44:24 +0000 (07:44 +0300)
12 files changed:
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_ConstraintDistanceAlongDir.cpp [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_ConstraintDistanceAlongDir.h [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_ConstraintDistanceHorizontal.cpp
src/SketchPlugin/SketchPlugin_ConstraintDistanceHorizontal.h
src/SketchPlugin/SketchPlugin_ConstraintDistanceVertical.cpp
src/SketchPlugin/SketchPlugin_ConstraintDistanceVertical.h
src/SketchPlugin/Test/TestConstraintDistanceBehavior.py
src/SketchPlugin/Test/TestConstraintDistanceHorizontal.py
src/SketchPlugin/Test/TestConstraintDistanceVertical.py
src/SketchPlugin/plugin-Sketch.xml
src/SketcherPrs/SketcherPrs_LengthDimension.cpp

index 4b4c0b15c54f67feaafcf83f62a99e9f6a073d27..e7ec8b7c75dd03891b82e56f0ad4bde4e7c85cba 100644 (file)
@@ -31,6 +31,7 @@ SET(PROJECT_HEADERS
     SketchPlugin_ConstraintCoincidence.h
     SketchPlugin_ConstraintCollinear.h
     SketchPlugin_ConstraintDistance.h
+    SketchPlugin_ConstraintDistanceAlongDir.h
     SketchPlugin_ConstraintDistanceHorizontal.h
     SketchPlugin_ConstraintDistanceVertical.h
     SketchPlugin_ConstraintEqual.h
@@ -76,6 +77,7 @@ SET(PROJECT_SOURCES
     SketchPlugin_ConstraintCoincidence.cpp
     SketchPlugin_ConstraintCollinear.cpp
     SketchPlugin_ConstraintDistance.cpp
+    SketchPlugin_ConstraintDistanceAlongDir.cpp
     SketchPlugin_ConstraintDistanceHorizontal.cpp
     SketchPlugin_ConstraintDistanceVertical.cpp
     SketchPlugin_ConstraintEqual.cpp
diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistanceAlongDir.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistanceAlongDir.cpp
new file mode 100644 (file)
index 0000000..779d082
--- /dev/null
@@ -0,0 +1,144 @@
+// Copyright (C) 2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
+
+// File:    SketchPlugin_ConstraintDistanceAlongDir.cpp
+// Created: 24 October 2017
+// Author:  Artem ZHIDKOV
+
+#include <SketchPlugin_ConstraintDistanceAlongDir.h>
+
+#include <SketcherPrs_Tools.h>
+#include <SketcherPrs_Factory.h>
+
+#include <GeomAPI_Dir2d.h>
+#include <GeomAPI_XY.h>
+#include <GeomDataAPI_Point2D.h>
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+
+const double tolerance = 1e-7;
+
+
+SketchPlugin_ConstraintDistanceAlongDir::SketchPlugin_ConstraintDistanceAlongDir()
+  : SketchPlugin_ConstraintDistance(),
+    myValue(-1.e100),
+    myValueUpdate(false)
+{
+}
+
+//*************************************************************************************
+void SketchPlugin_ConstraintDistanceAlongDir::initAttributes()
+{
+  data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId());
+  data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
+  data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId());
+
+  data()->addAttribute(LOCATION_TYPE_ID(), ModelAPI_AttributeInteger::typeId());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), LOCATION_TYPE_ID());
+
+  data()->addAttribute(DISTANCE_VALUE_ID(), ModelAPI_AttributeDouble::typeId());
+
+  data()->addAttribute(NEGATIVE_TYPE_ID(), ModelAPI_AttributeBoolean::typeId());
+  boolean(NEGATIVE_TYPE_ID())->setValue(false);
+}
+
+//*************************************************************************************
+void SketchPlugin_ConstraintDistanceAlongDir::execute()
+{
+  AttributeDoublePtr anAttrValue = real(SketchPlugin_Constraint::VALUE());
+  if (anAttrValue->isInitialized() || !areAttributesInitialized())
+    return;
+
+  double aDistance = calculateCurrentDistance();
+  anAttrValue->setValue(aDistance);
+}
+
+//*************************************************************************************
+AISObjectPtr SketchPlugin_ConstraintDistanceAlongDir::getAISObject(AISObjectPtr thePrevious)
+{
+  if (!sketch())
+    return thePrevious;
+
+  AISObjectPtr anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this,
+                                                                      sketch()->coordinatePlane(),
+                                                                      thePrevious);
+  return anAIS;
+}
+
+void SketchPlugin_ConstraintDistanceAlongDir::attributeChanged(const std::string& theID)
+{
+  if (theID == SketchPlugin_Constraint::ENTITY_A() ||
+      theID == SketchPlugin_Constraint::ENTITY_B())
+  {
+    AttributeDoublePtr aValueAttr = real(SketchPlugin_Constraint::VALUE());
+    if (!aValueAttr->isInitialized() && areAttributesInitialized()) {
+      // only if it is not initialized, try to compute the current value
+      double aDistance = calculateCurrentDistance();
+      aValueAttr->setValue(aDistance);
+    }
+  } else if (theID == SketchPlugin_Constraint::VALUE() && !myValueUpdate) {
+    myValueUpdate = true;
+    // value of the distance shown to the user should be always positive
+    AttributeDoublePtr aDistanceValueAttr = real(DISTANCE_VALUE_ID());
+    double aConstraintValue = real(SketchPlugin_Constraint::VALUE())->value();
+    aDistanceValueAttr->setValue(fabs(aConstraintValue));
+    myValueUpdate = false;
+  } else if (theID == DISTANCE_VALUE_ID() && !myValueUpdate){
+    myValueUpdate = true;
+    // update value of the distance according to the value set by user
+    double aDistanceValue = real(DISTANCE_VALUE_ID())->value();
+    AttributeDoublePtr aConstraintValueAttr = real(SketchPlugin_Constraint::VALUE());
+    if (aConstraintValueAttr->value() < 0.0)
+      aDistanceValue = -aDistanceValue;
+    aConstraintValueAttr->setValue(aDistanceValue);
+    myValueUpdate = false;
+  } else if (theID == SketchPlugin_Constraint::FLYOUT_VALUE_PNT() && !myFlyoutUpdate) {
+    // Recalculate flyout point in local coordinates of the distance constraint:
+    // the X coordinate is a length of projection of the flyout point on the
+    //                  line binding two distanced points
+    //                  or a line of projection of the distanced point onto the distanced segment
+    // the Y coordinate is a distance from the flyout point to the line
+    std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+        attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
+    std::shared_ptr<GeomAPI_Pnt2d> aFlyoutPnt = aFlyoutAttr->pnt();
+
+    std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(sketch());
+    std::shared_ptr<GeomDataAPI_Point2D> aPointA = SketcherPrs_Tools::getFeaturePoint(
+        data(), SketchPlugin_Constraint::ENTITY_A(), aPlane);
+    std::shared_ptr<GeomDataAPI_Point2D> aPointB = SketcherPrs_Tools::getFeaturePoint(
+        data(), SketchPlugin_Constraint::ENTITY_B(), aPlane);
+
+    std::shared_ptr<GeomAPI_XY> aStartPnt = aPointA->pnt()->xy();
+    std::shared_ptr<GeomAPI_XY> aEndPnt = aPointB->pnt()->xy();
+
+    if (aEndPnt->distance(aStartPnt) < tolerance)
+      return;
+
+    std::shared_ptr<GeomAPI_XY> aFlyoutDir = aFlyoutPnt->xy()->decreased(aEndPnt);
+    myFlyoutUpdate = true;
+    updateFlyoutPoint();
+    myFlyoutUpdate = false;
+  }
+}
diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistanceAlongDir.h b/src/SketchPlugin/SketchPlugin_ConstraintDistanceAlongDir.h
new file mode 100644 (file)
index 0000000..bd38dad
--- /dev/null
@@ -0,0 +1,91 @@
+// Copyright (C) 2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
+
+// File:    SketchPlugin_ConstraintDistanceAlongDir.h
+// Created: 24 October 2017
+// Author:  Artem ZHIDKOV
+
+#ifndef SketchPlugin_ConstraintDistanceAlongDir_H_
+#define SketchPlugin_ConstraintDistanceAlongDir_H_
+
+#include <SketchPlugin.h>
+#include <SketchPlugin_ConstraintDistance.h>
+
+/** \class SketchPlugin_ConstraintDistanceAlongDir
+ *  \ingroup Plugins
+ *  \brief Feature for creation of a new constraint which defines a distance along direction.
+ *         The base class for horizontal and vertical constraints.
+ *
+ *  This constraint has three attributes:
+ *  SketchPlugin_Constraint::VALUE(), SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B()
+ */
+class SketchPlugin_ConstraintDistanceAlongDir : public SketchPlugin_ConstraintDistance
+{
+public:
+  /// attribute name of dimension location type
+  inline static const std::string& LOCATION_TYPE_ID()
+  {
+    static const std::string MY_LOCATION_TYPE_ID("LocationType");
+    return MY_LOCATION_TYPE_ID;
+  }
+
+  /// attribute name of the distance value shown to the user
+  inline static const std::string& DISTANCE_VALUE_ID()
+  {
+    static const std::string& MY_DISTANCE_VALUE("DistanceValue");
+    return MY_DISTANCE_VALUE;
+  }
+
+  /// attribute name of the sign of distance
+  inline static const std::string& NEGATIVE_TYPE_ID()
+  {
+    static const std::string MY_NEGATIVE_VALUE("NegativeValue");
+    return MY_NEGATIVE_VALUE;
+  }
+
+  /// \brief Creates a new part document if needed
+  SKETCHPLUGIN_EXPORT virtual void execute();
+
+  /// \brief Request for initialization of data model of the feature: adding all attributes
+  SKETCHPLUGIN_EXPORT virtual void initAttributes();
+
+  /// Returns the AIS preview
+  SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
+
+  /// Called on change of any argument-attribute of this object
+  /// \param theID identifier of changed attribute
+  SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+
+  /// \brief Use plugin manager for features creation
+  SketchPlugin_ConstraintDistanceAlongDir();
+
+protected:
+  /// Returns the current distance between the feature attributes
+  virtual double calculateCurrentDistance() = 0;
+
+  /// Update flyout point
+  virtual void updateFlyoutPoint() = 0;
+
+protected:
+  double myValue;
+  bool myValueUpdate;
+};
+
+#endif
index 355292413533f48d127d4443380c85af2188e92f..ae3a5e0a56d14da1fa3d762c42653fe8f5b4ae71 100644 (file)
 #include <SketchPlugin_ConstraintDistanceHorizontal.h>
 
 #include <SketcherPrs_Tools.h>
-#include <SketcherPrs_Factory.h>
 
-#include <GeomAPI_Dir2d.h>
 #include <GeomAPI_XY.h>
 #include <GeomDataAPI_Point2D.h>
 
-#include <ModelAPI_AttributeDouble.h>
-#include <ModelAPI_AttributeInteger.h>
-#include <ModelAPI_Session.h>
-#include <ModelAPI_Validator.h>
-
-const double tolerance = 1e-7;
-
 
 SketchPlugin_ConstraintDistanceHorizontal::SketchPlugin_ConstraintDistanceHorizontal()
-  : SketchPlugin_ConstraintDistance()
-{
-}
-
-//*************************************************************************************
-void SketchPlugin_ConstraintDistanceHorizontal::initAttributes()
-{
-  data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId());
-  data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId());
-  data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
-  data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId());
-
-  data()->addAttribute(SketchPlugin_ConstraintDistanceHorizontal::LOCATION_TYPE_ID(),
-                       ModelAPI_AttributeInteger::typeId());
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), LOCATION_TYPE_ID());
-}
-
-//*************************************************************************************
-void SketchPlugin_ConstraintDistanceHorizontal::execute()
-{
-  AttributeDoublePtr anAttrValue = real(SketchPlugin_Constraint::VALUE());
-  if (anAttrValue->isInitialized() || !areAttributesInitialized())
-    return;
-
-  double aDistance = calculateCurrentDistance();
-  anAttrValue->setValue(aDistance);
-}
-
-//*************************************************************************************
-AISObjectPtr SketchPlugin_ConstraintDistanceHorizontal::getAISObject(AISObjectPtr thePrevious)
+  : SketchPlugin_ConstraintDistanceAlongDir()
 {
-  if (!sketch())
-    return thePrevious;
-
-  AISObjectPtr anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this,
-                                                                      sketch()->coordinatePlane(),
-                                                                      thePrevious);
-  return anAIS;
 }
 
 double SketchPlugin_ConstraintDistanceHorizontal::calculateCurrentDistance()
@@ -92,44 +47,19 @@ double SketchPlugin_ConstraintDistanceHorizontal::calculateCurrentDistance()
   return aPointB->x() - aPointA->x();
 }
 
-void SketchPlugin_ConstraintDistanceHorizontal::attributeChanged(const std::string& theID)
+void SketchPlugin_ConstraintDistanceHorizontal::updateFlyoutPoint()
 {
-  if (theID == SketchPlugin_Constraint::ENTITY_A() ||
-      theID == SketchPlugin_Constraint::ENTITY_B())
-  {
-    AttributeDoublePtr aValueAttr = real(SketchPlugin_Constraint::VALUE());
-    if (!aValueAttr->isInitialized() && areAttributesInitialized()) {
-      // only if it is not initialized, try to compute the current value
-      double aDistance = calculateCurrentDistance();
-      aValueAttr->setValue(aDistance);
-    }
-  } else if (theID == SketchPlugin_Constraint::FLYOUT_VALUE_PNT() && !myFlyoutUpdate) {
-    // Recalculate flyout point in local coordinates of the distance constraint:
-    // the X coordinate is a length of projection of the flyout point on the
-    //                  line binding two distanced points
-    //                  or a line of projection of the distanced point onto the distanced segment
-    // the Y coordinate is a distance from the flyout point to the line
-    std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
-        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-        attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
-    std::shared_ptr<GeomAPI_Pnt2d> aFlyoutPnt = aFlyoutAttr->pnt();
+  std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
+      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+      attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
+  std::shared_ptr<GeomAPI_Pnt2d> aFlyoutPnt = aFlyoutAttr->pnt();
 
-    std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(sketch());
-    std::shared_ptr<GeomDataAPI_Point2D> aPointA = SketcherPrs_Tools::getFeaturePoint(
-        data(), SketchPlugin_Constraint::ENTITY_A(), aPlane);
-    std::shared_ptr<GeomDataAPI_Point2D> aPointB = SketcherPrs_Tools::getFeaturePoint(
-        data(), SketchPlugin_Constraint::ENTITY_B(), aPlane);
-
-    std::shared_ptr<GeomAPI_XY> aStartPnt = aPointA->pnt()->xy();
-    std::shared_ptr<GeomAPI_XY> aEndPnt = aPointB->pnt()->xy();
-    if (aEndPnt->distance(aStartPnt) < tolerance)
-      return;
+  std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(sketch());
+  std::shared_ptr<GeomDataAPI_Point2D> aEndPoint = SketcherPrs_Tools::getFeaturePoint(
+      data(), SketchPlugin_Constraint::ENTITY_B(), aPlane);
 
-    myFlyoutUpdate = true;
-    std::shared_ptr<GeomAPI_XY> aFlyoutDir = aFlyoutPnt->xy()->decreased(aEndPnt);
-    double X = aFlyoutDir->x(); // Dot on OX axis
-    double Y = aFlyoutDir->y(); // Cross to OX axis
-    aFlyoutAttr->setValue(X, Y);
-    myFlyoutUpdate = false;
-  }
+  std::shared_ptr<GeomAPI_XY> aFlyoutDir = aFlyoutPnt->xy()->decreased(aEndPoint->pnt()->xy());
+  double X = aFlyoutDir->x(); // Dot on OX axis
+  double Y = aFlyoutDir->y(); // Cross to OX axis
+  aFlyoutAttr->setValue(X, Y);
 }
index c5ddc47fe42e7044cf825520d24e77d6ffd16315..689cf57d329946989954c550543ea6eb7f7168be 100644 (file)
@@ -26,7 +26,7 @@
 #define SketchPlugin_ConstraintDistanceHorizontal_H_
 
 #include <SketchPlugin.h>
-#include <SketchPlugin_ConstraintDistance.h>
+#include <SketchPlugin_ConstraintDistanceAlongDir.h>
 
 /** \class SketchPlugin_ConstraintDistanceHorizontal
  *  \ingroup Plugins
@@ -35,7 +35,7 @@
  *  This constraint has three attributes:
  *  SketchPlugin_Constraint::VALUE(), SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B()
  */
-class SketchPlugin_ConstraintDistanceHorizontal : public SketchPlugin_ConstraintDistance
+class SketchPlugin_ConstraintDistanceHorizontal : public SketchPlugin_ConstraintDistanceAlongDir
 {
 public:
   /// Distance constraint kind
@@ -52,33 +52,15 @@ public:
     return MY_KIND;
   }
 
-  /// attribute name of dimension location type
-  inline static const std::string& LOCATION_TYPE_ID()
-  {
-    static const std::string MY_LOCATION_TYPE_ID("LocationType");
-    return MY_LOCATION_TYPE_ID;
-  }
-
-
-  /// \brief Creates a new part document if needed
-  SKETCHPLUGIN_EXPORT virtual void execute();
-
-  /// \brief Request for initialization of data model of the feature: adding all attributes
-  SKETCHPLUGIN_EXPORT virtual void initAttributes();
-
-  /// Returns the AIS preview
-  SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
-
-  /// Called on change of any argument-attribute of this object
-  /// \param theID identifier of changed attribute
-  SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
-
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintDistanceHorizontal();
 
 protected:
   /// Returns the current distance between the feature attributes
   virtual double calculateCurrentDistance();
+
+  /// Update flyout point
+  virtual void updateFlyoutPoint();
 };
 
 #endif
index 8823c3aa06bd25ae252a611e9de489f5d9b7658e..d0dae6161abeed62beb81cd4b83e5434a65e422e 100644 (file)
 #include <SketchPlugin_ConstraintDistanceVertical.h>
 
 #include <SketcherPrs_Tools.h>
-#include <SketcherPrs_Factory.h>
 
-#include <GeomAPI_Dir2d.h>
 #include <GeomAPI_XY.h>
 #include <GeomDataAPI_Point2D.h>
 
-#include <ModelAPI_AttributeDouble.h>
-#include <ModelAPI_AttributeInteger.h>
-#include <ModelAPI_Session.h>
-#include <ModelAPI_Validator.h>
-
-const double tolerance = 1e-7;
-
 
 SketchPlugin_ConstraintDistanceVertical::SketchPlugin_ConstraintDistanceVertical()
-  : SketchPlugin_ConstraintDistance()
+  : SketchPlugin_ConstraintDistanceAlongDir()
 {
 }
 
-//*************************************************************************************
-void SketchPlugin_ConstraintDistanceVertical::initAttributes()
-{
-  data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId());
-  data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId());
-  data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
-  data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId());
-
-  data()->addAttribute(SketchPlugin_ConstraintDistanceVertical::LOCATION_TYPE_ID(),
-                       ModelAPI_AttributeInteger::typeId());
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), LOCATION_TYPE_ID());
-}
-
-//*************************************************************************************
-void SketchPlugin_ConstraintDistanceVertical::execute()
-{
-  AttributeDoublePtr anAttrValue = real(SketchPlugin_Constraint::VALUE());
-  if (anAttrValue->isInitialized() || !areAttributesInitialized())
-    return;
-
-  double aDistance = calculateCurrentDistance();
-  anAttrValue->setValue(aDistance);
-}
-
-//*************************************************************************************
-AISObjectPtr SketchPlugin_ConstraintDistanceVertical::getAISObject(AISObjectPtr thePrevious)
-{
-  if (!sketch())
-    return thePrevious;
-
-  AISObjectPtr anAIS = SketcherPrs_Factory::lengthDimensionConstraint(this,
-                                                                      sketch()->coordinatePlane(),
-                                                                      thePrevious);
-  return anAIS;
-}
-
 double SketchPlugin_ConstraintDistanceVertical::calculateCurrentDistance()
 {
   std::shared_ptr<ModelAPI_Data> aData = data();
@@ -92,45 +47,19 @@ double SketchPlugin_ConstraintDistanceVertical::calculateCurrentDistance()
   return aPointB->y() - aPointA->y();
 }
 
-void SketchPlugin_ConstraintDistanceVertical::attributeChanged(const std::string& theID)
+void SketchPlugin_ConstraintDistanceVertical::updateFlyoutPoint()
 {
-  if (theID == SketchPlugin_Constraint::ENTITY_A() ||
-      theID == SketchPlugin_Constraint::ENTITY_B())
-  {
-    AttributeDoublePtr aValueAttr = real(SketchPlugin_Constraint::VALUE());
-    if (!aValueAttr->isInitialized() && areAttributesInitialized()) {
-      // only if it is not initialized, try to compute the current value
-      double aDistance = calculateCurrentDistance();
-      aValueAttr->setValue(aDistance);
-    }
-  } else if (theID == SketchPlugin_Constraint::FLYOUT_VALUE_PNT() && !myFlyoutUpdate) {
-    // Recalculate flyout point in local coordinates of the distance constraint:
-    // the X coordinate is a length of projection of the flyout point on the
-    //                  line binding two distanced points
-    //                  or a line of projection of the distanced point onto the distanced segment
-    // the Y coordinate is a distance from the flyout point to the line
-    std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
-        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-        attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
-    std::shared_ptr<GeomAPI_Pnt2d> aFlyoutPnt = aFlyoutAttr->pnt();
-
-    std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(sketch());
-    std::shared_ptr<GeomDataAPI_Point2D> aPointA = SketcherPrs_Tools::getFeaturePoint(
-        data(), SketchPlugin_Constraint::ENTITY_A(), aPlane);
-    std::shared_ptr<GeomDataAPI_Point2D> aPointB = SketcherPrs_Tools::getFeaturePoint(
-        data(), SketchPlugin_Constraint::ENTITY_B(), aPlane);
+  std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
+      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+      attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
+  std::shared_ptr<GeomAPI_Pnt2d> aFlyoutPnt = aFlyoutAttr->pnt();
 
-    std::shared_ptr<GeomAPI_XY> aStartPnt = aPointA->pnt()->xy();
-    std::shared_ptr<GeomAPI_XY> aEndPnt = aPointB->pnt()->xy();
-
-    if (aEndPnt->distance(aStartPnt) < tolerance)
-      return;
+  std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(sketch());
+  std::shared_ptr<GeomDataAPI_Point2D> aEndPoint = SketcherPrs_Tools::getFeaturePoint(
+      data(), SketchPlugin_Constraint::ENTITY_B(), aPlane);
 
-    std::shared_ptr<GeomAPI_XY> aFlyoutDir = aFlyoutPnt->xy()->decreased(aEndPnt);
-    myFlyoutUpdate = true;
-    double X =  aFlyoutDir->y(); // Dot on OY axis
-    double Y = -aFlyoutDir->x(); // Cross to OY axis
-    aFlyoutAttr->setValue(X, Y);
-    myFlyoutUpdate = false;
-  }
+  std::shared_ptr<GeomAPI_XY> aFlyoutDir = aFlyoutPnt->xy()->decreased(aEndPoint->pnt()->xy());
+  double X =  aFlyoutDir->y(); // Dot on OY axis
+  double Y = -aFlyoutDir->x(); // Cross to OY axis
+  aFlyoutAttr->setValue(X, Y);
 }
index 1bfb6f144dfae47fb61b3be19ba6de6981597d7d..a9d7284b95c409e29c3883a5f217c5bd67ae9368 100644 (file)
@@ -26,7 +26,7 @@
 #define SketchPlugin_ConstraintDistanceVertical_H_
 
 #include <SketchPlugin.h>
-#include <SketchPlugin_ConstraintDistance.h>
+#include <SketchPlugin_ConstraintDistanceAlongDir.h>
 
 /** \class SketchPlugin_ConstraintDistanceVertical
  *  \ingroup Plugins
@@ -35,7 +35,7 @@
  *  This constraint has three attributes:
  *  SketchPlugin_Constraint::VALUE(), SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B()
  */
-class SketchPlugin_ConstraintDistanceVertical : public SketchPlugin_ConstraintDistance
+class SketchPlugin_ConstraintDistanceVertical : public SketchPlugin_ConstraintDistanceAlongDir
 {
 public:
   /// Distance constraint kind
@@ -52,32 +52,15 @@ public:
     return MY_KIND;
   }
 
-  /// attribute name of dimension location type
-  inline static const std::string& LOCATION_TYPE_ID()
-  {
-    static const std::string MY_LOCATION_TYPE_ID("LocationType");
-    return MY_LOCATION_TYPE_ID;
-  }
-
-  /// \brief Creates a new part document if needed
-  SKETCHPLUGIN_EXPORT virtual void execute();
-
-  /// \brief Request for initialization of data model of the feature: adding all attributes
-  SKETCHPLUGIN_EXPORT virtual void initAttributes();
-
-  /// Returns the AIS preview
-  SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
-
-  /// Called on change of any argument-attribute of this object
-  /// \param theID identifier of changed attribute
-  SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
-
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintDistanceVertical();
 
 protected:
   /// Returns the current distance between the feature attributes
   virtual double calculateCurrentDistance();
+
+  /// Update flyout point
+  virtual void updateFlyoutPoint();
 };
 
 #endif
index 35ab1496c62a7d35459e590568951f54a7431421..a38089083b344ab3de2abc200841e464764bc1ba 100644 (file)
@@ -45,6 +45,8 @@ model.do()
 
 # changing the parameter
 for param in range(-30, 31, 2):
+    if param == 0:
+        continue
     DistanceParam.setValue(param)
     model.do()
     dist = secondPoint.x() - firstPoint.x()
@@ -66,6 +68,8 @@ model.do()
 
 # changing the parameter
 for param in range(-30, 31, 2):
+    if param == 0:
+        continue
     DistanceParam.setValue(param)
     model.do()
     dist = secondPoint.y() - firstPoint.y()
index 24278747112d3c0b53efa128acf1c87452511983..29cfb568025fcc4482f30f47de0d864e47ccf611 100644 (file)
@@ -125,7 +125,10 @@ while d >= -30.:
     DISTANCE1 = d
     aDistance.setValue(DISTANCE1)
     aSession.finishOperation()
-    assert math.fabs(horizontalDistance(aPoint1Coords, aPoint2Coords) - DISTANCE1) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(aPoint1Coords, aPoint2Coords), DISTANCE1)
+    if DISTANCE1 == 0:
+        assert(aHDist1.error() != "")
+    else:
+        assert math.fabs(horizontalDistance(aPoint1Coords, aPoint2Coords) - DISTANCE1) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(aPoint1Coords, aPoint2Coords), DISTANCE1)
     d += dStep
 assert (model.dof(aSketchFeature) == 3)
 
@@ -158,9 +161,12 @@ while d >= -50.:
     DISTANCE2 = d
     aDistance.setValue(DISTANCE2)
     aSession.finishOperation()
-    assert math.fabs(horizontalDistance(anExtCoords, aPoint1Coords) - DISTANCE2) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(anExtCoords, aPoint1Coords), DISTANCE2)
-    assert math.fabs(aPoint1Coords.x() - DISTANCE2) < 1.e-5, "Wrong point coordinates ({}, {}), expected x = {}".format(aPoint1Coords.x(), aPoint1Coords.y(), DISTANCE2)
-    assert math.fabs(horizontalDistance(aPoint1Coords, aPoint2Coords) - DISTANCE1) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(aPoint1Coords, aPoint2Coords), DISTANCE1)
+    if DISTANCE2 == 0:
+        assert(aHDist2.error() != "")
+    else:
+        assert math.fabs(horizontalDistance(anExtCoords, aPoint1Coords) - DISTANCE2) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(anExtCoords, aPoint1Coords), DISTANCE2)
+        assert math.fabs(aPoint1Coords.x() - DISTANCE2) < 1.e-5, "Wrong point coordinates ({}, {}), expected x = {}".format(aPoint1Coords.x(), aPoint1Coords.y(), DISTANCE2)
+        assert math.fabs(horizontalDistance(aPoint1Coords, aPoint2Coords) - DISTANCE1) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(aPoint1Coords, aPoint2Coords), DISTANCE1)
     d += dStep
 assert (model.dof(aSketchFeature) == 2)
 
@@ -217,7 +223,10 @@ while d >= -50.:
     DISTANCE3 = d
     aDistance.setValue(DISTANCE3)
     aSession.finishOperation()
-    assert math.fabs(horizontalDistance(aStartPoint, aEndPoint) - DISTANCE3) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(aStartPoint, aEndPoint), DISTANCE3)
+    if DISTANCE3 == 0:
+        assert(aHDist3.error() != "")
+    else:
+        assert math.fabs(horizontalDistance(aStartPoint, aEndPoint) - DISTANCE3) < 1.e-5, "Distance values are different: {0} != {1}".format(horizontalDistance(aStartPoint, aEndPoint), DISTANCE3)
     d += dStep
 assert (model.dof(aSketchFeature) == 6)
 
index 8910edcbfd5613e5da8b4e631d3d12ab6d63b393..5045080d35512ed3ce1f7206e8a4c5776857979b 100644 (file)
@@ -125,7 +125,10 @@ while d >= -30.:
     DISTANCE1 = d
     aDistance.setValue(DISTANCE1)
     aSession.finishOperation()
-    assert math.fabs(verticalDistance(aPoint1Coords, aPoint2Coords) - DISTANCE1) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(aPoint1Coords, aPoint2Coords), DISTANCE1)
+    if DISTANCE1 == 0:
+        assert(aVDist1.error() != "")
+    else:
+        assert math.fabs(verticalDistance(aPoint1Coords, aPoint2Coords) - DISTANCE1) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(aPoint1Coords, aPoint2Coords), DISTANCE1)
     d += dStep
 assert (model.dof(aSketchFeature) == 3)
 
@@ -158,9 +161,12 @@ while d >= -50.:
     DISTANCE2 = d
     aDistance.setValue(DISTANCE2)
     aSession.finishOperation()
-    assert math.fabs(verticalDistance(anExtCoords, aPoint1Coords) - DISTANCE2) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(anExtCoords, aPoint1Coords), DISTANCE2)
-    assert math.fabs(aPoint1Coords.y() - DISTANCE2) < 1.e-5, "Wrong point coordinates ({}, {}), expected y = {}".format(aPoint1Coords.x(), aPoint1Coords.y(), DISTANCE2)
-    assert math.fabs(verticalDistance(aPoint1Coords, aPoint2Coords) - DISTANCE1) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(aPoint1Coords, aPoint2Coords), DISTANCE1)
+    if DISTANCE2 == 0:
+        assert(aVDist2.error() != "")
+    else:
+        assert math.fabs(verticalDistance(anExtCoords, aPoint1Coords) - DISTANCE2) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(anExtCoords, aPoint1Coords), DISTANCE2)
+        assert math.fabs(aPoint1Coords.y() - DISTANCE2) < 1.e-5, "Wrong point coordinates ({}, {}), expected y = {}".format(aPoint1Coords.x(), aPoint1Coords.y(), DISTANCE2)
+        assert math.fabs(verticalDistance(aPoint1Coords, aPoint2Coords) - DISTANCE1) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(aPoint1Coords, aPoint2Coords), DISTANCE1)
     d += dStep
 assert (model.dof(aSketchFeature) == 2)
 
@@ -217,7 +223,10 @@ while d >= -50.:
     DISTANCE3 = d
     aDistance.setValue(DISTANCE3)
     aSession.finishOperation()
-    assert math.fabs(verticalDistance(aStartPoint, aEndPoint) - DISTANCE3) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(aStartPoint, aEndPoint), DISTANCE3)
+    if DISTANCE3 == 0:
+        assert(aVDist3.error() != "")
+    else:
+        assert math.fabs(verticalDistance(aStartPoint, aEndPoint) - DISTANCE3) < 1.e-5, "Distance values are different: {0} != {1}".format(verticalDistance(aStartPoint, aEndPoint), DISTANCE3)
     d += dStep
 assert (model.dof(aSketchFeature) == 6)
 
index 2c004c890d6a739d59cd72bd238a6decb7bb5c0d..4372af6457090572f69c3a43ff15a0bcebfb897c 100644 (file)
@@ -703,7 +703,9 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
         </sketch_shape_selector>
         <sketch-2dpoint_flyout_selector id="ConstraintFlyoutValuePnt"  default="computed" internal="1" obligatory="0"/>
 
-        <doublevalue_editor label="Value" tooltip="Distance" id="ConstraintValue" default="computed"/>
+        <doublevalue_editor label="Value" tooltip="Distance" id="DistanceValue" default="computed" min="0">
+          <validator id="GeomValidators_Positive"/>
+        </doublevalue_editor>
 
         <module_choice id="LocationType"
           widget_type="radiobuttons"
@@ -745,7 +747,9 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
         </sketch_shape_selector>
         <sketch-2dpoint_flyout_selector id="ConstraintFlyoutValuePnt"  default="computed" internal="1" obligatory="0"/>
 
-        <doublevalue_editor label="Value" tooltip="Distance" id="ConstraintValue" default="computed"/>
+        <doublevalue_editor label="Value" tooltip="Distance" id="DistanceValue" default="computed" min="0">
+          <validator id="GeomValidators_Positive"/>
+        </doublevalue_editor>
 
         <module_choice id="LocationType"
           widget_type="radiobuttons"
index cee80b8b9b29ca6ad1c5abf0738c51feaf654e7d..5f9b54cff59faad8698f26c9d2715c414c016ef8 100644 (file)
@@ -158,7 +158,12 @@ void SketcherPrs_LengthDimension::Compute(
     myPlane = gp_Pln(mySketcherPlane->impl<gp_Ax3>());
 
     DataPtr aData = myConstraint->data();
-    AttributeDoublePtr anAttributeValue = aData->real(SketchPlugin_Constraint::VALUE());
+    AttributeDoublePtr anAttributeValue;
+    if (myConstraint->getKind() == SketchPlugin_ConstraintDistanceHorizontal::ID() ||
+        myConstraint->getKind() == SketchPlugin_ConstraintDistanceVertical::ID())
+      anAttributeValue = aData->real(SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID());
+    else
+      anAttributeValue = aData->real(SketchPlugin_Constraint::VALUE());
     myValue.init(anAttributeValue);
   }