Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4VVisCommand.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 // $Id: G4VVisCommand.cc 109510 2018-04-26 07:15:57Z gcosmo $
28 
29 // Base class for visualization commands - John Allison 9th August 1998
30 // It is really a messenger - we have one command per messenger.
31 
32 #include "G4VVisCommand.hh"
33 
34 #include "G4UIcommand.hh"
35 #include "G4UImanager.hh"
36 #include "G4UnitsTable.hh"
37 #include <sstream>
38 #include <cctype>
39 
41 
48 // Not yet used: G4VisAttributes::LineStyle G4VVisCommand::fCurrentLineStyle = G4VisAttributes::unbroken;
49 // Not yet used: G4VMarker::FillStyle G4VVisCommand::fCurrentFillStyle = G4VMarker::filled;
50 // Not yet used: G4VMarker::SizeType G4VVisCommand::fCurrentSizeType = G4VMarker::screen;
52 
54 
56 
58 
60 (G4double x, G4double y, const char * unitName)
61 {
62  G4double uv = G4UIcommand::ValueOf(unitName);
63 
64  std::ostringstream oss;
65  oss << x/uv << " " << y/uv << " " << unitName;
66  return oss.str();
67 }
68 
70  G4double& xval,
71  G4double& yval)
72 {
73  G4double x, y;
74  G4String unit;
75 
76  std::istringstream is(paramString);
77  is >> x >> y >> unit;
78 
80  xval = x*G4UIcommand::ValueOf(unit);
81  yval = y*G4UIcommand::ValueOf(unit);
82  } else {
84  if (verbosity >= G4VisManager::errors) {
85  G4cout << "ERROR: Unrecognised unit" << G4endl;
86  }
87  return false;
88  }
89 
90  return true;
91 }
92 
94 {
95  static G4String guidance
96  ("Accepts (a) RGB triplet. e.g., \".3 .4 .5\", or"
97  "\n (b) string such as \"white\", \"black\", \"grey\", \"red\"...or"
98  "\n (c) an additional number for opacity, e.g., \".3 .4 .5 .6\""
99  "\n or \"grey ! ! .6\" (note \"!\"'s for unused parameters).");
100  return guidance;
101 }
102 
104 (G4Colour& colour,
105  const G4String& redOrString, G4double green, G4double blue, G4double opacity)
106 {
107  // Note: colour is supplied by the caller and some or all of its components
108  // may act as default.
109  //
110  // Note: redOrString is either a number or string. If a string it must be
111  // one of the recognised colours.
112  //
113  // Thus the arguments can be, for example:
114  // (colour,"red",...,...,0.5): will give the colour red with opacity 0.5 (the
115  // third and fourth arguments are ignored), or
116  // (1.,0.,0.,0.5): this also will be red with opacity 0.5.
117 
118  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
119 
120  const size_t iPos0 = 0;
121  if (std::isalpha(redOrString[iPos0])) {
122 
123  // redOrString is probably alphabetic characters defining the colour
124  if (!G4Colour::GetColour(redOrString, colour)) {
125  // Not a recognised string
126  if (verbosity >= G4VisManager::warnings) {
127  G4cout << "WARNING: Colour \"" << redOrString
128  << "\" not found. Defaulting to " << colour
129  << G4endl;
130  }
131  return;
132  } else {
133  // It was a recognised string. Now add opacity.
134  colour.SetAlpha(opacity);
135  return;
136  }
137 
138  } else {
139 
140  // redOrString is probably numeric defining the red component
141  std::istringstream iss(redOrString);
142  G4double red;
143  iss >> red;
144  if (iss.fail()) {
145  if (verbosity >= G4VisManager::warnings) {
146  G4cout << "WARNING: String \"" << redOrString
147  << "\" cannot be parsed. Defaulting to " << colour
148  << G4endl;
149  }
150  return;
151  } else {
152  colour = G4Colour(red,green,blue,opacity);
153  return;
154  }
155 
156  }
157 }
158 
160 (const G4String& where,
161  const G4String& unit,
162  const G4String& category,
163  G4double& value)
164 {
165  // Return false if there's a problem
166 
167  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
168 
169  G4bool success = true;
170  if (!G4UnitDefinition::IsUnitDefined(unit)) {
171  if (verbosity >= G4VisManager::warnings) {
172  G4cerr << where
173  << "\n Unit \"" << unit << "\" not defined"
174  << G4endl;
175  }
176  success = false;
177  } else if (G4UnitDefinition::GetCategory(unit) != category) {
178  if (verbosity >= G4VisManager::warnings) {
179  G4cerr << where
180  << "\n Unit \"" << unit << "\" not a unit of " << category;
181  if (category == "Volumic Mass") G4cerr << " (density)";
182  G4cerr << G4endl;
183  }
184  success = false;
185  } else {
186  value = G4UnitDefinition::GetValueOf(unit);
187  }
188  return success;
189 }
190 
192 (const G4String& sceneName) {
193 
194  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
195 
196  const G4SceneList& sceneList = fpVisManager -> GetSceneList ();
197 
198  G4int iScene, nScenes = sceneList.size ();
199  for (iScene = 0; iScene < nScenes; iScene++) {
200  if (sceneList [iScene] -> GetName () == sceneName) break;
201  }
202 
203  G4Scene* pScene = 0; // Zero unless scene has been found...
204  if (iScene < nScenes) {
205  pScene = sceneList [iScene];
206  }
207 
208  if (!pScene) {
209  if (verbosity >= G4VisManager::warnings) {
210  G4cout << "WARNING: Scene \"" << sceneName << "\" not found."
211  << G4endl;
212  }
213  return;
214  }
215 
216  fpVisManager -> SetCurrentScene (pScene);
217 
218  // Scene has changed. Refresh viewers of all sceneHandlers using
219  // this scene...
220  G4VViewer* pViewer = fpVisManager -> GetCurrentViewer();
221  G4VSceneHandler* sceneHandler = fpVisManager -> GetCurrentSceneHandler();
222  if (sceneHandler && sceneHandler -> GetScene ()) {
223  if (pViewer) {
225  ApplyCommand ("/vis/scene/notifyHandlers");
226  }
227  }
228 }
Float_t x
Definition: compare.C:6
std::vector< PVNameCopyNo > PVNameCopyNoPath
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:311
Definition: test07.cc:36
static G4String ConvertToString(G4double x, G4double y, const char *unitName)
#define G4endl
Definition: G4ios.hh:61
Float_t y
Definition: compare.C:6
virtual ~G4VVisCommand()
static G4double fCurrentLineWidth
static G4bool IsUnitDefined(const G4String &)
Definition: test07.cc:36
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:73
void UpdateVisManagerScene(const G4String &sceneName="")
void ConvertToColour(G4Colour &colour, const G4String &redOrString, G4double green, G4double blue, G4double opacity)
static G4int fErrorCode
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
const XML_Char int const XML_Char * value
Definition: expat.h:331
static G4Colour Blue()
Definition: G4Colour.hh:162
static G4double GetValueOf(const G4String &)
static Verbosity GetVerbosity()
const G4String & ConvertToColourGuidance()
G4GLOB_DLL std::ostream G4cerr
static G4Colour fCurrentColour
Layout
Definition: G4Text.hh:77
int G4int
Definition: G4Types.hh:78
G4bool ProvideValueOfUnit(const G4String &where, const G4String &unit, const G4String &category, G4double &value)
static G4ModelingParameters::PVNameCopyNoPath fCurrentTouchablePath
void SetAlpha(G4double)
Definition: G4Colour.cc:71
static G4Colour White()
Definition: G4Colour.hh:155
G4GLOB_DLL std::ostream G4cout
static G4Text::Layout fCurrentTextLayout
static G4int fCurrentArrow3DLineSegmentsPerCircle
static G4String GetCategory(const G4String &)
static G4Colour fCurrentTextColour
static G4double fCurrentTextSize
static G4VisManager * fpVisManager
static G4bool ConvertToDoublePair(const G4String &paramString, G4double &xval, G4double &yval)
static G4bool GetColour(const G4String &key, G4Colour &result)
Definition: G4Colour.cc:163