Salome HOME
Update copyright information
[modules/visu.git] / src / VISUGUI / VisuGUI_OffsetDlg.cxx
index 759c9948cda2971b8044c6e16174dd6883dc46e3..b0e0b0cde4f33a0c823e2d46bd95b2df61b791a2 100644 (file)
@@ -1,18 +1,20 @@
-// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-// 
+//
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either 
+// License as published by the Free Software Foundation; either
 // version 2.1 of the License.
-// 
-// This library is distributed in the hope that it will be useful 
-// but WITHOUT ANY WARRANTY; without even the implied warranty of 
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 // Lesser General Public License for more details.
 //
-// You should have received a copy of the GNU Lesser General Public  
-// License along with this library; if not, write to the Free Software 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #include "VISU_Actor.h"
 
 #include "LightApp_Application.h"
+#include "LightApp_SelectionMgr.h"
+#include "SALOME_ListIteratorOfListIO.hxx"
 #include "SalomeApp_Application.h"
+#include <SalomeApp_DoubleSpinBox.h>
 #include "SVTK_ViewWindow.h"
 #include "SVTK_ViewModel.h"
+#include "SUIT_ViewManager.h"
 #include "SUIT_Desktop.h"
 #include "SUIT_Session.h"
 #include "SUIT_MessageBox.h"
 #include "SUIT_ResourceMgr.h"
 
-#include "QtxDblSpinBox.h"
-
 // VTK Includes
 #include "vtkRenderer.h"
 
 // QT Includes
-#include <qhbox.h>
-#include <qlabel.h>
-#include <qlayout.h>
-#include <qcheckbox.h>
-#include <qgroupbox.h>
-#include <qpushbutton.h>
+#include <QLabel>
+#include <QLayout>
+#include <QCheckBox>
+#include <QGroupBox>
+#include <QPushButton>
+#include <QKeyEvent>
 
 
 #define  MAXVAL 1e10
 
 
 VisuGUI_OffsetDlg::VisuGUI_OffsetDlg (VisuGUI* theModule)
