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