rgradisc@1311
|
1 |
/*
|
rgradisc@1311
|
2 |
* Created on Sep 11, 2003
|
rgradisc@1311
|
3 |
*/
|
rgradisc@1311
|
4 |
package isac.util.formulae;
|
rgradisc@1311
|
5 |
|
rgradisc@1311
|
6 |
/**
|
wneuper@1947
|
7 |
* Every calculation has a CalcHead, which consists of Model and Specification
|
wneuper@2271
|
8 |
* of the calculation. The CalcHead is empty at the beginning of the
|
wneuper@1947
|
9 |
* Specifying-phase and has to be filled before one can start the solving phase.
|
akremp@1336
|
10 |
*
|
akremp@1336
|
11 |
* @author Alan Krempler
|
rgradisc@1311
|
12 |
*/
|
rgradisc@1311
|
13 |
public class CalcHead extends CalcElement {
|
rgradisc@1311
|
14 |
|
wneuper@1947
|
15 |
/**
|
wneuper@1978
|
16 |
* Labels a model item as "correct" TODO rename CALCHEAD_* to MODEL_ITEM_*
|
wneuper@1947
|
17 |
*/
|
wneuper@2245
|
18 |
public static final int MODEL_ITEM_CORRECT = 1;
|
rgradisc@1311
|
19 |
|
wneuper@1947
|
20 |
/**
|
wneuper@1947
|
21 |
* Labels a model item as "incorrect"
|
wneuper@1947
|
22 |
*/
|
wneuper@2245
|
23 |
public static final int MODEL_ITEM_INCORRECT = 2;
|
rgradisc@1311
|
24 |
|
wneuper@1947
|
25 |
/**
|
wneuper@1947
|
26 |
* Labels a model item as "syntax error"
|
wneuper@1947
|
27 |
*/
|
wneuper@2245
|
28 |
public static final int MODEL_ITEM_SYNTAXERROR = 3;
|
rgradisc@1311
|
29 |
|
wneuper@1947
|
30 |
/**
|
wneuper@1947
|
31 |
* Labels a model item as "incomplete"
|
wneuper@1947
|
32 |
*/
|
wneuper@2245
|
33 |
public static final int MODEL_ITEM_INCOMPLETE = 4;
|
rgradisc@1615
|
34 |
|
wneuper@1947
|
35 |
/**
|
wneuper@1947
|
36 |
* Labels a model item as "false"
|
wneuper@1947
|
37 |
*/
|
wneuper@2245
|
38 |
public static final int MODEL_ITEM_FALSE = 5;
|
rgradisc@1615
|
39 |
|
wneuper@1947
|
40 |
/**
|
wneuper@1947
|
41 |
* Labels a model item as to be filled in by the KI
|
wneuper@1947
|
42 |
*/
|
wneuper@2245
|
43 |
public static final int MODEL_ITEM_HELP_ME = 6;
|
rgradisc@1615
|
44 |
|
wneuper@1947
|
45 |
/**
|
wneuper@1947
|
46 |
* Labels a model item as superfluous
|
wneuper@1947
|
47 |
*/
|
wneuper@2245
|
48 |
public static final int MODEL_ITEM_SUPERFLUOUS = 7;
|
rgradisc@1615
|
49 |
|
wneuper@1947
|
50 |
/**
|
wneuper@1947
|
51 |
* Labels a model item as missing
|
wneuper@1947
|
52 |
*/
|
wneuper@2245
|
53 |
public static final int MODEL_ITEM_MISSING = 8;
|
rgradisc@1615
|
54 |
|
wneuper@2245
|
55 |
/**
|
wneuper@2245
|
56 |
* show all details of a CalcHead in the CalcHeadPanel
|
wneuper@2271
|
57 |
*
|
wneuper@2271
|
58 |
* @deprecated in favour of ICalcElement#VIEWSTYLE_DEFAULT FIXME.WN0504
|
wneuper@2245
|
59 |
*/
|
wneuper@1947
|
60 |
public static final int VIEWSTYLE_FULL = 2;
|
rgradisc@1615
|
61 |
|
wneuper@2245
|
62 |
/**
|
wneuper@2245
|
63 |
* skip to show the CalcHead in the CalcHeadPanel, rather only show the
|
wneuper@2351
|
64 |
* HeadLine of the CalcHead on the Worksheet
|
wneuper@2271
|
65 |
*
|
wneuper@2271
|
66 |
* @deprecated in favour of ICalcElement#DISPLAY_HIDDEN FIXME.WN0504
|
wneuper@2245
|
67 |
*/
|
wneuper@1947
|
68 |
public static final int VIEWSTYLE_SINGLELINE = 4;
|
rgradisc@1615
|
69 |
|
wneuper@2245
|
70 |
/**
|
wneuper@2245
|
71 |
* @deprecated WN050415 no description available
|
wneuper@2245
|
72 |
*/
|
wneuper@2271
|
73 |
//public static final int VIEWSTYLE_IN_CALC = 5;
|
wneuper@2245
|
74 |
/**
|
wneuper@2245
|
75 |
* @deprecated WN050415 no description available
|
wneuper@2245
|
76 |
*/
|
wneuper@2271
|
77 |
//public static final int VIEWSTYLE_SIMPLE_SOLVE = 10;
|
wneuper@1947
|
78 |
// TODO: remove testing constant
|
wneuper@1947
|
79 |
private int calcTreeID = -4711;
|
rgradisc@1311
|
80 |
|
wneuper@1947
|
81 |
private CalcHeadItemList given_, where_, find_, relate_;
|
rgradisc@1615
|
82 |
|
wneuper@1947
|
83 |
private Specification specification;
|
rgradisc@1311
|
84 |
|
wneuper@1947
|
85 |
private Position position;
|
rgradisc@1615
|
86 |
|
wneuper@1947
|
87 |
private String belongsTo;
|
rgradisc@1311
|
88 |
|
wneuper@2271
|
89 |
private String head;//TODO.WN050420 should be type Formula
|
rgradisc@1311
|
90 |
|
wneuper@1947
|
91 |
private int calcHeadStatus;//TODO.WN041007 confusion with statusString
|
rgradisc@1311
|
92 |
|
wneuper@1947
|
93 |
private String statusString;//TODO.WN041007 confusion with calcHeadStatus
|
wneuper@1978
|
94 |
|
wneuper@1978
|
95 |
// drop THIS one and setStatusString
|
rgradisc@1311
|
96 |
|
wneuper@1947
|
97 |
/**
|
wneuper@2245
|
98 |
* Format the object in a way that the bridge can handle it FIXME.WN041008
|
wneuper@2391
|
99 |
* this is Formalization.toSMLString, _NOT_ CalcHead.toSMLString !!!
|
wneuper@1947
|
100 |
*
|
wneuper@1947
|
101 |
* @return SML representation
|
wneuper@1947
|
102 |
*/
|
wneuper@1947
|
103 |
public String toSMLString() {
|
wneuper@2271
|
104 |
//this should go to Formalization???WN050420 dont understand
|
wneuper@1947
|
105 |
StringBuffer sb = new StringBuffer();
|
wneuper@1947
|
106 |
sb.append("[([");
|
wneuper@1947
|
107 |
if (getGiven() != null) {
|
wneuper@1947
|
108 |
sb.append(getGiven().toSMLString());
|
wneuper@1947
|
109 |
}
|
wneuper@1947
|
110 |
if (getWhere() != null) {
|
wneuper@1947
|
111 |
sb.append(",");
|
wneuper@1947
|
112 |
sb.append(getWhere().toSMLString());
|
wneuper@1947
|
113 |
}
|
wneuper@1947
|
114 |
if (getFind() != null) {
|
wneuper@1947
|
115 |
sb.append(",");
|
wneuper@1947
|
116 |
sb.append(getFind().toSMLString());
|
wneuper@1947
|
117 |
}
|
wneuper@1947
|
118 |
if (getRelate() != null) {
|
wneuper@1947
|
119 |
sb.append(",");
|
wneuper@1947
|
120 |
sb.append(getRelate().toSMLString());
|
wneuper@1947
|
121 |
}
|
wneuper@1947
|
122 |
sb.append("],(");
|
wneuper@1947
|
123 |
if (getSpecification() != null) {
|
wneuper@1947
|
124 |
sb.append(specification.toSMLString());
|
wneuper@1947
|
125 |
}
|
wneuper@1947
|
126 |
sb.append("))]");
|
wneuper@1947
|
127 |
return sb.toString();
|
wneuper@1947
|
128 |
}
|
rgradisc@1311
|
129 |
|
wneuper@1947
|
130 |
/**
|
wneuper@1947
|
131 |
* Special string format of the calcHead used by modifyCalcHead
|
wneuper@1947
|
132 |
* TODO.WN041007 ?
|
wneuper@1947
|
133 |
*
|
wneuper@1947
|
134 |
* @return String used by modifyCalcHead
|
wneuper@1947
|
135 |
*/
|
wneuper@1947
|
136 |
public String toModifyCalcHeadString() {
|
wneuper@1947
|
137 |
StringBuffer sb = new StringBuffer();
|
wneuper@1947
|
138 |
try {
|
wneuper@1947
|
139 |
belongsTo = "Pbl";//TODO.WN041007 this is too restrictive: + Met !!
|
wneuper@1947
|
140 |
sb.append("((");
|
wneuper@1947
|
141 |
if (position == null) {
|
wneuper@1947
|
142 |
position = new Position();
|
wneuper@1947
|
143 |
position.setKind("Pbl");
|
wneuper@1947
|
144 |
}
|
wneuper@1947
|
145 |
sb.append(position.toSMLString());
|
wneuper@1947
|
146 |
sb.append("),\"");
|
wneuper@1947
|
147 |
sb.append(head);
|
wneuper@1947
|
148 |
sb.append("\",[Given [");
|
wneuper@1947
|
149 |
sb.append(given_.toSMLString());
|
wneuper@1947
|
150 |
sb.append("],Find [");
|
wneuper@1947
|
151 |
sb.append(find_.toSMLString());
|
wneuper@1947
|
152 |
sb.append("],Relate [");
|
wneuper@1947
|
153 |
sb.append(relate_.toSMLString());
|
wneuper@1947
|
154 |
sb.append("]]," + belongsTo + ",(");
|
wneuper@1947
|
155 |
sb.append(specification.toSMLString());
|
wneuper@1947
|
156 |
sb.append("))");
|
rgradisc@1311
|
157 |
|
wneuper@1947
|
158 |
} catch (Exception e) {
|
wneuper@1947
|
159 |
System.out.println("Some Items of Calchead are null!");
|
wneuper@1947
|
160 |
}
|
wneuper@1947
|
161 |
return sb.toString();
|
wneuper@1947
|
162 |
}
|
rgradisc@1311
|
163 |
|
wneuper@1947
|
164 |
/**
|
wneuper@1947
|
165 |
* Copies values form one CalcHead object to another. This is needed,
|
wneuper@1947
|
166 |
* because the backend produces a new calcHead after each update, but the
|
wneuper@1947
|
167 |
* dialog holds only one instance of CalcHead all the time.
|
wneuper@1947
|
168 |
*
|
wneuper@1947
|
169 |
* @param other
|
wneuper@1947
|
170 |
* the other calcHead object
|
wneuper@1947
|
171 |
*/
|
wneuper@1947
|
172 |
public void fillValuesfrom(CalcHead other) {
|
wneuper@1947
|
173 |
this.belongsTo = other.belongsTo;
|
wneuper@1947
|
174 |
this.calcHeadStatus = other.calcHeadStatus;
|
wneuper@1947
|
175 |
this.calcTreeID = other.calcTreeID;
|
wneuper@1947
|
176 |
this.find_ = other.find_;
|
wneuper@1947
|
177 |
this.given_ = other.given_;
|
wneuper@1947
|
178 |
this.head = other.head;
|
wneuper@1947
|
179 |
this.position = other.position;
|
wneuper@1947
|
180 |
this.relate_ = other.relate_;
|
wneuper@1947
|
181 |
this.specification = other.specification;
|
wneuper@1947
|
182 |
this.where_ = other.where_;
|
wneuper@1947
|
183 |
this.visibility_ = other.visibility_;
|
wneuper@1947
|
184 |
this.view_style_ = other.view_style_;
|
wneuper@1947
|
185 |
this.rating_ = other.rating_;
|
wneuper@1947
|
186 |
}
|
rgradisc@1311
|
187 |
|
wneuper@1947
|
188 |
/*
|
wneuper@1947
|
189 |
* (non-Javadoc)
|
wneuper@1947
|
190 |
*
|
wneuper@1947
|
191 |
* @see isac.util.CalcElement#getMathML()
|
wneuper@1947
|
192 |
*/
|
wneuper@1947
|
193 |
public String getMathML() {
|
wneuper@1947
|
194 |
// TODO Auto-generated method stub
|
wneuper@1947
|
195 |
return null;
|
wneuper@1947
|
196 |
}
|
rgradisc@1311
|
197 |
|
wneuper@1947
|
198 |
/*
|
wneuper@1947
|
199 |
* (non-Javadoc)
|
wneuper@1947
|
200 |
*
|
wneuper@1947
|
201 |
* @see isac.util.CalcElement#getType()
|
wneuper@1947
|
202 |
*/
|
wneuper@1947
|
203 |
public int getType() {
|
wneuper@1947
|
204 |
return CALCEL_CALCHEAD;
|
wneuper@1947
|
205 |
}
|
rgradisc@1311
|
206 |
|
wneuper@1947
|
207 |
public CalcHeadItemList getFind() {
|
wneuper@1947
|
208 |
return find_;
|
wneuper@1947
|
209 |
}
|
rgradisc@1311
|
210 |
|
wneuper@1947
|
211 |
public CalcHeadItemList getGiven() {
|
wneuper@1947
|
212 |
return given_;
|
wneuper@1947
|
213 |
}
|
rgradisc@1311
|
214 |
|
wneuper@1947
|
215 |
public CalcHeadItemList getRelate() {
|
wneuper@1947
|
216 |
return relate_;
|
wneuper@1947
|
217 |
}
|
rgradisc@1311
|
218 |
|
wneuper@1947
|
219 |
public CalcHeadItemList getWhere() {
|
wneuper@1947
|
220 |
return where_;
|
wneuper@1947
|
221 |
}
|
rgradisc@1311
|
222 |
|
wneuper@1947
|
223 |
public void setFind(CalcHeadItemList el) {
|
wneuper@1947
|
224 |
find_ = el;
|
wneuper@1947
|
225 |
}
|
rgradisc@1311
|
226 |
|
wneuper@1947
|
227 |
public void setGiven(CalcHeadItemList el) {
|
wneuper@1947
|
228 |
given_ = el;
|
wneuper@1947
|
229 |
}
|
rgradisc@1311
|
230 |
|
wneuper@1947
|
231 |
public void setRelate(CalcHeadItemList el) {
|
wneuper@1947
|
232 |
relate_ = el;
|
wneuper@1947
|
233 |
}
|
rgradisc@1311
|
234 |
|
wneuper@1947
|
235 |
public void setWhere(CalcHeadItemList el) {
|
wneuper@1947
|
236 |
where_ = el;
|
wneuper@1947
|
237 |
}
|
rgradisc@1615
|
238 |
|
wneuper@1947
|
239 |
public Specification getSpecification() {
|
wneuper@1947
|
240 |
return specification;
|
wneuper@1947
|
241 |
}
|
rgradisc@1311
|
242 |
|
wneuper@1947
|
243 |
public void setSpecification(Specification specification) {
|
wneuper@1947
|
244 |
this.specification = specification;
|
wneuper@1947
|
245 |
}
|
rgradisc@1615
|
246 |
|
wneuper@1947
|
247 |
public Position getPosition() {
|
wneuper@1947
|
248 |
return position;
|
wneuper@1947
|
249 |
}
|
rgradisc@1311
|
250 |
|
wneuper@1947
|
251 |
public void setPosition(Position position) {
|
wneuper@1947
|
252 |
this.position = position;
|
rgradisc@1623
|
253 |
}
|
wneuper@2245
|
254 |
|
wneuper@2059
|
255 |
//for XMLParserDigest
|
wneuper@2059
|
256 |
public void setResponse(Position position) {
|
wneuper@2059
|
257 |
this.position = position;
|
wneuper@2059
|
258 |
}
|
rgradisc@1311
|
259 |
|
wneuper@1947
|
260 |
public String getBelongsTo() {
|
wneuper@1947
|
261 |
return belongsTo;
|
wneuper@1947
|
262 |
}
|
wneuper@1947
|
263 |
|
wneuper@1947
|
264 |
public void setBelongsTo(String string) {
|
wneuper@1947
|
265 |
belongsTo = string;
|
wneuper@1947
|
266 |
}
|
wneuper@1947
|
267 |
|
wneuper@1947
|
268 |
public String getHead() {
|
wneuper@1947
|
269 |
return head;
|
wneuper@1947
|
270 |
}
|
wneuper@1947
|
271 |
|
wneuper@1978
|
272 |
/**
|
wneuper@1978
|
273 |
* set the headline in the CalcHead; this is in general e.g.
|
wneuper@1978
|
274 |
* 'Problem(Reals,[by_calculus,maximum])' or for algebrasystem-like problems
|
wneuper@1978
|
275 |
* e.g. 'solve(x+1=2,x)'
|
wneuper@1978
|
276 |
*/
|
wneuper@1947
|
277 |
public void setHead(String string) {
|
wneuper@1947
|
278 |
head = string;
|
wneuper@1947
|
279 |
}
|
wneuper@1947
|
280 |
|
wneuper@1947
|
281 |
public int getCalcTreeID() {
|
wneuper@1947
|
282 |
return calcTreeID;
|
wneuper@1947
|
283 |
}
|
wneuper@1947
|
284 |
|
wneuper@1947
|
285 |
public void setCalcTreeID(int id) {
|
wneuper@1947
|
286 |
calcTreeID = id;
|
wneuper@1947
|
287 |
}
|
wneuper@1947
|
288 |
|
wneuper@1947
|
289 |
public int getCalcHeadStatus() {
|
wneuper@1947
|
290 |
return calcHeadStatus;
|
wneuper@1947
|
291 |
}
|
wneuper@1947
|
292 |
|
wneuper@1947
|
293 |
/**
|
wneuper@1947
|
294 |
* distinguish between (1) the _overall_-status of a CalcHead and (2) e.g.
|
wneuper@2245
|
295 |
* the MODEL_ITEM_CORRECT for model items as defined above HERE (2) IS MEANT !
|
wneuper@1947
|
296 |
*
|
wneuper@1947
|
297 |
* @see <isac.util.formulae.CalcHead#setStatusString(String)>
|
wneuper@1947
|
298 |
*/
|
wneuper@1947
|
299 |
public void setCalcHeadStatus(int i) {
|
wneuper@1947
|
300 |
calcHeadStatus = i;
|
wneuper@1947
|
301 |
}
|
wneuper@1947
|
302 |
|
wneuper@1947
|
303 |
public void setCalcHeadStatus(String s) {//TOD0.WN041007 drop this NONSENSE
|
wneuper@1947
|
304 |
if (s.compareTo("correct") == 0) {
|
wneuper@2245
|
305 |
calcHeadStatus = (MODEL_ITEM_CORRECT);
|
wneuper@1947
|
306 |
} else if (s.compareTo("incorrect") == 0) {
|
wneuper@2245
|
307 |
calcHeadStatus = (MODEL_ITEM_INCORRECT);
|
wneuper@1947
|
308 |
}
|
wneuper@1947
|
309 |
}
|
wneuper@1947
|
310 |
|
wneuper@1947
|
311 |
public String getStatusString() {
|
wneuper@1947
|
312 |
return statusString;
|
wneuper@1947
|
313 |
}
|
wneuper@1947
|
314 |
|
wneuper@1947
|
315 |
/**
|
wneuper@1947
|
316 |
* distinguish between (1) the _overall_-status of a CalcHead and (2) e.g.
|
wneuper@2245
|
317 |
* the MODEL_ITEM_CORRECT for model items as defined above HERE (1) IS MEANT !
|
wneuper@1947
|
318 |
*
|
wneuper@1947
|
319 |
* @see <isac.util.formulae.CalcHead#setCalcHeadStatus(int)>
|
wneuper@1947
|
320 |
*/
|
wneuper@1978
|
321 |
public void setStatusString(String string) {//TOD0.WN041007 rename to
|
wneuper@1978
|
322 |
// setCalcHeadStatus
|
wneuper@1978
|
323 |
statusString = string; //TOD0.WN041007 calcHeadStatus = string;
|
wneuper@1947
|
324 |
setCalcHeadStatus(string);//TOD0.WN041007 drop this !!!
|
wneuper@1947
|
325 |
}
|
wneuper@1947
|
326 |
|
wneuper@1947
|
327 |
public boolean usesTheory(String thyID) {//TODO.WN040930 new type TheoryID
|
wneuper@1978
|
328 |
// ?
|
wneuper@1947
|
329 |
return this.specification.getTheory().equals(thyID);
|
wneuper@1947
|
330 |
}
|
wneuper@1947
|
331 |
|
wneuper@1947
|
332 |
public boolean usesSubTheoryOf(String thyID) {//TODO.WN040930 new type
|
wneuper@1978
|
333 |
// TheoryID ?
|
wneuper@1947
|
334 |
System.err.println("TODO CalcHead.usesSubTheoryOf(" + thyID + ")");
|
wneuper@1947
|
335 |
System.exit(999);
|
wneuper@1947
|
336 |
return false;
|
wneuper@1947
|
337 |
}
|
wneuper@1947
|
338 |
|
wneuper@1947
|
339 |
public boolean usesProblem(ProblemID pid) {
|
wneuper@1947
|
340 |
return this.specification.getProblem().equals(pid);
|
wneuper@1947
|
341 |
}
|
wneuper@1947
|
342 |
|
wneuper@1947
|
343 |
public boolean usesProblemClass(ProblemID pid) {
|
wneuper@1978
|
344 |
CalcHeadCompoundID p = this.specification.getProblem();
|
wneuper@1947
|
345 |
return ((ProblemID) this.specification.getProblem())
|
wneuper@1947
|
346 |
.belongsToClass(pid);
|
wneuper@1947
|
347 |
}
|
wneuper@1947
|
348 |
|
wneuper@1947
|
349 |
} |