Allow copying and pasting constraints.

This commit is contained in:
whitequark 2016-05-20 14:19:50 +00:00
parent 457ff78849
commit bb0eef2b96
3 changed files with 25 additions and 2 deletions

View File

@ -118,6 +118,15 @@ void GraphicsWindow::CopySelection() {
SS.clipboard.r.Add(&cr); 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; Constraint *c;
for(c = SK.constraint.First(); c; c = SK.constraint.NextAfter(c)) { for(c = SK.constraint.First(); c; c = SK.constraint.NextAfter(c)) {
if(!SS.clipboard.ContainsEntity(c->ptA) || if(!SS.clipboard.ContainsEntity(c->ptA) ||
@ -125,7 +134,8 @@ void GraphicsWindow::CopySelection() {
!SS.clipboard.ContainsEntity(c->entityA) || !SS.clipboard.ContainsEntity(c->entityA) ||
!SS.clipboard.ContainsEntity(c->entityB) || !SS.clipboard.ContainsEntity(c->entityB) ||
!SS.clipboard.ContainsEntity(c->entityC) || !SS.clipboard.ContainsEntity(c->entityC) ||
!SS.clipboard.ContainsEntity(c->entityD)) { !SS.clipboard.ContainsEntity(c->entityD) ||
c->type == Constraint::COMMENT) {
continue; continue;
} }
SS.clipboard.c.Add(c); SS.clipboard.c.Add(c);
@ -202,7 +212,12 @@ void GraphicsWindow::PasteClipboard(Vector trans, double theta, double scale) {
c.other2 = cc->other2; c.other2 = cc->other2;
c.reference = cc->reference; c.reference = cc->reference;
c.disp = cc->disp; 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(); SS.ScheduleGenerateAll();

View File

@ -156,6 +156,13 @@ void GraphicsWindow::MakeSelected(hEntity he) {
stog.entity = he; stog.entity = he;
MakeSelected(&stog); MakeSelected(&stog);
} }
void GraphicsWindow::MakeSelected(hConstraint hc) {
Selection stog = {};
stog.constraint = hc;
MakeSelected(&stog);
}
void GraphicsWindow::MakeSelected(Selection *stog) { void GraphicsWindow::MakeSelected(Selection *stog) {
if(stog->IsEmpty()) return; if(stog->IsEmpty()) return;
if(IsSelected(stog)) return; if(IsSelected(stog)) return;

View File

@ -659,6 +659,7 @@ public:
bool IsSelected(Selection *s); bool IsSelected(Selection *s);
bool IsSelected(hEntity he); bool IsSelected(hEntity he);
void MakeSelected(hEntity he); void MakeSelected(hEntity he);
void MakeSelected(hConstraint hc);
void MakeSelected(Selection *s); void MakeSelected(Selection *s);
void MakeUnselected(hEntity he, bool coincidentPointTrick); void MakeUnselected(hEntity he, bool coincidentPointTrick);
void MakeUnselected(Selection *s, bool coincidentPointTrick); void MakeUnselected(Selection *s, bool coincidentPointTrick);