Geant4 11.2.2
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 ()=default
 
 G4UImessenger (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
 
virtual ~G4UImessenger ()
 
G4bool CommandsShouldBeInMaster () const
 

Additional Inherited Members

- Static Public Member Functions inherited from G4VVisCommand
static G4VisManagerGetVisManager ()
 
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="")
 
void Twinkle (G4VViewer *currentViewer, const G4ViewParameters &baseVP, const std::vector< std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > > &paths)
 
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 CopyCameraParameters (G4ViewParameters &target, const G4ViewParameters &from)
 
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 LtoS (G4long l)
 
G4String DtoS (G4double a)
 
G4String BtoS (G4bool b)
 
G4int StoI (const G4String &s)
 
G4long StoL (const G4String &s)
 
G4double StoD (const 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 = nullptr
 
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
 
static G4bool fThereWasAViewer = false
 
static G4ViewParameters fExistingVP
 
static G4SceneTreeItem fExistingSceneTree
 

Detailed Description

Definition at line 49 of file G4VisCommandsSceneHandler.hh.

Constructor & Destructor Documentation

◆ G4VisCommandSceneHandlerCreate()

G4VisCommandSceneHandlerCreate::G4VisCommandSceneHandlerCreate ( )

Definition at line 139 of file G4VisCommandsSceneHandler.cc.

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

◆ ~G4VisCommandSceneHandlerCreate()

G4VisCommandSceneHandlerCreate::~G4VisCommandSceneHandlerCreate ( )

Definition at line 171 of file G4VisCommandsSceneHandler.cc.

171 {
172 delete fpCommand;
173}

Member Function Documentation

◆ GetCurrentValue()

G4String G4VisCommandSceneHandlerCreate::GetCurrentValue ( G4UIcommand * command)
virtual

Reimplemented from G4UImessenger.

Definition at line 181 of file G4VisCommandsSceneHandler.cc.

181 {
182
183 G4String graphicsSystemName;
184 const G4VGraphicsSystem* graphicsSystem =
185 fpVisManager -> GetCurrentGraphicsSystem ();
186 if (graphicsSystem) {
187 graphicsSystemName = graphicsSystem -> GetName ();
188 }
189 else {
190 graphicsSystemName = fpVisManager->GetDefaultGraphicsSystemName();
191 }
192
193 return graphicsSystemName + " " + NextName ();
194}
const G4String & GetDefaultGraphicsSystemName() const

◆ SetNewValue()

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

Reimplemented from G4UImessenger.

Definition at line 196 of file G4VisCommandsSceneHandler.cc.

197 {
198
200
201 G4String graphicsSystem, newName;
202 std::istringstream is (newValue);
203 is >> graphicsSystem >> newName;
204
205 const G4GraphicsSystemList& gsl =
206 fpVisManager -> GetAvailableGraphicsSystems ();
207 std::size_t nSystems = gsl.size ();
208 if (nSystems <= 0) {
210 ed <<
211 "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
212 " no graphics systems available."
213 "\n Did you instantiate any in"
214 " YourVisManager::RegisterGraphicsSystems()?";
215 command->CommandFailed(JustWarning,ed);
216 return;
217 }
218 std::size_t iGS; // Selector index.
219 G4bool found = false;
220 for (iGS = 0; iGS < nSystems; ++iGS) {
221 const auto& gs = gsl[iGS];
222 if (G4StrUtil::icompare(graphicsSystem, gs->GetName()) == 0) {
223 found = true;
224 break; // Match found
225 } else {
226 const auto& nicknames = gs->GetNicknames();
227 for (std::size_t i = 0; i < nicknames.size(); ++i) {
228 const auto& nickname = nicknames[i];
229 if (G4StrUtil::icompare(graphicsSystem, nickname) == 0) {
230 found = true;
231 break; // Match found
232 }
233 }
234 if (found) {
235 break; // Match found
236 }
237 }
238 }
239 if (!found) {
240 // Shouldn't happen, since graphicsSystem should be a candidate
242 ed <<
243 "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
244 "\n Invalid graphics system \""
245 << graphicsSystem
246 << "\" requested."
247 << "\n Candidates are:";
249 command->CommandFailed(JustWarning,ed);
250 return;
251 }
252
253 // Check UI session compatibility.
254 G4bool fallback = false;
255 G4int loopCounter = 0;
256 while (!gsl[iGS]->IsUISessionCompatible()) {
257 std::size_t iGSBeingTested = iGS;
258 // Not compatible, search for a fallback
259 fallback = false;
260 G4String fallbackNickname = gsl[iGS]->GetNickname() + "_FALLBACK";
261 for (iGS = 0; iGS < nSystems; iGS++) {
262 const auto& nicknames = gsl[iGS]->GetNicknames();
263 for (std::size_t i = 0; i < nicknames.size(); ++i) {
264 const auto& nickname = nicknames[i];
265 if (G4StrUtil::icompare(fallbackNickname, nickname) == 0) {
266 fallback = true;
267 break; // Match found
268 }
269 }
270 if (fallback) {
271 break; // Match found
272 }
273 }
274 if (iGS >= nSystems || loopCounter >=3) {
276 ed << "\"" << gsl[iGSBeingTested]->GetNickname()
277 << "\" is not compatible with your chosen session,"
278 " and no fallback system found.";
279 command->CommandFailed(JustWarning,ed);
280 return;
281 }
282 // A fallback system found...but go back and check this too.
283 ++loopCounter;
284 }
285
286 // A graphics system has been found
287 G4VGraphicsSystem* pSystem = gsl [iGS];
288
289 if (fallback && verbosity >= G4VisManager::warnings) {
290 G4warn << "WARNING: G4VisCommandSceneHandlerCreate::SetNewValue:"
291 "\n Using fallback graphics system: "
292 << pSystem -> GetName ()
293 << " ("
294 << pSystem -> GetNickname ()
295 << ')'
296 << G4endl;
297 }
298
299 // Now deal with name of scene handler.
300 G4String nextName = NextName ();
301 if (newName == "") {
302 newName = nextName;
303 }
304 if (newName == nextName) fId++;
305
306 const G4SceneHandlerList& list = fpVisManager -> GetAvailableSceneHandlers ();
307 std::size_t iScene;
308 for (iScene = 0; iScene < list.size (); ++iScene) {
309 G4VSceneHandler* sceneHandler = list [iScene];
310 if (sceneHandler -> GetName () == newName) {
312 ed <<
313 "ERROR: Scene handler \"" << newName
314 << "\" already exists.";
315 command->CommandFailed(JustWarning,ed);
316 return;
317 }
318 }
319
320 // If there is an existing viewer, store its view parameters and scene tree
322 fThereWasAViewer = true;
323 auto viewer = fpVisManager->GetCurrentViewer();
324 fExistingVP = viewer->GetViewParameters();
325 fExistingSceneTree = viewer->AccessSceneTree();
326 }
327
328 // Set current graphics system in preparation for
329 // creating scene handler.
330 fpVisManager -> SetCurrentGraphicsSystem (pSystem);
331 if (verbosity >= G4VisManager::confirmations) {
332 G4cout << "Graphics system set to "
333 << pSystem -> GetName ()
334 << " ("
335 << pSystem -> GetNickname ()
336 << ')'
337 << G4endl;
338 }
339
340 //Create scene handler.
341 fpVisManager -> CreateSceneHandler (newName);
342 if (fpVisManager -> GetCurrentSceneHandler () -> GetName () != newName) {
344 ed <<
345 "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
346 " Curious name mismatch."
347 "\n Current name \""
348 << fpVisManager -> GetCurrentSceneHandler () -> GetName ()
349 << "\" is not the new name \""
350 << newName
351 << "\".\n Please report to vis coordinator.";
352 command->CommandFailed(JustWarning,ed);
353 return;
354 }
355
356 if (verbosity >= G4VisManager::confirmations)
357 G4cout << "New scene handler \"" << newName << "\" created." << G4endl;
358
359 if (fpVisManager -> GetCurrentScene ()) {
360 auto errorCode = G4UImanager::GetUIpointer () -> ApplyCommand ("/vis/sceneHandler/attach");
361 if (errorCode) {
363 ed << "sub-command \"/vis/sceneHandler/attach\" failed.";
364 command->CommandFailed(errorCode,ed);
365 return;
366 }
367 }
368}
@ JustWarning
std::ostringstream G4ExceptionDescription
#define G4warn
Definition G4Scene.cc:41
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
void CommandFailed(G4int errCode, G4ExceptionDescription &ed)
static G4UImanager * GetUIpointer()
static G4ViewParameters fExistingVP
static G4SceneTreeItem fExistingSceneTree
static G4bool fThereWasAViewer
void PrintAvailableGraphicsSystems(Verbosity, std::ostream &=G4cout) const
G4VViewer * GetCurrentViewer() const
static Verbosity GetVerbosity()

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