1 // Copyright (C) 2007-2021 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(), myDlg( dlg ), myName(name)
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" );
114 myCreateButton->setMinimumWidth(100);
116 myEditButton = new QPushButton( tr("EDIT"), this );
117 myEditButton->setObjectName( "editBut" );
118 myEditButton->setMinimumWidth(100);
120 myHypTypePopup = new QMenu( this );
122 // Add to pop-up hypotheses of "Regular_1D" algo
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->addAction( hypData->Label );
134 aHBox->addWidget( myCreateButton );
135 aHBox->addStretch(5);
136 aHBox->addWidget( myEditButton );
138 connect( myCreateButton, SIGNAL(clicked()), SLOT(onCreate()));
139 connect( myEditButton, SIGNAL(clicked()), SLOT(onEdit()));
140 connect( myHypTypePopup, SIGNAL(triggered( QAction* ) ), SLOT( onHypTypePopup( QAction* ) ) );
143 //================================================================================
145 * \brief Create a new hyp of selected type
146 * \param int - selected type index
148 //================================================================================
150 void StdMeshersGUI_LayerDistributionParamWdg::onHypTypePopup( QAction* a )
152 SMESH::SMESH_Gen_var gen = mySMESHGUI->GetSMESHGen();
154 // avoid publishing a new 1D hyp
155 gen->SetEnablePublish( false );
158 HypothesisData* aHypData = 0;
159 QStringList::const_iterator anIter = myHypTypes.begin();
161 for ( ; !aHypData && anIter != myHypTypes.end(); ++anIter )
163 HypothesisData* hypData = SMESH::GetHypothesisData( *anIter );
164 if ( a->text() == hypData->Label )
167 QString aServLib = aHypData->ServerLibName;
168 QString aHypType = aHypData->TypeName;
170 set( gen->CreateHypothesis(aHypType.toLatin1().data(), aServLib.toUtf8().data()));
172 catch (const SALOME::SALOME_Exception & S_ex) {
173 SalomeApp_Tools::QtCatchCorbaException(S_ex);
176 // restore current study
177 gen->SetEnablePublish( true );
182 //================================================================================
184 * \brief Show popup with available types
186 //================================================================================
188 void StdMeshersGUI_LayerDistributionParamWdg::onCreate()
190 myHypTypePopup->exec( QCursor::pos() );
193 //================================================================================
195 * \brief Edit hypothesis
197 //================================================================================
199 void StdMeshersGUI_LayerDistributionParamWdg::onEdit()
201 if ( myHyp->_is_nil() )
204 CORBA::String_var hypType = myHyp->GetName();
206 SMESHGUI_GenericHypothesisCreator* editor = SMESH::GetHypothesisCreator(hypType.in());
207 if ( !editor ) return;
211 //myDlg->hide(); -- pb: show() does not work
212 myDlg->setWindowTitle( tr( "SMESH_HYPOTHESIS" ));
213 myDlg->setEnabled(false);
217 QWidget* parent = this;
219 parent = myDlg->parentWidget();
220 editor->edit( myHyp, myName, parent, this, SLOT( onEdited( int ) ) );
227 void StdMeshersGUI_LayerDistributionParamWdg::onEdited( int /*result*/ )
231 //myDlg->show(); does not work
232 myDlg->setEnabled(true);