From 80a5b02bdcd1239f9d23cdcce18032dfa62ba136 Mon Sep 17 00:00:00 2001 From: Mikhail Svechnikov <svechnikovmv@gmail.com> Date: Wed, 24 Jul 2024 15:07:43 +0200 Subject: [PATCH 1/2] rm IFactory --- Base/Util/IFactory.h | 67 ------------------- auto/Examples/scatter2d/CustomFormFactor.py | 6 +- .../scatter2d/CustomFormFactor.py | 6 +- 3 files changed, 6 insertions(+), 73 deletions(-) delete mode 100644 Base/Util/IFactory.h diff --git a/Base/Util/IFactory.h b/Base/Util/IFactory.h deleted file mode 100644 index bf1fa732a63..00000000000 --- a/Base/Util/IFactory.h +++ /dev/null @@ -1,67 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file Base/Util/IFactory.h -//! @brief Defines class interface IFactory. -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2018 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#ifndef BORNAGAIN_BASE_UTIL_IFACTORY_H -#define BORNAGAIN_BASE_UTIL_IFACTORY_H - -#include <cassert> -#include <functional> -#include <iostream> // debug -#include <map> -#include <memory> -#include <sstream> - -//! Base class for all factories. - -template <class Key, class AbstractProduct> class IFactory { -public: - //! function which will be used to create object of AbstractProduct base type - using CreateItemCallback = std::function<AbstractProduct*()>; - - //! map for correspondence between object identifier and object creation function - using CallbackMap_t = std::map<Key, CreateItemCallback>; - - //! Creates object by calling creation function corresponded to given identifier - AbstractProduct* createItem(const Key& item_key) const - { - auto it = m_callbacks.find(item_key); - assert(it != m_callbacks.end()); - return (it->second)(); - } - - std::unique_ptr<AbstractProduct> createItemPtr(const Key& item_key) const - { - return std::unique_ptr<AbstractProduct>{createItem(item_key)}; - } - - //! Registers object's creation function - bool registerItem(const Key& item_key, CreateItemCallback CreateFn) - { - assert(m_callbacks.find(item_key) == m_callbacks.end()); - return m_callbacks.insert(make_pair(item_key, CreateFn)).second; - } - - bool contains(const Key& item_key) const - { - return m_callbacks.find(item_key) != m_callbacks.end(); - } - - //! Returns number of registered objects - size_t size() const { return m_callbacks.size(); } - -protected: - CallbackMap_t m_callbacks; //!< map of correspondence of objectsId and creation functions -}; - -#endif // BORNAGAIN_BASE_UTIL_IFACTORY_H diff --git a/auto/Examples/scatter2d/CustomFormFactor.py b/auto/Examples/scatter2d/CustomFormFactor.py index 1553c5079d0..c4712349a53 100755 --- a/auto/Examples/scatter2d/CustomFormFactor.py +++ b/auto/Examples/scatter2d/CustomFormFactor.py @@ -13,7 +13,7 @@ def sinc(x): return cmath.sin(x)/x -class CustomFormFactor(ba.IFormfactor): +class CustomFormfactor(ba.IFormfactor): """ A custom defined form factor. The particle is a prism of height H, @@ -32,7 +32,7 @@ class CustomFormFactor(ba.IFormfactor): The clone method needs to call transferToCPP() on the cloned object to transfer the ownership of the clone to the cpp code """ - cloned_ff = CustomFormFactor(self.L, self.H) + cloned_ff = CustomFormfactor(self.L, self.H) cloned_ff.transferToCPP() return cloned_ff @@ -58,7 +58,7 @@ def get_sample(): material_particle = ba.RefractiveMaterial("Particle", 6e-4, 2e-8) # collection of particles - ff = CustomFormFactor(20*nm, 15*nm) + ff = CustomFormfactor(20*nm, 15*nm) particle = ba.Particle(material_particle, ff) particle_layout = ba.ParticleLayout() particle_layout.addParticle(particle) diff --git a/auto/MiniExamples/scatter2d/CustomFormFactor.py b/auto/MiniExamples/scatter2d/CustomFormFactor.py index 28127d06aa1..a772f2bf3a5 100755 --- a/auto/MiniExamples/scatter2d/CustomFormFactor.py +++ b/auto/MiniExamples/scatter2d/CustomFormFactor.py @@ -13,7 +13,7 @@ def sinc(x): return cmath.sin(x)/x -class CustomFormFactor(ba.IFormfactor): +class CustomFormfactor(ba.IFormfactor): """ A custom defined form factor. The particle is a prism of height H, @@ -32,7 +32,7 @@ class CustomFormFactor(ba.IFormfactor): The clone method needs to call transferToCPP() on the cloned object to transfer the ownership of the clone to the cpp code """ - cloned_ff = CustomFormFactor(self.L, self.H) + cloned_ff = CustomFormfactor(self.L, self.H) cloned_ff.transferToCPP() return cloned_ff @@ -58,7 +58,7 @@ def get_sample(): material_particle = ba.RefractiveMaterial("Particle", 6e-4, 2e-8) # collection of particles - ff = CustomFormFactor(20*nm, 15*nm) + ff = CustomFormfactor(20*nm, 15*nm) particle = ba.Particle(material_particle, ff) particle_layout = ba.ParticleLayout() particle_layout.addParticle(particle) -- GitLab From 86d841b6f8c531105527eed6a04070f9465b2487 Mon Sep 17 00:00:00 2001 From: Mikhail Svechnikov <svechnikovmv@gmail.com> Date: Wed, 24 Jul 2024 15:08:54 +0200 Subject: [PATCH 2/2] rm debug messages --- GUI/View/Main/ProjectManager.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/GUI/View/Main/ProjectManager.cpp b/GUI/View/Main/ProjectManager.cpp index a63125df041..1c5a024ae30 100644 --- a/GUI/View/Main/ProjectManager.cpp +++ b/GUI/View/Main/ProjectManager.cpp @@ -183,11 +183,8 @@ void ProjectManager::openProject(QString projectPullPath) } createNewProject(); - std::cout << "ProjectManager::openProject 6" << std::endl; loadProject(projectPullPath); - std::cout << "ProjectManager::openProject 7" << std::endl; emit documentOpenedOrClosed(true); - std::cout << "ProjectManager::openProject 8" << std::endl; } //! Calls dialog window to define project path and name. @@ -209,17 +206,12 @@ void ProjectManager::loadProject(const QString& fullPathAndName) if (qApp) QApplication::setOverrideCursor(Qt::WaitCursor); if (useAutosave && restoreProjectDialog(fullPathAndName, autosaveFullPath)) { - std::cout << "ProjectManager::loadProject with autosave 1" << std::endl; gDoc->loadProjectFileWithData(autosaveFullPath); - std::cout << "ProjectManager::loadProject with autosave 2" << std::endl; gDoc->setProjectFullPath(fullPathAndName); - std::cout << "ProjectManager::loadProject with autosave 3" << std::endl; // restored project should be marked by '*' gDoc->setModified(); } else { - std::cout << "ProjectManager::loadProject without autosave 4" << std::endl; gDoc->loadProjectFileWithData(fullPathAndName); - std::cout << "ProjectManager::loadProject without autosave 5" << std::endl; } if (qApp) QApplication::restoreOverrideCursor(); -- GitLab