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
52 ::StdMeshersGUI_LayerDistributionParamWdg(SMESH::SMESH_Hypothesis_ptr hyp,
53 const QString& theName,
55 QHGroupBox(), 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()
95 delete myHypTypePopup;
98 //================================================================================
100 * \brief Create a leayout, initialize fields
102 //================================================================================
104 void StdMeshersGUI_LayerDistributionParamWdg::init()
106 setFrameStyle(QFrame::NoFrame);
109 mySMESHGUI = SMESHGUI::GetSMESHGUI();
111 myCreateButton = new QPushButton( this, "createBut");
112 myEditButton = new QPushButton( tr("EDIT"), this, "createBut");
114 // SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
115 // QPixmap iconSlct ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
116 // mySelButton->setPixmap(iconSlct);
117 // mySelButton->setToggleButton( true );
119 myHypTypePopup = new QPopupMenu();
121 // Add to pop-up hypotheses of "Regular_1D" algo
122 myHypTypePopup->clear();
123 HypothesisData* algoData = SMESH::GetHypothesisData( "Regular_1D" );
124 myHypTypes = SMESH::GetAvailableHypotheses( false, 1 );
125 QStringList::const_iterator anIter = myHypTypes.begin();
126 for ( ; anIter != myHypTypes.end(); ++anIter )
128 HypothesisData* hypData = SMESH::GetHypothesisData( *anIter );
130 if ( SMESH::IsAvailableHypothesis( algoData, hypData->TypeName, bidon ))
131 myHypTypePopup->insertItem( hypData->Label );
134 connect( myCreateButton, SIGNAL(clicked()), SLOT(onCreate()));
135 connect( myEditButton, SIGNAL(clicked()), SLOT(onEdit()));
136 connect( myHypTypePopup, SIGNAL( activated( int ) ), SLOT( onHypTypePopup( int ) ) );
139 //================================================================================
141 * \brief Create a new hyp of selected type
142 * \param int - selected type index
144 //================================================================================
146 void StdMeshersGUI_LayerDistributionParamWdg::onHypTypePopup( int theIndex )
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();
156 for ( ; !aHypData && anIter != myHypTypes.end(); ++anIter )
158 HypothesisData* hypData = SMESH::GetHypothesisData( *anIter );
159 if ( myHypTypePopup->text( theIndex ) == hypData->Label )
162 QString aServLib = aHypData->ServerLibName;
163 QString aHypType = aHypData->TypeName;
165 set( gen->CreateHypothesis(aHypType, aServLib));
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();