Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MoveNodesDlg.cxx
index fba4f187f6718e2bb6dc3948a18232e7b27192d8..ebcfd21d8b5b036496c221d52eb88e3292ae67a7 100644 (file)
 #include "SMDS_Mesh.hxx"
 #include "SMDS_MeshNode.hxx"
 
-#include "SalomeApp_SelectionMgr.h"
+#include "LightApp_SelectionMgr.h"
+#include "LightApp_Application.h"
 #include "SUIT_ResourceMgr.h"
 #include "SUIT_Desktop.h"
+#include "SUIT_Session.h"
+#include "SUIT_MessageBox.h"
 
 #include "SVTK_Selector.h"
 #include "SVTK_ViewModel.h"
@@ -49,6 +52,7 @@
 #include "SALOME_ListIO.hxx"
 
 #include "SVTK_ViewWindow.h"
+#include "VTKViewer_CellLocationsArray.h"
 
 #include "utilities.h"
 
 // VTK includes
 #include <vtkCell.h>
 #include <vtkIdList.h>
-#include <vtkIntArray.h>
 #include <vtkCellArray.h>
 #include <vtkUnsignedCharArray.h>
 #include <vtkUnstructuredGrid.h>
 #include <vtkDataSetMapper.h>
+#include <vtkProperty.h>
 
 // QT includes
 #include <qgroupbox.h>
