BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
RealSpaceCanvas Class Reference

Description

Provides 3D object generation for RealSpace presentation.

Definition at line 42 of file RealSpaceCanvas.h.

Inheritance diagram for RealSpaceCanvas:
[legend]
Collaboration diagram for RealSpaceCanvas:
[legend]

Public Types

using ItemForRealSpace = std::variant< MultiLayerItem *, LayerItem *, ParticleLayoutItem *, ItemWithParticles * >
 Defines the item types which can be the "current item". More...
 

Public Member Functions

 RealSpaceCanvas (QWidget *parent=nullptr)
 
void changeLayerSize (double layerSizeChangeScale)
 
template<typename T >
currentItemAs () const
 
void defaultView ()
 
void resetScene ()
 
void savePicture ()
 
void setCurrentItem (MultiLayerItem *containingMultiLayerItem, ItemForRealSpace item)
 
void sideView ()
 
void topView ()
 
void updateScene ()
 

Protected Member Functions

void showEvent (QShowEvent *) override
 

Private Member Functions

void savePicture (const QPixmap &pixmap)
 

Private Attributes

CautionSignm_cautionSign
 
MultiLayerItemm_containingMultiLayerItem
 
std::optional< ItemForRealSpacem_currentItem
 
bool m_firstView
 
std::unique_ptr< GUI::RealSpace::Modelm_realSpaceModel
 
SceneGeometry m_sceneGeometry
 
GUI::RealSpace::Canvasm_view
 

Member Typedef Documentation

◆ ItemForRealSpace

Defines the item types which can be the "current item".

Definition at line 47 of file RealSpaceCanvas.h.

Constructor & Destructor Documentation

◆ RealSpaceCanvas()

RealSpaceCanvas::RealSpaceCanvas ( QWidget *  parent = nullptr)

Definition at line 31 of file RealSpaceCanvas.cpp.

32  : QWidget(parent)
34  , m_cautionSign(new CautionSign(this))
36  , m_firstView(true)
37 {
38  auto* layout = new QVBoxLayout;
39  layout->setMargin(0);
40  layout->setSpacing(0);
41  layout->addWidget(m_view);
42  setLayout(layout);
43 }
The CautionSign controls appearance of CautionSignWidget on top of parent widget.
Definition: CautionSign.h:25
GUI::RealSpace::Canvas * m_view
CautionSign * m_cautionSign
MultiLayerItem * m_containingMultiLayerItem

References m_view.

Member Function Documentation

◆ changeLayerSize()

void RealSpaceCanvas::changeLayerSize ( double  layerSizeChangeScale)

Definition at line 60 of file RealSpaceCanvas.cpp.

61 {
62  // when no object is selected --> take no action
63  if (!m_currentItem)
64  return;
65 
66  m_sceneGeometry.layerSize = m_sceneGeometry.layerSize * layerSizeChangeScale;
67  updateScene();
68 }
SceneGeometry m_sceneGeometry
std::optional< ItemForRealSpace > m_currentItem

References SceneGeometry::layerSize, m_currentItem, m_sceneGeometry, and updateScene().

Referenced by RealSpacePanel::RealSpacePanel().

Here is the call graph for this function:

◆ currentItemAs()

template<typename T >
T RealSpaceCanvas::currentItemAs

Definition at line 79 of file RealSpaceCanvas.h.

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 }

References m_currentItem.

Referenced by SampleView::onAboutToRemoveItem().

◆ defaultView()

void RealSpaceCanvas::defaultView ( )

Definition at line 152 of file RealSpaceCanvas.cpp.

153 {
154  m_view->defaultView();
155 }

References GUI::RealSpace::Canvas::defaultView(), and m_view.

Referenced by RealSpacePanel::RealSpacePanel(), and setCurrentItem().

Here is the call graph for this function:

◆ resetScene()

void RealSpaceCanvas::resetScene ( )

Definition at line 144 of file RealSpaceCanvas.cpp.

