From: nds Date: Thu, 5 Jun 2014 12:24:28 +0000 (+0400) Subject: refs #80 - Sketch base GUI: create/draw point, circle and arc X-Git-Tag: V_0.4.4~314 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0d18ed597ed8d69a3ef15db56035fc5fcedde694;p=modules%2Fshaper.git refs #80 - Sketch base GUI: create/draw point, circle and arc Point feature creation is finished. Constraint for the point is available between two points or a point and a line point. --- diff --git a/src/PartSet/PartSet_FeaturePointPrs.cpp b/src/PartSet/PartSet_FeaturePointPrs.cpp index 18db26a09..ac695dada 100644 --- a/src/PartSet/PartSet_FeaturePointPrs.cpp +++ b/src/PartSet/PartSet_FeaturePointPrs.cpp @@ -1,4 +1,4 @@ -// File: PartSet_FeaturePointPrs.h +// File: PartSet_FeaturePrs.h // Created: 04 Jun 2014 // Author: Natalia ERMOLAEVA @@ -7,9 +7,7 @@ #include #include -#include -#include -#include +#include #include @@ -22,10 +20,69 @@ using namespace std; -PartSet_FeaturePointPrs::PartSet_FeaturePointPrs(FeaturePtr theFeature) +PartSet_FeaturePointPrs::PartSet_FeaturePointPrs(FeaturePtr theSketch) +: PartSet_FeaturePrs(theSketch) { } -PartSet_FeaturePointPrs::~PartSet_FeaturePointPrs() +void PartSet_FeaturePointPrs::initFeature(FeaturePtr theFeature) { } + +PartSet_SelectionMode PartSet_FeaturePointPrs::setPoint(double theX, double theY, + const PartSet_SelectionMode& theMode) +{ + PartSet_SelectionMode aMode = theMode; + switch (theMode) + { + case SM_FirstPoint: { + PartSet_Tools::setFeaturePoint(feature(), theX, theY, POINT_ATTR_COORD); + aMode = SM_DonePoint; + } + break; + default: + break; + } + return aMode; +} + +std::string PartSet_FeaturePointPrs::getAttribute(const PartSet_SelectionMode& theMode) const +{ + std::string aAttribute; + switch (theMode) + { + case SM_FirstPoint: + aAttribute = POINT_ATTR_COORD; + break; + default: + break; + } + return aAttribute; +} + +PartSet_SelectionMode PartSet_FeaturePointPrs::getNextMode(const std::string& theAttribute) const +{ + PartSet_SelectionMode aMode; + + if (theAttribute == POINT_ATTR_COORD) + aMode = SM_DonePoint; + return aMode; +} + +boost::shared_ptr PartSet_FeaturePointPrs::featurePoint + (const PartSet_SelectionMode& theMode) +{ + std::string aPointArg; + switch (theMode) + { + case SM_FirstPoint: + aPointArg = POINT_ATTR_COORD; + 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_FeaturePointPrs.h b/src/PartSet/PartSet_FeaturePointPrs.h index b43de80ed..d06b3c734 100644 --- a/src/PartSet/PartSet_FeaturePointPrs.h +++ b/src/PartSet/PartSet_FeaturePointPrs.h @@ -7,6 +7,7 @@ #include "PartSet.h" +#include "PartSet_FeaturePrs.h" #include "PartSet_Constants.h" class GeomDataAPI_Point2D; @@ -17,14 +18,40 @@ class GeomDataAPI_Point2D; * the feature create operation to move out the feature properties set and use one operation * for any type of features. */ -class PARTSET_EXPORT PartSet_FeaturePointPrs +class PARTSET_EXPORT PartSet_FeaturePointPrs : public PartSet_FeaturePrs { public: /// Constructor /// \param theSketch the sketch feature PartSet_FeaturePointPrs(FeaturePtr theSketch); /// Destructor - virtual ~PartSet_FeaturePointPrs(); + virtual ~PartSet_FeaturePointPrs() {}; + + /// 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 83b8fbe74..9302a0618 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -25,6 +25,9 @@ #include #include +#include +#include + #include #include #include @@ -327,7 +330,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) + if (theCmdId == SKETCH_LINE_KIND || theCmdId == SKETCH_POINT_KIND) 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 60a5ded04..06931c524 100644 --- a/src/PartSet/PartSet_OperationCreateFeature.cpp +++ b/src/PartSet/PartSet_OperationCreateFeature.cpp @@ -7,8 +7,10 @@ #include #include #include +#include #include +#include #include @@ -29,12 +31,17 @@ using namespace std; PartSet_OperationCreateFeature::PartSet_OperationCreateFeature(const QString& theId, - QObject* theParent, - FeaturePtr theFeature) + QObject* theParent, + FeaturePtr theFeature) : PartSet_OperationSketchBase(theId, theParent), myPointSelectionMode(SM_FirstPoint) { - myFeaturePrs = new PartSet_FeatureLinePrs(theFeature); + if (theId.toStdString() == SKETCH_LINE_KIND) { + myFeaturePrs = new PartSet_FeatureLinePrs(theFeature); + } + else { + myFeaturePrs = new PartSet_FeaturePointPrs(theFeature); + } } PartSet_OperationCreateFeature::~PartSet_OperationCreateFeature() diff --git a/src/PartSet/PartSet_OperationCreateFeature.h b/src/PartSet/PartSet_OperationCreateFeature.h index e53bf9b84..acea5a01e 100644 --- a/src/PartSet/PartSet_OperationCreateFeature.h +++ b/src/PartSet/PartSet_OperationCreateFeature.h @@ -10,8 +10,6 @@ #include #include -#include - #include class PartSet_FeaturePrs; diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 265a3b26b..3e8c921b2 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -297,5 +298,12 @@ boost::shared_ptr PartSet_Tools::findPoint(FeaturePtr theFe aPoint2D = aPoint; } } + else if (theFeature->getKind() == SKETCH_POINT_KIND) + { + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(POINT_ATTR_COORD)); + if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() ) + aPoint2D = aPoint; + } return aPoint2D; } diff --git a/src/SketchPlugin/SketchPlugin_Point.cpp b/src/SketchPlugin/SketchPlugin_Point.cpp index 1d9601a83..63cf747a2 100644 --- a/src/SketchPlugin/SketchPlugin_Point.cpp +++ b/src/SketchPlugin/SketchPlugin_Point.cpp @@ -6,6 +6,7 @@ #include "SketchPlugin_Sketch.h" #include #include +#include using namespace std; @@ -30,8 +31,8 @@ const boost::shared_ptr& SketchPlugin_Point::preview() boost::dynamic_pointer_cast(data()->attribute(POINT_ATTR_COORD)); boost::shared_ptr aPoint3D(aSketch->to3D(aPoint->x(), aPoint->y())); // make a visible point - //boost::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd); - //setPreview(anEdge); + boost::shared_ptr aPointShape = GeomAlgoAPI_PointBuilder::point(aPoint3D); + setPreview(aPointShape); return getPreview(); } diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index be4bb9e41..e9e8a7105 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -1,11 +1,13 @@ - + - + + +