00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "G4VisCommandsSceneHandler.hh"
00032
00033 #include "G4VisManager.hh"
00034 #include "G4GraphicsSystemList.hh"
00035 #include "G4VisCommandsScene.hh"
00036 #include "G4UImanager.hh"
00037 #include "G4UIcommand.hh"
00038 #include "G4UIcmdWithAString.hh"
00039 #include "G4ios.hh"
00040 #include <sstream>
00041
00043
00044 G4VisCommandSceneHandlerAttach::G4VisCommandSceneHandlerAttach () {
00045 G4bool omitable, currentAsDefault;
00046 fpCommand = new G4UIcmdWithAString ("/vis/sceneHandler/attach", this);
00047 fpCommand -> SetGuidance ("Attaches scene to current scene handler.");
00048 fpCommand -> SetGuidance
00049 ("If scene-name is omitted, current scene is attached. To see scenes and"
00050 "\nscene handlers, use \"/vis/scene/list\" and \"/vis/sceneHandler/list\"");
00051 fpCommand -> SetParameterName ("scene-name",
00052 omitable = true,
00053 currentAsDefault = true);
00054 }
00055
00056 G4VisCommandSceneHandlerAttach::~G4VisCommandSceneHandlerAttach () {
00057 delete fpCommand;
00058 }
00059
00060 G4String G4VisCommandSceneHandlerAttach::GetCurrentValue (G4UIcommand*) {
00061 G4Scene* pScene = fpVisManager -> GetCurrentScene ();
00062 return pScene ? pScene -> GetName () : G4String("");
00063 }
00064
00065 void G4VisCommandSceneHandlerAttach::SetNewValue (G4UIcommand*,
00066 G4String newValue) {
00067
00068 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00069
00070 G4String& sceneName = newValue;
00071
00072 if (sceneName.length () == 0) {
00073 if (verbosity >= G4VisManager::warnings) {
00074 G4cout <<
00075 "WARNING: No scene specified. Maybe there are no scenes available"
00076 "\n yet. Please create one." << G4endl;
00077 }
00078 return;
00079 }
00080
00081 G4VSceneHandler* pSceneHandler = fpVisManager -> GetCurrentSceneHandler ();
00082 if (!pSceneHandler) {
00083 if (verbosity >= G4VisManager::errors) {
00084 G4cout <<
00085 "ERROR: Current scene handler not defined. Please select or create one."
00086 << G4endl;
00087 }
00088 return;
00089 }
00090
00091 G4SceneList& sceneList = fpVisManager -> SetSceneList ();
00092
00093 if (sceneList.empty ()) {
00094 if (verbosity >= G4VisManager::errors) {
00095 G4cout <<
00096 "ERROR: No valid scenes available yet. Please create one."
00097 << G4endl;
00098 }
00099 return;
00100 }
00101
00102 G4int iScene, nScenes = sceneList.size ();
00103 for (iScene = 0; iScene < nScenes; iScene++) {
00104 if (sceneList [iScene] -> GetName () == sceneName) break;
00105 }
00106 if (iScene < nScenes) {
00107 G4Scene* pScene = sceneList [iScene];
00108 pSceneHandler -> SetScene (pScene);
00109
00110 fpVisManager -> SetCurrentScene (pScene);
00111
00112 G4VViewer* pViewer = pSceneHandler -> GetCurrentViewer();
00113 if (pViewer && pViewer -> GetViewParameters().IsAutoRefresh()) {
00114 pViewer -> SetView ();
00115 pViewer -> ClearView ();
00116 pViewer -> DrawView ();
00117 }
00118 if (verbosity >= G4VisManager::confirmations) {
00119 G4cout << "Scene \"" << sceneName
00120 << "\" attached to scene handler \""
00121 << pSceneHandler -> GetName () <<
00122 ".\n (You may have to refresh with \"/vis/viewer/flush\" if view"
00123 " is not \"auto-refresh\".)"
00124 << G4endl;
00125 }
00126 }
00127 else {
00128 if (verbosity >= G4VisManager::errors) {
00129 G4cout << "ERROR: Scene \"" << sceneName
00130 << "\" not found. Use \"/vis/scene/list\" to see possibilities."
00131 << G4endl;
00132 }
00133 }
00134 }
00135
00137
00138 G4VisCommandSceneHandlerCreate::G4VisCommandSceneHandlerCreate (): fId (0) {
00139 G4bool omitable;
00140 fpCommand = new G4UIcommand ("/vis/sceneHandler/create", this);
00141 fpCommand -> SetGuidance
00142 ("Creates an scene handler for a specific graphics system.");
00143 fpCommand -> SetGuidance
00144 ("Attaches current scene, if any. (You can change attached scenes with"
00145 "\n\"/vis/sceneHandler/attach\".) Invents a scene handler name if not"
00146 "\nsupplied. This scene handler becomes current.");
00147 G4UIparameter* parameter;
00148 parameter = new G4UIparameter ("graphics-system-name",
00149 's', omitable = false);
00150 const G4GraphicsSystemList& gslist =
00151 fpVisManager -> GetAvailableGraphicsSystems ();
00152 G4String candidates;
00153 for (size_t igslist = 0; igslist < gslist.size (); igslist++) {
00154 const G4String& name = gslist [igslist] -> GetName ();
00155 const G4String& nickname = gslist [igslist] -> GetNickname ();
00156 if (nickname.isNull ()) {
00157 candidates += name;
00158 }
00159 else {
00160 candidates += nickname;
00161 }
00162 candidates += " ";
00163 }
00164 candidates = candidates.strip ();
00165 parameter -> SetParameterCandidates(candidates);
00166 fpCommand -> SetParameter (parameter);
00167 parameter = new G4UIparameter
00168 ("scene-handler-name", 's', omitable = true);
00169 parameter -> SetCurrentAsDefault (true);
00170 fpCommand -> SetParameter (parameter);
00171 }
00172
00173 G4VisCommandSceneHandlerCreate::~G4VisCommandSceneHandlerCreate () {
00174 delete fpCommand;
00175 }
00176
00177 G4String G4VisCommandSceneHandlerCreate::NextName () {
00178 std::ostringstream oss;
00179 oss << "scene-handler-" << fId;
00180 return oss.str();
00181 }
00182
00183 G4String G4VisCommandSceneHandlerCreate::GetCurrentValue(G4UIcommand*) {
00184
00185 G4String graphicsSystemName;
00186 const G4VGraphicsSystem* graphicsSystem =
00187 fpVisManager -> GetCurrentGraphicsSystem ();
00188 if (graphicsSystem) {
00189 graphicsSystemName = graphicsSystem -> GetName ();
00190 }
00191 else {
00192 const G4GraphicsSystemList& gslist =
00193 fpVisManager -> GetAvailableGraphicsSystems ();
00194 if (gslist.size ()) {
00195 graphicsSystemName = gslist [0] -> GetName ();
00196 }
00197 else {
00198 graphicsSystemName = "none";
00199 }
00200 }
00201
00202 return graphicsSystemName + " " + NextName ();
00203 }
00204
00205 void G4VisCommandSceneHandlerCreate::SetNewValue (G4UIcommand*,
00206 G4String newValue) {
00207
00208 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00209
00210 G4String graphicsSystem, newName;
00211 std::istringstream is (newValue);
00212 is >> graphicsSystem >> newName;
00213
00214 const G4GraphicsSystemList& gsl =
00215 fpVisManager -> GetAvailableGraphicsSystems ();
00216 int nSystems = gsl.size ();
00217 if (nSystems <= 0) {
00218 if (verbosity >= G4VisManager::errors) {
00219 G4cout << "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
00220 " no graphics systems available."
00221 "\n Did you instantiate any in"
00222 " YourVisManager::RegisterGraphicsSystems()?"
00223 << G4endl;
00224 }
00225 return;
00226 }
00227 int iGS;
00228 for (iGS = 0; iGS < nSystems; iGS++) {
00229 if (graphicsSystem.compareTo (gsl [iGS] -> GetName (),
00230 G4String::ignoreCase) == 0 ||
00231 graphicsSystem.compareTo (gsl [iGS] -> GetNickname (),
00232 G4String::ignoreCase) == 0) {
00233 break;
00234 }
00235 }
00236 if (iGS < 0 || iGS >= nSystems) {
00237
00238
00239 if (verbosity >= G4VisManager::errors) {
00240 G4cout << "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
00241 " invalid graphics system specified."
00242 << G4endl;
00243 }
00244 return;
00245 }
00246
00247
00248 if (!gsl[iGS]->IsUISessionCompatible()) {
00249 G4String fallbackNickname = gsl[iGS]->GetNickname() + "_FALLBACK";
00250 for (iGS = 0; iGS < nSystems; iGS++) {
00251 if (fallbackNickname.compareTo (gsl [iGS] -> GetNickname (),
00252 G4String::ignoreCase) == 0) {
00253 break;
00254 }
00255 }
00256 if (iGS < 0 || iGS >= nSystems) {
00257 if (verbosity >= G4VisManager::errors) {
00258 G4cout << "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
00259 " could not find fallback graphics system."
00260 << G4endl;
00261 }
00262 return;
00263 }
00264 if (verbosity >= G4VisManager::warnings) {
00265 G4cout << "WARNING: G4VisCommandSceneHandlerCreate::SetNewValue:"
00266 " using fallback graphics system."
00267 << G4endl;
00268 }
00269 }
00270
00271
00272
00273 G4VGraphicsSystem* pSystem = gsl [iGS];
00274 fpVisManager -> SetCurrentGraphicsSystem (pSystem);
00275 if (verbosity >= G4VisManager::confirmations) {
00276 G4cout << "Graphics system set to " << pSystem -> GetName () << G4endl;
00277 }
00278
00279
00280 G4String nextName = NextName ();
00281 if (newName == "") {
00282 newName = nextName;
00283 }
00284 if (newName == nextName) fId++;
00285
00286 const G4SceneHandlerList& list = fpVisManager -> GetAvailableSceneHandlers ();
00287 size_t iScene;
00288 for (iScene = 0; iScene < list.size (); iScene++) {
00289 G4VSceneHandler* sceneHandler = list [iScene];
00290 if (sceneHandler -> GetName () == newName) {
00291 if (verbosity >= G4VisManager::errors) {
00292 G4cout << "ERROR: Scene handler \"" << newName
00293 << "\" already exists." << G4endl;
00294 }
00295 return;
00296 }
00297 }
00298
00299
00300 fpVisManager -> CreateSceneHandler (newName);
00301 if (fpVisManager -> GetCurrentSceneHandler () -> GetName () != newName) {
00302 if (verbosity >= G4VisManager::errors) {
00303 G4cout << "ERROR: G4VisCommandSceneHandlerCreate::SetNewValue:"
00304 " Curious name mismatch."
00305 "\n Current name \""
00306 << fpVisManager -> GetCurrentSceneHandler () -> GetName ()
00307 << "\" is not the new name \""
00308 << newName
00309 << "\".\n Please report to vis coordinator."
00310 << G4endl;
00311 }
00312 return;
00313 }
00314
00315 if (verbosity >= G4VisManager::confirmations) {
00316 G4cout << "New scene handler \"" << newName << "\" created." << G4endl;
00317 }
00318
00319
00320 if (fpVisManager -> GetCurrentScene ())
00321 G4UImanager::GetUIpointer () -> ApplyCommand ("/vis/sceneHandler/attach");
00322 }
00323
00325
00326 G4VisCommandSceneHandlerList::G4VisCommandSceneHandlerList () {
00327 G4bool omitable;
00328 fpCommand = new G4UIcommand ("/vis/sceneHandler/list", this);
00329 fpCommand -> SetGuidance ("Lists scene handler(s).");
00330 fpCommand -> SetGuidance
00331 ("\"help /vis/verbose\" for definition of verbosity.");
00332 G4UIparameter* parameter;
00333 parameter = new G4UIparameter("scene-handler-name", 's', omitable = true);
00334 parameter -> SetDefaultValue ("all");
00335 fpCommand -> SetParameter (parameter);
00336 parameter = new G4UIparameter ("verbosity", 's', omitable = true);
00337 parameter -> SetDefaultValue ("warnings");
00338 fpCommand -> SetParameter (parameter);
00339 }
00340
00341 G4VisCommandSceneHandlerList::~G4VisCommandSceneHandlerList () {
00342 delete fpCommand;
00343 }
00344
00345 G4String G4VisCommandSceneHandlerList::GetCurrentValue (G4UIcommand*) {
00346 return "";
00347 }
00348
00349 void G4VisCommandSceneHandlerList::SetNewValue (G4UIcommand*,
00350 G4String newValue) {
00351 G4String name, verbosityString;
00352 std::istringstream is (newValue);
00353 is >> name >> verbosityString;
00354 G4VisManager::Verbosity verbosity =
00355 fpVisManager->GetVerbosityValue(verbosityString);
00356 const G4VSceneHandler* currentSceneHandler =
00357 fpVisManager -> GetCurrentSceneHandler ();
00358 G4String currentName;
00359 if (currentSceneHandler) currentName = currentSceneHandler->GetName();
00360
00361 const G4SceneHandlerList& list = fpVisManager -> GetAvailableSceneHandlers ();
00362 G4bool found = false;
00363 for (size_t iSH = 0; iSH < list.size (); iSH++) {
00364 const G4String& iName = list [iSH] -> GetName ();
00365 if (name != "all") {
00366 if (name != iName) continue;
00367 }
00368 found = true;
00369 if (iName == currentName) {
00370 G4cout << " (current)";
00371 }
00372 else {
00373 G4cout << " ";
00374 }
00375 G4cout << " scene handler \"" << list [iSH] -> GetName () << "\""
00376 << " (" << list [iSH] -> GetGraphicsSystem () -> GetName () << ")";
00377 if (verbosity >= G4VisManager::parameters) {
00378 G4cout << "\n " << *(list [iSH]);
00379 }
00380 G4cout << G4endl;
00381 }
00382 if (!found) {
00383 G4cout << "No scene handlers found";
00384 if (name != "all") {
00385 G4cout << " of name \"" << name << "\"";
00386 }
00387 G4cout << "." << G4endl;
00388 }
00389 }
00390
00392
00393 G4VisCommandSceneHandlerSelect::G4VisCommandSceneHandlerSelect () {
00394 G4bool omitable;
00395 fpCommand = new G4UIcmdWithAString ("/vis/sceneHandler/select", this);
00396 fpCommand -> SetGuidance ("Selects a scene handler.");
00397 fpCommand -> SetGuidance
00398 ("Makes the scene handler current. \"/vis/sceneHandler/list\" to see"
00399 "\n possible scene handler names.");
00400 fpCommand -> SetParameterName ("scene-handler-name",
00401 omitable = false);
00402 }
00403
00404 G4VisCommandSceneHandlerSelect::~G4VisCommandSceneHandlerSelect () {
00405 delete fpCommand;
00406 }
00407
00408 G4String G4VisCommandSceneHandlerSelect::GetCurrentValue (G4UIcommand*) {
00409 return "";
00410 }
00411
00412 void G4VisCommandSceneHandlerSelect::SetNewValue (G4UIcommand*,
00413 G4String newValue) {
00414
00415 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00416
00417 G4String& selectName = newValue;
00418 const G4SceneHandlerList& list = fpVisManager -> GetAvailableSceneHandlers ();
00419
00420 size_t iSH;
00421 for (iSH = 0; iSH < list.size (); iSH++) {
00422 if (list [iSH] -> GetName () == selectName) break;
00423 }
00424 if (iSH < list.size ()) {
00425 if (fpVisManager -> GetCurrentSceneHandler () -> GetName ()
00426 == selectName) {
00427 if (verbosity >= G4VisManager::confirmations) {
00428 G4cout << "Scene handler \"" << selectName << "\""
00429 << " already selected." << G4endl;
00430 }
00431 }
00432 else {
00433 if (verbosity >= G4VisManager::confirmations) {
00434 G4cout << "Scene handler \"" << selectName << "\""
00435 << " being selected." << G4endl;
00436 }
00437 fpVisManager -> SetCurrentSceneHandler (list [iSH]);
00438 }
00439 }
00440 else {
00441 if (verbosity >= G4VisManager::errors) {
00442 G4cout << "ERROR: Scene handler \"" << selectName << "\""
00443 << " not found - \"/vis/sceneHandler/list\""
00444 "\n to see possibilities."
00445 << G4endl;
00446 }
00447 }
00448 }