]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #23: Last discussed scenario (#14) for document activation was implemented.
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 16 May 2014 15:24:49 +0000 (19:24 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 16 May 2014 15:24:49 +0000 (19:24 +0400)
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_DocumentDataModel.cpp
src/XGUI/XGUI_DocumentDataModel.h
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_ObjectsBrowser.h
src/XGUI/XGUI_SelectionMgr.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h
src/XGUI/XGUI_pictures.qrc
src/XGUI/pictures/activate.png [new file with mode: 0644]
src/XGUI/pictures/assembly.png [new file with mode: 0644]

index b191e7fa31e2e54c65425ab2b9ad20e0cd35d71e..2a8fe108b3e4a5b23ff8e4515ebe37a5128a2f21 100644 (file)
@@ -22,6 +22,12 @@ void XGUI_ContextMenuMgr::createActions()
 {
   QAction* aAction = new QAction(QIcon(":pictures/edit.png"), tr("Edit..."), this);
   addAction("EDIT_CMD", aAction);
+
+  aAction = new QAction(QIcon(":pictures/activate.png"), tr("Activate"), this);
+  addAction("ACTIVATE_PART_CMD", aAction);
+
+  aAction = new QAction(QIcon(":pictures/assembly.png"), tr("Deactivate"), this);
+  addAction("DEACTIVATE_PART_CMD", aAction);
 }
 
 void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction)
@@ -73,11 +79,14 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const
   QFeatureList aFeatures = aSelMgr->selectedFeatures();
   if (aFeatures.size() == 1) {
     FeaturePtr aFeature = aFeatures.first();
-    if (aFeature->getKind() != "Part") {
-      QMenu* aMenu = new QMenu();
+    QMenu* aMenu = new QMenu();
+    if (aFeature->getKind() == "Part") {
+      //TODO: Check that feature is active
+      aMenu->addAction(action("ACTIVATE_PART_CMD"));
+    } else {
       aMenu->addAction(action("EDIT_CMD"));
-      return aMenu;
     }
+    return aMenu;
   }
   return 0;
 }
index c5b0cbd9b78454fbfddba3bf2e6fd96b65a218e4..2c4470cce95b8d88c0fb3c7dc4d5758499bbbd33 100644 (file)
@@ -431,7 +431,15 @@ bool XGUI_DocumentDataModel::activatedIndex(const QModelIndex& theIndex)
     // if this is root node (Part item index)
     if (!aIndex->parent().isValid()) {
       if (myActivePart) myActivePart->setItemsColor(PASSIVE_COLOR);
-      myActivePart = (myActivePart == aModel)? 0 : (XGUI_PartModel*)aModel;
+
+      if (myActivePart == aModel) {
+        myActivePart = 0;
+        myActivePartIndex = QModelIndex();
+      } else {
+        myActivePart = (XGUI_PartModel*)aModel;
+        myActivePartIndex = theIndex;
+      }
+
       if (myActivePart) {
         myActivePart->setItemsColor(ACTIVE_COLOR);
         myModel->setItemsColor(PASSIVE_COLOR);
@@ -448,4 +456,12 @@ FeaturePtr XGUI_DocumentDataModel::activePart() const
   if (myActivePart) 
     return myActivePart->part();
   return FeaturePtr();
-}
\ No newline at end of file
+}
+
+void XGUI_DocumentDataModel::deactivatePart() 
+{ 
+  if (myActivePart) 
+    myActivePart->setItemsColor(PASSIVE_COLOR);
+  myActivePart = 0;
+  myModel->setItemsColor(ACTIVE_COLOR);
+}
index 68bfa406252f3c8e30a112fab1ca8ea98dee4cdc..f6ce80eac56ee2efd203ba46d22df6456b9f2b98 100644 (file)
@@ -60,6 +60,11 @@ public:
 
   FeaturePtr activePart() const;
 
+  QModelIndex activePartIndex() const { return myActivePartIndex; }
+
+  //! Deactivates a Part
+  void deactivatePart();
+
 private:
 
   enum {PartsFolder, HistoryNode};
