11 {
"Store in project file and apply from file", ProjectParams::StoreWindowStatesType::ApplyStoredWindowStates },
12 {
"Don't store in project file but apply defaults", ProjectParams::StoreWindowStatesType::ApplyDefaultWindowStates }
25 : HardwareAdapterLib(std::move(HardwareAdapterLib)), InstrumentLib(std::move(InstrumentLib)),
26 ModuleLib(std::move(ModuleLib)),
27 Params(std::make_unique<
ProjectParams>(*this)), OwnerThreadID(std::this_thread::get_id())
39 Util::EventLog().
Log(
"DynExp was compiled in DEBUG mode and might thus run slowly.");
75 Params = std::make_unique<ProjectParams>(*
this);
81 void DynExpCore::SaveProject(std::string_view Filename,
const QMainWindow& MainWindow,
const QDialog& CircuitDiagramDlg, QSplitter& HSplitter, QSplitter& VSplitter)
83 QDomDocument Document;
84 Document.appendChild(Document.createProcessingInstruction(
"xml",
"version=\"1.0\" standalone=\"yes\""));
85 QDomElement RootNode = Document.createElement(
"DynExp");
87 QDomElement ProjectNode = Document.createElement(
"Project");
90 QDomElement ParamsNode = Document.createElement(
"Params");
91 ParamsNode.appendChild(
GetParams()->ConfigToXML(Document));
92 ProjectNode.appendChild(ParamsNode);
98 RootNode.appendChild(ProjectNode);
99 Document.appendChild(RootNode);
101 auto DocumentString = Document.toString().toStdString();
104 File.exceptions(std::ofstream::failbit | std::ofstream::badbit);
105 File.open(std::string(Filename), std::ofstream::out | std::ofstream::trunc);
106 File.write(DocumentString.c_str(), DocumentString.length());
111 Util::EventLog().
Log(std::string(
"Saved project successfully to ").append(Filename) +
".");
117 std::string Contents;
118 File.exceptions(std::ifstream::failbit | std::ifstream::badbit);
119 File.open(std::string(Filename), std::ifstream::in | std::ifstream::binary);
120 File.seekg(0, std::ios::end);
121 Contents.resize(File.tellg());
122 File.seekg(0, std::ios::beg);
123 File.read(&Contents[0], Contents.size());
126 QDomDocument Document;
128 int Line = 0, Column = 0;
129 if (!Document.setContent(QString::fromStdString(Contents),
false, &ErrorMsg, &Line, &Column))
133 auto RootNode = Document.documentElement();
153 Util::EventLog().
Log(std::string(
"Loaded project from ").append(Filename) +
" successfully.");
158 auto ConfigDlg = std::make_unique<ParamsConfigDialog>(DialogParent, *
this,
"Project settings");
160 GetParams()->ConfigFromDialog(*ConfigDlg);
161 ConfigDlg->Display();
200 for (
const auto AdapterID : FailedAndUsedHardwareAdapters)
203 InstrumentsToRestart.insert(InstrumentsToRestart.cend(), Users.cbegin(), Users.cend());
206 if (!InstrumentsToRestart.empty())
208 std::string InstrumentsToRestartNames(
"The following instruments will be stopped and restarted:");
209 for (
const auto InstrID : InstrumentsToRestart)
212 InstrumentsToRestartNames +=
"\n- " + Instr->GetObjectName() +
" (" + Instr->GetCategoryAndName() +
")";
214 InstrumentsToRestartNames +=
"\n\nDo you wish to continue?";
215 if (QMessageBox::question(&ParentWindow,
"DynExp - Restart instruments?", QString::fromStdString(InstrumentsToRestartNames),
216 QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, QMessageBox::StandardButton::No)
217 != QMessageBox::StandardButton::Yes)
221 for (
const auto InstrID : InstrumentsToRestart)
227 for (
const auto InstrID : InstrumentsToRestart)
237 if (
Params->StoreWindowStates != ProjectParams::StoreWindowStatesType::ApplyStoredWindowStates)
240 Params->MainWindowStyleParams.ApplyTo(MainWindow);
241 Params->CircuitWindowStyleParams.ApplyTo(CircuitDiagramDlg,
242 Params->CircuitWindowStyleParams.WindowDockingState == WindowStyleParamsExtension::WindowDockingStateType::Undocked);
243 if (
Params->CircuitWindowStyleParams.WindowDockingState == WindowStyleParamsExtension::WindowDockingStateType::Docked)
244 CircuitDiagramDlg.hide();
246 if (
Params->HSplitterWidgetWidths.Get().size() >= Util::NumToT<size_t>(HSplitter.sizes().size()))
247 HSplitter.setSizes(QList<int>::fromVector(QVector<int>(
Params->HSplitterWidgetWidths.Get().cbegin(),
Params->HSplitterWidgetWidths.Get().cend())));
248 if (
Params->VSplitterWidgetHeights.Get().size() >= Util::NumToT<size_t>(VSplitter.sizes().size()))
249 VSplitter.setSizes(QList<int>::fromVector(QVector<int>(
Params->VSplitterWidgetHeights.Get().cbegin(),
Params->VSplitterWidgetHeights.Get().cend())));
276 return LoadedProjectFromCommandlineParamsCopy;
281 return (
Path.is_relative() && !
Path.empty()) ?
293 QObject::connect(&
WorkerThread, &QThread::finished, &Worker, &QObject::deleteLater);
301 if (!LastDataSaveDirectory.empty() && std::filesystem::exists(LastDataSaveDirectory))
302 return LastDataSaveDirectory.string();
305 return ProjectFilename.empty() ?
"" : ProjectFilename.parent_path().string();
315 if (Filename.empty())
318 std::string ErrorMessage =
"";
321 OpenProject(Filename);
323 catch (
const std::exception& e)
325 ErrorMessage = e.what();
329 ErrorMessage =
"Unknown Error";
332 if (!ErrorMessage.empty())
334 Util::EventLog().
Log(
"Opening a project from file " + Filename +
", the following error occurred: " + ErrorMessage,
344 Util::EventLog().
Log(
"Error occurred while resetting project. Execution cannot continue.",
366 if (
Params->StoreWindowStates != ProjectParams::StoreWindowStatesType::ApplyStoredWindowStates)
369 Params->MainWindowStyleParams.FromWidget(MainWindow);
370 Params->CircuitWindowStyleParams.FromWidget(CircuitDiagramDlg);
371 Params->CircuitWindowStyleParams.WindowDockingState = CircuitDiagramDlg.isVisible() ?
372 WindowStyleParamsExtension::WindowDockingStateType::Undocked : WindowStyleParamsExtension::WindowDockingStateType::Docked;
374 const auto HSplitterSizes = HSplitter.sizes().toVector();
375 const auto VSplitterSizes = VSplitter.sizes().toVector();
376 Params->HSplitterWidgetWidths = std::vector<int>(HSplitterSizes.cbegin(), HSplitterSizes.cend());
377 Params->VSplitterWidgetHeights = std::vector<int>(VSplitterSizes.cbegin(), VSplitterSizes.cend());
Defines DynExp's core module as an interface between the UI and DynExp objects.
const std::function< void(Object *const)> FunctionToCallWhenObjectStartedType
Type of a callback function to invoke after a resource has been started in a call to ResourceManagerB...
std::unique_ptr< ProjectParams > Params
Project parameters (configuration) of the current DynExp project. Must never be nullptr.
DynExpCore(HardwareAdapterLibraryVectorType HardwareAdapterLib, InstrumentLibraryVectorType InstrumentLib, ModuleLibraryVectorType ModuleLib, std::string ProjectFileToOpen="")
Constructs a DynExpCore instance.
void SaveProject(std::string_view Filename, const QMainWindow &MainWindow, const QDialog &CircuitDiagramDlg, QSplitter &HSplitter, QSplitter &VSplitter)
Saves the current DynExp project to an XML project file.
void ShutdownProject()
Terminates all running instruments and modules.
bool AllInstrumentsInitialized() const
Checks whether all instruments contained in InstrumentMgr have been initialized successfully.
auto & GetModuleManager() noexcept
Getter for the module manager.
void OpenProject(std::string_view Filename)
Loads a DynExp project from an XML project file.
bool LoadedProjectFromCommandlineParams
This flag will be set to true if DynExpCore has been initialized with a path to a project file to loa...
bool OpenProjectSafe(const std::string &Filename) noexcept
Calls OpenProject() and performs error handling for that function.
HardwareAdapterManager HardwareAdapterMgr
Hardware adapter manager owning all instantiated hardware adapters.
const HardwareAdapterLibraryVectorType HardwareAdapterLib
Hardware adapter library vector containing information about all hardware adapters DynExp knows.
auto & GetHardwareAdapterManager() noexcept
Getter for the hardware adapter manager.
void EditProjectSettings(QWidget *const DialogParent)
Opens a settings dialog (ParamsConfigDialog) to let the user configure the parameter values of the cu...
void RestoreWindowStatesFromParams(QMainWindow &MainWindow, QDialog &CircuitDiagramDlg, QSplitter &HSplitter, QSplitter &VSplitter, bool OnlyMainWindow=false)
Sets module and main windows' positions, sizes and styles according to parameters stored in the curre...
QThread WorkerThread
One worker thread runs the Qt event queues for all objects derived from Util::QWorker (e....
auto & GetInstrumentManager() noexcept
Getter for the instrument manager.
void Reset(bool Force=false)
Resets the currently loaded project removing all resources from the resource managers....
bool HasLoadedProjectFromCommandlineParams() noexcept
Indicates whether a DynExp project has been loaded from a path specified as a command line argument w...
ModuleManager ModuleMgr
Module manager owning all instantiated modules.
const InstrumentLibraryVectorType InstrumentLib
Instrument library vector containing information about all instruments DynExp knows.
void MoveQWorkerToWorkerThread(Util::QWorker &Worker, ItemIDType ID) const
Moves a Util::QWorker instance to WorkerThread to run its Qt event queue there. This method is thread...
void SetDataSaveDirectory(const std::filesystem::path &Directory, const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault)
Sets a path where modules might save recorded data to. Used by Util::PromptSaveFilePathModule() to st...
const ModuleLibraryVectorType ModuleLib
Module library vector containing information about all modules DynExp knows.
auto GetLastDataSaveDirectory(const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault) const
Locks Params and returns the path to a directory where modules can save data.
auto GetProjectFilename(const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault) const
Locks Params and returns the current DynExp project's filename.
void RunModules(CommonResourceManagerBase::FunctionToCallWhenObjectStartedType FunctionToCallWhenModuleStarted=nullptr)
Runs all modules contained in ModuleMgr with RunnableObjectParams::StartupType::OnCreation startup se...
ParamsConstTypeSyncPtrType GetParams(const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault) const
Locks the mutex of the parameter class instance Params assigned to the current project and returns a ...
void UpdateParamsFromWindowStates(const QMainWindow &MainWindow, const QDialog &CircuitDiagramDlg, QSplitter &HSplitter, QSplitter &VSplitter)
Retrieves the module and main windows' positions, sizes and styles from the windows and updates the p...
InstrumentManager InstrumentMgr
Instrument manager owning all instantiated instruments.
void RunInstruments(CommonResourceManagerBase::FunctionToCallWhenObjectStartedType FunctionToCallWhenInstrumentStarted=nullptr)
Runs all instruments contained in InstrumentMgr with RunnableObjectParams::StartupType::OnCreation st...
ItemIDType MakeItem(const LibraryEntry< HardwareAdapterPtrType > &LibEntry, ParamsBasePtrType &&Params)
Creates a DynExp::HardwareAdapterBase instance from a LibraryEntry.
bool AllHardwareAdaptersConnected() const
Checks whether all hardware adapters contained in HardwareAdapterMgr have been connected successfully...
Util::SynchronizedPointer< const ProjectParams > ParamsConstTypeSyncPtrType
Alias for the return type of DynExpCore::GetParams() const. Parameters wrapped into Util::Synchronize...
void ResetFailedItems(QWidget &ParentWindow)
Calls Object::Reset() and Object::ClearWarning() on all owned DynExp::Object instances which are in a...
std::string GetDataSaveDirectory(const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault) const
Recalls a path where modules might save recorded data to. Used by Util::PromptSaveFilePathModule() to...
std::filesystem::path ToAbsolutePath(const std::filesystem::path &Path) const
Transforms the path Path into an absolute path relative to ProjectParams::ProjectFilename.
Util::SynchronizedPointer< ProjectParams > ParamsTypeSyncPtrType
Alias for the return type of DynExpCore::GetParams(). Parameters wrapped into Util::SynchronizedPoint...
void Shutdown()
Terminates DynExpCore::WorkerThread and waits until the thread has ended.
bool AllConnected() const
Determines whether all hardware adapters managed by this resource manager are connected....
bool AllInitialized() const
Determines whether all instruments managed by this resource manager are initialized....
void RestoreWindowStatesFromParams() const
Calls ModuleBase::RestoreWindowStatesFromParams() on all modules managed by this resource manager....
void UpdateParamsFromWindowStates() const
Calls ModuleBase::UpdateParamsFromWindowStates() on all modules managed by this resource manager....
Param< UsageType > Usage
Determines whether an object can be used by only one other ("unique") or by multiple other ("shared")...
static void DisableUserEditable(ParamBase &Param) noexcept
Sets the UserEditable property of the parameter Param to false. Refer to ParamBase::UserEditable.
Tag for function dispatching mechanism within this class used when derived classes are not intended t...
Defines a parameter class with parameters common to all DynExp projects.
static Util::TextValueListType< StoreWindowStatesType > AvlblStoreWindowStatesTypeStrList()
Assigns labels to the entries of StoreWindowStatesType.
void ConfigureParamsImpl(dispatch_tag< ParamsBase >) override final
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
void Reset()
Resets the resource manager by calling ResetChild(), by removing all resources from Map and by resett...
void ClearResourcesWarnings() const
Calls Object::ClearWarning() on all resources stored in this resource manager.
void ResetFailedResources() const
Calls Object::Reset() on all resources stored in this resource manager which are in an error state (d...
const PointerType::element_type * GetResource(ItemIDType ID) const
Retrieves a resource specified by its ID from the resource manager.
void MakeEntriesFromXML(const QDomElement &XMLNode, const LibraryVectorT &Library, const DynExpCore &Core)
Creates resources and takes ownership of them according to an XML tree from a DynExp project XML file...
void Shutdown() const
Calls ShutdownChild() to terminate and clean up all resources stored in this resource manager.
void PrepareReset()
Prepares all resources stored in this resource manager for their deletion by e.g. asking them to term...
ItemIDListType GetFailedResourceIDs(bool OnlyResourcesBeingInUse=false) const
Builds and returns a list of the IDs of all resources stored in this resource manager which are in an...
void Startup(FunctionToCallWhenObjectStartedType FunctionToCallWhenObjectStarted) const
Starts all resources owned by the resource manager. For HardwareAdapterBase instances,...
QDomElement EntryConfigsToXML(QDomDocument &Document) const
Creates and returns the XML tree containing the configuration of each resource owned by this resource...
Defines an Object which possesses a thread it runs in. The RunnableObject can be started and stopped ...
void Log(const std::string &Message, const ErrorType Type=ErrorType::Info, const size_t Line=0, const std::string &Function="", const std::string &File="", const int ErrorCode=0, const std::stacktrace &Trace={}) noexcept
Logs an event from information specified manually.
void OpenLogFile(std::string Filename)
Opens the HTML log file on disk. If it already exists, the file gets overwritten.
Data to operate on is invalid for a specific purpose. This indicates a corrupted data structure or fu...
Implements a QObject belonging to a hardware adapter (derived from DynExp::HardwareAdapterBase) that ...
static const DynExp::DynExpCore & GetDynExpCore(const DynExp::DynExpCore *DynExpCore=nullptr)
Returns the application's DynExp::DynExpCore instance which is globally set in constructor DynExp::Dy...
void SetOwner(OwnerPtrType Owner) noexcept
Sets the hardware adapter owning this worker instance.
Pointer to lock a class derived from ISynchronizedPointerLockable for synchronizing between threads....
Thrown in a multi-threading context when an answer is expected from another thread an when the commun...
DynExp's main namespace contains the implementation of DynExp including classes to manage resources (...
std::vector< ItemIDType > ItemIDListType
Type of a list of IDs belonging to objects managed by DynExp.
std::vector< LibraryEntry< InstrumentPtrType > > InstrumentLibraryVectorType
Alias for the vector type containing entries of a instrument library.
std::vector< LibraryEntry< HardwareAdapterPtrType > > HardwareAdapterLibraryVectorType
Alias for the vector type containing entries of a hardware adapter library.
std::unique_ptr< ParamsBase > ParamsBasePtrType
Alias for a pointer to the parameter system base class ParamsBase.
size_t ItemIDType
ID type of objects/items managed by DynExp.
std::vector< LibraryEntry< ModulePtrType > > ModuleLibraryVectorType
Alias for the vector type containing entries of a module library.
constexpr auto DynExpVersion
DynExp's version string
std::string ToStr(const T &Value, int Precision=-1)
Converts a (numeric) value of type T to a std::string using operator<< of std::stringstream.
QDomElement GetSingleChildDOMElement(const QDomElement &Parent, const QString &ChildTagName)
Behaves like GetSingleChildDOMNode() but returns the node converted to a DOM element.
VersionType VersionFromString(std::string_view Str)
Extracts a program version from a string.
EventLogger & EventLog()
This function holds a static EventLogger instance and returns a reference to it. DynExp uses only one...
std::vector< std::pair< TextType, ValueType > > TextValueListType
Type of a list containing key-value pairs where key is a text of type Util::TextType.
std::string GetStringFromDOMAttribute(const QDomElement &Element, const QString &AttributeName)
Behaves like GetDOMAttribute() but returns the text from the attribute.
Data type describing DynExp's program version in the form Major.Minor.Patch.
Accumulates include statements to provide a precompiled header.
Represents an entry in the library.