]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Activate a Part on its creation (issue #23)
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 21 May 2014 14:08:28 +0000 (18:08 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 21 May 2014 14:08:28 +0000 (18:08 +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 42c609dac5f2c382b948a2cf30a2a80c7fa411a6..05c5f7e123961d7bea1ebad2ff907413198172eb 100644 (file)
@@ -25,6 +25,10 @@ public:
   //! Returns 0 if the given index is not index of a feature
   virtual FeaturePtr feature(const QModelIndex& theIndex) const = 0;
 
+  //! Returns QModelIndex which corresponds to the given feature
+  //! If the feature is not found then index is not valid
+  virtual QModelIndex featureIndex(const FeaturePtr& theFeature) const = 0;
+
   //! Returns parent index of the given feature
   virtual QModelIndex findParent(const FeaturePtr& theFeature) const = 0;
 
index e459f9cc24307ef91187b860aa79566193c959ef..30d3b9a0fc85be7dc854d794ae1e296df1f14344 100644 (file)
@@ -24,7 +24,7 @@ XGUI_DocumentDataModel::XGUI_DocumentDataModel(QObject* theParent)
   : QAbstractItemModel(theParent), myActivePart(0)
 {
   // Find Document object
-  boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
+  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
   myDocument = aMgr->currentDocument();
 
   // Register in event loop
@@ -49,8 +49,8 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage)
   // Created object event *******************
   if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED)) {
     const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
-    boost::shared_ptr<ModelAPI_Feature> aFeature = aUpdMsg->feature();
-    boost::shared_ptr<ModelAPI_Document> aDoc = aFeature->document();
+    FeaturePtr aFeature = aUpdMsg->feature();
+    DocumentPtr aDoc = aFeature->document();
 
     if (aDoc == myDocument) {  // If root objects
       if (aFeature->getGroup().compare(PARTS_GROUP) == 0) { // Update only Parts group
@@ -86,7 +86,7 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage)
   // Deleted object event ***********************
   } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_DELETED)) {
     const Model_FeatureDeletedMessage* aUpdMsg = dynamic_cast<const Model_FeatureDeletedMessage*>(theMessage);
-    boost::shared_ptr<ModelAPI_Document> aDoc = aUpdMsg->document();
+    DocumentPtr aDoc = aUpdMsg->document();
 
     if (aDoc == myDocument) {  // If root objects
       if (aUpdMsg->group().compare(PARTS_GROUP) == 0) { // Updsate only Parts group
@@ -119,8 +119,8 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage)
   // Deleted object event ***********************
   } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED)) {
     //const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
-    //boost::shared_ptr<ModelAPI_Feature> aFeature = aUpdMsg->feature();
-    //boost::shared_ptr<ModelAPI_Document> aDoc = aFeature->document();
+    //FeaturePtr aFeature = aUpdMsg->feature();
+    //DocumentPtr aDoc = aFeature->document();
     
     // TODO: Identify the necessary index by the modified feature
     QModelIndex aIndex;
@@ -465,7 +465,7 @@ void XGUI_DocumentDataModel::deactivatePart()
   myActivePart = 0;
   myModel->setItemsColor(ACTIVE_COLOR);
 }
-
 Qt::ItemFlags XGUI_DocumentDataModel::flags(const QModelIndex& theIndex) const
 {
   Qt::ItemFlags aFlags = QAbstractItemModel::flags(theIndex);
@@ -473,4 +473,21 @@ Qt::ItemFlags XGUI_DocumentDataModel::flags(const QModelIndex& theIndex) const
     aFlags |= Qt::ItemIsEditable;
   }
   return aFlags;
-}
\ No newline at end of file
+}
+
+QModelIndex XGUI_DocumentDataModel::partIndex(const FeaturePtr& theFeature) const 
+{
+  int aRow = -1;
+  XGUI_PartModel* aModel = 0;
+  foreach (XGUI_PartModel* aPartModel, myPartModels) {
+    aRow++;
+    if (aPartModel->part() == theFeature) {
+      aModel = aPartModel;
+      break;
+    }
+  }
+  if (aModel) {
+    return createIndex(aRow, 0, (void*)getModelIndex(aModel->index(0, 0, QModelIndex())));
+  }
+  return QModelIndex();
+}
index ee76b86ceaa6b7326d4c995cdb51234646be86fa..c43b99d19c42e5588b0aa859e2bac4e2cf03ed91 100644 (file)
@@ -56,6 +56,10 @@ public:
   //! Returns 0 if the given index is not index of a feature
   FeaturePtr feature(const QModelIndex& theIndex) const;
 
