From: nds Date: Mon, 28 Apr 2014 13:11:15 +0000 (+0400) Subject: refs #30 - Sketch base GUI: create, draw lines X-Git-Tag: V_0.2~112^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=973230a6a9b5c239063e3f7ae7a74601238b2a5f;p=modules%2Fshaper.git refs #30 - Sketch base GUI: create, draw lines Line visualization by the mouse click/move --- diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 519efbf13..f31a292e0 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -16,8 +16,6 @@ #include #include -#include - #ifdef _DEBUG #include #endif diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 5a999aaba..3744b2d4c 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -5,17 +5,21 @@ SET(CMAKE_AUTOMOC ON) SET(PROJECT_HEADERS PartSet.h + PartSet_Listener.h PartSet_Module.h PartSet_OperationSketchBase.h PartSet_OperationSketch.h PartSet_OperationSketchLine.h + PartSet_Tools.h ) SET(PROJECT_SOURCES + PartSet_Listener.cpp PartSet_Module.cpp PartSet_OperationSketchBase.cpp PartSet_OperationSketch.cpp PartSet_OperationSketchLine.cpp + PartSet_Tools.cpp ) SET(PROJECT_RESOURCES @@ -47,6 +51,7 @@ SOURCE_GROUP ("Resource Files" FILES ${TEXT_RESOURCES} ${PROJECT_RESOURCES}) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/XGUI ${CMAKE_SOURCE_DIR}/src/Config ${CMAKE_SOURCE_DIR}/src/Events + ${CMAKE_SOURCE_DIR}/src/Model ${CMAKE_SOURCE_DIR}/src/ModuleBase ${CMAKE_SOURCE_DIR}/src/ModelAPI ${CMAKE_SOURCE_DIR}/src/GeomDataAPI diff --git a/src/PartSet/PartSet_Listener.cpp b/src/PartSet/PartSet_Listener.cpp new file mode 100644 index 000000000..580186b56 --- /dev/null +++ b/src/PartSet/PartSet_Listener.cpp @@ -0,0 +1,37 @@ +// File: PartSet_Listener.h +// Created: 28 Apr 2014 +// Author: Natalia ERMOLAEVA + +#include + +#include + +#include +#include + +#ifdef _DEBUG +#include +#endif + +using namespace std; + +PartSet_Listener::PartSet_Listener(PartSet_Module* theModule) +: myModule(theModule) +{ + Events_Loop* aLoop = Events_Loop::loop(); + Events_ID aFeatureUpdatedId = aLoop->eventByName(EVENT_FEATURE_UPDATED); + aLoop->registerListener(this, aFeatureUpdatedId); +} + +PartSet_Listener::~PartSet_Listener() +{ +} + +//****************************************************** +void PartSet_Listener::processEvent(const Events_Message* theMessage) +{ + if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_UPDATED) + { + myModule->visualizePreview(true); + } +} diff --git a/src/PartSet/PartSet_Listener.h b/src/PartSet/PartSet_Listener.h new file mode 100644 index 000000000..051224554 --- /dev/null +++ b/src/PartSet/PartSet_Listener.h @@ -0,0 +1,35 @@ +// File: PartSet_Listener.h +// Created: 28 Apr 2014 +// Author: Natalia ERMOLAEVA + +#ifndef PartSet_Listener_H +#define PartSet_Listener_H + +#include "PartSet.h" + +#include + +class PartSet_Module; + +/*! + \class PartSet_Listener + * \brief The operation for the sketch feature creation +*/ +class PARTSET_EXPORT PartSet_Listener : public Events_Listener +{ +public: + /// Constructor + /// \param theId the feature identifier + /// \param theParent the operation parent + PartSet_Listener(PartSet_Module* theModule); + /// Destructor + virtual ~PartSet_Listener(); + + /// This method is called by loop when the event is started to process. + virtual void processEvent(const Events_Message* theMessage); + +private: + PartSet_Module* myModule; ///< the current module +}; + +#endif diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index c91631f06..b6ae9bfe0 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include @@ -9,6 +11,8 @@ #include #include #include +#include +#include #include #include @@ -37,14 +41,19 @@ extern "C" PARTSET_EXPORT XGUI_Module* createModule(XGUI_Workshop* theWshop) PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop) { myWorkshop = theWshop; + myListener = new PartSet_Listener(this); + XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr(); connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted())); connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), this, SLOT(onOperationStopped(ModuleBase_Operation*))); - if (!myWorkshop->isSalomeMode()) - connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()), - this, SLOT(onViewSelectionChanged())); + if (!myWorkshop->isSalomeMode()) { + connect(myWorkshop->mainWindow()->viewer(), SIGNAL(mouseReleased(QPoint)), + this, SLOT(onMouseReleased(QPoint))); + connect(myWorkshop->mainWindow()->viewer(), SIGNAL(mouseMoved(QPoint)), + this, SLOT(onMouseMoved(QPoint))); + } } PartSet_Module::~PartSet_Module() @@ -131,7 +140,7 @@ void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation) visualizePreview(false); } -void PartSet_Module::onViewSelectionChanged() +void PartSet_Module::onMouseReleased(QPoint thePoint) { ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); @@ -140,7 +149,33 @@ void PartSet_Module::onViewSelectionChanged() if (aViewer) { NCollection_List aList; aViewer->getSelectedShapes(aList); - aPreviewOp->setSelectedShapes(aList); + XGUI_ViewWindow* aWindow = aViewer->activeViewWindow(); + if (aWindow) { + Handle(V3d_View) aView3d = aWindow->viewPort()->getView(); + if ( !aView3d.IsNull() ) { + gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(thePoint, aView3d); + aPreviewOp->setSelectedShapes(aList, aPoint); + } + } + } + } +} + +void PartSet_Module::onMouseMoved(QPoint thePoint) +{ + ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); + PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); + if (aPreviewOp) { + XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer(); + if (aViewer) { + XGUI_ViewWindow* aWindow = aViewer->activeViewWindow(); + if (aWindow) { + Handle(V3d_View) aView3d = aWindow->viewPort()->getView(); + if ( !aView3d.IsNull() ) { + gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(thePoint, aView3d); + aPreviewOp->setMouseMovePoint(aPoint); + } + } } } } @@ -163,14 +198,16 @@ void PartSet_Module::visualizePreview(bool isDisplay) if (!aPreviewOp) return; + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); if (isDisplay) { boost::shared_ptr aPreview = aPreviewOp->preview(); - if (aPreview) - myWorkshop->displayer()->LocalSelection(anOperation->feature(), + if (aPreview) { + aDisplayer->LocalSelection(anOperation->feature(), aPreview->impl(), aPreviewOp->getSelectionMode()); + } } else { - myWorkshop->displayer()->GlobalSelection(false); - myWorkshop->displayer()->Erase(anOperation->feature()); + aDisplayer->GlobalSelection(false); + aDisplayer->Erase(anOperation->feature()); } } diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 523a15ad2..d210fc513 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -11,6 +11,8 @@ #include +class PartSet_Listener; + class PARTSET_EXPORT PartSet_Module: public QObject, public XGUI_Module { Q_OBJECT @@ -25,6 +27,10 @@ public: virtual void launchOperation(const QString& theCmdId); + /// Displays or erase the current operation preview, if it has it. + /// \param isDisplay the state whether the presentation should be displayed or erased + void visualizePreview(bool isDisplay); + public slots: void onFeatureTriggered(); /// SLOT, that is called after the operation is started. Perform some specific for module @@ -35,20 +41,21 @@ public slots: void onOperationStopped(ModuleBase_Operation* theOperation); /// SLOT, that is called by the selection in the viewer is changed. /// The selection is sent to the current operation if it listen the selection. - void onViewSelectionChanged(); + void onMouseReleased(QPoint thePoint); + /// SLOT, that is called by the selection in the viewer is changed. + /// The selection is sent to the current operation if it listen the selection. + /// \thePoint the mouse point + void onMouseMoved(QPoint thePoint); + /// SLOT, to apply to the current viewer the operation /// \param theX the X projection value /// \param theY the Y projection value /// \param theZ the Z projection value void onViewerProjectionChange(double theX, double theY, double theZ); -private: - /// Displays or erase the current operation preview, if it has it. - /// \param isDisplay the state whether the presentation should be displayed or erased - void visualizePreview(bool isDisplay); - private: XGUI_Workshop* myWorkshop; + PartSet_Listener* myListener; std::map myFeaturesInFiles; }; diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 32a2199b8..48bd5f0e3 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -35,7 +35,8 @@ int PartSet_OperationSketch::getSelectionMode() const return TopAbs_FACE; } -void PartSet_OperationSketch::setSelectedShapes(const NCollection_List& theList) +void PartSet_OperationSketch::setSelectedShapes(const NCollection_List& theList, + const gp_Pnt& theSelectedPoint) { if (theList.IsEmpty()) return; diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index 4a4fd74bc..021a8c8cd 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -31,7 +31,9 @@ public: /// Gives the current selected objects to be processed by the operation /// \param theList a list of interactive selected shapes - virtual void setSelectedShapes(const NCollection_List& theList); + /// \param theSelectedPoint a point clidked in the viewer + virtual void setSelectedShapes(const NCollection_List& theList, + const gp_Pnt& theSelectedPoint); }; #endif diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index 916ebc466..0e6c24263 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -8,6 +8,7 @@ #include "PartSet.h" #include +#include #include #include @@ -39,8 +40,13 @@ public: virtual int getSelectionMode() const = 0; /// Gives the current selected objects to be processed by the operation - /// \param a list of interactive selected objects - virtual void setSelectedShapes(const NCollection_List& theList) = 0; + /// \param theList a list of interactive selected shapes + /// \param theSelectedPoint a 3D selected point + virtual void setSelectedShapes(const NCollection_List& theList, + const gp_Pnt& thePoint) = 0; + /// Gives the current mouse point in the viewer + /// \param thePoint a point clidked in the viewer + virtual void setMouseMovePoint(const gp_Pnt& thePoint) {}; signals: void viewerProjectionChange(double theX, double theY, double theZ); diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp index 6ceda06f1..57d5f7646 100644 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -5,6 +5,10 @@ #include #include +#include +#include + +#include #ifdef _DEBUG #include @@ -15,7 +19,8 @@ using namespace std; PartSet_OperationSketchLine::PartSet_OperationSketchLine(const QString& theId, QObject* theParent, boost::shared_ptr theFeature) -: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature) +: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature), + myPointSelectionMode(SM_FirstPoint) { } @@ -30,13 +35,40 @@ bool PartSet_OperationSketchLine::isGranted() const int PartSet_OperationSketchLine::getSelectionMode() const { - return TopAbs_FACE; + return 0;//TopAbs_FACE; } -void PartSet_OperationSketchLine::setSelectedShapes(const NCollection_List& theList) +void PartSet_OperationSketchLine::setSelectedShapes(const NCollection_List& theList, + const gp_Pnt& thePoint) { if (theList.IsEmpty()) return; + + switch (myPointSelectionMode) + { + case SM_FirstPoint: { + setLinePoint(thePoint, LINE_ATTR_START); + myPointSelectionMode = SM_SecondPoint; + } + break; + case SM_SecondPoint: { + setLinePoint(thePoint, LINE_ATTR_END); + commit(); + } + break; + case SM_None: { + + } + break; + default: + break; + } +} + +void PartSet_OperationSketchLine::setMouseMovePoint(const gp_Pnt& thePoint) +{ + if (myPointSelectionMode == SM_SecondPoint) + setLinePoint(thePoint, LINE_ATTR_END); } void PartSet_OperationSketchLine::startOperation() @@ -49,4 +81,23 @@ void PartSet_OperationSketchLine::startOperation() aFeature->addSub(feature()); } + myPointSelectionMode = SM_FirstPoint; } + +void PartSet_OperationSketchLine::stopOperation() +{ + PartSet_OperationSketchBase::stopOperation(); + + myPointSelectionMode = SM_None; +} + +void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint, + const std::string& theAttribute) +{ + boost::shared_ptr aData = feature()->data(); + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(theAttribute)); + double aX = thePoint.X(), anY = thePoint.Y(); + aPoint->setValue(aX, anY); +} + diff --git a/src/PartSet/PartSet_OperationSketchLine.h b/src/PartSet/PartSet_OperationSketchLine.h index 737c73c36..27a03a43f 100644 --- a/src/PartSet/PartSet_OperationSketchLine.h +++ b/src/PartSet/PartSet_OperationSketchLine.h @@ -37,7 +37,12 @@ public: /// Gives the current selected objects to be processed by the operation /// \param theList a list of interactive selected shapes - virtual void setSelectedShapes(const NCollection_List& theList); + /// \param theSelectedPoint a point clidked in the viewer + virtual void setSelectedShapes(const NCollection_List& theList, + const gp_Pnt& thePoint); + /// Gives the current mouse point in the viewer + /// \param thePoint a point clidked in the viewer + virtual void setMouseMovePoint(const gp_Pnt& thePoint); protected: /// \brief Virtual method called when operation is started @@ -45,8 +50,24 @@ protected: /// 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(); + +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); + +protected: + ///< Structure to lists the possible types of point selection modes + enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint, SM_None}; + private: boost::shared_ptr mySketch; ///< the sketch feature + PointSelectionMode myPointSelectionMode; ///< point selection mode }; #endif diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp new file mode 100644 index 000000000..8afc9aec8 --- /dev/null +++ b/src/PartSet/PartSet_Tools.cpp @@ -0,0 +1,36 @@ +// File: PartSet_Tools.h +// Created: 28 Apr 2014 +// Author: Natalia ERMOLAEVA + +#include + +#include +#include +#include +#include + +#ifdef _DEBUG +#include +#endif + +gp_Pnt PartSet_Tools::ConvertClickToPoint(QPoint thePoint, Handle(V3d_View) theView) +{ + V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt; + theView->Eye( XEye, YEye, ZEye ); + + theView->At( XAt, YAt, ZAt ); + gp_Pnt EyePoint( XEye, YEye, ZEye ); + gp_Pnt AtPoint( XAt, YAt, ZAt ); + + gp_Vec EyeVector( EyePoint, AtPoint ); + gp_Dir EyeDir( EyeVector ); + + gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir ); + Standard_Real X, Y, Z; + theView->Convert( thePoint.x(), thePoint.y(), X, Y, Z ); + gp_Pnt ConvertedPoint( X, Y, Z ); + + gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint ); + gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView ); + return ResultPoint; +} diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h new file mode 100644 index 000000000..4139385d6 --- /dev/null +++ b/src/PartSet/PartSet_Tools.h @@ -0,0 +1,30 @@ +// File: PartSet_Tools.h +// Created: 28 Apr 2014 +// Author: Natalia ERMOLAEVA + +#ifndef PartSet_Tools_H +#define PartSet_Tools_H + +#include "PartSet.h" + +#include + +#include + +class Handle_V3d_View; + +/*! + \class PartSet_Tools + * \brief The operation for the sketch feature creation +*/ +class PARTSET_EXPORT PartSet_Tools +{ +public: + /// Converts the 2D screen point to the 3D point on the view according to the point of view + /// \param thePoint a screen point + /// \param theView a 3D view + static gp_Pnt ConvertClickToPoint(QPoint thePoint, Handle_V3d_View theView); + +}; + +#endif diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 5b510bbb6..41c912f1a 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -22,6 +22,11 @@ XGUI_Displayer::~XGUI_Displayer() { } +bool XGUI_Displayer::IsVisible(boost::shared_ptr theFeature) +{ + return myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end(); +} + void XGUI_Displayer::Display(boost::shared_ptr theFeature, const bool isUpdateViewer) { @@ -73,6 +78,10 @@ void XGUI_Displayer::LocalSelection(boost::shared_ptr theFeatu const int theMode, const bool isUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); + + if (IsVisible(theFeature)) { + Erase(theFeature, false); + } Handle(AIS_Shape) anAIS = new AIS_Shape(theShape); std::vector aDispAIS; diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 319a07a5e..b6967a2ab 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -38,6 +38,10 @@ public: /// or can not be initialized in constructor void setAISContext(const Handle(AIS_InteractiveContext)& theAIS); + /// Returns the feature visibility state. + /// \param theFeature a feature instance + bool IsVisible(boost::shared_ptr theFeature); + /// Display the feature. Obtain the visualized object from the feature. /// \param theFeature a feature instance /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly diff --git a/src/XGUI/XGUI_Viewer.cpp b/src/XGUI/XGUI_Viewer.cpp index 0d93d6cc0..23560ca86 100644 --- a/src/XGUI/XGUI_Viewer.cpp +++ b/src/XGUI/XGUI_Viewer.cpp @@ -190,6 +190,10 @@ QMdiSubWindow* XGUI_Viewer::createView(V3d_TypeOfView theType) return aWnd; } +XGUI_ViewWindow* XGUI_Viewer::activeViewWindow() const +{ + return dynamic_cast(myActiveView->widget()); +} void XGUI_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList) { @@ -502,8 +506,10 @@ void XGUI_Viewer::onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent) XGUI_ViewPort* aViewPort = theWindow->viewPort(); Handle(V3d_View) aView3d = aViewPort->getView(); - if ( !aView3d.IsNull() ) + if ( !aView3d.IsNull() ) { myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d); + mouseMoved(theEvent->pos()); + } } /*! @@ -513,5 +519,5 @@ void XGUI_Viewer::onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEv { myAISContext->Select(); - emit selectionChanged(); + emit mouseReleased(theEvent->pos()); } diff --git a/src/XGUI/XGUI_Viewer.h b/src/XGUI/XGUI_Viewer.h index 784ddd3cf..23d66656a 100644 --- a/src/XGUI/XGUI_Viewer.h +++ b/src/XGUI/XGUI_Viewer.h @@ -14,6 +14,8 @@ #include #include +#include + class XGUI_MainWindow; class QMdiSubWindow; class XGUI_ViewWindow; @@ -57,6 +59,9 @@ public: return myAISContext; } + //! Returns an active view window or NULL + XGUI_ViewWindow* activeViewWindow() const; + /// Return objects selected in 3D viewer /// \param theList - list to be filled with selected objects void getSelectedObjects(AIS_ListOfInteractive& theList); @@ -137,6 +142,8 @@ signals: void keyRelease(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent); void activated(XGUI_ViewWindow* theWindow); void selectionChanged(); + void mouseReleased(QPoint thePoint); + void mouseMoved(QPoint thePoint); public slots: void onWindowMinimized(QMdiSubWindow*);