1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : GeometryGUI_CircleDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_CircleDlg.h"
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "QAD_Config.h"
36 #include "utilities.h"
38 #include <BRepAdaptor_Curve.hxx>
40 #include <qbuttongroup.h>
41 #include <qgroupbox.h>
43 #include <qlineedit.h>
44 #include <qpushbutton.h>
45 #include <qradiobutton.h>
49 #include <qwhatsthis.h>
51 #include <qvalidator.h>
54 //=================================================================================
55 // class : GeometryGUI_CircleDlg()
56 // purpose : Constructs a GeometryGUI_CircleDlg which is a child of 'parent', with the
57 // name 'name' and widget flags set to 'f'.
58 // The dialog will by default be modeless, unless you set 'modal' to
59 // TRUE to construct a modal dialog.
60 //=================================================================================
61 GeometryGUI_CircleDlg::GeometryGUI_CircleDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
62 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
64 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_CIRCLE_PV")));
65 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
68 setName( "GeometryGUI_CircleDlg" );
70 setCaption( tr( "GEOM_CIRCLE_TITLE" ) );
71 setSizeGripEnabled( TRUE );
72 GeometryGUI_CircleDlgLayout = new QGridLayout( this );
73 GeometryGUI_CircleDlgLayout->setSpacing( 6 );
74 GeometryGUI_CircleDlgLayout->setMargin( 11 );
76 /***************************************************************/
77 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
78 GroupConstructors->setTitle( tr( "GEOM_CIRCLE" ) );
79 GroupConstructors->setExclusive( TRUE );
80 GroupConstructors->setColumnLayout(0, Qt::Vertical );
81 GroupConstructors->layout()->setSpacing( 0 );
82 GroupConstructors->layout()->setMargin( 0 );
83 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
84 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
85 GroupConstructorsLayout->setSpacing( 6 );
86 GroupConstructorsLayout->setMargin( 11 );
87 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
88 Constructor1->setText( tr( "" ) );
89 Constructor1->setPixmap( image0 );
90 Constructor1->setChecked( TRUE );
91 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
92 Constructor1->setMinimumSize( QSize( 50, 0 ) );
93 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
94 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
95 GroupConstructorsLayout->addItem( spacer, 0, 1 );
96 GeometryGUI_CircleDlgLayout->addWidget( GroupConstructors, 0, 0 );
98 /***************************************************************/
99 GroupC1 = new QGroupBox( this, "GroupC1" );
100 GroupC1->setTitle( tr( "GEOM_ARGUMENTS" ) );
101 GroupC1->setFrameShape( QGroupBox::Box );
102 GroupC1->setFrameShadow( QGroupBox::Sunken );
103 GroupC1->setColumnLayout(0, Qt::Vertical );
104 GroupC1->layout()->setSpacing( 0 );
105 GroupC1->layout()->setMargin( 0 );
106 GroupC1Layout = new QGridLayout( GroupC1->layout() );
107 GroupC1Layout->setAlignment( Qt::AlignTop );
108 GroupC1Layout->setSpacing( 6 );
109 GroupC1Layout->setMargin( 11 );
111 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
112 TextLabelC1A1->setText( tr( "GEOM_CENTER_POINT" ) );
113 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
114 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
115 TextLabelC1A1->setFrameShadow( QLabel::Plain );
116 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
117 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
118 SelectButtonC1A1->setText( tr( "" ) );
119 SelectButtonC1A1->setPixmap( image1 );
120 SelectButtonC1A1->setToggleButton( FALSE );
121 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
122 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
123 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
124 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
125 TextLabelC1A2->setText( tr( "GEOM_VECTOR" ) );
126 TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
127 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
128 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
129 SelectButtonC1A2->setText( tr( "" ) );
130 SelectButtonC1A2->setPixmap( image1 );
131 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
132 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
133 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
134 TextLabelC1A3 = new QLabel( GroupC1, "TextLabelC1A3" );
135 TextLabelC1A3->setText( tr( "GEOM_RADIUS" ) );
136 TextLabelC1A3->setMinimumSize( QSize( 50, 0 ) );
137 GroupC1Layout->addWidget( TextLabelC1A3, 2, 0 );
138 SpinBox_C1A3 = new GeometryGUI_SpinBox( GroupC1, "GeomSpinBox_C1A3" ) ;
139 GroupC1Layout->addWidget( SpinBox_C1A3, 2, 2 );
140 GeometryGUI_CircleDlgLayout->addWidget( GroupC1, 1, 0 );
141 /***************************************************************/
143 GroupButtons = new QGroupBox( this, "GroupButtons" );
144 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
145 GroupButtons->setTitle( tr( "" ) );
146 GroupButtons->setColumnLayout(0, Qt::Vertical );
147 GroupButtons->layout()->setSpacing( 0 );
148 GroupButtons->layout()->setMargin( 0 );
149 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
150 GroupButtonsLayout->setAlignment( Qt::AlignTop );
151 GroupButtonsLayout->setSpacing( 6 );
152 GroupButtonsLayout->setMargin( 11 );
153 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
154 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
155 buttonOk->setAutoDefault( TRUE );
156 buttonOk->setDefault( TRUE );
157 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
158 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
159 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
160 buttonApply->setAutoDefault( TRUE );
161 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
162 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
163 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
164 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
165 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
166 buttonCancel->setAutoDefault( TRUE );
167 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
168 GeometryGUI_CircleDlgLayout->addWidget( GroupButtons, 2, 0 );
169 /***************************************************************/
171 Init(Sel) ; /* Initialisations */
175 //=================================================================================
176 // function : ~GeometryGUI_CircleDlg()
177 // purpose : Destroys the object and frees any allocated resources
178 //=================================================================================
179 GeometryGUI_CircleDlg::~GeometryGUI_CircleDlg()
181 // no need to delete child widgets, Qt does it all for us
185 //=================================================================================
188 //=================================================================================
189 void GeometryGUI_CircleDlg::Init( SALOME_Selection* Sel )
192 QString St = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" ) ;
193 step = St.toDouble() ;
195 /* min, max, step and decimals for spin boxes */
196 SpinBox_C1A3->RangeStepAndValidator( 0.001, 999.999, step, 3 ) ;
197 SpinBox_C1A3->SetValue( 100.0 ) ; /* = myRadius */
200 myConstructorId = 0 ;
201 Constructor1->setChecked( TRUE );
202 myEditCurrentArgument = LineEditC1A1 ;
204 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
206 myOkPoint1 = myOkDir = false ;
207 mySimulationTopoDs.Nullify() ;
208 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
210 // TODO : previous selection into argument ?
212 /* Filter definitions */
213 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
214 myGeom = GEOM::GEOM_Gen::_narrow(comp);
215 myEdgeFilter = new GEOM_EdgeFilter( StdSelect_Line, myGeom );
216 myVertexFilter = new GEOM_ShapeTypeFilter( TopAbs_VERTEX, myGeom );
218 mySelection->AddFilter(myVertexFilter) ; /* first filter used */
220 /* signals and slots connections */
221 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
222 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
223 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
224 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
225 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
226 connect( SelectButtonC1A2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
228 connect( LineEditC1A1, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
229 connect( LineEditC1A2, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
231 connect( SpinBox_C1A3, SIGNAL ( valueChanged( double) ), this, SLOT( ValueChangedInSpinBox( double) ) ) ;
232 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
233 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
234 /* to close dialog if study change */
235 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
237 /* Move widget on the botton right corner of main widget */
239 myGeomGUI->DefineDlgPosition( this, x, y ) ;
241 this->show() ; /* displays Dialog */
247 //=================================================================================
248 // function : ConstructorsClicked()
249 // purpose : Radio button management
250 //=================================================================================
251 void GeometryGUI_CircleDlg::ConstructorsClicked(int constructorId)
253 /* only a constructor now */
257 //=================================================================================
258 // function : ClickOnOk()
260 //=================================================================================
261 void GeometryGUI_CircleDlg::ClickOnOk()
263 this->ClickOnApply() ;
264 this->ClickOnCancel() ;
269 //=================================================================================
270 // function : ClickOnApply()
272 //=================================================================================
273 void GeometryGUI_CircleDlg::ClickOnApply()
275 myGeomGUI->EraseSimulationShape() ;
276 mySimulationTopoDs.Nullify() ;
277 switch(myConstructorId)
281 if(myOkPoint1 && myOkDir) {
282 myGeomGUI->MakeCircleAndDisplay( myPoint1, myDir, myRadius) ;
291 //=================================================================================
292 // function : ClickOnCancel()
294 //=================================================================================
295 void GeometryGUI_CircleDlg::ClickOnCancel()
297 mySelection->ClearFilters() ;
298 myGeomGUI->EraseSimulationShape() ;
299 mySimulationTopoDs.Nullify() ;
300 disconnect( mySelection, 0, this, 0 );
301 myGeomGUI->ResetState() ;
306 //=================================================================================
307 // function : SelectionIntoArgument()
308 // purpose : Called when selection as changed or other case
309 //=================================================================================
310 void GeometryGUI_CircleDlg::SelectionIntoArgument()
313 myGeomGUI->EraseSimulationShape() ;
314 mySimulationTopoDs.Nullify() ;
316 /* Future name of selection */
317 QString aString = "";
319 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
321 if ( myEditCurrentArgument == LineEditC1A1 ) {
322 LineEditC1A1->setText("") ;
325 else if ( myEditCurrentArgument == LineEditC1A2 ) {
326 LineEditC1A2->setText("") ;
334 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
337 /* gp_Pnt : not used */
338 if ( myEditCurrentArgument == LineEditC1A1 && myGeomGUI->VertexToPoint(S, myPoint1) ) {
339 LineEditC1A1->setText(aString) ;
342 else if ( myEditCurrentArgument == LineEditC1A2 /*&& myGeomGUI->LinearLocationAndDirection(S, notUsed, myDir) */) {
343 BRepAdaptor_Curve curv(TopoDS::Edge(S));
344 myDir = curv.Line().Direction();
345 LineEditC1A2->setText(aString) ;
349 if( myOkPoint1 && myOkDir ) {
350 MakeCircleSimulationAndDisplay() ;
355 //=================================================================================
356 // function : SetEditCurrentArgument()
358 //=================================================================================
359 void GeometryGUI_CircleDlg::SetEditCurrentArgument()
361 mySelection->ClearFilters() ;
362 QPushButton* send = (QPushButton*)sender();
363 switch (myConstructorId)
365 case 0: /* default constructor */
367 if(send == SelectButtonC1A1) {
368 LineEditC1A1->setFocus() ;
369 myEditCurrentArgument = LineEditC1A1;
370 mySelection->AddFilter(myVertexFilter) ;
372 else if(send == SelectButtonC1A2) {
373 LineEditC1A2->setFocus() ;
374 myEditCurrentArgument = LineEditC1A2;
375 mySelection->AddFilter(myEdgeFilter) ;
377 SelectionIntoArgument() ;
384 //=================================================================================
385 // function : LineEditReturnPressed()
387 //=================================================================================
388 void GeometryGUI_CircleDlg::LineEditReturnPressed()
390 QLineEdit* send = (QLineEdit*)sender();
391 if( send == LineEditC1A1 )
392 myEditCurrentArgument = LineEditC1A1 ;
393 else if ( send == LineEditC1A2 )
394 myEditCurrentArgument = LineEditC1A2 ;
398 /* User name of object input management */
399 /* If successfull the selection is changed and signal emitted... */
400 /* so SelectionIntoArgument() is automatically called. */
401 const QString objectUserName = myEditCurrentArgument->text() ;
402 QWidget* thisWidget = (QWidget*)this ;
403 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
404 myEditCurrentArgument->setText( objectUserName ) ;
410 //=================================================================================
411 // function : ValueChangedInSpinBox()
413 //=================================================================================
414 void GeometryGUI_CircleDlg::ValueChangedInSpinBox( double newValue )
416 myRadius = newValue ;
418 if (myOkPoint1 && myOkDir) {
419 MakeCircleSimulationAndDisplay() ;
422 myGeomGUI->EraseSimulationShape() ;
423 mySimulationTopoDs.Nullify() ;
428 //=================================================================================
429 // function : DeactivateActiveDialog()
431 //=================================================================================
432 void GeometryGUI_CircleDlg::DeactivateActiveDialog()
434 if ( GroupConstructors->isEnabled() ) {
435 GroupConstructors->setEnabled(false) ;
436 GroupC1->setEnabled(false) ;
437 GroupButtons->setEnabled(false) ;
438 disconnect( mySelection, 0, this, 0 );
439 myGeomGUI->EraseSimulationShape() ;
440 mySelection->ClearFilters() ;
445 //=================================================================================
446 // function : ActivateThisDialog()
448 //=================================================================================
449 void GeometryGUI_CircleDlg::ActivateThisDialog()
451 /* Emit a signal to deactivate the active dialog */
452 myGeomGUI->EmitSignalDeactivateDialog() ;
453 GroupConstructors->setEnabled(true) ;
454 GroupC1->setEnabled(true) ;
455 GroupButtons->setEnabled(true) ;
456 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
457 if( !mySimulationTopoDs.IsNull() )
458 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
463 //=================================================================================
464 // function : enterEvent()
466 //=================================================================================
467 void GeometryGUI_CircleDlg::enterEvent(QEvent* e)
469 if ( GroupConstructors->isEnabled() )
471 ActivateThisDialog() ;
475 //=================================================================================
476 // function : closeEvent()
478 //=================================================================================
479 void GeometryGUI_CircleDlg::closeEvent( QCloseEvent* e )
481 this->ClickOnCancel() ; /* same than click on cancel button */
485 //=================================================================================
486 // function : MakeCircleSimulationAndDisplay()
488 //=================================================================================
489 void GeometryGUI_CircleDlg::MakeCircleSimulationAndDisplay()
491 myGeomGUI->EraseSimulationShape() ;
494 gp_Ax2 axis( this->myPoint1, this->myDir ) ;
495 gp_Circ circ( axis, this->myRadius);
496 BRepBuilderAPI_MakeEdge MakeEdge( circ );
497 mySimulationTopoDs = MakeEdge.Shape();
498 myGeomGUI->DisplaySimulationShape( mySimulationTopoDs ) ;
500 catch(Standard_Failure) {
501 MESSAGE( "Exception catched in MakeCircleSimulationAndDisplay" ) ;