From 464bb75626f8423ef7e5272bcd7a7dc4834137d1 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Wed, 22 Sep 2021 23:29:58 +0200 Subject: [PATCH] Live updates of layer properties --- .../tools/view_25d/lay_plugin/layD25View.cc | 19 +++++++ .../tools/view_25d/lay_plugin/layD25View.h | 3 + .../view_25d/lay_plugin/layD25ViewWidget.cc | 55 ++++++++++++++++--- .../view_25d/lay_plugin/layD25ViewWidget.h | 5 +- 4 files changed, 73 insertions(+), 9 deletions(-) diff --git a/src/plugins/tools/view_25d/lay_plugin/layD25View.cc b/src/plugins/tools/view_25d/lay_plugin/layD25View.cc index b0b4888fe..0055a43cf 100644 --- a/src/plugins/tools/view_25d/lay_plugin/layD25View.cc +++ b/src/plugins/tools/view_25d/lay_plugin/layD25View.cc @@ -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 diff --git a/src/plugins/tools/view_25d/lay_plugin/layD25View.h b/src/plugins/tools/view_25d/lay_plugin/layD25View.h index 95b6fd405..8cbedbbfc 100644 --- a/src/plugins/tools/view_25d/lay_plugin/layD25View.h +++ b/src/plugins/tools/view_25d/lay_plugin/layD25View.h @@ -70,6 +70,9 @@ private slots: private: Ui::D25View *mp_ui; + + void cellviews_changed (); + void layer_properties_changed (int); }; } diff --git a/src/plugins/tools/view_25d/lay_plugin/layD25ViewWidget.cc b/src/plugins/tools/view_25d/lay_plugin/layD25ViewWidget.cc index 8bf19c87d..22144ec51 100644 --- a/src/plugins/tools/view_25d/lay_plugin/layD25ViewWidget.cc +++ b/src/plugins/tools/view_25d/lay_plugin/layD25ViewWidget.cc @@ -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 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 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, 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::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::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); diff --git a/src/plugins/tools/view_25d/lay_plugin/layD25ViewWidget.h b/src/plugins/tools/view_25d/lay_plugin/layD25ViewWidget.h index e0fc28412..e0addceca 100644 --- a/src/plugins/tools/view_25d/lay_plugin/layD25ViewWidget.h +++ b/src/plugins/tools/view_25d/lay_plugin/layD25ViewWidget.h @@ -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 m_layers; + std::vector m_layers; + std::map, size_t> m_layer_to_info; void initializeGL (); void paintGL ();