Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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/forit>
33#include <tools/tokenize>
34
36 static G4PlotterManager s_instance;
37 return s_instance;
38}
39
40G4PlotterManager::G4PlotterManager():fMessenger(0) {
41 fMessenger = new Messenger(*this);
42}
43
44G4PlotterManager::~G4PlotterManager() {
45 delete fMessenger;
46}
47
49 tools_vforit(NamedPlotter,fPlotters,it) {
50 if((*it).first==a_name) {
51 return (*it).second;
52 }
53 }
54 fPlotters.push_back(NamedPlotter(a_name,G4Plotter()));
55 return fPlotters.back().second;
56}
57
59 tools_vforcit(NamedPlotter,fPlotters,it) {
60 G4cout << (*it).first << G4endl;
61 }
62}
63
64//////////////////////////////////////////////////////////////////
65/// styles: //////////////////////////////////////////////////////
66//////////////////////////////////////////////////////////////////
67
68void G4PlotterManager::ListStyles() const {
69 tools_vforcit(NamedStyle,fStyles,it) {
70 G4cout << (*it).first << G4endl;
71 }
72}
73
74G4PlotterManager::Style* G4PlotterManager::FindStyle(const G4String& a_name) {
75 tools_vforit(NamedStyle,fStyles,it){
76 if((*it).first==a_name) return &((*it).second);
77 }
78 return 0;
79}
80
81void G4PlotterManager::SelectStyle(const G4String& a_name) {
82 if(!FindStyle(a_name)) {
83 fStyles.push_back(NamedStyle(a_name,Style()));
84 }
85 fCurrentStyle = a_name;
86}
87
88void G4PlotterManager::RemoveStyle(const G4String& a_name) {
89 tools_vforit(NamedStyle,fStyles,it) {
90 if((*it).first==a_name) {
91 fStyles.erase(it);
92 if(fCurrentStyle==a_name) fCurrentStyle.clear();
93 return;
94 }
95 }
96}
97
98void G4PlotterManager::PrintStyle(const G4String& a_name) const {
99 tools_vforcit(NamedStyle,fStyles,it) {
100 if((*it).first==a_name) {
101 G4cout << (*it).first << ":" << G4endl;
102 tools_vforcit(StyleItem,(*it).second,its) {
103 G4cout << " " << (*its).first << " " << (*its).second << G4endl;
104 }
105 }
106 }
107}
108
109void G4PlotterManager::AddStyleParameter(const G4String& a_parameter,const G4String& a_value) {
110 Style* _style = FindStyle(fCurrentStyle);
111 if(!_style) {
112 G4cout << "G4PlotterManager::AddStyleParameter: style " << fCurrentStyle << " not found." << G4endl;
113 return;
114 }
115 tools_vforit(StyleItem,(*_style),it) {
116 if((*it).first==a_parameter) {
117 (*it).second = a_value;
118 return;
119 }
120 }
121 _style->push_back(StyleItem(a_parameter,a_value));
122}
123
124void G4PlotterManager::Messenger::SetNewValue(G4UIcommand* a_cmd,G4String a_value) {
125 std::vector<std::string> args;
126 tools::double_quotes_tokenize(a_value,args);
127 if(args.size()!=a_cmd->GetParameterEntries()) return;
128 if(a_cmd==select_style) {
129 fPlotterManager.SelectStyle(args[0]);
130 } else if(a_cmd==add_style_parameter) {
131 fPlotterManager.AddStyleParameter(args[0],args[1]);
132 } else if(a_cmd==remove_style) {
133 fPlotterManager.RemoveStyle(args[0]);
134 } else if(a_cmd==list_styles) {
135 G4cout << "default (embedded)." << G4endl;
136 G4cout << "ROOT_default (embedded)." << G4endl;
137 G4cout << "hippodraw (embedded)." << G4endl;
138 fPlotterManager.ListStyles();
139 } else if(a_cmd==print_style) {
140 fPlotterManager.PrintStyle(args[0]);
141 }
142}
#define G4endl
Definition: G4ios.hh:57
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
Definition: G4UIcommand.hh:139