From: vsv Date: Mon, 28 Apr 2014 14:55:57 +0000 (+0400) Subject: Using of SelectionMgr instead of using Viewer directly in Sketcher starting operation X-Git-Tag: V_0.2~109^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=af3e1c3206761f41cbdf56b5ca4da2ac20c62193;p=modules%2Fshaper.git Using of SelectionMgr instead of using Viewer directly in Sketcher starting operation --- diff --git a/src/NewGeom/NewGeom_Module.cpp b/src/NewGeom/NewGeom_Module.cpp index ee68ba0c9..7285933d1 100644 --- a/src/NewGeom/NewGeom_Module.cpp +++ b/src/NewGeom/NewGeom_Module.cpp @@ -6,14 +6,16 @@ #include #include +#include +#include #include +#include #include #include #include - extern "C" { NewGeom_EXPORT CAM_Module* createModule() { return new NewGeom_Module(); @@ -64,6 +66,11 @@ bool NewGeom_Module::activateModule(SUIT_Study* theStudy) if (isDone) { setMenuShown( true ); setToolShown( true ); + + SUIT_ViewManager* aMgr = application()->viewManager(OCCViewer_Viewer::Type()); + if (aMgr) { + OCCViewer_Viewer* aViewer = static_cast(aMgr->getViewModel()); + } } return isDone; } @@ -173,4 +180,11 @@ Handle(AIS_InteractiveContext) NewGeom_Module::AISContext() const aContext = aViewer->getAISContext(); } return aContext; -} \ No newline at end of file +} + +//****************************************************** +void NewGeom_Module::selectionChanged() +{ + LightApp_Module::selectionChanged(); + //myWorkshop->salomeViewerSelectionChanged(); +} diff --git a/src/NewGeom/NewGeom_Module.h b/src/NewGeom/NewGeom_Module.h index 1440856ff..f8f2cb5c0 100644 --- a/src/NewGeom/NewGeom_Module.h +++ b/src/NewGeom/NewGeom_Module.h @@ -23,9 +23,11 @@ public: NewGeom_Module(); virtual ~NewGeom_Module(); + //----- LightAPP_Module interface --------------- virtual void initialize( CAM_Application* theApp); virtual void windows( QMap& theWndMap) const; virtual void viewManagers( QStringList& theList) const; + virtual void selectionChanged(); //--- XGUI connector interface ----- virtual void addFeature(const QString& theWBName, diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index c91631f06..4d0b8867e 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -42,8 +43,7 @@ PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop) 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()), + connect(myWorkshop->selector(), SIGNAL(selectionChanged()), this, SLOT(onViewSelectionChanged())); } @@ -136,10 +136,10 @@ void PartSet_Module::onViewSelectionChanged() ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); if (aPreviewOp) { - XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer(); - if (aViewer) { + XGUI_SelectionMgr* aSelector = myWorkshop->selector(); + if (aSelector) { NCollection_List aList; - aViewer->getSelectedShapes(aList); + aSelector->selectedShapes(aList); aPreviewOp->setSelectedShapes(aList); } } diff --git a/src/XGUI/XGUI_ObjectsBrowser.h b/src/XGUI/XGUI_ObjectsBrowser.h index 1b7e710c7..b0949534b 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.h +++ b/src/XGUI/XGUI_ObjectsBrowser.h @@ -24,7 +24,7 @@ public: XGUI_DocumentDataModel* dataModel() const { return myDocModel; } //! Returns list of currently selected features - QFeatureList selectedData() const { return mySelectedData; } + QFeatureList selectedFeatures() const { return mySelectedData; } signals: //! Emited when selection is changed diff --git a/src/XGUI/XGUI_SelectionMgr.cpp b/src/XGUI/XGUI_SelectionMgr.cpp index c2d2c3de3..efca3fde5 100644 --- a/src/XGUI/XGUI_SelectionMgr.cpp +++ b/src/XGUI/XGUI_SelectionMgr.cpp @@ -2,6 +2,8 @@ #include "XGUI_Workshop.h" #include "XGUI_MainWindow.h" #include "XGUI_ObjectsBrowser.h" +#include "XGUI_Viewer.h" +#include "XGUI_SalomeConnector.h" #include #include @@ -15,30 +17,80 @@ XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent) : { } -void XGUI_SelectionMgr::connectObjectBrowser(XGUI_ObjectsBrowser* theOB) +XGUI_SelectionMgr::~XGUI_SelectionMgr() { - myObjectBrowser = theOB; - connect(myObjectBrowser, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); } -XGUI_SelectionMgr::~XGUI_SelectionMgr() +//************************************************************** +void XGUI_SelectionMgr::connectViewers() { + connect(myWorkshop->objectBrowser(), SIGNAL(selectionChanged()), + this, SLOT(onObjectBrowserSelection())); + + //Connect to other viewers + if (myWorkshop->isSalomeMode()) { + connect(myWorkshop, SIGNAL(salomeViewerSelection()), + this, SLOT(onViewerSelection())); + } else { + connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()), + this, SLOT(onViewerSelection())); + } } -void XGUI_SelectionMgr::onSelectionChanged() +//************************************************************** +void XGUI_SelectionMgr::onObjectBrowserSelection() { - XGUI_ObjectsBrowser* aObjBrowser = myWorkshop->objectBrowser(); - mySelectedData = aObjBrowser->selectedData(); - - // Set current document - if (mySelectedData.size() > 0) { - FeaturePtr aFeature = mySelectedData.first(); - - boost::shared_ptr aMgr = ModelAPI_PluginManager::get(); - boost::shared_ptr aDocRef = aFeature->data()->docRef("PartDocument"); - if (aDocRef) - aMgr->setCurrentDocument(aDocRef->value()); - } + + // TODO: Highliht selected objects in Viewer 3d emit selectionChanged(); +} + +//************************************************************** +void XGUI_SelectionMgr::onViewerSelection() +{ + emit selectionChanged(); +} + +//************************************************************** +QFeatureList XGUI_SelectionMgr::selectedFeatures() const +{ + return myWorkshop->objectBrowser()->selectedFeatures(); +} + +//************************************************************** +QModelIndexList XGUI_SelectionMgr::selectedIndexes() const +{ + return myWorkshop->objectBrowser()->selectionModel()->selectedIndexes(); +} + +//************************************************************** +void XGUI_SelectionMgr::selectedAISObjects(AIS_ListOfInteractive& theList) const +{ + if (myWorkshop->isSalomeMode()) { + Handle(AIS_InteractiveContext) aContext = myWorkshop->salomeConnector()->AISContext(); + theList.Clear(); + for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) + theList.Append(aContext->SelectedInteractive()); + } else { + XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer(); + aViewer->getSelectedObjects(theList); + } +} + +//************************************************************** +void XGUI_SelectionMgr::selectedShapes(NCollection_List& theList) const +{ + if (myWorkshop->isSalomeMode()) { + theList.Clear(); + Handle(AIS_InteractiveContext) aContext = myWorkshop->salomeConnector()->AISContext(); + for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { + TopoDS_Shape aShape = aContext->SelectedShape(); + if (!aShape.IsNull()) + theList.Append(aShape); + } + } else { + XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer(); + aViewer->getSelectedShapes(theList); + } } \ No newline at end of file diff --git a/src/XGUI/XGUI_SelectionMgr.h b/src/XGUI/XGUI_SelectionMgr.h index 91b4c255f..b75989abb 100644 --- a/src/XGUI/XGUI_SelectionMgr.h +++ b/src/XGUI/XGUI_SelectionMgr.h @@ -4,6 +4,11 @@ #include "XGUI.h" #include "XGUI_Constants.h" #include +#include + +#include +#include +#include class XGUI_Workshop; class XGUI_ObjectsBrowser; @@ -20,24 +25,32 @@ public: XGUI_SelectionMgr(XGUI_Workshop* theParent); virtual ~XGUI_SelectionMgr(); - //! Returns list of currently selected objects - QFeatureList selectedData() const { return mySelectedData; } + //! Returns list of currently selected data objects + QFeatureList selectedFeatures() const; + + //! Returns list of currently selected QModelIndexes + QModelIndexList selectedIndexes() const; + + //! Returns list of currently selected AIS objects + void selectedAISObjects(AIS_ListOfInteractive& theList) const; + + //! Returns list of currently selected shapes + void selectedShapes(NCollection_List& theList) const; - void connectObjectBrowser(XGUI_ObjectsBrowser* theOB); + //! Connects the manager to all viewers accessible by Workshop + void connectViewers(); signals: //! Emited when selection in a one of viewers was changed void selectionChanged(); -public slots: - void onSelectionChanged(); +private slots: + void onObjectBrowserSelection(); + void onViewerSelection(); private: - XGUI_Workshop* myWorkshop; - XGUI_ObjectsBrowser* myObjectBrowser; - //! List of selected features - QFeatureList mySelectedData; + XGUI_Workshop* myWorkshop; }; #endif diff --git a/src/XGUI/XGUI_ViewWindow.cpp b/src/XGUI/XGUI_ViewWindow.cpp index f02499857..2c4809cb8 100644 --- a/src/XGUI/XGUI_ViewWindow.cpp +++ b/src/XGUI/XGUI_ViewWindow.cpp @@ -1166,13 +1166,5 @@ void XGUI_ViewWindow::updateToolBar() myGripWgt->update(); myViewBar->update(); myWindowBar->update(); - //QTimer::singleShot(50, Qt::VeryCoarseTimer, this, SLOT(repaintToolBar())); } -/*void XGUI_ViewWindow::repaintToolBar() -{ - QApplication::sync(); - myGripWgt->repaint(); - myViewBar->repaint(); - myWindowBar->repaint(); -}*/ diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index b453a3ec9..51bc022d5 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -59,6 +59,7 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) // So, displayer will be created on demand. mySelector = new XGUI_SelectionMgr(this); + connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(changeCurrentDocument())); myOperationMgr = new XGUI_OperationMgr(this); connect(myOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted())); connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), @@ -319,7 +320,7 @@ void XGUI_Workshop::onNew() QApplication::setOverrideCursor(Qt::WaitCursor); if (objectBrowser() == 0) { createDockWidgets(); - mySelector->connectObjectBrowser(objectBrowser()); + mySelector->connectViewers(); } showObjectBrowser(); if (!isSalomeMode()) { @@ -609,3 +610,25 @@ XGUI_Displayer* XGUI_Workshop::displayer() const } return myDisplayer; } + +//****************************************************** +void XGUI_Workshop::changeCurrentDocument() +{ + QFeatureList aFeatures = objectBrowser()->selectedFeatures(); + + // Set current document + if (aFeatures.size() > 0) { + FeaturePtr aFeature = aFeatures.first(); + + boost::shared_ptr aMgr = ModelAPI_PluginManager::get(); + boost::shared_ptr aDocRef = aFeature->data()->docRef("PartDocument"); + if (aDocRef) + aMgr->setCurrentDocument(aDocRef->value()); + } +} + +//****************************************************** +void XGUI_Workshop::salomeViewerSelectionChanged() +{ + emit salomeViewerSelection(); +} \ No newline at end of file diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 937aca383..5ea558ca2 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -71,6 +71,11 @@ public: //! Returns Object browser XGUI_ObjectsBrowser* objectBrowser() const { return myObjectBrowser; } + void salomeViewerSelectionChanged(); + +signals: + void salomeViewerSelection(); + public slots: void updateCommandStatus(); @@ -89,6 +94,8 @@ public slots: void onFeatureTriggered(); + void changeCurrentDocument(); + protected: //Event-loop processing methods: void addFeature(const Config_FeatureMessage*);