Salome HOME
[EDF28974] : Move to python implementation of driver and integrate monitoring into...
[modules/yacs.git] / src / runtime / VisitorSaveSalomeSchema.cxx
1 // Copyright (C) 2006-2024  CEA, EDF
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 "PresetPorts.hxx"
21 #include "VisitorSaveSalomeSchema.hxx"
22 #include "DataNode.hxx"
23 #include "PresetNode.hxx"
24 #include "OutNode.hxx"
25 #include "StudyNodes.hxx"
26 #include "ComposedNode.hxx"
27 #include "StudyPorts.hxx"
28 #include "TypeCode.hxx"
29
30 #include <cassert>
31 #include <iostream>
32 #include <string>
33 #include <set>
34
35
36 using namespace YACS::ENGINE;
37 using namespace std;
38
39 //#define _DEVDEBUG_
40 #include "YacsTrace.hxx"
41
42 VisitorSaveSalomeSchema::VisitorSaveSalomeSchema(ComposedNode *root)
43   : VisitorSaveSchema(root)
44 {
45 }
46
47 VisitorSaveSalomeSchema::~VisitorSaveSalomeSchema()
48 {
49 }
50
51 void VisitorSaveSalomeSchema::visitPresetNode(DataNode *node)
52 {
53   DEBTRACE("START visitPresetNode " << _root->getChildName(node));
54   beginCase(node);
55   int depth = depthNode(node);
56   _out << indent(depth) << "<datanode name=\"" << node->getName() << "\"";
57   string ref = node->getRef();
58   if (!ref.empty()) _out << " ref=\"" << ref << "\"";
59   if (node->getState() == YACS::DISABLED)
60     _out << " state=\"disabled\">" << endl;
61   else
62     _out << ">" << endl;
63   writeDataNodeParameters(node);
64   writeProperties(node);
65   _out << indent(depth) << "</datanode>" << endl;
66   endCase(node);
67   DEBTRACE("END visitPresetNode " << _root->getChildName(node));
68 }
69
70 void VisitorSaveSalomeSchema::visitOutNode(DataNode *node)
71 {
72   DEBTRACE("START visitOutNode " << _root->getChildName(node));
73   beginCase(node);
74   int depth = depthNode(node);
75   _out << indent(depth) << "<outnode name=\"" << node->getName() << "\"";
76   string ref = node->getRef();
77   if (!ref.empty()) _out << " ref=\"" << ref << "\"";
78   if (node->getState() == YACS::DISABLED)
79     _out << " state=\"disabled\">" << endl;
80   else
81     _out << ">" << endl;
82   writeOutNodeParameters(node);
83   writeProperties(node);
84   _out << indent(depth) << "</outnode>" << endl;
85   endCase(node);
86   DEBTRACE("END visitOutNode " << _root->getChildName(node));
87 }
88
89 void VisitorSaveSalomeSchema::visitStudyInNode(DataNode *node)
90 {
91   DEBTRACE("START visitStudyInNode " << _root->getChildName(node));
92   beginCase(node);
93   int depth = depthNode(node);
94   _out << indent(depth) << "<datanode name=\"" << node->getName() << "\" kind=\"study\"";
95   string ref = node->getRef();
96   if (!ref.empty()) _out << " ref=\"" << ref << "\"";
97   if (node->getState() == YACS::DISABLED)
98     _out << " state=\"disabled\">" << endl;
99   else
100     _out << ">" << endl;
101   writeStudyInNodeParameters(node);
102   writeProperties(node);
103   _out << indent(depth) << "</datanode>" << endl;
104   endCase(node);
105   DEBTRACE("END visitStudyInNode " << _root->getChildName(node));
106 }
107
108 void VisitorSaveSalomeSchema::visitStudyOutNode(DataNode *node)
109 {
110   DEBTRACE("START visitStudyOutNode " << _root->getChildName(node));
111   beginCase(node);
112   int depth = depthNode(node);
113   _out << indent(depth) << "<outnode name=\"" << node->getName() << "\" kind=\"study\"";
114   string ref = node->getRef();
115   if (!ref.empty()) _out << " ref=\"" << ref << "\"";
116   if (node->getState() == YACS::DISABLED)
117     _out << " state=\"disabled\">" << endl;
118   else
119     _out << ">" << endl;
120   writeStudyOutNodeParameters(node);
121   writeProperties(node);
122   _out << indent(depth) << "</outnode>" << endl;
123   endCase(node);
124   DEBTRACE("END visitStudyOutNode " << _root->getChildName(node));
125 }
126
127 void VisitorSaveSalomeSchema::writeDataNodeParameters(DataNode *node)
128 {
129   int depth = depthNode(node)+1;
130   list<OutputPort*> listOfOutputPorts = node->getSetOfOutputPort();
131   for (list<OutputPort*>::iterator it = listOfOutputPorts.begin(); it != listOfOutputPorts.end(); ++it)
132     {
133       _out << indent(depth) << "<parameter name=\"" << (*it)->getName() << "\" type=\"" 
134            << (*it)->edGetType()->name() << "\">" << endl;
135       OutputPresetPort *outp = dynamic_cast<OutputPresetPort*>(*it);
136       YASSERT(outp);
137       _out << indent(depth+1) << outp->getData();
138       _out << indent(depth) << "</parameter>" << endl;
139     }
140 }
141
142 void VisitorSaveSalomeSchema::writeStudyInNodeParameters(DataNode *node)
143 {
144   int depth = depthNode(node)+1;
145   list<OutputPort*> listOfOutputPorts = node->getSetOfOutputPort();
146   for (list<OutputPort*>::iterator it = listOfOutputPorts.begin(); it != listOfOutputPorts.end(); ++it)
147     {
148       _out << indent(depth) << "<parameter name=\"" << (*it)->getName() << "\" type=\"" 
149            << (*it)->edGetType()->name() << "\" ref=\"";
150       OutputStudyPort *outp = dynamic_cast<OutputStudyPort*>(*it);
151       YASSERT(outp);
152       _out << outp->getData() << "\"/>" << endl;
153     }
154 }
155
156 void VisitorSaveSalomeSchema::writeOutNodeParameters(DataNode *node)
157 {
158   int depth = depthNode(node)+1;
159   list<InputPort*> listOfInputPorts = node->getSetOfInputPort();
160   for (list<InputPort*>::iterator it = listOfInputPorts.begin(); it != listOfInputPorts.end(); ++it)
161     {
162       _out << indent(depth) << "<parameter name=\"" << (*it)->getName() << "\" type=\"" 
163            << (*it)->edGetType()->name() << "\"/>" << endl;
164     }
165 }
166
167 void VisitorSaveSalomeSchema::writeStudyOutNodeParameters(DataNode *node)
168 {
169   int depth = depthNode(node)+1;
170   list<InputPort*> listOfInputPorts = node->getSetOfInputPort();
171   for (list<InputPort*>::iterator it = listOfInputPorts.begin(); it != listOfInputPorts.end(); ++it)
172     {
173       _out << indent(depth) << "<parameter name=\"" << (*it)->getName() << "\" type=\"" 
174            << (*it)->edGetType()->name() << "\" ref=\"";
175       InputStudyPort *inp = dynamic_cast<InputStudyPort*>(*it);
176       YASSERT(inp);
177       _out << inp->getData() << "\"/>" << endl;
178     }
179 }
180
181 void YACS::ENGINE::VisitorSaveSalomeSchemaUnsafe(ComposedNode* proc, const std::string& xmlSchema)
182 {
183   VisitorSaveSalomeSchema vss(proc);
184   vss.openFileSchema(xmlSchema);
185   proc->accept(&vss);
186   vss.closeFileSchema();
187 }