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