1 // Copyright (C) 2007-2008 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 : RepairGUI_RemoveIntWiresDlg.cxx
24 // Author : Lucien PIGNOLONI
28 #include "RepairGUI_RemoveIntWiresDlg.h"
30 #include "SalomeApp_Application.h"
31 #include "LightApp_SelectionMgr.h"
32 #include "SUIT_Session.h"
33 #include "SALOME_ListIteratorOfListIO.hxx"
35 #include "GEOMImpl_Types.hxx"
38 #include <TColStd_MapOfInteger.hxx>
42 //=================================================================================
43 // class : RepairGUI_RemoveIntWiresDlg()
44 // purpose : Constructs a RepairGUI_RemoveIntWiresDlg which is a child of 'parent', with the
45 // name 'name' and widget flags set to 'f'.
46 // The dialog will by default be modeless, unless you set 'modal' to
47 // TRUE to construct a modal dialog.
48 //=================================================================================
49 RepairGUI_RemoveIntWiresDlg::RepairGUI_RemoveIntWiresDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
50 const char* name, bool modal, WFlags fl)
51 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
52 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
54 QPixmap image0 (myGeomGUI->getApp()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SUPPRESS_INT_WIRES")));
55 QPixmap image1 (myGeomGUI->getApp()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
57 setCaption(tr("GEOM_REMOVE_INTERNAL_WIRES_TITLE"));
59 /***************************************************************/
60 GroupConstructors->setTitle(tr("GEOM_REMOVE_INTERNAL_WIRES_TITLE"));
61 RadioButton1->setPixmap(image0);
62 RadioButton2->close(TRUE);
63 RadioButton3->close(TRUE);
65 GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
66 GroupPoints->GroupBox1->setTitle(tr("GEOM_INTERNAL_WIRES"));
67 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_FACE"));
68 GroupPoints->PushButton1->setPixmap(image1);
69 GroupPoints->LineEdit1->setReadOnly( true );
71 Layout1->addWidget(GroupPoints, 2, 0);
73 myAllChk = new QCheckBox( tr( "GEOM_REMOVE_ALL_INT_WIRES" ), GroupPoints->GroupBox1 );
75 QGridLayout* aSelectWiresLay = new QGridLayout( 0, 1, 1, 0, 6, "aSelectWiresLay");
77 mySelectWiresBtn = new QPushButton( GroupPoints->GroupBox1, "mySelectWiresBtn" );
78 mySelectWiresBtn->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresBtn->sizePolicy().hasHeightForWidth() ) );
79 mySelectWiresBtn->setText( trUtf8( "" ) );
80 mySelectWiresBtn->setPixmap(image1);
82 mySelectWiresEdt = new QLineEdit( GroupPoints->GroupBox1, "mySelectWiresEdt" );
83 mySelectWiresEdt->setReadOnly( true );
85 mySelectWiresLbl = new QLabel( tr( "GEOM_WIRES_TO_REMOVE" ), GroupPoints->GroupBox1, "TextLabel1" );
86 mySelectWiresLbl->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresLbl->sizePolicy().hasHeightForWidth() ) );
88 aSelectWiresLay->addWidget( mySelectWiresLbl, 0, 0 );
89 aSelectWiresLay->addWidget( mySelectWiresBtn, 0, 1 );
90 aSelectWiresLay->addWidget( mySelectWiresEdt, 0, 2 );
91 QSpacerItem* spacer = new QSpacerItem( 0, 16, QSizePolicy::Minimum, QSizePolicy::Expanding );
92 aSelectWiresLay->addItem( spacer, 1, 2 );
94 GroupPoints->getGroupBoxLayout()->addMultiCellWidget( myAllChk, 1, 1, 0, 2 );
95 GroupPoints->getGroupBoxLayout()->addLayout( aSelectWiresLay, 2, 0 );
96 /***************************************************************/
98 setHelpFileName("suppress_internal_wires_operation_page.html");
104 //=================================================================================
105 // function : ~RepairGUI_RemoveIntWiresDlg()
106 // purpose : Destroys the object and frees any allocated resources
107 //=================================================================================
108 RepairGUI_RemoveIntWiresDlg::~RepairGUI_RemoveIntWiresDlg()
113 //=================================================================================
116 //=================================================================================
117 void RepairGUI_RemoveIntWiresDlg::Init()
120 myEditCurrentArgument = GroupPoints->LineEdit1;
122 myObject = GEOM::GEOM_Object::_nil();
123 myWiresInd = new GEOM::short_array();
124 myWiresInd->length( 0 );
126 //myGeomGUI->SetState( 0 );
129 /* signals and slots connections */
130 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
131 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
133 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
134 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
135 connect(mySelectWiresBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
136 connect(mySelectWiresEdt, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
138 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
139 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
141 connect( myAllChk, SIGNAL( clicked() ), this, SLOT( onRemoveAllClicked() ) );
143 initName( tr( "REMOVE_INT_WIRES_NEW_OBJ_NAME" ) );
147 //=================================================================================
148 // function : ClickOnOk()
149 // purpose : Same than click on apply but close this dialog.
150 //=================================================================================
151 void RepairGUI_RemoveIntWiresDlg::ClickOnOk()
153 if ( ClickOnApply() )
157 //=================================================================================
158 // function : ClickOnApply()
160 //=================================================================================
161 bool RepairGUI_RemoveIntWiresDlg::ClickOnApply()
168 myEditCurrentArgument = GroupPoints->LineEdit1;
169 myEditCurrentArgument->setText("");
170 mySelectWiresEdt->setText("");
171 myObject = GEOM::GEOM_Object::_nil();
172 myWiresInd->length( 0 );
180 //=================================================================================
181 // function : SelectionIntoArgument()
182 // purpose : Called when selection
183 //=================================================================================
184 void RepairGUI_RemoveIntWiresDlg::SelectionIntoArgument()
186 myEditCurrentArgument->setText("");
187 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myObject = GEOM::GEOM_Object::_nil();
188 else if ( myEditCurrentArgument == mySelectWiresEdt ) myWiresInd->length( 0 );
190 if ( IObjectCount() == 1 )
192 Handle(SALOME_InteractiveObject) anIO = firstIObject();
194 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) // face selection
196 Standard_Boolean aRes;
197 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
198 if ( aRes && GEOMBase::IsShape( myObject ) )
199 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
201 myObject = GEOM::GEOM_Object::_nil();
203 else if ( myEditCurrentArgument == mySelectWiresEdt && !myAllChk->isChecked() )
205 TColStd_IndexedMapOfInteger aMap;
206 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( anIO, aMap );
207 const int n = aMap.Extent();
208 myWiresInd->length( n );
209 for ( int i = 1; i <= n; i++ )
210 myWiresInd[i-1] = aMap( i );
212 myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
217 //=================================================================================
218 // function : SetEditCurrentArgument()
220 //=================================================================================
221 void RepairGUI_RemoveIntWiresDlg::SetEditCurrentArgument()
223 const QObject* send = sender();
224 if ( send == GroupPoints->PushButton1 )
225 myEditCurrentArgument = GroupPoints->LineEdit1;
226 else if ( send == mySelectWiresBtn && !myObject->_is_nil() )
227 myEditCurrentArgument = mySelectWiresEdt;
229 if ( myEditCurrentArgument )
232 myEditCurrentArgument->setFocus();
233 SelectionIntoArgument();
238 //=================================================================================
239 // function : LineEditReturnPressed()
241 //=================================================================================
242 void RepairGUI_RemoveIntWiresDlg::LineEditReturnPressed()
244 const QObject* send = sender();
245 if( send == GroupPoints->LineEdit1 || send == mySelectWiresEdt )
247 myEditCurrentArgument = (QLineEdit*)send;
248 GEOMBase_Skeleton::LineEditReturnPressed();
253 //=================================================================================
254 // function : ActivateThisDialog()
256 //=================================================================================
257 void RepairGUI_RemoveIntWiresDlg::ActivateThisDialog()
259 GEOMBase_Skeleton::ActivateThisDialog();
260 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
261 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
263 myEditCurrentArgument = GroupPoints->LineEdit1;
264 myEditCurrentArgument->setText("");
265 mySelectWiresEdt->setText("");
266 myObject = GEOM::GEOM_Object::_nil();
267 myWiresInd->length( 0 );
269 //myGeomGUI->SetState( 0 );
273 //=================================================================================
274 // function : enterEvent()
275 // purpose : Mouse enter onto the dialog to activate it
276 //=================================================================================
277 void RepairGUI_RemoveIntWiresDlg::enterEvent(QEvent* e)
279 if ( !GroupConstructors->isEnabled() )
280 ActivateThisDialog();
283 //=================================================================================
284 // function : closeEvent()
286 //=================================================================================
287 void RepairGUI_RemoveIntWiresDlg::closeEvent(QCloseEvent* e)
289 //myGeomGUI->SetState( -1 );
290 GEOMBase_Skeleton::closeEvent( e );
293 //=================================================================================
294 // function : createOperation
296 //=================================================================================
297 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveIntWiresDlg::createOperation()
299 return getGeomEngine()->GetIHealingOperations( getStudyId() );
302 //=================================================================================
303 // function : isValid
305 //=================================================================================
306 bool RepairGUI_RemoveIntWiresDlg::isValid( QString& msg )
308 return !myObject->_is_nil() && ( myAllChk->isChecked() || myWiresInd->length() );
311 //=================================================================================
312 // function : execute
314 //=================================================================================
315 bool RepairGUI_RemoveIntWiresDlg::execute( ObjectList& objects )
317 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->
318 RemoveIntWires( myObject, myWiresInd );
319 bool aResult = !anObj->_is_nil();
321 objects.push_back( anObj._retn() );
326 //=================================================================================
327 // function : onRemoveAllClicked
329 //=================================================================================
330 void RepairGUI_RemoveIntWiresDlg::onRemoveAllClicked()
332 bool b = myAllChk->isOn();
333 mySelectWiresLbl->setEnabled( !b );
334 mySelectWiresBtn->setEnabled( !b );
335 mySelectWiresEdt->setEnabled( !b );
338 mySelectWiresEdt->setText( "" );
339 myWiresInd->length( 0 );
343 //=================================================================================
344 // function : initSelection
346 //=================================================================================
347 void RepairGUI_RemoveIntWiresDlg::initSelection()
349 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
351 TColStd_MapOfInteger aTypes;
352 aTypes.Add( GEOM_COMPOUND );
353 aTypes.Add( GEOM_SOLID );
354 aTypes.Add( GEOM_SHELL );
355 aTypes.Add( GEOM_FACE );
357 globalSelection( aTypes );
359 else if ( myEditCurrentArgument == mySelectWiresEdt )
361 //localSelection( myObject, TopAbs_EDGE );
362 localSelection( myObject, TopAbs_WIRE );