Geant4  10.02.p03
G4VisCommandSceneHandlerCreate Class Reference

#include <G4VisCommandsSceneHandler.hh>

Inheritance diagram for G4VisCommandSceneHandlerCreate:
Collaboration diagram for G4VisCommandSceneHandlerCreate:

Public Member Functions

 G4VisCommandSceneHandlerCreate ()
 
 ~G4VisCommandSceneHandlerCreate ()
 
G4String GetCurrentValue (G4UIcommand *command)
 
void SetNewValue (G4UIcommand *command, G4String newValue)
 
- Public Member Functions inherited from G4VVisCommand
 G4VVisCommand ()
 
virtual ~G4VVisCommand ()
 
- Public Member Functions inherited from G4UImessenger
 G4UImessenger ()
 
 G4UImessenger (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
 
virtual ~G4UImessenger ()
 
G4bool operator== (const G4UImessenger &messenger) const
 
G4bool CommandsShouldBeInMaster () const
 

Private Member Functions

G4String NextName ()
 

Private Attributes

G4UIcommandfpCommand
 
G4int fId
 

Additional Inherited Members

- Static Public Member Functions inherited from G4VVisCommand
static void SetVisManager (G4VisManager *)
 
static const G4ColourGetCurrentColour ()
 
static G4double GetCurrentLineWidth ()
 
static const G4ColourGetCurrentTextColour ()
 
static G4Text::Layout GetCurrentTextLayout ()
 
static G4double GetCurrentTextSize ()
 
- Protected Member Functions inherited from G4VVisCommand
void UpdateVisManagerScene (const G4String &sceneName="")
 
- Protected Member Functions inherited from G4UImessenger
G4String ItoS (G4int i)
 
G4String DtoS (G4double a)
 
G4String BtoS (G4bool b)
 
G4int StoI (G4String s)
 
G4double StoD (G4String s)
 
G4bool StoB (G4String s)
 
void AddUIcommand (G4UIcommand *newCommand)
 
void CreateDirectory (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
 
template<typename T >
T * CreateCommand (const G4String &cname, const G4String &dsc)
 
- Static Protected Member Functions inherited from G4VVisCommand
static G4String ConvertToString (G4double x, G4double y, const char *unitName)
 
static void ConvertToDoublePair (const G4String &paramString, G4double &xval, G4double &yval)
 
- Protected Attributes inherited from G4UImessenger
G4UIdirectorybaseDir
 
G4String baseDirName
 
G4bool commandsShouldBeInMaster
 
- Static Protected Attributes inherited from G4VVisCommand
static G4VisManagerfpVisManager = 0
 
static G4Colour fCurrentColour = G4Colour::White()
 
static G4double fCurrentLineWidth = 1.
 
static G4Colour fCurrentTextColour = G4Colour::Blue()
 
static G4Text::Layout fCurrentTextLayout = G4Text::left
 
static G4double fCurrentTextSize = 12.
 
static G4ModelingParameters::PVNameCopyNoPath fCurrentTouchablePath
 

Detailed Description

Definition at line 50 of file G4VisCommandsSceneHandler.hh.

Constructor & Destructor Documentation

◆ G4VisCommandSceneHandlerCreate()

G4VisCommandSceneHandlerCreate::G4VisCommandSceneHandlerCreate ( )

Definition at line 138 of file G4VisCommandsSceneHandler.cc.

138  : fId (0) {
139  G4bool omitable;
140  fpCommand = new G4UIcommand ("/vis/sceneHandler/create", this);
141  fpCommand -> SetGuidance
142  ("Creates an scene handler for a specific graphics system.");
143  fpCommand -> SetGuidance
144  ("Attaches current scene, if any. (You can change attached scenes with"
145  "\n\"/vis/sceneHandler/attach\".) Invents a scene handler name if not"
146  "\nsupplied. This scene handler becomes current.");
147  G4UIparameter* parameter;
148  parameter = new G4UIparameter ("graphics-system-name",
149  's', omitable = false);
150  const G4GraphicsSystemList& gslist =
151  fpVisManager -> GetAvailableGraphicsSystems ();
152  G4String candidates;
153  for (auto&& gs: gslist) {
154  const G4String& name = gs -> GetName ();
155  candidates += name + ' ';
156  for (auto&& nickname: gs -> GetNicknames ())
157  candidates += nickname + ' ';
158  }
159  candidates = candidates.strip ();
160  parameter -> SetParameterCandidates(candidates);
161  fpCommand -> SetParameter (parameter);
162  parameter = new G4UIparameter
163  ("scene-handler-name", 's', omitable = true);
164  parameter -> SetCurrentAsDefault (true);
165  fpCommand -> SetParameter (parameter);
166 }
G4String strip(G4int strip_Type=trailing, char c=' ')
G4String name
Definition: TRTMaterials.hh:40
bool G4bool
Definition: G4Types.hh:79
static G4VisManager * fpVisManager
Here is the call graph for this function:

◆ ~G4VisCommandSceneHandlerCreate()

G4VisCommandSceneHandlerCreate::~G4VisCommandSceneHandlerCreate ( )

Definition at line 168 of file G4VisCommandsSceneHandler.cc.

168  {
169  delete fpCommand;
170 }

Member Function Documentation

◆ GetCurrentValue()

G4String G4VisCommandSceneHandlerCreate::GetCurrentValue ( G4UIcommand command)
virtual

Reimplemented from G4UImessenger.

Definition at line 178 of file G4VisCommandsSceneHandler.cc.

178  {
179 
180  G4String graphicsSystemName;
181  const G4VGraphicsSystem* graphicsSystem =
182  fpVisManager -> GetCurrentGraphicsSystem ();
183  if (graphicsSystem) {
184  graphicsSystemName = graphicsSystem -> GetName ();
185  }
186  else {
187  const G4GraphicsSystemList& gslist =
188  fpVisManager -> GetAvailableGraphicsSystems ();
189  if (gslist.size ()) {
190  graphicsSystemName = gslist [0] -> GetName ();
191  }
192  else {
193  graphicsSystemName = "none";
194  }
195  }
196 
197  return graphicsSystemName + " " + NextName ();
198 }
static G4VisManager * fpVisManager
Here is the call graph for this function:

◆ NextName()

G4String G4VisCommandSceneHandlerCreate::NextName ( )
private

Definition at line 172 of file G4VisCommandsSceneHandler.cc.

172  {
173  std::ostringstream oss;
174  oss << "scene-handler-" << fId;
175  return oss.str();
176 }
Here is the caller graph for this function:

◆ SetNewValue()

void G4VisCommandSceneHandlerCreate::SetNewValue ( G4UIcommand command,
G4String  newValue 
)
virtual

Reimplemented from G4UImessenger.

Definition at line 200 of file G4VisCommandsSceneHandler.cc.

201  {
202 
204 
205  G4String graphicsSystem, newName;
206  std::istringstream is (newValue);
207  is >> graphicsSystem >> newName;
208 
209  const G4GraphicsSystemList& gsl =
210  fpVisManager -> GetAvailableGraphicsSystems ();
211  G4int nSystems = gsl.size ();
212  if (nSystems <= 0) {
213  if (verbosity >= G4VisManager::errors) {
214  G4cerr << "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
215  " no graphics systems available."
216  "\n Did you instantiate any in"
217  " YourVisManager::RegisterGraphicsSystems()?"
218  << G4endl;
219  }
220  return;
221  }
222  G4int iGS; // Selector index.
223  G4bool found = false;
224  for (iGS = 0; iGS < nSystems; iGS++) {
225  auto&& gs = gsl[iGS];
226  if (graphicsSystem.compareTo(gs->GetName(), G4String::ignoreCase) == 0) {
227  found = true;
228  break; // Match found
229  } else {
230  auto&& nicknames = gs->GetNicknames();
231  for (size_t i = 0; i < nicknames.size(); ++i) {
232  auto&& nickname = nicknames[i];
233  if (graphicsSystem.compareTo (nickname, G4String::ignoreCase) == 0) {
234  found = true;
235  break; // Match found
236  }
237  }
238  if (found) {
239  break; // Match found
240  }
241  }
242  }
243  if (!found) {
244  // Invalid command line argument or none.
245  // This shouldn't happen!!!!!!
246  if (verbosity >= G4VisManager::errors) {
247  G4cerr <<
248  "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
249  "\n invalid graphics system \""
250  << graphicsSystem
251  << "\" requested."
252  << G4endl;
253  }
254  return;
255  }
256 
257  // Check UI session compatibility.
258  G4bool fallback = false;
259  while (!gsl[iGS]->IsUISessionCompatible()) {
260  // Not compatible, search for a fallback
261  fallback = false;
262  G4String fallbackNickname = gsl[iGS]->GetNickname() + "_FALLBACK";
263  for (iGS = 0; iGS < nSystems; iGS++) {
264  auto&& nicknames = gsl[iGS]->GetNicknames();
265  for (size_t i = 0; i < nicknames.size(); ++i) {
266  auto&& nickname = nicknames[i];
267  if (fallbackNickname.compareTo (nickname, G4String::ignoreCase) == 0) {
268  fallback = true;
269  break; // Match found
270  }
271  }
272  if (fallback) {
273  break; // Match found
274  }
275  }
276  if (iGS < 0 || iGS >= nSystems) {
277  if (verbosity >= G4VisManager::errors) {
278  G4cerr <<
279  "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
280  " could not find fallback graphics system for \""
281  << graphicsSystem
282  << "\"."
283  << G4endl;
284  }
285  return;
286  }
287  // A fallback system found...but go back and check this too.
288  }
289 
290  // A graphics system has been found
291  G4VGraphicsSystem* pSystem = gsl [iGS];
292 
293  if (fallback && verbosity >= G4VisManager::warnings) {
294  G4cout << "WARNING: G4VisCommandSceneHandlerCreate::SetNewValue:"
295  "\n Using fallback graphics system: "
296  << pSystem -> GetName ()
297  << " ("
298  << pSystem -> GetNickname ()
299  << ')'
300  << G4endl;
301  }
302 
303  // Set current graphics system in preparation for
304  // creating scene handler.
305  fpVisManager -> SetCurrentGraphicsSystem (pSystem);
306  if (verbosity >= G4VisManager::confirmations) {
307  G4cout << "Graphics system set to "
308  << pSystem -> GetName ()
309  << " ("
310  << pSystem -> GetNickname ()
311  << ')'
312  << G4endl;
313  }
314 
315  // Now deal with name of scene handler.
316  G4String nextName = NextName ();
317  if (newName == "") {
318  newName = nextName;
319  }
320  if (newName == nextName) fId++;
321 
322  const G4SceneHandlerList& list = fpVisManager -> GetAvailableSceneHandlers ();
323  size_t iScene;
324  for (iScene = 0; iScene < list.size (); iScene++) {
325  G4VSceneHandler* sceneHandler = list [iScene];
326  if (sceneHandler -> GetName () == newName) {
327  if (verbosity >= G4VisManager::errors) {
328  G4cerr << "ERROR: Scene handler \"" << newName
329  << "\" already exists." << G4endl;
330  }
331  return;
332  }
333  }
334 
335  //Create scene handler.
336  fpVisManager -> CreateSceneHandler (newName);
337  if (fpVisManager -> GetCurrentSceneHandler () -> GetName () != newName) {
338  if (verbosity >= G4VisManager::errors) {
339  G4cerr << "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
340  " Curious name mismatch."
341  "\n Current name \""
342  << fpVisManager -> GetCurrentSceneHandler () -> GetName ()
343  << "\" is not the new name \""
344  << newName
345  << "\".\n Please report to vis coordinator."
346  << G4endl;
347  }
348  return;
349  }
350 
351  if (verbosity >= G4VisManager::confirmations) {
352  G4cout << "New scene handler \"" << newName << "\" created." << G4endl;
353  }
354 
355  // Attach scene.
356  if (fpVisManager -> GetCurrentScene ())
357  G4UImanager::GetUIpointer () -> ApplyCommand ("/vis/sceneHandler/attach");
358 }
G4int compareTo(const char *, caseCompare mode=exact) const
int G4int
Definition: G4Types.hh:78
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
static Verbosity GetVerbosity()
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr
static G4VisManager * fpVisManager
Here is the call graph for this function:

Member Data Documentation

◆ fId

G4int G4VisCommandSceneHandlerCreate::fId
private

Definition at line 60 of file G4VisCommandsSceneHandler.hh.

◆ fpCommand

G4UIcommand* G4VisCommandSceneHandlerCreate::fpCommand
private

Definition at line 59 of file G4VisCommandsSceneHandler.hh.


The documentation for this class was generated from the following files: