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