Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VisCommandSceneHandlerCreate Class Reference

#include <G4VisCommandsSceneHandler.hh>

+ Inheritance 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 ()
 
virtual G4String GetCurrentValue (G4UIcommand *command)
 
virtual void SetNewValue (G4UIcommand *command, G4String newValue)
 
G4bool operator== (const G4UImessenger &messenger) const
 
G4bool operator!= (const G4UImessenger &messenger) const
 
G4bool CommandsShouldBeInMaster () const
 

Additional Inherited Members

- Static Public Member Functions inherited from G4VVisCommand
static void SetVisManager (G4VisManager *pVisManager)
 
static const G4ColourGetCurrentTextColour ()
 
- Protected Member Functions inherited from G4VVisCommand
void SetViewParameters (G4VViewer *viewer, const G4ViewParameters &viewParams)
 
void RefreshIfRequired (G4VViewer *viewer)
 
void InterpolateViews (G4VViewer *currentViewer, std::vector< G4ViewParameters > viewVector, const G4int nInterpolationPoints=50, const G4int waitTimePerPointmilliseconds=20, const G4String exportString="")
 
void InterpolateToNewView (G4VViewer *currentViewer, const G4ViewParameters &oldVP, const G4ViewParameters &newVP, const G4int nInterpolationPoints=50, const G4int waitTimePerPointmilliseconds=20, const G4String exportString="")
 
const G4StringConvertToColourGuidance ()
 
void ConvertToColour (G4Colour &colour, const G4String &redOrString, G4double green, G4double blue, G4double opacity)
 
G4bool ProvideValueOfUnit (const G4String &where, const G4String &unit, const G4String &category, G4double &value)
 
void CheckSceneAndNotifyHandlers (G4Scene *=nullptr)
 
G4bool CheckView ()
 
void G4VisCommandsSceneAddUnsuccessful (G4VisManager::Verbosity verbosity)
 
void CopyGuidanceFrom (const G4UIcommand *fromCmd, G4UIcommand *toCmd, G4int startLine=0)
 
void CopyParametersFrom (const G4UIcommand *fromCmd, G4UIcommand *toCmd)
 
void DrawExtent (const G4VisExtent &)
 
- Protected Member Functions inherited from G4UImessenger
G4String ItoS (G4int i)
 
G4String DtoS (G4double a)
 
G4String BtoS (G4bool b)
 
G4int StoI (G4String s)
 