145 {
146  m_realSpaceModel.reset();
147  m_view->setModel(nullptr);
148  m_currentItem.reset();
149  m_containingMultiLayerItem = nullptr;
150 }
void setModel(Model *)
Definition: canvas.cpp:94
std::unique_ptr< GUI::RealSpace::Model > m_realSpaceModel

References m_containingMultiLayerItem, m_currentItem, m_realSpaceModel, m_view, and GUI::RealSpace::Canvas::setModel().

Referenced by setCurrentItem().

Here is the call graph for this function:

◆ savePicture() [1/2]

void RealSpaceCanvas::savePicture ( )

Definition at line 70 of file RealSpaceCanvas.cpp.

71 {
72  QPixmap pixmap(this->size());
73  render(&pixmap, QPoint(), childrenRegion());
74  savePicture(pixmap);
75 }

Referenced by RealSpacePanel::RealSpacePanel().

◆ savePicture() [2/2]

void RealSpaceCanvas::savePicture ( const QPixmap &  pixmap)
private

Definition at line 85 of file RealSpaceCanvas.cpp.

86 {
87  QString dirname = gSessionData->projectDocument.value()->userExportDir();
88  QString defaultExtension = ".png";
89  QString selectedFilter("*" + defaultExtension);
90  QString defaultName = dirname + "/untitled";
91  QString fileName = QFileDialog::getSaveFileName(
92  nullptr, "Save 3D real space view", defaultName, selectedFilter, nullptr,
93  appSettings->useNativeFileDialog() ? QFileDialog::Options()
94  : QFileDialog::DontUseNativeDialog);
95  QString nameToSave =
96  fileName.endsWith(defaultExtension) ? fileName : fileName + defaultExtension;
97 
98  if (!nameToSave.isEmpty()) {
99  try {
100  pixmap.save(nameToSave);
101  } catch (const std::exception& ex) {
102  QString message = "Attempt to save file with the name '";
103  message.append(nameToSave);
104  message.append("' has failed with following error message\n\n");
105  message.append(QString::fromStdString(ex.what()));
106  QMessageBox::warning(nullptr, "Houston, we have a problem.", message);
107  }
108  }
109 }
ApplicationSettings * appSettings
global pointer to the instance
SessionData * gSessionData
global pointer to the single instance
Definition: SessionData.cpp:17
bool useNativeFileDialog() const
void warning(QWidget *parent, const QString &title, const QString &text, const QString &detailedText)
Definition: MessageBox.cpp:37
std::optional< ProjectDocument * > projectDocument
Definition: SessionData.h:27

References appSettings, gSessionData, SessionData::projectDocument, ApplicationSettings::useNativeFileDialog(), and GUI::View::Helpers::warning().

Here is the call graph for this function:

◆ setCurrentItem()

void RealSpaceCanvas::setCurrentItem ( MultiLayerItem containingMultiLayerItem,
ItemForRealSpace  item 
)

Definition at line 45 of file RealSpaceCanvas.cpp.

47 {
48  bool isValid = false;
49  std::visit([&](auto&& arg) { isValid = arg != nullptr; }, item);
50 
51  if (isValid) {
52  m_containingMultiLayerItem = containingMultiLayerItem;
53  m_currentItem = item;
54  updateScene();
55  defaultView(); // Enforces default view and also sets the zoomLevel to default i.e. 0
56  } else
57  resetScene();
58 }

References defaultView(), m_containingMultiLayerItem, m_currentItem, resetScene(), and updateScene().

Referenced by SampleView::onRequestViewInRealSpace().

Here is the call graph for this function:

◆ showEvent()

void RealSpaceCanvas::showEvent ( QShowEvent *  )
overrideprotected

Definition at line 77 of file RealSpaceCanvas.cpp.

78 {
79  updateScene();
80  if (m_firstView)
82  m_firstView = false;
83 }

References GUI::RealSpace::Canvas::defaultView(), m_firstView, m_view, and updateScene().

Here is the call graph for this function:

◆ sideView()

void RealSpaceCanvas::sideView ( )

Definition at line 157 of file RealSpaceCanvas.cpp.

158 {
159  m_view->sideView();
160 }

