Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / VISUGUI / VisuGUI_IsoSurfacesDlg.cxx
index 34d170b91a3ed5ac73e19d431a23fc2e11158397..d68d57cc0166609cb21673a312a63ec798f3feee 100644 (file)
@@ -1,6 +1,6 @@
-//  VISU VISUGUI : GUI of VISU component
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  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
 //  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
-//
-//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
+//  VISU VISUGUI : GUI of VISU component
 //  File   : VisuGUI_IsoSurfacesDlg.cxx
 //  Author : Laurent CORNABE & Hubert ROLLAND
 //  Module : VISU
 //  $Header$
-
+//
 #include "VisuGUI_IsoSurfacesDlg.h"
 
 #include "VisuGUI.h"
 #include "VisuGUI_Tools.h"
-
-#include "SalomeApp_Application.h"
-
-#include "SUIT_Desktop.h"
-#include "SUIT_MessageBox.h"
-
-#include <limits.h>
-
-#include <qlayout.h>
-#include <qvalidator.h>
-#include <qtabwidget.h>
-
-using namespace std;
-
-
-VisuGUI_IsoSurfPane::VisuGUI_IsoSurfPane (QWidget* parent)
-     : QVBox(parent)
+#include "VisuGUI_InputPane.h"
+
+#include <VISU_ColoredPrs3dFactory.hh>
+
+#include <LightApp_Application.h>
+
+#include <SalomeApp_IntSpinBox.h>
+
+#include <QtxColorButton.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_Session.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_ResourceMgr.h>
+
+#include <limits>
+
+#include <QLayout>
+#include <QValidator>
+#include <QLabel>
+#include <QGroupBox>
+#include <QPushButton>
+#include <QCheckBox>
+#include <QLineEdit>
+#include <QTabWidget>
+#include <QKeyEvent>
+#include <QColorDialog>
+#include <QButtonGroup>
+#include <QRadioButton>
+
+VisuGUI_IsoSurfPane::VisuGUI_IsoSurfPane (QWidget* parent,
+                                          VisuGUI_ScalarBarPane* theScalarPane)
+  : QWidget(parent),
+    myScalarPane(theScalarPane)
 {
-  QFrame* TopGroup = new QFrame( this, "TopGroup" );
+  QVBoxLayout* aMainLayout = new QVBoxLayout( this );
+  QFrame* TopGroup = new QFrame( this );
+  aMainLayout->addWidget( TopGroup );
+  
   TopGroup->setFrameStyle(QFrame::Box | QFrame::Sunken);
   TopGroup->setLineWidth(1);
 
@@ -57,44 +76,82 @@ VisuGUI_IsoSurfPane::VisuGUI_IsoSurfPane (QWidget* parent)
   TopGroupLayout->setSpacing( 6 );
   TopGroupLayout->setMargin( 11 );
 
-  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 );
+  QGroupBox* aRangeBox = new QGroupBox( tr( "RANGE" ), this );
+  QRadioButton* aUseScalarBarRange = new QRadioButton( tr( "USE_SCALAR_BAR_RANGE" ), aRangeBox );
+  QRadioButton* aUseCustomRange = new QRadioButton( tr( "USE_CUSTOM_RANGE" ), aRangeBox );
 
-  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) );
+  myRangeGrp = new QButtonGroup( aRangeBox );
+  myRangeGrp->addButton( aUseScalarBarRange, ScalarBarRange );
+  myRangeGrp->addButton( aUseCustomRange, CustomRange );
+  aUseScalarBarRange->setChecked( true );
+
+  connect( myRangeGrp, SIGNAL( buttonClicked( int ) ), this, SLOT( onRangeButtonClicked( int ) ) );
+
+  QLabel* LabelMin = new QLabel( tr( "MIN_VALUE" ), aRangeBox );
+  MinIso = new QLineEdit( aRangeBox );
+  MinIso->setValidator( new QDoubleValidator( aRangeBox ) );
   MinIso->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
   MinIso->setMinimumSize( 70, 0 );
-  LabelMin->setBuddy(MinIso);
-  TopGroupLayout->addWidget( MinIso, 1, 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) );
+  LabelMin->setBuddy( MinIso );
+
+  QLabel* LabelMax = new QLabel( tr( "MAX_VALUE" ), aRangeBox );
+  MaxIso = new QLineEdit( aRangeBox );
+  MaxIso->setValidator( new QDoubleValidator( aRangeBox ) );
   MaxIso->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
   MaxIso->setMinimumSize( 70, 0 );
