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

WIP Initial mirror groups implementation. by phkahler · Pull Request #592 · solvespace/solvespace · GitHub

Repository navigation

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

Filter by extension

Filter by extension .cpp  (5) .h  (2) 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
8 changes: 7 additions & 1 deletion src/drawentity.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 @@ -86,6 +86,7 @@ void Entity::GetReferencePoints(std::vector<Vector> *refs) {
case Type::POINT_N_ROT_TRANS:
case Type::POINT_N_ROT_AA:
case Type::POINT_N_ROT_AXIS_TRANS:
case Type::POINT_MIRROR:
case Type::POINT_IN_3D:
case Type::POINT_IN_2D:
refs->push_back(PointGetNum());
Expand All @@ -96,6 +97,7 @@ void Entity::GetReferencePoints(std::vector<Vector> *refs) {
case Type::NORMAL_N_ROT_AA:
case Type::NORMAL_IN_3D:
case Type::NORMAL_IN_2D:
case Type::NORMAL_MIRROR:
case Type::WORKPLANE:
case Type::CIRCLE:
case Type::ARC_OF_CIRCLE:
Expand All @@ -121,6 +123,7 @@ void Entity::GetReferencePoints(std::vector<Vector> *refs) {
case Type::FACE_N_TRANS:
case Type::FACE_N_ROT_AA:
case Type::FACE_ROT_NORMAL_PT:
case Type::FACE_MIRROR:
break;
}
}
Expand Down Expand Up @@ -503,7 +506,8 @@ void Entity::Draw(DrawAs how, Canvas *canvas) {
case Type::POINT_N_ROT_AA:
case Type::POINT_N_ROT_AXIS_TRANS:
case Type::POINT_IN_3D:
case Type::POINT_IN_2D: {
case Type::POINT_IN_2D:
case Type::POINT_MIRROR: {
if(how == DrawAs::HIDDEN) return;

// If we're analyzing the sketch to show the degrees of freedom,
Expand Down Expand Up @@ -547,6 +551,7 @@ void Entity::Draw(DrawAs how, Canvas *canvas) {
case Type::NORMAL_N_COPY:
case Type::NORMAL_N_ROT:
case Type::NORMAL_N_ROT_AA:
case Type::NORMAL_MIRROR:
case Type::NORMAL_IN_3D:
case Type::NORMAL_IN_2D: {
const Camera &camera = canvas->GetCamera();
Expand Down Expand Up @@ -757,6 +762,7 @@ void Entity::Draw(DrawAs how, Canvas *canvas) {
case Type::FACE_N_TRANS:
case Type::FACE_N_ROT_AA:
case Type::FACE_ROT_NORMAL_PT:
case Type::FACE_MIRROR:
// Do nothing; these are drawn with the triangle mesh
return;
}
Expand Down
56 changes: 53 additions & 3 deletions src/entity.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 @@ -246,6 +246,7 @@ bool EntityBase::IsPoint() const {
case Type::POINT_N_ROT_TRANS:
case Type::POINT_N_ROT_AA:
case Type::POINT_N_ROT_AXIS_TRANS:
case Type::POINT_MIRROR:
return true;

default:
Expand All @@ -260,6 +261,7 @@ bool EntityBase::IsNormal() const {
case Type::NORMAL_N_COPY:
case Type::NORMAL_N_ROT:
case Type::NORMAL_N_ROT_AA:
case Type::NORMAL_MIRROR:
return true;

default: return false;
Expand Down Expand Up @@ -293,7 +295,11 @@ Quaternion EntityBase::NormalGetNum() const {
q = q.Times(numNormal);
break;
}

case Type::NORMAL_MIRROR: {
Vector m = Vector::From(param[0], param[1], param[2]);
q = numNormal.Times(Quaternion::From(m, PI));
break;
}
default: ssassert(false, "Unexpected entity type");
}
return q;
Expand Down Expand Up @@ -325,6 +331,9 @@ void EntityBase::NormalForceTo(Quaternion q) {
case Type::NORMAL_N_ROT_AA:
// Not sure if I'll bother implementing this one
break;
case Type::NORMAL_MIRROR:
// Not sure if I'll bother implementing this one
break;

default: ssassert(false, "Unexpected entity type");
}
Expand Down Expand Up @@ -381,7 +390,13 @@ ExprQuaternion EntityBase::NormalGetExprs() const {
q = q.Times(orig);
break;
}

case Type::NORMAL_MIRROR: {
ExprQuaternion orig = ExprQuaternion::From(numNormal);
ExprQuaternion r = ExprQuaternion::From(Expr::From(0.0),
Expr::From(param[0]), Expr::From(param[1]), Expr::From(param[2]));
q = orig.Times(r);
break;
}
default: ssassert(false, "Unexpected entity type");
}
return q;
Expand Down Expand Up @@ -420,6 +435,15 @@ void EntityBase::PointForceTo(Vector p) {
break;
}

case Type::POINT_MIRROR: {
Vector trans = p.Minus(numPoint).WithMagnitude(1.0);
SK.GetParam(param[0])->val = trans.x;
SK.GetParam(param[1])->val = trans.y;
SK.GetParam(param[2])->val = trans.z;
SK.GetParam(param[3])->val = p.Plus(numPoint).ScaledBy(0.5).Dot(trans);
break;
}

case Type::POINT_N_TRANS: {
if(timesApplied == 0) break;
Vector trans = (p.Minus(numPoint)).ScaledBy(1.0/timesApplied);
Expand Down Expand Up @@ -512,6 +536,13 @@ Vector EntityBase::PointGetNum() const {
break;
}

case Type::POINT_MIRROR: {
Vector norm = Vector::From(param[0], param[1], param[2]);
double dist = SK.GetParam(param[3])->val;
p = numPoint.Plus(norm.ScaledBy(dist*2 - 2*numPoint.Dot(norm)));
break;
}

case Type::POINT_N_TRANS: {
Vector trans = Vector::From(param[0], param[1], param[2]);
p = numPoint.Plus(trans.ScaledBy(timesApplied));
Expand Down Expand Up @@ -571,6 +602,14 @@ ExprVector EntityBase::PointGetExprs() const {
r = r.Plus(v.ScaledBy(Expr::From(param[1])));
break;
}
case Type::POINT_MIRROR:{
ExprVector orig = ExprVector::From(numPoint);
ExprVector norm = ExprVector::From(param[0], param[1], param[2]);
Expr *dist = Expr::From(param[3]);
r = orig.Plus(norm.ScaledBy(
dist->Minus(orig.Dot(norm))->Times(Expr::From(2.0))));
break;
}
case Type::POINT_N_TRANS: {
ExprVector orig = ExprVector::From(numPoint);
ExprVector trans = ExprVector::From(param[0], param[1], param[2]);
Expand Down Expand Up @@ -702,6 +741,7 @@ bool EntityBase::IsFace() const {
case Type::FACE_N_TRANS:
case Type::FACE_N_ROT_AA:
case Type::FACE_ROT_NORMAL_PT:
case Type::FACE_MIRROR:
return true;
default:
return false;
Expand Down Expand Up @@ -741,6 +781,10 @@ Vector EntityBase::FaceGetNormalNum() const {
Vector r;
if(type == Type::FACE_NORMAL_PT) {
r = Vector::From(numNormal.vx, numNormal.vy, numNormal.vz);
} else if(type == Type::FACE_MIRROR) {
Vector m_norm = Vector::From(param[0], param[1], param[2]);
Vector fn = Vector::From(numNormal.vx, numNormal.vy, numNormal.vz);
r = fn.Minus(m_norm.ScaledBy(fn.Dot(m_norm)*2));
} else if(type == Type::FACE_XPROD) {
Vector vc = Vector::From(param[0], param[1], param[2]);
Vector vn = Vector::From(numNormal.vx, numNormal.vy, numNormal.vz);
Expand All @@ -762,7 +806,8 @@ Vector EntityBase::FaceGetNormalNum() const {

ExprVector EntityBase::FaceGetPointExprs() const {
ExprVector r;
if((type == Type::FACE_NORMAL_PT) || (type==Type::FACE_ROT_NORMAL_PT)) {
if((type == Type::FACE_NORMAL_PT) || (type==Type::FACE_ROT_NORMAL_PT)
|| (type == Type::FACE_MIRROR)) {
r = SK.GetEntity(point[0])->PointGetExprs();
} else if(type == Type::FACE_XPROD) {
r = ExprVector::From(numPoint);
Expand Down Expand Up @@ -793,6 +838,11 @@ Vector EntityBase::FaceGetPointNum() const {
Vector r;
if((type == Type::FACE_NORMAL_PT) || (type==Type::FACE_ROT_NORMAL_PT)) {
r = SK.GetEntity(point[0])->PointGetNum();
} else if(type == Type::FACE_MIRROR) {
Vector norm = Vector::From(param[0], param[1], param[2]);
double dist = SK.GetParam(param[3])->val;
Vector numpoint = SK.GetEntity(point[0])->PointGetNum();
r = numpoint.Plus(norm.ScaledBy(dist*2 - 2*numPoint.Dot(norm)));
} else if(type == Type::FACE_XPROD) {
r = numPoint;
} else if(type == Type::FACE_N_ROT_TRANS) {
Expand Down
1 change: 1 addition & 0 deletions src/graphicswin.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 @@ -114,6 +114,7 @@ const MenuEntry Menu[] = {
{ 1, N_("&Helix"), Command::GROUP_HELIX, S|'h', KN, mGrp },
{ 1, N_("&Lathe"), Command::GROUP_LATHE, S|'l', KN, mGrp },
{ 1, N_("Re&volve"), Command::GROUP_REVOLVE, S|'v', KN, mGrp },
{ 1, N_("&Mirror"), Command::GROUP_MIRROR , S|'m', KN, mGrp },
{ 1, NULL, Command::NONE, 0, KN, NULL },
{ 1, N_("Link / Assemble..."), Command::GROUP_LINK, S|'i', KN, mGrp },
{ 1, N_("Link Recent"), Command::GROUP_RECENT, 0, KN, mGrp },
Expand Down
83 changes: 83 additions & 0 deletions src/group.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 @@ -163,6 +163,23 @@ void Group::MenuGroup(Command id, Platform::Path linkFile) {
g.name = C_("group-name", "extrude");
break;

case Command::GROUP_MIRROR:
// g.predef.entityB = SS.GW.ActiveWorkplane();
/*
// If entities are selected we will constrain the mirror plane to them later
if(gs.points == 1 && gs.vectors == 1 && gs.n == 2) {
g.predef.origin = gs.point[0];
g.predef.entityB = gs.vector[0];
} else if(gs.lineSegments == 1 && gs.n == 1) {
g.predef.origin = SK.GetEntity(gs.entity[0])->point[0];
g.predef.entityB = gs.entity[0];
}
*/
g.type = Type::MIRROR;
g.opA = SS.GW.activeGroup;
g.name = C_("group-name", "mirror");
break;

case Command::GROUP_LATHE:
if(!SS.GW.LockedInWorkplane()) {
Error(_("Lathe operation can only be applied to planar sketches."));
Expand Down Expand Up @@ -512,6 +529,36 @@ void Group::Generate(IdList<Entity,hEntity> *entity,
return;
}

case Type::MIRROR: {
Vector norm = gp.WithMagnitude(1.0);
AddParam(param, h.param(0), norm.x);
AddParam(param, h.param(1), norm.y);
AddParam(param, h.param(2), norm.z);
AddParam(param, h.param(3), 25.0);

// Get some arbitrary point in the sketch, that will be used
// as a reference when defining top and bottom faces.
// Not using range-for here because we're changing the size of entity in the loop.
for(i = 0; i < entity->n; i++) {
Entity *e = &(entity->Get(i));
if(e->group != opA) continue;

e->CalculateNumerical(/*forExport=*/false);
hEntity he = e->h;
// As soon as I call CopyEntity, e may become invalid! That
// adds entities, which may cause a realloc.
CopyEntity(entity, SK.GetEntity(he), 0, REMAP_BOTTOM,
h.param(0), h.param(1), h.param(2),
h.param(3), NO_PARAM, NO_PARAM, NO_PARAM, NO_PARAM,
CopyAs::NUMERIC);
CopyEntity(entity, SK.GetEntity(he), 1, REMAP_TOP,
h.param(0), h.param(1), h.param(2),
h.param(3), NO_PARAM, NO_PARAM, NO_PARAM, NO_PARAM,
CopyAs::MIRROR);
}
return;
}

case Type::LATHE: {
Vector axis_pos = SK.GetEntity(predef.origin)->PointGetNum();
Vector axis_dir = SK.GetEntity(predef.entityB)->VectorGetNum();
Expand Down Expand Up @@ -812,6 +859,21 @@ void Group::GenerateEquations(IdList<Equation,hEquation> *l) {
AddEq(l, u.Dot(extruden), 0);
AddEq(l, v.Dot(extruden), 1);
}
} else if(type == Type::MIRROR) {
// Normalize the mirror normal
ExprVector n = {
Expr::From(h.param(0)),
Expr::From(h.param(1)),
Expr::From(h.param(2)) };
AddEq(l, (n.Magnitude())->Minus(Expr::From(1)), 0);

if (predef.entityB != Entity::FREE_IN_3D) {
// to reflect in plane, mirror normal must be perpendicular to the sketch normal
Entity *w = SK.GetEntity(predef.entityB);
ExprVector u = w->Normal()->NormalExprsU();
ExprVector v = w->Normal()->NormalExprsV();
AddEq(l, (n.Dot(u.Cross(v))), 1);
}
} else if(type == Type::TRANSLATE) {
if(predef.entityB != Entity::FREE_IN_3D) {
Entity *w = SK.GetEntity(predef.entityB);
Expand Down Expand Up @@ -1043,6 +1105,7 @@ void Group::CopyEntity(IdList<Entity,hEntity> *el,
case Entity::Type::POINT_N_ROT_TRANS:
case Entity::Type::POINT_N_ROT_AA:
case Entity::Type::POINT_N_ROT_AXIS_TRANS:
case Entity::Type::POINT_MIRROR:
case Entity::Type::POINT_IN_3D:
case Entity::Type::POINT_IN_2D:
if(as == CopyAs::N_TRANS) {
Expand All @@ -1052,6 +1115,12 @@ void Group::CopyEntity(IdList<Entity,hEntity> *el,
en.param[2] = dz;
} else if(as == CopyAs::NUMERIC) {
en.type = Entity::Type::POINT_N_COPY;
} else if(as == CopyAs::MIRROR) {
en.type = Entity::Type::POINT_MIRROR;
en.param[0] = dx;
en.param[1] = dy;
en.param[2] = dz;
en.param[3] = qw;
} else {
if(as == CopyAs::N_ROT_AA) {
en.type = Entity::Type::POINT_N_ROT_AA;
Expand All @@ -1077,10 +1146,17 @@ void Group::CopyEntity(IdList<Entity,hEntity> *el,
case Entity::Type::NORMAL_N_COPY:
case Entity::Type::NORMAL_N_ROT:
case Entity::Type::NORMAL_N_ROT_AA:
case Entity::Type::NORMAL_MIRROR:
case Entity::Type::NORMAL_IN_3D:
case Entity::Type::NORMAL_IN_2D:
if(as == CopyAs::N_TRANS || as == CopyAs::NUMERIC) {
en.type = Entity::Type::NORMAL_N_COPY;
} else if (as == CopyAs::MIRROR) {
en.type = Entity::Type::NORMAL_MIRROR;
en.param[0] = dx;
en.param[1] = dy;
en.param[2] = dz;
en.param[3] = qw;
} else { // N_ROT_AXIS_TRANS probably doesn't warrant a new entity Type
if(as == CopyAs::N_ROT_AA || as == CopyAs::N_ROT_AXIS_TRANS) {
en.type = Entity::Type::NORMAL_N_ROT_AA;
Expand Down Expand Up @@ -1110,13 +1186,20 @@ void Group::CopyEntity(IdList<Entity,hEntity> *el,
case Entity::Type::FACE_N_TRANS:
case Entity::Type::FACE_N_ROT_AA:
case Entity::Type::FACE_ROT_NORMAL_PT:
case Entity::Type::FACE_MIRROR:
if(as == CopyAs::N_TRANS) {
en.type = Entity::Type::FACE_N_TRANS;
en.param[0] = dx;
en.param[1] = dy;
en.param[2] = dz;
} else if (as == CopyAs::NUMERIC) {
en.type = Entity::Type::FACE_NORMAL_PT;
} else if (as == CopyAs::MIRROR) {
en.type = Entity::Type::FACE_MIRROR;
en.param[0] = dx;
en.param[1] = dy;
en.param[2] = dz;
en.param[3] = qw;
} else {
if(as == CopyAs::N_ROT_AA || as == CopyAs::N_ROT_AXIS_TRANS) {
en.type = Entity::Type::FACE_N_ROT_AA;
Expand Down
Loading

Back | FazBrowse Home | New Git URL