1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : BlocksGUI_ExplodeDlg.cxx
25 // Author : Julia DOROVSKIKH, Open CASCADE S.A.S. (julia.dorovskikh@opencascade.com)
27 #include "BlocksGUI_ExplodeDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_Desktop.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_ViewWindow.h>
37 #include <SUIT_ViewManager.h>
38 #include <SUIT_MessageBox.h>
39 #include <SalomeApp_Application.h>
40 #include <LightApp_SelectionMgr.h>
41 #include <OCCViewer_ViewModel.h>
42 #include <SALOME_ListIteratorOfListIO.hxx>
44 //=================================================================================
45 // class : BlocksGUI_ExplodeDlg()
46 // purpose : Constructs a BlocksGUI_ExplodeDlg which is a child of 'parent'.
47 //=================================================================================
48 BlocksGUI_ExplodeDlg::BlocksGUI_ExplodeDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
49 : GEOMBase_Skeleton( theGeometryGUI, parent )
51 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BLOCK_EXPLODE" ) ) );
52 QPixmap imageS( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
54 setWindowTitle( tr( "GEOM_BLOCK_EXPLODE_TITLE" ) );
56 /***************************************************************/
57 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_BLOCK_EXPLODE" ) );
59 mainFrame()->RadioButton1->setIcon( image1 );
60 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
61 mainFrame()->RadioButton2->close();
62 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
63 mainFrame()->RadioButton3->close();
66 myGrp1 = new DlgRef_1Sel2Spin1View1Check( centralWidget() );
67 myGrp1->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
68 myGrp1->TextLabel1->setText( tr( "GEOM_MAIN_OBJECT" ) );
69 myGrp1->PushButton1->setIcon( imageS );
70 myGrp1->LineEdit1->setReadOnly( true );
71 myGrp1->TextLabel2->setText( tr( "NB_FACES_MIN" ) );
72 myGrp1->TextLabel3->setText( tr( "NB_FACES_MAX" ) );
73 myGrp1->CheckBox1->setText( tr( "GEOM_SUBSHAPE_SELECT" ) );
75 // Add groups to layout
76 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
77 layout->setMargin( 0 ); layout->setSpacing( 6 );
78 layout->addWidget( myGrp1 );
79 /***************************************************************/
81 setHelpFileName( "explode_on_blocks_operation_page.html" );
86 //=================================================================================
87 // function : ~BlocksGUI_ExplodeDlg()
88 // purpose : Destroys the object and frees any allocated resources
89 //=================================================================================
90 BlocksGUI_ExplodeDlg::~BlocksGUI_ExplodeDlg()
92 // no need to delete child widgets, Qt does it all for us
96 //=================================================================================
99 //=================================================================================
100 void BlocksGUI_ExplodeDlg::Init()
102 mainFrame()->GroupBoxName->hide();
104 // Set range of spinboxes
105 int SpecificStep = 1;
106 initSpinBox( myGrp1->SpinBox1, 0, 999, SpecificStep );
107 initSpinBox( myGrp1->SpinBox2, 0, 999, SpecificStep );
109 if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
110 != OCCViewer_Viewer::Type() )
111 myGrp1->CheckBox1->setEnabled( false );
113 // signals and slots connections
114 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
115 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
117 connect( myGrp1->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
119 connect( myGrp1->SpinBox1, SIGNAL( valueChanged( int ) ), this, SLOT( ValueChangedInSpinBox( int ) ) );
120 connect( myGrp1->SpinBox2, SIGNAL( valueChanged( int ) ), this, SLOT( ValueChangedInSpinBox( int ) ) );
122 connect( myGrp1->CheckBox1, SIGNAL( stateChanged( int ) ), this, SLOT( SubShapeToggled() ) );
124 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
125 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
127 myConstructorId = -1;
128 ConstructorsClicked( 0 );
131 //=================================================================================
132 // function : ConstructorsClicked()
133 // purpose : Radio button management
134 //=================================================================================
135 void BlocksGUI_ExplodeDlg::ConstructorsClicked( int constructorId )
137 if ( myConstructorId == constructorId )
140 myConstructorId = constructorId;
142 switch ( constructorId ) {
145 myGrp1->SpinBox1->setValue( 6 );
146 myGrp1->SpinBox2->setValue( 6 );
147 myGrp1->CheckBox1->setChecked( false );
154 myEditCurrentArgument = myGrp1->LineEdit1;
155 myObject = GEOM::GEOM_Object::_nil();
160 //=================================================================================
161 // function : ClickOnOk()
163 //=================================================================================
164 void BlocksGUI_ExplodeDlg::ClickOnOk()
166 if ( ClickOnApply() )
170 //=================================================================================
171 // function : ClickOnApply()
173 //=================================================================================
174 bool BlocksGUI_ExplodeDlg::ClickOnApply()
176 SUIT_Session::session()->activeApplication()->putInfo( tr( "" ) );
178 // Explode all sub shapes
179 if ( isAllSubShapes() ) {
180 // More than 30 subshapes : ask confirmation
181 if ( myNbBlocks > 30 ) {
182 if ( SUIT_MessageBox::warning( this,
183 tr( "GEOM_CONFIRM" ),
184 tr( "GEOM_CONFIRM_INFO" ).arg( myNbBlocks ),
185 tr( "GEOM_BUT_EXPLODE" ),
186 tr( "GEOM_BUT_CANCEL" ) ) != 0 )
187 return false; /* aborted */
199 //=================================================================================
200 // function : SelectionIntoArgument()
201 // purpose : Called when selection has changed
202 //=================================================================================
203 void BlocksGUI_ExplodeDlg::SelectionIntoArgument()
205 if (!isAllSubShapes())
208 myObject = GEOM::GEOM_Object::_nil();
209 myGrp1->LineEdit1->setText("");
211 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
212 SALOME_ListIO aSelList;
213 aSelMgr->selectedObjects(aSelList);
215 if (aSelList.Extent() == 1) {
216 GEOM::GEOM_Object_var anObj = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
218 if ( GEOMBase::IsShape(anObj) ) {
220 myGrp1->LineEdit1->setText(GEOMBase::GetName(anObj));
227 //=================================================================================
228 // function : SetEditCurrentArgument()
230 //=================================================================================
231 void BlocksGUI_ExplodeDlg::SetEditCurrentArgument()
233 QPushButton* aSender = (QPushButton*)sender();
235 if ( myGrp1->PushButton1 == aSender ) {
236 myGrp1->LineEdit1->setFocus();
237 myEditCurrentArgument = myGrp1->LineEdit1;
238 myGrp1->CheckBox1->setChecked( false );
244 //=================================================================================
245 // function : ActivateThisDialog()
247 //=================================================================================
248 void BlocksGUI_ExplodeDlg::ActivateThisDialog()
250 GEOMBase_Skeleton::ActivateThisDialog();
251 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
252 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
257 //=================================================================================
258 // function : enterEvent()
260 //=================================================================================
261 void BlocksGUI_ExplodeDlg::enterEvent( QEvent* )
263 if ( !mainFrame()->GroupConstructors->isEnabled() )
264 this->ActivateThisDialog();
267 //=================================================================================
268 // function : ValueChangedInSpinBox()
270 //=================================================================================
271 void BlocksGUI_ExplodeDlg::ValueChangedInSpinBox()
273 if ( !isAllSubShapes() )
279 //=================================================================================
280 // function : SubShapeToggled()
281 // purpose : Allow user selection of all or only selected sub shapes
282 // : Called when 'myGrp1->CheckBox1' state change
283 //=================================================================================
284 void BlocksGUI_ExplodeDlg::SubShapeToggled()
289 //=================================================================================
290 // function : activateSelection
291 // purpose : Redisplay preview and Activate selection
292 //=================================================================================
293 void BlocksGUI_ExplodeDlg::activateSelection()
296 erasePreview( true );
298 if ( isAllSubShapes() ) { // Sub-shapes selection disabled
299 disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
300 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
301 globalSelection( GEOM_ALLSHAPES );
302 if ( myObject->_is_nil() ) {
303 SelectionIntoArgument();
305 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
306 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
309 displayPreview( true, true, false );
310 globalSelection( GEOM_PREVIEW );
314 //=================================================================================
315 // function : updateButtonState
317 //=================================================================================
318 void BlocksGUI_ExplodeDlg::updateButtonState()
320 if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
321 != OCCViewer_Viewer::Type() || myObject->_is_nil() ) {
322 myGrp1->CheckBox1->setChecked( false );
323 myGrp1->CheckBox1->setEnabled( false );
326 myGrp1->CheckBox1->setEnabled( true );
331 if ( myObject->_is_nil() ) {
332 myGrp1->TextBrowser1->setText( "" );
335 GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow(getOperation());
336 bool isOnlyBlocks = anOper->IsCompoundOfBlocks( myObject,
337 myGrp1->SpinBox1->value(),
338 myGrp1->SpinBox2->value(),
341 myGrp1->TextBrowser1->setText( tr( "GEOM_NB_BLOCKS_NO_OTHERS" ).arg( myNbBlocks ) );
343 myGrp1->TextBrowser1->setText( tr( "GEOM_NB_BLOCKS_SOME_OTHERS" ).arg( myNbBlocks ) );
347 //=================================================================================
348 // function : isAllSubShapes
350 //=================================================================================
351 bool BlocksGUI_ExplodeDlg::isAllSubShapes() const
353 return !myGrp1->CheckBox1->isChecked() || !myGrp1->CheckBox1->isEnabled();
356 //=================================================================================
357 // function : createOperation
359 //=================================================================================
360 GEOM::GEOM_IOperations_ptr BlocksGUI_ExplodeDlg::createOperation()
362 return getGeomEngine()->GetIBlocksOperations( getStudyId() );
365 //=================================================================================
366 // function : isValid()
367 // purpose : Verify validity of input data
368 //=================================================================================
369 bool BlocksGUI_ExplodeDlg::isValid (QString& msg)
372 okSP = myGrp1->SpinBox1->isValid( msg, !IsPreview() ) && okSP;
373 okSP = myGrp1->SpinBox2->isValid( msg, !IsPreview() ) && okSP;
376 switch ( getConstructorId() ) {
379 ok = !myObject->_is_nil();
382 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
383 SALOME_ListIO aSelList;
384 aSelMgr->selectedObjects(aSelList);
386 ok = !myObject->_is_nil() && (isAllSubShapes() || aSelList.Extent());
396 //=================================================================================
397 // function : execute
399 //=================================================================================
400 bool BlocksGUI_ExplodeDlg::execute( ObjectList& objects )
402 GEOM::ListOfGO_var aList;
404 GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow(getOperation());
406 switch ( getConstructorId() ) {
408 aList = anOper->ExplodeCompoundOfBlocks( myObject,
409 myGrp1->SpinBox1->value(),
410 myGrp1->SpinBox2->value() );
414 if ( !aList->length() )
420 // Store objects. They will be put in study when "Apply" is pressed
421 for ( int i = 0, n = aList->length(); i < n; i++ ) {
422 objects.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
423 myTmpObjs.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
426 return objects.size() > 0;
429 QStringList aParameters;
430 aParameters << myGrp1->SpinBox1->text();
431 aParameters << myGrp1->SpinBox2->text();
433 // Throw away sub-shapes not selected by user if not in preview mode
434 // and manual selection is active
435 if ( !isAllSubShapes() ) {
436 QMap<QString, char> selected;
438 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
439 SALOME_ListIO aSelList;
440 aSelMgr->selectedObjects(aSelList);
442 // Get names of selected objects
443 SALOME_ListIteratorOfListIO it (aSelList);
444 for ( ; it.More(); it.Next() ) {
445 selected.insert( it.Value()->getName(), 0 );
448 // Iterate through result and select objects with names from selection
449 ObjectList toRemoveFromEngine;
450 ObjectList::iterator anIter;
451 for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter ) {
452 CORBA::String_var objStr = myGeomGUI->getApp()->orb()->object_to_string( *anIter );
453 if ( selected.contains( QString( objStr.in() ) ) )
456 (*anIter)->SetParameters(aParameters.join(":").toLatin1().constData());
457 objects.push_back( *anIter );
460 toRemoveFromEngine.push_back( *anIter );
463 // Remove from engine useless objects
464 ObjectList::iterator anIter2 = toRemoveFromEngine.begin();
465 for ( ; anIter2 != toRemoveFromEngine.end(); ++anIter2 )
466 getGeomEngine()->RemoveObject( *anIter2 );
472 for ( int i = 0, n = aList->length(); i < n; i++ )
474 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aList[i] );
476 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
477 objects.push_back( anObj._retn() );
481 return objects.size();
484 //=================================================================================
485 // function : clearTemporary
486 // purpose : Remove temporary objects from engine
487 //=================================================================================
488 void BlocksGUI_ExplodeDlg::clearTemporary()
490 ObjectList::iterator anIter;
491 for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter )
492 getGeomEngine()->RemoveObject( *anIter );
497 //================================================================
498 // Function : getFather
499 // Purpose : Get father object for object to be added in study
500 // ( called with addInStudy method )
501 //================================================================
502 GEOM::GEOM_Object_ptr BlocksGUI_ExplodeDlg::getFather( GEOM::GEOM_Object_ptr )
507 //================================================================
508 // Function : getNewObjectName
509 // Purpose : Redefine this method to return proper name for a new object
510 //================================================================
511 QString BlocksGUI_ExplodeDlg::getNewObjectName() const
513 return QString::null;