-  LabelMax->setBuddy(MaxIso);
-  TopGroupLayout->addWidget( MaxIso, 2, 1 );
+  LabelMax->setBuddy( MaxIso );
 
-
-//   CBUpdate = new QCheckBox ( tr( "Update scalar bar with these values" ), TopGroup);
-//   CBUpdate->setSizePolicy( QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed) );
-//   TopGroupLayout->addMultiCellWidget( CBUpdate, 4, 4, 0, 1);
-//   CBUpdate->setChecked(false);
-  QPushButton* aUpdateBtn = new QPushButton( "Update scalar bar range with these values", TopGroup);
-  TopGroupLayout->addMultiCellWidget( aUpdateBtn, 3, 3, 0, 1);
+  QPushButton* aUpdateBtn = new QPushButton( "Update scalar bar range with these values", aRangeBox );
+  aUpdateBtn->setEnabled( false );
   connect( aUpdateBtn, SIGNAL( clicked() ), this, SLOT(onCBUpdate() ) );
-
-//   CBLog = new QCheckBox ( tr( "Logarithmic scaling" ), TopGroup);
-//   CBLog->setSizePolicy( QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed) );
-//   TopGroupLayout->addMultiCellWidget( CBLog, 3, 3, 0, 1);
+  connect( aUseCustomRange, SIGNAL( toggled( bool ) ), aUpdateBtn, SLOT( setEnabled( bool ) ) );
+
+  QGridLayout* aRangeLayout = new QGridLayout( aRangeBox );
+  aRangeLayout->setSpacing( 6 );
+  aRangeLayout->setMargin( 11 );
+  aRangeLayout->addWidget( aUseScalarBarRange, 0, 0 );
+  aRangeLayout->addWidget( aUseCustomRange, 0, 1 );
+  aRangeLayout->addWidget( LabelMin, 1, 0 );
+  aRangeLayout->addWidget( MinIso, 1, 1 );
+  aRangeLayout->addWidget( LabelMax, 2, 0 );
+  aRangeLayout->addWidget( MaxIso, 2, 1 );
+  aRangeLayout->addWidget( aUpdateBtn, 3, 0, 1, 2 );
+
+  TopGroupLayout->addWidget( aRangeBox, 0, 0, 1, 2 );
+
+  QLabel* LabelNbr = new QLabel (tr("NB_SURFACES"), TopGroup);
+  TopGroupLayout->addWidget( LabelNbr, 1, 0 );
+  NbrIso = new SalomeApp_IntSpinBox( TopGroup );
+  NbrIso->setAcceptNames( false );
+  NbrIso->setMaximum( 100 );
+  NbrIso->setMinimum( 1 );
+  NbrIso->setSingleStep( 1 );
+  NbrIso->setValue( 1 );
+  TopGroupLayout->addWidget( NbrIso, 1, 1 );
+
+  myUseMagnitude = new QCheckBox(tr("MAGNITUDE_COLORING_CHK"), TopGroup);
+  myUseMagnitude->setChecked(true);
+  TopGroupLayout->addWidget( myUseMagnitude, 2, 0 );
+
+  mySelColor = new QtxColorButton( TopGroup );
+  mySelColor->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
+  TopGroupLayout->addWidget( mySelColor, 2, 1 );
+  //connect( mySelColor, SIGNAL( clicked() ), this, SLOT( setColor() ) );
+  connect( myUseMagnitude, SIGNAL( toggled(bool) ), mySelColor, SLOT( setDisabled(bool) ) );
+
+  myUseLabels = new QCheckBox(tr("SHOW_VALUES_CHK"), TopGroup);
+  myUseLabels->setChecked(false);
+  TopGroupLayout->addWidget( myUseLabels, 3, 0 );
+  myNbLabels = new SalomeApp_IntSpinBox( TopGroup );
+  myNbLabels->setAcceptNames( false );
+  myNbLabels->setMinimum(1);
+  myNbLabels->setMaximum(100);
+  myNbLabels->setSingleStep(1);
+  myNbLabels->setEnabled(false);
+  TopGroupLayout->addWidget( myNbLabels, 3, 1 );
+  connect( myUseLabels, SIGNAL( toggled(bool) ), myNbLabels, SLOT( setEnabled(bool) ) );
+
+  mySelColor->setEnabled( !myUseMagnitude->isChecked() );
 }
 
 void VisuGUI_IsoSurfPane::initFromPrsObject (VISU::IsoSurfaces_i* thePrs)