@@ -104,6 +109,8 @@ private:
   //! Active part in part editing mode
   XGUI_PartModel* myActivePart;
 
+  QModelIndex myActivePartIndex;
+
   //! List of saved QModelIndexes created by sub-models
   QList<QModelIndex*> myIndexes;
 
index 21530908eadd40b545986b574b114e2f6d780ade..cf0e8577d5556843d6b32295085e96cbc24c443b 100644 (file)
 #include "XGUI_ObjectsBrowser.h"
 #include "XGUI_DocumentDataModel.h"
 
-XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent)
+#include <ModelAPI_Data.h>
+
+#include <QLayout>
+#include <QLabel>
+#include <QPixmap>
+#include <QEvent>
+#include <QMouseEvent>
+
+
+
+XGUI_DataTree::XGUI_DataTree(QWidget* theParent)
   : QTreeView(theParent)
 {
   setHeaderHidden(true);
-  myDocModel = new XGUI_DocumentDataModel(this);
-  setModel(myDocModel);
+  setModel(new XGUI_DocumentDataModel(this));
 
   connect(selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), 
-    this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
+          this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
 }
 
-
-XGUI_ObjectsBrowser::~XGUI_ObjectsBrowser()
+XGUI_DataTree::~XGUI_DataTree()
 {
 }
 
