]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Using of SelectionMgr instead of using Viewer directly in Sketcher starting operation
authorvsv <vitaly.smetannikov@opencascade.com>
Mon, 28 Apr 2014 14:55:57 +0000 (18:55 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Mon, 28 Apr 2014 14:55:57 +0000 (18:55 +0400)
src/NewGeom/NewGeom_Module.cpp
src/NewGeom/NewGeom_Module.h
src/PartSet/PartSet_Module.cpp
src/XGUI/XGUI_ObjectsBrowser.h
src/XGUI/XGUI_SelectionMgr.cpp
src/XGUI/XGUI_SelectionMgr.h
src/XGUI/XGUI_ViewWindow.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index ee68ba0c91d0ac5947dec781ea33d085fa4206d7..7285933d12304a230923c714c7e4c3206a733da5 100644 (file)
@@ -6,14 +6,16 @@
 #include <XGUI_Workshop.h>
 
 #include <LightApp_Application.h>
+#include <LightApp_SelectionMgr.h>
+#include <LightApp_OCCSelector.h>
 #include <OCCViewer_ViewModel.h>
+#include <SUIT_Selector.h>
 
 #include <SUIT_Desktop.h>
 #include <SUIT_ViewManager.h>
 
 #include <QtxActionMenuMgr.h>
 
-
 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<OCCViewer_Viewer*>(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();
+}
index 1440856ff903be33b98a8ea4034e6ab6a1b6ee30..f8f2cb5c07b9c3bb9e9b7205f119abb31ebebe1b 100644 (file)
@@ -23,9 +23,11 @@ public:
   NewGeom_Module();
   virtual ~NewGeom_Module();
 
+  //----- LightAPP_Module interface ---------------
   virtual void initialize( CAM_Application* theApp);
   virtual void windows( QMap<int, int>& theWndMap) const;
   virtual void viewManagers( QStringList& theList) const;
+  virtual void selectionChanged();
 
   //--- XGUI connector interface -----
   virtual void addFeature(const QString& theWBName,
index c91631f06b3eb6e6ad7fae0466a893ce0b9b663e..4d0b8867e05f7b09761547a7703032ecae08f3d2 100644 (file)
@@ -9,6 +9,7 @@
 #include <XGUI_Viewer.h>
 #include <XGUI_Workshop.h>
 #include <XGUI_OperationMgr.h>
+#include <XGUI_SelectionMgr.h>
 
 #include <Config_PointerMessage.h>
 #include <Config_ModuleReader.h>
@@ -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<PartSet_OperationSketchBase*>(anOperation);
   if (aPreviewOp) {
-    XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
-    if (aViewer) {
+    XGUI_SelectionMgr* aSelector = myWorkshop->selector();
+    if (aSelector) {
       NCollection_List<TopoDS_Shape> aList;
-      aViewer->getSelectedShapes(aList);
+      aSelector->selectedShapes(aList);
       aPreviewOp->setSelectedShapes(aList);
     }
   }
index 1b7e710c70ad31f4d24c908ed3bbee774d5b06e0..b0949534bb6e321af70a2c9fe74cfdf484b9f027 100644 (file)
@@ -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
index c2d2c3de305f0dac81555fe4ee8aaef8a4167ad7..efca3fde5a3ff658a2736867af5e2393a9819d18 100644 (file)
@@ -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 <ModelAPI_Feature.h>
 #include <ModelAPI_PluginManager.h>
@@ -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<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
-    boost::shared_ptr<ModelAPI_AttributeDocRef> 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<TopoDS_Shape>& 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
index 91b4c255fea2d71ddbf482ace5053820048359cf..b75989abbfb6640bc90ec681c263cc800eb8c4c2 100644 (file)
@@ -4,6 +4,11 @@
 #include "XGUI.h"
 #include "XGUI_Constants.h"
 #include <QObject>
+#include <QModelIndexList>
+
+#include <AIS_ListOfInteractive.hxx>
+#include <NCollection_List.hxx>
+#include <TopoDS_Shape.hxx>
 
 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<TopoDS_Shape>& 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
index f02499857f78df73bddb95ad02a5685d725d5ed2..2c4809cb86d9af4f5c7511f479e2114926395a51 100644 (file)
@@ -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();
-}*/
index b453a3ec935d363fe2fc0a4d78eb339869b1dab9..51bc022d5b58210b620cb1434d4b8de9decf2336 100644 (file)
@@ -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<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
+    boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = aFeature->data()->docRef("PartDocument");
+    if (aDocRef)
+      aMgr->setCurrentDocument(aDocRef->value());
+  }
+}
+
+//******************************************************
+void XGUI_Workshop::salomeViewerSelectionChanged()
+{
+  emit salomeViewerSelection();
+}
\ No newline at end of file
index 937aca3830d42f01b7f2d132bfcfb8d0b67d5d58..5ea558ca2fc4c9763054219dcc7901df7ca83417 100644 (file)
@@ -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*);