Salome HOME
PAL12789. Add and use COORD_MIN and COORD_MAX macros
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Hypotheses.cxx
index 676c37cc4a3678198ac2c7e2de1e7439125ea34d..6e90a709363baf58c15b77a09d672cf794cb0644 100644 (file)
@@ -1,3 +1,22 @@
+// Copyright (C) 2005  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
+//
 
 #include "SMESHGUI_Hypotheses.h"
 #include "SMESHGUI.h"
@@ -8,8 +27,15 @@
 #include <SALOMEDSClient_Study.hxx>
 #include <utilities.h>
 
+#include <SMESHGUI.h>
+
 #include <QtxIntSpinBox.h>
 
+#include <SUIT_Session.h>
+#include <SUIT_MessageBox.h>
+
+#include <LightApp_Application.h>
+
 #include <qframe.h>
 #include <qlayout.h>
 #include <qlineedit.h>
@@ -27,6 +53,16 @@ SMESHGUI_GenericHypothesisCreator::~SMESHGUI_GenericHypothesisCreator()
 {
 }
 
+void SMESHGUI_GenericHypothesisCreator::create( SMESH::SMESH_Hypothesis_ptr initParamsHyp,
+                                                QWidget* parent)
+{
+  MESSAGE( "Creation of hypothesis with initial params" );
+
+  if ( !CORBA::is_nil( initParamsHyp ) && hypType() == initParamsHyp->GetName() )
+    myInitParamsHypo = SMESH::SMESH_Hypothesis::_duplicate( initParamsHyp );
+  create( false, parent );
+}
+
 void SMESHGUI_GenericHypothesisCreator::create( const bool isAlgo, QWidget* parent )
 {
   MESSAGE( "Creation of hypothesis" );
@@ -94,6 +130,7 @@ bool SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_
 
   bool res = true;
   myHypo = SMESH::SMESH_Hypothesis::_duplicate( h );
+
   QFrame* fr = buildFrame();
   if( fr )
   {
@@ -105,12 +142,18 @@ bool SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_
     dlg->setType( type() );
     retrieveParams();
     res = dlg->exec()==QDialog::Accepted;
-    if( res )
-      storeParams();
+    if( res ) {
+      QString paramValues = storeParams();
+      if ( !paramValues.isEmpty() ) {
+        if ( _PTR(SObject) SHyp = SMESH::FindSObject( myHypo ))
+          SMESH::SetValue( SHyp, paramValues );
+      }
+    }
     delete dlg;
   }
   changeWidgets().clear();
   myHypo = SMESH::SMESH_Hypothesis::_nil();
+  myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil();
   return res;
 }
 
@@ -144,37 +187,38 @@ QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
     QLabel* lab = new QLabel( (*anIt).myName, GroupC1 );
     GroupC1Layout->addWidget( lab, i, 0 );
 
-    QWidget* w = 0;
-    switch( (*anIt).myValue.type() )
-    {
-    case QVariant::Int:
-      {
-       QtxIntSpinBox* sb = new QtxIntSpinBox( GroupC1, (*anIt).myName.latin1() );
-       attuneStdWidget( sb, i );
-       sb->setValue( (*anIt).myValue.toInt() );
-       connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
-       w = sb;
-      }
-      break;
-    case QVariant::Double:
-      {
-       QtxDblSpinBox* sb = new SMESHGUI_SpinBox( GroupC1, (*anIt).myName.latin1() );
-       attuneStdWidget( sb, i );
-       sb->setValue( (*anIt).myValue.toDouble() );
-       connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
-       w = sb;
-      }
-      break;
-    case QVariant::String:
+    QWidget* w = getCustomWidget( *anIt, GroupC1 );
+    if ( !w ) 
+      switch( (*anIt).myValue.type() )
       {
-       QLineEdit* le = new QLineEdit( GroupC1, (*anIt).myName.latin1() );
-       attuneStdWidget( le, i );
-       le->setText( (*anIt).myValue.toString() );
-       connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
-       w = le;
+      case QVariant::Int:
+        {
+          QtxIntSpinBox* sb = new QtxIntSpinBox( GroupC1, (*anIt).myName.latin1() );
+          attuneStdWidget( sb, i );
+          sb->setValue( (*anIt).myValue.toInt() );
+          connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
+          w = sb;
+        }
+        break;
+      case QVariant::Double:
+        {
+          QtxDblSpinBox* sb = new SMESHGUI_SpinBox( GroupC1, (*anIt).myName.latin1() );
+          attuneStdWidget( sb, i );
+          sb->setValue( (*anIt).myValue.toDouble() );
+          connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
+          w = sb;
+        }
+        break;
+      case QVariant::String:
+        {
+          QLineEdit* le = new QLineEdit( GroupC1, (*anIt).myName.latin1() );
+          attuneStdWidget( le, i );
+          le->setText( (*anIt).myValue.toString() );
+          connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
+          w = le;
+        }
+        break;
       }
-      break;
-    }
 
     if( w )
     {
@@ -224,17 +268,56 @@ bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& par
       params.append( item );
     }
 
