1 // Copyright (C) 2007-2008 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
22 // SMESH StdMeshersGUI
23 // File : StdMeshersGUI_LayerDistributionParamWdg.cxx
26 #include "StdMeshersGUI_LayerDistributionParamWdg.h"
28 #include <qpushbutton.h>
30 #include <qpopupmenu.h>
34 #include "SMESHGUI_Utils.h"
35 #include "SMESHGUI_HypothesesUtils.h"
36 #include "SMESHGUI_Hypotheses.h"
37 // #include "SUIT_ResourceMgr.h"
38 // #include "LightApp_SelectionMgr.h"
39 #include "SALOMEDSClient_SObject.hxx"
40 #include "SALOMEDS_Study.hxx"
41 #include "SalomeApp_Tools.h"
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 QHGroupBox(), 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()
94 delete myHypTypePopup;
97 //================================================================================
99 * \brief Create a leayout, initialize fields
101 //================================================================================
103 void StdMeshersGUI_LayerDistributionParamWdg::init()
105 setFrameStyle(QFrame::NoFrame);
108 mySMESHGUI = SMESHGUI::GetSMESHGUI();
110 myCreateButton = new QPushButton( this, "createBut");
111 myEditButton = new QPushButton( tr("EDIT"), this, "createBut");
113 // SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
114 // QPixmap iconSlct ( mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
115 // mySelButton->setPixmap(iconSlct);
116 // mySelButton->setToggleButton( true );
118 myHypTypePopup = new QPopupMenu();
120 // Add to pop-up hypotheses of "Regular_1D" algo
121 myHypTypePopup->clear();
122 HypothesisData* algoData = SMESH::GetHypothesisData( "Regular_1D" );
123 myHypTypes = SMESH::GetAvailableHypotheses( false, 1 );
124 QStringList::const_iterator anIter = myHypTypes.begin();
125 for ( ; anIter != myHypTypes.end(); ++anIter )
127 HypothesisData* hypData = SMESH::GetHypothesisData( *anIter );
129 if ( SMESH::IsAvailableHypothesis( algoData, hypData->TypeName, bidon ))
130 myHypTypePopup->insertItem( hypData->Label );
133 connect( myCreateButton, SIGNAL(clicked()), SLOT(onCreate()));
134 connect( myEditButton, SIGNAL(clicked()), SLOT(onEdit()));
135 connect( myHypTypePopup, SIGNAL( activated( int ) ), SLOT( onHypTypePopup( int ) ) );
138 //================================================================================
140 * \brief Create a new hyp of selected type
141 * \param int - selected type index
143 //================================================================================
145 void StdMeshersGUI_LayerDistributionParamWdg::onHypTypePopup( int theIndex )
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();
155 for ( ; !aHypData && anIter != myHypTypes.end(); ++anIter )
157 HypothesisData* hypData = SMESH::GetHypothesisData( *anIter );
158 if ( myHypTypePopup->text( theIndex ) == hypData->Label )
161 QString aServLib = aHypData->ServerLibName;
162 QString aHypType = aHypData->TypeName;
164 set( gen->CreateHypothesis(aHypType, aServLib));
166 catch (const SALOME::SALOME_Exception & S_ex) {
167 SalomeApp_Tools::QtCatchCorbaException(S_ex);
170 // restore current study
171 mySMESHGUI->GetSMESHGen();
176 //================================================================================
178 * \brief Show popup with available types
180 //================================================================================
182 void StdMeshersGUI_LayerDistributionParamWdg::onCreate()
184 myHypTypePopup->exec( QCursor::pos() );
187 //================================================================================
189 * \brief Edit hypothesis
191 //================================================================================
193 void StdMeshersGUI_LayerDistributionParamWdg::onEdit()
195 if ( myHyp->_is_nil() )
198 CORBA::String_var hypType = myHyp->GetName();
199 SMESHGUI_GenericHypothesisCreator*
200 editor = SMESH::GetHypothesisCreator( hypType.in() );
201 if ( !editor ) return;
203 if ( myDlg ) myDlg->hide();
206 QWidget* parent = this;
207 if ( myDlg ) parent = myDlg->parentWidget();
208 editor->edit( myHyp, myName, parent );
213 if ( myDlg ) myDlg->show();