source: trunk/geant4/visualization/management/src/G4VisCommandsGeometrySet.cc @ 558

Last change on this file since 558 was 531, checked in by garnier, 17 years ago

r660@mac-90108: laurentgarnier | 2007-06-25 16:10:12 +0200
ajout de fichiers NON modifies

  • Property svn:mime-type set to text/cpp
File size: 19.2 KB
Line 
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: G4VisCommandsGeometrySet.cc,v 1.6 2006/09/19 16:05:13 allison Exp $
28// GEANT4 tag $Name: geant4-08-02-patch-01 $
29
30// /vis/geometry commands - John Allison  31st January 2006
31
32#include "G4VisCommandsGeometrySet.hh"
33
34#include "G4UIcommand.hh"
35#include "G4VisManager.hh"
36#include "G4LogicalVolumeStore.hh"
37#include "G4UImanager.hh"
38
39#include <sstream>
40#include <cctype>
41
42void G4VVisCommandGeometrySet::Set
43(G4String requestedName,
44 const G4VVisCommandGeometrySetFunction& setFunction,
45 G4int requestedDepth)
46{
47  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
48  G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
49  G4bool found = false;
50  for (size_t iLV = 0; iLV < pLVStore->size(); iLV++ ) {
51    G4LogicalVolume* pLV = (*pLVStore)[iLV];
52    const G4String& logVolName = pLV->GetName();
53    if (logVolName == requestedName) found = true;
54    if (requestedName == "all" || logVolName == requestedName) {
55      SetLVVisAtts(pLV, setFunction, 0, requestedDepth);
56    }
57  }
58  if (requestedName != "all" && !found) {
59    if (verbosity >= G4VisManager::errors) {
60      G4cout << "ERROR: Logical volume \"" << requestedName
61             << "\" not found in logical volume store." << G4endl;
62    }
63    return;
64  }
65  if (fpVisManager->GetCurrentViewer()) {
66    G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/rebuild");
67  }
68}
69
70void G4VVisCommandGeometrySet::SetLVVisAtts
71(G4LogicalVolume* pLV,
72 const G4VVisCommandGeometrySetFunction& setFunction,
73 G4int depth, G4int requestedDepth)
74{
75  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
76  const G4VisAttributes* oldVisAtts = pLV->GetVisAttributes();
77  fVisAttsMap.insert(std::make_pair(pLV,oldVisAtts));  // Store old vis atts.
78  G4VisAttributes* newVisAtts = new G4VisAttributes;   // Memory leak!
79  if (oldVisAtts) {
80    *newVisAtts = *oldVisAtts;
81  }
82  setFunction(newVisAtts);  // Sets whatever attribute determined by
83                            // function object.
84  pLV->SetVisAttributes(newVisAtts);
85  if (verbosity >= G4VisManager::confirmations) {
86    G4cout << "\nLogical Volume \"" << pLV->GetName()
87           << "\": setting vis attributes:\nwas: " << *oldVisAtts
88           << "\nnow: " << *newVisAtts
89           << G4endl;
90  }
91  if (requestedDepth < 0 || depth++ < requestedDepth) {
92    G4int nDaughters = pLV->GetNoDaughters();
93    for (G4int i = 0; i < nDaughters; ++i) {
94      SetLVVisAtts(pLV->GetDaughter(i)->GetLogicalVolume(),
95                   setFunction, depth, requestedDepth);
96    }
97  }
98}
99
100////////////// /vis/geometry/set/colour ///////////////////////////////////////
101
102G4VisCommandGeometrySetColour::G4VisCommandGeometrySetColour()
103{
104  G4bool omitable;
105  fpCommand = new G4UIcommand("/vis/geometry/set/colour", this);
106  fpCommand->SetGuidance("Sets colour of logical volume(s).");
107  fpCommand->SetGuidance("\"all\" sets all logical volumes.");
108  fpCommand->SetGuidance
109    ("Optionally propagates down hierarchy to given depth.");
110  G4UIparameter* parameter;
111  parameter = new G4UIparameter ("logical-volume-name", 's', omitable = true);
112  parameter->SetDefaultValue("all");
113  fpCommand->SetParameter(parameter);
114  parameter = new G4UIparameter("depth", 'd', omitable = true);
115  parameter->SetDefaultValue(0);
116  parameter->SetGuidance
117    ("Depth of propagation (-1 means unlimited depth).");
118  fpCommand->SetParameter(parameter);
119  parameter = new G4UIparameter("red", 's', omitable = true);
120  parameter->SetDefaultValue("1.");
121  parameter->SetGuidance
122    ("Red component or a string, e.g., \"blue\", in which case succeeding colour components are ignored.");
123  fpCommand->SetParameter(parameter);
124  parameter = new G4UIparameter("green", 'd', omitable = true);
125  parameter->SetDefaultValue(1.);
126  fpCommand->SetParameter(parameter);
127  parameter = new G4UIparameter("blue", 'd', omitable = true);
128  parameter->SetDefaultValue(1.);
129  fpCommand->SetParameter(parameter);
130  parameter = new G4UIparameter("opacity", 'd', omitable = true);
131  parameter->SetDefaultValue(1.);
132  fpCommand->SetParameter(parameter);
133}
134
135G4VisCommandGeometrySetColour::~G4VisCommandGeometrySetColour()
136{
137  delete fpCommand;
138}
139
140G4String G4VisCommandGeometrySetColour::GetCurrentValue(G4UIcommand*)
141{
142  return "";
143}
144
145void G4VisCommandGeometrySetColour::SetNewValue
146(G4UIcommand*, G4String newValue)
147{
148  G4String name, redOrString;
149  G4int requestedDepth;
150  G4double green, blue, opacity;
151  std::istringstream iss(newValue);
152  iss >> name >> requestedDepth >> redOrString >> green >> blue >> opacity;
153  G4Colour colour(1,1,1,1);  // Default white and opaque.
154  const size_t iPos0 = 0;
155  if (std::isalpha(redOrString[iPos0])) {
156    G4Colour::GetColour(redOrString, colour); // Remains if not found.
157  } else {
158    colour = G4Colour(G4UIcommand::ConvertToDouble(redOrString), green, blue);
159  }
160  colour = G4Colour
161    (colour.GetRed(), colour.GetGreen(), colour.GetBlue(), opacity);
162
163  G4VisCommandGeometrySetColourFunction setColour(colour);
164  Set(name, setColour, requestedDepth);
165}
166
167////////////// /vis/geometry/set/daughtersInvisible //////////////////////
168
169G4VisCommandGeometrySetDaughtersInvisible::G4VisCommandGeometrySetDaughtersInvisible()
170{
171  G4bool omitable;
172  fpCommand = new G4UIcommand("/vis/geometry/set/daughtersInvisible", this);
173  fpCommand->SetGuidance("Sets daughters of logical volume(s) invisible.");
174  fpCommand->SetGuidance("\"all\" sets all logical volumes.");
175  fpCommand->SetGuidance
176    ("Optionally propagates down hierarchy to given depth.");
177  G4UIparameter* parameter;
178  parameter = new G4UIparameter ("logical-volume-name", 's', omitable = true);
179  parameter->SetDefaultValue("all");
180  fpCommand->SetParameter(parameter);
181  parameter = new G4UIparameter("depth", 'd', omitable = true);
182  parameter->SetDefaultValue(0);
183  parameter->SetGuidance
184    ("Depth of propagation (-1 means unlimited depth).");
185  fpCommand->SetParameter(parameter);
186  parameter = new G4UIparameter("daughtersInvisible", 'b', omitable = true);
187  parameter->SetDefaultValue(false);
188  fpCommand->SetParameter(parameter);
189}
190
191G4VisCommandGeometrySetDaughtersInvisible::~G4VisCommandGeometrySetDaughtersInvisible()
192{
193  delete fpCommand;
194}
195
196G4String
197G4VisCommandGeometrySetDaughtersInvisible::GetCurrentValue(G4UIcommand*)
198{
199  return "";
200}
201
202void G4VisCommandGeometrySetDaughtersInvisible::SetNewValue
203(G4UIcommand*, G4String newValue)
204{
205  G4String name;
206  G4int requestedDepth;
207  G4String daughtersInvisibleString;
208  std::istringstream iss(newValue);
209  iss >> name >> requestedDepth >> daughtersInvisibleString;
210  G4bool daughtersInvisible =
211    G4UIcommand::ConvertToBool(daughtersInvisibleString);
212
213  if (requestedDepth !=0) {
214    requestedDepth = 0;
215    if (fpVisManager->GetVerbosity() >= G4VisManager::warnings) {
216      G4cout << "Recursive application suppressed for this attribute."
217             << G4endl;
218    }
219  }
220
221  G4VisCommandGeometrySetDaughtersInvisibleFunction
222    setDaughtersInvisible(daughtersInvisible);
223  Set(name, setDaughtersInvisible, requestedDepth);
224
225  G4VViewer* pViewer = fpVisManager->GetCurrentViewer();
226  if (pViewer) {
227    const G4ViewParameters& viewParams = pViewer->GetViewParameters();
228    if (fpVisManager->GetVerbosity() >= G4VisManager::warnings) {
229      if (!viewParams.IsCulling()) {
230        G4cout <<
231          "Culling must be on - \"/vis/viewer/set/culling global true\" - to see effect."
232               << G4endl;
233      }
234    }
235  }
236}
237
238////////////// /vis/geometry/set/forceAuxEdgeVisible /////////////////////////
239
240G4VisCommandGeometrySetForceAuxEdgeVisible::G4VisCommandGeometrySetForceAuxEdgeVisible()
241{
242  G4bool omitable;
243  fpCommand = new G4UIcommand("/vis/geometry/set/forceAuxEdgeVisible", this);
244  fpCommand->SetGuidance
245    ("Sets auxiliary (soft) edges of logical volume(s) drawing visible.");
246  fpCommand->SetGuidance("\"all\" sets all logical volumes.");
247  fpCommand->SetGuidance
248    ("Optionally propagates down hierarchy to given depth.");
249  G4UIparameter* parameter;
250  parameter = new G4UIparameter ("logical-volume-name", 's', omitable = true);
251  parameter->SetDefaultValue("all");
252  fpCommand->SetParameter(parameter);
253  parameter = new G4UIparameter("depth", 'd', omitable = true);
254  parameter->SetDefaultValue(0);
255  parameter->SetGuidance
256    ("Depth of propagation (-1 means unlimited depth).");
257  fpCommand->SetParameter(parameter);
258  parameter = new G4UIparameter("forceAuxEdgeVisible", 'b', omitable = true);
259  parameter->SetDefaultValue(false);
260  fpCommand->SetParameter(parameter);
261}
262
263G4VisCommandGeometrySetForceAuxEdgeVisible::~G4VisCommandGeometrySetForceAuxEdgeVisible()
264{
265  delete fpCommand;
266}
267
268G4String
269G4VisCommandGeometrySetForceAuxEdgeVisible::GetCurrentValue(G4UIcommand*)
270{
271  return "";
272}
273
274void G4VisCommandGeometrySetForceAuxEdgeVisible::SetNewValue
275(G4UIcommand*, G4String newValue)
276{
277  G4String name;
278  G4int requestedDepth;
279  G4String forceAuxEdgeVisibleString;
280  std::istringstream iss(newValue);
281  iss >> name >> requestedDepth >> forceAuxEdgeVisibleString;
282  G4bool forceAuxEdgeVisible =
283    G4UIcommand::ConvertToBool(forceAuxEdgeVisibleString);;
284
285  G4VisCommandGeometrySetForceAuxEdgeVisibleFunction
286    setForceAuxEdgeVisible(forceAuxEdgeVisible);
287  Set(name, setForceAuxEdgeVisible, requestedDepth);
288}
289
290////////////// /vis/geometry/set/forceSolid /////////////////////////
291
292G4VisCommandGeometrySetForceSolid::G4VisCommandGeometrySetForceSolid()
293{
294  G4bool omitable;
295  fpCommand = new G4UIcommand("/vis/geometry/set/forceSolid", this);
296  fpCommand->SetGuidance
297   ("Sets logical volume(s) drawing always to be as solid (surface drawing).");
298  fpCommand->SetGuidance("\"all\" sets all logical volumes.");
299  fpCommand->SetGuidance
300    ("Optionally propagates down hierarchy to given depth.");
301  G4UIparameter* parameter;
302  parameter = new G4UIparameter ("logical-volume-name", 's', omitable = true);
303  parameter->SetDefaultValue("all");
304  fpCommand->SetParameter(parameter);
305  parameter = new G4UIparameter("depth", 'd', omitable = true);
306  parameter->SetDefaultValue(0);
307  parameter->SetGuidance
308    ("Depth of propagation (-1 means unlimited depth).");
309  fpCommand->SetParameter(parameter);
310  parameter = new G4UIparameter("forceSolid", 'b', omitable = true);
311  parameter->SetDefaultValue(false);
312  fpCommand->SetParameter(parameter);
313}
314
315G4VisCommandGeometrySetForceSolid::~G4VisCommandGeometrySetForceSolid()
316{
317  delete fpCommand;
318}
319
320G4String
321G4VisCommandGeometrySetForceSolid::GetCurrentValue(G4UIcommand*)
322{
323  return "";
324}
325
326void G4VisCommandGeometrySetForceSolid::SetNewValue
327(G4UIcommand*, G4String newValue)
328{
329  G4String name;
330  G4int requestedDepth;
331  G4String forceSolidString;
332  std::istringstream iss(newValue);
333  iss >> name >> requestedDepth >> forceSolidString;
334  G4bool forceSolid = G4UIcommand::ConvertToBool(forceSolidString);
335
336  G4VisCommandGeometrySetForceSolidFunction setForceSolid(forceSolid);
337  Set(name, setForceSolid, requestedDepth);
338}
339
340////////////// /vis/geometry/set/forceWireframe /////////////////////////
341
342G4VisCommandGeometrySetForceWireframe::G4VisCommandGeometrySetForceWireframe()
343{
344  G4bool omitable;
345  fpCommand = new G4UIcommand("/vis/geometry/set/forceWireframe", this);
346  fpCommand->SetGuidance
347   ("Sets logical volume(s) drawing always to be as wireframe.");
348  fpCommand->SetGuidance("\"all\" sets all logical volumes.");
349  fpCommand->SetGuidance
350    ("Optionally propagates down hierarchy to given depth.");
351  G4UIparameter* parameter;
352  parameter = new G4UIparameter ("logical-volume-name", 's', omitable = true);
353  parameter->SetDefaultValue("all");
354  fpCommand->SetParameter(parameter);
355  parameter = new G4UIparameter("depth", 'd', omitable = true);
356  parameter->SetDefaultValue(0);
357  parameter->SetGuidance
358    ("Depth of propagation (-1 means unlimited depth).");
359  fpCommand->SetParameter(parameter);
360  parameter = new G4UIparameter("forceWireframe", 'b', omitable = true);
361  parameter->SetDefaultValue(false);
362  fpCommand->SetParameter(parameter);
363}
364
365G4VisCommandGeometrySetForceWireframe::~G4VisCommandGeometrySetForceWireframe()
366{
367  delete fpCommand;
368}
369
370G4String
371G4VisCommandGeometrySetForceWireframe::GetCurrentValue(G4UIcommand*)
372{
373  return "";
374}
375
376void G4VisCommandGeometrySetForceWireframe::SetNewValue
377(G4UIcommand*, G4String newValue)
378{
379  G4String name;
380  G4int requestedDepth;
381  G4String forceWireframeString;
382  std::istringstream iss(newValue);
383  iss >> name >> requestedDepth >> forceWireframeString;
384  G4bool forceWireframe = G4UIcommand::ConvertToBool(forceWireframeString);
385
386  G4VisCommandGeometrySetForceWireframeFunction
387    setForceWireframe(forceWireframe);
388  Set(name, setForceWireframe, requestedDepth);
389}
390
391////////////// /vis/geometry/set/lineStyle /////////////////////////////////
392
393G4VisCommandGeometrySetLineStyle::G4VisCommandGeometrySetLineStyle()
394{
395  G4bool omitable;
396  fpCommand = new G4UIcommand("/vis/geometry/set/lineStyle", this);
397  fpCommand->SetGuidance("Sets line style of logical volume(s) drawing.");
398  fpCommand->SetGuidance("\"all\" sets all logical volumes.");
399  fpCommand->SetGuidance
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("lineStyle", 's', omitable = true);
411  parameter->SetParameterCandidates("unbroken dashed dotted");
412  parameter->SetDefaultValue("unbroken");
413  fpCommand->SetParameter(parameter);
414}
415
416G4VisCommandGeometrySetLineStyle::~G4VisCommandGeometrySetLineStyle()
417{
418  delete fpCommand;
419}
420
421G4String
422G4VisCommandGeometrySetLineStyle::GetCurrentValue(G4UIcommand*)
423{
424  return "";
425}
426
427void G4VisCommandGeometrySetLineStyle::SetNewValue
428(G4UIcommand*, G4String newValue)
429{
430  G4String name, lineStyleString;
431  G4int requestedDepth;
432  std::istringstream iss(newValue);
433  iss >> name >> requestedDepth >> lineStyleString;
434  G4VisAttributes::LineStyle lineStyle = G4VisAttributes::unbroken;
435  if (lineStyleString == "unbroken") lineStyle = G4VisAttributes::unbroken;
436  if (lineStyleString == "dashed") lineStyle = G4VisAttributes::dashed;
437  if (lineStyleString == "dotted") lineStyle = G4VisAttributes::dotted;
438
439  G4VisCommandGeometrySetLineStyleFunction setLineStyle(lineStyle);
440  Set(name, setLineStyle, requestedDepth);
441}
442
443////////////// /vis/geometry/set/lineWidth /////////////////////////////////
444
445G4VisCommandGeometrySetLineWidth::G4VisCommandGeometrySetLineWidth()
446{
447  G4bool omitable;
448  fpCommand = new G4UIcommand("/vis/geometry/set/lineWidth", this);
449  fpCommand->SetGuidance("Sets line width of logical volume(s) drawing.");
450  fpCommand->SetGuidance("\"all\" sets all logical volumes.");
451  fpCommand->SetGuidance
452    ("Optionally propagates down hierarchy to given depth.");
453  G4UIparameter* parameter;
454  parameter = new G4UIparameter ("logical-volume-name", 's', omitable = true);
455  parameter->SetDefaultValue("all");
456  fpCommand->SetParameter(parameter);
457  parameter = new G4UIparameter("depth", 'd', omitable = true);
458  parameter->SetDefaultValue(0);
459  parameter->SetGuidance
460    ("Depth of propagation (-1 means unlimited depth).");
461  fpCommand->SetParameter(parameter);
462  parameter = new G4UIparameter("lineWidth", 'd', omitable = true);
463  parameter->SetDefaultValue(1.);
464  fpCommand->SetParameter(parameter);
465}
466
467G4VisCommandGeometrySetLineWidth::~G4VisCommandGeometrySetLineWidth()
468{
469  delete fpCommand;
470}
471
472G4String
473G4VisCommandGeometrySetLineWidth::GetCurrentValue(G4UIcommand*)
474{
475  return "";
476}
477
478void G4VisCommandGeometrySetLineWidth::SetNewValue
479(G4UIcommand*, G4String newValue)
480{
481  G4String name;
482  G4int requestedDepth;
483  G4double lineWidth;
484  std::istringstream iss(newValue);
485  iss >> name >> requestedDepth >> lineWidth;
486
487  G4VisCommandGeometrySetLineWidthFunction setLineWidth(lineWidth);
488  Set(name, setLineWidth, requestedDepth);
489}
490
491////////////// /vis/geometry/set/visibility ///////////////////////////////////////
492
493G4VisCommandGeometrySetVisibility::G4VisCommandGeometrySetVisibility()
494{
495  G4bool omitable;
496  fpCommand = new G4UIcommand("/vis/geometry/set/visibility", this);
497  fpCommand->SetGuidance("Sets visibility of logical volume(s).");
498  fpCommand->SetGuidance("\"all\" sets all logical volumes.");
499  fpCommand->SetGuidance
500    ("Optionally propagates down hierarchy to given depth.");
501  G4UIparameter* parameter;
502  parameter = new G4UIparameter ("logical-volume-name", 's', omitable = true);
503  parameter->SetDefaultValue("all");
504  fpCommand->SetParameter(parameter);
505  parameter = new G4UIparameter("depth", 'd', omitable = true);
506  parameter->SetDefaultValue(0);
507  parameter->SetGuidance
508    ("Depth of propagation (-1 means unlimited depth).");
509  fpCommand->SetParameter(parameter);
510  parameter = new G4UIparameter("visibility", 'b', omitable = true);
511  parameter->SetDefaultValue(true);
512  fpCommand->SetParameter(parameter);
513}
514
515G4VisCommandGeometrySetVisibility::~G4VisCommandGeometrySetVisibility()
516{
517  delete fpCommand;
518}
519
520G4String G4VisCommandGeometrySetVisibility::GetCurrentValue(G4UIcommand*)
521{
522  return "";
523}
524
525void G4VisCommandGeometrySetVisibility::SetNewValue
526(G4UIcommand*, G4String newValue)
527{
528  G4String name;
529  G4int requestedDepth;
530  G4String visibilityString;
531  std::istringstream iss(newValue);
532  iss >> name >> requestedDepth >> visibilityString;
533  G4bool visibility = G4UIcommand::ConvertToBool(visibilityString);
534
535  G4VisCommandGeometrySetVisibilityFunction setVisibility(visibility);
536  Set(name, setVisibility, requestedDepth);
537
538  G4VViewer* pViewer = fpVisManager->GetCurrentViewer();
539  if (pViewer) {
540    const G4ViewParameters& viewParams = pViewer->GetViewParameters();
541    if (fpVisManager->GetVerbosity() >= G4VisManager::warnings) {
542      if (!viewParams.IsCulling() ||
543          !viewParams.IsCullingInvisible()) {
544        G4cout <<
545          "Culling must be on - \"/vis/viewer/set/culling global true\" and"
546          "\n  \"/vis/viewer/set/culling invisible true\" - to see effect."
547               << G4endl;
548      }
549    }
550  }
551}
Note: See TracBrowser for help on using the repository browser.