Import Geant4 11.4.1 source tree

This commit is contained in:
Gabriele Cosmo
2026-03-19 16:51:22 +01:00
parent b4a16de652
commit 41f2dd7996
352 changed files with 26342 additions and 24532 deletions
+19 -4
View File
@@ -5,6 +5,21 @@ which **must** added in reverse chronological order (newest at the top).
It must **not** be used as a substitute for writing good git commit messages!
-------------------------------------------------------------------------------
## 2026-02-20 Gabriele Cosmo (interfaces-V11-03-13)
- Fix in G4UIQt::ComputeStringMatchScore(..) in setting number of elements
for a QVector; restored use of G4int in place of std::size_t, according
to QVector signature.
## 2026-02-17 Gabriele Cosmo
- G4UIQt: Use std::size_t and G4 types where appropriate.
## 2026-02-16 John Allison
- G4UIQt: Fix "Implicit conversion loses integer precision" warnings on Mac Xcode.
## 2026-01-30 Andrea Barresi
- G4UIQt: Reimplemented the command search feature for the Help tree.
## 2025-10-31 Andrea Barresi (interfaces-V11-03-12)
-G4VInteractiveSession:
- Added UpdateDrawingStyle, UpdateProjectionStyle, UpdateTransparencySlider
@@ -70,16 +85,16 @@ It must **not** be used as a substitute for writing good git commit messages!
- Introduce Time Window tab.
- This exploits generic time windowing recently introduced in modeling an
management.
- Try it with example B1. Hit Prepare, then Go. It is more spectacular
- Try it with example B1. Hit "Prepare", then "Go". It is more spectacular
if you prepare, say, 100 events.
- However, it doesnt work with OGL in Qt6. (Try it with Qt5 if you can.)
- However, it doesn't work with OGL in Qt6. (Try it with Qt5 if you can.)
TSG works fine with both Qt5 and Qt6, except line width is not implemented.
- I have noticed that in Qt5, mouse events seem to processed in strict order.
Values of boxes dont get updated until the windowing is finished. But with
Values of boxes don't get updated until the windowing is finished. But with
Qt6, events seem to be processed in parallel. Values in other boxes are
continuously updated during time evolution. How do they do that? Is each
slot executed on a different thread? This could cause the problem with OGL,
but I dont have sufficient knowledge of Qt protocols.
but I don't have sufficient knowledge of Qt protocols.
- Change "bar" to "toolbar" to avoid conflict with G4PhysicalConstants.
## 2025-01-06 John Allison (interfaces-V11-03-00)
@@ -25,8 +25,8 @@
//
//
//
#ifndef G4UIQt_h
#define G4UIQt_h
#ifndef G4UIQT_HH
#define G4UIQT_HH
#include "G4VBasicShell.hh"
#include "G4VInteractiveSession.hh"
@@ -307,11 +307,9 @@ private:
G4int&) override; // have to be implemeted because we heritate from G4VBasicShell
bool eventFilter(QObject*, QEvent*) override;
void ActivateCommand(G4String);
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
QMap<G4int, QString> LookForHelpStringInChildTree(G4UIcommandTree*, const QString&);
#else
QMultiMap<G4int, QString> LookForHelpStringInChildTree(G4UIcommandTree*, const QString&);
#endif
QMultiMap<G4double, QString> LookForHelpStringInChildTree(G4UIcommandTree*, const QString&);
G4double ComputeStringMatchScore(const QString&, const QString&);
QWidget* CreateVisParametersTBWidget();
QWidget* CreateHelpTBWidget();
QWidget* CreateTimeWindowWidget();
+86 -172
View File
@@ -2270,7 +2270,7 @@ QWidget* G4UIQt::CreateHelpTBWidget()
fHelpLine = new QLineEdit();
helpLayout->addWidget(new QLabel("Search :"));
helpLayout->addWidget(fHelpLine);
connect(fHelpLine, SIGNAL(editingFinished()), this, SLOT(LookForHelpStringCallback()));
connect(fHelpLine, SIGNAL(textChanged(const QString&)), this, SLOT(LookForHelpStringCallback()));
// Create Help tree
FillHelpTree();
@@ -4134,10 +4134,8 @@ void G4UIQt::FillHelpTree()
QString searchText = fHelpLine->text();
if (searchText == "") {
// clear old help tree
// fHelpTreeWidget->clear();
}
else {
fHelpTreeWidget->clear();
} else {
return;
}
@@ -4146,10 +4144,6 @@ void G4UIQt::FillHelpTree()
fParameterHelpTable->setVisible(false);
}
if (fHelpLine != nullptr) {
fHelpLine->setText("");
}
G4UImanager* UI = G4UImanager::GetUIpointer();
if (UI == nullptr) return;
G4UIcommandTree* treeTop = UI->GetTree();
@@ -5012,7 +5006,7 @@ void G4UIQt::UpdateCommandCompleter()
G4UIcommandTree* commandTreeTop = UI->GetTree();
G4UIcommandTree* aTree = commandTreeTop->FindCommandTree("/");
if (aTree != nullptr) {
int Ndir = aTree->GetTreeEntry();
G4int Ndir = aTree->GetTreeEntry();
fCompleter->setMaxVisibleItems(Ndir);
}
fCommandArea->setCompleter(fCompleter);
@@ -5521,9 +5515,9 @@ void G4UIQt::FilterAllOutputTextArea()
}
}
/** Callback called when user give a new string to look for<br>
Display a list of matching commands descriptions. If no string is set,
will display the complete help tree
/* Callback called when user give a new string to look for
Display a list of matching commands.
If no string is set, will display the complete help tree
*/
void G4UIQt::LookForHelpStringCallback()
{
@@ -5533,92 +5527,34 @@ void G4UIQt::LookForHelpStringCallback()
fParameterHelpLabel->setText("");
fParameterHelpTable->setVisible(false);
if (searchText == "") {
// clear old help tree
fHelpTreeWidget->clear();
FillHelpTree();
return;
}
OpenHelpTreeOnCommand(searchText);
}
void G4UIQt::OpenHelpTreeOnCommand(const QString& searchText)
{
// Invoke textual help (writes guidance to output window)
ApplyShellCommand("help "+G4String(searchText.toStdString()), exitSession, exitPause);
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
// The code below searches the help tree and offers a list of commands matching searchText.
// All is OK with Qt5, but there is an undiagnosed crash with Qt6, so disable this feature.
// FIXME : JA 8/8/25
// the help tree
// Get the help tree
G4UImanager* UI = G4UImanager::GetUIpointer();
if (UI == nullptr) return;
G4UIcommandTree* treeTop = UI->GetTree();
G4int treeSize = treeTop->GetTreeEntry();
// clear old help tree
// Clear old help tree
fHelpTreeWidget->clear();
// look for new items
// Look for matching commands
QMultiMap<G4double, QString> commandResultMap;
commandResultMap = LookForHelpStringInChildTree(treeTop, searchText);
int tmp = 0;
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
// Before Qt5.15
QMap<G4int, QString> commandResultMap;
QMap<G4int, QString> commandChildResultMap;
for (G4int a = 0; a < treeSize; ++a) {
G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a + 1)->GetPathName().data());
tmp = GetCommandList(command).count(searchText, Qt::CaseInsensitive);
if (tmp > 0) {
commandResultMap.insertMulti(
tmp, QString((char*)(treeTop->GetTree(a + 1)->GetPathName()).data()));
}
// look for childs
commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a + 1), searchText);
// insert new childs
if (! commandChildResultMap.empty()) {
QMap<int, QString>::const_iterator i = commandChildResultMap.constBegin();
while (i != commandChildResultMap.constEnd()) {
commandResultMap.insertMulti(i.key(), i.value());
i++;
}
commandChildResultMap.clear();
}
}
#else
// Qt5.15 and beyond
QMultiMap<G4int, QString> commandResultMap;
QMultiMap<G4int, QString> commandChildResultMap;
for (G4int a = 0; a < treeSize; ++a) {
G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a + 1)->GetPathName().data());
tmp = (int)GetCommandList(command).count(searchText, Qt::CaseInsensitive);
if (tmp > 0) {
commandResultMap.insert(tmp, QString((char*)(treeTop->GetTree(a + 1)->GetPathName()).data()));
}
// look for childs
commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a + 1), searchText);
// insert new childs
if (! commandChildResultMap.empty()) {
auto i = commandChildResultMap.constBegin();
while (i != commandChildResultMap.constEnd()) {
commandResultMap.insert(i.key(), i.value());
++i;
}
commandChildResultMap.clear();
}
}
#endif
// build new help tree
// Build new help tree
fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
fHelpTreeWidget->setColumnCount(2);
QStringList labels;
labels << QString("Command") << QString("Match");
QStringList labels = {"Command", "Match"};
fHelpTreeWidget->setHeaderLabels(labels);
if (commandResultMap.empty()) {
@@ -5627,123 +5563,101 @@ void G4UIQt::OpenHelpTreeOnCommand(const QString& searchText)
return;
}
auto i = commandResultMap.constEnd();
i--;
// 10 maximum progress values
G4float multValue = 10.0 / (G4float)(i.key());
QString progressChar = "|";
QString progressStr = "|";
QTreeWidgetItem* newItem;
G4bool end = false;
while (! end) {
if (i == commandResultMap.constBegin()) {
end = true;
}
for (G4int a = 0; a < G4int(i.key() * multValue); ++a) {
G4int nItems = 0;
for (auto it = commandResultMap.end(); it != commandResultMap.begin();) {
it--;
if (nItems >= 50) break;
// 20 maximum progress values
for (G4int i = 0; i < G4int(it.key() * 10); ++i) {
progressStr += progressChar;
}
newItem = new QTreeWidgetItem();
QString commandStr = i.value().trimmed();
QString commandStr = it.value().trimmed();
if (commandStr.indexOf("/") == 0) {
commandStr = commandStr.right(commandStr.size() - 1);
commandStr.remove(0, 1);
}
newItem->setText(0, commandStr);
newItem->setText(1, progressStr);
fHelpTreeWidget->addTopLevelItem(newItem);
newItem->setForeground(1, QBrush(Qt::blue));
if (it.key() > 1) {
newItem->setForeground(1, QBrush(Qt::red));
} else {
newItem->setForeground(1, QBrush(Qt::blue));
}
progressStr = "|";
i--;
++nItems;
}
fHelpTreeWidget->resizeColumnToContents(0);
fHelpTreeWidget->sortItems(1, Qt::DescendingOrder);
// fHelpTreeWidget->setColumnWidth(1,10);//resizeColumnToContents (1);
#endif
}
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
// Before Qt5.15
QMap<G4int, QString> G4UIQt::LookForHelpStringInChildTree(
G4UIcommandTree* aCommandTree, const QString& text)
QMultiMap<G4double, QString> G4UIQt::LookForHelpStringInChildTree(
G4UIcommandTree* aCommandTree, const QString& searchText)
{
QMap<G4int, QString> commandResultMap;
if (aCommandTree == NULL) return commandResultMap;
// Get the Sub directories
G4int tmp = 0;
QMap<G4int, QString> commandChildResultMap;
for (G4int a = 0; a < aCommandTree->GetTreeEntry(); ++a) {
const G4UIcommand* command = aCommandTree->GetGuidance();
tmp = GetCommandList(command).count(text, Qt::CaseInsensitive);
if (tmp > 0) {
commandResultMap.insertMulti(
tmp, QString((char*)(aCommandTree->GetTree(a + 1)->GetPathName()).data()));
}
// look for childs
commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a + 1), text);
if (! commandChildResultMap.empty()) {
// insert new childs
QMap<G4int, QString>::const_iterator i = commandChildResultMap.constBegin();
while (i != commandChildResultMap.constEnd()) {
commandResultMap.insertMulti(i.key(), i.value());
++i;
}
commandChildResultMap.clear();
}
}
// Get the Commands
for (G4int a = 0; a < aCommandTree->GetCommandEntry(); ++a) {
const G4UIcommand* command = aCommandTree->GetCommand(a + 1);
tmp = GetCommandList(command).count(text, Qt::CaseInsensitive);
if (tmp > 0) {
commandResultMap.insertMulti(
tmp, QString((char*)(aCommandTree->GetCommand(a + 1)->GetCommandPath()).data()));
}
}
return commandResultMap;
}
#else
// Qt5.15 and beyond
QMultiMap<G4int, QString> G4UIQt::LookForHelpStringInChildTree(
G4UIcommandTree* aCommandTree, const QString& text)
{
QMultiMap<G4int, QString> commandResultMap;
QMultiMap<G4double, QString> commandResultMap;
if (aCommandTree == nullptr) return commandResultMap;
// Get the Sub directories
G4int tmp = 0;
QMultiMap<G4int, QString> commandChildResultMap;
for (G4int a = 0; a < aCommandTree->GetTreeEntry(); ++a) {
const G4UIcommand* command = aCommandTree->GetGuidance();
tmp = (int)GetCommandList(command).count(text, Qt::CaseInsensitive);
if (tmp > 0) {
commandResultMap.insert(
tmp, QString((char*)(aCommandTree->GetTree(a + 1)->GetPathName()).data()));
}
// look for childs
commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a + 1), text);
if (! commandChildResultMap.empty()) {
// insert new childs
auto i = commandChildResultMap.constBegin();
while (i != commandChildResultMap.constEnd()) {
commandResultMap.insert(i.key(), i.value());
++i;
}
commandChildResultMap.clear();
}
// Loop over sub trees
QMultiMap<G4double, QString> commandChildResultMap;
for (G4int i = 0; i < aCommandTree->GetTreeEntry(); ++i) {
commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(i + 1), searchText);
commandResultMap += commandChildResultMap;
commandChildResultMap.clear();
}
// Get the Commands
for (G4int a = 0; a < aCommandTree->GetCommandEntry(); ++a) {
const G4UIcommand* command = aCommandTree->GetCommand(a + 1);
tmp = (int)GetCommandList(command).count(text, Qt::CaseInsensitive);
if (tmp > 0) {
commandResultMap.insert(
tmp, QString((char*)(aCommandTree->GetCommand(a + 1)->GetCommandPath()).data()));
}
// Loop over the commands and compute match score
for (G4int i = 0; i < aCommandTree->GetCommandEntry(); ++i) {
const G4UIcommand* command = aCommandTree->GetCommand(i + 1);
if (command == nullptr) continue;
G4double score = ComputeStringMatchScore(QString(command->GetCommandPath().data()), searchText);
if (score > 0) commandResultMap.insert(score, QString(command->GetCommandPath().data()));
}
return commandResultMap;
}
#endif
G4double G4UIQt::ComputeStringMatchScore(const QString& string, const QString& searchText)
{
if (string.contains(searchText, Qt::CaseInsensitive)) {
//Score (1,2] for matched string
return 1 + G4double(searchText.size()) / string.size();
} else {
//Score (0,1) for similar string (Normalized Levenshtein distance)
const auto nSize = (G4int)string.size();
const auto mSize = (G4int)searchText.size();
QVector<QVector<G4int>> dp(nSize + 1, QVector<G4int>(mSize + 1));
for (G4int i = 0; i <= nSize; ++i) dp[i][0] = i;
for (G4int j = 0; j <= mSize; ++j) dp[0][j] = j;
for (G4int i = 1; i <= nSize; ++i) {
for (G4int j = 1; j <= mSize; ++j) {
G4int cost = (string[i - 1] == searchText[j - 1]) ? 0 : 1;
dp[i][j] = std::min({dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + cost});
}
}
return 1.0 - G4double(dp[nSize][mSize]) / std::max(nSize, mSize);
}
}
QString G4UIQt::GetShortCommandPath(QString& commandPath)
{