Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / VISUGUI / VisuGUI_IsoSurfacesDlg.cxx
index a5cc4f6126e2037423f927505477cb69317c801b..17a5e38387404527ce4792109eaa618d03f41a79 100644 (file)
-using namespace std;
-//  File      : VisuGUI_IsoSurfacesDlg.cxx
-//  Created   : Wed Aug 01 10:23:06 2001
-//  Author    : Laurent CORNABE & Hubert ROLLAND 
-//  Project   : SALOME
-//  Module    : VISUGUI
-//  Copyright : PRINCIPIA
+//  VISU VISUGUI : GUI of VISU component
+//
+//  Copyright (C) 2003  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
+//  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
+//  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
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+//
+//
+//  File   : VisuGUI_IsoSurfacesDlg.cxx
+//  Author : Laurent CORNABE & Hubert ROLLAND
+//  Module : VISU
 //  $Header$
 
 #include "VisuGUI_IsoSurfacesDlg.h"
+
+#include "VisuGUI.h"
+#include "VisuGUI_Tools.h"
+#include "VisuGUI_InputPane.h"
+
+#include "VISU_ColoredPrs3dFactory.hh"
+
+#include "LightApp_Application.h"
+
+#include "SUIT_Desktop.h"
+#include "SUIT_Session.h"
+#include "SUIT_MessageBox.h"
+#include "SUIT_ResourceMgr.h"
+
+#include <limits.h>
+
 #include <qlayout.h>
-#include "QAD_Application.h"
-#include "QAD_Desktop.h"
+#include <qvalidator.h>
+#include <qtabwidget.h>
 
