All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Graphic.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/Graphic.cpp
22 
23  \brief Support for Graphic serialization.
24 */
25 
26 // TerraLib
27 #include "../../se/Graphic.h"
28 #include "../../xml/Reader.h"
29 #include "../../xml/Writer.h"
30 #include "AnchorPoint.h"
31 #include "Displacement.h"
32 #include "ExternalGraphic.h"
33 #include "Graphic.h"
34 #include "Mark.h"
35 #include "ParameterValue.h"
36 #include "Utils.h"
37 
38 // STL
39 #include <cassert>
40 #include <memory>
41 
43 {
44  assert(reader.getNodeType() == te::xml::START_ELEMENT);
45  assert(reader.getElementLocalName() == "Graphic");
46 
47  reader.next();
48 
49  std::auto_ptr<te::se::Graphic> graphic(new te::se::Graphic);
50 
51  while(reader.getNodeType() == te::xml::START_ELEMENT &&
52  (reader.getElementLocalName() == "Mark" ||
53  reader.getElementLocalName() == "ExternalGraphic"))
54  reader.getElementLocalName() == "Mark" ? graphic->add(ReadMark(reader)) : graphic->add(ReadExternalGraphic(reader));
55 
56  // Opacity
57  if(reader.getElementLocalName() == "Opacity")
58  {
59  reader.next();
60  graphic->setOpacity(ReadParameterValue(reader));
61  }
62 
63  // Size
64  if(reader.getElementLocalName() == "Size")
65  {
66  reader.next();
67  graphic->setSize(ReadParameterValue(reader));
68  }
69 
70  // Rotation
71  if(reader.getElementLocalName() == "Rotation")
72  {
73  reader.next();
74  graphic->setRotation(ReadParameterValue(reader));
75  }
76 
77  // AnchorPoint
78  if(reader.getElementLocalName() == "AnchorPoint")
79  graphic->setAnchorPoint(ReadAnchorPoint(reader));
80 
81  // Displacement
82  if(reader.getElementLocalName() == "Displacement")
83  graphic->setDisplacement(ReadDisplacement(reader));
84 
85  assert(reader.getNodeType() == te::xml::END_ELEMENT);
86  reader.next();
87 
88  return graphic.release();
89 }
90 
92 {
93  if(graphic == 0)
94  return;
95 
96  writer.writeStartElement("se:Graphic");
97 
98  const std::vector<te::se::Mark*> marks = graphic->getMarks();
99  for(std::size_t i = 0; i < marks.size(); ++i)
100  Save(marks[i], writer);
101 
102  const std::vector<te::se::ExternalGraphic*> egs = graphic->getExternalGraphics();
103  for(std::size_t i = 0; i < egs.size(); ++i)
104  Save(egs[i], writer);
105 
106  WriteParameterValuePtrHelper("se:Opacity", graphic->getOpacity(), writer);
107  WriteParameterValuePtrHelper("se:Size", graphic->getSize(), writer);
108  WriteParameterValuePtrHelper("se:Rotation", graphic->getRotation(), writer);
109 
110  Save(graphic->getAnchorPoint(), writer);
111  Save(graphic->getDisplacement(), writer);
112 
113  writer.writeEndElement("se:Graphic");
114 }
const AnchorPoint * getAnchorPoint() const
Definition: Graphic.cpp:142
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
Support for ExternalGraphic serialization.
This class models a XML reader object.
Definition: Reader.h:55
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.
TESERIALIZATIONEXPORT te::se::AnchorPoint * ReadAnchorPoint(te::xml::Reader &reader)
Definition: AnchorPoint.cpp:38
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
TESERIALIZATIONEXPORT te::se::ExternalGraphic * ReadExternalGraphic(te::xml::Reader &reader)
Support for Displacement serialization.
TESERIALIZATIONEXPORT te::se::Mark * ReadMark(te::xml::Reader &reader)
Definition: Mark.cpp:41
const Displacement * getDisplacement() const
Definition: Graphic.cpp:153
const ParameterValue * getOpacity() const
Definition: Graphic.cpp:109
Support for Mark serialization.
const ParameterValue * getSize() const
Definition: Graphic.cpp:120
TESERIALIZATIONEXPORT te::se::Displacement * ReadDisplacement(te::xml::Reader &reader)
const ParameterValue * getRotation() const
Definition: Graphic.cpp:131
const std::vector< ExternalGraphic * > getExternalGraphics() const
Definition: Graphic.cpp:76
Support for AnchorPoint serialization.
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.
A Graphic is a graphic symbol with an inherent shape, color(s), and possibly size.
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
const std::vector< Mark * > getMarks() const
Definition: Graphic.cpp:98
This class models a XML writer object.
Definition: Writer.h:52