]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'master' of newgeom:newgeom
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 14 May 2014 11:28:38 +0000 (15:28 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 14 May 2014 11:28:38 +0000 (15:28 +0400)
src/XGUI/XGUI_DataTreeModel.h
src/XGUI/XGUI_DocumentDataModel.cpp
src/XGUI/XGUI_DocumentDataModel.h
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_ObjectsBrowser.h
src/XGUI/XGUI_PartDataModel.cpp
src/XGUI/XGUI_PartDataModel.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 676c9d8fdf98e249441ae195287e952f57e4d033..b7313a922a5a53f99aaef4a79cd9cc359e49af5b 100644 (file)
@@ -48,6 +48,9 @@ public:
   //! Returns true if the given document is a sub-document of this tree
   virtual bool hasDocument(const boost::shared_ptr<ModelAPI_Document>& theDoc) const = 0;
 
+  //! Return a Part object
+  virtual FeaturePtr part() const = 0;
+
 protected:
   //! Id of the current part object in the document
   int myId;
index 16a56174e2c13013a8ac36e29399bd0ccc315719..b5cc13697ae3ba1c64abefdf35c639625663f62b 100644 (file)
@@ -17,7 +17,7 @@
 
 
 XGUI_DocumentDataModel::XGUI_DocumentDataModel(QObject* theParent)
-  : QAbstractItemModel(theParent)
+  : QAbstractItemModel(theParent), myActivePart(0)
 {
   // Find Document object
   boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
@@ -184,7 +184,7 @@ QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole)
   if (aParent.isValid() && (aParent.internalId() == PartsFolder)) {
     return myPartModels.at(theIndex.row())->data(QModelIndex(), theRole);
   }
-  return toSourceModelIndex(theIndex).data(theRole);
+  return toSourceModelIndex(theIndex)->data(theRole);
 }
 
 
@@ -208,11 +208,16 @@ int XGUI_DocumentDataModel::rowCount(const QModelIndex& theParent) const
   if (theParent.internalId() == HistoryNode) {
     return 0;
   }
-  QModelIndex aParent = toSourceModelIndex(theParent);
-  if (!isSubModel(aParent.model())) 
+  QModelIndex* aParent = toSourceModelIndex(theParent);
+  const QAbstractItemModel* aModel = aParent->model();
+  if (!isSubModel(aModel)) 
     return 0;
 
-  return aParent.model()->rowCount(aParent);
+  if (isPartSubModel(aModel)) {
+    if (aModel != myActivePart)
+      return 0;
+  }
+  return aModel->rowCount(*aParent);
 }
 
 int XGUI_DocumentDataModel::columnCount(const QModelIndex& theParent) const
@@ -252,21 +257,21 @@ QModelIndex XGUI_DocumentDataModel::parent(const QModelIndex& theIndex) const
   if ((theIndex.internalId() == PartsFolder) || (theIndex.internalId() == HistoryNode))
     return QModelIndex();
 
-  QModelIndex aIndex = toSourceModelIndex(theIndex);
-  const QAbstractItemModel* aModel = aIndex.model();
+  QModelIndex* aIndex = toSourceModelIndex(theIndex);
+  const QAbstractItemModel* aModel = aIndex->model();
   if (!isSubModel(aModel)) 
     return QModelIndex();
 
   if (isPartSubModel(aModel)) {
-    if (!aModel->parent(aIndex).isValid()) {
+    if (!aModel->parent(*aIndex).isValid()) {
       return partFolderNode();
     }
   }
 
-  aIndex = aModel->parent(aIndex);
-  if (aIndex.isValid())
-    return createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex));
-  return aIndex;
+  QModelIndex aIndex1 = aModel->parent(*aIndex);
+  if (aIndex1.isValid())
+    return createIndex(aIndex1.row(), aIndex1.column(), (void*)getModelIndex(aIndex1));
+  return aIndex1;
 }
 
 
@@ -278,10 +283,10 @@ bool XGUI_DocumentDataModel::hasChildren(const QModelIndex& theParent) const
 }
 
 
-QModelIndex XGUI_DocumentDataModel::toSourceModelIndex(const QModelIndex& theProxy) const
+QModelIndex* XGUI_DocumentDataModel::toSourceModelIndex(const QModelIndex& theProxy) const
 {
   QModelIndex* aIndexPtr = static_cast<QModelIndex*>(theProxy.internalPointer());
-  return (*aIndexPtr);
+  return aIndexPtr;
 }
 
 
