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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : GenerationGUI_PrismDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "GenerationGUI_PrismDlg.h"
28 #include <GEOM_DlgRef.h>
29 #include <GeometryGUI.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
37 #include <GEOMImpl_Types.hxx>
39 //=================================================================================
40 // class : GenerationGUI_PrismDlg()
41 // purpose : Constructs a GenerationGUI_PrismDlg which is a child of 'parent', with the
42 // name 'name' and widget flags set to 'f'.
43 // The dialog will by default be modeless, unless you set 'modal' to
44 // TRUE to construct a modal dialog.
45 //=================================================================================
46 GenerationGUI_PrismDlg::GenerationGUI_PrismDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
47 bool modal, Qt::WindowFlags fl )
48 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
50 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_PRISM" ) ) );
51 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
52 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_PRISM_2P" ) ) );
54 setWindowTitle( tr( "GEOM_EXTRUSION_TITLE" ) );
56 /***************************************************************/
57 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_EXTRUSION" ) );
58 mainFrame()->RadioButton1->setIcon( image0 );
59 mainFrame()->RadioButton2->setIcon( image2 );
60 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
61 mainFrame()->RadioButton3->close();
63 GroupPoints = new DlgRef_2Sel1Spin2Check( centralWidget() );
64 GroupPoints->CheckButton1->hide();
65 GroupPoints->GroupBox1->setTitle( tr( "GEOM_EXTRUSION_BSV" ) );
66 GroupPoints->TextLabel1->setText( tr( "GEOM_BASE" ) );
67 GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR" ) );
68 GroupPoints->TextLabel3->setText( tr( "GEOM_HEIGHT" ) );
69 GroupPoints->PushButton1->setIcon( image1 );
70 GroupPoints->PushButton2->setIcon( image1 );
71 GroupPoints->LineEdit1->setReadOnly( true );
72 GroupPoints->LineEdit2->setReadOnly( true );
73 GroupPoints->CheckButton2->setText( tr( "GEOM_REVERSE" ) );
75 GroupPoints2 = new DlgRef_3Sel( centralWidget() );
77 GroupPoints2->GroupBox1->setTitle( tr( "GEOM_EXTRUSION_BSV_2P" ) );
78 GroupPoints2->TextLabel1->setText( tr( "GEOM_BASE" ) );
79 GroupPoints2->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
80 GroupPoints2->TextLabel3->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
81 GroupPoints2->PushButton1->setIcon( image1 );
82 GroupPoints2->PushButton2->setIcon( image1 );
83 GroupPoints2->PushButton3->setIcon( image1 );
85 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
86 layout->setMargin( 0 ); layout->setSpacing( 6 );
87 layout->addWidget( GroupPoints );
88 layout->addWidget( GroupPoints2 );
89 /***************************************************************/
91 setHelpFileName( "extrusion.htm" );
98 //=================================================================================
99 // function : ~GenerationGUI_PrismDlg()
100 // purpose : Destroys the object and frees any allocated resources
101 //=================================================================================
102 GenerationGUI_PrismDlg::~GenerationGUI_PrismDlg()
104 /* no need to delete child widgets, Qt does it all for us */
108 //=================================================================================
111 //=================================================================================
112 void GenerationGUI_PrismDlg::Init()
115 myEditCurrentArgument = GroupPoints->LineEdit1;
116 GroupPoints->LineEdit1->setReadOnly( true );
117 GroupPoints->LineEdit2->setReadOnly( true );
119 GroupPoints2->LineEdit1->setReadOnly( true );
120 GroupPoints2->LineEdit2->setReadOnly( true );
121 GroupPoints2->LineEdit3->setReadOnly( true );
123 //myOkBase = myOkVec = false;
124 myOkBase = myOkVec = myOkPnt1 = myOkPnt2 = false;
126 /* Get setting of step value from file configuration */
127 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
128 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
130 /* min, max, step and decimals for spin boxes & initial values */
131 initSpinBox( GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 );
132 GroupPoints->SpinBox_DX->setValue( 100.0 );
134 /* signals and slots connections */
135 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
136 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
138 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
140 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
141 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
143 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
144 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
146 connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
148 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupPoints->SpinBox_DX, SLOT( SetStep( double ) ) );
151 connect( GroupPoints->CheckButton2, SIGNAL( toggled( bool ) ), this, SLOT( onReverse() ) );
153 connect( GroupPoints2->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
154 connect( GroupPoints2->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
155 connect( GroupPoints2->PushButton3, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
157 connect( GroupPoints2->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
158 connect( GroupPoints2->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
159 connect( GroupPoints2->LineEdit3, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
162 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
163 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
165 initName( tr( "GEOM_EXTRUSION" ) );
167 globalSelection( GEOM_ALLSHAPES );
168 ConstructorsClicked( 0 );
172 //=================================================================================
173 // function : ConstructorsClicked()
174 // purpose : Radio button management
175 //=================================================================================
176 void GenerationGUI_PrismDlg::ConstructorsClicked( int constructorId )
178 disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 0, this, 0 );
180 switch ( constructorId ) {
183 globalSelection( GEOM_POINT );
184 GroupPoints2->hide();
187 //GroupPoints->LineEdit1->setFocus();
188 //myEditCurrentArgument = GroupPoints->LineEdit1;
191 myEditCurrentArgument = GroupPoints->LineEdit1;
192 GroupPoints->LineEdit1->setText( "" );
193 GroupPoints->LineEdit2->setText( "" );
194 GroupPoints2->LineEdit1->setText( "" );
195 GroupPoints2->LineEdit2->setText( "" );
196 GroupPoints2->LineEdit3->setText( "" );
197 myPoint1 = myPoint2 = myBase = myVec = GEOM::GEOM_Object::_nil();
198 myOkBase = myOkVec = myOkPnt1 = myOkPnt2 = false;
205 GroupPoints2->show();
207 myEditCurrentArgument = GroupPoints2->LineEdit1;
208 GroupPoints2->LineEdit1->setText( "" );
209 GroupPoints2->LineEdit2->setText( "" );
210 GroupPoints2->LineEdit3->setText( "" );
211 myPoint1 = myPoint2 = myBase = myVec = GEOM::GEOM_Object::_nil();
212 myOkBase = myOkVec = myOkPnt1 = myOkPnt2 = false;
213 GroupPoints->LineEdit1->setText("");
214 GroupPoints->LineEdit2->setText("");
220 qApp->processEvents();
222 resize( minimumSize() );
228 //=================================================================================
229 // function : ClickOnOk()
231 //=================================================================================
232 void GenerationGUI_PrismDlg::ClickOnOk()
234 if ( ClickOnApply() )
239 //=================================================================================
240 // function : ClickOnApply()
242 //=================================================================================
243 bool GenerationGUI_PrismDlg::ClickOnApply()
253 //=================================================================================
254 // function : SelectionIntoArgument()
255 // purpose : Called when selection has changed
256 //=================================================================================
257 void GenerationGUI_PrismDlg::SelectionIntoArgument()
260 myEditCurrentArgument->setText( "" );
262 if ( getConstructorId() == 0 ) {
264 if ( IObjectCount() != 1 ) {
265 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
267 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
273 Standard_Boolean testResult = Standard_False;
274 GEOM::GEOM_Object_ptr aSelectedObject =
275 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
280 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
281 myBase = aSelectedObject;
284 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
285 myVec = aSelectedObject;
288 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
293 else { // getConstructorId()==1 - extrusion using 2 points
295 if ( IObjectCount() != 1 ) {
296 if ( myEditCurrentArgument == GroupPoints2->LineEdit1 )
298 else if ( myEditCurrentArgument == GroupPoints2->LineEdit2 ) {
299 myPoint1 = GEOM::GEOM_Object::_nil();
302 else if ( myEditCurrentArgument == GroupPoints2->LineEdit3 ) {
303 myPoint2 = GEOM::GEOM_Object::_nil();
310 Standard_Boolean testResult = Standard_False;
311 GEOM::GEOM_Object_var aSelectedObject =
312 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
314 if ( !testResult || CORBA::is_nil( aSelectedObject ) )
317 if ( myEditCurrentArgument == GroupPoints2->LineEdit1 ) {
318 myBase = aSelectedObject;
321 else if ( myEditCurrentArgument == GroupPoints2->LineEdit2 ) {
322 myPoint1 = aSelectedObject;
325 else if ( myEditCurrentArgument == GroupPoints2->LineEdit3 ) {
326 myPoint2 = aSelectedObject;
330 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
337 //=================================================================================
338 // function : SetEditCurrentArgument()
340 //=================================================================================
341 void GenerationGUI_PrismDlg::SetEditCurrentArgument()
343 QPushButton* send = (QPushButton*)sender();
344 globalSelection( GEOM_ALLSHAPES );
346 if ( send == GroupPoints->PushButton1 ) {
347 GroupPoints->LineEdit1->setFocus();
348 myEditCurrentArgument = GroupPoints->LineEdit1;
350 else if ( send == GroupPoints->PushButton2 ) {
351 GroupPoints->LineEdit2->setFocus();
352 myEditCurrentArgument = GroupPoints->LineEdit2;
353 globalSelection( GEOM_LINE );
355 else if ( send == GroupPoints2->PushButton1 ) {
356 GroupPoints2->LineEdit1->setFocus();
357 myEditCurrentArgument = GroupPoints2->LineEdit1;
359 else if ( send == GroupPoints2->PushButton2 ) {
360 GroupPoints2->LineEdit2->setFocus();
361 myEditCurrentArgument = GroupPoints2->LineEdit2;
362 globalSelection( GEOM_POINT );
364 else if ( send == GroupPoints2->PushButton3 ) {
365 GroupPoints2->LineEdit3->setFocus();
366 myEditCurrentArgument = GroupPoints2->LineEdit3;
367 globalSelection( GEOM_POINT );
369 SelectionIntoArgument();
373 //=================================================================================
374 // function : LineEditReturnPressed()
376 //=================================================================================
377 void GenerationGUI_PrismDlg::LineEditReturnPressed()
379 QLineEdit* send = (QLineEdit*)sender();
380 if ( send == GroupPoints->LineEdit1 ||
381 send == GroupPoints->LineEdit2 ||
382 send == GroupPoints2->LineEdit1 ||
383 send == GroupPoints2->LineEdit2 ||
384 send == GroupPoints2->LineEdit3 ) {
385 myEditCurrentArgument = send;
386 GEOMBase_Skeleton::LineEditReturnPressed();
390 //=================================================================================
391 // function : enterEvent()
392 // purpose : when mouse enter onto the QWidget
393 //=================================================================================
394 void GenerationGUI_PrismDlg::enterEvent( QEvent* )
396 if ( !mainFrame()->GroupConstructors->isEnabled() )
397 ActivateThisDialog();
401 //=================================================================================
402 // function : ActivateThisDialog()
404 //=================================================================================
405 void GenerationGUI_PrismDlg::ActivateThisDialog()
407 GEOMBase_Skeleton::ActivateThisDialog();
408 globalSelection( GEOM_ALLSHAPES );
409 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
410 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
411 //GroupPoints->LineEdit1->setFocus();
412 //myEditCurrentArgument = GroupPoints->LineEdit1;
414 ConstructorsClicked( getConstructorId() );
418 //=================================================================================
419 // function : ValueChangedInSpinBox()
421 //=================================================================================
422 void GenerationGUI_PrismDlg::ValueChangedInSpinBox()
428 //=================================================================================
429 // function : getHeight()
431 //=================================================================================
432 double GenerationGUI_PrismDlg::getHeight() const
434 return GroupPoints->SpinBox_DX->value();
437 //=================================================================================
438 // function : createOperation
440 //=================================================================================
441 GEOM::GEOM_IOperations_ptr GenerationGUI_PrismDlg::createOperation()
443 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
446 //=================================================================================
447 // function : isValid
449 //=================================================================================
450 bool GenerationGUI_PrismDlg::isValid( QString& )
452 return myOkBase && ( myOkVec || (myOkPnt1 && myOkPnt2) );
455 //=================================================================================
456 // function : execute
458 //=================================================================================
459 bool GenerationGUI_PrismDlg::execute( ObjectList& objects )
461 GEOM::GEOM_Object_var anObj;
463 switch ( getConstructorId() ) {
465 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->
466 MakePrismVecH( myBase, myVec, getHeight() );
469 anObj = GEOM::GEOM_I3DPrimOperations::_narrow( getOperation() )->
470 MakePrismTwoPnt( myBase, myPoint1, myPoint2 );
473 if ( !anObj->_is_nil() )
474 objects.push_back( anObj._retn() );
480 //=================================================================================
481 // function : onReverse()
483 //=================================================================================
484 void GenerationGUI_PrismDlg::onReverse()
486 double anOldValue = GroupPoints->SpinBox_DX->value();
487 GroupPoints->SpinBox_DX->setValue( -anOldValue );