1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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
23 // NETGENPlugin GUI: GUI for plugged-in mesher NETGENPlugin
24 // File : NETGENPluginGUI_HypothesisCreator.cxx
25 // Author : Michael Zorin
26 // Module : NETGENPlugin
28 #include "NETGENPluginGUI_HypothesisCreator.h"
30 #include <SMESHGUI_Utils.h>
31 #include <SMESHGUI_HypothesesUtils.h>
32 #include <SMESHGUI_SpinBox.h>
33 #include <GeomSelectionTools.h>
35 #include CORBA_SERVER_HEADER(NETGENPlugin_Algorithm)
37 #include <SUIT_FileDlg.h>
38 #include <SUIT_ResourceMgr.h>
39 #include <SUIT_Session.h>
41 #include <SalomeApp_Tools.h>
42 #include <LightApp_SelectionMgr.h>
43 #include <SALOME_ListIO.hxx>
53 #include <QTableWidget>
54 #include <QHeaderView>
55 #include <QPushButton>
90 NETGENPluginGUI_HypothesisCreator::NETGENPluginGUI_HypothesisCreator( const QString& theHypType )
91 : SMESHGUI_GenericHypothesisCreator( theHypType )
93 myGeomSelectionTools = NULL;
94 myLocalSizeMap.clear();
95 myIs2D = ( theHypType.startsWith("NETGEN_Parameters_2D") ||
96 theHypType == "NETGEN_RemesherParameters_2D");
97 myIsONLY = ( theHypType == "NETGEN_Parameters_2D_ONLY" ||
98 theHypType == "NETGEN_Parameters_3D" ||
99 theHypType == "NETGEN_RemesherParameters_2D");
102 NETGENPluginGUI_HypothesisCreator::~NETGENPluginGUI_HypothesisCreator()
106 bool NETGENPluginGUI_HypothesisCreator::checkParams(QString& msg) const
108 NetgenHypothesisData data_old, data_new;
109 readParamsFromHypo( data_old );
110 readParamsFromWidgets( data_new );
111 bool res = storeParamsToHypo( data_new );
112 //storeParamsToHypo( data_old ); -- issue 0021364: Dump of netgen parameters has duplicate lines
114 res = myMaxSize->isValid(msg,true) && res;
115 res = myMinSize->isValid(msg,true) && res;
116 res = myGrowthRate->isValid(msg,true) && res; ;
117 if ( myNbSegPerEdge )
118 res = myNbSegPerEdge->isValid(msg,true) && res;
119 if ( myNbSegPerRadius )
120 res = myNbSegPerRadius->isValid(msg,true) && res;
122 res = myRidgeAngle->isValid(msg,true) && res;
124 if ( !res ) // -- issue 0021364: Dump of netgen parameters has duplicate lines
125 storeParamsToHypo( data_old );
130 QFrame* NETGENPluginGUI_HypothesisCreator::buildFrame()
132 const bool isRemesher = ( hypType() == "NETGEN_RemesherParameters_2D" );
134 QFrame* fr = new QFrame( 0 );
135 fr->setObjectName( "myframe" );
136 QVBoxLayout* lay = new QVBoxLayout( fr );
138 lay->setSpacing( 0 );
140 QTabWidget* tab = new QTabWidget( fr );
141 tab->setTabShape( QTabWidget::Rounded );
142 tab->setTabPosition( QTabWidget::North );
143 lay->addWidget( tab );
144 QWidget* GroupC1 = new QWidget();
145 tab->insertTab( STD_TAB, GroupC1, tr( "SMESH_ARGUMENTS" ) );
147 QGridLayout* aGroupLayout = new QGridLayout( GroupC1 );
148 aGroupLayout->setSpacing( 6 );
149 aGroupLayout->setMargin( 11 );
155 aGroupLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), GroupC1 ), row, 0 );
156 myName = new QLineEdit( GroupC1 );
157 myName->setMinimumWidth(160);
158 aGroupLayout->addWidget( myName, row, 1 );
162 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_MAX_SIZE" ), GroupC1 ), row, 0 );
163 myMaxSize = new SMESHGUI_SpinBox( GroupC1 );
164 myMaxSize->RangeStepAndValidator( 1e-07, 1e+06, 10., "length_precision" );
165 aGroupLayout->addWidget( myMaxSize, row, 1 );
168 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_MIN_SIZE" ), GroupC1 ), row, 0 );
169 myMinSize = new SMESHGUI_SpinBox( GroupC1 );
170 myMinSize->RangeStepAndValidator( 0.0, 1e+06, 10., "length_precision" );
171 aGroupLayout->addWidget( myMinSize, row, 1 );
177 mySecondOrder = new QCheckBox( tr( "NETGEN_SECOND_ORDER" ), GroupC1 );
178 aGroupLayout->addWidget( mySecondOrder, row, 0, 1, 2 );
182 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_FINENESS" ), GroupC1 ), row, 0 );
183 myFineness = new QComboBox( GroupC1 );
185 types << tr( "NETGEN_VERYCOARSE" ) << tr( "NETGEN_COARSE" ) << tr( "NETGEN_MODERATE" ) <<
186 tr( "NETGEN_FINE" ) << tr( "NETGEN_VERYFINE" ) << tr( "NETGEN_CUSTOM" );
187 myFineness->addItems( types );
188 aGroupLayout->addWidget( myFineness, row, 1 );
189 connect( myFineness, SIGNAL( activated( int ) ), this, SLOT( onFinenessChanged() ) );
192 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_GROWTH_RATE" ), GroupC1 ), row, 0 );
193 myGrowthRate = new SMESHGUI_SpinBox( GroupC1 );
194 myGrowthRate->RangeStepAndValidator( .0001, 10., .1, "parametric_precision" );
195 aGroupLayout->addWidget( myGrowthRate, row, 1 );
199 myNbSegPerRadius = 0;
202 const double VALUE_MAX = 1.0e+6;
204 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_SEG_PER_EDGE" ), GroupC1 ), row, 0 );
205 myNbSegPerEdge = new SMESHGUI_SpinBox( GroupC1 );
206 myNbSegPerEdge->RangeStepAndValidator( .2, VALUE_MAX, .1, "parametric_precision" );
207 aGroupLayout->addWidget( myNbSegPerEdge, row, 1 );
210 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_SEG_PER_RADIUS" ), GroupC1 ), row, 0 );
211 myNbSegPerRadius = new SMESHGUI_SpinBox( GroupC1 );
212 myNbSegPerRadius->RangeStepAndValidator( .2, VALUE_MAX, .1, "parametric_precision" );
213 aGroupLayout->addWidget( myNbSegPerRadius, row, 1 );
217 myChordalErrorEnabled = 0;
219 if (( myIs2D && !isRemesher ) || !myIsONLY )
221 myChordalErrorEnabled = new QCheckBox( tr( "NETGEN_CHORDAL_ERROR" ), GroupC1 );
222 aGroupLayout->addWidget( myChordalErrorEnabled, row, 0 );
223 myChordalError = new SMESHGUI_SpinBox( GroupC1 );
224 myChordalError->RangeStepAndValidator( COORD_MIN, COORD_MAX, .1, "length_precision" );
225 aGroupLayout->addWidget( myChordalError, row, 1 );
226 connect( myChordalErrorEnabled, SIGNAL( stateChanged(int)), SLOT( onChordalErrorEnabled()));
233 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_RIDGE_ANGLE" ), GroupC1 ), row, 0 );
234 myRidgeAngle = new SMESHGUI_SpinBox( GroupC1 );
235 myRidgeAngle->RangeStepAndValidator( 0, 90, 10, "angle_precision" );
236 aGroupLayout->addWidget( myRidgeAngle, row, 1 );
240 mySurfaceCurvature = 0;
241 if (( myIs2D && !isRemesher ) || !myIsONLY )
243 mySurfaceCurvature = new QCheckBox( tr( "NETGEN_SURFACE_CURVATURE" ), GroupC1 );
244 aGroupLayout->addWidget( mySurfaceCurvature, row, 0, 1, 2 );
245 connect( mySurfaceCurvature, SIGNAL( stateChanged( int ) ), this, SLOT( onSurfaceCurvatureChanged() ) );
249 myAllowQuadrangles = 0;
250 if ( myIs2D || !myIsONLY ) // disable only for NETGEN 3D
252 myAllowQuadrangles = new QCheckBox( tr( "NETGEN_ALLOW_QUADRANGLES" ), GroupC1 );
253 aGroupLayout->addWidget( myAllowQuadrangles, row, 0, 1, 2 );
260 myOptimize = new QCheckBox( tr( "NETGEN_OPTIMIZE" ), GroupC1 );
261 aGroupLayout->addWidget( myOptimize, row, 0, 1, 2 );
268 myFuseEdges = new QCheckBox( tr( "NETGEN_FUSE_EDGES" ), GroupC1 );
269 aGroupLayout->addWidget( myFuseEdges, row, 0, 1, 2 );
273 myLocalSizeTable = 0;
276 QWidget* localSizeGroup = new QWidget();
277 QGridLayout* localSizeLayout = new QGridLayout(localSizeGroup);
279 myLocalSizeTable = new QTableWidget(0, LSZ_NB_COLUMNS, localSizeGroup);
280 localSizeLayout->addWidget(myLocalSizeTable, 1, 0, 8, 2);
281 QStringList localSizeHeaders;
282 localSizeHeaders << tr( "LSZ_ENTRY_COLUMN" )<< tr( "LSZ_NAME_COLUMN" ) << tr( "LSZ_LOCALSIZE_COLUMN" );
283 myLocalSizeTable->setHorizontalHeaderLabels(localSizeHeaders);
284 myLocalSizeTable->horizontalHeader()->hideSection(LSZ_ENTRY_COLUMN);
285 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
286 myLocalSizeTable->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
288 myLocalSizeTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
290 myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN);
291 myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
292 myLocalSizeTable->setAlternatingRowColors(true);
293 myLocalSizeTable->verticalHeader()->hide();
295 QPushButton* addVertexButton = new QPushButton(tr("NETGEN_LSZ_VERTEX"), localSizeGroup);
296 localSizeLayout->addWidget(addVertexButton, LSZ_VERTEX_BTN, 2, 1, 1);
297 QPushButton* addEdgeButton = new QPushButton(tr("NETGEN_LSZ_EDGE"), localSizeGroup);
298 localSizeLayout->addWidget(addEdgeButton, LSZ_EDGE_BTN, 2, 1, 1);
299 QPushButton* addFaceButton = new QPushButton(tr("NETGEN_LSZ_FACE"), localSizeGroup);
300 localSizeLayout->addWidget(addFaceButton, LSZ_FACE_BTN, 2, 1, 1);
301 QPushButton* addSolidButton = new QPushButton(tr("NETGEN_LSZ_SOLID"), localSizeGroup);
302 localSizeLayout->addWidget(addSolidButton, LSZ_SOLID_BTN, 2, 1, 1);
304 QFrame *line2 = new QFrame(localSizeGroup);
305 line2->setFrameShape(QFrame::HLine);
306 line2->setFrameShadow(QFrame::Sunken);
307 localSizeLayout->addWidget(line2, LSZ_SEPARATOR2, 2, 1, 1);
309 QPushButton* removeButton = new QPushButton(tr("NETGEN_LSZ_REMOVE"), localSizeGroup);
310 localSizeLayout->addWidget(removeButton, LSZ_REMOVE_BTN, 2, 1, 1);
312 QPushButton* fileBtn = new QPushButton(tr("NETGEN_LSZ_FILE"), localSizeGroup);
313 myMeshSizeFile = new QLineEdit(localSizeGroup);
314 myMeshSizeFile->setReadOnly( true );
315 localSizeLayout->addWidget( fileBtn, LSZ_FILE_LE, 0, 1, 1);
316 localSizeLayout->addWidget( myMeshSizeFile, LSZ_FILE_LE, 1, 1, 2);
318 connect( addVertexButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnVertex()));
319 connect( addEdgeButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnEdge()));
320 connect( addFaceButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnFace()));
321 connect( addSolidButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnSolid()));
322 connect( removeButton, SIGNAL(clicked()), this, SLOT(onRemoveLocalSizeOnShape()));
323 connect( myLocalSizeTable, SIGNAL(cellChanged(int, int)), this, SLOT(onSetLocalSize(int, int)));
324 connect( fileBtn, SIGNAL(clicked()), this, SLOT(onSetSizeFile()));
326 tab->insertTab(LSZ_TAB, localSizeGroup, tr("NETGEN_LOCAL_SIZE"));
331 void NETGENPluginGUI_HypothesisCreator::retrieveParams() const
333 NetgenHypothesisData data;
334 readParamsFromHypo( data );
337 myName->setText( data.myName );
338 if(data.myMaxSizeVar.isEmpty())
339 myMaxSize->setValue( data.myMaxSize );
341 myMaxSize->setText( data.myMaxSizeVar );
343 if(data.myMinSizeVar.isEmpty())
344 myMinSize->setValue( data.myMinSize );
346 myMinSize->setText( data.myMinSizeVar );
349 mySecondOrder->setChecked( data.mySecondOrder );
351 myOptimize->setChecked( data.myOptimize );
352 myFineness->setCurrentIndex( data.myFineness );
354 if(data.myGrowthRateVar.isEmpty())
355 myGrowthRate->setValue( data.myGrowthRate );
357 myGrowthRate->setText( data.myGrowthRateVar );
359 if ( myNbSegPerEdge )
361 if(data.myNbSegPerEdgeVar.isEmpty())
362 myNbSegPerEdge->setValue( data.myNbSegPerEdge );
364 myNbSegPerEdge->setText( data.myNbSegPerEdgeVar );
366 if ( myNbSegPerRadius )
368 if(data.myNbSegPerRadiusVar.isEmpty())
369 myNbSegPerRadius->setValue( data.myNbSegPerRadius );
371 myNbSegPerRadius->setText( data.myNbSegPerRadiusVar );
373 if ( myChordalError )
375 myChordalErrorEnabled->setChecked( data.myChordalErrorEnabled && data.myChordalError > 0 );
376 if(data.myChordalErrorVar.isEmpty())
377 myChordalError->setValue( data.myChordalError > 0 ? data.myChordalError : 0.1 );
379 myChordalError->setText( data.myChordalErrorVar );
380 myChordalError->setEnabled( myChordalErrorEnabled->isChecked() );
384 if ( data.myRidgeAngleVar.isEmpty() )
385 myRidgeAngle->setValue( data.myRidgeAngle );
387 myRidgeAngle->setText( data.myRidgeAngleVar );
389 if (myAllowQuadrangles)
390 myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
392 if (mySurfaceCurvature)
393 mySurfaceCurvature->setChecked( data.mySurfaceCurvature );
396 myFuseEdges->setChecked( data.myFuseEdges );
399 ((NETGENPluginGUI_HypothesisCreator*) this )-> onSurfaceCurvatureChanged();
401 if ( myLocalSizeTable )
403 NETGENPluginGUI_HypothesisCreator* that = (NETGENPluginGUI_HypothesisCreator*)this;
404 QMapIterator<QString, QString> i(myLocalSizeMap);
405 GeomSelectionTools* geomSelectionTools = that->getGeomSelectionTools();
406 while (i.hasNext()) {
408 const QString entry = i.key();
409 std::string shapeName = geomSelectionTools->getNameFromEntry(entry.toStdString());
410 const QString localSize = i.value();
411 int row = myLocalSizeTable->rowCount();
412 myLocalSizeTable->setRowCount(row+1);
413 myLocalSizeTable->setItem(row, LSZ_ENTRY_COLUMN, new QTableWidgetItem(entry));
414 myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN)->setFlags(0);
415 myLocalSizeTable->setItem(row, LSZ_NAME_COLUMN, new QTableWidgetItem(QString::fromStdString(shapeName)));
416 myLocalSizeTable->item(row, LSZ_NAME_COLUMN)->setFlags(0);
417 myLocalSizeTable->setItem(row, LSZ_LOCALSIZE_COLUMN, new QTableWidgetItem(localSize));
418 myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN)->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsEnabled);
420 myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN);
421 myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
423 myMeshSizeFile->setText( data.myMeshSizeFile );
427 QString NETGENPluginGUI_HypothesisCreator::storeParams() const
429 NetgenHypothesisData data;
430 readParamsFromWidgets( data );
431 storeParamsToHypo( data );
436 bool NETGENPluginGUI_HypothesisCreator::readParamsFromHypo( NetgenHypothesisData& h_data ) const
438 NETGENPlugin::NETGENPlugin_Hypothesis_var h =
439 NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( initParamsHypothesis() );
441 h_data.myName = isCreation() ? hypName() : "";
443 h_data.myMaxSize = h->GetMaxSize();
444 h_data.myMaxSizeVar = getVariableName("SetMaxSize");
445 h_data.mySecondOrder = h->GetSecondOrder();
446 h_data.myOptimize = h->GetOptimize();
448 h_data.myFineness = (int) h->GetFineness();
449 h_data.myGrowthRate = h->GetGrowthRate();
450 h_data.myGrowthRateVar = getVariableName("SetGrowthRate");
451 h_data.myNbSegPerEdge = h->GetNbSegPerEdge();
452 h_data.myNbSegPerEdgeVar = getVariableName("SetNbSegPerEdge");
453 h_data.myNbSegPerRadius = h->GetNbSegPerRadius();
454 h_data.myNbSegPerRadiusVar = getVariableName("SetNbSegPerRadius");
455 h_data.myChordalError = h->GetChordalError();
456 h_data.myChordalErrorVar = getVariableName("SetChordalError");
457 h_data.myChordalErrorEnabled = h->GetChordalErrorEnabled();
458 h_data.myMinSize = h->GetMinSize();
459 h_data.myMinSizeVar = getVariableName("SetMinSize");
460 h_data.mySurfaceCurvature = h->GetUseSurfaceCurvature();
461 h_data.myFuseEdges = h->GetFuseEdges();
462 h_data.myMeshSizeFile = h->GetMeshSizeFile();
466 // NETGENPlugin::NETGENPlugin_Hypothesis_var h =
467 // NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( initParamsHypothesis() );
470 h_data.myAllowQuadrangles = h->GetQuadAllowed();
474 NETGENPlugin::NETGENPlugin_RemesherHypothesis_2D_var rh =
475 NETGENPlugin::NETGENPlugin_RemesherHypothesis_2D::_narrow( h );
477 if ( !rh->_is_nil() )
478 h_data.myRidgeAngle = rh->GetRidgeAngle();
481 NETGENPluginGUI_HypothesisCreator* that = (NETGENPluginGUI_HypothesisCreator*)this;
482 NETGENPlugin::string_array_var myEntries = h->GetLocalSizeEntries();
483 for ( size_t i = 0; i < myEntries->length(); i++ )
485 QString entry = myEntries[i].in();
486 if (myLocalSizeMap.contains(entry) &&
487 myLocalSizeMap[entry] == "__TO_DELETE__")
489 double val = h->GetLocalSizeOnEntry( myEntries[i] );
490 std::ostringstream tmp;
492 that->myLocalSizeMap[entry] = tmp.str().c_str();
498 bool NETGENPluginGUI_HypothesisCreator::storeParamsToHypo( const NetgenHypothesisData& h_data ) const
500 NETGENPlugin::NETGENPlugin_Hypothesis_var h =
501 NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( hypothesis() );
507 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().data() );
508 h->SetVarParameter( h_data.myMaxSizeVar.toLatin1().constData(), "SetMaxSize");
509 h->SetMaxSize ( h_data.myMaxSize );
511 h->SetSecondOrder ( h_data.mySecondOrder );
513 h->SetOptimize ( h_data.myOptimize );
514 int fineness = h_data.myFineness;
515 h->SetFineness ( fineness );
517 if( fineness==UserDefined )
519 h->SetVarParameter ( h_data.myGrowthRateVar.toLatin1().constData(), "SetGrowthRate");
520 h->SetGrowthRate ( h_data.myGrowthRate );
521 if ( myNbSegPerEdge )
523 h->SetVarParameter ( h_data.myNbSegPerEdgeVar.toLatin1().constData(), "SetNbSegPerEdge");
524 h->SetNbSegPerEdge ( h_data.myNbSegPerEdge );
526 if ( myNbSegPerRadius )
528 h->SetVarParameter ( h_data.myNbSegPerRadiusVar.toLatin1().constData(), "SetNbSegPerRadius");
529 h->SetNbSegPerRadius( h_data.myNbSegPerRadius );
532 if ( myChordalError )
534 h->SetVarParameter ( h_data.myChordalErrorVar.toLatin1().constData(), "SetChordalError");
535 h->SetChordalError ( h_data.myChordalError );
536 h->SetChordalErrorEnabled( h_data.myChordalErrorEnabled );
538 h->SetVarParameter ( h_data.myMinSizeVar.toLatin1().constData(), "SetMinSize");
539 h->SetMinSize ( h_data.myMinSize );
540 if ( mySurfaceCurvature )
541 h->SetUseSurfaceCurvature( h_data.mySurfaceCurvature );
543 h->SetFuseEdges ( h_data.myFuseEdges );
544 h->SetMeshSizeFile ( h_data.myMeshSizeFile.toUtf8().constData() );
548 // NETGENPlugin::NETGENPlugin_Hypothesis_2D_var h_2d =
549 // NETGENPlugin::NETGENPlugin_Hypothesis_2D::_narrow( h );
550 // if ( !h_2d->_is_nil() )
551 // h_2d->SetQuadAllowed( h_data.myAllowQuadrangles );
552 if ( myAllowQuadrangles )
553 h->SetQuadAllowed( h_data.myAllowQuadrangles );
557 NETGENPlugin::NETGENPlugin_RemesherHypothesis_2D_var rh =
558 NETGENPlugin::NETGENPlugin_RemesherHypothesis_2D::_narrow( h );
559 if ( !rh->_is_nil() )
561 rh->SetVarParameter( h_data.myRidgeAngleVar.toLatin1().constData(), "SetRidgeAngle");
562 rh->SetRidgeAngle ( h_data.myRidgeAngle );
565 for ( QMapIterator<QString,QString> i(myLocalSizeMap); i.hasNext(); )
568 const QString& entry = i.key();
569 const QString& localSize = i.value();
570 if (localSize == "__TO_DELETE__")
572 h->UnsetLocalSizeOnEntry(entry.toLatin1().constData());
576 h->SetLocalSizeOnEntry(entry.toLatin1().constData(), localSize.toDouble());
580 catch(const SALOME::SALOME_Exception& ex)
582 SalomeApp_Tools::QtCatchCorbaException(ex);
588 bool NETGENPluginGUI_HypothesisCreator::readParamsFromWidgets( NetgenHypothesisData& h_data ) const
590 h_data.myName = myName ? myName->text() : "";
591 h_data.myMaxSize = myMaxSize->value();
592 h_data.myMaxSizeVar = myMaxSize->text();
593 h_data.myMinSize = myMinSize->value();
594 h_data.myMinSizeVar = myMinSize->text();
596 h_data.mySecondOrder = mySecondOrder->isChecked();
598 h_data.myOptimize = myOptimize->isChecked();
599 h_data.myFineness = myFineness->currentIndex();
600 h_data.myGrowthRate = myGrowthRate->value();
601 if ( myNbSegPerEdge )
602 h_data.myNbSegPerEdge = myNbSegPerEdge->value();
603 if ( myNbSegPerRadius )
604 h_data.myNbSegPerRadius = myNbSegPerRadius->value();
606 h_data.myGrowthRateVar = myGrowthRate->text();
607 if ( myNbSegPerEdge )
608 h_data.myNbSegPerEdgeVar = myNbSegPerEdge->text();
609 if ( myNbSegPerRadius )
610 h_data.myNbSegPerRadiusVar = myNbSegPerRadius->text();
611 if ( myChordalError )
613 h_data.myChordalErrorVar = myChordalError->text();
614 h_data.myChordalError = myChordalError->value();
615 h_data.myChordalErrorEnabled = myChordalError->isEnabled();
619 h_data.myRidgeAngleVar = myRidgeAngle->text();
620 h_data.myRidgeAngle = myRidgeAngle->value();
623 if ( myAllowQuadrangles )
624 h_data.myAllowQuadrangles = myAllowQuadrangles->isChecked();
626 if ( mySurfaceCurvature )
627 h_data.mySurfaceCurvature = mySurfaceCurvature->isChecked();
630 h_data.myFuseEdges = myFuseEdges->isChecked();
632 if ( myLocalSizeTable )
634 NETGENPluginGUI_HypothesisCreator* that = (NETGENPluginGUI_HypothesisCreator*)this;
635 int nbRows = myLocalSizeTable->rowCount();
636 for(int row=0 ; row < nbRows ; row++)
638 QString entry = myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN)->text();
639 QString localSize = myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN)->text().trimmed();
640 that->myLocalSizeMap[entry] = localSize;
642 h_data.myMeshSizeFile = myMeshSizeFile->text();
647 void NETGENPluginGUI_HypothesisCreator::onChordalErrorEnabled()
649 myChordalError->setEnabled( myChordalErrorEnabled->isChecked() );
652 void NETGENPluginGUI_HypothesisCreator::onSurfaceCurvatureChanged()
654 bool isSurfaceCurvature = (mySurfaceCurvature ? mySurfaceCurvature->isChecked() : true);
655 bool isCustom = (myFineness->currentIndex() == UserDefined);
656 //myFineness->setEnabled(isSurfaceCurvature);
657 myGrowthRate->setEnabled(isCustom);
658 if ( myNbSegPerEdge )
659 myNbSegPerEdge->setEnabled(isCustom && isSurfaceCurvature);
660 if ( myNbSegPerRadius )
661 myNbSegPerRadius->setEnabled(isCustom && isSurfaceCurvature);
662 // if ( myChordalError )
664 // myChordalError->setEnabled( isSurfaceCurvature );
665 // myChordalErrorEnabled->setEnabled( isSurfaceCurvature );
669 void NETGENPluginGUI_HypothesisCreator::onFinenessChanged()
671 bool isCustom = (myFineness->currentIndex() == UserDefined);
673 myGrowthRate->setEnabled(isCustom);
674 if ( myNbSegPerEdge )
675 myNbSegPerEdge->setEnabled(isCustom);
676 if ( myNbSegPerRadius )
677 myNbSegPerRadius->setEnabled(isCustom);
681 double aGrowthRate, aNbSegPerEdge, aNbSegPerRadius;
683 switch ( myFineness->currentIndex() )
693 aNbSegPerRadius = 1.5;
713 myGrowthRate->setValue( aGrowthRate );
714 if ( myNbSegPerEdge )
715 myNbSegPerEdge->setValue( aNbSegPerEdge );
716 if ( myNbSegPerRadius )
717 myNbSegPerRadius->setValue( aNbSegPerRadius );
721 void NETGENPluginGUI_HypothesisCreator::onAddLocalSizeOnVertex()
723 addLocalSizeOnShape(TopAbs_VERTEX);
726 void NETGENPluginGUI_HypothesisCreator::onAddLocalSizeOnEdge()
728 addLocalSizeOnShape(TopAbs_EDGE);
731 void NETGENPluginGUI_HypothesisCreator::onAddLocalSizeOnFace()
733 addLocalSizeOnShape(TopAbs_FACE);
736 void NETGENPluginGUI_HypothesisCreator::onAddLocalSizeOnSolid()
738 addLocalSizeOnShape(TopAbs_SOLID);
741 void NETGENPluginGUI_HypothesisCreator::addLocalSizeOnShape(TopAbs_ShapeEnum typeShapeAsked)
743 NETGENPlugin::NETGENPlugin_Hypothesis_var h = NETGENPlugin::NETGENPlugin_Hypothesis::_narrow(initParamsHypothesis());
744 GeomSelectionTools* geomSelectionTools = getGeomSelectionTools();
745 LightApp_SelectionMgr* mySel = geomSelectionTools->selectionMgr();
746 SALOME_ListIO ListSelectedObjects;
747 mySel->selectedObjects(ListSelectedObjects, NULL, false );
748 SALOME_ListIteratorOfListIO Object_It(ListSelectedObjects);
749 for ( ; Object_It.More() ; Object_It.Next())
751 Handle(SALOME_InteractiveObject) anObject = Object_It.Value();
752 std::string entry = geomSelectionTools->getEntryOfObject(anObject);
753 std::string shapeName = anObject->getName();
754 TopAbs_ShapeEnum shapeType = geomSelectionTools->entryToShapeType(entry);
755 if (shapeType == TopAbs_SHAPE)
757 // E.A. if shapeType == TopAbs_SHAPE, it is NOT a TopoDS_Shape !!!
761 if(shapeType != typeShapeAsked)
766 myLocalSizeTable->setFocus();
767 QString shapeEntry = QString::fromStdString(entry);
768 if (myLocalSizeMap.contains(shapeEntry) &&
769 myLocalSizeMap[shapeEntry] != "__TO_DELETE__")
772 double phySize = h->GetMaxSize();
773 std::ostringstream oss;
776 localSize = QString::fromStdString(oss.str());
778 int row = myLocalSizeTable->rowCount() ;
779 myLocalSizeTable->setRowCount(row+1);
780 myLocalSizeTable->setItem(row, LSZ_ENTRY_COLUMN, new QTableWidgetItem(shapeEntry));
781 myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN )->setFlags(0);
782 myLocalSizeTable->setItem(row, LSZ_NAME_COLUMN, new QTableWidgetItem(QString::fromStdString(shapeName)));
783 myLocalSizeTable->item(row, LSZ_NAME_COLUMN )->setFlags(0);
784 myLocalSizeTable->setItem(row, LSZ_LOCALSIZE_COLUMN, new QTableWidgetItem(localSize));
785 myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN )->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsEnabled);
786 myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN);
787 myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
788 myLocalSizeTable->clearSelection();
789 myLocalSizeTable->scrollToItem( myLocalSizeTable->item( row, LSZ_LOCALSIZE_COLUMN ) );
794 void NETGENPluginGUI_HypothesisCreator::onRemoveLocalSizeOnShape()
796 QList<int> selectedRows;
797 QList<QTableWidgetItem*> selected = myLocalSizeTable->selectedItems();
798 QTableWidgetItem* item;
800 foreach(item, selected) {
802 if (!selectedRows.contains(row))
803 selectedRows.append( row );
805 qSort( selectedRows );
806 QListIterator<int> it( selectedRows );
808 while (it.hasPrevious())
811 QString entry = myLocalSizeTable->item(row,LSZ_ENTRY_COLUMN)->text();
812 if (myLocalSizeMap.contains(entry))
814 myLocalSizeMap[entry] = "__TO_DELETE__";
816 myLocalSizeTable->removeRow(row );
818 myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN);
819 myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
822 void NETGENPluginGUI_HypothesisCreator::onSetLocalSize(int row,int col)
824 if (col == LSZ_LOCALSIZE_COLUMN) {
825 QString entry = myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN)->text();
826 QString localSize = myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN)->text().trimmed();
827 myLocalSizeMap[entry] = localSize;
828 myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
832 void NETGENPluginGUI_HypothesisCreator::onSetSizeFile()
834 QString dir = SUIT_FileDlg::getFileName( dlg(), QString(),
835 QStringList() << tr( "ALL_FILES_FILTER" ) + " (*)");
836 myMeshSizeFile->setText( dir );
839 GeomSelectionTools* NETGENPluginGUI_HypothesisCreator::getGeomSelectionTools()
841 if (myGeomSelectionTools == NULL) {
842 delete myGeomSelectionTools;
843 myGeomSelectionTools = new GeomSelectionTools();
845 return myGeomSelectionTools;
848 QString NETGENPluginGUI_HypothesisCreator::caption() const
850 return tr( myIs2D ? "NETGEN_2D_TITLE" : "NETGEN_3D_TITLE");
853 QPixmap NETGENPluginGUI_HypothesisCreator::icon() const
855 QString hypIconName = tr( myIs2D ?
856 "ICON_DLG_NETGEN_PARAMETERS_2D" :
857 "ICON_DLG_NETGEN_PARAMETERS");
858 return SUIT_Session::session()->resourceMgr()->loadPixmap( "NETGENPlugin", hypIconName );
861 QString NETGENPluginGUI_HypothesisCreator::type() const
863 return tr( myIs2D ? "NETGEN_2D_HYPOTHESIS" : "NETGEN_3D_HYPOTHESIS");
866 QString NETGENPluginGUI_HypothesisCreator::helpPage() const
868 return "netgen_2d_3d_hypo_page.html";