Belle II Software  release-05-01-25
SVGPrimitivePlotter.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <tracking/trackFindingCDC/display/PrimitivePlotter.h>
13 #include <sstream>
14 
15 namespace Belle2 {
20  namespace TrackFindingCDC {
21 
23  class SVGPrimitivePlotter : public PrimitivePlotter {
24 
25  private:
27  static const int s_defaultNIndentationSpaces;
28 
30  static const int s_addtionalNIndentationSpaces;
31 
32  public:
35 
40  explicit SVGPrimitivePlotter(const AttributeMap& svgAttributes);
41 
44 
45  public:
50  std::unique_ptr<PrimitivePlotter> clone() const override;
51 
52  public:
62  void drawLine(float startX,
63  float startY,
64  float endX,
65  float endY,
66  const AttributeMap& attributeMap = AttributeMap()) override;
67 
77  void drawArrow(float startX,
78  float startY,
79  float endX,
80  float endY,
81  const AttributeMap& attributeMap = AttributeMap()) override;
82 
91  void drawCircle(float centerX,
92  float centerY,
93  float radius,
94  const AttributeMap& attributeMap = AttributeMap()) override;
95 
108  void drawCircleArc(float startX,
109  float startY,
110  float endX,
111  float endY,
112  float radius,
113  bool longArc,
114  bool sweepFlag,
115  const AttributeMap& attributeMap = AttributeMap()) override;
116 
125  void drawCurve(const std::vector<std::array<float, 2>>& points,
126  const std::vector<std::array<float, 2>>& tangents,
127  const AttributeMap& attributeMap = AttributeMap()) override;
128 
132  void startGroup(const AttributeMap& attributeMap = AttributeMap()) override;
133 
137  void endGroup() override;
138 
149  const std::string save(const std::string& fileName) override;
150 
154  void clear() override;
155 
156  private:
158  void indent();
159 
161  void dedent();
162 
168  void writeSVGHeader(std::ostream& outputStream);
169 
171  void writeSVGDefs(std::ostream& outputStream);
172 
183  void writeOpeningTag(std::ostream& outputStream,
184  const std::string& tagName,
185  const AttributeMap& geometryAttributeMap = AttributeMap(),
186  const AttributeMap& styleAttributeMap = AttributeMap());
187 
198  void writeStandAloneTag(std::ostream& outputStream,
199  const std::string& tagName,
200  const AttributeMap& geometryAttributeMap = AttributeMap(),
201  const AttributeMap& styleAttributeMap = AttributeMap());
202 
216  void writeTagIntern(std::ostream& outputStream,
217  const std::string& tagName,
218  const AttributeMap& geometryAttributeMap = AttributeMap(),
219  const AttributeMap& styleAttributeMap = AttributeMap());
220 
227  void writeAttributes(std::ostream& outputStream,
228  const AttributeMap& attributeMap);
229 
236  void writeClosingTag(std::ostream& outputStream,
237  const std::string& tagName);
238 
239  private:
241  std::ostringstream m_svgContentStream;
242 
245 
248 
249  };
250 
251  }
253 }
Belle2::TrackFindingCDC::SVGPrimitivePlotter::clone
std::unique_ptr< PrimitivePlotter > clone() const override
Returns a newly created plotter instance containing all information of this.
Definition: SVGPrimitivePlotter.cc:46
Belle2::TrackFindingCDC::SVGPrimitivePlotter::SVGPrimitivePlotter
SVGPrimitivePlotter()
Default constructor for ROOT compatibility.
Definition: SVGPrimitivePlotter.cc:22
Belle2::TrackFindingCDC::SVGPrimitivePlotter::writeSVGDefs
void writeSVGDefs(std::ostream &outputStream)
Writes a preamble of <defs> that define an arrow cap which can be referenced by lines.
Definition: SVGPrimitivePlotter.cc:321
Belle2::TrackFindingCDC::SVGPrimitivePlotter::drawArrow
void drawArrow(float startX, float startY, float endX, float endY, const AttributeMap &attributeMap=AttributeMap()) override
Adds an arrow to the plot.
Definition: SVGPrimitivePlotter.cc:71
Belle2::TrackFindingCDC::SVGPrimitivePlotter::dedent
void dedent()
Decreases the current indention by one.
Definition: SVGPrimitivePlotter.cc:310
Belle2::TrackFindingCDC::SVGPrimitivePlotter::m_nIndentationSpaces
int m_nIndentationSpaces
Memory for the number of spaces that shall be prepended to each line.
Definition: SVGPrimitivePlotter.h:252
Belle2::TrackFindingCDC::PrimitivePlotter::AttributeMap
Belle2::TrackFindingCDC::AttributeMap AttributeMap
A map type for attributes names to values for additional drawing information.
Definition: PrimitivePlotter.h:39
Belle2::TrackFindingCDC::SVGPrimitivePlotter::drawLine
void drawLine(float startX, float startY, float endX, float endY, const AttributeMap &attributeMap=AttributeMap()) override
Adds a line to the plot.
Definition: SVGPrimitivePlotter.cc:51
Belle2::TrackFindingCDC::SVGPrimitivePlotter::writeClosingTag
void writeClosingTag(std::ostream &outputStream, const std::string &tagName)
Writes a closing xml tag to the given output stream.
Definition: SVGPrimitivePlotter.cc:465
Belle2::TrackFindingCDC::SVGPrimitivePlotter::writeAttributes
void writeAttributes(std::ostream &outputStream, const AttributeMap &attributeMap)
Writes attribute specification that belongs between the <, > brakets after the tag name.
Definition: SVGPrimitivePlotter.cc:437
Belle2::TrackFindingCDC::SVGPrimitivePlotter::m_svgAttributes
AttributeMap m_svgAttributes
Memory for additional attributes to the toplevel svg element.
Definition: SVGPrimitivePlotter.h:255
Belle2::TrackFindingCDC::SVGPrimitivePlotter::drawCircle
void drawCircle(float centerX, float centerY, float radius, const AttributeMap &attributeMap=AttributeMap()) override
Adds a circle to the plot.
Definition: SVGPrimitivePlotter.cc:91
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::SVGPrimitivePlotter::indent
void indent()
Increases the current indention by one.
Definition: SVGPrimitivePlotter.cc:305
Belle2::TrackFindingCDC::SVGPrimitivePlotter::save
const std::string save(const std::string &fileName) override
Saves the current plot state to a file.
Definition: SVGPrimitivePlotter.cc:238
Belle2::TrackFindingCDC::SVGPrimitivePlotter::writeOpeningTag
void writeOpeningTag(std::ostream &outputStream, const std::string &tagName, const AttributeMap &geometryAttributeMap=AttributeMap(), const AttributeMap &styleAttributeMap=AttributeMap())
Writes an opening xml tag to the given output stream taking attributes from two sources.
Definition: SVGPrimitivePlotter.cc:350
Belle2::TrackFindingCDC::SVGPrimitivePlotter::drawCurve
void drawCurve(const std::vector< std::array< float, 2 >> &points, const std::vector< std::array< float, 2 >> &tangents, const AttributeMap &attributeMap=AttributeMap()) override
Adds a smooth curve to the plot.
Definition: SVGPrimitivePlotter.cc:154
Belle2::TrackFindingCDC::SVGPrimitivePlotter::writeStandAloneTag
void writeStandAloneTag(std::ostream &outputStream, const std::string &tagName, const AttributeMap &geometryAttributeMap=AttributeMap(), const AttributeMap &styleAttributeMap=AttributeMap())
Writes a stand alone xml tag to the given output stream taking attributes from two sources.
Definition: SVGPrimitivePlotter.cc:388
Belle2::TrackFindingCDC::SVGPrimitivePlotter::endGroup
void endGroup() override
Indicates the end of a group of drawn elements.
Definition: SVGPrimitivePlotter.cc:233
Belle2::TrackFindingCDC::SVGPrimitivePlotter::s_addtionalNIndentationSpaces
static const int s_addtionalNIndentationSpaces
Constant for the additional number of space to be prepended with each open tag group.
Definition: SVGPrimitivePlotter.h:38
Belle2::TrackFindingCDC::SVGPrimitivePlotter::writeTagIntern
void writeTagIntern(std::ostream &outputStream, const std::string &tagName, const AttributeMap &geometryAttributeMap=AttributeMap(), const AttributeMap &styleAttributeMap=AttributeMap())
Writes part that belongs between the <, > brakets.
Definition: SVGPrimitivePlotter.cc:416
Belle2::TrackFindingCDC::SVGPrimitivePlotter
A concrete plotter that can draw primitive objects to standalone SVG files.
Definition: SVGPrimitivePlotter.h:31
Belle2::TrackFindingCDC::SVGPrimitivePlotter::startGroup
void startGroup(const AttributeMap &attributeMap=AttributeMap()) override
Indicates the start of a group of drawn elements.
Definition: SVGPrimitivePlotter.cc:228
Belle2::TrackFindingCDC::SVGPrimitivePlotter::s_defaultNIndentationSpaces
static const int s_defaultNIndentationSpaces
Constant for the number of indention space to be used within the svg block.
Definition: SVGPrimitivePlotter.h:35
Belle2::TrackFindingCDC::SVGPrimitivePlotter::clear
void clear() override
Clears all drawed elements from the plotter.
Definition: SVGPrimitivePlotter.cc:298
Belle2::TrackFindingCDC::SVGPrimitivePlotter::drawCircleArc
void drawCircleArc(float startX, float startY, float endX, float endY, float radius, bool longArc, bool sweepFlag, const AttributeMap &attributeMap=AttributeMap()) override
Adds a circle arc to the plot.
Definition: SVGPrimitivePlotter.cc:109
Belle2::TrackFindingCDC::SVGPrimitivePlotter::writeSVGHeader
void writeSVGHeader(std::ostream &outputStream)
Writes the xml header that indicates that this document will be a SVG document to the given output st...
Definition: SVGPrimitivePlotter.cc:315
Belle2::TrackFindingCDC::SVGPrimitivePlotter::m_svgContentStream
std::ostringstream m_svgContentStream
Memory for the plotted elements. This contains only the fragment that is inbetween the svg tags and c...
Definition: SVGPrimitivePlotter.h:249