]> SALOME platform Git repositories - modules/geom.git/blob - src/RepairGUI/RepairGUI_CloseContourDlg.cxx
Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/geom.git] / src / RepairGUI / RepairGUI_CloseContourDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : RepairGUI_CloseContourDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "RepairGUI_CloseContourDlg.h"
31
32 #include "QAD_RightFrame.h"
33 #include "QAD_Desktop.h"
34 #include "OCCViewer_Viewer3d.h"
35 #include "SALOME_ListIteratorOfListIO.hxx"
36
37 #include "GEOMImpl_Types.hxx"
38
39 #include <TopAbs.hxx>
40
41
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)
51 {
52   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CLOSECONTOUR")));
53   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
54
55   setCaption(tr("GEOM_CLOSECONTOUR_TITLE"));
56
57   /***************************************************************/
58   GroupConstructors->setTitle(tr("GEOM_CLOSECONTOUR_TITLE"));
59   RadioButton1->setPixmap(image0);
60   RadioButton2->close(TRUE);
61   RadioButton3->close(TRUE);
62
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 );
68
69   QGridLayout* aSelectWiresLay = new QGridLayout( 0, 1, 1, 0, 6, "aSelectWiresLay");
70
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);
75
76   mySelectWiresEdt = new QLineEdit( GroupPoints->GroupBox1, "mySelectWiresEdt" );
77   mySelectWiresEdt->setReadOnly( true );
78
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() ) );
81
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 );
87
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();
94
95   Layout1->addWidget(GroupPoints, 2, 0);
96   GroupPoints->getGroupBoxLayout()->addLayout( aSelectWiresLay, 1, 0 );
97   GroupPoints->getGroupBoxLayout()->addMultiCellWidget(myIsVertexGr, 2, 2, 0, 2);
98   /***************************************************************/
99
100   Init();
101 }
102
103
104 //=================================================================================
105 // function : ~RepairGUI_CloseContourDlg()
106 // purpose  : Destroys the object and frees any allocated resources
107 //=================================================================================
108 RepairGUI_CloseContourDlg::~RepairGUI_CloseContourDlg()
109 {
110 }
111
112
113 //=================================================================================
114 // function : Init()
115 // purpose  :
116 //=================================================================================
117 void RepairGUI_CloseContourDlg::Init()
118 {
119   /* init variables */
120   myEditCurrentArgument = GroupPoints->LineEdit1;
121
122   myObject = GEOM::GEOM_Object::_nil();
123   myWiresInd = new GEOM::short_array();
124   myWiresInd->length( 0 );
125   
126   myGeomGUI->SetState( 0 );
127   initSelection();
128
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()));
133
134   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
135   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
136
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()));
141
142   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
143
144   initName( tr( "CLOSE_CONTOUR_NEW_OBJ_NAME" ) );
145 }
146
147
148 //=================================================================================
149 // function : ClickOnOk()
150 // purpose  : Same than click on apply but close this dialog.
151 //=================================================================================
152 void RepairGUI_CloseContourDlg::ClickOnOk()
153 {
154   if ( ClickOnApply() )
155     ClickOnCancel();
156 }
157
158
159
160 //=================================================================================
161 // function : ClickOnApply()
162 // purpose  :
163 //=================================================================================
164 bool RepairGUI_CloseContourDlg::ClickOnApply()
165 {
166   if ( !onAccept() )
167     return false;
168
169   initName();
170
171   myEditCurrentArgument = GroupPoints->LineEdit1;
172   myEditCurrentArgument->setText("");
173   myObject = GEOM::GEOM_Object::_nil();
174   myWiresInd->length( 0 );
175
176   initSelection();
177
178   return true;
179 }
180
181
182 //=================================================================================
183 // function : ClickOnCancel()
184 // purpose  :
185 //=================================================================================
186 void RepairGUI_CloseContourDlg::ClickOnCancel()
187 {
188   GEOMBase_Skeleton::ClickOnCancel();
189 }
190
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()
197 {
198   erasePreview();
199   myEditCurrentArgument->setText( "" );
200   mySelectWiresEdt->setText( "" );
201   
202   if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
203     myObject = GEOM::GEOM_Object::_nil();
204   else if ( myEditCurrentArgument == mySelectWiresEdt )
205     myWiresInd->length( 0 );
206
207   if ( mySelection->IObjectCount() == 1 )
208   {
209     Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
210
211     if ( myEditCurrentArgument == GroupPoints->LineEdit1 )  // face selection
212     {
213       Standard_Boolean aRes;
214       myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
215       if ( aRes && GEOMBase::IsShape( myObject ) )
216       {
217         myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
218         TopoDS_Shape aShape;
219         if ( myGeomBase->GetShape( myObject, aShape, TopAbs_WIRE ) )
220           mySelectWiresEdt->setText( myEditCurrentArgument->text() );
221       }
222       else
223         myObject = GEOM::GEOM_Object::_nil();
224     }
225     else if ( myEditCurrentArgument == mySelectWiresEdt )
226     {
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 );
233       if ( n )
234         myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
235     }
236   }
237 }
238
239 //=================================================================================
240 // function : SetEditCurrentArgument()
241 // purpose  :
242 //=================================================================================
243 void RepairGUI_CloseContourDlg::SetEditCurrentArgument()
244 {
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 )
251   {
252     initSelection();
253     myEditCurrentArgument->setFocus();
254     SelectionIntoArgument();
255   }
256 }
257
258
259 //=================================================================================
260 // function : LineEditReturnPressed()
261 // purpose  :
262 //=================================================================================
263 void RepairGUI_CloseContourDlg::LineEditReturnPressed()
264 {
265   const QObject* send = sender();
266   if( send == GroupPoints->LineEdit1 || send == mySelectWiresEdt )
267   {
268     myEditCurrentArgument = (QLineEdit*)send;
269     GEOMBase_Skeleton::LineEditReturnPressed();
270   }
271 }
272
273
274 //=================================================================================
275 // function : DeactivateActiveDialog()
276 // purpose  :
277 //=================================================================================
278 void RepairGUI_CloseContourDlg::DeactivateActiveDialog()
279 {
280   myGeomGUI->SetState( -1 );
281   GEOMBase_Skeleton::DeactivateActiveDialog();
282 }
283
284
285 //=================================================================================
286 // function : ActivateThisDialog()
287 // purpose  :
288 //=================================================================================
289 void RepairGUI_CloseContourDlg::ActivateThisDialog()
290 {
291   GEOMBase_Skeleton::ActivateThisDialog();
292   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
293
294   myEditCurrentArgument = GroupPoints->LineEdit1;
295   myEditCurrentArgument->setText("");
296   mySelectWiresEdt->setText("");
297   myObject = GEOM::GEOM_Object::_nil();
298   myWiresInd->length( 0 );
299
300   myGeomGUI->SetState( 0 );
301   initSelection();
302 }
303
304
305 //=================================================================================
306 // function : enterEvent()
307 // purpose  : Mouse enter onto the dialog to activate it
308 //=================================================================================
309 void RepairGUI_CloseContourDlg::enterEvent(QEvent* e)
310 {
311   if ( !GroupConstructors->isEnabled() )
312     ActivateThisDialog();
313 }
314
315
316 //=================================================================================
317 // function : closeEvent()
318 // purpose  :
319 //=================================================================================
320 void RepairGUI_CloseContourDlg::closeEvent(QCloseEvent* e)
321 {
322   myGeomGUI->SetState( -1 );
323   GEOMBase_Skeleton::closeEvent( e );
324 }
325
326 //=================================================================================
327 // function : createOperation
328 // purpose  :
329 //=================================================================================
330 GEOM::GEOM_IOperations_ptr RepairGUI_CloseContourDlg::createOperation()
331 {
332   return getGeomEngine()->GetIHealingOperations( getStudyId() );
333 }
334
335 //=================================================================================
336 // function : isValid
337 // purpose  :
338 //=================================================================================
339 bool RepairGUI_CloseContourDlg::isValid( QString& msg )
340 {
341   TopoDS_Shape aTmpShape;
342   return !myObject->_is_nil() && ( myWiresInd->length() || myGeomBase->GetShape( myObject, aTmpShape, TopAbs_WIRE ) );
343 }
344
345 //=================================================================================
346 // function : execute
347 // purpose  :
348 //=================================================================================
349 bool RepairGUI_CloseContourDlg::execute( ObjectList& objects )
350 {
351   GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->CloseContour( myObject, myWiresInd, getIsByVertex() );
352   bool aResult = !anObj->_is_nil();
353   if ( aResult )
354     objects.push_back( anObj._retn() );
355     
356   return aResult;
357 }
358
359 //=================================================================================
360 // function : getIsByVertex
361 // purpose  :
362 //=================================================================================
363 bool RepairGUI_CloseContourDlg::getIsByVertex() const
364 {
365   return myIsVertexGr->find( 0 )->isOn();
366 }
367
368 //=================================================================================
369 // function : initSelection
370 // purpose  :
371 //=================================================================================
372 void RepairGUI_CloseContourDlg::initSelection()
373 {
374   if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
375   {
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 );
382     
383     globalSelection( aTypes );
384   }
385   else if ( myEditCurrentArgument == mySelectWiresEdt )
386   {
387     localSelection( myObject, TopAbs_EDGE );
388     localSelection( myObject, TopAbs_WIRE );
389   }
390 }
391
392