3 // Copyright (C) 2003 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
24 // File : StdMeshersGUI_LayerDistributionParamWdg.cxx
27 #include "StdMeshersGUI_LayerDistributionParamWdg.h"
29 #include <qpushbutton.h>
31 #include <qpopupmenu.h>
35 #include "SMESHGUI_Utils.h"
36 #include "SMESHGUI_HypothesesUtils.h"
37 #include "SMESHGUI_Hypotheses.h"
38 // #include "SUIT_ResourceMgr.h"
39 // #include "LightApp_SelectionMgr.h"
40 #include "SALOMEDSClient_SObject.hxx"
41 #include "SALOMEDS_Study.hxx"
42 #include "SalomeApp_Tools.h"
44 //================================================================================
46 * \brief Constructor initialized by filter
47 * \param f - object filter
49 //================================================================================
51 StdMeshersGUI_LayerDistributionParamWdg::StdMeshersGUI_LayerDistributionParamWdg
52 ( SMESH::SMESH_Hypothesis_ptr hyp,
53 QDialog* dlg ): QHGroupBox(), myDlg( dlg )
61 //================================================================================
63 * \brief initialize fields with hypothesis
64 * \param hyp - hypothesis
66 //================================================================================
68 void StdMeshersGUI_LayerDistributionParamWdg::set(SMESH::SMESH_Hypothesis_ptr hyp)
70 myHyp = SMESH::SMESH_Hypothesis::_nil();
71 if ( !CORBA::is_nil( hyp )) {
72 myHyp = SMESH::SMESH_Hypothesis::_duplicate( hyp );
73 myEditButton->setEnabled( true );
74 myCreateButton->setText( tr("CHANGE_TYPE"));
75 myParamValue = hyp->GetName();
78 myEditButton->setEnabled( false );
79 myCreateButton->setText( tr("CREATE"));
84 //================================================================================
88 //================================================================================
90 StdMeshersGUI_LayerDistributionParamWdg::~StdMeshersGUI_LayerDistributionParamWdg()
93 delete myHypTypePopup;
96 //================================================================================
98 * \brief Create a leayout, initialize fields
100 //================================================================================
102 void StdMeshersGUI_LayerDistributionParamWdg::init()
104 setFrameStyle(QFrame::NoFrame);
107 mySMESHGUI = SMESHGUI::GetSMESHGUI();
109 myCreateButton = new QPushButton( this, "createBut");
110 myEditButton = new QPushButton( tr("EDIT"), this, "createBut");
112 // SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
113 // QPixmap iconSlct ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
114 // mySelButton->setPixmap(iconSlct);
115 // mySelButton->setToggleButton( true );
117 myHypTypePopup = new QPopupMenu();
119 // Add to pop-up hypotheses of "Regular_1D" algo
120 myHypTypePopup->clear();
121 HypothesisData* algoData = SMESH::GetHypothesisData( "Regular_1D" );
122 myHypTypes = SMESH::GetAvailableHypotheses( false, 0 );
123 QStringList::const_iterator anIter = myHypTypes.begin();
124 for ( ; anIter != myHypTypes.end(); ++anIter )
126 HypothesisData* hypData = SMESH::GetHypothesisData( *anIter );
128 if ( SMESH::IsAvailableHypothesis( algoData, hypData->TypeName, bidon ))
129 myHypTypePopup->insertItem( hypData->Label );
132 connect( myCreateButton, SIGNAL(clicked()), SLOT(onCreate()));
133 connect( myEditButton, SIGNAL(clicked()), SLOT(onEdit()));
134 connect( myHypTypePopup, SIGNAL( activated( int ) ), SLOT( onHypTypePopup( int ) ) );
137 //================================================================================
139 * \brief Create a new hyp of selected type
140 * \param int - selected type index
142 //================================================================================
144 void StdMeshersGUI_LayerDistributionParamWdg::onHypTypePopup( int theIndex )
146 SMESH::SMESH_Gen_var gen = mySMESHGUI->GetSMESHGen();
148 // avoid publishing a new 1D hyp
149 gen->SetCurrentStudy( SALOMEDS::Study::_nil() );
152 HypothesisData* aHypData = 0;
153 QStringList::const_iterator anIter = myHypTypes.begin();
154 for ( ; !aHypData && anIter != myHypTypes.end(); ++anIter )
156 HypothesisData* hypData = SMESH::GetHypothesisData( *anIter );
157 if ( myHypTypePopup->text( theIndex ) == hypData->Label )
160 QString aServLib = aHypData->ServerLibName;
161 QString aHypType = aHypData->TypeName;
163 set( gen->CreateHypothesis(aHypType, aServLib));
165 catch (const SALOME::SALOME_Exception & S_ex) {
166 SalomeApp_Tools::QtCatchCorbaException(S_ex);
169 // restore current study
170 mySMESHGUI->GetSMESHGen();
175 //================================================================================
177 * \brief Show popup with available types
179 //================================================================================
181 void StdMeshersGUI_LayerDistributionParamWdg::onCreate()
183 myHypTypePopup->exec( QCursor::pos() );
186 //================================================================================
188 * \brief Edit hypothesis
190 //================================================================================
192 void StdMeshersGUI_LayerDistributionParamWdg::onEdit()
194 if ( myHyp->_is_nil() )
197 CORBA::String_var hypType = myHyp->GetName();
198 SMESHGUI_GenericHypothesisCreator*
199 editor = SMESH::GetHypothesisCreator( hypType.in() );
200 if ( !editor ) return;
202 if ( myDlg ) myDlg->hide();
205 QWidget* parent = this;
206 if ( myDlg ) parent = myDlg->parentWidget();
207 editor->edit( myHyp, parent );
212 if ( myDlg ) myDlg->show();