Date:2010-09-25 02:28:42 (8 years 7 months ago)
Author:Werner Almesberger
Commit:01d8e411f34d448b83fdb1cbfa4b63b0ac95fe6b
Message:Use the project name to disambiguate names in POV-Ray output.

- solidify/main.pov: change name from "Part" to "Part_batcvr"
- solidify/solid.h (povray), solidify/solid.c (sanitize, povray): use the
project name as prefix for PGM files and a suffix for the object name
- solidify/solidify.c (main): pass the project's basename to povray()
Files: solidify/main.pov (1 diff)
solidify/solid.c (1 diff)
solidify/solid.h (1 diff)
solidify/solidify.c (2 diffs)

Change Details

solidify/main.pov
1414}
1515
1616union {
17    Part
17    Part_batcvr
1818    pigment { rgb <0.9, 0.9, 0.9> }
1919    finish {
2020        brilliance 2
solidify/solid.c
4747}
4848
4949
50void povray(const struct solid *s)
50static void sanitize(const char *s, char *res)
51{
52    while (*s) {
53        if ((*s >= 'A' && *s <= 'Z') ||
54            (*s >= 'a' && *s <= 'z') ||
55            (*s >= '0' && *s <= '9') || *s == '_')
56            *res = *s;
57        else
58            *res = '_';
59        res++;
60        s++;
61    }
62    *res = 0;
63}
64
65
66void povray(const char *name, const struct solid *s)
5167{
5268    struct matrix m;
69    char tmp[1000]; /* @@@ enough */
5370
5471    m.a[0][0] = m.a[1][1] = 1;
5572    m.a[0][1] = m.a[1][0] = 0;
5673    m.b[0] = m.b[1] = 0;
5774
58    height_field("top.pgm", s->a, &m);
59    height_field("bot.pgm", s->b, &m);
75    sprintf(tmp, "%s-top.pgm", name);
76    height_field(tmp, s->a, &m);
77    sprintf(tmp, "%s-bot.pgm", name);
78    height_field(tmp, s->b, &m);
6079
6180    /*
6281     * 1/65535 = 0.000015..., so we set the water level a bit lower, e.g.,
6382     * to 0.0001
6483     */
84    sanitize(name, tmp);
6585    printf(
66"#declare Part =\n"
86"#declare Part_%s =\n"
6787" intersection {\n"
68" height_field { pgm \"top.pgm\" water_level 0.00001 smooth }\n"
69" height_field { pgm \"bot.pgm\" water_level 0.00001 smooth }\n"
70" }\n");
88" height_field { pgm \"%s-top.pgm\" water_level 0.00001 smooth }\n"
89" height_field { pgm \"%s-bot.pgm\" water_level 0.00001 smooth }\n"
90" }\n", tmp, name, name);
7191}
solidify/solid.h
1919};
2020
2121
22void povray(const struct solid *s);
22void povray(const char *name, const struct solid *s);
2323
2424#endif /* !SOLID_H */
solidify/solidify.c
1414#include <stdlib.h>
1515#include <stdio.h>
1616#include <unistd.h>
17#include <string.h>
1718#include <locale.h>
1819#include <gtk/gtk.h>
1920
...... 
148149
149150    save_project(prj);
150151
151    if (!isatty(1))
152        povray(&prj->s);
152    if (!isatty(1)) {
153        const char *slash = strrchr(prj->name, '/');
154        char tmp[1000]; /* @@@ enough */
155
156        strcpy(tmp, slash ? slash+1 : prj->name);
157        if (strchr(tmp, '.'))
158            *strchr(tmp, '.') = 0;
159        povray(tmp, &prj->s);
160    }
153161
154162    return 0;
155163}

Archive Download the corresponding diff file

Branches:
master



interactive