1 #include <YACSGui_XMLDriver.h>
2 #include <YACSGui_Graph.h>
3 #include <YACSGui_Module.h>
4 #include <YACSPrs_ElementaryNode.h>
5 #include <YACSPrs_Link.h>
7 #include <QxGraph_Canvas.h>
10 #include <InputPort.hxx>
11 #include <OutputPort.hxx>
12 #include <InputDataStreamPort.hxx>
13 #include <OutputDataStreamPort.hxx>
20 using namespace YACS::ENGINE;
23 static canvastype_parser canvas_parser;
24 static presentationtype_parser presentation_parser;
25 static pointtype_parser point_parser;
26 static prslinktype_parser prslink_parser;
28 void prslinktype_parser::onStart(const XML_Char* el, const XML_Char** attr)
30 std::cerr << "prslinktype_parser::onStart: " << el << std::endl;
31 std::string element(el);
32 parser* pp=&main_parser;
33 if(element == "point") pp = &point_parser;
34 SetUserDataAndPush(pp);
40 YACSGui_VisitorSaveSchema::YACSGui_VisitorSaveSchema(YACSGui_Module* module,
42 : VisitorSaveSchema(root), myModule(module)
46 YACSGui_VisitorSaveSchema::~YACSGui_VisitorSaveSchema()
50 void YACSGui_VisitorSaveSchema::visitProc(Proc *node)
52 this->VisitorSaveSchema::visitProc(node);
53 writePresentation(node);
57 void YACSGui_VisitorSaveSchema::writePresentation(Proc *proc)
59 YACSGui_Graph* aGraph = myModule->getGraph(proc);
60 if ( !aGraph || !aGraph->getCanvas() )
65 _out << indent(depth) << "<canvas";
66 _out << " width=\"" << aGraph->getCanvas()->width() << "\"";
67 _out << " height=\"" << aGraph->getCanvas()->height() << "\"";
70 set<Node*> nodeSet = getAllNodes(proc);
72 for (set<Node*>::iterator iter = nodeSet.begin(); iter != nodeSet.end(); ++iter)
75 YACSPrs_ElementaryNode* aPrs = aGraph->getItem( aNode );
79 _out << indent(depth) << "<presentation";
80 _out << " name=\"" << proc->getChildName( aNode ) << "\"";
81 _out << " x=\"" << aPrs->x() << "\"";
82 _out << " y=\"" << aPrs->y() << "\"";
83 _out << " z=\"" << aPrs->z() << "\"";
84 _out << " width=\"" << aPrs->width() << "\"";
85 _out << " height=\""<< aPrs->height() << "\"";
90 void YACSGui_VisitorSaveSchema::writeLinks(YACS::ENGINE::Proc *proc)
92 YACSGui_Graph* aGraph = myModule->getGraph(proc);
93 if ( !aGraph || !aGraph->getCanvas() )
98 set<Node*> nodeSet = getAllNodes(proc);
100 for (set<Node*>::iterator iter = nodeSet.begin(); iter != nodeSet.end(); ++iter)
103 YACSPrs_ElementaryNode* aPrs = aGraph->getItem( aNode );
107 QPtrList<YACSPrs_Port> aPorts = aPrs->getPortList();
108 for (YACSPrs_Port* aPort = aPorts.first(); aPort; aPort = aPorts.next())
110 YACSPrs_InOutPort* anIOPort;
111 if ( ( anIOPort = dynamic_cast<YACSPrs_InOutPort*>( aPort ) ) && !anIOPort->isInput()
113 dynamic_cast<YACSPrs_LabelPort*>( aPort ) )
114 { // this port is an output port => iterates on its links
115 list<YACSPrs_Link*> aLinks = aPort->getLinks();
116 for(list<YACSPrs_Link*>::iterator itL = aLinks.begin(); itL != aLinks.end(); itL++)
118 _out << indent(depth) << "<prslink";
120 if ( YACSPrs_PortLink* aPL = dynamic_cast<YACSPrs_PortLink*>( *itL ) ) {
121 _out << " fromnode=\"" << proc->getChildName( aNode ) << "\"";
122 _out << " fromport=\"" << aPort->getName() << "\"";
123 _out << " tonode=\"" << proc->getChildName( aPL->getInputPort()->getEngine()->getNode() ) << "\"";
124 _out << " toport=\"" << aPL->getInputPort()->getName() << "\"";
126 else if ( YACSPrs_LabelLink* aLL = dynamic_cast<YACSPrs_LabelLink*>( *itL ) ) {
127 _out << " tonode=\"" << proc->getChildName( aLL->getSlaveNode()->getEngine() ) << "\"";
132 list<QPoint> aPoints = (*itL)->getPoints();
133 for(list<QPoint>::iterator itP = aPoints.begin(); itP != aPoints.end(); itP++) {
134 _out << indent(depth+1) << "<point";
135 _out << " x=\"" << (*itP).x() << "\"";
136 _out << " y=\"" << (*itP).y() << "\"";
137 _out << "/>" << endl;
140 _out << indent(depth) << "</prslink>" << endl;
147 YACSGui_Loader::YACSGui_Loader()
150 _defaultParsersMap.clear();
152 presentation_parser.collector_ = this;
153 prslink_parser.collector_ = this;
155 _defaultParsersMap.insert(make_pair("canvas",&canvas_parser));
156 _defaultParsersMap.insert(make_pair("presentation",&presentation_parser));
157 _defaultParsersMap.insert(make_pair("point",&point_parser));
158 _defaultParsersMap.insert(make_pair("prslink",&prslink_parser));
161 YACSGui_Loader::~YACSGui_Loader()
165 const YACSGui_Loader::PrsDataMap& YACSGui_Loader::getPrsData(Proc* proc, int& width, int& height)
169 if ( _defaultParsersMap.empty()
171 !_defaultParsersMap["canvas"] ) return myPrsMap;
173 // get information from canvastype_parser
174 width = ((canvastype_parser*)_defaultParsersMap["canvas"])->width_;
175 height = ((canvastype_parser*)_defaultParsersMap["canvas"])->height_;
177 for ( InputMap::iterator it = myInputMap.begin(); it != myInputMap.end(); it++ )
179 Node* aNode = proc->getChildByName( (*it).first );
180 myPrsMap[aNode] = (*it).second;
186 const YACSGui_Loader::PortLinkDataMap& YACSGui_Loader::getPortLinkData(YACS::ENGINE::Proc* proc)
188 myPortLinkMap.clear();
190 for ( InputPLList::iterator it = myInputPLList.begin(); it != myInputPLList.end(); it++ )
192 Node* aFromNode = proc->getChildByName((*it).fromnode);
194 if ( (*it).fromport == "Gate" )
195 aFromPort = aFromNode->getOutGate();
197 aFromPort = (Port*)(aFromNode->getOutPort((*it).fromport));
199 Node* aToNode = proc->getChildByName((*it).tonode);
201 if ( (*it).toport == "Gate" )
202 aToPort = aToNode->getInGate();
204 aToPort = (Port*)(aToNode->getInPort((*it).toport));
206 std::pair<Port*,Port*> aPPair(aFromPort,aToPort);
207 myPortLinkMap[aPPair] = (*it).points;
210 return myPortLinkMap;
213 const YACSGui_Loader::LabelLinkDataMap& YACSGui_Loader::getLabelLinkData(YACS::ENGINE::Proc* proc)
215 myLabelLinkMap.clear();
217 for ( InputLLList::iterator it = myInputLLList.begin(); it != myInputLLList.end(); it++ )
219 Node* aSlaveNode = proc->getChildByName((*it).slavenode);
220 myLabelLinkMap[aSlaveNode] = (*it).points;
223 return myLabelLinkMap;
226 void YACSGui_Loader::process(std::string theElement, bool theNewLink)
228 if(theElement == "presentation")
230 if ( _defaultParsersMap["presentation"] )
232 presentationtype_parser* aP = (presentationtype_parser*)_defaultParsersMap["presentation"];
233 myInputMap[aP->name_] = PrsData(aP->x_,aP->y_,aP->z_,aP->width_,aP->height_);
236 else if(theElement == "prslink")
238 if ( _defaultParsersMap["prslink"] )
240 prslinktype_parser* aP = (prslinktype_parser*)_defaultParsersMap["prslink"];
241 if ( aP->type() == "portlink" )
244 PortLinkData aPLData(aP->fromnode_,aP->fromport_,aP->tonode_,aP->toport_);
245 //aPLData.fillPoints(aP->points_);
246 myInputPLList.push_back(aPLData);
248 else if ( !myInputPLList.empty() )
249 myInputPLList.back().appendPoint(aP->points_.back());
251 else if ( aP->type() == "labellink" )
254 LabelLinkData aLLData(aP->tonode_);
255 //aLLData.fillPoints(aP->points_);
256 myInputLLList.push_back(aLLData);
258 else if ( !myInputLLList.empty() )
259 myInputLLList.back().appendPoint(aP->points_.back());