Geant4-11
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
35#include <tools/xml/xml_style> //it uses expat.
36
38 static G4PlotterManager s_instance;
39 return s_instance;
40}
41
43 fMessenger = new Messenger(*this);
44}
45
47 delete fMessenger;
48}
49
51 tools_vforit(NamedPlotter,fPlotters,it) {
52 if((*it).first==a_name) {
53 return (*it).second;
54 }
55 }
56 fPlotters.push_back(NamedPlotter(a_name,G4Plotter()));
57 return fPlotters.back().second;
58}
59
61 tools_vforcit(NamedPlotter,fPlotters,it) {
62 G4cout << (*it).first << G4endl;
63 }
64}
65
69
71 tools_vforcit(NamedStyle,fStyles,it) {
72 G4cout << (*it).first << G4endl;
73 }
74}
75
77 tools_vforit(NamedStyle,fStyles,it){
78 if((*it).first==a_name) return &((*it).second);
79 }
80 return 0;
81}
82
84 if(!FindStyle(a_name)) {
85 fStyles.push_back(NamedStyle(a_name,Style()));
86 }
87 fCurrentStyle = a_name;
88}
89
91 tools_vforit(NamedStyle,fStyles,it) {
92 if((*it).first==a_name) {
93 fStyles.erase(it);
94 if(fCurrentStyle==a_name) fCurrentStyle.clear();
95 return;
96 }
97 }
98}
99
100void G4PlotterManager::PrintStyle(const G4String& a_name) const {
101 tools_vforcit(NamedStyle,fStyles,it) {
102 if((*it).first==a_name) {
103 G4cout << (*it).first << ":" << G4endl;
104 tools_vforcit(StyleItem,(*it).second,its) {
105 G4cout << " " << (*its).first << " " << (*its).second << G4endl;
106 }
107 }
108 }
109}
110
111void G4PlotterManager::AddStyleParameter(const G4String& a_parameter,const G4String& a_value) {
112 Style* _style = FindStyle(fCurrentStyle);
113 if(!_style) {
114 G4cout << "G4PlotterManager::AddStyleParameter: style " << fCurrentStyle << " not found." << G4endl;
115 return;
116 }
117 tools_vforit(StyleItem,(*_style),it) {
118 if((*it).first==a_parameter) {
119 (*it).second = a_value;
120 return;
121 }
122 }
123 _style->push_back(StyleItem(a_parameter,a_value));
124}
125
127 std::vector<std::string> args;
128 tools::double_quotes_tokenize(a_value,args);
129 if(args.size()!=a_cmd->GetParameterEntries()) return;
130 if(a_cmd==select_style) {
132 } else if(a_cmd==add_style_parameter) {
134 } else if(a_cmd==remove_style) {
136 } else if(a_cmd==list_styles) {
137 G4cout << "default (embedded)." << G4endl;
138 G4cout << "ROOT_default (embedded)." << G4endl;
139 G4cout << "hippodraw (embedded)." << G4endl;
141 } else if(a_cmd==print_style) {
143 }
144}
static char ** args
Definition: G4Xt.cc:51
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
virtual void SetNewValue(G4UIcommand *, G4String)
G4PlotterManager & fPlotterManager
Messenger * fMessenger
void ListStyles() const
styles: //////////////////////////////////////////////////////
std::vector< NamedPlotter > fPlotters
G4Plotter & GetPlotter(const G4String &a_name)
virtual ~G4PlotterManager()
void SelectStyle(const G4String &style)
void RemoveStyle(const G4String &name)
std::pair< G4String, Style > NamedStyle
std::pair< G4String, G4Plotter > NamedPlotter
void AddStyleParameter(const G4String &param, const G4String &value)
std::vector< StyleItem > Style
void PrintStyle(const G4String &) const
Style * FindStyle(const G4String &name)
std::pair< G4String, G4String > StyleItem
static G4PlotterManager & GetInstance()
std::size_t GetParameterEntries() const
Definition: G4UIcommand.hh:138