@@ -102,124 +159,190 @@ void VisuGUI_IsoSurfPane::initFromPrsObject (VISU::IsoSurfaces_i* thePrs)
   NbrIso->setValue(thePrs->GetNbSurfaces());
   MinIso->setText(QString::number(thePrs->GetSubMin()));
   MaxIso->setText(QString::number(thePrs->GetSubMax()));
-//   switch(thePrs->GetScaling()){
-//   case VISU::LOGARITHMIC :
-//     CBLog->setChecked(true);
-//     break;
-//   default:
-//     CBLog->setChecked(false);
-//   }
+
+  int anId = thePrs->IsSubRangeFixed() ? ScalarBarRange : CustomRange;
+  bool anIsSubRangeFixed = thePrs->IsSubRangeFixed();
+  myRangeGrp->button( anId )->setChecked( true );
+  onRangeButtonClicked( anId );
+
+  myUseMagnitude->setChecked(thePrs->IsColored());
+  SALOMEDS::Color anOldColor = thePrs->GetColor();
+  QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
+  setColor(aColor);
+
+  myUseLabels->setChecked(thePrs->IsLabeled());
+  myNbLabels->setValue(thePrs->GetNbLabels());
+  mySelColor->setEnabled( !myUseMagnitude->isChecked() );
 }
 
 int VisuGUI_IsoSurfPane::storeToPrsObject (VISU::IsoSurfaces_i* thePrs)
 {
   thePrs->SetNbSurfaces(NbrIso->value());
-  thePrs->SetSubRange(MinIso->text().toDouble(), MaxIso->text().toDouble());
+
+  if( myRangeGrp->checkedId() == ScalarBarRange )
+  {
+    thePrs->SetSubRange( myScalarPane->getMin(), myScalarPane->getMax() );
+    thePrs->SetSubRangeFixed( true );
+  }
+  else // CustomRange
+  {
+    thePrs->SetSubRange( MinIso->text().toDouble(), MaxIso->text().toDouble() );
+    thePrs->SetSubRangeFixed( false );
+  }
+
+  thePrs->ShowLabels(myUseLabels->isChecked(), myNbLabels->value());
+  thePrs->ShowColored(myUseMagnitude->isChecked());
+  if(!thePrs->IsColored()){
+    QColor aQColor = color();
+    SALOMEDS::Color aColor;
+    aColor.R = aQColor.red()/255.;
+    aColor.G = aQColor.green()/255.;
+    aColor.B = aQColor.blue()/255.;
+    thePrs->SetColor(aColor);
+  }
   return 1;
-//   if (CBUpdate->isChecked())
-//     {
-//       thePrs->SetRange(MinIso->text().toDouble(), MaxIso->text().toDouble());
-//       if (CBLog->isChecked())
-//     thePrs->SetScaling(VISU::LOGARITHMIC);
-//       else
-//     thePrs->SetScaling(VISU::LINEAR);
-//    }
+}
+
+void VisuGUI_IsoSurfPane::onRangeButtonClicked( int theId )
+{
+  bool isCustomRange = theId == 1;
+  MinIso->setEnabled( isCustomRange );
+  MaxIso->setEnabled( isCustomRange );
 }
 
 void VisuGUI_IsoSurfPane::onCBUpdate()
 {
-  //  if (CBUpdate->isChecked()) {
   myScalarPane->setRange(MinIso->text().toDouble(), MaxIso->text().toDouble(), true);
-    //  }
-//     CBLog->setDisabled(false);
-//   else CBLog->setDisabled(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"));
+    MESSAGE(tr("MSG_MINMAX_VALUES").toLatin1().data());
+    SUIT_MessageBox::warning( this,tr("WRN_VISU"),
+                              tr("MSG_MINMAX_VALUES"),
+                              tr("BUT_OK"));
     return false;
-  } // else if (/* CBUpdate->isChecked() && CBLog->isChecked() && */
-//           (MinIso->text().toDouble() <=0 || MaxIso->text().toDouble() <=0) ) {
-//     SUIT_MessageBox::warn1( this,
-//                        tr("WRN_VISU"),
-//                        tr("WRN_LOGARITHMIC_RANGE_ISOSURF"),
-//                        tr("BUT_OK"));
-//     return false;
-//   }
+  }
   return true;
 }
 
