Import Geant4 10.3.0.beta source tree
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4VisCommandsViewer.cc 93303 2015-10-15 15:19:40Z gcosmo $
|
||||
// $Id: G4VisCommandsViewer.cc 97316 2016-06-01 12:12:58Z gcosmo $
|
||||
|
||||
// /vis/viewer commands - John Allison 25th October 1998
|
||||
|
||||
@@ -41,10 +41,17 @@
|
||||
#include "G4UIcmdWithADoubleAndUnit.hh"
|
||||
#include "G4UIcmdWith3Vector.hh"
|
||||
#include "G4Point3D.hh"
|
||||
#include "G4SystemOfUnits.hh"
|
||||
#include "G4UnitsTable.hh"
|
||||
#include "G4ios.hh"
|
||||
#ifdef G4VIS_USE_STD11
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#endif
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
G4VVisCommandViewer::G4VVisCommandViewer () {}
|
||||
|
||||
@@ -275,6 +282,7 @@ void G4VisCommandViewerClear::SetNewValue (G4UIcommand*, G4String newValue) {
|
||||
return;
|
||||
}
|
||||
|
||||
viewer->SetView();
|
||||
viewer->ClearView();
|
||||
viewer->FinishView();
|
||||
if (verbosity >= G4VisManager::confirmations) {
|
||||
@@ -372,6 +380,47 @@ void G4VisCommandViewerClearTransients::SetNewValue (G4UIcommand*, G4String newV
|
||||
|
||||
}
|
||||
|
||||
////////////// /vis/viewer/clearVisAttributesModifiers ///////////////////////////////////////
|
||||
|
||||
G4VisCommandViewerClearVisAttributesModifiers::G4VisCommandViewerClearVisAttributesModifiers () {
|
||||
fpCommand = new G4UIcmdWithoutParameter
|
||||
("/vis/viewer/clearVisAttributesModifiers", this);
|
||||
fpCommand -> SetGuidance ("Clear vis attribute modifiers of current viewer.");
|
||||
fpCommand -> SetGuidance ("(These are used for touchables, etc.)");
|
||||
}
|
||||
|
||||
G4VisCommandViewerClearVisAttributesModifiers::~G4VisCommandViewerClearVisAttributesModifiers () {
|
||||
delete fpCommand;
|
||||
}
|
||||
|
||||
G4String G4VisCommandViewerClearVisAttributesModifiers::GetCurrentValue (G4UIcommand*) {
|
||||
return "";
|
||||
}
|
||||
|
||||
void G4VisCommandViewerClearVisAttributesModifiers::SetNewValue (G4UIcommand*, G4String) {
|
||||
|
||||
G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
||||
|
||||
G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
|
||||
if (!viewer) {
|
||||
if (verbosity >= G4VisManager::errors) {
|
||||
G4cerr <<
|
||||
"ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
|
||||
<< G4endl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
G4ViewParameters vp = viewer->GetViewParameters();
|
||||
vp.ClearVisAttributesModifiers();
|
||||
if (verbosity >= G4VisManager::confirmations) {
|
||||
G4cout << "Vis attributes modifiers for viewer \"" << viewer->GetName()
|
||||
<< "\" now cleared." << G4endl;
|
||||
}
|
||||
|
||||
SetViewParameters(viewer, vp);
|
||||
}
|
||||
|
||||
////////////// /vis/viewer/clone ///////////////////////////////////////
|
||||
|
||||
G4VisCommandViewerClone::G4VisCommandViewerClone () {
|
||||
@@ -907,6 +956,182 @@ void G4VisCommandViewerFlush::SetNewValue (G4UIcommand*, G4String newValue) {
|
||||
}
|
||||
}
|
||||
|
||||
////////////// /vis/viewer/interpolate ///////////////////////////////////////
|
||||
|
||||
#ifndef WIN32
|
||||
// popen is not available in Windows. _popen is said to be available in
|
||||
// Windows but this has not been tried.
|
||||
|
||||
G4VisCommandViewerInterpolate::G4VisCommandViewerInterpolate () {
|
||||
G4bool omitable;
|
||||
fpCommand = new G4UIcommand ("/vis/viewer/interpolate", this);
|
||||
fpCommand -> SetGuidance
|
||||
("Interpolate views defined by the first argument, which can contain "
|
||||
"Unix-shell-style pattern matching characters such as '*', '?' and '[' "
|
||||
"- see \"man sh\" and look for \"Pattern Matching\". The contents "
|
||||
"of each file are assumed to be \"/vis/viewer\" commands "
|
||||
"that specify a particular view. The files are processed in alphanumeric "
|
||||
"order of filename. The files may be written by hand or produced by the "
|
||||
"\"/vis/viewer/save\" command.");
|
||||
fpCommand -> SetGuidance
|
||||
("The default is to search the working directory for files with a .view "
|
||||
"extension. Another procedure is to assemble view files in a subdirectory, "
|
||||
"e.g., \"myviews\"; then they can be interpolated with\n"
|
||||
"\"/vis/viewer/interpolate myviews/*\".");
|
||||
fpCommand -> SetGuidance
|
||||
("To export interpolated views to file for a future possible movie, "
|
||||
"write \"export\" as 5th parameter (OpenGL only).");
|
||||
G4UIparameter* parameter;
|
||||
parameter = new G4UIparameter("pattern", 's', omitable = true);
|
||||
parameter -> SetGuidance("Pattern that defines the view files.");
|
||||
parameter -> SetDefaultValue("*.view");
|
||||
fpCommand -> SetParameter(parameter);
|
||||
parameter = new G4UIparameter("no-of-points", 'i', omitable = true);
|
||||
parameter -> SetGuidance ("Number of interpolation points per interval.");
|
||||
parameter -> SetDefaultValue(50);
|
||||
fpCommand -> SetParameter(parameter);
|
||||
parameter = new G4UIparameter("wait-time", 's', omitable = true);
|
||||
parameter -> SetGuidance("Wait time per interpolated point");
|
||||
parameter -> SetDefaultValue("20.");
|
||||
fpCommand -> SetParameter(parameter);
|
||||
parameter = new G4UIparameter("time-unit", 's', omitable = true);
|
||||
parameter -> SetDefaultValue("millisecond");
|
||||
fpCommand -> SetParameter (parameter);
|
||||
parameter = new G4UIparameter("export", 's', omitable = true);
|
||||
parameter -> SetDefaultValue("no");
|
||||
fpCommand -> SetParameter (parameter);
|
||||
}
|
||||
|
||||
G4VisCommandViewerInterpolate::~G4VisCommandViewerInterpolate () {
|
||||
delete fpCommand;
|
||||
}
|
||||
|
||||
G4String G4VisCommandViewerInterpolate::GetCurrentValue (G4UIcommand*) {
|
||||
return "";
|
||||
}
|
||||
|
||||
void G4VisCommandViewerInterpolate::SetNewValue (G4UIcommand*, G4String newValue) {
|
||||
|
||||
G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
||||
|
||||
G4String pattern;
|
||||
G4int nInterpolationPoints;
|
||||
G4String waitTimePerPointString;
|
||||
G4String timeUnit;
|
||||
G4String exportString;
|
||||
|
||||
std::istringstream iss (newValue);
|
||||
iss
|
||||
>> pattern
|
||||
>> nInterpolationPoints
|
||||
>> waitTimePerPointString
|
||||
>> timeUnit
|
||||
>> exportString;
|
||||
const G4double waitTimePerPoint =
|
||||
G4UIcommand::ConvertToDimensionedDouble((waitTimePerPointString + ' ' + timeUnit).c_str());
|
||||
G4int waitTimePerPointmilliseconds = waitTimePerPoint/millisecond;
|
||||
if (waitTimePerPointmilliseconds < 0) waitTimePerPointmilliseconds = 0;
|
||||
|
||||
// Execute pattern and get resulting list of filles
|
||||
G4String shellCommand = "echo " + pattern;
|
||||
FILE *filelist = popen(shellCommand.c_str(), "r");
|
||||
if (!filelist) {
|
||||
if (verbosity >= G4VisManager::errors) {
|
||||
G4cerr
|
||||
<< "ERROR: G4VisCommandViewerInterpolate::SetNewValue:"
|
||||
<< "\n Error obtaining pipe."
|
||||
<< G4endl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
|
||||
if (!currentViewer) {
|
||||
if (verbosity >= G4VisManager::errors) {
|
||||
G4cerr <<
|
||||
"ERROR: G4VisCommandViewerInterpolate::SetNewValue: no current viewer."
|
||||
<< G4endl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Save current view parameters
|
||||
G4ViewParameters saveVP = currentViewer->GetViewParameters();
|
||||
|
||||
// Save current verbosities
|
||||
G4VisManager::Verbosity keepVisVerbosity = fpVisManager->GetVerbosity();
|
||||
G4UImanager* ui = G4UImanager::GetUIpointer();
|
||||
G4int keepUIVerbosity = ui->GetVerboseLevel();
|
||||
|
||||
// Set verbosities for this operation
|
||||
fpVisManager->SetVerboseLevel(G4VisManager::errors);
|
||||
ui->SetVerboseLevel(0);
|
||||
|
||||
// Switch off auto-refresh (it will be restored later)
|
||||
// Note: the view files do not set autoRefresh.
|
||||
G4ViewParameters non_auto = saveVP;
|
||||
non_auto.SetAutoRefresh(false);
|
||||
currentViewer->SetViewParameters(non_auto);
|
||||
|
||||
// Build view vector of way points
|
||||
std::vector<G4ViewParameters> viewVector;
|
||||
const size_t BUFLENGTH = 999999;
|
||||
char buf[BUFLENGTH];
|
||||
fgets(buf, BUFLENGTH, filelist);
|
||||
std::istringstream fileliststream(buf);
|
||||
const G4int safety = 9999;
|
||||
G4int safetyCount = 0;
|
||||
G4String pathname;
|
||||
while (fileliststream >> pathname
|
||||
&& safetyCount++ < safety) { // Loop checking, 16.02.2016, J.Allison
|
||||
ui->ApplyCommand("/control/execute " + pathname);
|
||||
viewVector.push_back(currentViewer->GetViewParameters());
|
||||
}
|
||||
|
||||
if (safetyCount >= safety) {
|
||||
if (verbosity >= G4VisManager::errors) {
|
||||
G4cout <<
|
||||
"/vis/viewer/interpolate:"
|
||||
"\n the number of way points exceeds the maximum currently allowed: "
|
||||
<< safety << G4endl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Interpolate views
|
||||
safetyCount = 0;
|
||||
do {
|
||||
G4ViewParameters* vp =
|
||||
G4ViewParameters::CatmullRomCubicSplineInterpolation(viewVector,nInterpolationPoints);
|
||||
if (!vp) break;
|
||||
currentViewer->SetViewParameters(*vp);
|
||||
currentViewer->RefreshView();
|
||||
if (exportString == "export" &&
|
||||
currentViewer->GetName().contains("OpenGL"))
|
||||
ui->ApplyCommand("/vis/ogl/export");
|
||||
#ifdef G4VIS_USE_STD11
|
||||
if (waitTimePerPointmilliseconds > 0)
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(waitTimePerPointmilliseconds));
|
||||
#endif
|
||||
} while (safetyCount++ < safety); // Loop checking, 16.02.2016, J.Allison
|
||||
|
||||
// Restore original verbosities
|
||||
ui->SetVerboseLevel(keepUIVerbosity);
|
||||
fpVisManager->SetVerboseLevel(keepVisVerbosity);
|
||||
|
||||
// Restore original view parameters
|
||||
currentViewer->SetViewParameters(saveVP);
|
||||
currentViewer->RefreshView();
|
||||
if (verbosity >= G4VisManager::confirmations) {
|
||||
G4cout << "Viewer \"" << currentViewer -> GetName () << "\""
|
||||
<< " restored." << G4endl;
|
||||
}
|
||||
|
||||
pclose(filelist);
|
||||
}
|
||||
|
||||
#endif // WIN32 - popen is not available in Windows. _popen is there but not tried.
|
||||
|
||||
////////////// /vis/viewer/list ///////////////////////////////////////
|
||||
|
||||
G4VisCommandViewerList::G4VisCommandViewerList () {
|
||||
@@ -1316,9 +1541,19 @@ G4VisCommandViewerSave::G4VisCommandViewerSave () {
|
||||
fpCommand -> SetGuidance
|
||||
("Write commands that define the current view to file.");
|
||||
fpCommand -> SetGuidance
|
||||
("Read them back into the same or any viewer with \"/control/execute <filename>\".");
|
||||
fpCommand -> SetParameterName ("file-name", omitable = true);
|
||||
fpCommand -> SetDefaultValue ("G4cout");
|
||||
("Read them back into the same or any viewer with \"/control/execute\".");
|
||||
fpCommand -> SetGuidance
|
||||
("If the filename is omitted the view is saved to a file "
|
||||
"\"g4_nn.view\", where nn is a sequential two-digit number.");
|
||||
fpCommand -> SetGuidance
|
||||
("If the filename is \"-\", the data are written to G4cout.");
|
||||
fpCommand -> SetGuidance
|
||||
("If you are wanting to save views for future interpolation a recommended "
|
||||
"procedure is: save views to \"g4_nn.view\", as above, then move the files "
|
||||
"into a sub-directory, say, \"views\", then interpolate with"
|
||||
"\"/vis/viewer/interpolate views/\" (note the trailing \'/\').");
|
||||
fpCommand -> SetParameterName ("filename", omitable = true);
|
||||
fpCommand -> SetDefaultValue ("");
|
||||
}
|
||||
|
||||
G4VisCommandViewerSave::~G4VisCommandViewerSave () {
|
||||
@@ -1334,7 +1569,7 @@ namespace {
|
||||
void WriteCommands
|
||||
(std::ostream& os,
|
||||
const G4ViewParameters& vp,
|
||||
const G4Point3D& stp)
|
||||
const G4Point3D& stp) // Standard Target Point
|
||||
{
|
||||
os
|
||||
<< vp.CameraAndLightingCommands(stp)
|
||||
@@ -1368,38 +1603,12 @@ void G4VisCommandViewerSave::SetNewValue (G4UIcommand*, G4String newValue) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
std::ofstream ofs;
|
||||
if (newValue != "G4cout") {
|
||||
// Check if file exists
|
||||
std::ifstream ifs(newValue);
|
||||
if (ifs) {
|
||||
if (verbosity >= G4VisManager::errors) {
|
||||
G4cerr <<
|
||||
"ERROR: G4VisCommandsViewerSave::SetNewValue: File \""
|
||||
<< newValue << "\" already exists."
|
||||
<< G4endl;
|
||||
}
|
||||
ifs.close();
|
||||
return;
|
||||
}
|
||||
ofs.open(newValue);
|
||||
if (!ofs) {
|
||||
if (verbosity >= G4VisManager::errors) {
|
||||
G4cerr <<
|
||||
"ERROR: G4VisCommandsViewerSave::SetNewValue: Trouble opening file \""
|
||||
<< newValue << "\"."
|
||||
<< G4endl;
|
||||
}
|
||||
ofs.close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Get view parameters and ther relevant information.
|
||||
G4ViewParameters vp = currentViewer->GetViewParameters();
|
||||
// Concatenate any private vis attributes modifiers...
|
||||
const std::vector<G4ModelingParameters::VisAttributesModifier>*
|
||||
privateVAMs = currentViewer->GetPrivateVisAttributesModifiers();
|
||||
privateVAMs = currentViewer->GetPrivateVisAttributesModifiers();
|
||||
if (privateVAMs) {
|
||||
std::vector<G4ModelingParameters::VisAttributesModifier>::const_iterator i;
|
||||
for (i = privateVAMs->begin(); i != privateVAMs->end(); ++i) {
|
||||
@@ -1407,23 +1616,58 @@ void G4VisCommandViewerSave::SetNewValue (G4UIcommand*, G4String newValue) {
|
||||
}
|
||||
}
|
||||
const G4Point3D& stp = currentScene->GetStandardTargetPoint();
|
||||
|
||||
if (newValue == "G4cout") {
|
||||
|
||||
G4String filename = newValue;
|
||||
if (newValue.length() == 0) {
|
||||
// Null filename - generate a filename
|
||||
const G4int maxNoOfFiles = 100;
|
||||
static G4int sequenceNumber = 0;
|
||||
if (sequenceNumber >= maxNoOfFiles) {
|
||||
if (verbosity >= G4VisManager::errors) {
|
||||
G4cerr
|
||||
<< "ERROR: G4VisCommandsViewerSave::SetNewValue: Maximum number, "
|
||||
<< maxNoOfFiles
|
||||
<< ", of files exceeded."
|
||||
<< G4endl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
std::ostringstream oss;
|
||||
oss << std::setw(2) << std::setfill('0') << sequenceNumber++;
|
||||
filename = "g4_" + oss.str() + ".view";
|
||||
}
|
||||
|
||||
if (filename == "-") {
|
||||
// Write to standard output
|
||||
WriteCommands(G4cout,vp,stp);
|
||||
} else {
|
||||
// Write to file
|
||||
std::ofstream ofs(filename);
|
||||
if (!ofs) {
|
||||
if (verbosity >= G4VisManager::errors) {
|
||||
G4cerr <<
|
||||
"ERROR: G4VisCommandsViewerSave::SetNewValue: Trouble opening file \""
|
||||
<< filename << "\"."
|
||||
<< G4endl;
|
||||
}
|
||||
ofs.close();
|
||||
return;
|
||||
}
|
||||
WriteCommands(ofs,vp,stp);
|
||||
ofs.close();
|
||||
}
|
||||
|
||||
if (verbosity >= G4VisManager::confirmations) {
|
||||
|
||||
if (verbosity >= G4VisManager::warnings) {
|
||||
G4cout << "Viewer \"" << currentViewer -> GetName ()
|
||||
<< "\"" << " saved to ";
|
||||
if (newValue == "G4cout") {
|
||||
if (filename == "-") {
|
||||
G4cout << "G4cout.";
|
||||
} else {
|
||||
G4cout << "file \'" << newValue << "\"." <<
|
||||
"\n Read view parameters back into this or any viewer with"
|
||||
"\n \"/control/execute " << newValue << "\"";
|
||||
G4cout << "file \'" << filename << "\"." <<
|
||||
"\n Read the view back into this or any viewer with"
|
||||
"\n \"/control/execute " << filename << "\" or use"
|
||||
"\n \"/vis/viewer/interpolate\" if you have several saved files -"
|
||||
"\n see \"help /vis/viewer/interpolate\" for guidance.";
|
||||
}
|
||||
G4cout << G4endl;
|
||||
}
|
||||
@@ -1553,7 +1797,8 @@ void G4VisCommandViewerSelect::SetNewValue (G4UIcommand*, G4String newValue) {
|
||||
return;
|
||||
}
|
||||
|
||||
fpVisManager -> SetCurrentViewer (viewer); // Prints confirmation.
|
||||
// Set pointers, call SetView and print confirmation.
|
||||
fpVisManager -> SetCurrentViewer (viewer);
|
||||
|
||||
RefreshIfRequired(viewer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user