]> SALOME platform Git repositories - modules/geom.git/blob - src/BooleanGUI/BooleanGUI_CutDlg.cxx
Salome HOME
DCQ : Add Multi-Wire for MakeFace
[modules/geom.git] / src / BooleanGUI / BooleanGUI_CutDlg.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   : BooleanGUI_CutDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "BooleanGUI_CutDlg.h"
31
32 //=================================================================================
33 // class    : BooleanGUI_CutDlg()
34 // purpose  : Constructs a BooleanGUI_CutDlg 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 BooleanGUI_CutDlg::BooleanGUI_CutDlg(QWidget* parent, const char* name, BooleanGUI* theBooleanGUI, 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_CUT")));
43   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
44
45   setCaption(tr("GEOM_CUT_TITLE"));
46
47   /***************************************************************/
48   GroupConstructors->setTitle(tr("GEOM_CUT"));
49   RadioButton1->setPixmap(image0);
50   RadioButton2->close(TRUE);
51   RadioButton3->close(TRUE);
52
53   GroupCut = new DlgRef_2Sel_QTD(this, "GroupCut");
54   GroupCut->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
55   GroupCut->TextLabel1->setText(tr("GEOM_OBJECT_I").arg("1"));
56   GroupCut->TextLabel2->setText(tr("GEOM_OBJECT_I").arg("2"));
57   GroupCut->PushButton1->setPixmap(image1);
58   GroupCut->PushButton2->setPixmap(image1);
59
60   Layout1->addWidget(GroupCut, 1, 0);
61   /***************************************************************/
62
63   /* Initialisation */
64   myBooleanGUI = theBooleanGUI;
65   Init();
66 }
67
68
69 //=================================================================================
70 // function : ~BooleanGUI_CutDlg()
71 // purpose  : Destroys the object and frees any allocated resources
72 //=================================================================================
73 BooleanGUI_CutDlg::~BooleanGUI_CutDlg()
74 {  
75   /* no need to delete child widgets, Qt does it all for us */
76 }
77
78
79 //=================================================================================
80 // function : Init()
81 // purpose  :
82 //=================================================================================
83 void BooleanGUI_CutDlg::Init()
84 {  
85   /* init variables */
86   myEditCurrentArgument = GroupCut->LineEdit1;
87   myOkShape1 = myOkShape2 = false;
88
89    /* signals and slots connections */
90   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
91   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
92
93   connect(GroupCut->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
94   connect(GroupCut->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
95
96   connect(GroupCut->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
97   connect(GroupCut->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
98
99   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
100
101   /* displays Dialog */
102   GroupCut->show();
103   this->show();
104
105   return;
106 }
107
108
109 //=================================================================================
110 // function : ClickOnOk()
111 // purpose  :
112 //=================================================================================
113 void BooleanGUI_CutDlg::ClickOnOk()
114 {
115   this->ClickOnApply();
116   ClickOnCancel();
117   return ;
118 }
119
120
121 //=================================================================================
122 // function : ClickOnApply()
123 // purpose  :
124 //=================================================================================
125 void BooleanGUI_CutDlg::ClickOnApply()
126 {
127   QAD_Application::getDesktop()->putInfo(tr(""));
128
129   if(myOkShape1 && myOkShape2)
130     myBooleanGUI->MakeBooleanAndDisplay(myGeomShape1 ,myGeomShape2, 2);
131
132   return;
133 }
134
135
136 //=================================================================================
137 // function : SelectionIntoArgument()
138 // purpose  : Called when selection has changed
139 //=================================================================================
140 void BooleanGUI_CutDlg::SelectionIntoArgument()
141 {
142   myEditCurrentArgument->setText("");
143   QString aString = "";
144
145   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
146   if(nbSel != 1) {
147     if(myEditCurrentArgument == GroupCut->LineEdit1)
148       myOkShape1 = false;
149     else if( myEditCurrentArgument == GroupCut->LineEdit2)
150       myOkShape2 = false;
151     return;
152   }
153
154   /*  nbSel == 1  */
155   TopoDS_Shape S;
156   Standard_Boolean testResult;
157   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
158
159   if(!myGeomBase->GetTopoFromSelection(mySelection, S))
160     return;
161
162   if(myEditCurrentArgument == GroupCut->LineEdit1) {
163     myGeomShape1 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
164     if(!testResult)
165       return;
166     GroupCut->LineEdit1->setText(aString);
167     myOkShape1 = true;
168   }
169   else if(myEditCurrentArgument == GroupCut->LineEdit2) {
170     myGeomShape2 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
171     if(!testResult)
172       return;
173     GroupCut->LineEdit2->setText(aString);
174     myOkShape2 = true;
175   }
176   return;
177 }
178
179
180 //=================================================================================
181 // function : SetEditCurrentArgument()
182 // purpose  :
183 //=================================================================================
184 void BooleanGUI_CutDlg::SetEditCurrentArgument()
185 {
186   QPushButton* send = (QPushButton*)sender();
187
188   if(send == GroupCut->PushButton1) {
189     GroupCut->LineEdit1->setFocus();
190     myEditCurrentArgument = GroupCut->LineEdit1;
191   }
192   else if(send == GroupCut->PushButton2) {
193     GroupCut->LineEdit2->setFocus();
194     myEditCurrentArgument = GroupCut->LineEdit2;
195   }
196   SelectionIntoArgument();
197
198   return;
199 }
200
201
202 //=================================================================================
203 // function : LineEditReturnPressed()
204 // purpose  :
205 //=================================================================================
206 void BooleanGUI_CutDlg::LineEditReturnPressed()
207 {
208   QLineEdit* send = (QLineEdit*)sender();
209   if(send == GroupCut->LineEdit1)
210     myEditCurrentArgument = GroupCut->LineEdit1;
211   else if(send == GroupCut->LineEdit2)
212     myEditCurrentArgument = GroupCut->LineEdit2;
213   else
214     return;
215
216   GEOMBase_Skeleton::LineEditReturnPressed();
217   return;
218 }
219
220
221 //=================================================================================
222 // function : ActivateThisDialog()
223 // purpose  :
224 //=================================================================================
225 void BooleanGUI_CutDlg::ActivateThisDialog()
226 {
227   GEOMBase_Skeleton::ActivateThisDialog();
228   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
229   return;
230 }
231
232
233 //=================================================================================
234 // function : enterEvent()
235 // purpose  : when mouse enter onto the QWidget
236 //=================================================================================
237 void BooleanGUI_CutDlg::enterEvent(QEvent * e)
238 {
239   if(GroupConstructors->isEnabled())
240     return;
241   this->ActivateThisDialog();
242   return;
243 }