Skip to content

Commit

Permalink
Add snapping setting logic for QPolyMod as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
starseeker committed Oct 6, 2023
1 parent d74f92d commit bad79f3
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/qged/plugins/polygon/QPolyMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ QPolyMod::QPolyMod()
QObject::connect(ps->sketch_name, &QLineEdit::textEdited, this, &QPolyMod::sketch_name_edit_str);
QObject::connect(ps->view_name, &QLineEdit::editingFinished, this, &QPolyMod::sketch_name_edit);
QObject::connect(ps->sketch_name, &QLineEdit::editingFinished, this, &QPolyMod::sketch_name_update);
QObject::connect(ps, &QPolySettings::grid_snapping_changed, this, &QPolyMod::toggle_grid_snapping);
QObject::connect(ps, &QPolySettings::line_snapping_changed, this, &QPolyMod::toggle_line_snapping);

QGroupBox *modpolyBox = new QGroupBox("Modify Polygon");
QVBoxLayout *mod_poly_gl = new QVBoxLayout;
Expand Down Expand Up @@ -825,6 +827,61 @@ QPolyMod::view_name_update()
emit view_updated(QG_VIEW_REFRESH);
}


void
QPolyMod::toggle_line_snapping(bool s)
{
line_snapping = s;
}

void
QPolyMod::toggle_grid_snapping(bool s)
{
grid_snapping = s;
}

void
QPolyMod::config_line_snapping(struct bview *v, struct bv_scene_obj *co)
{
if (!v)
return;
v->gv_s->gv_snap_flags = BV_SNAP_VIEW;
bu_ptbl_reset(&v->gv_s->gv_snap_objs);
if (!line_snapping) {
v->gv_s->gv_snap_lines = 0;
} else {
// Turn snapping on if we have other polygons to snap to
struct bu_ptbl *view_objs = bv_view_objs(v, BV_VIEW_OBJS);
if (!view_objs)
return;
for (size_t i = 0; i < BU_PTBL_LEN(view_objs); i++) {
struct bv_scene_obj *s = (struct bv_scene_obj *)BU_PTBL_GET(view_objs, i);
if (s == co)
continue;
if (s->s_type_flags & BV_POLYGONS)
bu_ptbl_ins(&v->gv_s->gv_snap_objs, (long *)s);
}
if (BU_PTBL_LEN(&v->gv_s->gv_snap_objs)) {
v->gv_s->gv_snap_lines = 1;
} else {
v->gv_s->gv_snap_lines = 0;
}
}
}

void
QPolyMod::config_grid_snapping(struct bview *v)
{
if (!v)
return;
v->gv_s->gv_snap_flags = BV_SNAP_VIEW;
if (!grid_snapping) {
v->gv_s->gv_grid.snap = 0;
} else {
v->gv_s->gv_grid.snap = 1;
}
}

void
QPolyMod::propagate_update(int)
{
Expand Down Expand Up @@ -862,6 +919,9 @@ QPolyMod::eventFilter(QObject *, QEvent *e)
cf->v = (p) ? p->s_v : gedp->ged_gvp;
cf->ptype = (ip) ? ip->type : BV_POLYGON_GENERAL;

config_line_snapping(cf->v, cf->wp);
config_grid_snapping(cf->v);

// Connect whatever the current filter is to pass on updating signals from
// the libqtcad logic.
QObject::connect(cf, &QgPolyFilter::view_updated, this, &QPolyMod::propagate_update);
Expand Down
6 changes: 6 additions & 0 deletions src/qged/plugins/polygon/QPolyMod.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ class QPolyMod : public QWidget
void view_name_edit_str(const QString &);
void view_name_edit();
void view_name_update();
void toggle_line_snapping(bool);
void config_line_snapping(struct bview *, struct bv_scene_obj *);
void toggle_grid_snapping(bool);
void config_grid_snapping(struct bview *);

protected:
bool eventFilter(QObject *, QEvent *);
Expand All @@ -103,6 +107,8 @@ class QPolyMod : public QWidget
int poly_cnt = 0;
struct bv_scene_obj *p = NULL;
bool do_bool = false;
bool line_snapping = false;
bool grid_snapping = false;

QgPolyFilter *cf = NULL;
QPolyUpdateFilter *puf;
Expand Down

0 comments on commit bad79f3

Please sign in to comment.