]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Show/Hide operations and selection synchronization
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 6 Jun 2014 13:16:27 +0000 (17:16 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 6 Jun 2014 13:16:27 +0000 (17:16 +0400)
15 files changed:
src/XGUI/CMakeLists.txt
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.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_SalomeViewer.h
src/XGUI/XGUI_SelectionMgr.cpp
src/XGUI/XGUI_Tools.cpp
src/XGUI/XGUI_Tools.h
src/XGUI/XGUI_ViewerProxy.cpp
src/XGUI/XGUI_Workshop.cpp

index 1775cb1259fa8bdb1aaa53860868341af26aa758..8c9244e52392af267ea209b8dbd0fb887c13ce12 100644 (file)
@@ -115,7 +115,8 @@ INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/src/Events
                                         ${PROJECT_SOURCE_DIR}/src/PyInterp
                                         ${PROJECT_SOURCE_DIR}/src/PyConsole
                                         ${PROJECT_SOURCE_DIR}/src/ModelAPI
-                                        ${PROJECT_SOURCE_DIR}/src/Model
+                                        ${PROJECT_SOURCE_DIR}/src/GeomAPI
+                                    ${PROJECT_SOURCE_DIR}/src/Model
                                         ${PROJECT_SOURCE_DIR}/src/ModuleBase
                                         ${PROJECT_SOURCE_DIR}/src/PartSetPlugin
                                         ${CAS_INCLUDE_DIRS})
index 54f3728edb3e01d4f92a4fbe406efe06987d53de..fee4e4230fb64f7a0f63444924b555232ce934ab 100644 (file)
@@ -10,6 +10,9 @@
 
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+
+#include <GeomAPI_Shape.h>
 
 #include <AIS_InteractiveContext.hxx>
 #include <AIS_LocalContext.hxx>
@@ -34,26 +37,31 @@ XGUI_Displayer::~XGUI_Displayer()
 
 bool XGUI_Displayer::isVisible(FeaturePtr theFeature)
 {
-  return myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end();
+  FeaturePtr aFeature = XGUI_Tools::realFeature(theFeature);
+  return myFeature2AISObjectMap.find(aFeature) != myFeature2AISObjectMap.end();
 }
 
-//void XGUI_Displayer::Display(FeaturePtr theFeature,
-//                             const bool isUpdateViewer)
-//{
-//}
+void XGUI_Displayer::display(FeaturePtr theFeature, bool isUpdateViewer)
+{
+  FeaturePtr aFeature = XGUI_Tools::realFeature(theFeature);
+  boost::shared_ptr<GeomAPI_Shape> aShapePtr = aFeature->data()->shape();
+
+  if (aShapePtr) {
+    TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
+    display(aFeature, aShape, isUpdateViewer);
+  }
+}
 
-/*void XGUI_Displayer::Display(FeaturePtr theFeature,
-                             const TopoDS_Shape& theShape, const bool isUpdateViewer)
+void XGUI_Displayer::display(FeaturePtr theFeature,
+                             const TopoDS_Shape& theShape, bool isUpdateViewer)
 {
   Handle(AIS_InteractiveContext) aContext = AISContext();
 
   Handle(AIS_Shape) anAIS = new AIS_Shape(theShape);
   myFeature2AISObjectMap[theFeature] = anAIS;
 
-  aContext->Display(anAIS, Standard_False);
-  if (isUpdateViewer)
-    updateViewer();
-}*/
+  aContext->Display(anAIS, isUpdateViewer);
+}
 
 
 std::list<XGUI_ViewerPrs> XGUI_Displayer::getSelected(const int theShapeTypeToSkip)
@@ -79,6 +87,21 @@ std::list<XGUI_ViewerPrs> XGUI_Displayer::getSelected(const int theShapeTypeToSk
   return aPresentations;
 }
 
