From b284baffce47ae2bc6142bf3ea45f2e0cdb0b872 Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Thu, 12 Jun 2008 20:41:27 -0800 Subject: [PATCH] Treatment of numerical faces was screwy, exporting stuff in numXXX. So fix that, and now I can simplify what's exported for an entity. And add an extra measurement (face-face distance/angle), and some other little stuff. [git-p4: depot-paths = "//depot/solvespace/": change = 1789] --- drawentity.cpp | 4 ++++ entity.cpp | 20 ++++++++++++++------ file.cpp | 22 +++++----------------- graphicswin.cpp | 5 +++-- group.cpp | 14 ++++++++------ sketch.h | 8 +++++--- textwin.cpp | 24 ++++++++++++++++++++++++ wishlist.txt | 6 ++++-- 8 files changed, 67 insertions(+), 36 deletions(-) diff --git a/drawentity.cpp b/drawentity.cpp index ea4e2fd..c765952 100644 --- a/drawentity.cpp +++ b/drawentity.cpp @@ -47,6 +47,7 @@ void Entity::DrawAll(void) { if(!e->IsPoint()) continue; if(!(SS.GetGroup(e->group)->visible)) continue; if(SS.GroupsInOrder(SS.GW.activeGroup, e->group)) continue; + if(e->forceHidden) continue; Vector v = e->PointGetNum(); glxVertex3v(v.Plus (r).Plus (d)); @@ -123,6 +124,9 @@ bool Entity::IsVisible(void) { // The group-associated workplanes are hidden outside their group. if(g->h.v != SS.GW.activeGroup.v) return false; } + + if(forceHidden) return false; + return true; } diff --git a/entity.cpp b/entity.cpp index ee6ab84..0c4d087 100644 --- a/entity.cpp +++ b/entity.cpp @@ -574,7 +574,8 @@ ExprVector Entity::FaceGetNormalExprs(void) { r = ExprVector::From(v.WithMagnitude(1)); } else if(type == FACE_XPROD) { ExprVector vc = ExprVector::From(param[0], param[1], param[2]); - ExprVector vn = ExprVector::From(numVector); + ExprVector vn = + ExprVector::From(numNormal.vx, numNormal.vy, numNormal.vz); r = vc.Cross(vn); r = r.WithMagnitude(Expr::From(1.0)); } else if(type == FACE_N_ROT_TRANS) { @@ -595,7 +596,8 @@ Vector Entity::FaceGetNormalNum(void) { r = Vector::From(numNormal.vx, numNormal.vy, numNormal.vz); } else if(type == FACE_XPROD) { Vector vc = Vector::From(param[0], param[1], param[2]); - r = vc.Cross(numVector); + Vector vn = Vector::From(numNormal.vx, numNormal.vy, numNormal.vz); + r = vc.Cross(vn); } else if(type == FACE_N_ROT_TRANS) { // The numerical normal vector gets the rotation r = Vector::From(numNormal.vx, numNormal.vy, numNormal.vz); @@ -669,17 +671,23 @@ void Entity::GenerateEquations(IdList *l) { } } -void Entity::CalculateNumerical(void) { +void Entity::CalculateNumerical(bool forExport) { if(IsPoint()) actPoint = PointGetNum(); if(IsNormal()) actNormal = NormalGetNum(); if(type == DISTANCE || type == DISTANCE_N_COPY) { actDistance = DistanceGetNum(); } if(IsFace()) { - numPoint = FaceGetPointNum(); + actPoint = FaceGetPointNum(); Vector n = FaceGetNormalNum(); - numNormal = Quaternion::From(0, n.x, n.y, n.z); + actNormal = Quaternion::From(0, n.x, n.y, n.z); + } + if(forExport) { + // Visibility in copied import entities follows source file + actVisible = IsVisible(); + } else { + // Copied entities within a file are always visible + actVisible = true; } - actVisible = IsVisible(); } diff --git a/file.cpp b/file.cpp index 9278bf0..ff8e73b 100644 --- a/file.cpp +++ b/file.cpp @@ -95,15 +95,7 @@ const SolveSpace::SaveTable SolveSpace::SAVED[] = { { 'e', "Entity.h.v", 'x', &(SS.sv.e.h.v) }, { 'e', "Entity.type", 'd', &(SS.sv.e.type) }, - { 'e', "Entity.group.v", 'x', &(SS.sv.e.group.v) }, { 'e', "Entity.construction", 'b', &(SS.sv.e.construction) }, - { 'e', "Entity.param[0].v", 'x', &(SS.sv.e.param[0].v) }, - { 'e', "Entity.param[1].v", 'x', &(SS.sv.e.param[1].v) }, - { 'e', "Entity.param[2].v", 'x', &(SS.sv.e.param[2].v) }, - { 'e', "Entity.param[3].v", 'x', &(SS.sv.e.param[3].v) }, - { 'e', "Entity.param[4].v", 'x', &(SS.sv.e.param[4].v) }, - { 'e', "Entity.param[5].v", 'x', &(SS.sv.e.param[5].v) }, - { 'e', "Entity.param[6].v", 'x', &(SS.sv.e.param[6].v) }, { 'e', "Entity.point[0].v", 'x', &(SS.sv.e.point[0].v) }, { 'e', "Entity.point[1].v", 'x', &(SS.sv.e.point[1].v) }, { 'e', "Entity.point[2].v", 'x', &(SS.sv.e.point[2].v) }, @@ -111,14 +103,6 @@ const SolveSpace::SaveTable SolveSpace::SAVED[] = { { 'e', "Entity.normal.v", 'x', &(SS.sv.e.normal.v) }, { 'e', "Entity.distance.v", 'x', &(SS.sv.e.distance.v) }, { 'e', "Entity.workplane.v", 'x', &(SS.sv.e.workplane.v) }, - { 'e', "Entity.numPoint.x", 'f', &(SS.sv.e.numPoint.x) }, - { 'e', "Entity.numPoint.y", 'f', &(SS.sv.e.numPoint.y) }, - { 'e', "Entity.numPoint.z", 'f', &(SS.sv.e.numPoint.z) }, - { 'e', "Entity.numNormal.w", 'f', &(SS.sv.e.numNormal.w) }, - { 'e', "Entity.numNormal.vx", 'f', &(SS.sv.e.numNormal.vx) }, - { 'e', "Entity.numNormal.vy", 'f', &(SS.sv.e.numNormal.vy) }, - { 'e', "Entity.numNormal.vz", 'f', &(SS.sv.e.numNormal.vz) }, - { 'e', "Entity.numDistance", 'f', &(SS.sv.e.numDistance) }, { 'e', "Entity.actPoint.x", 'f', &(SS.sv.e.actPoint.x) }, { 'e', "Entity.actPoint.y", 'f', &(SS.sv.e.actPoint.y) }, { 'e', "Entity.actPoint.z", 'f', &(SS.sv.e.actPoint.z) }, @@ -192,6 +176,10 @@ void SolveSpace::SaveUsingTable(int type) { } bool SolveSpace::SaveToFile(char *filename) { + // Make sure all the entities are regenerated up to date, since they + // will be exported. + SS.GenerateAll(0, INT_MAX); + fh = fopen(filename, "w"); if(!fh) { Error("Couldn't write to file '%s'", filename); @@ -220,7 +208,7 @@ bool SolveSpace::SaveToFile(char *filename) { } for(i = 0; i < entity.n; i++) { - (entity.elem[i]).CalculateNumerical(); + (entity.elem[i]).CalculateNumerical(true); sv.e = entity.elem[i]; SaveUsingTable('e'); fprintf(fh, "AddEntity\n\n"); diff --git a/graphicswin.cpp b/graphicswin.cpp index ce17bec..2962866 100644 --- a/graphicswin.cpp +++ b/graphicswin.cpp @@ -107,8 +107,6 @@ void GraphicsWindow::Init(void) { } SS.GetGroup(activeGroup)->Activate(); - EnsureValidActives(); - showWorkplanes = true; showNormals = true; showPoints = true; @@ -119,6 +117,9 @@ void GraphicsWindow::Init(void) { showTextWindow = true; ShowTextWindow(showTextWindow); + + // Do this last, so that all the menus get updated correctly. + EnsureValidActives(); } void GraphicsWindow::NormalizeProjectionVectors(void) { diff --git a/group.cpp b/group.cpp index 129bfeb..8157268 100644 --- a/group.cpp +++ b/group.cpp @@ -266,7 +266,7 @@ void Group::Generate(IdList *entity, if(e->IsPoint()) pt = e->h; - e->CalculateNumerical(); + e->CalculateNumerical(false); hEntity he = e->h; e = NULL; // As soon as I call CopyEntity, e may become invalid! That // adds entities, which may cause a realloc. @@ -306,7 +306,7 @@ void Group::Generate(IdList *entity, Entity *e = &(entity->elem[i]); if(e->group.v != opA.v) continue; - e->CalculateNumerical(); + e->CalculateNumerical(false); CopyEntity(entity, e, a*2 - (subtype == ONE_SIDED ? 0 : (n-1)), (a == (n - 1)) ? REMAP_LAST : a, @@ -338,7 +338,7 @@ void Group::Generate(IdList *entity, Entity *e = &(entity->elem[i]); if(e->group.v != opA.v) continue; - e->CalculateNumerical(); + e->CalculateNumerical(false); CopyEntity(entity, e, a*2 - (subtype == ONE_SIDED ? 0 : (n-1)), (a == (n - 1)) ? REMAP_LAST : a, @@ -481,7 +481,7 @@ void Group::MakeExtrusionLines(IdList *el, hEntity in) { en.param[1] = h.param(1); en.param[2] = h.param(2); en.numPoint = a; - en.numVector = ab; + en.numNormal = Quaternion::From(0, ab.x, ab.y, ab.z); en.group = h; en.h = Remap(ep->h, REMAP_LINE_TO_FACE); @@ -624,13 +624,15 @@ void Group::CopyEntity(IdList *el, en.param[4] = qvx; en.param[5] = qvy; en.param[6] = qvz; - en.numPoint = ep->numPoint; - en.numNormal = ep->numNormal; + en.numPoint = ep->actPoint; + en.numNormal = ep->actNormal; break; default: oops(); } + en.forceHidden = !ep->actVisible; + el->Add(&en); } diff --git a/sketch.h b/sketch.h index fb1d367..d4bf6c4 100644 --- a/sketch.h +++ b/sketch.h @@ -279,8 +279,10 @@ public: Vector numPoint; Quaternion numNormal; double numDistance; - // and a bit more state that the faces need - Vector numVector; + + // An imported entity that was hidden in the source file ends up hidden + // here too. + bool forceHidden; // All points/normals/distances have their numerical value; this is // a convenience, to simplify the import/assembly code, so that the @@ -376,7 +378,7 @@ public: void AddEq(IdList *l, Expr *expr, int index); void GenerateEquations(IdList *l); - void CalculateNumerical(void); + void CalculateNumerical(bool forExport); char *DescriptionString(void); }; diff --git a/textwin.cpp b/textwin.cpp index c4780cb..6cc3bd5 100644 --- a/textwin.cpp +++ b/textwin.cpp @@ -221,6 +221,7 @@ void TextWindow::Show(void) { case SCREEN_CONFIGURATION: ShowConfiguration(); break; } } + Printf(false, ""); InvalidateText(); } @@ -371,6 +372,29 @@ void TextWindow::DescribeSelection(void) { Printf(true, " vector = " PT_AS_NUM, CO(v)); double d = (p1.Minus(p0)).Dot(v); Printf(true, " proj_d = %Fi%s", SS.GW.ToString(d)); + } else if(gs.n == 2 && gs.faces == 2) { + Printf(false, "%FtTWO PLANE FACES"); + + Vector n0 = SS.GetEntity(gs.face[0])->FaceGetNormalNum(); + Printf(true, " planeA normal = " PT_AS_NUM, CO(n0)); + Vector p0 = SS.GetEntity(gs.face[0])->FaceGetPointNum(); + Printf(false, " planeA thru = " PT_AS_STR, COSTR(p0)); + + Vector n1 = SS.GetEntity(gs.face[1])->FaceGetNormalNum(); + Printf(true, " planeB normal = " PT_AS_NUM, CO(n1)); + Vector p1 = SS.GetEntity(gs.face[1])->FaceGetPointNum(); + Printf(false, " planeB thru = " PT_AS_STR, COSTR(p1)); + + double theta = acos(n0.Dot(n1)); + Printf(true, " angle = %Fi%2%E degrees", theta*180/PI); + while(theta < PI/2) theta += PI; + while(theta > PI/2) theta -= PI; + Printf(false, " or angle = %Fi%2%E (mod 180)", theta*180/PI); + + if(fabs(theta) < 0.01) { + double d = (p1.Minus(p0)).Dot(n0); + Printf(true, " distance = %Fi%s", SS.GW.ToString(d)); + } } else { Printf(true, "%FtSELECTED:%E %d item%s", gs.n, gs.n == 1 ? "" : "s"); } diff --git a/wishlist.txt b/wishlist.txt index 19e3c21..332383c 100644 --- a/wishlist.txt +++ b/wishlist.txt @@ -2,9 +2,7 @@ STL check for meshes, and T intersection removal STL export DXF export -partitioned subsystems in the solver TTF font text -display with proper formatting/units some kind of rounding / chamfer remove back button in browser? clean up user-created workplanes @@ -12,6 +10,10 @@ graphic export relative paths for import auto-generate circles and faces when lathing +partitioned subsystems in the solver +display with proper formatting/units +sweep tool + long term -----