1 // Copyright (C) 2007-2008 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
22 // File : StdMeshersGUI_LayerDistributionParamWdg.cxx
23 // Author : Open CASCADE S.A.S.
26 #include "StdMeshersGUI_LayerDistributionParamWdg.h"
29 #include <SMESHGUI_HypothesesUtils.h>
30 #include <SMESHGUI_Hypotheses.h>
32 // SALOME GUI includes
33 #include <SalomeApp_Tools.h>
36 #include <QPushButton>
40 #include <QHBoxLayout>
44 //================================================================================
46 * \brief Constructor initialized by filter
47 * \param f - object filter
49 //================================================================================
51 StdMeshersGUI_LayerDistributionParamWdg
52 ::StdMeshersGUI_LayerDistributionParamWdg(SMESH::SMESH_Hypothesis_ptr hyp,
53 const QString& theName,
55 QWidget(), myName(theName), myDlg( dlg )
63 //================================================================================
65 * \brief initialize fields with hypothesis
66 * \param hyp - hypothesis
68 //================================================================================
70 void StdMeshersGUI_LayerDistributionParamWdg::set(SMESH::SMESH_Hypothesis_ptr hyp)
72 myHyp = SMESH::SMESH_Hypothesis::_nil();
73 if ( !CORBA::is_nil( hyp )) {
74 myHyp = SMESH::SMESH_Hypothesis::_duplicate( hyp );
75 myEditButton->setEnabled( true );
76 myCreateButton->setText( tr("CHANGE_TYPE"));
77 myParamValue = hyp->GetName();
80 myEditButton->setEnabled( false );
81 myCreateButton->setText( tr("CREATE"));
86 //================================================================================
90 //================================================================================
92 StdMeshersGUI_LayerDistributionParamWdg::~StdMeshersGUI_LayerDistributionParamWdg()
96 //================================================================================
98 * \brief Create a leayout, initialize fields
100 //================================================================================
102 void StdMeshersGUI_LayerDistributionParamWdg::init()
104 QHBoxLayout* aHBox = new QHBoxLayout( this );
105 aHBox->setMargin( 0 );
106 aHBox->setSpacing( SPACING );
108 mySMESHGUI = SMESHGUI::GetSMESHGUI();
110 myCreateButton = new QPushButton( this );
111 myCreateButton->setObjectName( "createBut" );
113 myEditButton = new QPushButton( tr("EDIT"), this );
114 myEditButton->setObjectName( "editBut" );
116 myHypTypePopup = new QMenu( this );
118 // Add to pop-up hypotheses of "Regular_1D" algo
119 HypothesisData* algoData = SMESH::GetHypothesisData( "Regular_1D" );
120 myHypTypes = SMESH::GetAvailableHypotheses( false, 1 );
121 QStringList::const_iterator anIter = myHypTypes.begin();
122 for ( ; anIter != myHypTypes.end(); ++anIter )
124 HypothesisData* hypData = SMESH::GetHypothesisData( *anIter );
126 if ( SMESH::IsAvailableHypothesis( algoData, hypData->TypeName, bidon ))
127 myHypTypePopup->addAction( hypData->Label );
130 aHBox->addWidget( myCreateButton );
131 aHBox->addWidget( myEditButton );
134 connect( myCreateButton, SIGNAL(clicked()), SLOT(onCreate()));
135 connect( myEditButton, SIGNAL(clicked()), SLOT(onEdit()));
136 connect( myHypTypePopup, SIGNAL(triggered( QAction* ) ), SLOT( onHypTypePopup( QAction* ) ) );
139 //================================================================================
141 * \brief Create a new hyp of selected type
142 * \param int - selected type index
144 //================================================================================
146 void StdMeshersGUI_LayerDistributionParamWdg::onHypTypePopup( QAction* a )
148 SMESH::SMESH_Gen_var gen = mySMESHGUI->GetSMESHGen();
150 // avoid publishing a new 1D hyp
151 gen->SetCurrentStudy( SALOMEDS::Study::_nil() );
154 HypothesisData* aHypData = 0;
155 QStringList::const_iterator anIter = myHypTypes.begin();
157 for ( ; !aHypData && anIter != myHypTypes.end(); ++anIter )
159 HypothesisData* hypData = SMESH::GetHypothesisData( *anIter );
160 if ( a->text() == hypData->Label )
163 QString aServLib = aHypData->ServerLibName;
164 QString aHypType = aHypData->TypeName;
166 set( gen->CreateHypothesis(aHypType.toLatin1().data(), aServLib.toLatin1().data()));
168 catch (const SALOME::SALOME_Exception & S_ex) {
169 SalomeApp_Tools::QtCatchCorbaException(S_ex);
172 // restore current study
173 mySMESHGUI->GetSMESHGen();
178 //================================================================================
180 * \brief Show popup with available types
182 //================================================================================
184 void StdMeshersGUI_LayerDistributionParamWdg::onCreate()
186 myHypTypePopup->exec( QCursor::pos() );
189 //================================================================================
191 * \brief Edit hypothesis
193 //================================================================================
195 void StdMeshersGUI_LayerDistributionParamWdg::onEdit()
197 if ( myHyp->_is_nil() )
200 CORBA::String_var hypType = myHyp->GetName();
202 //SMESHGUI_GenericHypothesisCreator* editor = SMESH::GetHypothesisCreator(hypType.in());
203 SMESH::HypothesisCreatorPtr editor = SMESH::GetHypothesisCreator(hypType.in());
204 if ( !editor ) return;
206 if ( myDlg ) myDlg->hide();
209 QWidget* parent = this;
210 if ( myDlg ) parent = myDlg->parentWidget();
211 editor->edit( myHyp, myName, parent );
216 if ( myDlg ) myDlg->show();