+  //! Returns QModelIndex which corresponds to the given feature if this is a part
+  //! If the feature is not found then index is not valid
+  QModelIndex partIndex(const FeaturePtr& theFeature) 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);
index f526690b4bb886028b4f9988cace376080d2f26a..e5f8c8355a7d57fb032926ec1bb35cfe3116bb45 100644 (file)
@@ -20,6 +20,7 @@ XGUI_DataTree::XGUI_DataTree(QWidget* theParent)
 {
   setHeaderHidden(true);
   setModel(new XGUI_DocumentDataModel(this));
+  setEditTriggers(QAbstractItemView::NoEditTriggers);
 
   connect(selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), 
           this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
@@ -191,7 +192,7 @@ bool XGUI_ObjectsBrowser::eventFilter(QObject* obj, QEvent* theEvent)
         QMouseEvent* aEvent = (QMouseEvent*) theEvent;
         QPoint aPnt = mapFromGlobal(aEvent->globalPos());
         if (childAt(aPnt) != myActiveDocLbl) {
-          closeDocNameEditing(false);
+          closeDocNameEditing(true);
         }
       } else if (theEvent->type() == QEvent::KeyRelease) {
         QKeyEvent* aEvent = (QKeyEvent*) theEvent;
@@ -226,10 +227,10 @@ void XGUI_ObjectsBrowser::closeDocNameEditing(bool toSave)
 }
 
 //***************************************************
-void XGUI_ObjectsBrowser::activateCurrentPart(bool toActivate)
+void XGUI_ObjectsBrowser::activatePart(const FeaturePtr& thePart)
 {
-  if (toActivate) {
-    QModelIndex aIndex = myTreeView->currentIndex();
+  if (thePart) {
+    QModelIndex aIndex = myDocModel->partIndex(thePart);
 
     if ((myDocModel->activePartIndex() != aIndex) && myDocModel->activePartIndex().isValid()) {
       myTreeView->setExpanded(myDocModel->activePartIndex(), false);
@@ -237,6 +238,7 @@ void XGUI_ObjectsBrowser::activateCurrentPart(bool toActivate)
     bool isChanged = myDocModel->activatedIndex(aIndex);
     if (isChanged) {
       if (myDocModel->activePartIndex().isValid()) {
+        myTreeView->setExpanded(aIndex.parent(), true);
         myTreeView->setExpanded(aIndex, true);
         onActivePartChanged(myDocModel->feature(aIndex));
       } else {
index fa30d2b8215de09346a63c3e63fe64e5e76aea6b..b8e275ae688e3d6f7478bc832ef244377a4eea38 100644 (file)
@@ -73,7 +73,7 @@ public:
   XGUI_DataTree* treeView() const { return myTreeView; }
 
   //! Activates currently selected part. Signal activePartChanged will not be sent
-  void activateCurrentPart(bool toActivate);
+  void activatePart(const FeaturePtr& thePart);
 
 signals:
   //! Emited when selection is changed
index ff0f8aad8af53b726dc0f37bec961e3692659e87..6610b64c58ff15dcbbe5b5268c7224188ad021c9 100644 (file)
@@ -162,13 +162,7 @@ FeaturePtr XGUI_TopDataModel::feature(const QModelIndex& theIndex) const
 
 QModelIndex XGUI_TopDataModel::findParent(const FeaturePtr& theFeature) const
 {
-  QString aGroup(theFeature->getGroup().c_str());
-
-  if (theFeature->getGroup().compare(PARAMETERS_GROUP) == 0)
-    return createIndex(0, 0, (qint32) ParamsFolder);
-  if (theFeature->getGroup().compare(CONSTRUCTIONS_GROUP) == 0)
-    return createIndex(1, 0, (qint32) ConstructFolder);
-  return QModelIndex();
+  return findGroup(theFeature->getGroup().c_str());
 }
 
 QModelIndex XGUI_TopDataModel::findGroup(const std::string& theGroup) const
@@ -180,6 +174,30 @@ QModelIndex XGUI_TopDataModel::findGroup(const std::string& theGroup) const
   return QModelIndex();
 }
 
+QModelIndex XGUI_TopDataModel::featureIndex(const FeaturePtr& theFeature) const
+{
+  QModelIndex aIndex;
+  if (theFeature) {
+    std::string aGroup = theFeature->getGroup();
+    int aNb = myDocument->size(aGroup);
+    int aRow = -1;
+    for (int i = 0; i < aNb; i++) {
+      if (myDocument->feature(aGroup, i, true) == theFeature) {
+        aRow = i;
+        break;
+      }
+    }
+    if (aRow != -1) {
+      if (aGroup.compare(PARAMETERS_GROUP) == 0)
+        return createIndex(aRow, 0, (qint32) ParamObject);
+      if (aGroup.compare(CONSTRUCTIONS_GROUP) == 0)
+        return createIndex(aRow, 0, (qint32) ConstructObject);
+    }
+  }
+  return aIndex;
+}
+
+
 
 //******************************************************************
 //******************************************************************
@@ -319,7 +337,7 @@ QModelIndex XGUI_PartDataModel::index(int theRow, int theColumn, const QModelInd
   case ConstructFolder:
     return createIndex(theRow, 0, (qint32) ConstructObject);
   case BodiesFolder:
-    return createIndex(theRow, 0, (qint32) BodieswObject);
+    return createIndex(theRow, 0, (qint32) BodiesObject);
   }
   return QModelIndex();
 }
@@ -364,11 +382,14 @@ FeaturePtr XGUI_PartDataModel::feature(const QModelIndex& theIndex) const
       return featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3, true);
   case ParamsFolder:
   case ConstructFolder:
+  case BodiesFolder:
     return FeaturePtr();
   case ParamObject:
     return featureDocument()->feature(PARAMETERS_GROUP, theIndex.row(), true);
   case ConstructObject:
     return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row(), true);
+  //case BodiesObject:
+  //  return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row(), true);
   }
   return FeaturePtr();
 }
