]> SALOME platform Git repositories - modules/geom.git/blob - src/RepairGUI/RepairGUI_CloseContourDlg.cxx
Salome HOME
Update copyright information
[modules/geom.git] / src / RepairGUI / RepairGUI_CloseContourDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  GEOM GEOMGUI : GUI for Geometry component
23 //  File   : RepairGUI_CloseContourDlg.cxx
24 //  Author : Lucien PIGNOLONI
25 //  Module : GEOM
26 //  $Header$
27 //
28 #include "RepairGUI_CloseContourDlg.h"
29
30 #include "SalomeApp_Application.h"
31 #include "LightApp_SelectionMgr.h"
32 #include "SUIT_Session.h"
33 #include "SALOME_ListIteratorOfListIO.hxx"
34
35 #include "GEOMImpl_Types.hxx"
36
37 #include <TopAbs.hxx>
38 #include <TColStd_IndexedMapOfInteger.hxx>
39 #include <TColStd_MapOfInteger.hxx>
40
41 #include <qlabel.h>
42
43 using namespace std;
44
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)
56 {
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")));
59
60   setCaption(tr("GEOM_CLOSECONTOUR_TITLE"));
61
62   /***************************************************************/
63   GroupConstructors->setTitle(tr("GEOM_CLOSECONTOUR_TITLE"));
64   RadioButton1->setPixmap(image0);
65   RadioButton2->close(TRUE);
66   RadioButton3->close(TRUE);
67
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 );
73
74   QGridLayout* aSelectWiresLay = new QGridLayout( 0, 1, 1, 0, 6, "aSelectWiresLay");
75
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);
80
81   mySelectWiresEdt = new QLineEdit( GroupPoints->GroupBox1, "mySelectWiresEdt" );
82   mySelectWiresEdt->setReadOnly( true );
83
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() ) );
86
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 );
92
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();
99
100   Layout1->addWidget(GroupPoints, 2, 0);
101   GroupPoints->getGroupBoxLayout()->addLayout( aSelectWiresLay, 1, 0 );
102   GroupPoints->getGroupBoxLayout()->addMultiCellWidget(myIsVertexGr, 2, 2, 0, 2);
103   /***************************************************************/
104
105   setHelpFileName("close_contour_operation_page.html");
106
107   Init();
108 }
109
110
111 //=================================================================================
112 // function : ~RepairGUI_CloseContourDlg()
113 // purpose  : Destroys the object and frees any allocated resources
114 //=================================================================================
115 RepairGUI_CloseContourDlg::~RepairGUI_CloseContourDlg()
116 {
117 }
118
119
120 //=================================================================================
121 // function : Init()
122 // purpose  :
123 //=================================================================================
124 void RepairGUI_CloseContourDlg::Init()
125 {
126   /* init variables */
127   myEditCurrentArgument = GroupPoints->LineEdit1;
128
129   myObject = GEOM::GEOM_Object::_nil();
130   myWiresInd = new GEOM::short_array();
131   myWiresInd->length( 0 );
132   
133   //myGeomGUI->SetState( 0 );
134   initSelection();
135
136   /* signals and slots connections */
137   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
138   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
139
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()));
144
145   connect(myGeomGUI->getApp()->selectionMgr(), 
146           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
147
148   initName( tr( "CLOSE_CONTOUR_NEW_OBJ_NAME" ) );
149 }
150
151
152 //=================================================================================
153 // function : ClickOnOk()
154 // purpose  : Same than click on apply but close this dialog.
155 //=================================================================================
156 void RepairGUI_CloseContourDlg::ClickOnOk()
157 {
158   if ( ClickOnApply() )
159     ClickOnCancel();
160 }
161
162
163
164 //=================================================================================
165 // function : ClickOnApply()
166 // purpose  :
167 //=================================================================================
168 bool RepairGUI_CloseContourDlg::ClickOnApply()
169 {
170   if ( !onAccept() )
171     return false;
172
173   initName();
174
175   myEditCurrentArgument = GroupPoints->LineEdit1;
176   myEditCurrentArgument->setText("");
177   myObject = GEOM::GEOM_Object::_nil();
178   myWiresInd->length( 0 );
179
180   initSelection();
181
182   return true;
183 }
184
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()
191 {
192   erasePreview();
193   myEditCurrentArgument->setText( "" );
194   mySelectWiresEdt->setText( "" );
195   
196   if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
197     myObject = GEOM::GEOM_Object::_nil();
198   else if ( myEditCurrentArgument == mySelectWiresEdt )
199     myWiresInd->length( 0 );
200
201   if ( IObjectCount() == 1 )
202   {
203     Handle(SALOME_InteractiveObject) anIO = firstIObject();
204
205     if ( myEditCurrentArgument == GroupPoints->LineEdit1 )  // face selection
206     {
207       Standard_Boolean aRes;
208       myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
209       if ( aRes && GEOMBase::IsShape( myObject ) )
210       {
211         myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
212         TopoDS_Shape aShape;
213         if ( GEOMBase::GetShape( myObject, aShape, TopAbs_WIRE ) )
214           mySelectWiresEdt->setText( myEditCurrentArgument->text() );
215       }
216       else
217         myObject = GEOM::GEOM_Object::_nil();
218     }
219     else if ( myEditCurrentArgument == mySelectWiresEdt )
220     {
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 );
227       if ( n )
228         myEditCurrentArgument->setText( QString::number( n ) + "_" + tr( "GEOM_WIRE" ) + tr( "_S_" ) );
229     }
230   }
231 }
232
233 //=================================================================================
234 // function : SetEditCurrentArgument()
235 // purpose  :
236 //=================================================================================
237 void RepairGUI_CloseContourDlg::SetEditCurrentArgument()
238 {
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 )
245   {
246     initSelection();
247     myEditCurrentArgument->setFocus();
248     SelectionIntoArgument();
249   }
250 }
251
252
253 //=================================================================================
254 // function : LineEditReturnPressed()
255 // purpose  :
256 //=================================================================================
257 void RepairGUI_CloseContourDlg::LineEditReturnPressed()
258 {
259   const QObject* send = sender();
260   if( send == GroupPoints->LineEdit1 || send == mySelectWiresEdt )
261   {
262     myEditCurrentArgument = (QLineEdit*)send;
263     GEOMBase_Skeleton::LineEditReturnPressed();
264   }
265 }
266
267
268 //=================================================================================
269 // function : ActivateThisDialog()
270 // purpose  :
271 //=================================================================================
272 void RepairGUI_CloseContourDlg::ActivateThisDialog()
273 {
274   GEOMBase_Skeleton::ActivateThisDialog();
275   connect(myGeomGUI->getApp()->selectionMgr(), 
276           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
277
278   myEditCurrentArgument = GroupPoints->LineEdit1;
279   myEditCurrentArgument->setText("");
280   mySelectWiresEdt->setText("");
281   myObject = GEOM::GEOM_Object::_nil();
282   myWiresInd->length( 0 );
283
284   //myGeomGUI->SetState( 0 );
285   initSelection();
286 }
287
288
289 //=================================================================================
290 // function : enterEvent()
291 // purpose  : Mouse enter onto the dialog to activate it
292 //=================================================================================
293 void RepairGUI_CloseContourDlg::enterEvent(QEvent* e)
294 {
295   if ( !GroupConstructors->isEnabled() )
296     ActivateThisDialog();
297 }
298
299
300 //=================================================================================
301 // function : closeEvent()
302 // purpose  :
303 //=================================================================================
304 void RepairGUI_CloseContourDlg::closeEvent(QCloseEvent* e)
305 {
306   //myGeomGUI->SetState( -1 );
307   GEOMBase_Skeleton::closeEvent( e );
308 }
309
310 //=================================================================================
311 // function : createOperation
312 // purpose  :
313 //=================================================================================
314 GEOM::GEOM_IOperations_ptr RepairGUI_CloseContourDlg::createOperation()
315 {
316   return getGeomEngine()->GetIHealingOperations( getStudyId() );
317 }
318
319 //=================================================================================
320 // function : isValid
321 // purpose  :
322 //=================================================================================
323 bool RepairGUI_CloseContourDlg::isValid( QString& msg )
324 {
325   TopoDS_Shape aTmpShape;
326   return !myObject->_is_nil() && ( myWiresInd->length() || GEOMBase::GetShape( myObject, aTmpShape, TopAbs_WIRE ) );
327 }
328
329 //=================================================================================
330 // function : execute
331 // purpose  :
332 //=================================================================================
333 bool RepairGUI_CloseContourDlg::execute( ObjectList& objects )
334 {
335   GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->CloseContour( myObject, myWiresInd, getIsByVertex() );
336   bool aResult = !anObj->_is_nil();
337   if ( aResult )
338     objects.push_back( anObj._retn() );
339     
340   return aResult;
341 }
342
343 //=================================================================================
344 // function : getIsByVertex
345 // purpose  :
346 //=================================================================================
347 bool RepairGUI_CloseContourDlg::getIsByVertex() const
348 {
349   return myIsVertexGr->find( 0 )->isOn();
350 }
351
352 //=================================================================================
353 // function : initSelection
354 // purpose  :
355 //=================================================================================
356 void RepairGUI_CloseContourDlg::initSelection()
357 {
358   if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
359   {
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 );
366     
367     globalSelection( aTypes );
368   }
369   else if ( myEditCurrentArgument == mySelectWiresEdt )
370   {
371     localSelection( myObject, TopAbs_EDGE );
372     localSelection( myObject, TopAbs_WIRE );
373   }
374 }