-: QDialog(VISU::GetDesktop(theModule), 0, false, WStyle_Customize |
-          WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
-myModule(theModule)
+: QDialog(VISU::GetDesktop(theModule), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
+  myModule(theModule),
+  mySelectionMgr(VISU::GetSelectionMgr(theModule))
 {
-  myPrsList.setAutoDelete(false);
+  //myPrsList.setAutoDelete(false);
+  //myPointMapList.setAutoDelete(false);
 
-  setName("VisuGUI_OffsetDlg");
-  setCaption(tr("TIT_OFFSETDLG"));
+  setWindowTitle(tr("TIT_OFFSETDLG"));
   setSizeGripEnabled(TRUE);
 
   QVBoxLayout* TopLayout = new QVBoxLayout (this);
   TopLayout->setSpacing(6);
   TopLayout->setMargin(11);
 
-  QHBox* anOffsetsPane = new QHBox (this);
-  anOffsetsPane->setSpacing(6);
+  QWidget* anOffsetsPane = new QWidget (this);
+  QHBoxLayout* aHBLay = new QHBoxLayout( anOffsetsPane );
+  aHBLay->setSpacing(6);
 
-  new QLabel ("dX:", anOffsetsPane);
-  myDxEdt = new QtxDblSpinBox (anOffsetsPane, "myDxEdt");
-  myDxEdt->setRange(-MAXVAL, MAXVAL);
+  aHBLay->addWidget( new QLabel ("dX:", anOffsetsPane) );
+  aHBLay->addWidget( myDxEdt = new SalomeApp_DoubleSpinBox (anOffsetsPane) );
+  VISU::initSpinBox( myDxEdt, -MAXVAL, MAXVAL, 1., "length_precision" );
 
-  new QLabel("dY:", anOffsetsPane);
-  myDyEdt = new QtxDblSpinBox (anOffsetsPane, "myDyEdt");
-  myDyEdt->setRange(-MAXVAL, MAXVAL);
+  aHBLay->addWidget( new QLabel("dY:", anOffsetsPane) );;
+  aHBLay->addWidget( myDyEdt = new SalomeApp_DoubleSpinBox (anOffsetsPane) );
+  VISU::initSpinBox( myDyEdt, -MAXVAL, MAXVAL, 1., "length_precision" );
 
-  new QLabel("dZ:", anOffsetsPane);
-  myDzEdt = new QtxDblSpinBox (anOffsetsPane, "myDzEdt");
-  myDzEdt->setRange(-MAXVAL, MAXVAL);
+  aHBLay->addWidget( new QLabel("dZ:", anOffsetsPane) );
+  aHBLay->addWidget( myDzEdt = new SalomeApp_DoubleSpinBox (anOffsetsPane) );
+  VISU::initSpinBox( myDzEdt, -MAXVAL, MAXVAL, 1., "length_precision" );
 
   QPushButton* aResetBtn = new QPushButton(tr("BTN_RESET"), anOffsetsPane);
+  aHBLay->addWidget( aResetBtn );
   connect(aResetBtn, SIGNAL(clicked()), this, SLOT(onReset()));
 
   TopLayout->addWidget(anOffsetsPane);
@@ -96,32 +102,32 @@ myModule(theModule)
   }
 
   // Common buttons ===========================================================
-  QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
-  GroupButtons->setColumnLayout(0, Qt::Vertical);
-  GroupButtons->layout()->setSpacing(0);
-  GroupButtons->layout()->setMargin(0);
-  QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
+  QGroupBox* GroupButtons = new QGroupBox(this);
+  //GroupButtons->setColumnLayout(0, Qt::Vertical);
+  //GroupButtons->layout()->setSpacing(0);
+  //GroupButtons->layout()->setMargin(0);
+  QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons);
   GroupButtonsLayout->setAlignment(Qt::AlignTop);
   GroupButtonsLayout->setSpacing(6);
   GroupButtonsLayout->setMargin(11);
 
-  QPushButton* buttonOk = new QPushButton(tr("&OK"), GroupButtons, "buttonOk");
+  QPushButton* buttonOk = new QPushButton(tr("&OK"), GroupButtons);
   buttonOk->setAutoDefault(TRUE);
   buttonOk->setDefault(TRUE);
   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
   GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
 
-  QPushButton* buttonApply = new QPushButton(tr("&Apply"), GroupButtons, "buttonApply");
+  QPushButton* buttonApply = new QPushButton(tr("&Apply"), GroupButtons);
   buttonOk->setAutoDefault(TRUE);
   GroupButtonsLayout->addWidget(buttonApply, 0, 2);
   GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 3);
 
-  QPushButton* buttonCancel = new QPushButton(tr("&Cancel") , GroupButtons, "buttonCancel");
+  QPushButton* buttonCancel = new QPushButton(tr("&Cancel") , GroupButtons);
   buttonCancel->setAutoDefault(TRUE);
   GroupButtonsLayout->addWidget(buttonCancel, 0, 4);
   GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 5);  
 
-  QPushButton* buttonHelp = new QPushButton(tr("&Help") , GroupButtons, "buttonHelp");
+  QPushButton* buttonHelp = new QPushButton(tr("&Help") , GroupButtons );
   buttonHelp->setAutoDefault(TRUE);
   GroupButtonsLayout->addWidget(buttonHelp, 0, 6);
 
@@ -131,6 +137,50 @@ myModule(theModule)
   connect(buttonApply,  SIGNAL(clicked()), this, SLOT(onApply()));
   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(onHelp()));