@@ -93,9 +97,7 @@ SMESHGUI_MoveNodesDlg::SMESHGUI_MoveNodesDlg (SMESHGUI* theModule,
          theName, 
          false,
          WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
-  mySelector(SMESH::GetViewWindow(theModule)->GetSelector()),
   mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
-  myViewWindow(SMESH::GetViewWindow(theModule)),
   mySMESHGUI(theModule)
 {
   myPreviewActor = 0;
@@ -113,6 +115,10 @@ SMESHGUI_MoveNodesDlg::SMESHGUI_MoveNodesDlg (SMESHGUI* theModule,
 
   aDlgLay->setStretchFactor(aMainFrame, 1);
 
+  mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
+
+  myHelpFileName = "/files/displacing_nodes.htm";
+
   Init();
 }
 
@@ -128,6 +134,7 @@ QFrame* SMESHGUI_MoveNodesDlg::createButtonFrame (QWidget* theParent)
   myOkBtn     = new QPushButton(tr("SMESH_BUT_OK"   ), aFrame);
   myApplyBtn  = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
   myCloseBtn  = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
+  myHelpBtn   = new QPushButton(tr("SMESH_BUT_HELP"), aFrame);
 
   QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
 
@@ -137,10 +144,12 @@ QFrame* SMESHGUI_MoveNodesDlg::createButtonFrame (QWidget* theParent)
   aLay->addWidget(myApplyBtn);
   aLay->addItem(aSpacer);
   aLay->addWidget(myCloseBtn);
+  aLay->addWidget(myHelpBtn);
 
   connect(myOkBtn,    SIGNAL(clicked()), SLOT(onOk()));
   connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
   connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
+  connect(myHelpBtn,  SIGNAL(clicked()), SLOT(onHelp()));
 
   return aFrame;
 }
@@ -153,8 +162,8 @@ QFrame* SMESHGUI_MoveNodesDlg::createMainFrame (QWidget* theParent)
 {
   QFrame* aFrame = new QFrame(theParent);
 
-  QPixmap iconMoveNode (SMESHGUI::resourceMgr()->loadPixmap("SMESH", tr("ICON_DLG_MOVE_NODE")));
-  QPixmap iconSelect   (SMESHGUI::resourceMgr()->loadPixmap("SMESH", tr("ICON_SELECT")));
+  QPixmap iconMoveNode (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MOVE_NODE")));
+  QPixmap iconSelect   (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
 
   QButtonGroup* aPixGrp = new QButtonGroup(1, Qt::Vertical, tr("MESH_NODE"), aFrame);
   aPixGrp->setExclusive(TRUE);
@@ -223,14 +232,12 @@ void SMESHGUI_MoveNodesDlg::Init()
   reset();
   setEnabled(true);
 
-  int x, y;
-  mySMESHGUI->DefineDlgPosition(this, x, y);
-  this->move(x, y);
   this->show();
 
   // set selection mode
   SMESH::SetPointRepresentation(true);
-  myViewWindow->SetSelectionMode(NodeSelection);
+  if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+    aViewWindow->SetSelectionMode(NodeSelection);
 
   onSelectionDone();
 }
@@ -270,7 +277,7 @@ void SMESHGUI_MoveNodesDlg::reset()
 //=======================================================================
 bool SMESHGUI_MoveNodesDlg::onApply()
 {
-  if (SMESHGUI::GetSMESHGUI()->isActiveStudyLocked())
+  if (mySMESHGUI->isActiveStudyLocked())
     return false;
 
   if (!isValid(true))
@@ -321,15 +328,34 @@ void SMESHGUI_MoveNodesDlg::onOk()
 //=======================================================================
 void SMESHGUI_MoveNodesDlg::onClose()
 {
-  mySelectionMgr->clearSelected();
+  //mySelectionMgr->clearSelected();
   SMESH::SetPointRepresentation(false);
-  mySelector->SetSelectionMode(ActorSelection);
+  if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+    aViewWindow->SetSelectionMode(ActorSelection);
   disconnect(mySelectionMgr, 0, this, 0);
   disconnect(mySMESHGUI, 0, this, 0);
+  erasePreview();
   mySMESHGUI->ResetState();
   reject();
 }
 
+//=================================================================================
+// function : onHelp()
+// purpose  :
+//=================================================================================
+void SMESHGUI_MoveNodesDlg::onHelp()
+{
+  LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
+  if (app) 
+    app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
+  else {
+    SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
+                          QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
+                          arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
+                          QObject::tr("BUT_OK"));
+  }
+}
+
 //=======================================================================
 // name    : SMESHGUI_MoveNodesDlg::onTextChange
 // Purpose :
@@ -355,8 +381,11 @@ void SMESHGUI_MoveNodesDlg::onTextChange (const QString& theNewText)
       if(const SMDS_MeshElement *anElem = aMesh->FindElement(theNewText.toInt())) {
        TColStd_MapOfInteger aListInd;
        aListInd.Add(anElem->GetID());
-       mySelector->AddOrRemoveIndex(anIO,aListInd, true);
-       myViewWindow->highlight(anIO,true,true);
+       mySelector->AddOrRemoveIndex(anIO,aListInd, false);
+       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+         aViewWindow->highlight(anIO,true,true);
+       
+       onSelectionDone();
       }
     }
   }
@@ -417,11 +446,12 @@ void SMESHGUI_MoveNodesDlg::onDeactivate()
 void SMESHGUI_MoveNodesDlg::enterEvent (QEvent*)
 {
   if (!isEnabled()) {
-    SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog();
+    mySMESHGUI->EmitSignalDeactivateDialog();
 
     // set selection mode
     SMESH::SetPointRepresentation(true);
-    myViewWindow->SetSelectionMode(NodeSelection);
+    if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+      aViewWindow->SetSelectionMode(NodeSelection);
 
     redisplayPreview();
 
@@ -436,7 +466,8 @@ void SMESHGUI_MoveNodesDlg::enterEvent (QEvent*)
 void SMESHGUI_MoveNodesDlg::closeEvent (QCloseEvent*)
 {
   onClose();
-  myViewWindow->Repaint();
+  if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+    aViewWindow->Repaint();
 }
 
 //=======================================================================
@@ -469,10 +500,13 @@ void  SMESHGUI_MoveNodesDlg::erasePreview()
   if (myPreviewActor == 0)
     return;
 
-  myViewWindow->RemoveActor(myPreviewActor);
+  SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
+  if (aViewWindow)
+    aViewWindow->RemoveActor(myPreviewActor);
   myPreviewActor->Delete();
   myPreviewActor = 0;
-  myViewWindow->Repaint();
+  if (aViewWindow)
+    aViewWindow->Repaint();
 }
 
 //=======================================================================
@@ -513,7 +547,7 @@ void SMESHGUI_MoveNodesDlg::redisplayPreview()
   aCellTypesArray->InsertNextValue(VTK_VERTEX);
   anIdList->Delete();
 
-  vtkIntArray* aCellLocationsArray = vtkIntArray::New();
+  VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
   aCellLocationsArray->SetNumberOfComponents(1);
   aCellLocationsArray->SetNumberOfTuples(1);
 
@@ -546,6 +580,9 @@ void SMESHGUI_MoveNodesDlg::redisplayPreview()
   myPreviewActor->SetProperty(aProp);
   aProp->Delete();
 
-  myViewWindow->AddActor(myPreviewActor);
-  myViewWindow->Repaint();
+  if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+    {
+      aViewWindow->AddActor(myPreviewActor);
+      aViewWindow->Repaint();
+    }
 }