From d7c6776ecbb30ac907b2e8e5b1ef466601638d19 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 20 Jun 2014 19:04:35 +0400 Subject: [PATCH] refs #80 - Sketch base GUI: create/draw point, circle and arc 1. Move the constraint presentation creation to the feature prs class 2. Create distance/radius presentation classes. --- src/PartSet/CMakeLists.txt | 4 + src/PartSet/PartSet_Constants.h | 2 + src/PartSet/PartSet_FeatureDistancePrs.cpp | 137 +++++++++++++++++ src/PartSet/PartSet_FeatureDistancePrs.h | 80 ++++++++++ src/PartSet/PartSet_FeatureLengthPrs.cpp | 140 ++++++++++++++--- src/PartSet/PartSet_FeatureLengthPrs.h | 20 ++- src/PartSet/PartSet_FeatureRadiusPrs.cpp | 143 ++++++++++++++++++ src/PartSet/PartSet_FeatureRadiusPrs.h | 80 ++++++++++ .../PartSet_OperationCreateConstraint.cpp | 13 +- src/PartSet/PartSet_Presentation.cpp | 115 ++------------ src/PartSet/PartSet_Presentation.h | 25 +-- src/PartSet/PartSet_Tools.cpp | 9 ++ .../SketchPlugin_ConstraintDistance.cpp | 1 + .../SketchPlugin_ConstraintRadius.cpp | 4 + .../SketchPlugin_ConstraintRadius.h | 3 + src/SketchPlugin/plugin-Sketch.xml | 10 +- src/SketchSolver/SketchSolver_Constraint.cpp | 2 +- 17 files changed, 636 insertions(+), 152 deletions(-) create mode 100644 src/PartSet/PartSet_FeatureDistancePrs.cpp create mode 100644 src/PartSet/PartSet_FeatureDistancePrs.h create mode 100644 src/PartSet/PartSet_FeatureRadiusPrs.cpp create mode 100644 src/PartSet/PartSet_FeatureRadiusPrs.h diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 800a4d593..37822dd00 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -8,10 +8,12 @@ SET(PROJECT_HEADERS PartSet_EditLine.h PartSet_FeatureArcPrs.h PartSet_FeatureCirclePrs.h + PartSet_FeatureDistancePrs.h PartSet_FeaturePrs.h PartSet_FeatureLengthPrs.h PartSet_FeatureLinePrs.h PartSet_FeaturePointPrs.h + PartSet_FeatureRadiusPrs.h PartSet_Listener.h PartSet_Module.h PartSet_OperationCreateConstraint.h @@ -30,9 +32,11 @@ SET(PROJECT_SOURCES PartSet_FeaturePrs.cpp PartSet_FeatureArcPrs.cpp PartSet_FeatureCirclePrs.cpp + PartSet_FeatureDistancePrs.cpp PartSet_FeatureLengthPrs.cpp PartSet_FeatureLinePrs.cpp PartSet_FeaturePointPrs.cpp + PartSet_FeatureRadiusPrs.cpp PartSet_Listener.cpp PartSet_Module.cpp PartSet_OperationCreateConstraint.cpp diff --git a/src/PartSet/PartSet_Constants.h b/src/PartSet/PartSet_Constants.h index 141e25bde..fd1fb9725 100644 --- a/src/PartSet/PartSet_Constants.h +++ b/src/PartSet/PartSet_Constants.h @@ -18,5 +18,7 @@ enum PartSet_SelectionMode SM_DonePoint }; +const int CONSTRAINT_TEXT_HEIGHT = 28; /// the text height of the constraint +const int CONSTRAINT_TEXT_SELECTION_TOLERANCE = 20; /// the text selection tolerance #endif diff --git a/src/PartSet/PartSet_FeatureDistancePrs.cpp b/src/PartSet/PartSet_FeatureDistancePrs.cpp new file mode 100644 index 000000000..e3e903a89 --- /dev/null +++ b/src/PartSet/PartSet_FeatureDistancePrs.cpp @@ -0,0 +1,137 @@ +// File: PartSet_FeaturePrs.h +// Created: 16 Jun 2014 +// Author: Natalia ERMOLAEVA + +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +using namespace std; + +PartSet_FeatureDistancePrs::PartSet_FeatureDistancePrs(FeaturePtr theSketch) +: PartSet_FeaturePrs(theSketch) +{ +} + +std::string PartSet_FeatureDistancePrs::getKind() +{ + return SKETCH_CONSTRAINT_DISTANCE_KIND; +} + +bool PartSet_FeatureDistancePrs::setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode) +{ + bool aResult = false; + if (feature() && theFeature && theFeature->getKind() == SKETCH_LINE_KIND && theMode == SM_FirstPoint) + { + // set length feature + boost::shared_ptr aData = feature()->data(); + boost::shared_ptr aRef = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + aRef->setFeature(theFeature); + + // set length value + aData = theFeature->data(); + boost::shared_ptr aPoint1 = + boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); + boost::shared_ptr aPoint2 = + boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); + + double aLenght = aPoint1->pnt()->distance(aPoint2->pnt()); + PartSet_Tools::setFeatureValue(feature(), aLenght, CONSTRAINT_ATTR_VALUE); + aResult = true; + } + return aResult; +} + +PartSet_SelectionMode PartSet_FeatureDistancePrs::setPoint(double theX, double theY, + const PartSet_SelectionMode& theMode) +{ + PartSet_SelectionMode aMode = theMode; + switch (theMode) + { + case SM_SecondPoint: { + boost::shared_ptr aData = feature()->data(); + boost::shared_ptr anAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + FeaturePtr aFeature; + if (anAttr) { + aFeature = anAttr->feature(); + if (aFeature->getKind() != SKETCH_LINE_KIND) { + aFeature = FeaturePtr(); + } + } + boost::shared_ptr aPoint = boost::shared_ptr + (new GeomAPI_Pnt2d(theX, theY)); + boost::shared_ptr aFeatureLin = PartSet_FeatureLinePrs::createLin2d(aFeature); + boost::shared_ptr aResult = aFeatureLin->project(aPoint); + double aDistance = aPoint->distance(aResult); + + double aStartX, aStartY; + PartSet_FeatureLinePrs::getLinePoint(aFeature, LINE_ATTR_START, aStartX, aStartY); + + if (!aFeatureLin->isRight(aPoint)) + aDistance = -aDistance; + + AttributeDoublePtr aFlyoutAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE)); + aFlyoutAttr->setValue(aDistance); + + aMode = SM_DonePoint; + } + break; + default: + break; + } + return aMode; +} + +std::string PartSet_FeatureDistancePrs::getAttribute(const PartSet_SelectionMode& theMode) const +{ + return ""; +} + +PartSet_SelectionMode PartSet_FeatureDistancePrs::getNextMode(const std::string& theAttribute) const +{ + return SM_FirstPoint; +} + +void PartSet_FeatureDistancePrs::move(double theDeltaX, double theDeltaY) +{ +} + +double PartSet_FeatureDistancePrs::distanceToPoint(FeaturePtr theFeature, + double theX, double theY) +{ + return 0; +} + +boost::shared_ptr PartSet_FeatureDistancePrs::findPoint(FeaturePtr theFeature, + double theX, double theY) +{ + boost::shared_ptr aPoint2D; + return aPoint2D; +} + +boost::shared_ptr PartSet_FeatureDistancePrs::featurePoint + (const PartSet_SelectionMode& theMode) +{ + return boost::shared_ptr(); +} diff --git a/src/PartSet/PartSet_FeatureDistancePrs.h b/src/PartSet/PartSet_FeatureDistancePrs.h new file mode 100644 index 000000000..4f7282969 --- /dev/null +++ b/src/PartSet/PartSet_FeatureDistancePrs.h @@ -0,0 +1,80 @@ +// File: PartSet_FeatureDistancePrs.h +// Created: 16 Jun 2014 +// Author: Natalia ERMOLAEVA + +#ifndef PartSet_FeatureDistancePrs_H +#define PartSet_FeatureDistancePrs_H + +#include "PartSet.h" + +#include "PartSet_FeaturePrs.h" +#include "PartSet_Constants.h" + +class GeomDataAPI_Point2D; + +/*! + \class PartSet_FeatureDistancePrs + * \brief The class to define the circle feature manipulation. It is created for + * the feature create operation to move out the feature properties set and use one operation + * for any type of features. +*/ +class PARTSET_EXPORT PartSet_FeatureDistancePrs : public PartSet_FeaturePrs +{ +public: + /// Returns the feature type processed by this presentation + /// \return the feature kind + static std::string getKind(); + + /// Constructor + /// \param theSketch the sketch feature + PartSet_FeatureDistancePrs(FeaturePtr theSketch); + /// Destructor + virtual ~PartSet_FeatureDistancePrs() {}; + + /// Sets the feature to to a feature attribute depending on the selection mode + /// \param theFeature a feature instance + /// \param theMode the selection mode + /// \return whether the feature is set + virtual bool setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode); + + /// Sets the point to the feature in an attribute depending on the selection mode + /// \param theX the 2D point horizontal coordinate + /// \param theY the 2D point vertical coordinate + /// \param theMode the selection mode + /// \return the new selection mode + virtual PartSet_SelectionMode setPoint(double theX, double theY, + const PartSet_SelectionMode& theMode); + + /// Returns the feature attribute name for the selection mode + /// \param theMode the current operation selection mode. The feature attribute depends on the mode + virtual std::string getAttribute(const PartSet_SelectionMode& theMode) const; + + /// Returns the next selection mode after the attribute + /// \param theAttribute the feature attribute name + /// \return next attribute selection mode + virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const; + + /// \brief Move the full feature. + /// \param theDeltaX the delta for X coordinate is moved + /// \param theDeltaY the delta for Y coordinate is moved + virtual void move(double theDeltaX, double theDeltaY); + + /// Return the distance between the feature and the point + /// \param theFeature feature object + /// \param theX the horizontal coordinate of the point + /// \param theX the vertical coordinate of the point + virtual double distanceToPoint(FeaturePtr theFeature, double theX, double theY); + + /// Find a point in the line with given coordinates + /// \param theFeature the line feature + /// \param theX the horizontal point coordinate + /// \param theY the vertical point coordinate + virtual boost::shared_ptr findPoint(FeaturePtr theFeature, double theX, + double theY); +protected: + /// Returns the feature point in the selection mode position. + /// \param theMode the current operation selection mode. The feature attribute depends on the mode + virtual boost::shared_ptr featurePoint(const PartSet_SelectionMode& theMode); +}; + +#endif diff --git a/src/PartSet/PartSet_FeatureLengthPrs.cpp b/src/PartSet/PartSet_FeatureLengthPrs.cpp index 26b4bee77..bd4bdd8c6 100644 --- a/src/PartSet/PartSet_FeatureLengthPrs.cpp +++ b/src/PartSet/PartSet_FeatureLengthPrs.cpp @@ -4,6 +4,7 @@ #include #include +#include #include @@ -12,16 +13,23 @@ #include #include +#include #include +#include #include #include +#include +#include + #include #include #include #include #include +#include +#include #include using namespace std; @@ -36,6 +44,31 @@ std::string PartSet_FeatureLengthPrs::getKind() return SKETCH_CONSTRAINT_LENGTH_KIND; } +bool PartSet_FeatureLengthPrs::setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode) +{ + bool aResult = false; + if (feature() && theFeature && theFeature->getKind() == SKETCH_LINE_KIND && theMode == SM_FirstPoint) + { + // set length feature + boost::shared_ptr aData = feature()->data(); + boost::shared_ptr aRef = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + aRef->setFeature(theFeature); + + // set length value + aData = theFeature->data(); + boost::shared_ptr aPoint1 = + boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); + boost::shared_ptr aPoint2 = + boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); + + double aLenght = aPoint1->pnt()->distance(aPoint2->pnt()); + PartSet_Tools::setFeatureValue(feature(), aLenght, CONSTRAINT_ATTR_VALUE); + aResult = true; + } + return aResult; +} + PartSet_SelectionMode PartSet_FeatureLengthPrs::setPoint(double theX, double theY, const PartSet_SelectionMode& theMode) { @@ -78,6 +111,88 @@ PartSet_SelectionMode PartSet_FeatureLengthPrs::setPoint(double theX, double the return aMode; } +Handle(AIS_InteractiveObject) PartSet_FeatureLengthPrs::createPresentation(FeaturePtr theFeature, + FeaturePtr theSketch, + Handle(AIS_InteractiveObject) thePreviuos) +{ + if (!theFeature || !theSketch) + return thePreviuos; + + boost::shared_ptr aData = theSketch->data(); + boost::shared_ptr anOrigin = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); + boost::shared_ptr aNormal = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_NORM)); + gp_Pln aPlane(aNormal->x(), aNormal->y(), aNormal->z(), 0/*D*/); + + aData = theFeature->data(); + boost::shared_ptr anAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + if (!anAttr) + return thePreviuos; + FeaturePtr aFeature = anAttr->feature(); + if (!aFeature || aFeature->getKind() != SKETCH_LINE_KIND) + return thePreviuos; + + boost::shared_ptr aFlyoutAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE)); + double aFlyout = aFlyoutAttr->value(); + + aData = aFeature->data(); + if (!aData->isValid()) + return thePreviuos; + + boost::shared_ptr aPointStart = + boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); + boost::shared_ptr aPointEnd = + boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); + + gp_Pnt aPoint1, aPoint2; + PartSet_Tools::convertTo3D(aPointStart->x(), aPointStart->y(), theSketch, aPoint1); + PartSet_Tools::convertTo3D(aPointEnd->x(), aPointEnd->y(), theSketch, aPoint2); + + //Build dimension here + gp_Pnt aP1 = aPoint1; + gp_Pnt aP2 = aPoint2; + if (aFlyout < 0) { + aP1 = aPoint2; + aP2 = aPoint1; + } + + Handle(AIS_InteractiveObject) anAIS = thePreviuos; + if (anAIS.IsNull()) + { + Handle(AIS_LengthDimension) aDimAIS = new AIS_LengthDimension (aP1, aP2, aPlane); + + Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect(); + anAspect->MakeArrows3d (Standard_False); + anAspect->MakeText3d(false/*is text 3d*/); + anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT); + anAspect->MakeTextShaded(false/*is test shaded*/); + aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false/*is units displayed*/); + /*if (isUnitsDisplayed) + { + aDimAIS->SetDisplayUnits (aDimDlg->GetUnits ()); + }*/ + aDimAIS->SetDimensionAspect (anAspect); + aDimAIS->SetFlyout(aFlyout); + aDimAIS->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE); + + anAIS = aDimAIS; + } + else { + // update presentation + Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS); + if (!aDimAIS.IsNull()) { + aDimAIS->SetMeasuredGeometry(aPoint1, aPoint2, aPlane); + aDimAIS->SetFlyout(aFlyout); + + aDimAIS->Redisplay(Standard_True); + } + } + return anAIS; +} + std::string PartSet_FeatureLengthPrs::getAttribute(const PartSet_SelectionMode& theMode) const { return ""; @@ -110,28 +225,3 @@ boost::shared_ptr PartSet_FeatureLengthPrs::featurePoint { return boost::shared_ptr(); } - -bool PartSet_FeatureLengthPrs::setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode) -{ - bool aResult = false; - if (feature() && theFeature && theFeature->getKind() == SKETCH_LINE_KIND && theMode == SM_FirstPoint) - { - // set length feature - boost::shared_ptr aData = feature()->data(); - boost::shared_ptr aRef = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); - aRef->setFeature(theFeature); - - // set length value - aData = theFeature->data(); - boost::shared_ptr aPoint1 = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); - boost::shared_ptr aPoint2 = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); - - double aLenght = aPoint1->pnt()->distance(aPoint2->pnt()); - PartSet_Tools::setFeatureValue(feature(), aLenght, CONSTRAINT_ATTR_VALUE); - aResult = true; - } - return aResult; -} diff --git a/src/PartSet/PartSet_FeatureLengthPrs.h b/src/PartSet/PartSet_FeatureLengthPrs.h index 1bd7f8c1f..90b1edd4a 100644 --- a/src/PartSet/PartSet_FeatureLengthPrs.h +++ b/src/PartSet/PartSet_FeatureLengthPrs.h @@ -11,6 +11,7 @@ #include "PartSet_Constants.h" class GeomDataAPI_Point2D; +class Handle_AIS_InteractiveObject; /*! \class PartSet_FeatureLengthPrs @@ -31,6 +32,12 @@ public: /// Destructor virtual ~PartSet_FeatureLengthPrs() {}; + /// Sets the feature to to a feature attribute depending on the selection mode + /// \param theFeature a feature instance + /// \param theMode the selection mode + /// \return whether the feature is set + virtual bool setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode); + /// Sets the point to the feature in an attribute depending on the selection mode /// \param theX the 2D point horizontal coordinate /// \param theY the 2D point vertical coordinate @@ -39,11 +46,14 @@ public: virtual PartSet_SelectionMode setPoint(double theX, double theY, const PartSet_SelectionMode& theMode); - /// Sets the feature to to a feature attribute depending on the selection mode - /// \param theFeature a feature instance - /// \param theMode the selection mode - /// \return whether the feature is set - virtual bool setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode); + /// Creates an AIS presentation if the previous is null or update the given one + /// \param theFeature a feature + /// \param theSketch a feature sketch + /// \param thePrevious a previuos AIS presentation + /// \return a created/changed AIS object with the feature parameters + static Handle_AIS_InteractiveObject createPresentation(FeaturePtr theFeature, + FeaturePtr theSketch, + Handle_AIS_InteractiveObject thePreviuos); /// Returns the feature attribute name for the selection mode /// \param theMode the current operation selection mode. The feature attribute depends on the mode diff --git a/src/PartSet/PartSet_FeatureRadiusPrs.cpp b/src/PartSet/PartSet_FeatureRadiusPrs.cpp new file mode 100644 index 000000000..0c6567956 --- /dev/null +++ b/src/PartSet/PartSet_FeatureRadiusPrs.cpp @@ -0,0 +1,143 @@ +// File: PartSet_FeaturePrs.h +// Created: 16 Jun 2014 +// Author: Natalia ERMOLAEVA + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +using namespace std; + +PartSet_FeatureRadiusPrs::PartSet_FeatureRadiusPrs(FeaturePtr theSketch) +: PartSet_FeaturePrs(theSketch) +{ +} + +std::string PartSet_FeatureRadiusPrs::getKind() +{ + return SKETCH_CONSTRAINT_RADIUS_KIND; +} + +bool PartSet_FeatureRadiusPrs::setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode) +{ + bool aResult = false; + if (feature() && theMode == SM_FirstPoint && + (theFeature && theFeature->getKind() == SKETCH_CIRCLE_KIND || + theFeature && theFeature->getKind() == SKETCH_ARC_KIND)) { + // set length feature + boost::shared_ptr aData = feature()->data(); + boost::shared_ptr aRef = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + aRef->setFeature(theFeature); + + // set length value + /*aData = theFeature->data(); + boost::shared_ptr aPoint1 = + boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); + boost::shared_ptr aPoint2 = + boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); + + double aLenght = aPoint1->pnt()->distance(aPoint2->pnt()); + */ + double aLenght = 50; + PartSet_Tools::setFeatureValue(feature(), aLenght, CONSTRAINT_ATTR_VALUE); + aResult = true; + } + return aResult; +} + +PartSet_SelectionMode PartSet_FeatureRadiusPrs::setPoint(double theX, double theY, + const PartSet_SelectionMode& theMode) +{ + PartSet_SelectionMode aMode = theMode; + switch (theMode) + { + case SM_SecondPoint: { + boost::shared_ptr aData = feature()->data(); + /*boost::shared_ptr anAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + FeaturePtr aFeature; + if (anAttr) { + aFeature = anAttr->feature(); + if (aFeature->getKind() != SKETCH_LINE_KIND) { + aFeature = FeaturePtr(); + } + } + boost::shared_ptr aPoint = boost::shared_ptr + (new GeomAPI_Pnt2d(theX, theY)); + boost::shared_ptr aFeatureLin = PartSet_FeatureLinePrs::createLin2d(aFeature); + boost::shared_ptr aResult = aFeatureLin->project(aPoint); + double aDistance = aPoint->distance(aResult); + + double aStartX, aStartY; + PartSet_FeatureLinePrs::getLinePoint(aFeature, LINE_ATTR_START, aStartX, aStartY); + + if (!aFeatureLin->isRight(aPoint)) + aDistance = -aDistance; + */ + double aDistance = 40; + AttributeDoublePtr aFlyoutAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE)); + aFlyoutAttr->setValue(aDistance); + + aMode = SM_DonePoint; + } + break; + default: + break; + } + return aMode; +} + +std::string PartSet_FeatureRadiusPrs::getAttribute(const PartSet_SelectionMode& theMode) const +{ + return ""; +} + +PartSet_SelectionMode PartSet_FeatureRadiusPrs::getNextMode(const std::string& theAttribute) const +{ + return SM_FirstPoint; +} + +void PartSet_FeatureRadiusPrs::move(double theDeltaX, double theDeltaY) +{ +} + +double PartSet_FeatureRadiusPrs::distanceToPoint(FeaturePtr theFeature, + double theX, double theY) +{ + return 0; +} + +boost::shared_ptr PartSet_FeatureRadiusPrs::findPoint(FeaturePtr theFeature, + double theX, double theY) +{ + boost::shared_ptr aPoint2D; + return aPoint2D; +} + +boost::shared_ptr PartSet_FeatureRadiusPrs::featurePoint + (const PartSet_SelectionMode& theMode) +{ + return boost::shared_ptr(); +} diff --git a/src/PartSet/PartSet_FeatureRadiusPrs.h b/src/PartSet/PartSet_FeatureRadiusPrs.h new file mode 100644 index 000000000..fcdaa6425 --- /dev/null +++ b/src/PartSet/PartSet_FeatureRadiusPrs.h @@ -0,0 +1,80 @@ +// File: PartSet_FeatureRadiusPrs.h +// Created: 16 Jun 2014 +// Author: Natalia ERMOLAEVA + +#ifndef PartSet_FeatureRadiusPrs_H +#define PartSet_FeatureRadiusPrs_H + +#include "PartSet.h" + +#include "PartSet_FeaturePrs.h" +#include "PartSet_Constants.h" + +class GeomDataAPI_Point2D; + +/*! + \class PartSet_FeatureRadiusPrs + * \brief The class to define the circle feature manipulation. It is created for + * the feature create operation to move out the feature properties set and use one operation + * for any type of features. +*/ +class PARTSET_EXPORT PartSet_FeatureRadiusPrs : public PartSet_FeaturePrs +{ +public: + /// Returns the feature type processed by this presentation + /// \return the feature kind + static std::string getKind(); + + /// Constructor + /// \param theSketch the sketch feature + PartSet_FeatureRadiusPrs(FeaturePtr theSketch); + /// Destructor + virtual ~PartSet_FeatureRadiusPrs() {}; + + /// Sets the feature to to a feature attribute depending on the selection mode + /// \param theFeature a feature instance + /// \param theMode the selection mode + /// \return whether the feature is set + virtual bool setFeature(FeaturePtr theFeature, const PartSet_SelectionMode& theMode); + + /// Sets the point to the feature in an attribute depending on the selection mode + /// \param theX the 2D point horizontal coordinate + /// \param theY the 2D point vertical coordinate + /// \param theMode the selection mode + /// \return the new selection mode + virtual PartSet_SelectionMode setPoint(double theX, double theY, + const PartSet_SelectionMode& theMode); + + /// Returns the feature attribute name for the selection mode + /// \param theMode the current operation selection mode. The feature attribute depends on the mode + virtual std::string getAttribute(const PartSet_SelectionMode& theMode) const; + + /// Returns the next selection mode after the attribute + /// \param theAttribute the feature attribute name + /// \return next attribute selection mode + virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const; + + /// \brief Move the full feature. + /// \param theDeltaX the delta for X coordinate is moved + /// \param theDeltaY the delta for Y coordinate is moved + virtual void move(double theDeltaX, double theDeltaY); + + /// Return the distance between the feature and the point + /// \param theFeature feature object + /// \param theX the horizontal coordinate of the point + /// \param theX the vertical coordinate of the point + virtual double distanceToPoint(FeaturePtr theFeature, double theX, double theY); + + /// Find a point in the line with given coordinates + /// \param theFeature the line feature + /// \param theX the horizontal point coordinate + /// \param theY the vertical point coordinate + virtual boost::shared_ptr findPoint(FeaturePtr theFeature, double theX, + double theY); +protected: + /// Returns the feature point in the selection mode position. + /// \param theMode the current operation selection mode. The feature attribute depends on the mode + virtual boost::shared_ptr featurePoint(const PartSet_SelectionMode& theMode); +}; + +#endif diff --git a/src/PartSet/PartSet_OperationCreateConstraint.cpp b/src/PartSet/PartSet_OperationCreateConstraint.cpp index bc4463b94..d4e9e5175 100644 --- a/src/PartSet/PartSet_OperationCreateConstraint.cpp +++ b/src/PartSet/PartSet_OperationCreateConstraint.cpp @@ -13,12 +13,17 @@ #include #include -#include +/*#include #include #include #include +*/ -#include +#include +#include +#include + +#include #include @@ -59,7 +64,9 @@ PartSet_OperationCreateConstraint::~PartSet_OperationCreateConstraint() bool PartSet_OperationCreateConstraint::canProcessKind(const std::string& theId) { // changed - return theId == SKETCH_CONSTRAINT_LENGTH_KIND; + return theId == PartSet_FeatureLengthPrs::getKind() || + theId == PartSet_FeatureDistancePrs::getKind() || + theId == PartSet_FeatureRadiusPrs::getKind(); } bool PartSet_OperationCreateConstraint::canBeCommitted() const diff --git a/src/PartSet/PartSet_Presentation.cpp b/src/PartSet/PartSet_Presentation.cpp index a89383a7a..5d174047b 100644 --- a/src/PartSet/PartSet_Presentation.cpp +++ b/src/PartSet/PartSet_Presentation.cpp @@ -5,44 +5,33 @@ #include #include -#include -#include -#include +#include -#include -#include -#include +#include #include -#include -#include -#include #include -#include #include -#include -#include +#include const Quantity_NameOfColor SKETCH_PLANE_COLOR = Quantity_NOC_CHOCOLATE; /// the plane edge color const int SKETCH_WIDTH = 4; /// the plane edge width -const int CONSTRAINT_TEXT_HEIGHT = 28; /// the text height of the constraint -const int CONSTRAINT_TEXT_SELECTION_TOLERANCE = 20; /// the text selection tolerance - Handle(AIS_InteractiveObject) PartSet_Presentation::createPresentation( FeaturePtr theFeature, FeaturePtr theSketch, const TopoDS_Shape& theShape, - Handle_AIS_InteractiveObject thePrevPrs) + Handle_AIS_InteractiveObject thePreviuos) { Handle(AIS_InteractiveObject) anAIS; - if (theFeature->getKind() == SKETCH_CONSTRAINT_LENGTH_KIND) - anAIS = createSketchConstraintLength(theFeature, theSketch, thePrevPrs); + std::string aKind = theFeature->getKind(); + if (aKind == PartSet_FeatureLengthPrs::getKind()) + anAIS = PartSet_FeatureLengthPrs::createPresentation(theFeature, theSketch, thePreviuos); else { - anAIS = createFeature(theFeature, theShape, thePrevPrs); + anAIS = createFeature(theFeature, theShape, thePreviuos); if (theFeature->getKind() == SKETCH_KIND) { Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS); @@ -58,9 +47,9 @@ Handle(AIS_InteractiveObject) PartSet_Presentation::createPresentation( Handle(AIS_InteractiveObject) PartSet_Presentation::createFeature( FeaturePtr theFeature, const TopoDS_Shape& theShape, - Handle_AIS_InteractiveObject thePrevPrs) + Handle_AIS_InteractiveObject thePreviuos) { - Handle(AIS_InteractiveObject) anAIS = thePrevPrs; + Handle(AIS_InteractiveObject) anAIS = thePreviuos; if (!anAIS.IsNull()) { Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS); @@ -80,87 +69,3 @@ Handle(AIS_InteractiveObject) PartSet_Presentation::createFeature( } return anAIS; } - -Handle(AIS_InteractiveObject) PartSet_Presentation::createSketchConstraintLength( - FeaturePtr theFeature, - FeaturePtr theSketch, - Handle(AIS_InteractiveObject) thePrevPrs) -{ - if (!theFeature || !theSketch) - return thePrevPrs; - - boost::shared_ptr aData = theSketch->data(); - boost::shared_ptr anOrigin = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); - boost::shared_ptr aNormal = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_NORM)); - gp_Pln aPlane(aNormal->x(), aNormal->y(), aNormal->z(), 0/*D*/); - - aData = theFeature->data(); - boost::shared_ptr anAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); - if (!anAttr) - return thePrevPrs; - FeaturePtr aFeature = anAttr->feature(); - if (!aFeature || aFeature->getKind() != SKETCH_LINE_KIND) - return thePrevPrs; - - boost::shared_ptr aFlyoutAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE)); - double aFlyout = aFlyoutAttr->value(); - - aData = aFeature->data(); - if (!aData->isValid()) - return thePrevPrs; - - boost::shared_ptr aPointStart = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); - boost::shared_ptr aPointEnd = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); - - gp_Pnt aPoint1, aPoint2; - PartSet_Tools::convertTo3D(aPointStart->x(), aPointStart->y(), theSketch, aPoint1); - PartSet_Tools::convertTo3D(aPointEnd->x(), aPointEnd->y(), theSketch, aPoint2); - - //Build dimension here - gp_Pnt aP1 = aPoint1; - gp_Pnt aP2 = aPoint2; - if (aFlyout < 0) { - aP1 = aPoint2; - aP2 = aPoint1; - } - - - Handle(AIS_InteractiveObject) anAIS = thePrevPrs; - if (anAIS.IsNull()) - { - Handle(AIS_LengthDimension) aDimAIS = new AIS_LengthDimension (aP1, aP2, aPlane); - - Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect(); - anAspect->MakeArrows3d (Standard_False); - anAspect->MakeText3d(false/*is text 3d*/); - anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT); - anAspect->MakeTextShaded(false/*is test shaded*/); - aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false/*is units displayed*/); - /*if (isUnitsDisplayed) - { - aDimAIS->SetDisplayUnits (aDimDlg->GetUnits ()); - }*/ - aDimAIS->SetDimensionAspect (anAspect); - aDimAIS->SetFlyout(aFlyout); - aDimAIS->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE); - - anAIS = aDimAIS; - } - else { - // update presentation - Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS); - if (!aDimAIS.IsNull()) { - aDimAIS->SetMeasuredGeometry(aPoint1, aPoint2, aPlane); - aDimAIS->SetFlyout(aFlyout); - - aDimAIS->Redisplay(Standard_True); - } - } - return anAIS; -} diff --git a/src/PartSet/PartSet_Presentation.h b/src/PartSet/PartSet_Presentation.h index 8e4b2ae6f..1e11bb578 100644 --- a/src/PartSet/PartSet_Presentation.h +++ b/src/PartSet/PartSet_Presentation.h @@ -22,24 +22,29 @@ class Handle_AIS_InteractiveObject; class PARTSET_EXPORT PartSet_Presentation { public: - /// Creates AIS presentation for the given feature + /// Creates AIS presentation for the given feature. It deals with features and + /// constraints presentations /// \param theFeature a feature - /// \return the presentation + /// \param theSketch a feature sketch + /// \param theShape a shape of the feature + /// \param thePrevious a previous AIS object + /// \return a created/changed AIS object with the feature parameters static Handle_AIS_InteractiveObject createPresentation( FeaturePtr theFeature, FeaturePtr theSketch, const TopoDS_Shape& theShape, - Handle_AIS_InteractiveObject thePrevPrs); + Handle_AIS_InteractiveObject thePreviuos); protected: - static Handle_AIS_InteractiveObject createFeature( + /// Creates AIS presentation based on the given shape + /// \param theFeature a feature + /// \param theSketch a feature sketch + /// \param theShape a shape of the feature + /// \param thePrevious a previous AIS object + /// \return a created/changed AIS object with the feature parameters + static Handle_AIS_InteractiveObject createFeature( FeaturePtr theFeature, const TopoDS_Shape& theShape, - Handle_AIS_InteractiveObject thePrevPrs); - - static Handle_AIS_InteractiveObject createSketchConstraintLength( - FeaturePtr theFeature, - FeaturePtr theSketch, - Handle_AIS_InteractiveObject thePrevPrs); + Handle_AIS_InteractiveObject thePreviuos); }; #endif diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 224183037..a8868beb7 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -26,6 +26,8 @@ #include #include +#include +#include #include @@ -157,6 +159,13 @@ boost::shared_ptr PartSet_Tools::createFeaturePrs(const std: else if (theKind == PartSet_FeatureLengthPrs::getKind()) { aFeaturePrs = boost::shared_ptr(new PartSet_FeatureLengthPrs(theSketch)); } + else if (theKind == PartSet_FeatureRadiusPrs::getKind()) { + aFeaturePrs = boost::shared_ptr(new PartSet_FeatureRadiusPrs(theSketch)); + } + else if (theKind == PartSet_FeatureDistancePrs::getKind()) { + aFeaturePrs = boost::shared_ptr(new PartSet_FeatureDistancePrs(theSketch)); + } + if (theFeature && aFeaturePrs) aFeaturePrs->init(theFeature); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index 57f7b627d..52c58e146 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -15,6 +15,7 @@ SketchPlugin_ConstraintDistance::SketchPlugin_ConstraintDistance() void SketchPlugin_ConstraintDistance::initAttributes() { data()->addAttribute(CONSTRAINT_ATTR_VALUE, ModelAPI_AttributeDouble::type()); + data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE, ModelAPI_AttributeDouble::type()); data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type()); data()->addAttribute(CONSTRAINT_ATTR_ENTITY_B, ModelAPI_AttributeRefAttr::type()); } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp index 6eb620f48..f56b89769 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp @@ -6,6 +6,7 @@ #include #include +#include #include SketchPlugin_ConstraintRadius::SketchPlugin_ConstraintRadius() @@ -16,6 +17,9 @@ void SketchPlugin_ConstraintRadius::initAttributes() { data()->addAttribute(CONSTRAINT_ATTR_VALUE, ModelAPI_AttributeDouble::type()); data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type()); + + data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE, ModelAPI_AttributeDouble::type()); + data()->addAttribute(SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT, GeomDataAPI_Point2D::type()); } void SketchPlugin_ConstraintRadius::execute() diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.h b/src/SketchPlugin/SketchPlugin_ConstraintRadius.h index bdfaa4297..fb39f7bc3 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.h @@ -12,6 +12,9 @@ /// Radius constraint kind const std::string SKETCH_CONSTRAINT_RADIUS_KIND("SketchConstraintRadius"); +/// Start 2D point of the line +const std::string SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT("CirclePoint"); + /** \class SketchPlugin_ConstraintRadius * \ingroup DataModel diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index e39aa518c..596879323 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -1,7 +1,7 @@ - + @@ -22,11 +22,15 @@ - + + - + + diff --git a/src/SketchSolver/SketchSolver_Constraint.cpp b/src/SketchSolver/SketchSolver_Constraint.cpp index d4f55e00d..1b92bf947 100644 --- a/src/SketchSolver/SketchSolver_Constraint.cpp +++ b/src/SketchSolver/SketchSolver_Constraint.cpp @@ -206,7 +206,7 @@ const int& SketchSolver_Constraint::getType(boost::shared_ptr( theConstraint->data()->attribute(CONSTRAINT_ATTRIBUTES[indAttr]) ); - if (!anAttr || !anAttr->isFeature()) continue; + if (!anAttr || !anAttr->isFeature() || !anAttr->feature()) continue; const std::string& aKind = anAttr->feature()->getKind(); if (aKind.compare(SKETCH_CIRCLE_KIND) == 0 || aKind.compare(SKETCH_ARC_KIND) == 0) { -- 2.30.2