G4long StoL (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 G4bool ConvertToDoublePair (const G4String &paramString, G4double &xval, G4double &yval)
 
- Protected Attributes inherited from G4UImessenger
G4UIdirectorybaseDir = nullptr
 
G4String baseDirName = ""
 
G4bool commandsShouldBeInMaster = false
 
- Static Protected Attributes inherited from G4VVisCommand
static G4VisManagerfpVisManager = 0
 
static G4int fCurrentArrow3DLineSegmentsPerCircle = 6
 
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 G4PhysicalVolumeModel::TouchableProperties fCurrentTouchableProperties
 
static G4VisExtent fCurrentExtentForField
 
static std::vector< G4PhysicalVolumesSearchScene::FindingsfCurrrentPVFindingsForField
 

Detailed Description

Definition at line 49 of file G4VisCommandsSceneHandler.hh.

Constructor & Destructor Documentation

◆ G4VisCommandSceneHandlerCreate()

G4VisCommandSceneHandlerCreate::G4VisCommandSceneHandlerCreate ( )

Definition at line 137 of file G4VisCommandsSceneHandler.cc.

137 : fId (0) {
138 G4bool omitable;
139 fpCommand = new G4UIcommand ("/vis/sceneHandler/create", this);
140 fpCommand -> SetGuidance
141 ("Creates an scene handler for a specific graphics system.");
142 fpCommand -> SetGuidance
143 ("Attaches current scene, if any. (You can change attached scenes with"
144 "\n\"/vis/sceneHandler/attach\".) Invents a scene handler name if not"
145 "\nsupplied. This scene handler becomes current.");
146 G4UIparameter* parameter;
147 parameter = new G4UIparameter ("graphics-system-name",
148 's', omitable = false);
149 const G4GraphicsSystemList& gslist =
150 fpVisManager -> GetAvailableGraphicsSystems ();
151 G4String candidates;
152 for (const auto gs: gslist) {
153 const G4String& name = gs -> GetName ();
154 candidates += name + ' ';
155 for (const auto& nickname: gs -> GetNicknames ()) {
156 if (nickname != name) candidates += nickname + ' ';
157 }
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}
bool G4bool
Definition: G4Types.hh:86
G4String strip(G4int strip_Type=trailing, char c=' ')
static G4VisManager * fpVisManager
const char * name(G4int ptype)

◆ ~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}

◆ 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 const auto& gs = gsl[iGS];
226 if (graphicsSystem.compareTo(gs->GetName(), G4String::ignoreCase) == 0) {
227 found = true;
228 break; // Match found
229 } else {
230 const auto& nicknames = gs->GetNicknames();
231 for (size_t i = 0; i < nicknames.size(); ++i) {
232 const 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 G4int loopCounter = 0;
260 while (!gsl[iGS]->IsUISessionCompatible()) {
261 G4int iGSBeingTested = iGS;
262 // Not compatible, search for a fallback
263 fallback = false;
264 G4String fallbackNickname = gsl[iGS]->GetNickname() + "_FALLBACK";
265 for (iGS = 0; iGS < nSystems; iGS++) {
266 const auto& nicknames = gsl[iGS]->GetNicknames();
267 for (size_t i = 0; i < nicknames.size(); ++i) {
268 const auto& nickname = nicknames[i];
269 if (fallbackNickname.compareTo (nickname, G4String::ignoreCase) == 0) {
270 fallback = true;
271 break; // Match found
272 }
273 }
274 if (fallback) {
275 break; // Match found
276 }
277 }
278 if (iGS < 0 || iGS >= nSystems || loopCounter >=3) {
279 std::ostringstream oss;
280 oss << "\"" << gsl[iGSBeingTested]->GetNickname()
281 << "\" is not compatible with your chosen session,"
282 " and no fallback system found.";
283 if (verbosity >= G4VisManager::errors) {
284 G4cerr << "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue: "
285 << oss.str() << G4endl;
286 }
287 command->CommandFailed(oss);
288 return;
289 }
290 // A fallback system found...but go back and check this too.
291 ++loopCounter;
292 }
293
294 // A graphics system has been found
295 G4VGraphicsSystem* pSystem = gsl [iGS];
296
297 if (fallback && verbosity >= G4VisManager::warnings) {
298 G4cout << "WARNING: G4VisCommandSceneHandlerCreate::SetNewValue:"
299 "\n Using fallback graphics system: "
300 << pSystem -> GetName ()
301 << " ("
302 << pSystem -> GetNickname ()
303 << ')'
304 << G4endl;
305 }
306
307 // Set current graphics system in preparation for
308 // creating scene handler.
309 fpVisManager -> SetCurrentGraphicsSystem (pSystem);
310 if (verbosity >= G4VisManager::confirmations) {
311 G4cout << "Graphics system set to "
312 << pSystem -> GetName ()
313 << " ("
314 << pSystem -> GetNickname ()
315 << ')'
316 << G4endl;
317 }
318
319 // Now deal with name of scene handler.
320 G4String nextName = NextName ();
321 if (newName == "") {
322 newName = nextName;
323 }
324 if (newName == nextName) fId++;
325
326 const G4SceneHandlerList& list = fpVisManager -> GetAvailableSceneHandlers ();
327 size_t iScene;
328 for (iScene = 0; iScene < list.size (); iScene++) {
329 G4VSceneHandler* sceneHandler = list [iScene];
330 if (sceneHandler -> GetName () == newName) {
331 if (verbosity >= G4VisManager::errors) {
332 G4cerr << "ERROR: Scene handler \"" << newName
333 << "\" already exists." << G4endl;
334 }
335 return;
336 }
337 }
338
339 //Create scene handler.
340 fpVisManager -> CreateSceneHandler (newName);
341 if (fpVisManager -> GetCurrentSceneHandler () -> GetName () != newName) {
342 if (verbosity >= G4VisManager::errors) {
343 G4cerr << "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
344 " Curious name mismatch."
345 "\n Current name \""
346 << fpVisManager -> GetCurrentSceneHandler () -> GetName ()
347 << "\" is not the new name \""
348 << newName
349 << "\".\n Please report to vis coordinator."
350 << G4endl;
351 }
352 return;
353 }
354
355 if (verbosity >= G4VisManager::confirmations) {
356 G4cout << "New scene handler \"" << newName << "\" created." << G4endl;
357 }
358
359 // Attach scene.
360 if (fpVisManager -> GetCurrentScene ())
361 G4UImanager::GetUIpointer () -> ApplyCommand ("/vis/sceneHandler/attach");
362}
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
@ ignoreCase
Definition: G4String.hh:60
G4int compareTo(const char *, caseCompare mode=exact) const
void CommandFailed(G4int errCode, G4ExceptionDescription &ed)
Definition: G4UIcommand.hh:179
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
static Verbosity GetVerbosity()

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