+  connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
+  
+  onSelectionChanged();
+  show();
+}
+
+void VisuGUI_OffsetDlg::setVisible(bool show){
+  if ( show  && getPrsCount() > 0 )
+    QDialog::setVisible( show );
+  else
+    QDialog::setVisible( show );
+}
+
+void VisuGUI_OffsetDlg::onSelectionChanged(){
+  if(!mySelectionMgr)
+    return;
+  
+  //Clear old selection
+  clearPresentations();
+
+  SALOME_ListIO aListIO;
+  mySelectionMgr->selectedObjects(aListIO);
+
+  SalomeApp_Study* aStudy = VISU::GetAppStudy(myModule);
+  SALOME_ListIteratorOfListIO anIter(aListIO);
+  for (; anIter.More(); anIter.Next()) {
+    Handle(SALOME_InteractiveObject) anIO = anIter.Value();
+    if (anIO->hasEntry()) {
+      QString anEntry(anIO->getEntry());
+      VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(aStudy, anEntry.toLatin1().constData());
+      if(VISU::Prs3d_i* aPrsObject = VISU::GetPrs3dFromBase(anObjectInfo.myBase))
+        addPresentation(aPrsObject);
+      else if (VISU::PointMap3d_i* aPrs = dynamic_cast<VISU::PointMap3d_i*>(anObjectInfo.myBase)) {
+        addPointMapPresentation(aPrs);
+      }
+    }
+  }
+}
+
+void VisuGUI_OffsetDlg::clearPresentations(){
+  myPrsList.clear();
+  myPointMapList.clear();
+  myOldOffsets.clear();
+  myOldPointMapOffsets.clear();
 }
 
 void VisuGUI_OffsetDlg::addPresentation (VISU::Prs3d_i* thePrs)
@@ -148,6 +198,22 @@ void VisuGUI_OffsetDlg::addPresentation (VISU::Prs3d_i* thePrs)
   }
 }
 
+void VisuGUI_OffsetDlg::addPointMapPresentation (VISU::PointMap3d_i* thePrs)
+{
+  myPointMapList.append(thePrs);
+
+  CORBA::Float anOffset[3];
+  thePrs->GetOffset(anOffset[0],anOffset[1],anOffset[2]);
+  OffsetStruct anOffs(anOffset[0],anOffset[1],anOffset[2]);
+  myOldPointMapOffsets.append(anOffs);
+  if (myPointMapList.count() == 1) {
+    setOffset(anOffs.myOffset);
+  } else if (myPointMapList.count() == 2) {
+    OffsetStruct anOffs;
+    setOffset(anOffs.myOffset);
+  }
+}
+
 void VisuGUI_OffsetDlg::setOffset (const vtkFloatingPointType* theOffset)
 {
   myDxEdt->setValue(theOffset[0]);
@@ -179,31 +245,60 @@ bool VisuGUI_OffsetDlg::isToSave() const
 
 void VisuGUI_OffsetDlg::updateOffset (VISU::Prs3d_i* thePrs, vtkFloatingPointType* theOffset)
 {
-  if (myPrsList.count() == 0) return;
+  if (myPrsList.count() == 0) 
+    return;
 
-  if (isToSave()) thePrs->SetOffset(theOffset[0],theOffset[1],theOffset[2]);
+  if (isToSave()) {
+    thePrs->SetOffset(theOffset[0],theOffset[1],theOffset[2]);
+    thePrs->UpdateActors();
+    return;
+  }
 
   ViewManagerList aViewManagerList;
   SalomeApp_Application* anApp = myModule->getApp();
   anApp->viewManagers(aViewManagerList);
-  QPtrListIterator<SUIT_ViewManager> anVMIter (aViewManagerList);
-  for (; anVMIter.current(); ++anVMIter) {
-    SUIT_ViewManager* aViewManager = anVMIter.current();
-    QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
+  QList<SUIT_ViewManager*>::Iterator anVMIter = aViewManagerList.begin();
+  for (; anVMIter !=  aViewManagerList.end(); anVMIter++ ) {
+    QVector<SUIT_ViewWindow*> aViews = (*anVMIter)->getViews();
     for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
       if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
         if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
-         vw->onAdjustTrihedron();
+          if (VISU_Actor* anActor = VISU::FindActor(vw, thePrs)) {
+                anActor->SetPosition(theOffset);
+            vw->onAdjustTrihedron();
+            vw->getRenderer()->ResetCameraClippingRange();
+            vw->Repaint();
+          }
+        }
+      }
+    }
+  }
+}
+
+void VisuGUI_OffsetDlg::updatePointMapOffset (VISU::PointMap3d_i* thePrs, vtkFloatingPointType* theOffset)
+{
+  if (myPointMapList.count() == 0) 
+    return;
+
+  if (isToSave())
+    thePrs->SetOffset(theOffset[0],theOffset[1],theOffset[2]);
+
+  ViewManagerList aViewManagerList;
+  SalomeApp_Application* anApp = myModule->getApp();
+  anApp->viewManagers(aViewManagerList);
+  SUIT_ViewManager* aViewManager;
+  foreach( aViewManager, aViewManagerList ) {
+    QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
+    for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
+      if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
+        if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
+          vw->onAdjustTrihedron();
 
-          if (VISU_Actor* anActor = VISU::GetActor(thePrs, vw)) {
+          if (VISU_ActorBase* anActor = VISU::FindActorBase(vw, thePrs)) {
             anActor->SetPosition(theOffset);
+            vw->highlight(thePrs->GetIO(), 1);
             vw->getRenderer()->ResetCameraClippingRange();
             vw->Repaint();
-
-            Handle(SALOME_InteractiveObject) anIO;
-            CORBA::Object_var anObject = VISU::GetSelectedObj(myModule, &anIO);
-            if (!CORBA::is_nil(anObject))
-             vw->highlight(anIO, 1);
           }
         }
       }
@@ -218,6 +313,9 @@ void VisuGUI_OffsetDlg::accept()
   for (int i = 0; i < myPrsList.count(); i++) {
     updateOffset(myPrsList.at(i), anOffset);
   }
+  for (int i = 0; i < myPointMapList.count(); i++) {
+    updatePointMapOffset(myPointMapList.at(i), anOffset);
+  }
   QDialog::accept();
 }
 
