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