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
30 #include "RepairGUI_RemoveIntWiresDlg.h"
32 #include "QAD_RightFrame.h"
33 #include "QAD_Desktop.h"
34 #include "OCCViewer_Viewer3d.h"
35 #include "SALOME_ListIteratorOfListIO.hxx"
37 #include "GEOMImpl_Types.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(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
50 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
52 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_SUPPRESS_INT_WIRES")));
53 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
55 setCaption(tr("GEOM_REMOVE_INTERNAL_WIRES_TITLE"));
57 /***************************************************************/
58 GroupConstructors->setTitle(tr("GEOM_REMOVE_INTERNAL_WIRES_TITLE"));
59 RadioButton1->setPixmap(image0);
60 RadioButton2->close(TRUE);
61 RadioButton3->close(TRUE);
63 GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
64 GroupPoints->GroupBox1->setTitle(tr("GEOM_INTERNAL_WIRES"));
65 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_FACE"));
66 GroupPoints->PushButton1->setPixmap(image1);
67 GroupPoints->LineEdit1->setReadOnly( true );
69 Layout1->addWidget(GroupPoints, 2, 0);
71 myAllChk = new QCheckBox( tr( "GEOM_REMOVE_ALL_INT_WIRES" ), GroupPoints->GroupBox1 );
73 QGridLayout* aSelectWiresLay = new QGridLayout( 0, 1, 1, 0, 6, "aSelectWiresLay");
75 mySelectWiresBtn = new QPushButton( GroupPoints->GroupBox1, "mySelectWiresBtn" );
76 mySelectWiresBtn->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresBtn->sizePolicy().hasHeightForWidth() ) );
77 mySelectWiresBtn->setText( trUtf8( "" ) );
78 mySelectWiresBtn->setPixmap(image1);
80 mySelectWiresEdt = new QLineEdit( GroupPoints->GroupBox1, "mySelectWiresEdt" );
81 mySelectWiresEdt->setReadOnly( true );
83 mySelectWiresLbl = new QLabel( tr( "GEOM_WIRES_TO_REMOVE" ), GroupPoints->GroupBox1, "TextLabel1" );
84 mySelectWiresLbl->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresLbl->sizePolicy().hasHeightForWidth() ) );
86 aSelectWiresLay->addWidget( mySelectWiresLbl, 0, 0 );
87 aSelectWiresLay->addWidget( mySelectWiresBtn, 0, 1 );
88 aSelectWiresLay->addWidget( mySelectWiresEdt, 0, 2 );
89 QSpacerItem* spacer = new QSpacerItem( 0, 16, QSizePolicy::Minimum, QSizePolicy::Expanding );
90 aSelectWiresLay->addItem( spacer, 1, 2 );
92 GroupPoints->getGroupBoxLayout()->addMultiCellWidget( myAllChk, 1, 1, 0, 2 );
93 GroupPoints->getGroupBoxLayout()->addLayout( aSelectWiresLay, 2, 0 );
94 /***************************************************************/
100 //=================================================================================
101 // function : ~RepairGUI_RemoveIntWiresDlg()
102 // purpose : Destroys the object and frees any allocated resources
103 //=================================================================================
104 RepairGUI_RemoveIntWiresDlg::~RepairGUI_RemoveIntWiresDlg()
109 //=================================================================================
112 //=================================================================================
113 void RepairGUI_RemoveIntWiresDlg::Init()
116 myEditCurrentArgument = GroupPoints->LineEdit1;
118 myObject = GEOM::GEOM_Object::_nil();
119 myWiresInd = new GEOM::short_array();
120 myWiresInd->length( 0 );
122 myGeomGUI->SetState( 0 );
125 /* signals and slots connections */
126 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
127 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
128 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
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(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
140 connect( myAllChk, SIGNAL( clicked() ), this, SLOT( onRemoveAllClicked() ) );
142 initName( tr( "REMOVE_INT_WIRES_NEW_OBJ_NAME" ) );
146 //=================================================================================
147 // function : ClickOnOk()
148 // purpose : Same than click on apply but close this dialog.
149 //=================================================================================
150 void RepairGUI_RemoveIntWiresDlg::ClickOnOk()
152 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 : ClickOnCancel()
184 //=================================================================================
185 void RepairGUI_RemoveIntWiresDlg::ClickOnCancel()
187 GEOMBase_Skeleton::ClickOnCancel();
191 //=================================================================================
192 // function : SelectionIntoArgument()
193 // purpose : Called when selection
194 //=================================================================================
195 void RepairGUI_RemoveIntWiresDlg::SelectionIntoArgument()
197 myEditCurrentArgument->setText("");
198 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myObject = GEOM::GEOM_Object::_nil();
199 else if ( myEditCurrentArgument == mySelectWiresEdt ) myWiresInd->length( 0 );
201 if ( mySelection->IObjectCount() == 1 )
203 Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
205 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) // face selection
207 Standard_Boolean aRes;
208 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
209 if ( aRes && GEOMBase::IsShape( myObject ) )
210 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
212 myObject = GEOM::GEOM_Object::_nil();
214 else if ( myEditCurrentArgument == mySelectWiresEdt && !myAllChk->isChecked() )
216 TColStd_IndexedMapOfInteger aMap;
217 mySelection->GetIndex( anIO, aMap );
218 const int n = aMap.Extent();
219 myWiresInd->length( n );
220 for ( int i = 1; i <= n; i++ )
221 myWiresInd[i-1] = aMap( i );
223 myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
228 //=================================================================================
229 // function : SetEditCurrentArgument()
231 //=================================================================================
232 void RepairGUI_RemoveIntWiresDlg::SetEditCurrentArgument()
234 const QObject* send = sender();
235 if ( send == GroupPoints->PushButton1 )
236 myEditCurrentArgument = GroupPoints->LineEdit1;
237 else if ( send == mySelectWiresBtn && !myObject->_is_nil() )
238 myEditCurrentArgument = mySelectWiresEdt;
240 if ( myEditCurrentArgument )
243 myEditCurrentArgument->setFocus();
244 SelectionIntoArgument();
249 //=================================================================================
250 // function : LineEditReturnPressed()
252 //=================================================================================
253 void RepairGUI_RemoveIntWiresDlg::LineEditReturnPressed()
255 const QObject* send = sender();
256 if( send == GroupPoints->LineEdit1 || send == mySelectWiresEdt )
258 myEditCurrentArgument = (QLineEdit*)send;
259 GEOMBase_Skeleton::LineEditReturnPressed();
264 //=================================================================================
265 // function : DeactivateActiveDialog()
267 //=================================================================================
268 void RepairGUI_RemoveIntWiresDlg::DeactivateActiveDialog()
270 myGeomGUI->SetState( -1 );
271 GEOMBase_Skeleton::DeactivateActiveDialog();
275 //=================================================================================
276 // function : ActivateThisDialog()
278 //=================================================================================
279 void RepairGUI_RemoveIntWiresDlg::ActivateThisDialog()
281 GEOMBase_Skeleton::ActivateThisDialog();
282 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
284 myEditCurrentArgument = GroupPoints->LineEdit1;
285 myEditCurrentArgument->setText("");
286 mySelectWiresEdt->setText("");
287 myObject = GEOM::GEOM_Object::_nil();
288 myWiresInd->length( 0 );
290 myGeomGUI->SetState( 0 );
295 //=================================================================================
296 // function : enterEvent()
297 // purpose : Mouse enter onto the dialog to activate it
298 //=================================================================================
299 void RepairGUI_RemoveIntWiresDlg::enterEvent(QEvent* e)
301 if ( !GroupConstructors->isEnabled() )
302 ActivateThisDialog();
306 //=================================================================================
307 // function : closeEvent()
309 //=================================================================================
310 void RepairGUI_RemoveIntWiresDlg::closeEvent(QCloseEvent* e)
312 myGeomGUI->SetState( -1 );
313 GEOMBase_Skeleton::closeEvent( e );
316 //=================================================================================
317 // function : createOperation
319 //=================================================================================
320 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveIntWiresDlg::createOperation()
322 return getGeomEngine()->GetIHealingOperations( getStudyId() );
325 //=================================================================================
326 // function : isValid
328 //=================================================================================
329 bool RepairGUI_RemoveIntWiresDlg::isValid( QString& msg )
331 return !myObject->_is_nil() && ( myAllChk->isChecked() || myWiresInd->length() );
334 //=================================================================================
335 // function : execute
337 //=================================================================================
338 bool RepairGUI_RemoveIntWiresDlg::execute( ObjectList& objects )
340 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->RemoveIntWires( myObject, myWiresInd );
341 bool aResult = !anObj->_is_nil();
343 objects.push_back( anObj._retn() );
348 //=================================================================================
349 // function : onRemoveAllClicked
351 //=================================================================================
352 void RepairGUI_RemoveIntWiresDlg::onRemoveAllClicked()
354 bool b = myAllChk->isOn();
355 mySelectWiresLbl->setEnabled( !b );
356 mySelectWiresBtn->setEnabled( !b );
357 mySelectWiresEdt->setEnabled( !b );
360 mySelectWiresEdt->setText( "" );
361 myWiresInd->length( 0 );
365 //=================================================================================
366 // function : initSelection
368 //=================================================================================
369 void RepairGUI_RemoveIntWiresDlg::initSelection()
371 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
373 TColStd_MapOfInteger aTypes;
374 aTypes.Add( GEOM_COMPOUND );
375 aTypes.Add( GEOM_SOLID );
376 aTypes.Add( GEOM_SHELL );
377 aTypes.Add( GEOM_FACE );
379 globalSelection( aTypes );
381 else if ( myEditCurrentArgument == mySelectWiresEdt )
383 //localSelection( myObject, TopAbs_EDGE );
384 localSelection( myObject, TopAbs_WIRE );