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_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(GeometryGUI* theGeometryGUI, QWidget* parent,
54 const char* name, bool modal, WFlags fl)
55 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
56 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
58 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CLOSECONTOUR")));
59 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
61 setCaption(tr("GEOM_CLOSECONTOUR_TITLE"));
63 /***************************************************************/
64 GroupConstructors->setTitle(tr("GEOM_CLOSECONTOUR_TITLE"));
65 RadioButton1->setPixmap(image0);
66 RadioButton2->close(TRUE);
67 RadioButton3->close(TRUE);
69 GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
70 GroupPoints->GroupBox1->setTitle(tr("Contour to close"));
71 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
72 GroupPoints->PushButton1->setPixmap(image1);
73 GroupPoints->LineEdit1->setReadOnly( true );
75 QGridLayout* aSelectWiresLay = new QGridLayout( 0, 1, 1, 0, 6, "aSelectWiresLay");
77 mySelectWiresBtn = new QPushButton( GroupPoints->GroupBox1, "mySelectWiresBtn" );
78 mySelectWiresBtn->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresBtn->sizePolicy().hasHeightForWidth() ) );
79 mySelectWiresBtn->setText( trUtf8( "" ) );
80 mySelectWiresBtn->setPixmap(image1);
82 mySelectWiresEdt = new QLineEdit( GroupPoints->GroupBox1, "mySelectWiresEdt" );
83 mySelectWiresEdt->setReadOnly( true );
85 mySelectWiresLbl = new QLabel( tr( "Contour to close" ), GroupPoints->GroupBox1, "ContourLbl" );
86 mySelectWiresLbl->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresLbl->sizePolicy().hasHeightForWidth() ) );
88 aSelectWiresLay->addWidget( mySelectWiresLbl, 0, 0 );
89 aSelectWiresLay->addWidget( mySelectWiresBtn, 0, 1 );
90 aSelectWiresLay->addWidget( mySelectWiresEdt, 0, 2 );
91 QSpacerItem* spacer = new QSpacerItem( 0, 16, QSizePolicy::Minimum, QSizePolicy::Expanding );
92 aSelectWiresLay->addItem( spacer, 1, 2 );
94 myIsVertexGr = new QButtonGroup( 2, Qt::Vertical, GroupPoints );
95 myIsVertexGr->setFrameStyle( QFrame::NoFrame );
96 myIsVertexGr->setRadioButtonExclusive( true );
97 myIsVertexGr->insert( new QRadioButton( tr( "Close by common vertex" ), myIsVertexGr ), 0 );
98 myIsVertexGr->insert( new QRadioButton( tr( "Close by new edge" ), myIsVertexGr ), 1 );
99 myIsVertexGr->find( 0 )->toggle();
101 Layout1->addWidget(GroupPoints, 2, 0);
102 GroupPoints->getGroupBoxLayout()->addLayout( aSelectWiresLay, 1, 0 );
103 GroupPoints->getGroupBoxLayout()->addMultiCellWidget(myIsVertexGr, 2, 2, 0, 2);
104 /***************************************************************/
106 setHelpFileName("close_contour_operation_page.html");
112 //=================================================================================
113 // function : ~RepairGUI_CloseContourDlg()
114 // purpose : Destroys the object and frees any allocated resources
115 //=================================================================================
116 RepairGUI_CloseContourDlg::~RepairGUI_CloseContourDlg()
121 //=================================================================================
124 //=================================================================================
125 void RepairGUI_CloseContourDlg::Init()
128 myEditCurrentArgument = GroupPoints->LineEdit1;
130 myObject = GEOM::GEOM_Object::_nil();
131 myWiresInd = new GEOM::short_array();
132 myWiresInd->length( 0 );
134 //myGeomGUI->SetState( 0 );
137 /* signals and slots connections */
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(myGeomGUI->getApp()->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 );
186 //=================================================================================
187 // function : SelectionIntoArgument()
188 // purpose : Called when selection as changed or other case
189 // : used only by SelectButtonC1A1 (LineEditC1A1)
190 //=================================================================================
191 void RepairGUI_CloseContourDlg::SelectionIntoArgument()
194 myEditCurrentArgument->setText( "" );
195 mySelectWiresEdt->setText( "" );
197 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
198 myObject = GEOM::GEOM_Object::_nil();
199 else if ( myEditCurrentArgument == mySelectWiresEdt )
200 myWiresInd->length( 0 );
202 if ( IObjectCount() == 1 )
204 Handle(SALOME_InteractiveObject) anIO = firstIObject();
206 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) // face selection
208 Standard_Boolean aRes;
209 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
210 if ( aRes && GEOMBase::IsShape( myObject ) )
212 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
214 if ( GEOMBase::GetShape( myObject, aShape, TopAbs_WIRE ) )
215 mySelectWiresEdt->setText( myEditCurrentArgument->text() );
218 myObject = GEOM::GEOM_Object::_nil();
220 else if ( myEditCurrentArgument == mySelectWiresEdt )
222 TColStd_IndexedMapOfInteger aMap;
223 myGeomGUI->getApp()->selectionMgr()->GetIndexes( anIO, aMap );
224 const int n = aMap.Extent();
225 myWiresInd->length( n );
226 for ( int i = 1; i <= n; i++ )
227 myWiresInd[ i-1 ] = aMap( i );
229 myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
234 //=================================================================================
235 // function : SetEditCurrentArgument()
237 //=================================================================================
238 void RepairGUI_CloseContourDlg::SetEditCurrentArgument()
240 const QObject* send = sender();
241 if ( send == GroupPoints->PushButton1 )
242 myEditCurrentArgument = GroupPoints->LineEdit1;
243 else if ( send == mySelectWiresBtn && !myObject->_is_nil() )
244 myEditCurrentArgument = mySelectWiresEdt;
245 if ( myEditCurrentArgument )
248 myEditCurrentArgument->setFocus();
249 SelectionIntoArgument();
254 //=================================================================================
255 // function : LineEditReturnPressed()
257 //=================================================================================
258 void RepairGUI_CloseContourDlg::LineEditReturnPressed()
260 const QObject* send = sender();
261 if( send == GroupPoints->LineEdit1 || send == mySelectWiresEdt )
263 myEditCurrentArgument = (QLineEdit*)send;
264 GEOMBase_Skeleton::LineEditReturnPressed();
269 //=================================================================================
270 // function : ActivateThisDialog()
272 //=================================================================================
273 void RepairGUI_CloseContourDlg::ActivateThisDialog()
275 GEOMBase_Skeleton::ActivateThisDialog();
276 connect(myGeomGUI->getApp()->selectionMgr(),
277 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
279 myEditCurrentArgument = GroupPoints->LineEdit1;
280 myEditCurrentArgument->setText("");
281 mySelectWiresEdt->setText("");
282 myObject = GEOM::GEOM_Object::_nil();
283 myWiresInd->length( 0 );
285 //myGeomGUI->SetState( 0 );
290 //=================================================================================
291 // function : enterEvent()
292 // purpose : Mouse enter onto the dialog to activate it
293 //=================================================================================
294 void RepairGUI_CloseContourDlg::enterEvent(QEvent* e)
296 if ( !GroupConstructors->isEnabled() )
297 ActivateThisDialog();
301 //=================================================================================
302 // function : closeEvent()
304 //=================================================================================
305 void RepairGUI_CloseContourDlg::closeEvent(QCloseEvent* e)
307 //myGeomGUI->SetState( -1 );
308 GEOMBase_Skeleton::closeEvent( e );
311 //=================================================================================
312 // function : createOperation
314 //=================================================================================
315 GEOM::GEOM_IOperations_ptr RepairGUI_CloseContourDlg::createOperation()
317 return getGeomEngine()->GetIHealingOperations( getStudyId() );
320 //=================================================================================
321 // function : isValid
323 //=================================================================================
324 bool RepairGUI_CloseContourDlg::isValid( QString& msg )
326 TopoDS_Shape aTmpShape;
327 return !myObject->_is_nil() && ( myWiresInd->length() || GEOMBase::GetShape( myObject, aTmpShape, TopAbs_WIRE ) );
330 //=================================================================================
331 // function : execute
333 //=================================================================================
334 bool RepairGUI_CloseContourDlg::execute( ObjectList& objects )
336 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->CloseContour( myObject, myWiresInd, getIsByVertex() );
337 bool aResult = !anObj->_is_nil();
339 objects.push_back( anObj._retn() );
344 //=================================================================================
345 // function : getIsByVertex
347 //=================================================================================
348 bool RepairGUI_CloseContourDlg::getIsByVertex() const
350 return myIsVertexGr->find( 0 )->isOn();
353 //=================================================================================
354 // function : initSelection
356 //=================================================================================
357 void RepairGUI_CloseContourDlg::initSelection()
359 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
361 TColStd_MapOfInteger aTypes;
362 aTypes.Add( GEOM_COMPOUND );
363 aTypes.Add( GEOM_SOLID );
364 aTypes.Add( GEOM_SHELL );
365 aTypes.Add( GEOM_FACE );
366 aTypes.Add( GEOM_WIRE );
368 globalSelection( aTypes );
370 else if ( myEditCurrentArgument == mySelectWiresEdt )
372 localSelection( myObject, TopAbs_EDGE );
373 localSelection( myObject, TopAbs_WIRE );