Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "StdMeshersGUI_LayerDistributionParamWdg.h"
00028
00029 #include <SMESHGUI.h>
00030 #include <SMESHGUI_HypothesesUtils.h>
00031 #include <SMESHGUI_Hypotheses.h>
00032
00033
00034 #include <SalomeApp_Tools.h>
00035
00036
00037 #include <QPushButton>
00038 #include <QCursor>
00039 #include <QMenu>
00040 #include <QDialog>
00041 #include <QHBoxLayout>
00042
00043 #define SPACING 6
00044
00045
00050
00051
00052 StdMeshersGUI_LayerDistributionParamWdg
00053 ::StdMeshersGUI_LayerDistributionParamWdg(SMESH::SMESH_Hypothesis_ptr hyp,
00054 const QString& theName,
00055 QDialog* dlg):
00056 QWidget(), myName(theName), myDlg( dlg )
00057 {
00058 init();
00059 set( hyp );
00060
00061
00062 }
00063
00064
00069
00070
00071 void StdMeshersGUI_LayerDistributionParamWdg::set(SMESH::SMESH_Hypothesis_ptr hyp)
00072 {
00073 myHyp = SMESH::SMESH_Hypothesis::_nil();
00074 if ( !CORBA::is_nil( hyp )) {
00075 myHyp = SMESH::SMESH_Hypothesis::_duplicate( hyp );
00076 myEditButton->setEnabled( true );
00077 myCreateButton->setText( tr("CHANGE_TYPE"));
00078 myParamValue = hyp->GetName();
00079 }
00080 else {
00081 myEditButton->setEnabled( false );
00082 myCreateButton->setText( tr("CREATE"));
00083 myParamValue = "";
00084 }
00085 }
00086
00087
00091
00092
00093 StdMeshersGUI_LayerDistributionParamWdg::~StdMeshersGUI_LayerDistributionParamWdg()
00094 {
00095 }
00096
00097
00101
00102
00103 void StdMeshersGUI_LayerDistributionParamWdg::init()
00104 {
00105 QHBoxLayout* aHBox = new QHBoxLayout( this );
00106 aHBox->setMargin( 0 );
00107 aHBox->setSpacing( SPACING );
00108
00109 mySMESHGUI = SMESHGUI::GetSMESHGUI();
00110
00111 myCreateButton = new QPushButton( this );
00112 myCreateButton->setObjectName( "createBut" );
00113
00114 myEditButton = new QPushButton( tr("EDIT"), this );
00115 myEditButton->setObjectName( "editBut" );
00116
00117 myHypTypePopup = new QMenu( this );
00118
00119
00120 HypothesisData* algoData = SMESH::GetHypothesisData( "Regular_1D" );
00121 myHypTypes = SMESH::GetAvailableHypotheses( false, 1 );
00122 QStringList::const_iterator anIter = myHypTypes.begin();
00123 for ( ; anIter != myHypTypes.end(); ++anIter )
00124 {
00125 HypothesisData* hypData = SMESH::GetHypothesisData( *anIter );
00126 bool bidon;
00127 if ( SMESH::IsAvailableHypothesis( algoData, hypData->TypeName, bidon ))
00128 myHypTypePopup->addAction( hypData->Label );
00129 }
00130
00131 aHBox->addWidget( myCreateButton );
00132 aHBox->addWidget( myEditButton );
00133 aHBox->addStretch();
00134
00135 connect( myCreateButton, SIGNAL(clicked()), SLOT(onCreate()));
00136 connect( myEditButton, SIGNAL(clicked()), SLOT(onEdit()));
00137 connect( myHypTypePopup, SIGNAL(triggered( QAction* ) ), SLOT( onHypTypePopup( QAction* ) ) );
00138 }
00139
00140
00145
00146
00147 void StdMeshersGUI_LayerDistributionParamWdg::onHypTypePopup( QAction* a )
00148 {
00149 SMESH::SMESH_Gen_var gen = mySMESHGUI->GetSMESHGen();
00150
00151
00152 gen->SetCurrentStudy( SALOMEDS::Study::_nil() );
00153
00154
00155 HypothesisData* aHypData = 0;
00156 QStringList::const_iterator anIter = myHypTypes.begin();
00157
00158 for ( ; !aHypData && anIter != myHypTypes.end(); ++anIter )
00159 {
00160 HypothesisData* hypData = SMESH::GetHypothesisData( *anIter );
00161 if ( a->text() == hypData->Label )
00162 aHypData = hypData;
00163 }
00164 QString aServLib = aHypData->ServerLibName;
00165 QString aHypType = aHypData->TypeName;
00166 try {
00167 set( gen->CreateHypothesis(aHypType.toLatin1().data(), aServLib.toLatin1().data()));
00168 }
00169 catch (const SALOME::SALOME_Exception & S_ex) {
00170 SalomeApp_Tools::QtCatchCorbaException(S_ex);
00171 }
00172
00173
00174 mySMESHGUI->GetSMESHGen();
00175
00176 onEdit();
00177 }
00178
00179
00183
00184
00185 void StdMeshersGUI_LayerDistributionParamWdg::onCreate()
00186 {
00187 myHypTypePopup->exec( QCursor::pos() );
00188 }
00189
00190
00194
00195
00196 void StdMeshersGUI_LayerDistributionParamWdg::onEdit()
00197 {
00198 if ( myHyp->_is_nil() )
00199 return;
00200
00201 CORBA::String_var hypType = myHyp->GetName();
00202
00203
00204 SMESHGUI_GenericHypothesisCreator* editor = SMESH::GetHypothesisCreator(hypType.in());
00205 if ( !editor ) return;
00206
00207 if ( myDlg )
00208 myDlg->hide();
00209
00210 try {
00211 QWidget* parent = this;
00212 if ( myDlg )
00213 parent = myDlg->parentWidget();
00214 editor->edit( myHyp, myName, parent, this, SLOT( onEdited( int ) ) );
00215 }
00216 catch(...)
00217 {
00218 }
00219 }
00220
00221 void StdMeshersGUI_LayerDistributionParamWdg::onEdited( int result )
00222 {
00223 if ( myDlg )
00224 myDlg->show();
00225 }