]> SALOME platform Git repositories - modules/geom.git/blob - src/BuildGUI/BuildGUI_SolidDlg.cxx
Salome HOME
IMP 0016175: EDF455: Save GUIState don't redisplay the objects.
[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_MessageBox.h>
36 #include <SUIT_Session.h>
37 #include <SalomeApp_Application.h>
38 #include <LightApp_SelectionMgr.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   : GEOMBase_Skeleton( theGeometryGUI, parent )
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   setWindowTitle( tr( "GEOM_SOLID_TITLE" ) );
54     
55   /***************************************************************/
56   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SOLID" ) );
57   mainFrame()->RadioButton1->setIcon( image0 );
58   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
59   mainFrame()->RadioButton2->close();
60   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
61   mainFrame()->RadioButton3->close();
62
63   GroupSolid = new DlgRef_1Sel1Check( centralWidget() );
64
65   GroupSolid->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
66   GroupSolid->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
67   GroupSolid->CheckButton1->setText( tr( "GEOM_CREATE_SINGLE_SOLID" ) );
68   GroupSolid->PushButton1->setIcon( image1 );
69   GroupSolid->LineEdit1->setReadOnly( true );
70   
71   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
72   layout->setMargin( 0 ); layout->setSpacing( 6 );
73   layout->addWidget( GroupSolid );
74   /***************************************************************/
75
76   setHelpFileName("create_solid_page.html");
77
78   /* Initialisations */
79   Init();
80 }
81
82
83 //=================================================================================
84 // function : ~BuildGUI_SolidDlg()
85 // purpose  : Destroys the object and frees any allocated resources
86 //=================================================================================
87 BuildGUI_SolidDlg::~BuildGUI_SolidDlg()
88 {
89   // no need to delete child widgets, Qt does it all for us
90 }
91
92
93 //=================================================================================
94 // function : Init()
95 // purpose  :
96 //=================================================================================
97 void BuildGUI_SolidDlg::Init()
98 {
99   /* init variables */
100   myEditCurrentArgument = GroupSolid->LineEdit1;
101   GroupSolid->LineEdit1->setReadOnly( true );
102   GroupSolid->CheckButton1->setChecked( true );
103
104   myOkShells = false;
105
106   globalSelection( GEOM_SHELL );
107
108   /* signals and slots connections */
109   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
110   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
111
112   connect( GroupSolid->PushButton1,  SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
113   connect( GroupSolid->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( EnableNameField( bool ) ) );
114
115   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
116            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
117
118   initName( tr( "GEOM_SOLID" ) );
119 }
120
121
122 //=================================================================================
123 // function : ClickOnOk()
124 // purpose  :
125 //=================================================================================
126 void BuildGUI_SolidDlg::ClickOnOk()
127 {
128   if ( ClickOnApply() )
129     ClickOnCancel();
130 }
131
132 //=================================================================================
133 // function : ClickOnApply()
134 // purpose  :
135 //=================================================================================
136 bool BuildGUI_SolidDlg::ClickOnApply()
137 {
138   for ( int i = 0, n = myShells.length(); i< n; i++ ) {
139     if ( !isClosed(i)) {
140       QString aName = GEOMBase::GetName( myShells[i] );
141       SUIT_MessageBox::warning( (QWidget*)SUIT_Session::session()->activeApplication()->desktop(),
142                                  QObject::tr("WRN_WARNING"),
143                                  QObject::tr("WRN_SHAPE_UNCLOSED").arg(aName) ,
144                                  QObject::tr("BUT_OK") );
145        return false;
146     }
147   }
148
149   if ( !onAccept() )
150     return false;
151
152   initName();
153   return true;
154 }
155
156
157 //=================================================================================
158 // function : SelectionIntoArgument()
159 // purpose  : Called when selection as changed or other case
160 //=================================================================================
161 void BuildGUI_SolidDlg::SelectionIntoArgument()
162 {
163   myEditCurrentArgument->setText( "" );
164   QString aString = "";
165   
166   myOkShells = false;
167   int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString );
168   if ( nbSel == 0 )
169     return;
170   if ( nbSel != 1 )
171     aString = tr( "%1_objects" ).arg( nbSel );
172   
173   GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myShells );
174   if ( !myShells.length() )
175     return;
176   
177   myEditCurrentArgument->setText( aString );
178   myOkShells = true;
179 }
180
181 //=================================================================================
182 // function : SetEditCurrentArgument()
183 // purpose  :
184 //=================================================================================
185 void BuildGUI_SolidDlg::SetEditCurrentArgument()
186 {
187   QPushButton* send = (QPushButton*)sender();
188   if ( send != GroupSolid->PushButton1 )
189     return;
190   
191   globalSelection( GEOM_SHELL );
192   myEditCurrentArgument = GroupSolid->LineEdit1;
193
194   myEditCurrentArgument->setFocus();
195   SelectionIntoArgument();
196 }
197
198
199 //=================================================================================
200 // function : ActivateThisDialog()
201 // purpose  :
202 //=================================================================================
203 void BuildGUI_SolidDlg::ActivateThisDialog()
204 {
205   GEOMBase_Skeleton::ActivateThisDialog();
206   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
207            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
208   globalSelection( GEOM_SHELL );
209 }
210
211
212 //=================================================================================
213 // function : enterEvent()
214 // purpose  :
215 //=================================================================================
216 void BuildGUI_SolidDlg::enterEvent( QEvent* )
217 {
218   if ( !mainFrame()->GroupConstructors->isEnabled() )
219     ActivateThisDialog();
220 }
221
222
223 //=================================================================================
224 // function :  EnableNameField()
225 // purpose  :
226 //=================================================================================
227 void  BuildGUI_SolidDlg::EnableNameField( bool toEnable )
228 {
229   mainFrame()->GroupBoxName->setEnabled( toEnable ); 
230 }
231
232 //=================================================================================
233 // function : createOperation
234 // purpose  :
235 //=================================================================================
236 GEOM::GEOM_IOperations_ptr BuildGUI_SolidDlg::createOperation()
237 {
238   return getGeomEngine()->GetIShapesOperations( getStudyId() );
239 }
240
241 //=================================================================================
242 // function : isValid
243 // purpose  :
244 //=================================================================================
245 bool BuildGUI_SolidDlg::isValid( QString& )
246 {
247   return myOkShells;
248 }
249
250 //=================================================================================
251 // function : isClosed
252 // purpose  : Check the object 'i' in myShells list is closed or unclosed
253 //=================================================================================
254 bool BuildGUI_SolidDlg::isClosed(int i)
255 {
256   GEOM::GEOM_Object_var aShape = myShells[i];
257   GEOM::GEOM_IKindOfShape::shape_kind aKind;
258   GEOM::ListOfLong_var anInts;
259   GEOM::ListOfDouble_var aDbls;
260
261   if (aShape->_is_nil()) {
262     MESSAGE ("Shape is NULL!!!");
263     return false;
264   }
265
266   GEOM::GEOM_IMeasureOperations_ptr anOp = myGeomGUI->GetGeomGen()->GetIMeasureOperations( getStudyId() );
267
268   //  GEOM::GEOM_IMeasureOperations_var anOp = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
269
270   // Detect kind of shape and parameters
271   aKind = anOp->KindOfShape(aShape, anInts, aDbls);
272
273   if ( !anOp->IsDone() ) {
274     MESSAGE ("KindOfShape Operation is NOT DONE!!!");
275     return false;
276   }
277   
278   if ( anInts[0] == 1 )
279     return true;
280   else if ( anInts[0] == 2 )
281     return false;
282  
283   return false;
284 }
285
286 //=================================================================================
287 // function : execute
288 // purpose  :
289 //=================================================================================
290 bool BuildGUI_SolidDlg::execute( ObjectList& objects )
291 {
292   bool toCreateSingleSolid = GroupSolid->CheckButton1->isChecked();
293   
294   if ( toCreateSingleSolid ) {
295     GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow(
296       getOperation() )->MakeSolidShells( myShells );
297
298     if ( !anObj->_is_nil() )
299       objects.push_back( anObj._retn() );
300   }
301   else {
302     for ( int i = 0, n = myShells.length(); i< n; i++ ) {
303       GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow(
304         getOperation() )->MakeSolidShell( myShells[ i ] );
305
306      if ( !anObj->_is_nil() )
307        objects.push_back( anObj._retn() );
308     }
309   }
310
311   return true;
312 }
313