Salome HOME
IMP 0016656: EDF531: Default constructor in creation dialog of geometric objects.
[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 <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
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( "create_lcs_page.html" );
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( myGeomGUI->getApp()->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 ); // VSR: TODO: DBL_DIGITS_DISPLAY
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     globalSelection(); // close local contexts, if any
244     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
245     activate( GEOM_MARKER );
246     displayPreview();
247     return;
248   }
249
250   myConstructorId = constructorId;
251
252   disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
253
254   switch ( constructorId ) {
255   case 0:
256     {
257       Group1->hide();
258       Group2->hide();
259       aMainGrp->show();
260       globalSelection(); // close local contexts, if any
261       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
262       activate( GEOM_MARKER );
263       break;
264     }
265   case 1:
266     {
267       aMainGrp->hide();
268       Group2->hide();
269       Group1->show();
270       
271       globalSelection( GEOM_ALLGEOM );
272       myEditCurrentArgument = Group1->LineEdit1;
273       Group1->LineEdit1->setText( "" );
274       break;
275     }
276   case 2:
277     {
278       aMainGrp->hide();
279       Group1->show();
280       Group2->show();
281       
282       globalSelection(); // close local contexts, if any
283       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
284       myEditCurrentArgument = Group2->LineEdit1;
285       Group2->LineEdit1->setText( "" );
286       Group2->LineEdit2->setText( "" );
287       Group2->LineEdit3->setText( "" );
288       break;
289     }
290   }
291
292   qApp->processEvents();
293   updateGeometry();
294   resize( minimumSize() );
295   
296   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
297            this, SLOT( onSelectionDone() ) );
298   onSelectionDone();
299 }
300
301 //=================================================================================
302 // function : onOk()
303 // purpose  :
304 //=================================================================================
305 void BasicGUI_MarkerDlg::onOk()
306 {
307   if ( onApply() )
308     ClickOnCancel();
309 }
310
311 //=================================================================================
312 // function : onApply()
313 // purpose  :
314 //=================================================================================
315 bool BasicGUI_MarkerDlg::onApply()
316 {
317   if ( !onAccept() )
318     return false;
319
320   initName();
321   ConstructorsClicked( getConstructorId() );
322
323   return true;
324 }
325
326 //=================================================================================
327 // function : onSelectionDone0()
328 // purpose  : Reaction on selection when first method of creation is current one
329 //=================================================================================
330 void BasicGUI_MarkerDlg::onSelectionDone0()
331 {
332   if ( IObjectCount() == 1 ) {
333     Standard_Boolean aRes = Standard_False;
334     Handle(SALOME_InteractiveObject) anIO = firstIObject();
335     GEOM::GEOM_Object_var aSelectedObj = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
336     
337     LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
338
339     if ( aRes && !aSelectedObj->_is_nil() ) {
340       TopoDS_Shape aShape;
341       if ( GEOMBase::GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
342         // Existing LCS selected
343         if ( aSelectedObj->GetType() == GEOM_MARKER && aShape.ShapeType() == TopAbs_FACE ) {
344           TopoDS_Face aFace = TopoDS::Face( aShape );
345           Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
346           
347           if ( !aPlane.IsNull() ) {
348             gp_Ax3 anAx3 = aPlane->Pln().Position();
349             gp_Pnt aLoc = anAx3.Location();
350             gp_Dir aXDir = anAx3.XDirection();
351             gp_Dir aYDir = anAx3.YDirection();
352             
353             myData[ X ]->setValue( aLoc.X() );
354             myData[ Y ]->setValue( aLoc.Y() );
355             myData[ Z ]->setValue( aLoc.Z() );
356             
357             myData[ DX1 ]->setValue( aXDir.X() );
358             myData[ DY1 ]->setValue( aXDir.Y() );
359             myData[ DZ1 ]->setValue( aXDir.Z() );
360             
361             myData[ DX2 ]->setValue( aYDir.X() );
362             myData[ DY2 ]->setValue( aYDir.Y() );
363             myData[ DZ2 ]->setValue( aYDir.Z() );
364             aSelMgr->clearSelected();
365           }
366         }
367         else {
368           TColStd_IndexedMapOfInteger aMap;
369           aSelMgr->GetIndexes( anIO, aMap );
370           if ( aMap.Extent() == 1 ) { // Local Selection
371             int anIndex = aMap( 1 );
372             TopTools_IndexedMapOfShape aShapes;
373             TopExp::MapShapes( aShape, aShapes );
374             aShape = aShapes.FindKey( anIndex );
375             aSelMgr->clearSelected(); // ???
376           }
377
378           if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) {
379             gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
380             myData[ X ]->setValue( aPnt.X() );
381             myData[ Y ]->setValue( aPnt.Y() );
382             myData[ Z ]->setValue( aPnt.Z() );
383           }
384         }
385       }
386     }
387   }
388   
389   displayPreview();
390 }
391
392
393 //=================================================================================
394 // function : onSelectionDone()
395 // purpose  : Called when selection as changed or other case
396 //=================================================================================
397 void BasicGUI_MarkerDlg::onSelectionDone()
398 {
399   if ( getConstructorId() == 0 ) {
400     onSelectionDone0();
401     return;
402   }
403
404   myEditCurrentArgument->setText( "" );
405
406   if ( IObjectCount() == 1 ) {
407     Standard_Boolean aRes = Standard_False;
408     Handle(SALOME_InteractiveObject) anIO = firstIObject();
409     GEOM::GEOM_Object_var aSelectedObj = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
410
411     if ( !CORBA::is_nil( aSelectedObj ) && aRes ) {
412       QString aName = GEOMBase::GetName( aSelectedObj );
413       
414       if ( getConstructorId() == 1 ) { // by shape position
415         // Get shape's position
416         CORBA::Double Ox, Oy, Oz,   Zx, Zy, Zz,   Xx, Xy, Xz,   Yx, Yy, Yz;
417         Ox = Oy = Oz = Zx = Zy = Xy = Xz = Yx = Yz = 0;
418         Zz = Xx = Yy = 1.;
419         
420         GEOM::GEOM_IMeasureOperations_ptr aMeasureOp =
421           myGeomGUI->GetGeomGen()->GetIMeasureOperations( getStudyId() );
422         aMeasureOp->GetPosition( aSelectedObj, Ox, Oy, Oz, Zx, Zy, Zz, Xx, Xy, Xz );
423         
424         // Calculate Y direction
425         if ( aMeasureOp->IsDone() ) {
426           gp_Pnt aPnt  ( Ox, Oy, Oz );
427           gp_Dir aDirN ( Zx, Zy, Zz );
428           gp_Dir aDirX ( Xx, Xy, Xz );
429           gp_Ax3 anAx3 ( aPnt, aDirN, aDirX );
430
431           gp_Dir aDirY = anAx3.YDirection();
432           aDirY.Coord(Yx,Yy,Yz);
433         }
434
435         // Set values
436         myData[ X ]->setValue( Ox );
437         myData[ Y ]->setValue( Oy );
438         myData[ Z ]->setValue( Oz );
439
440         myData[ DX1 ]->setValue( Xx );
441         myData[ DY1 ]->setValue( Xy );
442         myData[ DZ1 ]->setValue( Xz );
443
444         myData[ DX2 ]->setValue( Yx );
445         myData[ DY2 ]->setValue( Yy );
446         myData[ DZ2 ]->setValue( Yz );
447
448         myEditCurrentArgument->setText( aName );
449       }
450       else if ( getConstructorId() == 2 ) { // by point and two vectors
451         TopoDS_Shape aShape;
452         if ( GEOMBase::GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) ) {
453           TopAbs_ShapeEnum aNeedType = TopAbs_EDGE;
454           if ( myEditCurrentArgument == Group2->LineEdit1 )
455             aNeedType = TopAbs_VERTEX;
456           
457           TColStd_IndexedMapOfInteger aMap;
458           LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
459           aSelMgr->GetIndexes( anIO, aMap );
460
461           if ( !aMap.IsEmpty() ) {
462             int anIndex = aMap( 1 );
463             if ( aNeedType == TopAbs_EDGE )
464               aName += QString( "_edge_%1" ).arg( anIndex );
465             else
466               aName += QString( "_vertex_%1" ).arg( anIndex );
467
468             TopTools_IndexedMapOfShape aShapes;
469             TopExp::MapShapes( aShape, aShapes );
470             aShape = aShapes.FindKey( anIndex );
471           }
472
473           if ( myEditCurrentArgument == Group2->LineEdit1 ) {
474             if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) {
475               gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
476               myData[ X ]->setValue( aPnt.X() );
477               myData[ Y ]->setValue( aPnt.Y() );
478               myData[ Z ]->setValue( aPnt.Z() );
479               myEditCurrentArgument->setText( aName );
480             }
481             else {
482               myData[ X ]->setValue( 0 );
483               myData[ Y ]->setValue( 0 );
484               myData[ Z ]->setValue( 0 );
485             }
486           }
487           else if (myEditCurrentArgument == Group2->LineEdit2) {
488             if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE ) {
489               gp_Pnt aP1 = BRep_Tool::Pnt( TopExp::FirstVertex( TopoDS::Edge( aShape ) ) );
490               gp_Pnt aP2 = BRep_Tool::Pnt( TopExp::LastVertex( TopoDS::Edge( aShape ) ) );
491               gp_Dir aDir( gp_Vec( aP1, aP2 ) );
492
493               myData[ DX1 ]->setValue( aDir.X() );
494               myData[ DY1 ]->setValue( aDir.Y() );
495               myData[ DZ1 ]->setValue( aDir.Z() );
496               myEditCurrentArgument->setText( aName );
497             }
498             else {
499               myData[ DX1 ]->setValue( 0 );
500               myData[ DY1 ]->setValue( 0 );
501               myData[ DZ1 ]->setValue( 0 );
502             }
503           }
504           else if ( myEditCurrentArgument == Group2->LineEdit3 ) {
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[ DX2 ]->setValue( aDir.X() );
511               myData[ DY2 ]->setValue( aDir.Y() );
512               myData[ DZ2 ]->setValue( aDir.Z() );
513               myEditCurrentArgument->setText( aName );
514             }
515             else {
516               myData[ DX2 ]->setValue( 0 );
517               myData[ DY2 ]->setValue( 0 );
518               myData[ DZ2 ]->setValue( 0 );
519             }
520           }
521         }
522       }
523     }
524   }
525   else {
526     if ( getConstructorId() == 1 ) {
527       myData[ X ]->setValue( 0 );
528       myData[ Y ]->setValue( 0 );
529       myData[ Z ]->setValue( 0 );
530
531       myData[ DX1 ]->setValue( 0 );
532       myData[ DY1 ]->setValue( 0 );
533       myData[ DZ1 ]->setValue( 0 );
534
535       myData[ DX2 ]->setValue( 0 );
536       myData[ DY2 ]->setValue( 0 );
537       myData[ DZ2 ]->setValue( 0 );
538     }
539     else if ( getConstructorId() == 2 ) {
540       if ( myEditCurrentArgument == Group2->LineEdit1 ) {
541         myData[ X ]->setValue( 0 );
542         myData[ Y ]->setValue( 0 );
543         myData[ Z ]->setValue( 0 );
544       }
545       else if ( myEditCurrentArgument == Group2->LineEdit2 ) {
546         myData[ DX1 ]->setValue( 0 );
547         myData[ DY1 ]->setValue( 0 );
548         myData[ DZ1 ]->setValue( 0 );
549       }
550       else if ( myEditCurrentArgument == Group2->LineEdit3 ) {
551         myData[ DX2 ]->setValue( 0 );
552         myData[ DY2 ]->setValue( 0 );
553         myData[ DZ2 ]->setValue( 0 );
554       }
555     }
556   }
557
558   displayPreview();
559 }
560
561 //=================================================================================
562 // function : SetEditCurrentArgument()
563 // purpose  :
564 //=================================================================================
565 void BasicGUI_MarkerDlg::SetEditCurrentArgument()
566 {
567   QPushButton* send = (QPushButton*)sender();
568
569   if ( send == Group1->PushButton1 ) {
570     myEditCurrentArgument = Group1->LineEdit1;
571     globalSelection( GEOM_ALLGEOM );
572   }
573   else if ( send == Group2->PushButton1 ) {
574     myEditCurrentArgument = Group2->LineEdit1;
575     //globalSelection( GEOM_POINT );
576     globalSelection(); // close local contexts, if any
577     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
578   }
579   else if ( send == Group2->PushButton2 ) {
580     myEditCurrentArgument = Group2->LineEdit2;
581     //globalSelection( GEOM_LINE );
582     globalSelection(); // close local contexts, if any
583     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
584   }
585   else if ( send == Group2->PushButton3 ) {
586     myEditCurrentArgument = Group2->LineEdit3;
587     globalSelection(); // close local contexts, if any
588     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
589   }
590   
591   myEditCurrentArgument->setFocus();
592   onSelectionDone();
593 }
594
595 //=================================================================================
596 // function : LineEditReturnPressed()
597 // purpose  :
598 //=================================================================================
599 void BasicGUI_MarkerDlg::LineEditReturnPressed()
600 {
601   QLineEdit* send = (QLineEdit*)sender();
602
603   myEditCurrentArgument = send;
604   GEOMBase_Skeleton::LineEditReturnPressed();
605 }
606
607 //=================================================================================
608 // function : onActivate()
609 // purpose  :
610 //=================================================================================
611 void BasicGUI_MarkerDlg::onActivate()
612 {
613   GEOMBase_Skeleton::ActivateThisDialog();
614   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
615            this, SLOT( onSelectionDone() ) );
616
617   ConstructorsClicked( getConstructorId() );
618 }
619
620 //=================================================================================
621 // function : onDeactivate()
622 // purpose  : public slot to deactivate if active
623 //=================================================================================
624 void BasicGUI_MarkerDlg::onDeactivate()
625 {
626   GEOMBase_Skeleton::DeactivateActiveDialog();
627 }
628
629 //=================================================================================
630 // function : enterEvent()
631 // purpose  :
632 //=================================================================================
633 void BasicGUI_MarkerDlg::enterEvent( QEvent* )
634 {
635   if ( !mainFrame()->GroupConstructors->isEnabled() )
636     onActivate();
637 }
638
639 //=================================================================================
640 // function : createOperation
641 // purpose  :
642 //=================================================================================
643 GEOM::GEOM_IOperations_ptr BasicGUI_MarkerDlg::createOperation()
644 {
645   return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
646 }
647
648 //=================================================================================
649 // function : isValid
650 // purpose  :
651 //=================================================================================
652 bool BasicGUI_MarkerDlg::isValid( QString& msg )
653 {
654   const int id = getConstructorId();
655   gp_Vec v1( myData[ DX1 ]->value(), myData[ DY1 ]->value(), myData[ DZ1 ]->value() ),
656          v2( myData[ DX2 ]->value(), myData[ DY2 ]->value(), myData[ DZ2 ]->value() );
657
658   bool isOk = false;
659   // we will got exception if the magnitude of any of the 2 vectors <= gp::Resolution()
660   // Vectors shouldn't be checked for being orthogonal here!
661   if ( v1.Magnitude() > gp::Resolution() && v2.Magnitude() > gp::Resolution() ) {
662     isOk = !v1.IsParallel( v2, Precision::Angular() );
663     if ( !isOk )
664       msg += tr( "VEC_PARALLEL" );
665   }
666
667   switch ( id ) {
668   case 0:
669     return isOk;
670   case 1:
671     return !Group1->LineEdit1->text().isEmpty() && isOk;
672   case 2:
673     return !Group2->LineEdit1->text().isEmpty() &&
674       !Group2->LineEdit2->text().isEmpty() &&
675       !Group2->LineEdit3->text().isEmpty() && isOk;
676   }
677   return false;
678 }
679
680 //=================================================================================
681 // function : execute
682 // purpose  :
683 //=================================================================================
684 bool BasicGUI_MarkerDlg::execute( ObjectList& objects )
685 {
686   GEOM::GEOM_Object_var anObj = GEOM::GEOM_IBasicOperations::_narrow(
687     getOperation() )->MakeMarker( myData[ X   ]->value(), myData[ Y   ]->value(), myData[ Z   ]->value(),
688                                   myData[ DX1 ]->value(), myData[ DY1 ]->value(), myData[ DZ1 ]->value(),
689                                   myData[ DX2 ]->value(), myData[ DY2 ]->value(), myData[ DZ2 ]->value() );
690
691   if ( !anObj->_is_nil() )
692     objects.push_back( anObj._retn() );
693
694   return true;
695 }
696
697 //=================================================================================
698 // function : onValueChanged
699 // purpose  :
700 //=================================================================================
701 void BasicGUI_MarkerDlg::onValueChanged( double )
702 {
703   displayPreview();
704 }
705
706 //=================================================================================
707 // function : displayPreview
708 // purpose  :
709 //=================================================================================
710 void BasicGUI_MarkerDlg::displayPreview ( const bool   activate,
711                                           const bool   update,
712                                           const bool   toRemoveFromEngine,
713                                           const double lineWidth )
714 {
715   if ( !myBlockPreview ) {
716     GEOMBase_Skeleton::displayPreview( activate, update, toRemoveFromEngine, lineWidth );
717     if ( myConstructorId == 0 )
718       GEOMBase_Skeleton::activate( GEOM_MARKER );
719   }
720 }