]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
XGUI package is adapted to new Model architecture
authorvsv <vitaly.smetannikov@opencascade.com>
Mon, 14 Jul 2014 14:09:45 +0000 (18:09 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Mon, 14 Jul 2014 14:09:45 +0000 (18:09 +0400)
src/XGUI/XGUI_DocumentDataModel.cpp
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_ObjectsBrowser.h
src/XGUI/XGUI_PartDataModel.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h
src/XGUI/XGUI_pictures.qrc
src/XGUI/pictures/constr_object.png [new file with mode: 0644]

index 4290124700348d99a7854aa3988c92276451aefe..24b422421bc2564f4457de2d04670d16b9907cc2 100644 (file)
@@ -193,7 +193,8 @@ QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole)
     {
       int aOffset = historyOffset();
       DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
-      ObjectPtr aFeature = aRootDoc->object(ModelAPI_Feature::group(), theIndex.row() - aOffset);
+      ObjectPtr aObj = aRootDoc->object(ModelAPI_Feature::group(), theIndex.row() - aOffset);
+      FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
       if (!aFeature)
         return QVariant();
       switch (theRole) {
@@ -372,7 +373,7 @@ ObjectPtr XGUI_DocumentDataModel::object(const QModelIndex& theIndex) const
     return ObjectPtr();
 
   const XGUI_FeaturesModel* aModel = dynamic_cast<const XGUI_FeaturesModel*>(aIndex->model());
-  return aModel->feature(*aIndex);
+  return aModel->object(*aIndex);
 }
 
 bool XGUI_DocumentDataModel::insertRows(int theRow, int theCount, const QModelIndex& theParent)
@@ -475,11 +476,11 @@ bool XGUI_DocumentDataModel::activatedIndex(const QModelIndex& theIndex)
   return false;
 }
 
-ObjectPtr XGUI_DocumentDataModel::activePart() const
+ResultPartPtr XGUI_DocumentDataModel::activePart() const
 {
   if (myActivePart) 
     return myActivePart->part();
-  return ObjectPtr();
+  return ResultPartPtr();
 }
 
 void XGUI_DocumentDataModel::deactivatePart() 
@@ -500,7 +501,7 @@ Qt::ItemFlags XGUI_DocumentDataModel::flags(const QModelIndex& theIndex) const
   return aFlags;
 }
 
-QModelIndex XGUI_DocumentDataModel::partIndex(const ObjectPtr& theObject) const 
+QModelIndex XGUI_DocumentDataModel::partIndex(const ResultPartPtr& theObject) const 
 {
   int aRow = -1;
   XGUI_PartModel* aModel = 0;
@@ -517,7 +518,7 @@ QModelIndex XGUI_DocumentDataModel::partIndex(const ObjectPtr& theObject) const
   return QModelIndex();
 }
 
-QModelIndex XGUI_DocumentDataModel::featureIndex(const ObjectPtr theObject) const
+QModelIndex XGUI_DocumentDataModel::objectIndex(const ObjectPtr theObject) const
 {
   // Check that this feature belongs to root document
   DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
@@ -532,7 +533,7 @@ QModelIndex XGUI_DocumentDataModel::featureIndex(const ObjectPtr theObject) cons
       }
       return index(aId + historyOffset(), 0, QModelIndex());
     } else {
-      QModelIndex aIndex = myModel->featureIndex(theObject);
+      QModelIndex aIndex = myModel->objectIndex(theObject);
       return aIndex.isValid()? 
         createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex)) :
         QModelIndex();
@@ -546,7 +547,7 @@ QModelIndex XGUI_DocumentDataModel::featureIndex(const ObjectPtr theObject) cons
       }
     }
     if (aPartModel) {
-      QModelIndex aIndex = aPartModel->featureIndex(theObject);
+      QModelIndex aIndex = aPartModel->objectIndex(theObject);
       return aIndex.isValid()? 
         createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex)) :
         QModelIndex();
