1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : RepairGUI_CloseContourDlg.cxx
24 // Author : Lucien PIGNOLONI
28 #include "RepairGUI_CloseContourDlg.h"
30 #include "SalomeApp_Application.h"
31 #include "LightApp_SelectionMgr.h"
32 #include "SUIT_Session.h"
33 #include "SALOME_ListIteratorOfListIO.hxx"
35 #include "GEOMImpl_Types.hxx"
38 #include <TColStd_IndexedMapOfInteger.hxx>
39 #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(GeometryGUI* theGeometryGUI, QWidget* parent,
53 const char* name, bool modal, WFlags fl)
54 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
55 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
57 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CLOSECONTOUR")));
58 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
60 setCaption(tr("GEOM_CLOSECONTOUR_TITLE"));
62 /***************************************************************/
63 GroupConstructors->setTitle(tr("GEOM_CLOSECONTOUR_TITLE"));
64 RadioButton1->setPixmap(image0);
65 RadioButton2->close(TRUE);
66 RadioButton3->close(TRUE);
68 GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
69 GroupPoints->GroupBox1->setTitle(tr("Contour to close"));
70 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
71 GroupPoints->PushButton1->setPixmap(image1);
72 GroupPoints->LineEdit1->setReadOnly( true );
74 QGridLayout* aSelectWiresLay = new QGridLayout( 0, 1, 1, 0, 6, "aSelectWiresLay");
76 mySelectWiresBtn = new QPushButton( GroupPoints->GroupBox1, "mySelectWiresBtn" );
77 mySelectWiresBtn->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresBtn->sizePolicy().hasHeightForWidth() ) );
78 mySelectWiresBtn->setText( trUtf8( "" ) );
79 mySelectWiresBtn->setPixmap(image1);
81 mySelectWiresEdt = new QLineEdit( GroupPoints->GroupBox1, "mySelectWiresEdt" );
82 mySelectWiresEdt->setReadOnly( true );
84 mySelectWiresLbl = new QLabel( tr( "Contour to close" ), GroupPoints->GroupBox1, "ContourLbl" );
85 mySelectWiresLbl->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresLbl->sizePolicy().hasHeightForWidth() ) );
87 aSelectWiresLay->addWidget( mySelectWiresLbl, 0, 0 );
88 aSelectWiresLay->addWidget( mySelectWiresBtn, 0, 1 );
89 aSelectWiresLay->addWidget( mySelectWiresEdt, 0, 2 );
90 QSpacerItem* spacer = new QSpacerItem( 0, 16, QSizePolicy::Minimum, QSizePolicy::Expanding );
91 aSelectWiresLay->addItem( spacer, 1, 2 );
93 myIsVertexGr = new QButtonGroup( 2, Qt::Vertical, GroupPoints );
94 myIsVertexGr->setFrameStyle( QFrame::NoFrame );
95 myIsVertexGr->setRadioButtonExclusive( true );
96 myIsVertexGr->insert( new QRadioButton( tr( "Close by common vertex" ), myIsVertexGr ), 0 );
97 myIsVertexGr->insert( new QRadioButton( tr( "Close by new edge" ), myIsVertexGr ), 1 );
98 myIsVertexGr->find( 0 )->toggle();
100 Layout1->addWidget(GroupPoints, 2, 0);
101 GroupPoints->getGroupBoxLayout()->addLayout( aSelectWiresLay, 1, 0 );
102 GroupPoints->getGroupBoxLayout()->addMultiCellWidget(myIsVertexGr, 2, 2, 0, 2);
103 /***************************************************************/
105 setHelpFileName("close_contour_operation_page.html");
111 //=================================================================================
112 // function : ~RepairGUI_CloseContourDlg()
113 // purpose : Destroys the object and frees any allocated resources
114 //=================================================================================
115 RepairGUI_CloseContourDlg::~RepairGUI_CloseContourDlg()
120 //=================================================================================
123 //=================================================================================
124 void RepairGUI_CloseContourDlg::Init()
127 myEditCurrentArgument = GroupPoints->LineEdit1;
129 myObject = GEOM::GEOM_Object::_nil();
130 myWiresInd = new GEOM::short_array();
131 myWiresInd->length( 0 );
133 //myGeomGUI->SetState( 0 );
136 /* signals and slots connections */
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(myGeomGUI->getApp()->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 );
185 //=================================================================================
186 // function : SelectionIntoArgument()
187 // purpose : Called when selection as changed or other case
188 // : used only by SelectButtonC1A1 (LineEditC1A1)
189 //=================================================================================
190 void RepairGUI_CloseContourDlg::SelectionIntoArgument()
193 myEditCurrentArgument->setText( "" );
194 mySelectWiresEdt->setText( "" );
196 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
197 myObject = GEOM::GEOM_Object::_nil();
198 else if ( myEditCurrentArgument == mySelectWiresEdt )
199 myWiresInd->length( 0 );
201 if ( IObjectCount() == 1 )
203 Handle(SALOME_InteractiveObject) anIO = firstIObject();
205 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) // face selection
207 Standard_Boolean aRes;
208 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
209 if ( aRes && GEOMBase::IsShape( myObject ) )
211 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
213 if ( GEOMBase::GetShape( myObject, aShape, TopAbs_WIRE ) )
214 mySelectWiresEdt->setText( myEditCurrentArgument->text() );
217 myObject = GEOM::GEOM_Object::_nil();
219 else if ( myEditCurrentArgument == mySelectWiresEdt )
221 TColStd_IndexedMapOfInteger aMap;
222 myGeomGUI->getApp()->selectionMgr()->GetIndexes( anIO, aMap );
223 const int n = aMap.Extent();
224 myWiresInd->length( n );
225 for ( int i = 1; i <= n; i++ )
226 myWiresInd[ i-1 ] = aMap( i );
228 myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
233 //=================================================================================
234 // function : SetEditCurrentArgument()
236 //=================================================================================
237 void RepairGUI_CloseContourDlg::SetEditCurrentArgument()
239 const QObject* send = sender();
240 if ( send == GroupPoints->PushButton1 )
241 myEditCurrentArgument = GroupPoints->LineEdit1;
242 else if ( send == mySelectWiresBtn && !myObject->_is_nil() )
243 myEditCurrentArgument = mySelectWiresEdt;
244 if ( myEditCurrentArgument )
247 myEditCurrentArgument->setFocus();
248 SelectionIntoArgument();
253 //=================================================================================
254 // function : LineEditReturnPressed()
256 //=================================================================================
257 void RepairGUI_CloseContourDlg::LineEditReturnPressed()
259 const QObject* send = sender();
260 if( send == GroupPoints->LineEdit1 || send == mySelectWiresEdt )
262 myEditCurrentArgument = (QLineEdit*)send;
263 GEOMBase_Skeleton::LineEditReturnPressed();
268 //=================================================================================
269 // function : ActivateThisDialog()
271 //=================================================================================
272 void RepairGUI_CloseContourDlg::ActivateThisDialog()
274 GEOMBase_Skeleton::ActivateThisDialog();
275 connect(myGeomGUI->getApp()->selectionMgr(),
276 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
278 myEditCurrentArgument = GroupPoints->LineEdit1;
279 myEditCurrentArgument->setText("");
280 mySelectWiresEdt->setText("");
281 myObject = GEOM::GEOM_Object::_nil();
282 myWiresInd->length( 0 );
284 //myGeomGUI->SetState( 0 );
289 //=================================================================================
290 // function : enterEvent()
291 // purpose : Mouse enter onto the dialog to activate it
292 //=================================================================================
293 void RepairGUI_CloseContourDlg::enterEvent(QEvent* e)
295 if ( !GroupConstructors->isEnabled() )
296 ActivateThisDialog();
300 //=================================================================================
301 // function : closeEvent()
303 //=================================================================================
304 void RepairGUI_CloseContourDlg::closeEvent(QCloseEvent* e)
306 //myGeomGUI->SetState( -1 );
307 GEOMBase_Skeleton::closeEvent( e );
310 //=================================================================================
311 // function : createOperation
313 //=================================================================================
314 GEOM::GEOM_IOperations_ptr RepairGUI_CloseContourDlg::createOperation()
316 return getGeomEngine()->GetIHealingOperations( getStudyId() );
319 //=================================================================================
320 // function : isValid
322 //=================================================================================
323 bool RepairGUI_CloseContourDlg::isValid( QString& msg )
325 TopoDS_Shape aTmpShape;
326 return !myObject->_is_nil() && ( myWiresInd->length() || GEOMBase::GetShape( myObject, aTmpShape, TopAbs_WIRE ) );
329 //=================================================================================
330 // function : execute
332 //=================================================================================
333 bool RepairGUI_CloseContourDlg::execute( ObjectList& objects )
335 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->CloseContour( myObject, myWiresInd, getIsByVertex() );
336 bool aResult = !anObj->_is_nil();
338 objects.push_back( anObj._retn() );
343 //=================================================================================
344 // function : getIsByVertex
346 //=================================================================================
347 bool RepairGUI_CloseContourDlg::getIsByVertex() const
349 return myIsVertexGr->find( 0 )->isOn();
352 //=================================================================================
353 // function : initSelection
355 //=================================================================================
356 void RepairGUI_CloseContourDlg::initSelection()
358 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
360 TColStd_MapOfInteger aTypes;
361 aTypes.Add( GEOM_COMPOUND );
362 aTypes.Add( GEOM_SOLID );
363 aTypes.Add( GEOM_SHELL );
364 aTypes.Add( GEOM_FACE );
365 aTypes.Add( GEOM_WIRE );
367 globalSelection( aTypes );
369 else if ( myEditCurrentArgument == mySelectWiresEdt )
371 localSelection( myObject, TopAbs_EDGE );
372 localSelection( myObject, TopAbs_WIRE );