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