1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 // File : GeometryGUI_EllipseDlg.cxx
24 // Author : Nicolas REJNERI
28 #include "GeometryGUI_EllipseDlg.h"
30 #include "GeometryGUI.h"
31 #include "gp_Elips.hxx"
32 #include "QAD_Application.h"
33 #include "QAD_Desktop.h"
34 #include "QAD_Config.h"
35 #include "utilities.h"
37 #include <BRepAdaptor_Curve.hxx>
39 #include <qbuttongroup.h>
40 #include <qgroupbox.h>
42 #include <qlineedit.h>
43 #include <qpushbutton.h>
44 #include <qradiobutton.h>
49 #include <qwhatsthis.h>
53 //=================================================================================
54 // class : GeometryGUI_EllipseDlg()
55 // purpose : Constructs a GeometryGUI_EllipseDlg which is a child of 'parent', with the
56 // name 'name' and widget flags set to 'f'.
57 // The dialog will by default be modeless, unless you set 'modal' to
58 // TRUE to construct a modal dialog.
59 //=================================================================================
60 GeometryGUI_EllipseDlg::GeometryGUI_EllipseDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
61 : QDialog( parent, name, modal, fl )
63 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_ELLIPSE_PV")));
64 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
67 setName( "GeometryGUI_EllipseDlg" );
69 setCaption( tr( "GEOM_ELLIPSE_TITLE" ) );
71 GeometryGUI_EllipseDlgLayout = new QGridLayout( this );
72 GeometryGUI_EllipseDlgLayout->setSpacing( 6 );
73 GeometryGUI_EllipseDlgLayout->setMargin( 11 );
75 /***************************************************************/
76 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
77 GroupConstructors->setTitle( tr( "GEOM_ELLIPSE" ) );
78 GroupConstructors->setExclusive( TRUE );
79 GroupConstructors->setColumnLayout(0, Qt::Vertical );
80 GroupConstructors->layout()->setSpacing( 0 );
81 GroupConstructors->layout()->setMargin( 0 );
82 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
83 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
84 GroupConstructorsLayout->setSpacing( 6 );
85 GroupConstructorsLayout->setMargin( 11 );
86 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
87 Constructor1->setText( tr( "" ) );
88 Constructor1->setPixmap( image0 );
89 Constructor1->setChecked( TRUE );
90 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
91 Constructor1->setMinimumSize( QSize( 50, 0 ) );
92 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
93 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
94 GroupConstructorsLayout->addItem( spacer, 0, 1 );
95 GeometryGUI_EllipseDlgLayout->addWidget( GroupConstructors, 0, 0 );
97 /***************************************************************/
98 GroupButtons = new QGroupBox( this, "GroupButtons" );
99 GroupButtons->setTitle( tr( "" ) );
100 GroupButtons->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, GroupButtons->sizePolicy().hasHeightForWidth() ) );
101 GroupButtons->setColumnLayout(0, Qt::Vertical );
102 GroupButtons->layout()->setSpacing( 0 );
103 GroupButtons->layout()->setMargin( 0 );
104 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
105 GroupButtonsLayout->setAlignment( Qt::AlignTop );
106 GroupButtonsLayout->setSpacing( 6 );
107 GroupButtonsLayout->setMargin( 11 );
108 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
109 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
110 buttonApply->setAutoDefault( TRUE );
111 buttonApply->setDefault( TRUE );
112 GroupButtonsLayout->addWidget( buttonApply, 0, 2 );
113 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
114 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
115 buttonCancel->setAutoDefault( TRUE );
116 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
117 QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
118 GroupButtonsLayout->addItem( spacer_2, 0, 1 );
119 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
120 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
121 buttonOk->setAutoDefault( TRUE );
122 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
123 GeometryGUI_EllipseDlgLayout->addWidget( GroupButtons, 2, 0 );
125 /***************************************************************/
126 GroupC1 = new QGroupBox( this, "GroupC1" );
127 GroupC1->setTitle( tr( "GEOM_ARGUMENTS" ) );
128 GroupC1->setMinimumSize( QSize( 0, 150 ) );
129 GroupC1->setFrameShape( QGroupBox::Box );
130 GroupC1->setFrameShadow( QGroupBox::Sunken );
131 GroupC1->setColumnLayout(0, Qt::Vertical );
132 GroupC1->layout()->setSpacing( 0 );
133 GroupC1->layout()->setMargin( 0 );
134 GroupC1Layout = new QGridLayout( GroupC1->layout() );
135 GroupC1Layout->setAlignment( Qt::AlignTop );
136 GroupC1Layout->setSpacing( 6 );
137 GroupC1Layout->setMargin( 11 );
138 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
139 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
140 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
141 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
142 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
143 TextLabelC1A1->setText( tr( "GEOM_CENTER" ) );
144 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
145 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
146 TextLabelC1A1->setFrameShadow( QLabel::Plain );
148 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
149 TextLabelC1A4 = new QLabel( GroupC1, "TextLabelC1A4" );
150 TextLabelC1A4->setText( tr( "GEOM_RADIUS_MINOR" ) );
151 TextLabelC1A4->setMinimumSize( QSize( 50, 0 ) );
152 GroupC1Layout->addMultiCellWidget( TextLabelC1A4, 3, 3, 0, 1 );
154 TextLabelC1A3 = new QLabel( GroupC1, "TextLabelC1A3" );
155 TextLabelC1A3->setText( tr( "GEOM_RADIUS_MAJOR" ) );
156 TextLabelC1A3->setMinimumSize( QSize( 50, 0 ) );
157 GroupC1Layout->addWidget( TextLabelC1A3, 2, 0 );
159 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
160 TextLabelC1A2->setText( tr( "GEOM_VECTOR" ) );
161 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
163 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
164 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
165 SelectButtonC1A1->setText( tr( "" ) );
166 SelectButtonC1A1->setPixmap( image1 );
167 SelectButtonC1A1->setToggleButton( FALSE );
168 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
169 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
170 SelectButtonC1A2->setText( tr( "" ) );
171 SelectButtonC1A2->setPixmap( image1 );
172 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
174 SpinBox_C1A3 = new GeometryGUI_SpinBox( GroupC1, "GeomSpinBox_C1A3" );
175 GroupC1Layout->addWidget( SpinBox_C1A3, 2, 2 ) ;
176 SpinBox_C1A4 = new GeometryGUI_SpinBox( GroupC1, "GeomSpinBox_C1A4" );
177 GroupC1Layout->addWidget( SpinBox_C1A4, 3, 2 );
179 GeometryGUI_EllipseDlgLayout->addWidget( GroupC1, 1, 0 );
180 /***************************************************************/
182 Init(Sel) ; /* Initialisations */
186 //=================================================================================
187 // function : ~GeometryGUI_EllipseDlg()
188 // purpose : Destroys the object and frees any allocated resources
189 //=================================================================================
190 GeometryGUI_EllipseDlg::~GeometryGUI_EllipseDlg()
192 // no need to delete child widgets, Qt does it all for us
197 //=================================================================================
200 //=================================================================================
201 void GeometryGUI_EllipseDlg::Init( SALOME_Selection* Sel )
204 QString St = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" ) ;
205 step = St.toDouble() ;
207 /* min, max, step and decimals for spin boxes */
208 SpinBox_C1A3->RangeStepAndValidator( 0.00001, 999999.99999, step, 5 ) ;
209 SpinBox_C1A3->SetValue( 200.0 ) ; /* = myMajorRadius */
210 myMajorRadius = 200.0 ;
212 /* min, max, step and decimals for spin boxes */
213 SpinBox_C1A4->RangeStepAndValidator( 0.00001, 999999.99999, step, 5 ) ;
214 SpinBox_C1A4->SetValue( 100.0 ) ; /* = myMinorRadius */
215 myMinorRadius = 100.0 ;
218 myConstructorId = 0 ;
219 Constructor1->setChecked( TRUE );
220 myEditCurrentArgument = LineEditC1A1 ;
222 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
223 myOkPoint = myOkDir = false ;
224 mySimulationTopoDs.Nullify() ;
225 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
227 // TODO : previous selection into argument ?
229 /* Filter definitions */
230 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
231 myGeom = GEOM::GEOM_Gen::_narrow(comp);
232 myEdgeFilter = new GEOM_EdgeFilter( StdSelect_Line, myGeom );
233 myVertexFilter = new GEOM_ShapeTypeFilter( TopAbs_VERTEX, myGeom );
235 mySelection->AddFilter(myVertexFilter) ; /* first filter used */
237 /* signals and slots connections */
238 connect( buttonOk, SIGNAL( pressed() ), this, SLOT( ClickOnOk() ) );
239 connect( buttonCancel, SIGNAL( pressed() ), this, SLOT( ClickOnCancel() ) ) ;
240 connect( buttonApply, SIGNAL( pressed() ), this, SLOT( ClickOnApply() ) );
241 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
242 connect( SelectButtonC1A1, SIGNAL (pressed() ), this, SLOT( SetEditCurrentArgument() ) ) ;
243 connect( SelectButtonC1A2, SIGNAL (pressed() ), this, SLOT( SetEditCurrentArgument() ) ) ;
245 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
246 connect( LineEditC1A2, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
248 connect( SpinBox_C1A3, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
249 connect( SpinBox_C1A4, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
251 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
252 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
253 /* to close dialog if study change */
254 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
256 /* Move widget on the botton right corner of main widget */
258 myGeomGUI->DefineDlgPosition( this, x, y ) ;
260 this->show() ; /* displays Dialog */
266 //=================================================================================
267 // function : ConstructorsClicked()
268 // purpose : Radio button management
269 //=================================================================================
270 void GeometryGUI_EllipseDlg::ConstructorsClicked(int constructorId)
272 /* only a constructor now */
276 //=================================================================================
277 // function : ClickOnOk()
279 //=================================================================================
280 void GeometryGUI_EllipseDlg::ClickOnOk()
282 this->ClickOnApply() ;
283 this->ClickOnCancel() ;
288 //=================================================================================
289 // function : ClickOnApply()
291 //=================================================================================
292 void GeometryGUI_EllipseDlg::ClickOnApply()
294 myGeomGUI->EraseSimulationShape() ;
295 mySimulationTopoDs.Nullify() ;
296 switch(myConstructorId)
300 if(myOkPoint && myOkDir) {
301 myGeomGUI->MakeEllipseAndDisplay( myPoint, myDir, myMajorRadius, myMinorRadius ) ;
309 //=================================================================================
310 // function : ClickOnCancel()
312 //=================================================================================
313 void GeometryGUI_EllipseDlg::ClickOnCancel()
315 mySelection->ClearFilters() ;
316 myGeomGUI->EraseSimulationShape() ;
317 mySimulationTopoDs.Nullify() ;
318 disconnect( mySelection, 0, this, 0 );
319 myGeomGUI->ResetState() ;
324 //=================================================================================
325 // function : SelectionIntoArgument()
326 // purpose : Called when selection as changed or other case
327 //=================================================================================
328 void GeometryGUI_EllipseDlg::SelectionIntoArgument()
331 myGeomGUI->EraseSimulationShape() ;
332 mySimulationTopoDs.Nullify() ;
334 /* Future name of selection */
335 QString aString = "";
337 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
339 if ( myEditCurrentArgument == LineEditC1A1 ) {
340 LineEditC1A1->setText("") ;
343 else if ( myEditCurrentArgument == LineEditC1A2 ) {
344 LineEditC1A2->setText("") ;
352 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
355 /* gp_Pnt : not used */
356 if ( myEditCurrentArgument == LineEditC1A1 && myGeomGUI->VertexToPoint(S, myPoint) ) {
357 LineEditC1A1->setText(aString) ;
360 else if ( myEditCurrentArgument == LineEditC1A2 /*&& myGeomGUI->LinearLocationAndDirection(S, notUsed, myDir) */) {
361 BRepAdaptor_Curve curv(TopoDS::Edge(S));
362 myDir = curv.Line().Direction();
363 LineEditC1A2->setText(aString) ;
367 if( myOkPoint && myOkDir ) {
368 this->MakeEllipseSimulationAndDisplay() ;
373 //=================================================================================
374 // function : SetEditCurrentArgument()
376 //=================================================================================
377 void GeometryGUI_EllipseDlg::SetEditCurrentArgument()
379 mySelection->ClearFilters() ;
380 QPushButton* send = (QPushButton*)sender();
381 switch (myConstructorId)
383 case 0: /* default constructor */
385 if(send == SelectButtonC1A1) {
386 LineEditC1A1->setFocus() ;
387 myEditCurrentArgument = LineEditC1A1;
388 mySelection->AddFilter(myVertexFilter) ;
390 else if(send == SelectButtonC1A2) {
391 LineEditC1A2->setFocus() ;
392 myEditCurrentArgument = LineEditC1A2;
393 mySelection->AddFilter(myEdgeFilter) ;
395 SelectionIntoArgument() ;
402 //=================================================================================
403 // function : LineEditReturnPressed()
405 //=================================================================================
406 void GeometryGUI_EllipseDlg::LineEditReturnPressed()
408 QLineEdit* send = (QLineEdit*)sender();
409 if( send == LineEditC1A1 )
410 myEditCurrentArgument = LineEditC1A1 ;
411 else if ( send == LineEditC1A2 )
412 myEditCurrentArgument = LineEditC1A2 ;
416 /* User name of object input management */
417 /* If successfull the selection is changed and signal emitted... */
418 /* so SelectionIntoArgument() is automatically called. */
419 const QString objectUserName = myEditCurrentArgument->text() ;
420 QWidget* thisWidget = (QWidget*)this ;
421 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
422 myEditCurrentArgument->setText( objectUserName ) ;
428 //=================================================================================
429 // function : ValueChangedInSpinBox()
431 //=================================================================================
432 void GeometryGUI_EllipseDlg::ValueChangedInSpinBox( double newValue )
434 myGeomGUI->EraseSimulationShape() ;
435 mySimulationTopoDs.Nullify() ;
437 GeometryGUI_SpinBox* send = (GeometryGUI_SpinBox*)sender();
438 if(send == SpinBox_C1A3)
439 myMajorRadius = newValue ;
440 else if(send == SpinBox_C1A4)
441 myMinorRadius = newValue ;
445 if (myOkPoint && myOkDir) {
446 MakeEllipseSimulationAndDisplay() ;
453 //=================================================================================
454 // function : DeactivateActiveDialog()
456 //=================================================================================
457 void GeometryGUI_EllipseDlg::DeactivateActiveDialog()
459 if ( GroupConstructors->isEnabled() ) {
460 GroupConstructors->setEnabled(false) ;
461 GroupC1->setEnabled(false) ;
462 GroupButtons->setEnabled(false) ;
463 disconnect( mySelection, 0, this, 0 );
464 myGeomGUI->EraseSimulationShape() ;
465 mySelection->ClearFilters() ;
470 //=================================================================================
471 // function : ActivateThisDialog()
473 //=================================================================================
474 void GeometryGUI_EllipseDlg::ActivateThisDialog()
476 /* Emit a signal to deactivate the active dialog */
477 myGeomGUI->EmitSignalDeactivateDialog() ;
478 GroupConstructors->setEnabled(true) ;
479 GroupC1->setEnabled(true) ;
480 GroupButtons->setEnabled(true) ;
481 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
482 if( !mySimulationTopoDs.IsNull() )
483 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
488 //=================================================================================
489 // function : enterEvent()
491 //=================================================================================
492 void GeometryGUI_EllipseDlg::enterEvent(QEvent* e)
494 if ( GroupConstructors->isEnabled() )
496 ActivateThisDialog() ;
500 //=================================================================================
501 // function : closeEvent()
503 //=================================================================================
504 void GeometryGUI_EllipseDlg::closeEvent( QCloseEvent* e )
506 this->ClickOnCancel() ; /* same than click on cancel button */
510 //=================================================================================
511 // function : MakeEllipseSimulationAndDisplay()
513 //=================================================================================
514 void GeometryGUI_EllipseDlg::MakeEllipseSimulationAndDisplay()
516 myGeomGUI->EraseSimulationShape() ;
518 if( myMajorRadius < myMinorRadius )
522 const gp_Ax2 axis( this->myPoint, this->myDir ) ;
523 gp_Elips ellipse( axis, this->myMajorRadius, this->myMinorRadius );
525 BRepBuilderAPI_MakeEdge MakeEdge( ellipse );
526 mySimulationTopoDs = MakeEdge.Shape();
527 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
529 catch(Standard_Failure) {
530 MESSAGE( "Exception catched in MakeEllipseSimulationAndDisplay" ) ;