Salome HOME
Merge branch 'BR_PYTHON_PLUGIN' of newgeom:newgeom.git into Dev_0.6.1
[modules/shaper.git] / src / XGUI / XGUI_ObjectsBrowser.cpp
index c128f3235d88ab3400f19b6facd8054faae04f77..69cc9c616c58b32feda738a6194f444cfacd5a26 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
 #include "XGUI_ObjectsBrowser.h"
 #include "XGUI_DocumentDataModel.h"
 #include "XGUI_Tools.h"
@@ -57,16 +59,10 @@ void XGUI_DataTree::mouseDoubleClickEvent(QMouseEvent* theEvent)
   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());
+    ObjectPtr aObject = aModel->object(aIndex);
+    ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
+    if (aPart) {
+      aPart->activate();
     }
   } else
     QTreeView::mouseDoubleClickEvent(theEvent);
@@ -84,12 +80,20 @@ void XGUI_DataTree::commitData(QWidget* theEditor)
     QString aRes = aEditor->text();
     ObjectPtr aFeature = mySelectedData.first();
     SessionPtr aMgr = ModelAPI_Session::get();
-    aMgr->rootDocument()->startOperation();
+    aMgr->startOperation();
     aFeature->data()->setName(qPrintable(aRes));
-    aMgr->rootDocument()->finishOperation();
+    aMgr->finishOperation();
   }
 }
 
+void XGUI_DataTree::clear() 
+{
+  mySelectedData.clear();
+  XGUI_DocumentDataModel* aModel = dataModel();
+  aModel->clear();
+  reset();
+}
+
 //********************************************************************
 //********************************************************************
 //********************************************************************
@@ -120,7 +124,7 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent)
   aLabelLay->addWidget(aLbl);
 
   SessionPtr aMgr = ModelAPI_Session::get();
-  DocumentPtr aDoc = aMgr->rootDocument();
+  DocumentPtr aDoc = aMgr->moduleDocument();
   // TODO: Find a name of the root document
 
   myActiveDocLbl = new QLineEdit(tr("Part set"), aLabelWgt);
@@ -227,7 +231,7 @@ void XGUI_ObjectsBrowser::closeDocNameEditing(bool toSave)
   if (toSave) {
     // TODO: Save the name of root document
     SessionPtr aMgr = ModelAPI_Session::get();
-    DocumentPtr aDoc = aMgr->rootDocument();
+    DocumentPtr aDoc = aMgr->moduleDocument();
   } else {
     myActiveDocLbl->setText(myActiveDocLbl->property("OldText").toString());
   }
@@ -266,7 +270,7 @@ void XGUI_ObjectsBrowser::activatePart(const ResultPartPtr& thePart)
 void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent)
 {
   myObjectsList = myTreeView->selectedObjects();
-  bool toEnable = myObjectsList.size() > 0;
+  bool toEnable = myObjectsList.size() == 1;
   foreach(QAction* aCmd, actions())
   {
     aCmd->setEnabled(toEnable);
@@ -334,7 +338,7 @@ void XGUI_ObjectsBrowser::rebuildDataTree()
 }
 
 //***************************************************
-void XGUI_ObjectsBrowser::setObjectsSelected(const QList<ObjectPtr>& theObjects)
+void XGUI_ObjectsBrowser::setObjectsSelected(const QObjectPtrList& theObjects)
 {
   QList<QModelIndex> theIndexes;
   QItemSelectionModel* aSelectModel = myTreeView->selectionModel();
@@ -348,3 +352,17 @@ void XGUI_ObjectsBrowser::setObjectsSelected(const QList<ObjectPtr>& theObjects)
     }
   }
 }
+
+//***************************************************
+void XGUI_ObjectsBrowser::processEvent(const std::shared_ptr<Events_Message>& theMessage)
+{ 
+  myDocModel->processEvent(theMessage); 
+}
+
+
+//***************************************************
+void XGUI_ObjectsBrowser::clearContent()  
+{ 
+  myObjectsList.clear();
+  myTreeView->clear(); 
+}