All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LabelPlacement.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/LabelPlacement.cpp
22 
23  \brief Support for LabelPlacement serialization.
24 */
25 
26 // TerraLib
27 #include "../../se/LabelPlacement.h"
28 #include "../../xml/Reader.h"
29 #include "../../xml/Writer.h"
30 #include "LabelPlacement.h"
31 #include "LinePlacement.h"
32 #include "PointPlacement.h"
33 
34 // STL
35 #include <cassert>
36 #include <memory>
37 
39 {
40  assert(reader.getNodeType() == te::xml::START_ELEMENT);
41  assert(reader.getElementLocalName() == "LabelPlacement");
42 
43  reader.next();
44 
45  std::auto_ptr<te::se::LabelPlacement> lp(new te::se::LabelPlacement);
46 
47  if(reader.getElementLocalName() == "PointPlacement")
48  lp->setPointPlacement(ReadPointPlacement(reader));
49  else // LinePlacement
50  lp->setLinePlacement(ReadLinePlacement(reader));
51 
52  assert(reader.getNodeType() == te::xml::END_ELEMENT);
53  reader.next();
54 
55  return lp.release();
56 }
57 
59 {
60  if(lp == 0)
61  return;
62 
63  writer.writeStartElement("se:LabelPlacement");
64 
65  const te::se::PointPlacement* pp = lp->getPointPlacement();
66  if(pp)
67  Save(pp, writer);
68  else
69  {
70  const te::se::LinePlacement* linePlacement = lp->getLinePlacement();
71  assert(linePlacement);
72  Save(linePlacement, writer);
73  }
74 
75  writer.writeEndElement("se:LabelPlacement");
76 }
A PointPlacement specifies how a text label should be rendered relative to a geometric point...
The LabelPlacement specifies where and how a text label should be rendered relative to a geometry...
TEDATAACCESSEXPORT void Save(const std::string &fileName)
Definition: Serializer.cpp:191
const PointPlacement * getPointPlacement() const
This class models a XML reader object.
Definition: Reader.h:55
virtual bool next()=0
It gets the next event to be read.
virtual void writeStartElement(const std::string &qName)
Definition: Writer.cpp:44
TESERIALIZATIONEXPORT te::se::LabelPlacement * ReadLabelPlacement(te::xml::Reader &reader)
Support for LinePlacement serialization.
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::PointPlacement * ReadPointPlacement(te::xml::Reader &reader)
A LinePlacement specifies how a text label should be rendered relative to a linear geometry...
Definition: LinePlacement.h:61
The LabelPlacement specifies where and how a text label should be rendered relative to a geometry...
Support for PointPlacement serialization.
TESERIALIZATIONEXPORT te::se::LinePlacement * ReadLinePlacement(te::xml::Reader &reader)
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 LinePlacement * getLinePlacement() const
This class models a XML writer object.
Definition: Writer.h:52