From dfc218c452db606f206fa12542c3befad1f509b3 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 a6be420..2930596 100644 --- a/src/clipboard.cpp +++ b/src/clipboard.cpp @@ -117,6 +117,15 @@ void GraphicsWindow::CopySelection(void) { 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) || @@ -124,7 +133,8 @@ void GraphicsWindow::CopySelection(void) { !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); @@ -201,7 +211,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 597f9d8..5570fd5 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 4cbc4e8..61c7f82 100644 --- a/src/ui.h +++ b/src/ui.h @@ -658,6 +658,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);