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 QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( false, 0 );
123 QStringList::const_iterator anIter = aHypTypeNameList.begin();
124 for ( int i = 0; anIter != aHypTypeNameList.end(); ++anIter, ++i )
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 QString aHypType = myHypTypePopup->text( theIndex );
153 HypothesisData* aHypData = SMESH::GetHypothesisData(aHypType.latin1());
154 QString aServLib = aHypData->ServerLibName;
156 set( gen->CreateHypothesis(aHypType, aServLib));
158 catch (const SALOME::SALOME_Exception & S_ex) {
159 SalomeApp_Tools::QtCatchCorbaException(S_ex);
162 // restore current study
163 mySMESHGUI->GetSMESHGen();
168 //================================================================================
170 * \brief Show popup with available types
172 //================================================================================
174 void StdMeshersGUI_LayerDistributionParamWdg::onCreate()
176 myHypTypePopup->exec( QCursor::pos() );
179 //================================================================================
181 * \brief Edit hypothesis
183 //================================================================================
185 void StdMeshersGUI_LayerDistributionParamWdg::onEdit()
187 if ( myHyp->_is_nil() )
190 CORBA::String_var hypType = myHyp->GetName();
191 SMESHGUI_GenericHypothesisCreator*
192 editor = SMESH::GetHypothesisCreator( hypType.in() );
193 if ( !editor ) return;
195 if ( myDlg ) myDlg->hide();
198 QWidget* parent = this;
199 if ( myDlg ) parent = myDlg->parentWidget();
200 editor->edit( myHyp, parent );
205 if ( myDlg ) myDlg->show();