From: nds Date: Tue, 10 Jun 2014 12:28:21 +0000 (+0400) Subject: refs #80 - Sketch base GUI: create/draw point, circle and arc X-Git-Tag: V_0.4.4~294 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b06b3b0ce7ac5727badbdaab20c058358e337a8a;p=modules%2Fshaper.git refs #80 - Sketch base GUI: create/draw point, circle and arc Edit feature: creation a specific presentation in the tools in order to use it in the edit operation. --- diff --git a/src/PartSet/PartSet_FeatureArcPrs.cpp b/src/PartSet/PartSet_FeatureArcPrs.cpp index 97af28864..b742b64d7 100644 --- a/src/PartSet/PartSet_FeatureArcPrs.cpp +++ b/src/PartSet/PartSet_FeatureArcPrs.cpp @@ -29,6 +29,11 @@ PartSet_FeatureArcPrs::PartSet_FeatureArcPrs(FeaturePtr theSketch) { } +std::string PartSet_FeatureArcPrs::getKind() +{ + return SKETCH_ARC_KIND; +} + PartSet_SelectionMode PartSet_FeatureArcPrs::setPoint(double theX, double theY, const PartSet_SelectionMode& theMode) { diff --git a/src/PartSet/PartSet_FeatureArcPrs.h b/src/PartSet/PartSet_FeatureArcPrs.h index a02029e7f..dc8a91bfa 100644 --- a/src/PartSet/PartSet_FeatureArcPrs.h +++ b/src/PartSet/PartSet_FeatureArcPrs.h @@ -24,6 +24,10 @@ class Handle_V3d_View; class PARTSET_EXPORT PartSet_FeatureArcPrs : 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_FeatureArcPrs(FeaturePtr theSketch); diff --git a/src/PartSet/PartSet_OperationCreateFeature.cpp b/src/PartSet/PartSet_OperationCreateFeature.cpp index e92571382..2bfca9f7c 100644 --- a/src/PartSet/PartSet_OperationCreateFeature.cpp +++ b/src/PartSet/PartSet_OperationCreateFeature.cpp @@ -42,24 +42,11 @@ PartSet_OperationCreateFeature::PartSet_OperationCreateFeature(const QString& th myPointSelectionMode(SM_FirstPoint) { 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 if (aKind == SKETCH_CIRCLE_KIND) { - myFeaturePrs = new PartSet_FeatureCirclePrs(theFeature); - } - else if (aKind == SKETCH_ARC_KIND) { - myFeaturePrs = new PartSet_FeatureArcPrs(theFeature); - } + myFeaturePrs = PartSet_Tools::createFeaturePrs(aKind, theFeature); } PartSet_OperationCreateFeature::~PartSet_OperationCreateFeature() { - delete myFeaturePrs; } bool PartSet_OperationCreateFeature::canProcessKind(const std::string& theId) @@ -138,7 +125,8 @@ void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); // move to selected line if (feature()->getKind() == SKETCH_LINE_KIND) { - PartSet_FeatureLinePrs* aLinePrs = dynamic_cast(myFeaturePrs); + boost::shared_ptr aLinePrs = + boost::dynamic_pointer_cast(myFeaturePrs); if (aLinePrs) { FeaturePtr aFeature = aPrs.feature(); aLinePrs->projectPointOnLine(aFeature, myPointSelectionMode, aPoint, theView, aX, anY); @@ -154,7 +142,8 @@ void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle case SM_SecondPoint: case SM_ThirdPoint: { if (feature()->getKind() == SKETCH_ARC_KIND) { - PartSet_FeatureArcPrs* anArcPrs = dynamic_cast(myFeaturePrs); + boost::shared_ptr anArcPrs = + boost::dynamic_pointer_cast(myFeaturePrs); if (anArcPrs) { anArcPrs->projectPointOnArc(aPoint, theView, aX, anY); } @@ -182,7 +171,8 @@ void PartSet_OperationCreateFeature::mouseMoved(QMouseEvent* theEvent, Handle(V3 PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); if (myPointSelectionMode == SM_ThirdPoint) { if (feature()->getKind() == SKETCH_ARC_KIND) { - PartSet_FeatureArcPrs* anArcPrs = dynamic_cast(myFeaturePrs); + boost::shared_ptr anArcPrs = + boost::dynamic_pointer_cast(myFeaturePrs); if (anArcPrs) { anArcPrs->projectPointOnArc(aPoint, theView, aX, anY); } diff --git a/src/PartSet/PartSet_OperationCreateFeature.h b/src/PartSet/PartSet_OperationCreateFeature.h index 1eb352dd1..e35f5f88d 100644 --- a/src/PartSet/PartSet_OperationCreateFeature.h +++ b/src/PartSet/PartSet_OperationCreateFeature.h @@ -116,7 +116,7 @@ protected: const bool isToEmitSignal = true); private: - PartSet_FeaturePrs* myFeaturePrs; ///< the feature presentation + boost::shared_ptr myFeaturePrs; ///< the feature presentation FeaturePtr myInitFeature; ///< the initial feature PartSet_SelectionMode myPointSelectionMode; ///< point selection mode }; diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 4a483de02..bc73da323 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -174,6 +175,30 @@ void PartSet_Tools::projectPointOnLine(double theX1, double theY1, double theX2, } } +boost::shared_ptr PartSet_Tools::createFeaturePrs(const std::string& theKind, + FeaturePtr theSketch, + FeaturePtr theFeature) +{ + PartSet_FeaturePrs* aFeaturePrs; + + if (theKind == PartSet_FeaturePointPrs::getKind()) { + aFeaturePrs = new PartSet_FeaturePointPrs(theSketch); + } + else if (theKind == PartSet_FeatureLinePrs::getKind()) { + aFeaturePrs = new PartSet_FeatureLinePrs(theSketch); + } + else if (theKind == PartSet_FeatureCirclePrs::getKind()) { + aFeaturePrs = new PartSet_FeatureCirclePrs(theSketch); + } + else if (theKind == PartSet_FeatureArcPrs::getKind()) { + aFeaturePrs = new PartSet_FeatureArcPrs(theSketch); + } + if (theFeature) + aFeaturePrs->init(theFeature, FeaturePtr()); + + return boost::shared_ptr(aFeaturePrs); +} + FeaturePtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch, const std::list& theFeatures) diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 30c8fa401..4dd228226 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -20,6 +20,7 @@ class Handle_V3d_View; class XGUI_ViewerPrs; class GeomDataAPI_Point2D; +class PartSet_FeaturePrs; /*! \class PartSet_Tools @@ -75,6 +76,15 @@ public: static void projectPointOnLine(double theX1, double theY1, double theX2, double theY2, double thePointX, double thePointY, double& theX, double& theY); + /// Creates the feature presentation + /// \param theKind a feature kind + /// \param theSketch the sketch of the feature + /// \param theFeature the feature + static boost::shared_ptr createFeaturePrs(const std::string& theKind, + FeaturePtr theSketch, + FeaturePtr theFeature = FeaturePtr()); + + /// Returns a feature that is under the mouse point /// \param thePoint a screen point /// \param theView a 3D view