Salome HOME
Suivi de frontières 2D sur des cônes (suite)
[modules/homard.git] / src / HOMARDGUI / MonCreateBoundaryAn.cxx
1 // Copyright (C) 2011-2012  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 using namespace std;
21
22 #include "MonCreateBoundaryAn.h"
23 #include "MonCreateCase.h"
24
25 #include <QFileDialog>
26 #include <QMessageBox>
27
28 #include "SalomeApp_Tools.h"
29 #include "HOMARDGUI_Utils.h"
30 #include "HomardQtCommun.h"
31 #include <utilities.h>
32
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>
38
39 #include "math.h"
40 #define PI 3.141592653589793
41 // ------------------------------------------------------------------------------------------------------------------------
42 MonCreateBoundaryAn::MonCreateBoundaryAn(MonCreateCase* parent, bool modal,
43                              HOMARD::HOMARD_Gen_var myHomardGen,
44                              QString caseName) :
45 // ------------------------------------------------------------------------------------------------------------------------------
46 /* Constructs a MonCreateBoundaryAn
47    appele pour une vraie creation
48    initialise un cylindre et non une sphere
49 */
50     QDialog(0), Ui_CreateBoundaryAn(),
51     _parent(parent),
52     _aName (""),
53     _aCaseName(caseName),
54     _Xmin(0), _Xmax(0), _Xincr(0), _Ymin(0), _Ymax(0), _Yincr(0), _Zmin(0), _Zmax(0), _Zincr(0), _DMax(0),
55     _Type(1),
56     _BoundaryAnXcentre(0), _BoundaryAnYcentre(0), _BoundaryAnZcentre(0), _BoundaryAnRayon(0),
57     _BoundaryAnXaxis(0), _BoundaryAnYaxis(0), _BoundaryAnZaxis(0),
58     _Xcentre(0), _Ycentre(0), _Zcentre(0), _Rayon(0),
59     _BoundaryAnXcone1(0), _BoundaryAnYcone1(0), _BoundaryAnZcone1(0), _BoundaryAnRayon1(0),
60     _BoundaryAnXcone2(0), _BoundaryAnYcone2(0), _BoundaryAnZcone2(0), _BoundaryAnRayon2(0),
61     _BoundaryAnXaxisCone(0), _BoundaryAnYaxisCone(0), _BoundaryAnZaxisCone(0),
62     _BoundaryAngle(0),
63     Chgt (false)
64     {
65       MESSAGE("Constructeur") ;
66       _myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen);
67       setupUi(this);
68       setModal(modal);
69
70     //  Gestion des icones
71       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
72       QPixmap pix = resMgr->loadPixmap( "HOMARD", "spherepoint.png" );
73       QIcon IS=QIcon(pix);
74       RBSphere->setIcon(IS);
75       QPixmap pix2 = resMgr->loadPixmap( "HOMARD", "cylinderpointvector.png" );
76       QIcon IS2=QIcon(pix2);
77       RBCylindre->setIcon(IS2);
78       QPixmap pix3 = resMgr->loadPixmap( "HOMARD", "cone.png" );
79       QIcon IS3=QIcon(pix3);
80       RBCone->setIcon(IS3);
81       QPixmap pix4 = resMgr->loadPixmap( "HOMARD", "conepointvector.png" );
82       QIcon IS4=QIcon(pix4);
83       RB_Def_angle->setIcon(IS4);
84       QPixmap pix5 = resMgr->loadPixmap( "HOMARD", "conedxyz.png" );
85       QIcon IS5=QIcon(pix5);
86       RB_Def_radius->setIcon(IS5);
87
88       InitConnect( );
89
90       SetNewBoundaryAnName() ;
91       InitValBoundaryAn();          // Cherche les valeurs de la boite englobante le maillage
92       InitMinMax();                 // Initialise les bornes des boutons
93       SetCylinder();                // Propose un cylindre en premier choix
94     }
95 // --------------------------------------------------------------------------------------------------------------
96 MonCreateBoundaryAn::MonCreateBoundaryAn(MonCreateCase* parent,
97                              HOMARD::HOMARD_Gen_var myHomardGen,
98                              QString caseName):
99 // --------------------------------------------------------------------------------------------------------------
100 // Constructeur appele par MonEditBoundaryAn
101 //
102     QDialog(0), Ui_CreateBoundaryAn(),
103      _myHomardGen(myHomardGen),
104     _parent(parent),
105     _aName (""),
106     _aCaseName(caseName),
107     _Type(1),
108     _BoundaryAnXcentre(0), _BoundaryAnYcentre(0), _BoundaryAnZcentre(0), _BoundaryAnRayon(0),
109     _BoundaryAnXaxis(0), _BoundaryAnYaxis(0), _BoundaryAnZaxis(0),
110     // Pour affichage lors de l edition d une BoundaryAn sans nom de Cas
111     _Xcentre(0), _Ycentre(0), _Zcentre(0), _Rayon(0),
112     _Xmin(1), _Xmax(1), _Xincr(1), _Ymin(1), _Ymax(1), _Yincr(1), _Zmin(1), _Zmax(1), _Zincr(1), _DMax(1),
113     Chgt (false)
114     {
115   //  MESSAGE("Debut de  MonCreateBoundaryAn")
116       setupUi(this);
117       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
118       QPixmap pix = resMgr->loadPixmap( "HOMARD", "spherepoint.png" );
119       QIcon IS=QIcon(pix);
120       RBSphere->setIcon(IS);
121       QPixmap pix2 = resMgr->loadPixmap( "HOMARD", "cylinderpointvector.png" );
122       QIcon IS2=QIcon(pix2);
123       RBCylindre->setIcon(IS2);
124       QPixmap pix3 = resMgr->loadPixmap( "HOMARD", "cone.png" );
125       QIcon IS3=QIcon(pix3);
126       RBCone->setIcon(IS3);
127       QPixmap pix4 = resMgr->loadPixmap( "HOMARD", "conepointvector.png" );
128       QIcon IS4=QIcon(pix4);
129       RB_Def_angle->setIcon(IS4);
130       QPixmap pix5 = resMgr->loadPixmap( "HOMARD", "conedxyz.png" );
131       QIcon IS5=QIcon(pix5);
132       RB_Def_radius->setIcon(IS5);
133       setModal(true);
134       InitConnect();
135     }
136
137 // ------------------------------------------------------------------------
138 MonCreateBoundaryAn::~MonCreateBoundaryAn()
139 // ------------------------------------------------------------------------
140 {
141     // no need to delete child widgets, Qt does it all for us
142 }
143 // ------------------------------------------------------------------------
144 void MonCreateBoundaryAn::InitConnect()
145 // ------------------------------------------------------------------------
146 {
147     connect( RBCylindre,    SIGNAL(clicked()) , this, SLOT(SetCylinder()) ) ;
148     connect( RBSphere,      SIGNAL(clicked()) , this, SLOT(SetSphere()) ) ;
149     connect( RBCone,        SIGNAL(clicked()) , this, SLOT(SetCone()) ) ;
150     connect( RB_Def_radius, SIGNAL(clicked()) , this, SLOT(SetConeR()) );
151     connect( RB_Def_angle,  SIGNAL(clicked()) , this, SLOT(SetConeA()) );
152     connect( buttonOk,     SIGNAL( pressed() ), this, SLOT( PushOnOK() ) );
153     connect( buttonApply,  SIGNAL( pressed() ), this, SLOT( PushOnApply() ) );
154     connect( buttonCancel, SIGNAL( pressed() ), this, SLOT( close() ) );
155     connect( buttonHelp,   SIGNAL( pressed() ), this, SLOT( PushOnHelp() ) );
156 }
157 // ------------------------------------------------------------------------
158 void MonCreateBoundaryAn::InitValBoundaryAn()
159 // ------------------------------------------------------------------------
160 {
161 //
162 //  1. Les coordonnees extremes du maillage
163 //
164     if (_aCaseName == QString("")) { return; }
165
166     HOMARD::HOMARD_Cas_var aCas = _myHomardGen->GetCase(_aCaseName.toStdString().c_str());
167     HOMARD::extrema_var  MesExtremes = aCas->GetBoundingBox();
168     int num = MesExtremes->length() ;
169     ASSERT(num == 10);
170     _Xmin=MesExtremes[0]; _Xmax=MesExtremes[1]; _Xincr=MesExtremes[2];
171     _Ymin=MesExtremes[3]; _Ymax=MesExtremes[4]; _Yincr=MesExtremes[5];
172     _Zmin=MesExtremes[6]; _Zmax=MesExtremes[7]; _Zincr=MesExtremes[8];
173     _DMax=MesExtremes[9];
174      MESSAGE ("_Xmin : " << _Xmin << " _Xmax : " << _Xmax << " _Xincr : " << _Xincr ) ;
175      MESSAGE ("_Ymin : " << _Ymin << " _Ymax : " << _Ymax << " _Yincr : " << _Yincr ) ;
176      MESSAGE ("_Zmin : " << _Zmin << " _Zmax : " << _Zmax << " _Zincr : " << _Zincr) ;
177      MESSAGE ("_DMax : " << _DMax);
178
179 //  2. Caracteristiques des frontieres
180 // en X
181     _Xcentre=(_Xmin + _Xmax)/2.;
182 // en Y
183     _Ycentre=(_Ymin + _Ymax)/2.;
184 // en Z
185     _Zcentre=(_Zmin + _Zmax)/2.;
186 // Rayon
187     _Rayon= _DMax/4.;
188 }
189
190 // ------------------------------------------------------------------------
191 void MonCreateBoundaryAn::InitMinMax()
192 // ------------------------------------------------------------------------
193 {
194   // Cylindre
195   // . X du centre
196   SpinBox_Xcent->setValue(_Xcentre);
197   SpinBox_Xcent->setSingleStep(_Xincr);
198   // . Y du centre
199   SpinBox_Ycent->setValue(_Ycentre);
200   SpinBox_Ycent->setSingleStep(_Yincr);
201   // . Z du centre
202   SpinBox_Zcent->setValue(_Zcentre);
203   SpinBox_Zcent->setSingleStep(_Zincr);
204   // . X de l'axe
205   SpinBox_Xaxis->setValue(0.);
206   SpinBox_Xaxis->setSingleStep(0.1);
207   // . Y de l'axe
208   SpinBox_Yaxis->setValue(0.);
209   SpinBox_Yaxis->setSingleStep(0.1);
210   // . Z de l'axe
211   SpinBox_Zaxis->setValue(1.);
212   SpinBox_Zaxis->setSingleStep(0.1);
213   // . Rayon
214   SpinBox_Radius->setValue(_Rayon);
215   SpinBox_Radius->setSingleStep(_Rayon/10.);
216   SpinBox_Radius->setMinimum(0.);
217
218   // Sphere
219   // . X du centre
220   SpinBox_Xcentre->setValue(_Xcentre);
221   SpinBox_Xcentre->setSingleStep(_Xincr);
222   // . Y du centre
223   SpinBox_Ycentre->setValue(_Ycentre);
224   SpinBox_Ycentre->setSingleStep(_Yincr);
225   // . Z du centre
226   SpinBox_Zcentre->setValue(_Zcentre);
227   SpinBox_Zcentre->setSingleStep(_Zincr);
228   // . Rayon
229   SpinBox_Rayon->setValue(_Rayon);
230   SpinBox_Rayon->setSingleStep(_Rayon/10.);
231   SpinBox_Rayon->setMinimum(0.);
232
233   // Cone en rayons
234   // . X des centres
235   _BoundaryAnXcone1 = _Xcentre ;
236   SpinBox_Cone_X1->setSingleStep(_Xincr);
237   _BoundaryAnXcone2 = _Xcentre ;
238   SpinBox_Cone_X2->setSingleStep(_Xincr);
239   // . Y des centres
240   _BoundaryAnYcone1 = _Ycentre ;
241   SpinBox_Cone_Y1->setSingleStep(_Yincr);
242   _BoundaryAnYcone2 = _Ycentre ;
243   SpinBox_Cone_Y2->setSingleStep(_Yincr);
244   // . Z des centres
245   _BoundaryAnZcone1 = _Zmin ;
246   SpinBox_Cone_Z1->setSingleStep(_Zincr);
247   _BoundaryAnZcone2 = _Zmax ;
248   SpinBox_Cone_Z2->setSingleStep(_Zincr);
249   // . Rayons/Angles
250   _BoundaryAnRayon1 = 0. ;
251   SpinBox_Cone_V1->setMinimum(0.);
252   _BoundaryAnRayon2 = _Rayon ;
253   SpinBox_Cone_V2->setSingleStep(_Rayon/10.);
254   SpinBox_Cone_V2->setMinimum(0.);
255
256   // Cone en angle
257   convertRayonAngle(1) ;
258   SpinBox_Cone_X1->setValue(_BoundaryAnXaxisCone);
259   SpinBox_Cone_Y1->setValue(_BoundaryAnYaxisCone);
260   SpinBox_Cone_Z1->setValue(_BoundaryAnZaxisCone);
261   SpinBox_Cone_V1->setValue(_BoundaryAngle);
262   SpinBox_Cone_X2->setValue(_BoundaryAnXorigCone);
263   SpinBox_Cone_Y2->setValue(_BoundaryAnYorigCone);
264   SpinBox_Cone_Z2->setValue(_BoundaryAnZorigCone);
265 }
266 // ------------------------------------------------------------------------
267 bool MonCreateBoundaryAn::PushOnApply()
268 // ------------------------------------------------------------------------
269 // Appele lorsque l'un des boutons Ok ou Apply est presse
270 //
271 {
272   std::cerr << LEBoundaryName->text().trimmed().toStdString() << std::endl;
273   if (LEBoundaryName->text().trimmed()=="")
274   {
275     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
276                               QObject::tr("HOM_BOUN_NAME") );
277     return false;
278   }
279
280   switch (_Type)
281   {
282       case 1 : // il s agit d un cylindre
283       {
284         if ((_BoundaryAnXcentre != SpinBox_Xcent->value())  or
285             (_BoundaryAnYcentre != SpinBox_Ycent->value())  or
286             (_BoundaryAnZcentre != SpinBox_Zcent->value())  or
287             (_BoundaryAnRayon   != SpinBox_Radius->value()) or
288             (_BoundaryAnXaxis   != SpinBox_Xaxis->value()) or
289             (_BoundaryAnYaxis   != SpinBox_Yaxis->value()) or
290             (_BoundaryAnZaxis   != SpinBox_Zaxis->value()) )
291         {
292           Chgt = true;
293           _BoundaryAnXaxis= SpinBox_Xaxis->value();
294           _BoundaryAnYaxis= SpinBox_Yaxis->value();
295           _BoundaryAnZaxis= SpinBox_Zaxis->value();
296           _BoundaryAnXcentre=SpinBox_Xcent->value();
297           _BoundaryAnYcentre=SpinBox_Ycent->value();
298           _BoundaryAnZcentre=SpinBox_Zcent->value();
299           _BoundaryAnRayon=SpinBox_Radius->value();
300         }
301         break;
302       }
303
304       case 2 : // il s agit d une sphere
305       {
306         if ((_BoundaryAnXcentre != SpinBox_Xcentre->value()) or
307             (_BoundaryAnYcentre != SpinBox_Ycentre->value()) or
308             (_BoundaryAnZcentre != SpinBox_Zcentre->value()) or
309             (_BoundaryAnRayon   != SpinBox_Rayon->value())  )
310         {
311            Chgt = true;
312           _BoundaryAnXcentre=SpinBox_Xcentre->value();
313           _BoundaryAnYcentre=SpinBox_Ycentre->value();
314           _BoundaryAnZcentre=SpinBox_Zcentre->value();
315           _BoundaryAnRayon=SpinBox_Rayon->value();
316         }
317         break;
318       }
319
320       case 3 : // il s agit d un cone defini par un axe et un angle
321       {
322         if ((_BoundaryAnXaxisCone != SpinBox_Cone_X1->value())  or
323             (_BoundaryAnYaxisCone != SpinBox_Cone_Y1->value())  or
324             (_BoundaryAnZaxisCone != SpinBox_Cone_Z1->value())  or
325             (_BoundaryAnXorigCone != SpinBox_Cone_X2->value())  or
326             (_BoundaryAnYorigCone != SpinBox_Cone_Y2->value())  or
327             (_BoundaryAnZorigCone != SpinBox_Cone_Z2->value())  or
328             (_BoundaryAngle       != SpinBox_Cone_V1->value()) )
329         {
330            Chgt = true;
331           _BoundaryAnXaxisCone = SpinBox_Cone_X1->value() ;
332           _BoundaryAnYaxisCone = SpinBox_Cone_Y1->value() ;
333           _BoundaryAnZaxisCone = SpinBox_Cone_Z1->value() ;
334           _BoundaryAnXorigCone = SpinBox_Cone_X2->value() ;
335           _BoundaryAnYorigCone = SpinBox_Cone_Y2->value() ;
336           _BoundaryAnZorigCone = SpinBox_Cone_Z2->value() ;
337           _BoundaryAngle       = SpinBox_Cone_V1->value() ;
338         }
339         break;
340       }
341
342       case 4 : // il s agit d un cone defini par les 2 rayons
343       {
344         if ((_BoundaryAnXcone1 != SpinBox_Cone_X1->value())  or
345             (_BoundaryAnYcone1 != SpinBox_Cone_Y1->value())  or
346             (_BoundaryAnZcone1 != SpinBox_Cone_Z1->value())  or
347             (_BoundaryAnRayon1 != SpinBox_Cone_V1->value())  or
348             (_BoundaryAnXcone2 != SpinBox_Cone_X2->value())  or
349             (_BoundaryAnYcone2 != SpinBox_Cone_Y2->value())  or
350             (_BoundaryAnZcone2 != SpinBox_Cone_Z2->value())  or
351             (_BoundaryAnRayon2 != SpinBox_Cone_V2->value()) )
352         {
353            Chgt = true;
354           _BoundaryAnXcone1 = SpinBox_Cone_X1->value() ;
355           _BoundaryAnYcone1 = SpinBox_Cone_Y1->value() ;
356           _BoundaryAnZcone1 = SpinBox_Cone_Z1->value() ;
357           _BoundaryAnRayon1 = SpinBox_Cone_V1->value() ;
358           _BoundaryAnXcone2 = SpinBox_Cone_X2->value() ;
359           _BoundaryAnYcone2 = SpinBox_Cone_Y2->value() ;
360           _BoundaryAnZcone2 = SpinBox_Cone_Z2->value() ;
361           _BoundaryAnRayon2 = SpinBox_Cone_V2->value() ;
362         }
363         break;
364       }
365  }
366
367   bool bOK = CreateOrUpdateBoundaryAn();
368
369   if ( bOK ) { HOMARD_UTILS::updateObjBrowser() ; }
370
371   return bOK;
372
373 }
374 // ---------------------------------------------------
375 bool MonCreateBoundaryAn:: CreateOrUpdateBoundaryAn()
376 //----------------------------------------------------
377 //  Creation de l'objet boundary
378 {
379 //   if (_aName != LEBoundaryName->text().trimmed())
380 //   {
381     _aName = LEBoundaryName->text().trimmed();
382     switch (_Type)
383     {
384       case 1 : // il s agit d un cylindre
385       {
386         try
387         {
388           aBoundaryAn = _myHomardGen->CreateBoundaryCylinder(CORBA::string_dup(_aName.toStdString().c_str()), \
389           _BoundaryAnXcentre, _BoundaryAnYcentre, _BoundaryAnZcentre, _BoundaryAnXaxis, _BoundaryAnYaxis, _BoundaryAnZaxis, _BoundaryAnRayon );
390         }
391         catch( SALOME::SALOME_Exception& S_ex )
392         {
393           QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
394                                     QObject::tr(CORBA::string_dup(S_ex.details.text)) );
395           return false ;
396         }
397         break;
398       }
399       case 2 : // il s agit d une sphere
400       {
401         try
402         {
403           aBoundaryAn = _myHomardGen->CreateBoundarySphere(CORBA::string_dup(_aName.toStdString().c_str()), \
404           _BoundaryAnXcentre, _BoundaryAnYcentre, _BoundaryAnZcentre, _BoundaryAnRayon);
405         }
406         catch( SALOME::SALOME_Exception& S_ex )
407         {
408           QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
409                                     QObject::tr(CORBA::string_dup(S_ex.details.text)) );
410           return false ;
411         }
412         break;
413       }
414       case 3 : // il s agit d un cone defini par un axe et un angle
415       {
416         try
417         {
418           aBoundaryAn = _myHomardGen->CreateBoundaryConeA(CORBA::string_dup(_aName.toStdString().c_str()), \
419           _BoundaryAnXaxisCone, _BoundaryAnYaxisCone, _BoundaryAnZaxisCone, _BoundaryAngle, \
420           _BoundaryAnXorigCone, _BoundaryAnYorigCone, _BoundaryAnYorigCone);
421         }
422         catch( SALOME::SALOME_Exception& S_ex )
423         {
424           QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
425                                     QObject::tr(CORBA::string_dup(S_ex.details.text)) );
426           return false ;
427         }
428         break;
429       }
430       case 4 : // il s agit d un cone defini par les 2 rayons
431       {
432         try
433         {
434           aBoundaryAn = _myHomardGen->CreateBoundaryConeR(CORBA::string_dup(_aName.toStdString().c_str()), \
435           _BoundaryAnXcone1, _BoundaryAnYcone1, _BoundaryAnZcone1, _BoundaryAnRayon1, \
436           _BoundaryAnXcone2, _BoundaryAnYcone2, _BoundaryAnZcone2, _BoundaryAnRayon2);
437         }
438         catch( SALOME::SALOME_Exception& S_ex )
439         {
440           QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
441                                     QObject::tr(CORBA::string_dup(S_ex.details.text)) );
442           return false ;
443         }
444         break;
445       }
446     }
447     _parent->AddBoundaryAn(_aName);
448 // Mise en place des attributs
449     aBoundaryAn->SetLimit(_Xincr, _Yincr, _Zincr);
450
451     return true;
452 //   }
453 //   else { return false ; }
454 }
455 // ------------------------------------------------------------------------
456 void MonCreateBoundaryAn::PushOnOK()
457 // ------------------------------------------------------------------------
458 {
459      if (PushOnApply()) this->close();
460 }
461 // ------------------------------------------------------------------------
462 void MonCreateBoundaryAn::PushOnHelp()
463 // ------------------------------------------------------------------------
464 {
465   HOMARD_UTILS::PushOnHelp(QString("gui_create_boundary.html#un-cylindre") ) ;
466 }
467
468 // -----------------------------------
469 void MonCreateBoundaryAn::SetNewBoundaryAnName()
470 // -----------------------------------
471 {
472 // Recherche d'un nom par defaut qui n'existe pas encore
473
474   HOMARD::listeBoundarys_var  MyBoundaryAns = _myHomardGen->GetAllBoundarysName();
475   int num = 0; QString aBoundaryAnName="";
476   while (aBoundaryAnName=="" )
477   {
478     aBoundaryAnName.setNum(num+1) ;
479     aBoundaryAnName.insert(0, QString("Boun_")) ;
480     for ( int i=0; i<MyBoundaryAns->length(); i++)
481     {
482       if ( aBoundaryAnName ==  QString(MyBoundaryAns[i]))
483       {
484           num=num+1;
485           aBoundaryAnName="";
486           break;
487       }
488    }
489   }
490   LEBoundaryName->clear() ;
491   LEBoundaryName->insert(aBoundaryAnName);
492 }
493 // ------------------------------------------------------------------------
494 void MonCreateBoundaryAn::SetCylinder()
495 // ------------------------------------------------------------------------
496 {
497   MESSAGE("Debut de SetCylinder")
498   gBCylindre->setVisible(1);
499   gBSphere->setVisible(0);
500   gBCone->setVisible(0);
501   adjustSize();
502   _Type=1;
503 //   MESSAGE("Fin de SetCylinder")
504 }
505 // ------------------------------------------------------------------------
506 void MonCreateBoundaryAn::SetSphere()
507 // ------------------------------------------------------------------------
508 {
509   MESSAGE("Debut de SetSphere")
510   gBCylindre->setVisible(0);
511   gBSphere->setVisible(1);
512   gBCone->setVisible(0);
513   adjustSize();
514   _Type=2;
515 //   MESSAGE("Fin de SetSphere")
516 }
517 // ------------------------------------------------------------------------
518 void MonCreateBoundaryAn::SetConeR()
519 // ------------------------------------------------------------------------
520 {
521   MESSAGE("Debut de SetConeR")
522 //
523 // Stockage et conversion des valeurs si elles ont change
524   if ((_BoundaryAnXaxisCone != SpinBox_Cone_X1->value())  or
525       (_BoundaryAnYaxisCone != SpinBox_Cone_Y1->value())  or
526       (_BoundaryAnZaxisCone != SpinBox_Cone_Z1->value())  or
527       (_BoundaryAnXorigCone != SpinBox_Cone_X2->value())  or
528       (_BoundaryAnYorigCone != SpinBox_Cone_Y2->value())  or
529       (_BoundaryAnZorigCone != SpinBox_Cone_Z2->value())  or
530       (_BoundaryAngle       != SpinBox_Cone_V1->value()) )
531   {
532     MESSAGE("Stockage et conversion")
533     _BoundaryAnXaxisCone = SpinBox_Cone_X1->value() ;
534     _BoundaryAnYaxisCone = SpinBox_Cone_Y1->value() ;
535     _BoundaryAnZaxisCone = SpinBox_Cone_Z1->value() ;
536     _BoundaryAnXorigCone = SpinBox_Cone_X2->value() ;
537     _BoundaryAnYorigCone = SpinBox_Cone_Y2->value() ;
538     _BoundaryAnZorigCone = SpinBox_Cone_Z2->value() ;
539     _BoundaryAngle       = SpinBox_Cone_V1->value() ;
540     convertRayonAngle(-1) ;
541   }
542 //
543   _Type=4;
544 //
545   TLCone_X1->setText(QApplication::translate("CreateBoundaryAn", "X centre 1", 0, QApplication::UnicodeUTF8));
546   SpinBox_Cone_X1->setValue(_BoundaryAnXcone1);
547   TLCone_Y1->setText(QApplication::translate("CreateBoundaryAn", "Y centre 1", 0, QApplication::UnicodeUTF8));
548   SpinBox_Cone_Y1->setValue(_BoundaryAnYcone1);
549   TLCone_Z1->setText(QApplication::translate("CreateBoundaryAn", "Z centre 1", 0, QApplication::UnicodeUTF8));
550   SpinBox_Cone_Z1->setValue(_BoundaryAnZcone1);
551 //
552   TLCone_V1->setText(QApplication::translate("CreateBoundaryAn", "Radius 1", 0, QApplication::UnicodeUTF8));
553   SpinBox_Cone_V1->setSingleStep(_Rayon/10.);
554   SpinBox_Cone_V1->setMaximum(100000.*_DMax);
555   SpinBox_Cone_V1->setValue(_BoundaryAnRayon1);
556 //
557   TLCone_X2->setText(QApplication::translate("CreateBoundaryAn", "X centre 2", 0, QApplication::UnicodeUTF8));
558   SpinBox_Cone_X2->setValue(_BoundaryAnXcone2);
559   TLCone_Y2->setText(QApplication::translate("CreateBoundaryAn", "Y centre 2", 0, QApplication::UnicodeUTF8));
560   SpinBox_Cone_Y2->setValue(_BoundaryAnYcone2);
561   TLCone_Z2->setText(QApplication::translate("CreateBoundaryAn", "Z centre 2", 0, QApplication::UnicodeUTF8));
562   SpinBox_Cone_Z2->setValue(_BoundaryAnZcone2);
563 //
564   TLCone_V2->setVisible(1);
565   SpinBox_Cone_V2->setVisible(1);
566   TLCone_V2->setText(QApplication::translate("CreateBoundaryAn", "Radius 2", 0, QApplication::UnicodeUTF8));
567   SpinBox_Cone_V2->setValue(_BoundaryAnRayon2);
568 //
569 //   MESSAGE("Fin de SetConeR")
570 }
571 // ------------------------------------------------------------------------
572 void MonCreateBoundaryAn::SetConeA()
573 // ------------------------------------------------------------------------
574 {
575   MESSAGE("Debut de SetConeA")
576 // Stockage et conversion des valeurs si elles ont change
577   if ((_BoundaryAnXcone1 != SpinBox_Cone_X1->value())  or
578       (_BoundaryAnYcone1 != SpinBox_Cone_Y1->value())  or
579       (_BoundaryAnZcone1 != SpinBox_Cone_Z1->value())  or
580       (_BoundaryAnRayon1 != SpinBox_Cone_V1->value())  or
581       (_BoundaryAnXcone2 != SpinBox_Cone_X2->value())  or
582       (_BoundaryAnYcone2 != SpinBox_Cone_Y2->value())  or
583       (_BoundaryAnZcone2 != SpinBox_Cone_Z2->value())  or
584       (_BoundaryAnRayon2 != SpinBox_Cone_V2->value()) )
585   {
586     MESSAGE("Stockage et conversion")
587     _BoundaryAnXcone1 = SpinBox_Cone_X1->value() ;
588     _BoundaryAnYcone1 = SpinBox_Cone_Y1->value() ;
589     _BoundaryAnZcone1 = SpinBox_Cone_Z1->value() ;
590     _BoundaryAnRayon1 = SpinBox_Cone_V1->value() ;
591     _BoundaryAnXcone2 = SpinBox_Cone_X2->value() ;
592     _BoundaryAnYcone2 = SpinBox_Cone_Y2->value() ;
593     _BoundaryAnZcone2 = SpinBox_Cone_Z2->value() ;
594     _BoundaryAnRayon2 = SpinBox_Cone_V2->value() ;
595     convertRayonAngle(1) ;
596   }
597 //
598   _Type=3;
599 //
600   TLCone_X1->setText(QApplication::translate("CreateBoundaryAn", "X axis", 0, QApplication::UnicodeUTF8));
601   SpinBox_Cone_X1->setValue(_BoundaryAnXaxisCone);
602   TLCone_Y1->setText(QApplication::translate("CreateBoundaryAn", "Y axis", 0, QApplication::UnicodeUTF8));
603   SpinBox_Cone_Y1->setValue(_BoundaryAnYaxisCone);
604   TLCone_Z1->setText(QApplication::translate("CreateBoundaryAn", "Z axis", 0, QApplication::UnicodeUTF8));
605   SpinBox_Cone_Z1->setValue(_BoundaryAnZaxisCone);
606 //
607   TLCone_X2->setText(QApplication::translate("CreateBoundaryAn", "X centre", 0, QApplication::UnicodeUTF8));
608   SpinBox_Cone_X2->setValue(_BoundaryAnXorigCone);
609   TLCone_Y2->setText(QApplication::translate("CreateBoundaryAn", "Y centre", 0, QApplication::UnicodeUTF8));
610   SpinBox_Cone_Y2->setValue(_BoundaryAnYorigCone);
611   TLCone_Z2->setText(QApplication::translate("CreateBoundaryAn", "Z centre", 0, QApplication::UnicodeUTF8));
612   SpinBox_Cone_Z2->setValue(_BoundaryAnZorigCone);
613 //
614   TLCone_V1->setText(QApplication::translate("CreateBoundaryAn", "Angle", 0, QApplication::UnicodeUTF8));
615   SpinBox_Cone_V1->setValue(_BoundaryAngle);
616   SpinBox_Cone_V1->setSingleStep(1.);
617   SpinBox_Cone_V1->setMaximum(90.);
618 //
619   TLCone_V2->setVisible(0);
620   SpinBox_Cone_V2->setVisible(0);
621 //   MESSAGE("Fin de SetConeA")
622 }
623
624
625 // ------------------------------------------------------------------------
626 void MonCreateBoundaryAn::SetCone()
627 // ------------------------------------------------------------------------
628 {
629   MESSAGE("Debut de SetCone")
630   gBCylindre->setVisible(0);
631   gBSphere->setVisible(0);
632   gBCone->setVisible(1);
633 //
634   adjustSize();
635   if ( RB_Def_radius->isChecked() )
636   {
637     SetConeR();
638   }
639   else
640   {
641     SetConeA();
642   }
643 //   MESSAGE("Fin de SetCone")
644 }
645 // ------------------------------------------------------------------------
646 void MonCreateBoundaryAn::convertRayonAngle(int option)
647 // ------------------------------------------------------------------------
648 // Conversion entre les deux formulations du cone :
649 // par deux rayons ou avec un axe et un angle.
650 // Voir sfcoi1 de HOMARD
651 {
652   MESSAGE("Debut de convertRayonAngle, option = "<<option)
653 //
654 //         o
655 //         !    .
656 //         !        .
657 //       RA!            .
658 //         !                o
659 //         !              RB!   .
660 //         !                !       .
661 //         A----------------B----------O
662 //
663 //   Thales : RA/RB = AO/BO  ==> BO = AB*RB/(RA-RB)
664 //   Angle  : tg(alpha) = RA/AO
665 //
666   double daux ;
667 // De rayon vers angle :
668   if ( option == 1 )
669   {
670     double xa, ya, za, ra ;
671     double xb, yb, zb, rb ;
672 // Positionnement de A vers B, avec RA>RB
673     if ( _BoundaryAnRayon1 > _BoundaryAnRayon2 )
674     {
675       xa = _BoundaryAnXcone1 ;
676       ya = _BoundaryAnYcone1 ;
677       za = _BoundaryAnZcone1 ;
678       ra = _BoundaryAnRayon1 ;
679       xb = _BoundaryAnXcone2 ;
680       yb = _BoundaryAnYcone2 ;
681       zb = _BoundaryAnZcone2 ;
682       rb = _BoundaryAnRayon2 ;
683     }
684     else
685     {
686       xa = _BoundaryAnXcone2 ;
687       ya = _BoundaryAnYcone2 ;
688       za = _BoundaryAnZcone2 ;
689       ra = _BoundaryAnRayon2 ;
690       xb = _BoundaryAnXcone1 ;
691       yb = _BoundaryAnYcone1 ;
692       zb = _BoundaryAnZcone1 ;
693       rb = _BoundaryAnRayon1 ;
694     }
695 // Axe : relie les deux centres, de A vers B.  L'axe est normalise
696     _BoundaryAnXaxisCone = xb - xa ;
697     _BoundaryAnYaxisCone = yb - ya ;
698     _BoundaryAnZaxisCone = zb - za ;
699     daux = sqrt ( _BoundaryAnXaxisCone*_BoundaryAnXaxisCone + _BoundaryAnYaxisCone*_BoundaryAnYaxisCone + _BoundaryAnZaxisCone*_BoundaryAnZaxisCone ) ;
700     _BoundaryAnXaxisCone = _BoundaryAnXaxisCone/daux ;
701     _BoundaryAnYaxisCone = _BoundaryAnYaxisCone/daux ;
702     _BoundaryAnZaxisCone = _BoundaryAnZaxisCone/daux ;
703 // Origine
704     daux = daux * rb / (ra-rb) ;
705     _BoundaryAnXorigCone = xb + daux*_BoundaryAnXaxisCone ;
706     _BoundaryAnYorigCone = yb + daux*_BoundaryAnYaxisCone ;
707     _BoundaryAnZorigCone = zb + daux*_BoundaryAnZaxisCone ;
708 // Angle en degre
709     daux = ra / sqrt((_BoundaryAnXorigCone-xa)*(_BoundaryAnXorigCone-xa) + (_BoundaryAnYorigCone-ya)*(_BoundaryAnYorigCone-ya) + (_BoundaryAnZorigCone-za)*(_BoundaryAnZorigCone-za) ) ;
710     _BoundaryAngle = atan(daux)*180./PI ;
711   }
712 // D'angle vers rayon :
713   else
714   {
715     double xax, yax, zax ;
716 // L'axe est normalise
717     daux = sqrt ( _BoundaryAnXaxisCone*_BoundaryAnXaxisCone + _BoundaryAnYaxisCone*_BoundaryAnYaxisCone + _BoundaryAnZaxisCone*_BoundaryAnZaxisCone ) ;
718     xax = _BoundaryAnXaxisCone/daux ;
719     yax = _BoundaryAnYaxisCone/daux ;
720     zax = _BoundaryAnZaxisCone/daux ;
721 // Centre 1 : l'origine
722     _BoundaryAnXcone1 = _BoundaryAnXorigCone ;
723     _BoundaryAnYcone1 = _BoundaryAnYorigCone ;
724     _BoundaryAnZcone1 = _BoundaryAnZorigCone ;
725 // Rayon 1 : nul
726     _BoundaryAnRayon1 = 0. ;
727 // Centre 2 : l'origine decalee d'une longueur arbitraire le long de l'axe
728     _BoundaryAnXcone2 = _BoundaryAnXorigCone + _DMax*xax ;
729     _BoundaryAnYcone2 = _BoundaryAnYorigCone + _DMax*yax ;
730     _BoundaryAnZcone2 = _BoundaryAnZorigCone + _DMax*zax ;
731 // Rayon 2 : a calculer
732     _BoundaryAnRayon2 = _DMax*tan(_BoundaryAngle*PI/180.) ;
733   }
734 //   MESSAGE("Fin de convertRayonAngle")
735 }
736
737