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
24 // File : OperationGUI_PartitionDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "OperationGUI_PartitionDlg.h"
30 #include "OperationGUI_MaterialDlg.h"
32 #include "GEOMImpl_Types.hxx"
34 #include "SUIT_Desktop.h"
35 #include "SUIT_Session.h"
36 #include "SalomeApp_Application.h"
37 #include "LightApp_SelectionMgr.h"
39 #include <qcheckbox.h>
40 #include <qcombobox.h>
43 #include "utilities.h"
45 //=================================================================================
46 // class : OperationGUI_PartitionDlg()
47 // purpose : Constructs a OperationGUI_PartitionDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 OperationGUI_PartitionDlg::OperationGUI_PartitionDlg(GeometryGUI* theGeometryGUI, QWidget* parent)
53 :GEOMBase_Skeleton(theGeometryGUI, parent, "OperationGUI_PartitionDlg", false,
54 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
56 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
57 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PARTITION")));
58 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PARTITION_PLANE")));
59 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
61 setCaption(tr("GEOM_PARTITION_TITLE"));
63 /***************************************************************/
64 GroupConstructors->setTitle(tr("GEOM_PARTITION"));
65 RadioButton1->setPixmap(image0);
66 RadioButton2->setPixmap(image1);
67 RadioButton3->close(TRUE);
69 // Full partition (contains half-space partition)
70 GroupPoints = new DlgRef_2Sel1List_QTD(this, "GroupPoints");
71 GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
72 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
73 GroupPoints->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
74 GroupPoints->TextLabel3->setText(tr("GEOM_RECONSTRUCTION_LIMIT"));
75 GroupPoints->PushButton1->setPixmap(image2);
76 GroupPoints->PushButton2->setPixmap(image2);
77 GroupPoints->LineEdit1->setReadOnly( true );
78 GroupPoints->LineEdit2->setReadOnly( true );
80 Layout1->addWidget(GroupPoints, 2, 0);
81 /***************************************************************/
83 setHelpFileName("partition.htm");
89 //=================================================================================
90 // function : ~OperationGUI_PartitionDlg()
91 // purpose : Destroys the object and frees any allocated resources
92 //=================================================================================
93 OperationGUI_PartitionDlg::~OperationGUI_PartitionDlg()
95 // no need to delete child widgets, Qt does it all for us
99 //=================================================================================
102 //=================================================================================
103 void OperationGUI_PartitionDlg::Init()
105 /* type for sub shape selection */
106 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_SOLID"));
107 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_SHELL"));
108 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_FACE"));
109 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_WIRE"));
110 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_EDGE"));
111 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_VERTEX"));
113 /* signals and slots connections */
114 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
115 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
116 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
118 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
119 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
121 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
122 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
124 connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
126 connect(myGeomGUI->getApp()->selectionMgr(),
127 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
129 initName( tr( "GEOM_PARTITION" ) );
130 ConstructorsClicked( 0 );
134 //=================================================================================
135 // function : ConstructorsClicked()
136 // purpose : Radio button management
137 //=================================================================================
138 void OperationGUI_PartitionDlg::ConstructorsClicked(int constructorId)
140 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
143 myListShapes.length(0);
144 myListTools.length(0);
145 myListKeepInside.length(0);
146 myListRemoveInside.length(0);
147 myListMaterials.length(0);
149 switch (constructorId)
151 case 0: /*Full partition */
153 GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
154 GroupPoints->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
156 GroupPoints->TextLabel3->show();
157 GroupPoints->ComboBox1->show();
159 GroupPoints->ComboBox1->setCurrentItem(0);
162 case 1: /*Half-space partition */
165 GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION_HALFSPACE"));
166 GroupPoints->TextLabel3->hide();
167 GroupPoints->ComboBox1->hide();
168 GroupPoints->TextLabel2->setText(tr("GEOM_PLANE"));
174 myEditCurrentArgument = GroupPoints->LineEdit1;
175 GroupPoints->LineEdit1->clear();
176 GroupPoints->LineEdit2->clear();
178 myEditCurrentArgument->setFocus();
179 connect(myGeomGUI->getApp()->selectionMgr(),
180 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
181 MESSAGE(width()<<" "<<height());
185 //=================================================================================
186 // function : ClickOnOk()
188 //=================================================================================
189 void OperationGUI_PartitionDlg::ClickOnOk()
191 if ( ClickOnApply() )
196 //=================================================================================
197 // function : ClickOnApply()
199 //=================================================================================
200 bool OperationGUI_PartitionDlg::ClickOnApply()
206 ConstructorsClicked( getConstructorId() );
211 //=================================================================================
212 // function : SelectionIntoArgument()
213 // purpose : Called when selection as changed or other case
214 //=================================================================================
215 void OperationGUI_PartitionDlg::SelectionIntoArgument()
217 myEditCurrentArgument->setText( "" );
218 QString aString = "";
220 int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
224 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
226 myListShapes.length( 0 );
227 myListMaterials.length( 0 );
229 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
230 myListTools.length( 0 );
233 // One and only one plane can be selected
235 if ( getConstructorId() == 1 && myEditCurrentArgument == GroupPoints->LineEdit2 && nbSel != 1 )
237 myListTools.length( 0 );
241 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
243 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListShapes, true );
244 myListMaterials.length( 0 );
245 if ( !myListShapes.length() )
248 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
250 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListTools, true );
251 if ( !myListTools.length() )
255 myEditCurrentArgument->setText( aString );
259 //=================================================================================
260 // function : SetEditCurrentArgument()
262 //=================================================================================
263 void OperationGUI_PartitionDlg::SetEditCurrentArgument()
265 QPushButton* send = (QPushButton*)sender();
267 if(send == GroupPoints->PushButton1)
268 myEditCurrentArgument = GroupPoints->LineEdit1;
269 else if(send == GroupPoints->PushButton2)
271 myEditCurrentArgument = GroupPoints->LineEdit2;
272 if( getConstructorId()==1 )
273 globalSelection( GEOM_PLANE );
276 globalSelection( GEOM_ALLSHAPES );
278 myEditCurrentArgument->setFocus();
279 SelectionIntoArgument();
283 //=================================================================================
284 // function : LineEditReturnPressed()
286 //=================================================================================
287 void OperationGUI_PartitionDlg::LineEditReturnPressed()
289 QLineEdit* send = (QLineEdit*)sender();
291 if(send == GroupPoints->LineEdit1 ||
292 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* e)
320 if (!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& msg )
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 )) {
365 anObj = GEOM::GEOM_IBooleanOperations::_narrow(getOperation())->
366 MakePartition(myListShapes, myListTools,
367 myListKeepInside, myListRemoveInside,
368 aLimit, false, myListMaterials);
372 if (!anObj->_is_nil())
373 objects.push_back( anObj._retn() );
379 //=================================================================================
380 // function : closeEvent
382 //=================================================================================
383 void OperationGUI_PartitionDlg::closeEvent( QCloseEvent* e )
385 GEOMBase_Skeleton::closeEvent( e );
389 //=======================================================================
390 //function : ComboTextChanged
392 //=======================================================================
393 void OperationGUI_PartitionDlg::ComboTextChanged()
395 bool IsEnabled = GroupPoints->ComboBox1->currentItem() < 3;
396 //GroupPoints->LineEdit3->setEnabled(IsEnabled);
397 //GroupPoints->LineEdit4->setEnabled(IsEnabled);
398 //GroupPoints->TextLabel4->setEnabled(IsEnabled);
399 //GroupPoints->TextLabel5->setEnabled(IsEnabled);
400 //GroupPoints->PushButton3->setEnabled(IsEnabled);
401 //GroupPoints->PushButton4->setEnabled(IsEnabled);
405 //=================================================================================
406 // function : GetLimit()
408 //=================================================================================
409 int OperationGUI_PartitionDlg::GetLimit() const
411 int aLimit = GroupPoints->ComboBox1->currentItem();
415 case 0: aLimit = GEOM::SOLID ; break;
416 case 1: aLimit = GEOM::SHELL ; break;
417 case 2: aLimit = GEOM::FACE ; break;
418 case 3: aLimit = GEOM::WIRE ; break;
419 case 4: aLimit = GEOM::EDGE ; break;
420 case 5: aLimit = GEOM::VERTEX; break;
421 default: aLimit = GEOM::SHAPE ;