Last active
February 27, 2023 21:31
-
-
Save vespakoen/2713a79fcbf55bcbdb44ff61efb53dad to your computer and use it in GitHub Desktop.
slvs experiment
This file contains 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
typedef struct { | |
char type; | |
const char *desc; | |
char fmt; | |
void *ptr; | |
} SaveTable; | |
struct { | |
Group g; | |
EntityBase e; | |
Param p; | |
ConstraintBase c; | |
} sv; | |
const SaveTable SAVED[] = { | |
{ 'g', "Group.h.v", 'x', &(sv.g.h.v) }, | |
{ 'g', "Group.type", 'd', &(sv.g.type) }, | |
{ 'g', "Group.order", 'd', &(sv.g.order) }, | |
{ 'g', "Group.name", 'S', &(sv.g.name) }, | |
{ 'g', "Group.activeWorkplane.v", 'x', &(sv.g.activeWorkplane.v) }, | |
{ 'g', "Group.opA.v", 'x', &(sv.g.opA.v) }, | |
{ 'g', "Group.opB.v", 'x', &(sv.g.opB.v) }, | |
{ 'g', "Group.valA", 'f', &(sv.g.valA) }, | |
{ 'g', "Group.valB", 'f', &(sv.g.valB) }, | |
{ 'g', "Group.valC", 'f', &(sv.g.valB) }, | |
{ 'g', "Group.color", 'c', &(sv.g.color) }, | |
{ 'g', "Group.subtype", 'd', &(sv.g.subtype) }, | |
{ 'g', "Group.skipFirst", 'b', &(sv.g.skipFirst) }, | |
{ 'g', "Group.meshCombine", 'd', &(sv.g.meshCombine) }, | |
{ 'g', "Group.forceToMesh", 'd', &(sv.g.forceToMesh) }, | |
{ 'g', "Group.predef.q.w", 'f', &(sv.g.predef.q.w) }, | |
{ 'g', "Group.predef.q.vx", 'f', &(sv.g.predef.q.vx) }, | |
{ 'g', "Group.predef.q.vy", 'f', &(sv.g.predef.q.vy) }, | |
{ 'g', "Group.predef.q.vz", 'f', &(sv.g.predef.q.vz) }, | |
{ 'g', "Group.predef.origin.v", 'x', &(sv.g.predef.origin.v) }, | |
{ 'g', "Group.predef.entityB.v", 'x', &(sv.g.predef.entityB.v) }, | |
{ 'g', "Group.predef.entityC.v", 'x', &(sv.g.predef.entityC.v) }, | |
{ 'g', "Group.predef.swapUV", 'b', &(sv.g.predef.swapUV) }, | |
{ 'g', "Group.predef.negateU", 'b', &(sv.g.predef.negateU) }, | |
{ 'g', "Group.predef.negateV", 'b', &(sv.g.predef.negateV) }, | |
{ 'g', "Group.visible", 'b', &(sv.g.visible) }, | |
{ 'g', "Group.suppress", 'b', &(sv.g.suppress) }, | |
{ 'g', "Group.relaxConstraints", 'b', &(sv.g.relaxConstraints) }, | |
{ 'g', "Group.allowRedundant", 'b', &(sv.g.allowRedundant) }, | |
{ 'g', "Group.allDimsReference", 'b', &(sv.g.allDimsReference) }, | |
{ 'g', "Group.scale", 'f', &(sv.g.scale) }, | |
{ 'g', "Group.remap", 'M', &(sv.g.remap) }, | |
{ 'p', "Param.h.v.", 'x', &(sv.p.h.v) }, | |
{ 'p', "Param.val", 'f', &(sv.p.val) }, | |
{ 'e', "Entity.h.v", 'x', &(sv.e.h.v) }, | |
{ 'e', "Entity.type", 'd', &(sv.e.type) }, | |
// { 'e', "Entity.construction", 'b', &(sv.e.construction) }, | |
// { 'e', "Entity.style", 'x', &(sv.e.style) }, | |
{ 'e', "Entity.str", 'S', &(sv.e.str) }, | |
{ 'e', "Entity.font", 'S', &(sv.e.font) }, | |
{ 'e', "Entity.file", 'P', &(sv.e.file) }, | |
{ 'e', "Entity.point[0].v", 'x', &(sv.e.point[0].v) }, | |
{ 'e', "Entity.point[1].v", 'x', &(sv.e.point[1].v) }, | |
{ 'e', "Entity.point[2].v", 'x', &(sv.e.point[2].v) }, | |
{ 'e', "Entity.point[3].v", 'x', &(sv.e.point[3].v) }, | |
{ 'e', "Entity.point[4].v", 'x', &(sv.e.point[4].v) }, | |
{ 'e', "Entity.point[5].v", 'x', &(sv.e.point[5].v) }, | |
{ 'e', "Entity.point[6].v", 'x', &(sv.e.point[6].v) }, | |
{ 'e', "Entity.point[7].v", 'x', &(sv.e.point[7].v) }, | |
{ 'e', "Entity.point[8].v", 'x', &(sv.e.point[8].v) }, | |
{ 'e', "Entity.point[9].v", 'x', &(sv.e.point[9].v) }, | |
{ 'e', "Entity.point[10].v", 'x', &(sv.e.point[10].v) }, | |
{ 'e', "Entity.point[11].v", 'x', &(sv.e.point[11].v) }, | |
{ 'e', "Entity.extraPoints", 'd', &(sv.e.extraPoints) }, | |
{ 'e', "Entity.normal.v", 'x', &(sv.e.normal.v) }, | |
{ 'e', "Entity.distance.v", 'x', &(sv.e.distance.v) }, | |
{ 'e', "Entity.workplane.v", 'x', &(sv.e.workplane.v) }, | |
// { 'e', "Entity.actPoint.x", 'f', &(sv.e.actPoint.x) }, | |
// { 'e', "Entity.actPoint.y", 'f', &(sv.e.actPoint.y) }, | |
// { 'e', "Entity.actPoint.z", 'f', &(sv.e.actPoint.z) }, | |
// { 'e', "Entity.actNormal.w", 'f', &(sv.e.actNormal.w) }, | |
// { 'e', "Entity.actNormal.vx", 'f', &(sv.e.actNormal.vx) }, | |
// { 'e', "Entity.actNormal.vy", 'f', &(sv.e.actNormal.vy) }, | |
// { 'e', "Entity.actNormal.vz", 'f', &(sv.e.actNormal.vz) }, | |
// { 'e', "Entity.actDistance", 'f', &(sv.e.actDistance) }, | |
// { 'e', "Entity.actVisible", 'b', &(sv.e.actVisible), }, | |
{ 'c', "Constraint.h.v", 'x', &(sv.c.h.v) }, | |
{ 'c', "Constraint.type", 'd', &(sv.c.type) }, | |
{ 'c', "Constraint.group.v", 'x', &(sv.c.group.v) }, | |
{ 'c', "Constraint.workplane.v", 'x', &(sv.c.workplane.v) }, | |
{ 'c', "Constraint.valA", 'f', &(sv.c.valA) }, | |
{ 'c', "Constraint.valP.v", 'x', &(sv.c.valP.v) }, | |
{ 'c', "Constraint.ptA.v", 'x', &(sv.c.ptA.v) }, | |
{ 'c', "Constraint.ptB.v", 'x', &(sv.c.ptB.v) }, | |
{ 'c', "Constraint.entityA.v", 'x', &(sv.c.entityA.v) }, | |
{ 'c', "Constraint.entityB.v", 'x', &(sv.c.entityB.v) }, | |
{ 'c', "Constraint.entityC.v", 'x', &(sv.c.entityC.v) }, | |
{ 'c', "Constraint.entityD.v", 'x', &(sv.c.entityD.v) }, | |
{ 'c', "Constraint.other", 'b', &(sv.c.other) }, | |
{ 'c', "Constraint.other2", 'b', &(sv.c.other2) }, | |
{ 'c', "Constraint.reference", 'b', &(sv.c.reference) }, | |
{ 'c', "Constraint.comment", 'S', &(sv.c.comment) }, | |
// { 'c', "Constraint.disp.offset.x", 'f', &(sv.c.disp.offset.x) }, | |
// { 'c', "Constraint.disp.offset.y", 'f', &(sv.c.disp.offset.y) }, | |
// { 'c', "Constraint.disp.offset.z", 'f', &(sv.c.disp.offset.z) }, | |
// { 'c', "Constraint.disp.style", 'x', &(sv.c.disp.style) }, | |
{ 0, NULL, 0, NULL } | |
}; | |
struct SAVEDptr { | |
EntityMap &M() { return *((EntityMap *)this); } | |
std::string &S() { return *((std::string *)this); } | |
Platform::Path &P() { return *((Platform::Path *)this); } | |
bool &b() { return *((bool *)this); } | |
RgbaColor &c() { return *((RgbaColor *)this); } | |
int &d() { return *((int *)this); } | |
double &f() { return *((double *)this); } | |
uint32_t &x() { return *((uint32_t *)this); } | |
}; | |
void SaveUsingTable(FILE* fh, int type) { | |
int i; | |
for(i = 0; SAVED[i].type != 0; i++) { | |
if(SAVED[i].type != type) continue; | |
int fmt = SAVED[i].fmt; | |
SAVEDptr *p = (SAVEDptr *)SAVED[i].ptr; | |
// Any items that aren't specified are assumed to be zero | |
if(fmt == 'S' && p->S().empty()) continue; | |
if(fmt == 'P' && p->P().IsEmpty()) continue; | |
if(fmt == 'd' && p->d() == 0) continue; | |
if(fmt == 'f' && EXACT(p->f() == 0.0)) continue; | |
if(fmt == 'x' && p->x() == 0) continue; | |
if(fmt == 'i') continue; | |
fprintf(fh, "%s=", SAVED[i].desc); | |
switch(fmt) { | |
case 'S': fprintf(fh, "%s", p->S().c_str()); break; | |
case 'b': fprintf(fh, "%d", p->b() ? 1 : 0); break; | |
case 'c': fprintf(fh, "%08x", p->c().ToPackedInt()); break; | |
case 'd': fprintf(fh, "%d", p->d()); break; | |
case 'f': fprintf(fh, "%.20f", p->f()); break; | |
case 'x': fprintf(fh, "%08x", p->x()); break; | |
case 'M': { | |
fprintf(fh, "{\n"); | |
// Sort the mapping, since EntityMap is not deterministic. | |
std::vector<std::pair<EntityKey, EntityId>> sorted(p->M().begin(), p->M().end()); | |
std::sort(sorted.begin(), sorted.end(), | |
[](std::pair<EntityKey, EntityId> &a, std::pair<EntityKey, EntityId> &b) { | |
return a.second.v < b.second.v; | |
}); | |
for(auto it : sorted) { | |
fprintf(fh, " %d %08x %d\n", | |
it.second.v, it.first.input.v, it.first.copyNumber); | |
} | |
fprintf(fh, "}"); | |
break; | |
} | |
case 'i': break; | |
default: ssassert(false, "Unexpected value format"); | |
} | |
fprintf(fh, "\n"); | |
} | |
} | |
#define VERSION_STRING "\261\262\263" "SolveSpaceREVa" | |
void Slvs_SaveSketch() { | |
FILE *fh; | |
fh = fopen("/Users/koen/Desktop/example.slvs", "w"); | |
fprintf(fh, "%s\n\n\n", VERSION_STRING); | |
// Our initial group, that contains the references. | |
Group g = {}; | |
g.visible = true; | |
g.name = C_("group-name", "#references"); | |
g.type = Group::Type::DRAWING_3D; | |
g.order = 0; | |
g.h = hGroup { 1 }; // = Group::HGROUP_REFERENCES; | |
SK.group.Add(&g); | |
Group g2 = {}; | |
// And an empty group, for the first stuff the user draws. | |
g2.visible = true; | |
g2.name = C_("group-name", "sketch-in-plane"); | |
g2.type = Group::Type::DRAWING_WORKPLANE; | |
g2.subtype = Group::Subtype::WORKPLANE_BY_POINT_ORTHO; | |
g2.order = 1; | |
g2.predef.q = Quaternion::From(1, 0, 0, 0); | |
hRequest hr = { 1 }; // = Request::HREQUEST_REFERENCE_XY | |
g2.predef.origin = hr.entity(1); | |
SK.group.AddAndAssignId(&g2); | |
SK.GetGroup(g2.h)->activeWorkplane = g2.h.entity(0); | |
for(auto &g : SK.group) { | |
sv.g = g; | |
SaveUsingTable(fh, 'g'); | |
fprintf(fh, "AddGroup\n\n"); | |
} | |
for(auto &p : SK.param) { | |
sv.p = p; | |
SaveUsingTable(fh, 'p'); | |
fprintf(fh, "AddParam\n\n"); | |
} | |
fprintf(fh, "Request.h.v=00000001\n"); | |
fprintf(fh, "Request.type=100\n"); | |
fprintf(fh, "Request.group.v=00000001\n"); | |
fprintf(fh, "Request.construction=0\n"); | |
fprintf(fh, "AddRequest\n\n"); | |
fprintf(fh, "Request.h.v=00000002\n"); | |
fprintf(fh, "Request.type=100\n"); | |
fprintf(fh, "Request.group.v=00000001\n"); | |
fprintf(fh, "Request.construction=0\n"); | |
fprintf(fh, "AddRequest\n\n"); | |
fprintf(fh, "Request.h.v=00000003\n"); | |
fprintf(fh, "Request.type=100\n"); | |
fprintf(fh, "Request.group.v=00000001\n"); | |
fprintf(fh, "Request.construction=0\n"); | |
fprintf(fh, "AddRequest\n\n"); | |
for(auto &e : SK.entity) { | |
// e.group.v = 2; | |
sv.e = e; | |
SaveUsingTable(fh, 'e'); | |
fprintf(fh, "AddEntity\n\n"); | |
} | |
for(auto &c : SK.constraint) { | |
// c.group.v = 2; | |
sv.c = c; | |
SaveUsingTable(fh, 'c'); | |
fprintf(fh, "AddConstraint\n\n"); | |
} | |
fclose(fh); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment