From 4e672d4ecb0e8a86ccc5e210d879eecf365c3524 Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 5 Jun 2014 17:23:48 +0400 Subject: [PATCH] refs #80 - Sketch base GUI: create/draw point, circle and arc Circle draft creation. --- src/PartSet/CMakeLists.txt | 2 + src/PartSet/PartSet_FeatureCirclePrs.cpp | 118 ++++++++++++++++++ src/PartSet/PartSet_FeatureCirclePrs.h | 57 +++++++++ src/PartSet/PartSet_Module.cpp | 3 +- .../PartSet_OperationCreateFeature.cpp | 21 +++- src/PartSet/PartSet_OperationCreateFeature.h | 4 + src/PartSet/PartSet_icons.qrc | 1 + src/PartSet/icons/radius.png | Bin 0 -> 249 bytes src/SketchPlugin/plugin-Sketch.xml | 5 +- 9 files changed, 203 insertions(+), 8 deletions(-) create mode 100644 src/PartSet/PartSet_FeatureCirclePrs.cpp create mode 100644 src/PartSet/PartSet_FeatureCirclePrs.h create mode 100644 src/PartSet/icons/radius.png diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index f8629de87..a1c50ac66 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_FeatureCirclePrs.h PartSet_FeaturePrs.h PartSet_FeatureLinePrs.h PartSet_FeaturePointPrs.h @@ -22,6 +23,7 @@ SET(PROJECT_HEADERS SET(PROJECT_SOURCES PartSet_FeaturePrs.cpp + PartSet_FeatureCirclePrs.cpp PartSet_FeatureLinePrs.cpp PartSet_FeaturePointPrs.cpp PartSet_Listener.cpp diff --git a/src/PartSet/PartSet_FeatureCirclePrs.cpp b/src/PartSet/PartSet_FeatureCirclePrs.cpp new file mode 100644 index 000000000..48342d9a6 --- /dev/null +++ b/src/PartSet/PartSet_FeatureCirclePrs.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_FeatureCirclePrs::PartSet_FeatureCirclePrs(FeaturePtr theSketch) +: PartSet_FeaturePrs(theSketch) +{ +} + +void PartSet_FeatureCirclePrs::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_FeatureCirclePrs::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_FeatureCirclePrs::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_FeatureCirclePrs::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_FeatureCirclePrs::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_FeatureCirclePrs.h b/src/PartSet/PartSet_FeatureCirclePrs.h new file mode 100644 index 000000000..1e4e68000 --- /dev/null +++ b/src/PartSet/PartSet_FeatureCirclePrs.h @@ -0,0 +1,57 @@ +// File: PartSet_FeatureCirclePrs.h +// Created: 04 Jun 2014 +// Author: Natalia ERMOLAEVA + +#ifndef PartSet_FeatureCirclePrs_H +#define PartSet_FeatureCirclePrs_H + +#include "PartSet.h" + +#include "PartSet_FeaturePrs.h" +#include "PartSet_Constants.h" + +class GeomDataAPI_Point2D; + +/*! + \class PartSet_FeatureCirclePrs + * \brief The abstract class to define the specific 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_FeatureCirclePrs : public PartSet_FeaturePrs +{ +public: + /// Constructor + /// \param theSketch the sketch feature + PartSet_FeatureCirclePrs(FeaturePtr theSketch); + /// Destructor + virtual ~PartSet_FeatureCirclePrs() {}; + + /// 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_Module.cpp b/src/PartSet/PartSet_Module.cpp index 9302a0618..7d5751707 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #include @@ -330,7 +329,7 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI PartSet_OperationSketchBase* aPrevOp = dynamic_cast(aCurOperation); if (aPrevOp) aSketch = aPrevOp->sketch(); - if (theCmdId == SKETCH_LINE_KIND || theCmdId == SKETCH_POINT_KIND) + if (PartSet_OperationCreateFeature::canProcessKind(theCmdId)) anOperation = new PartSet_OperationCreateFeature(theCmdId.c_str(), this, aSketch); else if (theCmdId == PartSet_OperationEditLine::Type()) anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketch); diff --git a/src/PartSet/PartSet_OperationCreateFeature.cpp b/src/PartSet/PartSet_OperationCreateFeature.cpp index 06931c524..7905f6a01 100644 --- a/src/PartSet/PartSet_OperationCreateFeature.cpp +++ b/src/PartSet/PartSet_OperationCreateFeature.cpp @@ -6,11 +6,14 @@ #include #include -#include #include +#include +#include #include +#include #include +#include #include @@ -36,11 +39,16 @@ PartSet_OperationCreateFeature::PartSet_OperationCreateFeature(const QString& th : PartSet_OperationSketchBase(theId, theParent), myPointSelectionMode(SM_FirstPoint) { - if (theId.toStdString() == SKETCH_LINE_KIND) { + std::string aKind = theId.toStdString(); + + if (aKind == SKETCH_POINT_KIND) { + myFeaturePrs = new PartSet_FeaturePointPrs(theFeature); + } + if (aKind == SKETCH_LINE_KIND) { myFeaturePrs = new PartSet_FeatureLinePrs(theFeature); } - else { - myFeaturePrs = new PartSet_FeaturePointPrs(theFeature); + else if (aKind == SKETCH_CIRCLE_KIND) { + myFeaturePrs = new PartSet_FeatureCirclePrs(theFeature); } } @@ -49,6 +57,11 @@ PartSet_OperationCreateFeature::~PartSet_OperationCreateFeature() delete myFeaturePrs; } +bool PartSet_OperationCreateFeature::canProcessKind(const std::string& theId) +{ + return theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND || theId == SKETCH_CIRCLE_KIND; +} + bool PartSet_OperationCreateFeature::canBeCommitted() const { return myPointSelectionMode == SM_DonePoint; diff --git a/src/PartSet/PartSet_OperationCreateFeature.h b/src/PartSet/PartSet_OperationCreateFeature.h index acea5a01e..1eb352dd1 100644 --- a/src/PartSet/PartSet_OperationCreateFeature.h +++ b/src/PartSet/PartSet_OperationCreateFeature.h @@ -26,6 +26,10 @@ class PARTSET_EXPORT PartSet_OperationCreateFeature : public PartSet_OperationSk Q_OBJECT public: + /// Returns true if the feature with the given kind can be created by this operation + /// \param theId the feature kind + /// \return the boolean result + static bool canProcessKind(const std::string& theId); public: /// Constructor diff --git a/src/PartSet/PartSet_icons.qrc b/src/PartSet/PartSet_icons.qrc index 89a8e5735..0d9550b91 100644 --- a/src/PartSet/PartSet_icons.qrc +++ b/src/PartSet/PartSet_icons.qrc @@ -15,5 +15,6 @@ icons/sketch.png icons/hand_point.png icons/dimension_v.png + icons/radius.png diff --git a/src/PartSet/icons/radius.png b/src/PartSet/icons/radius.png new file mode 100644 index 0000000000000000000000000000000000000000..6213de3e4a5a7b330e16e60183603a6c50235c83 GIT binary patch literal 249 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucL8%hgh?3y^w370~qEv=}#LT=BJwMkFg)(D3 zQ$0gN_s>q|Kvfx@E{-7<{>cu^|2q%3G>0j$Wooc|_Fxfm_`}=b$o7XNsZK$S(}y)F zCA~SuS;*lU&tZiF97{Xd40>NQEO7J*kebfu(%fj=@GMS2qC=tgg#=4SpIeu(&{0oG lmJ_FZPMkZ|I+1~ynL)hCM04x^kba<@44$rjF6*2Ung9lUN - + @@ -12,8 +12,9 @@ - + + -- 2.39.2