Salome HOME
Using files from package LightApp instead of SalomeApp
[modules/geom.git] / src / BuildGUI / BuildGUI_SolidDlg.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_SolidDlg.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27 //  $Header: 
28
29 #include "BuildGUI_SolidDlg.h"
30 #include "GEOMImpl_Types.hxx"
31
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
35
36 //Qt includes
37 #include <qcheckbox.h>
38 #include <qlabel.h>
39
40 //=================================================================================
41 // class    : BuildGUI_SolidDlg()
42 // purpose  : Constructs a BuildGUI_SolidDlg 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_SolidDlg::BuildGUI_SolidDlg(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_SOLID")));
51   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
52
53   setCaption(tr("GEOM_SOLID_TITLE"));
54     
55   /***************************************************************/
56   GroupConstructors->setTitle(tr("GEOM_SOLID"));
57   RadioButton1->setPixmap(image0);
58   RadioButton2->close(TRUE);
59   RadioButton3->close(TRUE);
60
61   GroupSolid = new DlgRef_1Sel1Check_QTD(this, "GroupSolid");
62   GroupSolid->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
63   GroupSolid->TextLabel1->setText(tr("GEOM_OBJECTS"));
64   GroupSolid->CheckButton1->setText(tr("GEOM_CREATE_SINGLE_SOLID"));
65   GroupSolid->PushButton1->setPixmap(image1);
66   GroupSolid->LineEdit1->setReadOnly( true );
67   
68   Layout1->addWidget(GroupSolid, 2, 0);
69   /***************************************************************/
70
71   /* Initialisations */
72   Init();
73 }
74
75
76 //=================================================================================
77 // function : ~BuildGUI_SolidDlg()
78 // purpose  : Destroys the object and frees any allocated resources
79 //=================================================================================
80 BuildGUI_SolidDlg::~BuildGUI_SolidDlg()
81 {
82     // no need to delete child widgets, Qt does it all for us
83 }
84
85
86 //=================================================================================
87 // function : Init()
88 // purpose  :
89 //=================================================================================
90 void BuildGUI_SolidDlg::Init()
91 {
92   /* init variables */
93   myEditCurrentArgument = GroupSolid->LineEdit1;
94   GroupSolid->LineEdit1->setReadOnly( true );
95   GroupSolid->CheckButton1->setChecked( true );
96
97   myOkShells = false;
98
99   globalSelection( GEOM_SHELL );
100
101   /* signals and slots connections */
102   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
103   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
104
105   connect(GroupSolid->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
106   connect(GroupSolid->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(EnableNameField(bool)));
107
108   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
109           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
110
111   initName(tr("GEOM_SOLID"));
112 }
113
114
115 //=================================================================================
116 // function : ClickOnOk()
117 // purpose  :
118 //=================================================================================
119 void BuildGUI_SolidDlg::ClickOnOk()
120 {
121   if ( ClickOnApply() )
122     ClickOnCancel();
123 }
124
125 //=================================================================================
126 // function : ClickOnApply()
127 // purpose  :
128 //=================================================================================
129 bool BuildGUI_SolidDlg::ClickOnApply()
130 {
131   if ( !onAccept() )
132     return false;
133
134   initName();
135   return true;
136 }
137
138
139 //=================================================================================
140 // function : SelectionIntoArgument()
141 // purpose  : Called when selection as changed or other case
142 //=================================================================================
143 void BuildGUI_SolidDlg::SelectionIntoArgument()
144 {
145   myEditCurrentArgument->setText("");
146   QString aString = "";
147   
148   myOkShells = false;
149   int nbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aString);
150   if (nbSel == 0) 
151     return;
152   if(nbSel != 1)
153     aString = tr("%1_objects").arg(nbSel);
154   
155   GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myShells);
156   if (!myShells.length()) 
157     return;
158   
159   myEditCurrentArgument->setText(aString);
160   myOkShells = true;
161 }
162
163 //=================================================================================
164 // function : SetEditCurrentArgument()
165 // purpose  :
166 //=================================================================================
167 void BuildGUI_SolidDlg::SetEditCurrentArgument()
168 {
169   QPushButton* send = (QPushButton*)sender();
170   if(send != GroupSolid->PushButton1)
171     return;
172   
173   globalSelection( GEOM_SHELL );
174   myEditCurrentArgument = GroupSolid->LineEdit1;
175
176   myEditCurrentArgument->setFocus();
177   SelectionIntoArgument();
178 }
179
180
181 //=================================================================================
182 // function : ActivateThisDialog()
183 // purpose  :
184 //=================================================================================
185 void BuildGUI_SolidDlg::ActivateThisDialog()
186 {
187   GEOMBase_Skeleton::ActivateThisDialog();
188   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
189           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
190   globalSelection( GEOM_SHELL );
191 }
192
193
194 //=================================================================================
195 // function : enterEvent()
196 // purpose  :
197 //=================================================================================
198 void BuildGUI_SolidDlg::enterEvent(QEvent* e)
199 {
200   if ( !GroupConstructors->isEnabled() )
201     ActivateThisDialog();
202 }
203
204
205 //=================================================================================
206 // function :  EnableNameField()
207 // purpose  :
208 //=================================================================================
209 void  BuildGUI_SolidDlg::EnableNameField(bool toEnable)
210 {
211   this->GroupBoxName->setEnabled(toEnable); 
212 }
213
214 //=================================================================================
215 // function : createOperation
216 // purpose  :
217 //=================================================================================
218 GEOM::GEOM_IOperations_ptr BuildGUI_SolidDlg::createOperation()
219 {
220   return getGeomEngine()->GetIShapesOperations( getStudyId() );
221 }
222
223 //=================================================================================
224 // function : isValid
225 // purpose  :
226 //=================================================================================
227 bool BuildGUI_SolidDlg::isValid( QString& )
228 {
229   return myOkShells;
230 }
231
232 //=================================================================================
233 // function : execute
234 // purpose  :
235 //=================================================================================
236 bool BuildGUI_SolidDlg::execute( ObjectList& objects )
237 {
238   bool toCreateSingleSolid = GroupSolid->CheckButton1->isChecked();
239   
240   if ( toCreateSingleSolid )
241   {
242     GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow(
243       getOperation() )->MakeSolidShells( myShells );
244
245     if ( !anObj->_is_nil() )
246       objects.push_back( anObj._retn() );
247   }
248   else
249   {
250     for ( int i = 0, n = myShells.length(); i< n; i++ )
251     {
252       GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow(
253         getOperation() )->MakeSolidShell( myShells[ i ] );
254
255      if ( !anObj->_is_nil() )
256        objects.push_back( anObj._retn() );
257     }
258   }
259
260   return true;
261 }
262