Salome HOME
Issue 0020194: EDF 977 ALL: Get rid of warnings PACKAGE_VERSION already defined
[modules/geom.git] / src / BuildGUI / BuildGUI_SolidDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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 // GEOM GEOMGUI : GUI for Geometry component
23 // File   : BuildGUI_SolidDlg.cxx
24 // Author : Damien COQUERET, Open CASCADE S.A.S.
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   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
167   SALOME_ListIO aSelList;
168   aSelMgr->selectedObjects(aSelList);
169
170   myOkShells = false;
171   int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString);
172   if ( nbSel == 0 )
173     return;
174   if ( nbSel != 1 )
175     aString = tr( "%1_objects" ).arg( nbSel );
176   
177   GEOMBase::ConvertListOfIOInListOfGO(aSelList, myShells);
178   if ( !myShells.length() )
179     return;
180   
181   myEditCurrentArgument->setText( aString );
182   myOkShells = true;
183 }
184
185 //=================================================================================
186 // function : SetEditCurrentArgument()
187 // purpose  :
188 //=================================================================================
189 void BuildGUI_SolidDlg::SetEditCurrentArgument()
190 {
191   QPushButton* send = (QPushButton*)sender();
192   if ( send != GroupSolid->PushButton1 )
193     return;
194   
195   globalSelection( GEOM_SHELL );
196   myEditCurrentArgument = GroupSolid->LineEdit1;
197
198   myEditCurrentArgument->setFocus();
199   SelectionIntoArgument();
200 }
201
202
203 //=================================================================================
204 // function : ActivateThisDialog()
205 // purpose  :
206 //=================================================================================
207 void BuildGUI_SolidDlg::ActivateThisDialog()
208 {
209   GEOMBase_Skeleton::ActivateThisDialog();
210   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
211            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
212   globalSelection( GEOM_SHELL );
213 }
214
215
216 //=================================================================================
217 // function : enterEvent()
218 // purpose  :
219 //=================================================================================
220 void BuildGUI_SolidDlg::enterEvent( QEvent* )
221 {
222   if ( !mainFrame()->GroupConstructors->isEnabled() )
223     ActivateThisDialog();
224 }
225
226
227 //=================================================================================
228 // function :  EnableNameField()
229 // purpose  :
230 //=================================================================================
231 void  BuildGUI_SolidDlg::EnableNameField( bool toEnable )
232 {
233   mainFrame()->GroupBoxName->setEnabled( toEnable ); 
234 }
235
236 //=================================================================================
237 // function : createOperation
238 // purpose  :
239 //=================================================================================
240 GEOM::GEOM_IOperations_ptr BuildGUI_SolidDlg::createOperation()
241 {
242   return getGeomEngine()->GetIShapesOperations( getStudyId() );
243 }
244
245 //=================================================================================
246 // function : isValid
247 // purpose  :
248 //=================================================================================
249 bool BuildGUI_SolidDlg::isValid( QString& )
250 {
251   return myOkShells;
252 }
253
254 //=================================================================================
255 // function : isClosed
256 // purpose  : Check the object 'i' in myShells list is closed or unclosed
257 //=================================================================================
258 bool BuildGUI_SolidDlg::isClosed(int i)
259 {
260   GEOM::GEOM_Object_var aShape = myShells[i];
261   GEOM::GEOM_IKindOfShape::shape_kind aKind;
262   GEOM::ListOfLong_var anInts;
263   GEOM::ListOfDouble_var aDbls;
264
265   if (aShape->_is_nil()) {
266     MESSAGE ("Shape is NULL!!!");
267     return false;
268   }
269
270   GEOM::GEOM_IMeasureOperations_ptr anOp = myGeomGUI->GetGeomGen()->GetIMeasureOperations( getStudyId() );
271
272   //  GEOM::GEOM_IMeasureOperations_var anOp = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
273
274   // Detect kind of shape and parameters
275   aKind = anOp->KindOfShape(aShape, anInts, aDbls);
276
277   if ( !anOp->IsDone() ) {
278     MESSAGE ("KindOfShape Operation is NOT DONE!!!");
279     return false;
280   }
281   
282   if ( anInts[0] == 1 )
283     return true;
284   else if ( anInts[0] == 2 )
285     return false;
286  
287   return false;
288 }
289
290 //=================================================================================
291 // function : execute
292 // purpose  :
293 //=================================================================================
294 bool BuildGUI_SolidDlg::execute( ObjectList& objects )
295 {
296   bool toCreateSingleSolid = GroupSolid->CheckButton1->isChecked();
297   
298   if ( toCreateSingleSolid ) {
299     GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow(
300       getOperation() )->MakeSolidShells( myShells );
301
302     if ( !anObj->_is_nil() )
303       objects.push_back( anObj._retn() );
304   }
305   else {
306     for ( int i = 0, n = myShells.length(); i< n; i++ ) {
307       GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow(
308         getOperation() )->MakeSolidShell( myShells[ i ] );
309
310      if ( !anObj->_is_nil() )
311        objects.push_back( anObj._retn() );
312     }
313   }
314
315   return true;
316 }
317