Geant4 Cross Reference |
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 29 #include "G4VisCommandsPlotter.hh" 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 ///////////////////////////////////////////////////////////////////////////// 42 G4VisCommandPlotterCreate::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 51 G4VisCommandPlotterCreate::~G4VisCommandPlotterCreate () {delete fpCommand;} 52 53 void G4VisCommandPlotterCreate::SetNewValue (G4UIcommand*, G4String newValue) 54 { 55 G4Plotter& _plotter = G4PlotterManager::GetInstance().GetPlotter(newValue); 56 _plotter.Reset(); 57 G4Scene* pScene = fpVisManager->GetCurrentScene(); 58 if(pScene) CheckSceneAndNotifyHandlers (pScene); 59 } 60 61 ///////////////////////////////////////////////////////////////////////////// 62 ////////////// /vis/plotter/setLayout /////////////////////////////////////// 63 ///////////////////////////////////////////////////////////////////////////// 64 G4VisCommandPlotterSetLayout::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 81 G4VisCommandPlotterSetLayout::~G4VisCommandPlotterSetLayout () {delete fpCommand;} 82 83 void G4VisCommandPlotterSetLayout::SetNewValue (G4UIcommand*, G4String newValue) 84 { 85 G4String plotter; 86 G4int cols,rows; 87 std::istringstream is(newValue); 88 is >> plotter >> cols >> rows; 89 90 G4Plotter& _plotter = G4PlotterManager::GetInstance().GetPlotter(plotter); 91 _plotter.SetLayout(cols,rows); 92 93 G4Scene* pScene = fpVisManager->GetCurrentScene(); 94 if(pScene) CheckSceneAndNotifyHandlers (pScene); 95 } 96 97 ///////////////////////////////////////////////////////////////////////////// 98 ////////////// /vis/plotter/addStyle //////////////////////////////////////// 99 ///////////////////////////////////////////////////////////////////////////// 100 G4VisCommandPlotterAddStyle::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 116 G4VisCommandPlotterAddStyle::~G4VisCommandPlotterAddStyle () {delete fpCommand;} 117 118 void G4VisCommandPlotterAddStyle::SetNewValue (G4UIcommand*, G4String newValue) 119 { 120 G4String plotter; 121 G4String style; 122 std::istringstream is(newValue); 123 is >> plotter >> style; 124 125 G4Plotter& _plotter = G4PlotterManager::GetInstance().GetPlotter(plotter); 126 _plotter.AddStyle(style); 127 128 G4Scene* pScene = fpVisManager->GetCurrentScene(); 129 if(pScene) CheckSceneAndNotifyHandlers (pScene); 130 } 131 132 ///////////////////////////////////////////////////////////////////////////// 133 ////////////// /vis/plotter/addRegionStyle ////////////////////////////////// 134 ///////////////////////////////////////////////////////////////////////////// 135 G4VisCommandPlotterAddRegionStyle::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 154 G4VisCommandPlotterAddRegionStyle::~G4VisCommandPlotterAddRegionStyle () {delete fpCommand;} 155 156 void 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 172 G4Plotter& _plotter = G4PlotterManager::GetInstance().GetPlotter(plotter); 173 _plotter.AddRegionStyle(region,style); 174 175 G4Scene* pScene = fpVisManager->GetCurrentScene(); 176 if(pScene) CheckSceneAndNotifyHandlers (pScene); 177 } 178 179 ///////////////////////////////////////////////////////////////////////////// 180 ////////////// /vis/plotter/addRegionParameter ////////////////////////////// 181 ///////////////////////////////////////////////////////////////////////////// 182 G4VisCommandPlotterAddRegionParameter::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 200 G4VisCommandPlotterAddRegionParameter::~G4VisCommandPlotterAddRegionParameter () {delete fpCommand;} 201 202 void 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 226 G4Plotter& _plotter = G4PlotterManager::GetInstance().GetPlotter(plotter); 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 ///////////////////////////////////////////////////////////////////////////// 236 G4VisCommandPlotterClear::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 245 G4VisCommandPlotterClear::~G4VisCommandPlotterClear () {delete fpCommand;} 246 247 void 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 ///////////////////////////////////////////////////////////////////////////// 259 G4VisCommandPlotterClearRegion::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 272 G4VisCommandPlotterClearRegion::~G4VisCommandPlotterClearRegion () {delete fpCommand;} 273 274 void 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 289 G4Plotter& _plotter = G4PlotterManager::GetInstance().GetPlotter(plotter); 290 _plotter.ClearRegion(region); 291 292 G4Scene* pScene = fpVisManager->GetCurrentScene(); 293 if(pScene) CheckSceneAndNotifyHandlers (pScene); 294 } 295 296 ///////////////////////////////////////////////////////////////////////////// 297 ////////////// /vis/plotter/list //////////////////////////////////////////// 298 ///////////////////////////////////////////////////////////////////////////// 299 G4VisCommandPlotterList::G4VisCommandPlotterList () { 300 fpCommand = new G4UIcommand("/vis/plotter/list", this); 301 fpCommand->SetGuidance("List plotters in the scene."); 302 } 303 304 G4VisCommandPlotterList::~G4VisCommandPlotterList () {delete fpCommand;} 305 306 void G4VisCommandPlotterList::SetNewValue (G4UIcommand*, G4String) 307 { 308 G4PlotterManager::GetInstance().List(); 309 } 310 311 ///////////////////////////////////////////////////////////////////////////// 312 ////////////// /vis/plotter/add/h1 ////////////////////////////////////////// 313 ///////////////////////////////////////////////////////////////////////////// 314 G4VisCommandPlotterAddRegionH1::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 330 G4VisCommandPlotterAddRegionH1::~G4VisCommandPlotterAddRegionH1 () {delete fpCommand;} 331 332 void 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 349 G4Plotter& _plotter = G4PlotterManager::GetInstance().GetPlotter(plotter); 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 ///////////////////////////////////////////////////////////////////////////// 359 G4VisCommandPlotterAddRegionH2::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 375 G4VisCommandPlotterAddRegionH2::~G4VisCommandPlotterAddRegionH2 () {delete fpCommand;} 376 377 void 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 394 G4Plotter& _plotter = G4PlotterManager::GetInstance().GetPlotter(plotter); 395 _plotter.AddRegionH2(region,hid); 396 397 G4Scene* pScene = fpVisManager->GetCurrentScene(); 398 if(pScene) CheckSceneAndNotifyHandlers (pScene); 399 } 400 401