+QFeatureList XGUI_Displayer::selectedFeatures() const
+{
+  QFeatureList aSelectedList;
+
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
+    Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
+    FeaturePtr aFeature = getFeature(anIO);
+    if (aFeature)
+      aSelectedList.append(aFeature);
+  }
+  return aSelectedList;
+}
+
+
 std::list<XGUI_ViewerPrs> XGUI_Displayer::getHighlighted(const int theShapeTypeToSkip)
 {
   std::set<FeaturePtr > aPrsFeatures;
@@ -104,22 +127,22 @@ std::list<XGUI_ViewerPrs> XGUI_Displayer::getHighlighted(const int theShapeTypeT
 void XGUI_Displayer::erase(FeaturePtr theFeature,
                            const bool isUpdateViewer)
 {
-  if (myFeature2AISObjectMap.find(theFeature) == myFeature2AISObjectMap.end())
+  FeaturePtr aFeature = XGUI_Tools::realFeature(theFeature);
+
+  if (myFeature2AISObjectMap.find(aFeature) == myFeature2AISObjectMap.end())
     return;
 
   Handle(AIS_InteractiveContext) aContext = AISContext();
-  Handle(AIS_InteractiveObject) anAIS = myFeature2AISObjectMap[theFeature];
+  Handle(AIS_InteractiveObject) anAIS = myFeature2AISObjectMap[aFeature];
   Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
   if (!anAISShape.IsNull())
   {
-    aContext->Erase(anAISShape);
+    aContext->Erase(anAISShape, isUpdateViewer);
   }
-  myFeature2AISObjectMap.erase(theFeature);
-
-  if (isUpdateViewer)
-    updateViewer();
+  myFeature2AISObjectMap.erase(aFeature);
 }
 
+
 bool XGUI_Displayer::redisplay(FeaturePtr theFeature,
                                Handle(AIS_InteractiveObject) theAIS,
                                const int theSelectionMode,
@@ -245,6 +268,25 @@ void XGUI_Displayer::setSelected(const std::list<XGUI_ViewerPrs>& theFeatures, c
     updateViewer();
 }
 
+
+void XGUI_Displayer::setSelected(const QFeatureList& theFeatures, const bool isUpdateViewer)
+{
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  aContext->ClearSelected();
+  foreach(FeaturePtr aFeature, theFeatures) {
+    FeaturePtr aRFeature = XGUI_Tools::realFeature(aFeature);
+    if (myFeature2AISObjectMap.find(aRFeature) == myFeature2AISObjectMap.end()) 
+      return;
+
+    Handle(AIS_InteractiveObject) anAIS = myFeature2AISObjectMap[aRFeature];
+    if (!anAIS.IsNull())
+      aContext->AddOrRemoveSelected(anAIS, false);
+  }
+  if (isUpdateViewer)
+    updateViewer();
+}
+
+
 /*void XGUI_Displayer::EraseAll(const bool isUpdateViewer)
 {
   Handle(AIS_InteractiveContext) ic = AISContext();
index b8389af5d52539dab819b34850fbd125663f17ed..fdb8c76008ad2f23909fbb2f39df8e35fc6d569c 100644 (file)
@@ -6,6 +6,7 @@
 #define XGUI_Displayer_H
 
 #include "XGUI.h"
+#include "XGUI_Constants.h"
 
 #include <QString>
 #include <boost/shared_ptr.hpp>
@@ -51,20 +52,24 @@ public:
   /// Display the feature. Obtain the visualized object from the feature.
   /// \param theFeature a feature instance
   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
-  //void Display(FeaturePtr theFeature, const bool isUpdateViewer = true);
+  void display(FeaturePtr theFeature, bool isUpdateViewer = true);
 
   /// Display the feature and a shape. This shape would be associated to the given feature
   /// \param theFeature a feature instance
   /// \param theShape a shape
   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
-  //void Display(FeaturePtr theFeature, const TopoDS_Shape& theShape,
-  //             const bool isUpdateViewer = true);
+  void display(FeaturePtr theFeature, const TopoDS_Shape& theShape, bool isUpdateViewer = true);
   
   /// Returns a list of viewer selected presentations
   /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
   /// \return list of presentations
   std::list<XGUI_ViewerPrs> getSelected(const int theShapeTypeToSkip = -1);
 
+  /**
+  * Returns list of features currently selected in 3d viewer
+  */
+  QFeatureList selectedFeatures() const;
+
   /// Returns a list of viewer highlited presentations
   /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
   /// \return list of presentations
@@ -104,6 +109,13 @@ public:
   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
   void setSelected(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isUpdateViewer);
 
+  /**
+  * Add presentations which corresponds to the given features to current selection
+  * \param theFeatures a list of features to be selected
+  * isUpdateViewer the parameter whether the viewer should be update immediatelly
+  */
+  void setSelected(const QFeatureList& theFeatures, bool isUpdateViewer = true);
+
   /// Erase the feature and a shape.
   /// \param theFeature a feature instance
   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
index 7c2529bd5974998c34aab10dff4b63d185ebc1bd..09d530bab70ea5be675096b2f80c335231eb7c63 100644 (file)
@@ -501,11 +501,8 @@ Qt::ItemFlags XGUI_DocumentDataModel::flags(const QModelIndex& theIndex) const
 
 QModelIndex XGUI_DocumentDataModel::partIndex(const FeaturePtr& theFeature) const 
 {
-  FeaturePtr aFeature = theFeature;
-  if (XGUI_Tools::isModelObject(aFeature)) {
-    ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
-    aFeature = aObject->featureRef();
-  }
+  FeaturePtr aFeature = XGUI_Tools::realFeature(theFeature);
+
   int aRow = -1;
   XGUI_PartModel* aModel = 0;
   foreach (XGUI_PartModel* aPartModel, myPartModels) {
@@ -520,3 +517,40 @@ QModelIndex XGUI_DocumentDataModel::partIndex(const FeaturePtr& theFeature) cons
   }
   return QModelIndex();
 }
+
+QModelIndex XGUI_DocumentDataModel::featureIndex(const FeaturePtr theFeature) const
+{
+  // Check that this feature belongs to root document
+  DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+  DocumentPtr aDoc = theFeature->document();
+  if (aDoc == aRootDoc) {
+    // This feature belongs to histrory or top model
+    if (theFeature->isInHistory()) {
+      int aId;
+      for (aId = 0; aId < aRootDoc->size(FEATURES_GROUP); aId++) {
+        if (theFeature == aRootDoc->feature(FEATURES_GROUP, aId))
+          break;
+      }
+      return index(aId + historyOffset(), 0, QModelIndex());
+    } else {
+      QModelIndex aIndex = myModel->featureIndex(theFeature);
+      return aIndex.isValid()? 
+        createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex)) :
+        QModelIndex();
+    }
+  } else {
+    XGUI_PartModel* aPartModel = 0;
+    foreach(XGUI_PartModel* aModel, myPartModels) {
+      if (aModel->hasDocument(aDoc)) {
+        aPartModel = aModel;
+        break;
+      }
+    }
+    if (aPartModel) {
+      QModelIndex aIndex = aPartModel->featureIndex(theFeature);
+      return aIndex.isValid()? 
+        createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex)) :
+        QModelIndex();
+    }
+  }
+}
\ No newline at end of file
index 6683db4c9e228141c715ce603f98402f2f0279e4..a5257a981c7d1041f9a991d97447bcbf08f54269 100644 (file)
@@ -56,6 +56,8 @@ public:
   //! Returns 0 if the given index is not index of a feature
   FeaturePtr feature(const QModelIndex& theIndex) const;
 
