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