From 421ddd55c279e4eeb88f1ecaa6d8cebe5c497898 Mon Sep 17 00:00:00 2001 From: vsv Date: Tue, 29 Apr 2014 16:43:40 +0400 Subject: [PATCH] Provide selection mechanism from SALOME (issue #31) --- src/NewGeom/NewGeom_Module.cpp | 47 +++++++++++++++++++++++------ src/NewGeom/NewGeom_Module.h | 16 +++++++--- src/NewGeom/NewGeom_OCCSelector.cpp | 26 ++++++++++++++++ src/NewGeom/NewGeom_OCCSelector.h | 19 ++++++++++++ src/XGUI/XGUI_Viewer.h | 2 -- 5 files changed, 95 insertions(+), 15 deletions(-) create mode 100644 src/NewGeom/NewGeom_OCCSelector.cpp create mode 100644 src/NewGeom/NewGeom_OCCSelector.h diff --git a/src/NewGeom/NewGeom_Module.cpp b/src/NewGeom/NewGeom_Module.cpp index 7285933d1..f56deda0d 100644 --- a/src/NewGeom/NewGeom_Module.cpp +++ b/src/NewGeom/NewGeom_Module.cpp @@ -2,6 +2,7 @@ #include "NewGeom_Module.h" #include "NewGeom_DataModel.h" +#include "NewGeom_OCCSelector.h" #include @@ -20,7 +21,7 @@ extern "C" { NewGeom_EXPORT CAM_Module* createModule() { return new NewGeom_Module(); } - + NewGeom_EXPORT char* getModuleVersion() { return "0.0"; } @@ -29,7 +30,7 @@ extern "C" { //****************************************************** NewGeom_Module::NewGeom_Module() -: LightApp_Module( "NewGeom" ) +: LightApp_Module( "NewGeom" ), mySelector(0) { myWorkshop = new XGUI_Workshop(this); } @@ -67,14 +68,43 @@ bool NewGeom_Module::activateModule(SUIT_Study* theStudy) setMenuShown( true ); setToolShown( true ); - SUIT_ViewManager* aMgr = application()->viewManager(OCCViewer_Viewer::Type()); - if (aMgr) { - OCCViewer_Viewer* aViewer = static_cast(aMgr->getViewModel()); + if (!mySelector) { + ViewManagerList OCCViewManagers; + application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers); + if (OCCViewManagers.size() > 0) { + mySelector = createSelector(OCCViewManagers.first()); + } } } return isDone; } +//****************************************************** +void NewGeom_Module::onViewManagerAdded( SUIT_ViewManager* theMgr ) +{ + if ((!mySelector)) { + mySelector = createSelector(theMgr); + } +} + +//****************************************************** +NewGeom_OCCSelector* NewGeom_Module::createSelector(SUIT_ViewManager* theMgr) +{ + if (theMgr->getType() == OCCViewer_Viewer::Type()) { + OCCViewer_Viewer* aViewer = static_cast(theMgr->getViewModel()); + NewGeom_OCCSelector* aSelector = new NewGeom_OCCSelector(aViewer, + getApp()->selectionMgr()); + LightApp_SelectionMgr* aMgr = getApp()->selectionMgr(); + QList aList; + aMgr->selectors(aList); + foreach(SUIT_Selector* aSel, aList) { + aSel->setEnabled(aSel == aSelector); + } + return aSelector; + } + return 0; +} + //****************************************************** bool NewGeom_Module::deactivateModule(SUIT_Study* theStudy) { @@ -174,9 +204,8 @@ QAction* NewGeom_Module::command(const QString& theId) const Handle(AIS_InteractiveContext) NewGeom_Module::AISContext() const { Handle(AIS_InteractiveContext) aContext; - SUIT_ViewManager* aMgr = application()->viewManager(OCCViewer_Viewer::Type()); - if (aMgr) { - OCCViewer_Viewer* aViewer = static_cast(aMgr->getViewModel()); + OCCViewer_Viewer* aViewer = mySelector->viewer(); + if (aViewer) { aContext = aViewer->getAISContext(); } return aContext; @@ -186,5 +215,5 @@ Handle(AIS_InteractiveContext) NewGeom_Module::AISContext() const void NewGeom_Module::selectionChanged() { LightApp_Module::selectionChanged(); - //myWorkshop->salomeViewerSelectionChanged(); + myWorkshop->salomeViewerSelectionChanged(); } diff --git a/src/NewGeom/NewGeom_Module.h b/src/NewGeom/NewGeom_Module.h index f8f2cb5c0..be58a3602 100644 --- a/src/NewGeom/NewGeom_Module.h +++ b/src/NewGeom/NewGeom_Module.h @@ -10,8 +10,9 @@ #include -class XGUI_Workshop; - +class XGUI_Workshop; +class NewGeom_OCCSelector; +class OCCViewer_Viewer; /** * An implementation of SALOME connector class for implementation of * XGUI functionality as a module of SALOME @@ -61,17 +62,24 @@ public: virtual Handle(AIS_InteractiveContext) AISContext() const; public slots: - bool activateModule( SUIT_Study* theStudy); - bool deactivateModule( SUIT_Study* theStudy); + virtual bool activateModule( SUIT_Study* theStudy); + virtual bool deactivateModule( SUIT_Study* theStudy); + +protected slots: + virtual void onViewManagerAdded( SUIT_ViewManager* theMgr ); protected: CAM_DataModel* createDataModel(); private: + NewGeom_OCCSelector* createSelector(SUIT_ViewManager* theMgr); + QStringList myActionsList; XGUI_Workshop* myWorkshop; + + NewGeom_OCCSelector* mySelector; }; #endif diff --git a/src/NewGeom/NewGeom_OCCSelector.cpp b/src/NewGeom/NewGeom_OCCSelector.cpp new file mode 100644 index 000000000..b7442acb4 --- /dev/null +++ b/src/NewGeom/NewGeom_OCCSelector.cpp @@ -0,0 +1,26 @@ +#include "NewGeom_OCCSelector.h" + +NewGeom_OCCSelector::NewGeom_OCCSelector( OCCViewer_Viewer* theViewer, + SUIT_SelectionMgr* theMgr) +: LightApp_OCCSelector(theViewer, theMgr) +{ +} + +NewGeom_OCCSelector::~NewGeom_OCCSelector() +{ +} + +void NewGeom_OCCSelector::getSelection( SUIT_DataOwnerPtrList& thePtrList ) const +{ + OCCViewer_Viewer* vw = viewer(); + if (!vw) + return; +} + +void NewGeom_OCCSelector::setSelection( const SUIT_DataOwnerPtrList& thePtrList ) +{ + OCCViewer_Viewer* vw = viewer(); + if (!vw) + return; + +} diff --git a/src/NewGeom/NewGeom_OCCSelector.h b/src/NewGeom/NewGeom_OCCSelector.h new file mode 100644 index 000000000..ae6b1cbea --- /dev/null +++ b/src/NewGeom/NewGeom_OCCSelector.h @@ -0,0 +1,19 @@ +#ifndef NewGeom_OCCSelector_H +#define NewGeom_OCCSelector_H + +#include "NewGeom.h" + +#include + +class NewGeom_EXPORT NewGeom_OCCSelector : public LightApp_OCCSelector +{ +public: + NewGeom_OCCSelector( OCCViewer_Viewer* theViewer, SUIT_SelectionMgr* theMgr ); + virtual ~NewGeom_OCCSelector(); + +protected: + virtual void getSelection( SUIT_DataOwnerPtrList& theList ) const; + virtual void setSelection( const SUIT_DataOwnerPtrList& theList ); +}; + +#endif \ No newline at end of file diff --git a/src/XGUI/XGUI_Viewer.h b/src/XGUI/XGUI_Viewer.h index b422e4034..466951c7a 100644 --- a/src/XGUI/XGUI_Viewer.h +++ b/src/XGUI/XGUI_Viewer.h @@ -149,8 +149,6 @@ 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*); -- 2.39.2