Salome HOME
Update Help for VISU module.
[modules/visu.git] / src / VISUGUI / VisuGUI_Selection.cxx
index 2f59ddf6c58a1a1de0b0633dc369ecd8e4576e65..7b0bf293add1a75d26156df1a4a51dd022f7624d 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"
@@ -74,7 +74,6 @@
 #include <qlineedit.h>
 #include <qvalidator.h>
 #include <qtable.h>
-#include <qlistview.h>
 
 // VTK Includes
 #include <vtkDataSetMapper.h>
@@ -88,7 +87,6 @@
 
 using namespace std;
 
-//extern VisuGUI *visuGUI;
 static VisuGUI_SelectionDlg* mySelectionDlg = NULL;
 
 VisuGUI_SelectionDlg::VisuGUI_SelectionDlg (QWidget* parent)
@@ -96,14 +94,13 @@ VisuGUI_SelectionDlg::VisuGUI_SelectionDlg (QWidget* parent)
                WStyle_Title | WStyle_SysMenu | WDestructiveClose),
        mySelectionMgr(NULL)
 {
-  //MESSAGE("VisuGUI_SelectionDlg::VisuGUI_SelectionDlg()");
   if (mySelectionDlg)
     mySelectionDlg->close(true);
 
   setCaption( "Data on elements" );
-  setSizeGripEnabled( TRUE );
+  setSizeGripEnabled(TRUE);
 
-  QGridLayout* TopLayout = new QGridLayout(this);
+  QGridLayout* TopLayout = new QGridLayout (this);
   TopLayout->setSpacing(6);
   TopLayout->setMargin(11);
   TopLayout->setRowStretch(0, 0);
@@ -111,25 +108,26 @@ VisuGUI_SelectionDlg::VisuGUI_SelectionDlg (QWidget* parent)
   TopLayout->setRowStretch(2, 1);
   TopLayout->setRowStretch(3, 0);
 
-  QHButtonGroup* aTypeBox = new QHButtonGroup("Selection", this);
+  QHButtonGroup* aTypeBox = new QHButtonGroup ("Selection", this);
 
-  QRadioButton* aPointBtn = new QRadioButton("Point", aTypeBox);
-  QRadioButton* aCellBtn = new QRadioButton("Cell", aTypeBox);
-  QRadioButton* aActorBtn = new QRadioButton("Actor", aTypeBox);
+  QRadioButton* aPointBtn =
+  new QRadioButton ("Point", aTypeBox);
+  new QRadioButton ("Cell" , aTypeBox);
+  new QRadioButton ("Actor", aTypeBox);
   aPointBtn->setChecked(true);
 
   connect(aTypeBox, SIGNAL(clicked(int)), this, SLOT(onSelectionChange(int)));
 
   TopLayout->addWidget(aTypeBox, 0, 0);
 
-  QWidget* aNamePane = new QWidget(this);
-  QGridLayout* aNameLay = new QGridLayout(aNamePane);
+  QWidget* aNamePane = new QWidget (this);
+  QGridLayout* aNameLay = new QGridLayout (aNamePane);
 
-  QLabel* aMeshLbl = new QLabel("Mesh name: ", aNamePane);
-  myMeshName = new QLabel(aNamePane);
+  QLabel* aMeshLbl = new QLabel ("Mesh name: ", aNamePane);
+  myMeshName = new QLabel (aNamePane);
 
-  QLabel* aFieldLbl = new QLabel("Field name: ", aNamePane);
-  myFieldName = new QLabel(aNamePane);
+  QLabel* aFieldLbl = new QLabel ("Field name: ", aNamePane);
+  myFieldName = new QLabel (aNamePane);
 
   aNameLay->addWidget(aMeshLbl, 0, 0);
   aNameLay->addWidget(myMeshName, 0, 1);
@@ -138,62 +136,62 @@ VisuGUI_SelectionDlg::VisuGUI_SelectionDlg (QWidget* parent)
 
   TopLayout->addWidget(aNamePane, 1, 0);
 
-  myWidgetStack = new QWidgetStack(this);
+  myWidgetStack = new QWidgetStack (this);
 
   // Create Points pane
-  myPointsPane = new QVBox(myWidgetStack);
+  myPointsPane = new QVBox (myWidgetStack);
   myPointsPane->layout()->setSpacing(6);
 
-  QGroupBox* aDataGrp = new QGroupBox(2, Qt::Horizontal, "Data of Point", myPointsPane);
+  QGroupBox* aDataGrp = new QGroupBox (2, Qt::Horizontal, "Data of Point", myPointsPane);
   aDataGrp->layout()->setSpacing(6);
 
-  QLabel* aIDLbl = new QLabel("ID:", aDataGrp);
-  myIDValLbl = new QLineEdit("", aDataGrp);
-  QIntValidator* aIntValidator = new QIntValidator(myIDValLbl);
+  new QLabel ("ID:", aDataGrp);
+  myIDValLbl = new QLineEdit ("", aDataGrp);
+  QIntValidator* aIntValidator = new QIntValidator (myIDValLbl);
   aIntValidator->setBottom(0);
   myIDValLbl->setValidator(aIntValidator);
   connect(myIDValLbl, SIGNAL(textChanged(const QString&)), this, SLOT(onPointIdEdit(const QString&)));
 
-  QLabel* aValueLbl = new QLabel("Scalar Value:", aDataGrp);
-  myScalarValLbl = new QLabel("", aDataGrp);
-  QLabel* aVectorLbl = new QLabel("Vector Value:", aDataGrp);
-  myVectorValLbl = new QLabel("", aDataGrp);
+  new QLabel ("Scalar Value:", aDataGrp);
+  myScalarValLbl = new QLabel ("", aDataGrp);
+  new QLabel ("Vector Value:", aDataGrp);
+  myVectorValLbl = new QLabel ("", aDataGrp);
   myVectorValLbl->setMinimumWidth(150);
 
-  QGroupBox* aCoordGrp = new QGroupBox(2, Qt::Horizontal, "Coordinates", myPointsPane);
+  QGroupBox* aCoordGrp = new QGroupBox (2, Qt::Horizontal, "Coordinates", myPointsPane);
   aCoordGrp->layout()->setSpacing(6);
-  QLabel* aXLbl = new QLabel("X:", aCoordGrp);
-  myXValLbl = new QLabel("", aCoordGrp);
-  QLabel* aYLbl = new QLabel("Y:", aCoordGrp);
-  myYValLbl = new QLabel("", aCoordGrp);
-  QLabel* aZLbl = new QLabel("Z:",aCoordGrp );
-  myZValLbl = new QLabel("", aCoordGrp);
+  new QLabel ("X:", aCoordGrp);
+  myXValLbl = new QLabel ("", aCoordGrp);
+  new QLabel ("Y:", aCoordGrp);
+  myYValLbl = new QLabel ("", aCoordGrp);
+  new QLabel ("Z:",aCoordGrp );
+  myZValLbl = new QLabel ("", aCoordGrp);
 
 
   myWidgetStack->addWidget(myPointsPane, 0);
 
   // Create Cells pane
-  myCellsPane = new QWidget(myWidgetStack);
-  QGridLayout* aCellLayout = new QGridLayout(myCellsPane);
+  myCellsPane = new QWidget (myWidgetStack);
+  QGridLayout* aCellLayout = new QGridLayout (myCellsPane);
   aCellLayout->setSpacing(6);
   aCellLayout->setRowStretch(0, 0);
   aCellLayout->setRowStretch(1, 1);
 
   QGroupBox* aCellGrp = new QGroupBox(2, Qt::Horizontal, "Data of Cell", myCellsPane);
 
-  QLabel* aCellIDLbl = new QLabel("ID:", aCellGrp);
-  myCellIDValLbl = new QLineEdit("", aCellGrp);
+  new QLabel ("ID:", aCellGrp);
+  myCellIDValLbl = new QLineEdit ("", aCellGrp);
   myCellIDValLbl->setValidator(aIntValidator);
   connect(myCellIDValLbl, SIGNAL(textChanged(const QString&)), this, SLOT(onCellIdEdit(const QString&)));
 
-  QLabel* aCellValueLbl = new QLabel("Scalar Value:", aCellGrp);
-  myCellScalarValLbl = new QLabel("", aCellGrp);
-  QLabel* aCellVectorLbl = new QLabel("Vector Value:", aCellGrp);
-  myCellVectorValLbl = new QLabel("", aCellGrp);
+  new QLabel ("Scalar Value:", aCellGrp);
+  myCellScalarValLbl = new QLabel ("", aCellGrp);
+  new QLabel ("Vector Value:", aCellGrp);
+  myCellVectorValLbl = new QLabel ("", aCellGrp);
 
   aCellLayout->addWidget(aCellGrp, 0, 0);
 
-  myListPoints = new QTable(myCellsPane);
+  myListPoints = new QTable (myCellsPane);
   myListPoints->setReadOnly(true);
   myListPoints->setNumCols(6);
   myListPoints->setNumRows(0);
@@ -215,26 +213,26 @@ VisuGUI_SelectionDlg::VisuGUI_SelectionDlg (QWidget* parent)
   myWidgetStack->addWidget(myCellsPane, 1);
 
   // Actor Pane
-  myActorsPane = new QVBox(myWidgetStack);
+  myActorsPane = new QVBox (myWidgetStack);
   myActorsPane->layout()->setSpacing(6);
 
-  QGroupBox* aPosGrp = new QGroupBox(2, Qt::Horizontal, "Position", myActorsPane);
+  QGroupBox* aPosGrp = new QGroupBox (2, Qt::Horizontal, "Position", myActorsPane);
   aPosGrp->layout()->setSpacing(6);
-  QLabel* aXPosLbl = new QLabel("X:", aPosGrp);
-  myXPosLbl = new QLabel("0", aPosGrp);
-  QLabel* aYPosLbl = new QLabel("Y:", aPosGrp);
-  myYPosLbl = new QLabel("0", aPosGrp);
-  QLabel* aZPosLbl = new QLabel("Z:", aPosGrp);
-  myZPosLbl = new QLabel("0", aPosGrp);
-
-  QGroupBox* aSizeGrp = new QGroupBox(2, Qt::Horizontal, "Size", myActorsPane);
+  new QLabel ("X:", aPosGrp);
+  myXPosLbl = new QLabel ("0", aPosGrp);
+  new QLabel ("Y:", aPosGrp);
+  myYPosLbl = new QLabel ("0", aPosGrp);
+  new QLabel ("Z:", aPosGrp);
+  myZPosLbl = new QLabel ("0", aPosGrp);
+
+  QGroupBox* aSizeGrp = new QGroupBox (2, Qt::Horizontal, "Size", myActorsPane);
   aSizeGrp->layout()->setSpacing(6);
-  QLabel* aXSizeLbl = new QLabel("dX:", aSizeGrp);
-  myDXLbl = new QLabel("0", aSizeGrp);
-  QLabel* aYSizeLbl = new QLabel("dY:", aSizeGrp);
-  myDYLbl = new QLabel("0", aSizeGrp);
-  QLabel* aZSizeLbl = new QLabel("dZ:",aSizeGrp );
-  myDZLbl = new QLabel("0", aSizeGrp);
+  new QLabel ("dX:", aSizeGrp);
+  myDXLbl = new QLabel ("0", aSizeGrp);
+  new QLabel ("dY:", aSizeGrp);
+  myDYLbl = new QLabel ("0", aSizeGrp);
+  new QLabel ("dZ:",aSizeGrp );
+  myDZLbl = new QLabel ("0", aSizeGrp);
 
   myWidgetStack->addWidget(myActorsPane, 2);
 
@@ -242,11 +240,11 @@ VisuGUI_SelectionDlg::VisuGUI_SelectionDlg (QWidget* parent)
   TopLayout->addWidget(myWidgetStack, 2, 0);
 
   // Create buttons group
-  QHBox* aBtnBox = new QHBox(this);
+  QHBox* aBtnBox = new QHBox (this);
   QHBoxLayout* aBtnLayout = (QHBoxLayout*)aBtnBox->layout();
   aBtnLayout->addStretch();
 
-  QPushButton* aCloseBtn = new QPushButton(tr("BUT_CLOSE"), aBtnBox);
+  QPushButton* aCloseBtn = new QPushButton (tr("BUT_CLOSE"), aBtnBox);
   connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(close()));
 
   TopLayout->addWidget(aBtnBox, 3, 0);
