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