29 #include <QGraphicsScene>
48 bool BitmapGraphicsExporter::Export(shared_ptr<SimPT_Sim::Sim> sim,
49 const string& file_path,
51 std::shared_ptr<BitmapGraphicsPreferences> prefs)
53 if (ifstream(file_path).good()) {
56 QFile::remove(QString::fromStdString(file_path));
62 QGraphicsScene canvas;
68 if (prefs->m_window_preset) {
69 top_left = QPointF(prefs->m_window_x_min, prefs->m_window_y_min);
70 bottom_right = QPointF(prefs->m_window_x_max, prefs->m_window_y_max);
72 const auto box = MeshGeometry::BoundingBox(shared_ptr<Mesh>(sim->GetCoreData().m_mesh.get(), [](
Mesh*){}));
73 const auto min_p = get<0>(box) - 1.05 * (get<1>(box) - get<0>(box));
74 const auto max_p = get<1>(box) + 1.05 * (get<1>(box) - get<0>(box));
75 top_left = QPointF(get<0>(min_p), get<1>(min_p));
76 bottom_right = QPointF(get<0>(max_p), get<1>(max_p));
81 if (prefs->m_size_preset) {
82 width = prefs->m_size_x;
83 height = prefs->m_size_y;
90 switch (prefs->m_format) {
91 case BitmapGraphicsPreferences::Png:
94 case BitmapGraphicsPreferences::Bmp:
97 case BitmapGraphicsPreferences::Jpeg:
103 if (!file_path.empty()) {
104 QImage image(QSize(width, height), QImage::Format_RGB32);
105 image.fill(QColor(QString::fromStdString(prefs->m_background_color)).rgb());
106 QPainter painter(&image);
107 canvas.render(&painter, QRectF(), QRectF(top_left, bottom_right));
108 status = image.save(QDir::toNativeSeparators(QString::fromStdString(file_path)), format.c_str());
Class drawing a simulator/mesh onto a QGraphicsScene.
Interface for MeshGeometry.
Namespace for SimPT shell package.
Namespace for the core simulator.
void Draw(std::shared_ptr< SimPT_Sim::SimInterface > sim, QGraphicsScene *scene)
Draws the mesh to QGraphicsScene.
Sim, the actual simulator.
Interface for MeshDrawer.
Interface for BitmapGraphicsExporter.
Provides wall-clock time stamp using the time call.
Structure of cells; key data structure.