Geant4-11
G4VisCommandsPlotter.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//
27// /vis/plotter commands - Guy Barrand October 2021.
28
30
31#include "G4PlotterManager.hh"
32
33#include <tools/tokenize>
34
35#include <sstream>
36
40G4VisCommandPlotterCreate::G4VisCommandPlotterCreate () {
41 fpCommand = new G4UIcommand("/vis/plotter/create", this);
42 fpCommand->SetGuidance("Create a named G4Plotter.");
43
44 G4UIparameter* parameter;
45 parameter = new G4UIparameter("name",'s',false);
46 fpCommand->SetParameter (parameter);
47}
48
49G4VisCommandPlotterCreate::~G4VisCommandPlotterCreate () {delete fpCommand;}
50
51void G4VisCommandPlotterCreate::SetNewValue (G4UIcommand*, G4String newValue)
52{
54 _plotter.Reset();
55 G4Scene* pScene = fpVisManager->GetCurrentScene();
56 if(pScene) CheckSceneAndNotifyHandlers (pScene);
57}
58
62G4VisCommandPlotterSetLayout::G4VisCommandPlotterSetLayout () {
63 fpCommand = new G4UIcommand("/vis/plotter/setLayout", this);
64 fpCommand->SetGuidance("Set plotter grid layout.");
65
66 G4UIparameter* parameter;
67 parameter = new G4UIparameter("plotter",'s',false);
68 fpCommand->SetParameter (parameter);
69
70 parameter = new G4UIparameter("columns",'i',true);
71 parameter->SetDefaultValue(1);
72 fpCommand->SetParameter (parameter);
73
74 parameter = new G4UIparameter("rows",'i',true);
75 parameter->SetDefaultValue(1);
76 fpCommand->SetParameter (parameter);
77}
78
79G4VisCommandPlotterSetLayout::~G4VisCommandPlotterSetLayout () {delete fpCommand;}
80
81void G4VisCommandPlotterSetLayout::SetNewValue (G4UIcommand*, G4String newValue)
82{
83 G4String plotter;
84 G4int cols,rows;
85 std::istringstream is(newValue);
86 is >> plotter >> cols >> rows;
87
89 _plotter.SetLayout(cols,rows);
90
91 G4Scene* pScene = fpVisManager->GetCurrentScene();
92 if(pScene) CheckSceneAndNotifyHandlers (pScene);
93}
94
98G4VisCommandPlotterAddStyle::G4VisCommandPlotterAddStyle () {
99 fpCommand = new G4UIcommand("/vis/plotter/addStyle", this);
100 fpCommand->SetGuidance("Add a style for a plotter.");
101 fpCommand->SetGuidance("It is applied on all regions/plots of the plotter.");
102 fpCommand->SetGuidance("default, ROOT_default, hippodraw are known embedded styles.");
103 fpCommand->SetGuidance("reset is a keyword used to reset regions style.");
104
105 G4UIparameter* parameter;
106 parameter = new G4UIparameter("plotter",'s',false);
107 fpCommand->SetParameter (parameter);
108
109 parameter = new G4UIparameter("style",'s',true);
110 parameter->SetDefaultValue("default");
111 fpCommand->SetParameter (parameter);
112}
113
114G4VisCommandPlotterAddStyle::~G4VisCommandPlotterAddStyle () {delete fpCommand;}
115
116void G4VisCommandPlotterAddStyle::SetNewValue (G4UIcommand*, G4String newValue)
117{
118 G4String plotter;
119 G4String style;
120 std::istringstream is(newValue);
121 is >> plotter >> style;
122
124 _plotter.AddStyle(style);
125
126 G4Scene* pScene = fpVisManager->GetCurrentScene();
127 if(pScene) CheckSceneAndNotifyHandlers (pScene);
128}
129
133G4VisCommandPlotterAddRegionStyle::G4VisCommandPlotterAddRegionStyle () {
134 fpCommand = new G4UIcommand("/vis/plotter/addRegionStyle", this);
135 fpCommand->SetGuidance("Add a style to be applied on a region.");
136 fpCommand->SetGuidance("default, ROOT_default, hippodraw are known embedded styles.");
137 fpCommand->SetGuidance("reset is a keyword used to reset a region style.");
138
139 G4UIparameter* parameter;
140 parameter = new G4UIparameter("plotter",'s',false);
141 fpCommand->SetParameter (parameter);
142
143 parameter = new G4UIparameter("region",'i',false);
144//parameter->SetDefaultValue(0);
145 fpCommand->SetParameter (parameter);
146
147 parameter = new G4UIparameter("style",'s',true);
148 parameter->SetDefaultValue("default");
149 fpCommand->SetParameter (parameter);
150}
151
152G4VisCommandPlotterAddRegionStyle::~G4VisCommandPlotterAddRegionStyle () {delete fpCommand;}
153
154void G4VisCommandPlotterAddRegionStyle::SetNewValue (G4UIcommand*, G4String newValue)
155{
156 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
157
158 G4String plotter;
159 int region;
160 G4String style;
161 std::istringstream is(newValue);
162 is >> plotter >> region >> style;
163 if(region<0) {
164 if (verbosity >= G4VisManager::errors) {
165 G4cerr << "ERROR: bad region index " << region << "." << G4endl;
166 }
167 return;
168 }
169
171 _plotter.AddRegionStyle(region,style);
172
173 G4Scene* pScene = fpVisManager->GetCurrentScene();
174 if(pScene) CheckSceneAndNotifyHandlers (pScene);
175}
176
180G4VisCommandPlotterAddRegionParameter::G4VisCommandPlotterAddRegionParameter () {
181 fpCommand = new G4UIcommand("/vis/plotter/addRegionParameter", this);
182 fpCommand->SetGuidance("Add a parameter to be set on a region.");
183
184 G4UIparameter* parameter;
185 parameter = new G4UIparameter("plotter",'s',false);
186 fpCommand->SetParameter (parameter);
187
188 parameter = new G4UIparameter("region",'i',false);
189 fpCommand->SetParameter (parameter);
190
191 parameter = new G4UIparameter("parameter",'s',false);
192 fpCommand->SetParameter (parameter);
193
194 parameter = new G4UIparameter("value",'s',false);
195 fpCommand->SetParameter (parameter);
196}
197
198G4VisCommandPlotterAddRegionParameter::~G4VisCommandPlotterAddRegionParameter () {delete fpCommand;}
199
200void G4VisCommandPlotterAddRegionParameter::SetNewValue (G4UIcommand* command, G4String newValue)
201{
202 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
203
204 std::vector<std::string> args;
205 tools::double_quotes_tokenize(newValue, args);
206 if ( args.size() != command->GetParameterEntries() ) { // check consistency.
207 if (verbosity >= G4VisManager::errors) {
208 G4cerr << "ERROR: tokenize value problem." << G4endl;
209 }
210 return;
211 }
212
213 std::string plotter = args[0];
214 int region = G4UIcommand::ConvertToInt(args[1].c_str());
215 std::string parameter = args[2];
216 std::string value = args[3];
217 if(region<0) {
218 if (verbosity >= G4VisManager::errors) {
219 G4cerr << "ERROR: bad region index " << region << "." << G4endl;
220 }
221 return;
222 }
223
225 _plotter.AddRegionParameter(region,parameter,value);
226
227 G4Scene* pScene = fpVisManager->GetCurrentScene();
228 if(pScene) CheckSceneAndNotifyHandlers (pScene);
229}
230
234G4VisCommandPlotterClear::G4VisCommandPlotterClear () {
235 fpCommand = new G4UIcommand("/vis/plotter/clear", this);
236 fpCommand->SetGuidance("Remove plottables from all regions.");
237
238 G4UIparameter* parameter;
239 parameter = new G4UIparameter("plotter",'s',false);
240 fpCommand->SetParameter (parameter);
241}
242
243G4VisCommandPlotterClear::~G4VisCommandPlotterClear () {delete fpCommand;}
244
245void G4VisCommandPlotterClear::SetNewValue (G4UIcommand*, G4String newValue)
246{
247 G4Plotter& _plotter = G4PlotterManager::GetInstance().GetPlotter(newValue);
248 _plotter.Clear();
249
250 G4Scene* pScene = fpVisManager->GetCurrentScene();
251 if(pScene) CheckSceneAndNotifyHandlers (pScene);
252}
253
257G4VisCommandPlotterClearRegion::G4VisCommandPlotterClearRegion () {
258 fpCommand = new G4UIcommand("/vis/plotter/clearRegion", this);
259 fpCommand->SetGuidance("Remove plottables a region.");
260
261 G4UIparameter* parameter;
262 parameter = new G4UIparameter("plotter",'s',false);
263 fpCommand->SetParameter (parameter);
264
265 parameter = new G4UIparameter("region",'i',false);
266//parameter->SetDefaultValue(0);
267 fpCommand->SetParameter (parameter);
268}
269
270G4VisCommandPlotterClearRegion::~G4VisCommandPlotterClearRegion () {delete fpCommand;}
271
272void G4VisCommandPlotterClearRegion::SetNewValue (G4UIcommand*, G4String newValue)
273{
274 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
275
276 G4String plotter;
277 int region;
278 std::istringstream is(newValue);
279 is >> plotter >> region;
280 if(region<0) {
281 if (verbosity >= G4VisManager::errors) {
282 G4cerr << "ERROR: bad region index " << region << "." << G4endl;
283 }
284 return;
285 }
286
288 _plotter.ClearRegion(region);
289
290 G4Scene* pScene = fpVisManager->GetCurrentScene();
291 if(pScene) CheckSceneAndNotifyHandlers (pScene);
292}
293
297G4VisCommandPlotterList::G4VisCommandPlotterList () {
298 fpCommand = new G4UIcommand("/vis/plotter/list", this);
299 fpCommand->SetGuidance("List plotters in the scene.");
300}
301
302G4VisCommandPlotterList::~G4VisCommandPlotterList () {delete fpCommand;}
303
304void G4VisCommandPlotterList::SetNewValue (G4UIcommand*, G4String)
305{
307}
308
312G4VisCommandPlotterAddRegionH1::G4VisCommandPlotterAddRegionH1 () {
313 fpCommand = new G4UIcommand("/vis/plotter/add/h1", this);
314 fpCommand->SetGuidance("Attach a 1D histogram to a plotter region.");
315
316 G4UIparameter* parameter;
317 parameter = new G4UIparameter("histo",'i',false);
318 fpCommand->SetParameter (parameter);
319
320 parameter = new G4UIparameter("plotter",'s',false);
321 fpCommand->SetParameter (parameter);
322
323 parameter = new G4UIparameter("region",'i',true);
324 parameter->SetDefaultValue(0);
325 fpCommand->SetParameter (parameter);
326}
327
328G4VisCommandPlotterAddRegionH1::~G4VisCommandPlotterAddRegionH1 () {delete fpCommand;}
329
330void G4VisCommandPlotterAddRegionH1::SetNewValue (G4UIcommand*, G4String newValue)
331{
332 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
333
334 int hid;
335 G4String plotter;
336 int region;
337 std::istringstream is(newValue);
338 is >> hid >> plotter >> region;
339
340 if(region<0) {
341 if (verbosity >= G4VisManager::errors) {
342 G4cerr << "ERROR: bad region index " << region << "." << G4endl;
343 }
344 return;
345 }
346
348 _plotter.AddRegionH1(region,hid);
349
350 G4Scene* pScene = fpVisManager->GetCurrentScene();
351 if(pScene) CheckSceneAndNotifyHandlers (pScene);
352}
353
357G4VisCommandPlotterAddRegionH2::G4VisCommandPlotterAddRegionH2 () {
358 fpCommand = new G4UIcommand("/vis/plotter/add/h2", this);
359 fpCommand->SetGuidance("Attach a 2D histogram to a plotter region.");
360
361 G4UIparameter* parameter;
362 parameter = new G4UIparameter("histo",'i',false);
363 fpCommand->SetParameter (parameter);
364
365 parameter = new G4UIparameter("plotter",'s',false);
366 fpCommand->SetParameter (parameter);
367
368 parameter = new G4UIparameter("region",'i',true);
369 parameter->SetDefaultValue(0);
370 fpCommand->SetParameter (parameter);
371}
372
373G4VisCommandPlotterAddRegionH2::~G4VisCommandPlotterAddRegionH2 () {delete fpCommand;}
374
375void G4VisCommandPlotterAddRegionH2::SetNewValue (G4UIcommand*, G4String newValue)
376{
377 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
378
379 int hid;
380 G4String plotter;
381 int region;
382 std::istringstream is(newValue);
383 is >> hid >> plotter >> region;
384
385 if(region<0) {
386 if (verbosity >= G4VisManager::errors) {
387 G4cerr << "ERROR: bad region index " << region << "." << G4endl;
388 }
389 return;
390 }
391
393 _plotter.AddRegionH2(region,hid);
394
395 G4Scene* pScene = fpVisManager->GetCurrentScene();
396 if(pScene) CheckSceneAndNotifyHandlers (pScene);
397}
398
int G4int
Definition: G4Types.hh:85
static char ** args
Definition: G4Xt.cc:51
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4Plotter & GetPlotter(const G4String &a_name)
static G4PlotterManager & GetInstance()
void AddRegionH2(unsigned int region, int id)
Definition: G4Plotter.cc:80
void AddRegionStyle(unsigned int region, const G4String &style)
Definition: G4Plotter.cc:64
void AddRegionH1(unsigned int region, int id)
Definition: G4Plotter.cc:77
void Clear()
Definition: G4Plotter.cc:95
void Reset()
Definition: G4Plotter.cc:84
void AddStyle(const G4String &style)
Definition: G4Plotter.cc:61
void ClearRegion(unsigned int region)
Definition: G4Plotter.cc:101
void SetLayout(unsigned int colums, unsigned int rows)
Definition: G4Plotter.cc:57
void AddRegionParameter(unsigned int region, const G4String &parameter, const G4String &value)
Definition: G4Plotter.cc:67
std::size_t GetParameterEntries() const
Definition: G4UIcommand.hh:138
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:557
void SetDefaultValue(const char *theDefaultValue)