Salome HOME
Merge from BR_DumpPython_Extension branch (from tag mergeto_BR_V5_Dev_28Jan09)
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Hypotheses.cxx
index bc2765def472d818f3d640926e549d849955d7b8..8ca61f49fd0876129aa798574a258fe0377360c6 100644 (file)
@@ -1,28 +1,29 @@
-// SMESH SMESHGUI : GUI for SMESH component
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-// Copyright (C) 2003  CEA
+//  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 
-// version 2.1 of the License. 
+//  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. 
+//  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 
+//  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
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+// SMESH SMESHGUI : GUI for SMESH component
 // File   : SMESHGUI_Hypotheses.cxx
 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
-//
-
 // SMESH includes
+//
 #include "SMESHGUI_Hypotheses.h"
 
 #include "SMESHGUI.h"
 #include <utilities.h>
 
 // SALOME GUI includes
-#include <QtxIntSpinBox.h>
 #include <SUIT_Session.h>
 #include <SUIT_MessageBox.h>
 #include <SUIT_ResourceMgr.h>
 #include <LightApp_Application.h>
+#include <SalomeApp_IntSpinBox.h>
 
 // Qt includes
 #include <QFrame>
@@ -61,14 +62,18 @@ SMESHGUI_GenericHypothesisCreator::~SMESHGUI_GenericHypothesisCreator()
 {
 }
 
+void SMESHGUI_GenericHypothesisCreator::setInitParamsHypothesis(SMESH::SMESH_Hypothesis_ptr hyp)
+{
+  if ( !CORBA::is_nil( hyp ) && hypType() == hyp->GetName() )
+    myInitParamsHypo = SMESH::SMESH_Hypothesis::_duplicate( hyp );
+}
+
 void SMESHGUI_GenericHypothesisCreator::create( SMESH::SMESH_Hypothesis_ptr initParamsHyp,
                                                const QString& theHypName,
                                                 QWidget* parent)
 {
   MESSAGE( "Creation of hypothesis with initial params" );
-
-  if ( !CORBA::is_nil( initParamsHyp ) && hypType() == initParamsHyp->GetName() )
-    myInitParamsHypo = SMESH::SMESH_Hypothesis::_duplicate( initParamsHyp );
+  setInitParamsHypothesis( initParamsHyp );
   create( false, theHypName, parent );
 }
 
