Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
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 #include "utilities.h"
41
42 #include <TopExp.hxx>
43 #include <TopAbs.hxx>
44 #include <TopoDS.hxx>
45 #include <TopoDS_Vertex.hxx>
46 #include <TopoDS_Face.hxx>
47 #include <TColStd_IndexedMapOfInteger.hxx>
48 #include <TopTools_IndexedMapOfShape.hxx>
49 #include <BRep_Tool.hxx>
50 #include <gp_Pnt.hxx>
51 #include <gp_Pln.hxx>
52 #include <Geom_Plane.hxx>
53 #include <GProp_GProps.hxx>
54 #include <BRepGProp.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( -999.999, 999.999, step, 3 );
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         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         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
318     Standard_Boolean aRes = Standard_False;
319     Handle(SALOME_InteractiveObject) anIO = firstIObject();
320     GEOM::GEOM_Object_var aSelectedObj = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
321
322     if ( aRes && !aSelectedObj->_is_nil() )
323     {
324       TopoDS_Shape aShape;
325       if ( GEOMBase::GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
326       {
327         if ( aSelectedObj->GetType() == GEOM_MARKER && aShape.ShapeType() == TopAbs_FACE )
328         {
329           TopoDS_Face aFace = TopoDS::Face( aShape );
330           Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
331
332           if ( !aPlane.IsNull() )
333           {
334             gp_Ax3 anAx3 = aPlane->Pln().Position();
335             gp_Pnt aLoc = anAx3.Location();
336             gp_Dir aXDir = anAx3.XDirection();
337             gp_Dir aYDir = anAx3.YDirection();
338
339             myData[ X ]->SetValue( aLoc.X() );
340             myData[ Y ]->SetValue( aLoc.Y() );
341             myData[ Z ]->SetValue( aLoc.Z() );
342
343             myData[ DX1 ]->SetValue( aXDir.X() );
344             myData[ DY1 ]->SetValue( aXDir.Y() );
345             myData[ DZ1 ]->SetValue( aXDir.Z() );
346
347             myData[ DX2 ]->SetValue( aYDir.X() );
348             myData[ DY2 ]->SetValue( aYDir.Y() );
349             myData[ DZ2 ]->SetValue( aYDir.Z() );
350             ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->clearSelected();
351           }
352         }
353         else
354         {
355           TColStd_IndexedMapOfInteger aMap;
356           ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( anIO, aMap );
357           if ( aMap.Extent() == 1 )
358           {
359             int anIndex = aMap( 1 );
360             TopTools_IndexedMapOfShape aShapes;
361             TopExp::MapShapes( aShape, aShapes );
362             aShape = aShapes.FindKey( anIndex );
363             ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->clearSelected();
364           }
365           
366
367           if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
368           {
369             gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
370             myData[ X ]->SetValue( aPnt.X() );
371             myData[ Y ]->SetValue( aPnt.Y() );
372             myData[ Z ]->SetValue( aPnt.Z() );
373           }
374         }
375       }
376     }
377   }
378
379   displayPreview();
380 }
381
382
383 //=================================================================================
384 // function : onSelectionDone()
385 // purpose  : Called when selection as changed or other case
386 //=================================================================================
387 void BasicGUI_MarkerDlg::onSelectionDone()
388 {
389   if ( getConstructorId() == 0 )
390   {
391     onSelectionDone0();
392     return;
393   }
394     
395
396   myEditCurrentArgument->setText("");
397   QString aName;
398
399   if ( IObjectCount() == 1 ) {
400     Standard_Boolean aRes = Standard_False;
401     Handle(SALOME_InteractiveObject) anIO = firstIObject();
402     GEOM::GEOM_Object_var aSelectedObj = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
403
404     if ( !CORBA::is_nil( aSelectedObj ) && aRes ) {
405       aName = GEOMBase::GetName( aSelectedObj );
406       TopoDS_Shape aShape;
407       if ( GEOMBase::GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) ) {
408         GEOM::short_array anIndexes;
409
410         TColStd_IndexedMapOfInteger aMap;
411         ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( anIO, aMap );
412         
413         if ( !aMap.IsEmpty() ) { 
414           int anIndex = aMap( 1 );
415           TopTools_IndexedMapOfShape aShapes;
416           TopExp::MapShapes( aShape, aShapes );
417           aShape = aShapes.FindKey( anIndex );
418         }
419
420         if ( getConstructorId() == 1 ) {
421           if ( !aShape.IsNull() ) {
422             gp_Pnt aPnt;
423             if (aShape.ShapeType() == TopAbs_VERTEX) {
424               aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
425             } 
426             else {
427               GProp_GProps aSystem;
428               if (aShape.ShapeType() == TopAbs_EDGE || aShape.ShapeType() == TopAbs_WIRE)
429                 BRepGProp::LinearProperties(aShape, aSystem);
430               else if (aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_SHELL)
431                 BRepGProp::SurfaceProperties(aShape, aSystem);
432               else
433                 BRepGProp::VolumeProperties(aShape, aSystem);
434               
435               aPnt = aSystem.CentreOfMass();
436             }
437             
438             gp_Ax3 anAx3;
439             anAx3.Transform(aShape.Location().Transformation());
440             if(aShape.ShapeType() == TopAbs_FACE) {
441               Handle(Geom_Surface) aGS = BRep_Tool::Surface( TopoDS::Face( aShape ) );
442               if (!aGS.IsNull() && aGS->IsKind( STANDARD_TYPE( Geom_Plane ) ) ) {
443                 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast( aGS );
444                 gp_Pln aPln = aGPlane->Pln();
445                 anAx3 = aPln.Position();
446               }
447             }
448             
449             gp_Dir aDirX = anAx3.XDirection();
450             gp_Dir aDirY = anAx3.YDirection();
451             
452             myData[ X ]->SetValue( aPnt.X() );
453             myData[ Y ]->SetValue( aPnt.Y() );
454             myData[ Z ]->SetValue( aPnt.Z() );
455             
456             myData[ DX1 ]->SetValue( aDirX.X() );
457             myData[ DY1 ]->SetValue( aDirX.Y() );
458             myData[ DZ1 ]->SetValue( aDirX.Z() );
459             
460             myData[ DX2 ]->SetValue( aDirY.X() );
461             myData[ DY2 ]->SetValue( aDirY.Y() );
462             myData[ DZ2 ]->SetValue( aDirY.Z() );
463             
464             myEditCurrentArgument->setText( aName );
465           }
466           else {
467             myData[ X ]->SetValue( 0 );
468             myData[ Y ]->SetValue( 0 );
469             myData[ Z ]->SetValue( 0 );
470             
471             myData[ DX1 ]->SetValue( 0 );
472             myData[ DY1 ]->SetValue( 0 );
473             myData[ DZ1 ]->SetValue( 0 );
474             
475             myData[ DX2 ]->SetValue( 0 );
476             myData[ DY2 ]->SetValue( 0 );
477             myData[ DZ2 ]->SetValue( 0 );
478           }
479         }
480         else if ( getConstructorId() == 2 ) {
481           if (myEditCurrentArgument == Group2->LineEdit1) {
482             if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) {
483               gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
484               myData[ X ]->SetValue( aPnt.X() );
485               myData[ Y ]->SetValue( aPnt.Y() );
486               myData[ Z ]->SetValue( aPnt.Z() );
487               myEditCurrentArgument->setText( aName );
488             }
489             else {
490               myData[ X ]->SetValue( 0 );
491               myData[ Y ]->SetValue( 0 );
492               myData[ Z ]->SetValue( 0 );
493             }
494           }
495           else if (myEditCurrentArgument == Group2->LineEdit2) {
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[ DX1 ]->SetValue( aDir.X() );
502               myData[ DY1 ]->SetValue( aDir.Y() );
503               myData[ DZ1 ]->SetValue( aDir.Z() );
504               myEditCurrentArgument->setText( aName );
505             }
506             else {
507               myData[ DX1 ]->SetValue( 0 );
508               myData[ DY1 ]->SetValue( 0 );
509               myData[ DZ1 ]->SetValue( 0 );
510             }
511           }
512           else if (myEditCurrentArgument == Group2->LineEdit3) {
513             if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE ) {
514               gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(TopoDS::Edge(aShape)));
515               gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(TopoDS::Edge(aShape)));
516               gp_Dir aDir(gp_Vec(aP1, aP2));
517               
518               myData[ DX2 ]->SetValue( aDir.X() );
519               myData[ DY2 ]->SetValue( aDir.Y() );
520               myData[ DZ2 ]->SetValue( aDir.Z() );
521               myEditCurrentArgument->setText( aName );
522             }
523             else {
524               myData[ DX2 ]->SetValue( 0 );
525               myData[ DY2 ]->SetValue( 0 );
526               myData[ DZ2 ]->SetValue( 0 );
527             }
528           }
529         }
530       }
531     }
532   }
533   else {
534     if ( getConstructorId() == 1 ) {
535       myData[ X ]->SetValue( 0 );
536       myData[ Y ]->SetValue( 0 );
537       myData[ Z ]->SetValue( 0 );
538       
539       myData[ DX1 ]->SetValue( 0 );
540       myData[ DY1 ]->SetValue( 0 );
541       myData[ DZ1 ]->SetValue( 0 );
542       
543       myData[ DX2 ]->SetValue( 0 );
544       myData[ DY2 ]->SetValue( 0 );
545       myData[ DZ2 ]->SetValue( 0 );
546     }
547     else if ( getConstructorId() == 2 ) {
548       if (myEditCurrentArgument == Group2->LineEdit1) {
549         myData[ X ]->SetValue( 0 );
550         myData[ Y ]->SetValue( 0 );
551         myData[ Z ]->SetValue( 0 );
552       }
553       else if (myEditCurrentArgument == Group2->LineEdit2) {
554         myData[ DX1 ]->SetValue( 0 );
555         myData[ DY1 ]->SetValue( 0 );
556         myData[ DZ1 ]->SetValue( 0 );
557       }
558       else if (myEditCurrentArgument == Group2->LineEdit3) {
559         myData[ DX2 ]->SetValue( 0 );
560         myData[ DY2 ]->SetValue( 0 );
561         myData[ DZ2 ]->SetValue( 0 );
562       }
563     }    
564   }
565   
566   displayPreview();
567 }
568
569 //=================================================================================
570 // function : SetEditCurrentArgument()
571 // purpose  :
572 //=================================================================================
573 void BasicGUI_MarkerDlg::SetEditCurrentArgument()
574 {
575   QPushButton* send = (QPushButton*)sender();
576   
577   if(send == Group1->PushButton1) {
578     myEditCurrentArgument = Group1->LineEdit1;
579     globalSelection( GEOM_ALLGEOM );
580   }
581   else if(send == Group2->PushButton1) {
582     myEditCurrentArgument = Group2->LineEdit1;
583     globalSelection( GEOM_POINT );
584   }
585   else if(send == Group2->PushButton2) {
586     myEditCurrentArgument = Group2->LineEdit2;
587       globalSelection( GEOM_LINE );
588   }
589   else if(send == Group2->PushButton3) {
590     myEditCurrentArgument = Group2->LineEdit3;
591     globalSelection( GEOM_LINE );
592   }
593   
594   myEditCurrentArgument->setFocus();
595   onSelectionDone();
596 }
597
598 //=================================================================================
599 // function : LineEditReturnPressed()
600 // purpose  :
601 //=================================================================================
602 void BasicGUI_MarkerDlg::LineEditReturnPressed()
603 {
604   QLineEdit* send = (QLineEdit*)sender();
605
606   myEditCurrentArgument = send;
607   GEOMBase_Skeleton::LineEditReturnPressed();
608 }
609
610 //=================================================================================
611 // function : onActivate()
612 // purpose  :
613 //=================================================================================
614 void BasicGUI_MarkerDlg::onActivate()
615 {
616   GEOMBase_Skeleton::ActivateThisDialog();
617   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
618            SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionDone() ) );
619
620   ConstructorsClicked( getConstructorId() );
621 }
622
623 //=================================================================================
624 // function : onDeactivate()
625 // purpose  : public slot to deactivate if active
626 //=================================================================================
627 void BasicGUI_MarkerDlg::onDeactivate()
628 {
629   GEOMBase_Skeleton::DeactivateActiveDialog();
630 }
631
632 //=================================================================================
633 // function : enterEvent()
634 // purpose  :
635 //=================================================================================
636 void BasicGUI_MarkerDlg::enterEvent(QEvent* e)
637 {                       
638   if ( !GroupConstructors->isEnabled() )
639     onActivate();
640 }
641
642 //=================================================================================
643 // function : createOperation
644 // purpose  :
645 //=================================================================================
646 GEOM::GEOM_IOperations_ptr BasicGUI_MarkerDlg::createOperation()
647 {
648   return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
649 }
650
651 //=================================================================================
652 // function : isValid
653 // purpose  :
654 //=================================================================================
655 bool BasicGUI_MarkerDlg::isValid( QString& msg )
656 {
657   const int id = getConstructorId();
658   gp_Vec v1( myData[ DX1 ]->GetValue(), myData[ DY1 ]->GetValue(), myData[ DZ1 ]->GetValue() ),
659          v2( myData[ DX2 ]->GetValue(), myData[ DY2 ]->GetValue(), myData[ DZ2 ]->GetValue() );
660
661   bool isOk = false;
662   // we will got exception if the magnitude of any of the 2 vectors <= gp::Resolution()
663   // Vectors shouldn't be checked for being orthogonal here!
664   if ( v1.Magnitude() > gp::Resolution() && v2.Magnitude() > gp::Resolution() ) {
665     isOk = !v1.IsParallel( v2, Precision::Angular() );
666     if ( !isOk )
667       msg += tr( "VEC_PARALLEL" );
668   }
669
670   switch ( id )
671   {
672     case 0:
673       return isOk;
674     case 1:
675       return !Group1->LineEdit1->text().isEmpty() && isOk;
676     case 2:
677       return !Group2->LineEdit1->text().isEmpty() && 
678              !Group2->LineEdit2->text().isEmpty() && 
679              !Group2->LineEdit3->text().isEmpty() && isOk;
680   }
681   return false;
682 }
683
684 //=================================================================================
685 // function : execute
686 // purpose  :
687 //=================================================================================
688 bool BasicGUI_MarkerDlg::execute( ObjectList& objects )
689 {
690   GEOM::GEOM_Object_var anObj = GEOM::GEOM_IBasicOperations::_narrow(
691     getOperation() )->MakeMarker( myData[ X   ]->GetValue(), myData[ Y   ]->GetValue(), myData[ Z   ]->GetValue(),
692                                   myData[ DX1 ]->GetValue(), myData[ DY1 ]->GetValue(), myData[ DZ1 ]->GetValue(),
693                                   myData[ DX2 ]->GetValue(), myData[ DY2 ]->GetValue(), myData[ DZ2 ]->GetValue() );
694
695   if ( !anObj->_is_nil() )
696     objects.push_back( anObj._retn() );
697
698   return true;
699 }
700
701 //=================================================================================
702 // function : closeEvent
703 // purpose  :
704 //=================================================================================
705 void BasicGUI_MarkerDlg::closeEvent( QCloseEvent* e )
706 {
707   GEOMBase_Skeleton::closeEvent( e );
708 }
709
710 //=================================================================================
711 // function : onValueChanged
712 // purpose  :
713 //=================================================================================
714 void BasicGUI_MarkerDlg::onValueChanged( double )
715 {
716   displayPreview();
717 }
718
719 //=================================================================================
720 // function : displayPreview
721 // purpose  :
722 //=================================================================================
723 void BasicGUI_MarkerDlg::displayPreview ( const bool   activate,
724                                           const bool   update,
725                                           const bool   toRemoveFromEngine,
726                                           const double lineWidth )
727 {
728   if ( !myBlockPreview )
729   {
730     GEOMBase_Skeleton::displayPreview( activate, update, toRemoveFromEngine, lineWidth );
731     if ( myConstructorId == 0 )
732     {
733       GEOMBase_Skeleton::activate( GEOM_MARKER );
734     }
735   }
736 }
737
738
739
740
741
742
743
744
745
746
747
748
749
750