2013-07-28 22:08:34 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// The clipboard that gets manipulated when the user selects Edit -> Cut,
|
|
|
|
// Copy, Paste, etc.; may contain entities only, not constraints.
|
|
|
|
//
|
|
|
|
// Copyright 2008-2013 Jonathan Westhues.
|
|
|
|
//-----------------------------------------------------------------------------
|
2009-12-04 08:08:41 +00:00
|
|
|
#include "solvespace.h"
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void SolveSpaceUI::Clipboard::Clear() {
|
2009-12-04 08:08:41 +00:00
|
|
|
c.Clear();
|
|
|
|
r.Clear();
|
|
|
|
}
|
|
|
|
|
2015-12-30 12:36:31 +00:00
|
|
|
bool SolveSpaceUI::Clipboard::ContainsEntity(hEntity he) {
|
|
|
|
if(he.v == Entity::NO_ENTITY.v)
|
|
|
|
return true;
|
|
|
|
|
2009-12-04 08:08:41 +00:00
|
|
|
ClipboardRequest *cr;
|
|
|
|
for(cr = r.First(); cr; cr = r.NextAfter(cr)) {
|
2015-12-30 12:36:31 +00:00
|
|
|
if(cr->oldEnt.v == he.v)
|
|
|
|
return true;
|
|
|
|
|
2009-12-04 08:08:41 +00:00
|
|
|
for(int i = 0; i < MAX_POINTS_IN_ENTITY; i++) {
|
2015-12-30 12:36:31 +00:00
|
|
|
if(cr->oldPointEnt[i].v == he.v)
|
|
|
|
return true;
|
2009-12-04 08:08:41 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-30 12:36:31 +00:00
|
|
|
return false;
|
2009-12-04 08:08:41 +00:00
|
|
|
}
|
|
|
|
|
2015-12-30 12:36:31 +00:00
|
|
|
hEntity SolveSpaceUI::Clipboard::NewEntityFor(hEntity he) {
|
|
|
|
if(he.v == Entity::NO_ENTITY.v)
|
|
|
|
return Entity::NO_ENTITY;
|
|
|
|
|
|
|
|
ClipboardRequest *cr;
|
|
|
|
for(cr = r.First(); cr; cr = r.NextAfter(cr)) {
|
|
|
|
if(cr->oldEnt.v == he.v)
|
|
|
|
return cr->newReq.entity(0);
|
|
|
|
|
|
|
|
for(int i = 0; i < MAX_POINTS_IN_ENTITY; i++) {
|
|
|
|
if(cr->oldPointEnt[i].v == he.v)
|
|
|
|
return cr->newReq.entity(1+i);
|
|
|
|
}
|
2009-12-04 08:08:41 +00:00
|
|
|
}
|
2016-05-18 22:51:36 +00:00
|
|
|
|
|
|
|
ssassert(false, "Expected to find entity in some clipboard request");
|
2009-12-04 08:08:41 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void GraphicsWindow::DeleteSelection() {
|
2009-12-04 08:08:41 +00:00
|
|
|
SK.request.ClearTags();
|
|
|
|
SK.constraint.ClearTags();
|
|
|
|
List<Selection> *ls = &(selection);
|
|
|
|
for(Selection *s = ls->First(); s; s = ls->NextAfter(s)) {
|
|
|
|
hRequest r = { 0 };
|
|
|
|
if(s->entity.v && s->entity.isFromRequest()) {
|
|
|
|
r = s->entity.request();
|
|
|
|
}
|
|
|
|
if(r.v && !r.IsFromReferences()) {
|
|
|
|
SK.request.Tag(r, 1);
|
|
|
|
}
|
|
|
|
if(s->constraint.v) {
|
|
|
|
SK.constraint.Tag(s->constraint, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SK.constraint.RemoveTagged();
|
|
|
|
// Note that this regenerates and clears the selection, to avoid
|
|
|
|
// lingering references to the just-deleted items.
|
|
|
|
DeleteTaggedRequests();
|
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void GraphicsWindow::CopySelection() {
|
2009-12-04 08:08:41 +00:00
|
|
|
SS.clipboard.Clear();
|
|
|
|
|
|
|
|
Entity *wrkpl = SK.GetEntity(ActiveWorkplane());
|
|
|
|
Entity *wrkpln = SK.GetEntity(wrkpl->normal);
|
|
|
|
Vector u = wrkpln->NormalU(),
|
|
|
|
v = wrkpln->NormalV(),
|
|
|
|
n = wrkpln->NormalN(),
|
|
|
|
p = SK.GetEntity(wrkpl->point[0])->PointGetNum();
|
|
|
|
|
|
|
|
List<Selection> *ls = &(selection);
|
|
|
|
for(Selection *s = ls->First(); s; s = ls->NextAfter(s)) {
|
|
|
|
if(!s->entity.v) continue;
|
|
|
|
// Work only on entities that have requests that will generate them.
|
|
|
|
Entity *e = SK.GetEntity(s->entity);
|
|
|
|
bool hasDistance;
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
Request::Type req;
|
|
|
|
int pts;
|
2009-12-04 08:08:41 +00:00
|
|
|
if(!EntReqTable::GetEntityInfo(e->type, e->extraPoints,
|
|
|
|
&req, &pts, NULL, &hasDistance))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
if(req == Request::Type::WORKPLANE) continue;
|
2009-12-04 08:08:41 +00:00
|
|
|
|
2015-03-27 15:31:23 +00:00
|
|
|
ClipboardRequest cr = {};
|
2009-12-04 08:08:41 +00:00
|
|
|
cr.type = req;
|
|
|
|
cr.extraPoints = e->extraPoints;
|
|
|
|
cr.style = e->style;
|
2015-11-06 08:40:12 +00:00
|
|
|
cr.str = e->str;
|
|
|
|
cr.font = e->font;
|
2009-12-04 08:08:41 +00:00
|
|
|
cr.construction = e->construction;
|
2013-10-19 05:36:45 +00:00
|
|
|
{for(int i = 0; i < pts; i++) {
|
2009-12-04 08:08:41 +00:00
|
|
|
Vector pt = SK.GetEntity(e->point[i])->PointGetNum();
|
|
|
|
pt = pt.Minus(p);
|
|
|
|
pt = pt.DotInToCsys(u, v, n);
|
|
|
|
cr.point[i] = pt;
|
2013-10-19 05:36:45 +00:00
|
|
|
}}
|
2009-12-04 08:08:41 +00:00
|
|
|
if(hasDistance) {
|
|
|
|
cr.distance = SK.GetEntity(e->distance)->DistanceGetNum();
|
|
|
|
}
|
|
|
|
|
|
|
|
cr.oldEnt = e->h;
|
|
|
|
for(int i = 0; i < pts; i++) {
|
|
|
|
cr.oldPointEnt[i] = e->point[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
SS.clipboard.r.Add(&cr);
|
|
|
|
}
|
|
|
|
|
2016-05-20 14:19:50 +00:00
|
|
|
for(Selection *s = ls->First(); s; s = ls->NextAfter(s)) {
|
|
|
|
if(!s->constraint.v) continue;
|
|
|
|
|
|
|
|
Constraint *c = SK.GetConstraint(s->constraint);
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
if(c->type == Constraint::Type::COMMENT) {
|
2016-05-20 14:19:50 +00:00
|
|
|
SS.clipboard.c.Add(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-04 08:08:41 +00:00
|
|
|
Constraint *c;
|
|
|
|
for(c = SK.constraint.First(); c; c = SK.constraint.NextAfter(c)) {
|
2015-12-30 12:36:31 +00:00
|
|
|
if(!SS.clipboard.ContainsEntity(c->ptA) ||
|
|
|
|
!SS.clipboard.ContainsEntity(c->ptB) ||
|
|
|
|
!SS.clipboard.ContainsEntity(c->entityA) ||
|
|
|
|
!SS.clipboard.ContainsEntity(c->entityB) ||
|
|
|
|
!SS.clipboard.ContainsEntity(c->entityC) ||
|
2016-05-20 14:19:50 +00:00
|
|
|
!SS.clipboard.ContainsEntity(c->entityD) ||
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
c->type == Constraint::Type::COMMENT) {
|
2009-12-04 08:08:41 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SS.clipboard.c.Add(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-15 12:26:22 +00:00
|
|
|
void GraphicsWindow::PasteClipboard(Vector trans, double theta, double scale) {
|
2009-12-04 08:08:41 +00:00
|
|
|
Entity *wrkpl = SK.GetEntity(ActiveWorkplane());
|
|
|
|
Entity *wrkpln = SK.GetEntity(wrkpl->normal);
|
|
|
|
Vector u = wrkpln->NormalU(),
|
|
|
|
v = wrkpln->NormalV(),
|
2009-12-15 12:26:22 +00:00
|
|
|
n = wrkpln->NormalN(),
|
2009-12-04 08:08:41 +00:00
|
|
|
p = SK.GetEntity(wrkpl->point[0])->PointGetNum();
|
|
|
|
|
|
|
|
ClipboardRequest *cr;
|
|
|
|
for(cr = SS.clipboard.r.First(); cr; cr = SS.clipboard.r.NextAfter(cr)) {
|
2016-05-25 12:08:19 +00:00
|
|
|
hRequest hr = AddRequest(cr->type, /*rememberForUndo=*/false);
|
2009-12-04 08:08:41 +00:00
|
|
|
Request *r = SK.GetRequest(hr);
|
|
|
|
r->extraPoints = cr->extraPoints;
|
|
|
|
r->style = cr->style;
|
2015-11-06 08:40:12 +00:00
|
|
|
r->str = cr->str;
|
|
|
|
r->font = cr->font;
|
2009-12-04 08:08:41 +00:00
|
|
|
r->construction = cr->construction;
|
|
|
|
// Need to regen to get the right number of points, if extraPoints
|
|
|
|
// changed.
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
SS.GenerateAll(SolveSpaceUI::Generate::REGEN);
|
2009-12-04 08:08:41 +00:00
|
|
|
SS.MarkGroupDirty(r->group);
|
|
|
|
bool hasDistance;
|
2009-12-21 16:44:00 +00:00
|
|
|
int i, pts;
|
2009-12-04 08:08:41 +00:00
|
|
|
EntReqTable::GetRequestInfo(r->type, r->extraPoints,
|
|
|
|
NULL, &pts, NULL, &hasDistance);
|
2009-12-21 16:44:00 +00:00
|
|
|
for(i = 0; i < pts; i++) {
|
2009-12-04 08:08:41 +00:00
|
|
|
Vector pt = cr->point[i];
|
2009-12-15 12:26:22 +00:00
|
|
|
// We need the reflection to occur within the workplane; it may
|
|
|
|
// otherwise correspond to just a rotation as projected.
|
|
|
|
if(scale < 0) {
|
|
|
|
pt.x *= -1;
|
|
|
|
}
|
|
|
|
// Likewise the scale, which could otherwise take us out of the
|
|
|
|
// workplane.
|
|
|
|
pt = pt.ScaledBy(fabs(scale));
|
2009-12-04 08:08:41 +00:00
|
|
|
pt = pt.ScaleOutOfCsys(u, v, Vector::From(0, 0, 0));
|
|
|
|
pt = pt.Plus(p);
|
2009-12-15 12:26:22 +00:00
|
|
|
pt = pt.RotatedAbout(n, theta);
|
2009-12-04 08:08:41 +00:00
|
|
|
pt = pt.Plus(trans);
|
|
|
|
SK.GetEntity(hr.entity(i+1))->PointForceTo(pt);
|
|
|
|
}
|
|
|
|
if(hasDistance) {
|
2009-12-15 12:26:22 +00:00
|
|
|
SK.GetEntity(hr.entity(64))->DistanceForceTo(
|
|
|
|
cr->distance*fabs(scale));
|
2009-12-04 08:08:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cr->newReq = hr;
|
2010-01-03 10:26:15 +00:00
|
|
|
MakeSelected(hr.entity(0));
|
2009-12-21 16:44:00 +00:00
|
|
|
for(i = 0; i < pts; i++) {
|
2010-01-03 10:26:15 +00:00
|
|
|
MakeSelected(hr.entity(i+1));
|
2009-12-21 16:44:00 +00:00
|
|
|
}
|
2009-12-04 08:08:41 +00:00
|
|
|
}
|
2015-03-29 00:30:52 +00:00
|
|
|
|
2015-12-30 12:36:31 +00:00
|
|
|
Constraint *cc;
|
|
|
|
for(cc = SS.clipboard.c.First(); cc; cc = SS.clipboard.c.NextAfter(cc)) {
|
|
|
|
Constraint c = {};
|
|
|
|
c.group = SS.GW.activeGroup;
|
|
|
|
c.workplane = SS.GW.ActiveWorkplane();
|
|
|
|
c.type = cc->type;
|
|
|
|
c.valA = cc->valA;
|
|
|
|
c.ptA = SS.clipboard.NewEntityFor(cc->ptA);
|
|
|
|
c.ptB = SS.clipboard.NewEntityFor(cc->ptB);
|
|
|
|
c.entityA = SS.clipboard.NewEntityFor(cc->entityA);
|
|
|
|
c.entityB = SS.clipboard.NewEntityFor(cc->entityB);
|
|
|
|
c.entityC = SS.clipboard.NewEntityFor(cc->entityC);
|
|
|
|
c.entityD = SS.clipboard.NewEntityFor(cc->entityD);
|
|
|
|
c.other = cc->other;
|
|
|
|
c.other2 = cc->other2;
|
|
|
|
c.reference = cc->reference;
|
|
|
|
c.disp = cc->disp;
|
2016-05-20 14:19:50 +00:00
|
|
|
c.comment = cc->comment;
|
2016-07-19 12:12:01 +00:00
|
|
|
switch(c.type) {
|
|
|
|
case Constraint::Type::COMMENT:
|
|
|
|
c.disp.offset = c.disp.offset.Plus(trans);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Constraint::Type::PT_PT_DISTANCE:
|
|
|
|
case Constraint::Type::PT_LINE_DISTANCE:
|
|
|
|
case Constraint::Type::PROJ_PT_DISTANCE:
|
|
|
|
case Constraint::Type::DIAMETER:
|
|
|
|
c.valA *= fabs(scale);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-05-20 14:19:50 +00:00
|
|
|
hConstraint hc = Constraint::AddConstraint(&c, /*rememberForUndo=*/false);
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
if(c.type == Constraint::Type::COMMENT) {
|
2016-05-20 14:19:50 +00:00
|
|
|
MakeSelected(hc);
|
|
|
|
}
|
2009-12-04 08:08:41 +00:00
|
|
|
}
|
|
|
|
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleGenerateAll();
|
2009-12-04 08:08:41 +00:00
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
void GraphicsWindow::MenuClipboard(Command id) {
|
|
|
|
if(id != Command::DELETE && !SS.GW.LockedInWorkplane()) {
|
2010-01-16 18:15:40 +00:00
|
|
|
Error("Cut, paste, and copy work only in a workplane.\n\n"
|
2009-12-04 08:08:41 +00:00
|
|
|
"Select one with Sketch -> In Workplane.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(id) {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::PASTE: {
|
2009-12-15 12:26:22 +00:00
|
|
|
SS.UndoRemember();
|
2009-12-04 08:08:41 +00:00
|
|
|
Vector trans = SS.GW.projRight.ScaledBy(80/SS.GW.scale).Plus(
|
|
|
|
SS.GW.projUp .ScaledBy(40/SS.GW.scale));
|
2010-01-04 03:17:09 +00:00
|
|
|
SS.GW.ClearSelection();
|
2009-12-15 12:26:22 +00:00
|
|
|
SS.GW.PasteClipboard(trans, 0, 1);
|
2009-12-04 08:08:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::PASTE_TRANSFORM: {
|
2009-12-15 12:26:22 +00:00
|
|
|
if(SS.clipboard.r.n == 0) {
|
|
|
|
Error("Clipboard is empty; nothing to paste.");
|
|
|
|
break;
|
|
|
|
}
|
2015-03-29 00:30:52 +00:00
|
|
|
|
2009-12-15 12:26:22 +00:00
|
|
|
Entity *wrkpl = SK.GetEntity(SS.GW.ActiveWorkplane());
|
|
|
|
Vector p = SK.GetEntity(wrkpl->point[0])->PointGetNum();
|
|
|
|
SS.TW.shown.paste.times = 1;
|
|
|
|
SS.TW.shown.paste.trans = Vector::From(0, 0, 0);
|
|
|
|
SS.TW.shown.paste.theta = 0;
|
|
|
|
SS.TW.shown.paste.origin = p;
|
|
|
|
SS.TW.shown.paste.scale = 1;
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
SS.TW.GoToScreen(TextWindow::Screen::PASTE_TRANSFORMED);
|
2009-12-15 12:26:22 +00:00
|
|
|
SS.GW.ForceTextWindowShown();
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2009-12-04 08:08:41 +00:00
|
|
|
break;
|
2009-12-15 12:26:22 +00:00
|
|
|
}
|
2009-12-04 08:08:41 +00:00
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::COPY:
|
2009-12-04 08:08:41 +00:00
|
|
|
SS.GW.CopySelection();
|
|
|
|
SS.GW.ClearSelection();
|
|
|
|
break;
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::CUT:
|
2009-12-04 08:08:41 +00:00
|
|
|
SS.UndoRemember();
|
|
|
|
SS.GW.CopySelection();
|
|
|
|
SS.GW.DeleteSelection();
|
|
|
|
break;
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Command::DELETE:
|
2009-12-04 08:08:41 +00:00
|
|
|
SS.UndoRemember();
|
|
|
|
SS.GW.DeleteSelection();
|
|
|
|
break;
|
|
|
|
|
2016-05-18 22:51:36 +00:00
|
|
|
default: ssassert(false, "Unexpected menu ID");
|
2009-12-04 08:08:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-16 19:51:20 +00:00
|
|
|
bool TextWindow::EditControlDoneForPaste(const char *s) {
|
2010-10-12 03:13:41 +00:00
|
|
|
Expr *e;
|
2009-12-15 12:26:22 +00:00
|
|
|
switch(edit.meaning) {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Edit::PASTE_TIMES_REPEATED: {
|
2016-05-25 12:08:19 +00:00
|
|
|
e = Expr::From(s, /*popUpError=*/true);
|
2010-10-12 03:13:41 +00:00
|
|
|
if(!e) break;
|
|
|
|
int v = (int)e->Eval();
|
2009-12-15 12:26:22 +00:00
|
|
|
if(v > 0) {
|
|
|
|
shown.paste.times = v;
|
|
|
|
} else {
|
|
|
|
Error("Number of copies to paste must be at least one.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Edit::PASTE_ANGLE:
|
2016-05-25 12:08:19 +00:00
|
|
|
e = Expr::From(s, /*popUpError=*/true);
|
2010-10-12 03:13:41 +00:00
|
|
|
if(!e) break;
|
|
|
|
shown.paste.theta = WRAP_SYMMETRIC((e->Eval())*PI/180, 2*PI);
|
2009-12-15 12:26:22 +00:00
|
|
|
break;
|
|
|
|
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
case Edit::PASTE_SCALE: {
|
2016-05-25 12:08:19 +00:00
|
|
|
e = Expr::From(s, /*popUpError=*/true);
|
2010-10-12 03:13:41 +00:00
|
|
|
double v = e->Eval();
|
2009-12-15 12:26:22 +00:00
|
|
|
if(fabs(v) > 1e-6) {
|
|
|
|
shown.paste.scale = v;
|
|
|
|
} else {
|
|
|
|
Error("Scale cannot be zero.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
void TextWindow::ScreenChangePasteTransformed(int link, uint32_t v) {
|
2009-12-15 12:26:22 +00:00
|
|
|
switch(link) {
|
|
|
|
case 't':
|
2016-01-26 11:19:52 +00:00
|
|
|
SS.TW.ShowEditControl(13, ssprintf("%d", SS.TW.shown.paste.times));
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
SS.TW.edit.meaning = Edit::PASTE_TIMES_REPEATED;
|
2009-12-15 12:26:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'r':
|
2016-01-26 11:19:52 +00:00
|
|
|
SS.TW.ShowEditControl(13, ssprintf("%.3f", SS.TW.shown.paste.theta*180/PI));
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
SS.TW.edit.meaning = Edit::PASTE_ANGLE;
|
2009-12-15 12:26:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 's':
|
2016-01-26 11:19:52 +00:00
|
|
|
SS.TW.ShowEditControl(13, ssprintf("%.3f", SS.TW.shown.paste.scale));
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
SS.TW.edit.meaning = Edit::PASTE_SCALE;
|
2009-12-15 12:26:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
void TextWindow::ScreenPasteTransformed(int link, uint32_t v) {
|
2009-12-15 12:26:22 +00:00
|
|
|
SS.GW.GroupSelection();
|
|
|
|
switch(link) {
|
|
|
|
case 'o':
|
|
|
|
if(SS.GW.gs.points == 1 && SS.GW.gs.n == 1) {
|
|
|
|
Entity *e = SK.GetEntity(SS.GW.gs.point[0]);
|
|
|
|
SS.TW.shown.paste.origin = e->PointGetNum();
|
|
|
|
} else {
|
|
|
|
Error("Select one point to define origin of rotation.");
|
|
|
|
}
|
2010-01-04 03:17:09 +00:00
|
|
|
SS.GW.ClearSelection();
|
2009-12-15 12:26:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 't':
|
|
|
|
if(SS.GW.gs.points == 2 && SS.GW.gs.n == 2) {
|
|
|
|
Entity *pa = SK.GetEntity(SS.GW.gs.point[0]),
|
|
|
|
*pb = SK.GetEntity(SS.GW.gs.point[1]);
|
|
|
|
SS.TW.shown.paste.trans =
|
|
|
|
(pb->PointGetNum()).Minus(pa->PointGetNum());
|
|
|
|
} else {
|
|
|
|
Error("Select two points to define translation vector.");
|
|
|
|
}
|
2010-01-04 03:17:09 +00:00
|
|
|
SS.GW.ClearSelection();
|
2009-12-15 12:26:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'g': {
|
|
|
|
if(fabs(SS.TW.shown.paste.theta) < LENGTH_EPS &&
|
|
|
|
SS.TW.shown.paste.trans.Magnitude() < LENGTH_EPS &&
|
|
|
|
SS.TW.shown.paste.times != 1)
|
|
|
|
{
|
|
|
|
Message("Transformation is identity. So all copies will be "
|
|
|
|
"exactly on top of each other.");
|
|
|
|
}
|
|
|
|
if(SS.TW.shown.paste.times*SS.clipboard.r.n > 100) {
|
|
|
|
Error("Too many items to paste; split this into smaller "
|
|
|
|
"pastes.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(!SS.GW.LockedInWorkplane()) {
|
|
|
|
Error("No workplane active.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Entity *wrkpl = SK.GetEntity(SS.GW.ActiveWorkplane());
|
|
|
|
Entity *wrkpln = SK.GetEntity(wrkpl->normal);
|
|
|
|
Vector wn = wrkpln->NormalN();
|
|
|
|
SS.UndoRemember();
|
2010-01-04 03:17:09 +00:00
|
|
|
SS.GW.ClearSelection();
|
2009-12-15 12:26:22 +00:00
|
|
|
for(int i = 0; i < SS.TW.shown.paste.times; i++) {
|
|
|
|
Vector trans = SS.TW.shown.paste.trans.ScaledBy(i+1),
|
|
|
|
origin = SS.TW.shown.paste.origin;
|
|
|
|
double theta = SS.TW.shown.paste.theta*(i+1);
|
|
|
|
// desired transformation is Q*(p - o) + o + t =
|
|
|
|
// Q*p - Q*o + o + t = Q*p + (t + o - Q*o)
|
|
|
|
Vector t = trans.Plus(
|
|
|
|
origin).Minus(
|
|
|
|
origin.RotatedAbout(wn, theta));
|
|
|
|
|
|
|
|
SS.GW.PasteClipboard(t, theta, SS.TW.shown.paste.scale);
|
|
|
|
}
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
SS.TW.GoToScreen(Screen::LIST_OF_GROUPS);
|
2015-03-18 17:02:11 +00:00
|
|
|
SS.ScheduleShowTW();
|
2009-12-15 12:26:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-05 05:54:05 +00:00
|
|
|
void TextWindow::ShowPasteTransformed() {
|
2009-12-15 12:26:22 +00:00
|
|
|
Printf(true, "%FtPASTE TRANSFORMED%E");
|
2010-05-09 18:25:23 +00:00
|
|
|
Printf(true, "%Ba %Ftrepeat%E %d time%s %Fl%Lt%f[change]%E",
|
2009-12-15 12:26:22 +00:00
|
|
|
shown.paste.times, (shown.paste.times == 1) ? "" : "s",
|
|
|
|
&ScreenChangePasteTransformed);
|
2010-05-09 18:25:23 +00:00
|
|
|
Printf(false, "%Bd %Ftrotate%E %@ degrees %Fl%Lr%f[change]%E",
|
2009-12-15 12:26:22 +00:00
|
|
|
shown.paste.theta*180/PI,
|
|
|
|
&ScreenChangePasteTransformed);
|
2010-05-09 18:25:23 +00:00
|
|
|
Printf(false, "%Ba %Ftabout pt%E (%s, %s, %s) %Fl%Lo%f[use selected]%E",
|
2015-11-06 08:40:12 +00:00
|
|
|
SS.MmToString(shown.paste.origin.x).c_str(),
|
|
|
|
SS.MmToString(shown.paste.origin.y).c_str(),
|
|
|
|
SS.MmToString(shown.paste.origin.z).c_str(),
|
2009-12-15 12:26:22 +00:00
|
|
|
&ScreenPasteTransformed);
|
2010-05-09 18:25:23 +00:00
|
|
|
Printf(false, "%Bd %Fttranslate%E (%s, %s, %s) %Fl%Lt%f[use selected]%E",
|
2015-11-06 08:40:12 +00:00
|
|
|
SS.MmToString(shown.paste.trans.x).c_str(),
|
|
|
|
SS.MmToString(shown.paste.trans.y).c_str(),
|
|
|
|
SS.MmToString(shown.paste.trans.z).c_str(),
|
2009-12-15 12:26:22 +00:00
|
|
|
&ScreenPasteTransformed);
|
2010-05-09 18:25:23 +00:00
|
|
|
Printf(false, "%Ba %Ftscale%E %@ %Fl%Ls%f[change]%E",
|
2009-12-15 12:26:22 +00:00
|
|
|
shown.paste.scale,
|
|
|
|
&ScreenChangePasteTransformed);
|
|
|
|
|
|
|
|
Printf(true, " %Fl%Lg%fpaste transformed now%E", &ScreenPasteTransformed);
|
|
|
|
|
|
|
|
Printf(true, "(or %Fl%Ll%fcancel operation%E)", &ScreenHome);
|
|
|
|
}
|
|
|
|
|