Salome HOME
493ca2337b2a3c7a7f38f2dab2ddc81dbdabe4ac
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Helper.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 // SMESH SMESHGUI : GUI for SMESH component
23 // File   : SMESHGUI_Helper.cxx
24 // Author : Oleg UVAROV
25 // SMESH includes
26 //
27 #include "SMESHGUI_Helper.h"
28 #include "SMESHGUI.h"
29
30 // SALOME GUI includes
31 #include <SUIT_Desktop.h>
32 #include <SUIT_MessageBox.h>
33 #include <SUIT_Session.h>
34
35 #include <SalomeApp_Application.h>
36 #include <SalomeApp_DoubleSpinBox.h>
37 #include <SalomeApp_IntSpinBox.h>
38 #include <SalomeApp_Notebook.h>
39
40 // IDL includes
41 //#include <SALOMEconfig.h>
42 //#include CORBA_SERVER_HEADER(SMESH_Mesh)
43 //#include CORBA_SERVER_HEADER(SMESH_MeshEditor)
44
45 //=================================================================================
46 // name    : SMESHGUI_Helper::SMESHGUI_Helper
47 // Purpose :
48 //=================================================================================
49 SMESHGUI_Helper::SMESHGUI_Helper( SMESHGUI* theModule ) :
50   mySMESHGUI( theModule ),
51   myNotebook( 0 )
52 {
53 }
54
55 //=======================================================================
56 // name    : SMESHGUI_Helper::~SMESHGUI_Helper
57 // Purpose :
58 //=======================================================================
59 SMESHGUI_Helper::~SMESHGUI_Helper()
60 {
61   if( myNotebook )
62   {
63     delete myNotebook;
64     myNotebook = 0;
65   }
66 }
67
68 //================================================================
69 // Function : checkParameters
70 // Purpose  :
71 //================================================================
72 bool SMESHGUI_Helper::checkParameters( bool theMess, int theCount, QAbstractSpinBox* theFirstSpinBox, ... )
73 {
74   va_list aSpins;
75   va_start( aSpins, theFirstSpinBox );
76
77   int aCounter = 0;
78   QList<QAbstractSpinBox*> aSpinBoxList;
79   QAbstractSpinBox* aSpinBox = theFirstSpinBox;
80   while( aSpinBox && aCounter < theCount )
81   {
82     aSpinBoxList.append( aSpinBox );
83     aSpinBox = va_arg( aSpins, QAbstractSpinBox* );
84     aCounter++;
85   }
86   return checkParameters( theMess, aSpinBoxList );
87 }
88
89 //================================================================
90 // Function : checkParameters
91 // Purpose  :
92 //================================================================
93 bool SMESHGUI_Helper::checkParameters( bool theMess, const QList<QAbstractSpinBox*>& theSpinBoxList )
94 {
95   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
96   if ( !app )
97     return false;
98
99   QString msg;
100   QStringList absentParams;
101
102   bool ok = true;
103   QListIterator<QAbstractSpinBox*> anIter( theSpinBoxList );
104   while( anIter.hasNext() )
105   {
106     QAbstractSpinBox* aSpinBox = anIter.next();
107     if( SalomeApp_DoubleSpinBox* aDoubleSpinBox = dynamic_cast<SalomeApp_DoubleSpinBox*>( aSpinBox ) )
108       ok = aDoubleSpinBox->isValid( msg, absentParams, theMess ) && ok;
109     else if( SalomeApp_IntSpinBox* anIntSpinBox = dynamic_cast<SalomeApp_IntSpinBox*>( aSpinBox ) )
110       ok = anIntSpinBox->isValid( msg, absentParams, theMess ) && ok;
111   }
112
113   if( !ok && theMess )
114   {
115     if( !absentParams.isEmpty() )
116       app->defineAbsentParameters( absentParams );
117     else
118     {
119       QString str( QObject::tr( "SMESH_INCORRECT_INPUT" ) );
120       if( !msg.isEmpty() )
121         str += "\n" + msg;
122       SUIT_MessageBox::critical( mySMESHGUI->desktop(), QObject::tr( "SMESH_ERROR" ), str );
123     }
124   }
125   return ok;
126 }
127
128 //================================================================
129 // Function : getNotebook
130 // Purpose  :
131 //================================================================
132 SalomeApp_Notebook* SMESHGUI_Helper::getNotebook()
133 {
134   if ( !myNotebook )
135     myNotebook = new SalomeApp_Notebook( mySMESHGUI->activeStudy() );
136   return myNotebook;
137 }