1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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
23 // File : StdMeshersGUI_LayerDistributionParamWdg.cxx
24 // Author : Open CASCADE S.A.S.
27 #include "StdMeshersGUI_LayerDistributionParamWdg.h"
30 #include <SMESHGUI_HypothesesUtils.h>
31 #include <SMESHGUI_Hypotheses.h>
33 // SALOME GUI includes
34 #include <SalomeApp_Tools.h>
37 #include <QPushButton>
41 #include <QHBoxLayout>
45 //================================================================================
47 * \brief Constructor initialized by filter
48 * \param f - object filter
50 //================================================================================
52 StdMeshersGUI_LayerDistributionParamWdg
53 ::StdMeshersGUI_LayerDistributionParamWdg(SMESH::SMESH_Hypothesis_ptr holderHyp,
54 SMESH::SMESH_Hypothesis_ptr distribHyp,
57 QWidget(), myName(name), myDlg( dlg )
59 myHolderHyp = SMESH::SMESH_Hypothesis::_duplicate( holderHyp );
64 //================================================================================
66 * \brief initialize fields with hypothesis
67 * \param hyp - hypothesis
69 //================================================================================
71 void StdMeshersGUI_LayerDistributionParamWdg::set(SMESH::SMESH_Hypothesis_ptr hyp)
73 myHyp = SMESH::SMESH_Hypothesis::_nil();
74 if ( !CORBA::is_nil( hyp )) {
75 myHyp = SMESH::SMESH_Hypothesis::_duplicate( hyp );
76 myHyp->SetHolderHypothesis( myHolderHyp );
77 myEditButton->setEnabled( true );
78 myCreateButton->setText( tr("CHANGE_TYPE"));
79 myParamValue = hyp->GetName();
82 myEditButton->setEnabled( false );
83 myCreateButton->setText( tr("CREATE"));
88 //================================================================================
92 //================================================================================
94 StdMeshersGUI_LayerDistributionParamWdg::~StdMeshersGUI_LayerDistributionParamWdg()
98 //================================================================================
100 * \brief Create a layout, initialize fields
102 //================================================================================
104 void StdMeshersGUI_LayerDistributionParamWdg::init()
106 QHBoxLayout* aHBox = new QHBoxLayout( this );
107 aHBox->setMargin( 0 );
108 aHBox->setSpacing( SPACING );
110 mySMESHGUI = SMESHGUI::GetSMESHGUI();
112 myCreateButton = new QPushButton( this );
113 myCreateButton->setObjectName( "createBut" );
115 myEditButton = new QPushButton( tr("EDIT"), this );
116 myEditButton->setObjectName( "editBut" );
118 myHypTypePopup = new QMenu( this );
120 // Add to pop-up hypotheses of "Regular_1D" algo
121 HypothesisData* algoData = SMESH::GetHypothesisData( "Regular_1D" );
122 myHypTypes = SMESH::GetAvailableHypotheses( false, 1 );
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->addAction( hypData->Label );
132 aHBox->addWidget( myCreateButton );
133 aHBox->addWidget( myEditButton );
136 connect( myCreateButton, SIGNAL(clicked()), SLOT(onCreate()));
137 connect( myEditButton, SIGNAL(clicked()), SLOT(onEdit()));
138 connect( myHypTypePopup, SIGNAL(triggered( QAction* ) ), SLOT( onHypTypePopup( QAction* ) ) );
141 //================================================================================
143 * \brief Create a new hyp of selected type
144 * \param int - selected type index
146 //================================================================================
148 void StdMeshersGUI_LayerDistributionParamWdg::onHypTypePopup( QAction* a )
150 SMESH::SMESH_Gen_var gen = mySMESHGUI->GetSMESHGen();
152 // avoid publishing a new 1D hyp
153 gen->SetCurrentStudy( SALOMEDS::Study::_nil() );
156 HypothesisData* aHypData = 0;
157 QStringList::const_iterator anIter = myHypTypes.begin();
159 for ( ; !aHypData && anIter != myHypTypes.end(); ++anIter )
161 HypothesisData* hypData = SMESH::GetHypothesisData( *anIter );
162 if ( a->text() == hypData->Label )
165 QString aServLib = aHypData->ServerLibName;
166 QString aHypType = aHypData->TypeName;
168 set( gen->CreateHypothesis(aHypType.toLatin1().data(), aServLib.toLatin1().data()));
170 catch (const SALOME::SALOME_Exception & S_ex) {
171 SalomeApp_Tools::QtCatchCorbaException(S_ex);
174 // restore current study
175 mySMESHGUI->GetSMESHGen();
180 //================================================================================
182 * \brief Show popup with available types
184 //================================================================================
186 void StdMeshersGUI_LayerDistributionParamWdg::onCreate()
188 myHypTypePopup->exec( QCursor::pos() );
191 //================================================================================
193 * \brief Edit hypothesis
195 //================================================================================
197 void StdMeshersGUI_LayerDistributionParamWdg::onEdit()
199 if ( myHyp->_is_nil() )
202 CORBA::String_var hypType = myHyp->GetName();
204 SMESHGUI_GenericHypothesisCreator* editor = SMESH::GetHypothesisCreator(hypType.in());
205 if ( !editor ) return;
211 QWidget* parent = this;
213 parent = myDlg->parentWidget();
214 editor->edit( myHyp, myName, parent, this, SLOT( onEdited( int ) ) );
221 void StdMeshersGUI_LayerDistributionParamWdg::onEdited( int result )