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_Session.h>
38 #include <SUIT_ResourceMgr.h>
40 #include <SalomeApp_Tools.h>
41 #include <LightApp_SelectionMgr.h>
42 #include <SALOME_ListIO.hxx>
52 #include <QTableWidget>
53 #include <QHeaderView>
54 #include <QPushButton>
88 NETGENPluginGUI_HypothesisCreator::NETGENPluginGUI_HypothesisCreator( const QString& theHypType )
89 : SMESHGUI_GenericHypothesisCreator( theHypType )
91 myGeomSelectionTools = NULL;
92 myLocalSizeMap.clear();
93 myIs2D = ( theHypType.startsWith("NETGEN_Parameters_2D"));
94 myIsONLY = ( theHypType == "NETGEN_Parameters_2D_ONLY" ||
95 theHypType == "NETGEN_Parameters_3D");
98 NETGENPluginGUI_HypothesisCreator::~NETGENPluginGUI_HypothesisCreator()
102 bool NETGENPluginGUI_HypothesisCreator::checkParams(QString& msg) const
104 NetgenHypothesisData data_old, data_new;
105 readParamsFromHypo( data_old );
106 readParamsFromWidgets( data_new );
107 bool res = storeParamsToHypo( data_new );
108 //storeParamsToHypo( data_old ); -- issue 0021364: Dump of netgen parameters has duplicate lines
110 res = myMaxSize->isValid(msg,true) && res;
111 res = myMinSize->isValid(msg,true) && res;
112 res = myGrowthRate->isValid(msg,true) && res; ;
113 if ( myNbSegPerEdge )
114 res = myNbSegPerEdge->isValid(msg,true) && res;
115 if ( myNbSegPerRadius )
116 res = myNbSegPerRadius->isValid(msg,true) && res;
118 if ( !res ) // -- issue 0021364: Dump of netgen parameters has duplicate lines
119 storeParamsToHypo( data_old );
124 QFrame* NETGENPluginGUI_HypothesisCreator::buildFrame()
126 QFrame* fr = new QFrame( 0 );
127 fr->setObjectName( "myframe" );
128 QVBoxLayout* lay = new QVBoxLayout( fr );
130 lay->setSpacing( 0 );
132 QTabWidget* tab = new QTabWidget( fr );
133 tab->setTabShape( QTabWidget::Rounded );
134 tab->setTabPosition( QTabWidget::North );
135 lay->addWidget( tab );
136 QWidget* GroupC1 = new QWidget();
137 tab->insertTab( STD_TAB, GroupC1, tr( "SMESH_ARGUMENTS" ) );
139 QGridLayout* aGroupLayout = new QGridLayout( GroupC1 );
140 aGroupLayout->setSpacing( 6 );
141 aGroupLayout->setMargin( 11 );
147 aGroupLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), GroupC1 ), row, 0 );
148 myName = new QLineEdit( GroupC1 );
149 myName->setMinimumWidth(160);
150 aGroupLayout->addWidget( myName, row, 1 );
154 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_MAX_SIZE" ), GroupC1 ), row, 0 );
155 myMaxSize = new SMESHGUI_SpinBox( GroupC1 );
156 myMaxSize->RangeStepAndValidator( 1e-07, 1e+06, 10., "length_precision" );
157 aGroupLayout->addWidget( myMaxSize, row, 1 );
160 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_MIN_SIZE" ), GroupC1 ), row, 0 );
161 myMinSize = new SMESHGUI_SpinBox( GroupC1 );
162 myMinSize->RangeStepAndValidator( 0.0, 1e+06, 10., "length_precision" );
163 aGroupLayout->addWidget( myMinSize, row, 1 );
169 mySecondOrder = new QCheckBox( tr( "NETGEN_SECOND_ORDER" ), GroupC1 );
170 aGroupLayout->addWidget( mySecondOrder, row, 0, 1, 2 );
174 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_FINENESS" ), GroupC1 ), row, 0 );
175 myFineness = new QComboBox( GroupC1 );
177 types << tr( "NETGEN_VERYCOARSE" ) << tr( "NETGEN_COARSE" ) << tr( "NETGEN_MODERATE" ) <<
178 tr( "NETGEN_FINE" ) << tr( "NETGEN_VERYFINE" ) << tr( "NETGEN_CUSTOM" );
179 myFineness->addItems( types );
180 aGroupLayout->addWidget( myFineness, row, 1 );
181 connect( myFineness, SIGNAL( activated( int ) ), this, SLOT( onFinenessChanged() ) );
184 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_GROWTH_RATE" ), GroupC1 ), row, 0 );
185 myGrowthRate = new SMESHGUI_SpinBox( GroupC1 );
186 myGrowthRate->RangeStepAndValidator( .0001, 10., .1, "parametric_precision" );
187 aGroupLayout->addWidget( myGrowthRate, row, 1 );
191 myNbSegPerRadius = 0;
194 const double VALUE_MAX = 1.0e+6;
196 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_SEG_PER_EDGE" ), GroupC1 ), row, 0 );
197 myNbSegPerEdge = new SMESHGUI_SpinBox( GroupC1 );
198 myNbSegPerEdge->RangeStepAndValidator( .2, VALUE_MAX, .1, "parametric_precision" );
199 aGroupLayout->addWidget( myNbSegPerEdge, row, 1 );
202 aGroupLayout->addWidget( new QLabel( tr( "NETGEN_SEG_PER_RADIUS" ), GroupC1 ), row, 0 );
203 myNbSegPerRadius = new SMESHGUI_SpinBox( GroupC1 );
204 myNbSegPerRadius->RangeStepAndValidator( .2, VALUE_MAX, .1, "parametric_precision" );
205 aGroupLayout->addWidget( myNbSegPerRadius, row, 1 );
209 mySurfaceCurvature = 0;
210 if ( myIs2D || !myIsONLY )
212 mySurfaceCurvature = new QCheckBox( tr( "NETGEN_SURFACE_CURVATURE" ), GroupC1 );
213 aGroupLayout->addWidget( mySurfaceCurvature, row, 0, 1, 2 );
214 connect( mySurfaceCurvature, SIGNAL( stateChanged( int ) ), this, SLOT( onSurfaceCurvatureChanged() ) );
218 myAllowQuadrangles = 0;
219 if ( myIs2D || !myIsONLY ) // disable only for NETGEN 3D
221 myAllowQuadrangles = new QCheckBox( tr( "NETGEN_ALLOW_QUADRANGLES" ), GroupC1 );
222 aGroupLayout->addWidget( myAllowQuadrangles, row, 0, 1, 2 );
226 myOptimize = new QCheckBox( tr( "NETGEN_OPTIMIZE" ), GroupC1 );
227 aGroupLayout->addWidget( myOptimize, row, 0, 1, 2 );
233 myFuseEdges = new QCheckBox( tr( "NETGEN_FUSE_EDGES" ), GroupC1 );
234 aGroupLayout->addWidget( myFuseEdges, row, 0, 1, 2 );
238 myLocalSizeTable = 0;
241 QWidget* localSizeGroup = new QWidget();
242 QGridLayout* localSizeLayout = new QGridLayout(localSizeGroup);
244 myLocalSizeTable = new QTableWidget(0, LSZ_NB_COLUMNS, localSizeGroup);
245 localSizeLayout->addWidget(myLocalSizeTable, 1, 0, 8, 1);
246 QStringList localSizeHeaders;
247 localSizeHeaders << tr( "LSZ_ENTRY_COLUMN" )<< tr( "LSZ_NAME_COLUMN" ) << tr( "LSZ_LOCALSIZE_COLUMN" );
248 myLocalSizeTable->setHorizontalHeaderLabels(localSizeHeaders);
249 myLocalSizeTable->horizontalHeader()->hideSection(LSZ_ENTRY_COLUMN);
250 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
251 myLocalSizeTable->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
253 myLocalSizeTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
255 myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN);
256 myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
257 myLocalSizeTable->setAlternatingRowColors(true);
258 myLocalSizeTable->verticalHeader()->hide();
260 QPushButton* addVertexButton = new QPushButton(tr("NETGEN_LSZ_VERTEX"), localSizeGroup);
261 localSizeLayout->addWidget(addVertexButton, LSZ_VERTEX_BTN, 1, 1, 1);
262 QPushButton* addEdgeButton = new QPushButton(tr("NETGEN_LSZ_EDGE"), localSizeGroup);
263 localSizeLayout->addWidget(addEdgeButton, LSZ_EDGE_BTN, 1, 1, 1);
264 QPushButton* addFaceButton = new QPushButton(tr("NETGEN_LSZ_FACE"), localSizeGroup);
265 localSizeLayout->addWidget(addFaceButton, LSZ_FACE_BTN, 1, 1, 1);
266 QPushButton* addSolidButton = new QPushButton(tr("NETGEN_LSZ_SOLID"), localSizeGroup);
267 localSizeLayout->addWidget(addSolidButton, LSZ_SOLID_BTN, 1, 1, 1);
269 QFrame *line2 = new QFrame(localSizeGroup);
270 line2->setFrameShape(QFrame::HLine);
271 line2->setFrameShadow(QFrame::Sunken);
272 localSizeLayout->addWidget(line2, LSZ_SEPARATOR2, 1, 1, 1);
274 QPushButton* removeButton = new QPushButton(tr("NETGEN_LSZ_REMOVE"), localSizeGroup);
275 localSizeLayout->addWidget(removeButton, LSZ_REMOVE_BTN, 1, 1, 1);
277 connect( addVertexButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnVertex()));
278 connect( addEdgeButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnEdge()));
279 connect( addFaceButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnFace()));
280 connect( addSolidButton, SIGNAL(clicked()), this, SLOT(onAddLocalSizeOnSolid()));
281 connect( removeButton, SIGNAL(clicked()), this, SLOT(onRemoveLocalSizeOnShape()));
282 connect( myLocalSizeTable, SIGNAL(cellChanged(int, int)), this, SLOT(onSetLocalSize(int, int)));
284 tab->insertTab(LSZ_TAB, localSizeGroup, tr("NETGEN_LOCAL_SIZE"));
289 void NETGENPluginGUI_HypothesisCreator::retrieveParams() const
291 NetgenHypothesisData data;
292 readParamsFromHypo( data );
295 myName->setText( data.myName );
296 if(data.myMaxSizeVar.isEmpty())
297 myMaxSize->setValue( data.myMaxSize );
299 myMaxSize->setText( data.myMaxSizeVar );
301 if(data.myMinSizeVar.isEmpty())
302 myMinSize->setValue( data.myMinSize );
304 myMinSize->setText( data.myMinSizeVar );
307 mySecondOrder->setChecked( data.mySecondOrder );
309 myOptimize->setChecked( data.myOptimize );
310 myFineness->setCurrentIndex( data.myFineness );
312 if(data.myGrowthRateVar.isEmpty())
313 myGrowthRate->setValue( data.myGrowthRate );
315 myGrowthRate->setText( data.myGrowthRateVar );
317 if ( myNbSegPerEdge )
319 if(data.myNbSegPerEdgeVar.isEmpty())
320 myNbSegPerEdge->setValue( data.myNbSegPerEdge );
322 myNbSegPerEdge->setText( data.myNbSegPerEdgeVar );
324 if ( myNbSegPerRadius )
326 if(data.myNbSegPerRadiusVar.isEmpty())
327 myNbSegPerRadius->setValue( data.myNbSegPerRadius );
329 myNbSegPerRadius->setText( data.myNbSegPerRadiusVar );
331 if (myAllowQuadrangles)
332 myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
334 if (mySurfaceCurvature)
335 mySurfaceCurvature->setChecked( data.mySurfaceCurvature );
338 myFuseEdges->setChecked( data.myFuseEdges );
341 ((NETGENPluginGUI_HypothesisCreator*) this )-> onSurfaceCurvatureChanged();
343 if ( myLocalSizeTable )
345 NETGENPluginGUI_HypothesisCreator* that = (NETGENPluginGUI_HypothesisCreator*)this;
346 QMapIterator<QString, QString> i(myLocalSizeMap);
347 GeomSelectionTools* geomSelectionTools = that->getGeomSelectionTools();
348 while (i.hasNext()) {
350 const QString entry = i.key();
351 std::string shapeName = geomSelectionTools->getNameFromEntry(entry.toStdString());
352 const QString localSize = i.value();
353 int row = myLocalSizeTable->rowCount();
354 myLocalSizeTable->setRowCount(row+1);
355 myLocalSizeTable->setItem(row, LSZ_ENTRY_COLUMN, new QTableWidgetItem(entry));
356 myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN)->setFlags(0);
357 myLocalSizeTable->setItem(row, LSZ_NAME_COLUMN, new QTableWidgetItem(QString::fromStdString(shapeName)));
358 myLocalSizeTable->item(row, LSZ_NAME_COLUMN)->setFlags(0);
359 myLocalSizeTable->setItem(row, LSZ_LOCALSIZE_COLUMN, new QTableWidgetItem(localSize));
360 myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN)->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsEnabled);
362 myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN);
363 myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
367 QString NETGENPluginGUI_HypothesisCreator::storeParams() const
369 NetgenHypothesisData data;
370 readParamsFromWidgets( data );
371 storeParamsToHypo( data );
373 QString valStr = tr("NETGEN_MAX_SIZE") + " = " + QString::number( data.myMaxSize ) + "; ";
374 valStr += tr("NETGEN_MIN_SIZE") + " = " + QString::number( data.myMinSize ) + "; ";
375 if ( data.mySecondOrder )
376 valStr += tr("NETGEN_SECOND_ORDER") + "; ";
377 if ( data.myOptimize )
378 valStr += tr("NETGEN_OPTIMIZE") + "; ";
379 valStr += myFineness->currentText() + "(" + QString::number( data.myGrowthRate ) + ", " +
380 QString::number( data.myNbSegPerEdge ) + ", " +
381 QString::number( data.myNbSegPerRadius ) + ")";
383 if ( myIs2D && data.myAllowQuadrangles )
384 valStr += "; " + tr("NETGEN_ALLOW_QUADRANGLES");
386 if ( data.mySurfaceCurvature )
387 valStr += "; " + tr("NETGEN_SURFACE_CURVATURE");
389 if ( data.myFuseEdges )
390 valStr += "; " + tr("NETGEN_FUSE_EDGES");
395 bool NETGENPluginGUI_HypothesisCreator::readParamsFromHypo( NetgenHypothesisData& h_data ) const
397 NETGENPlugin::NETGENPlugin_Hypothesis_var h =
398 NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( initParamsHypothesis() );
400 //HypothesisData* data = SMESH::GetHypothesisData( hypType() );
401 h_data.myName = isCreation() ? hypName() : "";
403 h_data.myMaxSize = h->GetMaxSize();
404 h_data.myMaxSizeVar = getVariableName("SetMaxSize");
405 h_data.mySecondOrder = h->GetSecondOrder();
406 h_data.myOptimize = h->GetOptimize();
408 h_data.myFineness = (int) h->GetFineness();
409 h_data.myGrowthRate = h->GetGrowthRate();
410 h_data.myGrowthRateVar = getVariableName("SetGrowthRate");
411 h_data.myNbSegPerEdge = h->GetNbSegPerEdge();
412 h_data.myNbSegPerEdgeVar = getVariableName("SetNbSegPerEdge");
413 h_data.myNbSegPerRadius = h->GetNbSegPerRadius();
414 h_data.myNbSegPerRadiusVar = getVariableName("SetNbSegPerRadius");
415 h_data.myMinSize = h->GetMinSize();
416 h_data.myMinSizeVar = getVariableName("SetMinSize");
417 h_data.mySurfaceCurvature = h->GetUseSurfaceCurvature();
418 h_data.myFuseEdges = h->GetFuseEdges();
422 NETGENPlugin::NETGENPlugin_Hypothesis_var h =
423 NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( initParamsHypothesis() );
426 h_data.myAllowQuadrangles = h->GetQuadAllowed();
429 NETGENPluginGUI_HypothesisCreator* that = (NETGENPluginGUI_HypothesisCreator*)this;
430 NETGENPlugin::string_array_var myEntries = h->GetLocalSizeEntries();
431 for ( size_t i = 0; i < myEntries->length(); i++ )
433 QString entry = myEntries[i].in();
434 double val = h->GetLocalSizeOnEntry(entry.toStdString().c_str());
435 std::ostringstream tmp;
437 QString valstring = QString::fromStdString(tmp.str());
438 if (myLocalSizeMap.contains(entry))
440 if (myLocalSizeMap[entry] == "__TO_DELETE__")
445 that->myLocalSizeMap[entry] = valstring;
451 bool NETGENPluginGUI_HypothesisCreator::storeParamsToHypo( const NetgenHypothesisData& h_data ) const
453 NETGENPlugin::NETGENPlugin_Hypothesis_var h =
454 NETGENPlugin::NETGENPlugin_Hypothesis::_narrow( hypothesis() );
460 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().data() );
461 h->SetVarParameter( h_data.myMaxSizeVar.toLatin1().constData(), "SetMaxSize");
462 h->SetMaxSize ( h_data.myMaxSize );
463 h->SetSecondOrder ( h_data.mySecondOrder );
464 h->SetOptimize ( h_data.myOptimize );
465 int fineness = h_data.myFineness;
466 h->SetFineness ( fineness );
468 if( fineness==UserDefined )
470 h->SetVarParameter ( h_data.myGrowthRateVar.toLatin1().constData(), "SetGrowthRate");
471 h->SetGrowthRate ( h_data.myGrowthRate );
472 h->SetVarParameter ( h_data.myNbSegPerEdgeVar.toLatin1().constData(), "SetNbSegPerEdge");
473 h->SetNbSegPerEdge ( h_data.myNbSegPerEdge );
474 h->SetVarParameter ( h_data.myNbSegPerRadiusVar.toLatin1().constData(), "SetNbSegPerRadius");
475 h->SetNbSegPerRadius( h_data.myNbSegPerRadius );
477 h->SetVarParameter ( h_data.myMinSizeVar.toLatin1().constData(), "SetMinSize");
478 h->SetMinSize ( h_data.myMinSize );
479 h->SetUseSurfaceCurvature( h_data.mySurfaceCurvature );
480 h->SetFuseEdges ( h_data.myFuseEdges );
484 // NETGENPlugin::NETGENPlugin_Hypothesis_2D_var h_2d =
485 // NETGENPlugin::NETGENPlugin_Hypothesis_2D::_narrow( h );
487 // if ( !h_2d->_is_nil() )
488 // h_2d->SetQuadAllowed( h_data.myAllowQuadrangles );
489 h->SetQuadAllowed( h_data.myAllowQuadrangles );
492 QMapIterator<QString,QString> i(myLocalSizeMap);
493 while (i.hasNext()) {
495 const QString entry = i.key();
496 const QString localSize = i.value();
497 if (localSize == "__TO_DELETE__")
499 h->UnsetLocalSizeOnEntry(entry.toLatin1().constData());
503 std::istringstream tmp(localSize.toLatin1().constData());
506 h->SetLocalSizeOnEntry(entry.toLatin1().constData(), val);
510 catch(const SALOME::SALOME_Exception& ex)
512 SalomeApp_Tools::QtCatchCorbaException(ex);
518 bool NETGENPluginGUI_HypothesisCreator::readParamsFromWidgets( NetgenHypothesisData& h_data ) const
520 h_data.myName = myName ? myName->text() : "";
521 h_data.myMaxSize = myMaxSize->value();
522 h_data.myMaxSizeVar = myMaxSize->text();
523 h_data.myMinSize = myMinSize->value();
524 h_data.myMinSizeVar = myMinSize->text();
526 h_data.mySecondOrder = mySecondOrder->isChecked();
528 h_data.myOptimize = myOptimize->isChecked();
529 h_data.myFineness = myFineness->currentIndex();
530 h_data.myGrowthRate = myGrowthRate->value();
531 if ( myNbSegPerEdge )
532 h_data.myNbSegPerEdge = myNbSegPerEdge->value();
533 if ( myNbSegPerRadius )
534 h_data.myNbSegPerRadius = myNbSegPerRadius->value();
536 h_data.myGrowthRateVar = myGrowthRate->text();
537 if ( myNbSegPerEdge )
538 h_data.myNbSegPerEdgeVar = myNbSegPerEdge->text();
539 if ( myNbSegPerRadius )
540 h_data.myNbSegPerRadiusVar = myNbSegPerRadius->text();
543 if ( myAllowQuadrangles )
544 h_data.myAllowQuadrangles = myAllowQuadrangles->isChecked();
546 if ( mySurfaceCurvature )
547 h_data.mySurfaceCurvature = mySurfaceCurvature->isChecked();
550 h_data.myFuseEdges = myFuseEdges->isChecked();
552 if ( myLocalSizeTable )
554 NETGENPluginGUI_HypothesisCreator* that = (NETGENPluginGUI_HypothesisCreator*)this;
555 int nbRows = myLocalSizeTable->rowCount();
556 for(int row=0 ; row < nbRows ; row++)
558 QString entry = myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN)->text();
559 QString localSize = myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN)->text().trimmed();
560 that->myLocalSizeMap[entry] = localSize;
566 void NETGENPluginGUI_HypothesisCreator::onSurfaceCurvatureChanged()
568 bool isSurfaceCurvature = (mySurfaceCurvature ? mySurfaceCurvature->isChecked() : true);
569 bool isCustom = (myFineness->currentIndex() == UserDefined);
570 //myFineness->setEnabled(isSurfaceCurvature);
571 myGrowthRate->setEnabled(isCustom);
572 if ( myNbSegPerEdge )
573 myNbSegPerEdge->setEnabled(isCustom && isSurfaceCurvature);
574 if ( myNbSegPerRadius )
575 myNbSegPerRadius->setEnabled(isCustom && isSurfaceCurvature);
578 void NETGENPluginGUI_HypothesisCreator::onFinenessChanged()
580 bool isCustom = (myFineness->currentIndex() == UserDefined);
582 myGrowthRate->setEnabled(isCustom);
583 if ( myNbSegPerEdge )
584 myNbSegPerEdge->setEnabled(isCustom);
585 if ( myNbSegPerRadius )
586 myNbSegPerRadius->setEnabled(isCustom);
590 double aGrowthRate, aNbSegPerEdge, aNbSegPerRadius;
592 switch ( myFineness->currentIndex() )
602 aNbSegPerRadius = 1.5;
622 myGrowthRate->setValue( aGrowthRate );
623 if ( myNbSegPerEdge )
624 myNbSegPerEdge->setValue( aNbSegPerEdge );
625 if ( myNbSegPerRadius )
626 myNbSegPerRadius->setValue( aNbSegPerRadius );
630 void NETGENPluginGUI_HypothesisCreator::onAddLocalSizeOnVertex()
632 addLocalSizeOnShape(TopAbs_VERTEX);
635 void NETGENPluginGUI_HypothesisCreator::onAddLocalSizeOnEdge()
637 addLocalSizeOnShape(TopAbs_EDGE);
640 void NETGENPluginGUI_HypothesisCreator::onAddLocalSizeOnFace()
642 addLocalSizeOnShape(TopAbs_FACE);
645 void NETGENPluginGUI_HypothesisCreator::onAddLocalSizeOnSolid()
647 addLocalSizeOnShape(TopAbs_SOLID);
650 void NETGENPluginGUI_HypothesisCreator::addLocalSizeOnShape(TopAbs_ShapeEnum typeShapeAsked)
652 NETGENPlugin::NETGENPlugin_Hypothesis_var h = NETGENPlugin::NETGENPlugin_Hypothesis::_narrow(initParamsHypothesis());
653 GeomSelectionTools* geomSelectionTools = getGeomSelectionTools();
654 LightApp_SelectionMgr* mySel = geomSelectionTools->selectionMgr();
655 SALOME_ListIO ListSelectedObjects;
656 mySel->selectedObjects(ListSelectedObjects, NULL, false );
657 SALOME_ListIteratorOfListIO Object_It(ListSelectedObjects);
658 for ( ; Object_It.More() ; Object_It.Next())
660 Handle(SALOME_InteractiveObject) anObject = Object_It.Value();
661 std::string entry, shapeName;
662 entry = geomSelectionTools->getEntryOfObject(anObject);
663 shapeName = anObject->getName();
664 TopAbs_ShapeEnum shapeType;
665 shapeType = geomSelectionTools->entryToShapeType(entry);
666 if (shapeType == TopAbs_SHAPE)
668 // E.A. if shapeType == TopAbs_SHAPE, it is NOT a TopoDS_Shape !!!
672 if(shapeType != typeShapeAsked)
677 myLocalSizeTable->setFocus();
679 shapeEntry = QString::fromStdString(entry);
680 if (myLocalSizeMap.contains(shapeEntry))
682 if (myLocalSizeMap[shapeEntry] != "__TO_DELETE__")
687 double phySize = h->GetMaxSize();
688 std::ostringstream oss;
691 localSize = QString::fromStdString(oss.str());
693 int row = myLocalSizeTable->rowCount() ;
694 myLocalSizeTable->setRowCount(row+1);
695 myLocalSizeTable->setItem(row, LSZ_ENTRY_COLUMN, new QTableWidgetItem(shapeEntry));
696 myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN )->setFlags(0);
697 myLocalSizeTable->setItem(row, LSZ_NAME_COLUMN, new QTableWidgetItem(QString::fromStdString(shapeName)));
698 myLocalSizeTable->item(row, LSZ_NAME_COLUMN )->setFlags(0);
699 myLocalSizeTable->setItem(row, LSZ_LOCALSIZE_COLUMN, new QTableWidgetItem(localSize));
700 myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN )->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsEnabled);
701 myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN);
702 myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
703 myLocalSizeTable->clearSelection();
704 myLocalSizeTable->scrollToItem( myLocalSizeTable->item( row, LSZ_LOCALSIZE_COLUMN ) );
709 void NETGENPluginGUI_HypothesisCreator::onRemoveLocalSizeOnShape()
711 QList<int> selectedRows;
712 QList<QTableWidgetItem*> selected = myLocalSizeTable->selectedItems();
713 QTableWidgetItem* item;
715 foreach(item, selected) {
717 if (!selectedRows.contains(row))
718 selectedRows.append( row );
720 qSort( selectedRows );
721 QListIterator<int> it( selectedRows );
723 while (it.hasPrevious())
726 QString entry = myLocalSizeTable->item(row,LSZ_ENTRY_COLUMN)->text();
727 if (myLocalSizeMap.contains(entry))
729 myLocalSizeMap[entry] = "__TO_DELETE__";
731 myLocalSizeTable->removeRow(row );
733 myLocalSizeTable->resizeColumnToContents(LSZ_NAME_COLUMN);
734 myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
737 void NETGENPluginGUI_HypothesisCreator::onSetLocalSize(int row,int col)
739 if (col == LSZ_LOCALSIZE_COLUMN) {
740 QString entry = myLocalSizeTable->item(row, LSZ_ENTRY_COLUMN)->text();
741 QString localSize = myLocalSizeTable->item(row, LSZ_LOCALSIZE_COLUMN)->text().trimmed();
742 myLocalSizeMap[entry] = localSize;
743 myLocalSizeTable->resizeColumnToContents(LSZ_LOCALSIZE_COLUMN);
747 GeomSelectionTools* NETGENPluginGUI_HypothesisCreator::getGeomSelectionTools()
749 _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
750 if (myGeomSelectionTools == NULL || myGeomSelectionTools->getMyStudy() != aStudy) {
751 delete myGeomSelectionTools;
752 myGeomSelectionTools = new GeomSelectionTools(aStudy);
754 return myGeomSelectionTools;
757 QString NETGENPluginGUI_HypothesisCreator::caption() const
759 return tr( QString( "NETGEN_%1_TITLE" ).arg(myIs2D?QString("2D"):QString("3D")).toLatin1().data() );
762 QPixmap NETGENPluginGUI_HypothesisCreator::icon() const
764 QString hypIconName = tr( QString("ICON_DLG_NETGEN_PARAMETERS%1").arg(myIs2D?QString("_2D"):QString("")).toLatin1().data() );
765 return SUIT_Session::session()->resourceMgr()->loadPixmap( "NETGENPlugin", hypIconName );
768 QString NETGENPluginGUI_HypothesisCreator::type() const
770 return tr( QString( "NETGEN_%1_HYPOTHESIS" ).arg(myIs2D?QString("2D"):QString("3D")).toLatin1().data() );
773 QString NETGENPluginGUI_HypothesisCreator::helpPage() const
775 return "netgen_2d_3d_hypo_page.html";