@@ -323,12 +328,12 @@ FeaturePtr XGUI_DocumentDataModel::feature(const QModelIndex& theIndex) const
       int aOffset = historyOffset();
       return myDocument->feature(FEATURES_GROUP, theIndex.row() - aOffset);
   }
-  QModelIndex aIndex = toSourceModelIndex(theIndex);
-  if (!isSubModel(aIndex.model())) 
+  QModelIndex* aIndex = toSourceModelIndex(theIndex);
+  if (!isSubModel(aIndex->model())) 
     return FeaturePtr();
 
-  const XGUI_FeaturesModel* aModel = dynamic_cast<const XGUI_FeaturesModel*>(aIndex.model());
-  return aModel->feature(aIndex);
+  const XGUI_FeaturesModel* aModel = dynamic_cast<const XGUI_FeaturesModel*>(aIndex->model());
+  return aModel->feature(*aIndex);
 }
 
 bool XGUI_DocumentDataModel::insertRows(int theRow, int theCount, const QModelIndex& theParent)
@@ -394,4 +399,34 @@ int XGUI_DocumentDataModel::historyOffset() const
 {
   // Nb of rows of top model + Parts folder
   return myModel->rowCount(QModelIndex()) + 1;
+}
+
+bool XGUI_DocumentDataModel::activatedIndex(const QModelIndex& theIndex)
+{
+  if ((theIndex.internalId() == PartsFolder) || (theIndex.internalId() == HistoryNode))
+    return false;
+
+  QModelIndex* aIndex = toSourceModelIndex(theIndex);
+  if (!aIndex)
+    return false;
+
+  const QAbstractItemModel* aModel = aIndex->model();
+
+  if (isPartSubModel(aModel)) {
+    // if this is root node (Part item index)
+    if (!aIndex->parent().isValid()) {
+      beginResetModel();
+      myActivePart = (myActivePart == aModel)? 0 : (XGUI_PartModel*)aModel;
+      endResetModel();
+      return true;
+    }
+  }
+  return false;
+}
+
+FeaturePtr XGUI_DocumentDataModel::activePart() const
+{
+  if (myActivePart) 
+    return myActivePart->part();
+  return FeaturePtr();
 }
\ No newline at end of file
index 7214c82f4e443a68244b4e8428c49ad6618fb6bf..68bfa406252f3c8e30a112fab1ca8ea98dee4cdc 100644 (file)
@@ -54,13 +54,19 @@ public:
   //! Returns 0 if the given index is not index of a feature
   FeaturePtr feature(const QModelIndex& theIndex) const;
 
+  //! Activates a part data model if the index is a Part node index. 
+  //! Returns true if active part changed.
+  bool activatedIndex(const QModelIndex& theIndex);
+
+  FeaturePtr activePart() const;
+
 private:
 
   enum {PartsFolder, HistoryNode};
 
 
   //! Converts QModelIndex of this model to QModelIndex of a one of sub-models.
-  QModelIndex toSourceModelIndex(const QModelIndex& theProxy) const;
+  QModelIndex* toSourceModelIndex(const QModelIndex& theProxy) const;
 
   //! Finds a pointer on QModelIndex which is equal to the given one
   QModelIndex* findModelIndex(const QModelIndex& theIndex) const;
@@ -95,6 +101,9 @@ private:
   //! Data models for Parts data tree representation (one data model per a one part)
   QList<XGUI_PartModel*> myPartModels;
 
+  //! Active part in part editing mode
+  XGUI_PartModel* myActivePart;
+
   //! List of saved QModelIndexes created by sub-models
   QList<QModelIndex*> myIndexes;
 
index 8355754d6bbd70e88ce846d07e3b9992cf00603c..fb43e76122572d1bcb6b7f84ebfad54b4d7f5986 100644 (file)
@@ -31,4 +31,16 @@ void XGUI_ObjectsBrowser::onSelectionChanged(const QItemSelection& theSelected,
       mySelectedData.append(aFeature);
   }
   emit selectionChanged();
