From a2a59a74e85cb88c87037a2cd6b8c0e4edad22ce Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 6 Jun 2014 19:36:52 +0400 Subject: [PATCH] refs #80 - Sketch base GUI: create/draw point, circle and arc Arc feature inital creation. No V3d viewer. --- src/PartSet/CMakeLists.txt | 2 + src/PartSet/PartSet_FeatureArcPrs.cpp | 118 ++++++++++++++++++ src/PartSet/PartSet_FeatureArcPrs.h | 57 +++++++++ src/PartSet/PartSet_FeatureCirclePrs.h | 2 +- src/PartSet/PartSet_FeatureLinePrs.h | 2 +- src/PartSet/PartSet_FeaturePointPrs.h | 2 +- .../PartSet_OperationCreateFeature.cpp | 8 +- src/SketchPlugin/SketchPlugin_Plugin.cpp | 3 + src/SketchPlugin/plugin-Sketch.xml | 4 +- 9 files changed, 192 insertions(+), 6 deletions(-) create mode 100644 src/PartSet/PartSet_FeatureArcPrs.cpp create mode 100644 src/PartSet/PartSet_FeatureArcPrs.h diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index a1c50ac66..a07a1f599 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -5,6 +5,7 @@ SET(CMAKE_AUTOMOC ON) SET(PROJECT_HEADERS PartSet.h PartSet_Constants.h + PartSet_FeatureArcPrs.h PartSet_FeatureCirclePrs.h PartSet_FeaturePrs.h PartSet_FeatureLinePrs.h @@ -23,6 +24,7 @@ SET(PROJECT_HEADERS SET(PROJECT_SOURCES PartSet_FeaturePrs.cpp + PartSet_FeatureArcPrs.cpp PartSet_FeatureCirclePrs.cpp PartSet_FeatureLinePrs.cpp PartSet_FeaturePointPrs.cpp diff --git a/src/PartSet/PartSet_FeatureArcPrs.cpp b/src/PartSet/PartSet_FeatureArcPrs.cpp new file mode 100644 index 000000000..024d911d2 --- /dev/null +++ b/src/PartSet/PartSet_FeatureArcPrs.cpp @@ -0,0 +1,118 @@ +// File: PartSet_FeaturePrs.h +// Created: 04 Jun 2014 +// Author: Natalia ERMOLAEVA + +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include + +using namespace std; + +PartSet_FeatureArcPrs::PartSet_FeatureArcPrs(FeaturePtr theSketch) +: PartSet_FeaturePrs(theSketch) +{ +} + +void PartSet_FeatureArcPrs::initFeature(FeaturePtr theFeature) +{ + if (feature() && theFeature) + { + // use the last point of the previous feature as the first of the new one + boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr anInitPoint = boost::dynamic_pointer_cast + (aData->attribute(LINE_ATTR_END)); + PartSet_Tools::setFeaturePoint(feature(), anInitPoint->x(), anInitPoint->y(), LINE_ATTR_START); + PartSet_Tools::setFeaturePoint(feature(), anInitPoint->x(), anInitPoint->y(), LINE_ATTR_END); + + aData = feature()->data(); + boost::shared_ptr aPoint = boost::dynamic_pointer_cast + (aData->attribute(LINE_ATTR_START)); + PartSet_Tools::createConstraint(sketch(), anInitPoint, aPoint); + } +} + +PartSet_SelectionMode PartSet_FeatureArcPrs::setPoint(double theX, double theY, + const PartSet_SelectionMode& theMode) +{ + PartSet_SelectionMode aMode = theMode; + switch (theMode) + { + case SM_FirstPoint: { + PartSet_Tools::setFeaturePoint(feature(), theX, theY, LINE_ATTR_START); + PartSet_Tools::setFeaturePoint(feature(), theX, theY, LINE_ATTR_END); + aMode = SM_SecondPoint; + } + break; + case SM_SecondPoint: { + PartSet_Tools::setFeaturePoint(feature(), theX, theY, LINE_ATTR_END); + aMode = SM_DonePoint; + } + break; + default: + break; + } + return aMode; +} + +std::string PartSet_FeatureArcPrs::getAttribute(const PartSet_SelectionMode& theMode) const +{ + std::string aAttribute; + switch (theMode) + { + case SM_FirstPoint: + aAttribute = LINE_ATTR_START; + break; + case SM_SecondPoint: + aAttribute = LINE_ATTR_END; + break; + default: + break; + } + return aAttribute; +} + +PartSet_SelectionMode PartSet_FeatureArcPrs::getNextMode(const std::string& theAttribute) const +{ + PartSet_SelectionMode aMode; + + if (theAttribute == LINE_ATTR_START) + aMode = SM_SecondPoint; + else if (theAttribute == LINE_ATTR_END) + aMode = SM_DonePoint; + return aMode; +} + +boost::shared_ptr PartSet_FeatureArcPrs::featurePoint + (const PartSet_SelectionMode& theMode) +{ + std::string aPointArg; + switch (theMode) + { + case SM_FirstPoint: + aPointArg = LINE_ATTR_START; + break; + case SM_SecondPoint: + aPointArg = LINE_ATTR_END; + break; + default: + break; + } + boost::shared_ptr aData = feature()->data(); + boost::shared_ptr aPoint = boost::dynamic_pointer_cast + (aData->attribute(aPointArg)); + return aPoint; +} diff --git a/src/PartSet/PartSet_FeatureArcPrs.h b/src/PartSet/PartSet_FeatureArcPrs.h new file mode 100644 index 000000000..b0807db84 --- /dev/null +++ b/src/PartSet/PartSet_FeatureArcPrs.h @@ -0,0 +1,57 @@ +// File: PartSet_FeatureArcPrs.h +// Created: 04 Jun 2014 +// Author: Natalia ERMOLAEVA + +#ifndef PartSet_FeatureArcPrs_H +#define PartSet_FeatureArcPrs_H + +#include "PartSet.h" + +#include "PartSet_FeaturePrs.h" +#include "PartSet_Constants.h" + +class GeomDataAPI_Point2D; + +/*! + \class PartSet_FeatureArcPrs + * \brief The class to define the circle arc 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_FeatureArcPrs : public PartSet_FeaturePrs +{ +public: + /// Constructor + /// \param theSketch the sketch feature + PartSet_FeatureArcPrs(FeaturePtr theSketch); + /// Destructor + virtual ~PartSet_FeatureArcPrs() {}; + + /// 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; + +protected: + /// Initializes current feature by the given + /// \param theSourceFeature the feature, which attributes are used to initialize the current feature + virtual void initFeature(FeaturePtr theSourceFeature); + + /// 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_FeatureCirclePrs.h b/src/PartSet/PartSet_FeatureCirclePrs.h index ef4b8497d..6a75b05b8 100644 --- a/src/PartSet/PartSet_FeatureCirclePrs.h +++ b/src/PartSet/PartSet_FeatureCirclePrs.h @@ -14,7 +14,7 @@ class GeomDataAPI_Point2D; /*! \class PartSet_FeatureCirclePrs - * \brief The abstract class to define the specific feature manipulation. It is created for + * \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. */ diff --git a/src/PartSet/PartSet_FeatureLinePrs.h b/src/PartSet/PartSet_FeatureLinePrs.h index a2ff5bba0..b94e40265 100644 --- a/src/PartSet/PartSet_FeatureLinePrs.h +++ b/src/PartSet/PartSet_FeatureLinePrs.h @@ -14,7 +14,7 @@ class GeomDataAPI_Point2D; /*! \class PartSet_FeatureLinePrs - * \brief The abstract class to define the specific feature manipulation. It is created for + * \brief The class to define the line 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. */ diff --git a/src/PartSet/PartSet_FeaturePointPrs.h b/src/PartSet/PartSet_FeaturePointPrs.h index fa9f73deb..bd63137f2 100644 --- a/src/PartSet/PartSet_FeaturePointPrs.h +++ b/src/PartSet/PartSet_FeaturePointPrs.h @@ -14,7 +14,7 @@ class GeomDataAPI_Point2D; /*! \class PartSet_FeaturePointPrs - * \brief The abstract class to define the specific feature manipulation. It is created for + * \brief The class to define the point 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. */ diff --git a/src/PartSet/PartSet_OperationCreateFeature.cpp b/src/PartSet/PartSet_OperationCreateFeature.cpp index 7905f6a01..2bfa875d6 100644 --- a/src/PartSet/PartSet_OperationCreateFeature.cpp +++ b/src/PartSet/PartSet_OperationCreateFeature.cpp @@ -9,11 +9,13 @@ #include #include #include +#include #include #include #include #include +#include #include @@ -50,6 +52,9 @@ PartSet_OperationCreateFeature::PartSet_OperationCreateFeature(const QString& th else if (aKind == SKETCH_CIRCLE_KIND) { myFeaturePrs = new PartSet_FeatureCirclePrs(theFeature); } + else if (aKind == SKETCH_ARC_KIND) { + myFeaturePrs = new PartSet_FeatureArcPrs(theFeature); + } } PartSet_OperationCreateFeature::~PartSet_OperationCreateFeature() @@ -59,7 +64,8 @@ PartSet_OperationCreateFeature::~PartSet_OperationCreateFeature() bool PartSet_OperationCreateFeature::canProcessKind(const std::string& theId) { - return theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND || theId == SKETCH_CIRCLE_KIND; + return theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND || theId == SKETCH_CIRCLE_KIND || + theId == SKETCH_ARC_KIND; } bool PartSet_OperationCreateFeature::canBeCommitted() const diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 14e61b236..d494a6379 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -38,6 +38,9 @@ FeaturePtr SketchPlugin_Plugin::createFeature(string theFeatureID) else if (theFeatureID == SKETCH_CIRCLE_KIND) { return FeaturePtr(new SketchPlugin_Circle); } + else if (theFeatureID == SKETCH_ARC_KIND) { + return FeaturePtr(new SketchPlugin_Arc); + } else if (theFeatureID == SKETCH_CONSTRAINT_COINCIDENCE_KIND) { return FeaturePtr(new SketchPlugin_ConstraintCoincidence); } diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index f5d7507d3..e39aa518c 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -1,7 +1,7 @@ - + @@ -16,7 +16,7 @@ - + -- 2.39.2