From 950f8c3ca4de26c84757fe06698d8ea5a527757a Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 6 May 2014 14:04:55 +0400 Subject: [PATCH] refs #30 - Sketch base GUI: create, draw lines Drag of the line during edit line operation. --- src/ModuleBase/CMakeLists.txt | 2 - src/ModuleBase/ModuleBase_Operation.cpp | 4 +- src/ModuleBase/ModuleBase_Operation.h | 4 +- .../ModuleBase_OperationDescription.cpp | 4 +- .../ModuleBase_OperationDescription.h | 4 +- .../ModuleBase_PropPanelOperation.cpp | 32 ---- .../ModuleBase_PropPanelOperation.h | 79 --------- src/ModuleBase/ModuleBase_WidgetFactory.cpp | 1 - src/PartSet/PartSet_Module.cpp | 80 +++++---- src/PartSet/PartSet_Module.h | 10 +- src/PartSet/PartSet_OperationEditLine.cpp | 155 ++++-------------- src/PartSet/PartSet_OperationEditLine.h | 55 ++----- src/PartSet/PartSet_OperationSketch.cpp | 4 +- src/PartSet/PartSet_OperationSketch.h | 4 + src/PartSet/PartSet_OperationSketchBase.h | 13 +- src/PartSet/PartSet_OperationSketchLine.cpp | 36 +--- src/PartSet/PartSet_OperationSketchLine.h | 26 ++- src/PartSet/PartSet_Tools.cpp | 31 ++++ src/PartSet/PartSet_Tools.h | 10 ++ src/XGUI/XGUI_PropertyPanel.cpp | 2 - 20 files changed, 181 insertions(+), 375 deletions(-) delete mode 100644 src/ModuleBase/ModuleBase_PropPanelOperation.cpp delete mode 100644 src/ModuleBase/ModuleBase_PropPanelOperation.h diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 2e706ecb9..b154decb0 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -6,7 +6,6 @@ SET(PROJECT_HEADERS ModuleBase_IOperation.h ModuleBase_Operation.h ModuleBase_OperationDescription.h - ModuleBase_PropPanelOperation.h ModuleBase_ModelWidget.h ModuleBase_WidgetFactory.h ModuleBase_WidgetPoint2D.h @@ -18,7 +17,6 @@ SET(PROJECT_SOURCES ModuleBase_IOperation.cpp ModuleBase_Operation.cpp ModuleBase_OperationDescription.cpp - ModuleBase_PropPanelOperation.cpp ModuleBase_WidgetFactory.cpp ModuleBase_WidgetPoint2D.cpp ModuleBase_WidgetSwitch.cpp diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 2dc4b8f05..e742c0553 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -1,8 +1,8 @@ /* * ModuleBase_Operation.cpp * - * Created on: May 5, 2014 - * Author: nds + * Created on: Apr 2, 2014 + * Author: sbh */ #include "ModuleBase_Operation.h" diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h index 2f2aca0fa..43c225dd1 100644 --- a/src/ModuleBase/ModuleBase_Operation.h +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -1,8 +1,8 @@ /* * ModuleBase_Operation.h * - * Created on: May 5, 2014 - * Author: nds + * Created on: Apr 2, 2014 + * Author: sbh */ diff --git a/src/ModuleBase/ModuleBase_OperationDescription.cpp b/src/ModuleBase/ModuleBase_OperationDescription.cpp index a9bd201ac..692c5721a 100644 --- a/src/ModuleBase/ModuleBase_OperationDescription.cpp +++ b/src/ModuleBase/ModuleBase_OperationDescription.cpp @@ -1,8 +1,8 @@ /* * ModuleBase_OperationDescription.cpp * - * Created on: May 5, 2014 - * Author: nds + * Created on: Apr 2, 2014 + * Author: sbh */ #include diff --git a/src/ModuleBase/ModuleBase_OperationDescription.h b/src/ModuleBase/ModuleBase_OperationDescription.h index aedb625b2..56b37c28e 100644 --- a/src/ModuleBase/ModuleBase_OperationDescription.h +++ b/src/ModuleBase/ModuleBase_OperationDescription.h @@ -1,8 +1,8 @@ /* * ModuleBase_OperationDescription.h * - * Created on: May 5, 2014 - * Author: nds + * Created on: Apr 2, 2014 + * Author: sbh */ #ifndef MODULEBASE_OPERATIONDESCRIPTION_H diff --git a/src/ModuleBase/ModuleBase_PropPanelOperation.cpp b/src/ModuleBase/ModuleBase_PropPanelOperation.cpp deleted file mode 100644 index a35aaf75f..000000000 --- a/src/ModuleBase/ModuleBase_PropPanelOperation.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * ModuleBase_PropPanelOperation.cpp - * - * Created on: Apr 2, 2014 - * Author: sbh - */ - -#include -#include - -/*! - \brief Constructor - \param XGUI_Workshop - workshop for this operation - - Constructs an empty operation. Constructor should work very fast because many - operators may be created after starting workshop but only several from them - may be used. As result this constructor stores given workshop in myApp field - and set Waiting status. - */ -ModuleBase_PropPanelOperation::ModuleBase_PropPanelOperation(const QString& theId, QObject* parent) -: ModuleBase_Operation(theId, parent) -{ -} - -/*! - * \brief Destructor - */ -ModuleBase_PropPanelOperation::~ModuleBase_PropPanelOperation() -{ - -} - diff --git a/src/ModuleBase/ModuleBase_PropPanelOperation.h b/src/ModuleBase/ModuleBase_PropPanelOperation.h deleted file mode 100644 index c6dc06814..000000000 --- a/src/ModuleBase/ModuleBase_PropPanelOperation.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * ModuleBase_PropPanelOperation.h - * - * Created on: Apr 2, 2014 - * Author: sbh - */ - -#ifndef MODULEBASE_PROPPANELOPERATION_H -#define MODULEBASE_PROPPANELOPERATION_H - -#include -#include - -#include -#include - -#include - -/*! - * \class ModuleBase_PropPanelOperation - * - */ -class MODULEBASE_EXPORT ModuleBase_PropPanelOperation: public ModuleBase_Operation -{ - - Q_OBJECT - -public: - ModuleBase_PropPanelOperation(const QString& theId = "", QObject* parent = 0); - virtual ~ModuleBase_PropPanelOperation(); - - /*! - * \brief Returns XML representation of the operation's widget. - * \return XML QString - * - * Returns XML representation of the operation's widget. - */ - const QString& xmlRepresentation() const - { - return myXmlRepr; - } - - /*! - * \brief Sets XML representation of the operation's widget. - * \param xmlRepr - XML QString - * - * Sets XML representation of the operation's widget. - */ - void setXmlRepresentation(const QString& xmlRepr) - { - this->myXmlRepr = xmlRepr; - } - - - /* - * Returns a short description of operation (will be - * inserted in title of property panel) - */ - const QString& description() const - { - return myDescription; - } - - /* - * Sets a short description of operation (will be - * inserted in title of property panel) - */ - void setDescription(const QString& theDescription) - { - this->myDescription = theDescription; - } - -private: - //!< Next fields could be extracted into a subclass; - QString myXmlRepr; - QString myDescription; -}; - -#endif //MODULEBASE_PROPPANELOPERATION_H diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index ab27df2df..e5212c7e8 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 6bfffa8ce..36a58e67e 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -57,6 +57,8 @@ PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop) connect(myWorkshop->selector(), SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); + connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)), + this, SLOT(onMousePressed(QMouseEvent*))); connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)), this, SLOT(onMouseReleased(QMouseEvent*))); connect(myWorkshop->viewer(), SIGNAL(mouseMove(QMouseEvent*)), @@ -110,7 +112,7 @@ void PartSet_Module::onFeatureTriggered() void PartSet_Module::launchOperation(const QString& theCmdId) { - ModuleBase_Operation* anOperation = createOperation(theCmdId); + ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString()); sendOperation(anOperation); } @@ -142,34 +144,39 @@ void PartSet_Module::onSelectionChanged() } } +void PartSet_Module::onMousePressed(QMouseEvent* theEvent) +{ + PartSet_OperationSketchBase* aPreviewOp = dynamic_cast( + myWorkshop->operationMgr()->currentOperation()); + if (aPreviewOp) + { + gp_Pnt aPnt = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), + myWorkshop->viewer()->activeView()); + aPreviewOp->mousePressed(aPnt, theEvent); + } +} + void PartSet_Module::onMouseReleased(QMouseEvent* theEvent) { - QPoint aPoint = theEvent->pos(); - ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); - PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); - if (aPreviewOp) { - XGUI_SelectionMgr* aSelector = myWorkshop->selector(); - if (aSelector) { - Handle(V3d_View) aView3d = myWorkshop->viewer()->activeView(); - if ( !aView3d.IsNull() ) { - gp_Pnt aPnt = PartSet_Tools::ConvertClickToPoint(aPoint, aView3d); - aPreviewOp->mouseReleased(aPnt); - } - } + PartSet_OperationSketchBase* aPreviewOp = dynamic_cast( + myWorkshop->operationMgr()->currentOperation()); + if (aPreviewOp) + { + gp_Pnt aPnt = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), + myWorkshop->viewer()->activeView()); + aPreviewOp->mouseReleased(aPnt, theEvent); } } void PartSet_Module::onMouseMoved(QMouseEvent* theEvent) { - QPoint aPoint = theEvent->pos(); - ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); - PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); - if (aPreviewOp) { - Handle(V3d_View) aView3d = myWorkshop->viewer()->activeView(); - if ( !aView3d.IsNull() ) { - gp_Pnt aPnt = PartSet_Tools::ConvertClickToPoint(aPoint, aView3d); - aPreviewOp->mouseMoved(aPnt); - } + PartSet_OperationSketchBase* aPreviewOp = dynamic_cast( + myWorkshop->operationMgr()->currentOperation()); + if (aPreviewOp) + { + gp_Pnt aPnt = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), + myWorkshop->viewer()->activeView()); + aPreviewOp->mouseMoved(aPnt, theEvent); } } @@ -215,37 +222,41 @@ void PartSet_Module::onFeatureConstructed(boost::shared_ptr th visualizePreview(theFeature, isDisplay); } -ModuleBase_Operation* PartSet_Module::createOperation(const QString& theCmdId) +ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId) { - std::string aStdCmdId = theCmdId.toStdString(); - if (aStdCmdId == "EditLine") - aStdCmdId = "SketchLine"; + // get operation xml description + std::string aStdCmdId = theCmdId; + if (aStdCmdId == PartSet_OperationEditLine::Type()) + aStdCmdId = PartSet_OperationSketchLine::Type(); std::string aPluginFileName = featureFile(aStdCmdId); Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName); aWdgReader.readAll(); std::string aXmlCfg = aWdgReader.featureWidgetCfg(aStdCmdId); std::string aDescription = aWdgReader.featureDescription(aStdCmdId); + + // create the operation ModuleBase_Operation* anOperation; - if (theCmdId == "Sketch" ) { - anOperation = new PartSet_OperationSketch(theCmdId, this); + if (theCmdId == PartSet_OperationSketch::Type()) { + anOperation = new PartSet_OperationSketch(theCmdId.c_str(), this); } - else if(theCmdId == "SketchLine" || theCmdId == "EditLine") { + else if(theCmdId == PartSet_OperationSketchLine::Type() || + theCmdId == PartSet_OperationEditLine::Type()) { ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation(); boost::shared_ptr aSketchFeature; if (aCurOperation) aSketchFeature = aCurOperation->feature(); - if (theCmdId == "SketchLine") - anOperation = new PartSet_OperationSketchLine(theCmdId, this, aSketchFeature); + if (theCmdId == PartSet_OperationSketchLine::Type()) + anOperation = new PartSet_OperationSketchLine(theCmdId.c_str(), this, aSketchFeature); else - anOperation = new PartSet_OperationEditLine(theCmdId, this, aSketchFeature); + anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketchFeature); } else { - anOperation = new ModuleBase_Operation(theCmdId, this); + anOperation = new ModuleBase_Operation(theCmdId.c_str(), this); } anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg)); anOperation->getDescription()->setDescription(QString::fromStdString(aDescription)); - // connect + // connect the operation PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); if (aPreviewOp) { connect(aPreviewOp, SIGNAL(featureConstructed(boost::shared_ptr, int)), @@ -259,7 +270,6 @@ ModuleBase_Operation* PartSet_Module::createOperation(const QString& theCmdId) this, SLOT(onPlaneSelected(double, double, double))); } } - return anOperation; } diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 68fe21e6f..03207f252 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -53,11 +53,15 @@ public slots: /// SLOT, that is called by the selection in the viewer is changed. /// The selection is sent to the current operation if it listens selection. void onSelectionChanged(); - /// SLOT, that is called by mouse click in the viewer. + /// SLOT, that is called by mouse press in the viewer. + /// The mouse released point is sent to the current operation to be processed. + /// \param theEvent the mouse event + void onMousePressed(QMouseEvent* theEvent); + /// SLOT, that is called by mouse release in the viewer. /// The mouse released point is sent to the current operation to be processed. /// \param theEvent the mouse event void onMouseReleased(QMouseEvent* theEvent); - /// SLOT, that is called by the selection in the viewer is changed. + /// SLOT, that is called by mouse move in the viewer. /// The mouse moved point is sent to the current operation to be processed. /// \param theEvent the mouse event void onMouseMoved(QMouseEvent* theEvent); @@ -82,7 +86,7 @@ public slots: protected: /// Creates a new operation /// \param theCmdId the operation name - ModuleBase_Operation* createOperation(const QString& theCmdId); + ModuleBase_Operation* createOperation(const std::string& theCmdId); /// Sends the operation /// \param theOperation the operation diff --git a/src/PartSet/PartSet_OperationEditLine.cpp b/src/PartSet/PartSet_OperationEditLine.cpp index 72020fb9a..784194575 100644 --- a/src/PartSet/PartSet_OperationEditLine.cpp +++ b/src/PartSet/PartSet_OperationEditLine.cpp @@ -3,21 +3,21 @@ // Author: Natalia ERMOLAEVA #include +#include #include #include -#include -#include #include #include -#include #include #ifdef _DEBUG #include #endif +#include + using namespace std; PartSet_OperationEditLine::PartSet_OperationEditLine(const QString& theId, @@ -39,8 +39,8 @@ bool PartSet_OperationEditLine::isGranted() const std::list PartSet_OperationEditLine::getSelectionModes(boost::shared_ptr theFeature) const { std::list aModes; - //if (theFeature != feature()) - // aModes.push_back(TopAbs_VERTEX); + aModes.push_back(TopAbs_VERTEX); + aModes.push_back(TopAbs_EDGE); return aModes; } @@ -49,82 +49,30 @@ void PartSet_OperationEditLine::init(boost::shared_ptr theFeat setFeature(theFeature); } -void PartSet_OperationEditLine::mouseReleased(const gp_Pnt& thePoint) +void PartSet_OperationEditLine::mousePressed(const gp_Pnt& thePoint, QMouseEvent* theEvent) { - /*switch (myPointSelectionMode) - { - case SM_FirstPoint: { - setLinePoint(thePoint, LINE_ATTR_START); - myPointSelectionMode = SM_SecondPoint; - } - break; - case SM_SecondPoint: { - setLinePoint(thePoint, LINE_ATTR_END); - myPointSelectionMode = SM_None; - } - break; - case SM_None: { - - } - break; - default: - break; - } -*/ + if (!(theEvent->buttons() & Qt::LeftButton)) + return; + myCurPressed = thePoint; } -void PartSet_OperationEditLine::mouseMoved(const gp_Pnt& thePoint) +void PartSet_OperationEditLine::mouseMoved(const gp_Pnt& thePoint, QMouseEvent* theEvent) { -/* switch (myPointSelectionMode) - { - case SM_SecondPoint: - setLinePoint(thePoint, LINE_ATTR_END); - break; - case SM_None: { - boost::shared_ptr aPrevFeature = feature(); - // stop the last operation - commitOperation(); - document()->finishOperation(); - //emit changeSelectionMode(aPrevFeature, TopAbs_VERTEX); - // start a new operation - document()->startOperation(); - startOperation(); - // use the last point of the previous feature as the first of the new one - setLinePoint(aPrevFeature, LINE_ATTR_END, LINE_ATTR_START); - myPointSelectionMode = SM_SecondPoint; - - emit featureConstructed(aPrevFeature, FM_Deactivation); - } - break; - default: - break; - } -*/ -} + if (!(theEvent->buttons() & Qt::LeftButton)) + return; -void PartSet_OperationEditLine::keyReleased(const int theKey) -{ -/* switch (theKey) { - case Qt::Key_Escape: { - if (myPointSelectionMode != SM_None) - emit featureConstructed(feature(), FM_Abort); - abort(); - } - break; - case Qt::Key_Return: { - if (myPointSelectionMode != SM_None) { - emit featureConstructed(feature(), FM_Abort); - myPointSelectionMode = SM_FirstPoint; - document()->abortOperation(); - } - else - myPointSelectionMode = SM_FirstPoint; - } - break; - default: - break; - } - */ + double aCurX, aCurY; + PartSet_Tools::ConvertTo2D(myCurPressed, mySketch, aCurX, aCurY); + + double aX, anY; + PartSet_Tools::ConvertTo2D(thePoint, mySketch, aX, anY); + + double aDeltaX = aX - aCurX; + double aDeltaY = anY - aCurY; + + moveLinePoint(aDeltaX, aDeltaY, LINE_ATTR_START); + moveLinePoint(aDeltaX, aDeltaY, LINE_ATTR_END); + myCurPressed = thePoint; } void PartSet_OperationEditLine::setSelected(boost::shared_ptr theFeature, @@ -136,71 +84,26 @@ void PartSet_OperationEditLine::setSelected(boost::shared_ptr commit(); if (theFeature) - emit launchOperation("EditLine", theFeature); + emit launchOperation(PartSet_OperationEditLine::Type(), theFeature); } void PartSet_OperationEditLine::startOperation() { - //PartSet_OperationSketchBase::startOperation(); - //myPointSelectionMode = SM_FirstPoint; -} - -void PartSet_OperationEditLine::stopOperation() -{ - PartSet_OperationSketchBase::stopOperation(); - //myPointSelectionMode = SM_None; + // do nothing in order to do not create a new feature } boost::shared_ptr PartSet_OperationEditLine::createFeature() { + // do nothing in order to do not create a new feature return boost::shared_ptr(); } -void PartSet_OperationEditLine::setLinePoint(const gp_Pnt& thePoint, +void PartSet_OperationEditLine::moveLinePoint(double theDeltaX, double theDeltaY, const std::string& theAttribute) { boost::shared_ptr aData = feature()->data(); boost::shared_ptr aPoint = boost::dynamic_pointer_cast(aData->attribute(theAttribute)); - double aX = 0; - double anY = 0; - convertTo2D(thePoint, aX, anY); - aPoint->setValue(aX, anY); -} - -void PartSet_OperationEditLine::setLinePoint(boost::shared_ptr theSourceFeature, - const std::string& theSourceAttribute, - const std::string& theAttribute) -{ - boost::shared_ptr aData = theSourceFeature->data(); - boost::shared_ptr aPoint = - boost::dynamic_pointer_cast(aData->attribute(theSourceAttribute)); - double aX = aPoint->x(); - double anY = aPoint->y(); - - aData = feature()->data(); - aPoint = boost::dynamic_pointer_cast(aData->attribute(theAttribute)); - aPoint->setValue(aX, anY); -} - -void PartSet_OperationEditLine::convertTo2D(const gp_Pnt& thePoint, double& theX, double& theY) -{ - if (!mySketch) - return; - - boost::shared_ptr anAttr; - boost::shared_ptr aData = mySketch->data(); - - boost::shared_ptr anOrigin = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); - - boost::shared_ptr aX = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRX)); - boost::shared_ptr anY = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRY)); - - gp_Pnt aVec(thePoint.X() - anOrigin->x(), thePoint.Y() - anOrigin->y(), thePoint.Z() - anOrigin->z()); - theX = aVec.X() * aX->x() + aVec.Y() * aX->y() + aVec.Z() * aX->z(); - theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z(); + aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY); } diff --git a/src/PartSet/PartSet_OperationEditLine.h b/src/PartSet/PartSet_OperationEditLine.h index 5ce170bbc..28ae00298 100644 --- a/src/PartSet/PartSet_OperationEditLine.h +++ b/src/PartSet/PartSet_OperationEditLine.h @@ -10,6 +10,8 @@ #include #include +class QMouseEvent; + /*! \class PartSet_OperationEditLine * \brief The operation for the sketch feature creation @@ -17,6 +19,10 @@ class PARTSET_EXPORT PartSet_OperationEditLine : public PartSet_OperationSketchBase { Q_OBJECT +public: + /// Returns the operation type key + static std::string Type() { return "EditLine"; } + public: /// Constructor /// \param theId the feature identifier @@ -40,15 +46,14 @@ public: /// \param theFeature the feature virtual void init(boost::shared_ptr theFeature); - /// Gives the current selected objects to be processed by the operation + /// Processes the mouse pressed in the point /// \param thePoint a point clicked in the viewer - virtual void mouseReleased(const gp_Pnt& thePoint); + /// \param theEvent the mouse event + virtual void mousePressed(const gp_Pnt& thePoint, QMouseEvent* theEvent); /// Gives the current mouse point in the viewer /// \param thePoint a point clicked in the viewer - virtual void mouseMoved(const gp_Pnt& thePoint); - /// Processes the key pressed in the view - /// \param theKey a key value - virtual void keyReleased(const int theKey); + /// \param theEvent the mouse event + virtual void mouseMoved(const gp_Pnt& thePoint, QMouseEvent* theEvent); /// Gives the current selected objects to be processed by the operation /// \param theFeature the selected feature @@ -56,25 +61,12 @@ public: virtual void setSelected(boost::shared_ptr theFeature, const TopoDS_Shape& theShape); -signals: - /// signal about the sketch plane is selected - /// \param theX the value in the X direction of the plane - /// \param theX the value in the Y direction value of the plane - /// \param theX the value in the Z direction of the plane - void localContextChanged(boost::shared_ptr theFeature, - int theMode); - 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(); - /// \brief Virtual method called when operation is started - /// Virtual method called when operation stopped - committed or aborted. - /// After the parent operation body perform, reset selection point mode of the operation - virtual void stopOperation(); - /// Creates an operation new feature /// Returns NULL feature. This is an operation of edition, not creation. /// \returns the created feature @@ -82,30 +74,15 @@ protected: protected: /// \brief Save the point to the line. - /// \param thePoint the 3D point in the viewer - /// \param theAttribute the start or end attribute of the line - void setLinePoint(const gp_Pnt& thePoint, const std::string& theAttribute); - - /// \brief Set the point to the line by the point of the source line. - /// \param theSourceFeature the feature, where the point is obtained - /// \param theSourceAttribute the start or end attribute of the source line + /// \param theDeltaX the delta for X coordinate is moved + /// \param theDeltaY the delta for Y coordinate is moved /// \param theAttribute the start or end attribute of the line - void setLinePoint(boost::shared_ptr theSourceFeature, - const std::string& theSourceAttribute, - const std::string& theAttribute); - /// \brief Converts the 3D point to the projected coodinates on the sketch plane. - /// \param thePoint the 3D point in the viewer - /// \param theX the X coordinate - /// \param theY the Y coordinate - void convertTo2D(const gp_Pnt& thePoint, double& theX, double& theY); - -protected: - ///< Structure to lists the possible types of point selection modes - enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint, SM_None}; + void moveLinePoint(double theDeltaX, double theDeltaY, + const std::string& theAttribute); private: boost::shared_ptr mySketch; ///< the sketch feature - //PointSelectionMode myPointSelectionMode; ///< point selection mode + gp_Pnt myCurPressed; ///< the current 3D point clicked or moved }; #endif diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 8f2b4ae09..0fb183348 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -4,6 +4,8 @@ #include +#include + #include #include #include @@ -49,7 +51,7 @@ void PartSet_OperationSketch::setSelected(boost::shared_ptr th myIsEditMode = true; } else if (theFeature) - emit launchOperation("EditLine", theFeature); + emit launchOperation(PartSet_OperationEditLine::Type(), theFeature); } void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape) diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index 47cb5031f..b30ce2927 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -17,6 +17,10 @@ class PARTSET_EXPORT PartSet_OperationSketch : public PartSet_OperationSketchBase { Q_OBJECT +public: + /// Returns the operation type key + static std::string Type() { return "Sketch"; } + public: /// Constructor /// \param theId the feature identifier diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index aeeb7c842..a7bcf789a 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -15,6 +15,8 @@ #include #include +class QMouseEvent; + class GeomAPI_Shape; /*! @@ -55,13 +57,20 @@ public: virtual void setSelected(boost::shared_ptr theFeature, const TopoDS_Shape& theShape) {}; + /// Processes the mouse pressed in the point + /// \param thePoint a point clicked in the viewer + /// \param theEvent the mouse event + virtual void mousePressed(const gp_Pnt& thePoint, QMouseEvent* theEvent) {}; + /// Processes the mouse release in the point /// \param thePoint a point clicked in the viewer - virtual void mouseReleased(const gp_Pnt& thePoint) {}; + /// \param theEvent the mouse event + virtual void mouseReleased(const gp_Pnt& thePoint, QMouseEvent* theEvent) {}; /// Processes the mouse move in the point /// \param thePoint a 3D point clicked in the viewer - virtual void mouseMoved(const gp_Pnt& thePoint) {}; + /// \param theEvent the mouse event + virtual void mouseMoved(const gp_Pnt& thePoint, QMouseEvent* theEvent) {}; /// Processes the key pressed in the view /// \param theKey a key value diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp index e3a3c0f53..25bc76673 100644 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -4,14 +4,13 @@ #include +#include + #include #include -#include -#include #include #include -#include #include #ifdef _DEBUG @@ -47,7 +46,7 @@ std::list PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr< return aModes; } -void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint) +void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint, QMouseEvent* /*theEvent*/) { switch (myPointSelectionMode) { @@ -62,7 +61,6 @@ void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint) } break; case SM_None: { - } break; default: @@ -70,7 +68,7 @@ void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint) } } -void PartSet_OperationSketchLine::mouseMoved(const gp_Pnt& thePoint) +void PartSet_OperationSketchLine::mouseMoved(const gp_Pnt& thePoint, QMouseEvent* /*theEvent*/) { switch (myPointSelectionMode) { @@ -154,9 +152,8 @@ void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint, boost::shared_ptr aPoint = boost::dynamic_pointer_cast(aData->attribute(theAttribute)); - double aX = 0; - double anY = 0; - convertTo2D(thePoint, aX, anY); + double aX, anY; + PartSet_Tools::ConvertTo2D(thePoint, mySketch, aX, anY); aPoint->setValue(aX, anY); } @@ -174,24 +171,3 @@ void PartSet_OperationSketchLine::setLinePoint(boost::shared_ptr(aData->attribute(theAttribute)); aPoint->setValue(aX, anY); } - -void PartSet_OperationSketchLine::convertTo2D(const gp_Pnt& thePoint, double& theX, double& theY) -{ - if (!mySketch) - return; - - boost::shared_ptr anAttr; - boost::shared_ptr aData = mySketch->data(); - - boost::shared_ptr anOrigin = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); - - boost::shared_ptr aX = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRX)); - boost::shared_ptr anY = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRY)); - - gp_Pnt aVec(thePoint.X() - anOrigin->x(), thePoint.Y() - anOrigin->y(), thePoint.Z() - anOrigin->z()); - theX = aVec.X() * aX->x() + aVec.Y() * aX->y() + aVec.Z() * aX->z(); - theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z(); -} diff --git a/src/PartSet/PartSet_OperationSketchLine.h b/src/PartSet/PartSet_OperationSketchLine.h index 604baffa3..cab05194c 100644 --- a/src/PartSet/PartSet_OperationSketchLine.h +++ b/src/PartSet/PartSet_OperationSketchLine.h @@ -10,6 +10,8 @@ #include #include +class QMouseEvent; + /*! \class PartSet_OperationSketchLine * \brief The operation for the sketch feature creation @@ -17,6 +19,11 @@ class PARTSET_EXPORT PartSet_OperationSketchLine : public PartSet_OperationSketchBase { Q_OBJECT + +public: + /// Returns the operation type key + static std::string Type() { return "SketchLine"; } + public: /// Constructor /// \param theId the feature identifier @@ -38,22 +45,16 @@ public: /// Gives the current selected objects to be processed by the operation /// \param thePoint a point clicked in the viewer - virtual void mouseReleased(const gp_Pnt& thePoint); + /// \param theEvent the mouse event + virtual void mouseReleased(const gp_Pnt& thePoint, QMouseEvent* theEvent); /// Gives the current mouse point in the viewer /// \param thePoint a point clicked in the viewer - virtual void mouseMoved(const gp_Pnt& thePoint); + /// \param theEvent the mouse event + virtual void mouseMoved(const gp_Pnt& thePoint, QMouseEvent* theEvent); /// Processes the key pressed in the view /// \param theKey a key value virtual void keyReleased(const int theKey); -signals: - /// signal about the sketch plane is selected - /// \param theX the value in the X direction of the plane - /// \param theX the value in the Y direction value of the plane - /// \param theX the value in the Z direction of the plane - void localContextChanged(boost::shared_ptr theFeature, - int theMode); - protected: /// \brief Virtual method called when operation is started /// Virtual method called when operation started (see start() method for more description) @@ -84,11 +85,6 @@ protected: void setLinePoint(boost::shared_ptr theSourceFeature, const std::string& theSourceAttribute, const std::string& theAttribute); - /// \brief Converts the 3D point to the projected coodinates on the sketch plane. - /// \param thePoint the 3D point in the viewer - /// \param theX the X coordinate - /// \param theY the Y coordinate - void convertTo2D(const gp_Pnt& thePoint, double& theX, double& theY); protected: ///< Structure to lists the possible types of point selection modes diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 8afc9aec8..b2d24c396 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -9,12 +9,21 @@ #include #include +#include +#include +#include +#include +#include + #ifdef _DEBUG #include #endif gp_Pnt PartSet_Tools::ConvertClickToPoint(QPoint thePoint, Handle(V3d_View) theView) { + if (theView.IsNull()) + return gp_Pnt(); + V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt; theView->Eye( XEye, YEye, ZEye ); @@ -34,3 +43,25 @@ gp_Pnt PartSet_Tools::ConvertClickToPoint(QPoint thePoint, Handle(V3d_View) theV gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView ); return ResultPoint; } + +void PartSet_Tools::ConvertTo2D(const gp_Pnt& thePoint, boost::shared_ptr theSketch, + double& theX, double& theY) +{ + if (!theSketch) + return; + + boost::shared_ptr anAttr; + boost::shared_ptr aData = theSketch->data(); + + boost::shared_ptr anOrigin = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); + + boost::shared_ptr aX = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRX)); + boost::shared_ptr anY = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRY)); + + gp_Pnt aVec(thePoint.X() - anOrigin->x(), thePoint.Y() - anOrigin->y(), thePoint.Z() - anOrigin->z()); + theX = aVec.X() * aX->x() + aVec.Y() * aX->y() + aVec.Z() * aX->z(); + theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z(); +} diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 4139385d6..759f490d5 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -11,7 +11,10 @@ #include +#include + class Handle_V3d_View; +class ModelAPI_Feature; /*! \class PartSet_Tools @@ -25,6 +28,13 @@ public: /// \param theView a 3D view static gp_Pnt ConvertClickToPoint(QPoint thePoint, Handle_V3d_View theView); + /// \brief Converts the 3D point to the projected coodinates on the sketch plane. + /// \param thePoint the 3D point in the viewer + /// \param theSketch the sketch feature + /// \param theX the X coordinate + /// \param theY the Y coordinate + static void ConvertTo2D(const gp_Pnt& thePoint, boost::shared_ptr theSketch, + double& theX, double& theY); }; #endif diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index 2f4cca0ed..506748471 100644 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -8,8 +8,6 @@ #include #include -#include - #include #include #include -- 2.39.2