1271 {
1272
1274
1276 if (!currentViewer) {
1279 "ERROR: G4VisCommandViewerInterpolate::SetNewValue: no current viewer."
1281 }
1282 return;
1283 }
1284
1286 G4int nInterpolationPoints;
1290
1291 std::istringstream iss (newValue);
1292 iss
1293 >> pattern
1294 >> nInterpolationPoints
1295 >> waitTimePerPointString
1296 >> timeUnit
1297 >> exportString;
1298 G4String waitTimePerPointDimString(waitTimePerPointString +
' ' + timeUnit);
1301 G4int waitTimePerPointmilliseconds = waitTimePerPoint/millisecond;
1302 if (waitTimePerPointmilliseconds < 0) waitTimePerPointmilliseconds = 0;
1303
1305
1306
1308
1309
1312
1313
1316
1317
1318
1322
1323
1324 std::vector<G4ViewParameters> viewVector;
1325
1326 const G4int safety = 9999;
1327 G4int safetyCount = 0;
1329
1330#ifndef WIN32
1331
1332
1333 G4String shellCommand =
"echo " + pattern;
1334 FILE *filelist = popen(shellCommand.c_str(), "r");
1335 if (!filelist) {
1338 << "ERROR: G4VisCommandViewerInterpolate::SetNewValue:"
1339 << "\n Error obtaining pipe."
1341 }
1342 return;
1343 }
1344
1345
1346 const size_t BUFLENGTH = 999999;
1347 char buf[BUFLENGTH];
1348 char* result = std::fgets(buf, BUFLENGTH, filelist);
1349 if (result) {
1350 std::istringstream fileliststream(result);
1351 while (fileliststream >> pathname
1352 && safetyCount++ < safety) {
1353 uiManager->
ApplyCommand(
"/control/execute " + pathname);
1355
1357 viewVector.push_back(vp);
1358 }
1359 }
1360 pclose(filelist);
1361
1362#else
1363
1364 std::filesystem::path filePattern = pattern.c_str();
1365
1366
1367
1368
1369 std::string regexp_pattern("^" + filePattern.filename().string());
1370 std::string result_pattern = "";
1371
1372 size_t currentPos = 0;
1373 size_t nextPos = 0;
1374 std::string currentReplacement = "";
1375 size_t pos1 = regexp_pattern.find('.', nextPos);
1376 size_t pos2 = regexp_pattern.find('*', nextPos);
1377 size_t pos3 = regexp_pattern.find('?', nextPos);
1378 while ((pos1 != std::string::npos) || (pos2 != std::string::npos) || (pos3 != std::string::npos)) {
1379 nextPos = pos1;
1380 currentReplacement = "\\.";
1381 if (pos2 < nextPos) {
1382 nextPos = pos2;
1383 currentReplacement = ".*";
1384 }
1385 if (pos3 < nextPos) {
1386 nextPos = pos3;
1387 currentReplacement = "(.{1,1})";
1388 }
1389 result_pattern += regexp_pattern.substr(currentPos, nextPos - currentPos) + currentReplacement;
1390 nextPos++;
1391 currentPos = nextPos;
1392 pos1 = regexp_pattern.find('.', currentPos);
1393 pos2 = regexp_pattern.find('*', currentPos);
1394 pos3 = regexp_pattern.find('?', currentPos);
1395 }
1396 result_pattern += regexp_pattern.substr(currentPos);
1397
1398
1399
1400 G4String parentPath(filePattern.parent_path().string().length() ? filePattern.parent_path().string() : std::string(
"./"));
1401 std::filesystem::path parentPathPattern = parentPath.c_str();
1402
1403 std::regex result_pattern_regex (result_pattern, std::regex_constants::basic | std::regex_constants::icase);
1404 for (auto iter = std::filesystem::directory_iterator(parentPathPattern);
1405 iter != std::filesystem::directory_iterator() && safetyCount++ < safety;
1406 ++iter)
1407 {
1408 const auto& file = iter->path();
1409
1410 G4String filename(file.filename().string());
1411 if (std::regex_match(filename, result_pattern_regex))
1412 {
1413 uiManager->
ApplyCommand(
"/control/execute " + filename);
1415
1417 viewVector.push_back(vp);
1418 }
1419 }
1420
1421#endif
1422
1423 if (safetyCount >= safety) {
1426 "/vis/viewer/interpolate:"
1427 "\n the number of way points exceeds the maximum currently allowed: "
1429 }
1430 return;
1431 }
1432
1434 (currentViewer,viewVector,
1435 nInterpolationPoints,waitTimePerPointmilliseconds,exportString);
1436
1437
1440
1441
1445 G4cout <<
"Viewer \"" << currentViewer -> GetName () <<
"\""
1446 <<
" restored." <<
G4endl;
1447 }
1448}
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
static G4double ConvertToDimensionedDouble(const char *st)
G4int ApplyCommand(const char *aCommand)
G4int GetVerboseLevel() const
static G4UImanager * GetUIpointer()
void SetVerboseLevel(G4int val)
const G4ViewParameters & GetViewParameters() const
void SetViewParameters(const G4ViewParameters &vp)
static G4VisManager * fpVisManager
void InterpolateViews(G4VViewer *currentViewer, std::vector< G4ViewParameters > viewVector, const G4int nInterpolationPoints=50, const G4int waitTimePerPointmilliseconds=20, const G4String exportString="")
void SetAutoRefresh(G4bool)
G4bool IsAutoRefresh() const
G4VViewer * GetCurrentViewer() const
static Verbosity GetVerbosity()
void SetVerboseLevel(G4int)