1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : HexoticPluginGUI_HypothesisCreator.cxx
22 // Author : Lioka RAZAFINDRAZAKA (CEA)
25 #include "HexoticPluginGUI_HypothesisCreator.h"
26 #include "HexoticPluginGUI_Dlg.h"
28 #include <SMESHGUI_Utils.h>
29 #include <SMESHGUI_HypothesesUtils.h>
31 #include CORBA_SERVER_HEADER(HexoticPlugin_Algorithm)
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_FileDlg.h>
36 #include <SalomeApp_Tools.h>
37 #include <QtxIntSpinBox.h>
41 #include <QVBoxLayout>
42 #include <QGridLayout>
46 #include <QPushButton>
49 HexoticPluginGUI_HypothesisCreator::HexoticPluginGUI_HypothesisCreator( const QString& theHypType )
50 : SMESHGUI_GenericHypothesisCreator( theHypType ),
55 HexoticPluginGUI_HypothesisCreator::~HexoticPluginGUI_HypothesisCreator()
59 bool HexoticPluginGUI_HypothesisCreator::checkParams(QString& msg) const
62 HexoticHypothesisData data_old, data_new;
63 readParamsFromHypo( data_old );
64 readParamsFromWidgets( data_new );
66 bool res = storeParamsToHypo( data_new );
68 storeParamsToHypo( data_old );
72 res = data_new.myMinSize <= data_new.myMaxSize;
74 msg = tr(QString("Min size (%1) is higher than max size (%2)").arg(data_new.myMinSize).arg(data_new.myMaxSize).toStdString().c_str());
78 res = data_new.myHexesMinLevel == 0 || \
79 ( data_new.myHexesMinLevel != 0 && (data_new.myHexesMinLevel < data_new.myHexesMaxLevel) );
81 msg = tr(QString("Min hexes level (%1) is higher than max hexes level (%2)").arg(data_new.myHexesMinLevel).arg(data_new.myHexesMaxLevel).toStdString().c_str());
88 QFrame* HexoticPluginGUI_HypothesisCreator::buildFrame()
90 QFrame* fr = new QFrame( 0 );
91 QVBoxLayout* lay = new QVBoxLayout( fr );
95 QGroupBox* GroupC1 = new QGroupBox( tr( "SMESH_ARGUMENTS" ), fr );
96 lay->addWidget( GroupC1 );
98 QGridLayout* l = new QGridLayout( GroupC1 );
105 l->addWidget( new QLabel( tr( "SMESH_NAME" ), GroupC1 ), row, 0, 1, 1 );
106 myName = new QLineEdit( GroupC1 );
107 l->addWidget( myName, row++, 1, 1, 2 );
108 myName->setMinimumWidth( 150 );
111 HexoticPlugin::HexoticPlugin_Hypothesis_var h =
112 HexoticPlugin::HexoticPlugin_Hypothesis::_narrow( initParamsHypothesis() );
114 myStdWidget = new HexoticPluginGUI_StdWidget(GroupC1);
115 l->addWidget( myStdWidget, row++, 0, 1, 3 );
116 myStdWidget->onSdModeSelected(SD_MODE_4);
123 //=================================================================================
124 // function : resizeEvent [REDEFINED]
126 //=================================================================================
127 void HexoticPluginGUI_HypothesisCreator::resizeEvent(QResizeEvent */*event*/) {
128 QSize scaledSize = myStdWidget->imageSdMode.size();
129 scaledSize.scale(myStdWidget->sdModeLabel->size(), Qt::KeepAspectRatioByExpanding);
130 if (!myStdWidget->sdModeLabel->pixmap() || scaledSize != myStdWidget->sdModeLabel->pixmap()->size())
131 myStdWidget->sdModeLabel->setPixmap(myStdWidget->imageSdMode.scaled(myStdWidget->sdModeLabel->size(),
133 Qt::SmoothTransformation));
136 void HexoticPluginGUI_HypothesisCreator::retrieveParams() const
138 HexoticHypothesisData data;
139 readParamsFromHypo( data );
143 myName->setText( data.myName );
145 myStdWidget->myMinSize->setCleared(data.myMinSize == 0);
146 if (data.myMinSize == 0)
147 myStdWidget->myMinSize->setText("");
149 myStdWidget->myMinSize->setValue( data.myMinSize );
151 myStdWidget->myMaxSize->setCleared(data.myMaxSize == 0);
152 if (data.myMaxSize == 0)
153 myStdWidget->myMaxSize->setText("");
155 myStdWidget->myMaxSize->setValue( data.myMaxSize );
157 myStdWidget->myHexesMinLevel->setCleared(data.myHexesMinLevel == 0);
158 if (data.myHexesMinLevel == 0)
159 myStdWidget->myHexesMinLevel->setText("");
161 myStdWidget->myHexesMinLevel->setValue( data.myHexesMinLevel );
163 myStdWidget->myHexesMaxLevel->setCleared(data.myHexesMaxLevel == 0);
164 if (data.myHexesMaxLevel == 0)
165 myStdWidget->myHexesMaxLevel->setText("");
167 myStdWidget->myHexesMaxLevel->setValue( data.myHexesMaxLevel );
169 myStdWidget->myHexoticIgnoreRidges->setChecked( data.myHexoticIgnoreRidges );
170 myStdWidget->myHexoticInvalidElements->setChecked( data.myHexoticInvalidElements );
172 myStdWidget->myHexoticSharpAngleThreshold->setCleared(data.myHexoticSharpAngleThreshold == 0);
173 if (data.myHexoticSharpAngleThreshold == 0)
174 myStdWidget->myHexoticSharpAngleThreshold->setText("");
176 myStdWidget->myHexoticSharpAngleThreshold->setValue( data.myHexoticSharpAngleThreshold );
178 myStdWidget->myHexoticNbProc->setValue( data.myHexoticNbProc );
179 myStdWidget->myHexoticWorkingDir->setText( data.myHexoticWorkingDir );
181 myStdWidget->myHexoticVerbosity->setValue( data.myHexoticVerbosity );
183 myStdWidget->myHexoticMaxMemory->setValue( data.myHexoticMaxMemory );
185 myStdWidget->myHexoticSdMode->setCurrentIndex(data.myHexoticSdMode);
187 std::cout << "myStdWidget->myMinSize->value(): " << myStdWidget->myMinSize->value() << std::endl;
188 std::cout << "myStdWidget->myMaxSize->value(): " << myStdWidget->myMaxSize->value() << std::endl;
189 std::cout << "myStdWidget->myHexesMinLevel->value(): " << myStdWidget->myHexesMinLevel->value() << std::endl;
190 std::cout << "myStdWidget->myHexesMaxLevel->value(): " << myStdWidget->myHexesMaxLevel->value() << std::endl;
191 std::cout << "myStdWidget->myHexoticSharpAngleThreshold->value(): " << myStdWidget->myHexoticSharpAngleThreshold->value() << std::endl;
195 void HexoticPluginGUI_HypothesisCreator::printData( HexoticHypothesisData& data) const
198 valStr += tr("Hexotic_MIN_SIZE") + " = " + QString::number( data.myMinSize ) + "; ";
199 valStr += tr("Hexotic_MAX_SIZE") + " = " + QString::number( data.myMaxSize ) + "; ";
200 valStr += tr("Hexotic_HEXES_MIN_LEVEL") + " = " + QString::number( data.myHexesMinLevel ) + "; ";
201 valStr += tr("Hexotic_HEXES_MAX_LEVEL") + " = " + QString::number( data.myHexesMaxLevel ) + "; ";
202 valStr += tr("Hexotic_IGNORE_RIDGES") + " = " + QString::number( data.myHexoticIgnoreRidges ) + "; ";
203 valStr += tr("Hexotic_INVALID_ELEMENTS") + " = " + QString::number( data.myHexoticInvalidElements ) + "; ";
204 valStr += tr("Hexotic_SHARP_ANGLE_THRESHOLD") + " = " + QString::number( data.myHexoticSharpAngleThreshold ) + "; ";
205 valStr += tr("Hexotic_NB_PROC") + " = " + QString::number( data.myHexoticNbProc ) + "; ";
206 valStr += tr("Hexotic_WORKING_DIR") + " = " + data.myHexoticWorkingDir + "; ";
207 valStr += tr("Hexotic_VERBOSITY") + " = " + QString::number( data.myHexoticVerbosity ) + "; ";
208 valStr += tr("Hexotic_MAX_MEMORY") + " = " + QString::number( data.myHexoticMaxMemory ) + "; ";
209 valStr += tr("Hexotic_SD_MODE") + " = " + QString::number( data.myHexoticSdMode ) + "; ";
211 std::cout << "Data: " << valStr.toStdString() << std::endl;
214 QString HexoticPluginGUI_HypothesisCreator::storeParams() const
216 HexoticHypothesisData data;
217 readParamsFromWidgets( data );
218 storeParamsToHypo( data );
221 valStr += tr("Hexotic_MIN_SIZE") + " = " + QString::number( data.myMinSize ) + "; ";
222 valStr += tr("Hexotic_MAX_SIZE") + " = " + QString::number( data.myMaxSize ) + "; ";
223 valStr += tr("Hexotic_HEXES_MIN_LEVEL") + " = " + QString::number( data.myHexesMinLevel ) + "; ";
224 valStr += tr("Hexotic_HEXES_MAX_LEVEL") + " = " + QString::number( data.myHexesMaxLevel ) + "; ";
225 valStr += tr("Hexotic_IGNORE_RIDGES") + " = " + QString::number( data.myHexoticIgnoreRidges ) + "; ";
226 valStr += tr("Hexotic_INVALID_ELEMENTS") + " = " + QString::number( data.myHexoticInvalidElements ) + "; ";
227 valStr += tr("Hexotic_SHARP_ANGLE_THRESHOLD") + " = " + QString::number( data.myHexoticSharpAngleThreshold ) + "; ";
228 valStr += tr("Hexotic_NB_PROC") + " = " + QString::number( data.myHexoticNbProc ) + "; ";
229 valStr += tr("Hexotic_WORKING_DIR") + " = " + data.myHexoticWorkingDir + "; ";
230 valStr += tr("Hexotic_VERBOSITY") + " = " + QString::number( data.myHexoticVerbosity) + "; ";
231 valStr += tr("Hexotic_MAX_MEMORY") + " = " + QString::number( data.myHexoticMaxMemory ) + "; ";
232 valStr += tr("Hexotic_SD_MODE") + " = " + QString::number( data.myHexoticSdMode) + "; ";
234 // std::cout << "Data: " << valStr.toStdString() << std::endl;
239 bool HexoticPluginGUI_HypothesisCreator::readParamsFromHypo( HexoticHypothesisData& h_data ) const
241 HexoticPlugin::HexoticPlugin_Hypothesis_var h =
242 HexoticPlugin::HexoticPlugin_Hypothesis::_narrow( initParamsHypothesis() );
244 HypothesisData* data = SMESH::GetHypothesisData( hypType() );
245 h_data.myName = isCreation() && data ? data->Label : "";
246 h_data.myMinSize = h->GetMinSize();
247 h_data.myMaxSize = h->GetMaxSize();
248 h_data.myHexesMinLevel = h->GetHexesMinLevel();
249 h_data.myHexesMaxLevel = h->GetHexesMaxLevel();
250 h_data.myHexoticIgnoreRidges = h->GetHexoticIgnoreRidges();
251 h_data.myHexoticInvalidElements = h->GetHexoticInvalidElements();
252 h_data.myHexoticSharpAngleThreshold = h->GetHexoticSharpAngleThreshold();
253 h_data.myHexoticNbProc = h->GetHexoticNbProc();
254 h_data.myHexoticWorkingDir = h->GetHexoticWorkingDirectory();
255 h_data.myHexoticVerbosity = h->GetHexoticVerbosity();
256 h_data.myHexoticMaxMemory = h->GetHexoticMaxMemory();
257 h_data.myHexoticSdMode = h->GetHexoticSdMode()-1;
262 bool HexoticPluginGUI_HypothesisCreator::storeParamsToHypo( const HexoticHypothesisData& h_data ) const
264 HexoticPlugin::HexoticPlugin_Hypothesis_var h =
265 HexoticPlugin::HexoticPlugin_Hypothesis::_narrow( hypothesis() );
272 SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
274 h->SetMinSize( h_data.myMinSize );
275 h->SetMaxSize( h_data.myMaxSize );
276 h->SetHexesMinLevel( h_data.myHexesMinLevel );
277 h->SetHexesMaxLevel( h_data.myHexesMaxLevel );
278 h->SetHexoticIgnoreRidges( h_data.myHexoticIgnoreRidges );
279 h->SetHexoticInvalidElements( h_data.myHexoticInvalidElements );
280 h->SetHexoticSharpAngleThreshold( h_data.myHexoticSharpAngleThreshold );
281 h->SetHexoticNbProc( h_data.myHexoticNbProc );
282 h->SetHexoticWorkingDirectory( h_data.myHexoticWorkingDir.toLatin1().constData() );
283 h->SetHexoticVerbosity( h_data.myHexoticVerbosity );
284 h->SetHexoticMaxMemory( h_data.myHexoticMaxMemory );
285 h->SetHexoticSdMode( h_data.myHexoticSdMode+1 );
287 catch(const SALOME::SALOME_Exception& ex)
289 SalomeApp_Tools::QtCatchCorbaException(ex);
295 bool HexoticPluginGUI_HypothesisCreator::readParamsFromWidgets( HexoticHypothesisData& h_data ) const
297 h_data.myName = myName ? myName->text() : "";
299 h_data.myHexoticIgnoreRidges = myStdWidget->myHexoticIgnoreRidges->isChecked();
300 h_data.myHexoticInvalidElements = myStdWidget->myHexoticInvalidElements->isChecked();
302 h_data.myHexoticNbProc = myStdWidget->myHexoticNbProc->value();
303 h_data.myHexoticWorkingDir = myStdWidget->myHexoticWorkingDir->text();
304 h_data.myHexoticVerbosity = myStdWidget->myHexoticVerbosity->value();
305 h_data.myHexoticMaxMemory = myStdWidget->myHexoticMaxMemory->value();
306 h_data.myHexoticSdMode = myStdWidget->myHexoticSdMode->currentIndex();
308 h_data.myMinSize = myStdWidget->myMinSize->text().isEmpty() ? 0.0 : myStdWidget->myMinSize->value();
309 h_data.myMaxSize = myStdWidget->myMaxSize->text().isEmpty() ? 0.0 : myStdWidget->myMaxSize->value();
310 h_data.myHexesMinLevel = myStdWidget->myHexesMinLevel->text().isEmpty() ? 0 : myStdWidget->myHexesMinLevel->value();
311 h_data.myHexesMaxLevel = myStdWidget->myHexesMaxLevel->text().isEmpty() ? 0 : myStdWidget->myHexesMaxLevel->value();
312 h_data.myHexoticSharpAngleThreshold = myStdWidget->myHexoticSharpAngleThreshold->text().isEmpty() ? 0 : myStdWidget->myHexoticSharpAngleThreshold->value();
319 QString HexoticPluginGUI_HypothesisCreator::caption() const
321 return myIs3D ? tr( "Hexotic_3D_TITLE" ) : tr( "Hexotic_3D_TITLE" ); // ??? 3D/2D ???
324 QPixmap HexoticPluginGUI_HypothesisCreator::icon() const
326 QString hypIconName = myIs3D ? tr( "ICON_DLG_Hexotic_PARAMETERS" ) : tr( "ICON_DLG_Hexotic_PARAMETERS" );
327 return SUIT_Session::session()->resourceMgr()->loadPixmap( "HexoticPLUGIN", hypIconName );
330 QString HexoticPluginGUI_HypothesisCreator::type() const
332 return myIs3D ? tr( "Hexotic_3D_HYPOTHESIS" ) : tr( "Hexotic_3D_HYPOTHESIS" ); // ??? 3D/2D ???
335 QString HexoticPluginGUI_HypothesisCreator::helpPage() const
337 return "hexotic_hypo_page.html";