+  QModelIndex featureIndex(const FeaturePtr theFeature) 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;
@@ -64,8 +66,10 @@ public:
   //! Returns true if active part changed.
   bool activatedIndex(const QModelIndex& theIndex);
 
+  //! Retrurns Feature which corresponds to active part
   FeaturePtr activePart() const;
 
+  //! Retrurns QModelIndex of active part
   QModelIndex activePartIndex() const { return myActivePartIndex; }
 
   //! Deactivates a Part
index f77f005e884fba1757c1566c3f71e51378c85d9a..27b92756283b4e6304239e698a03adb627b4ba26 100644 (file)
@@ -329,4 +329,19 @@ void XGUI_ObjectsBrowser::rebuildDataTree()
 {
   myDocModel->rebuildDataTree();
   update();
-}
\ No newline at end of file
+}
+
+//***************************************************
+void XGUI_ObjectsBrowser::setFeaturesSelected(const QFeatureList& theFeatures)
+{
+  QList<QModelIndex> theIndexes;
+  QItemSelectionModel* aSelectModel = myTreeView->selectionModel();
+  aSelectModel->clear();
+
+  foreach(FeaturePtr aFeature, theFeatures) {
+    QModelIndex aIndex = myDocModel->featureIndex(aFeature);
+    if (aIndex.isValid()) {
+      aSelectModel->select(aIndex, QItemSelectionModel::Select);
+    }
+  }
+}
index f9ae1fed396eebd1d8cd0c67675848eb252b04f1..70c13d11cc8648fed3d496090fe423ffd1003802 100644 (file)
@@ -66,6 +66,8 @@ public:
   //! Returns list of currently selected features
   QFeatureList selectedFeatures() const { return myFeaturesList; }
 