-/*!
-  Constructor
-*/
-VisuGUI_IsoSurfacesDlg::VisuGUI_IsoSurfacesDlg()
-    : QDialog( QAD_Application::getDesktop(), "VisuGUI_IsoSurfacesDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
+using namespace std;
+
+
+VisuGUI_IsoSurfPane::VisuGUI_IsoSurfPane (QWidget* parent,
+                                         VisuGUI_ScalarBarPane* theScalarPane)
+  : QVBox(parent),
+    myScalarPane(theScalarPane)
 {
-  setCaption( tr( "Iso Surfaces Definition" ) );
-  setSizeGripEnabled( TRUE );
+  QFrame* TopGroup = new QFrame( this, "TopGroup" );
+  TopGroup->setFrameStyle(QFrame::Box | QFrame::Sunken);
+  TopGroup->setLineWidth(1);
 
-  QGridLayout* TopLayout = new QGridLayout( this ); 
-  TopLayout->setSpacing( 6 );
-  TopLayout->setMargin( 11 );
-  
-  QGroupBox* TopGroup = new QGroupBox( this, "TopGroup" );
-  TopGroup->setColumnLayout(0, Qt::Vertical );
-  TopGroup->layout()->setSpacing( 0 );
-  TopGroup->layout()->setMargin( 0 );
-  QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
+  QGridLayout* TopGroupLayout = new QGridLayout(TopGroup);
   TopGroupLayout->setAlignment( Qt::AlignTop );
   TopGroupLayout->setSpacing( 6 );
   TopGroupLayout->setMargin( 11 );
 
-  QLabel* LabelMin = new QLabel( tr( "Minimum value:" ), TopGroup, "LabelMin" );
-  TopGroupLayout->addWidget( LabelMin, 0, 0 );
-  MinIso = new QAD_SpinBoxDbl( TopGroup, -999.99, 999.99, 0.1 );
+  QLabel* LabelNbr = new QLabel (tr("NB_SURFACES"), TopGroup, "LabelNbr");
+  TopGroupLayout->addWidget( LabelNbr, 0, 0 );
+  NbrIso = new QSpinBox( 1, 100, 1, TopGroup, "NbrIso" );
+  NbrIso->setValue( 1 );
+  TopGroupLayout->addWidget( NbrIso, 0, 1 );
+
+  QLabel* LabelMin = new QLabel (tr("MIN_VALUE"), TopGroup, "LabelMin");
+  TopGroupLayout->addWidget(LabelMin, 1, 0);
+  //MinIso = new QtxDblSpinBox( -DBL_MAX, DBL_MAX, 0.1, TopGroup );
+  MinIso = new QLineEdit( TopGroup );
+  MinIso->setValidator( new QDoubleValidator(TopGroup) );
   MinIso->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
   MinIso->setMinimumSize( 70, 0 );
-  TopGroupLayout->addWidget( MinIso, 0, 1 );
+  LabelMin->setBuddy(MinIso);
+  TopGroupLayout->addWidget( MinIso, 1, 1 );
 
-  QLabel* LabelMax = new QLabel( tr( "Maximum value:" ), TopGroup, "LabelMax" );
-  TopGroupLayout->addWidget( LabelMax, 1, 0 );
-  MaxIso = new QAD_SpinBoxDbl( TopGroup, -999.99, 999.99, 0.1);
+  QLabel* LabelMax = new QLabel (tr("MAX_VALUE"), TopGroup, "LabelMax");
+  TopGroupLayout->addWidget( LabelMax, 2, 0 );
+  //MaxIso = new QtxSpinBoxDbl( -DBL_MAX, DBL_MAX, 0.1, TopGroup );
+  MaxIso = new QLineEdit( TopGroup );
+  MaxIso->setValidator( new QDoubleValidator(TopGroup) );
   MaxIso->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
   MaxIso->setMinimumSize( 70, 0 );
-  TopGroupLayout->addWidget( MaxIso, 1, 1 );
-  
-  QLabel* LabelNbr = new QLabel( tr( "Number of surfaces:" ), TopGroup, "LabelNbr" );
-  TopGroupLayout->addWidget( LabelNbr, 2, 0 );
-  NbrIso = new QSpinBox( 1, 100, 1, TopGroup, "NbrIso" );
-  NbrIso->setValue( 1 );
-  TopGroupLayout->addWidget( NbrIso, 2, 1 );
+  LabelMax->setBuddy(MaxIso);
+  TopGroupLayout->addWidget( MaxIso, 2, 1 );
+
+  QPushButton* aUpdateBtn = new QPushButton( "Update scalar bar range with these values", TopGroup);
+  TopGroupLayout->addMultiCellWidget( aUpdateBtn, 3, 3, 0, 1);
+  connect( aUpdateBtn, SIGNAL( clicked() ), this, SLOT(onCBUpdate() ) );
+}
+
+void VisuGUI_IsoSurfPane::initFromPrsObject (VISU::IsoSurfaces_i* thePrs)
+{
+  NbrIso->setValue(thePrs->GetNbSurfaces());
+  MinIso->setText(QString::number(thePrs->GetSubMin()));
+  MaxIso->setText(QString::number(thePrs->GetSubMax()));
+}
+
+int VisuGUI_IsoSurfPane::storeToPrsObject (VISU::IsoSurfaces_i* thePrs)
+{
+  thePrs->SetNbSurfaces(NbrIso->value());
+  thePrs->SetSubRange(MinIso->text().toDouble(), MaxIso->text().toDouble());
+  return 1;
+}
+
+void VisuGUI_IsoSurfPane::onCBUpdate()
+{
+  myScalarPane->setRange(MinIso->text().toDouble(), MaxIso->text().toDouble(), true);
+}
+
+bool VisuGUI_IsoSurfPane::check()
+{
+  if (MinIso->text().toDouble() >= MaxIso->text().toDouble()) {
+    MESSAGE(tr("MSG_MINMAX_VALUES"));
+    SUIT_MessageBox::warn1( this,tr("WRN_VISU"),
+                           tr("MSG_MINMAX_VALUES"),
+                           tr("BUT_OK"));
+    return false;
+  }
+  return true;
+}
+
+
+
+
+
+/*!
+  Constructor
+*/
+VisuGUI_IsoSurfacesDlg::VisuGUI_IsoSurfacesDlg (SalomeApp_Module* theModule)
+  : VisuGUI_ScalarBarBaseDlg(theModule)
+{
+  setCaption(tr("DEFINE_ISOSURFACES"));
+  setSizeGripEnabled( TRUE );
+
+  QVBoxLayout* TopLayout = new QVBoxLayout(this);
+  TopLayout->setSpacing( 6 );
+  TopLayout->setMargin(11);
+
+  myTabBox = new QTabWidget(this);
+  myIsoPane = new  VisuGUI_IsoSurfPane(this, GetScalarPane());
+  myIsoPane->setMargin( 5 );
+  myTabBox->addTab(myIsoPane, "Iso Surface");
+  myInputPane = new VisuGUI_InputPane(VISU::TISOSURFACES, theModule, this);
+  myTabBox->addTab(GetScalarPane(), "Scalar Bar");
+  myTabBox->addTab(myInputPane, "Input");
+
+  TopLayout->addWidget(myTabBox);
 
   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
-  GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
+  GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
   GroupButtons->setColumnLayout(0, Qt::Vertical );
   GroupButtons->layout()->setSpacing( 0 );
   GroupButtons->layout()->setMargin( 0 );
@@ -72,32 +171,59 @@ VisuGUI_IsoSurfacesDlg::VisuGUI_IsoSurfacesDlg()
   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
   buttonCancel->setAutoDefault( TRUE );
   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
-  
-  TopLayout->addWidget( TopGroup,     0, 0 );
-  TopLayout->addWidget( GroupButtons, 1, 0 );
+  QPushButton* buttonHelp = new QPushButton( tr( "&Help" ) , GroupButtons, "buttonHelp" );
+  buttonHelp->setAutoDefault( TRUE );
+  GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
+
+  TopLayout->addWidget(GroupButtons);
 
   // signals and slots connections
   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
+  connect( buttonHelp,   SIGNAL( clicked() ), this, SLOT( onHelp() ) );
 }
 
-/*!
-   Destructor
-*/
 VisuGUI_IsoSurfacesDlg::~VisuGUI_IsoSurfacesDlg()
+{}
+
+void VisuGUI_IsoSurfacesDlg::accept()
 {
+  if ( myIsoPane->check() )
+    VisuGUI_ScalarBarBaseDlg::accept();
 }
 
+void VisuGUI_IsoSurfacesDlg::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs,
+                                               bool theInit )
+{
+  if( theInit )
+    myPrsCopy = VISU::TSameAsFactory<VISU::TISOSURFACES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
 
-void VisuGUI_IsoSurfacesDlg::initFromPrsObject(VISU::IsoSurfaces_i* thePrs) {
-  NbrIso->setValue(thePrs->GetNbSurfaces());
-  MinIso->setValue(thePrs->GetRangeMin());
-  MaxIso->setValue(thePrs->GetRangeMax());
+  VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
+
+  myIsoPane->initFromPrsObject(myPrsCopy);
+
+  if( !theInit )
+    return;
+
+  myInputPane->initFromPrsObject( myPrsCopy );
+  myTabBox->setCurrentPage( 0 );
 }
 
+int VisuGUI_IsoSurfacesDlg::storeToPrsObject(VISU::ColoredPrs3d_i* thePrs)
+{
+  if(!myInputPane->check() || !GetScalarPane()->check())
+    return 0;
+
+  int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
+  anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
+  anIsOk &= myIsoPane->storeToPrsObject( myPrsCopy );
 
-void VisuGUI_IsoSurfacesDlg::storeToPrsObject(VISU::IsoSurfaces_i* thePrs) {
-  thePrs->SetNbSurfaces(NbrIso->value());
-  thePrs->SetRange(MinIso->value(), MaxIso->value());
-  thePrs->Update();
+  VISU::TSameAsFactory<VISU::TISOSURFACES>().Copy(myPrsCopy, thePrs);
+
+  return anIsOk;
+}
+
+QString VisuGUI_IsoSurfacesDlg::GetContextHelpFilePath()
+{
+  return "iso_surfaces_page.html";
 }