]> SALOME platform Git repositories - modules/geom.git/blob - src/OperationGUI/OperationGUI_PartitionDlg.cxx
Salome HOME
MPV: Merge V1_2d
[modules/geom.git] / src / OperationGUI / OperationGUI_PartitionDlg.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   : OperationGUI_PartitionDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "OperationGUI_PartitionDlg.h"
31
32 //=================================================================================
33 // class    : OperationGUI_PartitionDlg()
34 // purpose  : Constructs a OperationGUI_PartitionDlg which is a child of 'parent', with the 
35 //            name 'name' and widget flags set to 'f'.
36 //            The dialog will by default be modeless, unless you set 'modal' to
37 //            TRUE to construct a modal dialog.
38 //=================================================================================
39 OperationGUI_PartitionDlg::OperationGUI_PartitionDlg(QWidget* parent, const char* name, OperationGUI* theOperationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
40   :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
41 {
42   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_PARTITION")));
43   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
44
45   setCaption(tr("GEOM_PARTITION_TITLE"));
46
47   /***************************************************************/
48   GroupConstructors->setTitle(tr("GEOM_PARTITION"));
49   RadioButton1->setPixmap(image0);
50   RadioButton2->close(TRUE);
51   RadioButton3->close(TRUE);
52
53   GroupPoints = new DlgRef_4Sel1List_QTD(this, "GroupPoints");
54   GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
55   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
56   GroupPoints->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
57   GroupPoints->TextLabel3->setText(tr("GEOM_RECONSTRUCTION_LIMIT"));
58   GroupPoints->TextLabel4->setText(tr("GEOM_SUPPRESS_RESULT_INSIDE"));
59   GroupPoints->TextLabel5->setText(tr("GEOM_SUPPRESS_RESULT_OUTSIDE"));
60   GroupPoints->PushButton1->setPixmap(image1);
61   GroupPoints->PushButton2->setPixmap(image1);
62   GroupPoints->PushButton3->setPixmap(image1);
63   GroupPoints->PushButton4->setPixmap(image1);
64
65   Layout1->addWidget(GroupPoints, 1, 0);
66   /***************************************************************/
67
68   /* Initialisations */
69   myOperationGUI = theOperationGUI;
70   Init();
71 }
72
73
74 //=================================================================================
75 // function : ~OperationGUI_PartitionDlg()
76 // purpose  : Destroys the object and frees any allocated resources
77 //=================================================================================
78 OperationGUI_PartitionDlg::~OperationGUI_PartitionDlg()
79 {
80   // no need to delete child widgets, Qt does it all for us
81 }
82
83
84 //=================================================================================
85 // function : Init()
86 // purpose  :
87 //=================================================================================
88 void OperationGUI_PartitionDlg::Init()
89 {
90   /* init variables */
91   myEditCurrentArgument = GroupPoints->LineEdit1;
92
93   myOkListShapes = myOkListTools = myOkKeepShape = myOkRemoveShape = false;
94
95   /* type for sub shape selection */
96   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_SOLID"));
97   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_SHELL"));
98   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_FACE"));
99   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_WIRE"));
100   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_EDGE"));
101   GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_VERTEX"));
102
103   /* Current item is 'Shape' */
104   GroupPoints->ComboBox1->setCurrentItem(0);
105   myLimit = GroupPoints->ComboBox1->currentItem();
106
107   /* signals and slots connections */
108   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
109   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
110
111   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
112   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
113   connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
114   connect(GroupPoints->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
115
116   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
117   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
118   connect(GroupPoints->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
119   connect(GroupPoints->LineEdit4, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
120
121   connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
122   
123   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
124
125   /* displays Dialog */
126   GroupPoints->show();
127   this->show();
128
129   return;
130 }
131
132
133 //=================================================================================
134 // function : ClickOnOk()
135 // purpose  :
136 //=================================================================================
137 void OperationGUI_PartitionDlg::ClickOnOk()
138 {
139   this->ClickOnApply();
140   ClickOnCancel();
141   return;
142 }
143
144
145 //=================================================================================
146 // function : ClickOnApply()
147 // purpose  :
148 //=================================================================================
149 void OperationGUI_PartitionDlg::ClickOnApply()
150 {
151   QAD_Application::getDesktop()->putInfo(tr(""));
152
153   if(myOkListShapes || myOkListTools || myOkKeepShape || myOkRemoveShape) {
154     GEOM::shape_type limit;
155     switch(myLimit)
156       {
157       case 0 : 
158         {
159           limit = GEOM::SHAPE;
160           break;
161         }
162       case 1 :
163         {
164           limit = GEOM::SHELL;
165           break;
166         }
167       case 2 :
168         {
169           limit = GEOM::FACE;
170           break;
171         }
172       case 3 :
173         {
174           limit = GEOM::WIRE;
175           break;
176         }
177       case 4 :
178         {
179           limit = GEOM::EDGE;
180           break;
181         }
182       case 5 :
183         {
184           limit = GEOM::VERTEX;
185           break;
186         }
187       default :
188         limit = GEOM::SHAPE;
189       }
190
191     myOperationGUI->MakePartitionAndDisplay(myListShapes, myListTools, myListKeepInside, myListRemoveInside, limit);
192   }
193   return;
194 }
195
196
197 //=================================================================================
198 // function : SelectionIntoArgument()
199 // purpose  : Called when selection as changed or other case
200 //=================================================================================
201 void OperationGUI_PartitionDlg::SelectionIntoArgument()
202 {
203   myEditCurrentArgument->setText("");
204   QString aString = ""; /* name of selection */
205
206   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
207   if(nbSel < 1) {
208     if(myEditCurrentArgument == GroupPoints->LineEdit1) {
209       myListShapes.length(0);
210       myOkListShapes = false;
211     } else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
212       myListTools.length(0);
213       myOkListTools = false;
214     } else if(myEditCurrentArgument == GroupPoints->LineEdit3) {
215       myListRemoveInside.length(0);
216       myOkKeepShape = false;
217     } else if(myEditCurrentArgument == GroupPoints->LineEdit4) {
218       myListKeepInside.length(0);
219       myOkRemoveShape = false;
220     }
221     return;
222   }
223
224   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
225     myGeomBase->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListShapes);
226     myEditCurrentArgument->setText(aString);
227     myOkListShapes = true;
228   }
229   else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
230     myGeomBase->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListTools);
231     myEditCurrentArgument->setText(aString);
232     myOkListTools = true;
233   }
234   else if(myEditCurrentArgument == GroupPoints->LineEdit3) {
235     myGeomBase->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListRemoveInside);
236     myEditCurrentArgument->setText(aString);
237     myOkKeepShape = true;
238   }
239   else if(myEditCurrentArgument == GroupPoints->LineEdit4) {
240     myGeomBase->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListKeepInside);
241     myEditCurrentArgument->setText(aString);
242     myOkRemoveShape = true;
243   }
244
245   /* no simulation */
246   return;
247 }
248
249
250 //=================================================================================
251 // function : SetEditCurrentArgument()
252 // purpose  :
253 //=================================================================================
254 void OperationGUI_PartitionDlg::SetEditCurrentArgument()
255 {
256   QPushButton* send = (QPushButton*)sender();
257
258   if(send == GroupPoints->PushButton1) {
259     GroupPoints->LineEdit1->setFocus();
260     myEditCurrentArgument = GroupPoints->LineEdit1;
261   }
262   else if(send == GroupPoints->PushButton2) {
263     GroupPoints->LineEdit2->setFocus();
264     myEditCurrentArgument = GroupPoints->LineEdit2;
265   }
266   else if(send == GroupPoints->PushButton3) {
267     GroupPoints->LineEdit3->setFocus();
268     myEditCurrentArgument = GroupPoints->LineEdit3;
269   }
270   else if(send == GroupPoints->PushButton4) {
271     GroupPoints->LineEdit4->setFocus();
272     myEditCurrentArgument = GroupPoints->LineEdit4;
273   }
274   this->SelectionIntoArgument();
275
276   return;
277 }
278
279
280 //=================================================================================
281 // function : LineEditReturnPressed()
282 // purpose  :
283 //=================================================================================
284 void OperationGUI_PartitionDlg::LineEditReturnPressed()
285 {
286   QLineEdit* send = (QLineEdit*)sender();
287   if(send == GroupPoints->LineEdit1)
288     myEditCurrentArgument = GroupPoints->LineEdit1;
289   else if (send == GroupPoints->LineEdit2)
290     myEditCurrentArgument = GroupPoints->LineEdit2;
291   else if (send == GroupPoints->LineEdit3)
292     myEditCurrentArgument = GroupPoints->LineEdit3;
293   else if (send == GroupPoints->LineEdit4)
294     myEditCurrentArgument = GroupPoints->LineEdit4;
295   else
296     return;
297
298   GEOMBase_Skeleton::LineEditReturnPressed();
299   return;
300 }
301
302
303 //=================================================================================
304 // function : ActivateThisDialog()
305 // purpose  :
306 //=================================================================================
307 void OperationGUI_PartitionDlg::ActivateThisDialog()
308 {
309   GEOMBase_Skeleton::ActivateThisDialog();
310   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
311   return;
312 }
313
314
315 //=================================================================================
316 // function : enterEvent()
317 // purpose  :
318 //=================================================================================
319 void OperationGUI_PartitionDlg::enterEvent(QEvent* e)
320 {
321   if(GroupConstructors->isEnabled())
322     return;
323   this->ActivateThisDialog();
324   return;
325 }
326
327
328 //=======================================================================
329 //function : ComboTextChanged
330 //purpose  : 
331 //=======================================================================
332
333 void OperationGUI_PartitionDlg::ComboTextChanged()
334 {
335  myLimit = GroupPoints->ComboBox1->currentItem();
336
337  bool IsEnabled = GroupPoints->ComboBox1->currentItem() < 3;
338  GroupPoints->LineEdit3->setEnabled(IsEnabled);
339  GroupPoints->LineEdit4->setEnabled(IsEnabled);
340  GroupPoints->TextLabel4->setEnabled(IsEnabled);
341  GroupPoints->TextLabel5->setEnabled(IsEnabled);
342  GroupPoints->PushButton3->setEnabled(IsEnabled);
343  GroupPoints->PushButton4->setEnabled(IsEnabled);
344  return;
345 }