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
29 #include "RepairGUI_CloseContourDlg.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_IndexedMapOfInteger.hxx>
40 #include <TColStd_MapOfInteger.hxx>
46 //=================================================================================
47 // class : RepairGUI_CloseContourDlg()
48 // purpose : Constructs a RepairGUI_CloseContourDlg which is a child of 'parent', with the
49 // name 'name' and widget flags set to 'f'.
50 // The dialog will by default be modeless, unless you set 'modal' to
51 // TRUE to construct a modal dialog.
52 //=================================================================================
53 RepairGUI_CloseContourDlg::RepairGUI_CloseContourDlg(QWidget* parent, const char* name, bool modal, WFlags fl)
54 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
56 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CLOSECONTOUR")));
57 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
59 setCaption(tr("GEOM_CLOSECONTOUR_TITLE"));
61 /***************************************************************/
62 GroupConstructors->setTitle(tr("GEOM_CLOSECONTOUR_TITLE"));
63 RadioButton1->setPixmap(image0);
64 RadioButton2->close(TRUE);
65 RadioButton3->close(TRUE);
67 GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
68 GroupPoints->GroupBox1->setTitle(tr("Contour to close"));
69 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
70 GroupPoints->PushButton1->setPixmap(image1);
71 GroupPoints->LineEdit1->setReadOnly( true );
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( "Contour to close" ), GroupPoints->GroupBox1, "ContourLbl" );
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 myIsVertexGr = new QButtonGroup( 2, Qt::Vertical, GroupPoints );
93 myIsVertexGr->setFrameStyle( QFrame::NoFrame );
94 myIsVertexGr->setRadioButtonExclusive( true );
95 myIsVertexGr->insert( new QRadioButton( tr( "Close by common vertex" ), myIsVertexGr ), 0 );
96 myIsVertexGr->insert( new QRadioButton( tr( "Close by new edge" ), myIsVertexGr ), 1 );
97 myIsVertexGr->find( 0 )->toggle();
99 Layout1->addWidget(GroupPoints, 2, 0);
100 GroupPoints->getGroupBoxLayout()->addLayout( aSelectWiresLay, 1, 0 );
101 GroupPoints->getGroupBoxLayout()->addMultiCellWidget(myIsVertexGr, 2, 2, 0, 2);
102 /***************************************************************/
108 //=================================================================================
109 // function : ~RepairGUI_CloseContourDlg()
110 // purpose : Destroys the object and frees any allocated resources
111 //=================================================================================
112 RepairGUI_CloseContourDlg::~RepairGUI_CloseContourDlg()
117 //=================================================================================
120 //=================================================================================
121 void RepairGUI_CloseContourDlg::Init()
124 myEditCurrentArgument = GroupPoints->LineEdit1;
126 myObject = GEOM::GEOM_Object::_nil();
127 myWiresInd = new GEOM::short_array();
128 myWiresInd->length( 0 );
130 //myGeomGUI->SetState( 0 );
133 /* signals and slots connections */
134 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
135 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
136 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
138 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
139 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
141 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
142 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
143 connect(mySelectWiresBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
144 connect(mySelectWiresEdt, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
146 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
147 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
149 initName( tr( "CLOSE_CONTOUR_NEW_OBJ_NAME" ) );
153 //=================================================================================
154 // function : ClickOnOk()
155 // purpose : Same than click on apply but close this dialog.
156 //=================================================================================
157 void RepairGUI_CloseContourDlg::ClickOnOk()
159 if ( ClickOnApply() )
165 //=================================================================================
166 // function : ClickOnApply()
168 //=================================================================================
169 bool RepairGUI_CloseContourDlg::ClickOnApply()
176 myEditCurrentArgument = GroupPoints->LineEdit1;
177 myEditCurrentArgument->setText("");
178 myObject = GEOM::GEOM_Object::_nil();
179 myWiresInd->length( 0 );
187 //=================================================================================
188 // function : ClickOnCancel()
190 //=================================================================================
191 void RepairGUI_CloseContourDlg::ClickOnCancel()
193 GEOMBase_Skeleton::ClickOnCancel();
196 //=================================================================================
197 // function : SelectionIntoArgument()
198 // purpose : Called when selection as changed or other case
199 // : used only by SelectButtonC1A1 (LineEditC1A1)
200 //=================================================================================
201 void RepairGUI_CloseContourDlg::SelectionIntoArgument()
204 myEditCurrentArgument->setText( "" );
205 mySelectWiresEdt->setText( "" );
207 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
208 myObject = GEOM::GEOM_Object::_nil();
209 else if ( myEditCurrentArgument == mySelectWiresEdt )
210 myWiresInd->length( 0 );
212 if ( IObjectCount() == 1 )
214 Handle(SALOME_InteractiveObject) anIO = firstIObject();
216 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) // face selection
218 Standard_Boolean aRes;
219 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
220 if ( aRes && GEOMBase::IsShape( myObject ) )
222 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
224 if ( myGeomBase->GetShape( myObject, aShape, TopAbs_WIRE ) )
225 mySelectWiresEdt->setText( myEditCurrentArgument->text() );
228 myObject = GEOM::GEOM_Object::_nil();
230 else if ( myEditCurrentArgument == mySelectWiresEdt )
232 TColStd_IndexedMapOfInteger aMap;
233 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr()->GetIndexes( anIO, aMap );
234 const int n = aMap.Extent();
235 myWiresInd->length( n );
236 for ( int i = 1; i <= n; i++ )
237 myWiresInd[ i-1 ] = aMap( i );
239 myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
244 //=================================================================================
245 // function : SetEditCurrentArgument()
247 //=================================================================================
248 void RepairGUI_CloseContourDlg::SetEditCurrentArgument()
250 const QObject* send = sender();
251 if ( send == GroupPoints->PushButton1 )
252 myEditCurrentArgument = GroupPoints->LineEdit1;
253 else if ( send == mySelectWiresBtn && !myObject->_is_nil() )
254 myEditCurrentArgument = mySelectWiresEdt;
255 if ( myEditCurrentArgument )
258 myEditCurrentArgument->setFocus();
259 SelectionIntoArgument();
264 //=================================================================================
265 // function : LineEditReturnPressed()
267 //=================================================================================
268 void RepairGUI_CloseContourDlg::LineEditReturnPressed()
270 const QObject* send = sender();
271 if( send == GroupPoints->LineEdit1 || send == mySelectWiresEdt )
273 myEditCurrentArgument = (QLineEdit*)send;
274 GEOMBase_Skeleton::LineEditReturnPressed();
279 //=================================================================================
280 // function : DeactivateActiveDialog()
282 //=================================================================================
283 void RepairGUI_CloseContourDlg::DeactivateActiveDialog()
285 //myGeomGUI->SetState( -1 );
286 GEOMBase_Skeleton::DeactivateActiveDialog();
290 //=================================================================================
291 // function : ActivateThisDialog()
293 //=================================================================================
294 void RepairGUI_CloseContourDlg::ActivateThisDialog()
296 GEOMBase_Skeleton::ActivateThisDialog();
297 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
298 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
300 myEditCurrentArgument = GroupPoints->LineEdit1;
301 myEditCurrentArgument->setText("");
302 mySelectWiresEdt->setText("");
303 myObject = GEOM::GEOM_Object::_nil();
304 myWiresInd->length( 0 );
306 //myGeomGUI->SetState( 0 );
311 //=================================================================================
312 // function : enterEvent()
313 // purpose : Mouse enter onto the dialog to activate it
314 //=================================================================================
315 void RepairGUI_CloseContourDlg::enterEvent(QEvent* e)
317 if ( !GroupConstructors->isEnabled() )
318 ActivateThisDialog();
322 //=================================================================================
323 // function : closeEvent()
325 //=================================================================================
326 void RepairGUI_CloseContourDlg::closeEvent(QCloseEvent* e)
328 //myGeomGUI->SetState( -1 );
329 GEOMBase_Skeleton::closeEvent( e );
332 //=================================================================================
333 // function : createOperation
335 //=================================================================================
336 GEOM::GEOM_IOperations_ptr RepairGUI_CloseContourDlg::createOperation()
338 return getGeomEngine()->GetIHealingOperations( getStudyId() );
341 //=================================================================================
342 // function : isValid
344 //=================================================================================
345 bool RepairGUI_CloseContourDlg::isValid( QString& msg )
347 TopoDS_Shape aTmpShape;
348 return !myObject->_is_nil() && ( myWiresInd->length() || myGeomBase->GetShape( myObject, aTmpShape, TopAbs_WIRE ) );
351 //=================================================================================
352 // function : execute
354 //=================================================================================
355 bool RepairGUI_CloseContourDlg::execute( ObjectList& objects )
357 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->CloseContour( myObject, myWiresInd, getIsByVertex() );
358 bool aResult = !anObj->_is_nil();
360 objects.push_back( anObj._retn() );
365 //=================================================================================
366 // function : getIsByVertex
368 //=================================================================================
369 bool RepairGUI_CloseContourDlg::getIsByVertex() const
371 return myIsVertexGr->find( 0 )->isOn();
374 //=================================================================================
375 // function : initSelection
377 //=================================================================================
378 void RepairGUI_CloseContourDlg::initSelection()
380 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
382 TColStd_MapOfInteger aTypes;
383 aTypes.Add( GEOM_COMPOUND );
384 aTypes.Add( GEOM_SOLID );
385 aTypes.Add( GEOM_SHELL );
386 aTypes.Add( GEOM_FACE );
387 aTypes.Add( GEOM_WIRE );
389 globalSelection( aTypes );
391 else if ( myEditCurrentArgument == mySelectWiresEdt )
393 localSelection( myObject, TopAbs_EDGE );
394 localSelection( myObject, TopAbs_WIRE );