1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "SMESHGUI_Hypotheses.h"
24 #include "SMESHGUI_HypothesesUtils.h"
25 #include "SMESHGUI_Utils.h"
26 #include "SMESHGUI_SpinBox.h"
28 #include <SALOMEDSClient_Study.hxx>
29 #include <utilities.h>
33 #include <QtxIntSpinBox.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_MessageBox.h>
38 #include <LightApp_Application.h>
42 #include <qlineedit.h>
45 #include <qgroupbox.h>
47 #include <qapplication.h>
49 SMESHGUI_GenericHypothesisCreator::SMESHGUI_GenericHypothesisCreator( const QString& theHypType )
50 : myHypType( theHypType ), myIsCreate( false ), myDlg( 0 )
54 SMESHGUI_GenericHypothesisCreator::~SMESHGUI_GenericHypothesisCreator()
58 void SMESHGUI_GenericHypothesisCreator::create( SMESH::SMESH_Hypothesis_ptr initParamsHyp,
59 const QString& theHypName,
62 MESSAGE( "Creation of hypothesis with initial params" );
64 if ( !CORBA::is_nil( initParamsHyp ) && hypType() == initParamsHyp->GetName() )
65 myInitParamsHypo = SMESH::SMESH_Hypothesis::_duplicate( initParamsHyp );
66 create( false, theHypName, parent );
69 void SMESHGUI_GenericHypothesisCreator::create( bool isAlgo,
70 const QString& theHypName,
73 MESSAGE( "Creation of hypothesis" );
77 // Create hypothesis/algorithm
79 SMESH::CreateHypothesis( hypType(), theHypName, isAlgo );
82 SMESH::SMESH_Hypothesis_var aHypothesis =
83 SMESH::CreateHypothesis( hypType(), theHypName, false );
84 if( !editHypothesis( aHypothesis.in(), theHypName, theParent ) )
85 { //remove just created hypothesis
86 _PTR(SObject) aHypSObject = SMESH::FindSObject( aHypothesis.in() );
87 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
88 if( aStudy && !aStudy->GetProperties()->IsLocked() )
90 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
91 aBuilder->RemoveObjectWithChildren( aHypSObject );
95 SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
98 void SMESHGUI_GenericHypothesisCreator::edit( SMESH::SMESH_Hypothesis_ptr theHypothesis,
99 const QString& theHypName,
102 if( CORBA::is_nil( theHypothesis ) )
105 MESSAGE("Edition of hypothesis");
109 if( !editHypothesis( theHypothesis, theHypName, theParent ) )
112 SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis( theHypothesis );
113 if( listSOmesh.size() > 0 )
114 for( int i = 0; i < listSOmesh.size(); i++ )
116 _PTR(SObject) submSO = listSOmesh[i];
117 SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( submSO );
118 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( submSO );
119 if( !aSubMesh->_is_nil() )
120 aMesh = aSubMesh->GetFather();
121 _PTR(SObject) meshSO = SMESH::FindSObject( aMesh );
122 SMESH::ModifiedMesh( meshSO, false, aMesh->NbNodes()==0);
124 SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 );
127 bool SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_ptr h,
128 const QString& theHypName,
131 if( CORBA::is_nil( h ) )
135 myHypName = theHypName;
136 myHypo = SMESH::SMESH_Hypothesis::_duplicate( h );
138 SMESHGUI_HypothesisDlg* Dlg = new SMESHGUI_HypothesisDlg( this, theParent );
140 QFrame* fr = buildFrame();
143 Dlg->setCustomFrame( fr );
144 Dlg->setCaption( caption() );
145 Dlg->setName( theHypName );
146 Dlg->setHIcon( icon() );
147 Dlg->setType( type() );
150 qApp->enter_loop(); // make myDlg not modal
151 res = myDlg->result();
153 QString paramValues = storeParams();
154 if ( !paramValues.isEmpty() ) {
155 if ( _PTR(SObject) SHyp = SMESH::FindSObject( myHypo ))
156 SMESH::SetValue( SHyp, paramValues );
160 delete Dlg; myDlg = 0;
161 changeWidgets().clear();
162 myHypo = SMESH::SMESH_Hypothesis::_nil();
163 myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil();
167 QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
169 if( CORBA::is_nil( hypothesis() ) )
172 ListOfStdParams params;
173 if( !stdParams( params ) || params.isEmpty() )
176 QFrame* fr = new QFrame( 0, "myframe" );
177 QVBoxLayout* lay = new QVBoxLayout( fr, 5, 0 );
179 QGroupBox* GroupC1 = new QGroupBox( fr, "GroupC1" );
180 lay->addWidget( GroupC1 );
182 GroupC1->setTitle( tr( "SMESH_ARGUMENTS" ) );
183 GroupC1->setColumnLayout(0, Qt::Vertical );
184 GroupC1->layout()->setSpacing( 0 );
185 GroupC1->layout()->setMargin( 0 );
186 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
187 GroupC1Layout->setAlignment( Qt::AlignTop );
188 GroupC1Layout->setSpacing( 6 );
189 GroupC1Layout->setMargin( 11 );
191 ListOfStdParams::const_iterator anIt = params.begin(), aLast = params.end();
192 for( int i=0; anIt!=aLast; anIt++, i++ )
194 QLabel* lab = new QLabel( (*anIt).myName, GroupC1 );
195 GroupC1Layout->addWidget( lab, i, 0 );
197 QWidget* w = getCustomWidget( *anIt, GroupC1, i );
199 switch( (*anIt).myValue.type() )
203 QtxIntSpinBox* sb = new QtxIntSpinBox( GroupC1, (*anIt).myName.latin1() );
204 attuneStdWidget( sb, i );
205 sb->setValue( (*anIt).myValue.toInt() );
206 connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
210 case QVariant::Double:
212 QtxDblSpinBox* sb = new SMESHGUI_SpinBox( GroupC1, (*anIt).myName.latin1() );
213 attuneStdWidget( sb, i );
214 sb->setValue( (*anIt).myValue.toDouble() );
215 connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
219 case QVariant::String:
221 QLineEdit* le = new QLineEdit( GroupC1, (*anIt).myName.latin1() );
222 attuneStdWidget( le, i );
223 le->setText( (*anIt).myValue.toString() );
224 connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
232 GroupC1Layout->addWidget( w, i, 1 );
233 changeWidgets().append( w );
240 void SMESHGUI_GenericHypothesisCreator::onValueChanged()
244 bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const
249 bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const
253 ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
254 for( ; anIt!=aLast; anIt++ )
256 item.myName = (*anIt)->name();
257 if( (*anIt)->inherits( "QtxIntSpinBox" ) )
259 QtxIntSpinBox* sb = ( QtxIntSpinBox* )( *anIt );
260 item.myValue = sb->value();
261 params.append( item );
264 else if( (*anIt)->inherits( "QtxDblSpinBox" ) )
266 QtxDblSpinBox* sb = ( QtxDblSpinBox* )( *anIt );
267 item.myValue = sb->value();
268 params.append( item );
271 else if( (*anIt)->inherits( "QLineEdit" ) )
273 QLineEdit* line = ( QLineEdit* )( *anIt );
274 item.myValue = line->text();
275 params.append( item );
278 else if ( getParamFromCustomWidget( item, *anIt ))
280 params.append( item );
289 QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params)
291 QString valueStr = "";
292 ListOfStdParams::const_iterator param = params.begin(), aLast = params.end();
294 for( int i=0; param!=aLast; param++, i++ )
296 if ( valueStr.length() > len0 ) {
298 len0 = valueStr.length();
300 switch( (*param).myValue.type() )
303 valueStr += valueStr.number( (*param).myValue.toInt() );
305 case QVariant::Double:
306 valueStr += valueStr.number( (*param).myValue.toDouble() );
308 case QVariant::String:
309 valueStr += (*param).myValue.toString();
312 QVariant valCopy = (*param).myValue;
313 valueStr += valCopy.asString();
319 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const
324 SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis() const
326 if ( CORBA::is_nil( myInitParamsHypo ))
328 return myInitParamsHypo;
331 QString SMESHGUI_GenericHypothesisCreator::hypType() const
336 QString SMESHGUI_GenericHypothesisCreator::hypName() const
341 const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const
343 return myParamWidgets;
346 SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets()
348 return myParamWidgets;
351 bool SMESHGUI_GenericHypothesisCreator::isCreation() const
356 void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const
360 QString SMESHGUI_GenericHypothesisCreator::caption() const
365 QPixmap SMESHGUI_GenericHypothesisCreator::icon() const
370 QString SMESHGUI_GenericHypothesisCreator::type() const
374 QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
376 const int /*index*/) const
380 bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam& , QWidget* ) const
385 void SMESHGUI_GenericHypothesisCreator::onReject()
389 QString SMESHGUI_GenericHypothesisCreator::helpPage() const
391 QString aHypType = hypType();
392 QString aHelpFileName;
393 if ( aHypType == "LocalLength" )
394 aHelpFileName = "a1d_meshing_hypo_page.html#average_length_anchor";
395 else if ( aHypType == "Arithmetic1D")
396 aHelpFileName = "a1d_meshing_hypo_page.html#arithmetic_1d_anchor";
397 else if ( aHypType == "MaxElementArea")
398 aHelpFileName = "a2d_meshing_hypo_page.html#max_element_area_anchor";
399 else if ( aHypType == "MaxElementVolume")
400 aHelpFileName = "max_element_volume_hypo_page.html";
401 else if ( aHypType == "StartEndLength")
402 aHelpFileName = "a1d_meshing_hypo_page.html#start_and_end_length_anchor";
403 else if ( aHypType == "Deflection1D")
404 aHelpFileName = "a1d_meshing_hypo_page.html#deflection_1d_anchor";
405 else if ( aHypType == "AutomaticLength")
406 aHelpFileName = "a1d_meshing_hypo_page.html#automatic_length_anchor";
407 else if ( aHypType == "NumberOfSegments")
408 aHelpFileName = "a1d_meshing_hypo_page.html#number_of_segments_anchor";
409 else if ( aHypType == "ProjectionSource1D")
410 aHelpFileName = "projection_algos_page.html";
411 else if ( aHypType == "ProjectionSource2D")
412 aHelpFileName = "projection_algos_page.html";
413 else if ( aHypType == "ProjectionSource3D")
414 aHelpFileName = "projection_algos_page.html";
415 else if ( aHypType == "NumberOfLayers")
416 aHelpFileName = "radial_prism_algo_page.html";
417 else if ( aHypType == "LayerDistribution")
418 aHelpFileName = "radial_prism_algo_page.html";
419 else if ( aHypType == "SegmentLengthAroundVertex")
420 aHelpFileName = "segments_around_vertex_algo.html";
423 return aHelpFileName;
427 SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent )
428 : QtxDialog( parent, "", false, true ),
431 setMinimumSize( 300, height() );
432 // setFixedSize( 300, height() );
433 myLayout = new QVBoxLayout( mainFrame(), 0, 0 );
435 QFrame* titFrame = new QFrame( mainFrame() );
436 QHBoxLayout* titLay = new QHBoxLayout( titFrame, 0, 5 );
438 myIconLabel = new QLabel( titFrame );
439 myIconLabel->setScaledContents( false );
440 myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
441 myTypeLabel = new QLabel( titFrame );
443 myTypeLabel->setText( creator->hypType() );
445 titLay->addWidget( myIconLabel, 0 );
446 titLay->addWidget( myTypeLabel, 0 );
447 titLay->addStretch( 1 );
449 myLayout->addWidget( titFrame, 0 );
451 myHelpFileName = creator->helpPage();
453 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
456 SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg()
460 void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f )
464 f->reparent( mainFrame(), QPoint( 0, 0 ) );
465 myLayout->insertWidget( 1, f, 1 );
469 void SMESHGUI_HypothesisDlg::accept()
471 if ( myCreator && !myCreator->checkParams() )
477 void SMESHGUI_HypothesisDlg::reject()
479 if ( myCreator ) myCreator->onReject();
484 void SMESHGUI_HypothesisDlg::onHelp()
486 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
488 SMESHGUI* aSMESHGUI = dynamic_cast<SMESHGUI*>( app->activeModule() );
489 app->onHelpContextModule(aSMESHGUI ? app->moduleName(aSMESHGUI->moduleName()) : QString(""), myHelpFileName);
494 platform = "winapplication";
496 platform = "application";
498 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
499 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
500 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
501 QObject::tr("BUT_OK"));
505 void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p )
507 myIconLabel->setPixmap( p );
510 void SMESHGUI_HypothesisDlg::setType( const QString& t )
512 myTypeLabel->setText( t );