+  void setFeaturesSelected(const QFeatureList& theFeatures);
+
   //! Returns currently selected indexes
   QModelIndexList selectedIndexes() const { return myTreeView->selectionModel()->selectedIndexes(); }
 
index ea8c1a51a9ebed97ff22272368516875ed531882..7ce708e65fe4e12e7c3faf5fbeb521512428d71e 100644 (file)
@@ -445,11 +445,11 @@ QModelIndex XGUI_PartDataModel::featureIndex(const FeaturePtr& theFeature) const
       return aIndex;
 
     std::string aGroup = theFeature->getGroup();
-    DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
-    int aNb = aRootDoc->size(aGroup);
+    DocumentPtr aDoc = theFeature->document();
+    int aNb = aDoc->size(aGroup);
     int aRow = -1;
     for (int i = 0; i < aNb; i++) {
-      if (aRootDoc->feature(aGroup, i) == theFeature) {
+      if (aDoc->feature(aGroup, i) == theFeature) {
         aRow = i;
         break;
       }
index 8d43fe46e440d067586f7747275ff883468696c9..fabadeb8b076829ac42f27163cb0b9d36b373316 100644 (file)
@@ -106,6 +106,8 @@ public:
   virtual FeaturePtr part() const;
 
 private: 
+
+  //! Returns document of the current part
   DocumentPtr featureDocument() const;
 
   //! Types of QModelIndexes
index b00d5aea391c940138b1320dbfb5f5d8d7411d48..a07008bfc7c66d7c22e4f5205be7bf28c4286f07 100644 (file)
@@ -57,6 +57,7 @@ signals:
   void keyRelease(QKeyEvent* theEvent);
   void activated();
 
+  void selectionChanged();
 };
 
 #endif
\ No newline at end of file
index f949c782a5a4b4a7ca17f5440ef2a7513a1cc441..9f830a74ec5757257915168ab59afcb277ad6e58 100644 (file)
@@ -1,10 +1,11 @@
 #include "XGUI_SelectionMgr.h"
+
 #include "XGUI_Workshop.h"
 #include "XGUI_MainWindow.h"
 #include "XGUI_ObjectsBrowser.h"
-#include "XGUI_Viewer.h"
 #include "XGUI_SalomeConnector.h"
 #include "XGUI_ViewerProxy.h"
+#include "XGUI_Displayer.h"
 
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_PluginManager.h>
@@ -29,20 +30,16 @@ void XGUI_SelectionMgr::connectViewers()
     this, SLOT(onObjectBrowserSelection()));
 
   //Connect to other viewers
