forked from weilixu/gbEplus
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIDFWriter.java
More file actions
144 lines (123 loc) · 4.59 KB
/
Copy pathIDFWriter.java
File metadata and controls
144 lines (123 loc) · 4.59 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package main.java.model.idf;
import java.util.ArrayList;
import main.java.model.idd.EnergyPlusFieldTemplate;
import main.java.model.idd.EnergyPlusObjectTemplate;
import main.java.model.idd.IddParser;
/**
* A simple utility class writes data into EnergyPlus
* @author weilixu
*
*/
public class IDFWriter {
private IddParser IDDData;
private EnergyPlusObjectTemplate objectTemplate; // record the object label that is current under processing
private ArrayList<String> lines;
private ArrayList<String> units;
private ArrayList<String> comments;
private ArrayList<String> topComments;
public IDFWriter(){
lines = new ArrayList<String>();
units = new ArrayList<String>();
comments = new ArrayList<String>();
topComments = new ArrayList<String>();
}
public void setIddParser(IddParser parser){
IDDData = parser;
}
public void setProcessingObject(String objectLabel){
if(IDDData == null){
//TODO raise exception
}
objectTemplate = IDDData.getObject(objectLabel);
if(objectTemplate == null){
//TODO raise exception
}
}
public int getSizeOfFields(){
return objectTemplate.getNumberOfFields();
}
public String getNextAvailableFieldComment(int index){
return objectTemplate.getFieldTemplateByIndex(index).getFieldName();
}
/**
* record inputs following the order of IDD data -
* this will trigger the rigorous IDD data check
* if the data does not match the IDD description, there will be error raised
*
* Since this method is using IDD to restrain the user behavior as well as automatically
* fill up the comments and units, it is not necessary to input comments
*
* The function should be called in the order of data inputs in the IDD.
*
* You have to firstly identify the object that is under processing first
* call set processingObject.
*/
public void recordInputsUsingIDD(String data){
if(IDDData == null){
//TODO raise error
}
int index = lines.size()-1;
if (index > objectTemplate.getNumberOfFields()){
//TODO raise error "The object ------ field is overflow"
}
EnergyPlusFieldTemplate fieldTemp = objectTemplate.getFieldTemplateByIndex(index);
if(data == null){
if(fieldTemp.getDefault()!=null){
lines.add(fieldTemp.getDefault());
}else if(fieldTemp.isAutoCalculatable()){
lines.add("AUTOCALCULATED");
}else if(fieldTemp.isAutoSizable()){
lines.add("AUTOSIZED");
}else{
lines.add("");
}
}else{
lines.add(data);
}
//TODO later need to confirm the checks
units.add(fieldTemp.getUnit());
comments.add(fieldTemp.getFieldName());
}
public void addObjectWithIDD(IDFFileObject file){
int size = lines.size();
if(size < objectTemplate.getNumberOfMinFields()){
//TODO raise exception - not enough fields
}else if(size > objectTemplate.getNumberOfFields()){
//TODO raise exception - fields overflow
}
if(objectTemplate.isExtensible()){
//if it is extensible - there is no need to fill up all the extensible fields
int remainder = (size - objectTemplate.getBeginningOfExtensible())%objectTemplate.numOfExtensibles();
if(remainder == 0){
file.addIDFObject(new IDFObject(lines,units, comments, topComments));
lines.clear();
units.clear();
comments.clear();
topComments.clear();
}else{//fill up the remainder field
for(int i=remainder-1; i>=0; i--){
lines.add("");
units.add(objectTemplate.getFieldTemplateByIndex(objectTemplate.getBeginningOfExtensible() + objectTemplate.numOfExtensibles() - i).getUnit());
comments.add(objectTemplate.getFieldTemplateByIndex(objectTemplate.getBeginningOfExtensible() + objectTemplate.numOfExtensibles() - i).getFieldName());
}
file.addIDFObject(new IDFObject(lines,units, comments, topComments));
lines.clear();
units.clear();
comments.clear();
topComments.clear();
}
}
}
public void recordInputs(String line, String unit, String comment, String topComments){
lines.add(line);
units.add(unit);
comments.add(comment);
}
public void addObject(IDFFileObject file){
file.addIDFObject(new IDFObject(lines,units, comments, topComments));
lines.clear();
units.clear();
comments.clear();
topComments.clear();
}
}