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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : RepairGUI_RemoveIntWiresDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "RepairGUI_RemoveIntWiresDlg.h"
31 #include "SalomeApp_Application.h"
32 #include "SalomeApp_SelectionMgr.h"
33 #include "SUIT_Session.h"
34 #include "SALOME_ListIteratorOfListIO.hxx"
36 #include "GEOMImpl_Types.hxx"
39 #include <TColStd_MapOfInteger.hxx>
43 //=================================================================================
44 // class : RepairGUI_RemoveIntWiresDlg()
45 // purpose : Constructs a RepairGUI_RemoveIntWiresDlg which is a child of 'parent', with the
46 // name 'name' and widget flags set to 'f'.
47 // The dialog will by default be modeless, unless you set 'modal' to
48 // TRUE to construct a modal dialog.
49 //=================================================================================
50 RepairGUI_RemoveIntWiresDlg::RepairGUI_RemoveIntWiresDlg(QWidget* parent, const char* name, bool modal, WFlags fl)
51 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
53 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SUPPRESS_INT_WIRES")));
54 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
56 setCaption(tr("GEOM_REMOVE_INTERNAL_WIRES_TITLE"));
58 /***************************************************************/
59 GroupConstructors->setTitle(tr("GEOM_REMOVE_INTERNAL_WIRES_TITLE"));
60 RadioButton1->setPixmap(image0);
61 RadioButton2->close(TRUE);
62 RadioButton3->close(TRUE);
64 GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
65 GroupPoints->GroupBox1->setTitle(tr("GEOM_INTERNAL_WIRES"));
66 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_FACE"));
67 GroupPoints->PushButton1->setPixmap(image1);
68 GroupPoints->LineEdit1->setReadOnly( true );
70 Layout1->addWidget(GroupPoints, 2, 0);
72 myAllChk = new QCheckBox( tr( "GEOM_REMOVE_ALL_INT_WIRES" ), GroupPoints->GroupBox1 );
74 QGridLayout* aSelectWiresLay = new QGridLayout( 0, 1, 1, 0, 6, "aSelectWiresLay");
76 mySelectWiresBtn = new QPushButton( GroupPoints->GroupBox1, "mySelectWiresBtn" );
77 mySelectWiresBtn->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresBtn->sizePolicy().hasHeightForWidth() ) );
78 mySelectWiresBtn->setText( trUtf8( "" ) );
79 mySelectWiresBtn->setPixmap(image1);
81 mySelectWiresEdt = new QLineEdit( GroupPoints->GroupBox1, "mySelectWiresEdt" );
82 mySelectWiresEdt->setReadOnly( true );
84 mySelectWiresLbl = new QLabel( tr( "GEOM_WIRES_TO_REMOVE" ), GroupPoints->GroupBox1, "TextLabel1" );
85 mySelectWiresLbl->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresLbl->sizePolicy().hasHeightForWidth() ) );
87 aSelectWiresLay->addWidget( mySelectWiresLbl, 0, 0 );
88 aSelectWiresLay->addWidget( mySelectWiresBtn, 0, 1 );
89 aSelectWiresLay->addWidget( mySelectWiresEdt, 0, 2 );
90 QSpacerItem* spacer = new QSpacerItem( 0, 16, QSizePolicy::Minimum, QSizePolicy::Expanding );
91 aSelectWiresLay->addItem( spacer, 1, 2 );
93 GroupPoints->getGroupBoxLayout()->addMultiCellWidget( myAllChk, 1, 1, 0, 2 );
94 GroupPoints->getGroupBoxLayout()->addLayout( aSelectWiresLay, 2, 0 );
95 /***************************************************************/
101 //=================================================================================
102 // function : ~RepairGUI_RemoveIntWiresDlg()
103 // purpose : Destroys the object and frees any allocated resources
104 //=================================================================================
105 RepairGUI_RemoveIntWiresDlg::~RepairGUI_RemoveIntWiresDlg()
110 //=================================================================================
113 //=================================================================================
114 void RepairGUI_RemoveIntWiresDlg::Init()
117 myEditCurrentArgument = GroupPoints->LineEdit1;
119 myObject = GEOM::GEOM_Object::_nil();
120 myWiresInd = new GEOM::short_array();
121 myWiresInd->length( 0 );
123 //myGeomGUI->SetState( 0 );
126 /* signals and slots connections */
127 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
128 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
129 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
131 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
132 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
134 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
136 connect(mySelectWiresBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
137 connect(mySelectWiresEdt, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
139 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
140 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
142 connect( myAllChk, SIGNAL( clicked() ), this, SLOT( onRemoveAllClicked() ) );
144 initName( tr( "REMOVE_INT_WIRES_NEW_OBJ_NAME" ) );
148 //=================================================================================
149 // function : ClickOnOk()
150 // purpose : Same than click on apply but close this dialog.
151 //=================================================================================
152 void RepairGUI_RemoveIntWiresDlg::ClickOnOk()
154 if ( ClickOnApply() )
160 //=================================================================================
161 // function : ClickOnApply()
163 //=================================================================================
164 bool RepairGUI_RemoveIntWiresDlg::ClickOnApply()
171 myEditCurrentArgument = GroupPoints->LineEdit1;
172 myEditCurrentArgument->setText("");
173 mySelectWiresEdt->setText("");
174 myObject = GEOM::GEOM_Object::_nil();
175 myWiresInd->length( 0 );
183 //=================================================================================
184 // function : ClickOnCancel()
186 //=================================================================================
187 void RepairGUI_RemoveIntWiresDlg::ClickOnCancel()
189 GEOMBase_Skeleton::ClickOnCancel();
193 //=================================================================================
194 // function : SelectionIntoArgument()
195 // purpose : Called when selection
196 //=================================================================================
197 void RepairGUI_RemoveIntWiresDlg::SelectionIntoArgument()
199 myEditCurrentArgument->setText("");
200 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myObject = GEOM::GEOM_Object::_nil();
201 else if ( myEditCurrentArgument == mySelectWiresEdt ) myWiresInd->length( 0 );
203 if ( IObjectCount() == 1 )
205 Handle(SALOME_InteractiveObject) anIO = firstIObject();
207 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) // face selection
209 Standard_Boolean aRes;
210 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
211 if ( aRes && GEOMBase::IsShape( myObject ) )
212 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
214 myObject = GEOM::GEOM_Object::_nil();
216 else if ( myEditCurrentArgument == mySelectWiresEdt && !myAllChk->isChecked() )
218 TColStd_IndexedMapOfInteger aMap;
219 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( anIO, aMap );
220 const int n = aMap.Extent();
221 myWiresInd->length( n );
222 for ( int i = 1; i <= n; i++ )
223 myWiresInd[i-1] = aMap( i );
225 myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
230 //=================================================================================
231 // function : SetEditCurrentArgument()
233 //=================================================================================
234 void RepairGUI_RemoveIntWiresDlg::SetEditCurrentArgument()
236 const QObject* send = sender();
237 if ( send == GroupPoints->PushButton1 )
238 myEditCurrentArgument = GroupPoints->LineEdit1;
239 else if ( send == mySelectWiresBtn && !myObject->_is_nil() )
240 myEditCurrentArgument = mySelectWiresEdt;
242 if ( myEditCurrentArgument )
245 myEditCurrentArgument->setFocus();
246 SelectionIntoArgument();
251 //=================================================================================
252 // function : LineEditReturnPressed()
254 //=================================================================================
255 void RepairGUI_RemoveIntWiresDlg::LineEditReturnPressed()
257 const QObject* send = sender();
258 if( send == GroupPoints->LineEdit1 || send == mySelectWiresEdt )
260 myEditCurrentArgument = (QLineEdit*)send;
261 GEOMBase_Skeleton::LineEditReturnPressed();
266 //=================================================================================
267 // function : DeactivateActiveDialog()
269 //=================================================================================
270 void RepairGUI_RemoveIntWiresDlg::DeactivateActiveDialog()
272 //myGeomGUI->SetState( -1 );
273 GEOMBase_Skeleton::DeactivateActiveDialog();
277 //=================================================================================
278 // function : ActivateThisDialog()
280 //=================================================================================
281 void RepairGUI_RemoveIntWiresDlg::ActivateThisDialog()
283 GEOMBase_Skeleton::ActivateThisDialog();
284 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
285 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
287 myEditCurrentArgument = GroupPoints->LineEdit1;
288 myEditCurrentArgument->setText("");
289 mySelectWiresEdt->setText("");
290 myObject = GEOM::GEOM_Object::_nil();
291 myWiresInd->length( 0 );
293 //myGeomGUI->SetState( 0 );
298 //=================================================================================
299 // function : enterEvent()
300 // purpose : Mouse enter onto the dialog to activate it
301 //=================================================================================
302 void RepairGUI_RemoveIntWiresDlg::enterEvent(QEvent* e)
304 if ( !GroupConstructors->isEnabled() )
305 ActivateThisDialog();
309 //=================================================================================
310 // function : closeEvent()
312 //=================================================================================
313 void RepairGUI_RemoveIntWiresDlg::closeEvent(QCloseEvent* e)
315 //myGeomGUI->SetState( -1 );
316 GEOMBase_Skeleton::closeEvent( e );
319 //=================================================================================
320 // function : createOperation
322 //=================================================================================
323 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveIntWiresDlg::createOperation()
325 return getGeomEngine()->GetIHealingOperations( getStudyId() );
328 //=================================================================================
329 // function : isValid
331 //=================================================================================
332 bool RepairGUI_RemoveIntWiresDlg::isValid( QString& msg )
334 return !myObject->_is_nil() && ( myAllChk->isChecked() || myWiresInd->length() );
337 //=================================================================================
338 // function : execute
340 //=================================================================================
341 bool RepairGUI_RemoveIntWiresDlg::execute( ObjectList& objects )
343 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->RemoveIntWires( myObject, myWiresInd );
344 bool aResult = !anObj->_is_nil();
346 objects.push_back( anObj._retn() );
351 //=================================================================================
352 // function : onRemoveAllClicked
354 //=================================================================================
355 void RepairGUI_RemoveIntWiresDlg::onRemoveAllClicked()
357 bool b = myAllChk->isOn();
358 mySelectWiresLbl->setEnabled( !b );
359 mySelectWiresBtn->setEnabled( !b );
360 mySelectWiresEdt->setEnabled( !b );
363 mySelectWiresEdt->setText( "" );
364 myWiresInd->length( 0 );
368 //=================================================================================
369 // function : initSelection
371 //=================================================================================
372 void RepairGUI_RemoveIntWiresDlg::initSelection()
374 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
376 TColStd_MapOfInteger aTypes;
377 aTypes.Add( GEOM_COMPOUND );
378 aTypes.Add( GEOM_SOLID );
379 aTypes.Add( GEOM_SHELL );
380 aTypes.Add( GEOM_FACE );
382 globalSelection( aTypes );
384 else if ( myEditCurrentArgument == mySelectWiresEdt )
386 //localSelection( myObject, TopAbs_EDGE );
387 localSelection( myObject, TopAbs_WIRE );