]> SALOME platform Git repositories - modules/geom.git/blob - src/OperationGUI/OperationGUI_GetShapesOnShapeDlg.cxx
Salome HOME
Changes for bug NPAL14533 (improvement GetShapesOnShape())
[modules/geom.git] / src / OperationGUI / OperationGUI_GetShapesOnShapeDlg.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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : OperationGUI_GetShapesOnShapeDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27
28 #include "OperationGUI_GetShapesOnShapeDlg.h"
29
30 #include "SUIT_Session.h"
31 #include "SalomeApp_Application.h"
32 #include "LightApp_SelectionMgr.h"
33
34 #include <qcombobox.h>
35 #include <qlabel.h>
36
37 //using namespace std;
38
39 //==============================================================================
40 // class    : OperationGUI_GetShapesOnShapeDlg()
41 // purpose  : Constructs a OperationGUI_GetShapesOnShapeDlg which is a child of
42 //            'parent', with the name 'name' and widget flags set to 'f'.
43 //            The dialog will by default be modeless, unless you set 'modal' to
44 //            TRUE to construct a modal dialog.
45 //=================================================================================
46 OperationGUI_GetShapesOnShapeDlg::OperationGUI_GetShapesOnShapeDlg(GeometryGUI* theGeometryGUI,
47                                                                    QWidget* parent)
48   :GEOMBase_Skeleton(theGeometryGUI, parent, "OperationGUI_GetShapesOnShapeDlg", false,
49                      WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
50 {
51
52   SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
53   QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_SHAPES_ON_SHAPE")));
54   QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
55
56   setCaption(tr("GEOM_SHAPES_ON_SHAPE_TITLE"));
57
58   GroupConstructors->setTitle(tr("GEOM_SHAPES_ON_SHAPE"));
59
60   RadioButton1->setPixmap(image0);
61   RadioButton2->close(TRUE);
62   RadioButton3->close(TRUE);
63
64   GroupPoints = new DlgRef_2Sel2List_QTD(this, "GroupPoints");
65   //GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
66   GroupPoints->GroupBox1->setTitle("Input data");
67   GroupPoints->TextLabel1->setText(tr("GEOM_SHAPES_ON_SHAPE_ESHAPE"));
68   GroupPoints->TextLabel2->setText(tr("GEOM_SHAPES_ON_SHAPE_CSHAPE"));
69   GroupPoints->TextLabel3->setText(tr("GEOM_RECONSTRUCTION_LIMIT"));
70   GroupPoints->TextLabel4->setText(tr("GEOM_SHAPES_ON_SHAPE_STATE"));
71   GroupPoints->PushButton1->setPixmap(image2);
72   GroupPoints->PushButton2->setPixmap(image2);
73   GroupPoints->LineEdit1->setReadOnly( true );
74   GroupPoints->LineEdit2->setReadOnly( true );
75
76   Layout1->addWidget(GroupPoints, 2, 0);
77
78   Init();
79 }
80
81
82 //=================================================================================
83 // function : ~OperationGUI_GetShapesOnShapeDlg
84 // purpose  : Destroys the object and frees any allocated resources
85 //=================================================================================
86 OperationGUI_GetShapesOnShapeDlg::~OperationGUI_GetShapesOnShapeDlg()
87 {
88 }
89
90
91 //=================================================================================
92 // function : Init()
93 // purpose  :
94 //=================================================================================
95 void OperationGUI_GetShapesOnShapeDlg::Init()
96 {
97   /* type for sub shape selection */
98   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_SOLID"));
99   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_SHELL"));
100   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_FACE"));
101   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_WIRE"));
102   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_EDGE"));
103   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_VERTEX"));
104
105   /* type for state selection */
106   GroupPoints->ComboBox2->insertItem(tr("GEOM_STATE_IN"));
107   GroupPoints->ComboBox2->insertItem(tr("GEOM_STATE_OUT"));
108   GroupPoints->ComboBox2->insertItem(tr("GEOM_STATE_ON"));
109   GroupPoints->ComboBox2->insertItem(tr("GEOM_STATE_ONIN"));
110   GroupPoints->ComboBox2->insertItem(tr("GEOM_STATE_ONOUT"));
111
112   GroupPoints->LineEdit1->clear();
113   GroupPoints->LineEdit2->clear();
114
115    /* signals and slots connections */
116   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
117   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
118
119   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
120   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
121
122   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
123   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
124   
125   connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
126   connect(GroupPoints->ComboBox2, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
127
128   connect(myGeomGUI->getApp()->selectionMgr(),
129           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
130   
131   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
132           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
133
134   globalSelection( GEOM_ALLSHAPES );
135
136   initName( GroupConstructors->title() );
137
138   resize(0, 0);
139   GroupPoints->TextLabel3->show();
140   GroupPoints->ComboBox1->show();
141   GroupPoints->ComboBox1->setCurrentItem(0);
142   GroupPoints->ComboBox2->show();
143   GroupPoints->ComboBox2->setCurrentItem(0);
144
145   myEditCurrentArgument = GroupPoints->LineEdit1;
146   myEditCurrentArgument->setFocus();
147   connect(myGeomGUI->getApp()->selectionMgr(),
148           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
149
150 }
151
152
153 //=================================================================================
154 // function : ClickOnOk()
155 // purpose  :
156 //=================================================================================
157 void OperationGUI_GetShapesOnShapeDlg::ClickOnOk()
158 {
159   if ( ClickOnApply() )
160     ClickOnCancel();
161 }
162
163
164 //=================================================================================
165 // function : ClickOnApply()
166 // purpose  :
167 //=================================================================================
168 bool OperationGUI_GetShapesOnShapeDlg::ClickOnApply()
169 {
170   if ( !onAccept() )
171     return false;  
172
173   initName();
174   return true;
175 }
176
177
178 //=================================================================================
179 // function : SelectionIntoArgument()
180 // purpose  : Called when selection has changed
181 //=================================================================================
182 void OperationGUI_GetShapesOnShapeDlg::SelectionIntoArgument()
183 {
184   myEditCurrentArgument->setText( "" );
185   QString aString = "";
186
187   int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
188
189   if(nbSel>0) {
190     Standard_Boolean aRes = Standard_False;
191     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
192     if ( !CORBA::is_nil( aSelectedObject ) && aRes && GEOMBase::IsShape( aSelectedObject ) ) {
193       {
194         myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
195         if      ( myEditCurrentArgument == GroupPoints->LineEdit1 )   myObject1 = aSelectedObject;
196         else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )   myObject2 = aSelectedObject;
197       }
198     }
199   }
200
201   myEditCurrentArgument->setText( aString );
202 }
203
204
205 //=================================================================================
206 // function : SetEditCurrentArgument()
207 // purpose  :
208 //=================================================================================
209 void OperationGUI_GetShapesOnShapeDlg::SetEditCurrentArgument()
210 {
211   QPushButton* send = (QPushButton*)sender();
212
213   if      ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
214   else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
215
216   myEditCurrentArgument->setFocus();
217   SelectionIntoArgument();
218 }
219
220
221 //=================================================================================
222 // function : LineEditReturnPressed()
223 // purpose  :
224 //=================================================================================
225 void OperationGUI_GetShapesOnShapeDlg::LineEditReturnPressed()
226 {
227   QLineEdit* send = (QLineEdit*)sender();
228   if ( send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2 )
229   {
230     myEditCurrentArgument = send;
231     GEOMBase_Skeleton::LineEditReturnPressed();
232   }
233 }
234
235
236 //=================================================================================
237 // function : ActivateThisDialog()
238 // purpose  :
239 //=================================================================================
240 void OperationGUI_GetShapesOnShapeDlg::ActivateThisDialog()
241 {
242   GEOMBase_Skeleton::ActivateThisDialog();
243   globalSelection( GEOM_ALLSHAPES );
244   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
245           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
246 }
247
248
249 //=================================================================================
250 // function : enterEvent()
251 // purpose  : when mouse enter onto the QWidget
252 //=================================================================================
253 void OperationGUI_GetShapesOnShapeDlg::enterEvent(QEvent * e)
254 {
255   if ( !GroupConstructors->isEnabled() )
256     ActivateThisDialog();
257 }
258
259
260 //=================================================================================
261 // function : createOperation
262 // purpose  :
263 //=================================================================================
264 GEOM::GEOM_IOperations_ptr OperationGUI_GetShapesOnShapeDlg::createOperation()
265 {
266   return getGeomEngine()->GetIShapesOperations( getStudyId() );
267 }
268
269
270 //=================================================================================
271 // function : isValid
272 // purpose  :
273 //=================================================================================
274 bool OperationGUI_GetShapesOnShapeDlg::isValid( QString& msg )
275 {
276   Handle(SALOME_InteractiveObject) IO = firstIObject();
277   Standard_Boolean testResult;
278   GEOM::GEOM_Object_var anObject = GEOMBase::ConvertIOinGEOMObject( IO, testResult );
279   if ( !testResult || anObject->_is_nil() )
280     return false;
281
282   return !CORBA::is_nil( myObject1 ) && !CORBA::is_nil( myObject2 );
283 }
284
285 //=================================================================================
286 // function : execute
287 // purpose  :
288 //=================================================================================
289 bool OperationGUI_GetShapesOnShapeDlg::execute( ObjectList& objects )
290 {
291   int aLimit = GroupPoints->ComboBox1->currentItem();
292   switch (aLimit)
293   {
294   case 0:  aLimit = GEOM::SOLID ; break;
295   case 1:  aLimit = GEOM::SHELL ; break;
296   case 2:  aLimit = GEOM::FACE  ; break;
297   case 3:  aLimit = GEOM::WIRE  ; break;
298   case 4:  aLimit = GEOM::EDGE  ; break;
299   case 5:  aLimit = GEOM::VERTEX; break;
300   default: aLimit = GEOM::SHAPE ;
301   }
302
303   GEOM::shape_state aState;
304   switch (GroupPoints->ComboBox2->currentItem())
305   {
306     case 0:  aState = GEOM::ST_IN; break;
307     case 1:  aState = GEOM::ST_OUT; break;
308     case 2:  aState = GEOM::ST_ON; break;
309     case 3:  aState = GEOM::ST_ONIN; break;
310     case 4:  aState = GEOM::ST_ONOUT; break;
311     default: break;
312   }
313
314   GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::
315     _narrow( getOperation() )->GetShapesOnShapeAsCompound(myObject2, myObject1,
316                                                           (CORBA::Short) aLimit,
317                                                           aState);
318
319   if (!anObj->_is_nil())
320     objects.push_back( anObj._retn() );
321
322   return objects.size();
323 }
324
325
326 //=================================================================================
327 // function : closeEvent
328 // purpose  :
329 //=================================================================================
330 void OperationGUI_GetShapesOnShapeDlg::closeEvent( QCloseEvent* e )
331 {
332   GEOMBase_Skeleton::closeEvent( e );
333 }
334
335
336 //=======================================================================
337 //function : ComboTextChanged
338 //purpose  : 
339 //=======================================================================
340 void OperationGUI_GetShapesOnShapeDlg::ComboTextChanged()
341 {
342   bool IsEnabled = GroupPoints->ComboBox1->currentItem() < 3;
343 }
344
345