SketchPlugin_ConstraintCoincidence.h
SketchPlugin_ConstraintCollinear.h
SketchPlugin_ConstraintDistance.h
+ SketchPlugin_ConstraintDistanceAlongDir.h
SketchPlugin_ConstraintDistanceHorizontal.h
SketchPlugin_ConstraintDistanceVertical.h
SketchPlugin_ConstraintEqual.h
SketchPlugin_ConstraintCoincidence.cpp
SketchPlugin_ConstraintCollinear.cpp
SketchPlugin_ConstraintDistance.cpp
+ SketchPlugin_ConstraintDistanceAlongDir.cpp
SketchPlugin_ConstraintDistanceHorizontal.cpp
SketchPlugin_ConstraintDistanceVertical.cpp
SketchPlugin_ConstraintEqual.cpp
--- /dev/null
+// 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;
+ }
+}
--- /dev/null
+// 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
#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()
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);
}
#define SketchPlugin_ConstraintDistanceHorizontal_H_
#include <SketchPlugin.h>
-#include <SketchPlugin_ConstraintDistance.h>
+#include <SketchPlugin_ConstraintDistanceAlongDir.h>
/** \class SketchPlugin_ConstraintDistanceHorizontal
* \ingroup Plugins
* 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
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
#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();
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);
}
#define SketchPlugin_ConstraintDistanceVertical_H_
#include <SketchPlugin.h>
-#include <SketchPlugin_ConstraintDistance.h>
+#include <SketchPlugin_ConstraintDistanceAlongDir.h>
/** \class SketchPlugin_ConstraintDistanceVertical
* \ingroup Plugins
* 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
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
# changing the parameter
for param in range(-30, 31, 2):
+ if param == 0:
+ continue
DistanceParam.setValue(param)
model.do()
dist = secondPoint.x() - firstPoint.x()
# changing the parameter
for param in range(-30, 31, 2):
+ if param == 0:
+ continue
DistanceParam.setValue(param)
model.do()
dist = secondPoint.y() - firstPoint.y()
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)
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)
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)
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)
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)
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)
</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"
</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"
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);
}