1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : StdMeshersGUI_LayerDistributionParamWdg.cxx
21 // Author : Open CASCADE S.A.S.
25 #include "StdMeshersGUI_LayerDistributionParamWdg.h"
28 #include <SMESHGUI_HypothesesUtils.h>
29 #include <SMESHGUI_Hypotheses.h>
31 // SALOME GUI includes
32 #include <SalomeApp_Tools.h>
35 #include <QPushButton>
39 #include <QHBoxLayout>
43 //================================================================================
45 * \brief Constructor initialized by filter
46 * \param f - object filter
48 //================================================================================
50 StdMeshersGUI_LayerDistributionParamWdg
51 ::StdMeshersGUI_LayerDistributionParamWdg(SMESH::SMESH_Hypothesis_ptr hyp,
52 const QString& theName,
54 QWidget(), myName(theName), myDlg( dlg )
62 //================================================================================
64 * \brief initialize fields with hypothesis
65 * \param hyp - hypothesis
67 //================================================================================
69 void StdMeshersGUI_LayerDistributionParamWdg::set(SMESH::SMESH_Hypothesis_ptr hyp)
71 myHyp = SMESH::SMESH_Hypothesis::_nil();
72 if ( !CORBA::is_nil( hyp )) {
73 myHyp = SMESH::SMESH_Hypothesis::_duplicate( hyp );
74 myEditButton->setEnabled( true );
75 myCreateButton->setText( tr("CHANGE_TYPE"));
76 myParamValue = hyp->GetName();
79 myEditButton->setEnabled( false );
80 myCreateButton->setText( tr("CREATE"));
85 //================================================================================
89 //================================================================================
91 StdMeshersGUI_LayerDistributionParamWdg::~StdMeshersGUI_LayerDistributionParamWdg()
95 //================================================================================
97 * \brief Create a leayout, initialize fields
99 //================================================================================
101 void StdMeshersGUI_LayerDistributionParamWdg::init()
103 QHBoxLayout* aHBox = new QHBoxLayout( this );
104 aHBox->setMargin( 0 );
105 aHBox->setSpacing( SPACING );
107 mySMESHGUI = SMESHGUI::GetSMESHGUI();
109 myCreateButton = new QPushButton( this );
110 myCreateButton->setObjectName( "createBut" );
112 myEditButton = new QPushButton( tr("EDIT"), this );
113 myEditButton->setObjectName( "editBut" );
115 myHypTypePopup = new QMenu( this );
117 // Add to pop-up hypotheses of "Regular_1D" algo
118 HypothesisData* algoData = SMESH::GetHypothesisData( "Regular_1D" );
119 myHypTypes = SMESH::GetAvailableHypotheses( false, 1 );
120 QStringList::const_iterator anIter = myHypTypes.begin();
121 for ( ; anIter != myHypTypes.end(); ++anIter )
123 HypothesisData* hypData = SMESH::GetHypothesisData( *anIter );
125 if ( SMESH::IsAvailableHypothesis( algoData, hypData->TypeName, bidon ))
126 myHypTypePopup->addAction( hypData->Label );
129 aHBox->addWidget( myCreateButton );
130 aHBox->addWidget( myEditButton );
133 connect( myCreateButton, SIGNAL(clicked()), SLOT(onCreate()));
134 connect( myEditButton, SIGNAL(clicked()), SLOT(onEdit()));
135 connect( myHypTypePopup, SIGNAL(triggered( QAction* ) ), SLOT( onHypTypePopup( QAction* ) ) );
138 //================================================================================
140 * \brief Create a new hyp of selected type
141 * \param int - selected type index
143 //================================================================================
145 void StdMeshersGUI_LayerDistributionParamWdg::onHypTypePopup( QAction* a )
147 SMESH::SMESH_Gen_var gen = mySMESHGUI->GetSMESHGen();
149 // avoid publishing a new 1D hyp
150 gen->SetCurrentStudy( SALOMEDS::Study::_nil() );
153 HypothesisData* aHypData = 0;
154 QStringList::const_iterator anIter = myHypTypes.begin();
156 for ( ; !aHypData && anIter != myHypTypes.end(); ++anIter )
158 HypothesisData* hypData = SMESH::GetHypothesisData( *anIter );
159 if ( a->text() == hypData->Label )
162 QString aServLib = aHypData->ServerLibName;
163 QString aHypType = aHypData->TypeName;
165 set( gen->CreateHypothesis(aHypType.toLatin1().data(), aServLib.toLatin1().data()));
167 catch (const SALOME::SALOME_Exception & S_ex) {
168 SalomeApp_Tools::QtCatchCorbaException(S_ex);
171 // restore current study
172 mySMESHGUI->GetSMESHGen();
177 //================================================================================
179 * \brief Show popup with available types
181 //================================================================================
183 void StdMeshersGUI_LayerDistributionParamWdg::onCreate()
185 myHypTypePopup->exec( QCursor::pos() );
188 //================================================================================
190 * \brief Edit hypothesis
192 //================================================================================
194 void StdMeshersGUI_LayerDistributionParamWdg::onEdit()
196 if ( myHyp->_is_nil() )
199 CORBA::String_var hypType = myHyp->GetName();
200 SMESHGUI_GenericHypothesisCreator*
201 editor = SMESH::GetHypothesisCreator( hypType.in() );
202 if ( !editor ) return;
204 if ( myDlg ) myDlg->hide();
207 QWidget* parent = this;
208 if ( myDlg ) parent = myDlg->parentWidget();
209 editor->edit( myHyp, myName, parent );
214 if ( myDlg ) myDlg->show();