+XGUI_DocumentDataModel* XGUI_DataTree::dataModel() const 
+{ 
+  return static_cast<XGUI_DocumentDataModel*>(model()); 
+}
 
 
-void XGUI_ObjectsBrowser::onSelectionChanged(const QItemSelection& theSelected, 
+void XGUI_DataTree::onSelectionChanged(const QItemSelection& theSelected, 
                                              const QItemSelection& theDeselected)
 {
   mySelectedData.clear();
   QModelIndexList aIndexes = selectionModel()->selectedIndexes();
+  XGUI_DocumentDataModel* aModel = dataModel();
   QModelIndexList::const_iterator aIt;
   for (aIt = aIndexes.constBegin(); aIt != aIndexes.constEnd(); ++aIt) {
-    FeaturePtr aFeature = myDocModel->feature(*aIt);
+    FeaturePtr aFeature = aModel->feature(*aIt);
     if (aFeature)
       mySelectedData.append(aFeature);
   }
   emit selectionChanged();
 }
 
-void XGUI_ObjectsBrowser::mouseDoubleClickEvent(QMouseEvent* theEvent)
+void XGUI_DataTree::mouseDoubleClickEvent(QMouseEvent* theEvent)
 {
-  QModelIndex aIndex = currentIndex();
-  bool isChanged = myDocModel->activatedIndex(aIndex);
-  QTreeView::mouseDoubleClickEvent(theEvent);
-  if (isChanged) {
-    emit activePartChanged(myDocModel->activePart());
-  }
+  if (theEvent->button() == Qt::LeftButton) {
+    QModelIndex aIndex = currentIndex();
+    XGUI_DocumentDataModel* aModel = dataModel();
+
+    if ((aModel->activePartIndex() != aIndex) && aModel->activePartIndex().isValid()) {
+      setExpanded(aModel->activePartIndex(), false);
+    }
+    bool isChanged = aModel->activatedIndex(aIndex);
+    QTreeView::mouseDoubleClickEvent(theEvent);
+    if (isChanged) {
+      if (aModel->activePartIndex().isValid())
+        setExpanded(aIndex, true);
+      emit activePartChanged(aModel->activePart());
+    }
+  } else 
+    QTreeView::mouseDoubleClickEvent(theEvent);
 }
 
-void XGUI_ObjectsBrowser::contextMenuEvent(QContextMenuEvent* theEvent)
+void XGUI_DataTree::contextMenuEvent(QContextMenuEvent* theEvent)
 {
   emit contextMenuRequested(theEvent);
+}
+
+//********************************************************************
+//********************************************************************
+//********************************************************************
+XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent)
+  : QWidget(theParent)
+{
+  QVBoxLayout* aLayout = new QVBoxLayout(this);
+  aLayout->setContentsMargins(0, 0, 0, 0);
+  aLayout->setSpacing(0);
+
+  QWidget* aLabelWgt = new QWidget(this);
+  aLayout->addWidget(aLabelWgt);
+  QHBoxLayout* aLabelLay = new QHBoxLayout(aLabelWgt);
+  aLabelLay->setContentsMargins(3, 3, 3, 3);
+
+  QLabel* aLbl = new QLabel(aLabelWgt);
+  aLbl->setPixmap(QPixmap(":pictures/assembly.png"));
+  aLabelLay->addWidget(aLbl);
+
+  myActiveDocLbl = new QLabel("", aLabelWgt);
+  myActiveDocLbl->setAlignment(Qt::AlignHCenter);
+
+  QFont aFnt = myActiveDocLbl->font();
+  aFnt.setBold(true);
+  myActiveDocLbl->setFont(aFnt);
+
+  myActiveDocLbl->installEventFilter(this);
+
+  aLabelLay->addWidget(myActiveDocLbl);
+  aLabelLay->setStretch(1,1);
+
+  myTreeView = new XGUI_DataTree(this);
+  aLayout->addWidget(myTreeView);
+
+  myDocModel = myTreeView->dataModel();
+
+  connect(myTreeView, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
+  connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SLOT(onActivePartChanged(FeaturePtr)));
+  connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SIGNAL(activePartChanged(FeaturePtr)));
+  connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)), 
+          this, SIGNAL(contextMenuRequested(QContextMenuEvent*)));
+  
+  onActivePartChanged(FeaturePtr());
+}
+
+
+XGUI_ObjectsBrowser::~XGUI_ObjectsBrowser()
+{
+}
+
+
+void XGUI_ObjectsBrowser::onActivePartChanged(FeaturePtr thePart)
+{
+  QPalette aPalet = myActiveDocLbl->palette();
+  if (thePart) {
+    myActiveDocLbl->setText(tr("Activate Part set"));
+    aPalet.setColor(QPalette::Foreground, Qt::black);
+    myActiveDocLbl->setCursor(Qt::PointingHandCursor);
+  }  else {
+    myActiveDocLbl->setText(tr("Part set is active"));
+    aPalet.setColor(QPalette::Foreground, QColor(0, 72, 140));
+    myActiveDocLbl->unsetCursor();
+  }
+  myActiveDocLbl->setPalette(aPalet);
+}
+
+bool XGUI_ObjectsBrowser::eventFilter(QObject* obj, QEvent* theEvent)
+{
+  if (obj == myActiveDocLbl) {
+    if (theEvent->type() == QEvent::MouseButtonDblClick) {
+      if (myDocModel->activePartIndex().isValid()) {
+        myTreeView->setExpanded(myDocModel->activePartIndex(), false);
+      }
+      myDocModel->deactivatePart();
+      onActivePartChanged(FeaturePtr());
+      emit activePartChanged(FeaturePtr());
+    }
+  }
+  return QWidget::eventFilter(obj, theEvent);
+}
+
+void XGUI_ObjectsBrowser::activateCurrentPart(bool toActivate)
+{
+  if (toActivate) {
+    QModelIndex aIndex = myTreeView->currentIndex();
+
+    if ((myDocModel->activePartIndex() != aIndex) && myDocModel->activePartIndex().isValid()) {
+      myTreeView->setExpanded(myDocModel->activePartIndex(), false);
+    }
+    bool isChanged = myDocModel->activatedIndex(aIndex);
+    if ((isChanged) && (myDocModel->activePartIndex().isValid())) {
+      myTreeView->setExpanded(aIndex, true);
+      onActivePartChanged(myDocModel->feature(aIndex));
+    }
+  } else {
+    QModelIndex aIndex = myDocModel->activePartIndex();
+    if (aIndex.isValid()) {
+      myDocModel->activatedIndex(aIndex);
+      myTreeView->setExpanded(aIndex, false);
+      onActivePartChanged(FeaturePtr());
+    }
+  }
 }
