Live updates of layer properties

This commit is contained in:
Matthias Koefferlein 2021-09-22 23:29:58 +02:00
parent df4e6ce262
commit 464bb75626
4 changed files with 73 additions and 9 deletions

View File

@ -60,12 +60,31 @@ D25View::D25View (lay::Dispatcher *root, lay::LayoutView *view)
mp_ui->gl_stack->setCurrentIndex (0);
lay::activate_help_links (mp_ui->doc_label);
view->cellviews_changed_event.add (this, &D25View::cellviews_changed);
view->layer_list_changed_event.add (this, &D25View::layer_properties_changed);
}
D25View::~D25View ()
{
delete mp_ui;
mp_ui = 0;
if (view ()) {
view ()->cellviews_changed_event.remove (this, &D25View::cellviews_changed);
}
}
void
D25View::cellviews_changed ()
{
deactivate ();
}
void
D25View::layer_properties_changed (int)
{
mp_ui->d25_view->refresh_view ();
}
void

View File

@ -70,6 +70,9 @@ private slots:
private:
Ui::D25View *mp_ui;
void cellviews_changed ();
void layer_properties_changed (int);
};
}

View File

@ -571,10 +571,19 @@ namespace {
}
static void color_to_gl (color_t color, GLfloat (&gl_color) [4])
{
gl_color[0] = ((color >> 16) & 0xff) / 255.0f;
gl_color[1] = ((color >> 8) & 0xff) / 255.0f;
gl_color[2] = (color & 0xff) / 255.0f;
gl_color[3] = 1.0f;
}
bool
D25ViewWidget::prepare_view ()
{
m_layers.clear ();
m_layer_to_info.clear ();
m_vertex_chunks.clear ();
bool zset = false;
@ -594,7 +603,7 @@ D25ViewWidget::prepare_view ()
for (lay::LayerPropertiesConstIterator lp = mp_view->begin_layers (); ! lp.at_end (); ++lp) {
std::vector<db::D25LayerInfo> zinfo;
if (! lp->has_children () && lp->visible (true)) {
if (! lp->has_children ()) {
zinfo = zdata (mp_view, lp->cellview_index (), lp->layer_index ());
}
@ -617,7 +626,7 @@ D25ViewWidget::prepare_view ()
for (lay::LayerPropertiesConstIterator lp = mp_view->begin_layers (); ! lp.at_end (); ++lp) {
std::vector<db::D25LayerInfo> zinfo;
if (! lp->has_children () && lp->visible (true)) {
if (! lp->has_children ()) {
zinfo = zdata (mp_view, lp->cellview_index (), lp->layer_index ());
}
@ -633,11 +642,11 @@ D25ViewWidget::prepare_view ()
m_vertex_chunks.push_back (chunks_type ());
LayerInfo info;
info.color[0] = ((color >> 16) & 0xff) / 255.0f;
info.color[1] = ((color >> 8) & 0xff) / 255.0f;
info.color[2] = (color & 0xff) / 255.0f;
color_to_gl (color, info.color);
info.vertex_chunk = &m_vertex_chunks.back ();
info.visible = lp->visible (true);
m_layer_to_info [std::make_pair (lp->cellview_index (), lp->layer_index ())] = m_layers.size ();
m_layers.push_back (info);
const lay::CellView &cv = mp_view->cellview ((unsigned int) lp->cellview_index ());
@ -660,6 +669,34 @@ D25ViewWidget::prepare_view ()
return any;
}
void
D25ViewWidget::refresh_view ()
{
if (! mp_view) {
return;
}
for (lay::LayerPropertiesConstIterator lp = mp_view->begin_layers (); ! lp.at_end (); ++lp) {
std::map<std::pair<size_t, size_t>, size_t>::const_iterator l = m_layer_to_info.find (std::make_pair (lp->cellview_index (), lp->layer_index ()));
if (l != m_layer_to_info.end ()) {
if (l->second < m_layers.size ()) {
LayerInfo &info = m_layers [l->second];
color_to_gl (lp->fill_color (true), info.color);
info.visible = lp->visible (true);
}
}
}
refresh ();
}
void
D25ViewWidget::render_polygon (D25ViewWidget::chunks_type &chunks, const db::Polygon &poly, double dbu, double zstart, double zstop)
{
@ -986,9 +1023,11 @@ D25ViewWidget::paintGL ()
glEnable (GL_DEPTH_TEST);
glEnableVertexAttribArray (positions);
for (std::list<LayerInfo>::const_iterator l = m_layers.begin (); l != m_layers.end (); ++l) {
m_shapes_program->setUniformValue ("color", l->color [0], l->color [1], l->color [2], l->color [3]);
l->vertex_chunk->draw_to (this, positions, GL_TRIANGLES);
for (std::vector<LayerInfo>::const_iterator l = m_layers.begin (); l != m_layers.end (); ++l) {
if (l->visible) {
m_shapes_program->setUniformValue ("color", l->color [0], l->color [1], l->color [2], l->color [3]);
l->vertex_chunk->draw_to (this, positions, GL_TRIANGLES);
}
}
glDisableVertexAttribArray (positions);

View File

@ -88,6 +88,7 @@ public:
void mouseMoveEvent (QMouseEvent *event);
bool attach_view(lay::LayoutView *view);
void refresh_view ();
QVector3D hit_point_with_scene(const QVector3D &line_dir);
void refresh ();
@ -158,9 +159,11 @@ private:
struct LayerInfo {
const chunks_type *vertex_chunk;
GLfloat color [4];
bool visible;
};
std::list<LayerInfo> m_layers;
std::vector<LayerInfo> m_layers;
std::map<std::pair<size_t, size_t>, size_t> m_layer_to_info;
void initializeGL ();
void paintGL ();