Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / hmi / guiContext.cxx
1 //  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #include "RuntimeSALOME.hxx"
20 #include "guiContext.hxx"
21 #include "Proc.hxx"
22 #include "Container.hxx"
23 #include "ComponentInstance.hxx"
24 #include "commandsProc.hxx"
25 #include "guiObservers.hxx"
26
27 //#define _DEVDEBUG_
28 #include "YacsTrace.hxx"
29
30 using namespace std;
31
32 using namespace YACS;
33 using namespace YACS::ENGINE;
34 using namespace YACS::HMI;
35
36 GuiContext * GuiContext::_current = 0;
37
38 GuiContext::GuiContext()
39   : Subject(0)
40 {
41   _builtinCatalog = getSALOMERuntime()->getBuiltinCatalog();
42   _sessionCatalog = 0;
43   _procCatalog = 0;
44   _currentCatalog = 0;
45
46   _invoc = new ProcInvoc();
47   _proc = 0;
48   _subjectProc = 0;
49   _numItem = 0;
50
51   _mapOfSubjectNode.clear();
52   _mapOfSubjectDataPort.clear();
53   _mapOfSubjectLink.clear();
54   _mapOfSubjectControlLink.clear();
55   _mapOfSubjectComponent.clear();
56   _mapOfSubjectContainer.clear();
57   _mapOfSubjectDataType.clear();
58   _mapOfExecSubjectNode.clear();
59   _lastErrorMessage ="";
60   _xmlSchema ="";
61   _YACSEngineContainer = pair<string, string>("YACSServer","localhost");
62 }
63
64 GuiContext::~GuiContext()
65 {
66   if (_invoc) delete _invoc;
67   _invoc = 0;
68   if (_subjectProc)
69     {
70       _subjectProc->clean();
71       delete _subjectProc;
72       _subjectProc = 0;
73     }
74   _current = 0;
75 }
76
77 void GuiContext::setProc(YACS::ENGINE::Proc* proc)
78 {
79   DEBTRACE("GuiContext::setProc ");
80   if (_subjectProc)
81     {
82       Subject::erase(_subjectProc);
83       _subjectProc = 0;
84     }
85   _proc = proc;
86   _mapOfSubjectNode.clear();
87   _mapOfSubjectDataPort.clear();
88   _mapOfSubjectLink.clear();
89   _mapOfSubjectControlLink.clear();
90   _mapOfSubjectComponent.clear();
91   _mapOfSubjectContainer.clear();
92   _mapOfSubjectDataType.clear();
93
94   _subjectProc = new SubjectProc(proc, this);
95   _mapOfSubjectNode[static_cast<Node*>(proc)] = _subjectProc;
96   update(YACS::HMI::NEWROOT, 0, _subjectProc);
97   _subjectProc->loadProc();
98   update(YACS::HMI::ENDLOAD, 0, _subjectProc);
99 }
100
101 long GuiContext::getNewId(YACS::HMI::TypeOfElem type)
102 {
103   return _numItem++;
104 }