Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4PlotterManager.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// Guy Barrand 12 October 2021
27//
28
29#include "G4PlotterManager.hh"
30#include "G4ios.hh"
31
32#include <tools/tokenize>
33
34G4PlotterManager& G4PlotterManager::GetInstance () {
35 static G4PlotterManager s_instance;
36 return s_instance;
37}
38
39G4PlotterManager::G4PlotterManager():fMessenger(0) {
40 fMessenger = new Messenger(*this);
41}
42
43G4PlotterManager::~G4PlotterManager() {
44 delete fMessenger;
45}
46
48 for(auto& plotter : fPlotters) {
49 if(plotter.first == a_name) {
50 return plotter.second;
51 }
52 }
53 fPlotters.push_back(NamedPlotter(a_name,G4Plotter()));
54 return fPlotters.back().second;
55}
56
58 for(const auto& plotter : fPlotters) {
59 G4cout << plotter.first << G4endl;
60 }
61}
62
63//////////////////////////////////////////////////////////////////
64/// styles: //////////////////////////////////////////////////////
65//////////////////////////////////////////////////////////////////
66
67void G4PlotterManager::ListStyles() const {
68 for(const auto& style : fStyles) {
69 G4cout << style.first << G4endl;
70 }
71}
72
73G4PlotterManager::Style* G4PlotterManager::FindStyle(const G4String& a_name) {
74 for(auto& style : fStyles) {
75 if(style.first == a_name) return &style.second;
76 }
77 return nullptr;
78}
79
80void G4PlotterManager::SelectStyle(const G4String& a_name) {
81 if(!FindStyle(a_name)) {
82 fStyles.push_back(NamedStyle(a_name,Style()));
83 }
84 fCurrentStyle = a_name;
85}
86
87void G4PlotterManager::RemoveStyle(const G4String& a_name) {
88 for (auto it = fStyles.begin(); it != fStyles.end(); ++it) {
89 if (it->first == a_name) {
90 fStyles.erase(it);
91 if (fCurrentStyle == a_name) fCurrentStyle.clear();
92 return;
93 }
94 }
95}
96
97void G4PlotterManager::PrintStyle(const G4String& a_name) const {
98 for(const auto& style : fStyles) {
99 if(style.first == a_name) {
100 G4cout << style.first << ":" << G4endl;
101 for(const auto& item : style.second) {
102 G4cout << " " << item.first << " " << item.second << G4endl;
103 }
104 }
105 }
106}
107
108void G4PlotterManager::AddStyleParameter(const G4String& a_parameter,const G4String& a_value) {
109 Style* _style = FindStyle(fCurrentStyle);
110 if(!_style) {
111 G4cout << "G4PlotterManager::AddStyleParameter: style " << fCurrentStyle << " not found." << G4endl;
112 return;
113 }
114 for(auto& item : *_style) {
115 if(item.first == a_parameter) {
116 item.second = a_value;
117 return;
118 }
119 }
120 _style->push_back(StyleItem(a_parameter,a_value));
121}
122
123void G4PlotterManager::Messenger::SetNewValue(G4UIcommand* a_cmd,G4String a_value) {
124 std::vector<std::string> args;
125 tools::double_quotes_tokenize(a_value,args);
126 if(args.size()!=a_cmd->GetParameterEntries()) return;
127 if(a_cmd==select_style) {
128 fPlotterManager.SelectStyle(args[0]);
129 } else if(a_cmd==add_style_parameter) {
130 fPlotterManager.AddStyleParameter(args[0],args[1]);
131 } else if(a_cmd==remove_style) {
132 fPlotterManager.RemoveStyle(args[0]);
133 } else if(a_cmd==list_styles) {
134 G4cout << "default (embedded)." << G4endl;
135 G4cout << "ROOT_default (embedded)." << G4endl;
136 G4cout << "hippodraw (embedded)." << G4endl;
137 fPlotterManager.ListStyles();
138 } else if(a_cmd==print_style) {
139 fPlotterManager.PrintStyle(args[0]);
140 }
141}
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
G4Plotter & GetPlotter(const G4String &a_name)
std::pair< G4String, Style > NamedStyle
std::vector< StyleItem > Style
std::pair< G4String, G4String > StyleItem
static G4PlotterManager & GetInstance()
std::size_t GetParameterEntries() const