@@ -226,6 +324,9 @@ void VisuGUI_OffsetDlg::reject()
   for (int i = 0; i < myPrsList.count(); i++) {
     updateOffset(myPrsList.at(i), myOldOffsets[i].myOffset);
   }
+  for (int i = 0; i < myPointMapList.count(); i++) {
+    updatePointMapOffset(myPointMapList.at(i), myOldPointMapOffsets[i].myOffset);
+  }
   QDialog::reject();
 }
 
@@ -233,21 +334,44 @@ void VisuGUI_OffsetDlg::onApply()
 {
   vtkFloatingPointType anOffset[3];
   getOffset(anOffset);
+
   for (int i = 0; i < myPrsList.count(); i++) {
     updateOffset(myPrsList.at(i), anOffset);
   }
+  for (int i = 0; i < myPointMapList.count(); i++) {
+    updatePointMapOffset(myPointMapList.at(i), anOffset);
+  }
 }
 
 void VisuGUI_OffsetDlg::onHelp()
 {
-  QString aHelpFileName = "/files/scaling_presentations.htm";
+  QString aHelpFileName = "translate_presentation_page.html";
   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
   if (app)
     app->onHelpContextModule(myModule ? app->moduleName(myModule->moduleName()) : QString(""), aHelpFileName);
   else {
-    SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
-                          QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
-                          arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),
-                          QObject::tr("BUT_OK"));
+    QString platform;
+#ifdef WIN32
+    platform = "winapplication";
+#else
+    platform = "application";
+#endif
+    SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
+                             QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
+                             arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
+                             QObject::tr("BUT_OK"));
   }
 }
+
+void VisuGUI_OffsetDlg::keyPressEvent( QKeyEvent* e )
+{
+  QDialog::keyPressEvent( e );
+  if ( e->isAccepted() )
+    return;
+
+  if ( e->key() == Qt::Key_F1 )
+    {
+      e->accept();
+      onHelp();
+    }
+}