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 "QAD_RightFrame.h"
33 #include "QAD_Desktop.h"
34 #include "OCCViewer_Viewer3d.h"
35 #include "SALOME_ListIteratorOfListIO.hxx"
37 #include "GEOMImpl_Types.hxx"
42 //=================================================================================
43 // class : RepairGUI_CloseContourDlg()
44 // purpose : Constructs a RepairGUI_CloseContourDlg which is a child of 'parent', with the
45 // name 'name' and widget flags set to 'f'.
46 // The dialog will by default be modeless, unless you set 'modal' to
47 // TRUE to construct a modal dialog.
48 //=================================================================================
49 RepairGUI_CloseContourDlg::RepairGUI_CloseContourDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
50 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
52 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CLOSECONTOUR")));
53 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
55 setCaption(tr("GEOM_CLOSECONTOUR_TITLE"));
57 /***************************************************************/
58 GroupConstructors->setTitle(tr("GEOM_CLOSECONTOUR_TITLE"));
59 RadioButton1->setPixmap(image0);
60 RadioButton2->close(TRUE);
61 RadioButton3->close(TRUE);
63 GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
64 GroupPoints->GroupBox1->setTitle(tr("Contour to close"));
65 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
66 GroupPoints->PushButton1->setPixmap(image1);
67 GroupPoints->LineEdit1->setReadOnly( true );
69 QGridLayout* aSelectWiresLay = new QGridLayout( 0, 1, 1, 0, 6, "aSelectWiresLay");
71 mySelectWiresBtn = new QPushButton( GroupPoints->GroupBox1, "mySelectWiresBtn" );
72 mySelectWiresBtn->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresBtn->sizePolicy().hasHeightForWidth() ) );
73 mySelectWiresBtn->setText( trUtf8( "" ) );
74 mySelectWiresBtn->setPixmap(image1);
76 mySelectWiresEdt = new QLineEdit( GroupPoints->GroupBox1, "mySelectWiresEdt" );
77 mySelectWiresEdt->setReadOnly( true );
79 mySelectWiresLbl = new QLabel( tr( "Contour to close" ), GroupPoints->GroupBox1, "ContourLbl" );
80 mySelectWiresLbl->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, mySelectWiresLbl->sizePolicy().hasHeightForWidth() ) );
82 aSelectWiresLay->addWidget( mySelectWiresLbl, 0, 0 );
83 aSelectWiresLay->addWidget( mySelectWiresBtn, 0, 1 );
84 aSelectWiresLay->addWidget( mySelectWiresEdt, 0, 2 );
85 QSpacerItem* spacer = new QSpacerItem( 0, 16, QSizePolicy::Minimum, QSizePolicy::Expanding );
86 aSelectWiresLay->addItem( spacer, 1, 2 );
88 myIsVertexGr = new QButtonGroup( 2, Qt::Vertical, GroupPoints );
89 myIsVertexGr->setFrameStyle( QFrame::NoFrame );
90 myIsVertexGr->setRadioButtonExclusive( true );
91 myIsVertexGr->insert( new QRadioButton( tr( "Close by common vertex" ), myIsVertexGr ), 0 );
92 myIsVertexGr->insert( new QRadioButton( tr( "Close by new edge" ), myIsVertexGr ), 1 );
93 myIsVertexGr->find( 0 )->toggle();
95 Layout1->addWidget(GroupPoints, 2, 0);
96 GroupPoints->getGroupBoxLayout()->addLayout( aSelectWiresLay, 1, 0 );
97 GroupPoints->getGroupBoxLayout()->addMultiCellWidget(myIsVertexGr, 2, 2, 0, 2);
98 /***************************************************************/
104 //=================================================================================
105 // function : ~RepairGUI_CloseContourDlg()
106 // purpose : Destroys the object and frees any allocated resources
107 //=================================================================================
108 RepairGUI_CloseContourDlg::~RepairGUI_CloseContourDlg()
113 //=================================================================================
116 //=================================================================================
117 void RepairGUI_CloseContourDlg::Init()
120 myEditCurrentArgument = GroupPoints->LineEdit1;
122 myObject = GEOM::GEOM_Object::_nil();
123 myWiresInd = new GEOM::short_array();
124 myWiresInd->length( 0 );
126 myGeomGUI->SetState( 0 );
129 /* signals and slots connections */
130 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
131 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
132 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
134 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
135 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
137 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
138 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
139 connect(mySelectWiresBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140 connect(mySelectWiresEdt, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
142 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
144 initName( tr( "CLOSE_CONTOUR_NEW_OBJ_NAME" ) );
148 //=================================================================================
149 // function : ClickOnOk()
150 // purpose : Same than click on apply but close this dialog.
151 //=================================================================================
152 void RepairGUI_CloseContourDlg::ClickOnOk()
154 if ( ClickOnApply() )
160 //=================================================================================
161 // function : ClickOnApply()
163 //=================================================================================
164 bool RepairGUI_CloseContourDlg::ClickOnApply()
171 myEditCurrentArgument = GroupPoints->LineEdit1;
172 myEditCurrentArgument->setText("");
173 myObject = GEOM::GEOM_Object::_nil();
174 myWiresInd->length( 0 );
182 //=================================================================================
183 // function : ClickOnCancel()
185 //=================================================================================
186 void RepairGUI_CloseContourDlg::ClickOnCancel()
188 GEOMBase_Skeleton::ClickOnCancel();
191 //=================================================================================
192 // function : SelectionIntoArgument()
193 // purpose : Called when selection as changed or other case
194 // : used only by SelectButtonC1A1 (LineEditC1A1)
195 //=================================================================================
196 void RepairGUI_CloseContourDlg::SelectionIntoArgument()
199 myEditCurrentArgument->setText( "" );
200 mySelectWiresEdt->setText( "" );
202 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
203 myObject = GEOM::GEOM_Object::_nil();
204 else if ( myEditCurrentArgument == mySelectWiresEdt )
205 myWiresInd->length( 0 );
207 if ( mySelection->IObjectCount() == 1 )
209 Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
211 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) // face selection
213 Standard_Boolean aRes;
214 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
215 if ( aRes && GEOMBase::IsShape( myObject ) )
217 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
219 if ( myGeomBase->GetShape( myObject, aShape, TopAbs_WIRE ) )
220 mySelectWiresEdt->setText( myEditCurrentArgument->text() );
223 myObject = GEOM::GEOM_Object::_nil();
225 else if ( myEditCurrentArgument == mySelectWiresEdt )
227 TColStd_IndexedMapOfInteger aMap;
228 mySelection->GetIndex( anIO, aMap );
229 const int n = aMap.Extent();
230 myWiresInd->length( n );
231 for ( int i = 1; i <= n; i++ )
232 myWiresInd[ i-1 ] = aMap( i );
234 myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
239 //=================================================================================
240 // function : SetEditCurrentArgument()
242 //=================================================================================
243 void RepairGUI_CloseContourDlg::SetEditCurrentArgument()
245 const QObject* send = sender();
246 if ( send == GroupPoints->PushButton1 )
247 myEditCurrentArgument = GroupPoints->LineEdit1;
248 else if ( send == mySelectWiresBtn && !myObject->_is_nil() )
249 myEditCurrentArgument = mySelectWiresEdt;
250 if ( myEditCurrentArgument )
253 myEditCurrentArgument->setFocus();
254 SelectionIntoArgument();
259 //=================================================================================
260 // function : LineEditReturnPressed()
262 //=================================================================================
263 void RepairGUI_CloseContourDlg::LineEditReturnPressed()
265 const QObject* send = sender();
266 if( send == GroupPoints->LineEdit1 || send == mySelectWiresEdt )
268 myEditCurrentArgument = (QLineEdit*)send;
269 GEOMBase_Skeleton::LineEditReturnPressed();
274 //=================================================================================
275 // function : DeactivateActiveDialog()
277 //=================================================================================
278 void RepairGUI_CloseContourDlg::DeactivateActiveDialog()
280 myGeomGUI->SetState( -1 );
281 GEOMBase_Skeleton::DeactivateActiveDialog();
285 //=================================================================================
286 // function : ActivateThisDialog()
288 //=================================================================================
289 void RepairGUI_CloseContourDlg::ActivateThisDialog()
291 GEOMBase_Skeleton::ActivateThisDialog();
292 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
294 myEditCurrentArgument = GroupPoints->LineEdit1;
295 myEditCurrentArgument->setText("");
296 mySelectWiresEdt->setText("");
297 myObject = GEOM::GEOM_Object::_nil();
298 myWiresInd->length( 0 );
300 myGeomGUI->SetState( 0 );
305 //=================================================================================
306 // function : enterEvent()
307 // purpose : Mouse enter onto the dialog to activate it
308 //=================================================================================
309 void RepairGUI_CloseContourDlg::enterEvent(QEvent* e)
311 if ( !GroupConstructors->isEnabled() )
312 ActivateThisDialog();
316 //=================================================================================
317 // function : closeEvent()
319 //=================================================================================
320 void RepairGUI_CloseContourDlg::closeEvent(QCloseEvent* e)
322 myGeomGUI->SetState( -1 );
323 GEOMBase_Skeleton::closeEvent( e );
326 //=================================================================================
327 // function : createOperation
329 //=================================================================================
330 GEOM::GEOM_IOperations_ptr RepairGUI_CloseContourDlg::createOperation()
332 return getGeomEngine()->GetIHealingOperations( getStudyId() );
335 //=================================================================================
336 // function : isValid
338 //=================================================================================
339 bool RepairGUI_CloseContourDlg::isValid( QString& msg )
341 TopoDS_Shape aTmpShape;
342 return !myObject->_is_nil() && ( myWiresInd->length() || myGeomBase->GetShape( myObject, aTmpShape, TopAbs_WIRE ) );
345 //=================================================================================
346 // function : execute
348 //=================================================================================
349 bool RepairGUI_CloseContourDlg::execute( ObjectList& objects )
351 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->CloseContour( myObject, myWiresInd, getIsByVertex() );
352 bool aResult = !anObj->_is_nil();
354 objects.push_back( anObj._retn() );
359 //=================================================================================
360 // function : getIsByVertex
362 //=================================================================================
363 bool RepairGUI_CloseContourDlg::getIsByVertex() const
365 return myIsVertexGr->find( 0 )->isOn();
368 //=================================================================================
369 // function : initSelection
371 //=================================================================================
372 void RepairGUI_CloseContourDlg::initSelection()
374 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
376 TColStd_MapOfInteger aTypes;
377 aTypes.Add( GEOM_COMPOUND );
378 aTypes.Add( GEOM_SOLID );
379 aTypes.Add( GEOM_SHELL );
380 aTypes.Add( GEOM_FACE );
381 aTypes.Add( GEOM_WIRE );
383 globalSelection( aTypes );
385 else if ( myEditCurrentArgument == mySelectWiresEdt )
387 localSelection( myObject, TopAbs_EDGE );
388 localSelection( myObject, TopAbs_WIRE );