\ No newline at end of file
index fd1adbed8b1cc6b1852fecc7e96706b1fb9fc00a..18c03d2ccb7d3cd241c57738b876d84655d55f52 100644 (file)
@@ -5,15 +5,52 @@
 #include "XGUI.h"
 #include "XGUI_Constants.h"
 
+#include <QWidget>
 #include <QTreeView>
 
 class XGUI_DocumentDataModel;
+class QLabel;
+
+
+class XGUI_DataTree: public QTreeView
+{
+  Q_OBJECT
+public:
+  XGUI_DataTree(QWidget* theParent);
+  virtual ~XGUI_DataTree();
+
+  //! Returns list of currently selected features
+  QFeatureList selectedFeatures() const { return mySelectedData; }
+
+  XGUI_DocumentDataModel* dataModel() const;
+
+signals:
+  //! Emited when selection is changed
+  void selectionChanged();
+  void activePartChanged(FeaturePtr thePart); 
+  //! Emited on context menu request
+  void contextMenuRequested(QContextMenuEvent* theEvent);
+
+protected:
+  virtual void mouseDoubleClickEvent(QMouseEvent* theEvent);
+  virtual void contextMenuEvent(QContextMenuEvent* theEvent);
+
+private slots:
+  //! Called when selection in Data Tree is changed
+  void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
+
+private:
+  //! List of currently selected data
+  QFeatureList mySelectedData;
+};
+
 
 /**\class XGUI_ObjectsBrowser
  * \ingroup GUI
  * \brief Object browser window object. Represents data tree of current data structure
  */
- class XGUI_EXPORT XGUI_ObjectsBrowser : public QTreeView
+ class XGUI_EXPORT XGUI_ObjectsBrowser : public QWidget
 {
   Q_OBJECT
 public:
@@ -24,32 +61,39 @@ public:
   XGUI_DocumentDataModel* dataModel() const { return myDocModel; }
 
   //! Returns list of currently selected features
-  QFeatureList selectedFeatures() const { return mySelectedData; }
+  QFeatureList selectedFeatures() const { return myTreeView->selectedFeatures(); }
+
+  //! Returns currently selected indexes
+  QModelIndexList selectedIndexes() const { return myTreeView->selectionModel()->selectedIndexes(); }
+
+  //! Returns TreeView widget
+  XGUI_DataTree* treeView() const { return myTreeView; }
+
+  //! Activates currently selected part. Signal activePartChanged will not be sent
+  void activateCurrentPart(bool toActivate);
 
 signals:
   //! Emited when selection is changed
   void selectionChanged();
+
+  //! Emited when current active document is changed
   void activePartChanged(FeaturePtr thePart); 
  
   //! Emited on context menu request
   void contextMenuRequested(QContextMenuEvent* theEvent);
 
 protected:
-  virtual void mouseDoubleClickEvent(QMouseEvent* theEvent);
-  virtual void contextMenuEvent(QContextMenuEvent* theEvent);
+  virtual bool eventFilter(QObject* obj, QEvent* theEvent);
 
 private slots:
-  //! Called when selection in Data Tree is changed
-  void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
+  void onActivePartChanged(FeaturePtr thePart);
 
 private:
   //! Internal model
   XGUI_DocumentDataModel* myDocModel;
 
-  //! List of currently selected data
-  QFeatureList mySelectedData;
-
-  //QModelIndex myActivePartIndex;
+  QLabel* myActiveDocLbl;
+  XGUI_DataTree* myTreeView;
 };
 
 #endif
\ No newline at end of file
index 8365772e730cff18b9dcd7a22ba5c38fdab27eeb..f949c782a5a4b4a7ca17f5440ef2a7513a1cc441 100644 (file)
@@ -63,7 +63,7 @@ QFeatureList XGUI_SelectionMgr::selectedFeatures() const
 //**************************************************************
 QModelIndexList XGUI_SelectionMgr::selectedIndexes() const 
 { 
-  return myWorkshop->objectBrowser()->selectionModel()->selectedIndexes();
+  return myWorkshop->objectBrowser()->selectedIndexes();
 }
 
 //**************************************************************