index 5d9d000e3b2af60d799babb832796672de6e1e49..6e61fef19bb19e453c7b639dcfff76a50b73d550 100644 (file)
@@ -46,9 +46,9 @@ void XGUI_DataTree::onSelectionChanged(const QItemSelection& theSelected,
   XGUI_DocumentDataModel* aModel = dataModel();
   QModelIndexList::const_iterator aIt;
   for (aIt = aIndexes.constBegin(); aIt != aIndexes.constEnd(); ++aIt) {
-    ObjectPtr aFeature = aModel->feature(*aIt);
-    if (aFeature)
-      mySelectedData.append(aFeature);
+    ObjectPtr aObject = aModel->object(*aIt);
+    if (aObject)
+      mySelectedData.append(aObject);
   }
   emit selectionChanged();
 }
@@ -86,10 +86,7 @@ void XGUI_DataTree::commitData(QWidget* theEditor)
     ObjectPtr aFeature = mySelectedData.first();
     PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
     aMgr->rootDocument()->startOperation();
-    if (!XGUI_Tools::isModelObject(aFeature))
-      aFeature->data()->setName(qPrintable(aRes));
-    else
-      boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->setName(qPrintable(aRes));
+    aFeature->data()->setName(qPrintable(aRes));
     aMgr->rootDocument()->finishOperation();
   }
 }
@@ -235,7 +232,7 @@ void XGUI_ObjectsBrowser::closeDocNameEditing(bool toSave)
 }
 
 //***************************************************
-void XGUI_ObjectsBrowser::activatePart(const ObjectPtr& thePart)
+void XGUI_ObjectsBrowser::activatePart(const ResultPartPtr& thePart)
 {
   if (thePart) {
     QModelIndex aIndex = myDocModel->partIndex(thePart);
@@ -248,7 +245,7 @@ void XGUI_ObjectsBrowser::activatePart(const ObjectPtr& thePart)
       if (myDocModel->activePartIndex().isValid()) {
         myTreeView->setExpanded(aIndex.parent(), true);
         myTreeView->setExpanded(aIndex, true);
-        onActivePartChanged(myDocModel->feature(aIndex));
+        onActivePartChanged(myDocModel->object(aIndex));
       } else {
         onActivePartChanged(ObjectPtr());
       }
@@ -266,7 +263,7 @@ void XGUI_ObjectsBrowser::activatePart(const ObjectPtr& thePart)
 //***************************************************
 void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent) 
 {
-  myObjectsList = myTreeView->selectedFeatures();
+  myObjectsList = myTreeView->selectedObjects();
   bool toEnable = myObjectsList.size() > 0;
   foreach(QAction* aCmd, actions()) {
     aCmd->setEnabled(toEnable);
index edcddc628d0f7a43d1f482ca806754e2fe041f5e..05a539566d5a8bdd438314ae52c8a61a8f94b4bc 100644 (file)
@@ -5,6 +5,7 @@
 #include "XGUI.h"
 #include <ModuleBase_Definitions.h>
 #include <ModelAPI_Object.h>
+#include <ModelAPI_ResultPart.h>
 
 #include <QWidget>
 #include <QTreeView>
@@ -76,7 +77,7 @@ public:
   XGUI_DataTree* treeView() const { return myTreeView; }
 
   //! Activates currently selected part. Signal activePartChanged will not be sent
-  void activatePart(const ObjectPtr& thePart);
+  void activatePart(const ResultPartPtr& thePart);
 
   void rebuildDataTree();
 
index c9e98b5d45d075c641fde056769a85e3692b026a..b77297f54b6e8690c8b3e6e2cd83ae50a8387ebb 100644 (file)
@@ -70,12 +70,13 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const
     case ConstructFolder:
       return QIcon(":pictures/constr_folder.png");
     case ConstructObject:
-      {
-        DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
-        ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row());
-        if (aObject)
-          return QIcon(XGUI_Workshop::featureIcon(aObject->getKind()));
-      }
+      return QIcon(":pictures/constr_object.png");
+      //{
+      //  DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+      //  ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row());
+      //  if (aObject)
+      //    return QIcon(XGUI_Workshop::featureIcon(aObject->getKind()));
+      //}
     }
     break;
 
@@ -238,7 +239,7 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
         DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
         ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId);
         if (aObject)
-          return boost::dynamic_pointer_cast<ModelAPI_Object>(aObject)->getName().c_str();
+          return boost::dynamic_pointer_cast<ModelAPI_Object>(aObject)->data()->name().c_str();
       }
     case ParamsFolder:
       return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex));
