FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Handle operators by rpavlik · Pull Request #447 · solvespace/solvespace · GitHub

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cpp  (29) .h  (5) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
28 changes: 14 additions & 14 deletions src/clipboard.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,33 @@ void SolveSpaceUI::Clipboard::Clear() {
}

bool SolveSpaceUI::Clipboard::ContainsEntity(hEntity he) {
if(he.v == Entity::NO_ENTITY.v)
if(he == Entity::NO_ENTITY)
return true;

ClipboardRequest *cr;
for(cr = r.First(); cr; cr = r.NextAfter(cr)) {
if(cr->oldEnt.v == he.v)
if(cr->oldEnt == he)
return true;

for(int i = 0; i < MAX_POINTS_IN_ENTITY; i++) {
if(cr->oldPointEnt[i].v == he.v)
if(cr->oldPointEnt[i] == he)
return true;
}
}
return false;
}

hEntity SolveSpaceUI::Clipboard::NewEntityFor(hEntity he) {
if(he.v == Entity::NO_ENTITY.v)
if(he == Entity::NO_ENTITY)
return Entity::NO_ENTITY;

ClipboardRequest *cr;
for(cr = r.First(); cr; cr = r.NextAfter(cr)) {
if(cr->oldEnt.v == he.v)
if(cr->oldEnt == he)
return cr->newReq.entity(0);

for(int i = 0; i < MAX_POINTS_IN_ENTITY; i++) {
if(cr->oldPointEnt[i].v == he.v)
if(cr->oldPointEnt[i] == he)
return cr->newReq.entity(1+i);
}
}
Expand All @@ -52,13 +52,13 @@ void GraphicsWindow::DeleteSelection() {
List<Selection> *ls = &(selection);
for(Selection *s = ls->First(); s; s = ls->NextAfter(s)) {
hRequest r = { 0 };
if(s->entity.v && s->entity.isFromRequest()) {
if(s->entity && s->entity.isFromRequest()) {
r = s->entity.request();
}
if(r.v && !r.IsFromReferences()) {
if(r && !r.IsFromReferences()) {
SK.request.Tag(r, 1);
}
if(s->constraint.v) {
if(s->constraint) {
SK.constraint.Tag(s->constraint, 1);
}
}
Expand All @@ -81,7 +81,7 @@ void GraphicsWindow::CopySelection() {

List<Selection> *ls = &(selection);
for(Selection *s = ls->First(); s; s = ls->NextAfter(s)) {
if(!s->entity.v) continue;
if(!s->entity) continue;
// Work only on entities that have requests that will generate them.
Entity *e = SK.GetEntity(s->entity);
bool hasDistance;
Expand Down Expand Up @@ -130,7 +130,7 @@ void GraphicsWindow::CopySelection() {
}

for(Selection *s = ls->First(); s; s = ls->NextAfter(s)) {
if(!s->constraint.v) continue;
if(!s->constraint) continue;

Constraint *c = SK.GetConstraint(s->constraint);
if(c->type == Constraint::Type::COMMENT) {
Expand Down Expand Up @@ -164,15 +164,15 @@ void GraphicsWindow::PasteClipboard(Vector trans, double theta, double scale) {
// For arcs, reflection involves swapping the endpoints, or otherwise
// the arc gets inverted.
auto mapPoint = [scale](hEntity he) {
if(he.v == 0) return he;
if(!he) return he;

if(scale < 0) {
hRequest hr = he.request();
Request *r = SK.GetRequest(hr);
if(r->type == Request::Type::ARC_OF_CIRCLE) {
if(he.v == hr.entity(2).v) {
if(he == hr.entity(2)) {
return hr.entity(3);
} else if(he.v == hr.entity(3).v) {
} else if(he == hr.entity(3)) {
return hr.entity(2);
}
}
Expand Down
20 changes: 9 additions & 11 deletions src/constraint.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ void Constraint::DeleteAllConstraintsFor(Constraint::Type type, hEntity entityA,
ConstraintBase *ct = &(SK.constraint.elem[i]);
if(ct->type != type) continue;

if(ct->entityA.v != entityA.v) continue;
if(ct->ptA.v != ptA.v) continue;
if(ct->entityA != entityA) continue;
if(ct->ptA != ptA) continue;
ct->tag = 1;
}
SK.constraint.RemoveTagged();
Expand Down Expand Up @@ -406,7 +406,7 @@ void Constraint::MenuConstrain(Command id) {
Entity *l0 = SK.GetEntity(gs.entity[0]),
*l1 = SK.GetEntity(gs.entity[1]);

if((l1->group.v != SS.GW.activeGroup.v) ||
if((l1->group != SS.GW.activeGroup) ||
(l1->construction && !(l0->construction)))
{
swap(l0, l1);
Expand All @@ -433,10 +433,10 @@ void Constraint::MenuConstrain(Command id) {
"(symmetric about workplane)\n"));
return;
}
if(c.entityA.v == Entity::NO_ENTITY.v) {
if(c.entityA == Entity::NO_ENTITY) {
// Horizontal / vertical symmetry, implicit symmetry plane
// normal to the workplane
if(c.workplane.v == Entity::FREE_IN_3D.v) {
if(c.workplane == Entity::FREE_IN_3D) {
Error(_("A workplane must be active when constraining "
"symmetric without an explicit symmetry plane."));
return;
Expand Down Expand Up @@ -466,7 +466,7 @@ void Constraint::MenuConstrain(Command id) {
case Command::VERTICAL:
case Command::HORIZONTAL: {
hEntity ha, hb;
if(c.workplane.v == Entity::FREE_IN_3D.v) {
if(c.workplane == Entity::FREE_IN_3D) {
Error(_("Activate a workplane (with Sketch -> In Workplane) before "
"applying a horizontal or vertical constraint."));
return;
Expand Down Expand Up @@ -510,12 +510,10 @@ void Constraint::MenuConstrain(Command id) {

Entity *nfree = SK.GetEntity(c.entityA);
Entity *nref = SK.GetEntity(c.entityB);
if(nref->group.v == SS.GW.activeGroup.v) {
if(nref->group == SS.GW.activeGroup) {
swap(nref, nfree);
}
if(nfree->group.v == SS.GW.activeGroup.v &&
nref ->group.v != SS.GW.activeGroup.v)
{
if(nfree->group == SS.GW.activeGroup && nref->group != SS.GW.activeGroup) {
// nfree is free, and nref is locked (since it came from a
// previous group); so let's force nfree aligned to nref,
// and make convergence easy
Expand Down Expand Up @@ -746,7 +744,7 @@ void Constraint::MenuConstrain(Command id) {
}

for(const Constraint &cc : SK.constraint) {
if(c.h.v != cc.h.v && c.Equals(cc)) {
if(c.h != cc.h && c.Equals(cc)) {
// Oops, we already have this exact constraint. Remove the one we just added.
SK.constraint.RemoveById(c.h);
SS.GW.ClearSelection();
Expand Down
34 changes: 17 additions & 17 deletions src/constrainteq.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Expr *ConstraintBase::PointLineDistance(hEntity wrkpl, hEntity hpt, hEntity hln)

EntityBase *p = SK.GetEntity(hpt);

if(wrkpl.v == EntityBase::FREE_IN_3D.v) {
if(wrkpl == EntityBase::FREE_IN_3D) {
ExprVector ep = p->PointGetExprs();

ExprVector ea = a->PointGetExprs();
Expand Down Expand Up @@ -82,7 +82,7 @@ Expr *ConstraintBase::Distance(hEntity wrkpl, hEntity hpa, hEntity hpb) {
ssassert(pa->IsPoint() && pb->IsPoint(),
"Expected two points to measure projected distance between");

if(wrkpl.v == EntityBase::FREE_IN_3D.v) {
if(wrkpl == EntityBase::FREE_IN_3D) {
// This is true distance
ExprVector ea, eb, eab;
ea = pa->PointGetExprs();
Expand Down Expand Up @@ -111,7 +111,7 @@ Expr *ConstraintBase::Distance(hEntity wrkpl, hEntity hpa, hEntity hpb) {
Expr *ConstraintBase::DirectionCosine(hEntity wrkpl,
ExprVector ae, ExprVector be)
{
if(wrkpl.v == EntityBase::FREE_IN_3D.v) {
if(wrkpl == EntityBase::FREE_IN_3D) {
Expr *mags = (ae.Magnitude())->Times(be.Magnitude());
return (ae.Dot(be))->Div(mags);
} else {
Expand Down Expand Up @@ -146,7 +146,7 @@ void ConstraintBase::ModifyToSatisfy() {
Vector a = SK.GetEntity(entityA)->VectorGetNum();
Vector b = SK.GetEntity(entityB)->VectorGetNum();
if(other) a = a.ScaledBy(-1);
if(workplane.v != EntityBase::FREE_IN_3D.v) {
if(workplane != EntityBase::FREE_IN_3D) {
a = a.ProjectVectorInto(workplane);
b = b.ProjectVectorInto(workplane);
}
Expand Down Expand Up @@ -190,7 +190,7 @@ void ConstraintBase::AddEq(IdList<Equation,hEquation> *l, const ExprVector &v,
int baseIndex) const {
AddEq(l, v.x, baseIndex);
AddEq(l, v.y, baseIndex + 1);
if(workplane.v == EntityBase::FREE_IN_3D.v) {
if(workplane == EntityBase::FREE_IN_3D) {
AddEq(l, v.z, baseIndex + 2);
}
}
Expand All @@ -200,7 +200,7 @@ void ConstraintBase::Generate(IdList<Param,hParam> *l) {
case Type::PARALLEL:
case Type::CUBIC_LINE_TANGENT:
// Add new parameter only when we operate in 3d space
if(workplane.v != EntityBase::FREE_IN_3D.v) break;
if(workplane != EntityBase::FREE_IN_3D) break;
// fallthrough
case Type::SAME_ORIENTATION:
case Type::PT_ON_LINE: {
Expand Down Expand Up @@ -361,7 +361,7 @@ void ConstraintBase::GenerateEquations(IdList<Equation,hEquation> *l,
case Type::POINTS_COINCIDENT: {
EntityBase *a = SK.GetEntity(ptA);
EntityBase *b = SK.GetEntity(ptB);
if(workplane.v == EntityBase::FREE_IN_3D.v) {
if(workplane == EntityBase::FREE_IN_3D) {
ExprVector pa = a->PointGetExprs();
ExprVector pb = b->PointGetExprs();
AddEq(l, pa.x->Minus(pb.x), 0);
Expand Down Expand Up @@ -430,13 +430,13 @@ void ConstraintBase::GenerateEquations(IdList<Equation,hEquation> *l,
}

case Type::AT_MIDPOINT:
if(workplane.v == EntityBase::FREE_IN_3D.v) {
if(workplane == EntityBase::FREE_IN_3D) {
EntityBase *ln = SK.GetEntity(entityA);
ExprVector a = SK.GetEntity(ln->point[0])->PointGetExprs();
ExprVector b = SK.GetEntity(ln->point[1])->PointGetExprs();
ExprVector m = (a.Plus(b)).ScaledBy(Expr::From(0.5));

if(ptA.v) {
if(ptA) {
ExprVector p = SK.GetEntity(ptA)->PointGetExprs();
AddEq(l, (m.x)->Minus(p.x), 0);
AddEq(l, (m.y)->Minus(p.y), 1);
Expand All @@ -455,7 +455,7 @@ void ConstraintBase::GenerateEquations(IdList<Equation,hEquation> *l,
Expr *mu = Expr::From(0.5)->Times(au->Plus(bu));
Expr *mv = Expr::From(0.5)->Times(av->Plus(bv));

if(ptA.v) {
if(ptA) {
EntityBase *p = SK.GetEntity(ptA);
Expr *pu, *pv;
p->PointGetExprsInWorkplane(workplane, &pu, &pv);
Expand All @@ -469,7 +469,7 @@ void ConstraintBase::GenerateEquations(IdList<Equation,hEquation> *l,
return;

case Type::SYMMETRIC:
if(workplane.v == EntityBase::FREE_IN_3D.v) {
if(workplane == EntityBase::FREE_IN_3D) {
EntityBase *plane = SK.GetEntity(entityA);
EntityBase *ea = SK.GetEntity(ptA);
EntityBase *eb = SK.GetEntity(ptB);
Expand Down Expand Up @@ -521,7 +521,7 @@ void ConstraintBase::GenerateEquations(IdList<Equation,hEquation> *l,

case Type::SYMMETRIC_HORIZ:
case Type::SYMMETRIC_VERT: {
ssassert(workplane.v != Entity::FREE_IN_3D.v,
ssassert(workplane != Entity::FREE_IN_3D,
"Unexpected horizontal/vertical symmetric constraint in 3d");

EntityBase *a = SK.GetEntity(ptA);
Expand Down Expand Up @@ -576,11 +576,11 @@ void ConstraintBase::GenerateEquations(IdList<Equation,hEquation> *l,

case Type::HORIZONTAL:
case Type::VERTICAL: {
ssassert(workplane.v != Entity::FREE_IN_3D.v,
ssassert(workplane != Entity::FREE_IN_3D,
"Unexpected horizontal/vertical constraint in 3d");

hEntity ha, hb;
if(entityA.v) {
if(entityA) {
EntityBase *e = SK.GetEntity(entityA);
ha = e->point[0];
hb = e->point[1];
Expand Down Expand Up @@ -701,7 +701,7 @@ void ConstraintBase::GenerateEquations(IdList<Equation,hEquation> *l,

ExprVector b = line->VectorGetExprs();

if(workplane.v == EntityBase::FREE_IN_3D.v) {
if(workplane == EntityBase::FREE_IN_3D) {
ExprVector eq = VectorsParallel3d(a, b, valP);
AddEq(l, eq);
} else {
Expand Down Expand Up @@ -755,7 +755,7 @@ void ConstraintBase::GenerateEquations(IdList<Equation,hEquation> *l,
ExprVector a = ea->VectorGetExprsInWorkplane(workplane);
ExprVector b = eb->VectorGetExprsInWorkplane(workplane);

if(workplane.v == EntityBase::FREE_IN_3D.v) {
if(workplane == EntityBase::FREE_IN_3D) {
ExprVector eq = VectorsParallel3d(a, b, valP);
AddEq(l, eq);
} else {
Expand All @@ -775,7 +775,7 @@ void ConstraintBase::GenerateEquations(IdList<Equation,hEquation> *l,

case Type::WHERE_DRAGGED: {
EntityBase *ep = SK.GetEntity(ptA);
if(workplane.v == EntityBase::FREE_IN_3D.v) {
if(workplane == EntityBase::FREE_IN_3D) {
ExprVector ev = ep->PointGetExprs();
Vector v = ep->PointGetNum();

Expand Down
31 changes: 15 additions & 16 deletions src/describescreen.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ void TextWindow::DescribeSelection() {
Group *g = SK.GetGroup(e->group);
Printf(false, "");
Printf(false, "%FtIN GROUP%E %s", g->DescriptionString().c_str());
if(e->workplane.v == Entity::FREE_IN_3D.v) {
if(e->workplane == Entity::FREE_IN_3D) {
Printf(false, "%FtNOT LOCKED IN WORKPLANE%E");
} else {
Entity *w = SK.GetEntity(e->workplane);
Printf(false, "%FtIN WORKPLANE%E %s", w->DescriptionString().c_str());
}
if(e->style.v) {
if(e->style) {
Style *s = Style::Get(e->style);
Printf(false, "%FtIN STYLE%E %s", s->DescriptionString().c_str());
} else {
Expand All @@ -232,12 +232,13 @@ void TextWindow::DescribeSelection() {

std::vector<hConstraint> lhc = {};
for(const Constraint &c : SK.constraint) {
if(!(c.ptA.v == e->h.v ||
c.ptB.v == e->h.v ||
c.entityA.v == e->h.v ||
c.entityB.v == e->h.v ||
c.entityC.v == e->h.v ||
c.entityD.v == e->h.v)) continue;
if(!(c.ptA == e->h ||
c.ptB == e->h ||
c.entityA == e->h ||
c.entityB == e->h ||
c.entityC == e->h ||
c.entityD == e->h))
continue;
lhc.push_back(c.h);
}

Expand Down Expand Up @@ -314,8 +315,7 @@ void TextWindow::DescribeSelection() {
Printf(true, " pt-ln distance = %Fi%s%E",
SS.MmToString(pp.DistanceToLine(lp0, lp1.Minus(lp0))).c_str());
hEntity wrkpl = SS.GW.ActiveWorkplane();
if(wrkpl.v != Entity::FREE_IN_3D.v &&
!(p->workplane.v == wrkpl.v && ln->workplane.v == wrkpl.v)) {
if(wrkpl != Entity::FREE_IN_3D && !(p->workplane == wrkpl && ln->workplane == wrkpl)) {
Vector ppw = pp.ProjectInto(wrkpl);
Vector lp0w = lp0.ProjectInto(wrkpl);
Vector lp1w = lp1.ProjectInto(wrkpl);
Expand Down Expand Up @@ -385,10 +385,9 @@ void TextWindow::DescribeSelection() {
lhe.push_back(c->entityC);
lhe.push_back(c->entityD);

auto it = std::remove_if(lhe.begin(), lhe.end(),
[](hEntity he) {
return he.v == Entity::NO_ENTITY.v || !he.isFromRequest();
});
auto it = std::remove_if(lhe.begin(), lhe.end(), [](hEntity he) {
return he == Entity::NO_ENTITY || !he.isFromRequest();
});
lhe.erase(it, lhe.end());

if(!lhe.empty()) {
Expand Down Expand Up @@ -426,13 +425,13 @@ void TextWindow::DescribeSelection() {
bool styleAssigned = false;
for(int i = 0; i < gs.entities; i++) {
Entity *e = SK.GetEntity(gs.entity[i]);
if(e->style.v != 0) {
if(e->style) {
styleAssigned = true;
}
}
for(int i = 0; i < gs.constraints; i++) {
Constraint *c = SK.GetConstraint(gs.constraint[i]);
if(c->type == Constraint::Type::COMMENT && c->disp.style.v != 0) {
if(c->type == Constraint::Type::COMMENT && c->disp.style) {
styleAssigned = true;
}
}
Expand Down
Loading

Back | FazBrowse Home | New Git URL