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