+}
+
+void XGUI_ObjectsBrowser::mouseDoubleClickEvent(QMouseEvent* theEvent)
+{
+  QModelIndex aIndex = currentIndex();
+  bool isChanged = myDocModel->activatedIndex(aIndex);
+  QTreeView::mouseDoubleClickEvent(theEvent);
+  if (isChanged) {
+    setExpanded(aIndex.parent(), true);
+    setExpanded(aIndex, myDocModel->hasChildren(aIndex));
+    emit activePartChanged(myDocModel->activePart());
+  }
 }
\ No newline at end of file
index b0949534bb6e321af70a2c9fe74cfdf484b9f027..de43e5272f7b6466f61286cb464559ab8f9d5ec7 100644 (file)
@@ -29,7 +29,10 @@ public:
 signals:
   //! Emited when selection is changed
   void selectionChanged();
+  void activePartChanged(FeaturePtr thePart); 
 
+protected:
+  virtual void mouseDoubleClickEvent(QMouseEvent* theEvent);
 
 private slots:
   //! Called when selection in Data Tree is changed
@@ -41,6 +44,8 @@ private:
 
   //! List of currently selected data
   QFeatureList mySelectedData;
+
+  //QModelIndex myActivePartIndex;
 };
 
 #endif
\ No newline at end of file
index cc5b7395c17e8c856e4f9610eceb95040f72fc4d..44b74b3207eeb7af3b1b69ac16b41011d7e11e1c 100644 (file)
@@ -384,3 +384,8 @@ QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const
     return createIndex(1, 0, (qint32) ConstructFolder);
   return QModelIndex();
 }
+
+FeaturePtr XGUI_PartDataModel::part() const
+{
+  return myDocument->feature(PARTS_GROUP, myId);
+}
\ No newline at end of file
index abda0bfded8df3b8a616c6aee4b265d9e0a5dccb..0c857f95b83e153507b30e3d9da30a9e56370ebc 100644 (file)
@@ -94,6 +94,9 @@ public:
   //! Returns index corresponded to the group
   virtual QModelIndex findGroup(const std::string& theGroup) const;
 
+  //! Return a Part object
+  virtual FeaturePtr part() const;
+
 private: 
   boost::shared_ptr<ModelAPI_Document> featureDocument() const;
 
index b0db00ee93d8df6efc5adafbea20916a801c88f0..577e6decae9422acb5def9a2c2e92719452320aa 100644 (file)
@@ -79,7 +79,6 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
   myDisplayer = new XGUI_Displayer(this);
 
   mySelector = new XGUI_SelectionMgr(this);
-  connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(changeCurrentDocument()));
 
   myOperationMgr = new XGUI_OperationMgr(this);
   myActionsMgr = new XGUI_ActionsMgr(this);
@@ -602,6 +601,7 @@ QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
   aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
   aObjDock->setWindowTitle(tr("Object browser"));
   myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
+  connect(myObjectBrowser, SIGNAL(activePartChanged(FeaturePtr)), this, SLOT(changeCurrentDocument(FeaturePtr)));
   aObjDock->setWidget(myObjectBrowser);
   return aObjDock;
 }
@@ -667,18 +667,15 @@ void XGUI_Workshop::onFeatureTriggered()
 }
 
 //******************************************************
-void XGUI_Workshop::changeCurrentDocument()
+void XGUI_Workshop::changeCurrentDocument(FeaturePtr thePart)
 {
-  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");
+  boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
+  if (thePart) {
+    boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = thePart->data()->docRef("PartDocument");
     if (aDocRef)
       aMgr->setCurrentDocument(aDocRef->value());
+  } else {
+    aMgr->setCurrentDocument(aMgr->rootDocument());
   }
 }
 
index 922a4dd89726886200b87b5e1ebbedaa8bbf3aca..737b36876a9c792dbb27f2cd8740bc31ae0c954c 100644 (file)
@@ -2,6 +2,7 @@
 #define XGUI_WORKSHOP_H
 
 #include "XGUI.h"
+#include "XGUI_Constants.h"
 #include <Events_Listener.h>
 
 #include <QObject>
@@ -114,7 +115,7 @@ public slots:
   void hideObjectBrowser();
 
   void onFeatureTriggered();
-  void changeCurrentDocument();
+  void changeCurrentDocument(FeaturePtr thePart);
 
 signals:
   void errorOccurred(const QString&);