Salome HOME
NRI : Merge from V1_2.
[modules/geom.git] / src / GEOMGUI / GeometryGUI_DistanceDlg.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_DistanceDlg.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "GeometryGUI_DistanceDlg.h"
31
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "QAD_RightFrame.h"
36 #include "utilities.h"
37
38 #include "OCCViewer_Viewer3d.h"
39 #include "OCCViewer_ViewFrame.h"
40
41 // Open CASCADE Includes
42 #include <BRepBuilderAPI_MakeEdge.hxx>
43 #include <BRepBuilderAPI_MakeVertex.hxx>
44 #include <AIS_ListIteratorOfListOfInteractive.hxx>
45
46 // QT Includes
47 #include <qmessagebox.h>
48 #include <qbuttongroup.h>
49 #include <qframe.h>
50 #include <qgroupbox.h>
51 #include <qlabel.h>
52 #include <qlineedit.h>
53 #include <qpushbutton.h>
54 #include <qradiobutton.h>
55 #include <qlayout.h>
56 #include <qvariant.h>
57 #include <qtooltip.h>
58 #include <qwhatsthis.h>
59 #include <qimage.h>
60 #include <qpixmap.h>
61 #include <qevent.h>
62
63
64 //=================================================================================
65 // class    : GeometryGUI_DistanceDlg()
66 // purpose  : Constructs a GeometryGUI_DistanceDlg which is a child of 'parent', with the 
67 //            name 'name' and widget flags set to 'f'.
68 //            The dialog will by default be modeless, unless you set 'modal' to
69 //            TRUE to construct a modal dialog.
70 //=================================================================================
71 GeometryGUI_DistanceDlg::GeometryGUI_DistanceDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
72     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
73 {
74     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_MINDIST")));
75     QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
76
77     if ( !name )
78         setName( "GeometryGUI_DistanceDlg" );
79     resize( 322, 220 ); 
80     setCaption( tr( "GEOM_MINDIST_TITLE" ) );
81     setSizeGripEnabled( TRUE );
82
83     GeometryGUI_DistanceDlgLayout = new QGridLayout( this ); 
84     GeometryGUI_DistanceDlgLayout->setSpacing( 6 );
85     GeometryGUI_DistanceDlgLayout->setMargin( 11 );
86
87     /***************************************************************/
88     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
89     GroupConstructors->setTitle( tr( "GEOM_DISTANCE"  ) );
90     GroupConstructors->setExclusive( TRUE );
91     GroupConstructors->setColumnLayout(0, Qt::Vertical );
92     GroupConstructors->layout()->setSpacing( 0 );
93     GroupConstructors->layout()->setMargin( 0 );
94     GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
95     GroupConstructorsLayout->setAlignment( Qt::AlignTop );
96     GroupConstructorsLayout->setSpacing( 6 );
97     GroupConstructorsLayout->setMargin( 11 );
98     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
99     GroupConstructorsLayout->addItem( spacer, 0, 1 );
100     Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
101     Constructor1->setText( tr( ""  ) );
102     Constructor1->setPixmap( image0 );
103     Constructor1->setChecked( TRUE );
104     Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
105     GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
106     GeometryGUI_DistanceDlgLayout->addWidget( GroupConstructors, 0, 0 );
107
108     /***************************************************************/
109     GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
110     GroupConstructor1->setTitle( tr( "GEOM_MINDIST_OBJ"  ) );
111     GroupConstructor1->setColumnLayout(0, Qt::Vertical );
112     GroupConstructor1->layout()->setSpacing( 0 );
113     GroupConstructor1->layout()->setMargin( 0 );
114     GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
115     GroupConstructor1Layout->setAlignment( Qt::AlignTop );
116     GroupConstructor1Layout->setSpacing( 6 );
117     GroupConstructor1Layout->setMargin( 11 );
118     LineEditC1A2Shape = new QLineEdit( GroupConstructor1, "LineEditC1A2Shape" );
119     LineEditC1A2Shape->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A2Shape->sizePolicy().hasHeightForWidth() ) );
120     GroupConstructor1Layout->addWidget( LineEditC1A2Shape, 1, 2 );
121     LineEditC1A1Shape = new QLineEdit( GroupConstructor1, "LineEditC1A1Shape" );
122     LineEditC1A1Shape->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1Shape->sizePolicy().hasHeightForWidth() ) );
123     GroupConstructor1Layout->addWidget( LineEditC1A1Shape, 0, 2 );
124     SelectButtonC1A1Shape = new QPushButton( GroupConstructor1, "SelectButtonC1A1Shape" );
125     SelectButtonC1A1Shape->setText( tr( ""  ) );
126     SelectButtonC1A1Shape->setPixmap( image1 );
127     GroupConstructor1Layout->addWidget( SelectButtonC1A1Shape, 0, 1 );
128     SelectButtonC1A2Shape = new QPushButton( GroupConstructor1, "SelectButtonC1A2Shape" );
129     SelectButtonC1A2Shape->setText( tr( ""  ) );
130     SelectButtonC1A2Shape->setPixmap( image1 );
131     GroupConstructor1Layout->addWidget( SelectButtonC1A2Shape, 1, 1 );
132     TextLabelC1A2Shape = new QLabel( GroupConstructor1, "TextLabelC1A2Shape" );
133     TextLabelC1A2Shape->setText( tr( "GEOM_OBJECT_I"  ).arg("2") );
134     TextLabelC1A2Shape->setMinimumSize( QSize( 50, 0 ) );
135     TextLabelC1A2Shape->setFrameShape( QLabel::NoFrame );
136     TextLabelC1A2Shape->setFrameShadow( QLabel::Plain );
137     GroupConstructor1Layout->addWidget( TextLabelC1A2Shape, 1, 0 );
138     TextLabelC1A1Shape = new QLabel( GroupConstructor1, "TextLabelC1A1Shape" );
139     TextLabelC1A1Shape->setText( tr( "GEOM_OBJECT_I"  ).arg("1") );
140     TextLabelC1A1Shape->setMinimumSize( QSize( 50, 0 ) );
141     TextLabelC1A1Shape->setFrameShape( QLabel::NoFrame );
142     TextLabelC1A1Shape->setFrameShadow( QLabel::Plain );
143     GroupConstructor1Layout->addWidget( TextLabelC1A1Shape, 0, 0 );
144     GeometryGUI_DistanceDlgLayout->addWidget( GroupConstructor1, 1, 0 );
145
146     TextLabel_Length = new QLabel( GroupConstructor1, "TextLabel_Length" );
147     TextLabel_Length->setText( tr( "GEOM_LENGTH"  ) );
148     TextLabel_Length->setMinimumSize( QSize( 50, 0 ) );
149     TextLabel_Length->setFrameShape( QLabel::NoFrame );
150     TextLabel_Length->setFrameShadow( QLabel::Plain );
151     GroupConstructor1Layout->addWidget( TextLabel_Length, 2, 0 );
152     LineEdit_Length = new QLineEdit( GroupConstructor1, "LineEdit_Length" );
153     LineEdit_Length->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEdit_Length->sizePolicy().hasHeightForWidth() ) );
154     //    LineEdit_Length->setEnabled( FALSE );
155     LineEdit_Length->setReadOnly( TRUE );
156     GroupConstructor1Layout->addWidget( LineEdit_Length, 2, 2 );
157
158     /***************************************************************/
159     GroupButtons = new QGroupBox( this, "GroupButtons" );
160     GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
161     GroupButtons->setTitle( tr( ""  ) );
162     GroupButtons->setColumnLayout(0, Qt::Vertical );
163     GroupButtons->layout()->setSpacing( 0 );
164     GroupButtons->layout()->setMargin( 0 );
165     GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
166     GroupButtonsLayout->setAlignment( Qt::AlignTop );
167     GroupButtonsLayout->setSpacing( 6 );
168     GroupButtonsLayout->setMargin( 11 );
169     buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
170     buttonCancel->setText( tr( "GEOM_BUT_CLOSE"  ) );
171     buttonCancel->setAutoDefault( TRUE );
172     GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
173     buttonApply = new QPushButton( GroupButtons, "buttonApply" );
174     buttonApply->setText( tr( "GEOM_BUT_APPLY"  ) );
175     buttonApply->setAutoDefault( TRUE );
176     GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
177     QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
178     GroupButtonsLayout->addItem( spacer_9, 0, 2 );
179     buttonOk = new QPushButton( GroupButtons, "buttonOk" );
180     buttonOk->setText( tr( "GEOM_BUT_OK"  ) );
181     buttonOk->setAutoDefault( TRUE );
182     buttonOk->setDefault( TRUE );
183     GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
184     GeometryGUI_DistanceDlgLayout->addWidget( GroupButtons, 2, 0 ); 
185
186     /* Initialisation */
187     Init( Sel ) ; 
188 }
189
190
191 //=================================================================================
192 // function : ~GeometryGUI_DistanceDlg()
193 // purpose  : Destroys the object and frees any allocated resources
194 //=================================================================================
195 GeometryGUI_DistanceDlg::~GeometryGUI_DistanceDlg()
196 {  
197   /* no need to delete child widgets, Qt does it all for us */
198   this->destroy(TRUE, TRUE) ;
199 }
200
201
202
203 //=================================================================================
204 // function : Init()
205 // purpose  :
206 //=================================================================================
207 void GeometryGUI_DistanceDlg::Init( SALOME_Selection* Sel )
208 {  
209   mySelection = Sel ;
210   myShape1.Nullify() ;
211   myShape2.Nullify() ;
212   myConstructorId = 0 ;
213   
214   myGeomGUI = GeometryGUI::GetGeometryGUI() ;
215
216   GroupConstructor1->show();
217   myConstructorId = 0 ;
218   myEditCurrentArgument = LineEditC1A1Shape ;   
219   Constructor1->setChecked( TRUE );
220   myOkShape1 = myOkShape2 = false ;
221
222   myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
223
224   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
225   myGeom = GEOM::GEOM_Gen::_narrow(comp);
226   
227   // TODO previous selection into argument ?
228
229   /* signals and slots connections */
230   connect( buttonOk, SIGNAL( clicked() ),     this, SLOT( ClickOnOk() ) );
231   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
232   connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
233   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
234   connect( SelectButtonC1A1Shape, SIGNAL (clicked() ),  this, SLOT( SetEditCurrentArgument() ) ) ;
235   connect( SelectButtonC1A2Shape, SIGNAL (clicked() ),  this, SLOT( SetEditCurrentArgument() ) ) ;
236
237   connect( LineEditC1A1Shape, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
238   connect( LineEditC1A2Shape, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
239
240   connect( mySelection, SIGNAL( currentSelectionChanged() ),     this, SLOT( SelectionIntoArgument() ) );
241   connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
242   /* to close dialog if study change */
243   connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
244
245   /* Move widget on the botton right corner of main widget */
246   int x, y ;
247   myGeomGUI->DefineDlgPosition( this, x, y ) ;
248   this->move( x, y ) ; 
249   this->show() ; /* Displays Dialog */ 
250
251   return ;
252 }
253
254
255
256 //=================================================================================
257 // function : ConstructorsClicked()
258 // purpose  : Radio button management
259 //=================================================================================
260 void GeometryGUI_DistanceDlg::ConstructorsClicked(int constructorId)
261 {
262   EraseDistance();
263   myGeomGUI->EraseSimulationShape() ;
264
265   switch (constructorId)
266     {
267     case 0:
268       {
269         GroupConstructor1->show();
270         myConstructorId = constructorId ;
271         myEditCurrentArgument = LineEditC1A1Shape ;
272         LineEditC1A2Shape->setText(tr("")) ;
273         Constructor1->setChecked( TRUE );
274         myOkShape1 =  myOkShape2 = false ;
275         break;
276       }
277     }
278  return ;
279 }
280
281 //=================================================================================
282 // function : ClickOnOk()
283 // purpose  :
284 //=================================================================================
285 void GeometryGUI_DistanceDlg::ClickOnOk()
286 {
287   this->ClickOnApply() ;
288   this->ClickOnCancel() ;
289
290   return ;
291 }
292
293 //=================================================================================
294 // function : ClickOnApply()
295 // purpose  :
296 //=================================================================================
297 void GeometryGUI_DistanceDlg::ClickOnApply()
298 {
299   EraseDistance() ;
300   myGeomGUI->EraseSimulationShape() ;
301   mySimulationTopoDs.Nullify() ;
302   myGeomGUI->GetDesktop()->putInfo( tr("") ) ; 
303   switch(myConstructorId)
304     { 
305     case 0 :
306       {
307         if(myOkShape1 && myOkShape2) {    
308           this->MakeDistanceSimulationAndDisplay(myShape1 ,myShape2) ;
309         }
310         break ;
311       }
312     }
313
314   // accept();
315   return ;
316 }
317
318
319 //=================================================================================
320 // function : ClickOnCancel()
321 // purpose  :
322 //=================================================================================
323 void GeometryGUI_DistanceDlg::ClickOnCancel()
324 {
325   EraseDistance() ;
326   myGeomGUI->EraseSimulationShape() ;
327   mySimulationTopoDs.Nullify() ;
328   disconnect( mySelection, 0, this, 0 );
329   myGeomGUI->ResetState() ;
330   reject() ;
331   return ;
332 }
333
334
335
336 //=================================================================================
337 // function : SelectionIntoArgument()
338 // purpose  : Called when selection has changed
339 //=================================================================================
340 void GeometryGUI_DistanceDlg::SelectionIntoArgument()
341 {
342   myGeomGUI->EraseSimulationShape() ; 
343   mySimulationTopoDs.Nullify() ;
344
345   LineEdit_Length->setText("") ;
346   myEditCurrentArgument->setText("") ; /* by default */
347   QString aString = ""; /* the name of selection */
348
349   int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
350   if ( nbSel != 1 ) {
351     switch (myConstructorId) 
352       {
353       case 0:
354         {
355           if ( myEditCurrentArgument == LineEditC1A1Shape ) {
356             myOkShape1 = false ;
357           }
358           else if ( myEditCurrentArgument == LineEditC1A2Shape ) {
359             myOkShape2 = false ;
360           }
361           break ;
362         } 
363       }
364     return ;
365   }
366
367   /*  nbSel == 1  */ 
368   TopoDS_Shape S; 
369   Standard_Boolean testResult ;
370   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
371   
372   if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
373     return ;
374
375   if ( myEditCurrentArgument == LineEditC1A1Shape ) {
376     myGeomShape1 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
377     if( !testResult )
378       return ;
379     myShape1 = S ;
380     LineEditC1A1Shape->setText(aString) ;
381     myOkShape1 = true ;
382   }    
383   else if ( myEditCurrentArgument == LineEditC1A2Shape ) {
384     myGeomShape2 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
385     if( !testResult )
386       return ;
387     myShape2 = S ;
388     LineEditC1A2Shape->setText(aString) ;
389     myOkShape2 = true ;
390   }
391
392   return ; 
393 }
394
395
396 //=================================================================================
397 // function : SetEditCurrentArgument()
398 // purpose  :
399 //=================================================================================
400 void GeometryGUI_DistanceDlg::SetEditCurrentArgument()
401 {
402   QPushButton* send = (QPushButton*)sender();
403
404   switch (myConstructorId)
405     {
406     case 0: /* default constructor */
407       { 
408         if( send == SelectButtonC1A1Shape ) {
409           LineEditC1A1Shape->setFocus() ;
410           myEditCurrentArgument = LineEditC1A1Shape ;
411         }
412         else if(send == SelectButtonC1A2Shape) {
413           LineEditC1A2Shape->setFocus() ;
414           myEditCurrentArgument = LineEditC1A2Shape;
415         }
416         SelectionIntoArgument() ;
417         break;
418       }
419     }
420   return ;
421 }
422
423
424
425 //=================================================================================
426 // function : LineEditReturnPressed()
427 // purpose  :
428 //=================================================================================
429 void GeometryGUI_DistanceDlg::LineEditReturnPressed()
430 {
431   QLineEdit* send = (QLineEdit*)sender();  
432   if( send == LineEditC1A1Shape )
433     myEditCurrentArgument = LineEditC1A1Shape ;
434   else if ( send == LineEditC1A2Shape )
435     myEditCurrentArgument = LineEditC1A2Shape ; 
436   else
437     return ;
438   
439   /* User name of object input management                          */
440   /* If successfull the selection is changed and signal emitted... */
441   /* so SelectionIntoArgument() is automatically called.           */
442   const QString objectUserName = myEditCurrentArgument->text() ;
443   QWidget* thisWidget = (QWidget*)this ;
444   if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
445     myEditCurrentArgument->setText( objectUserName ) ;
446   }
447   return ;
448 }
449
450
451
452 //=================================================================================
453 // function : DeactivateActiveDialog()
454 // purpose  :
455 //=================================================================================
456 void GeometryGUI_DistanceDlg::DeactivateActiveDialog()
457 {
458   if ( GroupConstructors->isEnabled() ) {
459
460     GroupConstructors->setEnabled(false) ;
461     GroupConstructor1->setEnabled(false) ;
462     GroupButtons->setEnabled(false) ;  
463     disconnect( mySelection, 0, this, 0 );
464   }
465   return ;
466 }
467
468
469
470 //=================================================================================
471 // function : closeEvent()
472 // purpose  :
473 //=================================================================================
474 void GeometryGUI_DistanceDlg::closeEvent( QCloseEvent* e )
475 {
476   this->ClickOnCancel() ; /* same than click on cancel button */
477 }
478
479
480 //=================================================================================
481 // function : enterEvent()
482 // purpose  : when mouse enter onto the QWidget
483 //=================================================================================
484 void GeometryGUI_DistanceDlg::enterEvent( QEvent *  )
485 {
486   if ( GroupConstructors->isEnabled() )
487     return ;
488   ActivateThisDialog() ;
489 }
490
491
492
493 //=================================================================================
494 // function : ActivateThisDialog()
495 // purpose  :
496 //=================================================================================
497 void GeometryGUI_DistanceDlg::ActivateThisDialog()
498 {
499   /* Emit a signal to deactivate any active dialog */
500   myGeomGUI->EmitSignalDeactivateDialog() ;
501   GroupConstructors->setEnabled(true) ;
502   GroupConstructor1->setEnabled(true) ;
503   GroupButtons->setEnabled(true) ;
504   
505   connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
506
507   if( !mySimulationTopoDs.IsNull() )
508     myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
509
510   return ;
511 }
512
513
514
515 //=================================================================================
516 // function : MakeDistanceSimulationAndDisplay()
517 // purpose  :
518 //=================================================================================
519 void GeometryGUI_DistanceDlg::MakeDistanceSimulationAndDisplay(const TopoDS_Shape& S1, const TopoDS_Shape& S2) 
520 {
521   LineEdit_Length->setText("") ;
522   EraseDistance() ;
523   myGeomGUI->EraseSimulationShape() ;
524   
525   BRepExtrema_DistShapeShape dst( S1, S2 );
526   if (dst.IsDone()) {
527     int i;
528     for (i=1; i<= dst.NbSolution(); i++) {
529       gp_Pnt P1,P2;
530       P1 = (dst.PointOnShape1(i));
531       P2 = (dst.PointOnShape2(i));
532       
533       Standard_Real Dist = P1.Distance(P2);
534       if (Dist<=1.e-9) {
535         BRepBuilderAPI_MakeVertex MakeVertex(P1);
536         mySimulationTopoDs =  MakeVertex.Vertex();
537         myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
538
539         LineEdit_Length->setText("0.0") ;
540       } else {
541         BRepBuilderAPI_MakeEdge MakeEdge(P1, P2);
542         mySimulationTopoDs = MakeEdge.Edge();
543
544         TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(P1);
545         TopoDS_Vertex V2 = BRepBuilderAPI_MakeVertex(P2);
546
547         QString S;
548         S.sprintf("%.1f",Dist);
549         Handle(AIS_LengthDimension) Distance = new AIS_LengthDimension (V1,V2, new Geom_Plane (0.,0.,1.,0.), 
550                                                                         Dist, TCollection_ExtendedString(strdup(S)));
551
552         LineEdit_Length->setText(S) ;
553
554         if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC )
555           return ;
556         
557         OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
558         Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
559         ic->Display( Distance );
560         ic->UpdateCurrentViewer();
561       }
562     }
563   } else
564     myGeomGUI->GetDesktop()->putInfo( tr( "GEOM_PRP_MIN_DIST" ) );
565 }
566
567
568 //=================================================================================
569 // function : EraseDistance()
570 // purpose  :
571 //=================================================================================
572 void GeometryGUI_DistanceDlg::EraseDistance()
573 {
574   int count = myGeomGUI->GetActiveStudy()->getStudyFramesCount();
575   for ( int i = 0; i < count; i++ )
576     if (myGeomGUI->GetActiveStudy()->getStudyFrame(i)->getTypeView() == VIEW_OCC ) {
577       OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myGeomGUI->GetActiveStudy()->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
578       Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
579
580       AIS_ListOfInteractive L;
581       ic->DisplayedObjects(AIS_KOI_Relation,-1,L);
582       AIS_ListIteratorOfListOfInteractive ite(L);
583       while (ite.More()) {
584         ic->Remove( ite.Value() );
585         ic->UpdateCurrentViewer();
586         ite.Next();
587       }
588     }
589 }