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_CloseContourDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "RepairGUI_CloseContourDlg.h"
32 #include "SalomeApp_Application.h"
33 #include "SalomeApp_SelectionMgr.h"
34 #include "SUIT_Session.h"
35 #include "SALOME_ListIteratorOfListIO.hxx"
37 #include "GEOMImpl_Types.hxx"
40 #include <TColStd_IndexedMapOfInteger.hxx>
41 #include <TColStd_MapOfInteger.hxx>
45 //=================================================================================
46 // class : RepairGUI_CloseContourDlg()
47 // purpose : Constructs a RepairGUI_CloseContourDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 RepairGUI_CloseContourDlg::RepairGUI_CloseContourDlg(QWidget* parent, const char* name, bool modal, WFlags fl)
53 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CLOSECONTOUR")));
56 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
58 setCaption(tr("GEOM_CLOSECONTOUR_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_CLOSECONTOUR_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("Contour to close"));
68 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
69 GroupPoints->PushButton1->setPixmap(image1);
70 GroupPoints->LineEdit1->setReadOnly( true );
72 QGridLayout* aSelectWiresLay = new QGridLayout( 0, 1, 1, 0, 6, "aSelectWiresLay");
74 mySelectWiresBtn = new QPushButton( GroupPoints->GroupBox1, "mySelectWiresBtn" );
75 mySelectWiresBtn->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresBtn->sizePolicy().hasHeightForWidth() ) );
76 mySelectWiresBtn->setText( trUtf8( "" ) );
77 mySelectWiresBtn->setPixmap(image1);
79 mySelectWiresEdt = new QLineEdit( GroupPoints->GroupBox1, "mySelectWiresEdt" );
80 mySelectWiresEdt->setReadOnly( true );
82 mySelectWiresLbl = new QLabel( tr( "Contour to close" ), GroupPoints->GroupBox1, "ContourLbl" );
83 mySelectWiresLbl->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresLbl->sizePolicy().hasHeightForWidth() ) );
85 aSelectWiresLay->addWidget( mySelectWiresLbl, 0, 0 );
86 aSelectWiresLay->addWidget( mySelectWiresBtn, 0, 1 );
87 aSelectWiresLay->addWidget( mySelectWiresEdt, 0, 2 );
88 QSpacerItem* spacer = new QSpacerItem( 0, 16, QSizePolicy::Minimum, QSizePolicy::Expanding );
89 aSelectWiresLay->addItem( spacer, 1, 2 );
91 myIsVertexGr = new QButtonGroup( 2, Qt::Vertical, GroupPoints );
92 myIsVertexGr->setFrameStyle( QFrame::NoFrame );
93 myIsVertexGr->setRadioButtonExclusive( true );
94 myIsVertexGr->insert( new QRadioButton( tr( "Close by common vertex" ), myIsVertexGr ), 0 );
95 myIsVertexGr->insert( new QRadioButton( tr( "Close by new edge" ), myIsVertexGr ), 1 );
96 myIsVertexGr->find( 0 )->toggle();
98 Layout1->addWidget(GroupPoints, 2, 0);
99 GroupPoints->getGroupBoxLayout()->addLayout( aSelectWiresLay, 1, 0 );
100 GroupPoints->getGroupBoxLayout()->addMultiCellWidget(myIsVertexGr, 2, 2, 0, 2);
101 /***************************************************************/
107 //=================================================================================
108 // function : ~RepairGUI_CloseContourDlg()
109 // purpose : Destroys the object and frees any allocated resources
110 //=================================================================================
111 RepairGUI_CloseContourDlg::~RepairGUI_CloseContourDlg()
116 //=================================================================================
119 //=================================================================================
120 void RepairGUI_CloseContourDlg::Init()
123 myEditCurrentArgument = GroupPoints->LineEdit1;
125 myObject = GEOM::GEOM_Object::_nil();
126 myWiresInd = new GEOM::short_array();
127 myWiresInd->length( 0 );
129 //myGeomGUI->SetState( 0 );
132 /* signals and slots connections */
133 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
134 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
135 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
137 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
138 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
140 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
142 connect(mySelectWiresBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
143 connect(mySelectWiresEdt, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
145 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
146 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
148 initName( tr( "CLOSE_CONTOUR_NEW_OBJ_NAME" ) );
152 //=================================================================================
153 // function : ClickOnOk()
154 // purpose : Same than click on apply but close this dialog.
155 //=================================================================================
156 void RepairGUI_CloseContourDlg::ClickOnOk()
158 if ( ClickOnApply() )
164 //=================================================================================
165 // function : ClickOnApply()
167 //=================================================================================
168 bool RepairGUI_CloseContourDlg::ClickOnApply()
175 myEditCurrentArgument = GroupPoints->LineEdit1;
176 myEditCurrentArgument->setText("");
177 myObject = GEOM::GEOM_Object::_nil();
178 myWiresInd->length( 0 );
186 //=================================================================================
187 // function : ClickOnCancel()
189 //=================================================================================
190 void RepairGUI_CloseContourDlg::ClickOnCancel()
192 GEOMBase_Skeleton::ClickOnCancel();
195 //=================================================================================
196 // function : SelectionIntoArgument()
197 // purpose : Called when selection as changed or other case
198 // : used only by SelectButtonC1A1 (LineEditC1A1)
199 //=================================================================================
200 void RepairGUI_CloseContourDlg::SelectionIntoArgument()
203 myEditCurrentArgument->setText( "" );
204 mySelectWiresEdt->setText( "" );
206 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
207 myObject = GEOM::GEOM_Object::_nil();
208 else if ( myEditCurrentArgument == mySelectWiresEdt )
209 myWiresInd->length( 0 );
211 if ( IObjectCount() == 1 )
213 Handle(SALOME_InteractiveObject) anIO = firstIObject();
215 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) // face selection
217 Standard_Boolean aRes;
218 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
219 if ( aRes && GEOMBase::IsShape( myObject ) )
221 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
223 if ( myGeomBase->GetShape( myObject, aShape, TopAbs_WIRE ) )
224 mySelectWiresEdt->setText( myEditCurrentArgument->text() );
227 myObject = GEOM::GEOM_Object::_nil();
229 else if ( myEditCurrentArgument == mySelectWiresEdt )
231 TColStd_IndexedMapOfInteger aMap;
232 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( anIO, aMap );
233 const int n = aMap.Extent();
234 myWiresInd->length( n );
235 for ( int i = 1; i <= n; i++ )
236 myWiresInd[ i-1 ] = aMap( i );
238 myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
243 //=================================================================================
244 // function : SetEditCurrentArgument()
246 //=================================================================================
247 void RepairGUI_CloseContourDlg::SetEditCurrentArgument()
249 const QObject* send = sender();
250 if ( send == GroupPoints->PushButton1 )
251 myEditCurrentArgument = GroupPoints->LineEdit1;
252 else if ( send == mySelectWiresBtn && !myObject->_is_nil() )
253 myEditCurrentArgument = mySelectWiresEdt;
254 if ( myEditCurrentArgument )
257 myEditCurrentArgument->setFocus();
258 SelectionIntoArgument();
263 //=================================================================================
264 // function : LineEditReturnPressed()
266 //=================================================================================
267 void RepairGUI_CloseContourDlg::LineEditReturnPressed()
269 const QObject* send = sender();
270 if( send == GroupPoints->LineEdit1 || send == mySelectWiresEdt )
272 myEditCurrentArgument = (QLineEdit*)send;
273 GEOMBase_Skeleton::LineEditReturnPressed();
278 //=================================================================================
279 // function : DeactivateActiveDialog()
281 //=================================================================================
282 void RepairGUI_CloseContourDlg::DeactivateActiveDialog()
284 //myGeomGUI->SetState( -1 );
285 GEOMBase_Skeleton::DeactivateActiveDialog();
289 //=================================================================================
290 // function : ActivateThisDialog()
292 //=================================================================================
293 void RepairGUI_CloseContourDlg::ActivateThisDialog()
295 GEOMBase_Skeleton::ActivateThisDialog();
296 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
297 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
299 myEditCurrentArgument = GroupPoints->LineEdit1;
300 myEditCurrentArgument->setText("");
301 mySelectWiresEdt->setText("");
302 myObject = GEOM::GEOM_Object::_nil();
303 myWiresInd->length( 0 );
305 //myGeomGUI->SetState( 0 );
310 //=================================================================================
311 // function : enterEvent()
312 // purpose : Mouse enter onto the dialog to activate it
313 //=================================================================================
314 void RepairGUI_CloseContourDlg::enterEvent(QEvent* e)
316 if ( !GroupConstructors->isEnabled() )
317 ActivateThisDialog();
321 //=================================================================================
322 // function : closeEvent()
324 //=================================================================================
325 void RepairGUI_CloseContourDlg::closeEvent(QCloseEvent* e)
327 //myGeomGUI->SetState( -1 );
328 GEOMBase_Skeleton::closeEvent( e );
331 //=================================================================================
332 // function : createOperation
334 //=================================================================================
335 GEOM::GEOM_IOperations_ptr RepairGUI_CloseContourDlg::createOperation()
337 return getGeomEngine()->GetIHealingOperations( getStudyId() );
340 //=================================================================================
341 // function : isValid
343 //=================================================================================
344 bool RepairGUI_CloseContourDlg::isValid( QString& msg )
346 TopoDS_Shape aTmpShape;
347 return !myObject->_is_nil() && ( myWiresInd->length() || myGeomBase->GetShape( myObject, aTmpShape, TopAbs_WIRE ) );
350 //=================================================================================
351 // function : execute
353 //=================================================================================
354 bool RepairGUI_CloseContourDlg::execute( ObjectList& objects )
356 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->CloseContour( myObject, myWiresInd, getIsByVertex() );
357 bool aResult = !anObj->_is_nil();
359 objects.push_back( anObj._retn() );
364 //=================================================================================
365 // function : getIsByVertex
367 //=================================================================================
368 bool RepairGUI_CloseContourDlg::getIsByVertex() const
370 return myIsVertexGr->find( 0 )->isOn();
373 //=================================================================================
374 // function : initSelection
376 //=================================================================================
377 void RepairGUI_CloseContourDlg::initSelection()
379 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
381 TColStd_MapOfInteger aTypes;
382 aTypes.Add( GEOM_COMPOUND );
383 aTypes.Add( GEOM_SOLID );
384 aTypes.Add( GEOM_SHELL );
385 aTypes.Add( GEOM_FACE );
386 aTypes.Add( GEOM_WIRE );
388 globalSelection( aTypes );
390 else if ( myEditCurrentArgument == mySelectWiresEdt )
392 localSelection( myObject, TopAbs_EDGE );
393 localSelection( myObject, TopAbs_WIRE );