Salome HOME
8bed0162ecc7f47023a2afa5578f34d4037cb96b
[modules/yacs.git] / src / hmi / guiContext.cxx
1 // Copyright (C) 2006-2022  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, or (at your option) any later version.
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
20 #include "RuntimeSALOME.hxx"
21 #include "guiContext.hxx"
22 #include "Proc.hxx"
23 #include "Container.hxx"
24 #include "ComponentInstance.hxx"
25 #include "commandsProc.hxx"
26 #include "guiObservers.hxx"
27
28 //#define _DEVDEBUG_
29 #include "YacsTrace.hxx"
30
31 using namespace std;
32
33 using namespace YACS;
34 using namespace YACS::ENGINE;
35 using namespace YACS::HMI;
36
37 GuiContext * GuiContext::_current = 0;
38
39 GuiContext::GuiContext()
40   : Subject(0)
41 {
42   _builtinCatalog = getSALOMERuntime()->getBuiltinCatalog();
43   _sessionCatalog = 0;
44   _procCatalog = 0;
45   _currentCatalog = 0;
46
47   _invoc = new ProcInvoc();
48   _proc = 0;
49   _subjectProc = 0;
50   _numItem = 0;
51   _isNotSaved = false;
52   _isLoading = false;
53
54   _mapOfSubjectNode.clear();
55   _mapOfSubjectDataPort.clear();
56   _mapOfSubjectLink.clear();
57   _mapOfSubjectControlLink.clear();
58   _mapOfSubjectComponent.clear();
59   _mapOfSubjectContainer.clear();
60   _mapOfSubjectDataType.clear();
61   _mapOfExecSubjectNode.clear();
62   _mapOfLastComponentInstance.clear();
63   _lastErrorMessage ="";
64   _xmlSchema ="";
65   _YACSEngineContainer = pair<string, string>("YACSServer","localhost");
66 }
67
68 GuiContext::~GuiContext()
69 {
70   if (_invoc) delete _invoc;
71   _invoc = 0;
72   if (_subjectProc)
73     {
74       _subjectProc->clean();
75       delete _subjectProc;
76       _subjectProc = 0;
77     }
78   _current = 0;
79 }
80
81 void GuiContext::setProc(YACS::ENGINE::Proc* proc)
82 {
83   DEBTRACE("GuiContext::setProc ");
84   if (_subjectProc)
85     {
86       Subject::erase(_subjectProc);
87       _subjectProc = 0;
88     }
89   _proc = proc;
90   _mapOfSubjectNode.clear();
91   _mapOfSubjectDataPort.clear();
92   _mapOfSubjectLink.clear();
93   _mapOfSubjectControlLink.clear();
94   _mapOfSubjectComponent.clear();
95   _mapOfSubjectContainer.clear();
96   _mapOfSubjectDataType.clear();
97   _mapOfLastComponentInstance.clear();
98   _lastErrorMessage ="";
99
100   _subjectProc = new SubjectProc(proc, this);
101   _mapOfSubjectNode[static_cast<Node*>(proc)] = _subjectProc;
102   update(YACS::HMI::NEWROOT, 0, _subjectProc);
103   _subjectProc->loadProc();
104   update(YACS::HMI::ENDLOAD, 0, _subjectProc);
105 }
106
107 long GuiContext::getNewId(YACS::HMI::TypeOfElem type)
108 {
109   return _numItem++;
110 }