Salome HOME
1970e6e97bca6406c0749d4ec99d2017d3cce283
[modules/geom.git] / src / GEOMGUI / GeometryGUI_OrientationDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : GeometryGUI_OrientationDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "GeometryGUI_OrientationDlg.h"
31
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "QAD_Config.h"
36 #include "utilities.h"
37
38 #include <TopoDS_Compound.hxx>
39 #include <BRep_Builder.hxx>
40 #include <BRepBuilderAPI_MakeEdge.hxx>
41 #include <BRepAdaptor_Surface.hxx>
42 #include <TopExp_Explorer.hxx>
43
44 #include <qbuttongroup.h>
45 #include <qcheckbox.h>
46 #include <qgroupbox.h>
47 #include <qlabel.h>
48 #include <qlineedit.h>
49 #include <qpushbutton.h>
50 #include <qradiobutton.h>
51 #include <qlayout.h>
52 #include <qvariant.h>
53 #include <qtooltip.h>
54 #include <qvalidator.h>
55 #include <qwhatsthis.h>
56 #include <qimage.h>
57 #include <qpixmap.h>
58
59 //=================================================================================
60 // class    : GeometryGUI_OrientationDlg()
61 // purpose  : Constructs a GeometryGUI_OrientationDlg which is a child of 'parent', with the 
62 //            name 'name' and widget flags set to 'f'.
63 //            The dialog will by default be modeless, unless you set 'modal' to
64 //            TRUE to construct a modal dialog.
65 //=================================================================================
66 GeometryGUI_OrientationDlg::GeometryGUI_OrientationDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
67     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
68 {
69     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_ORIENTATION")));
70     QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
71     if ( !name )
72         setName( "GeometryGUI_OrientationDlg" );
73     resize( 303, 242 ); 
74     setCaption( tr( "GEOM_ORIENTATION_TITLE"  ) );
75     setSizeGripEnabled( TRUE );
76     GeometryGUI_OrientationDlgLayout = new QGridLayout( this ); 
77     GeometryGUI_OrientationDlgLayout->setSpacing( 6 );
78     GeometryGUI_OrientationDlgLayout->setMargin( 11 );
79     
80     /***************************************************************/
81     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
82     GroupConstructors->setTitle( tr( "GEOM_ORIENTATION"  ) );
83     GroupConstructors->setExclusive( TRUE );
84     GroupConstructors->setColumnLayout(0, Qt::Vertical );
85     GroupConstructors->layout()->setSpacing( 0 );
86     GroupConstructors->layout()->setMargin( 0 );
87     GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
88     GroupConstructorsLayout->setAlignment( Qt::AlignTop );
89     GroupConstructorsLayout->setSpacing( 6 );
90     GroupConstructorsLayout->setMargin( 11 );
91     Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
92     Constructor1->setText( tr( ""  ) );
93     Constructor1->setPixmap( image0 );
94     Constructor1->setChecked( TRUE );
95     Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
96     Constructor1->setMinimumSize( QSize( 50, 0 ) );
97     GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
98     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
99     GroupConstructorsLayout->addItem( spacer, 0, 1 );
100     GeometryGUI_OrientationDlgLayout->addWidget( GroupConstructors, 0, 0 );    
101     
102     /***************************************************************/
103     GroupButtons = new QGroupBox( this, "GroupButtons" );
104     GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
105     GroupButtons->setTitle( tr( ""  ) );
106     GroupButtons->setColumnLayout(0, Qt::Vertical );
107     GroupButtons->layout()->setSpacing( 0 );
108     GroupButtons->layout()->setMargin( 0 );
109     GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
110     GroupButtonsLayout->setAlignment( Qt::AlignTop );
111     GroupButtonsLayout->setSpacing( 6 );
112     GroupButtonsLayout->setMargin( 11 );
113     buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
114     buttonCancel->setText( tr( "GEOM_BUT_CLOSE"  ) );
115     buttonCancel->setAutoDefault( TRUE );
116     GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
117     buttonApply = new QPushButton( GroupButtons, "buttonApply" );
118     buttonApply->setText( tr( "GEOM_BUT_APPLY"  ) );
119     buttonApply->setAutoDefault( TRUE );
120     GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
121     QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
122     GroupButtonsLayout->addItem( spacer_9, 0, 2 );
123     buttonOk = new QPushButton( GroupButtons, "buttonOk" );
124     buttonOk->setText( tr( "GEOM_BUT_OK"  ) );
125     buttonOk->setAutoDefault( TRUE );
126     buttonOk->setDefault( TRUE );
127     GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
128     GeometryGUI_OrientationDlgLayout->addWidget( GroupButtons, 2, 0 );
129
130     /***************************************************************/
131     GroupC1 = new QGroupBox( this, "GroupC1" );
132     GroupC1->setTitle( tr( "GEOM_ARGUMENTS"  ) );
133     GroupC1->setMinimumSize( QSize( 0, 0 ) );
134     GroupC1->setFrameShape( QGroupBox::Box );
135     GroupC1->setFrameShadow( QGroupBox::Sunken );
136     GroupC1->setColumnLayout(0, Qt::Vertical );
137     GroupC1->layout()->setSpacing( 0 );
138     GroupC1->layout()->setMargin( 0 );
139     GroupC1Layout = new QGridLayout( GroupC1->layout() );
140     GroupC1Layout->setAlignment( Qt::AlignTop );
141     GroupC1Layout->setSpacing( 6 );
142     GroupC1Layout->setMargin( 11 );
143     LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
144     GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
145
146     /* Spin box construction */
147     SpinBox_C1A2 = new GeometryGUI_SpinBox( GroupC1, "GeomSpinBox_C1A2" ) ;
148     GroupC1Layout->addWidget( SpinBox_C1A2, 1, 2 );
149     
150     SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
151     SelectButtonC1A1->setText( tr( ""  ) );
152     SelectButtonC1A1->setPixmap( image1 );
153     SelectButtonC1A1->setToggleButton( FALSE );
154     GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
155     TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
156     TextLabelC1A1->setText( tr( "GEOM_OBJECT"  ) );
157     TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
158     TextLabelC1A1->setFrameShape( QLabel::NoFrame );
159     TextLabelC1A1->setFrameShadow( QLabel::Plain );
160     GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
161     TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
162     TextLabelC1A2->setText( tr( "GEOM_VECTOR_LENGTH"  ) );
163     TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
164     GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
165     CheckBoxReverse = new QCheckBox( GroupC1, "CheckBoxReverse" );
166     CheckBoxReverse->setText( tr( "GEOM_ORIENTATION_OPT"  ) );
167     GroupC1Layout->addMultiCellWidget( CheckBoxReverse, 2, 2, 0, 2 );
168     GeometryGUI_OrientationDlgLayout->addWidget( GroupC1, 1, 0 );
169     /***************************************************************/
170
171     Init(Sel) ; /* Initialisations */
172
173 }
174
175 //=================================================================================
176 // function : ~GeometryGUI_OrientationDlg()
177 // purpose  : Destroys the object and frees any allocated resources
178 //=================================================================================
179 GeometryGUI_OrientationDlg::~GeometryGUI_OrientationDlg()
180 {
181     // no need to delete child widgets, Qt does it all for us
182 }
183
184
185 //=================================================================================
186 // function : Init()
187 // purpose  :
188 //=================================================================================
189 void GeometryGUI_OrientationDlg::Init( SALOME_Selection* Sel )
190 {
191
192   double step ;
193   QString St = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" ) ;
194   step = St.toDouble() ;
195
196   /* min, max, step and decimals for spin boxes */
197   SpinBox_C1A2->RangeStepAndValidator( 0.001, 999.999, step, 3 ) ;
198   SpinBox_C1A2->SetValue( 25.0 ) ; /* = myLength */
199
200   GroupC1->show();
201   myConstructorId = 0 ;
202   Constructor1->setChecked( TRUE );
203   CheckBoxReverse->setChecked( FALSE );
204   myEditCurrentArgument = LineEditC1A1 ;        
205   mySelection = Sel;
206   myGeomGUI = GeometryGUI::GetGeometryGUI() ;
207
208   myLength = 25.0 ;
209   myOkShape = false ;
210   myOkLength = true;
211   mySimulationTopoDs.Nullify() ;
212   myShape.Nullify() ;
213   myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
214
215   // TODO : previous selection into argument ?
216
217   /* Filter definitions */
218   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
219   myGeom = GEOM::GEOM_Gen::_narrow(comp);
220
221   /* signals and slots connections */
222   connect( buttonOk, SIGNAL( clicked() ),     this, SLOT( ClickOnOk() ) );
223   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
224   connect( buttonApply, SIGNAL( clicked() ),  this, SLOT(ClickOnApply() ) );
225   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );  
226   connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
227   connect( CheckBoxReverse, SIGNAL (stateChanged(int) ), this, SLOT( ReverseOrientation(int) ) ) ;
228
229   connect( LineEditC1A1, SIGNAL ( returnPressed() ),                   this, SLOT( LineEditReturnPressed() ) ) ;
230   connect( SpinBox_C1A2, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
231
232   connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;  
233   connect( mySelection, SIGNAL( currentSelectionChanged() ),     this, SLOT( SelectionIntoArgument() ) );
234   /* to close dialog if study change */
235   connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
236  
237   /* Move widget on the botton right corner of main widget */
238   int x, y ;
239   myGeomGUI->DefineDlgPosition( this, x, y ) ;
240   this->move( x, y ) ;
241   this->show() ; /* displays Dialog */
242
243   return ;
244 }
245
246
247 //=================================================================================
248 // function : ConstructorsClicked()
249 // purpose  : Radio button management
250 //=================================================================================
251 void GeometryGUI_OrientationDlg::ConstructorsClicked(int constructorId)
252 {
253   return ;
254 }
255
256 //=================================================================================
257 // function : ClickOnOk()
258 // purpose  :
259 //=================================================================================
260 void GeometryGUI_OrientationDlg::ClickOnOk()
261 {
262   this->ClickOnApply() ;
263   this->ClickOnCancel() ;
264
265   return ;
266 }
267
268 //=================================================================================
269 // function : ClickOnApply()
270 // purpose  :
271 //=================================================================================
272 void GeometryGUI_OrientationDlg::ClickOnApply()
273 {
274   /* Leave simulation display in this method ! */
275   myGeomGUI->GetDesktop()->putInfo( tr("") ) ; 
276   
277   switch(myConstructorId)
278     { 
279     case 0 :
280       { 
281         if(myOkShape && CheckBoxReverse->isChecked() && myOkLength == true ) {    
282           myGeomGUI->MakeOrientationChangeAndDisplay( myGeomShape ) ;
283           CheckBoxReverse->setChecked( FALSE );
284         }
285         break ;
286       }
287     }
288   // accept();
289   return ;
290 }
291
292
293 //=================================================================================
294 // function : ClickOnCancel()
295 // purpose  :
296 //=================================================================================
297 void GeometryGUI_OrientationDlg::ClickOnCancel()
298 {
299   myGeomGUI->EraseSimulationShape() ;
300   mySimulationTopoDs.Nullify() ;
301   disconnect( mySelection, 0, this, 0 );
302   myGeomGUI->ResetState() ;
303   reject() ;
304   return ;
305 }
306
307 //=================================================================================
308 // function : LineEditReturnPressed()
309 // purpose  :
310 //=================================================================================
311 void GeometryGUI_OrientationDlg::LineEditReturnPressed()
312 {
313   QLineEdit* send = (QLineEdit*)sender();  
314   if( send == LineEditC1A1 )
315     myEditCurrentArgument = LineEditC1A1 ;
316   else
317     return ;
318   
319   /* User name of object input management                          */
320   /* If successfull the selection is changed and signal emitted... */
321   /* so SelectionIntoArgument() is automatically called.           */
322   const QString objectUserName = myEditCurrentArgument->text() ;
323   QWidget* thisWidget = (QWidget*)this ;
324   if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
325     myEditCurrentArgument->setText( objectUserName ) ;
326   }
327   return ;
328 }
329
330
331
332 //=================================================================================
333 // function : SelectionIntoArgument()
334 // purpose  : Called when selection as changed or other case
335 //=================================================================================
336 void GeometryGUI_OrientationDlg::SelectionIntoArgument()
337 {
338   myGeomGUI->EraseSimulationShape() ; 
339   this->mySimulationTopoDs.Nullify() ;
340   
341   /* Name of future selection */
342   QString aString = "";
343
344   int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
345   if ( nbSel != 1 ) {
346     if ( myEditCurrentArgument == LineEditC1A1 ) {
347       LineEditC1A1->setText("") ;
348       this->myOkShape = false ;
349     }
350     return ;
351   }
352   
353   /* nbSel == 1 ! */
354   TopoDS_Shape S;
355   Standard_Boolean testResult ;
356   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
357   if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
358     return ;  
359   
360   /* Constructor */
361   if ( myEditCurrentArgument == LineEditC1A1 ) { 
362     myGeomShape = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
363     if( !testResult )
364       return ;
365     LineEditC1A1->setText(aString) ;
366     myShape = S ;
367     myOkShape = true ;
368   }
369   
370   if( myOkShape && myOkLength ) {
371     MakeOrientationSimulationAndDisplay( this->myShape, this->myLength ) ;
372   }
373   return ;
374 }
375
376
377 //=================================================================================
378 // function : SetEditCurrentArgument()
379 // purpose  :
380 //=================================================================================
381 void GeometryGUI_OrientationDlg::SetEditCurrentArgument()
382 {
383   QPushButton* send = (QPushButton*)sender();
384   switch (myConstructorId)
385     {
386     case 0: /* default constructor */
387       { 
388         if(send == SelectButtonC1A1) {
389           LineEditC1A1->setFocus() ;
390           myEditCurrentArgument = LineEditC1A1 ;
391         }
392         SelectionIntoArgument() ;
393         break;
394       }
395     }
396   return ;
397 }
398
399
400 //=================================================================================
401 // function : ValueChangedInSpinBox()
402 // purpose  :
403 //=================================================================================
404 void GeometryGUI_OrientationDlg::ValueChangedInSpinBox( double newValue )
405
406   myGeomGUI->EraseSimulationShape() ;
407   mySimulationTopoDs.Nullify() ;
408   
409   QObject* send = (QObject*)sender() ; 
410   if( send == SpinBox_C1A2 ) {
411     this->myLength = newValue ;
412     myOkLength = true ;
413   } 
414   
415   if ( myConstructorId == 0 && myOkShape && myOkLength == true ) {
416     MakeOrientationSimulationAndDisplay( this->myShape, this->myLength ) ;
417   }
418   return ;
419 }
420
421
422 //=================================================================================
423 // function : DeactivateActiveDialog()
424 // purpose  :
425 //=================================================================================
426 void GeometryGUI_OrientationDlg::DeactivateActiveDialog()
427 {
428   if ( GroupConstructors->isEnabled() ) {
429     GroupConstructors->setEnabled(false) ;
430     GroupButtons->setEnabled(false) ;
431     GroupC1->setEnabled(false) ;
432     disconnect( mySelection, 0, this, 0 );
433     myGeomGUI->EraseSimulationShape() ;
434   }
435   return ;
436 }
437
438
439 //=================================================================================
440 // function : ActivateThisDialog()
441 // purpose  :
442 //=================================================================================
443 void GeometryGUI_OrientationDlg::ActivateThisDialog()
444 {
445   /* Emit a signal to deactivate the active dialog */
446   myGeomGUI->EmitSignalDeactivateDialog() ;
447   GroupConstructors->setEnabled(true) ;
448   GroupButtons->setEnabled(true) ;
449   GroupC1->setEnabled(true) ;
450   
451   connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
452   if( !mySimulationTopoDs.IsNull() )
453     myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
454
455   return ;
456 }
457
458
459 //=================================================================================
460 // function : enterEvent()
461 // purpose  :
462 //=================================================================================
463 void GeometryGUI_OrientationDlg::enterEvent(QEvent* e)
464 {
465   if ( GroupConstructors->isEnabled() )
466     return ;  
467   ActivateThisDialog() ;
468   return ;
469 }
470
471
472
473 //=================================================================================
474 // function : closeEvent()
475 // purpose  :
476 //=================================================================================
477 void GeometryGUI_OrientationDlg::closeEvent( QCloseEvent* e )
478 {
479   /* same than click on cancel button */
480   this->ClickOnCancel() ;
481   return ;
482 }
483
484
485
486 //===========================================================================================
487 // function : ReverseOrientation()
488 // purpose  :
489 //===========================================================================================
490 void GeometryGUI_OrientationDlg::ReverseOrientation(int state)
491 {
492   if( this->myOkShape && myOkLength == true ) {
493     MakeOrientationSimulationAndDisplay( this->myShape, this-> myLength ) ;
494   }
495   return ;
496 }
497
498
499 //===========================================================================================
500 // function : MakeOrientationSimulationAndDisplay()
501 // purpose  : Create 'aCompound1' and 'aCompound2' each contains edges oriented
502 //          : respectively FORWARD and REVERSE for all faces of 'aTopoDS'
503 //          : These edges represent normal vectors on faces of 'aTopoDS'
504 //          : For a unique edge an arrow is displayed to show its orientation.
505 //===========================================================================================
506 void GeometryGUI_OrientationDlg::MakeOrientationSimulationAndDisplay(const TopoDS_Shape& aTopoDS, Standard_Real length )
507 {
508   myGeomGUI->EraseSimulationShape() ; 
509   mySimulationTopoDs.Nullify() ;
510   
511   TopoDS_Compound aCompound1, aCompound2 ;
512   TopoDS_Compound NullComp ;
513   BRep_Builder aBuilder1, aBuilder2;
514   aCompound1 = aCompound2 = NullComp ;
515   aBuilder1.MakeCompound(aCompound1) ;
516   aBuilder2.MakeCompound(aCompound2) ;
517   
518   if( aTopoDS.IsNull() )
519     return ;
520   
521   /* Case of an edge */
522   if( aTopoDS.ShapeType() == TopAbs_EDGE ) {
523     /* Try to display a cone simulation shape to show direction of edge */
524     TopoDS_Shape tmpShape = aTopoDS ;
525     if( this->CheckBoxReverse->isChecked() ) {
526       if( aTopoDS.Orientation() == TopAbs_FORWARD)
527         tmpShape.Orientation(TopAbs_REVERSED) ;
528       else
529         tmpShape.Orientation(TopAbs_FORWARD) ;
530     }
531     if( myGeomGUI->CreateArrowForLinearEdge( tmpShape, mySimulationTopoDs ) ) {
532       myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
533     }
534     return ;
535   }
536   
537
538   gp_Pnt P1, P2 ;
539   gp_Vec V, V1, V2 ;
540   TopExp_Explorer ex( aTopoDS, TopAbs_FACE );
541   int test = 0 ;
542   while (ex.More()) {
543     
544     const TopoDS_Face& F = TopoDS::Face(ex.Current());
545     /* find the center of the minmax */
546     BRepAdaptor_Surface SF(F);
547     Standard_Real u, v, x;
548     
549     u = SF.FirstUParameter();
550     x = SF.LastUParameter();
551     if ( Precision::IsInfinite(u) ) {
552       if( Precision::IsInfinite(x) ) u = 0.0 ;  else u = x ;
553     }
554     else if ( !Precision::IsInfinite(x) )
555       u = (u+x) / 2.0 ;
556     
557     v = SF.FirstVParameter();
558     x = SF.LastVParameter();
559     if ( Precision::IsInfinite(v) ) {
560       if ( Precision::IsInfinite(x) ) v = 0.0 ;  else v = x ;
561     }
562     else if ( !Precision::IsInfinite(x) )
563       v = (v+x) / 2.0 ;
564     
565     SF.D1( u, v, P1, V1, V2 );
566     V = V1.Crossed(V2);
567     x = V.Magnitude();
568     if ( x > 1.e-10 )
569       V.Multiply( length/x );
570     else {
571       V.SetCoord( length/2.0, 0.0, 0.0 ) ;
572       MESSAGE ("Null normal in Orientation " << endl ) ;
573     }
574     
575     P2 = P1;
576     /* test orientation of each face and displays forward (aCompound1) */
577     if( F.Orientation() == TopAbs_FORWARD )
578       P2.Translate(V);
579     else
580       P2.Translate(-V) ;    
581     BRepBuilderAPI_MakeEdge anEdge(P1, P2) ;
582     aBuilder1.Add( aCompound1, anEdge ) ;
583     
584     P2 = P1;
585     /* test orientation of each face and displays forward (aCompound2) */
586     if( F.Orientation() == TopAbs_FORWARD )
587       P2.Translate(-V);
588     else
589       P2.Translate(V) ;    
590     anEdge = BRepBuilderAPI_MakeEdge(P1, P2) ;
591     aBuilder2.Add( aCompound2, anEdge ) ;
592     
593     ex.Next();
594     test++ ;
595   }
596   
597   /* display simulation compounds */
598   if( test > 0 && this->CheckBoxReverse->isChecked() ) {
599     mySimulationTopoDs = aCompound1 ;    
600   }
601   else if ( test > 0 && !CheckBoxReverse->isChecked() ) {
602     mySimulationTopoDs = aCompound2 ;
603   }
604   if(!mySimulationTopoDs.IsNull() )
605     myGeomGUI->DisplaySimulationShape(mySimulationTopoDs) ;
606   
607   return ;
608 }