@@ -277,16 +278,18 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
     case BodiesFolder:
       return QIcon(":pictures/constr_folder.png");
     case ConstructObject:
-      {
-        ObjectPtr aObject = partDocument()->object(ModelAPI_ResultConstruction::group(), theIndex.row());
-        if (aObject)
-          return QIcon(XGUI_Workshop::featureIcon(aObject->getKind()));
-      }
+      return QIcon(":pictures/constr_object.png");
+      //{
+      //  ObjectPtr aObject = partDocument()->object(ModelAPI_ResultConstruction::group(), theIndex.row());
+      //  if (aObject)
+      //    return QIcon(XGUI_Workshop::featureIcon(aObject->getKind()));
+      //}
     case HistoryObject:
       {
         ObjectPtr aObject = partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - 3);
-        if (aObject)
-          return QIcon(XGUI_Workshop::featureIcon(aObject->getKind()));
+        FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
+        if (aFeature)
+          return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind()));
       }
     }
    break;
@@ -435,10 +438,11 @@ QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const
   return QModelIndex();
 }
 
-ObjectPtr XGUI_PartDataModel::part() const
+ResultPartPtr XGUI_PartDataModel::part() const
 {
   DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
-  return aRootDoc->object(ModelAPI_ResultPart::group(), myId);
+  ObjectPtr aObj = aRootDoc->object(ModelAPI_ResultPart::group(), myId);
+  return boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
 }
 
 QModelIndex XGUI_PartDataModel::objectIndex(const ObjectPtr& theObject) const
index 78c7cc717dc2817a2be42524e5cc910bce930f54..dddd97fb627b7570ded17519435a9f7138c6aa2e 100644 (file)
@@ -30,6 +30,7 @@
 #include <ModelAPI_AttributeDocRef.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Validator.h>
+#include <ModelAPI_ResultPart.h>
 
 #include <PartSetPlugin_Part.h>
 
