1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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_ListIO.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 ), myNbBlocks( 0 )
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 setIsApplyAndClose( true );
167 if ( ClickOnApply() )
171 //=================================================================================
172 // function : ClickOnApply()
174 //=================================================================================
175 bool BlocksGUI_ExplodeDlg::ClickOnApply()
177 SUIT_Session::session()->activeApplication()->putInfo( tr( "" ) );
179 // Explode all sub-shapes
180 if ( isAllSubShapes() ) {
181 // More than 30 sub-shapes : ask confirmation
182 if ( myNbBlocks > 30 ) {
183 if ( SUIT_MessageBox::warning( this,
184 tr( "GEOM_CONFIRM" ),
185 tr( "GEOM_CONFIRM_INFO" ).arg( myNbBlocks ),
186 tr( "GEOM_BUT_EXPLODE" ),
187 tr( "GEOM_BUT_CANCEL" ) ) != 0 )
188 return false; /* aborted */
192 if ( !onAccept( true, true, false ) )
200 //=================================================================================
201 // function : SelectionIntoArgument()
202 // purpose : Called when selection has changed
203 //=================================================================================
204 void BlocksGUI_ExplodeDlg::SelectionIntoArgument()
206 if (!isAllSubShapes())
209 myObject = GEOM::GEOM_Object::_nil();
210 myGrp1->LineEdit1->setText("");
212 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
213 SALOME_ListIO aSelList;
214 aSelMgr->selectedObjects(aSelList);
216 if (aSelList.Extent() == 1) {
217 GEOM::GEOM_Object_var anObj = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
219 if ( GEOMBase::IsShape(anObj) ) {
221 myGrp1->LineEdit1->setText(GEOMBase::GetName(anObj));
228 //=================================================================================
229 // function : SetEditCurrentArgument()
231 //=================================================================================
232 void BlocksGUI_ExplodeDlg::SetEditCurrentArgument()
234 QPushButton* aSender = (QPushButton*)sender();
236 if ( myGrp1->PushButton1 == aSender ) {
237 myGrp1->LineEdit1->setFocus();
238 myEditCurrentArgument = myGrp1->LineEdit1;
239 myGrp1->CheckBox1->setChecked( false );
245 //=================================================================================
246 // function : ActivateThisDialog()
248 //=================================================================================
249 void BlocksGUI_ExplodeDlg::ActivateThisDialog()
251 GEOMBase_Skeleton::ActivateThisDialog();
252 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
253 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
258 //=================================================================================
259 // function : enterEvent()
261 //=================================================================================
262 void BlocksGUI_ExplodeDlg::enterEvent( QEvent* )
264 if ( !mainFrame()->GroupConstructors->isEnabled() )
265 this->ActivateThisDialog();
268 //=================================================================================
269 // function : ValueChangedInSpinBox()
271 //=================================================================================
272 void BlocksGUI_ExplodeDlg::ValueChangedInSpinBox()
274 if ( !isAllSubShapes() )
280 //=================================================================================
281 // function : SubShapeToggled()
282 // purpose : Allow user selection of all or only selected sub-shapes
283 // : Called when 'myGrp1->CheckBox1' state change
284 //=================================================================================
285 void BlocksGUI_ExplodeDlg::SubShapeToggled()
290 //=================================================================================
291 // function : activateSelection
292 // purpose : Redisplay preview and Activate selection
293 //=================================================================================
294 void BlocksGUI_ExplodeDlg::activateSelection()
297 erasePreview( true );
299 if ( isAllSubShapes() ) { // Sub-shapes selection disabled
300 disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
301 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
302 globalSelection( GEOM_ALLSHAPES );
303 if ( myObject->_is_nil() ) {
304 SelectionIntoArgument();
306 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
307 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
310 displayPreview( true, true, true, false );
311 globalSelection( GEOM_PREVIEW );
315 //=================================================================================
316 // function : updateButtonState
318 //=================================================================================
319 void BlocksGUI_ExplodeDlg::updateButtonState()
321 if ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
322 != OCCViewer_Viewer::Type() || myObject->_is_nil() ) {
323 myGrp1->CheckBox1->setChecked( false );
324 myGrp1->CheckBox1->setEnabled( false );
327 myGrp1->CheckBox1->setEnabled( true );
332 if ( myObject->_is_nil() ) {
333 myGrp1->TextBrowser1->setText( "" );
336 GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow(getOperation());
337 bool isOnlyBlocks = anOper->IsCompoundOfBlocks( myObject,
338 myGrp1->SpinBox1->value(),
339 myGrp1->SpinBox2->value(),
342 myGrp1->TextBrowser1->setText( tr( "GEOM_NB_BLOCKS_NO_OTHERS" ).arg( myNbBlocks ) );
344 myGrp1->TextBrowser1->setText( tr( "GEOM_NB_BLOCKS_SOME_OTHERS" ).arg( myNbBlocks ) );
348 //=================================================================================
349 // function : isAllSubShapes
351 //=================================================================================
352 bool BlocksGUI_ExplodeDlg::isAllSubShapes() const
354 return !(myGrp1->CheckBox1->isEnabled() && myGrp1->CheckBox1->isChecked());
357 //=================================================================================
358 // function : createOperation
360 //=================================================================================
361 GEOM::GEOM_IOperations_ptr BlocksGUI_ExplodeDlg::createOperation()
363 return getGeomEngine()->GetIBlocksOperations( getStudyId() );
366 //=================================================================================
367 // function : isValid()
368 // purpose : Verify validity of input data
369 //=================================================================================
370 bool BlocksGUI_ExplodeDlg::isValid (QString& msg)
373 okSP = myGrp1->SpinBox1->isValid( msg, !IsPreview() ) && okSP;
374 okSP = myGrp1->SpinBox2->isValid( msg, !IsPreview() ) && okSP;
377 switch ( getConstructorId() ) {
380 ok = !myObject->_is_nil();
383 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
384 SALOME_ListIO aSelList;
385 aSelMgr->selectedObjects(aSelList);
387 ok = !myObject->_is_nil() && (isAllSubShapes() || aSelList.Extent());
397 //=================================================================================
398 // function : execute
400 //=================================================================================
401 bool BlocksGUI_ExplodeDlg::execute( ObjectList& objects )
403 GEOM::ListOfGO_var aList;
405 GEOM::GEOM_IBlocksOperations_var anOper = GEOM::GEOM_IBlocksOperations::_narrow(getOperation());
407 switch ( getConstructorId() ) {
409 aList = anOper->ExplodeCompoundOfBlocks( myObject,
410 myGrp1->SpinBox1->value(),
411 myGrp1->SpinBox2->value() );
415 if ( !aList->length() )
421 // Store objects. They will be put in study when "Apply" is pressed
422 for ( int i = 0, n = aList->length(); i < n; i++ ) {
423 objects.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
424 myTmpObjs.push_back( GEOM::GEOM_Object::_duplicate( aList[i] ) );
427 return objects.size() > 0;
430 QStringList aParameters;
431 aParameters << myGrp1->SpinBox1->text();
432 aParameters << myGrp1->SpinBox2->text();
434 // Throw away sub-shapes not selected by user if not in preview mode
435 // and manual selection is active
436 if ( !isAllSubShapes() ) {
437 QMap<QString, char> selected;
439 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
440 SALOME_ListIO aSelList;
441 aSelMgr->selectedObjects(aSelList);
443 // Get names of selected objects
444 SALOME_ListIteratorOfListIO it (aSelList);
445 for ( ; it.More(); it.Next() ) {
446 selected.insert( it.Value()->getName(), 0 );
449 // Iterate through result and select objects with names from selection
450 ObjectList toRemoveFromEngine;
451 ObjectList::iterator anIter;
452 for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter ) {
453 CORBA::String_var objStr = myGeomGUI->getApp()->orb()->object_to_string( *anIter );
454 if ( selected.contains( QString( objStr.in() ) ) )
457 (*anIter)->SetParameters(aParameters.join(":").toLatin1().constData());
458 objects.push_back( *anIter );
461 toRemoveFromEngine.push_back( *anIter );
464 // Remove from engine useless objects
465 ObjectList::iterator anIter2 = toRemoveFromEngine.begin();
466 for ( ; anIter2 != toRemoveFromEngine.end(); ++anIter2 )
467 getGeomEngine()->RemoveObject( *anIter2 );
473 for ( int i = 0, n = aList->length(); i < n; i++ )
475 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aList[i] );
477 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
478 objects.push_back( anObj._retn() );
482 return objects.size();
485 //=================================================================================
486 // function : clearTemporary
487 // purpose : Remove temporary objects from engine
488 //=================================================================================
489 void BlocksGUI_ExplodeDlg::clearTemporary()
491 ObjectList::iterator anIter;
492 for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter )
493 getGeomEngine()->RemoveObject( *anIter );
498 //================================================================
499 // Function : getFather
500 // Purpose : Get father object for object to be added in study
501 // ( called with addInStudy method )
502 //================================================================
503 GEOM::GEOM_Object_ptr BlocksGUI_ExplodeDlg::getFather( GEOM::GEOM_Object_ptr )
508 //================================================================
509 // Function : getNewObjectName
510 // Purpose : Redefine this method to return proper name for a new object
511 //================================================================
512 QString BlocksGUI_ExplodeDlg::getNewObjectName (int) const
514 return QString::null;
517 //=================================================================================
518 // function : getSourceObjects
519 // purpose : virtual method to get source objects
520 //=================================================================================
521 QList<GEOM::GeomObjPtr> BlocksGUI_ExplodeDlg::getSourceObjects()
523 QList<GEOM::GeomObjPtr> res;
524 GEOM::GeomObjPtr aGeomObjPtr(myObject);