ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VisCommandsGeometrySet.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4VisCommandsGeometrySet.cc
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 
28 // /vis/geometry commands - John Allison 31st January 2006
29 
31 
32 #include "G4UIcommand.hh"
33 #include "G4VisManager.hh"
34 #include "G4LogicalVolumeStore.hh"
35 #include "G4UImanager.hh"
36 
37 #include <sstream>
38 
40 (G4String requestedName,
41  const G4VVisCommandGeometrySetFunction& setFunction,
42  G4int requestedDepth)
43 {
44  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
46  G4bool found = false;
47  for (size_t iLV = 0; iLV < pLVStore->size(); iLV++ ) {
48  G4LogicalVolume* pLV = (*pLVStore)[iLV];
49  const G4String& logVolName = pLV->GetName();
50  if (logVolName == requestedName) found = true;
51  if (requestedName == "all" || logVolName == requestedName) {
52  SetLVVisAtts(pLV, setFunction, 0, requestedDepth);
53  }
54  }
55  if (requestedName != "all" && !found) {
56  if (verbosity >= G4VisManager::errors) {
57  G4cerr << "ERROR: Logical volume \"" << requestedName
58  << "\" not found in logical volume store." << G4endl;
59  }
60  return;
61  }
62  if (fpVisManager->GetCurrentViewer()) {
63  G4UImanager::GetUIpointer()->ApplyCommand("/vis/scene/notifyHandlers");
64  }
65 }
66 
69  const G4VVisCommandGeometrySetFunction& setFunction,
70  G4int depth, G4int requestedDepth)
71 {
72  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
73  const G4VisAttributes* oldVisAtts = pLV->GetVisAttributes();
74  fVisAttsMap.insert(std::make_pair(pLV,oldVisAtts)); // Store old vis atts.
75  G4VisAttributes* newVisAtts = new G4VisAttributes; // Memory leak!
76  if (oldVisAtts) {
77  *newVisAtts = *oldVisAtts;
78  }
79  setFunction(newVisAtts); // Sets whatever attribute determined by
80  // function object.
81  pLV->SetVisAttributes(newVisAtts);
82  if (verbosity >= G4VisManager::confirmations) {
83  G4cout << "\nLogical Volume \"" << pLV->GetName()
84  << "\": setting vis attributes:";
85  if (oldVisAtts) {
86  G4cout << "\nwas: " << *oldVisAtts;
87  } else {
88  G4cout << "\n(no old attributes)";
89  }
90  G4cout << "\nnow: " << *newVisAtts
91  << G4endl;
92  }
93  if (requestedDepth < 0 || depth < requestedDepth) {
94  G4int nDaughters = pLV->GetNoDaughters();
95  for (G4int i = 0; i < nDaughters; ++i) {
96  SetLVVisAtts(pLV->GetDaughter(i)->GetLogicalVolume(),
97  setFunction, ++depth, requestedDepth);
98  }
99  }
100 }
101 
103 
105 {
106  G4bool omitable;
107  fpCommand = new G4UIcommand("/vis/geometry/set/colour", this);
108  fpCommand->SetGuidance("Sets colour of logical volume(s).");
109  fpCommand->SetGuidance("\"all\" sets all logical volumes.");
111  ("Optionally propagates down hierarchy to given depth.");
112  G4UIparameter* parameter;
113  parameter = new G4UIparameter ("logical-volume-name", 's', omitable = true);
114  parameter->SetDefaultValue("all");
115  fpCommand->SetParameter(parameter);
116  parameter = new G4UIparameter("depth", 'd', omitable = true);
117  parameter->SetDefaultValue(0);
118  parameter->SetGuidance
119  ("Depth of propagation (-1 means unlimited depth).");
120  fpCommand->SetParameter(parameter);
121  parameter = new G4UIparameter("red", 's', omitable = true);
122  parameter->SetDefaultValue("1.");
123  parameter->SetGuidance
124  ("Red component or a string, e.g., \"blue\", in which case succeeding colour components are ignored.");
125  fpCommand->SetParameter(parameter);
126  parameter = new G4UIparameter("green", 'd', omitable = true);
127  parameter->SetDefaultValue(1.);
128  fpCommand->SetParameter(parameter);
129  parameter = new G4UIparameter("blue", 'd', omitable = true);
130  parameter->SetDefaultValue(1.);
131  fpCommand->SetParameter(parameter);
132  parameter = new G4UIparameter("opacity", 'd', omitable = true);
133  parameter->SetDefaultValue(1.);
134  fpCommand->SetParameter(parameter);
135 }
136 
138 {
139  delete fpCommand;
140 }
141 
143 {
144  return "";
145 }
146 
148 (G4UIcommand*, G4String newValue)
149 {
150  G4String name, redOrString;
151  G4int requestedDepth;
152  G4double green, blue, opacity;
153  std::istringstream iss(newValue);
154  iss >> name >> requestedDepth >> redOrString >> green >> blue >> opacity;
155  G4Colour colour(1,1,1,1); // Default white and opaque.
156  ConvertToColour(colour, redOrString, green, blue, opacity);
157  G4VisCommandGeometrySetColourFunction setColour(colour);
158  Set(name, setColour, requestedDepth);
159 }
160 
162 
164 {
165  G4bool omitable;
166  fpCommand = new G4UIcommand("/vis/geometry/set/daughtersInvisible", this);
167  fpCommand->SetGuidance("Makes daughters of logical volume(s) invisible.");
168  fpCommand->SetGuidance("\"all\" sets all logical volumes.");
170  ("Optionally propagates down hierarchy to given depth.");
171  G4UIparameter* parameter;
172  parameter = new G4UIparameter ("logical-volume-name", 's', omitable = true);
173  parameter->SetDefaultValue("all");
174  fpCommand->SetParameter(parameter);
175  parameter = new G4UIparameter("depth", 'd', omitable = true);
176  parameter->SetDefaultValue(0);
177  parameter->SetGuidance
178  ("Depth of propagation (-1 means unlimited depth).");
179  fpCommand->SetParameter(parameter);
180  parameter = new G4UIparameter("daughtersInvisible", 'b', omitable = true);
181  parameter->SetDefaultValue(true);
182  fpCommand->SetParameter(parameter);
183 }
184 
186 {
187  delete fpCommand;
188 }
189 
190 G4String
192 {
193  return "";
194 }
195 
197 (G4UIcommand*, G4String newValue)
198 {
199  G4String name;
200  G4int requestedDepth;
201  G4String daughtersInvisibleString;
202  std::istringstream iss(newValue);
203  iss >> name >> requestedDepth >> daughtersInvisibleString;
204  G4bool daughtersInvisible =
205  G4UIcommand::ConvertToBool(daughtersInvisibleString);
206 
207  if (requestedDepth !=0) {
208  requestedDepth = 0;
209  if (fpVisManager->GetVerbosity() >= G4VisManager::warnings) {
210  G4cout << "Recursive application suppressed for this attribute."
211  << G4endl;
212  }
213  }
214 
216  setDaughtersInvisible(daughtersInvisible);
217  Set(name, setDaughtersInvisible, requestedDepth);
218 
219  G4VViewer* pViewer = fpVisManager->GetCurrentViewer();
220  if (pViewer) {
221  const G4ViewParameters& viewParams = pViewer->GetViewParameters();
222  if (fpVisManager->GetVerbosity() >= G4VisManager::warnings) {
223  if (!viewParams.IsCulling()) {
224  G4cout <<
225  "Culling must be on - \"/vis/viewer/set/culling global true\" - to see effect."
226  << G4endl;
227  }
228  }
229  }
230 }
231 
233 
235 {
236  G4bool omitable;
237  fpCommand = new G4UIcommand("/vis/geometry/set/forceAuxEdgeVisible", this);
239  ("Forces auxiliary (soft) edges of logical volume(s) to be visible,"
240  "\nregardless of the view parameters.");
241  fpCommand->SetGuidance("\"all\" sets all logical volumes.");
243  ("Optionally propagates down hierarchy to given depth.");
244  G4UIparameter* parameter;
245  parameter = new G4UIparameter ("logical-volume-name", 's', omitable = true);
246  parameter->SetDefaultValue("all");
247  fpCommand->SetParameter(parameter);
248  parameter = new G4UIparameter("depth", 'd', omitable = true);
249  parameter->SetDefaultValue(0);
250  parameter->SetGuidance
251  ("Depth of propagation (-1 means unlimited depth).");
252  fpCommand->SetParameter(parameter);
253  parameter = new G4UIparameter("forceAuxEdgeVisible", 'b', omitable = true);
254  parameter->SetDefaultValue(true);
255  fpCommand->SetParameter(parameter);
256 }
257 
259 {
260  delete fpCommand;
261 }
262 
263 G4String
265 {
266  return "";
267 }
268 
270 (G4UIcommand*, G4String newValue)
271 {
272  G4String name;
273  G4int requestedDepth;
274  G4String forceAuxEdgeVisibleString;
275  std::istringstream iss(newValue);
276  iss >> name >> requestedDepth >> forceAuxEdgeVisibleString;
277  G4bool forceAuxEdgeVisible =
278  G4UIcommand::ConvertToBool(forceAuxEdgeVisibleString);;
279 
281  setForceAuxEdgeVisible(forceAuxEdgeVisible);
282  Set(name, setForceAuxEdgeVisible, requestedDepth);
283 }
284 
286 
288 {
289  G4bool omitable;
290  fpCommand = new G4UIcommand("/vis/geometry/set/forceLineSegmentsPerCircle", this);
292  ("Forces number of line segments per circle, the precision with which a"
293  "\ncurved line or surface is represented by a polygon or polyhedron,"
294  "\nregardless of the view parameters.");
295  fpCommand->SetGuidance("\"all\" sets all logical volumes.");
297  ("Optionally propagates down hierarchy to given depth.");
298  G4UIparameter* parameter;
299  parameter = new G4UIparameter ("logical-volume-name", 's', omitable = true);
300  parameter->SetDefaultValue("all");
301  fpCommand->SetParameter(parameter);
302  parameter = new G4UIparameter("depth", 'd', omitable = true);
303  parameter->SetDefaultValue(0);
304  parameter->SetGuidance
305  ("Depth of propagation (-1 means unlimited depth).");
306  fpCommand->SetParameter(parameter);
307  parameter = new G4UIparameter("lineSegmentsPerCircle", 'd', omitable = true);
308  parameter->SetGuidance
309  ("<= 0 means not forced, i.e., under control of viewer.");
310  parameter->SetDefaultValue(0);
311  fpCommand->SetParameter(parameter);
312 }
313 
315 {
316  delete fpCommand;
317 }
318 
319 G4String
321 {
322  return "";
323 }
324 
326 (G4UIcommand*, G4String newValue)
327 {
328  G4String name;
329  G4int requestedDepth;
330  G4int lineSegmentsPerCircle;
331  std::istringstream iss(newValue);
332  iss >> name >> requestedDepth >> lineSegmentsPerCircle;
333 
334  G4VisCommandGeometrySetForceLineSegmentsPerCircleFunction setForceLineSegmentsPerCircle(lineSegmentsPerCircle);
335  Set(name, setForceLineSegmentsPerCircle, requestedDepth);
336 }
337 
339 
341 {
342  G4bool omitable;
343  fpCommand = new G4UIcommand("/vis/geometry/set/forceSolid", this);
345  ("Forces logical volume(s) always to be drawn solid (surface drawing),"
346  "\nregardless of the view parameters.");
347  fpCommand->SetGuidance("\"all\" sets all logical volumes.");
349  ("Optionally propagates down hierarchy to given depth.");
350  G4UIparameter* parameter;
351  parameter = new G4UIparameter ("logical-volume-name", 's', omitable = true);
352  parameter->SetDefaultValue("all");
353  fpCommand->SetParameter(parameter);
354  parameter = new G4UIparameter("depth", 'd', omitable = true);
355  parameter->SetDefaultValue(0);
356  parameter->SetGuidance
357  ("Depth of propagation (-1 means unlimited depth).");
358  fpCommand->SetParameter(parameter);
359  parameter = new G4UIparameter("force", 'b', omitable = true);
360  parameter->SetDefaultValue(true);
361  fpCommand->SetParameter(parameter);
362 }
363 
365 {
366  delete fpCommand;
367 }
368 
369 G4String
371 {
372  return "";
373 }
374 
376 (G4UIcommand*, G4String newValue)
377 {
378  G4String name;
379  G4int requestedDepth;
380  G4String forceString;
381  std::istringstream iss(newValue);
382  iss >> name >> requestedDepth >> forceString;
383  G4bool force = G4UIcommand::ConvertToBool(forceString);
384 
385  G4VisCommandGeometrySetForceSolidFunction setForceSolid(force);
386  Set(name, setForceSolid, requestedDepth);
387 }
388 
390 
392 {
393  G4bool omitable;
394  fpCommand = new G4UIcommand("/vis/geometry/set/forceWireframe", this);
396  ("Forces logical volume(s) always to be drawn as wireframe,"
397  "\nregardless of the view parameters.");
398  fpCommand->SetGuidance("\"all\" sets all logical volumes.");
400  ("Optionally propagates down hierarchy to given depth.");
401  G4UIparameter* parameter;
402  parameter = new G4UIparameter ("logical-volume-name", 's', omitable = true);
403  parameter->SetDefaultValue("all");
404  fpCommand->SetParameter(parameter);
405  parameter = new G4UIparameter("depth", 'd', omitable = true);
406  parameter->SetDefaultValue(0);
407  parameter->SetGuidance
408  ("Depth of propagation (-1 means unlimited depth).");
409  fpCommand->SetParameter(parameter);
410  parameter = new G4UIparameter("forceWireframe", 'b', omitable = true);
411  parameter->SetDefaultValue(true);
412  fpCommand->SetParameter(parameter);
413 }
414 
416 {
417  delete fpCommand;
418 }
419 
420 G4String
422 {
423  return "";
424 }
425 
427 (G4UIcommand*, G4String newValue)
428 {
429  G4String name;
430  G4int requestedDepth;
431  G4String forceWireframeString;
432  std::istringstream iss(newValue);
433  iss >> name >> requestedDepth >> forceWireframeString;
434  G4bool forceWireframe = G4UIcommand::ConvertToBool(forceWireframeString);
435 
437  setForceWireframe(forceWireframe);
438  Set(name, setForceWireframe, requestedDepth);
439 }
440 
442 
444 {
445  G4bool omitable;
446  fpCommand = new G4UIcommand("/vis/geometry/set/lineStyle", this);
447  fpCommand->SetGuidance("Sets line style of logical volume(s) drawing.");
448  fpCommand->SetGuidance("\"all\" sets all logical volumes.");
450  ("Optionally propagates down hierarchy to given depth.");
451  G4UIparameter* parameter;
452  parameter = new G4UIparameter ("logical-volume-name", 's', omitable = true);
453  parameter->SetDefaultValue("all");
454  fpCommand->SetParameter(parameter);
455  parameter = new G4UIparameter("depth", 'd', omitable = true);
456  parameter->SetDefaultValue(0);
457  parameter->SetGuidance
458  ("Depth of propagation (-1 means unlimited depth).");
459  fpCommand->SetParameter(parameter);
460  parameter = new G4UIparameter("lineStyle", 's', omitable = true);
461  parameter->SetParameterCandidates("unbroken dashed dotted");
462  parameter->SetDefaultValue("unbroken");
463  fpCommand->SetParameter(parameter);
464 }
465 
467 {
468  delete fpCommand;
469 }
470 
471 G4String
473 {
474  return "";
475 }
476 
478 (G4UIcommand*, G4String newValue)
479 {
480  G4String name, lineStyleString;
481  G4int requestedDepth;
482  std::istringstream iss(newValue);
483  iss >> name >> requestedDepth >> lineStyleString;
485  if (lineStyleString == "unbroken") lineStyle = G4VisAttributes::unbroken;
486  if (lineStyleString == "dashed") lineStyle = G4VisAttributes::dashed;
487  if (lineStyleString == "dotted") lineStyle = G4VisAttributes::dotted;
488 
489  G4VisCommandGeometrySetLineStyleFunction setLineStyle(lineStyle);
490  Set(name, setLineStyle, requestedDepth);
491 }
492 
494 
496 {
497  G4bool omitable;
498  fpCommand = new G4UIcommand("/vis/geometry/set/lineWidth", this);
499  fpCommand->SetGuidance("Sets line width of logical volume(s) drawing.");
500  fpCommand->SetGuidance("\"all\" sets all logical volumes.");
502  ("Optionally propagates down hierarchy to given depth.");
503  G4UIparameter* parameter;
504  parameter = new G4UIparameter ("logical-volume-name", 's', omitable = true);
505  parameter->SetDefaultValue("all");
506  fpCommand->SetParameter(parameter);
507  parameter = new G4UIparameter("depth", 'd', omitable = true);
508  parameter->SetDefaultValue(0);
509  parameter->SetGuidance
510  ("Depth of propagation (-1 means unlimited depth).");
511  fpCommand->SetParameter(parameter);
512  parameter = new G4UIparameter("lineWidth", 'd', omitable = true);
513  parameter->SetDefaultValue(1.);
514  fpCommand->SetParameter(parameter);
515 }
516 
518 {
519  delete fpCommand;
520 }
521 
522 G4String
524 {
525  return "";
526 }
527 
529 (G4UIcommand*, G4String newValue)
530 {
531  G4String name;
532  G4int requestedDepth;
533  G4double lineWidth;
534  std::istringstream iss(newValue);
535  iss >> name >> requestedDepth >> lineWidth;
536 
537  G4VisCommandGeometrySetLineWidthFunction setLineWidth(lineWidth);
538  Set(name, setLineWidth, requestedDepth);
539 }
540 
542 
544 {
545  G4bool omitable;
546  fpCommand = new G4UIcommand("/vis/geometry/set/visibility", this);
547  fpCommand->SetGuidance("Sets visibility of logical volume(s).");
548  fpCommand->SetGuidance("\"all\" sets all logical volumes.");
550  ("Optionally propagates down hierarchy to given depth.");
551  G4UIparameter* parameter;
552  parameter = new G4UIparameter ("logical-volume-name", 's', omitable = true);
553  parameter->SetDefaultValue("all");
554  fpCommand->SetParameter(parameter);
555  parameter = new G4UIparameter("depth", 'd', omitable = true);
556  parameter->SetDefaultValue(0);
557  parameter->SetGuidance
558  ("Depth of propagation (-1 means unlimited depth).");
559  fpCommand->SetParameter(parameter);
560  parameter = new G4UIparameter("visibility", 'b', omitable = true);
561  parameter->SetDefaultValue(true);
562  fpCommand->SetParameter(parameter);
563 }
564 
566 {
567  delete fpCommand;
568 }
569 
571 {
572  return "";
573 }
574 
576 (G4UIcommand*, G4String newValue)
577 {
578  G4String name;
579  G4int requestedDepth;
580  G4String visibilityString;
581  std::istringstream iss(newValue);
582  iss >> name >> requestedDepth >> visibilityString;
583  G4bool visibility = G4UIcommand::ConvertToBool(visibilityString);
584 
585  G4VisCommandGeometrySetVisibilityFunction setVisibility(visibility);
586  Set(name, setVisibility, requestedDepth);
587 
588  G4VViewer* pViewer = fpVisManager->GetCurrentViewer();
589  if (pViewer) {
590  const G4ViewParameters& viewParams = pViewer->GetViewParameters();
591  if (fpVisManager->GetVerbosity() >= G4VisManager::warnings) {
592  if (!viewParams.IsCulling() ||
593  !viewParams.IsCullingInvisible()) {
594  G4cout <<
595  "Culling must be on - \"/vis/viewer/set/culling global true\" and"
596  "\n \"/vis/viewer/set/culling invisible true\" - to see effect."
597  << G4endl;
598  }
599  }
600  }
601 }
602 
604 (G4LogicalVolume* pLV, G4int requestedDepth,G4bool visibility)
605 {
606  if (!pLV) return;
607  G4VisCommandGeometrySetVisibilityFunction setVisibility(visibility);
608  SetLVVisAtts(pLV, setVisibility, 0, requestedDepth);
609 
610  G4VViewer* pViewer = fpVisManager->GetCurrentViewer();
611  if (pViewer) {
612  G4UImanager::GetUIpointer()->ApplyCommand("/vis/scene/notifyHandlers");
613  const G4ViewParameters& viewParams = pViewer->GetViewParameters();
614  if (fpVisManager->GetVerbosity() >= G4VisManager::warnings) {
615  if (!viewParams.IsCulling() ||
616  !viewParams.IsCullingInvisible()) {
617  G4cout <<
618  "Culling must be on - \"/vis/viewer/set/culling global true\" and"
619  "\n \"/vis/viewer/set/culling invisible true\" - to see effect."
620  << G4endl;
621  }
622  }
623  }
624 }