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