Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / VISUGUI / VisuGUI_Selection.cxx
index 433b64673207b693712e618506d3698e472d3397..5bcf465face56786563e21be085f1cefb845ce6a 100644 (file)
@@ -38,8 +38,8 @@
 
 #include "SalomeApp_Study.h"
 #include "SalomeApp_Application.h"
-#include "SalomeApp_SelectionMgr.h"
-#include "SalomeApp_VTKSelector.h"
+#include "LightApp_SelectionMgr.h"
+#include "LightApp_VTKSelector.h"
 
 #include "SUIT_MessageBox.h"
 #include "SUIT_ViewWindow.h"
@@ -89,10 +89,13 @@ using namespace std;
 
 static VisuGUI_SelectionDlg* mySelectionDlg = NULL;
 
-VisuGUI_SelectionDlg::VisuGUI_SelectionDlg (QWidget* parent)
-     : QDialog(parent, 0, false, WStyle_Customize | WStyle_NormalBorder |
-               WStyle_Title | WStyle_SysMenu | WDestructiveClose),
-       mySelectionMgr(NULL)
+VisuGUI_SelectionDlg::VisuGUI_SelectionDlg (const SalomeApp_Module* theModule):
+  QDialog(VISU::GetDesktop(theModule), 
+         0, 
+         false, 
+         WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
+  mySelectionMgr(NULL),
+  myModule(theModule)
 {
   if (mySelectionDlg)
     mySelectionDlg->close(true);
@@ -259,10 +262,9 @@ VisuGUI_SelectionDlg::VisuGUI_SelectionDlg (QWidget* parent)
   myFl = false;
 
   // Activate Points pane
-  SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow();
   myWidgetStack->raiseWidget(myPointsPane);
-  if (aSVTKVW)
-    aSVTKVW->SetSelectionMode(NodeSelection);
+  if(SVTK_ViewWindow* aViewWindow = VISU::GetViewWindow(myModule))
+    aViewWindow->SetSelectionMode(NodeSelection);
   onSelectionEvent();
 
   mySelectionDlg = this;
@@ -274,23 +276,23 @@ VisuGUI_SelectionDlg::~VisuGUI_SelectionDlg()
 
 void VisuGUI_SelectionDlg::onSelectionChange (int theId)
 {
-  SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow();
-  if (!aSVTKVW) return;
+  SVTK_ViewWindow* aViewWindow = VISU::GetViewWindow(myModule);
+  if (!aViewWindow) return;
 
   switch (theId) {
   case 0: // Points
     myWidgetStack->raiseWidget(myPointsPane);
-    aSVTKVW->SetSelectionMode(NodeSelection);
+    aViewWindow->SetSelectionMode(NodeSelection);
     onPointIdEdit(myIDValLbl->text());
     break;
   case 1: // Cells
     myWidgetStack->raiseWidget(myCellsPane);
-    aSVTKVW->SetSelectionMode(CellSelection);
+    aViewWindow->SetSelectionMode(CellSelection);
     onCellIdEdit(myCellIDValLbl->text());
     break;
   case 2: // Actor
     myWidgetStack->raiseWidget(myActorsPane);
-    aSVTKVW->SetSelectionMode(ActorSelection);
+    aViewWindow->SetSelectionMode(ActorSelection);
     onSelectionEvent();
   }
 }
@@ -298,12 +300,19 @@ void VisuGUI_SelectionDlg::onSelectionChange (int theId)
 
 void VisuGUI_SelectionDlg::closeEvent (QCloseEvent* theEvent)
 {
-  SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow();
-
-  mySelectionDlg = NULL;
-  if (aSVTKVW)
-    aSVTKVW->SetSelectionMode(ActorSelection);
-  disconnect(mySelectionMgr,0,0,0);
+  if( mySelectionDlg )
+  {
+    mySelectionDlg = NULL;
+    disconnect(mySelectionMgr,0,0,0);
+    if(SVTK_ViewWindow* aViewWindow = VISU::GetViewWindow(myModule)){
+      switch(aViewWindow->SelectionMode()){
+      case NodeSelection:
+      case CellSelection:
+       aViewWindow->SetSelectionMode(ActorSelection);
+       break;
+      }
+    }
+  }
   QDialog::closeEvent(theEvent);
 }
 
@@ -328,8 +337,18 @@ template<class TData> QString getVector(TData* theData, int theId){
 #define ABS(a) (a>=0)?a:-a
 
 void VisuGUI_SelectionDlg::onSelectionEvent() {
-  SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow();
-  if (!aSVTKVW) return;
+  SVTK_ViewWindow* aViewWindow = VISU::GetViewWindow(myModule);
+  if (!aViewWindow) return;
+
+  switch(aViewWindow->SelectionMode()){
+  case NodeSelection:
+  case CellSelection:
+  case ActorSelection:
+    break;
+  default:
+    close( TRUE );
+    return;
+  }
 
   if (myFl) return;
   myFl = true;
@@ -339,14 +358,14 @@ void VisuGUI_SelectionDlg::onSelectionEvent() {
   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
     (SUIT_Session::session()->activeApplication());
 
-  SVTK_Selector* aSelector = aSVTKVW->GetSelector();
+  SVTK_Selector* aSelector = aViewWindow->GetSelector();
 
   VISU::Prs3d_i* aPrs3d = NULL;
   _PTR(SObject) aSObject;
   Handle(SALOME_InteractiveObject) anIO;
 
   SALOME_ListIO aListIO;
-  mySelectionMgr->selectedObjects(aListIO, SVTK_Viewer::Type());
+  mySelectionMgr->selectedObjects(aListIO);
 
   if (aListIO.Extent() == 1) {
     anIO = aListIO.First();
@@ -392,7 +411,7 @@ void VisuGUI_SelectionDlg::onSelectionEvent() {
     myFieldName->setText((aFieldName == "NULL") ? QString("No name") : aFieldName);
 
     VISU_Actor* anVISUActor =
-      VISU::FindActor(aSVTKVW, aSObject->GetID().c_str());
+      VISU::FindActor(aViewWindow, aSObject->GetID().c_str());
     if (anVISUActor) {
       float aCoord[6];
       anVISUActor->GetBounds(aCoord);
@@ -414,33 +433,34 @@ void VisuGUI_SelectionDlg::onSelectionEvent() {
       vtkPointData* aPntData = aDataSet->GetPointData();
 
       for (int ind = 1; ind <= aMapIndex.Extent(); ind++) {
-        int aID = aMapIndex(ind);
+        int anID = aMapIndex(ind);
 
         switch (aType) {
         case 0:
           {
-            float aCoord[3];
-            aDataSet->GetPoint(aID, aCoord);
+            float* aCoord = anVISUActor->GetNodeCoord(anID);
+           int aVTKID = anVISUActor->GetNodeVTKID(anID);
             myXValLbl->setText( QString::number( aCoord[0] ) );
             myYValLbl->setText( QString::number( aCoord[1] ) );
             myZValLbl->setText( QString::number( aCoord[2] ) );
-            myIDValLbl->setText( QString::number(aID) );
-            myScalarValLbl->setText(getValue(aPntData, aID));
-            myVectorValLbl->setText(getVector(aPntData, aID));
+            myIDValLbl->setText( QString::number(anID) );
+            myScalarValLbl->setText(getValue(aPntData, aVTKID));
+            myVectorValLbl->setText(getVector(aPntData, aVTKID));
           }
           break;
         case 1:
           {
-            vtkCellData* aData = aDataSet->GetCellData();
-            vtkCell* aCell = aDataSet->GetCell(aID);
+            vtkCellData* aCellData = aDataSet->GetCellData();
+            vtkCell* aCell = anVISUActor->GetElemCell(anID);
+           int aVTKID = anVISUActor->GetElemVTKID(anID);
             if (aCell != NULL) {
               int aNbOfPoints = aCell->GetNumberOfPoints();
-              if (aNbOfPoints <=1 ) { // Cell is point
+              if ( aNbOfPoints <= 1 ) { // Cell is point
                 clearFields();
               } else {
-                myCellIDValLbl->setText( QString::number(aID) );
-                myCellScalarValLbl->setText(getValue(aData, aID));
-                myCellVectorValLbl->setText(getVector(aData, aID));
+                myCellIDValLbl->setText( QString::number(anID) );
+                myCellScalarValLbl->setText(getValue(aCellData, aVTKID));
+                myCellVectorValLbl->setText(getVector(aCellData, aVTKID));
 
                 float* aCoord;
                 vtkIdList *aPointList = aCell->GetPointIds();
@@ -511,16 +531,16 @@ typedef  vtkIdType (vtkDataSet::* TDataSetMethod)();
 bool onIdEdit (const QString& theText,
                TDataSetMethod theMethod,
                bool theIsCell,
-               SalomeApp_SelectionMgr* theSelectionMgr,
+              const SalomeApp_Module* theModule,
+               LightApp_SelectionMgr* theSelectionMgr,
                QLabel* theMeshName,
                QString theValue,
                QLabel* theFieldName)
 {
-  SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
-    (SUIT_Session::session()->activeApplication());
-  SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow();
-  if (!aSVTKVW) return false;
-  SVTK_Selector* aSelector = aSVTKVW->GetSelector();
+  SalomeApp_Application* anApp = theModule->getApp();
+  SVTK_ViewWindow* aViewWindow = VISU::GetViewWindow(theModule);
+  if (!aViewWindow) return false;
+  SVTK_Selector* aSelector = aViewWindow->GetSelector();
 
   VISU::Prs3d_i* aPrs3d = NULL;
   Handle(SALOME_InteractiveObject) anIO;
@@ -560,7 +580,7 @@ bool onIdEdit (const QString& theText,
     TColStd_MapOfInteger newIndices;
     newIndices.Add(anId);
     aSelector->AddOrRemoveIndex(anIO, newIndices, false);
-    aSVTKVW->highlight(anIO, true, true);
+    aViewWindow->highlight(anIO, true, true);
 
     return true;
 
@@ -575,7 +595,7 @@ void VisuGUI_SelectionDlg::onPointIdEdit (const QString& theText)
 {
   if (myFl) return;
   TDataSetMethod aMethod = &vtkDataSet::GetNumberOfPoints;
-  bool anIsSelected = onIdEdit(theText,aMethod,false,mySelectionMgr,
+  bool anIsSelected = onIdEdit(theText,aMethod,false,myModule,mySelectionMgr,
                               myMeshName,tr("WRN_NO_AVAILABLE_DATA"),
                               myFieldName);
   if (anIsSelected)
@@ -589,7 +609,7 @@ void VisuGUI_SelectionDlg::onCellIdEdit (const QString& theText)
 {
   if (myFl) return;
   TDataSetMethod aMethod = &vtkDataSet::GetNumberOfCells;
-  bool anIsSelected = onIdEdit(theText,aMethod,true,mySelectionMgr,
+  bool anIsSelected = onIdEdit(theText,aMethod,true,myModule,mySelectionMgr,
                               myMeshName,tr("WRN_NO_AVAILABLE_DATA"),
                               myFieldName);
   if (anIsSelected)