3 #include "MonCreateBoundaryAn.h"
4 #include "MonCreateCase.h"
9 #include "SalomeApp_Tools.h"
10 #include "HOMARDGUI_Utils.h"
11 #include "HomardQtCommun.h"
12 #include <utilities.h>
14 #include <SUIT_Desktop.h>
15 #include <SUIT_MessageBox.h>
16 #include <SUIT_ResourceMgr.h>
17 #include <SUIT_Session.h>
18 #include <SUIT_ViewManager.h>
20 // ------------------------------------------------------------------------------------------------------------------------
21 MonCreateBoundaryAn::MonCreateBoundaryAn(MonCreateCase* parent, bool modal,
22 HOMARD::HOMARD_Gen_var myHomardGen,
24 // ------------------------------------------------------------------------------------------------------------------------------
25 /* Constructs a MonCreateBoundaryAn
26 appele pour une vraie creation
27 initialise un cylindre et non une sphere
29 QDialog(0), Ui_CreateBoundaryAn(),
31 _aBoundaryAnName (""),
34 _BoundaryAnXcentre(0), _BoundaryAnYcentre(0), _BoundaryAnZcentre(0), _BoundaryAnRayon(0),
35 _BoundaryAnXaxis(0), _BoundaryAnYaxis(0), _BoundaryAnZaxis(0),
36 _Xcentre(0), _Ycentre(0), _Zcentre(0), _Rayon(0),
37 _Xmin(0), _Xmax(0), _Xincr(0), _Ymin(0), _Ymax(0), _Yincr(0), _Zmin(0), _Zmax(0), _Zincr(0), _DMax(0),
40 MESSAGE("Constructeur") ;
41 _myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen);
46 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
47 QPixmap pix = resMgr->loadPixmap( "HOMARD", "spherepoint.png" );
49 RBSphere->setIcon(IS);
50 QPixmap pix2 = resMgr->loadPixmap( "HOMARD", "cylinderpointvector.png" );
51 QIcon IS2=QIcon(pix2);
52 RBCylindre->setIcon(IS2);
56 SetNewBoundaryAnName() ;
57 InitValBoundaryAn(); // Cherche les valeurs de la boite englobante le maillage
58 InitMinMax(); // Initialise les bornes des boutons
59 SetCylinder(); // Propose un cylindre en premier choix
61 // --------------------------------------------------------------------------------------------------------------
62 MonCreateBoundaryAn::MonCreateBoundaryAn(MonCreateCase* parent,
63 HOMARD::HOMARD_Gen_var myHomardGen,
65 // --------------------------------------------------------------------------------------------------------------
66 // Constructeur appele par MonEditBoundaryAn
68 QDialog(0), Ui_CreateBoundaryAn(),
69 _myHomardGen(myHomardGen),
71 _aBoundaryAnName (""),
74 _BoundaryAnXcentre(0), _BoundaryAnYcentre(0), _BoundaryAnZcentre(0), _BoundaryAnRayon(0),
75 _BoundaryAnXaxis(0), _BoundaryAnYaxis(0), _BoundaryAnZaxis(0),
76 // Pour affichage lors de l edition d une BoundaryAn sans nom de Cas
77 _Xcentre(0), _Ycentre(0), _Zcentre(0), _Rayon(0),
78 _Xmin(1), _Xmax(1), _Xincr(1), _Ymin(1), _Ymax(1), _Yincr(1), _Zmin(1), _Zmax(1), _Zincr(1), _DMax(1),
81 // MESSAGE("Debut de MonCreateBoundaryAn")
83 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
84 QPixmap pix = resMgr->loadPixmap( "HOMARD", "spherepoint.png" );
86 RBSphere->setIcon(IS);
87 QPixmap pix2 = resMgr->loadPixmap( "HOMARD", "cylinderpointvector.png" );
88 QIcon IS2=QIcon(pix2);
89 RBCylindre->setIcon(IS2);
94 // ------------------------------------------------------------------------
95 MonCreateBoundaryAn::~MonCreateBoundaryAn()
96 // ------------------------------------------------------------------------
98 // no need to delete child widgets, Qt does it all for us
100 // ------------------------------------------------------------------------
101 void MonCreateBoundaryAn::InitConnect()
102 // ------------------------------------------------------------------------
104 connect( RBCylindre, SIGNAL(clicked()) , this, SLOT(SetCylinder()) ) ;
105 connect( RBSphere, SIGNAL(clicked()) , this, SLOT(SetSphere()) ) ;
106 connect( buttonOk, SIGNAL( pressed() ), this, SLOT( PushOnOK() ) );
107 connect( buttonApply, SIGNAL( pressed() ), this, SLOT( PushOnApply() ) );
108 connect( buttonCancel, SIGNAL( pressed() ), this, SLOT( close() ) );
109 connect( buttonHelp, SIGNAL( pressed() ), this, SLOT( PushOnHelp() ) );
111 // ------------------------------------------------------------------------
112 void MonCreateBoundaryAn::InitValBoundaryAn()
113 // ------------------------------------------------------------------------
116 // 1. Les coordonnees extremes du maillage
118 if (_aCaseName == QString("")) { return; }
120 HOMARD::HOMARD_Cas_var aCas = _myHomardGen->GetCas(_aCaseName.toStdString().c_str());
121 HOMARD::extrema_var MesExtremes = aCas->GetBoundingBox();
122 int num = MesExtremes->length() ;
124 _Xmin=MesExtremes[0]; _Xmax=MesExtremes[1]; _Xincr=MesExtremes[2];
125 _Ymin=MesExtremes[3]; _Ymax=MesExtremes[4]; _Yincr=MesExtremes[5];
126 _Zmin=MesExtremes[6]; _Zmax=MesExtremes[7]; _Zincr=MesExtremes[8];
127 _DMax=MesExtremes[9];
128 MESSAGE ("_Xmin : " << _Xmin << " _Xmax : " << _Xmax << " _Xincr : " << _Xincr ) ;
129 MESSAGE ("_Ymin : " << _Ymin << " _Ymax : " << _Ymax << " _Yincr : " << _Yincr ) ;
130 MESSAGE ("_Zmin : " << _Zmin << " _Zmax : " << _Zmax << " _Zincr : " << _Zincr) ;
131 MESSAGE ("_DMax : " << _DMax);
133 // 2. Caracteristiques des zones
135 _Xcentre=(_Xmin + _Xmax)/2.;
137 _Ycentre=(_Ymin + _Ymax)/2.;
139 _Zcentre=(_Zmin + _Zmax)/2.;
144 // ------------------------------------------------------------------------
145 void MonCreateBoundaryAn::InitMinMax()
146 // ------------------------------------------------------------------------
149 SpinBox_Xaxis->setSingleStep(0.1);
150 SpinBox_Xcentre->setSingleStep(_Xincr);
152 SpinBox_Yaxis->setSingleStep(0.1);
153 SpinBox_Ycentre->setSingleStep(_Yincr);
155 SpinBox_Zaxis->setSingleStep(0.1);
156 SpinBox_Zcentre->setSingleStep(_Zincr);
158 SpinBox_Radius->setSingleStep(_Rayon/10.);
159 SpinBox_Radius->setMinimum(0.);
160 SpinBox_Rayon->setSingleStep(_Rayon/10.);
161 SpinBox_Rayon->setMinimum(0.);
163 // ------------------------------------------------------------------------
164 bool MonCreateBoundaryAn::PushOnApply()
165 // ------------------------------------------------------------------------
166 // Appele lorsque l'un des boutons Ok ou Apply est presse
169 std::cerr << LEBoundaryName->text().trimmed().toStdString() << std::endl;
170 if (LEBoundaryName->text().trimmed()=="")
172 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
173 QObject::tr("HOM_BOUN_NAME") );
177 switch (_BoundaryType)
179 case 1 : // il s agit d un cylindre
181 if ((_BoundaryAnXcentre != SpinBox_Xcent->value()) or
182 (_BoundaryAnYcentre != SpinBox_Ycent->value()) or
183 (_BoundaryAnZcentre != SpinBox_Zcent->value()) or
184 (_BoundaryAnRayon != SpinBox_Radius->value()) or
185 (_BoundaryAnXaxis != SpinBox_Xaxis->value()) or
186 (_BoundaryAnYaxis != SpinBox_Yaxis->value()) or
187 (_BoundaryAnZaxis != SpinBox_Zaxis->value()) )
190 _BoundaryAnXaxis= SpinBox_Xaxis->value();
191 _BoundaryAnYaxis= SpinBox_Yaxis->value();
192 _BoundaryAnZaxis= SpinBox_Zaxis->value();
193 _BoundaryAnXcentre=SpinBox_Xcent->value();
194 _BoundaryAnYcentre=SpinBox_Ycent->value();
195 _BoundaryAnZcentre=SpinBox_Zcent->value();
196 _BoundaryAnRayon=SpinBox_Radius->value();
201 case 4 : // il s agit d une sphere
203 if ((_BoundaryAnXcentre != SpinBox_Xcentre->value()) or
204 (_BoundaryAnYcentre != SpinBox_Ycentre->value()) or
205 (_BoundaryAnZcentre != SpinBox_Zcentre->value()) or
206 (_BoundaryAnRayon != SpinBox_Rayon->value()) )
209 _BoundaryAnXcentre=SpinBox_Xcentre->value();
210 _BoundaryAnYcentre=SpinBox_Ycentre->value();
211 _BoundaryAnZcentre=SpinBox_Zcentre->value();
212 _BoundaryAnRayon=SpinBox_Rayon->value();
218 bool bOK = CreateOrUpdateBoundaryAn();
222 // ---------------------------------------------------
223 bool MonCreateBoundaryAn:: CreateOrUpdateBoundaryAn()
224 //----------------------------------------------------
225 // Creation de l'objet boundary
226 // Mise a jour des attributs de la BoundaryAn
229 if (_aBoundaryAnName != LEBoundaryName->text().trimmed())
233 _aBoundaryAnName = LEBoundaryName->text().trimmed();
234 aBoundaryAn = _myHomardGen->CreateBoundary( \
235 CORBA::string_dup(_aBoundaryAnName.toStdString().c_str()), \
236 CORBA::Long(_BoundaryType) );
237 _parent->addBoundaryAn(_aBoundaryAnName);
239 catch( SALOME::SALOME_Exception& S_ex )
241 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
242 QString(CORBA::string_dup(S_ex.details.text)) );
246 // Mise en place des attributs
247 aBoundaryAn->SetBoundaryType(_BoundaryType);
248 switch (_BoundaryType)
250 case 1 : // il s agit d un cylindre
252 aBoundaryAn->SetCylinder(_BoundaryAnXcentre, _BoundaryAnYcentre, _BoundaryAnZcentre, _BoundaryAnXaxis, _BoundaryAnYaxis, _BoundaryAnZaxis, _BoundaryAnRayon );
256 case 2 : // il s agit d une sphere
258 aBoundaryAn->SetSphere(_BoundaryAnXcentre, _BoundaryAnYcentre, _BoundaryAnZcentre, _BoundaryAnRayon);
262 aBoundaryAn->SetLimit(_Xincr, _Yincr, _Zincr);
264 HOMARD_UTILS::updateObjBrowser();
267 // ------------------------------------------------------------------------
268 void MonCreateBoundaryAn::PushOnOK()
269 // ------------------------------------------------------------------------
271 if (PushOnApply()) this->close();
273 // ------------------------------------------------------------------------
274 void MonCreateBoundaryAn::PushOnHelp()
275 // ------------------------------------------------------------------------
277 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html#un-cylindre") ) ;
280 // -----------------------------------
281 void MonCreateBoundaryAn::SetNewBoundaryAnName()
282 // -----------------------------------
284 // Recherche d'un nom par defaut qui n'existe pas encore
286 HOMARD::listeBoundarys_var MyBoundaryAns = _myHomardGen->GetAllBoundarys();
287 int num = 0; QString aBoundaryAnName="";
288 while (aBoundaryAnName=="" )
290 aBoundaryAnName.setNum(num+1) ;
291 aBoundaryAnName.insert(0, QString("Boun_")) ;
292 for ( int i=0; i<MyBoundaryAns->length(); i++)
294 if ( aBoundaryAnName == QString(MyBoundaryAns[i]))
302 LEBoundaryName->clear() ;
303 LEBoundaryName->insert(aBoundaryAnName);
305 // ------------------------------------------------------------------------
306 void MonCreateBoundaryAn::SetCylinder()
307 // ------------------------------------------------------------------------
309 MESSAGE("Debut de SetCylinder")
310 gBCylindre->setVisible(1);
311 gBSphere->setVisible(0);
314 SpinBox_Xcent->setValue(_Xcentre);
315 SpinBox_Xaxis->setValue(1.);
316 SpinBox_Ycent->setValue(_Ycentre);
317 SpinBox_Yaxis->setValue(1.);
318 SpinBox_Zcent->setValue(_Zcentre);
319 SpinBox_Zaxis->setValue(1.);
320 SpinBox_Radius->setValue(_Rayon);
321 MESSAGE("Fin de SetCylinder")
323 // ------------------------------------------------------------------------
324 void MonCreateBoundaryAn::SetSphere()
325 // ------------------------------------------------------------------------
327 MESSAGE("Debut de SetSphere")
328 gBCylindre->setVisible(0);
329 gBSphere->setVisible(1);
332 SpinBox_Xcentre->setValue(_Xcentre);
333 SpinBox_Ycentre->setValue(_Ycentre);
334 SpinBox_Zcentre->setValue(_Zcentre);
335 SpinBox_Rayon->setValue(_Rayon);
336 MESSAGE("Fin de SetSphere")