1 // Copyright (C) 2007-2011 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 // File : StdMeshersGUI_LayerDistributionParamWdg.cxx
24 // Author : Open CASCADE S.A.S.
27 #include "StdMeshersGUI_LayerDistributionParamWdg.h"
30 #include <SMESHGUI_HypothesesUtils.h>
31 #include <SMESHGUI_Hypotheses.h>
33 // SALOME GUI includes
34 #include <SalomeApp_Tools.h>
37 #include <QPushButton>
41 #include <QHBoxLayout>
45 //================================================================================
47 * \brief Constructor initialized by filter
48 * \param f - object filter
50 //================================================================================
52 StdMeshersGUI_LayerDistributionParamWdg
53 ::StdMeshersGUI_LayerDistributionParamWdg(SMESH::SMESH_Hypothesis_ptr hyp,
54 const QString& theName,
56 QWidget(), myName(theName), myDlg( dlg )
64 //================================================================================
66 * \brief initialize fields with hypothesis
67 * \param hyp - hypothesis
69 //================================================================================
71 void StdMeshersGUI_LayerDistributionParamWdg::set(SMESH::SMESH_Hypothesis_ptr hyp)
73 myHyp = SMESH::SMESH_Hypothesis::_nil();
74 if ( !CORBA::is_nil( hyp )) {
75 myHyp = SMESH::SMESH_Hypothesis::_duplicate( hyp );
76 myEditButton->setEnabled( true );
77 myCreateButton->setText( tr("CHANGE_TYPE"));
78 myParamValue = hyp->GetName();
81 myEditButton->setEnabled( false );
82 myCreateButton->setText( tr("CREATE"));
87 //================================================================================
91 //================================================================================
93 StdMeshersGUI_LayerDistributionParamWdg::~StdMeshersGUI_LayerDistributionParamWdg()
97 //================================================================================
99 * \brief Create a leayout, initialize fields
101 //================================================================================
103 void StdMeshersGUI_LayerDistributionParamWdg::init()
105 QHBoxLayout* aHBox = new QHBoxLayout( this );
106 aHBox->setMargin( 0 );
107 aHBox->setSpacing( SPACING );
109 mySMESHGUI = SMESHGUI::GetSMESHGUI();
111 myCreateButton = new QPushButton( this );
112 myCreateButton->setObjectName( "createBut" );
114 myEditButton = new QPushButton( tr("EDIT"), this );
115 myEditButton->setObjectName( "editBut" );
117 myHypTypePopup = new QMenu( this );
119 // Add to pop-up hypotheses of "Regular_1D" algo
120 HypothesisData* algoData = SMESH::GetHypothesisData( "Regular_1D" );
121 myHypTypes = SMESH::GetAvailableHypotheses( false, 1 );
122 QStringList::const_iterator anIter = myHypTypes.begin();
123 for ( ; anIter != myHypTypes.end(); ++anIter )
125 HypothesisData* hypData = SMESH::GetHypothesisData( *anIter );
127 if ( SMESH::IsAvailableHypothesis( algoData, hypData->TypeName, bidon ))
128 myHypTypePopup->addAction( hypData->Label );
131 aHBox->addWidget( myCreateButton );
132 aHBox->addWidget( myEditButton );
135 connect( myCreateButton, SIGNAL(clicked()), SLOT(onCreate()));
136 connect( myEditButton, SIGNAL(clicked()), SLOT(onEdit()));
137 connect( myHypTypePopup, SIGNAL(triggered( QAction* ) ), SLOT( onHypTypePopup( QAction* ) ) );
140 //================================================================================
142 * \brief Create a new hyp of selected type
143 * \param int - selected type index
145 //================================================================================
147 void StdMeshersGUI_LayerDistributionParamWdg::onHypTypePopup( QAction* a )
149 SMESH::SMESH_Gen_var gen = mySMESHGUI->GetSMESHGen();
151 // avoid publishing a new 1D hyp
152 gen->SetCurrentStudy( SALOMEDS::Study::_nil() );
155 HypothesisData* aHypData = 0;
156 QStringList::const_iterator anIter = myHypTypes.begin();
158 for ( ; !aHypData && anIter != myHypTypes.end(); ++anIter )
160 HypothesisData* hypData = SMESH::GetHypothesisData( *anIter );
161 if ( a->text() == hypData->Label )
164 QString aServLib = aHypData->ServerLibName;
165 QString aHypType = aHypData->TypeName;
167 set( gen->CreateHypothesis(aHypType.toLatin1().data(), aServLib.toLatin1().data()));
169 catch (const SALOME::SALOME_Exception & S_ex) {
170 SalomeApp_Tools::QtCatchCorbaException(S_ex);
173 // restore current study
174 mySMESHGUI->GetSMESHGen();
179 //================================================================================
181 * \brief Show popup with available types
183 //================================================================================
185 void StdMeshersGUI_LayerDistributionParamWdg::onCreate()
187 myHypTypePopup->exec( QCursor::pos() );
190 //================================================================================
192 * \brief Edit hypothesis
194 //================================================================================
196 void StdMeshersGUI_LayerDistributionParamWdg::onEdit()
198 if ( myHyp->_is_nil() )
201 CORBA::String_var hypType = myHyp->GetName();
203 //SMESHGUI_GenericHypothesisCreator* editor = SMESH::GetHypothesisCreator(hypType.in());
204 SMESHGUI_GenericHypothesisCreator* editor = SMESH::GetHypothesisCreator(hypType.in());
205 if ( !editor ) return;
211 QWidget* parent = this;
213 parent = myDlg->parentWidget();
214 editor->edit( myHyp, myName, parent, this, SLOT( onEdited( int ) ) );
221 void StdMeshersGUI_LayerDistributionParamWdg::onEdited( int result )