diff options
| author | Louis Burda <quent.burda@gmail.com> | 2021-05-18 14:45:50 +0200 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2021-05-18 14:46:23 +0200 |
| commit | 452885a387b3a1613defa378cee79eb97e7b4fc8 (patch) | |
| tree | d226bd9ffe720925fea752ea7b0d76c04ad4cdbc /service/src/stlfile.c | |
| parent | dafdcc3547ec786fac85486cbb77909fffe1a4de (diff) | |
| download | enowars5-service-stldoctor-452885a387b3a1613defa378cee79eb97e7b4fc8.tar.gz enowars5-service-stldoctor-452885a387b3a1613defa378cee79eb97e7b4fc8.zip | |
seperated modelname and solidname handling
Diffstat (limited to 'service/src/stlfile.c')
| -rw-r--r-- | service/src/stlfile.c | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/service/src/stlfile.c b/service/src/stlfile.c index 024f6cb..d1d1d7a 100644 --- a/service/src/stlfile.c +++ b/service/src/stlfile.c @@ -133,7 +133,7 @@ parse_file_ascii(struct parseinfo *info, char *buf, size_t len) PARSE_FAIL("Multiple nested solids!\n"); tmp = bp; if (!consume_keyword(&bp) && (arg = consume_arg(&bp, &end))) { - info->modelname = strndup(arg, end - arg); + info->solidname = strndup(arg, end - arg); } else { bp = tmp; } @@ -142,9 +142,9 @@ parse_file_ascii(struct parseinfo *info, char *buf, size_t len) if ((kw = stack_pop(&states)) != STATE_SOLID) PARSE_FAIL("Improper nesting, parent: %s\n", kwmap[kw].str); tmp = bp; - if (info->modelname && !consume_keyword(&bp) + if (info->solidname && !consume_keyword(&bp) && (arg = consume_arg(&bp, &end))) { - if (strncmp(info->modelname, arg, end - arg)) + if (strncmp(info->solidname, arg, end - arg)) PARSE_FAIL("Solid end/begin names do not match!\n"); } else { bp = tmp; @@ -219,9 +219,18 @@ parse_file_bin(struct parseinfo *info, char *buf, size_t len) memcpy(info->header, buf, 80); + if (strlen(buf + 1)) + info->solidname = checkp(strdup(buf + 1)); + bp = buf + 80; info->loopcount = le32toh(*(uint32_t*)bp); + if (!info->loopcount) { + memset(info->bbmax, 0, sizeof(float) * 3); + memset(info->bbmin, 0, sizeof(float) * 3); + return OK; + } + for (i = 0; i < 3; i++) { info->bbmin[i] = INFINITY; info->bbmax[i] = -INFINITY; @@ -261,14 +270,17 @@ parse_file(struct parseinfo *info, char *buf, size_t len) return FAIL; } - for (bp = buf; strchr(wsset, *bp); bp++); + info->filesize = len; /* check bin vs ascii with first keyword */ + for (bp = buf; strchr(wsset, *bp); bp++); status = !strncmp("solid", bp, 5) && strchr(wsset, bp[5]) ? parse_file_ascii(info, buf, len) : parse_file_bin(info, buf, len); if (status == FAIL) return FAIL; + if (!info->solidname) info->solidname = checkp(strdup("")); + if (!info->modelname) { resp = ask("Please enter your model name:\n"); if (strlen(resp) < 4) { @@ -291,6 +303,7 @@ save_info(struct parseinfo *info, FILE *f) nwrote += fwrite(&info->type, sizeof(int), 1, f); nwrote += fwrite(&info->loopcount, sizeof(int), 1, f); + nwrote += fwrite(&info->filesize, sizeof(unsigned), 1, f); for (i = 0; i < 3; i++) { nwrote += fwrite(&info->bbmin[i], sizeof(float), 1, f); @@ -299,10 +312,11 @@ save_info(struct parseinfo *info, FILE *f) nwrote += fwrite(info->header, 80, 1, f); - if (nwrote != 9) return FAIL; + if (nwrote != 10) return FAIL; - fputstr(f, info->modelname); + fputstr(f, info->solidname); fputstr(f, info->hash); + fputstr(f, info->modelname); return OK; } @@ -315,6 +329,7 @@ load_info(struct parseinfo *info, FILE *f) nread += fread(&info->type, sizeof(int), 1, f); nread += fread(&info->loopcount, sizeof(int), 1, f); + nread += fread(&info->filesize, sizeof(unsigned), 1, f); for (i = 0; i < 3; i++) { nread += fread(&info->bbmin[i], sizeof(float), 1, f); @@ -323,10 +338,11 @@ load_info(struct parseinfo *info, FILE *f) nread += fread(info->header, 80, 1, f); - if (nread != 9) return FAIL; + if (nread != 10) return FAIL; - freadstr(f, &info->modelname); + freadstr(f, &info->solidname); freadstr(f, &info->hash); + freadstr(f, &info->modelname); info->valid = 1; @@ -342,7 +358,7 @@ print_info(struct parseinfo *info) printf(" === Model info === \n"); - printf(" Name: %s\n", info->modelname); + printf(" File Size: %u\n", info->filesize); if (info->type == TYPE_BIN) { printf(" Header:\n "); @@ -356,12 +372,16 @@ print_info(struct parseinfo *info) } } - printf(" Hash: %s\n", info->hash); - printf(" Triangles: %i\n", info->loopcount); - printf(" Bounding Box: %.2f x %.2f x %.2f\n", + printf(" Model ID: %s\n", info->hash); + printf(" Model Name: %s\n", info->modelname); + printf(" Solid Name: %s\n", info->solidname); + printf(" Triangle Count: %i\n", info->loopcount); + printf(" Bounding Box Size: %.2f x %.2f x %.2f\n", info->bbmax[0] - info->bbmin[0], info->bbmax[1] - info->bbmin[1], info->bbmax[2] - info->bbmin[2]); + printf(" Bounding Box Origin: %.2f x %.2f x %.2f\n", + info->bbmin[0], info->bbmin[1], info->bbmin[2]); printf(" ================== \n"); } @@ -371,5 +391,6 @@ free_info(struct parseinfo *info) { NULLFREE(info->hash); NULLFREE(info->modelname); + NULLFREE(info->solidname); info->valid = 0; } |
