1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
pub mod cte;
pub mod parsers;
pub mod utils;
use std::{convert::TryFrom, path::Path};
use anyhow::{format_err, Error};
use cte::{BoundaryType, ExtraData, Model};
use parsers::{bdl, ctehexml, kyg, tbl};
use utils::fround2;
pub const PROGNAME: &str = env!("CARGO_PKG_NAME");
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub fn get_copytxt() -> String {
format!(
"{} {} - Exportación de datos de HULC a EnvolventeCTE
Copyright (c) 2018-2020 Rafael Villar Burke <pachi@ietcc.csic.es>
Daniel Jiménez González <danielj@ietcc.csic.es>
Marta Sorribes Gil <msorribes@ietcc.csic.es>
Publicado bajo licencia MIT
",
PROGNAME, VERSION
)
}
pub fn collect_hulc_data<T: AsRef<Path>>(
ctehexmlpath: Option<T>,
kygpath: Option<T>,
tblpath: Option<T>,
) -> Result<Model, Error> {
let ctehexmlpath = &ctehexmlpath.ok_or_else(|| {
format_err!("No se ha podido localizar el archivo .ctehexml del proyecto")
})?;
let ctehexmldata = ctehexml::parse_with_catalog(&ctehexmlpath)?;
let mut ecdata = Model::try_from(&ctehexmldata)?;
fix_ecdata_from_extra(&mut ecdata, kygpath, tblpath);
Ok(ecdata)
}
pub fn fix_ecdata_from_extra<T: AsRef<Path>>(
ecdata: &mut Model,
kygpath: Option<T>,
tblpath: Option<T>,
) {
let mut extra = ecdata
.walls
.iter()
.map(|w| ExtraData {
name: w.name.clone(),
bounds: w.bounds,
spacetype: ecdata.get_space(&w.space).unwrap().space_type,
nextspace: w.nextto.clone(),
nextspacetype: w
.nextto
.as_ref()
.and_then(|s| ecdata.get_space(s))
.map(|s| s.space_type),
tilt: w.tilt.into(),
cons: w.cons.clone(),
u: 0.0,
computed_u: fround2(ecdata.u_for_wall(w).unwrap_or(0.0)),
})
.collect::<Vec<_>>();
if let Some(kygpath) = &kygpath {
let kygdata = kyg::parse(&kygpath).unwrap();
for e in &mut extra {
let wallname = e.name.as_str();
let kygwall = kygdata.walls.get(wallname);
if let Some(kw) = kygwall {
e.u = fround2(kw.u);
}
}
for win in ecdata.windows.iter_mut() {
let kygwin = kygdata.windows.get(&win.name);
if let Some(kw) = kygwin {
win.fshobst = fround2(kw.fshobst);
}
}
}
if let Some(tblpath) = &tblpath {
let tbldata = tbl::parse(&tblpath).unwrap();
#[allow(unused_assignments, unused_variables)]
for e in &mut extra {
if e.bounds != BoundaryType::INTERIOR {
continue;
};
let w = tbldata.elements.get(e.name.as_str()).unwrap();
e.u = fround2(w.u);
}
}
extra.retain(|e| f32::abs(e.u - e.computed_u) > 0.001);
ecdata.extra = Some(extra);
}