]> SALOME platform Git repositories - modules/geom.git/blob - src/BuildGUI/BuildGUI_ShellDlg.cxx
Salome HOME
Porting to Qt4.
[modules/geom.git] / src / BuildGUI / BuildGUI_ShellDlg.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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : BuildGUI_ShellDlg.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27 //  $Header$
28
29 #include "BuildGUI_ShellDlg.h"
30 #include "GEOMImpl_Types.hxx"
31
32 #include "GeometryGUI.h"
33 #include "GEOMBase.h"
34
35 #include "SUIT_ResourceMgr.h"
36 #include "SUIT_Session.h"
37 #include "SalomeApp_Application.h"
38 #include "LightApp_SelectionMgr.h"
39
40 #include "TColStd_MapOfInteger.hxx"
41
42 //=================================================================================
43 // class    : BuildGUI_ShellDlg()
44 // purpose  : Constructs a BuildGUI_ShellDlg which is a child of 'parent', with the 
45 //            name 'name' and widget flags set to 'f'.
46 //            The dialog will by default be modeless, unless you set 'modal' to
47 //            TRUE to construct a modal dialog.
48 //=================================================================================
49 BuildGUI_ShellDlg::BuildGUI_ShellDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
50                                      const char* name, bool modal, Qt::WindowFlags fl)
51   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
52 {
53   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BUILD_SHELL")));
54   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
55
56   setWindowTitle(tr("GEOM_SHELL_TITLE"));
57     
58   /***************************************************************/
59   GroupConstructors->setTitle(tr("GEOM_SHELL"));
60   RadioButton1->setIcon(image0);
61   RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
62   RadioButton2->close();
63   RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
64   RadioButton3->close();
65
66   GroupShell = new Ui::DlgRef_1Sel_QTD();
67   QWidget* aGroupShellWidget = new QWidget(this);
68   GroupShell->setupUi(aGroupShellWidget);
69   aGroupShellWidget->setObjectName("GroupShell");
70
71   GroupShell->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
72   GroupShell->TextLabel1->setText(tr("GEOM_OBJECTS"));
73   GroupShell->PushButton1->setIcon(image1);
74   GroupShell->LineEdit1->setReadOnly( true );
75   
76   gridLayout1->addWidget(aGroupShellWidget, 2, 0);
77   /***************************************************************/
78
79   setHelpFileName("shell.htm");
80
81   /* Initialisations */
82   Init();
83 }
84
85
86 //=================================================================================
87 // function : ~BuildGUI_ShellDlg()
88 // purpose  : Destroys the object and frees any allocated resources
89 //=================================================================================
90 BuildGUI_ShellDlg::~BuildGUI_ShellDlg()
91 {
92     // no need to delete child widgets, Qt does it all for us
93 }
94
95
96 //=================================================================================
97 // function : Init()
98 // purpose  :
99 //=================================================================================
100 void BuildGUI_ShellDlg::Init()
101 {
102   /* init variables */
103   myEditCurrentArgument = GroupShell->LineEdit1;
104   GroupShell->LineEdit1->setReadOnly( true );
105   
106   myOkFacesAndShells = false;
107   
108   TColStd_MapOfInteger aMap;
109   aMap.Add(GEOM_SHELL);
110   aMap.Add(GEOM_FACE);
111   globalSelection( aMap );
112
113   /* signals and slots connections */
114   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
115   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
116
117   connect(GroupShell->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
118
119   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
120           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
121
122   initName(tr("GEOM_SHELL").toStdString().c_str());
123 }
124
125
126 //=================================================================================
127 // function : ClickOnOk()
128 // purpose  :
129 //=================================================================================
130 void BuildGUI_ShellDlg::ClickOnOk()
131 {
132   if ( ClickOnApply() )
133     ClickOnCancel();
134 }
135
136
137 //=================================================================================
138 // function : ClickOnApply()
139 // purpose  :
140 //=================================================================================
141 bool BuildGUI_ShellDlg::ClickOnApply()
142 {
143   if ( !onAccept() )
144     return false;
145
146   initName();
147   return true;
148 }
149
150
151 //=================================================================================
152 // function : SelectionIntoArgument()
153 // purpose  : Called when selection as changed or other case
154 //=================================================================================
155 void BuildGUI_ShellDlg::SelectionIntoArgument()
156 {
157   myEditCurrentArgument->setText( "" );
158   QString aString;
159
160   myOkFacesAndShells = false;
161   int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
162   if ( nbSel == 0 )
163     return;
164   if ( nbSel != 1 )
165     aString = QString( "%1_objects ").arg( nbSel );
166
167   GEOMBase::ConvertListOfIOInListOfGO( selectedIO(),  myFacesAndShells, true );
168   if ( !myFacesAndShells.length() )
169     return;
170
171   myEditCurrentArgument->setText( aString );
172   myOkFacesAndShells = true;
173 }
174
175
176 //=================================================================================
177 // function : SetEditCurrentArgument()
178 // purpose  :
179 //=================================================================================
180 void BuildGUI_ShellDlg::SetEditCurrentArgument()
181 {
182   QPushButton* send = (QPushButton*)sender();
183   if (send != GroupShell->PushButton1)
184     return;
185
186   TColStd_MapOfInteger aMap;
187   aMap.Add(GEOM_SHELL);
188   aMap.Add(GEOM_FACE);
189   globalSelection( aMap );
190   myEditCurrentArgument = GroupShell->LineEdit1;
191
192   myEditCurrentArgument->setFocus();
193   SelectionIntoArgument();
194 }
195
196
197 //=================================================================================
198 // function : ActivateThisDialog()
199 // purpose  :
200 //=================================================================================
201 void BuildGUI_ShellDlg::ActivateThisDialog()
202 {
203   GEOMBase_Skeleton::ActivateThisDialog();
204   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
205           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
206   TColStd_MapOfInteger aMap;
207   aMap.Add(GEOM_SHELL);
208   aMap.Add(GEOM_FACE);
209   globalSelection( aMap );
210 }
211
212
213 //=================================================================================
214 // function : enterEvent()
215 // purpose  :
216 //=================================================================================
217 void BuildGUI_ShellDlg::enterEvent(QEvent* e)
218 {
219   if ( !GroupConstructors->isEnabled() )
220     ActivateThisDialog();
221 }
222
223 //=================================================================================
224 // function : createOperation
225 // purpose  :
226 //=================================================================================
227 GEOM::GEOM_IOperations_ptr BuildGUI_ShellDlg::createOperation()
228 {
229   return getGeomEngine()->GetIShapesOperations( getStudyId() );
230 }
231
232 //=================================================================================
233 // function : isValid
234 // purpose  :
235 //=================================================================================
236 bool BuildGUI_ShellDlg::isValid( QString& )
237 {
238   return myOkFacesAndShells;
239 }
240
241 //=================================================================================
242 // function : execute
243 // purpose  :
244 //=================================================================================
245 bool BuildGUI_ShellDlg::execute( ObjectList& objects )
246 {
247   GEOM::GEOM_Object_var anObj;
248
249   anObj = GEOM::GEOM_IShapesOperations::_narrow(
250     getOperation() )->MakeShell( myFacesAndShells );
251
252   if ( !anObj->_is_nil() )
253     objects.push_back( anObj._retn() );
254
255   return true;
256 }
257