File indexing completed on 2025-12-16 09:23:22
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Utilities/GraphViz.hpp"
0010
0011 #include "Acts/Utilities/JoinStrings.hpp"
0012
0013 #include <algorithm>
0014 #include <iterator>
0015 #include <ranges>
0016 #include <string>
0017
0018 #include <boost/algorithm/string/join.hpp>
0019
0020 namespace Acts::GraphViz {
0021
0022 std::ostream& operator<<(std::ostream& os, const Shape& shape) {
0023 switch (shape) {
0024 using enum Shape;
0025
0026 case Box:
0027 os << "box";
0028 break;
0029 case Polygon:
0030 os << "polygon";
0031 break;
0032 case Ellipse:
0033 os << "ellipse";
0034 break;
0035 case Oval:
0036 os << "oval";
0037 break;
0038 case Circle:
0039 os << "circle";
0040 break;
0041 case Point:
0042 os << "point";
0043 break;
0044 case Egg:
0045 os << "egg";
0046 break;
0047 case Triangle:
0048 os << "triangle";
0049 break;
0050 case Plaintext:
0051 os << "plaintext";
0052 break;
0053 case Plain:
0054 os << "plain";
0055 break;
0056 case Diamond:
0057 os << "diamond";
0058 break;
0059 case Trapezium:
0060 os << "trapezium";
0061 break;
0062 case Parallelogram:
0063 os << "parallelogram";
0064 break;
0065 case House:
0066 os << "house";
0067 break;
0068 case Pentagon:
0069 os << "pentagon";
0070 break;
0071 case Hexagon:
0072 os << "hexagon";
0073 break;
0074 case Septagon:
0075 os << "septagon";
0076 break;
0077 case Octagon:
0078 os << "octagon";
0079 break;
0080 case DoubleCircle:
0081 os << "doublecircle";
0082 break;
0083 case DoubleOctagon:
0084 os << "doubleoctagon";
0085 break;
0086 case TripleOctagon:
0087 os << "tripleoctagon";
0088 break;
0089 case InvTriangle:
0090 os << "invtriangle";
0091 break;
0092 case InvTrapezium:
0093 os << "invtrapezium";
0094 break;
0095 case InvHouse:
0096 os << "invhouse";
0097 break;
0098 case Mdiamond:
0099 os << "Mdiamond";
0100 break;
0101 case Msquare:
0102 os << "Msquare";
0103 break;
0104 case Mcircle:
0105 os << "Mcircle";
0106 break;
0107 case Rect:
0108 os << "rect";
0109 break;
0110 case Rectangle:
0111 os << "rectangle";
0112 break;
0113 case Square:
0114 os << "square";
0115 break;
0116 case Star:
0117 os << "star";
0118 break;
0119 case None:
0120 os << "none";
0121 break;
0122 case Underline:
0123 os << "underline";
0124 break;
0125 case Cylinder:
0126 os << "cylinder";
0127 break;
0128 case Note:
0129 os << "note";
0130 break;
0131 case Tab:
0132 os << "tab";
0133 break;
0134 case Folder:
0135 os << "folder";
0136 break;
0137 case Box3d:
0138 os << "box3d";
0139 break;
0140 case Component:
0141 os << "component";
0142 break;
0143 case Promoter:
0144 os << "promoter";
0145 break;
0146 case Cds:
0147 os << "cds";
0148 break;
0149 case Terminator:
0150 os << "terminator";
0151 break;
0152 case Utr:
0153 os << "utr";
0154 break;
0155 case PrimerSite:
0156 os << "primersite";
0157 break;
0158 case RestrictionSite:
0159 os << "restrictionsite";
0160 break;
0161 case FivePOverhang:
0162 os << "fivepoverhang";
0163 break;
0164 case ThreePOverhang:
0165 os << "threepoverhang";
0166 break;
0167 case NOverhang:
0168 os << "noverhang";
0169 break;
0170 case Assembly:
0171 os << "assembly";
0172 break;
0173 case Signature:
0174 os << "signature";
0175 break;
0176 case Insulator:
0177 os << "insulator";
0178 break;
0179 case Ribosite:
0180 os << "ribosite";
0181 break;
0182 case RNAStab:
0183 os << "rnastab";
0184 break;
0185 case ProteaseSite:
0186 os << "proteasesite";
0187 break;
0188 case ProteinStab:
0189 os << "proteinstab";
0190 break;
0191 case RPromoter:
0192 os << "rpromoter";
0193 break;
0194 case RArrow:
0195 os << "rarrow";
0196 break;
0197 case LArrow:
0198 os << "larrow";
0199 break;
0200 case LPromoter:
0201 os << "lpromoter";
0202 break;
0203 default:
0204 std::terminate();
0205 }
0206
0207 return os;
0208 }
0209
0210 std::ostream& operator<<(std::ostream& os, const Style& style) {
0211 switch (style) {
0212 using enum Style;
0213 case Filled:
0214 os << "filled";
0215 break;
0216 case Invisible:
0217 os << "invisible";
0218 break;
0219 case Diagonals:
0220 os << "diagonals";
0221 break;
0222 case Rounded:
0223 os << "rounded";
0224 break;
0225 case Dashed:
0226 os << "dashed";
0227 break;
0228 case Dotted:
0229 os << "dotted";
0230 break;
0231 case Solid:
0232 os << "solid";
0233 break;
0234 case Bold:
0235 os << "bold";
0236 break;
0237 default:
0238 os << "unknown";
0239 break;
0240 }
0241 return os;
0242 }
0243
0244 std::ostream& operator<<(std::ostream& os, const Node& node) {
0245 if (node.id.empty()) {
0246 throw std::runtime_error("Node id must not be empty");
0247 }
0248
0249 std::string id = node.id;
0250 std::ranges::replace(id, ' ', '_');
0251
0252 std::vector<std::string> attributes;
0253
0254 if (!node.label.empty()) {
0255 attributes.push_back(std::format("label=<{}>", node.label));
0256 }
0257
0258 attributes.push_back(std::format("shape={}", node.shape));
0259
0260 attributes.push_back(std::format("style={}", joinStrings(node.style, ",")));
0261
0262 std::format_to(std::ostream_iterator<char>(os), "{} [{}];\n", id,
0263 joinStrings(attributes, ", "));
0264
0265 return os;
0266 }
0267
0268 std::ostream& operator<<(std::ostream& os, const Edge& node) {
0269 std::format_to(std::ostream_iterator<char>(os),
0270 "\"{}\" -> \"{}\" [style={}];\n", node.from.id, node.to.id,
0271 node.style);
0272 return os;
0273 }
0274
0275 }