Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:41:53

0001 // This file is part of the actsvg package.
0002 //
0003 // Copyright (C) 2022 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include <iostream>
0012 #include <map>
0013 #include <stdexcept>
0014 #include <string>
0015 #include <vector>
0016 
0017 #include "defs.hpp"
0018 #include "generators.hpp"
0019 #include "style.hpp"
0020 #include "svg.hpp"
0021 #include "utils.hpp"
0022 
0023 namespace actsvg {
0024 
0025 namespace detail {
0026 /** Helper method to estimate ranges of an object
0027  *
0028  * @param _o_ is the svg object in question (to be adapted)
0029  * @param vertices_ are the input vertices
0030  **/
0031 void adapt_range(svg::object &_o_, const std::vector<point2> &vertices_);
0032 
0033 }  // namespace detail
0034 
0035 /** The draw namespace encapsulates the CORRECT
0036  * left handed x-y system from the AWKWARD SVG draw system, and applies
0037  * the transform to it if necessary
0038  *
0039  * That is its main purpose (together with given allowing to
0040  * give an identifier an connect objects.
0041  *
0042  * */
0043 
0044 namespace draw {
0045 
0046 /** Method to draw a simple line
0047  *
0048  * @note will perform the y switch
0049  *
0050  * @param id_ is the identification tag of this line
0051  * @param start_ is the start point of the line
0052  * @param end_ is the end point of the line
0053  * @param stroke_ are the stroke parameters
0054  * @param transform_ is an optional transform of the object
0055  *
0056  * @note transform is directly applied and not attached as property
0057  * for raw drawing objects
0058  *
0059  * @return an svg object for the line
0060  */
0061 svg::object line(const std::string &id_, const point2 &start_,
0062                  const point2 &end_,
0063                  const style::stroke &stroke_ = style::stroke(),
0064                  const style::transform &transform_ = style::transform());
0065 
0066 /** Method to draw an arc
0067  *
0068  * @param id_ is the identification tag of this line
0069  * @param r_ the radius
0070  * @param start_ is the start point of the line
0071  * @param end_ is the end point of the line
0072  * @param stroke_ are the stroke parameters
0073  * @param transform_ is an optional transform of the object
0074  *
0075  * @note transform is directly applied and not attached as property
0076  * for raw drawing objects
0077  *
0078  * @return an svg object for the line
0079  */
0080 svg::object arc(const std::string &id_, scalar r_, const point2 &start_,
0081                 const point2 &end_, const style::fill &fill_ = style::fill(),
0082                 const style::stroke &stroke_ = style::stroke(),
0083                 const style::transform &transform_ = style::transform());
0084 
0085 /** Draw a Polyline path
0086  *
0087  * @param id_ is the identification
0088  * @param points_ are the points of the polyline
0089  * @param stroke_ is the stroke style
0090  * @param transform_ is the optional transform
0091  *
0092  * @return an object representing the polyline
0093  */
0094 svg::object polyline(const std::string &id_, const std::vector<point2> &points_,
0095                      const style::stroke &stroke = style::stroke(),
0096                      const style::transform &transform_ = style::transform());
0097 
0098 /** Draw a Bezier path
0099  * input is defined as pairs of position, momentum
0100  *
0101  * @param id_ is the identification
0102  * @param xds_ is the collection of point, direction tuples
0103  * @param stroke_ is the stroke style
0104  * @param transform_ is the optional transform
0105  *
0106  * @return a group object representing the curve
0107  */
0108 svg::object bezier(const std::string &id_,
0109                    const std::vector<std::array<point2, 2u>> &xds_,
0110                    const style::stroke &stroke_ = style::stroke(),
0111                    const style::transform &transform_ = style::transform());
0112 
0113 /** Draw a circle object
0114  *  - will translate into ellipse to allow for a scale
0115  *
0116  * @param id_ is the identification
0117  * @param p_ the position
0118  * @param r_ the radius
0119  * @param fill_ is the fill style
0120  * @param stroke_ is the stroke style
0121  * @param transform_ is the optional transform
0122  *
0123  * @note transform is directly applied and not attached as property
0124  * for raw drawing objects
0125  *
0126  * @return an svg object for the circle
0127  */
0128 svg::object circle(const std::string &id_, const point2 &p_, scalar r_,
0129                    const style::fill &fill_ = style::fill(),
0130                    const style::stroke &stroke_ = style::stroke(),
0131                    const style::transform &transform_ = style::transform());
0132 
0133 /** Draw an ellipse object
0134  *
0135  * @param id_ is the identification
0136  * @param p_ the position
0137  * @param rs_ the radii
0138  * @param fill_ is the fill style
0139  * @param stroke_ is the stroke style
0140  * @param transform_ is the optional transform
0141  *
0142  * @note transform is directly applied and not attached as property
0143  * for raw drawing objects
0144  *
0145  * @return an svg object for the ellipse
0146  */
0147 svg::object ellipse(const std::string &id_, const point2 &p_,
0148                     const std::array<scalar, 2> &rs_,
0149                     const style::fill &fill_ = style::fill(),
0150                     const style::stroke &stroke_ = style::stroke(),
0151                     const style::transform &transform_ = style::transform());
0152 
0153 /** Draw a polygon object
0154  *
0155  * @param id_ is the identification
0156  * @param polygon_ the polygon points
0157  * @param fill_ is the fill style
0158  * @param stroke_ is the stroke style
0159  * @param transform_ is the optional transform
0160  * @param apply_transform_ is the option to either apply the transform
0161  * or not
0162  *
0163  * @note transform is directly applied and not attached as property
0164  * for raw drawing objects
0165  *
0166  * @return an svg object for the polygon
0167  */
0168 svg::object polygon(const std::string &id_, const std::vector<point2> &polygon_,
0169                     const style::fill &fill_ = style::fill(),
0170                     const style::stroke &stroke_ = style::stroke(),
0171                     const style::transform &transform_ = style::transform(),
0172                     bool apply_transform_ = true);
0173 
0174 /** Draw a rectangle object
0175  *
0176  * @param id_ is the rectangle object id
0177  * @param c_ is the center position
0178  * @param half_x is the halflength in x
0179  * @param half_y is the halflength in y
0180  * @param fill_ are the fill parameters
0181  * @param stroke_ are the stroke parameters
0182  * @param transform_ defines the rectangle transform
0183  *
0184  * @return an svg object for the rectangle
0185  */
0186 svg::object rectangle(const std::string &id_, const point2 &c_, scalar half_x,
0187                       scalar half_y, const style::fill &fill_ = style::fill{},
0188                       const style::stroke &stroke_ = style::stroke(),
0189                       const style::transform &transform_ = style::transform());
0190 
0191 /** Draw a text object - unconnected
0192  *
0193  * @param id_ is the text object id
0194  * @param p_ is the text position
0195  * @param text_ is the actual text to be drawn
0196  * @param font_ is the font style specification
0197  * @param transform_ defines the text transform
0198  *
0199  * @return an svg object for the text
0200  *
0201  **/
0202 svg::object text(const std::string &id_, const point2 &p_,
0203                  const std::vector<std::string> &text_,
0204                  const style::font &font_ = style::font(),
0205                  const style::transform &transform_ = style::transform());
0206 
0207 /** Draw a label
0208  *
0209  * @param id_ is the label object id
0210  *
0211  * @return a label object
0212  **/
0213 svg::object label(const std::string &id_, const style::label &l_);
0214 
0215 /** Draw a text object - connected
0216  *
0217  * @param id_ is the text object id
0218  * @param p_ is the text position
0219  * @param text_ is the actual text to be drawn
0220  * @param font_ is the font style specification
0221  * @param transform_ defines the text transform
0222  * @param object_ is the connected object
0223  * @param highlight_ are the highlighting options
0224  *
0225  * @return an svg object with highlight connection
0226  *
0227  **/
0228 svg::object connected_text(
0229     const std::string &id_, const point2 &p_,
0230     const std::vector<std::string> &text_, const style::font &font_,
0231     const style::transform &transform_, const svg::object &object_,
0232     const std::vector<std::string> &highlight_ = {"mouseover", "mouseout"});
0233 
0234 /** Draw an image object - connected
0235  *
0236  * @param id_ is the image object id
0237  * @param href_ is the image object href field
0238  * @param height_ is the image object height field
0239  * @param width_ is the image object width field
0240  * @param x_ is the image object x field
0241  * @param y_ is the image object y field
0242  * @param object_ is the connected object
0243  * @param highlight_ are the highlighting options
0244  * @param onerror_ is the image object onerror field
0245  *
0246  * @return an svg object with highlight connection
0247  *
0248  **/
0249 svg::object image_box(const std::string &id_, const std::string &href_,
0250                       const scalar &height_, const scalar &width_,
0251                       const scalar &x_, const scalar &y_,
0252                       const svg::object &object_,
0253                       const std::vector<std::string> &highlight_,
0254                       const std::string &onerror_);
0255 
0256 /** Draw a text object - connected
0257  *
0258  * @param id_ is the text object id
0259  * @param p_ is the position of the info box
0260  * @param title_ is the title of the info box
0261  * @param title_fill_ is the fill color of the title
0262  * @param title_font_ is the font style of the title
0263  * @param text_ is the actual text to be drawn
0264  * @param text_fill_ is the fill color of the text box
0265  * @param text_font_ is the font style of the text box
0266  * @param stroke_ is the stroke
0267  * @param object_ is the connected object
0268  * @param highlight_ are the highlighting options
0269  *
0270  * @return an svg object with highlight connection
0271  *
0272  **/
0273 svg::object connected_info_box(
0274     const std::string &id_, const point2 &p_, const std::string &title_,
0275     const style::fill &title_fill_, const style::font &title_font_,
0276     const std::vector<std::string> &text_, const style::fill &text_fill_,
0277     const style::font &text_font_, const style::stroke &stroke_,
0278     const svg::object &object_,
0279     const std::vector<std::string> &highlight_ = {"mouseover", "mouseout"});
0280 
0281 /** Draw a tiled cartesian grid - ready for connecting
0282  *
0283  * @param id_ the grid identification
0284  * @param l0_edges_ are the edges in l0
0285  * @param l1_edges_ are the edges in l1
0286  * @param fill_ is the fill style
0287  * @param stroke_ is the stroke style
0288  * @param transform_ is the optional transform
0289  *
0290  * @return a simple cartesian grid
0291  */
0292 svg::object cartesian_grid(
0293     const std::string &id_, const std::vector<scalar> &l0_edges_,
0294     const std::vector<scalar> &l1_edges_,
0295     const style::stroke &stroke_ = style::stroke(),
0296     const style::transform &transform_ = style::transform());
0297 
0298 /** Draw a tiled cartesian grid - ready for connecting
0299  *
0300  * @param id_ the grid identification
0301  * @param l0_edges_ are the edges in l0
0302  * @param l1_edges_ are the edges in l1
0303  * @param fill_ is the fill style
0304  * @param stroke_ is the stroke style
0305  * @param transform_ is the optional transform
0306  *
0307  * @note - the single objects of the grid can be found by
0308  * their unique name "id_+_X_Y" when X is the bin in the
0309  * first local and j the bin in the second local coordinate
0310  *
0311  * @return a tiled grid with internal objects
0312  */
0313 svg::object tiled_cartesian_grid(
0314     const std::string &id_, const std::vector<scalar> &l0_edges_,
0315     const std::vector<scalar> &l1_edges_,
0316     const style::fill &fill_ = style::fill(),
0317     const style::stroke &stroke_ = style::stroke(),
0318     const style::transform &transform_ = style::transform());
0319 
0320 /** Draw a simple fan grid
0321  *
0322  * @param id_ the grid identification
0323  * @param x_low_edges_ are the edges in x at low y
0324  * @param x_high_edges_ are the edges in x at high y
0325  * @param y_edges_ are the edges in phi
0326  * @param stroke_ is the stroke style
0327  * @param transform_ is the optional transform
0328  *
0329  * @return a simple faned grid structure
0330  */
0331 svg::object fan_grid(
0332     const std::string &id_, const std::vector<scalar> &x_low_edges_,
0333     const std::vector<scalar> &x_high_edges_,
0334     const std::vector<scalar> &y_edges_,
0335     const style::stroke &stroke_ = style::stroke(),
0336     const style::transform &transform_ = style::transform()) noexcept(false);
0337 
0338 /** Draw a simple fan grid
0339  *
0340  * @param id_ the grid identification
0341  * @param x_low_edges_ are the edges in x at low y
0342  * @param x_high_edges_ are the edges in x at high y
0343  * @param y_edges_ are the edges in phi
0344  * @param fill_ is the fill style
0345  * @param stroke_ is the stroke style
0346  * @param transform_ is the optional transform
0347  *
0348  * @note - the single objects of the grid can be found by
0349  * their unique name "id_+_X_Y" when X is the bin in the
0350  * first local and j the bin in the second local coordinate
0351  *
0352  * @return a tiled grid with contained individual cells
0353  */
0354 svg::object tiled_fan_grid(
0355     const std::string &id_, const std::vector<scalar> &x_low_edges_,
0356     const std::vector<scalar> &x_high_edges_,
0357     const std::vector<scalar> &y_edges_,
0358     const style::fill &fill_ = style::fill(),
0359     const style::stroke &stroke_ = style::stroke(),
0360     const style::transform &transform_ = style::transform()) noexcept(false);
0361 
0362 /** Draw a simple polar grid
0363  *
0364  * @param id_ the grid identification
0365  * @param r_edges_ are the edges in r
0366  * @param phi_edges_ are the edges in phi
0367  * @param stroke_ is the stroke style
0368  * @param transform_ is the optional transform
0369  *
0370  * @return a simple polar grid object
0371  */
0372 svg::object polar_grid(const std::string &id_,
0373                        const std::vector<scalar> &r_edges_,
0374                        const std::vector<scalar> &phi_edges_,
0375                        const style::stroke &stroke_ = style::stroke(),
0376                        const style::transform &transform_ = style::transform());
0377 
0378 /** Draw a connected polar grid
0379  *
0380  * @param id_ the grid identification
0381  * @param r_edges_ are the edges in r
0382  * @param phi_edges_ are the edges in phi
0383  * @param fill_ is the fill style
0384  * @param stroke_ is the stroke style
0385  * @param transform_ is the optional transform
0386  *
0387  * @note - the single objects of the grid can be found by
0388  * their unique name "id_+_X_Y" when X is the bin in the
0389  * first local and j the bin in the second local coordinate
0390  *
0391  * @return a tiled polar grid in individual objects
0392  */
0393 svg::object tiled_polar_grid(
0394     const std::string &id_, const std::vector<scalar> &r_edges_,
0395     const std::vector<scalar> &phi_edges_,
0396     const style::fill &fill_ = style::fill(),
0397     const style::stroke &stroke_ = style::stroke(),
0398     const style::transform &transform_ = style::transform());
0399 
0400 /** Marker definition
0401  *
0402  *  Arrorws types are: <, <<, <|, |<, |<<, |<|, o, x, *
0403  * @param id_ is the marker identification
0404  * @param at_ is the position of the marker
0405  * @param marker_ is the marker style
0406  * @param rot_ is the rotation in [pi,phi)]
0407  *
0408  * @return an svg object for the marker group
0409  **/
0410 svg::object marker(const std::string &id_, const point2 &at_,
0411                    const style::marker &marker_, scalar rot_ = 0.);
0412 
0413 /** Draw a measure
0414  *
0415  * @param id_ is the identification tag of this object
0416  * @param start_ is the start point of the line
0417  * @param end_ is the end point of the line
0418  * @param stroke_ are the stroke parameters
0419  * @param start_marker_ are the marker parameters at start
0420  * @param end_marker_ are the marker parameters at start
0421  * @param font_ are the font parameters
0422  * @param label_ is the label associated
0423  * @param label_pos_ is the label position
0424  *
0425  * @return an svg object for the measure
0426  */
0427 svg::object measure(const std::string &id_, const point2 &start_,
0428                     const point2 &end_,
0429                     const style::stroke &stroke_ = style::stroke(),
0430                     const style::marker &start_marker_ = style::marker({"|<"}),
0431                     const style::marker &end_marker_ = style::marker({"|<"}),
0432                     const style::font &font_ = style::font(),
0433                     const std::string &label_ = "",
0434                     const point2 &label_pos_ = {0., 0.});
0435 
0436 /** Draw an arc measure
0437  *
0438  * @param id_ is the identification tag of this object
0439  * @param r_ the radius
0440  * @param start_ is the start point of the line, per definition
0441  * with smaller phi
0442  * @param end_ is the end point of the line, defines the marker
0443  * @param stroke_ are the stroke parameters
0444  * @param start_marker_ are the marker parameters
0445  * @param end_marker_ are the marker parameters
0446  * @param font_ are the font parameters
0447  * @param label_ is the label associated
0448  * @param label_pos_ is the label position
0449  *
0450  * @return an svg object for the measure
0451  */
0452 svg::object arc_measure(
0453     const std::string &id_, scalar r_, const point2 &start_, const point2 &end_,
0454     const style::stroke &stroke_ = style::stroke(),
0455     const style::marker &start_marker_ = style::marker(),
0456     const style::marker &end_marker_ = style::marker({"|<"}),
0457     const style::font &font_ = style::font(), const std::string &label_ = "",
0458     const point2 &label_pos_ = {0., 0.});
0459 
0460 /** Draw an arrow
0461  *
0462  * @param id_ is the identification tag of this object
0463  * @param start_ is the start point of the line
0464  * @param end_ is the end point of the line
0465  * @param stroke_ are the stroke parameters
0466  * @param start_marker_ are the marker parameters at start
0467  * @param end_marker_ are the marker parameters at start
0468  *
0469  * @return an svg object for the arrow
0470  */
0471 svg::object arrow(const std::string &id_, const point2 &start_,
0472                   const point2 &end_,
0473                   const style::stroke &stroke_ = style::stroke(),
0474                   const style::marker &start_marker_ = style::marker({"|<"}),
0475                   const style::marker &end_marker_ = style::marker({"|<"}));
0476 
0477 /** Draw an x-y axes system
0478  *
0479  * @param id_ is the id tag of this object
0480  * @param x_range_ is the x range of the axes to be drawn
0481  * @param y_range_ is the y range of the axes to be drawn
0482  * @param stroke_ are the stroke parameters
0483  * @param x_label_ is the x label of the axis system
0484  * @param y_label_ is the y label of the axis system
0485  * @param font_ are the font parameters
0486  * @param markers_ are the 4 markers on each axis end
0487  *
0488  * @return an svg object representing the axes
0489  */
0490 svg::object x_y_axes(const std::string &id_,
0491                      const std::array<scalar, 2> &x_range_,
0492                      const std::array<scalar, 2> &y_range_,
0493                      const style::stroke &stroke_ = style::stroke(),
0494                      const std::string &x_label_ = "",
0495                      const std::string &y_label_ = "",
0496                      const style::font &font_ = style::font(),
0497                      const style::axis_markers<2u> &markers_ = {
0498                          __standard_axis_markers, __standard_axis_markers});
0499 
0500 /** Helper method to create a gradient object
0501  *
0502  * @param g_ is the gradient definition
0503  *
0504  * @return the gradient as an object
0505  **/
0506 svg::object gradient_as_object(const style::gradient &g_);
0507 
0508 /** Place a gradient box
0509  *
0510  * @param id_ is the identification of this surface
0511  * @param p_ is the position of the box
0512  * @param w_h_ is the width and height of the box
0513  * @param stops_ is the gradient definition
0514  * @param label_ is the label string (optional)
0515  * @param font_ is the font of the box
0516  * @param transform_ is the transform of the box
0517  *
0518  * @note make sure the gradient is added to the file definition
0519  * @note this will flip the x-axis
0520  *
0521  * @return the create object
0522  */
0523 svg::object gradient_box(
0524     const std::string &id_, const point2 &p_, const std::array<scalar, 2> &w_h_,
0525     const std::vector<std::tuple<style::gradient::stop, scalar>> &stops_,
0526     const style::label &label_ = style::label{},
0527     const style::stroke &stroke_ = style::stroke(),
0528     const style::font &font_ = style::font{},
0529     const style::transform t_ = style::transform());
0530 
0531 /** Place a copy with different attributes via xling
0532  *
0533  * @param id_ the identification of this surface
0534  * @param ro_ the reference object
0535  * @param f_ the fill of the new object
0536  * @param s_ the stroke of the new object
0537  * @param t_ the transform of the new object
0538  *
0539  * @return the create object from reference
0540  */
0541 svg::object from_template(const std::string &id_, const svg::object &ro_,
0542                           const style::fill &f_ = style::fill(),
0543                           const style::stroke &s_ = style::stroke(),
0544                           const style::transform t_ = style::transform());
0545 
0546 }  // namespace draw
0547 
0548 }  // namespace actsvg