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