28 using std::ostringstream;
33 #define MY_ENCODING "utf-8" 35 #define PINK "#ff6666" //error state color 52 : writer(writer), taSystem(taSystem) {
63 if (xmlTextWriterStartElement(
writer, xmlCharStrdup(element)) < 0) {
64 throw std::runtime_error(
"Error at xmlTextWriterStartElement");
70 if (xmlTextWriterEndElement(
writer) < 0) {
71 throw std::runtime_error(
"Error at xmlTextWriterEndElement");
78 if (xmlTextWriterWriteElement(
writer, xmlCharStrdup(name),
79 xmlCharStrdup(content)) < 0) {
80 throw std::runtime_error(
"Error at xmlTextWriterWriteElement");
86 if (xmlTextWriterWriteString(
writer, xmlCharStrdup(data)) < 0) {
87 throw std::runtime_error(
"Error at xmlTextWriterWriteString");
93 if (xmlTextWriterWriteString(
writer, data) < 0) {
94 throw std::runtime_error(
"Error at xmlTextWriterWriteString");
101 if (xmlTextWriterWriteAttribute(
writer, xmlCharStrdup(name),
102 xmlCharStrdup(value)) < 0) {
103 throw std::runtime_error(
"Error at xmlTextWriterWriteAttribute");
110 globalDeclarations +=
"\n";
112 globalDeclarations +=
" ";
113 writeElement(
"declaration", globalDeclarations.c_str());
118 list<chan_priority_t>::const_iterator itr;
120 if (!chanProc->empty()) {
121 str +=
"// channel priorities\n";
122 for (itr = chanProc->begin(); itr != chanProc->end(); ++itr) {
123 str += itr->toString() +
";";
136 if (data.substr(0, 5) ==
"1 && ") {
137 data = data.substr(5, data.size() - 5);
162 int32_t
id = state.
locNr;
179 name(state, x + 8, y + 8);
183 label(
"invariant", invariant, x + 8, y + 24);
207 const char*
id =
concat(
"id", loc).c_str();
217 const char*
id =
concat(
"id", loc).c_str();
225 float begin = initialAngle +
PI / 8 *
selfLoops[loc] + 0.1;
226 float end = begin +
PI / 8 - 0.1;
228 int x1 = l + (int) (
RADIUS * cos(begin));
229 int y1 = l + (int) (
RADIUS * sin(begin));
230 int x2 = l + (int) (
RADIUS * cos(end));
231 int y2 = l + (int) (
RADIUS * sin(end));
232 int x3 = l + (int) ((
RADIUS + 10) * cos((begin + end) / 2));
233 int y3 = l + (int) ((
RADIUS + 10) * sin((begin + end) / 2));
270 str = edge.
select[0].getName() +
" : ";
271 if (edge.
select[0].getType().size() > 0
272 && edge.
select[0].getType()[0].size() > 0) {
273 str += edge.
select[0].getType()[0].getLabel(0);
275 label(
"select", str, x, y - 32);
296 string declarations = templ.
toString(
false);
304 std::deque<state_t>::const_iterator s_itr;
305 for (s_itr = templ.
states.begin(); s_itr != templ.
states.end(); ++s_itr) {
307 selfLoops.insert(std::pair<int, int>(s_itr->locNr, 0));
312 std::deque<edge_t>::const_iterator e_itr;
313 for (e_itr = templ.
edges.begin(); e_itr != templ.
edges.end(); ++e_itr) {
323 std::list<instance_t>::const_iterator itr;
324 for (itr = instances->begin(); itr != instances->end(); ++itr) {
325 if (itr->uid.getName() != itr->templ->uid.getName()) {
326 str += itr->uid.getName() +
" = " 327 + itr->templ->uid.getName() +
"(" 328 + itr->writeArguments() +
");\n";
330 proc += itr->uid.getName() +
", ";
332 proc = proc.substr(0, proc.size() - 2);
333 str +=
"system " + proc +
"; ";
344 std::list<template_t>::const_iterator itr;
345 for (itr = templates->begin(); itr != templates->end(); ++itr) {
358 throw std::runtime_error(
"Error at xmlTextWriterStartDocument");
361 xmlTextWriterWriteDTD(
writer, (xmlChar *)
"nta",
362 (xmlChar *)
"-//Uppaal Team//DTD Flat System 1.1//EN",
363 (xmlChar *)
"http://www.it.uu.se/research/group/darts/uppaal/flat-1_1.dtd", NULL);
364 xmlTextWriterSetIndent(
writer, 1);
365 xmlTextWriterSetIndentString(
writer, (xmlChar *)
" ");
369 if (xmlTextWriterEndDocument(
writer) < 0) {
370 throw std::runtime_error(
"Error at xmlTextWriterEndDocument");
389 xmlCharEncodingHandlerPtr handler;
394 handler = xmlFindCharEncodingHandler(encoding);
396 printf(
"ConvertInput: no encoding handler found for '%s'\n",
397 encoding ? encoding :
"");
401 size = (int) strlen(in) + 1;
402 out_size = size * 2 - 1;
403 out = (
unsigned char *) xmlMalloc((
size_t) out_size);
407 ret = handler->input(out, &out_size, (
const xmlChar *) in, &temp);
408 if ((ret < 0) || (temp - size + 1)) {
410 printf(
"ConvertInput: conversion wasn't successful.\n");
413 (
"ConvertInput: conversion wasn't successful. converted: %i octets.\n",
420 out = (
unsigned char *) xmlRealloc(out, out_size + 1);
424 printf(
"ConvertInput: no mem\n");
430 using namespace UTAP;
437 writer = xmlNewTextWriterFilename(filename, 0);
438 if (writer == NULL) {
439 throw std::runtime_error(
"Error creating the xml writer");
XMLWriter(xmlTextWriterPtr writer, TimedAutomataSystem *taSystem)
std::map< int, int > selfLoops
symbol_t uid
The symbol of the location.
bool empty() const
Returns true if this is an empty expression.
void project()
Parse the project document.
std::deque< state_t > states
Locations.
uint32_t getSize() const
Returns the number of symbols in this frame.
void system_instantiation()
void labels(int x, int y, const edge_t &edge)
Information about a location.
void taTempl(const template_t &templ)
writes a template
expression_t guard
The guard.
std::string writeParameters() const
void writeStateAttributes(const state_t &state, int x, int y)
std::string getName() const
Returns the name (identifier) of this symbol.
expression_t sync
The synchronisation.
void label(const char *kind, std::string data, int x, int y)
int32_t locNr
Location number in template.
xmlTextWriterPtr writer
The underlying xmlTextWriter.
state_t * src
Pointer to source location.
std::string getChanPriority() const
Information about an edge.
void writeString(const char *content)
void declaration()
Parses optional declaration.
expression_t assign
The assignment.
void selfLoop(int loc, float initialAngle, const edge_t &edge)
state_t * dst
Pointer to destination location.
std::list< instance_t > & getProcesses()
Returns the processes of the system.
int target(const edge_t &edge)
void name(const state_t &state, int x, int y)
std::deque< edge_t > edges
Edges.
expression_t invariant
The invariant.
std::string toString(bool old=false) const
Returns a string representation of the expression.
void writeElement(const char *name, const char *content)
void startElement(const char *element)
xmlChar * ConvertInput(const char *in, const char *encoding)
ConvertInput: : string in a given encoding : the encoding used.
std::string concat(const std::string &s, int i)
concatenates a string and an int
type_t getType() const
Returns the type of this symbol.
std::string concatDouble(const std::string &s, double i)
concatenates a string and a double
void transition(const edge_t &edge)
frame_t select
Frame for non-deterministic select.
TimedAutomataSystem * taSystem
The system to write.
void * getData()
Returns the user data of this symbol.
symbol_t init
The initial location.
std::string toString(bool global=false) const
The following methods are used to write the declarations in an XML file.
void location(const state_t &state)
bool is(Constants::kind_t kind) const
Returns true if the type has kind kind or if type is a prefix, RANGE or REF type and the getChild()...
std::list< template_t > & getTemplates()
Returns the templates of the system.
int32_t writeXMLFile(const char *filename, TimedAutomataSystem *taSystem)
int source(const edge_t &edge)
void xmlwriteString(const xmlChar *content)
const std::list< chan_priority_t > & getChanPriorities() const
declarations_t & getGlobals()
Returns the global declarations of the system.
void writeAttribute(const char *name, const char *value)
void init(const template_t &templ)