]> SALOME platform Git repositories - modules/kernel.git/blob - src/Notebook/SALOME_Notebook.hxx
Salome HOME
implementation of load and substitutions
[modules/kernel.git] / src / Notebook / SALOME_Notebook.hxx
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 //  File   : SALOME_Notebook.hxx
23 //  Author : Alexandre SOLOVYOV
24 //  Module : SALOME
25 //
26 #ifndef __SALOME_NOTEBOOK_H__
27 #define __SALOME_NOTEBOOK_H__
28
29 #include <SALOMEconfig.h>
30 #include CORBA_SERVER_HEADER(SALOME_Notebook)
31 #include CORBA_SERVER_HEADER(SALOMEDS)
32 #include <SALOME_GenericObj_i.hh>
33 #include <Utils_Mutex.hxx>
34 #include <string>
35 #include <list>
36 #include <map>
37 #include <vector>
38
39 class SALOME_Parameter;
40
41 class SALOME_Notebook : public virtual POA_SALOME::Notebook, public virtual SALOME::GenericObj_i
42 {
43 public:
44   SALOME_Notebook( PortableServer::POA_ptr thePOA, SALOMEDS::Study_ptr theStudy );
45
46   virtual CORBA::Boolean AddDependency( SALOME::ParameterizedObject_ptr theObj, SALOME::ParameterizedObject_ptr theRef );
47   virtual CORBA::Boolean RemoveDependency( SALOME::ParameterizedObject_ptr theObj, SALOME::ParameterizedObject_ptr theRef );
48   virtual void ClearDependencies( SALOME::ParameterizedObject_ptr theObj, SALOME::DependenciesType theType );
49   virtual void SetToUpdate( SALOME::ParameterizedObject_ptr theObj );
50   virtual void Update();
51
52   virtual CORBA::Boolean AddExpression( const char* theExpr );
53   virtual CORBA::Boolean AddNamedExpression( const char* theName, const char* theExpr );
54   virtual CORBA::Boolean AddBoolean( const char* theName, CORBA::Boolean theValue );
55   virtual CORBA::Boolean AddInteger( const char* theName, CORBA::Long theValue );
56   virtual CORBA::Boolean AddReal( const char* theName, CORBA::Double theValue );
57   virtual CORBA::Boolean AddString( const char* theName, const char* theValue );
58   virtual CORBA::Boolean Remove( const char* theParamName );
59   virtual CORBA::Boolean Rename( const char* theOldName, const char* theNewName );
60   virtual SALOME::Parameter_ptr GetParameter( const char* theParamName );
61   virtual SALOME::StringArray* Parameters();
62   virtual SALOME::StringArray* AbsentParameters();
63
64   virtual CORBA::Boolean Save( const char* theFileName );
65   virtual CORBA::Boolean Load( const char* theFileName );
66   virtual char*          DumpPython();
67   virtual char*          Dump();
68
69   SALOME_Parameter* GetParameterPtr( const char* theParamName ) const;
70   void UpdateAnonymous( const char* theOldName, SALOME_Parameter* theParam );
71
72   static std::vector<std::string> Split( const std::string& theData, const std::string& theSeparator, bool theIsKeepEmpty );
73
74 protected:
75   bool AddParameter( SALOME_Parameter* theParam );
76   bool AddDependencies( SALOME_Parameter* theParam );
77   bool AddDependency( const std::string& theObjKey, const std::string& theRefKey );
78   void ClearDependencies( const std::string& theObjKey, SALOME::DependenciesType theType );
79   bool CheckParamName( const std::string& theParamName ) const;
80   SALOME::StringArray* GenerateList( const std::list<std::string>& theList ) const;
81   std::string GetComponent( const std::string& theKey, std::string& theEntry ) const;
82   bool ParseDependencies( const std::string& theData );
83
84 private:
85   std::string GetKey( SALOME::ParameterizedObject_ptr theObj );
86   std::string GetKey( const std::string& theParamName );
87   std::list<std::string> GetAllDependingOn( const std::string& theKey );
88   SALOME::ParameterizedObject_ptr FindObject( const std::string& theKey );
89
90 private:
91   friend class KeyHelper;
92   class KeyHelper
93   {
94   public:
95     KeyHelper( const std::string& theKey, SALOME_Notebook* theNotebook );
96     std::string key() const;
97     bool operator < ( const KeyHelper& theKH ) const;
98     bool operator == ( const std::string& theKey ) const;
99
100   private:
101     std::string myKey;
102     SALOME_Notebook* myNotebook;
103   };
104
105   typedef struct
106   {
107     std::string myName, myExpr;
108     std::list< KeyHelper > myObjects;
109     bool myIsRename;
110   } SubstitutionInfo;
111
112 private:
113   void Sort( std::list< KeyHelper >& theList ) const;
114   bool Substitute( SubstitutionInfo& theSubstitution );
115   SubstitutionInfo CreateSubstitution( const std::string& theName, const std::string& theExpr, bool theIsRename );
116   void AddSubstitution( const std::string& theName, const std::string& theExpr, bool theIsRename );
117
118 private:
119   std::map< std::string, std::list<std::string> > myDependencies;
120   std::map< std::string, SALOME_Parameter* > myParameters;
121   std::list< KeyHelper > myToUpdate;
122   std::list<SubstitutionInfo> mySubstitutions;
123   SALOMEDS::Study_var myStudy;
124   Utils_Mutex myMutex;
125 };
126
127 #endif