Belle II Software  release-08-01-10
SVGPrimitivePlotter.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #pragma once
9 
10 #include <tracking/trackFindingCDC/display/PrimitivePlotter.h>
11 #include <sstream>
12 
13 namespace Belle2 {
18  namespace TrackFindingCDC {
19 
22 
23  private:
25  static const int s_defaultNIndentationSpaces;
26 
29 
30  public:
33 
38  explicit SVGPrimitivePlotter(const AttributeMap& svgAttributes);
39 
42 
43  public:
48  std::unique_ptr<PrimitivePlotter> clone() const override;
49 
50  public:
60  void drawLine(float startX,
61  float startY,
62  float endX,
63  float endY,
64  const AttributeMap& attributeMap = AttributeMap()) override;
65 
75  void drawArrow(float startX,
76  float startY,
77  float endX,
78  float endY,
79  const AttributeMap& attributeMap = AttributeMap()) override;
80 
89  void drawCircle(float centerX,
90  float centerY,
91  float radius,
92  const AttributeMap& attributeMap = AttributeMap()) override;
93 
106  void drawCircleArc(float startX,
107  float startY,
108  float endX,
109  float endY,
110  float radius,
111  bool longArc,
112  bool sweepFlag,
113  const AttributeMap& attributeMap = AttributeMap()) override;
114 
123  void drawCurve(const std::vector<std::array<float, 2>>& points,
124  const std::vector<std::array<float, 2>>& tangents,
125  const AttributeMap& attributeMap = AttributeMap()) override;
126 
130  void startGroup(const AttributeMap& attributeMap = AttributeMap()) override;
131 
135  void endGroup() override;
136 
147  const std::string save(const std::string& fileName) override;
148 
152  void clear() override;
153 
154  private:
156  void indent();
157 
159  void dedent();
160 
166  void writeSVGHeader(std::ostream& outputStream);
167 
169  void writeSVGDefs(std::ostream& outputStream);
170 
181  void writeOpeningTag(std::ostream& outputStream,
182  const std::string& tagName,
183  const AttributeMap& geometryAttributeMap = AttributeMap(),
184  const AttributeMap& styleAttributeMap = AttributeMap());
185 
196  void writeStandAloneTag(std::ostream& outputStream,
197  const std::string& tagName,
198  const AttributeMap& geometryAttributeMap = AttributeMap(),
199  const AttributeMap& styleAttributeMap = AttributeMap());
200 
214  void writeTagIntern(std::ostream& outputStream,
215  const std::string& tagName,
216  const AttributeMap& geometryAttributeMap = AttributeMap(),
217  const AttributeMap& styleAttributeMap = AttributeMap());
218 
225  void writeAttributes(std::ostream& outputStream,
226  const AttributeMap& attributeMap);
227 
234  void writeClosingTag(std::ostream& outputStream,
235  const std::string& tagName);
236 
237  private:
239  std::ostringstream m_svgContentStream;
240 
243 
246 
247  };
248 
249  }
251 }
A base class for plots of primitive objects.
Belle2::TrackFindingCDC::AttributeMap AttributeMap
A map type for attributes names to values for additional drawing information.
A concrete plotter that can draw primitive objects to standalone SVG files.
void startGroup(const AttributeMap &attributeMap=AttributeMap()) override
Indicates the start of a group of drawn elements.
std::unique_ptr< PrimitivePlotter > clone() const override
Returns a newly created plotter instance containing all information of this.
void indent()
Increases the current indention by one.
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.
void writeAttributes(std::ostream &outputStream, const AttributeMap &attributeMap)
Writes attribute specification that belongs between the <, > brakets after the tag name.
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.
std::ostringstream m_svgContentStream
Memory for the plotted elements. This contains only the fragment that is inbetween the svg tags and c...
int m_nIndentationSpaces
Memory for the number of spaces that shall be prepended to each line.
void writeSVGDefs(std::ostream &outputStream)
Writes a preamble of definitions that define an arrow cap which can be referenced by lines.
static const int s_defaultNIndentationSpaces
Constant for the number of indention space to be used within the svg block.
AttributeMap m_svgAttributes
Memory for additional attributes to the toplevel svg element.
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.
void drawCircle(float centerX, float centerY, float radius, const AttributeMap &attributeMap=AttributeMap()) override
Adds a circle to the plot.
SVGPrimitivePlotter()
Default constructor for ROOT compatibility.
void writeSVGHeader(std::ostream &outputStream)
Writes the xml header that indicates that this document will be a SVG document to the given output st...
void drawLine(float startX, float startY, float endX, float endY, const AttributeMap &attributeMap=AttributeMap()) override
Adds a line to the plot.
void drawArrow(float startX, float startY, float endX, float endY, const AttributeMap &attributeMap=AttributeMap()) override
Adds an arrow to the plot.
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.
void dedent()
Decreases the current indention by one.
void clear() override
Clears all drawed elements from the plotter.
static const int s_addtionalNIndentationSpaces
Constant for the additional number of space to be prepended with each open tag group.
const std::string save(const std::string &fileName) override
Saves the current plot state to a file.
void writeTagIntern(std::ostream &outputStream, const std::string &tagName, const AttributeMap &geometryAttributeMap=AttributeMap(), const AttributeMap &styleAttributeMap=AttributeMap())
Writes part that belongs between the <, > brakets.
void endGroup() override
Indicates the end of a group of drawn elements.
void writeClosingTag(std::ostream &outputStream, const std::string &tagName)
Writes a closing xml tag to the given output stream.
Abstract base class for different kinds of events.