commit 8f605f525e20c791cea7433a7022625b1c8e7d98
parent 30be2c8b93081874b588f2ab10cbe9befa54a8a9
Author: Benjamin Piaud <benjamin.piaud@meso-star.com>
Date: Mon, 7 Nov 2022 11:56:47 +0100
Connections of the model1
Diffstat:
3 files changed, 138 insertions(+), 21 deletions(-)
diff --git a/src/cg_building_model1.c b/src/cg_building_model1.c
@@ -807,6 +807,108 @@ error:
goto exit;
}
+static res_T
+build_connection
+ (const char* prefix,
+ struct data_cad_model1* data_cad,
+ struct scad_geometry*** connection)
+{
+ res_T res = RES_OK;
+ struct scad_geometry* connect = NULL;
+ size_t count = 0;
+ char* cname = NULL;
+ struct str name;
+ int is_init = 0;
+
+ if (!prefix || !data_cad || !connection) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ str_init(NULL, &name);
+ is_init = 1;
+
+#define CREATE_CONNECT(G1,G2,SUFFIX) ERR(str_set(&name, prefix));\
+ ERR(str_append(&name, SUFFIX));\
+ cname = str_get(&name);\
+ ERR(scad_geometries_common_boundaries\
+ (cname,\
+ &data_cad->G1, 1,\
+ &data_cad->G2, 1,\
+ &connect));\
+ ERR(scad_geometry_get_count(connect, &count)); \
+ if (count>0) sa_push(*connection, connect);
+
+
+ /* -------------------------------------------------------------------------*/
+ /* habitable cavity connections */
+ /* -------------------------------------------------------------------------*/
+
+ /* with floor */
+ CREATE_CONNECT(habitable_cavity,floor,"_C_cavity_floor");
+
+ /* with wall */
+ CREATE_CONNECT(habitable_cavity,wall,"_C_cavity_wall");
+
+ /* with internal insulation */
+ if (data_cad->internal_insulation) {
+ CREATE_CONNECT(habitable_cavity,internal_insulation,"_C_cavity_internal_insulation");
+ }
+
+ /* with roof insulation */
+ if (data_cad->roof_insulation) {
+ CREATE_CONNECT(habitable_cavity,roof_insulation,"_C_roof_insulation");
+ } else {
+ /* with roof */
+ CREATE_CONNECT(habitable_cavity,roof,"_C_cavity_roof");
+ }
+
+ /* with intermediate floor */
+ if (data_cad->intermediate_floor) {
+ CREATE_CONNECT(habitable_cavity,intermediate_floor,"_C_cavity_intermediate_floor");
+ }
+
+ /* -------------------------------------------------------------------------*/
+ /* crawlspace cavity connections */
+ /* -------------------------------------------------------------------------*/
+
+ if (data_cad->crawlspace_cavity) {
+ /* with floor insulation */
+ if (data_cad->floor_insulation) {
+ CREATE_CONNECT(crawlspace_cavity, floor_insulation,"_C_crawlspace_insulation");
+ } else {
+ /* with floor */
+ CREATE_CONNECT(crawlspace_cavity, floor,"_C_crawlspace_floor");
+ }
+
+ /* with wall */
+ CREATE_CONNECT(crawlspace_cavity, wall,"_C_crawlspace_wall");
+ }
+
+ /* -------------------------------------------------------------------------*/
+ /* attic cavity connections */
+ /* -------------------------------------------------------------------------*/
+
+ if (data_cad->attic_cavity) {
+ /* with roof */
+ CREATE_CONNECT(attic_cavity, roof,"_C_attic_roof");
+
+ /* with roof insulation */
+ CREATE_CONNECT(attic_cavity, roof_insulation,"_C_attic_insulation");
+
+ /* with wall */
+ CREATE_CONNECT(attic_cavity, wall,"_C_attic_wall");
+ }
+
+#undef CREATE_CONNECT
+
+exit:
+ if (is_init) str_release(&name);
+ return res;
+error:
+ goto exit;
+}
+
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
@@ -958,8 +1060,13 @@ build_cad_model1(struct building* building)
ERR(scad_scene_partition());
/* build boundaries */
+ data_cad->boundary = NULL;
ERR(build_boundary(str_cget(&prefix), data_cad, &data_cad->boundary));
+ /* build connections */
+ data_cad->connection = NULL;
+ ERR(build_connection(str_cget(&prefix), data_cad, &data_cad->connection));
+
exit:
if (is_init) str_release(&prefix);
return res;
@@ -1049,6 +1156,11 @@ export_stl_model1
ERR(scad_stl_export(data_cad->boundary[i], NULL, binary));
}
+ /* boundary export*/
+ for (i=0; i<sa_size(data_cad->connection); ++i) {
+ ERR(scad_stl_export(data_cad->connection[i], NULL, binary));
+ }
+
exit:
return res;
error:
@@ -1068,7 +1180,7 @@ release_model1
str_release(building->data_name);
if (data_cad->boundary) sa_release(data_cad->boundary);
- if (data_cad->connection) free(data_cad->connection);
+ if (data_cad->connection) sa_release(data_cad->connection);
if (data) free(data);
if (data_cad) free(data_cad);
diff --git a/src/cg_building_model1.h b/src/cg_building_model1.h
@@ -30,32 +30,32 @@ struct building_params;
/* specific data for model 0 */
struct data_model1 {
- size_t inter_floor_n; /* number of intermediate floors */
- double wall; /* wall thickness */
- double floor; /* floor thickness */
- double inter_floor; /* intermediate floor thickness */
- double roof; /* roof thickness */
- double int_insulation; /* internal insulation thickness */
- double ext_insulation; /* external insulation thickness */
- double floor_insulation; /* floor insulation thickness */
- double roof_insulation; /* roof insulation thickness */
- double foundation; /* foundation depth */
- double crawl; /* crawl space height */
- double attic; /* attic height */
+ size_t inter_floor_n; /* number of intermediate floor >= 0 */
+ double wall; /* wall thickness > 0 */
+ double floor; /* floor thickness > 0*/
+ double inter_floor; /* intermediate floor thickness > 0 */
+ double roof; /* roof thickness > 0*/
+ double int_insulation; /* internal insulation thickness >= 0 */
+ double ext_insulation; /* external insulation thickness >= 0 */
+ double floor_insulation; /* floor insulation thickness >= 0 */
+ double roof_insulation; /* roof insulation thickness >= 0*/
+ double foundation; /* foundation depth >= 0 */
+ double crawl; /* crawl space height >= 0 */
+ double attic; /* attic height >= 0 (and only if roof insulation > 0)*/
};
struct data_cad_model1 {
struct scad_geometry* wall;
struct scad_geometry* roof;
struct scad_geometry* floor;
- struct scad_geometry* intermediate_floor;
+ struct scad_geometry* intermediate_floor; /* can be NULL */
struct scad_geometry* habitable_cavity;
- struct scad_geometry* crawlspace_cavity;
- struct scad_geometry* attic_cavity;
- struct scad_geometry* internal_insulation;
- struct scad_geometry* external_insulation;
- struct scad_geometry* floor_insulation;
- struct scad_geometry* roof_insulation;
+ struct scad_geometry* crawlspace_cavity; /* can be NULL */
+ struct scad_geometry* attic_cavity; /* can be NULL */
+ struct scad_geometry* internal_insulation; /* can be NULL */
+ struct scad_geometry* external_insulation; /* can be NULL */
+ struct scad_geometry* floor_insulation; /* can be NULL */
+ struct scad_geometry* roof_insulation; /* can be NULL */
struct scad_geometry* ground;
struct scad_geometry** boundary;
struct scad_geometry** connection;
diff --git a/src/cg_parsing.c b/src/cg_parsing.c
@@ -394,7 +394,7 @@ parse_building_params
data1->roof = 0.3;
data1->int_insulation = 0.1;
data1->ext_insulation = 0.12;
- data1->floor_insulation = 0.15;
+ data1->floor_insulation = 0.2;
data1->roof_insulation = 0.3;
data1->foundation = 1.2;
data1->crawl = 0.5;
@@ -403,6 +403,11 @@ parse_building_params
params0[1].data = (void*)data1;
ERR(htable_building_params_set(ht_params, ¶ms0[1].name, ¶ms0[1]));
+ /* check coherence */
+ if (data1->roof_insulation <= 0) data1->attic = 0;
+ if (data1->inter_floor <= 0) data1->inter_floor_n = 0;
+
+
exit:
free(params0);
return res;