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