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