1 // Copyright (C) 2007-2011 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : OperationGUI_PartitionDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "OperationGUI_PartitionDlg.h"
29 #include <GeometryGUI.h>
32 #include <GEOMImpl_Types.hxx>
34 #include <SUIT_Desktop.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_ResourceMgr.h>
37 #include <SUIT_MessageBox.h>
38 #include <SalomeApp_Application.h>
39 #include <LightApp_SelectionMgr.h>
41 #include <TopoDS_Iterator.hxx>
42 #include <TopoDS_Shape.hxx>
44 //=================================================================================
45 // class : OperationGUI_PartitionDlg()
46 // purpose : Constructs a OperationGUI_PartitionDlg which is a child of 'parent', with the
47 // name 'name' and widget flags set to 'f'.
48 // The dialog will by default be modeless, unless you set 'modal' to
49 // TRUE to construct a modal dialog.
50 //=================================================================================
51 OperationGUI_PartitionDlg::OperationGUI_PartitionDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
52 : GEOMBase_Skeleton( theGeometryGUI, parent, false )
54 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
55 QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_PARTITION" ) ) );
56 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_PARTITION_PLANE" ) ) );
57 QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
59 setWindowTitle( tr( "GEOM_PARTITION_TITLE" ) );
61 /***************************************************************/
62 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PARTITION" ) );
63 mainFrame()->RadioButton1->setIcon( image0 );
64 mainFrame()->RadioButton2->setIcon( image1 );
65 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
66 mainFrame()->RadioButton3->close();
68 // Full partition (contains half-space partition)
69 GroupPoints = new DlgRef_2Sel1List2Check( centralWidget() );
70 GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION" ) );
71 GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
72 GroupPoints->TextLabel2->setText( tr( "GEOM_TOOL_OBJECTS" ) );
73 GroupPoints->TextLabel3->setText( tr( "GEOM_RECONSTRUCTION_LIMIT" ) );
74 GroupPoints->PushButton1->setIcon( image2 );
75 GroupPoints->PushButton2->setIcon( image2 );
76 GroupPoints->LineEdit1->setReadOnly( true );
77 GroupPoints->LineEdit2->setReadOnly( true );
78 GroupPoints->LineEdit1->setEnabled( true );
79 GroupPoints->LineEdit2->setEnabled( false );
80 GroupPoints->CheckButton1->setText( tr( "GEOM_KEEP_NONLIMIT_SHAPES" ) );
81 GroupPoints->CheckButton2->setText( tr( "GEOM_NO_SELF_INTERSECTION" ) );
83 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
84 layout->setMargin( 0 ); layout->setSpacing( 6 );
85 layout->addWidget( GroupPoints );
87 /***************************************************************/
89 setHelpFileName( "partition_page.html" );
95 //=================================================================================
96 // function : ~OperationGUI_PartitionDlg()
97 // purpose : Destroys the object and frees any allocated resources
98 //=================================================================================
99 OperationGUI_PartitionDlg::~OperationGUI_PartitionDlg()
101 // no need to delete child widgets, Qt does it all for us
104 void OperationGUI_PartitionDlg::SetListMaterials( GEOM::ListOfLong ListMaterials )
106 myListMaterials = ListMaterials;
109 GEOM::ListOfLong OperationGUI_PartitionDlg::GetListMaterials()
111 return myListMaterials;
114 //=================================================================================
117 //=================================================================================
118 void OperationGUI_PartitionDlg::Init()
120 /* type for sub-shape selection */
121 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_SOLID" ) );
122 GroupPoints->ComboBox1->setItemData(GroupPoints->ComboBox1->count()-1, GEOM::SOLID);
123 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_SHELL" ) );
124 GroupPoints->ComboBox1->setItemData(GroupPoints->ComboBox1->count()-1, GEOM::SHELL);
125 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_FACE" ) );
126 GroupPoints->ComboBox1->setItemData(GroupPoints->ComboBox1->count()-1, GEOM::FACE);
127 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_WIRE" ) );
128 GroupPoints->ComboBox1->setItemData(GroupPoints->ComboBox1->count()-1, GEOM::WIRE);
129 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_EDGE" ) );
130 GroupPoints->ComboBox1->setItemData(GroupPoints->ComboBox1->count()-1, GEOM::EDGE);
131 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_VERTEX" ) );
132 GroupPoints->ComboBox1->setItemData(GroupPoints->ComboBox1->count()-1, GEOM::VERTEX);
133 GroupPoints->CheckButton1->setChecked( false );
135 mainFrame()->GroupBoxPublish->show();
137 /* signals and slots connections */
138 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
139 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
141 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
143 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
144 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
146 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
147 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
149 connect( GroupPoints->ComboBox1, SIGNAL( activated( int ) ), this, SLOT( ComboTextChanged() ) );
151 connect( myGeomGUI->getApp()->selectionMgr(),
152 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
154 connect( GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(processPreview()) );
155 connect( GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(processPreview()) );
157 initName( tr( "GEOM_PARTITION" ) );
159 ConstructorsClicked( 0 );
160 GroupPoints->PushButton1->click();
164 //=================================================================================
165 // function : ConstructorsClicked()
166 // purpose : Radio button management
167 //=================================================================================
168 void OperationGUI_PartitionDlg::ConstructorsClicked( int constructorId )
170 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
173 //myListShapes.length( 0 );
174 //myListTools.length( 0 );
175 //myListKeepInside.length( 0 ); // obsolete
176 //myListRemoveInside.length( 0 ); // obsolete
177 //myListMaterials.length( 0 ); // obsolete
179 switch ( constructorId ) {
180 case 0: /*Full partition */
181 GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION" ) );
182 GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
183 GroupPoints->TextLabel2->setText( tr( "GEOM_TOOL_OBJECTS" ) );
184 GroupPoints->TextLabel3->show();
185 GroupPoints->ComboBox1->show();
186 GroupPoints->ComboBox1->setCurrentIndex( 0 );
187 GroupPoints->CheckButton1->show();
188 GroupPoints->CheckButton2->show();
189 GroupPoints->PushButton1->setDown( true );
190 GroupPoints->PushButton2->setDown( false );
191 GroupPoints->LineEdit1->setEnabled(true);
192 GroupPoints->LineEdit2->setEnabled(false);
194 case 1: /*Half-space partition */
195 GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION_HALFSPACE" ) );
196 GroupPoints->TextLabel3->hide();
197 GroupPoints->ComboBox1->hide();
198 GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
199 GroupPoints->TextLabel2->setText( tr( "GEOM_PLANE" ) );
200 GroupPoints->CheckButton1->hide();
201 GroupPoints->CheckButton2->hide();
202 GroupPoints->PushButton1->setDown( true );
203 GroupPoints->LineEdit1->setEnabled(true);
207 myEditCurrentArgument = GroupPoints->LineEdit1;
208 GroupPoints->LineEdit1->clear();
209 GroupPoints->LineEdit2->clear();
211 qApp->processEvents();
213 resize( minimumSizeHint() );
215 myEditCurrentArgument->setFocus();
216 connect( myGeomGUI->getApp()->selectionMgr(),
217 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
218 SelectionIntoArgument();
222 //=================================================================================
223 // function : ClickOnOk()
225 //=================================================================================
226 void OperationGUI_PartitionDlg::ClickOnOk()
228 setIsApplyAndClose( true );
229 if ( ClickOnApply() )
234 //=================================================================================
235 // function : ClickOnApply()
237 //=================================================================================
238 bool OperationGUI_PartitionDlg::ClickOnApply()
244 // 0020854: EDF 1398 GEOM: Ergonomy of Partition GUI window
245 // ConstructorsClicked( getConstructorId() );
250 //=================================================================================
251 // function : SelectionIntoArgument()
252 // purpose : Called when selection as changed or other case
253 //=================================================================================
254 void OperationGUI_PartitionDlg::SelectionIntoArgument()
256 myEditCurrentArgument->setText( "" );
257 QString aString = "";
259 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
260 SALOME_ListIO aSelList;
261 aSelMgr->selectedObjects(aSelList);
263 int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true);
265 if ( getConstructorId() == 1 ) {
266 // for half-selection, only one shape can be selected as an object
267 // and only one plane as a tool
269 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
270 myListShapes.length( 0 );
271 // myListMaterials.length( 0 ); // obsolete
274 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
275 myListTools.length( 0 );
282 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
283 myListShapes.length( 0 );
284 //myListMaterials.length( 0 ); // obsolete
287 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
288 myListTools.length( 0 );
294 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
295 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListShapes, true);
296 //myListMaterials.length( 0 ); // obsolete
298 GEOM::shape_type type = GEOM::SHAPE;
299 for (int i = 0; i < myListShapes.length(); i++)
300 type = qMin( type, myListShapes[i]->GetMaxShapeType() );
301 int idx = qMax( 0, GroupPoints->ComboBox1->findData( type ) );
302 GroupPoints->ComboBox1->setCurrentIndex( idx );
304 if ( !myListShapes.length() )
307 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
308 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListTools, true);
309 if ( !myListTools.length() )
311 else if ( myListTools.length() == 1 && getConstructorId() == 1 ) {
312 GEOM::GEOM_IMeasureOperations_var mOp = getGeomEngine()->GetIMeasureOperations( getStudyId() );
313 GEOM::ListOfLong_var intList;
314 GEOM::ListOfDouble_var dblList;
315 GEOM::GEOM_IKindOfShape::shape_kind kind = mOp->KindOfShape( myListTools[0].in(), intList.out(), dblList.out() );
317 if ( kind < GEOM::GEOM_IKindOfShape::DISK_CIRCLE || kind > GEOM::GEOM_IKindOfShape::PLANAR ) {
318 myListTools.length( 0 );
324 myEditCurrentArgument->setText( aString );
329 //=================================================================================
330 // function : SetEditCurrentArgument()
332 //=================================================================================
333 void OperationGUI_PartitionDlg::SetEditCurrentArgument()
335 QPushButton* send = (QPushButton*)sender();
337 if ( send == GroupPoints->PushButton1 ) {
338 myEditCurrentArgument = GroupPoints->LineEdit1;
339 GroupPoints->PushButton2->setDown(false);
340 GroupPoints->LineEdit1->setEnabled(true);
341 GroupPoints->LineEdit2->setEnabled(false);
343 else if ( send == GroupPoints->PushButton2 ) {
344 myGeomGUI->getApp()->selectionMgr()->clearSelected(); //clear prewious selection
345 myEditCurrentArgument = GroupPoints->LineEdit2;
346 GroupPoints->PushButton1->setDown(false);
347 GroupPoints->LineEdit1->setEnabled(false);
348 GroupPoints->LineEdit2->setEnabled(true);
349 if ( getConstructorId() == 1 )
350 globalSelection( GEOM_PLANE );
353 globalSelection( GEOM_ALLSHAPES );
355 myEditCurrentArgument->setFocus();
356 SelectionIntoArgument();
362 //=================================================================================
363 // function : LineEditReturnPressed()
365 //=================================================================================
366 void OperationGUI_PartitionDlg::LineEditReturnPressed()
368 QLineEdit* send = (QLineEdit*)sender();
370 if ( send == GroupPoints->LineEdit1 ||
371 send == GroupPoints->LineEdit2 ) {
372 myEditCurrentArgument = send;
373 GEOMBase_Skeleton::LineEditReturnPressed();
378 //=================================================================================
379 // function : ActivateThisDialog()
381 //=================================================================================
382 void OperationGUI_PartitionDlg::ActivateThisDialog()
384 GEOMBase_Skeleton::ActivateThisDialog();
385 connect( myGeomGUI->getApp()->selectionMgr(),
386 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
388 ConstructorsClicked( getConstructorId() );
393 //=================================================================================
394 // function : enterEvent()
396 //=================================================================================
397 void OperationGUI_PartitionDlg::enterEvent( QEvent* )
399 if ( !mainFrame()->GroupConstructors->isEnabled() )
400 this->ActivateThisDialog();
404 //=================================================================================
405 // function : createOperation
407 //=================================================================================
408 GEOM::GEOM_IOperations_ptr OperationGUI_PartitionDlg::createOperation()
410 return getGeomEngine()->GetIBooleanOperations( getStudyId() );
414 //=================================================================================
415 // function : isValid
417 //=================================================================================
418 bool OperationGUI_PartitionDlg::isValid (QString& )
420 return (getConstructorId() == 0 ?
421 myListShapes.length() :
422 myListShapes.length() && myListTools.length());
426 //=================================================================================
427 // function : execute
429 //=================================================================================
430 bool OperationGUI_PartitionDlg::execute (ObjectList& objects)
433 GEOM::GEOM_Object_var anObj;
435 GEOM::GEOM_IBooleanOperations_var anOper = GEOM::GEOM_IBooleanOperations::_narrow(getOperation());
437 switch ( getConstructorId() ) {
440 int aLimit = GetLimit();
441 int aKeepNonlimitShapes = GroupPoints->CheckButton1->isChecked();
442 bool aNoSelfIntersection = GroupPoints->CheckButton2->isChecked();
444 anObj = aNoSelfIntersection ?
445 anOper->MakePartitionNonSelfIntersectedShape(myListShapes, myListTools,
446 myListKeepInside, myListRemoveInside,
447 aLimit, false, myListMaterials, aKeepNonlimitShapes) :
448 anOper->MakePartition(myListShapes, myListTools,
449 myListKeepInside, myListRemoveInside,
450 aLimit, false, myListMaterials, aKeepNonlimitShapes);
456 anObj = anOper->MakeHalfPartition( myListShapes[0].in(), myListTools[0].in() );
462 if ( !anObj->_is_nil() ) {
464 GEOMBase::GetShape( anObj, aShape, TopAbs_SHAPE );
465 TopoDS_Iterator It( aShape, Standard_True, Standard_True );
467 for (; It.More(); It.Next())
471 objects.push_back( anObj._retn() );
473 SUIT_MessageBox::warning( this,
474 QObject::tr( "GEOM_ERROR" ),
475 QObject::tr( "GEOM_WRN_PARTITION_RESULT_EMPTY" ) );
481 //=================================================================================
482 // function : restoreSubShapes
484 //=================================================================================
485 void OperationGUI_PartitionDlg::restoreSubShapes( SALOMEDS::Study_ptr theStudy,
486 SALOMEDS::SObject_ptr theSObject )
488 if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
489 // empty list of arguments means that all arguments should be restored
490 getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
491 /*theFindMethod=*/GEOM::FSM_GetInPlaceByHistory,
492 /*theInheritFirstArg=*/myListShapes.length() == 1,
493 mainFrame()->CheckBoxAddPrefix->isChecked() ); // ? false
497 //=======================================================================
498 //function : ComboTextChanged
500 //=======================================================================
501 void OperationGUI_PartitionDlg::ComboTextChanged()
503 //bool IsEnabled = GroupPoints->ComboBox1->currentItem() < 3;
504 //GroupPoints->LineEdit3->setEnabled(IsEnabled);
505 //GroupPoints->LineEdit4->setEnabled(IsEnabled);
506 //GroupPoints->TextLabel4->setEnabled(IsEnabled);
507 //GroupPoints->TextLabel5->setEnabled(IsEnabled);
508 //GroupPoints->PushButton3->setEnabled(IsEnabled);
509 //GroupPoints->PushButton4->setEnabled(IsEnabled);
513 //=================================================================================
514 // function : GetLimit()
516 //=================================================================================
517 int OperationGUI_PartitionDlg::GetLimit() const
519 int aLimit = GroupPoints->ComboBox1->currentIndex();
522 case 0: aLimit = GEOM::SOLID ; break;
523 case 1: aLimit = GEOM::SHELL ; break;
524 case 2: aLimit = GEOM::FACE ; break;
525 case 3: aLimit = GEOM::WIRE ; break;
526 case 4: aLimit = GEOM::EDGE ; break;
527 case 5: aLimit = GEOM::VERTEX; break;
528 default: aLimit = GEOM::SHAPE ;