1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 CEA
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : BlocksGUI_TrsfDlg.cxx
22 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S. (julia.dorovskikh@opencascade.com)
25 #include "BlocksGUI_TrsfDlg.h"
28 #include <GeometryGUI.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SUIT_ViewWindow.h>
35 #include <SUIT_ViewManager.h>
36 #include <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
38 #include <OCCViewer_ViewModel.h>
40 #include <TColStd_IndexedMapOfInteger.hxx>
42 //=================================================================================
43 // class : BlocksGUI_TrsfDlg()
44 // purpose : Constructs a BlocksGUI_TrsfDlg which is a child of 'parent'.
45 //=================================================================================
46 BlocksGUI_TrsfDlg::BlocksGUI_TrsfDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
47 : GEOMBase_Skeleton( theGeometryGUI, parent )
49 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
50 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_BLOCK_MULTITRSF_SIMPLE" ) ) );
51 QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_BLOCK_MULTITRSF_DOUBLE" ) ) );
52 QPixmap imageS( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
54 setWindowTitle( tr( "GEOM_BLOCK_MULTITRSF_TITLE" ) );
56 /***************************************************************/
57 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_BLOCK_MULTITRSF" ) );
59 mainFrame()->RadioButton1->setIcon( image1 );
60 mainFrame()->RadioButton2->setIcon( image2 );
61 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
62 mainFrame()->RadioButton3->close();
65 myGrp1 = new QGroupBox( tr( "GEOM_BLOCK_MULTITRSF_SIMPLE" ), centralWidget() );
67 createSelWg( tr( "GEOM_MAIN_OBJECT" ), imageS, myGrp1, MainObj1 );
68 createSelWg( tr( "FACE_1" ), imageS, myGrp1, Face1 );
69 createSelWg( tr( "FACE_2" ), imageS, myGrp1, Face2 );
70 createSpinWg( tr( "GEOM_NB_TIMES" ), myGrp1, SpinBox1 );
72 // Create second group
73 myGrp2 = new QGroupBox( tr( "GEOM_BLOCK_MULTITRSF_DOUBLE" ), centralWidget() );
75 createSelWg( tr( "GEOM_MAIN_OBJECT"), imageS, myGrp2, MainObj2 );
76 createSelWg( tr( "FACE_1U"), imageS, myGrp2, Face1U );
77 createSelWg( tr( "FACE_2U"), imageS, myGrp2, Face2U );
78 createSpinWg( tr( "GEOM_NB_TIMES_U" ), myGrp2, SpinBox2U );
79 createSelWg( tr( "FACE_1V" ), imageS, myGrp2, Face1V );
80 createSelWg( tr( "FACE_2V" ), imageS, myGrp2, Face2V );
81 createSpinWg( tr( "GEOM_NB_TIMES_V" ), myGrp2, SpinBox2V );
83 // Add groups to layout
84 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
85 layout->setMargin( 0 ); layout->setSpacing( 6 );
86 layout->addWidget( myGrp1 );
87 layout->addWidget( myGrp2 );
88 /***************************************************************/
90 setHelpFileName( "multi_transformation_operation_page.html" );
95 //=================================================================================
96 // function : ~BlocksGUI_TrsfDlg()
97 // purpose : Destroys the object and frees any allocated resources
98 //=================================================================================
99 BlocksGUI_TrsfDlg::~BlocksGUI_TrsfDlg()
101 // no need to delete child widgets, Qt does it all for us
104 //=================================================================================
107 //=================================================================================
108 void BlocksGUI_TrsfDlg::Init()
110 // Set range of spinboxes
111 double SpecificStep = 1.0;
112 QMap<int, QDoubleSpinBox*>::iterator anIter;
113 for ( anIter = mySpinBox.begin(); anIter != mySpinBox.end(); ++anIter ) {
114 //anIter.data()->RangeStepAndValidator(1.0, 999.999, SpecificStep, 3);
115 initSpinBox( anIter.value(), 1.0, MAX_NUMBER, SpecificStep, 3 );
118 // signals and slots connections
119 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
120 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
122 connect( this, SIGNAL( constructorsClicked( int ) ),
123 this, SLOT( ConstructorsClicked( int ) ) );
125 QMap<int, QPushButton*>::iterator anIterBtn;
126 for ( anIterBtn = mySelBtn.begin(); anIterBtn != mySelBtn.end(); ++anIterBtn )
127 connect( anIterBtn.value(), SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
129 QMap<int, QDoubleSpinBox*>::iterator anIterSpin;
130 for ( anIterSpin = mySpinBox.begin(); anIterSpin != mySpinBox.end(); ++anIterSpin )
131 connect( anIterSpin.value(), SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
133 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
134 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ) ;
136 // init controls and fields
137 initName( tr( "GEOM_BLOCK_MULTITRSF" ) );
139 myConstructorId = -1;
140 ConstructorsClicked( 0 );
143 //=================================================================================
144 // function : ConstructorsClicked()
145 // purpose : Radio button management
146 //=================================================================================
147 void BlocksGUI_TrsfDlg::ConstructorsClicked( int constructorId )
149 if ( myConstructorId == constructorId )
152 myConstructorId = constructorId;
154 switch ( constructorId ) {
158 mySpinBox[SpinBox1]->setValue( 2.0 );
159 myEditCurrentArgument = mySelName[MainObj1];
166 mySpinBox[SpinBox2U]->setValue( 2.0 );
167 mySpinBox[SpinBox2V]->setValue( 2.0 );
168 myEditCurrentArgument = mySelName[MainObj2];
169 myFaces[Face1U] = -1;
170 myFaces[Face2U] = -1;
171 myFaces[Face1V] = -1;
172 myFaces[Face2V] = -1;
179 QMap<int, QLineEdit*>::iterator anIterLE;
180 for ( anIterLE = mySelName.begin(); anIterLE != mySelName.end(); ++anIterLE )
181 anIterLE.value()->setText( "" );
184 myShape = GEOM::GEOM_Object::_nil();
186 qApp->processEvents();
188 resize( minimumSize() );
195 //=================================================================================
196 // function : ClickOnOk()
198 //=================================================================================
199 void BlocksGUI_TrsfDlg::ClickOnOk()
201 if ( ClickOnApply() )
205 //=================================================================================
206 // function : ClickOnApply()
208 //=================================================================================
209 bool BlocksGUI_TrsfDlg::ClickOnApply()
218 //=================================================================================
219 // function : SelectionIntoArgument()
220 // purpose : Called when selection has changed
221 //=================================================================================
222 void BlocksGUI_TrsfDlg::SelectionIntoArgument()
225 myEditCurrentArgument->setText( "" );
227 // Get index of current selection focus
229 QMap<int, QLineEdit*>::iterator anIter;
230 for ( anIter = mySelName.begin(); anIter != mySelName.end(); ++anIter ) {
231 if ( myEditCurrentArgument == anIter.value() ) {
232 aCurrFocus = anIter.key();
237 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
238 SALOME_ListIO aSelList;
239 aSelMgr->selectedObjects(aSelList);
241 // If selection of main object is activated
242 if ( aCurrFocus == MainObj1 || aCurrFocus == MainObj2 ) {
243 if (aSelList.Extent() == 1) {
244 Standard_Boolean aResult = Standard_False;
245 GEOM::GEOM_Object_var anObj =
246 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
248 if ( aResult && !anObj->_is_nil() && GEOMBase::IsShape( anObj ) ) {
250 mySelName[aCurrFocus]->setText( GEOMBase::GetName( anObj ) );
256 myShape = GEOM::GEOM_Object::_nil();
259 // If face selection is activated
260 else if ( aCurrFocus == Face1 || aCurrFocus == Face2 ||
261 aCurrFocus == Face1U || aCurrFocus == Face2U ||
262 aCurrFocus == Face1V || aCurrFocus == Face2V ) {
263 if (aSelList.Extent() == 1) {
264 Standard_Boolean aResult = Standard_False;
265 GEOM::GEOM_Object_var anObj =
266 GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
268 if ( aResult && !anObj->_is_nil() && GEOMBase::IsShape( anObj ) ) {
269 TColStd_IndexedMapOfInteger anIndexes;
270 myGeomGUI->getApp()->selectionMgr()->GetIndexes(aSelList.First(), anIndexes);
272 if ( anIndexes.Extent() == 1 ) {
273 int anIndex = anIndexes( 1 );
274 QString aFaceName = QString( GEOMBase::GetName( anObj ) ) + ":%1";
275 myEditCurrentArgument->setText( aFaceName.arg( anIndex ) );
276 myFaces[aCurrFocus] = anIndex;
283 myFaces[aCurrFocus] = -1;
287 //=================================================================================
288 // function : SetEditCurrentArgument()
290 //=================================================================================
291 void BlocksGUI_TrsfDlg::SetEditCurrentArgument()
293 QPushButton* aSender = (QPushButton*)sender();
295 QMap<int, QPushButton*>::iterator anIter;
296 for ( anIter = mySelBtn.begin(); anIter != mySelBtn.end(); ++anIter ) {
297 if ( anIter.value() == aSender ) {
298 mySelName[anIter.key()]->setFocus();
299 myEditCurrentArgument = mySelName[anIter.key()];
307 //=================================================================================
308 // function : ActivateThisDialog()
310 //=================================================================================
311 void BlocksGUI_TrsfDlg::ActivateThisDialog()
313 GEOMBase_Skeleton::ActivateThisDialog();
314 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
315 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
321 //=================================================================================
322 // function : enterEvent()
324 //=================================================================================
325 void BlocksGUI_TrsfDlg::enterEvent( QEvent* )
327 if ( !mainFrame()->GroupConstructors->isEnabled() )
328 this->ActivateThisDialog();
331 //=================================================================================
332 // function : ValueChangedInSpinBox()
334 //=================================================================================
335 void BlocksGUI_TrsfDlg::ValueChangedInSpinBox( double )
340 //=================================================================================
341 // function : createSelWg()
343 //=================================================================================
344 void BlocksGUI_TrsfDlg::createSelWg( const QString& theLbl,
349 QLabel* lab = new QLabel( theLbl, theParent );
350 mySelBtn[theId] = new QPushButton( theParent );
351 mySelBtn[theId]->setIcon( thePix );
352 mySelBtn[theId]->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
353 mySelName[theId] = new QLineEdit( theParent );
354 mySelName[theId]->setReadOnly( true );
356 if ( !theParent->layout() ) {
357 l = new QGridLayout( theParent );
358 l->setMargin( 9 ); l->setSpacing( 6 );
361 l = qobject_cast<QGridLayout*>( theParent->layout() );
363 int row = l->rowCount();
364 l->addWidget( lab, row, 0 );
365 l->addWidget( mySelBtn[theId], row, 1 );
366 l->addWidget( mySelName[theId], row, 2 );
369 //=================================================================================
370 // function : createSpinWg()
372 //=================================================================================
373 void BlocksGUI_TrsfDlg::createSpinWg( const QString& theLbl,
377 QLabel* lab = new QLabel( theLbl, theParent );
378 mySpinBox[theId] = new QDoubleSpinBox( theParent );
380 if ( !theParent->layout() ) {
381 l = new QGridLayout( theParent );
382 l->setMargin( 9 ); l->setSpacing( 6 );
385 l = qobject_cast<QGridLayout*>( theParent->layout() );
387 int row = l->rowCount();
388 l->addWidget( lab, row, 0 );
389 l->addWidget( mySpinBox[theId], row, 2 );
392 //=================================================================================
393 // function : activateSelection
394 // purpose : Activate selection in accordance with myEditCurrentArgument
395 //=================================================================================
396 void BlocksGUI_TrsfDlg::activateSelection()
398 if ( !myShape->_is_nil() &&
399 ( myEditCurrentArgument == mySelName[ Face1 ] ||
400 myEditCurrentArgument == mySelName[ Face2 ] ||
401 myEditCurrentArgument == mySelName[ Face1U ] ||
402 myEditCurrentArgument == mySelName[ Face2U ] ||
403 myEditCurrentArgument == mySelName[ Face1V ] ||
404 myEditCurrentArgument == mySelName[ Face2V ] ) ) {
406 // Local selection is available only in the OCC Viewer
407 if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
408 == OCCViewer_Viewer::Type() ) {
409 localSelection( myShape, TopAbs_FACE );
416 globalSelection( GEOM_ALLSHAPES );
419 SelectionIntoArgument();
422 //=================================================================================
423 // function : enableWidgets
424 // purpose : Enable widgets of faces in accordance with value of main object
425 //=================================================================================
426 void BlocksGUI_TrsfDlg::enableWidgets()
428 int anId = getConstructorId();
430 bool toEnable = !myShape->_is_nil();
433 mySelName[Face1]->setEnabled( toEnable );
434 mySelName[Face2]->setEnabled( toEnable );
435 mySelBtn[Face1]->setEnabled( toEnable );
436 mySelBtn[Face2]->setEnabled( toEnable );
439 mySelName[Face1]->setText( "" );
440 mySelName[Face2]->setText( "" );
445 else if ( anId == 1 ) {
446 mySelName[Face1U]->setEnabled( toEnable );
447 mySelName[Face2U]->setEnabled( toEnable );
448 mySelName[Face1V]->setEnabled( toEnable );
449 mySelName[Face2V]->setEnabled( toEnable );
450 mySelBtn[Face1U]->setEnabled( toEnable );
451 mySelBtn[Face2U]->setEnabled( toEnable );
452 mySelBtn[Face1V]->setEnabled( toEnable );
453 mySelBtn[Face2V]->setEnabled( toEnable );
456 mySelName[Face1U]->setText( "" );
457 mySelName[Face2U]->setText( "" );
458 mySelName[Face1V]->setText( "" );
459 mySelName[Face2V]->setText( "" );
460 myFaces[Face1U] = -1;
461 myFaces[Face2U] = -1;
462 myFaces[Face1V] = -1;
463 myFaces[Face2V] = -1;
468 //=================================================================================
469 // function : createOperation
471 //=================================================================================
472 GEOM::GEOM_IOperations_ptr BlocksGUI_TrsfDlg::createOperation()
474 return getGeomEngine()->GetIBlocksOperations( getStudyId() );
477 //=================================================================================
478 // function : ClickOnApply()
479 // purpose : Verify validity of input data
480 //=================================================================================
481 bool BlocksGUI_TrsfDlg::isValid( QString& )
484 switch ( getConstructorId() ) {
486 ok = !myShape->_is_nil() && myFaces[Face1] > 0;
489 ok = !myShape->_is_nil() && myFaces[Face1U] > 0 && myFaces[Face1V] > 0;
497 //=================================================================================
498 // function : execute
500 //=================================================================================
501 bool BlocksGUI_TrsfDlg::execute( ObjectList& objects )
505 GEOM::GEOM_Object_var anObj;
507 switch ( getConstructorId() ) {
509 anObj = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->MakeMultiTransformation1D
513 (int)mySpinBox[SpinBox1]->value() );
517 anObj = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->MakeMultiTransformation2D
521 (int)mySpinBox[SpinBox2U]->value(),
524 (int)mySpinBox[SpinBox2V]->value() );
529 if ( !anObj->_is_nil() )
530 objects.push_back( anObj._retn() );