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.htm" );
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 // Set range of spinboxes
101 int SpecificStep = 1;
102 initSpinBox( myGrp1->SpinBox1, 0, 999, SpecificStep );
103 initSpinBox( myGrp1->SpinBox2, 0, 999, SpecificStep );
105 if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
106 != OCCViewer_Viewer::Type() )
107 myGrp1->CheckBox1->setEnabled( false );
109 // signals and slots connections
110 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
111 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
113 connect( myGrp1->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
115 connect( myGrp1->SpinBox1, SIGNAL( valueChanged( int ) ), this, SLOT( ValueChangedInSpinBox( int ) ) );
116 connect( myGrp1->SpinBox2, SIGNAL( valueChanged( int ) ), this, SLOT( ValueChangedInSpinBox( int ) ) );
118 connect( myGrp1->CheckBox1, SIGNAL( stateChanged( int ) ), this, SLOT( SubShapeToggled() ) );
120 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
121 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
123 myConstructorId = -1;
124 ConstructorsClicked( 0 );
127 //=================================================================================
128 // function : ConstructorsClicked()
129 // purpose : Radio button management
130 //=================================================================================
131 void BlocksGUI_ExplodeDlg::ConstructorsClicked( int constructorId )
133 if ( myConstructorId == constructorId )
136 myConstructorId = constructorId;
138 switch ( constructorId ) {
141 myGrp1->SpinBox1->setValue( 6 );
142 myGrp1->SpinBox2->setValue( 6 );
143 myGrp1->CheckBox1->setChecked( false );
150 myEditCurrentArgument = myGrp1->LineEdit1;
151 myObject = GEOM::GEOM_Object::_nil();
156 //=================================================================================
157 // function : ClickOnOk()
159 //=================================================================================
160 void BlocksGUI_ExplodeDlg::ClickOnOk()
162 if ( ClickOnApply() )
166 //=================================================================================
167 // function : ClickOnApply()
169 //=================================================================================
170 bool BlocksGUI_ExplodeDlg::ClickOnApply()
172 SUIT_Session::session()->activeApplication()->putInfo( tr( "" ) );
174 // Explode all sub shapes
175 if ( isAllSubShapes() ) {
176 // More than 30 subshapes : ask confirmation
177 if ( myNbBlocks > 30 ) {
178 if ( SUIT_MessageBox::warning( this,
179 tr( "GEOM_CONFIRM" ),
180 tr( "GEOM_CONFIRM_INFO" ).arg( myNbBlocks ),
181 tr( "GEOM_BUT_EXPLODE" ),
182 tr( "GEOM_BUT_CANCEL" ) ) != 0 )
183 return false; /* aborted */
195 //=================================================================================
196 // function : SelectionIntoArgument()
197 // purpose : Called when selection has changed
198 //=================================================================================
199 void BlocksGUI_ExplodeDlg::SelectionIntoArgument()
201 if ( !isAllSubShapes() )
204 myObject = GEOM::GEOM_Object::_nil();
205 myGrp1->LineEdit1->setText( "" );
207 if ( IObjectCount() == 1 ) {
208 Standard_Boolean aResult = Standard_False;
209 GEOM::GEOM_Object_var anObj =
210 GEOMBase::ConvertIOinGEOMObject( firstIObject(), aResult );
212 if ( aResult && !anObj->_is_nil() && GEOMBase::IsShape( anObj ) ) {
214 myGrp1->LineEdit1->setText( GEOMBase::GetName( anObj ) );
221 //=================================================================================
222 // function : SetEditCurrentArgument()
224 //=================================================================================
225 void BlocksGUI_ExplodeDlg::SetEditCurrentArgument()
227 QPushButton* aSender = (QPushButton*)sender();
229 if ( myGrp1->PushButton1 == aSender ) {
230 myGrp1->LineEdit1->setFocus();
231 myEditCurrentArgument = myGrp1->LineEdit1;
232 myGrp1->CheckBox1->setChecked( false );
238 //=================================================================================
239 // function : ActivateThisDialog()
241 //=================================================================================
242 void BlocksGUI_ExplodeDlg::ActivateThisDialog()
244 GEOMBase_Skeleton::ActivateThisDialog();
245 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
246 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
251 //=================================================================================
252 // function : enterEvent()
254 //=================================================================================
255 void BlocksGUI_ExplodeDlg::enterEvent( QEvent* )
257 if ( !mainFrame()->GroupConstructors->isEnabled() )
258 this->ActivateThisDialog();
261 //=================================================================================
262 // function : ValueChangedInSpinBox()
264 //=================================================================================
265 void BlocksGUI_ExplodeDlg::ValueChangedInSpinBox()
267 if ( !isAllSubShapes() )
273 //=================================================================================
274 // function : SubShapeToggled()
275 // purpose : Allow user selection of all or only selected sub shapes
276 // : Called when 'myGrp1->CheckBox1' state change
277 //=================================================================================
278 void BlocksGUI_ExplodeDlg::SubShapeToggled()
283 //=================================================================================
284 // function : activateSelection
285 // purpose : Redisplay preview and Activate selection
286 //=================================================================================
287 void BlocksGUI_ExplodeDlg::activateSelection()
290 erasePreview( true );
292 if ( isAllSubShapes() ) { // Sub-shapes selection disabled
293 disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
294 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
295 globalSelection( GEOM_ALLSHAPES );
296 if ( myObject->_is_nil() ) {
297 SelectionIntoArgument();
299 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
300 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
303 displayPreview( true, true, false );
304 globalSelection( GEOM_PREVIEW );
308 //=================================================================================
309 // function : updateButtonState
311 //=================================================================================
312 void BlocksGUI_ExplodeDlg::updateButtonState()
314 if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
315 != OCCViewer_Viewer::Type() || myObject->_is_nil() ) {
316 myGrp1->CheckBox1->setChecked( false );
317 myGrp1->CheckBox1->setEnabled( false );
320 myGrp1->CheckBox1->setEnabled( true );
325 if ( myObject->_is_nil() ) {
326 myGrp1->TextBrowser1->setText( "" );
329 bool isOnlyBlocks = GEOM::GEOM_IBlocksOperations::_narrow
330 ( getOperation() )->IsCompoundOfBlocks( myObject,
331 myGrp1->SpinBox1->value(),
332 myGrp1->SpinBox2->value(),
335 myGrp1->TextBrowser1->setText( tr( "GEOM_NB_BLOCKS_NO_OTHERS" ).arg( myNbBlocks ) );
337 myGrp1->TextBrowser1->setText( tr( "GEOM_NB_BLOCKS_SOME_OTHERS" ).arg( myNbBlocks ) );
341 //=================================================================================
342 // function : isAllSubShapes
344 //=================================================================================
345 bool BlocksGUI_ExplodeDlg::isAllSubShapes() const
347 return !myGrp1->CheckBox1->isChecked() || !myGrp1->CheckBox1->isEnabled();
350 //=================================================================================
351 // function : createOperation
353 //=================================================================================
354 GEOM::GEOM_IOperations_ptr BlocksGUI_ExplodeDlg::createOperation()
356 return getGeomEngine()->GetIBlocksOperations( getStudyId() );
359 //=================================================================================
360 // function : isValid()
361 // purpose : Verify validity of input data
362 //=================================================================================
363 bool BlocksGUI_ExplodeDlg::isValid( QString& )
366 switch ( getConstructorId() ) {
369 ok = !myObject->_is_nil();
371 ok = !myObject->_is_nil() && ( isAllSubShapes() || IObjectCount() );
380 //=================================================================================
381 // function : execute
383 //=================================================================================
384 bool BlocksGUI_ExplodeDlg::execute( ObjectList& objects )
386 GEOM::ListOfGO_var aList;
388 switch ( getConstructorId() ) {
390 aList = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->ExplodeCompoundOfBlocks
392 myGrp1->SpinBox1->value(),
393 myGrp1->SpinBox2->value() );
397 if ( !aList->length() )
403 // Store objects. They will be put in study when "Apply" is pressed
404 for ( int i = 0, n = aList->length(); i < n; i++ ) {
405 objects.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
406 myTmpObjs.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
409 return objects.size() > 0;
412 // Throw away sub-shapes not selected by user if not in preview mode
413 // and manual selection is active
414 if ( !isAllSubShapes() ) {
415 QMap<QString, char> selected;
417 // Get names of selected objects
418 SALOME_ListIteratorOfListIO it ( selectedIO() );
419 for ( ; it.More(); it.Next() ) {
420 selected.insert( it.Value()->getName(), 0 );
423 // Iterate through result and select objects with names from selection
424 ObjectList toRemoveFromEnggine;
425 ObjectList::iterator anIter;
426 for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter ) {
427 CORBA::String_var objStr = myGeomGUI->getApp()->orb()->object_to_string( *anIter );
428 if ( selected.contains( QString( objStr.in() ) ) )
429 objects.push_back( *anIter );
431 toRemoveFromEnggine.push_back( *anIter );
434 // Remove from engine useless objects
435 ObjectList::iterator anIter2 = toRemoveFromEnggine.begin();
436 for ( ; anIter2 != toRemoveFromEnggine.end(); ++anIter2 )
437 getGeomEngine()->RemoveObject( *anIter2 );
443 for ( int i = 0, n = aList->length(); i < n; i++ )
444 objects.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
447 return objects.size();
450 //=================================================================================
451 // function : clearTemporary
452 // purpose : Remove temporary objects from engine
453 //=================================================================================
454 void BlocksGUI_ExplodeDlg::clearTemporary()
456 ObjectList::iterator anIter;
457 for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter )
458 getGeomEngine()->RemoveObject( *anIter );
463 //================================================================
464 // Function : getFather
465 // Purpose : Get father object for object to be added in study
466 // ( called with addInStudy method )
467 //================================================================
468 GEOM::GEOM_Object_ptr BlocksGUI_ExplodeDlg::getFather( GEOM::GEOM_Object_ptr )
473 //================================================================
474 // Function : getNewObjectName
475 // Purpose : Redefine this method to return proper name for a new object
476 //================================================================
477 const char* BlocksGUI_ExplodeDlg::getNewObjectName() const