-  if (myWorkshop->isSalomeMode()) {
-    connect(myWorkshop, SIGNAL(salomeViewerSelection()),
-      this, SLOT(onViewerSelection()));
-  } else {
-    connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
-      this, SLOT(onViewerSelection()));
-  }
+  connect(myWorkshop->viewer(), SIGNAL(selectionChanged()),
+    this, SLOT(onViewerSelection()));
 }
 
 //**************************************************************
 void XGUI_SelectionMgr::onObjectBrowserSelection()
 {
-
-  // TODO: Highliht selected objects in Viewer 3d
+  QFeatureList aFeatures = selectedFeatures();
+  XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+  aDisplayer->setSelected(aFeatures);
 
   emit selectionChanged();
 }
@@ -50,7 +47,9 @@ void XGUI_SelectionMgr::onObjectBrowserSelection()
 //**************************************************************
 void XGUI_SelectionMgr::onViewerSelection()
 {
-  // TODO: Highliht selected objects in Object Browser
+  XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+  QFeatureList aFeatures = aDisplayer->selectedFeatures();
+  myWorkshop->objectBrowser()->setFeaturesSelected(aFeatures);
   emit selectionChanged();
 }
 
index 3148bc274b06024ee92ff0c92168b7826726455b..5cf560636b93be6c263d9eea048d6b664f0c32b6 100644 (file)
@@ -1,7 +1,7 @@
 #include "XGUI_Tools.h"
 
 #include <TopoDS_Shape.hxx>
-#include <ModelAPI_Feature.h>
+#include <ModelAPI_Object.h>
 
 #include <QDir>
 
@@ -70,4 +70,15 @@ std::string featureInfo(FeaturePtr theFeature)
   return QString(aStream.str().c_str()).toStdString();
 }
 
-}
\ No newline at end of file
+//******************************************************************
+FeaturePtr realFeature(const FeaturePtr theFeature)
+{
+  if (theFeature->data()) {
+    return theFeature;
+  } else {
+    ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(theFeature);
+    return aObject->featureRef();
+  }
+}
+
+}
index f2f2b9d88c5b98a2abc2a9c89d47b7c7f8fe9645..fa1c78af5652a8760b24c5639f76099e8d8a08bb 100644 (file)
@@ -72,6 +72,11 @@ namespace XGUI_Tools
    \param theFeature a feature
   */
   std::string XGUI_EXPORT featureInfo(FeaturePtr theFeature);
+
+  /**
+  * Returns pointer on real feature
+  */
+  FeaturePtr realFeature(const FeaturePtr theFeature);
 }
 
 #endif
index c3ae206ca44440ac40effb8a549a385d323f08cd..b5c3706da956764bebaa2b0db2a2341369ba8805 100644 (file)
@@ -95,6 +95,8 @@ void XGUI_ViewerProxy::connectToViewer()
     
     connect(aViewer, SIGNAL(keyRelease(QKeyEvent*)),
             this, SIGNAL(keyRelease(QKeyEvent*)));
+
+    connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
   } else {
     XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
 
@@ -121,6 +123,8 @@ void XGUI_ViewerProxy::connectToViewer()
             this, SLOT(onKeyPress(XGUI_ViewWindow*, QKeyEvent*)));
     connect(aViewer, SIGNAL(keyRelease(XGUI_ViewWindow*, QKeyEvent*)),
             this, SLOT(onKeyRelease(XGUI_ViewWindow*, QKeyEvent*)));
+
+    connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
   }
 }
 
index 8ac845aaa1c8effe5d6fb8b6b6b4b812732f949e..ca06c5e1f6007d6f78b9c616384d21a00e475bdd 100644 (file)
@@ -841,6 +841,14 @@ void XGUI_Workshop::deleteFeatures(QFeatureList theList)
 //**************************************************************
 void XGUI_Workshop::showFeatures(QFeatureList theList, bool isVisible)
 {
-//  foreach (FeaturePtr aFeature, theList) {
-//  }
+  if (isVisible) {
+    foreach (FeaturePtr aFeature, theList) {
+      myDisplayer->display(aFeature, false);
+    }
+  } else {
+    foreach (FeaturePtr aFeature, theList) {
+      myDisplayer->erase(aFeature, false);
+    }
+  }
+  myDisplayer->updateViewer();
 }