@@ -260,12 +258,11 @@ VisuGUI_SelectionDlg::VisuGUI_SelectionDlg (QWidget* parent)
 
   myFl = false;
 
-  //onSelectionChange(0);
-  SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow();
   // Activate Points pane
+  SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow();
   myWidgetStack->raiseWidget(myPointsPane);
-  aSVTKVW->SetSelectionMode(NodeSelection);
-  //onPointIdEdit(myIDValLbl->text());
+  if (aSVTKVW)
+    aSVTKVW->SetSelectionMode(NodeSelection);
   onSelectionEvent();
 
   mySelectionDlg = this;
@@ -273,30 +270,26 @@ VisuGUI_SelectionDlg::VisuGUI_SelectionDlg (QWidget* parent)
 
 VisuGUI_SelectionDlg::~VisuGUI_SelectionDlg()
 {
-  //MESSAGE("VisuGUI_SelectionDlg::~VisuGUI_SelectionDlg()");
 }
 
 void VisuGUI_SelectionDlg::onSelectionChange (int theId)
 {
-  //MESSAGE("VisuGUI_SelectionDlg::onSelectionChange()");
   SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow();
+  if (!aSVTKVW) return;
 
   switch (theId) {
   case 0: // Points
     myWidgetStack->raiseWidget(myPointsPane);
-    //mySelectionMgr->setSelectionModes(NodeSelection);
     aSVTKVW->SetSelectionMode(NodeSelection);
     onPointIdEdit(myIDValLbl->text());
     break;
   case 1: // Cells
     myWidgetStack->raiseWidget(myCellsPane);
-    //mySelectionMgr->setSelectionModes(CellSelection);
     aSVTKVW->SetSelectionMode(CellSelection);
     onCellIdEdit(myCellIDValLbl->text());
     break;
   case 2: // Actor
     myWidgetStack->raiseWidget(myActorsPane);
-    //mySelectionMgr->setSelectionModes(ActorSelection);
     aSVTKVW->SetSelectionMode(ActorSelection);
     onSelectionEvent();
   }
@@ -305,12 +298,11 @@ void VisuGUI_SelectionDlg::onSelectionChange (int theId)
 
 void VisuGUI_SelectionDlg::closeEvent (QCloseEvent* theEvent)
 {
-  //MESSAGE("VisuGUI_SelectionDlg::closeEvent()");
   SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow();
 
   mySelectionDlg = NULL;
-  //mySelectionMgr->setSelectionModes(ActorSelection);
-  aSVTKVW->SetSelectionMode(ActorSelection);
+  if (aSVTKVW)
+    aSVTKVW->SetSelectionMode(ActorSelection);
   disconnect(mySelectionMgr,0,0,0);
   QDialog::closeEvent(theEvent);
 }
@@ -336,27 +328,26 @@ template<class TData> QString getVector(TData* theData, int theId){
 #define ABS(a) (a>=0)?a:-a
 
 void VisuGUI_SelectionDlg::onSelectionEvent() {
-  //MESSAGE("VisuGUI_SelectionDlg::onSelectionEvent()");
+  SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow();
+  if (!aSVTKVW) return;
+
   if (myFl) return;
   myFl = true;
+
   int aType = myWidgetStack->id(myWidgetStack->visibleWidget());
 
   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
     (SUIT_Session::session()->activeApplication());
 
-  SVTK_ViewWindow* aSVTKVW = VISU::GetViewWindow();
   SVTK_Selector* aSelector = aSVTKVW->GetSelector();
 
   VISU::Prs3d_i* aPrs3d = NULL;
   _PTR(SObject) aSObject;
   Handle(SALOME_InteractiveObject) anIO;
 
-  //SALOME_ListIO aListIO;
-  //mySelectionMgr->selectedObjects(aListIO, SVTK_Viewer::Type());
-
-  const SALOME_ListIO& aListIO = aSelector->StoredIObjects();
+  SALOME_ListIO aListIO;
+  mySelectionMgr->selectedObjects(aListIO, SVTK_Viewer::Type());
 
-  //MESSAGE("aListIO.Extent() = " << aListIO.Extent());
   if (aListIO.Extent() == 1) {
     anIO = aListIO.First();
 
@@ -364,7 +355,6 @@ void VisuGUI_SelectionDlg::onSelectionEvent() {
       SalomeApp_Study* theStudy = dynamic_cast<SalomeApp_Study*>(anApp->activeStudy());
       _PTR(Study) aStudy = theStudy->studyDS();
       aSObject = aStudy->FindObjectID(anIO->getEntry());
-      //MESSAGE("anIO->hasEntry(): " << anIO->getEntry());
 
       if (aSObject) {
        CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObject);
@@ -387,7 +377,7 @@ void VisuGUI_SelectionDlg::onSelectionEvent() {
       if (aSObject->FindAttribute(anAttr, "AttributeComment")) {
         _PTR(AttributeComment) aComment (anAttr);
         std::string aString = aComment->Value();
-        QString strIn (aString);
+        QString strIn( aString.c_str() );
         VISU::Storable::StrToMap(strIn, aMap);
       }
     }
@@ -454,7 +444,6 @@ void VisuGUI_SelectionDlg::onSelectionEvent() {
 
                 float* aCoord;
                 vtkIdList *aPointList = aCell->GetPointIds();
-                QListViewItem* anItem = NULL;
 
                 for (int i = 0; i < aNbOfPoints; i++) {
                   int idCurrent = aPointList->GetId(i);
@@ -491,7 +480,6 @@ void VisuGUI_SelectionDlg::onSelectionEvent() {
 
 
 void VisuGUI_SelectionDlg::clearFields() {
-  //MESSAGE("VisuGUI_SelectionDlg::clearFields()");
   int aType = myWidgetStack->id(myWidgetStack->visibleWidget());
   switch (aType) {
   case 0:
@@ -523,24 +511,22 @@ typedef  vtkIdType (vtkDataSet::* TDataSetMethod)();
 bool onIdEdit (const QString& theText,
                TDataSetMethod theMethod,
                bool theIsCell,
-               SalomeApp_SelectionMgr* theSelectionMgr,
+               LightApp_SelectionMgr* theSelectionMgr,
                QLabel* theMeshName,
                QString theValue,
                QLabel* theFieldName)
 {
-  //MESSAGE("onIdEdit()");
   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();
 
   VISU::Prs3d_i* aPrs3d = NULL;
   Handle(SALOME_InteractiveObject) anIO;
 
-  //SALOME_ListIO aListIO;
-  //theSelectionMgr->selectedObjects(aListIO, SVTK_Viewer::Type());
-
-  const SALOME_ListIO& aListIO = aSelector->StoredIObjects();
+  SALOME_ListIO aListIO;
+  theSelectionMgr->selectedObjects(aListIO, SVTK_Viewer::Type());
 
   if (aListIO.Extent() == 1) {
     anIO = aListIO.First();
@@ -571,10 +557,6 @@ bool onIdEdit (const QString& theText,
     if (anId < 0) anId = 0;
     if (anId >= aMaxId) anId = aMaxId - 1;
 
-    //SALOME_ListIO sel;
-    //sel.Append(anIO);
-    //theSelectionMgr->setSelectedObjects(sel);
-
     TColStd_MapOfInteger newIndices;
     newIndices.Add(anId);
     aSelector->AddOrRemoveIndex(anIO, newIndices, false);
@@ -591,24 +573,28 @@ bool onIdEdit (const QString& theText,
 
 void VisuGUI_SelectionDlg::onPointIdEdit (const QString& theText)
 {
-  //MESSAGE("onPointIdEdit()");
   if (myFl) return;
   TDataSetMethod aMethod = &vtkDataSet::GetNumberOfPoints;
   bool anIsSelected = onIdEdit(theText,aMethod,false,mySelectionMgr,
                               myMeshName,tr("WRN_NO_AVAILABLE_DATA"),
                               myFieldName);
-  if (!anIsSelected)
+  if (anIsSelected)
+    // as selection manager doesn't send signal currentSelectionChanged()
+    onSelectionEvent();
+  else
     clearFields();
 }
 
 void VisuGUI_SelectionDlg::onCellIdEdit (const QString& theText)
 {
-  //MESSAGE("onCellIdEdit()");
   if (myFl) return;
   TDataSetMethod aMethod = &vtkDataSet::GetNumberOfCells;
   bool anIsSelected = onIdEdit(theText,aMethod,true,mySelectionMgr,
                               myMeshName,tr("WRN_NO_AVAILABLE_DATA"),
                               myFieldName);
-  if (!anIsSelected)
+  if (anIsSelected)
+    // as selection manager doesn't send signal currentSelectionChanged()
+    onSelectionEvent();
+  else
     clearFields();
 }