@@ -273,13 +274,13 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage)
 //******************************************************
 void XGUI_Workshop::onFeatureUpdatedMsg(const Model_ObjectUpdatedMessage* theMsg)
 {
-  std::set<FeaturePtr> aFeatures = theMsg->features();
+  std::set<ObjectPtr> aFeatures = theMsg->features();
   if (myOperationMgr->hasOperation())
   {
     FeaturePtr aCurrentFeature = myOperationMgr->currentOperation()->feature();
-    std::set<FeaturePtr>::const_iterator aIt;
+    std::set<ObjectPtr>::const_iterator aIt;
     for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
-      FeaturePtr aNewFeature = (*aIt);
+      ObjectPtr aNewFeature = (*aIt);
       if(aNewFeature == aCurrentFeature) {
         myPropertyPanel->updateContentWidget(aCurrentFeature);
         break;
@@ -291,13 +292,13 @@ void XGUI_Workshop::onFeatureUpdatedMsg(const Model_ObjectUpdatedMessage* theMsg
 //******************************************************
 void XGUI_Workshop::onFeatureRedisplayMsg(const Model_ObjectUpdatedMessage* theMsg)
 {
-  std::set<FeaturePtr> aFeatures = theMsg->features();
-  std::set<FeaturePtr>::const_iterator aIt;
+  std::set<ObjectPtr> aFeatures = theMsg->features();
+  std::set<ObjectPtr>::const_iterator aIt;
   bool isDisplayed = false;
   for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
-    FeaturePtr aFeature = (*aIt);
-    if (aFeature->getKind() != PARTSET_PART_KIND) {
-      isDisplayed = myDisplayer->redisplay(aFeature, false);
+    ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(*aIt);
+    if (aRes) {
+      isDisplayed = myDisplayer->redisplay(aRes, false);
     }
   }
   if (isDisplayed)
@@ -307,18 +308,20 @@ void XGUI_Workshop::onFeatureRedisplayMsg(const Model_ObjectUpdatedMessage* theM
 //******************************************************
 void XGUI_Workshop::onFeatureCreatedMsg(const Model_ObjectUpdatedMessage* theMsg)
 {
-  std::set<FeaturePtr> aFeatures = theMsg->features();
+  std::set<ObjectPtr> aFeatures = theMsg->features();
 
-  std::set<FeaturePtr>::const_iterator aIt;
+  std::set<ObjectPtr>::const_iterator aIt;
   bool aHasPart = false;
   bool isDisplayed = false;
   for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
-    FeaturePtr aFeature = (*aIt);
-    if (aFeature->getKind() == PARTSET_PART_KIND) {
+     ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(*aIt);
+    if (aPart) {
       aHasPart = true;
       //break;
     } else {
-      isDisplayed = myDisplayer->display(aFeature, false);
+      ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(*aIt);
+      if (aRes)
+        isDisplayed = myDisplayer->display(aRes, false);
     }
   }
   if (isDisplayed)
@@ -824,19 +827,13 @@ void XGUI_Workshop::onFeatureTriggered()
 }
 
 //******************************************************
-void XGUI_Workshop::changeCurrentDocument(FeaturePtr thePart)
+void XGUI_Workshop::changeCurrentDocument(ObjectPtr theObj)
 {
   PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
-  if (thePart) {
-    DocumentPtr aFeaDoc;
-    if (!XGUI_Tools::isModelObject(thePart)) {
-      aFeaDoc = thePart->data()->docRef("PartDocument")->value();
-    } else {
-      ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(thePart);
-      aFeaDoc = aObject->featureRef()->data()->docRef("PartDocument")->value();
-    }
-    if (aFeaDoc)
-      aMgr->setCurrentDocument(aFeaDoc);
+  if (theObj) {
+    DocumentPtr aPartDoc = theObj->document();
+    if (aPartDoc)
+      aMgr->setCurrentDocument(aPartDoc);
   } else {
     aMgr->setCurrentDocument(aMgr->rootDocument());
   }
@@ -858,17 +855,19 @@ XGUI_SalomeViewer* XGUI_Workshop::salomeViewer() const
 //**************************************************************
 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
 {
-  QFeatureList aFeatures = mySelector->selection()->selectedFeatures();
-  if ((theId == "ACTIVATE_PART_CMD") && (aFeatures.size() > 0))
-    activatePart(aFeatures.first());
-  else if (theId == "DEACTIVATE_PART_CMD") 
-    activatePart(FeaturePtr());
+  QList<ObjectPtr> aObjects = mySelector->selection()->selectedObjects();
+  if ((theId == "ACTIVATE_PART_CMD") && (aObjects.size() > 0)) {
+    ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObjects.first());
+    if (aPart)
+      activatePart(aPart);
+  } else if (theId == "DEACTIVATE_PART_CMD") 
+    activatePart(ResultPartPtr());
   else if (theId == "DELETE_CMD")
-    deleteFeatures(aFeatures);
+    deleteObjects(aObjects);
   else if (theId == "SHOW_CMD")
-    showFeatures(aFeatures, true);
+    showObjects(aObjects, true);
   else if (theId == "HIDE_CMD")
-    showFeatures(aFeatures, false);
+    showObjects(aObjects, false);
 }
 
 //**************************************************************
@@ -892,7 +891,7 @@ void XGUI_Workshop::onWidgetValuesChanged()
 }
 
 //**************************************************************
-void XGUI_Workshop::activatePart(FeaturePtr theFeature)
+void XGUI_Workshop::activatePart(ResultPartPtr theFeature)
 {
   changeCurrentDocument(theFeature);
   myObjectBrowser->activatePart(theFeature);
@@ -903,58 +902,52 @@ 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);
+  std::string aGrpName = ModelAPI_ResultPart::group();
+  ObjectPtr aLastPart = aDoc->object(aGrpName, aDoc->size(aGrpName) - 1);
+  ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aLastPart);
+  if (aPart)
+    activatePart(aPart);
 }
 
 //**************************************************************
-void XGUI_Workshop::deleteFeatures(QFeatureList theList)
+void XGUI_Workshop::deleteObjects(const QList<ObjectPtr>& theList)
 {
   QMainWindow* aDesktop = isSalomeMode()? salomeConnector()->desktop() : myMainWindow;
   QMessageBox::StandardButton aRes = QMessageBox::warning(aDesktop, tr("Delete features"), 
                                                           tr("Seleted features will be deleted. Continue?"), 
                                                           QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
-  if (aRes == QMessageBox::Yes) {
+  // ToDo: definbe deleting method
+  /*  if (aRes == QMessageBox::Yes) {
     PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
     aMgr->rootDocument()->startOperation();
-    foreach (FeaturePtr aFeature, theList) {
-      if (aFeature->getKind() == PARTSET_PART_KIND) {
-        DocumentPtr aDoc;
-        if (!XGUI_Tools::isModelObject(aFeature)) {
-          aDoc = aFeature->data()->docRef("PartDocument")->value();
-        } else {
-          ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
-          aDoc = aObject->featureRef()->data()->docRef("PartDocument")->value();
-          aFeature = aObject->featureRef();
-        }
+    foreach (ObjectPtr aObj, theList) {
+      ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
+      if (aPart) {
+        DocumentPtr aDoc = aPart->document();
         if (aDoc == aMgr->currentDocument()) {
           aDoc->close();
         }
+        aMgr->rootDocument()->removeFeature(aPart->owner());
       } else {
-        if (XGUI_Tools::isModelObject(aFeature)) {
-          ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
-          aFeature = aObject->featureRef();
-        }
+        aObj->document()->removeFeature(aObj);
       }
-      if (myDisplayer->isVisible(aFeature))
-        myDisplayer->erase(aFeature, false);
-      aFeature->document()->removeFeature(aFeature);
     }
     myDisplayer->updateViewer();
     aMgr->rootDocument()->finishOperation();
-  }
+  }*/
 }
 
 //**************************************************************
-void XGUI_Workshop::showFeatures(QFeatureList theList, bool isVisible)
+void XGUI_Workshop::showObjects(const QList<ObjectPtr>& theList, bool isVisible)
 {
-  if (isVisible) {
-    foreach (FeaturePtr aFeature, theList) {
-      myDisplayer->display(aFeature, false);
-    }
-  } else {
-    foreach (FeaturePtr aFeature, theList) {
-      myDisplayer->erase(aFeature, false);
+  foreach (ObjectPtr aObj, theList) {
+    ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+    if (aRes) {
+      if (isVisible) {
+        myDisplayer->display(aRes, false);
+      } else {
+        myDisplayer->erase(aRes, false);
+      }
     }
   }
   myDisplayer->updateViewer();
index 870e23f19cae1f771a24c0e166a5566024902049..1b85fbc0c417f318e6563492203f5742d7441808 100644 (file)
@@ -5,6 +5,7 @@
 #include "XGUI_Constants.h"
 #include <Events_Listener.h>
 #include <ModuleBase_Definitions.h>
+#include <ModelAPI_ResultPart.h>
 
 #include <QObject>
 #include <QMap>
@@ -110,13 +111,13 @@ public:
 
   //! Activates or deactivates a part
   //! If PartPtr is Null pointer then PartSet will be activated
-  void activatePart(FeaturePtr theFeature);
+  void activatePart(ResultPartPtr theFeature);
 
   //! Delete features
-  void deleteFeatures(QFeatureList theList);
+  void deleteObjects(const QList<ObjectPtr>& theList);
 
   //! Show the given features in 3d Viewer
-  void showFeatures(QFeatureList theList, bool isVisible);
+  void showObjects(const QList<ObjectPtr>& theList, bool isVisible);
 
   ModuleBase_IModule* module() const { return myModule; }
 
@@ -142,7 +143,7 @@ public slots:
   void hideObjectBrowser();
 
   void onFeatureTriggered();
-  void changeCurrentDocument(FeaturePtr thePart);
+  void changeCurrentDocument(ObjectPtr theObj);
 
   void activateLastPart();
 
index 065663ecfc1c94e73dcd67d3e90680962153e62f..efd946fcb86823b56fba8584e79c39bf0c2edbd9 100644 (file)
@@ -32,6 +32,7 @@
      
      <file>pictures/params_folder.png</file>
      <file>pictures/constr_folder.png</file>
+     <file>pictures/constr_object.png</file>
      <file>pictures/part_ico.png</file>
      <file>pictures/properties.png</file>
      <file>pictures/features.png</file>
diff --git a/src/XGUI/pictures/constr_object.png b/src/XGUI/pictures/constr_object.png
new file mode 100644 (file)
index 0000000..dd6dc98
Binary files /dev/null and b/src/XGUI/pictures/constr_object.png differ