From: nds Date: Fri, 20 Jun 2014 11:53:50 +0000 (+0400) Subject: refs #80 - Sketch base GUI: create/draw point, circle and arc X-Git-Tag: V_0.4.4~277 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=57c092b994542c9ab668a15511379c799757e571;p=modules%2Fshaper.git refs #80 - Sketch base GUI: create/draw point, circle and arc 1. Remove operation constraint class. 2. Edit constraint lenght. To debug --- diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 254cd9572..800a4d593 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -14,7 +14,6 @@ SET(PROJECT_HEADERS PartSet_FeaturePointPrs.h PartSet_Listener.h PartSet_Module.h - PartSet_OperationConstraint.h PartSet_OperationCreateConstraint.h PartSet_OperationCreateFeature.h PartSet_OperationEditConstraint.h @@ -36,7 +35,6 @@ SET(PROJECT_SOURCES PartSet_FeaturePointPrs.cpp PartSet_Listener.cpp PartSet_Module.cpp - PartSet_OperationConstraint.cpp PartSet_OperationCreateConstraint.cpp PartSet_OperationCreateFeature.cpp PartSet_OperationEditConstraint.cpp diff --git a/src/PartSet/PartSet_FeatureLengthPrs.cpp b/src/PartSet/PartSet_FeatureLengthPrs.cpp index 36bc766ea..26b4bee77 100644 --- a/src/PartSet/PartSet_FeatureLengthPrs.cpp +++ b/src/PartSet/PartSet_FeatureLengthPrs.cpp @@ -42,11 +42,6 @@ PartSet_SelectionMode PartSet_FeatureLengthPrs::setPoint(double theX, double the PartSet_SelectionMode aMode = theMode; switch (theMode) { - case SM_FirstPoint: { - //PartSet_Tools::setFeaturePoint(feature(), theX, theY, CIRCLE_ATTR_CENTER); - //aMode = SM_SecondPoint; - } - break; case SM_SecondPoint: { boost::shared_ptr aData = feature()->data(); boost::shared_ptr anAttr = @@ -85,56 +80,21 @@ PartSet_SelectionMode PartSet_FeatureLengthPrs::setPoint(double theX, double the std::string PartSet_FeatureLengthPrs::getAttribute(const PartSet_SelectionMode& theMode) const { - std::string aAttribute; - switch (theMode) - { - case SM_FirstPoint: - //aAttribute = CIRCLE_ATTR_CENTER; - break; - case SM_SecondPoint: - //aAttribute = CIRCLE_ATTR_RADIUS; - break; - default: - break; - } - return aAttribute; + return ""; } PartSet_SelectionMode PartSet_FeatureLengthPrs::getNextMode(const std::string& theAttribute) const { - PartSet_SelectionMode aMode = SM_SecondPoint; - - /*if (theAttribute == CIRCLE_ATTR_CENTER) - aMode = SM_SecondPoint; - else if (theAttribute == CIRCLE_ATTR_RADIUS) - aMode = SM_DonePoint;*/ - return aMode; + return SM_FirstPoint; } void PartSet_FeatureLengthPrs::move(double theDeltaX, double theDeltaY) { - /*boost::shared_ptr aData = feature()->data(); - if (!aData->isValid()) - return; - - boost::shared_ptr aPoint1 = - boost::dynamic_pointer_cast(aData->attribute(CIRCLE_ATTR_CENTER)); - aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);*/ } double PartSet_FeatureLengthPrs::distanceToPoint(FeaturePtr theFeature, double theX, double theY) { - /*double aDelta = 0; - if (!theFeature || theFeature->getKind() != getKind()) - return aDelta; - - boost::shared_ptr aData = theFeature->data(); - boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(CIRCLE_ATTR_CENTER)); - - boost::shared_ptr aPoint2d(new GeomAPI_Pnt2d(theX, theY)); - return aPoint->pnt()->distance(aPoint2d);*/ return 0; } @@ -142,35 +102,12 @@ boost::shared_ptr PartSet_FeatureLengthPrs::findPoint(Featu double theX, double theY) { boost::shared_ptr aPoint2D; - /*if (!theFeature || theFeature->getKind() != getKind()) - return aPoint2D; - - boost::shared_ptr aData = theFeature->data(); - boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(CIRCLE_ATTR_CENTER)); - if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() ) - aPoint2D = aPoint; -*/ return aPoint2D; } boost::shared_ptr PartSet_FeatureLengthPrs::featurePoint (const PartSet_SelectionMode& theMode) { - /*std::string aPointArg; - switch (theMode) - { - case SM_FirstPoint: - aPointArg = CIRCLE_ATTR_CENTER; - break; - default: - break; - } - boost::shared_ptr aData = feature()->data(); - boost::shared_ptr aPoint = boost::dynamic_pointer_cast - (aData->attribute(aPointArg)); - return aPoint; - */ return boost::shared_ptr(); } diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index ab0ad429b..c1ca60f14 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -350,8 +349,6 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI anOperation = new PartSet_OperationCreateConstraint(theCmdId.c_str(), this, aSketch); else if (theCmdId == PartSet_OperationEditConstraint::Type()) anOperation = new PartSet_OperationEditConstraint(theCmdId.c_str(), this, aSketch); - else if (theCmdId == PartSet_OperationConstraint::Type()) - anOperation = new PartSet_OperationConstraint(theCmdId.c_str(), this, aSketch); } if (!anOperation) { diff --git a/src/PartSet/PartSet_OperationConstraint.cpp b/src/PartSet/PartSet_OperationConstraint.cpp deleted file mode 100644 index 9b1d2129e..000000000 --- a/src/PartSet/PartSet_OperationConstraint.cpp +++ /dev/null @@ -1,175 +0,0 @@ -// File: PartSet_OperationConstraint.h -// Created: 20 Apr 2014 -// Author: Natalia ERMOLAEVA - -#include - -#include -#include -#include - -#include -#include - -#include - -#include - -#include -#include -#include -#include -#include - -#include - -#include -#include - -#include -#include - -#include - -#include -#include -#include -#include - -#ifdef _DEBUG -#include -#endif - -#include - -using namespace std; - -PartSet_OperationConstraint::PartSet_OperationConstraint(const QString& theId, - QObject* theParent, - FeaturePtr theFeature) -: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature) -{ -} - -PartSet_OperationConstraint::~PartSet_OperationConstraint() -{ -} - -std::string PartSet_OperationConstraint::Type() -{ - return SKETCH_CONSTRAINT_LENGTH_KIND; -} - -bool PartSet_OperationConstraint::isGranted(ModuleBase_IOperation* theOperation) const -{ - return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type(); -} - -void PartSet_OperationConstraint::init(FeaturePtr theFeature, - const std::list& /*theSelected*/, - const std::list& /*theHighlighted*/) -{ - //if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND) - // return; - // use the last point of the previous feature as the first of the new one - //boost::shared_ptr aData = theFeature->data(); - //myInitPoint = boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); -} - -FeaturePtr PartSet_OperationConstraint::sketch() const -{ - return mySketch; -} - -void PartSet_OperationConstraint::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView, - const std::list& theSelected, - const std::list& /*theHighlighted*/) -{ - if (theSelected.empty()) { - } - else { - XGUI_ViewerPrs aPrs = theSelected.front(); - FeaturePtr aFeature = aPrs.feature(); - - setFeature(aFeature); - setValue(120); - flushUpdated(); - } -} - -void PartSet_OperationConstraint::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) -{ -} - -void PartSet_OperationConstraint::startOperation() -{ - PartSet_OperationSketchBase::startOperation(); - //setPointSelectionMode(!myInitPoint ? SM_FirstPoint : SM_SecondPoint); - - emit multiSelectionEnabled(false); -} - -void PartSet_OperationConstraint::abortOperation() -{ - emit featureConstructed(feature(), FM_Hide); - PartSet_OperationSketchBase::abortOperation(); -} - -void PartSet_OperationConstraint::stopOperation() -{ - PartSet_OperationSketchBase::stopOperation(); - emit multiSelectionEnabled(true); -} - -void PartSet_OperationConstraint::afterCommitOperation() -{ - PartSet_OperationSketchBase::afterCommitOperation(); - emit featureConstructed(feature(), FM_Deactivation); -} - -FeaturePtr PartSet_OperationConstraint::createFeature(const bool theFlushMessage) -{ - FeaturePtr aNewFeature = ModuleBase_Operation::createFeature(false); - if (sketch()) { - boost::shared_ptr aFeature = - boost::dynamic_pointer_cast(sketch()); - - aFeature->addSub(aNewFeature); - } - /*if (myInitPoint) { - setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_START); - setLinePoint(aNewFeature, myInitPoint->x(), myInitPoint->y(), LINE_ATTR_END); - - boost::shared_ptr aData = aNewFeature->data(); - boost::shared_ptr aPoint = boost::dynamic_pointer_cast - (aData->attribute(LINE_ATTR_START)); - PartSet_Tools::createConstraint(myInitPoint, aPoint); - }*/ - - emit featureConstructed(aNewFeature, FM_Activation); - if (theFlushMessage) - flushCreated(); - return aNewFeature; -} - -void PartSet_OperationConstraint::setFeature(FeaturePtr theFeature) -{ - if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND) - return; - - boost::shared_ptr aData = feature()->data(); - - boost::shared_ptr anAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); - anAttr->setFeature(theFeature); -} - -void PartSet_OperationConstraint::setValue(const double theValue) -{ - boost::shared_ptr aData = feature()->data(); - - AttributeDoublePtr anAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); - anAttr->setValue(theValue); - -} diff --git a/src/PartSet/PartSet_OperationConstraint.h b/src/PartSet/PartSet_OperationConstraint.h deleted file mode 100644 index 56ffe2629..000000000 --- a/src/PartSet/PartSet_OperationConstraint.h +++ /dev/null @@ -1,101 +0,0 @@ -// File: PartSet_OperationConstraint.h -// Created: 20 Apr 2014 -// Author: Natalia ERMOLAEVA - -#ifndef PartSet_OperationConstraint_H -#define PartSet_OperationConstraint_H - -#include "PartSet.h" - -#include - -#include - -/*! - \class PartSet_OperationConstraint - * \brief The operation for the sketch constraint feature creation -*/ -class PARTSET_EXPORT PartSet_OperationConstraint : public PartSet_OperationSketchBase -{ - Q_OBJECT - -public: - /// Returns the operation type key - static std::string Type(); - -public: - /// Constructor - /// \param theId the feature identifier - /// \param theParent the operation parent - /// \param theFeature the parent feature - PartSet_OperationConstraint(const QString& theId, QObject* theParent, - FeaturePtr theSketchFeature); - /// Destructor - virtual ~PartSet_OperationConstraint(); - - /// Returns that this operator can be started above already running one. - /// The runned operation should be the sketch feature modified operation - /// \param theOperation the previous running operation - virtual bool isGranted(ModuleBase_IOperation* theOperation) const; - - /// Initializes some fields accorging to the feature - /// \param theSelected the list of selected presentations - /// \param theHighlighted the list of highlighted presentations - virtual void init(FeaturePtr theFeature, - const std::list& theSelected, - const std::list& theHighlighted); - - /// Returns the operation sketch feature - /// \returns the sketch instance - virtual FeaturePtr sketch() const; - - /// Gives the current selected objects to be processed by the operation - /// \param theEvent the mouse event - /// \param theView a viewer to have the viewer the eye position - /// \param theSelected the list of selected presentations - /// \param theHighlighted the list of highlighted presentations - virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, - const std::list& theSelected, - const std::list& theHighlighted); - /// Gives the current mouse point in the viewer - /// \param thePoint a point clicked in the viewer - /// \param theEvent the mouse event - virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView); - -protected: - /// \brief Virtual method called when operation is started - /// Virtual method called when operation started (see start() method for more description) - /// After the parent operation body perform, set sketch feature to the created line feature - virtual void startOperation(); - - /// Virtual method called when operation aborted (see abort() method for more description) - /// Before the feature is aborted, it should be hidden from the viewer - virtual void abortOperation(); - - /// Virtual method called when operation stopped - committed or aborted. - /// Restore the multi selection state - virtual void stopOperation(); - - /// Virtual method called after operation committed (see commit() method for more description) - virtual void afterCommitOperation(); - - /// Creates an operation new feature - /// In addition to the default realization it appends the created line feature to - /// the sketch feature - /// \param theFlushMessage the flag whether the create message should be flushed - /// \returns the created feature - virtual FeaturePtr createFeature(const bool theFlushMessage = true); - - /// Set the feature for the constraint - /// \param theFeature the line feature - void setFeature(FeaturePtr theFeature); - - /// Set the value for the constraint - /// \param theValue the constraint value - void setValue(const double theValue); - -private: - FeaturePtr mySketch; ///< the sketch feature -}; - -#endif diff --git a/src/PartSet/PartSet_OperationEditConstraint.cpp b/src/PartSet/PartSet_OperationEditConstraint.cpp index 53f7cc549..18857be25 100644 --- a/src/PartSet/PartSet_OperationEditConstraint.cpp +++ b/src/PartSet/PartSet_OperationEditConstraint.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -40,6 +41,9 @@ PartSet_OperationEditConstraint::PartSet_OperationEditConstraint(const QString& FeaturePtr theFeature) : PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature), myIsBlockedSelection(false) { + std::string aKind = theId.toStdString(); + myFeaturePrs = PartSet_Tools::createFeaturePrs(aKind, theFeature); + // changed myEditor = new PartSet_EditLine(0); connect(myEditor, SIGNAL(stopped(double)), this, SLOT(onEditStopped(double))); @@ -90,7 +94,7 @@ FeaturePtr PartSet_OperationEditConstraint::sketch() const } void PartSet_OperationEditConstraint::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView, - const std::list& /*theSelected*/, + const std::list& theSelected, const std::list& theHighlighted) { //if (myFeatures.size() == 1) @@ -98,6 +102,8 @@ void PartSet_OperationEditConstraint::mousePressed(QMouseEvent* theEvent, Handle FeaturePtr aFeature; if (!theHighlighted.empty()) aFeature = theHighlighted.front().feature(); + if (!aFeature && !theSelected.empty()) // changed + aFeature = theSelected.front().feature(); if (aFeature && aFeature == feature()) { // continue the feature edit } @@ -135,10 +141,12 @@ void PartSet_OperationEditConstraint::mouseMoved(QMouseEvent* theEvent, Handle(V double aX, anY; PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY); - double aDeltaX = aX - aCurX; + /*double aDeltaX = aX - aCurX; double aDeltaY = anY - aCurY; - PartSet_Tools::moveFeature(feature(), aDeltaX, aDeltaY); + PartSet_Tools::moveFeature(feature(), aDeltaX, aDeltaY);*/ + myFeaturePrs->setPoint(aX, anY, SM_SecondPoint); + /*std::list::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end(); for (; anIt != aLast; anIt++) { diff --git a/src/PartSet/PartSet_OperationEditConstraint.h b/src/PartSet/PartSet_OperationEditConstraint.h index 41700b6e7..8aaaa452f 100644 --- a/src/PartSet/PartSet_OperationEditConstraint.h +++ b/src/PartSet/PartSet_OperationEditConstraint.h @@ -11,6 +11,7 @@ #include class PartSet_EditLine; +class PartSet_FeaturePrs; class QMouseEvent; /*! @@ -146,6 +147,7 @@ protected slots: private: PartSet_EditLine* myEditor; ///< the constraint value editor + boost::shared_ptr myFeaturePrs; ///< the feature presentation FeaturePtr mySketch; ///< the sketch feature //std::list myFeatures; ///< the features to apply the edit operation Point myCurPoint; ///< the current 3D point clicked or moved