commit 17e7ff6b6c68cf92f5edde02d946f8c5cfab12c8
parent 7292b5ed640c497645b319c208139ca8983c48e0
Author: Benjamin Piaud <benjamin.piaud@meso-star.com>
Date: Fri, 23 Sep 2022 15:21:24 +0200
Adapt to new star-cad API
Diffstat:
7 files changed, 119 insertions(+), 135 deletions(-)
diff --git a/src/cg_building.c b/src/cg_building.c
@@ -25,7 +25,6 @@ static res_T
build_slab
(const struct pg_polygon* pg,
struct building* b,
- struct scad_scene* scene,
struct scad_geometry** slab)
{
res_T res = RES_OK;
@@ -51,9 +50,8 @@ build_slab
ERR(str_append_printf(&name, "%lu", (unsigned long)model));
ERR(str_append(&name, "_slab"));
- ERR(scad_scene_add_polygon
- (scene,
- NULL, /* Can be NULL */
+ ERR(scad_add_polygon
+ (NULL, /* Can be NULL */
pg->x,
pg->y,
0,
@@ -67,6 +65,8 @@ build_slab
d,
slab));
+ ERR(scad_geometry_delete(footprint));
+
exit:
if (is_init) str_release(&name);
return res;
@@ -119,7 +119,6 @@ build_wall
(const struct pg_polygon* pg,
const struct pg_polygon* pg_int,
struct building* b,
- struct scad_scene* scene,
struct scad_geometry** wall)
{
res_T res = RES_OK;
@@ -147,18 +146,16 @@ build_wall
ERR(str_append_printf(&name, "%lu", (unsigned long)model));
ERR(str_append(&name, "_wall"));
- ERR(scad_scene_add_polygon
- (scene,
- NULL,
+ ERR(scad_add_polygon
+ (NULL,
pg->x,
pg->y,
0,
pg->n,
&polygon));
- ERR(scad_scene_add_polygon
- (scene,
- NULL,
+ ERR(scad_add_polygon
+ (NULL,
pg_int->x,
pg_int->y,
0,
@@ -166,13 +163,11 @@ build_wall
&polygon_int));
- ERR(scad_scene_cut_geometries
- (scene,
- NULL,
- polygon,
- polygon_int,
- &footprint,
- 0));
+ ERR(scad_cut_geometries
+ (NULL,
+ &polygon, 1,
+ &polygon_int, 1,
+ &footprint));
d[2] = height;
ERR(scad_geometry_extrude
@@ -181,6 +176,10 @@ build_wall
d,
wall));
+ ERR(scad_geometry_delete(polygon));
+ ERR(scad_geometry_delete(polygon_int));
+ ERR(scad_geometry_delete(footprint));
+
exit:
if (is_init) str_release(&name);
return res;
@@ -217,9 +216,8 @@ build_cavity(const struct pg_polygon* pg, struct building* b)
ERR(str_append_printf(&name, "%lu", (unsigned long)model));
ERR(str_append(&name, "_cavity"));
- ERR(scad_scene_add_polygon
- (b->scene,
- NULL, /* Can be NULL */
+ ERR(scad_add_polygon
+ (NULL, /* Can be NULL */
pg->x,
pg->y,
e,
@@ -233,6 +231,8 @@ build_cavity(const struct pg_polygon* pg, struct building* b)
d,
&data_cad->cavity));
+ ERR(scad_geometry_delete(polygon));
+
exit:
if (is_init) str_release(&name);
return res;
@@ -266,14 +266,12 @@ build_connection(struct building* b)
ERR(str_append_printf(&name, "%lu", (unsigned long)model));
ERR(str_append(&name, "_C_cavity_slab"));
- ERR(scad_scene_geometries_common_boundaries
- (b->scene,
- str_cget(&name),
- data_cad->cavity,
- data_cad->slab,
- &data_cad->connection[0],
- 0));
-
+ ERR(scad_geometries_common_boundaries
+ (str_cget(&name),
+ &data_cad->cavity, 1,
+ &data_cad->slab, 1,
+ &data_cad->connection[0]));
+
/* cavity/wall connection */
ERR(str_set(&name, "building_"));
ERR(str_append_printf(&name, "%lu", (unsigned long)id));
@@ -281,13 +279,11 @@ build_connection(struct building* b)
ERR(str_append_printf(&name, "%lu", (unsigned long)model));
ERR(str_append(&name, "_C_cavity_wall"));
- ERR(scad_scene_geometries_common_boundaries
- (b->scene,
- str_cget(&name),
- data_cad->cavity,
- data_cad->wall,
- &data_cad->connection[1],
- 0));
+ ERR(scad_geometries_common_boundaries
+ (str_cget(&name),
+ &data_cad->cavity, 1,
+ &data_cad->wall, 1,
+ &data_cad->connection[1]));
/* cavity/roof connection */
ERR(str_set(&name, "building_"));
@@ -296,13 +292,11 @@ build_connection(struct building* b)
ERR(str_append_printf(&name, "%lu", (unsigned long)model));
ERR(str_append(&name, "_C_cavity_roof"));
- ERR(scad_scene_geometries_common_boundaries
- (b->scene,
- str_cget(&name),
- data_cad->cavity,
- data_cad->roof,
- &data_cad->connection[2],
- 0));
+ ERR(scad_geometries_common_boundaries
+ (str_cget(&name),
+ &data_cad->cavity, 1,
+ &data_cad->roof, 1,
+ &data_cad->connection[2]));
exit:
if (is_init) str_release(&name);
@@ -340,12 +334,9 @@ build_boundary(struct building* b)
ERR(str_append_printf(&name, "%lu", (unsigned long)model));
ERR(str_append(&name, "_boundary"));
- ERR(scad_scene_create_group
- (b->scene,
- str_cget(&name),
- 3,
- list,
- 4,
+ ERR(scad_geometry_boundary
+ (str_cget(&name),
+ list, 4,
&data_cad->boundary));
exit:
@@ -357,9 +348,7 @@ error:
}
res_T
-build_cad_model0
-(struct scad_device* dev,
- struct building* building)
+build_cad_model0(struct building* building)
{
res_T res = RES_OK;
double height = building->height;
@@ -369,7 +358,7 @@ build_cad_model0
struct data_cad_model0* data_cad;
double e_wall;
- if (!building || !dev) {
+ if (!building) {
res = RES_BAD_ARG;
goto error;
}
@@ -382,24 +371,22 @@ build_cad_model0
data_cad = malloc(sizeof(struct data_cad_model0));
building->data_cad = (struct data_cad_model0*)data_cad;
- ERR(scad_scene_create(dev, &building->scene));
-
e_wall = data->wall;
ERR(pg_offset(&pg, e_wall, &pg_int, &pg_ext));
/* build slab with pg_int */
- ERR(build_slab(&pg_int, building, building->scene, &data_cad->slab));
+ ERR(build_slab(&pg_int, building, &data_cad->slab));
/* roof is a translated copy of slab */
ERR(build_roof(data_cad->slab, building));
/* build wall with pg and pg_int */
- ERR(build_wall(&pg, &pg_int, building, building->scene, &data_cad->wall));
+ ERR(build_wall(&pg, &pg_int, building, &data_cad->wall));
/* build cavity */
ERR(build_cavity(&pg_int, building));
- ERR(scad_scene_conformal_mesh(building->scene));
+ ERR(scad_scene_partition());
/* build connection cavity/slab */
ERR(build_connection(building));
@@ -417,8 +404,7 @@ error:
res_T
build_footprint_model0
-(struct scad_scene* scene,
- struct building* building,
+(struct building* building,
struct scad_geometry** footprint)
{
res_T res = RES_OK;
@@ -438,8 +424,8 @@ build_footprint_model0
/* we simply add to the ground->scene the geometries in contact with ground */
- ERR(build_slab(&pg_int, building, scene, &geom[0]));
- ERR(build_wall(&pg, &pg_int, building, scene, &geom[1]));
+ ERR(build_slab(&pg_int, building, &geom[0]));
+ ERR(build_wall(&pg, &pg_int, building, &geom[1]));
str_init(NULL, &name);
is_init = 1;
@@ -449,13 +435,13 @@ build_footprint_model0
ERR(str_append_printf(&name, "%lu", (unsigned long)model));
ERR(str_append(&name, "_footprint"));
- ERR(scad_scene_create_group
- (scene,
- str_cget(&name),
- 3,
- geom,
- 2,
- footprint));
+/* ERR(scad_scene_create_group*/
+ /*(scene,*/
+ /*str_cget(&name), */
+ /*3,*/
+ /*geom,*/
+ /*2,*/
+ /*footprint));*/
exit:
if (is_init) str_release(&name);
@@ -513,7 +499,6 @@ release_model0
struct data_model0* data = (struct data_model0 *)building->data;
struct data_cad_model0* data_cad = (struct data_cad_model0 *)building->data_cad;
- ERR(scad_scene_ref_put(building->scene));
for (i=0; i<building->polygon_count; ++i) {
pg_release(&building->pg[i]);
diff --git a/src/cg_building.h b/src/cg_building.h
@@ -37,17 +37,16 @@ struct building {
size_t polygon_count; /* number of polygon */
/* each building has his own scene */
- struct scad_scene* scene;
+ /*struct scad_scene* scene;*/
/* specific data depending model */
void* data;
void* data_cad;
/* functors depending model */
- res_T (*build_cad)(struct scad_device* dev, struct building* building);
+ res_T (*build_cad)(struct building* building);
res_T (*build_footprint)
- (struct scad_scene* scene,
- struct building* building,
+ (struct building* building,
struct scad_geometry** footprint);
res_T (*export_stl)(const struct building* building);
res_T (*release)(struct building* building);
@@ -70,15 +69,12 @@ struct data_cad_model0 {
};
res_T
-build_cad_model0
-(struct scad_device* dev,
- struct building* building);
+build_cad_model0(struct building* building);
res_T
build_footprint_model0
-(struct scad_scene* scene,
- struct building* building,
- struct scad_geometry** footprint);
+ (struct building* building,
+ struct scad_geometry** footprint);
res_T
export_stl_model0
diff --git a/src/cg_city.c b/src/cg_city.c
@@ -143,8 +143,6 @@ parse:
/*city->ground.extent[3] = 100; */
/*city->ground.depth = 3; */
- ERR(scad_device_create(NULL, NULL, 1, &city->scad_device));
-
exit:
return res;
@@ -168,8 +166,7 @@ city_release(struct city* city)
}
ERR(ground_release(&city->ground));
-
- if (city->scad_device) scad_device_ref_put(city->scad_device);
+
if (city->building) sa_release(city->building);
exit:
@@ -179,32 +176,36 @@ error:
}
res_T
-city_cad_build(struct city* city)
+city_cad_build(struct logger* logger, struct city* city)
{
res_T res = RES_OK;
size_t i,n;
+ ERR(scad_initialize(logger, NULL, 3));
/* iterate on building */
n = city->n;
for (i=0; i<n; ++i) {
/* create building */
- ERR(city->building[i].build_cad(city->scad_device, &city->building[i]));
+ ERR(city->building[i].build_cad(&city->building[i]));
+ ERR(scad_scene_mesh());
+ ERR(city->building[i].export_stl(&city->building[i]));
+ ERR(scad_scene_clear());
}
exit:
+ scad_finalize();
return res;
error:
goto exit;
}
res_T
-city_ground_build(struct city* city)
+city_ground_build(struct logger* logger, struct city* city)
{
res_T res = RES_OK;
size_t i,n;
- ERR(scad_scene_create(city->scad_device, &city->ground.scene));
-
+ ERR(scad_initialize(logger, NULL, 3));
/* iterate on building */
n = city->n;
city->ground.n = n;
@@ -213,15 +214,17 @@ city_ground_build(struct city* city)
for (i=0; i<n; ++i) {
/* create building footprint */
ERR(city->building[i].build_footprint
- (city->ground.scene,
- &city->building[i],
+ (&city->building[i],
&city->ground.footprint[i]));
}
ERR(ground_build_cad(&city->ground));
-
+
+ ERR(scad_scene_mesh());
+ ERR(ground_export_stl(&city->ground));
exit:
+ scad_finalize();
return res;
error:
goto exit;
diff --git a/src/cg_city.h b/src/cg_city.h
@@ -56,23 +56,22 @@ log_err_fn(const char* msg, void* ctx)
struct city {
- struct scad_device* scad_device;
struct building* building; /* list of buildings */
size_t n;
struct ground ground;
};
-#define CITY_NULL__ {NULL, NULL, 0, GROUND_NULL}
+#define CITY_NULL__ {NULL, 0, GROUND_NULL}
static const struct city CITY_NULL = CITY_NULL__;
res_T
city_init(struct logger* logger, struct city* city, struct args* arg);
res_T
-city_cad_build(struct city* city);
+city_cad_build(struct logger* logger, struct city* city);
res_T
-city_ground_build(struct city* city);
+city_ground_build(struct logger* logger, struct city* city);
res_T
city_export_stl(const struct city* city);
diff --git a/src/cg_ground.c b/src/cg_ground.c
@@ -53,17 +53,17 @@ ground_build_cad
is_init = 1;
ERR(str_set(&name, "ground"));
- ERR(scad_scene_add_box
- (ground->scene,
- str_cget(&name),
+ ERR(scad_add_box
+ (str_cget(&name),
origin,
extent,
&ground->geometry));
+ ERR(scad_scene_partition());
/* TODO: do something for building with foundation.
* without foundation, the mesh is conformal because ground->footprint include
* geometry in contact with ground. */
- ERR(scad_scene_conformal_mesh(ground->scene));
+ /*ERR(scad_scene_conformal_mesh(ground->scene));*/
exit:
if (is_init) str_release(&name);
@@ -92,7 +92,7 @@ ground_release(struct ground* ground)
{
res_T res = RES_OK;
- if (ground->scene) {ERR(scad_scene_ref_get(ground->scene));}
+ /*if (ground->scene) {ERR(scad_scene_ref_get(ground->scene));}*/
if (ground->footprint) free(ground->footprint);
exit:
diff --git a/src/cg_main.c b/src/cg_main.c
@@ -33,11 +33,11 @@ int main
logger_set_stream(&logger, LOG_WARNING, log_warn_fn, NULL);
logger_set_stream(&logger, LOG_ERROR, log_err_fn, NULL);
+
ERR(parse_args(&logger,argc, argv, &args));
ERR(city_init(&logger, &city, &args));
- ERR(city_cad_build(&city));
- ERR(city_ground_build(&city));
- ERR(city_export_stl(&city));
+ ERR(city_cad_build(&logger, &city));
+ ERR(city_ground_build(&logger, &city));
exit:
city_release(&city);
diff --git a/src/cg_parsing.c b/src/cg_parsing.c
@@ -136,6 +136,7 @@ parse_building
{
res_T res = RES_OK;
char* line = NULL;
+ (void)logger;
ERR(txtrdr_read_line(reader));
while (txtrdr_get_line(reader)){
@@ -145,25 +146,25 @@ parse_building
line = remove_spaces(txtrdr_get_line(reader));
ERR(strtolower(line, line));
- if (sscanf(line, "id=%lf", &id) == 1 ) {
+ if (sscanf(line, "id=%lu", &id) == 1 ) {
building->id = id;
}
- value = malloc(( strlen(line )) * sizeof(char));
- if (sscanf(line, "extent=%s", value) == 1 ) {
- size_t sz = 0;
- if (cstr_to_list_double(value, ',', ground->extent, &sz, 4)
- != RES_OK || sz != 4) {
- logger_print(logger, LOG_ERROR,
- "[ground] extent value not valid: 4 values required.\n");
- res = RES_BAD_ARG;
- if (value) free(value);
- goto error;
- }
- }
- if (value) free(value);
+/* value = malloc(( strlen(line )) * sizeof(char));*/
+ /*if (sscanf(line, "extent=%s", value) == 1 ) {*/
+ /*size_t sz = 0;*/
+ /*if (cstr_to_list_double(value, ',', ground->extent, &sz, 4)*/
+ /*!= RES_OK || sz != 4) {*/
+ /*logger_print(logger, LOG_ERROR, */
+ /*"[ground] extent value not valid: 4 values required.\n");*/
+ /*res = RES_BAD_ARG;*/
+ /*if (value) free(value);*/
+ /*goto error;*/
+ /*}*/
+ /*}*/
+ /*if (value) free(value);*/
- [>if new section goto check and exit<]
+ /*if new section goto check and exit*/
if (sscanf(line, "[%[^]]", value) == 1 ) {
goto check;
}
@@ -171,22 +172,22 @@ parse_building
}
check:
- [>check depth<]
- if (ground->depth <= 0) {
- logger_print(logger, LOG_ERROR,
- "[ground] depth value not valid: must be > 0.\n");
- res = RES_BAD_ARG;
- goto error;
- }
-
- [>check extent<]
- if (ground->extent[0] >= ground->extent[1]
- || ground->extent[2] >= ground->extent[3]) {
- logger_print(logger, LOG_ERROR,
- "[ground] extent value not valid: xmax must be > xmin and ymax must be > ymin.\n");
- res = RES_BAD_ARG;
- goto error;
- }
+/* [>check depth<]*/
+ /*if (ground->depth <= 0) {*/
+ /*logger_print(logger, LOG_ERROR, */
+ /*"[ground] depth value not valid: must be > 0.\n");*/
+ /*res = RES_BAD_ARG;*/
+ /*goto error;*/
+ /*} */
+
+ /*[>check extent<]*/
+ /*if (ground->extent[0] >= ground->extent[1]*/
+ /*|| ground->extent[2] >= ground->extent[3]) {*/
+ /*logger_print(logger, LOG_ERROR, */
+ /*"[ground] extent value not valid: xmax must be > xmin and ymax must be > ymin.\n");*/
+ /*res = RES_BAD_ARG;*/
+ /*goto error;*/
+/* }*/
exit: