Salome HOME
DCQ : New Architecture
[modules/geom.git] / src / BuildGUI / BuildGUI_FaceDlg.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   : BuildGUI_FaceDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "BuildGUI_FaceDlg.h"
31
32 //=================================================================================
33 // class    : BuildGUI_FaceDlg()
34 // purpose  : Constructs a BuildGUI_FaceDlg 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 BuildGUI_FaceDlg::BuildGUI_FaceDlg(QWidget* parent, const char* name, BuildGUI* theBuildGUI, 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_BUILD_FACE")));
43   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
44
45   setCaption(tr("GEOM_FACE_TITLE"));
46
47   /***************************************************************/
48   GroupConstructors->setTitle(tr("GEOM_FACE"));
49   RadioButton1->setPixmap(image0);
50   RadioButton2->close(TRUE);
51   RadioButton3->close(TRUE);
52
53   GroupPoints = new DlgRef_1Sel1Check_QTD(this, "GroupPoints");
54   GroupPoints->GroupBox1->setTitle(tr("GEOM_FACE_FFW"));
55   GroupPoints->TextLabel1->setText(tr("GEOM_WIRE"));
56   GroupPoints->CheckButton1->setText(tr("GEOM_FACE_OPT"));
57   GroupPoints->PushButton1->setPixmap(image1);
58
59   Layout1->addWidget(GroupPoints, 1, 0);
60   /***************************************************************/
61
62   /* Initialisations */
63   myBuildGUI = theBuildGUI;
64   Init();
65 }
66
67
68 //=================================================================================
69 // function : ~BuildGUI_FaceDlg()
70 // purpose  : Destroys the object and frees any allocated resources
71 //=================================================================================
72 BuildGUI_FaceDlg::~BuildGUI_FaceDlg()
73 {
74   // no need to delete child widgets, Qt does it all for us
75 }
76
77
78 //=================================================================================
79 // function : Init()
80 // purpose  :
81 //=================================================================================
82 void BuildGUI_FaceDlg::Init()
83 {
84   /* init variables */
85   myEditCurrentArgument = GroupPoints->LineEdit1;
86   GroupPoints->CheckButton1->setChecked(TRUE);
87
88   myOkShape = false;
89
90   myWireFilter = new GEOM_ShapeTypeFilter(TopAbs_WIRE, myGeom);
91   mySelection->AddFilter(myWireFilter); /* first filter used */
92
93   /* signals and slots connections */
94   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
95   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
96   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
97   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));  
98   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
99
100   /* displays Dialog */
101   GroupPoints->show();
102   this->show();
103
104   return;
105 }
106
107
108 //=================================================================================
109 // function : ClickOnOk()
110 // purpose  :
111 //=================================================================================
112 void BuildGUI_FaceDlg::ClickOnOk()
113 {
114   this->ClickOnApply();
115   ClickOnCancel();
116   return;
117 }
118
119
120 //=================================================================================
121 // function : ClickOnApply()
122 // purpose  :
123 //=================================================================================
124 void BuildGUI_FaceDlg::ClickOnApply()
125 {
126   QAD_Application::getDesktop()->putInfo(tr(""));
127   if(myOkShape)   
128     myBuildGUI->MakeFaceAndDisplay(myGeomShape, GroupPoints->CheckButton1->isChecked());
129   return;
130 }
131
132
133 //=================================================================================
134 // function : SelectionIntoArgument()
135 // purpose  : Called when selection as changed or other case
136 //=================================================================================
137 void BuildGUI_FaceDlg::SelectionIntoArgument()
138 {
139   myEditCurrentArgument->setText("");
140   QString aString = ""; /* name of selection */
141
142   myOkShape = false;
143   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
144   if(nbSel != 1) {
145     return;
146   }
147   
148   // nbSel == 1!
149   Standard_Boolean testResult;
150   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
151   if(!myGeomBase->GetTopoFromSelection(mySelection, myShape))
152     return;
153
154   myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
155   if(!testResult)
156     return;
157
158   myEditCurrentArgument->setText(aString);
159   myOkShape = true;
160   /* no simulation */
161   return;
162 }
163
164
165 //=================================================================================
166 // function : SetEditCurrentArgument()
167 // purpose  :
168 //=================================================================================
169 void BuildGUI_FaceDlg::SetEditCurrentArgument()
170 {
171   GroupPoints->LineEdit1->setFocus();
172   mySelection->ClearFilters();
173   mySelection->AddFilter(myWireFilter);
174   this->SelectionIntoArgument();
175   return;
176 }
177
178
179 //=================================================================================
180 // function : LineEditReturnPressed()
181 // purpose  :
182 //=================================================================================
183 void BuildGUI_FaceDlg::LineEditReturnPressed()
184 {
185   QLineEdit* send = (QLineEdit*)sender();
186   if(send == GroupPoints->LineEdit1)
187     myEditCurrentArgument = GroupPoints->LineEdit1;
188   else
189     return;
190
191   GEOMBase_Skeleton::LineEditReturnPressed();
192   return;
193 }
194
195
196 //=================================================================================
197 // function : ActivateThisDialog()
198 // purpose  :
199 //=================================================================================
200 void BuildGUI_FaceDlg::ActivateThisDialog()
201 {
202   GEOMBase_Skeleton::ActivateThisDialog();
203   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
204   mySelection->AddFilter(myWireFilter);
205   return;
206 }
207
208
209 //=================================================================================
210 // function : enterEvent()
211 // purpose  :
212 //=================================================================================
213 void BuildGUI_FaceDlg::enterEvent(QEvent* e)
214 {
215   if (GroupConstructors->isEnabled())
216     return;
217   this->ActivateThisDialog();
218   return;
219 }