Import Geant4 11.2.0.beta source tree
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
// To unify Qt event treatment between
|
||||
// G4/interfaces Qt sessions and G4/visualizations Qt drivers.
|
||||
// L. Garnier
|
||||
|
||||
#ifndef G4QT_HH
|
||||
#define G4QT_HH
|
||||
|
||||
#include "G4VInteractorManager.hh"
|
||||
|
||||
class QWidget;
|
||||
class QString;
|
||||
|
||||
// Class description :
|
||||
//
|
||||
// G4Qt : a singleton to handle GUI sessions and visualization
|
||||
// drivers built over Qt. It permits to have one Qt main loop for
|
||||
// the whole application. The Qt toolkit is inited in the
|
||||
// constructor. It is done once for the whole application.
|
||||
//
|
||||
// Class description - end :
|
||||
|
||||
class G4Qt : public G4VInteractorManager
|
||||
{
|
||||
public:
|
||||
static G4Qt* getInstance();
|
||||
static G4Qt* getInstance(int, char**, char*);
|
||||
G4bool Inited() override;
|
||||
void* GetEvent() override;
|
||||
void FlushAndWaitExecution() override;
|
||||
~G4Qt() override;
|
||||
bool IsExternalApp();
|
||||
|
||||
private:
|
||||
G4Qt(const G4Qt&);
|
||||
G4Qt(int, char**, char*);
|
||||
G4Qt& operator=(const G4Qt&);
|
||||
static G4Qt* instance; // Pointer to single instance.
|
||||
int argn;
|
||||
char** args;
|
||||
bool externalApp;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,111 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// ====================================================================
|
||||
// G4UIExecutive.hh
|
||||
//
|
||||
// This class helps automatic instantiation of user session
|
||||
// according to your environment variable like G4UI_USE_XXX.
|
||||
//
|
||||
// Usage in main():
|
||||
//
|
||||
// ...
|
||||
// #include "G4UIExecutive.hh"
|
||||
//
|
||||
// int main(int argc, char** argv)
|
||||
// {
|
||||
// ...
|
||||
// G4UIExecutive* myapp = new G4UIExecutive(argc, argv);
|
||||
// if (session->IsGUI())
|
||||
// // Do any extra for a GUI session
|
||||
//
|
||||
// myapp-> SessionStart();
|
||||
// ...
|
||||
// delete myapp;
|
||||
// ...
|
||||
//
|
||||
// ====================================================================
|
||||
#ifndef G4UI_EXECUTIVE_HH
|
||||
#define G4UI_EXECUTIVE_HH
|
||||
|
||||
#include "G4VUIshell.hh"
|
||||
|
||||
#include <map>
|
||||
|
||||
class G4UIsession;
|
||||
|
||||
class G4UIExecutive
|
||||
{
|
||||
public:
|
||||
G4UIExecutive(G4int argc, char** argv, const G4String& type = "");
|
||||
~G4UIExecutive();
|
||||
|
||||
G4UIsession* GetSession() const;
|
||||
|
||||
G4bool IsGUI() const;
|
||||
|
||||
void SetVerbose(G4bool val);
|
||||
|
||||
void SetPrompt(const G4String& prompt);
|
||||
void SetLsColor(TermColorIndex dirColor, TermColorIndex cmdColor);
|
||||
|
||||
void SessionStart();
|
||||
|
||||
private:
|
||||
void SelectSessionByArg(const G4String& stype);
|
||||
void SelectSessionByEnv();
|
||||
void SelectSessionByFile(const G4String& appname);
|
||||
void SelectSessionByBestGuess();
|
||||
|
||||
enum SessionType
|
||||
{
|
||||
kNone,
|
||||
kQt,
|
||||
kXm,
|
||||
kWin32,
|
||||
kTcsh,
|
||||
kCsh
|
||||
};
|
||||
SessionType selected;
|
||||
|
||||
G4UIsession* session;
|
||||
G4VUIshell* shell;
|
||||
|
||||
G4bool isGUI;
|
||||
|
||||
G4bool verbose;
|
||||
|
||||
std::map<G4String, G4String> sessionMap;
|
||||
};
|
||||
|
||||
// ====================================================================
|
||||
inline G4UIsession* G4UIExecutive::GetSession() const { return session; }
|
||||
|
||||
inline G4bool G4UIExecutive::IsGUI() const { return isGUI; }
|
||||
|
||||
inline void G4UIExecutive::SetVerbose(G4bool val) { verbose = val; }
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,419 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef G4UIQt_h
|
||||
#define G4UIQt_h
|
||||
|
||||
#include "G4VBasicShell.hh"
|
||||
#include "G4VInteractiveSession.hh"
|
||||
#include "G4SceneTreeItem.hh"
|
||||
|
||||
#include <qdialog.h>
|
||||
#include <qdockwidget.h>
|
||||
#include <qmap.h>
|
||||
#include <qobject.h>
|
||||
#include <qtabwidget.h>
|
||||
|
||||
class QMainWindow;
|
||||
class QLineEdit;
|
||||
class G4UIsession;
|
||||
class QListWidget;
|
||||
class QTreeWidget;
|
||||
class QTreeWidgetItem;
|
||||
class QTextEdit;
|
||||
class QTextBrowser;
|
||||
class QLabel;
|
||||
class QResizeEvent;
|
||||
class QTabWidget;
|
||||
class QSplitter;
|
||||
class QToolBar;
|
||||
class QTableWidget;
|
||||
class QPixmap;
|
||||
class QComboBox;
|
||||
class QCompleter;
|
||||
class QtGlobal;
|
||||
class QStandardItemModel;
|
||||
class QToolButton;
|
||||
|
||||
// Class description :
|
||||
//
|
||||
// G4UIQt : class to handle a Qt interactive session.
|
||||
// G4UIQt is the Qt version of G4UIterminal.
|
||||
//
|
||||
// A command box is at disposal for entering/recalling Geant4 commands.
|
||||
// A menubar could be customized through the AddMenu, AddButton, AddIcon methods.
|
||||
// Note that there are corresponding Geant4 commands to add a
|
||||
// menus in the menubar and add buttons in a menu.
|
||||
// Ex :
|
||||
// /gui/addMenu test Test
|
||||
// /gui/addButton test Init /run/initialize
|
||||
// /gui/addButton test "Set gun" "/control/execute gun.g4m"
|
||||
// /gui/addButton test "Run one event" "/run/beamOn 1"
|
||||
//
|
||||
// Command completion, by typing "tab" key, is available on the
|
||||
// command line.
|
||||
//
|
||||
// Class description - end :
|
||||
|
||||
class G4QTabWidget : public QTabWidget
|
||||
{
|
||||
public:
|
||||
G4QTabWidget();
|
||||
G4QTabWidget(QWidget* aParent, G4int sizeX, G4int sizeY);
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
inline void setTabSelected(G4bool a) { fTabSelected = a; };
|
||||
inline void setLastTabCreated(G4int a) { fLastCreated = a; };
|
||||
inline bool isTabSelected() { return fTabSelected; };
|
||||
G4bool fTabSelected;
|
||||
G4int fLastCreated;
|
||||
G4int fPreferedSizeX;
|
||||
G4int fPreferedSizeY;
|
||||
inline void setPreferredSize(QSize s)
|
||||
{
|
||||
fPreferedSizeX = s.width() + 6; // tab label height + margin left+right
|
||||
fPreferedSizeY = s.height() + 58; // margin left+right
|
||||
}
|
||||
inline QSize sizeHint() const override { return QSize(fPreferedSizeX, fPreferedSizeY); }
|
||||
};
|
||||
|
||||
class G4UIOutputString
|
||||
{
|
||||
public:
|
||||
G4UIOutputString(QString text, G4String thread = "", G4String outputstream = "info");
|
||||
inline QString GetOutputList() { return " all info warning error "; };
|
||||
QString fText;
|
||||
G4String fThread;
|
||||
G4String fOutputStream; // Error, Warning, Info
|
||||
};
|
||||
|
||||
class G4UIDockWidget : public QDockWidget
|
||||
{
|
||||
public:
|
||||
G4UIDockWidget(QString txt);
|
||||
void closeEvent(QCloseEvent*) override;
|
||||
};
|
||||
|
||||
class G4UIQt : public QObject, public G4VBasicShell, public G4VInteractiveSession
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public: // With description
|
||||
// (argv, argc) or (0, NULL) had to be given.
|
||||
G4UIQt(G4int, char**);
|
||||
|
||||
// To enter interactive X loop ; waiting/executing command,...
|
||||
G4UIsession* SessionStart() override;
|
||||
|
||||
// To add a pulldown menu in the menu bar.
|
||||
// First argument is the name of the menu.
|
||||
// Second argument is the label of the cascade button.
|
||||
// Ex : AddMenu("my_menu","My menu")
|
||||
void AddMenu(const char*, const char*) override;
|
||||
|
||||
// To add a push button in a pulldown menu.
|
||||
// First argument is the name of the menu.
|
||||
// Second argument is the label of the button.
|
||||
// Third argument is the Geant4 command executed when the button is fired.
|
||||
// Ex : AddButton("my_menu","Run","/run/beamOn 1");
|
||||
void AddButton(const char*, const char*, const char*) override;
|
||||
|
||||
// To add a icon in the toolbar
|
||||
// First argument is the label of the icon.
|
||||
// Second argument is the selected icon type (open save move rotate pick zoom_in zoom_out
|
||||
// wireframe solid hidden_line_removal hidden_line_and_surface_removal perspective ortho
|
||||
// user_icon). Third argument is the Geant4 command executed when the button is fired. Fourth
|
||||
// argument is the path to the icon file if "user_icon" selected Ex : AddButton("change background
|
||||
// color","../background.xpm"," /vis/viewer/set/background");
|
||||
void AddIcon(const char* userLabel, const char* iconFile, const char* command,
|
||||
const char* file_name = "") override;
|
||||
|
||||
// Specify an output style - used by /gui/outputStyle
|
||||
// First argument destination ("cout" etc or "all")
|
||||
// Second argument is the required style - see guidance
|
||||
void SetOutputStyle(const char* destination, const char* style) override;
|
||||
|
||||
// Enable/Disable the native Menu Bar in Qt
|
||||
void NativeMenu(G4bool aVal) override;
|
||||
|
||||
// Clear Menu Bar, remove all actions
|
||||
void ClearMenu() override;
|
||||
|
||||
// Enable/Disable the default icon ToolBar in Qt
|
||||
void DefaultIcons(G4bool aVal) override;
|
||||
|
||||
// To add a tab for vis openGL Qt driver
|
||||
G4bool AddTabWidget(QWidget*, QString);
|
||||
|
||||
inline QTabWidget* GetViewerTabWidget() { return fViewerTabWidget; };
|
||||
|
||||
// Get the "old" scene tree component
|
||||
QWidget* GetSceneTreeWidget();
|
||||
|
||||
// Get the Viewer Properties Widget
|
||||
QWidget* GetViewerPropertiesWidget();
|
||||
|
||||
// Get the Pick Widget
|
||||
QWidget* GetPickInfosWidget();
|
||||
|
||||
G4bool IsSplitterReleased();
|
||||
|
||||
inline G4bool IsIconMoveSelected() { return fMoveSelected; };
|
||||
inline G4bool IsIconRotateSelected() { return fRotateSelected; };
|
||||
inline G4bool IsIconPickSelected() { return fPickSelected; };
|
||||
inline G4bool IsIconZoomInSelected() { return fZoomInSelected; };
|
||||
inline G4bool IsIconZoomOutSelected() { return fZoomOutSelected; };
|
||||
|
||||
void SetIconMoveSelected();
|
||||
void SetIconRotateSelected();
|
||||
void SetIconPickSelected();
|
||||
void SetIconZoomInSelected();
|
||||
void SetIconZoomOutSelected();
|
||||
void SetIconHLHSRSelected();
|
||||
void SetIconHLRSelected();
|
||||
void SetIconSolidSelected();
|
||||
void SetIconWireframeSelected();
|
||||
void SetIconPerspectiveSelected();
|
||||
void SetIconOrthoSelected();
|
||||
|
||||
// Return the main window
|
||||
inline QMainWindow* GetMainWindow() { return fMainWindow; };
|
||||
|
||||
// return the "search" icon pixmap
|
||||
inline QPixmap* getSearchIcon() { return fSearchIcon; };
|
||||
|
||||
// return the "clear" icon pixmap
|
||||
inline QPixmap* getClearIcon() { return fClearIcon; };
|
||||
|
||||
// Set the text on the first page of the viewer. If "", will take the last value as default
|
||||
// Note: Qt Rich text format could be used, see link for example :
|
||||
// https://qt-project.org/doc/qt-4.8/richtext-html-subset.html#table-cell-attributes
|
||||
void SetStartPage(const std::string&);
|
||||
|
||||
// Return the G4cout widget with filters
|
||||
inline QWidget* GetCoutWidget() { return fCoutDockWidget->widget(); };
|
||||
|
||||
// Return the cout dockable widget as a QDockWidget
|
||||
inline G4UIDockWidget* GetCoutDockWidget() { return fCoutDockWidget; };
|
||||
|
||||
// Return the UserInterface widget (including scene tree, help and History widgets)
|
||||
inline G4UIDockWidget* GetUserInterfaceWidget() { return fUIDockWidget; };
|
||||
|
||||
// return the viewer widget including all viewers
|
||||
inline QTabWidget* GetUITabWidget() { return fUITabWidget; }
|
||||
|
||||
// return the history widget
|
||||
inline QWidget* GetHistoryWidget() { return fHistoryTBWidget; }
|
||||
|
||||
// return the help widget
|
||||
inline QWidget* GetHelpWidget() { return fHelpTBWidget; }
|
||||
|
||||
// Add a new tab in the viewer, could be used to add your own component
|
||||
G4bool AddViewerTab(QWidget* w, std::string title);
|
||||
|
||||
// Add a new tab in the viewer containing the content of the file in a QLabel
|
||||
G4bool AddViewerTabFromFile(std::string fileName, std::string title);
|
||||
|
||||
// Update "new" scene tree
|
||||
void UpdateSceneTree(const G4SceneTreeItem&) override;
|
||||
|
||||
public:
|
||||
~G4UIQt() override;
|
||||
void Prompt(G4String);
|
||||
void SessionTerminate();
|
||||
void PauseSessionStart(const G4String&) override;
|
||||
G4int ReceiveG4debug(const G4String&) override;
|
||||
G4int ReceiveG4cout(const G4String&) override;
|
||||
G4int ReceiveG4cerr(const G4String&) override;
|
||||
// G4String GetCommand(Widget);
|
||||
|
||||
private:
|
||||
void SecondaryLoop(G4String); // a VIRER
|
||||
void CreateHelpWidget();
|
||||
void InitHelpTreeAndVisParametersWidget();
|
||||
void FillHelpTree();
|
||||
void UpdateCommandCompleter();
|
||||
void CreateIcons();
|
||||
void ExitHelp() const override;
|
||||
void SetDefaultIconsToolbar();
|
||||
|
||||
void CreateHelpTree(QTreeWidgetItem*, G4UIcommandTree*);
|
||||
QTreeWidgetItem* FindTreeItem(QTreeWidgetItem*, const QString&);
|
||||
|
||||
// Create the "mother" widget
|
||||
QWidget* CreateSceneTreeWidget();
|
||||
|
||||
// Classes/structs and functions for the "new" scene tree
|
||||
// UpdateSceneTree is in "public" section above.
|
||||
// Create and connect the new tree widget
|
||||
void CreateNewSceneTreeWidget();
|
||||
// Build Physical Volume tree of touchables
|
||||
void BuildPVQTree(const G4SceneTreeItem& g4stItem, QTreeWidgetItem* qtwItem);
|
||||
// Callbacks on new scene tree items
|
||||
void SceneTreeItemClicked(QTreeWidgetItem*);
|
||||
void SceneTreeItemDoubleClicked(QTreeWidgetItem*);
|
||||
void SceneTreeItemExpanded(QTreeWidgetItem*);
|
||||
void SceneTreeItemCollapsed(QTreeWidgetItem*);
|
||||
|
||||
QString GetCommandList(const G4UIcommand*);
|
||||
void updateHelpArea(const G4UIcommand*);
|
||||
G4bool GetHelpChoice(
|
||||
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
|
||||
QWidget* CreateVisParametersTBWidget();
|
||||
QWidget* CreateHelpTBWidget();
|
||||
G4UIDockWidget* CreateCoutTBWidget();
|
||||
QWidget* CreateHistoryTBWidget();
|
||||
G4UIDockWidget* CreateUITabWidget();
|
||||
void CreateViewerWidget();
|
||||
void OpenHelpTreeOnCommand(const QString&);
|
||||
QString GetShortCommandPath(QString);
|
||||
QString GetLongCommandPath(QTreeWidgetItem*);
|
||||
G4bool IsGUICommand(const G4UIcommand*);
|
||||
G4bool CreateVisCommandGroupAndToolBox(G4UIcommand*, QWidget*, G4int, G4bool isDialog);
|
||||
G4bool CreateCommandWidget(G4UIcommand* command, QWidget* parent, G4bool isDialog);
|
||||
void CreateViewerPropertiesDialog();
|
||||
void CreatePickInfosDialog();
|
||||
#ifdef G4MULTITHREADED
|
||||
void UpdateCoutThreadFilter();
|
||||
#endif
|
||||
void FilterAllOutputTextArea();
|
||||
QString FilterOutput(const G4UIOutputString&, const QString&, const QString&);
|
||||
G4String GetThreadPrefix();
|
||||
G4bool CheckG4EnvironmentVariable(char* txt, char* version);
|
||||
QStandardItemModel* CreateCompleterModel(G4String aCmd);
|
||||
void CreateEmptyViewerPropertiesWidget();
|
||||
void CreateEmptyPickInfosWidget();
|
||||
|
||||
private:
|
||||
QMainWindow* fMainWindow;
|
||||
QLabel* fCommandLabel;
|
||||
QLineEdit* fCommandArea;
|
||||
QTextEdit* fCoutTBTextArea;
|
||||
QTabWidget* fUITabWidget;
|
||||
std::vector<G4UIOutputString> fG4OutputString;
|
||||
QLineEdit* fCoutFilter;
|
||||
QCompleter* fCompleter;
|
||||
G4bool fDefaultIcons;
|
||||
|
||||
QListWidget* fHistoryTBTableList;
|
||||
QTreeWidget* fHelpTreeWidget;
|
||||
QWidget* fHelpTBWidget;
|
||||
QWidget* fHistoryTBWidget;
|
||||
G4UIDockWidget* fCoutDockWidget;
|
||||
G4UIDockWidget* fUIDockWidget;
|
||||
QWidget* fSceneTreeWidget;
|
||||
QWidget* fNewSceneTreeWidget;
|
||||
QTreeWidget* fNewSceneTreeItemTreeWidget;
|
||||
QWidget* fViewerPropertiesWidget;
|
||||
QWidget* fPickInfosWidget;
|
||||
QLineEdit* fHelpLine;
|
||||
G4QTabWidget* fViewerTabWidget;
|
||||
QString fCoutText;
|
||||
QTextBrowser* fStartPage;
|
||||
QSplitter* fHelpVSplitter;
|
||||
QTextEdit* fParameterHelpLabel;
|
||||
QTableWidget* fParameterHelpTable;
|
||||
|
||||
QToolBar* fToolbarApp;
|
||||
QToolBar* fToolbarUser;
|
||||
QString fStringSeparator;
|
||||
G4String fLastErrMessage;
|
||||
QString fLastOpenPath;
|
||||
QToolButton* fViewModePopupButton;
|
||||
QToolButton* fSurfaceModePopupButton;
|
||||
|
||||
QPixmap* fSearchIcon;
|
||||
QPixmap* fClearIcon;
|
||||
QPixmap* fSaveIcon;
|
||||
QPixmap* fOpenIcon;
|
||||
QPixmap* fMoveIcon;
|
||||
QPixmap* fRotateIcon;
|
||||
QPixmap* fPickIcon;
|
||||
QPixmap* fZoomInIcon;
|
||||
QPixmap* fZoomOutIcon;
|
||||
QPixmap* fWireframeIcon;
|
||||
QPixmap* fSolidIcon;
|
||||
QPixmap* fHiddenLineRemovalIcon;
|
||||
QPixmap* fHiddenLineAndSurfaceRemovalIcon;
|
||||
QPixmap* fPerspectiveIcon;
|
||||
QPixmap* fOrthoIcon;
|
||||
QPixmap* fCommandIcon;
|
||||
QPixmap* fDirIcon;
|
||||
QPixmap* fRunIcon;
|
||||
QPixmap* fParamIcon;
|
||||
QPixmap* fPickTargetIcon;
|
||||
QPixmap* fExitIcon;
|
||||
|
||||
#ifdef G4MULTITHREADED
|
||||
QComboBox* fThreadsFilterComboBox;
|
||||
#endif
|
||||
std::string fDefaultViewerFirstPageHTMLText;
|
||||
|
||||
QDialog* fViewerPropertiesDialog;
|
||||
QDialog* fPickInfosDialog;
|
||||
QString fLastCompleteCommand;
|
||||
G4bool fMoveSelected;
|
||||
G4bool fRotateSelected;
|
||||
G4bool fPickSelected;
|
||||
G4bool fZoomInSelected;
|
||||
G4bool fZoomOutSelected;
|
||||
|
||||
private Q_SLOTS:
|
||||
void ExitSession();
|
||||
void ClearButtonCallback();
|
||||
void SaveOutputCallback();
|
||||
void CommandEnteredCallback();
|
||||
void CommandEditedCallback(const QString& text);
|
||||
void ButtonCallback(const QString&);
|
||||
void HelpTreeClicCallback();
|
||||
void HelpTreeDoubleClicCallback();
|
||||
void ShowHelpCallback();
|
||||
void CommandHistoryCallback();
|
||||
void LookForHelpStringCallback();
|
||||
void UpdateTabWidget(int);
|
||||
void ResizeTabWidget(QResizeEvent*);
|
||||
void CoutFilterCallback(const QString&);
|
||||
void ThreadComboBoxCallback(int);
|
||||
void TabCloseCallback(int);
|
||||
void ToolBoxActivated(int);
|
||||
void VisParameterCallback(QWidget*);
|
||||
void ChangeColorCallback(QWidget*);
|
||||
void ChangeCursorAction(const QString&);
|
||||
void ChangeSurfaceStyle(const QString&);
|
||||
void OpenIconCallback(const QString&);
|
||||
void SaveIconCallback(const QString&);
|
||||
void ViewerPropertiesIconCallback(int);
|
||||
void ChangePerspectiveOrtho(const QString&);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,182 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4UIWin32
|
||||
//
|
||||
// Class description :
|
||||
//
|
||||
// G4UIWin32 is a class to handle a Windows interactive session.
|
||||
// It is the Windows version of G4UIterminal.
|
||||
//
|
||||
// A command box is at disposal for entering/recalling Geant4 commands.
|
||||
// A menubar could be customized through the AddMenu, AddButton methods.
|
||||
// Note that there are corresponding Geant4 commands to add a
|
||||
// menu in the menubar and add buttons in a menu.
|
||||
// Ex :
|
||||
// /gui/addMenu test Test
|
||||
// /gui/addButton test Init /run/initialize
|
||||
// /gui/addButton test "Set gun" "/control/execute gun.g4m"
|
||||
// /gui/addButton test "Run one event" "/run/beamOn 1"
|
||||
//
|
||||
// Command completion, by typing "tab" key, is available on the
|
||||
// command line.
|
||||
|
||||
// Original author: G.Barrand, 1998
|
||||
// Revised: O.Pena-Rodriguez, March 2021
|
||||
// -------------------------------------------------------------------
|
||||
#ifndef G4UIWin32_h
|
||||
#define G4UIWin32_h
|
||||
|
||||
#define ID_EXIT_APP 40001
|
||||
#define ID_OPEN_MACRO 40002
|
||||
#define ID_SAVE_VIEWER_STATE 40003
|
||||
#define ID_RUN_BEAMON 40004
|
||||
#define ID_RUN_CMD 40005
|
||||
#define ID_VIEW_SOLID 40006
|
||||
#define ID_VIEW_WIREFRAME 40007
|
||||
#define ID_PROJ_ORTHOGRAPHIC 40008
|
||||
#define ID_PROJ_PERSPECTIVE 40009
|
||||
#define ID_ZOOM_IN 40010
|
||||
#define ID_ZOOM_OUT 40011
|
||||
#define ID_ORIENTATION_XY 40012
|
||||
#define ID_ORIENTATION_XZ 40013
|
||||
#define ID_ORIENTATION_YZ 40014
|
||||
#define ID_ORIENTATION_OBLIQUE 40015
|
||||
#define ID_HELP_ABOUT 40016
|
||||
#define ID_LOG_CLEAN 40017
|
||||
#define ID_LOG_SAVE 40018
|
||||
|
||||
#define NUM_BUTTONS 12
|
||||
#define MAX_HISTORY_ITEMS 10
|
||||
|
||||
#define IDC_MAIN_EDIT 101
|
||||
#define IDC_MAIN_TOOL 102
|
||||
#define IDC_MAIN_TREE_VIEW 104
|
||||
#define IDC_MAIN_COMBO 105
|
||||
#define IDC_MAIN_STATUS 106
|
||||
|
||||
#include "G4VBasicShell.hh"
|
||||
#include "G4VInteractiveSession.hh"
|
||||
#include "G4Win32.hh"
|
||||
|
||||
#include <CommCtrl.h>
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
class G4VInteractorManager;
|
||||
|
||||
class G4UIWin32 : public G4VBasicShell, public G4VInteractiveSession
|
||||
{
|
||||
public:
|
||||
G4UIWin32();
|
||||
~G4UIWin32() override;
|
||||
|
||||
// To enter interactive Win32 loop ; waiting/executing command,...
|
||||
G4UIsession* SessionStart() override;
|
||||
|
||||
// To add a pulldown menu in the menu bar.
|
||||
// First argument is the name of the menu.
|
||||
// Second argument is the label of the cascade button.
|
||||
// Ex : AddMenu("my_menu","My menu")
|
||||
void AddMenu(const char*, const char*) override;
|
||||
|
||||
// To add a push button in a pulldown menu.
|
||||
// First argument is the name of the menu.
|
||||
// Second argument is the label of the button.
|
||||
// Third argument is the Geant4 command executed when the button is fired.
|
||||
// Ex : AddButton("my_menu","Run","/run/beamOn 1");
|
||||
void AddButton(const char*, const char*, const char*) override;
|
||||
|
||||
void Prompt(const G4String&);
|
||||
void SessionTerminate();
|
||||
void PauseSessionStart(const G4String&) override;
|
||||
|
||||
G4int ReceiveG4debug(const G4String&) override;
|
||||
G4int ReceiveG4cout(const G4String&) override;
|
||||
G4int ReceiveG4cerr(const G4String&) override;
|
||||
|
||||
G4String GetCommand(G4int);
|
||||
// void TextAppendString(char*);
|
||||
|
||||
private:
|
||||
void SecondaryLoop(const G4String&);
|
||||
G4bool GetHelpChoice(G4int&) override;
|
||||
void ExitHelp() const override;
|
||||
|
||||
G4bool CreateComponents(HWND);
|
||||
G4bool ResizeComponents(HWND);
|
||||
void ProcessTabKey();
|
||||
void ProcessEscKey();
|
||||
void ProcessEnterKey();
|
||||
void ProcessUpKey();
|
||||
void ProcessDownKey();
|
||||
|
||||
G4bool ProcessDefaultCommands(G4int);
|
||||
static G4String GetToolTips(G4int);
|
||||
G4String GetHelpTreeToolTips(HTREEITEM);
|
||||
|
||||
static G4String ConvertNewLines(G4String);
|
||||
|
||||
void HelpTreeDoubleClick(HTREEITEM);
|
||||
|
||||
G4bool SaveLogFile(LPCTSTR);
|
||||
void AddText(LPSTR);
|
||||
|
||||
void DoOpenMacro(HWND);
|
||||
void DoSaveViewer(HWND);
|
||||
void DoSaveLog(HWND);
|
||||
|
||||
G4bool InitHelpTreeItems();
|
||||
HTREEITEM AddItemToHelpTree(LPTSTR, HTREEITEM = TVI_ROOT);
|
||||
static G4String GetShortCommandPath(G4String);
|
||||
LPSTR GetItemPath(HTREEITEM);
|
||||
|
||||
void CreateHelpTree(HTREEITEM, G4UIcommandTree*);
|
||||
|
||||
private:
|
||||
HWND fHWndMainWindow;
|
||||
HWND fHWndEditor;
|
||||
HWND fHWndToolBar;
|
||||
HWND fHWndComboBox;
|
||||
HWND fHWndComboEditor;
|
||||
HWND fHWndHelpTree;
|
||||
HWND fHWndStatus;
|
||||
|
||||
G4VInteractorManager* interactorManager;
|
||||
HMENU menuBar;
|
||||
std::map<G4int, G4String, std::less<G4int>> commands;
|
||||
|
||||
static LRESULT CALLBACK MainWindowProc(HWND, UINT, WPARAM, LPARAM);
|
||||
// New wndproc for the combo box
|
||||
static LRESULT CALLBACK ComboEditorWindowProc(HWND, UINT, WPARAM, LPARAM);
|
||||
|
||||
G4bool fHelp;
|
||||
G4int fHelpChoice;
|
||||
std::vector<G4String> fHistory;
|
||||
G4int fHistoryPos;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,106 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
#ifndef G4UIXm_h
|
||||
#define G4UIXm_h
|
||||
|
||||
#include "G4VBasicShell.hh"
|
||||
#include "G4VInteractiveSession.hh"
|
||||
|
||||
#include <X11/Intrinsic.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
class G4UIsession;
|
||||
|
||||
// Class description :
|
||||
//
|
||||
// G4UIXm : class to handle a Motif interactive session.
|
||||
// G4UIXm is the Motif version of G4UIterminal.
|
||||
//
|
||||
// A command box is at disposal for entering/recalling Geant4 commands.
|
||||
// A menubar could be customized through the AddMenu, AddButton methods.
|
||||
// Note that there are corresponding Geant4 commands to add a
|
||||
// menus in the menubar and add buttons in a menu.
|
||||
// Ex :
|
||||
// /gui/addMenu test Test
|
||||
// /gui/addButton test Init /run/initialize
|
||||
// /gui/addButton test "Set gun" "/control/execute gun.g4m"
|
||||
// /gui/addButton test "Run one event" "/run/beamOn 1"
|
||||
//
|
||||
// Command completion, by typing "tab" key, is available on the
|
||||
// command line.
|
||||
//
|
||||
// Class description - end :
|
||||
|
||||
class G4UIXm : public G4VBasicShell, public G4VInteractiveSession
|
||||
{
|
||||
public: // With description
|
||||
// (argv, argc) or (0, NULL) had to be given.
|
||||
G4UIXm(G4int, char**);
|
||||
~G4UIXm();
|
||||
|
||||
// To enter interactive X loop ; waiting/executing command,...
|
||||
G4UIsession* SessionStart();
|
||||
|
||||
// To add a pulldown menu in the menu bar.
|
||||
// First argument is the name of the menu.
|
||||
// Second argument is the label of the cascade button.
|
||||
// Ex : AddMenu("my_menu","My menu")
|
||||
void AddMenu(const char*, const char*);
|
||||
|
||||
// To add a push button in a pulldown menu.
|
||||
// First argument is the name of the menu.
|
||||
// Second argument is the label of the button.
|
||||
// Third argument is the Geant4 command executed when the button is fired.
|
||||
// Ex : AddButton("my_menu","Run","/run/beamOn 1");
|
||||
void AddButton(const char*, const char*, const char*);
|
||||
|
||||
void Prompt(G4String);
|
||||
void SessionTerminate();
|
||||
virtual void PauseSessionStart(const G4String&);
|
||||
virtual G4int ReceiveG4debug(const G4String&);
|
||||
virtual G4int ReceiveG4cout(const G4String&);
|
||||
virtual G4int ReceiveG4cerr(const G4String&);
|
||||
G4String GetCommand(Widget);
|
||||
|
||||
private:
|
||||
void SecondaryLoop(G4String);
|
||||
G4bool GetHelpChoice(G4int&);
|
||||
void ExitHelp() const;
|
||||
static void CommandEnteredCallback(Widget, XtPointer, XtPointer);
|
||||
static void keyHandler(Widget, XtPointer, XEvent*, Boolean*);
|
||||
static void ButtonCallback(Widget, XtPointer, XtPointer);
|
||||
|
||||
Widget form, shell, command, menuBar, text;
|
||||
std::map<Widget, G4String, std::less<Widget>> commands;
|
||||
G4bool fHelp;
|
||||
G4int fHelpChoice;
|
||||
G4String menu_str[6] = {"form", "menuBar", "command", "Clear", "clearButton", "text"};
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4Win32
|
||||
//
|
||||
// Class description :
|
||||
//
|
||||
// A singleton to handle GUI sessions and visualization
|
||||
// drivers built over Windows. It allows to have one Windows main
|
||||
// loop for the whole application.
|
||||
// Unifies Windows message treatment between G4/interfaces Windows
|
||||
// sessions and G4/visualizations Windows drivers.
|
||||
|
||||
// Original author: G.Barrand, 1998
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4WIN32_HH
|
||||
#define G4WIN32_HH
|
||||
|
||||
#include "G4VInteractorManager.hh"
|
||||
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
class G4Win32 : public G4VInteractorManager
|
||||
{
|
||||
public:
|
||||
static G4Win32* getInstance();
|
||||
G4bool Inited();
|
||||
void* GetEvent();
|
||||
void FlushAndWaitExecution();
|
||||
static G4bool DispatchWin32Event(void*);
|
||||
virtual ~G4Win32();
|
||||
|
||||
private:
|
||||
G4Win32();
|
||||
static G4Win32* instance; // Pointer to single instance.
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
// To unify X11 event treatment between
|
||||
// G4/interfaces Xt sessions and G4/visualizations Xt drivers.
|
||||
// G.Barrand
|
||||
|
||||
#ifndef G4XT_HH
|
||||
#define G4XT_HH
|
||||
|
||||
#include "G4VInteractorManager.hh"
|
||||
|
||||
#include <X11/Intrinsic.h>
|
||||
|
||||
// Class description :
|
||||
//
|
||||
// G4Xt : a singleton to handle GUI sessions and visualization
|
||||
// drivers built over Xt. It permits to have one Xt main loop for
|
||||
// the whole application. The Xt toolkit is inited in the
|
||||
// constructor. It is done once for the whole application.
|
||||
//
|
||||
// Class description - end :
|
||||
|
||||
class G4Xt : public G4VInteractorManager
|
||||
{
|
||||
public:
|
||||
static G4Xt* getInstance();
|
||||
static G4Xt* getInstance(int, char**, char*);
|
||||
void PutStringInResourceDatabase(char*);
|
||||
G4bool Inited();
|
||||
void* GetEvent();
|
||||
void FlushAndWaitExecution();
|
||||
virtual ~G4Xt();
|
||||
// Workaround for gcc8 Coverity cast warning
|
||||
static bool xt_dispatch_event(void* a_event) { return XtDispatchEvent((XEvent*)a_event); }
|
||||
|
||||
private:
|
||||
G4Xt(const G4Xt&);
|
||||
G4Xt(int, char**, char*);
|
||||
G4Xt& operator=(const G4Xt&);
|
||||
static G4Xt* instance; // Pointer to single instance.
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
# - G4UIimplementation module build definition
|
||||
|
||||
# Define the Geant4 Module.
|
||||
geant4_add_module(G4UIimplementation PUBLIC_HEADERS G4UIExecutive.hh SOURCES G4UIExecutive.cc)
|
||||
geant4_module_link_libraries(G4UIimplementation PUBLIC G4UIcore PRIVATE G4intercoms G4globman)
|
||||
|
||||
# Win32 terminal only for MSVC builds, but always built here
|
||||
# ... not in G4UIcore because of the requirement to have G4Win32 interactor manager
|
||||
if(MSVC)
|
||||
geant4_module_sources(G4UIimplementation PUBLIC_HEADERS G4UIWin32.hh G4Win32.hh SOURCES G4UIWin32.cc G4Win32.cc)
|
||||
geant4_module_compile_definitions(G4UIimplementation
|
||||
PUBLIC G4UI_USE_WIN32
|
||||
PRIVATE G4UI_BUILD_WIN32_SESSION)
|
||||
geant4_module_link_libraries(G4UIimplementation PUBLIC COMCTL32)
|
||||
endif()
|
||||
|
||||
# Qt only if selected.
|
||||
if(GEANT4_USE_QT)
|
||||
geant4_module_sources(G4UIimplementation PUBLIC_HEADERS G4UIQt.hh G4Qt.hh SOURCES G4UIQt.cc G4Qt.cc)
|
||||
geant4_module_compile_definitions(G4UIimplementation
|
||||
PUBLIC G4UI_USE_QT
|
||||
PRIVATE G4UI_BUILD_QT_SESSION)
|
||||
geant4_module_link_libraries(G4UIimplementation PUBLIC G4graphics_reps Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Core)
|
||||
|
||||
# Coupling...
|
||||
if(GEANT4_USE_VTK)
|
||||
geant4_module_compile_definitions(G4UIimplementation PRIVATE G4VIS_USE_VTK_QT)
|
||||
geant4_module_link_libraries(G4UIimplementation PRIVATE ${VTK_LIBRARIES})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Xm and only on UNIX and if selected
|
||||
if(UNIX AND GEANT4_USE_XM)
|
||||
geant4_module_sources(G4UIimplementation PUBLIC_HEADERS G4UIXm.hh G4Xt.hh SOURCES G4UIXm.cc G4Xt.cc)
|
||||
geant4_module_compile_definitions(G4UIimplementation
|
||||
PUBLIC G4UI_USE_XM
|
||||
PRIVATE G4UI_BUILD_XM_SESSION)
|
||||
geant4_module_link_libraries(G4UIimplementation
|
||||
PUBLIC
|
||||
Motif::Xm
|
||||
X11::SM X11::ICE X11::X11 X11::Xext X11::Xmu X11::Xt)
|
||||
endif()
|
||||
@@ -0,0 +1,188 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
// L. Garnier
|
||||
|
||||
#include "G4Qt.hh"
|
||||
|
||||
#include "G4UImanager.hh"
|
||||
#include "G4ios.hh"
|
||||
|
||||
#include <qapplication.h>
|
||||
#include <qwidget.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#ifdef G4VIS_USE_VTK_QT
|
||||
# include "QVTKOpenGLNativeWidget.h"
|
||||
# include <qsurfaceformat.h>
|
||||
#endif
|
||||
|
||||
G4Qt* G4Qt::instance = nullptr;
|
||||
|
||||
static G4bool QtInited = false;
|
||||
|
||||
/***************************************************************************/
|
||||
G4Qt* G4Qt::getInstance()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
return G4Qt::getInstance(0, nullptr, (char*)"Geant4");
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4Qt* G4Qt::getInstance(int a_argn, char** a_args, char* a_class)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (instance == nullptr) {
|
||||
instance = new G4Qt(a_argn, a_args, a_class);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4Qt::G4Qt(int a_argn, char** a_args, char* /*a_class */
|
||||
)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
argn = 0;
|
||||
args = nullptr;
|
||||
externalApp = false;
|
||||
|
||||
// Check if Qt already init in another external app
|
||||
if (qApp) {
|
||||
externalApp = true;
|
||||
QtInited = true;
|
||||
SetMainInteractor(qApp);
|
||||
SetArguments(a_argn, a_args);
|
||||
}
|
||||
else {
|
||||
if (! QtInited) { // Qt should be Inited once !
|
||||
// Then two cases :
|
||||
// - It is the first time we create G4UI (argc!=0)
|
||||
// -> Inited and register
|
||||
// - It is the first time we create G4VIS (argc == 0)
|
||||
// -> Inited and NOT register
|
||||
|
||||
if (a_argn != 0) {
|
||||
argn = a_argn;
|
||||
args = a_args;
|
||||
}
|
||||
else { // argc = 0
|
||||
|
||||
// FIXME : That's not the good arguments, but I don't know how to get args from other
|
||||
// Interactor. Ex: How to get them from G4Xt ?
|
||||
argn = 1;
|
||||
args = (char**)malloc(1 * sizeof(char*));
|
||||
args[0] = (char*)malloc(10 * sizeof(char));
|
||||
strncpy(args[0], "my_app \0", 9);
|
||||
}
|
||||
|
||||
int* p_argn = (int*)malloc(sizeof(int));
|
||||
*p_argn = argn;
|
||||
#ifdef WIN32
|
||||
qApp->setAttribute(Qt::AA_UseDesktopOpenGL);
|
||||
#endif
|
||||
|
||||
#ifdef G4VIS_USE_VTK_QT
|
||||
QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat());
|
||||
#endif
|
||||
new QApplication(*p_argn, args);
|
||||
if (! qApp) {
|
||||
G4UImanager* UImanager = G4UImanager::GetUIpointer();
|
||||
G4int verbose = UImanager->GetVerboseLevel();
|
||||
if (verbose >= 2) {
|
||||
G4cout << "G4Qt : Unable to init Qt." << G4endl;
|
||||
}
|
||||
}
|
||||
else {
|
||||
QtInited = true;
|
||||
if (a_argn != 0) {
|
||||
SetMainInteractor(qApp);
|
||||
}
|
||||
SetArguments(a_argn, a_args);
|
||||
}
|
||||
}
|
||||
}
|
||||
// AddDispatcher ((G4DispatchFunction)XtDispatchEvent);
|
||||
|
||||
/*
|
||||
* On some non-English locale, comma is used for the decimal separator instead of dot
|
||||
* bringing to weird behavior of strtod (string to double) function in user application.
|
||||
* This is "by design" from Qt, see https://bugreports.qt-project.org/browse/QTBUG-10994
|
||||
*
|
||||
* $ LC_NUMERIC=fr_FR.UTF-8 ./qtstrtod
|
||||
* strtod(0.1) = 0
|
||||
* $ LC_NUMERIC=C ./qtstrtod
|
||||
* strtod(0.1) = 0.1
|
||||
*
|
||||
* Jerome Suhard, jerome@suhard.fr
|
||||
*/
|
||||
|
||||
// explicitly set the LC_NUMBERIC locale to "C"
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4Qt::~G4Qt()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (this == instance) {
|
||||
instance = nullptr;
|
||||
}
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4bool G4Qt::Inited()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
return QtInited;
|
||||
}
|
||||
/***************************************************************************/
|
||||
void* G4Qt::GetEvent()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
/***************************************************************************/
|
||||
void G4Qt::FlushAndWaitExecution()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (! qApp) return;
|
||||
qApp->processEvents();
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
bool G4Qt::IsExternalApp()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
return externalApp;
|
||||
}
|
||||
@@ -0,0 +1,295 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
|
||||
#include "G4UIExecutive.hh"
|
||||
|
||||
#include "G4UImanager.hh"
|
||||
#include "G4UIsession.hh"
|
||||
|
||||
#if defined(G4UI_BUILD_QT_SESSION)
|
||||
# include "G4Qt.hh"
|
||||
# include "G4UIQt.hh"
|
||||
#endif
|
||||
|
||||
#if defined(G4UI_BUILD_XM_SESSION)
|
||||
# include "G4UIXm.hh"
|
||||
#endif
|
||||
|
||||
#if defined(G4UI_BUILD_WIN32_SESSION)
|
||||
# include "G4UIWin32.hh"
|
||||
#endif
|
||||
|
||||
#include "G4TiMemory.hh"
|
||||
#include "G4UIcsh.hh"
|
||||
#include "G4UItcsh.hh"
|
||||
#include "G4UIterminal.hh"
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// build flags as variables
|
||||
|
||||
#if defined(G4UI_BUILD_QT_SESSION)
|
||||
static const G4bool qt_build = true;
|
||||
#else
|
||||
static const G4bool qt_build = false;
|
||||
#endif
|
||||
|
||||
#if defined(G4UI_BUILD_XM_SESSION)
|
||||
static const G4bool xm_build = true;
|
||||
#else
|
||||
static const G4bool xm_build = false;
|
||||
#endif
|
||||
|
||||
#if defined(G4UI_BUILD_WIN32_SESSION)
|
||||
static const G4bool win32_build = true;
|
||||
#else
|
||||
static const G4bool win32_build = false;
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
static const G4bool tcsh_build = true;
|
||||
#else
|
||||
static const G4bool tcsh_build = false;
|
||||
#endif
|
||||
|
||||
#define DISCARD_PARAMETER(p) (void)p
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
G4UIExecutive::G4UIExecutive(G4int argc, char** argv, const G4String& type)
|
||||
: selected(kNone), session(nullptr), shell(nullptr), isGUI(false), verbose(true)
|
||||
{
|
||||
if (verbose) {
|
||||
G4cout << "Available UI session types: [ ";
|
||||
if (qt_build) G4cout << "Qt, ";
|
||||
if (xm_build) G4cout << "Xm, ";
|
||||
if (win32_build) G4cout << "Win32, ";
|
||||
if (tcsh_build) G4cout << "tcsh, ";
|
||||
G4cout << "csh ]" << G4endl;
|
||||
}
|
||||
|
||||
// selecting session type...
|
||||
// 1st priority : in case argumant specified
|
||||
G4String stype = G4StrUtil::to_lower_copy(type); // session type is case-insensitive.
|
||||
if (! type.empty()) SelectSessionByArg(stype);
|
||||
|
||||
// 2nd priority : refer environment variables (as backword compatibility)
|
||||
if (selected == kNone) SelectSessionByEnv();
|
||||
|
||||
// 3rd priority : refer $HOME/.g4session
|
||||
if (selected == kNone) {
|
||||
G4String appinput = argv[0];
|
||||
G4String appname = "";
|
||||
size_t islash = appinput.find_last_of("/\\");
|
||||
if (islash == G4String::npos)
|
||||
appname = appinput;
|
||||
else
|
||||
appname = appinput.substr(islash + 1, appinput.size() - islash - 1);
|
||||
|
||||
SelectSessionByFile(appname);
|
||||
}
|
||||
|
||||
// 4th, best guess of session type
|
||||
if (selected == kNone) SelectSessionByBestGuess();
|
||||
|
||||
// instantiate a session...
|
||||
switch (selected) {
|
||||
case kQt:
|
||||
#if defined(G4UI_BUILD_QT_SESSION)
|
||||
session = new G4UIQt(argc, argv);
|
||||
isGUI = true;
|
||||
#endif
|
||||
break;
|
||||
case kXm:
|
||||
#if defined(G4UI_BUILD_XM_SESSION)
|
||||
session = new G4UIXm(argc, argv);
|
||||
isGUI = true;
|
||||
#endif
|
||||
break;
|
||||
case kWin32:
|
||||
#if defined(G4UI_BUILD_WIN32_SESSION)
|
||||
DISCARD_PARAMETER(argc);
|
||||
DISCARD_PARAMETER(argv);
|
||||
session = new G4UIWin32();
|
||||
isGUI = true;
|
||||
#endif
|
||||
break;
|
||||
case kTcsh:
|
||||
#if ! (defined(WIN32) || defined(__MINGW32__))
|
||||
DISCARD_PARAMETER(argc);
|
||||
DISCARD_PARAMETER(argv);
|
||||
shell = new G4UItcsh;
|
||||
session = new G4UIterminal(shell);
|
||||
#endif
|
||||
break;
|
||||
case kCsh:
|
||||
DISCARD_PARAMETER(argc);
|
||||
DISCARD_PARAMETER(argv);
|
||||
shell = new G4UIcsh;
|
||||
session = new G4UIterminal(shell);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// fallback (csh)
|
||||
if (session == nullptr) {
|
||||
G4Exception("G4UIExecutive::G4UIExecutive()", "UI0002", JustWarning,
|
||||
"Specified session type is not build in your system,\n"
|
||||
"or no session type is specified.\n"
|
||||
"A fallback session type is used.");
|
||||
|
||||
selected = kCsh;
|
||||
DISCARD_PARAMETER(argc);
|
||||
DISCARD_PARAMETER(argv);
|
||||
shell = new G4UIcsh;
|
||||
session = new G4UIterminal(shell);
|
||||
}
|
||||
|
||||
TIMEMORY_INIT(argc, argv);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
G4UIExecutive::~G4UIExecutive() { delete session; }
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
void G4UIExecutive::SelectSessionByArg(const G4String& stype)
|
||||
{
|
||||
if (qt_build && stype == "qt")
|
||||
selected = kQt;
|
||||
else if (xm_build && stype == "xm")
|
||||
selected = kXm;
|
||||
else if (win32_build && stype == "win32")
|
||||
selected = kWin32;
|
||||
else if (tcsh_build && stype == "tcsh")
|
||||
selected = kTcsh;
|
||||
else if (stype == "csh")
|
||||
selected = kCsh;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
void G4UIExecutive::SelectSessionByEnv()
|
||||
{
|
||||
if (qt_build && (std::getenv("G4UI_USE_QT") != nullptr))
|
||||
selected = kQt;
|
||||
else if (xm_build && (std::getenv("G4UI_USE_XM") != nullptr))
|
||||
selected = kXm;
|
||||
else if (win32_build && (std::getenv("G4UI_USE_WIN32") != nullptr))
|
||||
selected = kWin32;
|
||||
else if (tcsh_build && (std::getenv("G4UI_USE_TCSH") != nullptr))
|
||||
selected = kTcsh;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
void G4UIExecutive::SelectSessionByFile(const G4String& appname)
|
||||
{
|
||||
const char* path = std::getenv("HOME");
|
||||
if (path == nullptr) return;
|
||||
G4String homedir = path;
|
||||
|
||||
#ifndef WIN32
|
||||
G4String fname = homedir + "/.g4session";
|
||||
#else
|
||||
G4String fname = homedir + "\\.g4session";
|
||||
#endif
|
||||
|
||||
std::ifstream fsession;
|
||||
enum
|
||||
{
|
||||
BUFSIZE = 1024
|
||||
};
|
||||
char linebuf[BUFSIZE];
|
||||
|
||||
fsession.open(fname, std::ios::in);
|
||||
|
||||
G4String default_session = "";
|
||||
G4int iline = 1;
|
||||
sessionMap.clear();
|
||||
while (fsession.good()) {
|
||||
if (fsession.eof()) break;
|
||||
fsession.getline(linebuf, BUFSIZE);
|
||||
G4String aline = G4StrUtil::strip_copy(linebuf);
|
||||
if (aline[0] == '#') continue;
|
||||
if (aline.empty()) continue;
|
||||
if (iline == 1)
|
||||
default_session = aline;
|
||||
else {
|
||||
size_t idx = aline.find_first_of(' ');
|
||||
if (idx == G4String::npos) break;
|
||||
G4String aname = aline.substr(0, idx);
|
||||
idx = aline.find_first_not_of(' ', idx);
|
||||
if (idx == G4String::npos) break;
|
||||
G4String sname = aline.substr(idx, aline.size() - idx);
|
||||
sessionMap[aname] = sname;
|
||||
}
|
||||
iline++;
|
||||
}
|
||||
fsession.close();
|
||||
|
||||
G4String stype = "";
|
||||
auto it = sessionMap.find(appname);
|
||||
if (it != sessionMap.end())
|
||||
stype = sessionMap[appname];
|
||||
else
|
||||
stype = default_session;
|
||||
G4StrUtil::to_lower(stype);
|
||||
|
||||
// select session...
|
||||
if (qt_build && stype == "qt")
|
||||
selected = kQt;
|
||||
else if (xm_build && stype == "xm")
|
||||
selected = kXm;
|
||||
else if (win32_build && stype == "win32")
|
||||
selected = kWin32;
|
||||
else if (tcsh_build && stype == "tcsh")
|
||||
selected = kTcsh;
|
||||
else if (stype == "csh")
|
||||
selected = kCsh;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
void G4UIExecutive::SelectSessionByBestGuess()
|
||||
{
|
||||
if (qt_build)
|
||||
selected = kQt;
|
||||
else if (win32_build)
|
||||
selected = kWin32;
|
||||
else if (tcsh_build)
|
||||
selected = kTcsh;
|
||||
else if (xm_build)
|
||||
selected = kXm;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
void G4UIExecutive::SetPrompt(const G4String& prompt)
|
||||
{
|
||||
if (shell != nullptr) shell->SetPrompt(prompt);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
void G4UIExecutive::SetLsColor(TermColorIndex dirColor, TermColorIndex cmdColor)
|
||||
{
|
||||
if (shell != nullptr) shell->SetLsColor(dirColor, cmdColor);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
void G4UIExecutive::SessionStart() { session->SessionStart(); }
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,441 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
// G.Barrand
|
||||
|
||||
// #define DEBUG
|
||||
|
||||
#include "G4UIXm.hh"
|
||||
|
||||
#include "G4StateManager.hh"
|
||||
#include "G4Types.hh"
|
||||
#include "G4UIcommandStatus.hh"
|
||||
#include "G4UIcommandTree.hh"
|
||||
#include "G4UImanager.hh"
|
||||
#include "G4Xt.hh"
|
||||
|
||||
#include <X11/Intrinsic.h>
|
||||
#include <X11/Shell.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <Xm/CascadeB.h>
|
||||
#include <Xm/Command.h>
|
||||
#include <Xm/Form.h>
|
||||
#include <Xm/PushB.h>
|
||||
#include <Xm/RowColumn.h>
|
||||
#include <Xm/Text.h>
|
||||
#include <Xm/Xm.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static void XmTextAppendString(Widget, char*);
|
||||
|
||||
static void clearButtonCallback(Widget, XtPointer, XtPointer);
|
||||
|
||||
static char* XmConvertCompoundStringToString(XmString, G4int);
|
||||
static G4bool ConvertStringToInt(const char*, G4int&);
|
||||
static void ExecuteChangeSizeFunction(Widget);
|
||||
|
||||
static G4bool exitSession = true;
|
||||
static G4bool exitPause = true;
|
||||
static G4bool exitHelp = true;
|
||||
/***************************************************************************/
|
||||
G4UIXm::G4UIXm(G4int argc, char** argv)
|
||||
: shell(NULL), command(NULL), menuBar(NULL), text(NULL), fHelp(false), fHelpChoice(0)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
G4UImanager* UI = G4UImanager::GetUIpointer();
|
||||
if (UI != NULL) UI->SetSession(this);
|
||||
|
||||
G4Xt* interactorManager = G4Xt::getInstance(argc, argv, (char*)"Xm");
|
||||
|
||||
Widget top = (Widget)interactorManager->GetMainInteractor();
|
||||
|
||||
if (std::getenv("XENVIRONMENT") == NULL) {
|
||||
XrmDatabase database = XrmGetDatabase(XtDisplay(top));
|
||||
if (database != NULL) {
|
||||
XrmPutLineResource(&database, "*topShadowColor:white");
|
||||
XrmPutLineResource(&database, "*bottomShadowColor:black");
|
||||
XrmPutLineResource(&database, "*foreground:black");
|
||||
XrmPutLineResource(&database, "*background:lightgrey");
|
||||
XrmPutLineResource(&database, "*borderColor:lightgrey");
|
||||
XrmPutLineResource(&database, "*fontList:-*-helvetica-bold-r-*-*-*-120-*-*-*-*-iso8859-1");
|
||||
XrmPutLineResource(&database, "*text.background:white");
|
||||
XrmPutLineResource(&database, "*text.fontList:*courier*-r-*--14-*");
|
||||
XrmPutLineResource(&database, "*text.maxLength:8000");
|
||||
}
|
||||
}
|
||||
|
||||
Arg args[9];
|
||||
XtSetArg(args[0], XmNkeyboardFocusPolicy, XmPOINTER); // For completion.
|
||||
shell = XtAppCreateShell("G4UIXm", "G4UIXm", topLevelShellWidgetClass, XtDisplay(top), args, 1);
|
||||
form = XmCreateForm(shell, (char*)menu_str[0].c_str(), NULL, 0);
|
||||
XtManageChild(form);
|
||||
|
||||
XtSetArg(args[0], XmNtopAttachment, XmATTACH_FORM);
|
||||
XtSetArg(args[1], XmNleftAttachment, XmATTACH_FORM);
|
||||
XtSetArg(args[2], XmNrightAttachment, XmATTACH_FORM);
|
||||
menuBar = XmCreateMenuBar(form, (char*)menu_str[1].c_str(), args, 3);
|
||||
|
||||
XtSetArg(args[0], XmNtopAttachment, XmATTACH_NONE);
|
||||
XtSetArg(args[1], XmNleftAttachment, XmATTACH_FORM);
|
||||
XtSetArg(args[2], XmNrightAttachment, XmATTACH_FORM);
|
||||
XtSetArg(args[3], XmNbottomAttachment, XmATTACH_FORM);
|
||||
command = XmCreateCommand(form, (char*)menu_str[2].c_str(), args, 4);
|
||||
XtManageChild(command);
|
||||
|
||||
XtSetArg(args[0], XmNtopAttachment, XmATTACH_NONE);
|
||||
XtSetArg(args[1], XmNleftAttachment, XmATTACH_FORM);
|
||||
XtSetArg(args[2], XmNrightAttachment, XmATTACH_FORM);
|
||||
XtSetArg(args[3], XmNbottomAttachment, XmATTACH_WIDGET);
|
||||
XtSetArg(args[4], XmNbottomWidget, command);
|
||||
XmString cps = XmStringLtoRCreate((char*)menu_str[3].c_str(), (char*)XmSTRING_DEFAULT_CHARSET);
|
||||
XtSetArg(args[5], XmNlabelString, cps);
|
||||
Widget clearButton = XmCreatePushButton(form, (char*)menu_str[4].c_str(), args, 6);
|
||||
XmStringFree(cps);
|
||||
XtManageChild(clearButton);
|
||||
|
||||
XtSetArg(args[0], XmNtopAttachment, XmATTACH_WIDGET);
|
||||
XtSetArg(args[1], XmNtopWidget, menuBar);
|
||||
XtSetArg(args[2], XmNleftAttachment, XmATTACH_FORM);
|
||||
XtSetArg(args[3], XmNrightAttachment, XmATTACH_FORM);
|
||||
XtSetArg(args[4], XmNbottomAttachment, XmATTACH_WIDGET);
|
||||
XtSetArg(args[5], XmNbottomWidget, clearButton);
|
||||
XtSetArg(args[6], XmNeditMode, XmMULTI_LINE_EDIT);
|
||||
XtSetArg(args[7], XmNrows, 12);
|
||||
XtSetArg(args[8], XmNcolumns, 80);
|
||||
text = XmCreateScrolledText(form, (char*)menu_str[5].c_str(), args, 9);
|
||||
XtManageChild(text);
|
||||
|
||||
XtAddCallback(clearButton, XmNactivateCallback, clearButtonCallback, (XtPointer)text);
|
||||
XtAddCallback(command, XmNcommandEnteredCallback, CommandEnteredCallback, (XtPointer)this);
|
||||
|
||||
Widget commandText = XmCommandGetChild(command, XmDIALOG_COMMAND_TEXT);
|
||||
XtAddEventHandler(commandText, KeyPressMask, False, keyHandler, (XtPointer)this);
|
||||
|
||||
XtRealizeWidget(shell);
|
||||
XtMapWidget(shell);
|
||||
|
||||
if (UI != NULL) UI->SetCoutDestination(this);
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4UIXm::~G4UIXm()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
G4UImanager* UI = G4UImanager::GetUIpointer();
|
||||
if (UI != NULL) {
|
||||
UI->SetSession(NULL);
|
||||
UI->SetCoutDestination(NULL);
|
||||
}
|
||||
XtDestroyWidget(shell);
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4UIsession* G4UIXm::SessionStart()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
G4Xt* interactorManager = G4Xt::getInstance();
|
||||
Prompt("session");
|
||||
exitSession = false;
|
||||
interactorManager->DisableSecondaryLoop();
|
||||
void* event;
|
||||
while ((event = interactorManager->GetEvent()) != NULL) {
|
||||
interactorManager->DispatchEvent(event);
|
||||
if (exitSession == true) break;
|
||||
}
|
||||
interactorManager->EnableSecondaryLoop();
|
||||
return this;
|
||||
}
|
||||
/***************************************************************************/
|
||||
void G4UIXm::Prompt(G4String aPrompt)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
Arg args[1];
|
||||
char* str = (char*)XtNewString(aPrompt.data());
|
||||
XmString cps = XmStringLtoRCreate(str, (char*)XmSTRING_DEFAULT_CHARSET);
|
||||
XtFree(str);
|
||||
XtSetArg(args[0], XmNpromptString, cps);
|
||||
XtSetValues(command, args, 1);
|
||||
XmStringFree(cps);
|
||||
}
|
||||
/***************************************************************************/
|
||||
void G4UIXm::SessionTerminate()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{}
|
||||
/***************************************************************************/
|
||||
void G4UIXm::PauseSessionStart(const G4String& a_state)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (a_state == "G4_pause> ") {
|
||||
SecondaryLoop("Pause, type continue to exit this state");
|
||||
}
|
||||
|
||||
if (a_state == "EndOfEvent") {
|
||||
// Picking with feed back in event data Done here !!!
|
||||
SecondaryLoop("End of event, type continue to exit this state");
|
||||
}
|
||||
}
|
||||
/***************************************************************************/
|
||||
void G4UIXm::SecondaryLoop(G4String a_prompt)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
G4Xt* interactorManager = G4Xt::getInstance();
|
||||
Prompt(a_prompt);
|
||||
exitPause = false;
|
||||
void* event;
|
||||
while ((event = interactorManager->GetEvent()) != NULL) {
|
||||
interactorManager->DispatchEvent(event);
|
||||
if (exitPause == true) break;
|
||||
}
|
||||
Prompt("session");
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4int G4UIXm::ReceiveG4debug(const G4String& a_string)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
XmTextAppendString(text, (char*)a_string.data());
|
||||
return 0;
|
||||
} /***************************************************************************/
|
||||
G4int G4UIXm::ReceiveG4cout(const G4String& a_string)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
XmTextAppendString(text, (char*)a_string.data());
|
||||
return 0;
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4int G4UIXm::ReceiveG4cerr(const G4String& a_string)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
XmTextAppendString(text, (char*)a_string.data());
|
||||
return 0;
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4bool G4UIXm::GetHelpChoice(G4int& aInt)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
fHelp = true;
|
||||
// SecondaryLoop :
|
||||
G4Xt* interactorManager = G4Xt::getInstance();
|
||||
Prompt("Help");
|
||||
exitHelp = false;
|
||||
void* event;
|
||||
while ((event = interactorManager->GetEvent()) != NULL) {
|
||||
interactorManager->DispatchEvent(event);
|
||||
if (exitHelp == true) break;
|
||||
}
|
||||
Prompt("session");
|
||||
//
|
||||
if (fHelp == false) return false;
|
||||
aInt = fHelpChoice;
|
||||
fHelp = false;
|
||||
return true;
|
||||
}
|
||||
/***************************************************************************/
|
||||
void G4UIXm::ExitHelp() const
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{}
|
||||
/***************************************************************************/
|
||||
void G4UIXm::AddMenu(const char* a_name, const char* a_label)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (menuBar == NULL) return;
|
||||
if (a_name == NULL) return;
|
||||
if (a_label == NULL) return;
|
||||
XtManageChild(menuBar);
|
||||
// Pulldown menu :
|
||||
Widget widget;
|
||||
widget = XmCreatePulldownMenu(menuBar, (char*)a_name, NULL, 0);
|
||||
AddInteractor(a_name, (G4Interactor)widget);
|
||||
// Cascade button :
|
||||
Arg args[2];
|
||||
XmString cps = XmStringLtoRCreate((char*)a_label, (char*)XmSTRING_DEFAULT_CHARSET);
|
||||
XtSetArg(args[0], XmNlabelString, cps);
|
||||
XtSetArg(args[1], XmNsubMenuId, widget);
|
||||
widget = XmCreateCascadeButton(menuBar, (char*)a_name, args, 2);
|
||||
XmStringFree(cps);
|
||||
XtManageChild(widget);
|
||||
ExecuteChangeSizeFunction(form);
|
||||
}
|
||||
/***************************************************************************/
|
||||
void G4UIXm::AddButton(const char* a_menu, const char* a_label, const char* a_command)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (a_menu == NULL) return;
|
||||
if (a_label == NULL) return;
|
||||
if (a_command == NULL) return;
|
||||
Widget parent = (Widget)GetInteractor(a_menu);
|
||||
if (parent == NULL) return;
|
||||
Widget widget = XmCreatePushButton(parent, (char*)a_label, NULL, 0);
|
||||
XtManageChild(widget);
|
||||
XtAddCallback(widget, XmNactivateCallback, ButtonCallback, (XtPointer)this);
|
||||
commands[widget] = a_command;
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4String G4UIXm::GetCommand(Widget a_widget)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
return commands[a_widget];
|
||||
}
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
void G4UIXm::CommandEnteredCallback(Widget, XtPointer a_tag, XtPointer a_data)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
G4UIXm* This = (G4UIXm*)a_tag;
|
||||
|
||||
XmString cps = ((XmCommandCallbackStruct*)a_data)->value;
|
||||
char* ss = XmConvertCompoundStringToString(cps, 0);
|
||||
G4String scommand(ss);
|
||||
XtFree(ss);
|
||||
|
||||
if (This->fHelp == true) {
|
||||
exitHelp = true;
|
||||
This->fHelp = ConvertStringToInt(scommand.data(), This->fHelpChoice);
|
||||
}
|
||||
else {
|
||||
This->ApplyShellCommand(scommand, exitSession, exitPause);
|
||||
}
|
||||
|
||||
a_tag = NULL;
|
||||
}
|
||||
/***************************************************************************/
|
||||
void G4UIXm::keyHandler(Widget a_widget, XtPointer a_tag, XEvent* a_event, Boolean*)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
KeySym keySym;
|
||||
XLookupString(&(a_event->xkey), NULL, 0, &keySym, NULL);
|
||||
if (keySym != XK_Tab) return;
|
||||
G4UIXm* This = (G4UIXm*)a_tag;
|
||||
char* s = XmTextGetString(a_widget);
|
||||
G4String ss = This->Complete(s);
|
||||
XmTextSetString(a_widget, (char*)ss.data());
|
||||
XtFree(s);
|
||||
XmTextSetInsertionPosition(a_widget, XmTextGetLastPosition(a_widget));
|
||||
}
|
||||
/***************************************************************************/
|
||||
void clearButtonCallback(Widget, XtPointer a_tag, XtPointer)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
static const G4String empty_str = "";
|
||||
XmTextSetString((Widget)a_tag, (char*)empty_str.c_str());
|
||||
}
|
||||
/***************************************************************************/
|
||||
void G4UIXm::ButtonCallback(Widget a_widget, XtPointer a_tag, XtPointer)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
G4UIXm* This = (G4UIXm*)a_tag;
|
||||
if (This->fHelp == true) return; // Disabled when in help.
|
||||
G4String ss = This->GetCommand(a_widget);
|
||||
This->ApplyShellCommand(ss, exitSession, exitPause);
|
||||
}
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
char* XmConvertCompoundStringToString(XmString a_cps, G4int a_number)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (a_cps == NULL) return NULL;
|
||||
char* ss = NULL;
|
||||
XmStringContext context;
|
||||
XmStringInitContext(&context, a_cps);
|
||||
G4int icount = 0;
|
||||
Boolean Done = False;
|
||||
while (Done == False) {
|
||||
char* text = NULL;
|
||||
XmStringCharSet charset = NULL;
|
||||
XmStringDirection direct;
|
||||
Boolean sep;
|
||||
if (XmStringGetNextSegment(context, &text, &charset, &direct, &sep) == True) {
|
||||
XtFree(charset);
|
||||
if (sep == True) Done = True;
|
||||
if (icount == a_number) {
|
||||
ss = text;
|
||||
break;
|
||||
}
|
||||
icount++;
|
||||
XtFree(text);
|
||||
}
|
||||
else
|
||||
Done = True;
|
||||
}
|
||||
XmStringFreeContext(context);
|
||||
return ss;
|
||||
}
|
||||
/***************************************************************************/
|
||||
void XmTextAppendString(Widget This, char* a_string)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (This == NULL) return;
|
||||
if (! XtIsSubclass(This, xmTextWidgetClass)) return;
|
||||
if (a_string == NULL) return;
|
||||
XmTextPosition lastpos = XmTextGetLastPosition(This);
|
||||
XmTextReplace(This, lastpos, lastpos, a_string);
|
||||
XmTextSetInsertionPosition(This, XmTextGetLastPosition(This));
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
G4bool ConvertStringToInt(const char* aString, G4int& aInt)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
aInt = 0;
|
||||
if (aString == NULL) return false;
|
||||
char* s;
|
||||
G4long value = strtol(aString, &s, 10);
|
||||
if (s == aString) return false;
|
||||
aInt = (G4int)value;
|
||||
return true;
|
||||
}
|
||||
#include <X11/IntrinsicP.h>
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void ExecuteChangeSizeFunction(Widget aWidget)
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
||||
{
|
||||
if (aWidget == NULL) return;
|
||||
if (aWidget->core.widget_class->core_class.resize == NULL) return;
|
||||
(aWidget->core.widget_class->core_class.resize)(aWidget);
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4Win32 implementation
|
||||
//
|
||||
// Original author: G.Barrand, 1998
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// this :
|
||||
#include "G4Win32.hh"
|
||||
|
||||
#include "G4ios.hh"
|
||||
|
||||
static char className[] = "G4Win32";
|
||||
|
||||
G4Win32* G4Win32::instance = NULL;
|
||||
|
||||
static G4bool Win32Inited = false;
|
||||
static HWND topWindow = NULL;
|
||||
/***************************************************************************/
|
||||
G4Win32* G4Win32::getInstance()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (instance == NULL) {
|
||||
instance = new G4Win32();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4Win32::G4Win32()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (Win32Inited == false) { // Should be Done once.
|
||||
|
||||
WNDCLASS wc;
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wc.lpfnWndProc = (WNDPROC)DefWindowProc;
|
||||
wc.cbClsExtra = 0;
|
||||
wc.cbWndExtra = 0;
|
||||
wc.hInstance = ::GetModuleHandle(NULL);
|
||||
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wc.hbrBackground = GetStockBrush(BLACK_BRUSH);
|
||||
wc.lpszMenuName = className;
|
||||
wc.lpszClassName = className;
|
||||
::RegisterClass(&wc);
|
||||
|
||||
topWindow =
|
||||
::CreateWindowEx(WS_EX_CLIENTEDGE, className, "Test", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, ::GetModuleHandle(NULL), NULL);
|
||||
|
||||
if (topWindow == NULL) {
|
||||
G4cout << "G4Win32: Unable to create Win32 window." << G4endl;
|
||||
}
|
||||
|
||||
Win32Inited = true;
|
||||
}
|
||||
|
||||
AddDispatcher((G4DispatchFunction)G4Win32::DispatchWin32Event);
|
||||
SetMainInteractor(topWindow);
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4Win32::~G4Win32()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (this == instance) {
|
||||
instance = NULL;
|
||||
}
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4bool G4Win32::Inited()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
return Win32Inited;
|
||||
}
|
||||
/***************************************************************************/
|
||||
void* G4Win32::GetEvent()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
static MSG event;
|
||||
BOOL status = ::GetMessage(&event, NULL, 0, 0);
|
||||
if (status == FALSE) return NULL;
|
||||
return &event;
|
||||
}
|
||||
/***************************************************************************/
|
||||
void G4Win32::FlushAndWaitExecution()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
MSG event;
|
||||
while (::PeekMessage(&event, NULL, 0, 0, PM_REMOVE)) {
|
||||
::TranslateMessage(&event);
|
||||
::DispatchMessage(&event);
|
||||
}
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4bool G4Win32::DispatchWin32Event(void* a_event)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
::TranslateMessage((MSG*)a_event);
|
||||
::DispatchMessage((MSG*)a_event);
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
// G.Barrand
|
||||
|
||||
#include "G4Xt.hh"
|
||||
|
||||
#include "G4ios.hh"
|
||||
|
||||
#include <X11/Intrinsic.h>
|
||||
#include <X11/Shell.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define NewString(str) \
|
||||
((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : NULL)
|
||||
|
||||
// static void XWidgetIconify (Widget);
|
||||
// static void XWidgetUniconify (Widget);
|
||||
// static void XDisplaySetWindowToNormalState (Display*,Window);
|
||||
|
||||
G4Xt* G4Xt::instance = NULL;
|
||||
|
||||
static G4bool XtInited = false;
|
||||
static int argn = 0;
|
||||
static char** args = NULL;
|
||||
static XtAppContext appContext = NULL;
|
||||
static Widget topWidget = NULL;
|
||||
/***************************************************************************/
|
||||
G4Xt* G4Xt::getInstance()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
return G4Xt::getInstance(0, NULL, (char*)"Geant4");
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4Xt* G4Xt::getInstance(int a_argn, char** a_args, char* a_class)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (instance == NULL) {
|
||||
instance = new G4Xt(a_argn, a_args, a_class);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4Xt::G4Xt(int a_argn, char** a_args, char* a_class)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (XtInited == false) { // Xt should be Inited once !
|
||||
if (a_argn != 0) { // Save args.
|
||||
args = (char**)malloc(a_argn * sizeof(char*));
|
||||
if (args != NULL) {
|
||||
argn = a_argn;
|
||||
for (int argi = 0; argi < a_argn; argi++) {
|
||||
args[argi] = (char*)NewString(a_args[argi]);
|
||||
}
|
||||
}
|
||||
}
|
||||
#if XtSpecificationRelease == 4
|
||||
Cardinal narg;
|
||||
narg = (Cardinal)a_argn;
|
||||
#else
|
||||
int narg;
|
||||
narg = a_argn;
|
||||
#endif
|
||||
Arg xargs[1];
|
||||
XtSetArg(xargs[0], XtNgeometry, "100x100");
|
||||
topWidget =
|
||||
XtAppInitialize(&appContext, a_class, NULL, (Cardinal)0, &narg, a_args, NULL, xargs, 1);
|
||||
if (topWidget == NULL) {
|
||||
G4cout << "G4Xt : Unable to init Xt." << G4endl;
|
||||
}
|
||||
// Restore a_args. XtAppInitialize corrupts the given ones !!!
|
||||
if ((a_argn != 0) && (args != NULL)) {
|
||||
for (int argi = 0; argi < a_argn; argi++) {
|
||||
if (args[argi] != NULL)
|
||||
strcpy(a_args[argi], args[argi]);
|
||||
else
|
||||
a_args[argi] = NULL;
|
||||
}
|
||||
}
|
||||
// If topWidget not realized, pbs with Inventor shells.
|
||||
XtSetMappedWhenManaged(topWidget, False);
|
||||
XtRealizeWidget(topWidget);
|
||||
XtInited = true;
|
||||
}
|
||||
SetArguments(argn, args);
|
||||
SetMainInteractor(topWidget);
|
||||
AddDispatcher(xt_dispatch_event);
|
||||
// Coverity gcc8 cast warning
|
||||
// AddDispatcher ((G4DispatchFunction)XtDispatchEvent);
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4Xt::~G4Xt()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (this == instance) {
|
||||
instance = NULL;
|
||||
}
|
||||
}
|
||||
/***************************************************************************/
|
||||
G4bool G4Xt::Inited()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
return XtInited;
|
||||
}
|
||||
/***************************************************************************/
|
||||
void* G4Xt::GetEvent()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
static XEvent event;
|
||||
if (appContext == NULL) return NULL;
|
||||
if (topWidget == NULL) return NULL;
|
||||
XtAppNextEvent(appContext, &event);
|
||||
return &event;
|
||||
}
|
||||
/***************************************************************************/
|
||||
void G4Xt::PutStringInResourceDatabase(char* a_string)
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (topWidget == NULL) return;
|
||||
if (a_string == NULL) return;
|
||||
Display* dpy = XtDisplay(topWidget);
|
||||
XrmDatabase dbres = XrmGetStringDatabase(a_string);
|
||||
if (dbres == NULL) return;
|
||||
XrmDatabase database = XrmGetDatabase(dpy);
|
||||
if (database != NULL) {
|
||||
XrmMergeDatabases(dbres, &database);
|
||||
}
|
||||
else {
|
||||
XrmSetDatabase(dpy, dbres);
|
||||
}
|
||||
}
|
||||
/***************************************************************************/
|
||||
void G4Xt::FlushAndWaitExecution()
|
||||
/***************************************************************************/
|
||||
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
||||
{
|
||||
if (topWidget == NULL) return;
|
||||
XSync(XtDisplay(topWidget), False);
|
||||
}
|
||||
Reference in New Issue
Block a user