klayout/src/plugins/tools/view_25d/lay_plugin/layD25ViewWidget.h

190 lines
4.7 KiB
C
Raw Normal View History

2020-04-05 18:22:45 +02:00
/*
KLayout Layout Viewer
Copyright (C) 2006-2022 Matthias Koefferlein
2020-04-05 18:22:45 +02:00
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef HDR_layD25ViewWidget
#define HDR_layD25ViewWidget
2020-04-16 23:14:22 +02:00
#include "dbPolygon.h"
#include "layD25MemChunks.h"
#include "layD25Camera.h"
2020-04-05 18:22:45 +02:00
#include <QOpenGLWidget>
2020-04-10 22:40:53 +02:00
#include <QOpenGLVertexArrayObject>
#include <QOpenGLBuffer>
#include <QOpenGLShaderProgram>
#include <QOpenGLFunctions>
#include <QMatrix4x4>
#include <QPoint>
#include <QVector3D>
2020-04-05 18:22:45 +02:00
2020-04-16 23:14:22 +02:00
#include <memory>
2020-04-11 11:21:59 +02:00
namespace db
{
class Layout;
class Cell;
}
2021-08-31 13:29:50 +02:00
namespace tl
{
class AbsoluteProgress;
}
2020-04-05 18:22:45 +02:00
namespace lay
{
2020-04-11 11:21:59 +02:00
class LayoutView;
2021-09-23 00:33:55 +02:00
class LayerPropertiesNode;
2020-04-16 23:14:22 +02:00
class D25ViewWidget;
class D25InteractionMode
{
public:
D25InteractionMode (D25ViewWidget *widget);
virtual ~D25InteractionMode ();
D25ViewWidget *view () { return mp_view; }
virtual void mouse_move (QMouseEvent *event) = 0;
private:
D25ViewWidget *mp_view;
};
2020-04-11 11:21:59 +02:00
2020-04-05 18:22:45 +02:00
class D25ViewWidget
2020-04-10 22:40:53 +02:00
: public QOpenGLWidget,
2020-04-16 23:14:22 +02:00
private QOpenGLFunctions,
public D25Camera
2020-04-05 18:22:45 +02:00
{
Q_OBJECT
public:
D25ViewWidget (QWidget *parent);
~D25ViewWidget ();
2020-04-10 22:40:53 +02:00
2020-04-12 10:32:23 +02:00
void keyPressEvent (QKeyEvent *event);
void keyReleaseEvent (QKeyEvent *event);
2020-04-10 22:40:53 +02:00
void wheelEvent (QWheelEvent *event);
void mousePressEvent (QMouseEvent *event);
void mouseReleaseEvent (QMouseEvent *event);
void mouseMoveEvent (QMouseEvent *event);
2020-04-17 19:02:13 +02:00
bool attach_view(lay::LayoutView *view);
2021-09-22 23:29:58 +02:00
void refresh_view ();
2020-04-11 11:21:59 +02:00
2020-04-16 23:14:22 +02:00
QVector3D hit_point_with_scene(const QVector3D &line_dir);
void refresh ();
void reset ();
QVector3D displacement () const { return m_displacement; }
void set_displacement (const QVector3D &d)
{
m_displacement = d;
refresh ();
}
QVector3D scale_factors () const
{
return QVector3D (scale_factor (), scale_factor () * vscale_factor (), scale_factor ());
}
2020-04-16 23:14:22 +02:00
double scale_factor () const { return m_scale_factor; }
void set_scale_factor (double f)
{
m_scale_factor = f;
refresh ();
}
double vscale_factor () const { return m_vscale_factor; }
void set_vscale_factor (double f)
{
m_vscale_factor = f;
refresh ();
}
const std::string &error () const
{
return m_error;
}
2020-04-17 00:25:21 +02:00
signals:
void scale_factor_changed (double f);
void vscale_factor_changed (double f);
void init_failed ();
2020-04-17 00:25:21 +02:00
2020-04-16 23:14:22 +02:00
protected:
virtual void camera_changed ();
virtual double aspect_ratio () const;
virtual void showEvent (QShowEvent *);
2020-04-16 23:14:22 +02:00
public slots:
void fit ();
2020-04-10 22:40:53 +02:00
private:
2021-09-23 00:33:55 +02:00
typedef lay::mem_chunks<GLfloat, 1024 * 18> triangle_chunks_type;
typedef lay::mem_chunks<GLfloat, 1024 * 6> line_chunks_type;
2020-04-11 11:21:59 +02:00
std::unique_ptr<D25InteractionMode> mp_mode;
2021-09-23 00:33:55 +02:00
QOpenGLShaderProgram *m_shapes_program, *m_lines_program, *m_gridplane_program;
std::string m_error;
2020-04-11 22:46:35 +02:00
double m_scale_factor;
double m_vscale_factor;
2020-04-11 22:46:35 +02:00
QVector3D m_displacement;
2020-04-11 11:21:59 +02:00
lay::LayoutView *mp_view;
2020-04-11 22:46:35 +02:00
db::DBox m_bbox;
double m_zmin, m_zmax;
2020-04-11 11:21:59 +02:00
2021-09-23 00:33:55 +02:00
std::list<triangle_chunks_type> m_vertex_chunks;
std::list<line_chunks_type> m_line_chunks;
2020-04-11 11:21:59 +02:00
struct LayerInfo {
2021-09-23 00:33:55 +02:00
const triangle_chunks_type *vertex_chunk;
const line_chunks_type *line_chunk;
2020-04-11 11:21:59 +02:00
GLfloat color [4];
2021-09-23 00:33:55 +02:00
GLfloat frame_color [4];
2021-09-22 23:29:58 +02:00
bool visible;
2020-04-11 11:21:59 +02:00
};
2021-09-22 23:29:58 +02:00
std::vector<LayerInfo> m_layers;
std::multimap<std::pair<size_t, size_t>, size_t> m_layer_to_info;
2020-04-10 22:40:53 +02:00
void initializeGL ();
void paintGL ();
void resizeGL (int w, int h);
void do_initialize_gl ();
2020-04-17 19:02:13 +02:00
bool prepare_view();
2021-09-23 00:33:55 +02:00
void render_layout (tl::AbsoluteProgress &progress, D25ViewWidget::triangle_chunks_type &vertex_chunks, D25ViewWidget::line_chunks_type &line_chunks, const db::Layout &layout, const db::Cell &cell, const db::Box &clip_box, unsigned int layer, double zstart, double zstop);
void render_polygon (D25ViewWidget::triangle_chunks_type &vertex_chunks, D25ViewWidget::line_chunks_type &line_chunks, const db::Polygon &poly, double dbu, double zstart, double zstop);
void render_wall (D25ViewWidget::triangle_chunks_type &vertex_chunks, D25ViewWidget::line_chunks_type &line_chunks, const db::Edge &poly, double dbu, double zstart, double zstop);
void reset_viewport ();
2021-09-23 00:33:55 +02:00
static void lp_to_info (const lay::LayerPropertiesNode &lp, D25ViewWidget::LayerInfo &info);
2020-04-05 18:22:45 +02:00
};
}
#endif