All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stroke.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011-2011 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/serialization/se/Stroke.cpp
22 
23  \brief Support for Stroke serialization.
24 */
25 
26 // TerraLib
27 #include "../../se/Stroke.h"
28 #include "../../xml/Reader.h"
29 #include "../../xml/Writer.h"
30 #include "Graphic.h"
31 #include "GraphicStroke.h"
32 #include "Stroke.h"
33 #include "SvgParameter.h"
34 
35 // STL
36 #include <cassert>
37 #include <memory>
38 
40 {
41  assert(reader.getNodeType() == te::xml::START_ELEMENT);
42  assert(reader.getElementLocalName() == "Stroke");
43 
44  reader.next();
45 
46  std::auto_ptr<te::se::Stroke> stroke(new te::se::Stroke);
47 
48  // GraphicFill
49  if(reader.getElementLocalName() == "GraphicFill")
50  {
51  reader.next();
52  stroke->setGraphicFill(ReadGraphic(reader));
53 
54  assert(reader.getNodeType() == te::xml::END_ELEMENT);
55  reader.next();
56  }
57  // GraphicStroke
58  else if(reader.getElementLocalName() == "GraphicStroke")
59  stroke->setGraphicStroke(ReadGraphicStroke(reader));
60 
61  // SvgParameters
62  while(reader.getNodeType() == te::xml::START_ELEMENT &&
63  reader.getElementLocalName() == "SvgParameter")
64  stroke->add(ReadSvgParameter(reader));
65 
66  assert(reader.getNodeType() == te::xml::END_ELEMENT);
67  reader.next();
68 
69  return stroke.release();
70 }
71 
73 {
74  if(stroke == 0)
75  return;
76 
77  writer.writeStartElement("se:Stroke");
78 
79  if(stroke->getGraphicFill())
80  {
81  writer.writeStartElement("se:GraphicFill");
82  Save(stroke->getGraphicFill(), writer);
83  writer.writeEndElement("se:GraphicFill");
84  }
85  else if(stroke->getGraphicStroke())
86  Save(stroke->getGraphicStroke(), writer);
87 
88  Save(stroke->getColor(), writer);
89  Save(stroke->getOpacity(), writer);
90  Save(stroke->getWidth(), writer);
91  Save(stroke->getLineJoin(), writer);
92  Save(stroke->getLineCap(), writer);
93  Save(stroke->getDashArray(), writer);
94  Save(stroke->setDashOffset(), writer);
95 
96  writer.writeEndElement("se:Stroke");
97 }
const SvgParameter * getLineJoin() const
Definition: Stroke.cpp:138
const SvgParameter * getWidth() const
Definition: Stroke.cpp:133
TEDATAACCESSEXPORT void Save(const std::string &fileName)
Definition: Serializer.cpp:191
Support for SvgParameter serialization.
const SvgParameter * getLineCap() const
Definition: Stroke.cpp:143
This class models a XML reader object.
Definition: Reader.h:55
A Stroke specifies the appearance of a linear geometry.
Definition: Stroke.h:67
virtual bool next()=0
It gets the next event to be read.
const SvgParameter * getOpacity() const
Definition: Stroke.cpp:128
const SvgParameter * getDashArray() const
Definition: Stroke.cpp:148
virtual void writeStartElement(const std::string &qName)
Definition: Writer.cpp:44
A Stroke specifies the appearance of a linear geometry.
virtual void writeEndElement(const std::string &qName)
Definition: Writer.cpp:156
TESERIALIZATIONEXPORT void Save(const te::fe::Filter *filter, te::xml::Writer &writer)
Definition: Filter.cpp:54
Support for Graphic serialization.
TESERIALIZATIONEXPORT te::se::Stroke * ReadStroke(te::xml::Reader &reader)
Definition: Stroke.cpp:39
TESERIALIZATIONEXPORT te::se::SvgParameter * ReadSvgParameter(te::xml::Reader &reader)
const SvgParameter * getColor() const
Definition: Stroke.cpp:123
void setDashOffset(const std::string &offset)
Definition: Stroke.cpp:118
TESERIALIZATIONEXPORT te::se::GraphicStroke * ReadGraphicStroke(te::xml::Reader &reader)
Support for GraphicStroke serialization.
const Graphic * getGraphicFill() const
Gets the GraphicFill element associate to this Stroke.
Definition: Stroke.cpp:63
TESERIALIZATIONEXPORT te::se::Graphic * ReadGraphic(te::xml::Reader &reader)
Definition: Graphic.cpp:42
virtual NodeType getNodeType() const =0
It return the type of node read.
virtual std::string getElementLocalName() const =0
It returns the local part of the element name in the case of an element node.
const GraphicStroke * getGraphicStroke() const
Gets the GraphicStroke element associate to this Stroke.
Definition: Stroke.cpp:74
This class models a XML writer object.
Definition: Writer.h:52