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
22 // File : RepairGUI_CloseContourDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "RepairGUI_CloseContourDlg.h"
29 #include <GeometryGUI.h>
32 #include <SalomeApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_ResourceMgr.h>
37 #include <GEOMImpl_Types.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
41 #include <TColStd_MapOfInteger.hxx>
43 //=================================================================================
44 // class : RepairGUI_CloseContourDlg()
45 // purpose : Constructs a RepairGUI_CloseContourDlg which is a child of 'parent', with the
46 // name 'name' and widget flags set to 'f'.
47 // The dialog will by default be modeless, unless you set 'modal' to
48 // TRUE to construct a modal dialog.
49 //=================================================================================
50 RepairGUI_CloseContourDlg::RepairGUI_CloseContourDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
52 : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
54 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CLOSECONTOUR" ) ) );
55 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
57 setWindowTitle( tr( "GEOM_CLOSECONTOUR_TITLE" ) );
59 /***************************************************************/
60 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CLOSECONTOUR_TITLE" ) );
61 mainFrame()->RadioButton1->setIcon( image0 );
62 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
63 mainFrame()->RadioButton2->close();
64 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
65 mainFrame()->RadioButton3->close();
67 GroupPoints = new DlgRef_2SelExt( centralWidget() );
68 GroupPoints->GroupBox1->setTitle( tr( "Contour to close" ) );
69 GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
70 GroupPoints->PushButton1->setIcon( image1 );
71 GroupPoints->LineEdit1->setReadOnly( true );
73 GroupPoints->TextLabel2->setText( tr( "Contour to close" ) );
74 GroupPoints->PushButton2->setIcon( image1 );
75 GroupPoints->LineEdit2->setReadOnly( true );
77 QRadioButton* rb1 = new QRadioButton( tr( "Close by common vertex" ), GroupPoints->Box );
78 QRadioButton* rb2 = new QRadioButton( tr( "Close by new edge" ), GroupPoints->Box );
80 myIsVertexGr = new QButtonGroup( GroupPoints->Box );
81 myIsVertexGr->addButton( rb1, 0 );
82 myIsVertexGr->addButton( rb2, 1 );
83 rb1->setChecked( true );
85 QVBoxLayout* l = new QVBoxLayout( GroupPoints->Box );
86 l->setMargin( 0 ); l->setSpacing( 6 );
90 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
91 layout->setMargin( 0 ); layout->setSpacing( 6 );
92 layout->addWidget( GroupPoints );
94 /***************************************************************/
96 setHelpFileName( "close_contour_operation_page.html" );
102 //=================================================================================
103 // function : ~RepairGUI_CloseContourDlg()
104 // purpose : Destroys the object and frees any allocated resources
105 //=================================================================================
106 RepairGUI_CloseContourDlg::~RepairGUI_CloseContourDlg()
111 //=================================================================================
114 //=================================================================================
115 void RepairGUI_CloseContourDlg::Init()
118 myEditCurrentArgument = GroupPoints->LineEdit1;
120 myObject = GEOM::GEOM_Object::_nil();
121 myWiresInd = new GEOM::short_array();
122 myWiresInd->length( 0 );
124 //myGeomGUI->SetState( 0 );
127 /* signals and slots connections */
128 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
129 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
131 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
132 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
133 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
134 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
136 connect( myGeomGUI->getApp()->selectionMgr(),
137 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
139 initName( tr( "CLOSE_CONTOUR_NEW_OBJ_NAME" ) );
143 //=================================================================================
144 // function : ClickOnOk()
145 // purpose : Same than click on apply but close this dialog.
146 //=================================================================================
147 void RepairGUI_CloseContourDlg::ClickOnOk()
149 if ( ClickOnApply() )
155 //=================================================================================
156 // function : ClickOnApply()
158 //=================================================================================
159 bool RepairGUI_CloseContourDlg::ClickOnApply()
166 myEditCurrentArgument = GroupPoints->LineEdit1;
167 myEditCurrentArgument->setText( "" );
168 myObject = GEOM::GEOM_Object::_nil();
169 myWiresInd->length( 0 );
176 //=================================================================================
177 // function : SelectionIntoArgument()
178 // purpose : Called when selection as changed or other case
179 // : used only by SelectButtonC1A1 (LineEditC1A1)
180 //=================================================================================
181 void RepairGUI_CloseContourDlg::SelectionIntoArgument()
184 myEditCurrentArgument->setText( "" );
185 GroupPoints->LineEdit2->setText( "" );
187 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
188 myObject = GEOM::GEOM_Object::_nil();
189 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
190 myWiresInd->length( 0 );
192 if ( IObjectCount() == 1 ) {
193 Handle(SALOME_InteractiveObject) anIO = firstIObject();
195 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) { // face selection
196 Standard_Boolean aRes;
197 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
198 if ( aRes && GEOMBase::IsShape( myObject ) ) {
199 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
201 if ( GEOMBase::GetShape( myObject, aShape, TopAbs_WIRE ) )
202 GroupPoints->LineEdit2->setText( myEditCurrentArgument->text() );
205 myObject = GEOM::GEOM_Object::_nil();
207 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
208 TColStd_IndexedMapOfInteger aMap;
209 myGeomGUI->getApp()->selectionMgr()->GetIndexes( anIO, aMap );
210 const int n = aMap.Extent();
211 myWiresInd->length( n );
212 for ( int i = 1; i <= n; i++ )
213 myWiresInd[ i-1 ] = aMap( i );
215 myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
220 //=================================================================================
221 // function : SetEditCurrentArgument()
223 //=================================================================================
224 void RepairGUI_CloseContourDlg::SetEditCurrentArgument()
226 const QObject* send = sender();
227 if ( send == GroupPoints->PushButton1 )
228 myEditCurrentArgument = GroupPoints->LineEdit1;
229 else if ( send == GroupPoints->PushButton2 && !myObject->_is_nil() )
230 myEditCurrentArgument = GroupPoints->LineEdit2;
231 if ( myEditCurrentArgument ) {
233 myEditCurrentArgument->setFocus();
234 SelectionIntoArgument();
239 //=================================================================================
240 // function : LineEditReturnPressed()
242 //=================================================================================
243 void RepairGUI_CloseContourDlg::LineEditReturnPressed()
245 const QObject* send = sender();
246 if ( send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2 ) {
247 myEditCurrentArgument = (QLineEdit*)send;
248 GEOMBase_Skeleton::LineEditReturnPressed();
253 //=================================================================================
254 // function : ActivateThisDialog()
256 //=================================================================================
257 void RepairGUI_CloseContourDlg::ActivateThisDialog()
259 GEOMBase_Skeleton::ActivateThisDialog();
260 connect( myGeomGUI->getApp()->selectionMgr(),
261 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
263 myEditCurrentArgument = GroupPoints->LineEdit1;
264 myEditCurrentArgument->setText( "" );
265 GroupPoints->LineEdit2->setText( "" );
266 myObject = GEOM::GEOM_Object::_nil();
267 myWiresInd->length( 0 );
269 //myGeomGUI->SetState( 0 );
274 //=================================================================================
275 // function : enterEvent()
276 // purpose : Mouse enter onto the dialog to activate it
277 //=================================================================================
278 void RepairGUI_CloseContourDlg::enterEvent( QEvent* )
280 if ( !mainFrame()->GroupConstructors->isEnabled() )
281 ActivateThisDialog();
285 //=================================================================================
286 // function : createOperation
288 //=================================================================================
289 GEOM::GEOM_IOperations_ptr RepairGUI_CloseContourDlg::createOperation()
291 return getGeomEngine()->GetIHealingOperations( getStudyId() );
294 //=================================================================================
295 // function : isValid
297 //=================================================================================
298 bool RepairGUI_CloseContourDlg::isValid( QString& )
300 TopoDS_Shape aTmpShape;
301 return !myObject->_is_nil() && ( myWiresInd->length() || GEOMBase::GetShape( myObject, aTmpShape, TopAbs_WIRE ) );
304 //=================================================================================
305 // function : execute
307 //=================================================================================
308 bool RepairGUI_CloseContourDlg::execute( ObjectList& objects )
310 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->CloseContour( myObject, myWiresInd, getIsByVertex() );
311 bool aResult = !anObj->_is_nil();
313 objects.push_back( anObj._retn() );
318 //=================================================================================
319 // function : getIsByVertex
321 //=================================================================================
322 bool RepairGUI_CloseContourDlg::getIsByVertex() const
324 return myIsVertexGr->button( 0 )->isChecked();
327 //=================================================================================
328 // function : initSelection
330 //=================================================================================
331 void RepairGUI_CloseContourDlg::initSelection()
333 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
334 TColStd_MapOfInteger aTypes;
335 aTypes.Add( GEOM_COMPOUND );
336 aTypes.Add( GEOM_SOLID );
337 aTypes.Add( GEOM_SHELL );
338 aTypes.Add( GEOM_FACE );
339 aTypes.Add( GEOM_WIRE );
341 globalSelection( aTypes );
343 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
344 localSelection( myObject, TopAbs_EDGE );
345 localSelection( myObject, TopAbs_WIRE );