BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
RealSpaceCanvas.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Realspace/RealSpaceCanvas.h
6 //! @brief Defines class RealSpaceCanvas
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_GUI_VIEW_REALSPACE_REALSPACECANVAS_H
16 #define BORNAGAIN_GUI_VIEW_REALSPACE_REALSPACECANVAS_H
17 
18 #include <QWidget>
19 #include <memory>
20 #include <optional>
21 #include <variant>
22 
23 class CautionSign;
24 class MultiLayerItem;
25 class LayerItem;
26 class ParticleLayoutItem;
27 class ItemWithParticles;
28 
29 namespace GUI::RealSpace {
30 class Canvas;
31 class Model;
32 } // namespace GUI::RealSpace
33 
34 //! Size and thickness information of layers
35 struct SceneGeometry {
36  double layerSize = 100.0;
38  double layerMinimumThickness = 2.0;
39 };
40 
41 //! Provides 3D object generation for RealSpace presentation.
42 class RealSpaceCanvas : public QWidget {
43  Q_OBJECT
44 
45 public:
46  //! Defines the item types which can be the "current item"
48  std::variant<MultiLayerItem*, LayerItem*, ParticleLayoutItem*, ItemWithParticles*>;
49 
50  RealSpaceCanvas(QWidget* parent = nullptr);
51 
52  void setCurrentItem(MultiLayerItem* containingMultiLayerItem, ItemForRealSpace item);
53  template <typename T>
54  T currentItemAs() const;
55  void defaultView();
56  void sideView();
57  void topView();
58  void changeLayerSize(double layerSizeChangeScale);
59  void savePicture();
60  void resetScene();
61  void updateScene();
62 
63 protected:
64  void showEvent(QShowEvent*) override;
65 
66 private:
67  void savePicture(const QPixmap& pixmap);
68 
70  std::unique_ptr<GUI::RealSpace::Model> m_realSpaceModel;
73  std::optional<ItemForRealSpace> m_currentItem;
76 };
77 
78 template <typename T>
80 {
81  if (!m_currentItem)
82  return nullptr;
83 
84  auto currentVariant = m_currentItem.value();
85  T* ppCurrent = std::get_if<T>(&currentVariant);
86  return ppCurrent ? *ppCurrent : nullptr;
87 }
88 
89 #endif // BORNAGAIN_GUI_VIEW_REALSPACE_REALSPACECANVAS_H
The CautionSign controls appearance of CautionSignWidget on top of parent widget.
Definition: CautionSign.h:25
Provides 3D object generation for RealSpace presentation.
SceneGeometry m_sceneGeometry
void setCurrentItem(MultiLayerItem *containingMultiLayerItem, ItemForRealSpace item)
GUI::RealSpace::Canvas * m_view
std::variant< MultiLayerItem *, LayerItem *, ParticleLayoutItem *, ItemWithParticles * > ItemForRealSpace
Defines the item types which can be the "current item".
std::optional< ItemForRealSpace > m_currentItem
void showEvent(QShowEvent *) override
CautionSign * m_cautionSign
void changeLayerSize(double layerSizeChangeScale)
MultiLayerItem * m_containingMultiLayerItem
std::unique_ptr< GUI::RealSpace::Model > m_realSpaceModel
RealSpaceCanvas(QWidget *parent=nullptr)
T currentItemAs() const
Size and thickness information of layers.
double topOrBottomLayerThickness
double layerMinimumThickness