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_ExplodeDlg.cxx
22 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S. (julia.dorovskikh@opencascade.com)
25 #include "BlocksGUI_ExplodeDlg.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 <SUIT_MessageBox.h>
37 #include <SalomeApp_Application.h>
38 #include <LightApp_SelectionMgr.h>
39 #include <OCCViewer_ViewModel.h>
40 #include <SALOME_ListIteratorOfListIO.hxx>
42 //=================================================================================
43 // class : BlocksGUI_ExplodeDlg()
44 // purpose : Constructs a BlocksGUI_ExplodeDlg which is a child of 'parent'.
45 //=================================================================================
46 BlocksGUI_ExplodeDlg::BlocksGUI_ExplodeDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
47 : GEOMBase_Skeleton( theGeometryGUI, parent )
49 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BLOCK_EXPLODE" ) ) );
50 QPixmap imageS( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
52 setWindowTitle( tr( "GEOM_BLOCK_EXPLODE_TITLE" ) );
54 /***************************************************************/
55 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_BLOCK_EXPLODE" ) );
57 mainFrame()->RadioButton1->setIcon( image1 );
58 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
59 mainFrame()->RadioButton2->close();
60 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
61 mainFrame()->RadioButton3->close();
64 myGrp1 = new DlgRef_1Sel2Spin1View1Check( centralWidget() );
65 myGrp1->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
66 myGrp1->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
67 myGrp1->PushButton1->setIcon( imageS );
68 myGrp1->LineEdit1->setReadOnly( true );
69 myGrp1->TextLabel2->setText( tr( "NB_FACES_MIN" ) );
70 myGrp1->TextLabel3->setText( tr( "NB_FACES_MAX" ) );
71 myGrp1->CheckBox1->setText( tr( "GEOM_SUBSHAPE_SELECT" ) );
73 // Add groups to layout
74 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
75 layout->setMargin( 0 ); layout->setSpacing( 6 );
76 layout->addWidget( myGrp1 );
77 /***************************************************************/
79 setHelpFileName( "explode_on_blocks_operation_page.html" );
84 //=================================================================================
85 // function : ~BlocksGUI_ExplodeDlg()
86 // purpose : Destroys the object and frees any allocated resources
87 //=================================================================================
88 BlocksGUI_ExplodeDlg::~BlocksGUI_ExplodeDlg()
90 // no need to delete child widgets, Qt does it all for us
94 //=================================================================================
97 //=================================================================================
98 void BlocksGUI_ExplodeDlg::Init()
100 mainFrame()->GroupBoxName->hide();
102 // Set range of spinboxes
103 int SpecificStep = 1;
104 initSpinBox( myGrp1->SpinBox1, 0, 999, SpecificStep );
105 initSpinBox( myGrp1->SpinBox2, 0, 999, SpecificStep );
107 if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
108 != OCCViewer_Viewer::Type() )
109 myGrp1->CheckBox1->setEnabled( false );
111 // signals and slots connections
112 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
113 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
115 connect( myGrp1->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
117 connect( myGrp1->SpinBox1, SIGNAL( valueChanged( int ) ), this, SLOT( ValueChangedInSpinBox( int ) ) );
118 connect( myGrp1->SpinBox2, SIGNAL( valueChanged( int ) ), this, SLOT( ValueChangedInSpinBox( int ) ) );
120 connect( myGrp1->CheckBox1, SIGNAL( stateChanged( int ) ), this, SLOT( SubShapeToggled() ) );
122 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
123 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
125 myConstructorId = -1;
126 ConstructorsClicked( 0 );
129 //=================================================================================
130 // function : ConstructorsClicked()
131 // purpose : Radio button management
132 //=================================================================================
133 void BlocksGUI_ExplodeDlg::ConstructorsClicked( int constructorId )
135 if ( myConstructorId == constructorId )
138 myConstructorId = constructorId;
140 switch ( constructorId ) {
143 myGrp1->SpinBox1->setValue( 6 );
144 myGrp1->SpinBox2->setValue( 6 );
145 myGrp1->CheckBox1->setChecked( false );
152 myEditCurrentArgument = myGrp1->LineEdit1;
153 myObject = GEOM::GEOM_Object::_nil();
158 //=================================================================================
159 // function : ClickOnOk()
161 //=================================================================================
162 void BlocksGUI_ExplodeDlg::ClickOnOk()
164 if ( ClickOnApply() )
168 //=================================================================================
169 // function : ClickOnApply()
171 //=================================================================================
172 bool BlocksGUI_ExplodeDlg::ClickOnApply()
174 SUIT_Session::session()->activeApplication()->putInfo( tr( "" ) );
176 // Explode all sub shapes
177 if ( isAllSubShapes() ) {
178 // More than 30 subshapes : ask confirmation
179 if ( myNbBlocks > 30 ) {
180 if ( SUIT_MessageBox::warning( this,
181 tr( "GEOM_CONFIRM" ),
182 tr( "GEOM_CONFIRM_INFO" ).arg( myNbBlocks ),
183 tr( "GEOM_BUT_EXPLODE" ),
184 tr( "GEOM_BUT_CANCEL" ) ) != 0 )
185 return false; /* aborted */
197 //=================================================================================
198 // function : SelectionIntoArgument()
199 // purpose : Called when selection has changed
200 //=================================================================================
201 void BlocksGUI_ExplodeDlg::SelectionIntoArgument()
203 if (!isAllSubShapes())
206 myObject = GEOM::GEOM_Object::_nil();
207 myGrp1->LineEdit1->setText("");
209 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
210 SALOME_ListIO aSelList;
211 aSelMgr->selectedObjects(aSelList);
213 if (aSelList.Extent() == 1) {
214 Standard_Boolean aResult = Standard_False;
215 GEOM::GEOM_Object_var anObj = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aResult);
217 if (aResult && !anObj->_is_nil() && GEOMBase::IsShape(anObj)) {
219 myGrp1->LineEdit1->setText(GEOMBase::GetName(anObj));
226 //=================================================================================
227 // function : SetEditCurrentArgument()
229 //=================================================================================
230 void BlocksGUI_ExplodeDlg::SetEditCurrentArgument()
232 QPushButton* aSender = (QPushButton*)sender();
234 if ( myGrp1->PushButton1 == aSender ) {
235 myGrp1->LineEdit1->setFocus();
236 myEditCurrentArgument = myGrp1->LineEdit1;
237 myGrp1->CheckBox1->setChecked( false );
243 //=================================================================================
244 // function : ActivateThisDialog()
246 //=================================================================================
247 void BlocksGUI_ExplodeDlg::ActivateThisDialog()
249 GEOMBase_Skeleton::ActivateThisDialog();
250 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
251 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
256 //=================================================================================
257 // function : enterEvent()
259 //=================================================================================
260 void BlocksGUI_ExplodeDlg::enterEvent( QEvent* )
262 if ( !mainFrame()->GroupConstructors->isEnabled() )
263 this->ActivateThisDialog();
266 //=================================================================================
267 // function : ValueChangedInSpinBox()
269 //=================================================================================
270 void BlocksGUI_ExplodeDlg::ValueChangedInSpinBox()
272 if ( !isAllSubShapes() )
278 //=================================================================================
279 // function : SubShapeToggled()
280 // purpose : Allow user selection of all or only selected sub shapes
281 // : Called when 'myGrp1->CheckBox1' state change
282 //=================================================================================
283 void BlocksGUI_ExplodeDlg::SubShapeToggled()
288 //=================================================================================
289 // function : activateSelection
290 // purpose : Redisplay preview and Activate selection
291 //=================================================================================
292 void BlocksGUI_ExplodeDlg::activateSelection()
295 erasePreview( true );
297 if ( isAllSubShapes() ) { // Sub-shapes selection disabled
298 disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
299 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
300 globalSelection( GEOM_ALLSHAPES );
301 if ( myObject->_is_nil() ) {
302 SelectionIntoArgument();
304 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
305 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
308 displayPreview( true, true, false );
309 globalSelection( GEOM_PREVIEW );
313 //=================================================================================
314 // function : updateButtonState
316 //=================================================================================
317 void BlocksGUI_ExplodeDlg::updateButtonState()
319 if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
320 != OCCViewer_Viewer::Type() || myObject->_is_nil() ) {
321 myGrp1->CheckBox1->setChecked( false );
322 myGrp1->CheckBox1->setEnabled( false );
325 myGrp1->CheckBox1->setEnabled( true );
330 if ( myObject->_is_nil() ) {
331 myGrp1->TextBrowser1->setText( "" );
334 bool isOnlyBlocks = GEOM::GEOM_IBlocksOperations::_narrow
335 ( getOperation() )->IsCompoundOfBlocks( myObject,
336 myGrp1->SpinBox1->value(),
337 myGrp1->SpinBox2->value(),
340 myGrp1->TextBrowser1->setText( tr( "GEOM_NB_BLOCKS_NO_OTHERS" ).arg( myNbBlocks ) );
342 myGrp1->TextBrowser1->setText( tr( "GEOM_NB_BLOCKS_SOME_OTHERS" ).arg( myNbBlocks ) );
346 //=================================================================================
347 // function : isAllSubShapes
349 //=================================================================================
350 bool BlocksGUI_ExplodeDlg::isAllSubShapes() const
352 return !myGrp1->CheckBox1->isChecked() || !myGrp1->CheckBox1->isEnabled();
355 //=================================================================================
356 // function : createOperation
358 //=================================================================================
359 GEOM::GEOM_IOperations_ptr BlocksGUI_ExplodeDlg::createOperation()
361 return getGeomEngine()->GetIBlocksOperations( getStudyId() );
364 //=================================================================================
365 // function : isValid()
366 // purpose : Verify validity of input data
367 //=================================================================================
368 bool BlocksGUI_ExplodeDlg::isValid (QString&)
371 switch ( getConstructorId() ) {
374 ok = !myObject->_is_nil();
377 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
378 SALOME_ListIO aSelList;
379 aSelMgr->selectedObjects(aSelList);
381 ok = !myObject->_is_nil() && (isAllSubShapes() || aSelList.Extent());
391 //=================================================================================
392 // function : execute
394 //=================================================================================
395 bool BlocksGUI_ExplodeDlg::execute( ObjectList& objects )
397 GEOM::ListOfGO_var aList;
399 switch ( getConstructorId() ) {
401 aList = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->ExplodeCompoundOfBlocks
403 myGrp1->SpinBox1->value(),
404 myGrp1->SpinBox2->value() );
408 if ( !aList->length() )
414 // Store objects. They will be put in study when "Apply" is pressed
415 for ( int i = 0, n = aList->length(); i < n; i++ ) {
416 objects.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
417 myTmpObjs.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
420 return objects.size() > 0;
423 // Throw away sub-shapes not selected by user if not in preview mode
424 // and manual selection is active
425 if ( !isAllSubShapes() ) {
426 QMap<QString, char> selected;
428 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
429 SALOME_ListIO aSelList;
430 aSelMgr->selectedObjects(aSelList);
432 // Get names of selected objects
433 SALOME_ListIteratorOfListIO it (aSelList);
434 for ( ; it.More(); it.Next() ) {
435 selected.insert( it.Value()->getName(), 0 );
438 // Iterate through result and select objects with names from selection
439 ObjectList toRemoveFromEngine;
440 ObjectList::iterator anIter;
441 for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter ) {
442 CORBA::String_var objStr = myGeomGUI->getApp()->orb()->object_to_string( *anIter );
443 if ( selected.contains( QString( objStr.in() ) ) )
444 objects.push_back( *anIter );
446 toRemoveFromEngine.push_back( *anIter );
449 // Remove from engine useless objects
450 ObjectList::iterator anIter2 = toRemoveFromEngine.begin();
451 for ( ; anIter2 != toRemoveFromEngine.end(); ++anIter2 )
452 getGeomEngine()->RemoveObject( *anIter2 );
458 for ( int i = 0, n = aList->length(); i < n; i++ )
459 objects.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
462 return objects.size();
465 //=================================================================================
466 // function : clearTemporary
467 // purpose : Remove temporary objects from engine
468 //=================================================================================
469 void BlocksGUI_ExplodeDlg::clearTemporary()
471 ObjectList::iterator anIter;
472 for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter )
473 getGeomEngine()->RemoveObject( *anIter );
478 //================================================================
479 // Function : getFather
480 // Purpose : Get father object for object to be added in study
481 // ( called with addInStudy method )
482 //================================================================
483 GEOM::GEOM_Object_ptr BlocksGUI_ExplodeDlg::getFather( GEOM::GEOM_Object_ptr )
488 //================================================================
489 // Function : getNewObjectName
490 // Purpose : Redefine this method to return proper name for a new object
491 //================================================================
492 QString BlocksGUI_ExplodeDlg::getNewObjectName() const
494 return QString::null;