@@ -206,7 +211,7 @@ QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
       {
       case QVariant::Int:
         {
-          QtxIntSpinBox* sb = new QtxIntSpinBox( GroupC1 );
+          SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
          sb->setObjectName( (*anIt).myName );
           attuneStdWidget( sb, i );
           sb->setValue( (*anIt).myValue.toInt() );
@@ -216,7 +221,7 @@ QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
         break;
       case QVariant::Double:
         {
-          QtxDoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
+          SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
          sb->setObjectName( (*anIt).myName );
           attuneStdWidget( sb, i );
           sb->setValue( (*anIt).myValue.toDouble() );
@@ -226,12 +231,34 @@ QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
         break;
       case QVariant::String:
         {
-          QLineEdit* le = new QLineEdit( GroupC1 );
-         le->setObjectName( (*anIt).myName );
-          attuneStdWidget( le, i );
-          le->setText( (*anIt).myValue.toString() );
-          connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
-          w = le;
+          if((*anIt).isVariable) {
+            _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+            QString aVar = (*anIt).myValue.toString();
+            if(aStudy->IsInteger(aVar.toLatin1().constData())){
+              SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
+              sb->setObjectName( (*anIt).myName );
+              attuneStdWidget( sb, i );
+              sb->setText( aVar );
+              connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
+              w = sb;
+            }
+            else if(aStudy->IsReal(aVar.toLatin1().constData())){
+              SalomeApp_DoubleSpinBox* sb = new SalomeApp_DoubleSpinBox( GroupC1 );
+              sb->setObjectName( (*anIt).myName );
+              attuneStdWidget( sb, i );
+              sb->setText( aVar );
+              connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
+              w = sb;
+            }
+          }
+          else {
+            QLineEdit* le = new QLineEdit( GroupC1 );
+            le->setObjectName( (*anIt).myName );
+            attuneStdWidget( le, i );
+            le->setText( (*anIt).myValue.toString() );
+            connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
+            w = le;
+          }
         }
         break;
       }
@@ -247,6 +274,11 @@ QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
 }
 
 void SMESHGUI_GenericHypothesisCreator::onValueChanged()
+{
+  valueChanged( (QWidget*) sender() );
+}
+
+void SMESHGUI_GenericHypothesisCreator::valueChanged( QWidget* )
 {
 }
 
@@ -269,16 +301,16 @@ bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& par
   for( ; anIt!=aLast; anIt++ )
   {
     item.myName = (*anIt)->objectName();
-    if( (*anIt)->inherits( "QtxIntSpinBox" ) )
+    if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
     {
-      QtxIntSpinBox* sb = ( QtxIntSpinBox* )( *anIt );
+      SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
       item.myValue = sb->value();
       params.append( item );
     }
     
-    else if( (*anIt)->inherits( "QtxDoubleSpinBox" ) )
+    else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
     {
-      QtxDoubleSpinBox* sb = ( QtxDoubleSpinBox* )( *anIt );
+      SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
       item.myValue = sb->value();
       params.append( item );
     }
@@ -301,6 +333,24 @@ bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& par
   return res;
 }
 
+
+QStringList SMESHGUI_GenericHypothesisCreator::getVariablesFromDlg() const
+{
+  QStringList aResult;
+  ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
+  for( ; anIt!=aLast; anIt++ ) {
+    if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) ) {
+      SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
+      aResult.append(sb->text());
+    } 
+    else if( (*anIt)->inherits( "QtxDoubleSpinBox" ) ) {
+      QtxDoubleSpinBox* sb = ( QtxDoubleSpinBox* )( *anIt );
+      aResult.append(sb->text());
+    } 
+  }
+  return aResult;
+}
+
 QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params)
 {
   QString valueStr = "";
@@ -336,13 +386,29 @@ SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() cons
   return myHypo;
 }
 
-SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis() const
+//================================================================================
+/*!
+ * \brief Return hypothesis containing initial parameters
+ *  \param strictly - if true, always return myInitParamsHypo,
+ *                    else, return myInitParamsHypo only in creation mode and if it
+ *                    is non-nil
+ */
+//================================================================================
+
+SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis(const bool strictly) const
 {
-  if ( CORBA::is_nil( myInitParamsHypo ))
+  if ( strictly )
+    return myInitParamsHypo;
+  if ( !isCreation() || CORBA::is_nil( myInitParamsHypo ))
     return myHypo;
   return myInitParamsHypo;
 }
 
+bool SMESHGUI_GenericHypothesisCreator::hasInitParamsHypothesis() const
+{
+  return !CORBA::is_nil( myInitParamsHypo );
+}
+
 QString SMESHGUI_GenericHypothesisCreator::hypType() const
 {
   return myHypType;
@@ -402,6 +468,26 @@ bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam&, QWi
   return false;
 }
 
+bool SMESHGUI_GenericHypothesisCreator::checkParams( QString& msg ) const
+{
+  bool ok = true;
+  ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
+  for( ; anIt!=aLast; anIt++ )
+  {
+    if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
+    {
+      SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
+      ok = sb->isValid( msg, true ) && ok;
+    }
+    else if( (*anIt)->inherits( "SalomeApp_DoubleSpinBox" ) )
+    {
+      SalomeApp_DoubleSpinBox* sb = ( SalomeApp_DoubleSpinBox* )( *anIt );
+      ok = sb->isValid( msg, true ) && ok;
+    }
+  }
+  return ok;
+}
+
 void SMESHGUI_GenericHypothesisCreator::onReject()
 {
 }
@@ -494,8 +580,15 @@ void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
 
 void SMESHGUI_HypothesisDlg::accept()
 {
-  if ( myCreator && !myCreator->checkParams() )
+  QString msg;
+  if ( myCreator && !myCreator->checkParams( msg ) )
+  {
+    QString str( tr( "SMESH_INCORRECT_INPUT" ) );
+    if ( !msg.isEmpty() )
+      str += "\n" + msg;
+    SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
     return;
+  }
   QtxDialog::accept();
 }