Salome HOME
Merge with OCC-V2_1_0_deb
[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         }
456         else if ( getConstructorId() == 2 ) {
457           if (myEditCurrentArgument == Group2->LineEdit1) {
458             if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) {
459               gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
460               myData[ X ]->SetValue( aPnt.X() );
461               myData[ Y ]->SetValue( aPnt.Y() );
462               myData[ Z ]->SetValue( aPnt.Z() );
463               myEditCurrentArgument->setText( aName );
464             }
465           }
466           else if (myEditCurrentArgument == Group2->LineEdit2) {
467             if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE ) {
468               gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(TopoDS::Edge(aShape)));
469               gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(TopoDS::Edge(aShape)));
470               gp_Dir aDir(gp_Vec(aP1, aP2));
471
472               myData[ DX1 ]->SetValue( aDir.X() );
473               myData[ DY1 ]->SetValue( aDir.Y() );
474               myData[ DZ1 ]->SetValue( aDir.Z() );
475               myEditCurrentArgument->setText( aName );
476             }
477           }
478           else if (myEditCurrentArgument == Group2->LineEdit3) {
479             if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE ) {
480               gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(TopoDS::Edge(aShape)));
481               gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(TopoDS::Edge(aShape)));
482               gp_Dir aDir(gp_Vec(aP1, aP2));
483
484               myData[ DX2 ]->SetValue( aDir.X() );
485               myData[ DY2 ]->SetValue( aDir.Y() );
486               myData[ DZ2 ]->SetValue( aDir.Z() );
487               myEditCurrentArgument->setText( aName );
488             }
489           }
490         }
491       }
492     }
493   }
494
495   displayPreview();
496 }
497
498 //=================================================================================
499 // function : SetEditCurrentArgument()
500 // purpose  :
501 //=================================================================================
502 void BasicGUI_MarkerDlg::SetEditCurrentArgument()
503 {
504   QPushButton* send = (QPushButton*)sender();
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     globalSelection( GEOM_POINT );
513   }
514   else if(send == Group2->PushButton2) {
515     myEditCurrentArgument = Group2->LineEdit2;
516       globalSelection( GEOM_LINE );
517   }
518   else if(send == Group2->PushButton3) {
519     myEditCurrentArgument = Group2->LineEdit3;
520     globalSelection( GEOM_LINE );
521   }
522   
523   myEditCurrentArgument->setFocus();
524   onSelectionDone();
525 }
526
527 //=================================================================================
528 // function : LineEditReturnPressed()
529 // purpose  :
530 //=================================================================================
531 void BasicGUI_MarkerDlg::LineEditReturnPressed()
532 {
533   QLineEdit* send = (QLineEdit*)sender();
534
535   myEditCurrentArgument = send;
536   GEOMBase_Skeleton::LineEditReturnPressed();
537 }
538
539 //=================================================================================
540 // function : onActivate()
541 // purpose  :
542 //=================================================================================
543 void BasicGUI_MarkerDlg::onActivate()
544 {
545   GEOMBase_Skeleton::ActivateThisDialog();
546   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionDone() ) );
547
548   ConstructorsClicked( getConstructorId() );
549 }
550
551 //=================================================================================
552 // function : onDeactivate()
553 // purpose  : public slot to deactivate if active
554 //=================================================================================
555 void BasicGUI_MarkerDlg::onDeactivate()
556 {
557   GEOMBase_Skeleton::DeactivateActiveDialog();
558 }
559
560 //=================================================================================
561 // function : enterEvent()
562 // purpose  :
563 //=================================================================================
564 void BasicGUI_MarkerDlg::enterEvent(QEvent* e)
565 {                       
566   if ( !GroupConstructors->isEnabled() )
567     onActivate();
568 }
569
570 //=================================================================================
571 // function : createOperation
572 // purpose  :
573 //=================================================================================
574 GEOM::GEOM_IOperations_ptr BasicGUI_MarkerDlg::createOperation()
575 {
576   return getGeomEngine()->GetIBasicOperations( getStudyId() );
577 }
578
579 //=================================================================================
580 // function : isValid
581 // purpose  :
582 //=================================================================================
583 bool BasicGUI_MarkerDlg::isValid( QString& msg )
584 {
585   const int id = getConstructorId();
586   gp_Vec v1( myData[ DX1 ]->GetValue(), myData[ DY1 ]->GetValue(), myData[ DZ1 ]->GetValue() ),
587          v2( myData[ DX2 ]->GetValue(), myData[ DY2 ]->GetValue(), myData[ DZ2 ]->GetValue() );
588
589   bool isOrthogonal = false;
590   // we will got exception if the magnitude of any of the 2 vectors <= gp::Resolution()
591   if ( v1.Magnitude() > gp::Resolution() && v2.Magnitude() > gp::Resolution() )
592     isOrthogonal = v1.IsNormal( v2, Precision::Confusion() );
593
594   switch ( id )
595   {
596     case 0:
597       return isOrthogonal;
598     case 1:
599       return !Group1->LineEdit1->text().isEmpty() && isOrthogonal;
600     case 2:
601       return !Group2->LineEdit1->text().isEmpty() && 
602              !Group2->LineEdit2->text().isEmpty() && 
603              !Group2->LineEdit3->text().isEmpty() && isOrthogonal;
604   }
605   return false;
606 }
607
608 //=================================================================================
609 // function : execute
610 // purpose  :
611 //=================================================================================
612 bool BasicGUI_MarkerDlg::execute( ObjectList& objects )
613 {
614   GEOM::GEOM_Object_var anObj = GEOM::GEOM_IBasicOperations::_narrow(
615     getOperation() )->MakeMarker( myData[ X   ]->GetValue(), myData[ Y   ]->GetValue(), myData[ Z   ]->GetValue(),
616                                   myData[ DX1 ]->GetValue(), myData[ DY1 ]->GetValue(), myData[ DZ1 ]->GetValue(),
617                                   myData[ DX2 ]->GetValue(), myData[ DY2 ]->GetValue(), myData[ DZ2 ]->GetValue() );
618
619   if ( !anObj->_is_nil() )
620     objects.push_back( anObj._retn() );
621
622   return true;
623 }
624
625 //=================================================================================
626 // function : closeEvent
627 // purpose  :
628 //=================================================================================
629 void BasicGUI_MarkerDlg::closeEvent( QCloseEvent* e )
630 {
631   GEOMBase_Skeleton::closeEvent( e );
632 }
633
634 //=================================================================================
635 // function : onValueChanged
636 // purpose  :
637 //=================================================================================
638 void BasicGUI_MarkerDlg::onValueChanged( double )
639 {
640   displayPreview();
641 }
642
643 //=================================================================================
644 // function : displayPreview
645 // purpose  :
646 //=================================================================================
647 void BasicGUI_MarkerDlg::displayPreview ( const bool   activate,
648                                           const bool   update,
649                                           const bool   toRemoveFromEngine,
650                                           const double lineWidth )
651 {
652   if ( !myBlockPreview )
653   {
654     GEOMBase_Skeleton::displayPreview( activate, update, toRemoveFromEngine, lineWidth );
655     if ( myConstructorId == 0 )
656     {
657       GEOMBase_Skeleton::activate( GEOM_MARKER );
658     }
659   }
660 }
661
662
663
664
665
666
667
668
669
670
671
672
673
674