Salome HOME
2edaf57b90e539f515949d54cbdd42ea4abd11d4
[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   myOkListShapes = 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(myOkListShapes)
128     myBuildGUI->MakeFaceAndDisplay(myListShapes, 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   myOkListShapes = false;
143   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
144   if(nbSel == 0)
145     return;
146   if(nbSel != 1)
147     aString = tr("%1_objects").arg(nbSel);
148
149   myGeomBase->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListShapes);
150   
151   myEditCurrentArgument->setText(aString);
152   myOkListShapes = true;
153   /* no simulation */
154   return;
155 }
156
157
158 //=================================================================================
159 // function : SetEditCurrentArgument()
160 // purpose  :
161 //=================================================================================
162 void BuildGUI_FaceDlg::SetEditCurrentArgument()
163 {
164   GroupPoints->LineEdit1->setFocus();
165   mySelection->ClearFilters();
166   mySelection->AddFilter(myWireFilter);
167   this->SelectionIntoArgument();
168   return;
169 }
170
171
172 //=================================================================================
173 // function : ActivateThisDialog()
174 // purpose  :
175 //=================================================================================
176 void BuildGUI_FaceDlg::ActivateThisDialog()
177 {
178   GEOMBase_Skeleton::ActivateThisDialog();
179   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
180   mySelection->AddFilter(myWireFilter);
181   return;
182 }
183
184
185 //=================================================================================
186 // function : enterEvent()
187 // purpose  :
188 //=================================================================================
189 void BuildGUI_FaceDlg::enterEvent(QEvent* e)
190 {
191   if (GroupConstructors->isEnabled())
192     return;
193   this->ActivateThisDialog();
194   return;
195 }