2013-07-28 22:08:34 +00:00
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// Routines to write and read our .slvs file format.
|
|
|
|
|
//
|
|
|
|
|
// Copyright 2008-2013 Jonathan Westhues.
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-04-18 11:11:48 +00:00
|
|
|
|
#include "solvespace.h"
|
|
|
|
|
|
2008-05-29 10:10:12 +00:00
|
|
|
|
#define VERSION_STRING "<22><><EFBFBD>SolveSpaceREVa"
|
|
|
|
|
|
2013-08-26 18:58:35 +00:00
|
|
|
|
static int StrStartsWith(const char *str, const char *start) {
|
2009-05-19 07:26:38 +00:00
|
|
|
|
return memcmp(str, start, strlen(start)) == 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-28 19:23:01 +00:00
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// Clear and free all the dynamic memory associated with our currently-loaded
|
|
|
|
|
// sketch. This does not leave the program in an acceptable state (with the
|
|
|
|
|
// references created, and so on), so anyone calling this must fix that later.
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
void SolveSpace::ClearExisting(void) {
|
|
|
|
|
UndoClearStack(&redo);
|
|
|
|
|
UndoClearStack(&undo);
|
|
|
|
|
|
|
|
|
|
Group *g;
|
|
|
|
|
for(g = SK.group.First(); g; g = SK.group.NextAfter(g)) {
|
|
|
|
|
g->Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SK.constraint.Clear();
|
|
|
|
|
SK.request.Clear();
|
|
|
|
|
SK.group.Clear();
|
|
|
|
|
SK.style.Clear();
|
|
|
|
|
|
|
|
|
|
SK.entity.Clear();
|
|
|
|
|
SK.param.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-02 11:43:27 +00:00
|
|
|
|
hGroup SolveSpace::CreateDefaultDrawingGroup(void) {
|
|
|
|
|
Group g;
|
|
|
|
|
ZERO(&g);
|
|
|
|
|
|
|
|
|
|
// And an empty group, for the first stuff the user draws.
|
|
|
|
|
g.visible = true;
|
|
|
|
|
g.type = Group::DRAWING_WORKPLANE;
|
|
|
|
|
g.subtype = Group::WORKPLANE_BY_POINT_ORTHO;
|
|
|
|
|
g.predef.q = Quaternion::From(1, 0, 0, 0);
|
|
|
|
|
hRequest hr = Request::HREQUEST_REFERENCE_XY;
|
|
|
|
|
g.predef.origin = hr.entity(1);
|
2008-07-13 09:57:46 +00:00
|
|
|
|
g.name.strcpy("sketch-in-plane");
|
2009-04-19 05:53:16 +00:00
|
|
|
|
SK.group.AddAndAssignId(&g);
|
|
|
|
|
SK.GetGroup(g.h)->activeWorkplane = g.h.entity(0);
|
2008-06-02 11:43:27 +00:00
|
|
|
|
return g.h;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-24 06:22:16 +00:00
|
|
|
|
void SolveSpace::NewFile(void) {
|
2010-02-28 19:23:01 +00:00
|
|
|
|
ClearExisting();
|
2008-04-24 06:22:16 +00:00
|
|
|
|
|
|
|
|
|
// Our initial group, that contains the references.
|
|
|
|
|
Group g;
|
|
|
|
|
memset(&g, 0, sizeof(g));
|
2008-04-30 04:52:34 +00:00
|
|
|
|
g.visible = true;
|
2008-04-24 06:22:16 +00:00
|
|
|
|
g.name.strcpy("#references");
|
2008-05-11 10:40:37 +00:00
|
|
|
|
g.type = Group::DRAWING_3D;
|
2008-04-24 06:22:16 +00:00
|
|
|
|
g.h = Group::HGROUP_REFERENCES;
|
2009-04-19 05:53:16 +00:00
|
|
|
|
SK.group.Add(&g);
|
2008-04-24 06:22:16 +00:00
|
|
|
|
|
|
|
|
|
// Let's create three two-d coordinate systems, for the coordinate
|
|
|
|
|
// planes; these are our references, present in every sketch.
|
|
|
|
|
Request r;
|
2008-06-02 11:43:27 +00:00
|
|
|
|
ZERO(&r);
|
2008-04-27 03:26:27 +00:00
|
|
|
|
r.type = Request::WORKPLANE;
|
2008-04-24 06:22:16 +00:00
|
|
|
|
r.group = Group::HGROUP_REFERENCES;
|
2008-04-27 03:26:27 +00:00
|
|
|
|
r.workplane = Entity::FREE_IN_3D;
|
2008-04-24 06:22:16 +00:00
|
|
|
|
|
|
|
|
|
r.h = Request::HREQUEST_REFERENCE_XY;
|
2009-04-19 05:53:16 +00:00
|
|
|
|
SK.request.Add(&r);
|
2008-04-24 06:22:16 +00:00
|
|
|
|
|
|
|
|
|
r.h = Request::HREQUEST_REFERENCE_YZ;
|
2009-04-19 05:53:16 +00:00
|
|
|
|
SK.request.Add(&r);
|
2008-04-24 06:22:16 +00:00
|
|
|
|
|
|
|
|
|
r.h = Request::HREQUEST_REFERENCE_ZX;
|
2009-04-19 05:53:16 +00:00
|
|
|
|
SK.request.Add(&r);
|
2008-04-24 06:22:16 +00:00
|
|
|
|
|
2008-06-02 11:43:27 +00:00
|
|
|
|
CreateDefaultDrawingGroup();
|
2008-05-27 02:22:20 +00:00
|
|
|
|
}
|
2008-04-24 06:22:16 +00:00
|
|
|
|
|
|
|
|
|
const SolveSpace::SaveTable SolveSpace::SAVED[] = {
|
2008-05-27 02:22:20 +00:00
|
|
|
|
{ 'g', "Group.h.v", 'x', &(SS.sv.g.h.v) },
|
|
|
|
|
{ 'g', "Group.type", 'd', &(SS.sv.g.type) },
|
2008-02-07 09:53:52 +00:00
|
|
|
|
{ 'g', "Group.order", 'd', &(SS.sv.g.order) },
|
2008-05-27 02:22:20 +00:00
|
|
|
|
{ 'g', "Group.name", 'N', &(SS.sv.g.name) },
|
|
|
|
|
{ 'g', "Group.activeWorkplane.v", 'x', &(SS.sv.g.activeWorkplane.v) },
|
|
|
|
|
{ 'g', "Group.opA.v", 'x', &(SS.sv.g.opA.v) },
|
2008-06-21 10:18:20 +00:00
|
|
|
|
{ 'g', "Group.opB.v", 'x', &(SS.sv.g.opB.v) },
|
2008-06-14 08:43:38 +00:00
|
|
|
|
{ 'g', "Group.valA", 'f', &(SS.sv.g.valA) },
|
2008-06-23 08:25:17 +00:00
|
|
|
|
{ 'g', "Group.valB", 'f', &(SS.sv.g.valB) },
|
|
|
|
|
{ 'g', "Group.valC", 'f', &(SS.sv.g.valB) },
|
2008-05-30 06:09:41 +00:00
|
|
|
|
{ 'g', "Group.color", 'x', &(SS.sv.g.color) },
|
2008-05-27 02:22:20 +00:00
|
|
|
|
{ 'g', "Group.subtype", 'd', &(SS.sv.g.subtype) },
|
2008-06-12 04:36:33 +00:00
|
|
|
|
{ 'g', "Group.skipFirst", 'b', &(SS.sv.g.skipFirst) },
|
2008-05-27 02:22:20 +00:00
|
|
|
|
{ 'g', "Group.meshCombine", 'd', &(SS.sv.g.meshCombine) },
|
2009-05-21 09:06:26 +00:00
|
|
|
|
{ 'g', "Group.forceToMesh", 'd', &(SS.sv.g.forceToMesh) },
|
2008-06-01 08:29:59 +00:00
|
|
|
|
{ 'g', "Group.predef.q.w", 'f', &(SS.sv.g.predef.q.w) },
|
|
|
|
|
{ 'g', "Group.predef.q.vx", 'f', &(SS.sv.g.predef.q.vx) },
|
|
|
|
|
{ 'g', "Group.predef.q.vy", 'f', &(SS.sv.g.predef.q.vy) },
|
|
|
|
|
{ 'g', "Group.predef.q.vz", 'f', &(SS.sv.g.predef.q.vz) },
|
|
|
|
|
{ 'g', "Group.predef.origin.v", 'x', &(SS.sv.g.predef.origin.v) },
|
|
|
|
|
{ 'g', "Group.predef.entityB.v", 'x', &(SS.sv.g.predef.entityB.v) },
|
|
|
|
|
{ 'g', "Group.predef.entityC.v", 'x', &(SS.sv.g.predef.entityC.v) },
|
|
|
|
|
{ 'g', "Group.predef.swapUV", 'b', &(SS.sv.g.predef.swapUV) },
|
|
|
|
|
{ 'g', "Group.predef.negateU", 'b', &(SS.sv.g.predef.negateU) },
|
|
|
|
|
{ 'g', "Group.predef.negateV", 'b', &(SS.sv.g.predef.negateV) },
|
2008-05-27 02:22:20 +00:00
|
|
|
|
{ 'g', "Group.visible", 'b', &(SS.sv.g.visible) },
|
2008-02-15 11:35:15 +00:00
|
|
|
|
{ 'g', "Group.suppress", 'b', &(SS.sv.g.suppress) },
|
2009-10-01 11:22:56 +00:00
|
|
|
|
{ 'g', "Group.relaxConstraints", 'b', &(SS.sv.g.relaxConstraints) },
|
2010-05-10 01:06:09 +00:00
|
|
|
|
{ 'g', "Group.allDimsReference", 'b', &(SS.sv.g.allDimsReference) },
|
2009-12-15 12:26:22 +00:00
|
|
|
|
{ 'g', "Group.scale", 'f', &(SS.sv.g.scale) },
|
2008-05-27 02:22:20 +00:00
|
|
|
|
{ 'g', "Group.remap", 'M', &(SS.sv.g.remap) },
|
2008-05-29 10:10:12 +00:00
|
|
|
|
{ 'g', "Group.impFile", 'P', &(SS.sv.g.impFile) },
|
2008-06-25 05:14:49 +00:00
|
|
|
|
{ 'g', "Group.impFileRel", 'P', &(SS.sv.g.impFileRel) },
|
2008-05-27 02:22:20 +00:00
|
|
|
|
|
|
|
|
|
{ 'p', "Param.h.v.", 'x', &(SS.sv.p.h.v) },
|
|
|
|
|
{ 'p', "Param.val", 'f', &(SS.sv.p.val) },
|
|
|
|
|
|
|
|
|
|
{ 'r', "Request.h.v", 'x', &(SS.sv.r.h.v) },
|
|
|
|
|
{ 'r', "Request.type", 'd', &(SS.sv.r.type) },
|
2009-10-21 04:46:01 +00:00
|
|
|
|
{ 'r', "Request.extraPoints", 'd', &(SS.sv.r.extraPoints) },
|
2008-05-27 02:22:20 +00:00
|
|
|
|
{ 'r', "Request.workplane.v", 'x', &(SS.sv.r.workplane.v) },
|
|
|
|
|
{ 'r', "Request.group.v", 'x', &(SS.sv.r.group.v) },
|
|
|
|
|
{ 'r', "Request.construction", 'b', &(SS.sv.r.construction) },
|
2009-07-20 01:47:59 +00:00
|
|
|
|
{ 'r', "Request.style", 'x', &(SS.sv.r.style) },
|
2008-06-30 09:09:17 +00:00
|
|
|
|
{ 'r', "Request.str", 'N', &(SS.sv.r.str) },
|
|
|
|
|
{ 'r', "Request.font", 'N', &(SS.sv.r.font) },
|
2008-05-27 02:22:20 +00:00
|
|
|
|
|
|
|
|
|
{ 'e', "Entity.h.v", 'x', &(SS.sv.e.h.v) },
|
|
|
|
|
{ 'e', "Entity.type", 'd', &(SS.sv.e.type) },
|
|
|
|
|
{ 'e', "Entity.construction", 'b', &(SS.sv.e.construction) },
|
2009-07-20 01:47:59 +00:00
|
|
|
|
{ 'e', "Entity.style", 'x', &(SS.sv.e.style) },
|
2008-06-30 09:09:17 +00:00
|
|
|
|
{ 'e', "Entity.str", 'N', &(SS.sv.e.str) },
|
|
|
|
|
{ 'e', "Entity.font", 'N', &(SS.sv.e.font) },
|
2008-05-27 02:22:20 +00:00
|
|
|
|
{ '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) },
|
|
|
|
|
{ 'e', "Entity.point[3].v", 'x', &(SS.sv.e.point[3].v) },
|
2009-10-21 04:46:01 +00:00
|
|
|
|
{ 'e', "Entity.point[4].v", 'x', &(SS.sv.e.point[4].v) },
|
|
|
|
|
{ 'e', "Entity.point[5].v", 'x', &(SS.sv.e.point[5].v) },
|
|
|
|
|
{ 'e', "Entity.point[6].v", 'x', &(SS.sv.e.point[6].v) },
|
|
|
|
|
{ 'e', "Entity.point[7].v", 'x', &(SS.sv.e.point[7].v) },
|
|
|
|
|
{ 'e', "Entity.point[8].v", 'x', &(SS.sv.e.point[8].v) },
|
|
|
|
|
{ 'e', "Entity.point[9].v", 'x', &(SS.sv.e.point[9].v) },
|
|
|
|
|
{ 'e', "Entity.point[10].v", 'x', &(SS.sv.e.point[10].v) },
|
|
|
|
|
{ 'e', "Entity.point[11].v", 'x', &(SS.sv.e.point[11].v) },
|
|
|
|
|
{ 'e', "Entity.extraPoints", 'd', &(SS.sv.e.extraPoints) },
|
2008-05-27 02:22:20 +00:00
|
|
|
|
{ '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) },
|
2008-05-29 10:10:12 +00:00
|
|
|
|
{ '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) },
|
|
|
|
|
{ 'e', "Entity.actNormal.w", 'f', &(SS.sv.e.actNormal.w) },
|
|
|
|
|
{ 'e', "Entity.actNormal.vx", 'f', &(SS.sv.e.actNormal.vx) },
|
|
|
|
|
{ 'e', "Entity.actNormal.vy", 'f', &(SS.sv.e.actNormal.vy) },
|
|
|
|
|
{ 'e', "Entity.actNormal.vz", 'f', &(SS.sv.e.actNormal.vz) },
|
|
|
|
|
{ 'e', "Entity.actDistance", 'f', &(SS.sv.e.actDistance) },
|
2008-06-12 04:36:33 +00:00
|
|
|
|
{ 'e', "Entity.actVisible", 'b', &(SS.sv.e.actVisible), },
|
2008-05-29 10:10:12 +00:00
|
|
|
|
|
2008-05-27 02:22:20 +00:00
|
|
|
|
|
|
|
|
|
{ 'c', "Constraint.h.v", 'x', &(SS.sv.c.h.v) },
|
|
|
|
|
{ 'c', "Constraint.type", 'd', &(SS.sv.c.type) },
|
|
|
|
|
{ 'c', "Constraint.group.v", 'x', &(SS.sv.c.group.v) },
|
|
|
|
|
{ 'c', "Constraint.workplane.v", 'x', &(SS.sv.c.workplane.v) },
|
2008-06-14 08:43:38 +00:00
|
|
|
|
{ 'c', "Constraint.valA", 'f', &(SS.sv.c.valA) },
|
2008-05-27 02:22:20 +00:00
|
|
|
|
{ 'c', "Constraint.ptA.v", 'x', &(SS.sv.c.ptA.v) },
|
|
|
|
|
{ 'c', "Constraint.ptB.v", 'x', &(SS.sv.c.ptB.v) },
|
|
|
|
|
{ 'c', "Constraint.entityA.v", 'x', &(SS.sv.c.entityA.v) },
|
|
|
|
|
{ 'c', "Constraint.entityB.v", 'x', &(SS.sv.c.entityB.v) },
|
2008-07-20 12:24:43 +00:00
|
|
|
|
{ 'c', "Constraint.entityC.v", 'x', &(SS.sv.c.entityC.v) },
|
|
|
|
|
{ 'c', "Constraint.entityD.v", 'x', &(SS.sv.c.entityD.v) },
|
2008-07-13 12:44:05 +00:00
|
|
|
|
{ 'c', "Constraint.other", 'b', &(SS.sv.c.other) },
|
2010-05-10 04:14:06 +00:00
|
|
|
|
{ 'c', "Constraint.other2", 'b', &(SS.sv.c.other2) },
|
2008-06-11 04:22:52 +00:00
|
|
|
|
{ 'c', "Constraint.reference", 'b', &(SS.sv.c.reference) },
|
2008-06-12 08:58:58 +00:00
|
|
|
|
{ 'c', "Constraint.comment", 'N', &(SS.sv.c.comment) },
|
2008-05-27 02:22:20 +00:00
|
|
|
|
{ 'c', "Constraint.disp.offset.x", 'f', &(SS.sv.c.disp.offset.x) },
|
|
|
|
|
{ 'c', "Constraint.disp.offset.y", 'f', &(SS.sv.c.disp.offset.y) },
|
|
|
|
|
{ 'c', "Constraint.disp.offset.z", 'f', &(SS.sv.c.disp.offset.z) },
|
2009-07-20 01:47:59 +00:00
|
|
|
|
{ 'c', "Constraint.disp.style", 'x', &(SS.sv.c.disp.style) },
|
2008-05-27 02:22:20 +00:00
|
|
|
|
|
2009-09-17 07:32:36 +00:00
|
|
|
|
{ 's', "Style.h.v", 'x', &(SS.sv.s.h.v) },
|
2009-09-18 08:14:15 +00:00
|
|
|
|
{ 's', "Style.name", 'N', &(SS.sv.s.name) },
|
2009-09-17 07:32:36 +00:00
|
|
|
|
{ 's', "Style.width", 'f', &(SS.sv.s.width) },
|
2009-09-24 15:52:48 +00:00
|
|
|
|
{ 's', "Style.widthAs", 'd', &(SS.sv.s.widthAs) },
|
|
|
|
|
{ 's', "Style.textHeight", 'f', &(SS.sv.s.textHeight) },
|
|
|
|
|
{ 's', "Style.textHeightAs", 'd', &(SS.sv.s.textHeightAs) },
|
2009-09-29 11:35:19 +00:00
|
|
|
|
{ 's', "Style.textAngle", 'f', &(SS.sv.s.textAngle) },
|
2009-09-24 15:52:48 +00:00
|
|
|
|
{ 's', "Style.textOrigin", 'x', &(SS.sv.s.textOrigin) },
|
2009-09-17 07:32:36 +00:00
|
|
|
|
{ 's', "Style.color", 'x', &(SS.sv.s.color) },
|
2009-10-22 17:16:20 +00:00
|
|
|
|
{ 's', "Style.fillColor", 'x', &(SS.sv.s.fillColor) },
|
|
|
|
|
{ 's', "Style.filled", 'b', &(SS.sv.s.filled) },
|
2009-09-17 07:32:36 +00:00
|
|
|
|
{ 's', "Style.visible", 'b', &(SS.sv.s.visible) },
|
|
|
|
|
{ 's', "Style.exportable", 'b', &(SS.sv.s.exportable) },
|
|
|
|
|
|
2008-05-27 02:22:20 +00:00
|
|
|
|
{ 0, NULL, NULL, NULL },
|
2008-04-24 06:22:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void SolveSpace::SaveUsingTable(int type) {
|
|
|
|
|
int i;
|
|
|
|
|
for(i = 0; SAVED[i].type != 0; i++) {
|
|
|
|
|
if(SAVED[i].type != type) continue;
|
2008-05-29 10:10:12 +00:00
|
|
|
|
|
|
|
|
|
int fmt = SAVED[i].fmt;
|
2008-04-24 06:22:16 +00:00
|
|
|
|
void *p = SAVED[i].ptr;
|
2008-05-29 10:10:12 +00:00
|
|
|
|
// Any items that aren't specified are assumed to be zero
|
|
|
|
|
if(fmt == 'd' && *((int *)p) == 0) continue;
|
|
|
|
|
if(fmt == 'x' && *((DWORD *)p) == 0) continue;
|
|
|
|
|
if(fmt == 'f' && *((double *)p) == 0.0) continue;
|
2008-06-30 09:09:17 +00:00
|
|
|
|
if(fmt == 'N' && strlen(((NameStr *)p)->str) == 0) continue;
|
2008-05-29 10:10:12 +00:00
|
|
|
|
|
|
|
|
|
fprintf(fh, "%s=", SAVED[i].desc);
|
|
|
|
|
switch(fmt) {
|
2008-04-24 06:22:16 +00:00
|
|
|
|
case 'd': fprintf(fh, "%d", *((int *)p)); break;
|
|
|
|
|
case 'b': fprintf(fh, "%d", *((bool *)p) ? 1 : 0); break;
|
|
|
|
|
case 'x': fprintf(fh, "%08x", *((DWORD *)p)); break;
|
|
|
|
|
case 'f': fprintf(fh, "%.20f", *((double *)p)); break;
|
|
|
|
|
case 'N': fprintf(fh, "%s", ((NameStr *)p)->str); break;
|
2008-05-29 10:10:12 +00:00
|
|
|
|
case 'P': fprintf(fh, "%s", (char *)p); break;
|
2008-04-27 10:01:23 +00:00
|
|
|
|
|
|
|
|
|
case 'M': {
|
|
|
|
|
int j;
|
|
|
|
|
fprintf(fh, "{\n");
|
|
|
|
|
IdList<EntityMap,EntityId> *m = (IdList<EntityMap,EntityId> *)p;
|
|
|
|
|
for(j = 0; j < m->n; j++) {
|
|
|
|
|
EntityMap *em = &(m->elem[j]);
|
|
|
|
|
fprintf(fh, " %d %08x %d\n",
|
|
|
|
|
em->h.v, em->input.v, em->copyNumber);
|
|
|
|
|
}
|
|
|
|
|
fprintf(fh, "}");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-24 06:22:16 +00:00
|
|
|
|
default: oops();
|
|
|
|
|
}
|
|
|
|
|
fprintf(fh, "\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-18 11:11:48 +00:00
|
|
|
|
bool SolveSpace::SaveToFile(char *filename) {
|
2008-06-13 04:41:27 +00:00
|
|
|
|
// Make sure all the entities are regenerated up to date, since they
|
|
|
|
|
// will be exported.
|
|
|
|
|
SS.GenerateAll(0, INT_MAX);
|
|
|
|
|
|
2008-06-14 23:31:36 +00:00
|
|
|
|
fh = fopen(filename, "wb");
|
2008-04-18 11:11:48 +00:00
|
|
|
|
if(!fh) {
|
2008-04-24 06:22:16 +00:00
|
|
|
|
Error("Couldn't write to file '%s'", filename);
|
2008-04-18 11:11:48 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-29 10:10:12 +00:00
|
|
|
|
fprintf(fh, "%s\n\n\n", VERSION_STRING);
|
2008-04-18 11:11:48 +00:00
|
|
|
|
|
2009-05-19 07:26:38 +00:00
|
|
|
|
int i, j;
|
2009-04-19 05:53:16 +00:00
|
|
|
|
for(i = 0; i < SK.group.n; i++) {
|
|
|
|
|
sv.g = SK.group.elem[i];
|
2008-04-24 06:22:16 +00:00
|
|
|
|
SaveUsingTable('g');
|
2008-04-18 11:11:48 +00:00
|
|
|
|
fprintf(fh, "AddGroup\n\n");
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-19 05:53:16 +00:00
|
|
|
|
for(i = 0; i < SK.param.n; i++) {
|
|
|
|
|
sv.p = SK.param.elem[i];
|
2008-04-24 06:22:16 +00:00
|
|
|
|
SaveUsingTable('p');
|
2008-04-18 11:11:48 +00:00
|
|
|
|
fprintf(fh, "AddParam\n\n");
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-19 05:53:16 +00:00
|
|
|
|
for(i = 0; i < SK.request.n; i++) {
|
|
|
|
|
sv.r = SK.request.elem[i];
|
2008-04-24 06:22:16 +00:00
|
|
|
|
SaveUsingTable('r');
|
2008-04-18 11:11:48 +00:00
|
|
|
|
fprintf(fh, "AddRequest\n\n");
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-19 05:53:16 +00:00
|
|
|
|
for(i = 0; i < SK.entity.n; i++) {
|
|
|
|
|
(SK.entity.elem[i]).CalculateNumerical(true);
|
|
|
|
|
sv.e = SK.entity.elem[i];
|
2008-04-24 06:22:16 +00:00
|
|
|
|
SaveUsingTable('e');
|
2008-04-18 11:11:48 +00:00
|
|
|
|
fprintf(fh, "AddEntity\n\n");
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-19 05:53:16 +00:00
|
|
|
|
for(i = 0; i < SK.constraint.n; i++) {
|
|
|
|
|
sv.c = SK.constraint.elem[i];
|
2008-04-24 06:22:16 +00:00
|
|
|
|
SaveUsingTable('c');
|
2008-04-18 11:11:48 +00:00
|
|
|
|
fprintf(fh, "AddConstraint\n\n");
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-17 07:32:36 +00:00
|
|
|
|
for(i = 0; i < SK.style.n; i++) {
|
|
|
|
|
sv.s = SK.style.elem[i];
|
|
|
|
|
if(sv.s.h.v >= Style::FIRST_CUSTOM) {
|
|
|
|
|
SaveUsingTable('s');
|
|
|
|
|
fprintf(fh, "AddStyle\n\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-21 09:06:26 +00:00
|
|
|
|
// A group will have either a mesh or a shell, but not both; but the code
|
|
|
|
|
// to print either of those just does nothing if the mesh/shell is empty.
|
|
|
|
|
|
2009-04-19 05:53:16 +00:00
|
|
|
|
SMesh *m = &(SK.group.elem[SK.group.n-1].runningMesh);
|
2008-05-29 10:10:12 +00:00
|
|
|
|
for(i = 0; i < m->l.n; i++) {
|
|
|
|
|
STriangle *tr = &(m->l.elem[i]);
|
2008-05-30 06:09:41 +00:00
|
|
|
|
fprintf(fh, "Triangle %08x %08x "
|
2008-06-04 06:39:32 +00:00
|
|
|
|
"%.20f %.20f %.20f %.20f %.20f %.20f %.20f %.20f %.20f\n",
|
2008-05-30 06:09:41 +00:00
|
|
|
|
tr->meta.face, tr->meta.color,
|
2008-05-29 10:10:12 +00:00
|
|
|
|
CO(tr->a), CO(tr->b), CO(tr->c));
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-19 07:26:38 +00:00
|
|
|
|
SShell *s = &(SK.group.elem[SK.group.n-1].runningShell);
|
|
|
|
|
SSurface *srf;
|
|
|
|
|
for(srf = s->surface.First(); srf; srf = s->surface.NextAfter(srf)) {
|
|
|
|
|
fprintf(fh, "Surface %08x %08x %08x %d %d\n",
|
|
|
|
|
srf->h.v, srf->color, srf->face, srf->degm, srf->degn);
|
|
|
|
|
for(i = 0; i <= srf->degm; i++) {
|
|
|
|
|
for(j = 0; j <= srf->degn; j++) {
|
|
|
|
|
fprintf(fh, "SCtrl %d %d %.20f %.20f %.20f Weight %20.20f\n",
|
|
|
|
|
i, j, CO(srf->ctrl[i][j]), srf->weight[i][j]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
STrimBy *stb;
|
|
|
|
|
for(stb = srf->trim.First(); stb; stb = srf->trim.NextAfter(stb)) {
|
|
|
|
|
fprintf(fh, "TrimBy %08x %d %.20f %.20f %.20f %.20f %.20f %.20f\n",
|
|
|
|
|
stb->curve.v, stb->backwards ? 1 : 0,
|
|
|
|
|
CO(stb->start), CO(stb->finish));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fprintf(fh, "AddSurface\n");
|
|
|
|
|
}
|
|
|
|
|
SCurve *sc;
|
|
|
|
|
for(sc = s->curve.First(); sc; sc = s->curve.NextAfter(sc)) {
|
|
|
|
|
fprintf(fh, "Curve %08x %d %d %08x %08x\n",
|
|
|
|
|
sc->h.v,
|
|
|
|
|
sc->isExact ? 1 : 0, sc->exact.deg,
|
|
|
|
|
sc->surfA.v, sc->surfB.v);
|
|
|
|
|
|
|
|
|
|
if(sc->isExact) {
|
|
|
|
|
for(i = 0; i <= sc->exact.deg; i++) {
|
|
|
|
|
fprintf(fh, "CCtrl %d %.20f %.20f %.20f Weight %.20f\n",
|
|
|
|
|
i, CO(sc->exact.ctrl[i]), sc->exact.weight[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
SCurvePt *scpt;
|
|
|
|
|
for(scpt = sc->pts.First(); scpt; scpt = sc->pts.NextAfter(scpt)) {
|
|
|
|
|
fprintf(fh, "CurvePt %d %.20f %.20f %.20f\n",
|
|
|
|
|
scpt->vertex ? 1 : 0, CO(scpt->p));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fprintf(fh, "AddCurve\n");
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-18 11:11:48 +00:00
|
|
|
|
fclose(fh);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-27 10:01:23 +00:00
|
|
|
|
void SolveSpace::LoadUsingTable(char *key, char *val) {
|
|
|
|
|
int i;
|
|
|
|
|
for(i = 0; SAVED[i].type != 0; i++) {
|
|
|
|
|
if(strcmp(SAVED[i].desc, key)==0) {
|
|
|
|
|
void *p = SAVED[i].ptr;
|
|
|
|
|
switch(SAVED[i].fmt) {
|
|
|
|
|
case 'd': *((int *)p) = atoi(val); break;
|
|
|
|
|
case 'b': *((bool *)p) = (atoi(val) != 0); break;
|
|
|
|
|
case 'x': sscanf(val, "%x", (DWORD *)p); break;
|
|
|
|
|
case 'f': *((double *)p) = atof(val); break;
|
|
|
|
|
case 'N': ((NameStr *)p)->strcpy(val); break;
|
|
|
|
|
|
2008-05-29 10:10:12 +00:00
|
|
|
|
case 'P':
|
|
|
|
|
if(strlen(val)+1 < MAX_PATH) strcpy((char *)p, val);
|
|
|
|
|
break;
|
|
|
|
|
|
2008-04-27 10:01:23 +00:00
|
|
|
|
case 'M': {
|
|
|
|
|
IdList<EntityMap,EntityId> *m =
|
|
|
|
|
(IdList<EntityMap,EntityId> *)p;
|
2008-05-11 06:09:46 +00:00
|
|
|
|
// Don't clear this list! When the group gets added, it
|
|
|
|
|
// makes a shallow copy, so that would result in us
|
|
|
|
|
// freeing memory that we want to keep around. Just
|
|
|
|
|
// zero it out so that new memory is allocated.
|
|
|
|
|
memset(m, 0, sizeof(*m));
|
2008-04-27 10:01:23 +00:00
|
|
|
|
for(;;) {
|
|
|
|
|
EntityMap em;
|
|
|
|
|
char line2[1024];
|
2013-08-26 20:09:15 +00:00
|
|
|
|
fgets(line2, (int)sizeof(line2), fh);
|
2008-04-27 10:01:23 +00:00
|
|
|
|
if(sscanf(line2, "%d %x %d", &(em.h.v), &(em.input.v),
|
|
|
|
|
&(em.copyNumber)) == 3)
|
|
|
|
|
{
|
|
|
|
|
m->Add(&em);
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default: oops();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-12-15 12:26:22 +00:00
|
|
|
|
if(SAVED[i].type == 0) {
|
|
|
|
|
fileLoadError = true;
|
|
|
|
|
}
|
2008-04-27 10:01:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-04-18 11:11:48 +00:00
|
|
|
|
bool SolveSpace::LoadFromFile(char *filename) {
|
2008-06-25 05:14:49 +00:00
|
|
|
|
allConsistent = false;
|
2009-12-15 12:26:22 +00:00
|
|
|
|
fileLoadError = false;
|
2008-06-25 05:14:49 +00:00
|
|
|
|
|
2008-06-14 23:31:36 +00:00
|
|
|
|
fh = fopen(filename, "rb");
|
2008-04-18 11:11:48 +00:00
|
|
|
|
if(!fh) {
|
2008-04-24 06:22:16 +00:00
|
|
|
|
Error("Couldn't read from file '%s'", filename);
|
2008-04-18 11:11:48 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-28 19:23:01 +00:00
|
|
|
|
ClearExisting();
|
2008-06-12 07:31:41 +00:00
|
|
|
|
|
2008-05-29 10:10:12 +00:00
|
|
|
|
memset(&sv, 0, sizeof(sv));
|
2009-12-15 12:26:22 +00:00
|
|
|
|
sv.g.scale = 1; // default is 1, not 0; so legacy files need this
|
2008-04-24 06:22:16 +00:00
|
|
|
|
|
|
|
|
|
char line[1024];
|
2013-08-26 20:09:15 +00:00
|
|
|
|
while(fgets(line, (int)sizeof(line), fh)) {
|
2008-04-24 06:22:16 +00:00
|
|
|
|
char *s = strchr(line, '\n');
|
|
|
|
|
if(s) *s = '\0';
|
2009-01-10 08:18:54 +00:00
|
|
|
|
// We should never get files with \r characters in them, but mailers
|
|
|
|
|
// will sometimes mangle attachments.
|
|
|
|
|
s = strchr(line, '\r');
|
|
|
|
|
if(s) *s = '\0';
|
2008-04-24 06:22:16 +00:00
|
|
|
|
|
|
|
|
|
if(*line == '\0') continue;
|
|
|
|
|
|
|
|
|
|
char *e = strchr(line, '=');
|
|
|
|
|
if(e) {
|
|
|
|
|
*e = '\0';
|
|
|
|
|
char *key = line, *val = e+1;
|
2008-04-27 10:01:23 +00:00
|
|
|
|
LoadUsingTable(key, val);
|
2008-04-24 06:22:16 +00:00
|
|
|
|
} else if(strcmp(line, "AddGroup")==0) {
|
2009-04-19 05:53:16 +00:00
|
|
|
|
SK.group.Add(&(sv.g));
|
2009-09-17 07:32:36 +00:00
|
|
|
|
ZERO(&(sv.g));
|
2009-12-15 12:26:22 +00:00
|
|
|
|
sv.g.scale = 1; // default is 1, not 0; so legacy files need this
|
2008-04-24 06:22:16 +00:00
|
|
|
|
} else if(strcmp(line, "AddParam")==0) {
|
|
|
|
|
// params are regenerated, but we want to preload the values
|
|
|
|
|
// for initial guesses
|
2009-04-19 05:53:16 +00:00
|
|
|
|
SK.param.Add(&(sv.p));
|
2009-09-17 07:32:36 +00:00
|
|
|
|
ZERO(&(sv.p));
|
2008-04-24 06:22:16 +00:00
|
|
|
|
} else if(strcmp(line, "AddEntity")==0) {
|
|
|
|
|
// entities are regenerated
|
|
|
|
|
} else if(strcmp(line, "AddRequest")==0) {
|
2009-04-19 05:53:16 +00:00
|
|
|
|
SK.request.Add(&(sv.r));
|
2009-09-17 07:32:36 +00:00
|
|
|
|
ZERO(&(sv.r));
|
2008-04-24 06:22:16 +00:00
|
|
|
|
} else if(strcmp(line, "AddConstraint")==0) {
|
2009-04-19 05:53:16 +00:00
|
|
|
|
SK.constraint.Add(&(sv.c));
|
2009-09-17 07:32:36 +00:00
|
|
|
|
ZERO(&(sv.c));
|
|
|
|
|
} else if(strcmp(line, "AddStyle")==0) {
|
|
|
|
|
SK.style.Add(&(sv.s));
|
|
|
|
|
ZERO(&(sv.s));
|
2008-05-29 10:10:12 +00:00
|
|
|
|
} else if(strcmp(line, VERSION_STRING)==0) {
|
2008-04-24 06:22:16 +00:00
|
|
|
|
// do nothing, version string
|
2009-05-19 07:26:38 +00:00
|
|
|
|
} else if(StrStartsWith(line, "Triangle ") ||
|
|
|
|
|
StrStartsWith(line, "Surface ") ||
|
|
|
|
|
StrStartsWith(line, "SCtrl ") ||
|
|
|
|
|
StrStartsWith(line, "TrimBy ") ||
|
|
|
|
|
StrStartsWith(line, "Curve ") ||
|
|
|
|
|
StrStartsWith(line, "CCtrl ") ||
|
|
|
|
|
StrStartsWith(line, "CurvePt ") ||
|
|
|
|
|
strcmp(line, "AddSurface")==0 ||
|
|
|
|
|
strcmp(line, "AddCurve")==0)
|
|
|
|
|
{
|
|
|
|
|
// ignore the mesh or shell, since we regenerate that
|
2008-04-24 06:22:16 +00:00
|
|
|
|
} else {
|
2009-12-15 12:26:22 +00:00
|
|
|
|
fileLoadError = true;
|
2008-04-24 06:22:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fclose(fh);
|
|
|
|
|
|
2009-12-15 12:26:22 +00:00
|
|
|
|
if(fileLoadError) {
|
|
|
|
|
Error("Unrecognized data in file. This file may be corrupt, or "
|
|
|
|
|
"from a new version of the program.");
|
2010-01-25 01:32:36 +00:00
|
|
|
|
// At least leave the program in a non-crashing state.
|
|
|
|
|
if(SK.group.n == 0) {
|
|
|
|
|
NewFile();
|
|
|
|
|
}
|
2009-12-15 12:26:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-04-18 11:11:48 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-19 07:26:38 +00:00
|
|
|
|
bool SolveSpace::LoadEntitiesFromFile(char *file, EntityList *le,
|
|
|
|
|
SMesh *m, SShell *sh)
|
|
|
|
|
{
|
|
|
|
|
SSurface srf;
|
|
|
|
|
ZERO(&srf);
|
|
|
|
|
SCurve crv;
|
|
|
|
|
ZERO(&crv);
|
|
|
|
|
|
2008-06-14 23:31:36 +00:00
|
|
|
|
fh = fopen(file, "rb");
|
2008-05-29 10:10:12 +00:00
|
|
|
|
if(!fh) return false;
|
|
|
|
|
|
|
|
|
|
le->Clear();
|
|
|
|
|
memset(&sv, 0, sizeof(sv));
|
|
|
|
|
|
|
|
|
|
char line[1024];
|
2013-08-26 20:09:15 +00:00
|
|
|
|
while(fgets(line, (int)sizeof(line), fh)) {
|
2008-05-29 10:10:12 +00:00
|
|
|
|
char *s = strchr(line, '\n');
|
|
|
|
|
if(s) *s = '\0';
|
2009-01-10 08:18:54 +00:00
|
|
|
|
// We should never get files with \r characters in them, but mailers
|
|
|
|
|
// will sometimes mangle attachments.
|
|
|
|
|
s = strchr(line, '\r');
|
|
|
|
|
if(s) *s = '\0';
|
2008-05-29 10:10:12 +00:00
|
|
|
|
|
|
|
|
|
if(*line == '\0') continue;
|
|
|
|
|
|
|
|
|
|
char *e = strchr(line, '=');
|
|
|
|
|
if(e) {
|
|
|
|
|
*e = '\0';
|
|
|
|
|
char *key = line, *val = e+1;
|
|
|
|
|
LoadUsingTable(key, val);
|
|
|
|
|
} else if(strcmp(line, "AddGroup")==0) {
|
2008-06-04 10:22:30 +00:00
|
|
|
|
// Don't leak memory; these get allocated whether we want them
|
|
|
|
|
// or not.
|
|
|
|
|
sv.g.remap.Clear();
|
2008-05-29 10:10:12 +00:00
|
|
|
|
} else if(strcmp(line, "AddParam")==0) {
|
|
|
|
|
|
|
|
|
|
} else if(strcmp(line, "AddEntity")==0) {
|
|
|
|
|
le->Add(&(sv.e));
|
|
|
|
|
memset(&(sv.e), 0, sizeof(sv.e));
|
|
|
|
|
} else if(strcmp(line, "AddRequest")==0) {
|
|
|
|
|
|
|
|
|
|
} else if(strcmp(line, "AddConstraint")==0) {
|
2008-06-14 08:43:38 +00:00
|
|
|
|
|
2009-09-24 15:52:48 +00:00
|
|
|
|
} else if(strcmp(line, "AddStyle")==0) {
|
|
|
|
|
|
2008-05-29 10:10:12 +00:00
|
|
|
|
} else if(strcmp(line, VERSION_STRING)==0) {
|
|
|
|
|
|
2009-05-19 07:26:38 +00:00
|
|
|
|
} else if(StrStartsWith(line, "Triangle ")) {
|
2008-05-29 10:10:12 +00:00
|
|
|
|
STriangle tr; ZERO(&tr);
|
2008-05-30 06:09:41 +00:00
|
|
|
|
if(sscanf(line, "Triangle %x %x "
|
|
|
|
|
"%lf %lf %lf %lf %lf %lf %lf %lf %lf",
|
|
|
|
|
&(tr.meta.face), &(tr.meta.color),
|
2008-05-29 10:10:12 +00:00
|
|
|
|
&(tr.a.x), &(tr.a.y), &(tr.a.z),
|
|
|
|
|
&(tr.b.x), &(tr.b.y), &(tr.b.z),
|
2008-05-30 06:09:41 +00:00
|
|
|
|
&(tr.c.x), &(tr.c.y), &(tr.c.z)) != 11)
|
2008-05-29 10:10:12 +00:00
|
|
|
|
{
|
|
|
|
|
oops();
|
|
|
|
|
}
|
|
|
|
|
m->AddTriangle(&tr);
|
2009-05-19 07:26:38 +00:00
|
|
|
|
} else if(StrStartsWith(line, "Surface ")) {
|
|
|
|
|
if(sscanf(line, "Surface %x %x %x %d %d",
|
|
|
|
|
&(srf.h.v), &(srf.color), &(srf.face),
|
|
|
|
|
&(srf.degm), &(srf.degn)) != 5)
|
|
|
|
|
{
|
|
|
|
|
oops();
|
|
|
|
|
}
|
|
|
|
|
} else if(StrStartsWith(line, "SCtrl ")) {
|
|
|
|
|
int i, j;
|
|
|
|
|
Vector c;
|
|
|
|
|
double w;
|
|
|
|
|
if(sscanf(line, "SCtrl %d %d %lf %lf %lf Weight %lf",
|
|
|
|
|
&i, &j, &(c.x), &(c.y), &(c.z), &w) != 6)
|
|
|
|
|
{
|
|
|
|
|
oops();
|
|
|
|
|
}
|
|
|
|
|
srf.ctrl[i][j] = c;
|
|
|
|
|
srf.weight[i][j] = w;
|
|
|
|
|
} else if(StrStartsWith(line, "TrimBy ")) {
|
|
|
|
|
STrimBy stb;
|
|
|
|
|
ZERO(&stb);
|
|
|
|
|
int backwards;
|
|
|
|
|
if(sscanf(line, "TrimBy %x %d %lf %lf %lf %lf %lf %lf",
|
|
|
|
|
&(stb.curve.v), &backwards,
|
|
|
|
|
&(stb.start.x), &(stb.start.y), &(stb.start.z),
|
|
|
|
|
&(stb.finish.x), &(stb.finish.y), &(stb.finish.z)) != 8)
|
|
|
|
|
{
|
|
|
|
|
oops();
|
|
|
|
|
}
|
|
|
|
|
stb.backwards = (backwards != 0);
|
|
|
|
|
srf.trim.Add(&stb);
|
|
|
|
|
} else if(strcmp(line, "AddSurface")==0) {
|
|
|
|
|
sh->surface.Add(&srf);
|
|
|
|
|
ZERO(&srf);
|
|
|
|
|
} else if(StrStartsWith(line, "Curve ")) {
|
|
|
|
|
int isExact;
|
|
|
|
|
if(sscanf(line, "Curve %x %d %d %x %x",
|
|
|
|
|
&(crv.h.v),
|
|
|
|
|
&(isExact),
|
|
|
|
|
&(crv.exact.deg),
|
|
|
|
|
&(crv.surfA.v), &(crv.surfB.v)) != 5)
|
|
|
|
|
{
|
|
|
|
|
oops();
|
|
|
|
|
}
|
|
|
|
|
crv.isExact = (isExact != 0);
|
|
|
|
|
} else if(StrStartsWith(line, "CCtrl ")) {
|
|
|
|
|
int i;
|
|
|
|
|
Vector c;
|
|
|
|
|
double w;
|
|
|
|
|
if(sscanf(line, "CCtrl %d %lf %lf %lf Weight %lf",
|
|
|
|
|
&i, &(c.x), &(c.y), &(c.z), &w) != 5)
|
|
|
|
|
{
|
|
|
|
|
oops();
|
|
|
|
|
}
|
|
|
|
|
crv.exact.ctrl[i] = c;
|
|
|
|
|
crv.exact.weight[i] = w;
|
|
|
|
|
} else if(StrStartsWith(line, "CurvePt ")) {
|
|
|
|
|
SCurvePt scpt;
|
|
|
|
|
int vertex;
|
|
|
|
|
if(sscanf(line, "CurvePt %d %lf %lf %lf",
|
|
|
|
|
&vertex,
|
|
|
|
|
&(scpt.p.x), &(scpt.p.y), &(scpt.p.z)) != 4)
|
|
|
|
|
{
|
|
|
|
|
oops();
|
|
|
|
|
}
|
|
|
|
|
scpt.vertex = (vertex != 0);
|
|
|
|
|
crv.pts.Add(&scpt);
|
|
|
|
|
} else if(strcmp(line, "AddCurve")==0) {
|
|
|
|
|
sh->curve.Add(&crv);
|
|
|
|
|
ZERO(&crv);
|
2008-05-29 10:10:12 +00:00
|
|
|
|
} else {
|
|
|
|
|
oops();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fclose(fh);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SolveSpace::ReloadAllImported(void) {
|
2008-06-25 05:14:49 +00:00
|
|
|
|
allConsistent = false;
|
|
|
|
|
|
2008-05-29 10:10:12 +00:00
|
|
|
|
int i;
|
2009-04-19 05:53:16 +00:00
|
|
|
|
for(i = 0; i < SK.group.n; i++) {
|
|
|
|
|
Group *g = &(SK.group.elem[i]);
|
2008-05-29 10:10:12 +00:00
|
|
|
|
if(g->type != Group::IMPORTED) continue;
|
|
|
|
|
|
|
|
|
|
g->impEntity.Clear();
|
|
|
|
|
g->impMesh.Clear();
|
2009-05-19 07:26:38 +00:00
|
|
|
|
g->impShell.Clear();
|
2008-06-25 05:14:49 +00:00
|
|
|
|
|
|
|
|
|
FILE *test = fopen(g->impFile, "rb");
|
|
|
|
|
if(test) {
|
|
|
|
|
fclose(test); // okay, exists
|
|
|
|
|
} else {
|
|
|
|
|
// It doesn't exist. Perhaps the entire tree has moved, and we
|
|
|
|
|
// can use the relative filename to get us back.
|
|
|
|
|
if(SS.saveFile[0]) {
|
|
|
|
|
char fromRel[MAX_PATH];
|
|
|
|
|
strcpy(fromRel, g->impFileRel);
|
|
|
|
|
MakePathAbsolute(SS.saveFile, fromRel);
|
|
|
|
|
test = fopen(fromRel, "rb");
|
|
|
|
|
if(test) {
|
|
|
|
|
fclose(test);
|
|
|
|
|
// It worked, this is our new absolute path
|
|
|
|
|
strcpy(g->impFile, fromRel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-19 07:26:38 +00:00
|
|
|
|
if(LoadEntitiesFromFile(g->impFile,
|
|
|
|
|
&(g->impEntity), &(g->impMesh), &(g->impShell)))
|
|
|
|
|
{
|
2008-06-25 05:14:49 +00:00
|
|
|
|
if(SS.saveFile[0]) {
|
|
|
|
|
// Record the imported file's name relative to our filename;
|
|
|
|
|
// if the entire tree moves, then everything will still work
|
|
|
|
|
strcpy(g->impFileRel, g->impFile);
|
|
|
|
|
MakePathRelative(SS.saveFile, g->impFileRel);
|
|
|
|
|
} else {
|
|
|
|
|
// We're not yet saved, so can't make it absolute
|
|
|
|
|
strcpy(g->impFileRel, g->impFile);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2008-06-14 23:31:36 +00:00
|
|
|
|
Error("Failed to load imported file '%s'", g->impFile);
|
2008-05-29 10:10:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|