1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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
22 // File : OperationGUI_PartitionDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "OperationGUI_PartitionDlg.h"
27 #include "OperationGUI_MaterialDlg.h"
30 #include <GeometryGUI.h>
33 #include <GEOMImpl_Types.hxx>
35 #include <SUIT_Desktop.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_ResourceMgr.h>
38 #include <SalomeApp_Application.h>
39 #include <LightApp_SelectionMgr.h>
41 //=================================================================================
42 // class : OperationGUI_PartitionDlg()
43 // purpose : Constructs a OperationGUI_PartitionDlg which is a child of 'parent', with the
44 // name 'name' and widget flags set to 'f'.
45 // The dialog will by default be modeless, unless you set 'modal' to
46 // TRUE to construct a modal dialog.
47 //=================================================================================
48 OperationGUI_PartitionDlg::OperationGUI_PartitionDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
49 : GEOMBase_Skeleton( theGeometryGUI, parent, false )
51 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
52 QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_PARTITION" ) ) );
53 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_PARTITION_PLANE" ) ) );
54 QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
56 setWindowTitle( tr( "GEOM_PARTITION_TITLE" ) );
58 /***************************************************************/
59 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PARTITION" ) );
60 mainFrame()->RadioButton1->setIcon( image0 );
61 mainFrame()->RadioButton2->setIcon( image1 );
62 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
63 mainFrame()->RadioButton3->close();
65 // Full partition (contains half-space partition)
66 GroupPoints = new DlgRef_2Sel1List( centralWidget() );
67 GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION" ) );
68 GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
69 GroupPoints->TextLabel2->setText( tr( "GEOM_TOOL_OBJECT" ) );
70 GroupPoints->TextLabel3->setText( tr( "GEOM_RECONSTRUCTION_LIMIT" ) );
71 GroupPoints->PushButton1->setIcon( image2 );
72 GroupPoints->PushButton2->setIcon( image2 );
73 GroupPoints->LineEdit1->setReadOnly( true );
74 GroupPoints->LineEdit2->setReadOnly( true );
76 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
77 layout->setMargin( 0 ); layout->setSpacing( 6 );
78 layout->addWidget( GroupPoints );
80 /***************************************************************/
82 setHelpFileName( "partition.htm" );
88 //=================================================================================
89 // function : ~OperationGUI_PartitionDlg()
90 // purpose : Destroys the object and frees any allocated resources
91 //=================================================================================
92 OperationGUI_PartitionDlg::~OperationGUI_PartitionDlg()
94 // no need to delete child widgets, Qt does it all for us
97 void OperationGUI_PartitionDlg::SetListMaterials( GEOM::ListOfLong ListMaterials )
99 myListMaterials = ListMaterials;
102 GEOM::ListOfLong OperationGUI_PartitionDlg::GetListMaterials()
104 return myListMaterials;
107 //=================================================================================
110 //=================================================================================
111 void OperationGUI_PartitionDlg::Init()
113 /* type for sub shape selection */
114 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_SOLID" ) );
115 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_SHELL" ) );
116 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_FACE" ) );
117 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_WIRE" ) );
118 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_EDGE" ) );
119 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_VERTEX" ) );
121 /* signals and slots connections */
122 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
123 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
125 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
127 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
128 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
130 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
131 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
133 connect( GroupPoints->ComboBox1, SIGNAL( activated( int ) ), this, SLOT( ComboTextChanged() ) );
135 connect( myGeomGUI->getApp()->selectionMgr(),
136 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
138 initName( tr( "GEOM_PARTITION" ) );
140 ConstructorsClicked( 0 );
144 //=================================================================================
145 // function : ConstructorsClicked()
146 // purpose : Radio button management
147 //=================================================================================
148 void OperationGUI_PartitionDlg::ConstructorsClicked( int constructorId )
150 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
153 myListShapes.length( 0 );
154 myListTools.length( 0 );
155 myListKeepInside.length( 0 );
156 myListRemoveInside.length( 0 );
157 myListMaterials.length( 0 );
159 switch ( constructorId ) {
160 case 0: /*Full partition */
161 GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION" ) );
162 GroupPoints->TextLabel2->setText( tr( "GEOM_TOOL_OBJECT" ) );
163 GroupPoints->TextLabel3->show();
164 GroupPoints->ComboBox1->show();
166 GroupPoints->ComboBox1->setCurrentIndex( 0 );
168 case 1: /*Half-space partition */
169 GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION_HALFSPACE" ) );
170 GroupPoints->TextLabel3->hide();
171 GroupPoints->ComboBox1->hide();
172 GroupPoints->TextLabel2->setText( tr( "GEOM_PLANE" ) );
176 myEditCurrentArgument = GroupPoints->LineEdit1;
177 GroupPoints->LineEdit1->clear();
178 GroupPoints->LineEdit2->clear();
180 qApp->processEvents();
182 resize( minimumSize() );
184 myEditCurrentArgument->setFocus();
185 connect( myGeomGUI->getApp()->selectionMgr(),
186 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
190 //=================================================================================
191 // function : ClickOnOk()
193 //=================================================================================
194 void OperationGUI_PartitionDlg::ClickOnOk()
196 if ( ClickOnApply() )
201 //=================================================================================
202 // function : ClickOnApply()
204 //=================================================================================
205 bool OperationGUI_PartitionDlg::ClickOnApply()
211 ConstructorsClicked( getConstructorId() );
216 //=================================================================================
217 // function : SelectionIntoArgument()
218 // purpose : Called when selection as changed or other case
219 //=================================================================================
220 void OperationGUI_PartitionDlg::SelectionIntoArgument()
222 myEditCurrentArgument->setText( "" );
223 QString aString = "";
225 int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
228 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
229 myListShapes.length( 0 );
230 myListMaterials.length( 0 );
232 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
233 myListTools.length( 0 );
236 // One and only one plane can be selected
238 if ( getConstructorId() == 1 &&
239 myEditCurrentArgument == GroupPoints->LineEdit2 &&
241 myListTools.length( 0 );
245 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
246 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListShapes, true );
247 myListMaterials.length( 0 );
248 if ( !myListShapes.length() )
251 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
252 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListTools, true );
253 if ( !myListTools.length() )
257 myEditCurrentArgument->setText( aString );
261 //=================================================================================
262 // function : SetEditCurrentArgument()
264 //=================================================================================
265 void OperationGUI_PartitionDlg::SetEditCurrentArgument()
267 QPushButton* send = (QPushButton*)sender();
269 if ( send == GroupPoints->PushButton1 )
270 myEditCurrentArgument = GroupPoints->LineEdit1;
271 else if ( send == GroupPoints->PushButton2 ) {
272 myEditCurrentArgument = GroupPoints->LineEdit2;
273 if ( getConstructorId() == 1 )
274 globalSelection( GEOM_PLANE );
277 globalSelection( GEOM_ALLSHAPES );
279 myEditCurrentArgument->setFocus();
280 SelectionIntoArgument();
284 //=================================================================================
285 // function : LineEditReturnPressed()
287 //=================================================================================
288 void OperationGUI_PartitionDlg::LineEditReturnPressed()
290 QLineEdit* send = (QLineEdit*)sender();
292 if ( send == GroupPoints->LineEdit1 ||
293 send == GroupPoints->LineEdit2 ) {
294 myEditCurrentArgument = send;
295 GEOMBase_Skeleton::LineEditReturnPressed();
300 //=================================================================================
301 // function : ActivateThisDialog()
303 //=================================================================================
304 void OperationGUI_PartitionDlg::ActivateThisDialog()
306 GEOMBase_Skeleton::ActivateThisDialog();
307 connect( myGeomGUI->getApp()->selectionMgr(),
308 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
310 ConstructorsClicked( getConstructorId() );
314 //=================================================================================
315 // function : enterEvent()
317 //=================================================================================
318 void OperationGUI_PartitionDlg::enterEvent( QEvent* )
320 if ( !mainFrame()->GroupConstructors->isEnabled() )
321 this->ActivateThisDialog();
325 //=================================================================================
326 // function : createOperation
328 //=================================================================================
329 GEOM::GEOM_IOperations_ptr OperationGUI_PartitionDlg::createOperation()
331 return getGeomEngine()->GetIBooleanOperations( getStudyId() );
335 //=================================================================================
336 // function : isValid
338 //=================================================================================
339 bool OperationGUI_PartitionDlg::isValid( QString& )
341 return ( myListShapes.length() || myListTools.length() ||
342 myListKeepInside.length() || myListRemoveInside.length() );
346 //=================================================================================
347 // function : execute
349 //=================================================================================
350 bool OperationGUI_PartitionDlg::execute( ObjectList& objects )
354 GEOM::GEOM_Object_var anObj;
357 int aLimit = GetLimit();
358 int aConstructorId = getConstructorId();
360 if ( aConstructorId == 1 )
361 aLimit = GEOM::SHAPE;
363 if ( isValid( msg ) ) {
364 anObj = GEOM::GEOM_IBooleanOperations::_narrow(getOperation())->
365 MakePartition(myListShapes, myListTools,
366 myListKeepInside, myListRemoveInside,
367 aLimit, false, myListMaterials);
371 if ( !anObj->_is_nil() )
372 objects.push_back( anObj._retn() );
378 //=================================================================================
379 // function : closeEvent
381 //=================================================================================
382 void OperationGUI_PartitionDlg::closeEvent( QCloseEvent* e )
384 GEOMBase_Skeleton::closeEvent( e );
388 //=======================================================================
389 //function : ComboTextChanged
391 //=======================================================================
392 void OperationGUI_PartitionDlg::ComboTextChanged()
394 //bool IsEnabled = GroupPoints->ComboBox1->currentItem() < 3;
395 //GroupPoints->LineEdit3->setEnabled(IsEnabled);
396 //GroupPoints->LineEdit4->setEnabled(IsEnabled);
397 //GroupPoints->TextLabel4->setEnabled(IsEnabled);
398 //GroupPoints->TextLabel5->setEnabled(IsEnabled);
399 //GroupPoints->PushButton3->setEnabled(IsEnabled);
400 //GroupPoints->PushButton4->setEnabled(IsEnabled);
404 //=================================================================================
405 // function : GetLimit()
407 //=================================================================================
408 int OperationGUI_PartitionDlg::GetLimit() const
410 int aLimit = GroupPoints->ComboBox1->currentIndex();
413 case 0: aLimit = GEOM::SOLID ; break;
414 case 1: aLimit = GEOM::SHELL ; break;
415 case 2: aLimit = GEOM::FACE ; break;
416 case 3: aLimit = GEOM::WIRE ; break;
417 case 4: aLimit = GEOM::EDGE ; break;
418 case 5: aLimit = GEOM::VERTEX; break;
419 default: aLimit = GEOM::SHAPE ;