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