1 // Copyright (C) 2007-2013 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
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_Session.h>
38 #include <SUIT_ResourceMgr.h>
40 #include <SalomeApp_Tools.h>
41 #include <LightApp_SelectionMgr.h>
42 #include <SALOME_ListIteratorOfListIO.hxx>
52 #include <QTableWidget>
53 #include <QHeaderView>
54 #include <QPushButton>
87 NETGENPluginGUI_HypothesisCreator::NETGENPluginGUI_HypothesisCreator( const QString& theHypType )
88 : SMESHGUI_GenericHypothesisCreator( theHypType )
90 myGeomSelectionTools = NULL;
91 myLocalSizeMap.clear();
92 myIs2D = ( theHypType.startsWith("NETGEN_Parameters_2D"));
93 myIsONLY = ( theHypType == "NETGEN_Parameters_2D_ONLY" ||
94 theHypType == "NETGEN_Parameters_3D");
97 NETGENPluginGUI_HypothesisCreator::~NETGENPluginGUI_HypothesisCreator()
101 bool NETGENPluginGUI_HypothesisCreator::checkParams(QString& msg) const
103 NetgenHypothesisData data_old, data_new;
104 readParamsFromHypo( data_old );
105 readParamsFromWidgets( data_new );
106 bool res = storeParamsToHypo( data_new );
107 //storeParamsToHypo( data_old ); -- issue 0021364: Dump of netgen parameters has duplicate lines
109 res = myMaxSize->isValid(msg,true) && res;
110 res = myMinSize->isValid(msg,true) && res;
111 res = myGrowthRate->isValid(msg,true) && res; ;
112 if ( myNbSegPerEdge )
113 res = myNbSegPerEdge->isValid(msg,true) && res;
114 if ( myNbSegPerRadius )
115 res = myNbSegPerRadius->isValid(msg,true) && res;
117 if ( !res ) // -- issue 0021364: Dump of netgen parameters has duplicate lines
118 storeParamsToHypo( data_old );
123 QFrame* NETGENPluginGUI_HypothesisCreator::buildFrame()
125 QFrame* fr = new QFrame( 0 );
126 fr->setObjectName( "myframe" );
127 QVBoxLayout* lay = new QVBoxLayout( fr );
129 lay->setSpacing( 0 );
131 QTabWidget* tab = new QTabWidget( fr );
132 tab->setTabShape( QTabWidget::Rounded );
133 tab->setTabPosition( QTabWidget::North );
134 lay->addWidget( tab );
135 QWidget* GroupC1 = new QWidget();
136 tab->insertTab( STD_TAB, GroupC1, tr( "SMESH_ARGUMENTS" ) );
138 QGridLayout* aGroupLayout = new QGridLayout( GroupC1 );
139 aGroupLayout->setSpacing( 6 );
140 aGroupLayout->setMargin( 11 );
146 aGroupLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), GroupC1 ), row, 0 );
147 myName = new QLineEdit( GroupC1 );
148 myName->setMinimumWidth(160);
149 aGroupLayout->addWidget( myName, row, 1 );
153 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_MAX_SIZE" ), GroupC1 ), row, 0 );
154 myMaxSize = new SMESHGUI_SpinBox( GroupC1 );
155 myMaxSize->RangeStepAndValidator( 1e-07, 1e+06, 10., "length_precision" );
156 aGroupLayout->addWidget( myMaxSize, row, 1 );
159 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_MIN_SIZE" ), GroupC1 ), row, 0 );
160 myMinSize = new SMESHGUI_SpinBox( GroupC1 );
161 myMinSize->RangeStepAndValidator( 0.0, 1e+06, 10., "length_precision" );
162 aGroupLayout->addWidget( myMinSize, row, 1 );
168 mySecondOrder = new QCheckBox( tr( "NETGEN_SECOND_ORDER" ), GroupC1 );
169 aGroupLayout->addWidget( mySecondOrder, row, 0, 1, 2 );
173 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_FINENESS" ), GroupC1 ), row, 0 );
174 myFineness = new QComboBox( GroupC1 );
176 types << tr( "NETGEN_VERYCOARSE" ) << tr( "NETGEN_COARSE" ) << tr( "NETGEN_MODERATE" ) <<
177 tr( "NETGEN_FINE" ) << tr( "NETGEN_VERYFINE" ) << tr( "NETGEN_CUSTOM" );
178 myFineness->addItems( types );
179 aGroupLayout->addWidget( myFineness, row, 1 );
180 connect( myFineness, SIGNAL( activated( int ) ), this, SLOT( onFinenessChanged() ) );
183 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_GROWTH_RATE" ), GroupC1 ), row, 0 );
184 myGrowthRate = new SMESHGUI_SpinBox( GroupC1 );
185 myGrowthRate->RangeStepAndValidator( .0001, 10., .1, "parametric_precision" );
186 aGroupLayout->addWidget( myGrowthRate, row, 1 );
190 myNbSegPerRadius = 0;
193 const double VALUE_MAX = 1.0e+6;
195 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_SEG_PER_EDGE" ), GroupC1 ), row, 0 );
196 myNbSegPerEdge = new SMESHGUI_SpinBox( GroupC1 );
197 myNbSegPerEdge->RangeStepAndValidator( .2, VALUE_MAX, .1, "parametric_precision" );
198 aGroupLayout->addWidget( myNbSegPerEdge, row, 1 );
201 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_SEG_PER_RADIUS" ), GroupC1 ), row, 0 );
202 myNbSegPerRadius = new SMESHGUI_SpinBox( GroupC1 );
203 myNbSegPerRadius->RangeStepAndValidator( .2, VALUE_MAX, .1, "parametric_precision" );
204 aGroupLayout->addWidget( myNbSegPerRadius, row, 1 );
208 mySurfaceCurvature = 0;
209 if ( myIs2D || !myIsONLY )
211 mySurfaceCurvature = new QCheckBox( tr( "NETGEN_SURFACE_CURVATURE" ), GroupC1 );
212 aGroupLayout->addWidget( mySurfaceCurvature, row, 0, 1, 2 );
213 connect( mySurfaceCurvature, SIGNAL( stateChanged( int ) ), this, SLOT( onSurfaceCurvatureChanged() ) );
217 myAllowQuadrangles = 0;
218 if ( myIs2D || !myIsONLY ) // disable only for NETGEN 3D
220 myAllowQuadrangles = new QCheckBox( tr( "NETGEN_ALLOW_QUADRANGLES" ), GroupC1 );
221 aGroupLayout->addWidget( myAllowQuadrangles, row, 0, 1, 2 );
225 myOptimize = new QCheckBox( tr( "NETGEN_OPTIMIZE" ), GroupC1 );
226 aGroupLayout->addWidget( myOptimize, row, 0, 1, 2 );
232 myFuseEdges = new QCheckBox( tr( "NETGEN_FUSE_EDGES" ), GroupC1 );
233 aGroupLayout->addWidget( myFuseEdges, row, 0, 1, 2 );
237 myLocalSizeTable = 0;
240 QWidget* localSizeGroup = new QWidget();
241 QGridLayout* localSizeLayout = new QGridLayout(localSizeGroup);
243 myLocalSizeTable = new QTableWidget(0, LSZ_NB_COLUMNS, localSizeGroup);
244 localSizeLayout->addWidget(myLocalSizeTable, 1, 0, 8, 1);
245 QStringList localSizeHeaders;
246 localSizeHeaders << tr( "LSZ_ENTRY_COLUMN" )<< tr( "LSZ_NAME_COLUMN" ) << tr( "LSZ_LOCALSIZE_COLUMN" );
247 myLocalSizeTable->setHorizontalHeaderLabels(localSizeHeaders);
248 myLocalSizeTable->horizontalHeader()->hideSection(LSZ_ENTRY_COLUMN);
249 myLocalSizeTable->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
250 myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN);
251 myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
252 myLocalSizeTable->setAlternatingRowColors(true);
253 myLocalSizeTable->verticalHeader()->hide();
255 QPushButton* addVertexButton = new QPushButton(tr("NETGEN_LSZ_VERTEX"), localSizeGroup);
256 localSizeLayout->addWidget(addVertexButton, LSZ_VERTEX_BTN, 1, 1, 1);
257 QPushButton* addEdgeButton = new QPushButton(tr("NETGEN_LSZ_EDGE"), localSizeGroup);
258 localSizeLayout->addWidget(addEdgeButton, LSZ_EDGE_BTN, 1, 1, 1);
259 QPushButton* addFaceButton = new QPushButton(tr("NETGEN_LSZ_FACE"), localSizeGroup);
260 localSizeLayout->addWidget(addFaceButton, LSZ_FACE_BTN, 1, 1, 1);
262 QFrame *line2 = new QFrame(localSizeGroup);
263 line2->setFrameShape(QFrame::HLine);
264 line2->setFrameShadow(QFrame::Sunken);
265 localSizeLayout->addWidget(line2, LSZ_SEPARATOR2, 1, 1, 1);
267 QPushButton* removeButton = new QPushButton(tr("NETGEN_LSZ_REMOVE"), localSizeGroup);
268 localSizeLayout->addWidget(removeButton, LSZ_REMOVE_BTN, 1, 1, 1);
270 connect( addVertexButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnVertex()));
271 connect( addEdgeButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnEdge()));
272 connect( addFaceButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnFace()));
273 connect( removeButton, SIGNAL(clicked()), this, SLOT(onRemoveLocalSizeOnShape()));
274 connect( myLocalSizeTable, SIGNAL(cellChanged(int, int)), this, SLOT(onSetLocalSize(int, int)));
276 tab->insertTab(LSZ_TAB, localSizeGroup, tr("NETGEN_LOCAL_SIZE"));
281 void NETGENPluginGUI_HypothesisCreator::retrieveParams() const
283 NetgenHypothesisData data;
284 readParamsFromHypo( data );
287 myName->setText( data.myName );
288 if(data.myMaxSizeVar.isEmpty())
289 myMaxSize->setValue( data.myMaxSize );
291 myMaxSize->setText( data.myMaxSizeVar );
293 if(data.myMinSizeVar.isEmpty())
294 myMinSize->setValue( data.myMinSize );
296 myMinSize->setText( data.myMinSizeVar );
299 mySecondOrder->setChecked( data.mySecondOrder );
301 myOptimize->setChecked( data.myOptimize );
302 myFineness->setCurrentIndex( data.myFineness );
304 if(data.myGrowthRateVar.isEmpty())
305 myGrowthRate->setValue( data.myGrowthRate );
307 myGrowthRate->setText( data.myGrowthRateVar );
309 if ( myNbSegPerEdge )
311 if(data.myNbSegPerEdgeVar.isEmpty())
312 myNbSegPerEdge->setValue( data.myNbSegPerEdge );
314 myNbSegPerEdge->setText( data.myNbSegPerEdgeVar );
316 if ( myNbSegPerRadius )
318 if(data.myNbSegPerRadiusVar.isEmpty())
319 myNbSegPerRadius->setValue( data.myNbSegPerRadius );
321 myNbSegPerRadius->setText( data.myNbSegPerRadiusVar );
323 if (myAllowQuadrangles)
324 myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
326 if (mySurfaceCurvature)
327 mySurfaceCurvature->setChecked( data.mySurfaceCurvature );
330 myFuseEdges->setChecked( data.myFuseEdges );
333 bool isCustom = (myFineness->currentIndex() == UserDefined);
334 bool isSurfaceCurvature = (mySurfaceCurvature ? mySurfaceCurvature->checkState() == Qt::Checked : true);
335 myFineness->setEnabled(isSurfaceCurvature);
336 myGrowthRate->setEnabled(isCustom && isSurfaceCurvature);
337 if ( myNbSegPerEdge )
338 myNbSegPerEdge->setEnabled(isCustom && isSurfaceCurvature);
339 if ( myNbSegPerRadius )
340 myNbSegPerRadius->setEnabled(isCustom && isSurfaceCurvature);
342 if ( myLocalSizeTable )
344 NETGENPluginGUI_HypothesisCreator* that = (NETGENPluginGUI_HypothesisCreator*)this;
345 QMapIterator<QString, QString> i(myLocalSizeMap);
346 GeomSelectionTools* geomSelectionTools = that->getGeomSelectionTools();
347 while (i.hasNext()) {
349 const QString entry = i.key();
350 std::string shapeName = geomSelectionTools->getNameFromEntry(entry.toStdString());
351 const QString localSize = i.value();
352 int row = myLocalSizeTable->rowCount();
353 myLocalSizeTable->setRowCount(row+1);
354 myLocalSizeTable->setItem(row, LSZ_ENTRY_COLUMN, new QTableWidgetItem(entry));
355 myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN)->setFlags(0);
356 myLocalSizeTable->setItem(row, LSZ_NAME_COLUMN, new QTableWidgetItem(QString::fromStdString(shapeName)));
357 myLocalSizeTable->item(row, LSZ_NAME_COLUMN)->setFlags(0);
358 myLocalSizeTable->setItem(row, LSZ_LOCALSIZE_COLUMN, new QTableWidgetItem(localSize));
359 myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN)->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsEnabled);
361 myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN);
362 myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
366 QString NETGENPluginGUI_HypothesisCreator::storeParams() const
368 NetgenHypothesisData data;
369 readParamsFromWidgets( data );
370 storeParamsToHypo( data );
372 QString valStr = tr("NETGEN_MAX_SIZE") + " = " + QString::number( data.myMaxSize ) + "; ";
373 valStr += tr("NETGEN_MIN_SIZE") + " = " + QString::number( data.myMinSize ) + "; ";
374 if ( data.mySecondOrder )
375 valStr += tr("NETGEN_SECOND_ORDER") + "; ";
376 if ( data.myOptimize )
377 valStr += tr("NETGEN_OPTIMIZE") + "; ";
378 valStr += myFineness->currentText() + "(" + QString::number( data.myGrowthRate ) + ", " +
379 QString::number( data.myNbSegPerEdge ) + ", " +
380 QString::number( data.myNbSegPerRadius ) + ")";
382 if ( myIs2D && data.myAllowQuadrangles )
383 valStr += "; " + tr("NETGEN_ALLOW_QUADRANGLES");
385 if ( data.mySurfaceCurvature )
386 valStr += "; " + tr("NETGEN_SURFACE_CURVATURE");
388 if ( data.myFuseEdges )
389 valStr += "; " + tr("NETGEN_FUSE_EDGES");
394 bool NETGENPluginGUI_HypothesisCreator::readParamsFromHypo( NetgenHypothesisData& h_data ) const
396 NETGENPlugin::NETGENPlugin_Hypothesis_var h =
397 NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( initParamsHypothesis() );
399 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
400 h_data.myName = isCreation() && data ? data->Label : "";
402 h_data.myMaxSize = h->GetMaxSize();
403 h_data.myMaxSizeVar = getVariableName("SetMaxSize");
404 h_data.mySecondOrder = h->GetSecondOrder();
405 h_data.myOptimize = h->GetOptimize();
407 h_data.myFineness = (int) h->GetFineness();
408 h_data.myGrowthRate = h->GetGrowthRate();
409 h_data.myGrowthRateVar = getVariableName("SetGrowthRate");
410 h_data.myNbSegPerEdge = h->GetNbSegPerEdge();
411 h_data.myNbSegPerEdgeVar = getVariableName("SetNbSegPerEdge");
412 h_data.myNbSegPerRadius = h->GetNbSegPerRadius();
413 h_data.myNbSegPerRadiusVar = getVariableName("SetNbSegPerRadius");
414 h_data.myMinSize = h->GetMinSize();
415 h_data.myMinSizeVar = getVariableName("SetMinSize");
416 h_data.mySurfaceCurvature = h->GetUseSurfaceCurvature();
417 h_data.myFuseEdges = h->GetFuseEdges();
421 NETGENPlugin::NETGENPlugin_Hypothesis_var h =
422 NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( initParamsHypothesis() );
425 h_data.myAllowQuadrangles = h->GetQuadAllowed();
428 NETGENPluginGUI_HypothesisCreator* that = (NETGENPluginGUI_HypothesisCreator*)this;
429 NETGENPlugin::string_array_var myEntries = h->GetLocalSizeEntries();
430 for ( int i=0 ; i<myEntries->length() ; i++ )
432 QString entry = myEntries[i].in();
433 double val = h->GetLocalSizeOnEntry(entry.toStdString().c_str());
434 std::ostringstream tmp;
436 QString valstring = QString::fromStdString(tmp.str());
437 if (myLocalSizeMap.contains(entry))
439 if (myLocalSizeMap[entry] == "__TO_DELETE__")
444 that->myLocalSizeMap[entry] = valstring;
450 bool NETGENPluginGUI_HypothesisCreator::storeParamsToHypo( const NetgenHypothesisData& h_data ) const
452 NETGENPlugin::NETGENPlugin_Hypothesis_var h =
453 NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( hypothesis() );
459 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().data() );
460 h->SetVarParameter( h_data.myMaxSizeVar.toLatin1().constData(), "SetMaxSize");
461 h->SetMaxSize ( h_data.myMaxSize );
462 h->SetSecondOrder ( h_data.mySecondOrder );
463 h->SetOptimize ( h_data.myOptimize );
464 int fineness = h_data.myFineness;
465 h->SetFineness ( fineness );
467 if( fineness==UserDefined )
469 h->SetVarParameter ( h_data.myGrowthRateVar.toLatin1().constData(), "SetGrowthRate");
470 h->SetGrowthRate ( h_data.myGrowthRate );
471 h->SetVarParameter ( h_data.myNbSegPerEdgeVar.toLatin1().constData(), "SetNbSegPerEdge");
472 h->SetNbSegPerEdge ( h_data.myNbSegPerEdge );
473 h->SetVarParameter ( h_data.myNbSegPerRadiusVar.toLatin1().constData(), "SetNbSegPerRadius");
474 h->SetNbSegPerRadius( h_data.myNbSegPerRadius );
476 h->SetVarParameter ( h_data.myMinSizeVar.toLatin1().constData(), "SetMinSize");
477 h->SetMinSize ( h_data.myMinSize );
478 h->SetUseSurfaceCurvature( h_data.mySurfaceCurvature );
479 h->SetFuseEdges ( h_data.myFuseEdges );
483 // NETGENPlugin::NETGENPlugin_Hypothesis_2D_var h_2d =
484 // NETGENPlugin::NETGENPlugin_Hypothesis_2D::_narrow( h );
486 // if ( !h_2d->_is_nil() )
487 // h_2d->SetQuadAllowed( h_data.myAllowQuadrangles );
488 h->SetQuadAllowed( h_data.myAllowQuadrangles );
491 QMapIterator<QString,QString> i(myLocalSizeMap);
492 while (i.hasNext()) {
494 const QString entry = i.key();
495 const QString localSize = i.value();
496 if (localSize == "__TO_DELETE__")
498 h->UnsetLocalSizeOnEntry(entry.toLatin1().constData());
502 std::istringstream tmp(localSize.toLatin1().constData());
505 h->SetLocalSizeOnEntry(entry.toLatin1().constData(), val);
509 catch(const SALOME::SALOME_Exception& ex)
511 SalomeApp_Tools::QtCatchCorbaException(ex);
517 bool NETGENPluginGUI_HypothesisCreator::readParamsFromWidgets( NetgenHypothesisData& h_data ) const
519 h_data.myName = myName ? myName->text() : "";
520 h_data.myMaxSize = myMaxSize->value();
521 h_data.myMaxSizeVar = myMaxSize->text();
522 h_data.myMinSize = myMinSize->value();
523 h_data.myMinSizeVar = myMinSize->text();
525 h_data.mySecondOrder = mySecondOrder->isChecked();
527 h_data.myOptimize = myOptimize->isChecked();
528 h_data.myFineness = myFineness->currentIndex();
529 h_data.myGrowthRate = myGrowthRate->value();
530 if ( myNbSegPerEdge )
531 h_data.myNbSegPerEdge = myNbSegPerEdge->value();
532 if ( myNbSegPerRadius )
533 h_data.myNbSegPerRadius = myNbSegPerRadius->value();
535 h_data.myGrowthRateVar = myGrowthRate->text();
536 if ( myNbSegPerEdge )
537 h_data.myNbSegPerEdgeVar = myNbSegPerEdge->text();
538 if ( myNbSegPerRadius )
539 h_data.myNbSegPerRadiusVar = myNbSegPerRadius->text();
542 if ( myAllowQuadrangles )
543 h_data.myAllowQuadrangles = myAllowQuadrangles->isChecked();
545 if ( mySurfaceCurvature )
546 h_data.mySurfaceCurvature = mySurfaceCurvature->isChecked();
549 h_data.myFuseEdges = myFuseEdges->isChecked();
551 if ( myLocalSizeTable )
553 NETGENPluginGUI_HypothesisCreator* that = (NETGENPluginGUI_HypothesisCreator*)this;
554 int nbRows = myLocalSizeTable->rowCount();
555 for(int row=0 ; row < nbRows ; row++)
557 QString entry = myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN)->text();
558 QString localSize = myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN)->text().trimmed();
559 that->myLocalSizeMap[entry] = localSize;
565 void NETGENPluginGUI_HypothesisCreator::onSurfaceCurvatureChanged()
567 bool isSurfaceCurvature = (mySurfaceCurvature ? mySurfaceCurvature->isChecked() : true);
568 bool isCustom = (myFineness->currentIndex() == UserDefined);
569 myGrowthRate->setEnabled(isCustom);
570 if ( myNbSegPerEdge )
571 myNbSegPerEdge->setEnabled(isCustom && isSurfaceCurvature);
572 if ( myNbSegPerRadius )
573 myNbSegPerRadius->setEnabled(isCustom && isSurfaceCurvature);
576 void NETGENPluginGUI_HypothesisCreator::onFinenessChanged()
578 bool isCustom = (myFineness->currentIndex() == UserDefined);
580 myGrowthRate->setEnabled(isCustom);
581 if ( myNbSegPerEdge )
582 myNbSegPerEdge->setEnabled(isCustom);
583 if ( myNbSegPerRadius )
584 myNbSegPerRadius->setEnabled(isCustom);
588 double aGrowthRate, aNbSegPerEdge, aNbSegPerRadius;
590 switch ( myFineness->currentIndex() )
600 aNbSegPerRadius = 1.5;
620 myGrowthRate->setValue( aGrowthRate );
621 if ( myNbSegPerEdge )
622 myNbSegPerEdge->setValue( aNbSegPerEdge );
623 if ( myNbSegPerRadius )
624 myNbSegPerRadius->setValue( aNbSegPerRadius );
628 void NETGENPluginGUI_HypothesisCreator::onAddLocalSizeOnVertex()
630 addLocalSizeOnShape(TopAbs_VERTEX);
633 void NETGENPluginGUI_HypothesisCreator::onAddLocalSizeOnEdge()
635 addLocalSizeOnShape(TopAbs_EDGE);
638 void NETGENPluginGUI_HypothesisCreator::onAddLocalSizeOnFace()
640 addLocalSizeOnShape(TopAbs_FACE);
643 void NETGENPluginGUI_HypothesisCreator::addLocalSizeOnShape(TopAbs_ShapeEnum typeShapeAsked)
645 NETGENPlugin::NETGENPlugin_Hypothesis_var h = NETGENPlugin::NETGENPlugin_Hypothesis::_narrow(initParamsHypothesis());
646 GeomSelectionTools* geomSelectionTools = getGeomSelectionTools();
647 LightApp_SelectionMgr* mySel = geomSelectionTools->selectionMgr();
648 SALOME_ListIO ListSelectedObjects;
649 mySel->selectedObjects(ListSelectedObjects, NULL, false );
650 SALOME_ListIteratorOfListIO Object_It(ListSelectedObjects);
651 for (Object_It ; Object_It.More() ; Object_It.Next())
653 Handle(SALOME_InteractiveObject) anObject = Object_It.Value();
654 std::string entry, shapeName;
655 entry = geomSelectionTools->getEntryOfObject(anObject);
656 shapeName = anObject->getName();
657 TopAbs_ShapeEnum shapeType;
658 shapeType = geomSelectionTools->entryToShapeType(entry);
659 if (shapeType == TopAbs_SHAPE)
661 // E.A. if shapeType == TopAbs_SHAPE, it is NOT a TopoDS_Shape !!!
665 if(shapeType != typeShapeAsked)
670 myLocalSizeTable->setFocus();
672 shapeEntry = QString::fromStdString(entry);
673 if (myLocalSizeMap.contains(shapeEntry))
675 if (myLocalSizeMap[shapeEntry] != "__TO_DELETE__")
680 double phySize = h->GetMaxSize();
681 std::ostringstream oss;
684 localSize = QString::fromStdString(oss.str());
686 int row = myLocalSizeTable->rowCount() ;
687 myLocalSizeTable->setRowCount(row+1);
688 myLocalSizeTable->setItem(row, LSZ_ENTRY_COLUMN, new QTableWidgetItem(shapeEntry));
689 myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN )->setFlags(0);
690 myLocalSizeTable->setItem(row, LSZ_NAME_COLUMN, new QTableWidgetItem(QString::fromStdString(shapeName)));
691 myLocalSizeTable->item(row, LSZ_NAME_COLUMN )->setFlags(0);
692 myLocalSizeTable->setItem(row, LSZ_LOCALSIZE_COLUMN, new QTableWidgetItem(localSize));
693 myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN )->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsEnabled);
694 myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN);
695 myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
696 myLocalSizeTable->clearSelection();
697 myLocalSizeTable->scrollToItem( myLocalSizeTable->item( row, LSZ_LOCALSIZE_COLUMN ) );
702 void NETGENPluginGUI_HypothesisCreator::onRemoveLocalSizeOnShape()
704 QList<int> selectedRows;
705 QList<QTableWidgetItem*> selected = myLocalSizeTable->selectedItems();
706 QTableWidgetItem* item;
708 foreach(item, selected) {
710 if (!selectedRows.contains(row))
711 selectedRows.append( row );
713 qSort( selectedRows );
714 QListIterator<int> it( selectedRows );
716 while (it.hasPrevious())
719 QString entry = myLocalSizeTable->item(row,LSZ_ENTRY_COLUMN)->text();
720 if (myLocalSizeMap.contains(entry))
722 myLocalSizeMap[entry] = "__TO_DELETE__";
724 myLocalSizeTable->removeRow(row );
726 myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN);
727 myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
730 void NETGENPluginGUI_HypothesisCreator::onSetLocalSize(int row,int col)
732 if (col == LSZ_LOCALSIZE_COLUMN) {
733 QString entry = myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN)->text();
734 QString localSize = myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN)->text().trimmed();
735 myLocalSizeMap[entry] = localSize;
736 myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
740 GeomSelectionTools* NETGENPluginGUI_HypothesisCreator::getGeomSelectionTools()
742 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
743 if (myGeomSelectionTools == NULL || myGeomSelectionTools->getMyStudy() != aStudy) {
744 delete myGeomSelectionTools;
745 myGeomSelectionTools = new GeomSelectionTools(aStudy);
747 return myGeomSelectionTools;
750 QString NETGENPluginGUI_HypothesisCreator::caption() const
752 return tr( QString( "NETGEN_%1_TITLE" ).arg(myIs2D?QString("2D"):QString("3D")).toLatin1().data() );
755 QPixmap NETGENPluginGUI_HypothesisCreator::icon() const
757 QString hypIconName = tr( QString("ICON_DLG_NETGEN_PARAMETERS%1").arg(myIs2D?QString("_2D"):QString("")).toLatin1().data() );
758 return SUIT_Session::session()->resourceMgr()->loadPixmap( "NETGENPlugin", hypIconName );
761 QString NETGENPluginGUI_HypothesisCreator::type() const
763 return tr( QString( "NETGEN_%1_HYPOTHESIS" ).arg(myIs2D?QString("2D"):QString("3D")).toLatin1().data() );
766 QString NETGENPluginGUI_HypothesisCreator::helpPage() const
768 return "netgen_2d_3d_hypo_page.html";