@@ -381,13 +402,7 @@ bool XGUI_PartDataModel::hasDocument(const DocumentPtr& theDoc) const
 
 QModelIndex XGUI_PartDataModel::findParent(const FeaturePtr& theFeature) const
 {
-  QString aGroup(theFeature->getGroup().c_str());
-
-  if (theFeature->getGroup().compare(PARAMETERS_GROUP) == 0)
-    return createIndex(0, 0, (qint32) ParamsFolder);
-  if (theFeature->getGroup().compare(CONSTRUCTIONS_GROUP) == 0)
-    return createIndex(1, 0, (qint32) ConstructFolder);
-  return QModelIndex();
+  return findGroup(theFeature->getGroup().c_str());
 }
 
 QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const
@@ -402,4 +417,30 @@ QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const
 FeaturePtr XGUI_PartDataModel::part() const
 {
   return myDocument->feature(PARTS_GROUP, myId, true);
-}
\ No newline at end of file
+}
+
+QModelIndex XGUI_PartDataModel::featureIndex(const FeaturePtr& theFeature) const
+{
+  QModelIndex aIndex;
+  if (theFeature) {
+    if (part() == theFeature) 
+      return aIndex;
+
+    std::string aGroup = theFeature->getGroup();
+    int aNb = myDocument->size(aGroup);
+    int aRow = -1;
+    for (int i = 0; i < aNb; i++) {
+      if (myDocument->feature(aGroup, i, true) == theFeature) {
+        aRow = i;
+        break;
+      }
+    }
+    if (aRow != -1) {
+      if (aGroup.compare(PARAMETERS_GROUP) == 0)
+        return createIndex(aRow, 0, (qint32) ParamObject);
+      if (aGroup.compare(CONSTRUCTIONS_GROUP) == 0)
+        return createIndex(aRow, 0, (qint32) ConstructObject);
+    }
+  }
+  return aIndex;
+}
index a44dfb03ca5d22f869bdd67f944985816c6ca1ff..e1533ee0bfbd4a14b04628ca438a1715d1f6fa20 100644 (file)
@@ -36,6 +36,10 @@ public:
   //! Returns 0 if the given index is not index of a feature
   virtual FeaturePtr feature(const QModelIndex& theIndex) const;
 
+  //! Returns QModelIndex which corresponds to the given feature
+  //! If the feature is not found then index is not valid
+  virtual QModelIndex featureIndex(const FeaturePtr& theFeature) const;
+
   //! Returns parent index of the given feature
   virtual QModelIndex findParent(const FeaturePtr& theFeature) const;
 
