Salome HOME
Merge from V5_1_3_BR branch (07/12/09)
[modules/geom.git] / src / BasicGUI / BasicGUI_MarkerDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File   : BasicGUI_MarkerDlg.cxx
24 // Author : Sergey LITONIN, Open CASCADE S.A.S. (sergey.litonin@opencascade.com)
25 //
26 #include "BasicGUI_MarkerDlg.h"
27
28 #include <DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36
37 #include <QLabel>
38
39 #include <GEOMImpl_Types.hxx>
40
41 // OCCT Includes
42 #include <BRep_Tool.hxx>
43 #include <TopExp.hxx>
44 #include <TopAbs.hxx>
45 #include <TopoDS.hxx>
46 #include <TopoDS_Vertex.hxx>
47 #include <TopoDS_Face.hxx>
48 #include <Geom_Plane.hxx>
49 #include <TopTools_IndexedMapOfShape.hxx>
50 #include <TColStd_IndexedMapOfInteger.hxx>
51 #include <gp_Pnt.hxx>
52 #include <gp_Pln.hxx>
53
54 //=================================================================================
55 // class    : BasicGUI_MarkerDlg()
56 // purpose  : Constructor
57 //=================================================================================
58 BasicGUI_MarkerDlg::BasicGUI_MarkerDlg( GeometryGUI* theGeometryGUI, QWidget* theParent )
59   : GEOMBase_Skeleton( theGeometryGUI, theParent, false,
60                        Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
61 {
62   QPixmap iconCS1   ( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_MARKER" ) ) );
63   QPixmap iconCS2   ( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_MARKER2" ) ) );
64   QPixmap iconCS3   ( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_MARKER3" ) ) );
65   QPixmap iconSelect( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
66
67   setWindowTitle( tr( "CAPTION" ) );
68
69   mainFrame()->GroupConstructors->setTitle( tr( "LOCALCS" ) );
70   mainFrame()->RadioButton1->setIcon( iconCS1 );
71   mainFrame()->RadioButton2->setIcon( iconCS2 );
72   mainFrame()->RadioButton3->setIcon( iconCS3 );
73
74   Group1 = new DlgRef_1Sel( centralWidget() );
75
76   Group1->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
77   Group1->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
78   Group1->PushButton1->setIcon( iconSelect );
79   Group1->PushButton1->setDown( true );
80
81   Group2 = new DlgRef_3Sel( centralWidget() );
82
83   Group2->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
84   Group2->TextLabel1->setText( tr( "GEOM_POINT" ) );
85   Group2->TextLabel2->setText( tr( "XDIR" ) );
86   Group2->TextLabel3->setText( tr( "YDIR" ) );
87   Group2->PushButton1->setIcon( iconSelect );
88   Group2->PushButton2->setIcon( iconSelect );
89   Group2->PushButton3->setIcon( iconSelect );
90   Group2->PushButton1->setDown( true );
91
92   aMainGrp = new QFrame( centralWidget() );
93   aMainGrp->setFrameStyle( QFrame::NoFrame | QFrame::Plain );
94   aMainGrp->setContentsMargins( 0, 0, 0, 0 );
95   QHBoxLayout* aMainGrpLayout = new QHBoxLayout( aMainGrp );
96   aMainGrpLayout->setMargin( 0 );
97   
98   QGroupBox* anOriGrp = new QGroupBox( tr( "ORIGIN" ), aMainGrp );
99   QVBoxLayout* anOriGrpLayout = new QVBoxLayout( anOriGrp );
100
101   anOriGrpLayout->addWidget( new QLabel( tr( "GEOM_X" ), anOriGrp ) );
102   myData[ X ] = new SalomeApp_DoubleSpinBox( anOriGrp );
103   anOriGrpLayout->addWidget( myData[ X ] );
104   anOriGrpLayout->addWidget( new QLabel( tr( "GEOM_Y" ), anOriGrp ) );
105   myData[ Y ] = new SalomeApp_DoubleSpinBox( anOriGrp );
106   anOriGrpLayout->addWidget( myData[ Y ] );
107   anOriGrpLayout->addWidget( new QLabel( tr( "GEOM_Z" ), anOriGrp ) );
108   myData[ Z ] = new SalomeApp_DoubleSpinBox( anOriGrp );
109   anOriGrpLayout->addWidget( myData[ Z ] );
110
111   aMainGrpLayout->addWidget( anOriGrp );
112
113   QGroupBox* aXAxisGrp = new QGroupBox( tr( "XDIR" ), aMainGrp );
114   QVBoxLayout* aXAxisGrpLayout = new QVBoxLayout( aXAxisGrp );
115
116   aXAxisGrpLayout->addWidget( new QLabel( tr( "DX" ), aXAxisGrp ) );
117   myData[ DX1 ] = new SalomeApp_DoubleSpinBox( aXAxisGrp );
118   aXAxisGrpLayout->addWidget( myData[ DX1 ] );
119   aXAxisGrpLayout->addWidget( new QLabel( tr( "DY" ), aXAxisGrp ) );
120   myData[ DY1 ] = new SalomeApp_DoubleSpinBox( aXAxisGrp );
121   aXAxisGrpLayout->addWidget( myData[ DY1 ] );
122   aXAxisGrpLayout->addWidget( new QLabel( tr( "DZ" ), aXAxisGrp ) );
123   myData[ DZ1 ] = new SalomeApp_DoubleSpinBox( aXAxisGrp );
124   aXAxisGrpLayout->addWidget( myData[ DZ1 ] );
125
126   aMainGrpLayout->addWidget( aXAxisGrp );
127
128   QGroupBox* anYAxisGrp = new QGroupBox( tr( "YDIR" ), aMainGrp );
129   QVBoxLayout* anYAxisGrpLayout = new QVBoxLayout( anYAxisGrp );
130
131   anYAxisGrpLayout->addWidget( new QLabel( tr( "DX" ), anYAxisGrp ) );
132   myData[ DX2 ] = new SalomeApp_DoubleSpinBox( anYAxisGrp );
133   anYAxisGrpLayout->addWidget( myData[ DX2 ] );
134   anYAxisGrpLayout->addWidget( new QLabel( tr( "DY" ), anYAxisGrp ) );
135   myData[ DY2 ] = new SalomeApp_DoubleSpinBox( anYAxisGrp );
136   anYAxisGrpLayout->addWidget( myData[ DY2 ] );
137   anYAxisGrpLayout->addWidget( new QLabel( tr( "DZ" ), anYAxisGrp ) );
138   myData[ DZ2 ] = new SalomeApp_DoubleSpinBox( anYAxisGrp );
139   anYAxisGrpLayout->addWidget( myData[ DZ2 ] );
140
141   aMainGrpLayout->addWidget( anYAxisGrp );
142
143   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
144   layout->setMargin( 0 ); layout->setSpacing( 6 );
145   layout->addWidget( aMainGrp );
146   layout->addWidget( Group1 );
147   layout->addWidget( Group2 );
148
149   setHelpFileName( "create_lcs_page.html" );
150
151   Init();
152 }
153
154
155 //=================================================================================
156 // function : ~BasicGUI_MarkerDlg()
157 // purpose  : Destroys the object and frees any allocated resources
158 //=================================================================================
159 BasicGUI_MarkerDlg::~BasicGUI_MarkerDlg()
160 {
161 }
162
163
164 //=================================================================================
165 // function : Init()
166 // purpose  :
167 //=================================================================================
168 void BasicGUI_MarkerDlg::Init()
169 {
170   myBlockPreview = false;
171   myConstructorId = -1;
172   myEditCurrentArgument = Group1->LineEdit1;
173   Group1->LineEdit1->setReadOnly( true );
174   Group2->LineEdit1->setReadOnly( true );
175   Group2->LineEdit2->setReadOnly( true );
176   Group2->LineEdit3->setReadOnly( true );
177   Group2->LineEdit1->setEnabled( true );
178   Group2->LineEdit2->setEnabled( false );
179   Group2->LineEdit3->setEnabled( false );
180
181   connect( this,                SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
182
183   connect( Group1->PushButton1, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
184   connect( Group2->PushButton1, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
185   connect( Group2->PushButton2, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
186   connect( Group2->PushButton3, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
187
188   connect( Group1->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
189   connect( Group2->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
190   connect( Group2->LineEdit2,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
191   connect( Group2->LineEdit3,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
192
193   connect( myGeomGUI,           SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( onDeactivate() ) );
194   connect( myGeomGUI,           SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
195
196   connect( buttonOk(),          SIGNAL( clicked() ), this, SLOT( onOk() ) );
197   connect( buttonApply(),       SIGNAL( clicked() ), this, SLOT( onApply() ) );
198
199   connect( myGeomGUI->getApp()->selectionMgr(),
200            SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionDone() ) );
201
202   initName( tr( "LCS_NAME" ) );
203
204   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
205   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
206
207   for ( DataMap::iterator anIter = myData.begin(); anIter != myData.end(); ++anIter ) {
208     initSpinBox( anIter.value(), COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
209     connect( anIter.value(), SIGNAL( valueChanged( double ) ),
210              this, SLOT( onValueChanged( double ) ) );
211   }
212   
213   myBlockPreview = true;
214   for ( DataMap::iterator anIter = myData.begin(); anIter != myData.end(); ++anIter )
215     anIter.value()->setValue( 0 );
216   myData[ DX1 ]->setValue( 1 );
217   myData[ DY2 ]->setValue( 1 );
218   myBlockPreview = false;
219
220   ConstructorsClicked( 0 );
221
222
223   //@
224   /*
225   QAD_ViewFrame* aFrame = QAD_Application::getDesktop()->getActiveApp()->
226     getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame();
227
228   VTKViewer_ViewFrame* aVTKFrame = dynamic_cast<VTKViewer_ViewFrame*>( aFrame );
229   if ( aVTKFrame )
230   {
231     aVTKFrame->AdjustTrihedrons( true );
232     return;
233   }
234
235   OCCViewer_ViewFrame* aOCCFrame = dynamic_cast<OCCViewer_ViewFrame*>( aFrame );
236   if ( aOCCFrame )
237     aOCCFrame->AdjustTrihedrons( true );
238   */
239 }
240
241 //=================================================================================
242 // function : ConstructorsClicked()
243 // purpose  : Radio button management
244 //=================================================================================
245 void BasicGUI_MarkerDlg::ConstructorsClicked( int constructorId )
246 {
247   if ( myConstructorId == constructorId && myConstructorId == 0 ) {
248     globalSelection(); // close local contexts, if any
249     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
250     activate( GEOM_MARKER );
251     displayPreview();
252     return;
253   }
254
255   myConstructorId = constructorId;
256
257   disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
258
259   switch ( constructorId ) {
260   case 0:
261     {
262       Group1->hide();
263       Group2->hide();
264       aMainGrp->show();
265       globalSelection(); // close local contexts, if any
266       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
267       activate( GEOM_MARKER );
268       break;
269     }
270   case 1:
271     {
272       aMainGrp->hide();
273       Group2->hide();
274       Group1->show();
275       Group1->PushButton1->setDown( true );
276       globalSelection( GEOM_ALLGEOM );
277       myEditCurrentArgument = Group1->LineEdit1;
278       Group1->LineEdit1->setText( "" );
279       break;
280     }
281   case 2:
282     {
283       aMainGrp->hide();
284       Group1->hide();
285       Group2->show();
286       Group2->PushButton1->setDown( true );
287       Group2->PushButton2->setDown( false );
288       Group2->PushButton3->setDown( false );
289       globalSelection(); // close local contexts, if any
290       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
291       myEditCurrentArgument = Group2->LineEdit1;
292       Group2->LineEdit1->setText( "" );
293       Group2->LineEdit2->setText( "" );
294       Group2->LineEdit3->setText( "" );
295       Group2->LineEdit1->setEnabled( true );
296       Group2->LineEdit2->setEnabled( false );
297       Group2->LineEdit3->setEnabled( false );
298       break;
299     }
300   }
301
302   qApp->processEvents();
303   updateGeometry();
304   resize( minimumSizeHint() );
305   
306   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
307            this, SLOT( onSelectionDone() ) );
308   onSelectionDone();
309 }
310
311 //=================================================================================
312 // function : onOk()
313 // purpose  :
314 //=================================================================================
315 void BasicGUI_MarkerDlg::onOk()
316 {
317   if ( onApply() )
318     ClickOnCancel();
319 }
320
321 //=================================================================================
322 // function : onApply()
323 // purpose  :
324 //=================================================================================
325 bool BasicGUI_MarkerDlg::onApply()
326 {
327   if ( !onAccept() )
328     return false;
329
330   initName();
331   ConstructorsClicked( getConstructorId() );
332
333   return true;
334 }
335
336 //=================================================================================
337 // function : onSelectionDone0()
338 // purpose  : Reaction on selection when first method of creation is current one
339 //=================================================================================
340 void BasicGUI_MarkerDlg::onSelectionDone0()
341 {
342   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
343   SALOME_ListIO aSelList;
344   aSelMgr->selectedObjects(aSelList);
345
346   if (aSelList.Extent() == 1) {
347     Standard_Boolean aRes = Standard_False;
348     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
349     GEOM::GEOM_Object_var aSelectedObj = GEOMBase::ConvertIOinGEOMObject(anIO, aRes);
350     
351     if ( aRes && !aSelectedObj->_is_nil() ) {
352       TopoDS_Shape aShape;
353       if ( GEOMBase::GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
354         // Existing LCS selected
355         if ( aSelectedObj->GetType() == GEOM_MARKER && aShape.ShapeType() == TopAbs_FACE ) {
356           TopoDS_Face aFace = TopoDS::Face( aShape );
357           Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
358           
359           if ( !aPlane.IsNull() ) {
360             gp_Ax3 anAx3 = aPlane->Pln().Position();
361             gp_Pnt aLoc = anAx3.Location();
362             gp_Dir aXDir = anAx3.XDirection();
363             gp_Dir aYDir = anAx3.YDirection();
364             
365             myData[ X ]->setValue( aLoc.X() );
366             myData[ Y ]->setValue( aLoc.Y() );
367             myData[ Z ]->setValue( aLoc.Z() );
368             
369             myData[ DX1 ]->setValue( aXDir.X() );
370             myData[ DY1 ]->setValue( aXDir.Y() );
371             myData[ DZ1 ]->setValue( aXDir.Z() );
372             
373             myData[ DX2 ]->setValue( aYDir.X() );
374             myData[ DY2 ]->setValue( aYDir.Y() );
375             myData[ DZ2 ]->setValue( aYDir.Z() );
376             aSelMgr->clearSelected();
377           }
378         }
379         else {
380           TColStd_IndexedMapOfInteger aMap;
381           aSelMgr->GetIndexes( anIO, aMap );
382           if ( aMap.Extent() == 1 ) { // Local Selection
383             int anIndex = aMap( 1 );
384             TopTools_IndexedMapOfShape aShapes;
385             TopExp::MapShapes( aShape, aShapes );
386             aShape = aShapes.FindKey( anIndex );
387             aSelMgr->clearSelected(); // ???
388           }
389
390           if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) {
391             gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
392             myData[ X ]->setValue( aPnt.X() );
393             myData[ Y ]->setValue( aPnt.Y() );
394             myData[ Z ]->setValue( aPnt.Z() );
395           }
396         }
397       }
398     }
399   }
400   
401   displayPreview();
402 }
403
404
405 //=================================================================================
406 // function : onSelectionDone()
407 // purpose  : Called when selection as changed or other case
408 //=================================================================================
409 void BasicGUI_MarkerDlg::onSelectionDone()
410 {
411   if ( getConstructorId() == 0 ) {
412     onSelectionDone0();
413     return;
414   }
415
416   myEditCurrentArgument->setText( "" );
417
418   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
419   SALOME_ListIO aSelList;
420   aSelMgr->selectedObjects(aSelList);
421
422   if (aSelList.Extent() == 1) {
423     Standard_Boolean aRes = Standard_False;
424     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
425     GEOM::GEOM_Object_var aSelectedObj = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
426
427     if ( !CORBA::is_nil( aSelectedObj ) && aRes ) {
428       QString aName = GEOMBase::GetName( aSelectedObj );
429       
430       if ( getConstructorId() == 1 ) { // by shape position
431         // Get shape's position
432         CORBA::Double Ox, Oy, Oz,   Zx, Zy, Zz,   Xx, Xy, Xz,   Yx, Yy, Yz;
433         Ox = Oy = Oz = Zx = Zy = Xy = Xz = Yx = Yz = 0;
434         Zz = Xx = Yy = 1.;
435         
436         GEOM::GEOM_IMeasureOperations_ptr aMeasureOp =
437           myGeomGUI->GetGeomGen()->GetIMeasureOperations( getStudyId() );
438         aMeasureOp->GetPosition( aSelectedObj, Ox, Oy, Oz, Zx, Zy, Zz, Xx, Xy, Xz );
439         
440         // Calculate Y direction
441         if ( aMeasureOp->IsDone() ) {
442           gp_Pnt aPnt  ( Ox, Oy, Oz );
443           gp_Dir aDirN ( Zx, Zy, Zz );
444           gp_Dir aDirX ( Xx, Xy, Xz );
445           gp_Ax3 anAx3 ( aPnt, aDirN, aDirX );
446
447           gp_Dir aDirY = anAx3.YDirection();
448           aDirY.Coord(Yx,Yy,Yz);
449         }
450
451         // Set values
452         myData[ X ]->setValue( Ox );
453         myData[ Y ]->setValue( Oy );
454         myData[ Z ]->setValue( Oz );
455
456         myData[ DX1 ]->setValue( Xx );
457         myData[ DY1 ]->setValue( Xy );
458         myData[ DZ1 ]->setValue( Xz );
459
460         myData[ DX2 ]->setValue( Yx );
461         myData[ DY2 ]->setValue( Yy );
462         myData[ DZ2 ]->setValue( Yz );
463
464         myEditCurrentArgument->setText( aName );
465       }
466       else if ( getConstructorId() == 2 ) { // by point and two vectors
467         TopoDS_Shape aShape;
468         if ( GEOMBase::GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) ) {
469           TopAbs_ShapeEnum aNeedType = TopAbs_EDGE;
470           if ( myEditCurrentArgument == Group2->LineEdit1 )
471             aNeedType = TopAbs_VERTEX;
472           
473           TColStd_IndexedMapOfInteger aMap;
474           aSelMgr->GetIndexes( anIO, aMap );
475
476           if ( !aMap.IsEmpty() ) {
477             int anIndex = aMap( 1 );
478             if ( aNeedType == TopAbs_EDGE )
479               aName += QString( "_edge_%1" ).arg( anIndex );
480             else
481               aName += QString( "_vertex_%1" ).arg( anIndex );
482
483             TopTools_IndexedMapOfShape aShapes;
484             TopExp::MapShapes( aShape, aShapes );
485             aShape = aShapes.FindKey( anIndex );
486           }
487
488           if ( myEditCurrentArgument == Group2->LineEdit1 ) {
489             if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) {
490               gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
491               myData[ X ]->setValue( aPnt.X() );
492               myData[ Y ]->setValue( aPnt.Y() );
493               myData[ Z ]->setValue( aPnt.Z() );
494               myEditCurrentArgument->setText( aName );
495               if (Group2->LineEdit2->text() == "")
496                 Group2->PushButton2->click();
497             }
498             else {
499               myData[ X ]->setValue( 0 );
500               myData[ Y ]->setValue( 0 );
501               myData[ Z ]->setValue( 0 );
502             }
503           }
504           else if (myEditCurrentArgument == Group2->LineEdit2) {
505             if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE ) {
506               gp_Pnt aP1 = BRep_Tool::Pnt( TopExp::FirstVertex( TopoDS::Edge( aShape ) ) );
507               gp_Pnt aP2 = BRep_Tool::Pnt( TopExp::LastVertex( TopoDS::Edge( aShape ) ) );
508               gp_Dir aDir( gp_Vec( aP1, aP2 ) );
509
510               myData[ DX1 ]->setValue( aDir.X() );
511               myData[ DY1 ]->setValue( aDir.Y() );
512               myData[ DZ1 ]->setValue( aDir.Z() );
513               myEditCurrentArgument->setText( aName );
514               if (Group2->LineEdit3->text() == "")
515                 Group2->PushButton3->click();
516             }
517             else {
518               myData[ DX1 ]->setValue( 0 );
519               myData[ DY1 ]->setValue( 0 );
520               myData[ DZ1 ]->setValue( 0 );
521             }
522           }
523           else if ( myEditCurrentArgument == Group2->LineEdit3 ) {
524             if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE ) {
525               gp_Pnt aP1 = BRep_Tool::Pnt( TopExp::FirstVertex( TopoDS::Edge( aShape ) ) );
526               gp_Pnt aP2 = BRep_Tool::Pnt( TopExp::LastVertex( TopoDS::Edge( aShape ) ) );
527               gp_Dir aDir(gp_Vec( aP1, aP2 ));
528
529               myData[ DX2 ]->setValue( aDir.X() );
530               myData[ DY2 ]->setValue( aDir.Y() );
531               myData[ DZ2 ]->setValue( aDir.Z() );
532               myEditCurrentArgument->setText( aName );
533               if (Group2->LineEdit1->text() == "")
534                 Group2->PushButton1->click();
535             }
536             else {
537               myData[ DX2 ]->setValue( 0 );
538               myData[ DY2 ]->setValue( 0 );
539               myData[ DZ2 ]->setValue( 0 );
540             }
541           }
542         }
543       }
544     }
545   }
546   else {
547     if ( getConstructorId() == 1 ) {
548       myData[ X ]->setValue( 0 );
549       myData[ Y ]->setValue( 0 );
550       myData[ Z ]->setValue( 0 );
551
552       myData[ DX1 ]->setValue( 0 );
553       myData[ DY1 ]->setValue( 0 );
554       myData[ DZ1 ]->setValue( 0 );
555
556       myData[ DX2 ]->setValue( 0 );
557       myData[ DY2 ]->setValue( 0 );
558       myData[ DZ2 ]->setValue( 0 );
559     }
560     else if ( getConstructorId() == 2 ) {
561       if ( myEditCurrentArgument == Group2->LineEdit1 ) {
562         myData[ X ]->setValue( 0 );
563         myData[ Y ]->setValue( 0 );
564         myData[ Z ]->setValue( 0 );
565       }
566       else if ( myEditCurrentArgument == Group2->LineEdit2 ) {
567         myData[ DX1 ]->setValue( 0 );
568         myData[ DY1 ]->setValue( 0 );
569         myData[ DZ1 ]->setValue( 0 );
570       }
571       else if ( myEditCurrentArgument == Group2->LineEdit3 ) {
572         myData[ DX2 ]->setValue( 0 );
573         myData[ DY2 ]->setValue( 0 );
574         myData[ DZ2 ]->setValue( 0 );
575       }
576     }
577   }
578
579   displayPreview();
580 }
581
582 //=================================================================================
583 // function : SetEditCurrentArgument()
584 // purpose  :
585 //=================================================================================
586 void BasicGUI_MarkerDlg::SetEditCurrentArgument()
587 {
588   QPushButton* send = (QPushButton*)sender();
589   globalSelection(); // close local contexts, if any
590
591   if ( send == Group1->PushButton1 ) {
592     myEditCurrentArgument = Group1->LineEdit1;
593     globalSelection( GEOM_ALLGEOM );
594   }
595   else if ( send == Group2->PushButton1 ) {
596     myEditCurrentArgument = Group2->LineEdit1;
597     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
598     Group2->PushButton2->setDown( false );
599     Group2->PushButton3->setDown( false );
600     Group2->LineEdit1->setEnabled( true );
601     Group2->LineEdit2->setEnabled( false );
602     Group2->LineEdit3->setEnabled( false );
603   }
604   else if ( send == Group2->PushButton2 ) {
605     myEditCurrentArgument = Group2->LineEdit2;
606     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
607     Group2->PushButton1->setDown( false );
608     Group2->PushButton3->setDown( false );
609     Group2->LineEdit1->setEnabled( false );
610     Group2->LineEdit2->setEnabled( true );
611     Group2->LineEdit3->setEnabled( false );
612   }
613   else if ( send == Group2->PushButton3 ) {
614     myEditCurrentArgument = Group2->LineEdit3;
615     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
616     Group2->PushButton1->setDown( false );
617     Group2->PushButton2->setDown( false );
618     Group2->LineEdit1->setEnabled( false );
619     Group2->LineEdit2->setEnabled( false );
620     Group2->LineEdit3->setEnabled( true );
621   }
622   
623   myEditCurrentArgument->setFocus();
624   send->setDown(true);
625   onSelectionDone();
626 }
627
628 //=================================================================================
629 // function : LineEditReturnPressed()
630 // purpose  :
631 //=================================================================================
632 void BasicGUI_MarkerDlg::LineEditReturnPressed()
633 {
634   QLineEdit* send = (QLineEdit*)sender();
635
636   myEditCurrentArgument = send;
637   GEOMBase_Skeleton::LineEditReturnPressed();
638 }
639
640 //=================================================================================
641 // function : onActivate()
642 // purpose  :
643 //=================================================================================
644 void BasicGUI_MarkerDlg::onActivate()
645 {
646   GEOMBase_Skeleton::ActivateThisDialog();
647   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
648            this, SLOT( onSelectionDone() ) );
649
650   ConstructorsClicked( getConstructorId() );
651 }
652
653 //=================================================================================
654 // function : onDeactivate()
655 // purpose  : public slot to deactivate if active
656 //=================================================================================
657 void BasicGUI_MarkerDlg::onDeactivate()
658 {
659   GEOMBase_Skeleton::DeactivateActiveDialog();
660 }
661
662 //=================================================================================
663 // function : enterEvent()
664 // purpose  :
665 //=================================================================================
666 void BasicGUI_MarkerDlg::enterEvent( QEvent* )
667 {
668   if ( !mainFrame()->GroupConstructors->isEnabled() )
669     onActivate();
670 }
671
672 //=================================================================================
673 // function : createOperation
674 // purpose  :
675 //=================================================================================
676 GEOM::GEOM_IOperations_ptr BasicGUI_MarkerDlg::createOperation()
677 {
678   return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
679 }
680
681 //=================================================================================
682 // function : isValid
683 // purpose  :
684 //=================================================================================
685 bool BasicGUI_MarkerDlg::isValid( QString& msg )
686 {
687   const int id = getConstructorId();
688   gp_Vec v1( myData[ DX1 ]->value(), myData[ DY1 ]->value(), myData[ DZ1 ]->value() ),
689          v2( myData[ DX2 ]->value(), myData[ DY2 ]->value(), myData[ DZ2 ]->value() );
690
691   bool isOk = false;
692   // we will got exception if the magnitude of any of the 2 vectors <= gp::Resolution()
693   // Vectors shouldn't be checked for being orthogonal here!
694   if ( v1.Magnitude() > gp::Resolution() && v2.Magnitude() > gp::Resolution() ) {
695     isOk = !v1.IsParallel( v2, Precision::Angular() );
696     if ( !isOk )
697       msg += tr( "VEC_PARALLEL" );
698   }
699
700   switch ( id ) {
701   case 0: {
702     bool ok = true;
703     for ( DataMap::iterator anIter = myData.begin(); anIter != myData.end(); ++anIter )
704       ok = anIter.value()->isValid( msg, !IsPreview()) && ok;
705     return isOk && ok;
706   }
707   case 1:
708     return !Group1->LineEdit1->text().isEmpty() && isOk;
709   case 2:
710     return !Group2->LineEdit1->text().isEmpty() &&
711       !Group2->LineEdit2->text().isEmpty() &&
712       !Group2->LineEdit3->text().isEmpty() && isOk;
713   }
714   return false;
715 }
716
717 //=================================================================================
718 // function : execute
719 // purpose  :
720 //=================================================================================
721 bool BasicGUI_MarkerDlg::execute( ObjectList& objects )
722 {
723   GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow( getOperation() );
724   GEOM::GEOM_Object_var anObj = anOper->MakeMarker( myData[ X   ]->value(), 
725                                                     myData[ Y   ]->value(), 
726                                                     myData[ Z   ]->value(),
727                                                     myData[ DX1 ]->value(),
728                                                     myData[ DY1 ]->value(), 
729                                                     myData[ DZ1 ]->value(),
730                                                     myData[ DX2 ]->value(),
731                                                     myData[ DY2 ]->value(),
732                                                     myData[ DZ2 ]->value() );
733   QStringList aParameters;
734   aParameters<<myData[X]->text();
735   aParameters<<myData[Y]->text();
736   aParameters<<myData[Z]->text();
737   aParameters<<myData[ DX1 ]->text(); 
738   aParameters<<myData[ DY1 ]->text(); 
739   aParameters<<myData[ DZ1 ]->text();
740   aParameters<<myData[ DX2 ]->text();
741   aParameters<<myData[ DY2 ]->text();
742   aParameters<<myData[ DZ2 ]->text();
743   
744   if ( !anObj->_is_nil() ) {
745     if ( !IsPreview() )
746       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
747     objects.push_back( anObj._retn() );
748   }
749
750   return true;
751 }
752
753 //=================================================================================
754 // function : onValueChanged
755 // purpose  :
756 //=================================================================================
757 void BasicGUI_MarkerDlg::onValueChanged( double )
758 {
759   displayPreview();
760 }
761
762 //=================================================================================
763 // function : displayPreview
764 // purpose  :
765 //=================================================================================
766 void BasicGUI_MarkerDlg::displayPreview ( const bool   activate,
767                                           const bool   update,
768                                           const bool   toRemoveFromEngine,
769                                           const double lineWidth )
770 {
771   if ( !myBlockPreview ) {
772     GEOMBase_Skeleton::displayPreview( activate, update, toRemoveFromEngine, lineWidth );
773     if ( myConstructorId == 0 )
774       GEOMBase_Skeleton::activate( GEOM_MARKER );
775   }
776 }