Salome HOME
Debug
[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 //=================================================================================
41 // name    : SMESHGUI_Helper::SMESHGUI_Helper
42 // Purpose :
43 //=================================================================================
44 SMESHGUI_Helper::SMESHGUI_Helper( SMESHGUI* theModule ) :
45   mySMESHGUI( theModule )
46 {
47   myNotebook = new SalomeApp_Notebook( mySMESHGUI->activeStudy() );
48 }
49
50 //=======================================================================
51 // name    : SMESHGUI_Helper::~SMESHGUI_Helper
52 // Purpose :
53 //=======================================================================
54 SMESHGUI_Helper::~SMESHGUI_Helper()
55 {
56   if( myNotebook )
57   {
58     delete myNotebook;
59     myNotebook = 0;
60   }
61 }
62
63 //================================================================
64 // Function : checkParameters
65 // Purpose  :
66 //================================================================
67 bool SMESHGUI_Helper::checkParameters( bool theMess, int theCount, QAbstractSpinBox* theFirstSpinBox, ... )
68 {
69   va_list aSpins;
70   va_start( aSpins, theFirstSpinBox );
71
72   int aCounter = 0;
73   QList<QAbstractSpinBox*> aSpinBoxList;
74   QAbstractSpinBox* aSpinBox = theFirstSpinBox;
75   while( aSpinBox && aCounter < theCount )
76   {
77     aSpinBoxList.append( aSpinBox );
78     aSpinBox = va_arg( aSpins, QAbstractSpinBox* );
79     aCounter++;
80   }
81   return checkParameters( theMess, aSpinBoxList );
82 }
83
84 //================================================================
85 // Function : checkParameters
86 // Purpose  :
87 //================================================================
88 bool SMESHGUI_Helper::checkParameters( bool theMess, const QList<QAbstractSpinBox*>& theSpinBoxList )
89 {
90   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
91   if ( !app )
92     return false;
93
94   QString msg;
95   QStringList absentParams;
96
97   bool ok = true;
98   QListIterator<QAbstractSpinBox*> anIter( theSpinBoxList );
99   while( anIter.hasNext() )
100   {
101     QAbstractSpinBox* aSpinBox = anIter.next();
102     if( SalomeApp_DoubleSpinBox* aDoubleSpinBox = dynamic_cast<SalomeApp_DoubleSpinBox*>( aSpinBox ) )
103       ok = aDoubleSpinBox->isValid( msg, absentParams, theMess ) && ok;
104     else if( SalomeApp_IntSpinBox* anIntSpinBox = dynamic_cast<SalomeApp_IntSpinBox*>( aSpinBox ) )
105       ok = anIntSpinBox->isValid( msg, absentParams, theMess ) && ok;
106   }
107
108   if( !ok && theMess )
109   {
110     if( !absentParams.isEmpty() )
111       app->defineAbsentParameters( absentParams );
112     else
113     {
114       QString str( QObject::tr( "SMESH_INCORRECT_INPUT" ) );
115       if( !msg.isEmpty() )
116         str += "\n" + msg;
117       SUIT_MessageBox::critical( mySMESHGUI->desktop(), QObject::tr( "SMESH_ERROR" ), str );
118     }
119   }
120   return ok;
121 }
122
123 //================================================================
124 // Function : getNotebook
125 // Purpose  :
126 //================================================================
127 SalomeApp_Notebook* SMESHGUI_Helper::getNotebook() const
128 {
129   return myNotebook;
130 }