Salome HOME
IMPs 21044, 21057, 21067
[modules/geom.git] / src / OperationGUI / OperationGUI_GetShapesOnShapeDlg.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // GEOM GEOMGUI : GUI for Geometry component
21 // File   : OperationGUI_GetShapesOnShapeDlg.cxx
22 // Author : Sergey KUUL, Open CASCADE S.A.S. (sergey.kuul@opencascade.com)
23 //
24 #include "OperationGUI_GetShapesOnShapeDlg.h"
25
26 #include <DlgRef.h>
27 #include <GeometryGUI.h>
28 #include <GEOMBase.h>
29
30 #include <SUIT_Session.h>
31 #include <SUIT_ResourceMgr.h>
32 #include <SalomeApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
34
35 //==============================================================================
36 // class    : OperationGUI_GetShapesOnShapeDlg()
37 // purpose  : Constructs a OperationGUI_GetShapesOnShapeDlg which is a child of
38 //            'parent', with the name 'name' and widget flags set to 'f'.
39 //            The dialog will by default be modeless, unless you set 'modal' to
40 //            TRUE to construct a modal dialog.
41 //=================================================================================
42 OperationGUI_GetShapesOnShapeDlg::OperationGUI_GetShapesOnShapeDlg (GeometryGUI* theGeometryGUI,
43                                                                     QWidget* parent)
44   : GEOMBase_Skeleton(theGeometryGUI, parent, false)
45 {
46   SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
47   QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_SHAPES_ON_SHAPE")));
48   QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
49
50   setWindowTitle(tr("GEOM_SHAPES_ON_SHAPE_TITLE"));
51
52   /***************************************************************/
53   mainFrame()->GroupConstructors->setTitle(tr("GEOM_SHAPES_ON_SHAPE"));
54   mainFrame()->RadioButton1->setIcon(image0);
55   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
56   mainFrame()->RadioButton2->close();
57   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
58   mainFrame()->RadioButton3->close();
59
60   GroupPoints = new DlgRef_2Sel2List(centralWidget());
61   //GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
62   GroupPoints->GroupBox1->setTitle("Input data");
63   GroupPoints->TextLabel1->setText(tr("GEOM_SHAPES_ON_SHAPE_ESHAPE"));
64   GroupPoints->TextLabel2->setText(tr("GEOM_SHAPES_ON_SHAPE_CSHAPE"));
65   GroupPoints->TextLabel3->setText(tr("GEOM_RECONSTRUCTION_LIMIT"));
66   GroupPoints->TextLabel4->setText(tr("GEOM_SHAPES_ON_SHAPE_STATE"));
67   GroupPoints->PushButton1->setIcon(image2);
68   GroupPoints->PushButton2->setIcon(image2);
69   GroupPoints->LineEdit1->setReadOnly(true);
70   GroupPoints->LineEdit2->setReadOnly(true);
71
72   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
73   layout->setMargin(0); layout->setSpacing(6);
74   layout->addWidget(GroupPoints);
75   /***************************************************************/
76
77   setHelpFileName("shapesonshape_page.html");
78
79   Init();
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 // function : Init()
92 // purpose  :
93 //=================================================================================
94 void OperationGUI_GetShapesOnShapeDlg::Init()
95 {
96   // type for sub shape selection
97   GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_SOLID"));
98   // commented by skl for IPAL19949 - finder isn't allowed such type
99   //GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_SHELL"));
100   GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_FACE"));
101   // commented by skl for IPAL19949 - finder isn't allowed such type
102   //GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_WIRE"));
103   GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_EDGE"));
104   GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_VERTEX"));
105
106   // type for state selection
107   GroupPoints->ComboBox2->addItem(tr("GEOM_STATE_IN"));
108   GroupPoints->ComboBox2->addItem(tr("GEOM_STATE_OUT"));
109   GroupPoints->ComboBox2->addItem(tr("GEOM_STATE_ON"));
110   GroupPoints->ComboBox2->addItem(tr("GEOM_STATE_ONIN"));
111   GroupPoints->ComboBox2->addItem(tr("GEOM_STATE_ONOUT"));
112
113   GroupPoints->LineEdit1->clear();
114   GroupPoints->LineEdit2->clear();
115   myObject1 = myObject2 = GEOM::GEOM_Object::_nil();
116
117   // signals and slots connections
118   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
119   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
120
121   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
122   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
123
124   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
125   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
126
127   connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
128   connect(GroupPoints->ComboBox2, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
129
130   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
131           this, SLOT(SelectionIntoArgument()));
132
133   initName(mainFrame()->GroupConstructors->title());
134
135   GroupPoints->TextLabel3->show();
136   GroupPoints->ComboBox1->show();
137   GroupPoints->ComboBox1->setCurrentIndex(0);
138   GroupPoints->ComboBox2->show();
139   GroupPoints->ComboBox2->setCurrentIndex(0);
140
141   globalSelection(GEOM_ALLSHAPES);
142
143   GroupPoints->PushButton1->click();
144   SelectionIntoArgument();
145   resize(100,100);
146 }
147
148 //=================================================================================
149 // function : ClickOnOk()
150 // purpose  :
151 //=================================================================================
152 void OperationGUI_GetShapesOnShapeDlg::ClickOnOk()
153 {
154   if (ClickOnApply())
155     ClickOnCancel();
156 }
157
158 //=================================================================================
159 // function : ClickOnApply()
160 // purpose  :
161 //=================================================================================
162 bool OperationGUI_GetShapesOnShapeDlg::ClickOnApply()
163 {
164   if (!onAccept())
165     return false;
166
167   initName();
168   // activate first line edit
169   GroupPoints->PushButton1->click();
170   return true;
171 }
172
173 //=================================================================================
174 // function : SelectionIntoArgument()
175 // purpose  : Called when selection is changed or on dialog initialization or activation
176 //=================================================================================
177 void OperationGUI_GetShapesOnShapeDlg::SelectionIntoArgument()
178 {
179   myEditCurrentArgument->setText("");
180
181   if      (myEditCurrentArgument == GroupPoints->LineEdit1) myObject1 = GEOM::GEOM_Object::_nil();
182   else if (myEditCurrentArgument == GroupPoints->LineEdit2) myObject2 = GEOM::GEOM_Object::_nil();
183
184   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
185   SALOME_ListIO aSelList;
186   aSelMgr->selectedObjects(aSelList);
187
188   QString aName = "";
189   int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aName, true);
190
191   if (nbSel > 0) {
192     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
193     if ( GEOMBase::IsShape(aSelectedObject) ) {
194       myEditCurrentArgument->setText(aName);
195
196       // clear selection
197       disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
198       myGeomGUI->getApp()->selectionMgr()->clearSelected();
199       connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
200               this, SLOT(SelectionIntoArgument()));
201
202       if (myEditCurrentArgument == GroupPoints->LineEdit1) {
203         myObject1 = aSelectedObject;
204         if (myObject2->_is_nil())
205           GroupPoints->PushButton2->click();
206       }
207       else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
208         myObject2 = aSelectedObject;
209         if (myObject1->_is_nil())
210           GroupPoints->PushButton1->click();
211       }
212     }
213   }
214 }
215
216 //=================================================================================
217 // function : SetEditCurrentArgument()
218 // purpose  :
219 //=================================================================================
220 void OperationGUI_GetShapesOnShapeDlg::SetEditCurrentArgument()
221 {
222   QPushButton* send = (QPushButton*)sender();
223
224   if      (send == GroupPoints->PushButton1) {
225     myEditCurrentArgument = GroupPoints->LineEdit1;
226
227     GroupPoints->PushButton2->setDown(false);
228     GroupPoints->LineEdit2->setEnabled(false);
229   }
230   else if (send == GroupPoints->PushButton2) {
231     myEditCurrentArgument = GroupPoints->LineEdit2;
232
233     GroupPoints->PushButton1->setDown(false);
234     GroupPoints->LineEdit1->setEnabled(false);
235   }
236
237   // enable line edit
238   myEditCurrentArgument->setEnabled(true);
239   myEditCurrentArgument->setFocus();
240   // after setFocus(), because it will be setDown(false) when loses focus
241   send->setDown(true);
242 }
243
244 //=================================================================================
245 // function : LineEditReturnPressed()
246 // purpose  :
247 //=================================================================================
248 void OperationGUI_GetShapesOnShapeDlg::LineEditReturnPressed()
249 {
250   QLineEdit* send = (QLineEdit*)sender();
251   if (send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2)
252   {
253     myEditCurrentArgument = send;
254     GEOMBase_Skeleton::LineEditReturnPressed();
255   }
256 }
257
258 //=================================================================================
259 // function : ActivateThisDialog()
260 // purpose  :
261 //=================================================================================
262 void OperationGUI_GetShapesOnShapeDlg::ActivateThisDialog()
263 {
264   GEOMBase_Skeleton::ActivateThisDialog();
265   globalSelection(GEOM_ALLSHAPES);
266   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
267            this, SLOT( SelectionIntoArgument() ) );
268 }
269
270 //=================================================================================
271 // function : enterEvent()
272 // purpose  : when mouse enter onto the QWidget
273 //=================================================================================
274 void OperationGUI_GetShapesOnShapeDlg::enterEvent (QEvent*)
275 {
276   if (!mainFrame()->GroupConstructors->isEnabled())
277     ActivateThisDialog();
278 }
279
280 //=================================================================================
281 // function : createOperation
282 // purpose  :
283 //=================================================================================
284 GEOM::GEOM_IOperations_ptr OperationGUI_GetShapesOnShapeDlg::createOperation()
285 {
286   return getGeomEngine()->GetIShapesOperations(getStudyId());
287 }
288
289 //=================================================================================
290 // function : isValid
291 // purpose  :
292 //=================================================================================
293 bool OperationGUI_GetShapesOnShapeDlg::isValid(QString&)
294 {
295   //Handle(SALOME_InteractiveObject) IO = firstIObject();
296   //GEOM::GEOM_Object_var anObject = GEOMBase::ConvertIOinGEOMObject( IO );
297   //if ( anObject->_is_nil() )
298   //  return false;
299
300   return !CORBA::is_nil(myObject1) && !CORBA::is_nil(myObject2);
301 }
302
303 //=================================================================================
304 // function : execute
305 // purpose  :
306 //=================================================================================
307 bool OperationGUI_GetShapesOnShapeDlg::execute (ObjectList& objects)
308 {
309   int aLimit = GroupPoints->ComboBox1->currentIndex();
310   switch (aLimit)
311   {
312   case 0:  aLimit = GEOM::SOLID ; break;
313   case 1:  aLimit = GEOM::FACE  ; break;
314   case 2:  aLimit = GEOM::EDGE  ; break;
315   case 3:  aLimit = GEOM::VERTEX; break;
316   default: aLimit = GEOM::SHAPE ; break;
317   }
318
319   GEOM::shape_state aState;
320   switch (GroupPoints->ComboBox2->currentIndex())
321   {
322     case 0:  aState = GEOM::ST_IN;    break;
323     case 1:  aState = GEOM::ST_OUT;   break;
324     case 2:  aState = GEOM::ST_ON;    break;
325     case 3:  aState = GEOM::ST_ONIN;  break;
326     case 4:  aState = GEOM::ST_ONOUT; break;
327     default: break;
328   }
329
330   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation());
331   GEOM::GEOM_Object_var anObj = anOper->GetShapesOnShapeAsCompound(myObject2, myObject1,
332                                                                    (CORBA::Short) aLimit,
333                                                                    aState);
334
335   if (!anObj->_is_nil())
336     objects.push_back(anObj._retn());
337
338   return objects.size();
339 }
340
341 //=======================================================================
342 //function : ComboTextChanged
343 //purpose  :
344 //=======================================================================
345 void OperationGUI_GetShapesOnShapeDlg::ComboTextChanged()
346 {
347   // VRS ???? What is it for ??? commented for a while...
348   //bool IsEnabled = GroupPoints->ComboBox1->currentIndex() < 3;
349 }