Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-17 09:38:03

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 <cmath>
0012 #include <fstream>
0013 #include <map>
0014 #include <vector>
0015 
0016 #include "draw.hpp"
0017 #include "svg.hpp"
0018 #include "utils.hpp"
0019 
0020 namespace actsvg {
0021 
0022 namespace connectors {
0023 
0024 // The type of connections that exist
0025 enum type { e_highlight, e_associate_id, e_associate_info };
0026 
0027 /** Helper method to connect objects
0028  *
0029  * @param sources_ are the source objects
0030  * @param targests_ are the target objects
0031  * @param s_t_connections_ are the connections from source to target
0032  * @param ls_ label the source or not (in case of multiple connection sheets)
0033  * @param on_off_ are the connection effects
0034  *
0035  * In case of e.g. a grid surface connection:
0036  * - the @param sources_ [in, out]are the grid tiles
0037  * - the @param targets_ [in, out] are the surfaces
0038  * - the @param s_t_connections are the indices which type of association
0039  * - the @param font_ is used for associate info action
0040  *
0041  **/
0042 std::vector<svg::object> connect_action(
0043     std::vector<svg::object> &sources_, std::vector<svg::object> &targets_,
0044     const std::vector<std::vector<size_t>> &s_t_connections_, bool ls_ = true,
0045     const std::array<std::string, 2u> &on_off_ = {"mouseover", "mouseout"},
0046     const std::vector<connectors::type> &ct_ = {e_highlight, e_associate_info},
0047     const style::font &font_ = style::font());
0048 
0049 struct name_extractor {
0050     /// Strips the name out of an object
0051     template <typename source_type>
0052     auto name(const source_type &s_) {
0053         return s_._name;
0054     }
0055 };
0056 
0057 struct id_extractor {
0058     /// Strips the id out of an object
0059     template <typename source_type>
0060     auto name(const source_type &s_) {
0061         return s_._id;
0062     }
0063 };
0064 
0065 /** Helper method to connect the appearance of an object to some other
0066  * objects
0067  *
0068  * @tparam source_objects_type the type of the source objects
0069  * @tparam source_name_getter_type the way the name is provided
0070  *
0071  * @param sources_ are the source objects
0072  * @param targests_ [in, out] are the target objects
0073  * @param s_t_connections_ an association which source belongs to which target
0074  *
0075  **/
0076 template <typename source_objects_type,
0077           typename source_name_getter_type = name_extractor>
0078 void connect_action(const source_objects_type &sources_,
0079                     std::vector<svg::object> &targets_,
0080                     const std::vector<std::vector<size_t>> &s_t_connections_) {
0081 
0082     // Ignore if the s_t_connections and sources don't match up
0083     if (sources_.size() != s_t_connections_.size()) {
0084         return;
0085     }
0086 
0087     // Loop over the sources and and register the connections
0088     for (auto [is, s] : utils::enumerate(sources_)) {
0089         // Isolate the name
0090         std::string sid = source_name_getter_type{}.name(s);
0091 
0092         // Get the target list and create the connection
0093         auto st_cs = s_t_connections_[is];
0094 
0095         for (auto it : st_cs) {
0096             // Ignore if not available
0097             if (it >= targets_.size()) {
0098                 continue;
0099             }
0100 
0101             svg::object &t = targets_[it];
0102             t._attribute_map["display"] = "none";
0103 
0104             // Object information to appear
0105             svg::object on;
0106             on._tag = "animate";
0107             on._attribute_map["fill"] = "freeze";
0108             on._attribute_map["attributeName"] = "display";
0109             on._attribute_map["from"] = "none";
0110             on._attribute_map["to"] = "block";
0111             on._attribute_map["begin"] = sid + __d + "mouseout";
0112 
0113             svg::object off;
0114 
0115             off._tag = "animate";
0116             off._attribute_map["fill"] = "freeze";
0117             off._attribute_map["attributeName"] = "display";
0118             off._attribute_map["to"] = "none";
0119             off._attribute_map["from"] = "block";
0120             off._attribute_map["begin"] = sid + __d + "mouseover";
0121 
0122             // Store the animation
0123             t._sub_objects.push_back(off);
0124             t._sub_objects.push_back(on);
0125         }
0126     }
0127 }
0128 
0129 }  // namespace connectors
0130 }  // namespace actsvg