1 // Copyright (C) 2011-2012 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "MonCreateBoundaryAn.h"
23 #include "MonCreateCase.h"
25 #include <QFileDialog>
26 #include <QMessageBox>
28 #include "SalomeApp_Tools.h"
29 #include "HOMARDGUI_Utils.h"
30 #include "HomardQtCommun.h"
31 #include <utilities.h>
33 #include <SUIT_Desktop.h>
34 #include <SUIT_MessageBox.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_ViewManager.h>
39 // ------------------------------------------------------------------------------------------------------------------------
40 MonCreateBoundaryAn::MonCreateBoundaryAn(MonCreateCase* parent, bool modal,
41 HOMARD::HOMARD_Gen_var myHomardGen,
43 // ------------------------------------------------------------------------------------------------------------------------------
44 /* Constructs a MonCreateBoundaryAn
45 appele pour une vraie creation
46 initialise un cylindre et non une sphere
48 QDialog(0), Ui_CreateBoundaryAn(),
53 _BoundaryAnXcentre(0), _BoundaryAnYcentre(0), _BoundaryAnZcentre(0), _BoundaryAnRayon(0),
54 _BoundaryAnXaxis(0), _BoundaryAnYaxis(0), _BoundaryAnZaxis(0),
55 _Xcentre(0), _Ycentre(0), _Zcentre(0), _Rayon(0),
56 _Xmin(0), _Xmax(0), _Xincr(0), _Ymin(0), _Ymax(0), _Yincr(0), _Zmin(0), _Zmax(0), _Zincr(0), _DMax(0),
59 MESSAGE("Constructeur") ;
60 _myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen);
65 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
66 QPixmap pix = resMgr->loadPixmap( "HOMARD", "spherepoint.png" );
68 RBSphere->setIcon(IS);
69 QPixmap pix2 = resMgr->loadPixmap( "HOMARD", "cylinderpointvector.png" );
70 QIcon IS2=QIcon(pix2);
71 RBCylindre->setIcon(IS2);
75 SetNewBoundaryAnName() ;
76 InitValBoundaryAn(); // Cherche les valeurs de la boite englobante le maillage
77 InitMinMax(); // Initialise les bornes des boutons
78 SetCylinder(); // Propose un cylindre en premier choix
80 // --------------------------------------------------------------------------------------------------------------
81 MonCreateBoundaryAn::MonCreateBoundaryAn(MonCreateCase* parent,
82 HOMARD::HOMARD_Gen_var myHomardGen,
84 // --------------------------------------------------------------------------------------------------------------
85 // Constructeur appele par MonEditBoundaryAn
87 QDialog(0), Ui_CreateBoundaryAn(),
88 _myHomardGen(myHomardGen),
93 _BoundaryAnXcentre(0), _BoundaryAnYcentre(0), _BoundaryAnZcentre(0), _BoundaryAnRayon(0),
94 _BoundaryAnXaxis(0), _BoundaryAnYaxis(0), _BoundaryAnZaxis(0),
95 // Pour affichage lors de l edition d une BoundaryAn sans nom de Cas
96 _Xcentre(0), _Ycentre(0), _Zcentre(0), _Rayon(0),
97 _Xmin(1), _Xmax(1), _Xincr(1), _Ymin(1), _Ymax(1), _Yincr(1), _Zmin(1), _Zmax(1), _Zincr(1), _DMax(1),
100 // MESSAGE("Debut de MonCreateBoundaryAn")
102 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
103 QPixmap pix = resMgr->loadPixmap( "HOMARD", "spherepoint.png" );
105 RBSphere->setIcon(IS);
106 QPixmap pix2 = resMgr->loadPixmap( "HOMARD", "cylinderpointvector.png" );
107 QIcon IS2=QIcon(pix2);
108 RBCylindre->setIcon(IS2);
113 // ------------------------------------------------------------------------
114 MonCreateBoundaryAn::~MonCreateBoundaryAn()
115 // ------------------------------------------------------------------------
117 // no need to delete child widgets, Qt does it all for us
119 // ------------------------------------------------------------------------
120 void MonCreateBoundaryAn::InitConnect()
121 // ------------------------------------------------------------------------
123 connect( RBCylindre, SIGNAL(clicked()) , this, SLOT(SetCylinder()) ) ;
124 connect( RBSphere, SIGNAL(clicked()) , this, SLOT(SetSphere()) ) ;
125 connect( buttonOk, SIGNAL( pressed() ), this, SLOT( PushOnOK() ) );
126 connect( buttonApply, SIGNAL( pressed() ), this, SLOT( PushOnApply() ) );
127 connect( buttonCancel, SIGNAL( pressed() ), this, SLOT( close() ) );
128 connect( buttonHelp, SIGNAL( pressed() ), this, SLOT( PushOnHelp() ) );
130 // ------------------------------------------------------------------------
131 void MonCreateBoundaryAn::InitValBoundaryAn()
132 // ------------------------------------------------------------------------
135 // 1. Les coordonnees extremes du maillage
137 if (_aCaseName == QString("")) { return; }
139 HOMARD::HOMARD_Cas_var aCas = _myHomardGen->GetCase(_aCaseName.toStdString().c_str());
140 HOMARD::extrema_var MesExtremes = aCas->GetBoundingBox();
141 int num = MesExtremes->length() ;
143 _Xmin=MesExtremes[0]; _Xmax=MesExtremes[1]; _Xincr=MesExtremes[2];
144 _Ymin=MesExtremes[3]; _Ymax=MesExtremes[4]; _Yincr=MesExtremes[5];
145 _Zmin=MesExtremes[6]; _Zmax=MesExtremes[7]; _Zincr=MesExtremes[8];
146 _DMax=MesExtremes[9];
147 MESSAGE ("_Xmin : " << _Xmin << " _Xmax : " << _Xmax << " _Xincr : " << _Xincr ) ;
148 MESSAGE ("_Ymin : " << _Ymin << " _Ymax : " << _Ymax << " _Yincr : " << _Yincr ) ;
149 MESSAGE ("_Zmin : " << _Zmin << " _Zmax : " << _Zmax << " _Zincr : " << _Zincr) ;
150 MESSAGE ("_DMax : " << _DMax);
152 // 2. Caracteristiques des frontieres
154 _Xcentre=(_Xmin + _Xmax)/2.;
156 _Ycentre=(_Ymin + _Ymax)/2.;
158 _Zcentre=(_Zmin + _Zmax)/2.;
163 // ------------------------------------------------------------------------
164 void MonCreateBoundaryAn::InitMinMax()
165 // ------------------------------------------------------------------------
168 SpinBox_Xaxis->setSingleStep(0.1);
169 SpinBox_Xcentre->setSingleStep(_Xincr);
171 SpinBox_Yaxis->setSingleStep(0.1);
172 SpinBox_Ycentre->setSingleStep(_Yincr);
174 SpinBox_Zaxis->setSingleStep(0.1);
175 SpinBox_Zcentre->setSingleStep(_Zincr);
177 SpinBox_Radius->setSingleStep(_Rayon/10.);
178 SpinBox_Radius->setMinimum(0.);
179 SpinBox_Rayon->setSingleStep(_Rayon/10.);
180 SpinBox_Rayon->setMinimum(0.);
182 // ------------------------------------------------------------------------
183 bool MonCreateBoundaryAn::PushOnApply()
184 // ------------------------------------------------------------------------
185 // Appele lorsque l'un des boutons Ok ou Apply est presse
188 std::cerr << LEBoundaryName->text().trimmed().toStdString() << std::endl;
189 if (LEBoundaryName->text().trimmed()=="")
191 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
192 QObject::tr("HOM_BOUN_NAME") );
198 case 1 : // il s agit d un cylindre
200 if ((_BoundaryAnXcentre != SpinBox_Xcent->value()) or
201 (_BoundaryAnYcentre != SpinBox_Ycent->value()) or
202 (_BoundaryAnZcentre != SpinBox_Zcent->value()) or
203 (_BoundaryAnRayon != SpinBox_Radius->value()) or
204 (_BoundaryAnXaxis != SpinBox_Xaxis->value()) or
205 (_BoundaryAnYaxis != SpinBox_Yaxis->value()) or
206 (_BoundaryAnZaxis != SpinBox_Zaxis->value()) )
209 _BoundaryAnXaxis= SpinBox_Xaxis->value();
210 _BoundaryAnYaxis= SpinBox_Yaxis->value();
211 _BoundaryAnZaxis= SpinBox_Zaxis->value();
212 _BoundaryAnXcentre=SpinBox_Xcent->value();
213 _BoundaryAnYcentre=SpinBox_Ycent->value();
214 _BoundaryAnZcentre=SpinBox_Zcent->value();
215 _BoundaryAnRayon=SpinBox_Radius->value();
216 double daux = _BoundaryAnXaxis*_BoundaryAnXaxis + _BoundaryAnYaxis*_BoundaryAnYaxis + _BoundaryAnZaxis*_BoundaryAnZaxis ;
217 if ( daux < 0.0000001 )
219 QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
220 QObject::tr("HOM_AXE") );
227 case 2 : // il s agit d une sphere
229 if ((_BoundaryAnXcentre != SpinBox_Xcentre->value()) or
230 (_BoundaryAnYcentre != SpinBox_Ycentre->value()) or
231 (_BoundaryAnZcentre != SpinBox_Zcentre->value()) or
232 (_BoundaryAnRayon != SpinBox_Rayon->value()) )
235 _BoundaryAnXcentre=SpinBox_Xcentre->value();
236 _BoundaryAnYcentre=SpinBox_Ycentre->value();
237 _BoundaryAnZcentre=SpinBox_Zcentre->value();
238 _BoundaryAnRayon=SpinBox_Rayon->value();
244 bool bOK = CreateOrUpdateBoundaryAn();
248 // ---------------------------------------------------
249 bool MonCreateBoundaryAn:: CreateOrUpdateBoundaryAn()
250 //----------------------------------------------------
251 // Creation de l'objet boundary
253 if (_aName != LEBoundaryName->text().trimmed())
255 _aName = LEBoundaryName->text().trimmed();
258 case 1 : // il s agit d un cylindre
260 aBoundaryAn = _myHomardGen->CreateBoundaryCylinder(CORBA::string_dup(_aName.toStdString().c_str()), \
261 _BoundaryAnXcentre, _BoundaryAnYcentre, _BoundaryAnZcentre, _BoundaryAnXaxis, _BoundaryAnYaxis, _BoundaryAnZaxis, _BoundaryAnRayon );
264 case 2 : // il s agit d une sphere
266 aBoundaryAn = _myHomardGen->CreateBoundarySphere(CORBA::string_dup(_aName.toStdString().c_str()), \
267 _BoundaryAnXcentre, _BoundaryAnYcentre, _BoundaryAnZcentre, _BoundaryAnRayon);
271 _parent->AddBoundaryAn(_aName);
273 // Mise en place des attributs
274 aBoundaryAn->SetLimit(_Xincr, _Yincr, _Zincr);
276 HOMARD_UTILS::updateObjBrowser();
279 // ------------------------------------------------------------------------
280 void MonCreateBoundaryAn::PushOnOK()
281 // ------------------------------------------------------------------------
283 if (PushOnApply()) this->close();
285 // ------------------------------------------------------------------------
286 void MonCreateBoundaryAn::PushOnHelp()
287 // ------------------------------------------------------------------------
289 HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html#un-cylindre") ) ;
292 // -----------------------------------
293 void MonCreateBoundaryAn::SetNewBoundaryAnName()
294 // -----------------------------------
296 // Recherche d'un nom par defaut qui n'existe pas encore
298 HOMARD::listeBoundarys_var MyBoundaryAns = _myHomardGen->GetAllBoundarysName();
299 int num = 0; QString aBoundaryAnName="";
300 while (aBoundaryAnName=="" )
302 aBoundaryAnName.setNum(num+1) ;
303 aBoundaryAnName.insert(0, QString("Boun_")) ;
304 for ( int i=0; i<MyBoundaryAns->length(); i++)
306 if ( aBoundaryAnName == QString(MyBoundaryAns[i]))
314 LEBoundaryName->clear() ;
315 LEBoundaryName->insert(aBoundaryAnName);
317 // ------------------------------------------------------------------------
318 void MonCreateBoundaryAn::SetCylinder()
319 // ------------------------------------------------------------------------
321 MESSAGE("Debut de SetCylinder")
322 gBCylindre->setVisible(1);
323 gBSphere->setVisible(0);
326 SpinBox_Xcent->setValue(_Xcentre);
327 SpinBox_Xaxis->setValue(0.);
328 SpinBox_Ycent->setValue(_Ycentre);
329 SpinBox_Yaxis->setValue(0.);
330 SpinBox_Zcent->setValue(_Zcentre);
331 SpinBox_Zaxis->setValue(1.);
332 SpinBox_Radius->setValue(_Rayon);
333 // MESSAGE("Fin de SetCylinder")
335 // ------------------------------------------------------------------------
336 void MonCreateBoundaryAn::SetSphere()
337 // ------------------------------------------------------------------------
339 MESSAGE("Debut de SetSphere")
340 gBCylindre->setVisible(0);
341 gBSphere->setVisible(1);
344 SpinBox_Xcentre->setValue(_Xcentre);
345 SpinBox_Ycentre->setValue(_Ycentre);
346 SpinBox_Zcentre->setValue(_Zcentre);
347 SpinBox_Rayon->setValue(_Rayon);
348 // MESSAGE("Fin de SetSphere")