+void VisuGUI_IsoSurfPane::setColor()
+{
+  QColor cnew = QColorDialog::getColor( color(), this );
+  if ( cnew.isValid() )
+    setColor(cnew);
+}
 
+void VisuGUI_IsoSurfPane::setColor( const QColor& theColor)
+{
+  /*  QPalette pal = mySelColor->palette();
+  pal.setColor(mySelColor->backgroundRole(), theColor);
+  mySelColor->setPalette(pal);*/
+  mySelColor->setColor( theColor );
+}
 
+QColor VisuGUI_IsoSurfPane::color() const
+{
+  return mySelColor->color();
+}
 
 
 /*!
   Constructor
 */
 VisuGUI_IsoSurfacesDlg::VisuGUI_IsoSurfacesDlg (SalomeApp_Module* theModule)
-     : QDialog(VISU::GetDesktop(theModule), "VisuGUI_IsoSurfacesDlg", true,
-               WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
+  : VisuGUI_ScalarBarBaseDlg(theModule)
 {
-  setCaption(tr("DEFINE_ISOSURFACES"));
+  setWindowTitle(tr("DEFINE_ISOSURFACES"));
   setSizeGripEnabled( TRUE );
 
   QVBoxLayout* TopLayout = new QVBoxLayout(this);
   TopLayout->setSpacing( 6 );
   TopLayout->setMargin(11);
 
-  QTabWidget* aTabBox = new QTabWidget(this);
-  myIsoPane = new  VisuGUI_IsoSurfPane(this);
-  myIsoPane->setMargin( 5 );
-  aTabBox->addTab(myIsoPane, "Iso Surface");
-  myScalarPane = new VisuGUI_ScalarBarPane(this, false);
-  myIsoPane->setScalarBarPane(myScalarPane);
-  myScalarPane->setMargin( 5 );
-  aTabBox->addTab(myScalarPane, "Scalar Bar");
+  myTabBox = new QTabWidget(this);
+  myIsoPane = new  VisuGUI_IsoSurfPane(this, GetScalarPane());
+  if ( myIsoPane->layout() )
+    myIsoPane->layout()->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(aTabBox);
+  TopLayout->addWidget(myTabBox);
 
-  QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
+  QGroupBox* GroupButtons = new QGroupBox( this );
   GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
-  GroupButtons->setColumnLayout(0, Qt::Vertical );
-  GroupButtons->layout()->setSpacing( 0 );
-  GroupButtons->layout()->setMargin( 0 );
-  QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
+  //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( "BUT_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* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
+  QPushButton* buttonCancel = new QPushButton( tr( "BUT_CANCEL" ) , GroupButtons );
   buttonCancel->setAutoDefault( TRUE );
   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
+  QPushButton* buttonHelp = new QPushButton( tr( "BUT_HELP" ) , GroupButtons );
+  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() ) );
 }
 
+VisuGUI_IsoSurfacesDlg::~VisuGUI_IsoSurfacesDlg()
+{}
+
 void VisuGUI_IsoSurfacesDlg::accept()
 {
-  if (myIsoPane->check() && myScalarPane->check())
-    {
-      myScalarPane->deletePreview();
-      QDialog::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);
+
+  VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
+
+  myIsoPane->initFromPrsObject(myPrsCopy);
+
+  if( !theInit )
+    return;
+
+  myInputPane->initFromPrsObject( myPrsCopy );
+  myTabBox->setCurrentIndex( 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 );
+
+  VISU::TSameAsFactory<VISU::TISOSURFACES>().Copy(myPrsCopy, thePrs);
+
+  return anIsOk;
 }
 
-void VisuGUI_IsoSurfacesDlg::reject()
+QString VisuGUI_IsoSurfacesDlg::GetContextHelpFilePath()
 {
-  myScalarPane->deletePreview();
-  QDialog::reject();
+  return "iso_surfaces_page.html";
 }