1 // Copyright (C) 2012-2013 ALNEOS
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.alneos.com/ or email : contact@alneos.fr
19 #include "GMSHPluginGUI_HypothesisCreator.h"
21 #include <SMESHGUI_Utils.h>
22 #include <SMESHGUI_HypothesesUtils.h>
23 #include <SMESHGUI_SpinBox.h>
24 #include <GeomSelectionTools.h>
26 #include CORBA_SERVER_HEADER(GMSHPlugin_Algorithm)
28 #include <SUIT_Session.h>
29 #include <SUIT_ResourceMgr.h>
31 #include <SalomeApp_Tools.h>
32 #include <LightApp_SelectionMgr.h>
33 #include <SALOME_ListIO.hxx>
43 #include <QTableWidget>
44 #include <QHeaderView>
45 #include <QPushButton>
93 GMSHPluginGUI_HypothesisCreator::GMSHPluginGUI_HypothesisCreator( const QString& theHypType )
94 : SMESHGUI_GenericHypothesisCreator( theHypType )
96 myGeomSelectionTools = NULL;
97 myCompoundSet.clear();
98 myIs2D = ( theHypType.endsWith("2D"));
101 GMSHPluginGUI_HypothesisCreator::~GMSHPluginGUI_HypothesisCreator()
105 bool GMSHPluginGUI_HypothesisCreator::checkParams(QString& msg) const
107 GmshHypothesisData data_old, data_new;
108 readParamsFromHypo( data_old );
109 readParamsFromWidgets( data_new );
110 bool res = storeParamsToHypo( data_new );
111 storeParamsToHypo( data_old );
115 QFrame* GMSHPluginGUI_HypothesisCreator::buildFrame()
117 QFrame* fr = new QFrame( 0 );
118 fr->setObjectName( "myframe" );
119 QVBoxLayout* lay = new QVBoxLayout( fr );
121 lay->setSpacing( 0 );
123 QTabWidget* tab = new QTabWidget( fr );
124 tab->setTabShape( QTabWidget::Rounded );
125 tab->setTabPosition( QTabWidget::North );
126 lay->addWidget( tab );
127 QWidget* GroupC1 = new QWidget();
128 tab->insertTab( 0, GroupC1, tr( "SMESH_ARGUMENTS" ) );
130 QGridLayout* aGroupLayout = new QGridLayout( GroupC1 );
131 aGroupLayout->setSpacing( 6 );
132 aGroupLayout->setMargin( 11 );
138 aGroupLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), GroupC1 ), row, 0 );
139 myName = new QLineEdit( GroupC1 );
140 myName->setMinimumWidth(160);
141 aGroupLayout->addWidget( myName, row, 1 );
145 aGroupLayout->addWidget( new QLabel( tr( "GMSH_2D_ALGO" ), GroupC1 ), row, 0 );
146 my2DAlgo = new QComboBox( GroupC1 );
147 QStringList types2DAlgo;
148 types2DAlgo << tr( "GMSH_AUTOMATIC" ) << tr( "GMSH_MESH_ADAPT" ) << tr( "GMSH_DELAUNAY" ) <<
149 tr( "GMSH_FRONTAL" ) << tr( "GMSH_DELAUNAY_FOR_QUAD" );
150 my2DAlgo->addItems( types2DAlgo );
151 aGroupLayout->addWidget( my2DAlgo, row, 1 );
157 aGroupLayout->addWidget( new QLabel( tr( "GMSH_3D_ALGO" ), GroupC1 ), row, 0 );
158 my3DAlgo = new QComboBox( GroupC1 );
159 QStringList types3DAlgo;
160 types3DAlgo << tr( "GMSH_FRONTAL_DELAUNAY" ) << tr( "GMSH_FRONTAL_HEX" ) << tr( "GMSH_MMG3D" ) <<
162 my3DAlgo->addItems( types3DAlgo );
163 aGroupLayout->addWidget( my3DAlgo, row, 1 );
167 aGroupLayout->addWidget( new QLabel( tr( "GMSH_2D_RECOMB_ALGO" ), GroupC1 ), row, 0 );
168 myRecomb2DAlgo = new QComboBox( GroupC1 );
169 QStringList typesRecomb2DAlgo;
170 typesRecomb2DAlgo << tr( "GMSH_STANDARD" ) << tr( "GMSH_BLOSSOM" );
171 myRecomb2DAlgo->addItems( typesRecomb2DAlgo );
172 aGroupLayout->addWidget( myRecomb2DAlgo, row, 1 );
175 myRecombineAll = new QCheckBox( tr( "GMSH_RECOMBINE_ALL" ), GroupC1 );
176 aGroupLayout->addWidget( myRecombineAll, row, 0 );
179 aGroupLayout->addWidget( new QLabel( tr( "GMSH_SUBDIV_ALGO" ), GroupC1 ), row, 0 );
180 mySubdivAlgo = new QComboBox( GroupC1 );
181 QStringList typesSubdivAlgo;
182 typesSubdivAlgo << tr( "GMSH_NONE" ) << tr( "GMSH_ALL_QUADS" ) << tr( "GMSH_ALL_HEXAS" );
183 mySubdivAlgo->addItems( typesSubdivAlgo );
184 aGroupLayout->addWidget( mySubdivAlgo, row, 1 );
187 aGroupLayout->addWidget( new QLabel( tr( "GMSH_REMESH_ALGO" ), GroupC1 ), row, 0 );
188 myRemeshAlgo = new QComboBox( GroupC1 );
189 QStringList typesRemeshAlgo;
190 typesRemeshAlgo << tr( "GMSH_NO_SPLIT" ) << tr( "GMSH_AUTO" ) << tr( "GMSH_AUTO_ONLY_WITH_METIS" );
191 myRemeshAlgo->addItems( typesRemeshAlgo );
192 aGroupLayout->addWidget( myRemeshAlgo, row, 1 );
195 aGroupLayout->addWidget( new QLabel( tr( "GMSH_REMESH_PARA" ), GroupC1 ), row, 0 );
196 myRemeshPara = new QComboBox( GroupC1 );
197 QStringList typesRemeshPara;
198 typesRemeshPara << tr( "GMSH_HARMONIC" ) << tr( "GMSH_CONFORMAL" ) << tr( "GMSH_RBF_HARMONIC" );
199 myRemeshPara->addItems( typesRemeshPara );
200 aGroupLayout->addWidget( myRemeshPara, row, 1 );
203 aGroupLayout->addWidget( new QLabel( tr( "GMSH_SMOOTHING_STEPS" ), GroupC1 ), row, 0 );
204 mySmouthSteps = new SMESHGUI_SpinBox( GroupC1 );
205 mySmouthSteps->RangeStepAndValidator( 1, 1000, 1, "length_precision" );
206 aGroupLayout->addWidget( mySmouthSteps, row, 1 );
209 aGroupLayout->addWidget( new QLabel( tr( "GMSH_SIZE_FACTOR" ), GroupC1 ), row, 0 );
210 mySizeFactor = new SMESHGUI_SpinBox( GroupC1 );
211 mySizeFactor->RangeStepAndValidator( 1e-06, 1e+06, 0.1, "length_precision" );
212 aGroupLayout->addWidget( mySizeFactor, row, 1 );
215 aGroupLayout->addWidget( new QLabel( tr( "GMSH_MIN_SIZE" ), GroupC1 ), row, 0 );
216 myMinSize = new SMESHGUI_SpinBox( GroupC1 );
217 myMinSize->RangeStepAndValidator( 0.0, 1e+22, 1., "length_precision" );
218 aGroupLayout->addWidget( myMinSize, row, 1 );
221 aGroupLayout->addWidget( new QLabel( tr( "GMSH_MAX_SIZE" ), GroupC1 ), row, 0 );
222 myMaxSize = new SMESHGUI_SpinBox( GroupC1 );
223 myMaxSize->RangeStepAndValidator( 0.0, 1e+22, 1e+21, "length_precision" );
224 aGroupLayout->addWidget( myMaxSize, row, 1 );
227 mySecondOrder = new QCheckBox( tr( "GMSH_SECOND_ORDER" ), GroupC1 );
228 aGroupLayout->addWidget( mySecondOrder, row, 0 );
230 myUseIncomplElem = new QCheckBox( tr( "GMSH_USE_INCOMPLETE_ELEMENT" ), GroupC1 );
231 aGroupLayout->addWidget( myUseIncomplElem, row, 1 );
234 connect( mySecondOrder, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) );
237 QWidget* compoundGroup = new QWidget();
238 tab->insertTab(1, compoundGroup, tr("GMSH_COMPOUND"));
240 myCompoundTable = new QTableWidget(0, 2, compoundGroup);
241 QGridLayout* compoundLayout = new QGridLayout(compoundGroup);
242 compoundLayout->addWidget(myCompoundTable, 1, 0, 8, 1);
244 QStringList compoundHeaders;
245 compoundHeaders << tr( "GMSH_COMPOUND_ENTRY_COLUMN" ) << tr( "GMSH_COMPOUND_NAME_COLUMN" );
246 myCompoundTable->setHorizontalHeaderLabels(compoundHeaders);
247 myCompoundTable->horizontalHeader()->hideSection(0);
248 myCompoundTable->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
249 myCompoundTable->resizeColumnToContents(1);
250 myCompoundTable->setAlternatingRowColors(true);
251 myCompoundTable->verticalHeader()->hide();
253 QPushButton* addCompoundButton = new QPushButton(tr("GMSH_COMPOUND_ADD"), compoundGroup);
254 compoundLayout->addWidget(addCompoundButton, 1, 1, 1, 1);
255 QFrame *line2 = new QFrame(compoundGroup);
257 line2->setFrameShape(QFrame::HLine);
258 line2->setFrameShadow(QFrame::Sunken);
259 compoundLayout->addWidget(line2, 2, 1, 1, 1);
261 QPushButton* removeButton = new QPushButton(tr("GMSH_COMPOUND_REMOVE"), compoundGroup);
262 compoundLayout->addWidget(removeButton, 3, 1, 1, 1);
264 connect( addCompoundButton, SIGNAL(clicked()), this, SLOT(onAddCompound()));
265 connect( removeButton, SIGNAL(clicked()), this, SLOT(onRemoveCompound()));
270 void GMSHPluginGUI_HypothesisCreator::updateWidgets()
272 myUseIncomplElem->setEnabled(mySecondOrder->isChecked());
275 void GMSHPluginGUI_HypothesisCreator::onAddCompound()
277 GMSHPlugin::GMSHPlugin_Hypothesis_var h = GMSHPlugin::GMSHPlugin_Hypothesis::_narrow(initParamsHypothesis());
278 GeomSelectionTools* geomSelectionTools = getGeomSelectionTools();
279 LightApp_SelectionMgr* mySel = geomSelectionTools->selectionMgr();
280 SALOME_ListIO ListSelectedObjects;
281 mySel->selectedObjects(ListSelectedObjects, NULL, false );
282 SALOME_ListIteratorOfListIO Object_It(ListSelectedObjects);
283 for (Object_It ; Object_It.More() ; Object_It.Next())
285 Handle(SALOME_InteractiveObject) anObject = Object_It.Value();
286 std::string entry, shapeName;
287 entry = geomSelectionTools->getEntryOfObject(anObject);
288 shapeName = anObject->getName();
289 TopAbs_ShapeEnum shapeType;
290 shapeType = geomSelectionTools->entryToShapeType(entry);
291 if ((shapeType == TopAbs_SHAPE) || (shapeType != TopAbs_EDGE && shapeType != TopAbs_FACE))
293 myCompoundTable->setFocus();
295 shapeEntry = QString::fromStdString(entry);
296 if (myCompoundSet.contains(shapeEntry))
298 int row = myCompoundTable->rowCount() ;
299 myCompoundTable->setRowCount(row+1);
300 myCompoundTable->setItem(row, 0, new QTableWidgetItem(shapeEntry));
301 myCompoundTable->item(row, 0 )->setFlags(0);
302 myCompoundTable->setItem(row, 1, new QTableWidgetItem(QString::fromStdString(shapeName)));
303 myCompoundTable->item(row, 1 )->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
304 myCompoundTable->resizeColumnToContents(1);
305 myCompoundTable->clearSelection();
306 myCompoundTable->scrollToItem( myCompoundTable->item( row, 1 ) );
307 myCompoundSet.insert(shapeEntry);
308 myCompoundToRemove.remove(shapeEntry);
312 void GMSHPluginGUI_HypothesisCreator::onRemoveCompound()
314 QList<int> selectedRows;
315 QList<QTableWidgetItem*> selected = myCompoundTable->selectedItems();
316 QTableWidgetItem* item;
318 foreach(item, selected)
321 if (!selectedRows.contains(row))
322 selectedRows.append( row );
324 qSort( selectedRows );
325 QListIterator<int> it( selectedRows );
327 while (it.hasPrevious())
330 QString entry = myCompoundTable->item(row,0)->text();
331 if (myCompoundSet.contains(entry))
333 myCompoundSet.remove(entry);
334 myCompoundToRemove.insert(entry);
336 myCompoundTable->removeRow(row );
338 myCompoundTable->resizeColumnToContents(1);
341 void GMSHPluginGUI_HypothesisCreator::retrieveParams() const
343 GmshHypothesisData data;
344 readParamsFromHypo( data );
347 myName->setText( data.myName );
348 my2DAlgo->setCurrentIndex( data.my2DAlgo );
350 my3DAlgo->setCurrentIndex( data.my3DAlgo );
351 myRecomb2DAlgo->setCurrentIndex( data.myRecomb2DAlgo );
352 if ( myRecombineAll )
353 myRecombineAll->setChecked( data.myRecombineAll );
355 mySubdivAlgo->setCurrentIndex( data.mySubdivAlgo );
356 myRemeshAlgo->setCurrentIndex( data.myRemeshAlgo);
357 myRemeshPara->setCurrentIndex( data.myRemeshPara);
358 if(data.mySmouthStepsVar.isEmpty())
359 mySmouthSteps->setValue( data.mySmouthSteps );
361 mySmouthSteps->setText( data.mySmouthStepsVar );
362 if(data.mySizeFactorVar.isEmpty())
363 mySizeFactor->setValue( data.mySizeFactor );
365 mySizeFactor->setText( data.mySizeFactorVar );
366 if(data.myMaxSizeVar.isEmpty())
367 myMaxSize->setValue( data.myMaxSize );
369 myMaxSize->setText( data.myMaxSizeVar );
370 if(data.myMinSizeVar.isEmpty())
371 myMinSize->setValue( data.myMinSize );
373 myMinSize->setText( data.myMinSizeVar );
375 mySecondOrder->setChecked( data.mySecondOrder );
376 if ( myUseIncomplElem )
377 myUseIncomplElem->setChecked( data.myUseIncomplElem );
379 GMSHPluginGUI_HypothesisCreator* that = (GMSHPluginGUI_HypothesisCreator*)this;
380 that->updateWidgets();
382 GeomSelectionTools* geomSelectionTools = that->getGeomSelectionTools();
383 for (QSet<QString>::const_iterator i = myCompoundSet.begin(); i != myCompoundSet.end(); ++i)
385 const QString entry = *i;
386 std::string shapeName = geomSelectionTools->getNameFromEntry(entry.toStdString());
387 int row = myCompoundTable->rowCount();
388 myCompoundTable->setRowCount(row+1);
389 myCompoundTable->setItem(row, 0, new QTableWidgetItem(entry));
390 myCompoundTable->item(row, 0)->setFlags(0);
391 myCompoundTable->setItem(row, 1, new QTableWidgetItem(QString::fromStdString(shapeName)));
392 myCompoundTable->item(row, 1)->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
394 myCompoundTable->resizeColumnToContents(1);
397 QString GMSHPluginGUI_HypothesisCreator::storeParams() const
399 GmshHypothesisData data;
400 readParamsFromWidgets( data );
401 storeParamsToHypo( data );
403 QString valStr = tr("GMSH_MAX_SIZE") + " = " + QString::number( data.myMaxSize ) + "; ";
404 valStr += tr("GMSH_MIN_SIZE") + " = " + QString::number( data.myMinSize ) + "; ";
405 if ( data.mySecondOrder )
406 valStr += tr("GMSH_SECOND_ORDER") + "; ";
411 bool GMSHPluginGUI_HypothesisCreator::readParamsFromHypo( GmshHypothesisData& h_data ) const
413 GMSHPlugin::GMSHPlugin_Hypothesis_var h =
414 GMSHPlugin::GMSHPlugin_Hypothesis::_narrow( initParamsHypothesis() );
416 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
417 h_data.myName = isCreation() && data ? data->Label : "";
419 h_data.my2DAlgo = (int) h->Get2DAlgo();
421 h_data.my3DAlgo = (int) h->Get3DAlgo();
422 h_data.myRecomb2DAlgo = (int) h->GetRecomb2DAlgo();
423 h_data.myRecombineAll = h->GetRecombineAll();
424 h_data.mySubdivAlgo = (int) h->GetSubdivAlgo();
425 h_data.myRemeshAlgo = (int) h->GetRemeshAlgo();
426 h_data.myRemeshPara = (int) h->GetRemeshPara();
427 h_data.mySmouthSteps = h->GetSmouthSteps();
428 h_data.mySizeFactor = h->GetSizeFactor();
429 h_data.myMinSize = h->GetMinSize();
430 h_data.myMaxSize = h->GetMaxSize();
431 h_data.mySmouthStepsVar = getVariableName("SmouthSteps");
432 h_data.mySizeFactorVar = getVariableName("SizeFactor");
433 h_data.myMinSizeVar = getVariableName("SetMinSize");
434 h_data.myMaxSizeVar = getVariableName("SetMaxSize");
435 h_data.mySecondOrder = h->GetSecondOrder();
436 h_data.myUseIncomplElem = h->GetUseIncomplElem();
438 GMSHPluginGUI_HypothesisCreator* that = (GMSHPluginGUI_HypothesisCreator*)this;
439 GMSHPlugin::string_array_var myEntries = h->GetCompoundOnEntries();
440 for ( int i=0 ; i<myEntries->length() ; i++ )
442 QString entry = myEntries[i].in();
443 that->myCompoundSet.insert(entry);
449 bool GMSHPluginGUI_HypothesisCreator::storeParamsToHypo( const GmshHypothesisData& h_data ) const
451 GMSHPlugin::GMSHPlugin_Hypothesis_var h =
452 GMSHPlugin::GMSHPlugin_Hypothesis::_narrow( hypothesis() );
458 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().data() );
460 h->Set2DAlgo( h_data.my2DAlgo );
462 h->Set3DAlgo( h_data.my3DAlgo );
463 h->SetRecomb2DAlgo( h_data.myRecomb2DAlgo );
464 h->SetRecombineAll( h_data.myRecombineAll );
465 h->SetSubdivAlgo( h_data.mySubdivAlgo );
466 h->SetRemeshAlgo( h_data.myRemeshAlgo );
467 h->SetRemeshPara( h_data.myRemeshPara );
468 h->SetSmouthSteps( h_data.mySmouthSteps );
469 h->SetSizeFactor( h_data.mySizeFactor );
470 h->SetMinSize( h_data.myMinSize );
471 h->SetMaxSize( h_data.myMaxSize );
472 h->SetVarParameter( h_data.mySmouthStepsVar.toLatin1().constData(), "SmouthSteps");
473 h->SetVarParameter( h_data.mySizeFactorVar.toLatin1().constData(), "SizeFactor");
474 h->SetVarParameter( h_data.myMinSizeVar.toLatin1().constData(), "SetMinSize");
475 h->SetVarParameter( h_data.myMaxSizeVar.toLatin1().constData(), "SetMaxSize");
476 h->SetSecondOrder( h_data.mySecondOrder );
477 h->SetUseIncomplElem( h_data.myUseIncomplElem );
478 h->SetIs2d( myIs2D );
480 for (QSet<QString>::const_iterator i = myCompoundSet.begin(); i != myCompoundSet.end(); ++i)
482 const QString entry = *i;
483 h->SetCompoundOnEntry(entry.toLatin1().constData());
485 for (QSet<QString>::const_iterator i = myCompoundToRemove.begin(); i != myCompoundToRemove.end(); ++i)
487 const QString entry = *i;
488 h->UnsetCompoundOnEntry(entry.toLatin1().constData());
491 catch(const SALOME::SALOME_Exception& ex)
493 SalomeApp_Tools::QtCatchCorbaException(ex);
499 bool GMSHPluginGUI_HypothesisCreator::readParamsFromWidgets( GmshHypothesisData& h_data ) const
501 h_data.myName = myName ? myName->text() : "";
502 h_data.my2DAlgo = my2DAlgo->currentIndex();
504 h_data.my3DAlgo = my3DAlgo->currentIndex();
505 h_data.myRecomb2DAlgo = myRecomb2DAlgo->currentIndex();
506 h_data.myRecombineAll = myRecombineAll->isChecked();
507 h_data.mySubdivAlgo = mySubdivAlgo->currentIndex();
508 h_data.myRemeshAlgo = myRemeshAlgo->currentIndex();
509 h_data.myRemeshPara = myRemeshPara->currentIndex();
510 h_data.mySmouthSteps = mySmouthSteps->value();
511 h_data.mySizeFactor = mySizeFactor->value();
512 h_data.myMinSize = myMinSize->value();
513 h_data.myMaxSize = myMaxSize->value();
514 h_data.mySmouthStepsVar = mySmouthSteps->text();
515 h_data.mySizeFactorVar = mySizeFactor->text();
516 h_data.myMinSizeVar = myMinSize->text();
517 h_data.myMaxSizeVar = myMaxSize->text();
518 h_data.mySecondOrder = mySecondOrder->isChecked();
519 h_data.myUseIncomplElem = myUseIncomplElem->isChecked();
521 // ne semble pas utile dans la mesure ou myCompoundSet n'a pas besoin d'etre modifier
523 GMSHPluginGUI_HypothesisCreator* that = (GMSHPluginGUI_HypothesisCreator*)this;
524 int nbRows = myCompoundTable->rowCount();
525 for(int row=0 ; row < nbRows ; row++)
527 QString entry = myLocalSizeTable->item(row, 1)->text();
528 that->myCompoundSet.insert(entry);
534 // on ne modifie rien à partir de là
536 GeomSelectionTools* GMSHPluginGUI_HypothesisCreator::getGeomSelectionTools()
538 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
539 if (myGeomSelectionTools == NULL || myGeomSelectionTools->getMyStudy() != aStudy) {
540 delete myGeomSelectionTools;
541 myGeomSelectionTools = new GeomSelectionTools(aStudy);
543 return myGeomSelectionTools;
546 QString GMSHPluginGUI_HypothesisCreator::caption() const
548 return tr( QString( "GMSH_%1_TITLE" ).arg(myIs2D?QString("2D"):QString("3D")).toLatin1().data() );
551 QPixmap GMSHPluginGUI_HypothesisCreator::icon() const
553 QString hypIconName = tr( QString("ICON_DLG_GMSH_PARAMETERS%1").arg(myIs2D?QString("_2D"):QString("")).toLatin1().data() );
554 return SUIT_Session::session()->resourceMgr()->loadPixmap( "GMSHPlugin", hypIconName );
557 QString GMSHPluginGUI_HypothesisCreator::type() const
559 return tr( QString( "GMSH_%1_HYPOTHESIS" ).arg(myIs2D?QString("2D"):QString("3D")).toLatin1().data() );
562 QString GMSHPluginGUI_HypothesisCreator::helpPage() const
564 return "gmsh_2d_3d_hypo_page.html";