-    else 
+    else if ( getParamFromCustomWidget( item, *anIt ))
+    {
+      params.append( item );
+    }
+
+    else
       res = false;
   }
   return res;
 }
 
+QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params)
+{
+  QString valueStr = "";
+  ListOfStdParams::const_iterator param = params.begin(), aLast = params.end();
+  for( int i=0; param!=aLast; param++, i++ )
+  {
+    if ( i > 0 )
+      valueStr += "; ";
+    switch( (*param).myValue.type() )
+    {
+    case QVariant::Int:
+      valueStr += valueStr.number( (*param).myValue.toInt() );
+      break;
+    case QVariant::Double:
+      valueStr += valueStr.number( (*param).myValue.toDouble() );
+      break;
+    case QVariant::String:
+      valueStr += (*param).myValue.toString();
+      break;
+    default:
+      QVariant valCopy = (*param).myValue;
+      valueStr += valCopy.asString();
+    }
+  }
+  return valueStr;
+}
+
 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const
 {
   return myHypo;
 }
 
+SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis() const
+{
+  if ( CORBA::is_nil( myInitParamsHypo ))
+    return myHypo;
+  return myInitParamsHypo;
+}
+
 QString SMESHGUI_GenericHypothesisCreator::hypType() const
 {
   return myHypType;
@@ -273,16 +356,21 @@ QString SMESHGUI_GenericHypothesisCreator::type() const
 {
   return QString();
 }
-
-
-
-
+QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
+                                                             QWidget*   /*parent*/) const
+{
+  return 0;
+}
+bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam& , QWidget* ) const
+{
+  return false;
+}
 
 
 
 
 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
-: QtxDialog( parent, "", true, true, QtxDialog::OKCancel ),
+: QtxDialog( parent, "", true, true ),
   myCreator( creator )
 {
   setMinimumSize( 300, height() );
@@ -304,6 +392,29 @@ SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreato
   titLay->addStretch( 1 );
 
   myLayout->addWidget( titFrame, 0 );
+
+  QString aHypType = creator->hypType();
+  if ( aHypType == "LocalLength" )
+    myHelpFileName = "/files/arithmetic_1d.htm#Average_length";
+  else if ( aHypType == "Arithmetic1D")
+    myHelpFileName = "/files/arithmetic_1d.htm#arithmetic_1D";
+  else if ( aHypType == "MaxElementArea")
+    myHelpFileName = "/files/max._element_area_hypothesis.htm";
+  else if ( aHypType == "MaxElementVolume")
+    myHelpFileName = "/files/max._element_volume_hypothsis.htm";
+  else if ( aHypType == "StartEndLength")
+    myHelpFileName = "/files/arithmetic_1d.htm#start_and_end_length";
+  else if ( aHypType == "Deflection1D")
+    myHelpFileName = "/files/arithmetic_1d.htm#deflection_1D";
+  else if ( aHypType == "AutomaticLength")
+    myHelpFileName = "/files/arithmetic_1d.htm#automatic_length";
+  else if ( aHypType == "NumberOfSegments")
+    myHelpFileName = "/files/arithmetic_1d.htm#Number_of_elements";
+  else
+    myHelpFileName = "";
+
+  connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
+
 }
 
 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
@@ -325,6 +436,21 @@ void SMESHGUI_HypothesisDlg::accept()
     QtxDialog::accept();
 }
 
+void SMESHGUI_HypothesisDlg::onHelp()
+{
+  LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
+  if (app) {
+    SMESHGUI* aSMESHGUI = dynamic_cast<SMESHGUI*>( app->activeModule() );
+    app->onHelpContextModule(aSMESHGUI ? app->moduleName(aSMESHGUI->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"));
+  }
+}
+
 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
 {
   myIconLabel->setPixmap( p );