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