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