index 9b391a44e4a37ceff33e15b60cc10e4ebea39641..a935975d286f96da3e3e3cccb59ed0ab6d9e6286 100644 (file)
@@ -85,6 +85,8 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
   myActionsMgr = new XGUI_ActionsMgr(this);
   myErrorDlg = new XGUI_ErrorDialog(myMainWindow);
   myContextMenuMgr = new XGUI_ContextMenuMgr(this);
+  connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), 
+          this, SLOT(onContextMenuCommand(const QString&, bool)));
 
   myViewerProxy = new XGUI_ViewerProxy(this);
 
@@ -470,7 +472,7 @@ void XGUI_Workshop::onSaveAs()
 //******************************************************
 void XGUI_Workshop::onUndo()
 {
-  objectBrowser()->setCurrentIndex(QModelIndex());
+  objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
   boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
   boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
   if (aDoc->isOperation())
@@ -482,7 +484,7 @@ void XGUI_Workshop::onUndo()
 //******************************************************
 void XGUI_Workshop::onRedo()
 {
-  objectBrowser()->setCurrentIndex(QModelIndex());
+  objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
   boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
   boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
   aDoc->redo();
@@ -698,3 +700,29 @@ XGUI_SalomeViewer* XGUI_Workshop::salomeViewer() const
 { 
   return mySalomeConnector->viewer(); 
 }
+
+//**************************************************************
+void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
+{
+  if (theId == "ACTIVATE_PART_CMD")
+    activatePart(true);
+  else if (theId == "DEACTIVATE_PART_CMD") 
+    activatePart(false);
+
+}
+
+//**************************************************************
+void XGUI_Workshop::activatePart(bool toActivate)
+{
+  if (toActivate) {
+    QFeatureList aFeatures = mySelector->selectedFeatures();
+    if (aFeatures.size() > 0) {
+      changeCurrentDocument(aFeatures.first());
+      myObjectBrowser->activateCurrentPart(true);
+    }
+  } else {
+    changeCurrentDocument(FeaturePtr());
+    myObjectBrowser->activateCurrentPart(false);
+  }
+}
+
index f0121474b608056a73f56fff7444d7ca5f8748c8..cd77d3b13a29f56584cbca2bba009767b65366de 100644 (file)
@@ -139,6 +139,8 @@ protected slots:
   /// \param theOpertion a stopped operation
   void onOperationStopped(ModuleBase_Operation* theOperation);
 
+  void onContextMenuCommand(const QString& theId, bool isChecked);
+
 private:
   void initMenu();
 
@@ -151,6 +153,9 @@ private:
   // Creates Dock widgets: Object browser and Property panel
   void createDockWidgets();
 
+  //! Activates or deactivates currently selected part
+  void activatePart(bool toActivate);
+
   QString myCurrentFile;
   XGUI_MainWindow* myMainWindow;
   XGUI_Module* myPartSetModule;
index 893d8d7b6b2a0442e8eaad115d2ea915630b6309..30d9ba286de752a09b080113369f1d8334bb21a8 100644 (file)
@@ -52,5 +52,7 @@
      <file>pictures/tile_views.png</file>
      <file>pictures/new_view.png</file>
      <file>pictures/edit.png</file>
+     <file>pictures/assembly.png</file>
+     <file>pictures/activate.png</file>
  </qresource>
  </RCC>
diff --git a/src/XGUI/pictures/activate.png b/src/XGUI/pictures/activate.png
new file mode 100644 (file)
index 0000000..f829179
Binary files /dev/null and b/src/XGUI/pictures/activate.png differ
diff --git a/src/XGUI/pictures/assembly.png b/src/XGUI/pictures/assembly.png
new file mode 100644 (file)
index 0000000..1b1c71a
Binary files /dev/null and b/src/XGUI/pictures/assembly.png differ