References m_view, and GUI::RealSpace::Canvas::sideView().

Referenced by RealSpacePanel::RealSpacePanel().

Here is the call graph for this function:

◆ topView()

void RealSpaceCanvas::topView ( )

Definition at line 162 of file RealSpaceCanvas.cpp.

163 {
164  m_view->topView();
165 }

References m_view, and GUI::RealSpace::Canvas::topView().

Referenced by RealSpacePanel::RealSpacePanel().

Here is the call graph for this function:

◆ updateScene()

void RealSpaceCanvas::updateScene ( )

Definition at line 111 of file RealSpaceCanvas.cpp.

112 {
113  if (!isVisible()) // to improve performance
114  return;
115 
116  if (!m_view->isValid()) // GL not initialized (widget not shown so far) -> no updating possible
117  return;
118 
119  QApplication::setOverrideCursor(Qt::WaitCursor);
120 
121  m_realSpaceModel = std::make_unique<GUI::RealSpace::Model>();
122 
123  const auto colorForMaterialName = [&](const QString& materialName) {
125  };
126 
127  RealSpaceBuilder builder3D(colorForMaterialName);
128 
129  try {
130  m_cautionSign->clear();
131  if (m_currentItem)
132  builder3D.populate(m_realSpaceModel.get(), *m_currentItem, m_sceneGeometry,
133  m_view->cam()->getPos());
134  } catch (const std::exception& ex) {
135  m_cautionSign->setCautionMessage(ex.what());
136  } catch (...) {
137  // ignore other exceptions thrown
138  }
140 
141  QApplication::restoreOverrideCursor();
142 }
void clear()
Clears caution message;.
Definition: CautionSign.cpp:42
void setCautionMessage(const QString &cautionMessage)
Shows caution sign on the screen. If clear of previous caution sign had happened just few msec ago,...
Definition: CautionSign.cpp:60
const Position & getPos() const
Definition: camera.h:50
Camera * cam()
Definition: canvas.h:59
QColor color() const
MaterialItem * materialFromName(const QString &name) const
MaterialItems & materialItems()

References GUI::RealSpace::Canvas::cam(), CautionSign::clear(), MaterialItem::color(), GUI::RealSpace::Camera::getPos(), m_cautionSign, m_containingMultiLayerItem, m_currentItem, m_realSpaceModel, m_sceneGeometry, m_view, MaterialItems::materialFromName(), MultiLayerItem::materialItems(), RealSpaceBuilder::populate(), CautionSign::setCautionMessage(), and GUI::RealSpace::Canvas::setModel().

Referenced by SampleView::SampleView(), changeLayerSize(), setCurrentItem(), and showEvent().

Here is the call graph for this function:

Member Data Documentation

◆ m_cautionSign

CautionSign* RealSpaceCanvas::m_cautionSign
private

Definition at line 72 of file RealSpaceCanvas.h.

Referenced by updateScene().

◆ m_containingMultiLayerItem

MultiLayerItem* RealSpaceCanvas::m_containingMultiLayerItem
private

Definition at line 74 of file RealSpaceCanvas.h.

Referenced by resetScene(), setCurrentItem(), and updateScene().

◆ m_currentItem

std::optional<ItemForRealSpace> RealSpaceCanvas::m_currentItem
private

◆ m_firstView

bool RealSpaceCanvas::m_firstView
private

Definition at line 75 of file RealSpaceCanvas.h.

Referenced by showEvent().

◆ m_realSpaceModel

std::unique_ptr<GUI::RealSpace::Model> RealSpaceCanvas::m_realSpaceModel
private

Definition at line 70 of file RealSpaceCanvas.h.

Referenced by resetScene(), and updateScene().

◆ m_sceneGeometry

SceneGeometry RealSpaceCanvas::m_sceneGeometry
private

Definition at line 71 of file RealSpaceCanvas.h.

Referenced by changeLayerSize(), and updateScene().

◆ m_view

GUI::RealSpace::Canvas* RealSpaceCanvas::m_view
private

The documentation for this class was generated from the following files: