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 "G4VisCommandsCompound.hh"
00032
00033 #include "G4VisManager.hh"
00034 #include "G4UImanager.hh"
00035 #include "G4UIcmdWithAString.hh"
00036
00037 #include <sstream>
00038
00040
00041 G4VisCommandDrawTree::G4VisCommandDrawTree() {
00042 G4bool omitable;
00043 fpCommand = new G4UIcommand("/vis/drawTree", this);
00044 fpCommand->SetGuidance
00045 ("(DTREE) Creates a scene consisting of this physical volume and"
00046 "\n produces a representation of the geometry hieracrhy.");
00047 fpCommand->SetGuidance("The scene becomes current.");
00048 G4UIparameter* parameter;
00049 parameter = new G4UIparameter("physical-volume-name", 's', omitable = true);
00050 parameter -> SetDefaultValue("world");
00051 fpCommand -> SetParameter (parameter);
00052 parameter = new G4UIparameter("system", 's', omitable = true);
00053 parameter -> SetDefaultValue("ATree");
00054 fpCommand -> SetParameter (parameter);
00055 }
00056
00057 G4VisCommandDrawTree::~G4VisCommandDrawTree() {
00058 delete fpCommand;
00059 }
00060
00061 void G4VisCommandDrawTree::SetNewValue(G4UIcommand*, G4String newValue) {
00062
00063 G4String pvname, system;
00064 std::istringstream is(newValue);
00065 is >> pvname >> system;
00066
00067 G4VGraphicsSystem* keepSystem = fpVisManager->GetCurrentGraphicsSystem();
00068 G4Scene* keepScene = fpVisManager->GetCurrentScene();
00069 G4VSceneHandler* keepSceneHandler = fpVisManager->GetCurrentSceneHandler();
00070 G4VViewer* keepViewer = fpVisManager->GetCurrentViewer();
00071
00072 G4UImanager* UImanager = G4UImanager::GetUIpointer();
00073 G4int keepVerbose = UImanager->GetVerboseLevel();
00074 G4int newVerbose(0);
00075 if (keepVerbose >= 2 ||
00076 fpVisManager->GetVerbosity() >= G4VisManager::confirmations)
00077 newVerbose = 2;
00078 UImanager->SetVerboseLevel(newVerbose);
00079 UImanager->ApplyCommand(G4String("/vis/open " + system));
00080 UImanager->ApplyCommand(G4String("/vis/drawVolume " + pvname));
00081 UImanager->ApplyCommand("/vis/viewer/flush");
00082 UImanager->SetVerboseLevel(keepVerbose);
00083
00084 if (keepViewer) {
00085 if (fpVisManager->GetVerbosity() >= G4VisManager::warnings) {
00086 G4cout << "Reverting to " << keepViewer->GetName() << G4endl;
00087 }
00088 fpVisManager->SetCurrentGraphicsSystem(keepSystem);
00089 fpVisManager->SetCurrentScene(keepScene);
00090 fpVisManager->SetCurrentSceneHandler(keepSceneHandler);
00091 fpVisManager->SetCurrentViewer(keepViewer);
00092 }
00093 }
00094
00096
00097 G4VisCommandDrawView::G4VisCommandDrawView() {
00098 G4bool omitable;
00099 fpCommand = new G4UIcommand("/vis/drawView", this);
00100 fpCommand->SetGuidance
00101 ("Draw view from this angle, etc.");
00102 G4UIparameter* parameter;
00103 parameter = new G4UIparameter("theta-degrees", 'd', omitable = true);
00104 parameter -> SetDefaultValue(0.);
00105 fpCommand -> SetParameter (parameter);
00106 parameter = new G4UIparameter("phi-degrees", 'd', omitable = true);
00107 parameter -> SetDefaultValue(0.);
00108 fpCommand -> SetParameter (parameter);
00109 parameter = new G4UIparameter("pan-right", 'd', omitable = true);
00110 parameter -> SetDefaultValue(0.);
00111 fpCommand -> SetParameter (parameter);
00112 parameter = new G4UIparameter("pan-up", 'd', omitable = true);
00113 parameter -> SetDefaultValue(0.);
00114 fpCommand -> SetParameter (parameter);
00115 parameter = new G4UIparameter("pan-unit", 's', omitable = true);
00116 parameter -> SetDefaultValue("cm");
00117 fpCommand -> SetParameter (parameter);
00118 parameter = new G4UIparameter("zoom-factor", 'd', omitable = true);
00119 parameter -> SetDefaultValue(1.);
00120 fpCommand -> SetParameter (parameter);
00121 parameter = new G4UIparameter("dolly", 'd', omitable = true);
00122 parameter -> SetDefaultValue(0.);
00123 fpCommand -> SetParameter (parameter);
00124 parameter = new G4UIparameter("dolly-unit", 's', omitable = true);
00125 parameter -> SetDefaultValue("cm");
00126 fpCommand -> SetParameter (parameter);
00127 }
00128
00129 G4VisCommandDrawView::~G4VisCommandDrawView() {
00130 delete fpCommand;
00131 }
00132
00133 void G4VisCommandDrawView::SetNewValue(G4UIcommand*, G4String newValue) {
00134
00135 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00136
00137 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
00138 if (!currentViewer) {
00139 if (verbosity >= G4VisManager::warnings) {
00140 G4cout <<
00141 "WARNING: G4VisCommandsDrawView::SetNewValue: no current viewer."
00142 << G4endl;
00143 }
00144 return;
00145 }
00146
00147 G4String thetaDeg;
00148 G4String phiDeg;
00149 G4String panRight;
00150 G4String panUp;
00151 G4String panUnit;
00152 G4String zoomFactor;
00153 G4String dolly;
00154 G4String dollyUnit;
00155 std::istringstream is(newValue);
00156 is >> thetaDeg >> phiDeg >> panRight >> panUp >> panUnit
00157 >> zoomFactor >> dolly >> dollyUnit;
00158
00159 G4UImanager* UImanager = G4UImanager::GetUIpointer();
00160 G4int keepVerbose = UImanager->GetVerboseLevel();
00161 G4int newVerbose(0);
00162 if (keepVerbose >= 2 ||
00163 fpVisManager->GetVerbosity() >= G4VisManager::confirmations)
00164 newVerbose = 2;
00165 UImanager->SetVerboseLevel(newVerbose);
00166 G4ViewParameters vp = currentViewer->GetViewParameters();
00167 G4bool keepAutoRefresh = vp.IsAutoRefresh();
00168 vp.SetAutoRefresh(false);
00169 currentViewer->SetViewParameters(vp);
00170 UImanager->ApplyCommand(
00171 G4String("/vis/viewer/set/viewpointThetaPhi " + thetaDeg + " " + phiDeg + " deg"));
00172 UImanager->ApplyCommand(
00173 G4String("/vis/viewer/panTo " + panRight + " " + panUp + " " + panUnit));
00174 UImanager->ApplyCommand(
00175 G4String("/vis/viewer/zoomTo " + zoomFactor));
00176 vp = currentViewer->GetViewParameters();
00177 vp.SetAutoRefresh(keepAutoRefresh);
00178 currentViewer->SetViewParameters(vp);
00179 UImanager->ApplyCommand(
00180 G4String("/vis/viewer/dollyTo " + dolly + " " + dollyUnit));
00181 UImanager->SetVerboseLevel(keepVerbose);
00182 }
00183
00185
00186 G4VisCommandDrawVolume::G4VisCommandDrawVolume() {
00187 G4bool omitable;
00188 fpCommand = new G4UIcmdWithAString("/vis/drawVolume", this);
00189 fpCommand->SetGuidance
00190 ("Creates a scene containing this physical volume and asks the"
00191 "\ncurrent viewer to draw it. The scene becomes current.");
00192 fpCommand -> SetGuidance
00193 ("If physical-volume-name is \"world\" (the default), the main geometry"
00194 "\ntree (material world) is drawn. If \"worlds\", all worlds - material"
00195 "\nworld and parallel worlds, if any - are drawn. Otherwise a search of"
00196 "\nall worlds is made, taking the first matching occurence only. To see"
00197 "\na representation of the geometry hierarchy of the worlds, try"
00198 "\n\"/vis/drawTree [worlds]\" or one of the driver/browser combinations"
00199 "\nthat have the required functionality, e.g., HepRep");
00200 fpCommand->SetParameterName("physical-volume-name", omitable = true);
00201 fpCommand->SetDefaultValue("world");
00202 }
00203
00204 G4VisCommandDrawVolume::~G4VisCommandDrawVolume() {
00205 delete fpCommand;
00206 }
00207
00208 void G4VisCommandDrawVolume::SetNewValue(G4UIcommand*, G4String newValue) {
00209 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00210 G4UImanager* UImanager = G4UImanager::GetUIpointer();
00211 G4int keepVerbose = UImanager->GetVerboseLevel();
00212 G4int newVerbose(0);
00213 if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
00214 newVerbose = 2;
00215 UImanager->SetVerboseLevel(newVerbose);
00216 UImanager->ApplyCommand("/vis/scene/create");
00217 UImanager->ApplyCommand(G4String("/vis/scene/add/volume " + newValue));
00218 UImanager->ApplyCommand("/vis/sceneHandler/attach");
00219 UImanager->SetVerboseLevel(keepVerbose);
00220 static G4bool warned = false;
00221 if (verbosity >= G4VisManager::confirmations && !warned) {
00222 G4cout <<
00223 "NOTE: For systems which are not \"auto-refresh\" you will need to"
00224 "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"."
00225 << G4endl;
00226 warned = true;
00227 }
00228 }
00229
00231
00232 G4VisCommandOpen::G4VisCommandOpen() {
00233 G4bool omitable;
00234 fpCommand = new G4UIcommand("/vis/open", this);
00235 fpCommand->SetGuidance
00236 ("Creates a scene handler ready for drawing.");
00237 fpCommand->SetGuidance
00238 ("The scene handler becomes current (the name is auto-generated).");
00239 G4UIparameter* parameter;
00240 parameter = new G4UIparameter("graphics-system-name", 's', omitable = false);
00241 const G4GraphicsSystemList& gslist =
00242 fpVisManager->GetAvailableGraphicsSystems();
00243 G4String candidates;
00244 for (size_t igslist = 0; igslist < gslist.size(); igslist++) {
00245 const G4String& name = gslist[igslist]->GetName();
00246 const G4String& nickname = gslist[igslist]->GetNickname();
00247 if (nickname.isNull()) {
00248 candidates += name;
00249 }
00250 else {
00251 candidates += nickname;
00252 }
00253 candidates += " ";
00254 }
00255 candidates = candidates.strip();
00256 parameter->SetParameterCandidates(candidates);
00257 fpCommand->SetParameter(parameter);
00258 parameter = new G4UIparameter("window-size-hint", 's', omitable = true);
00259 parameter->SetGuidance
00260 ("integer (pixels) for square window placed by window manager or"
00261 " X-Windows-type geometry string, e.g. 600x600-100+100");
00262 parameter->SetDefaultValue("600");
00263 fpCommand->SetParameter(parameter);
00264 }
00265
00266 G4VisCommandOpen::~G4VisCommandOpen() {
00267 delete fpCommand;
00268 }
00269
00270 void G4VisCommandOpen::SetNewValue (G4UIcommand*, G4String newValue) {
00271 G4String systemName, windowSizeHint;
00272 std::istringstream is(newValue);
00273 is >> systemName >> windowSizeHint;
00274 G4UImanager* UImanager = G4UImanager::GetUIpointer();
00275 G4int keepVerbose = UImanager->GetVerboseLevel();
00276 G4int newVerbose(0);
00277 if (keepVerbose >= 2 ||
00278 fpVisManager->GetVerbosity() >= G4VisManager::confirmations)
00279 newVerbose = 2;
00280 UImanager->SetVerboseLevel(newVerbose);
00281 UImanager->ApplyCommand(G4String("/vis/sceneHandler/create " + systemName));
00282 UImanager->ApplyCommand(G4String("/vis/viewer/create ! ! " + windowSizeHint));
00283 UImanager->SetVerboseLevel(keepVerbose);
00284 }
00285
00287
00288 G4VisCommandSpecify::G4VisCommandSpecify() {
00289 G4bool omitable;
00290 fpCommand = new G4UIcommand("/vis/specify", this);
00291 fpCommand->SetGuidance
00292 ("Draws logical volume with Boolean components, voxels and readout geometry.");
00293 fpCommand->SetGuidance
00294 ("Creates a scene consisting of this logical volume and asks the"
00295 "\n current viewer to draw it to the specified depth of descent"
00296 "\n showing boolean components (if any), voxels (if any)"
00297 "\n and readout geometry (if any), under control of the appropriate flag.");
00298 fpCommand->SetGuidance
00299 ("Note: voxels are not constructed until start of run - /run/beamOn.");
00300 fpCommand->SetGuidance("The scene becomes current.");
00301 G4UIparameter* parameter;
00302 parameter = new G4UIparameter("logical-volume-name", 's', omitable = false);
00303 fpCommand->SetParameter(parameter);
00304 parameter = new G4UIparameter("depth-of-descent", 'i', omitable = true);
00305 parameter->SetDefaultValue(1);
00306 fpCommand->SetParameter(parameter);
00307 parameter = new G4UIparameter("booleans-flag", 'b', omitable = true);
00308 parameter->SetDefaultValue(true);
00309 fpCommand->SetParameter(parameter);
00310 parameter = new G4UIparameter("voxels-flag", 'b', omitable = true);
00311 parameter->SetDefaultValue(true);
00312 fpCommand->SetParameter(parameter);
00313 parameter = new G4UIparameter("readout-flag", 'b', omitable = true);
00314 parameter->SetDefaultValue(true);
00315 fpCommand->SetParameter(parameter);
00316 }
00317
00318 G4VisCommandSpecify::~G4VisCommandSpecify() {
00319 delete fpCommand;
00320 }
00321
00322 void G4VisCommandSpecify::SetNewValue(G4UIcommand*, G4String newValue) {
00323 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00324 G4UImanager* UImanager = G4UImanager::GetUIpointer();
00325 G4int keepVerbose = UImanager->GetVerboseLevel();
00326 G4int newVerbose(0);
00327 if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
00328 newVerbose = 2;
00329 UImanager->SetVerboseLevel(newVerbose);
00330
00331 UImanager->ApplyCommand("/vis/scene/create");
00332 UImanager->ApplyCommand(G4String("/vis/scene/add/logicalVolume " + newValue));
00333 UImanager->ApplyCommand("/vis/sceneHandler/attach");
00334 UImanager->SetVerboseLevel(keepVerbose);
00335 static G4bool warned = false;
00336 if (verbosity >= G4VisManager::confirmations && !warned) {
00337 G4cout <<
00338 "NOTE: For systems which are not \"auto-refresh\" you will need to"
00339 "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"."
00340 << G4endl;
00341 warned = true;
00342 }
00343 }