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