Salome HOME
a24113d4e400747f0dabc8b03a62439a31dd0dfb
[modules/geom.git] / src / BasicGUI / BasicGUI_MarkerDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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 // GEOM GEOMGUI : GUI for Geometry component
23 // File   : BasicGUI_MarkerDlg.cxx
24 // Author : Sergey LITONIN, Open CASCADE S.A.S. (sergey.litonin@opencascade.com)
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   Group1->PushButton1->setDown( true );
80
81   Group2 = new DlgRef_3Sel( centralWidget() );
82
83   Group2->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
84   Group2->TextLabel1->setText( tr( "GEOM_POINT" ) );
85   Group2->TextLabel2->setText( tr( "XDIR" ) );
86   Group2->TextLabel3->setText( tr( "YDIR" ) );
87   Group2->PushButton1->setIcon( iconSelect );
88   Group2->PushButton2->setIcon( iconSelect );
89   Group2->PushButton3->setIcon( iconSelect );
90   Group2->PushButton1->setDown( true );
91
92   aMainGrp = new QFrame( centralWidget() );
93   aMainGrp->setFrameStyle( QFrame::NoFrame | QFrame::Plain );
94   aMainGrp->setContentsMargins( 0, 0, 0, 0 );
95   QHBoxLayout* aMainGrpLayout = new QHBoxLayout( aMainGrp );
96   aMainGrpLayout->setMargin( 0 );
97   
98   QGroupBox* anOriGrp = new QGroupBox( tr( "ORIGIN" ), aMainGrp );
99   QVBoxLayout* anOriGrpLayout = new QVBoxLayout( anOriGrp );
100
101   anOriGrpLayout->addWidget( new QLabel( tr( "GEOM_X" ), anOriGrp ) );
102   myData[ X ] = new SalomeApp_DoubleSpinBox( anOriGrp );
103   anOriGrpLayout->addWidget( myData[ X ] );
104   anOriGrpLayout->addWidget( new QLabel( tr( "GEOM_Y" ), anOriGrp ) );
105   myData[ Y ] = new SalomeApp_DoubleSpinBox( anOriGrp );
106   anOriGrpLayout->addWidget( myData[ Y ] );
107   anOriGrpLayout->addWidget( new QLabel( tr( "GEOM_Z" ), anOriGrp ) );
108   myData[ Z ] = new SalomeApp_DoubleSpinBox( anOriGrp );
109   anOriGrpLayout->addWidget( myData[ Z ] );
110
111   aMainGrpLayout->addWidget( anOriGrp );
112
113   QGroupBox* aXAxisGrp = new QGroupBox( tr( "XDIR" ), aMainGrp );
114   QVBoxLayout* aXAxisGrpLayout = new QVBoxLayout( aXAxisGrp );
115
116   aXAxisGrpLayout->addWidget( new QLabel( tr( "DX" ), aXAxisGrp ) );
117   myData[ DX1 ] = new SalomeApp_DoubleSpinBox( aXAxisGrp );
118   aXAxisGrpLayout->addWidget( myData[ DX1 ] );
119   aXAxisGrpLayout->addWidget( new QLabel( tr( "DY" ), aXAxisGrp ) );
120   myData[ DY1 ] = new SalomeApp_DoubleSpinBox( aXAxisGrp );
121   aXAxisGrpLayout->addWidget( myData[ DY1 ] );
122   aXAxisGrpLayout->addWidget( new QLabel( tr( "DZ" ), aXAxisGrp ) );
123   myData[ DZ1 ] = new SalomeApp_DoubleSpinBox( aXAxisGrp );
124   aXAxisGrpLayout->addWidget( myData[ DZ1 ] );
125
126   aMainGrpLayout->addWidget( aXAxisGrp );
127
128   QGroupBox* anYAxisGrp = new QGroupBox( tr( "YDIR" ), aMainGrp );
129   QVBoxLayout* anYAxisGrpLayout = new QVBoxLayout( anYAxisGrp );
130
131   anYAxisGrpLayout->addWidget( new QLabel( tr( "DX" ), anYAxisGrp ) );
132   myData[ DX2 ] = new SalomeApp_DoubleSpinBox( anYAxisGrp );
133   anYAxisGrpLayout->addWidget( myData[ DX2 ] );
134   anYAxisGrpLayout->addWidget( new QLabel( tr( "DY" ), anYAxisGrp ) );
135   myData[ DY2 ] = new SalomeApp_DoubleSpinBox( anYAxisGrp );
136   anYAxisGrpLayout->addWidget( myData[ DY2 ] );
137   anYAxisGrpLayout->addWidget( new QLabel( tr( "DZ" ), anYAxisGrp ) );
138   myData[ DZ2 ] = new SalomeApp_DoubleSpinBox( anYAxisGrp );
139   anYAxisGrpLayout->addWidget( myData[ DZ2 ] );
140
141   aMainGrpLayout->addWidget( anYAxisGrp );
142
143   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
144   layout->setMargin( 0 ); layout->setSpacing( 6 );
145   layout->addWidget( aMainGrp );
146   layout->addWidget( Group1 );
147   layout->addWidget( Group2 );
148
149   setHelpFileName( "create_lcs_page.html" );
150
151   Init();
152 }
153
154
155 //=================================================================================
156 // function : ~BasicGUI_MarkerDlg()
157 // purpose  : Destroys the object and frees any allocated resources
158 //=================================================================================
159 BasicGUI_MarkerDlg::~BasicGUI_MarkerDlg()
160 {
161 }
162
163
164 //=================================================================================
165 // function : Init()
166 // purpose  :
167 //=================================================================================
168 void BasicGUI_MarkerDlg::Init()
169 {
170   myShape = myPoint = myVectorX = myVectorY = GEOM::GEOM_Object::_nil();
171   myBlockPreview = false;
172   myConstructorId = -1;
173   myEditCurrentArgument = Group1->LineEdit1;
174   Group1->LineEdit1->setReadOnly( true );
175   Group2->LineEdit1->setReadOnly( true );
176   Group2->LineEdit2->setReadOnly( true );
177   Group2->LineEdit3->setReadOnly( true );
178   Group2->LineEdit1->setEnabled( true );
179   Group2->LineEdit2->setEnabled( false );
180   Group2->LineEdit3->setEnabled( false );
181
182   connect( this,                SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
183
184   connect( Group1->PushButton1, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
185   connect( Group2->PushButton1, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
186   connect( Group2->PushButton2, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
187   connect( Group2->PushButton3, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
188
189   connect( Group1->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
190   connect( Group2->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
191   connect( Group2->LineEdit2,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
192   connect( Group2->LineEdit3,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
193
194   connect( myGeomGUI,           SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( onDeactivate() ) );
195   connect( myGeomGUI,           SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
196
197   connect( buttonOk(),          SIGNAL( clicked() ), this, SLOT( onOk() ) );
198   connect( buttonApply(),       SIGNAL( clicked() ), this, SLOT( onApply() ) );
199
200   connect( myGeomGUI->getApp()->selectionMgr(),
201            SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionDone() ) );
202
203   initName( tr( "LCS_NAME" ) );
204
205   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
206   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
207
208   for ( DataMap::iterator anIter = myData.begin(); anIter != myData.end(); ++anIter ) {
209     initSpinBox( anIter.value(), COORD_MIN, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
210     connect( anIter.value(), SIGNAL( valueChanged( double ) ),
211              this, SLOT( onValueChanged( double ) ) );
212   }
213   
214   myBlockPreview = true;
215   for ( DataMap::iterator anIter = myData.begin(); anIter != myData.end(); ++anIter )
216     anIter.value()->setValue( 0 );
217   myData[ DX1 ]->setValue( 1 );
218   myData[ DY2 ]->setValue( 1 );
219   myBlockPreview = false;
220
221   ConstructorsClicked( 0 );
222 }
223
224 //=================================================================================
225 // function : ConstructorsClicked()
226 // purpose  : Radio button management
227 //=================================================================================
228 void BasicGUI_MarkerDlg::ConstructorsClicked( int constructorId )
229 {
230   if ( myConstructorId == constructorId && myConstructorId == 0 ) {
231     globalSelection(); // close local contexts, if any
232     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
233     activate( GEOM_MARKER );
234     return;
235   }
236
237   myConstructorId = constructorId;
238
239   disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
240
241   switch ( constructorId ) {
242   case 0:
243     {
244       Group1->hide();
245       Group2->hide();
246       aMainGrp->show();
247       globalSelection(); // close local contexts, if any
248       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
249       activate( GEOM_MARKER );
250       break;
251     }
252   case 1:
253     {
254       aMainGrp->hide();
255       Group2->hide();
256       Group1->show();
257       Group1->PushButton1->setDown( true );
258       globalSelection( GEOM_ALLGEOM );
259       myEditCurrentArgument = Group1->LineEdit1;
260       Group1->LineEdit1->setText( "" );
261       myShape = GEOM::GEOM_Object::_nil();
262       break;
263     }
264   case 2:
265     {
266       aMainGrp->hide();
267       Group1->hide();
268       Group2->show();
269       Group2->PushButton1->setDown( true );
270       Group2->PushButton2->setDown( false );
271       Group2->PushButton3->setDown( false );
272       globalSelection(); // close local contexts, if any
273       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
274       myEditCurrentArgument = Group2->LineEdit1;
275       Group2->LineEdit1->setText( "" );
276       Group2->LineEdit2->setText( "" );
277       Group2->LineEdit3->setText( "" );
278       Group2->LineEdit1->setEnabled( true );
279       Group2->LineEdit2->setEnabled( false );
280       Group2->LineEdit3->setEnabled( false );
281       myPoint = GEOM::GEOM_Object::_nil();
282       myVectorX = GEOM::GEOM_Object::_nil();
283       myVectorY = GEOM::GEOM_Object::_nil();
284       break;
285     }
286   }
287
288   displayPreview();
289
290   qApp->processEvents();
291   updateGeometry();
292   resize( minimumSizeHint() );
293   
294   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
295            this, SLOT( onSelectionDone() ) );
296   onSelectionDone();
297 }
298
299 //=================================================================================
300 // function : onOk()
301 // purpose  :
302 //=================================================================================
303 void BasicGUI_MarkerDlg::onOk()
304 {
305   if ( onApply() )
306     ClickOnCancel();
307 }
308
309 //=================================================================================
310 // function : onApply()
311 // purpose  :
312 //=================================================================================
313 bool BasicGUI_MarkerDlg::onApply()
314 {
315   if ( !onAccept() )
316     return false;
317
318   initName();
319   ConstructorsClicked( getConstructorId() );
320
321   return true;
322 }
323
324 //=================================================================================
325 // function : onSelectionDone0()
326 // purpose  : Reaction on selection when first method of creation is current one
327 //=================================================================================
328 void BasicGUI_MarkerDlg::onSelectionDone0()
329 {
330   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
331   SALOME_ListIO aSelList;
332   aSelMgr->selectedObjects(aSelList);
333
334   if (aSelList.Extent() == 1) {
335     Standard_Boolean aRes = Standard_False;
336     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
337     GEOM::GEOM_Object_var aSelectedObj = GEOMBase::ConvertIOinGEOMObject(anIO, aRes);
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   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
407   SALOME_ListIO aSelList;
408   aSelMgr->selectedObjects(aSelList);
409
410   if (aSelList.Extent() == 1) {
411     Standard_Boolean aRes = Standard_False;
412     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
413     GEOM::GEOM_Object_var aSelectedObj = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
414
415     if ( !CORBA::is_nil( aSelectedObj ) && aRes ) {
416       QString aName = GEOMBase::GetName( aSelectedObj );
417       
418       if ( getConstructorId() == 1 ) { // by shape position
419         TopoDS_Shape aShape;
420         if ( GEOMBase::GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) )
421           myShape = aSelectedObj;
422         myEditCurrentArgument->setText( aName );
423       }
424       else if ( getConstructorId() == 2 ) { // by point and two vectors
425         TopoDS_Shape aShape;
426         if ( GEOMBase::GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) ) {
427           TopAbs_ShapeEnum aNeedType = TopAbs_EDGE;
428           if ( myEditCurrentArgument == Group2->LineEdit1 )
429             aNeedType = TopAbs_VERTEX;
430           
431           TColStd_IndexedMapOfInteger aMap;
432           aSelMgr->GetIndexes( anIO, aMap );
433
434           if ( !aMap.IsEmpty() ) {
435             int anIndex = aMap( 1 );
436             if ( aNeedType == TopAbs_EDGE )
437               aName += QString( "_edge_%1" ).arg( anIndex );
438             else
439               aName += QString( "_vertex_%1" ).arg( anIndex );
440
441             TopTools_IndexedMapOfShape aShapes;
442             TopExp::MapShapes( aShape, aShapes );
443             aShape = aShapes.FindKey( anIndex );
444           }
445
446           if ( myEditCurrentArgument == Group2->LineEdit1 ) {
447             if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) {
448               myPoint = aSelectedObj;
449               myEditCurrentArgument->setText( aName );
450               if (Group2->LineEdit2->text() == "")
451                 Group2->PushButton2->click();
452             }
453           }
454           else if (myEditCurrentArgument == Group2->LineEdit2) {
455             if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE ) {
456               myVectorX = aSelectedObj;
457               myEditCurrentArgument->setText( aName );
458               if (Group2->LineEdit3->text() == "")
459                 Group2->PushButton3->click();
460             }
461           }
462           else if ( myEditCurrentArgument == Group2->LineEdit3 ) {
463             if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE ) {
464               myVectorY = aSelectedObj;
465               myEditCurrentArgument->setText( aName );
466               if (Group2->LineEdit1->text() == "")
467                 Group2->PushButton1->click();
468             }
469           }
470         }
471       }
472     }
473   }
474   else {
475     if ( getConstructorId() == 1 ) {
476       myShape = GEOM::GEOM_Object::_nil();
477     } else if ( getConstructorId() == 2 ) {
478       if ( myEditCurrentArgument == Group2->LineEdit1 )
479         myPoint = GEOM::GEOM_Object::_nil();
480       else if ( myEditCurrentArgument == Group2->LineEdit2 )
481         myVectorX = GEOM::GEOM_Object::_nil();
482       else if ( myEditCurrentArgument == Group2->LineEdit3 )
483         myVectorY = GEOM::GEOM_Object::_nil();
484     }
485   }
486
487   displayPreview();
488 }
489
490 //=================================================================================
491 // function : SetEditCurrentArgument()
492 // purpose  :
493 //=================================================================================
494 void BasicGUI_MarkerDlg::SetEditCurrentArgument()
495 {
496   QPushButton* send = (QPushButton*)sender();
497   globalSelection(); // close local contexts, if any
498
499   if ( send == Group1->PushButton1 ) {
500     myEditCurrentArgument = Group1->LineEdit1;
501     globalSelection( GEOM_ALLGEOM );
502   }
503   else if ( send == Group2->PushButton1 ) {
504     myEditCurrentArgument = Group2->LineEdit1;
505     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
506     Group2->PushButton2->setDown( false );
507     Group2->PushButton3->setDown( false );
508     Group2->LineEdit1->setEnabled( true );
509     Group2->LineEdit2->setEnabled( false );
510     Group2->LineEdit3->setEnabled( false );
511   }
512   else if ( send == Group2->PushButton2 ) {
513     myEditCurrentArgument = Group2->LineEdit2;
514     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
515     Group2->PushButton1->setDown( false );
516     Group2->PushButton3->setDown( false );
517     Group2->LineEdit1->setEnabled( false );
518     Group2->LineEdit2->setEnabled( true );
519     Group2->LineEdit3->setEnabled( false );
520   }
521   else if ( send == Group2->PushButton3 ) {
522     myEditCurrentArgument = Group2->LineEdit3;
523     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
524     Group2->PushButton1->setDown( false );
525     Group2->PushButton2->setDown( false );
526     Group2->LineEdit1->setEnabled( false );
527     Group2->LineEdit2->setEnabled( false );
528     Group2->LineEdit3->setEnabled( true );
529   }
530   
531   myEditCurrentArgument->setFocus();
532   send->setDown(true);
533   onSelectionDone();
534 }
535
536 //=================================================================================
537 // function : LineEditReturnPressed()
538 // purpose  :
539 //=================================================================================
540 void BasicGUI_MarkerDlg::LineEditReturnPressed()
541 {
542   QLineEdit* send = (QLineEdit*)sender();
543
544   myEditCurrentArgument = send;
545   GEOMBase_Skeleton::LineEditReturnPressed();
546 }
547
548 //=================================================================================
549 // function : onActivate()
550 // purpose  :
551 //=================================================================================
552 void BasicGUI_MarkerDlg::onActivate()
553 {
554   GEOMBase_Skeleton::ActivateThisDialog();
555   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
556            this, SLOT( onSelectionDone() ) );
557
558   ConstructorsClicked( getConstructorId() );
559 }
560
561 //=================================================================================
562 // function : onDeactivate()
563 // purpose  : public slot to deactivate if active
564 //=================================================================================
565 void BasicGUI_MarkerDlg::onDeactivate()
566 {
567   GEOMBase_Skeleton::DeactivateActiveDialog();
568 }
569
570 //=================================================================================
571 // function : enterEvent()
572 // purpose  :
573 //=================================================================================
574 void BasicGUI_MarkerDlg::enterEvent( QEvent* )
575 {
576   if ( !mainFrame()->GroupConstructors->isEnabled() )
577     onActivate();
578 }
579
580 //=================================================================================
581 // function : createOperation
582 // purpose  :
583 //=================================================================================
584 GEOM::GEOM_IOperations_ptr BasicGUI_MarkerDlg::createOperation()
585 {
586   return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
587 }
588
589 //=================================================================================
590 // function : isValid
591 // purpose  :
592 //=================================================================================
593 bool BasicGUI_MarkerDlg::isValid( QString& msg )
594 {
595   const int id = getConstructorId();
596   switch ( id ) {
597     case 0: {
598       gp_Vec v1( myData[ DX1 ]->value(), myData[ DY1 ]->value(), myData[ DZ1 ]->value() ),
599         v2( myData[ DX2 ]->value(), myData[ DY2 ]->value(), myData[ DZ2 ]->value() );
600       
601       bool isOk = false;
602       // we will got exception if the magnitude of any of the 2 vectors <= gp::Resolution()
603       // Vectors shouldn't be checked for being orthogonal here!
604       if ( v1.Magnitude() > gp::Resolution() && v2.Magnitude() > gp::Resolution() ) {
605         isOk = !v1.IsParallel( v2, Precision::Angular() );
606         if ( !isOk )
607           msg += tr( "VEC_PARALLEL" );
608       }
609       bool ok = true;
610       for ( DataMap::iterator anIter = myData.begin(); anIter != myData.end(); ++anIter )
611         ok = anIter.value()->isValid( msg, !IsPreview()) && ok;
612       return isOk && ok;
613     }
614     case 1:
615       return !myShape->_is_nil();
616     case 2:
617       return !myPoint->_is_nil() && !myVectorX->_is_nil() && !myVectorY->_is_nil();
618   }
619   return false;
620 }
621
622 //=================================================================================
623 // function : execute
624 // purpose  :
625 //=================================================================================
626 bool BasicGUI_MarkerDlg::execute( ObjectList& objects )
627 {
628   GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow( getOperation() );
629   GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_nil();
630   QStringList aParameters;
631   const int id = getConstructorId();
632   if (id == 0) {
633     anObj = anOper->MakeMarker( myData[ X   ]->value(), myData[ Y   ]->value(), 
634                                 myData[ Z   ]->value(), myData[ DX1 ]->value(),
635                                 myData[ DY1 ]->value(), myData[ DZ1 ]->value(),
636                                 myData[ DX2 ]->value(), myData[ DY2 ]->value(),
637                                 myData[ DZ2 ]->value() );
638     aParameters<<myData[X]->text();
639     aParameters<<myData[Y]->text();
640     aParameters<<myData[Z]->text();
641     aParameters<<myData[ DX1 ]->text(); 
642     aParameters<<myData[ DY1 ]->text(); 
643     aParameters<<myData[ DZ1 ]->text();
644     aParameters<<myData[ DX2 ]->text();
645     aParameters<<myData[ DY2 ]->text();
646     aParameters<<myData[ DZ2 ]->text();
647   } else if (id == 1) {
648     anObj = anOper->MakeMarkerFromShape( myShape ); 
649   } else if (id == 2) {
650     anObj = anOper->MakeMarkerPntTwoVec( myPoint, myVectorX, myVectorY ); 
651   }
652   
653   if ( !anObj->_is_nil() ) {
654     if ( !IsPreview() && id == 0)
655       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
656     objects.push_back( anObj._retn() );
657   }
658
659   return true;
660 }
661
662 //=================================================================================
663 // function : onValueChanged
664 // purpose  :
665 //=================================================================================
666 void BasicGUI_MarkerDlg::onValueChanged( double )
667 {
668   displayPreview();
669 }
670
671 //=================================================================================
672 // function : displayPreview
673 // purpose  :
674 //=================================================================================
675 void BasicGUI_MarkerDlg::displayPreview ( const bool   activate,
676                                           const bool   update,
677                                           const bool   toRemoveFromEngine,
678                                           const double lineWidth )
679 {
680   if ( !myBlockPreview ) {
681     GEOMBase_Skeleton::displayPreview( activate, update, toRemoveFromEngine, lineWidth );
682     if ( myConstructorId == 0 )
683       GEOMBase_Skeleton::activate( GEOM_MARKER );
684   }
685 }