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 : RepairGUI_RemoveIntWiresDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "RepairGUI_RemoveIntWiresDlg.h"
31 #include "SalomeApp_Application.h"
32 #include "LightApp_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(GeometryGUI* theGeometryGUI, QWidget* parent,
51 const char* name, bool modal, WFlags fl)
52 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
53 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 QPixmap image0 (myGeomGUI->getApp()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SUPPRESS_INT_WIRES")));
56 QPixmap image1 (myGeomGUI->getApp()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
58 setCaption(tr("GEOM_REMOVE_INTERNAL_WIRES_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_REMOVE_INTERNAL_WIRES_TITLE"));
62 RadioButton1->setPixmap(image0);
63 RadioButton2->close(TRUE);
64 RadioButton3->close(TRUE);
66 GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
67 GroupPoints->GroupBox1->setTitle(tr("GEOM_INTERNAL_WIRES"));
68 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_FACE"));
69 GroupPoints->PushButton1->setPixmap(image1);
70 GroupPoints->LineEdit1->setReadOnly( true );
72 Layout1->addWidget(GroupPoints, 2, 0);
74 myAllChk = new QCheckBox( tr( "GEOM_REMOVE_ALL_INT_WIRES" ), GroupPoints->GroupBox1 );
76 QGridLayout* aSelectWiresLay = new QGridLayout( 0, 1, 1, 0, 6, "aSelectWiresLay");
78 mySelectWiresBtn = new QPushButton( GroupPoints->GroupBox1, "mySelectWiresBtn" );
79 mySelectWiresBtn->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresBtn->sizePolicy().hasHeightForWidth() ) );
80 mySelectWiresBtn->setText( trUtf8( "" ) );
81 mySelectWiresBtn->setPixmap(image1);
83 mySelectWiresEdt = new QLineEdit( GroupPoints->GroupBox1, "mySelectWiresEdt" );
84 mySelectWiresEdt->setReadOnly( true );
86 mySelectWiresLbl = new QLabel( tr( "GEOM_WIRES_TO_REMOVE" ), GroupPoints->GroupBox1, "TextLabel1" );
87 mySelectWiresLbl->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresLbl->sizePolicy().hasHeightForWidth() ) );
89 aSelectWiresLay->addWidget( mySelectWiresLbl, 0, 0 );
90 aSelectWiresLay->addWidget( mySelectWiresBtn, 0, 1 );
91 aSelectWiresLay->addWidget( mySelectWiresEdt, 0, 2 );
92 QSpacerItem* spacer = new QSpacerItem( 0, 16, QSizePolicy::Minimum, QSizePolicy::Expanding );
93 aSelectWiresLay->addItem( spacer, 1, 2 );
95 GroupPoints->getGroupBoxLayout()->addMultiCellWidget( myAllChk, 1, 1, 0, 2 );
96 GroupPoints->getGroupBoxLayout()->addLayout( aSelectWiresLay, 2, 0 );
97 /***************************************************************/
99 setHelpFileName("suppress_internal_wires.htm");
105 //=================================================================================
106 // function : ~RepairGUI_RemoveIntWiresDlg()
107 // purpose : Destroys the object and frees any allocated resources
108 //=================================================================================
109 RepairGUI_RemoveIntWiresDlg::~RepairGUI_RemoveIntWiresDlg()
114 //=================================================================================
117 //=================================================================================
118 void RepairGUI_RemoveIntWiresDlg::Init()
121 myEditCurrentArgument = GroupPoints->LineEdit1;
123 myObject = GEOM::GEOM_Object::_nil();
124 myWiresInd = new GEOM::short_array();
125 myWiresInd->length( 0 );
127 //myGeomGUI->SetState( 0 );
130 /* signals and slots connections */
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() )
158 //=================================================================================
159 // function : ClickOnApply()
161 //=================================================================================
162 bool RepairGUI_RemoveIntWiresDlg::ClickOnApply()
169 myEditCurrentArgument = GroupPoints->LineEdit1;
170 myEditCurrentArgument->setText("");
171 mySelectWiresEdt->setText("");
172 myObject = GEOM::GEOM_Object::_nil();
173 myWiresInd->length( 0 );
181 //=================================================================================
182 // function : SelectionIntoArgument()
183 // purpose : Called when selection
184 //=================================================================================
185 void RepairGUI_RemoveIntWiresDlg::SelectionIntoArgument()
187 myEditCurrentArgument->setText("");
188 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myObject = GEOM::GEOM_Object::_nil();
189 else if ( myEditCurrentArgument == mySelectWiresEdt ) myWiresInd->length( 0 );
191 if ( IObjectCount() == 1 )
193 Handle(SALOME_InteractiveObject) anIO = firstIObject();
195 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) // face selection
197 Standard_Boolean aRes;
198 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
199 if ( aRes && GEOMBase::IsShape( myObject ) )
200 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
202 myObject = GEOM::GEOM_Object::_nil();
204 else if ( myEditCurrentArgument == mySelectWiresEdt && !myAllChk->isChecked() )
206 TColStd_IndexedMapOfInteger aMap;
207 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( anIO, aMap );
208 const int n = aMap.Extent();
209 myWiresInd->length( n );
210 for ( int i = 1; i <= n; i++ )
211 myWiresInd[i-1] = aMap( i );
213 myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
218 //=================================================================================
219 // function : SetEditCurrentArgument()
221 //=================================================================================
222 void RepairGUI_RemoveIntWiresDlg::SetEditCurrentArgument()
224 const QObject* send = sender();
225 if ( send == GroupPoints->PushButton1 )
226 myEditCurrentArgument = GroupPoints->LineEdit1;
227 else if ( send == mySelectWiresBtn && !myObject->_is_nil() )
228 myEditCurrentArgument = mySelectWiresEdt;
230 if ( myEditCurrentArgument )
233 myEditCurrentArgument->setFocus();
234 SelectionIntoArgument();
239 //=================================================================================
240 // function : LineEditReturnPressed()
242 //=================================================================================
243 void RepairGUI_RemoveIntWiresDlg::LineEditReturnPressed()
245 const QObject* send = sender();
246 if( send == GroupPoints->LineEdit1 || send == mySelectWiresEdt )
248 myEditCurrentArgument = (QLineEdit*)send;
249 GEOMBase_Skeleton::LineEditReturnPressed();
254 //=================================================================================
255 // function : ActivateThisDialog()
257 //=================================================================================
258 void RepairGUI_RemoveIntWiresDlg::ActivateThisDialog()
260 GEOMBase_Skeleton::ActivateThisDialog();
261 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
262 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
264 myEditCurrentArgument = GroupPoints->LineEdit1;
265 myEditCurrentArgument->setText("");
266 mySelectWiresEdt->setText("");
267 myObject = GEOM::GEOM_Object::_nil();
268 myWiresInd->length( 0 );
270 //myGeomGUI->SetState( 0 );
274 //=================================================================================
275 // function : enterEvent()
276 // purpose : Mouse enter onto the dialog to activate it
277 //=================================================================================
278 void RepairGUI_RemoveIntWiresDlg::enterEvent(QEvent* e)
280 if ( !GroupConstructors->isEnabled() )
281 ActivateThisDialog();
284 //=================================================================================
285 // function : closeEvent()
287 //=================================================================================
288 void RepairGUI_RemoveIntWiresDlg::closeEvent(QCloseEvent* e)
290 //myGeomGUI->SetState( -1 );
291 GEOMBase_Skeleton::closeEvent( e );
294 //=================================================================================
295 // function : createOperation
297 //=================================================================================
298 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveIntWiresDlg::createOperation()
300 return getGeomEngine()->GetIHealingOperations( getStudyId() );
303 //=================================================================================
304 // function : isValid
306 //=================================================================================
307 bool RepairGUI_RemoveIntWiresDlg::isValid( QString& msg )
309 return !myObject->_is_nil() && ( myAllChk->isChecked() || myWiresInd->length() );
312 //=================================================================================
313 // function : execute
315 //=================================================================================
316 bool RepairGUI_RemoveIntWiresDlg::execute( ObjectList& objects )
318 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->
319 RemoveIntWires( myObject, myWiresInd );
320 bool aResult = !anObj->_is_nil();
322 objects.push_back( anObj._retn() );
327 //=================================================================================
328 // function : onRemoveAllClicked
330 //=================================================================================
331 void RepairGUI_RemoveIntWiresDlg::onRemoveAllClicked()
333 bool b = myAllChk->isOn();
334 mySelectWiresLbl->setEnabled( !b );
335 mySelectWiresBtn->setEnabled( !b );
336 mySelectWiresEdt->setEnabled( !b );
339 mySelectWiresEdt->setText( "" );
340 myWiresInd->length( 0 );
344 //=================================================================================
345 // function : initSelection
347 //=================================================================================
348 void RepairGUI_RemoveIntWiresDlg::initSelection()
350 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
352 TColStd_MapOfInteger aTypes;
353 aTypes.Add( GEOM_COMPOUND );
354 aTypes.Add( GEOM_SOLID );
355 aTypes.Add( GEOM_SHELL );
356 aTypes.Add( GEOM_FACE );
358 globalSelection( aTypes );
360 else if ( myEditCurrentArgument == mySelectWiresEdt )
362 //localSelection( myObject, TopAbs_EDGE );
363 localSelection( myObject, TopAbs_WIRE );