From bb0eef2b96216fdd1b4546eb191fc1d499ff430f Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 20 May 2016 14:19:50 +0000 Subject: [PATCH] Allow copying and pasting constraints. --- src/clipboard.cpp | 19 +++++++++++++++++-- src/draw.cpp | 7 +++++++ src/ui.h | 1 + 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/clipboard.cpp b/src/clipboard.cpp index 91ea0f8..711a182 100644 --- a/src/clipboard.cpp +++ b/src/clipboard.cpp @@ -118,6 +118,15 @@ void GraphicsWindow::CopySelection() { SS.clipboard.r.Add(&cr); } + for(Selection *s = ls->First(); s; s = ls->NextAfter(s)) { + if(!s->constraint.v) continue; + + Constraint *c = SK.GetConstraint(s->constraint); + if(c->type == Constraint::COMMENT) { + SS.clipboard.c.Add(c); + } + } + Constraint *c; for(c = SK.constraint.First(); c; c = SK.constraint.NextAfter(c)) { if(!SS.clipboard.ContainsEntity(c->ptA) || @@ -125,7 +134,8 @@ void GraphicsWindow::CopySelection() { !SS.clipboard.ContainsEntity(c->entityA) || !SS.clipboard.ContainsEntity(c->entityB) || !SS.clipboard.ContainsEntity(c->entityC) || - !SS.clipboard.ContainsEntity(c->entityD)) { + !SS.clipboard.ContainsEntity(c->entityD) || + c->type == Constraint::COMMENT) { continue; } SS.clipboard.c.Add(c); @@ -202,7 +212,12 @@ void GraphicsWindow::PasteClipboard(Vector trans, double theta, double scale) { c.other2 = cc->other2; c.reference = cc->reference; c.disp = cc->disp; - Constraint::AddConstraint(&c, /*rememberForUndo=*/false); + c.comment = cc->comment; + hConstraint hc = Constraint::AddConstraint(&c, /*rememberForUndo=*/false); + if(c.type == Constraint::COMMENT) { + SK.GetConstraint(hc)->disp.offset = SK.GetConstraint(hc)->disp.offset.Plus(trans); + MakeSelected(hc); + } } SS.ScheduleGenerateAll(); diff --git a/src/draw.cpp b/src/draw.cpp index 60d071d..8c9fb2d 100644 --- a/src/draw.cpp +++ b/src/draw.cpp @@ -156,6 +156,13 @@ void GraphicsWindow::MakeSelected(hEntity he) { stog.entity = he; MakeSelected(&stog); } + +void GraphicsWindow::MakeSelected(hConstraint hc) { + Selection stog = {}; + stog.constraint = hc; + MakeSelected(&stog); +} + void GraphicsWindow::MakeSelected(Selection *stog) { if(stog->IsEmpty()) return; if(IsSelected(stog)) return; diff --git a/src/ui.h b/src/ui.h index 8724f0e..dea2de1 100644 --- a/src/ui.h +++ b/src/ui.h @@ -659,6 +659,7 @@ public: bool IsSelected(Selection *s); bool IsSelected(hEntity he); void MakeSelected(hEntity he); + void MakeSelected(hConstraint hc); void MakeSelected(Selection *s); void MakeUnselected(hEntity he, bool coincidentPointTrick); void MakeUnselected(Selection *s, bool coincidentPointTrick);