All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GraphicStroke.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/GraphicStroke.cpp
22 
23  \brief Support for GraphicStroke serialization.
24 */
25 
26 // TerraLib
27 #include "../../se/GraphicStroke.h"
28 #include "../../xml/Reader.h"
29 #include "../../xml/Writer.h"
30 #include "Graphic.h"
31 #include "GraphicStroke.h"
32 #include "ParameterValue.h"
33 #include "Utils.h"
34 
35 // STL
36 #include <cassert>
37 #include <memory>
38 
40 {
41  assert(reader.getNodeType() == te::xml::START_ELEMENT);
42  assert(reader.getElementLocalName() == "GraphicStroke");
43 
44  reader.next();
45 
46  std::auto_ptr<te::se::GraphicStroke> graphicStroke(new te::se::GraphicStroke);
47 
48  assert(reader.getElementLocalName() == "Graphic");
49  graphicStroke->setGraphic(ReadGraphic(reader));
50 
51  // InitialGap
52  if(reader.getElementLocalName() == "InitialGap")
53  {
54  reader.next();
55  graphicStroke->setInitialGap(ReadParameterValue(reader));
56  }
57 
58  // Gap
59  if(reader.getElementLocalName() == "Gap")
60  {
61  reader.next();
62  graphicStroke->setGap(ReadParameterValue(reader));
63  }
64 
65  assert(reader.getNodeType() == te::xml::END_ELEMENT);
66  reader.next();
67 
68  return graphicStroke.release();
69 }
70 
71 void te::serialize::Save(const te::se::GraphicStroke* graphicStroke, te::xml::Writer& writer)
72 {
73  if(graphicStroke == 0)
74  return;
75 
76  writer.writeStartElement("se:GraphicStroke");
77 
78  const te::se::Graphic* graphic = graphicStroke->getGraphic();
79  assert(graphic);
80  Save(graphic, writer);
81 
82  WriteParameterValuePtrHelper("se:InitialGap", graphicStroke->getInitialGap(), writer);
83  WriteParameterValuePtrHelper("se:Gap", graphicStroke->getGap(), writer);
84 
85  writer.writeEndElement("se:GraphicStroke");
86 }
TESERIALIZATIONEXPORT te::se::ParameterValue * ReadParameterValue(te::xml::Reader &reader)
Utility methods for Symbology serialization.
TEDATAACCESSEXPORT void Save(const std::string &fileName)
Definition: Serializer.cpp:191
A GraphicStroke defines a repeated-linear graphic pattern to be used for stroking a line...
Definition: GraphicStroke.h:50
This class models a XML reader object.
Definition: Reader.h:55
const ParameterValue * getGap() const
void WriteParameterValuePtrHelper(const std::string &elementName, const te::se::ParameterValue *p, te::xml::Writer &writer)
Definition: Utils.cpp:46
virtual bool next()=0
It gets the next event to be read.
virtual void writeStartElement(const std::string &qName)
Definition: Writer.cpp:44
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
const ParameterValue * getInitialGap() const
Support for Graphic serialization.
A GraphicStroke defines a repeated-linear graphic pattern to be used for stroking a line...
const Graphic * getGraphic() const
TESERIALIZATIONEXPORT te::se::GraphicStroke * ReadGraphicStroke(te::xml::Reader &reader)
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.
A Graphic is a graphic symbol with an inherent shape, color(s), and possibly size.
Definition: Graphic.h:66
This class models a XML writer object.
Definition: Writer.h:52