@@ -85,6 +89,10 @@ public:
   //! Returns 0 if the given index is not index of a feature
   virtual FeaturePtr feature(const QModelIndex& theIndex) const;
 
+  //! Returns QModelIndex which corresponds to the given feature
+  //! If the feature is not found then index is not valid
+  virtual QModelIndex featureIndex(const FeaturePtr& theFeature) const;
+
   //! Returns true if the given document is a sub-document of this tree
   virtual bool hasDocument(const DocumentPtr& theDoc) const;
 
@@ -108,7 +116,7 @@ private:
     ConstructFolder,
     ConstructObject,
     BodiesFolder,
-    BodieswObject,
+    BodiesObject,
     HistoryObject
   };
 
index 40c545b2c2567000db3f10b3f75d8d6357be071b..9cef8d9b65604fb68665360173b89538c28e5834 100644 (file)
@@ -45,6 +45,7 @@
 #include <QPushButton>
 #include <QDockWidget>
 #include <QLayout>
+#include <QTimer>
 
 #ifdef _DEBUG
 #include <QDebug>
@@ -117,6 +118,8 @@ void XGUI_Workshop::startApplication()
   aLoop->registerListener(this, aPartSetId);
   Events_ID aFeatureUpdatedId = aLoop->eventByName(EVENT_FEATURE_UPDATED);
   aLoop->registerListener(this, aFeatureUpdatedId);
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
+
   activateModule();
   if (myMainWindow) {
     myMainWindow->show();
@@ -203,6 +206,17 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage)
     addFeature(aFeatureMsg);
     return;
   }
+  // Process creation of Part
+  if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED)) {
+    const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
+    FeaturePtr aFeature = aUpdMsg->feature();
+    if (aFeature->getKind() == "Part") {
+      //The created part will be created in Object Browser later and we have to activate that
+      // only when it created everywere
+      QTimer::singleShot(50, this, SLOT(activateLastPart()));
+    }
+  }
+
   //Update property panel on corresponding message. If there is no current operation (no
   //property panel), or received message has different feature to the current - do nothing.
   static Events_ID aFeatureUpdatedId = Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED);
@@ -708,25 +722,26 @@ XGUI_SalomeViewer* XGUI_Workshop::salomeViewer() const
 //**************************************************************
 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
 {
-  if (theId == "ACTIVATE_PART_CMD")
-    activatePart(true);
+  QFeatureList aFeatures = mySelector->selectedFeatures();
+  if ((theId == "ACTIVATE_PART_CMD") && (aFeatures.size() > 0))
+    activatePart(aFeatures.first());
   else if (theId == "DEACTIVATE_PART_CMD") 
-    activatePart(false);
+    activatePart(FeaturePtr());
 
 }
 
 //**************************************************************
-void XGUI_Workshop::activatePart(bool toActivate)
+void XGUI_Workshop::activatePart(FeaturePtr theFeature)
 {
-  if (toActivate) {
-    QFeatureList aFeatures = mySelector->selectedFeatures();
-    if (aFeatures.size() > 0) {
-      changeCurrentDocument(aFeatures.first());
-      myObjectBrowser->activateCurrentPart(true);
-    }
-  } else {
-    changeCurrentDocument(FeaturePtr());
-    myObjectBrowser->activateCurrentPart(false);
-  }
+  changeCurrentDocument(theFeature);
+  myObjectBrowser->activatePart(theFeature);
 }
 
+//**************************************************************
+void XGUI_Workshop::activateLastPart()
+{
+  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  DocumentPtr aDoc = aMgr->rootDocument();
+  FeaturePtr aLastPart = aDoc->feature(PARTS_GROUP, aDoc->size(PARTS_GROUP) - 1, true);
+  activatePart(aLastPart);
+}
index cd77d3b13a29f56584cbca2bba009767b65366de..04920e9ea7e342745647b9a5844f5b580319d596 100644 (file)
@@ -124,6 +124,13 @@ public slots:
 signals:
   void errorOccurred(const QString&);
 
+public slots:
+  //! Activates or deactivates a part
+  //! If PartPtr is Null pointer then PartSet will be activated
+  void activatePart(FeaturePtr theFeature);
+
+  void activateLastPart();
+
 protected:
   //Event-loop processing methods:
   void addFeature(const Config_FeatureMessage*);
@@ -153,9 +160,6 @@ 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;