2 * Created on Sep 11, 2003
4 package isac.util.formulae;
7 * Every calculation has a CalcHead, which consists of Model and Specification
8 * of the calculation. The CalcHead is empty at the beginning of the
9 * Specifying-phase and has to be filled before one can start the solving phase.
11 * @author Alan Krempler
13 public class CalcHead extends CalcElement {
16 * Labels a model item as "correct" TODO rename CALCHEAD_* to MODEL_ITEM_*
18 public static final int MODEL_ITEM_CORRECT = 1;
21 * Labels a model item as "incorrect"
23 public static final int MODEL_ITEM_INCORRECT = 2;
26 * Labels a model item as "syntax error"
28 public static final int MODEL_ITEM_SYNTAXERROR = 3;
31 * Labels a model item as "incomplete"
33 public static final int MODEL_ITEM_INCOMPLETE = 4;
36 * Labels a model item as "false"
38 public static final int MODEL_ITEM_FALSE = 5;
41 * Labels a model item as to be filled in by the KI
43 public static final int MODEL_ITEM_HELP_ME = 6;
46 * Labels a model item as superfluous
48 public static final int MODEL_ITEM_SUPERFLUOUS = 7;
51 * Labels a model item as missing
53 public static final int MODEL_ITEM_MISSING = 8;
56 * show all details of a CalcHead in the CalcHeadPanel
58 * @deprecated in favour of ICalcElement#VIEWSTYLE_DEFAULT FIXME.WN0504
60 public static final int VIEWSTYLE_FULL = 2;
63 * skip to show the CalcHead in the CalcHeadPanel, rather only show the
64 * HeadLine of the CalcHead on the Worksheet
66 * @deprecated in favour of ICalcElement#DISPLAY_HIDDEN FIXME.WN0504
68 public static final int VIEWSTYLE_SINGLELINE = 4;
71 * @deprecated WN050415 no description available
73 //public static final int VIEWSTYLE_IN_CALC = 5;
75 * @deprecated WN050415 no description available
77 //public static final int VIEWSTYLE_SIMPLE_SOLVE = 10;
78 // TODO: remove testing constant
79 private int calcTreeID = -4711;
81 private CalcHeadItemList given_, where_, find_, relate_;
83 private Specification specification;
85 private Position position;
87 private String belongsTo;
89 private String head;//TODO.WN050420 should be type Formula
91 private int calcHeadStatus;//TODO.WN041007 confusion with statusString
93 private String statusString;//TODO.WN041007 confusion with calcHeadStatus
95 // drop THIS one and setStatusString
98 * Format the object in a way that the bridge can handle it FIXME.WN041008
99 * this is Formalization.toSMLString, _NOT_ CalcHead.toSMLString !!!
101 * @return SML representation
103 public String toSMLString() {
104 //this should go to Formalization???WN050420 dont understand
105 StringBuffer sb = new StringBuffer();
107 if (getGiven() != null) {
108 sb.append(getGiven().toSMLString());
110 if (getWhere() != null) {
112 sb.append(getWhere().toSMLString());
114 if (getFind() != null) {
116 sb.append(getFind().toSMLString());
118 if (getRelate() != null) {
120 sb.append(getRelate().toSMLString());
123 if (getSpecification() != null) {
124 sb.append(specification.toSMLString());
127 return sb.toString();
131 * Special string format of the calcHead used by modifyCalcHead
134 * @return String used by modifyCalcHead
136 public String toModifyCalcHeadString() {
137 StringBuffer sb = new StringBuffer();
139 belongsTo = "Pbl";//TODO.WN041007 this is too restrictive: + Met !!
141 if (position == null) {
142 position = new Position();
143 position.setKind("Pbl");
145 sb.append(position.toSMLString());
148 sb.append("\",[Given [");
149 sb.append(given_.toSMLString());
150 sb.append("],Find [");
151 sb.append(find_.toSMLString());
152 sb.append("],Relate [");
153 sb.append(relate_.toSMLString());
154 sb.append("]]," + belongsTo + ",(");
155 sb.append(specification.toSMLString());
158 } catch (Exception e) {
159 System.out.println("Some Items of Calchead are null!");
161 return sb.toString();
165 * Copies values form one CalcHead object to another. This is needed,
166 * because the backend produces a new calcHead after each update, but the
167 * dialog holds only one instance of CalcHead all the time.
170 * the other calcHead object
172 public void fillValuesfrom(CalcHead other) {
173 this.belongsTo = other.belongsTo;
174 this.calcHeadStatus = other.calcHeadStatus;
175 this.calcTreeID = other.calcTreeID;
176 this.find_ = other.find_;
177 this.given_ = other.given_;
178 this.head = other.head;
179 this.position = other.position;
180 this.relate_ = other.relate_;
181 this.specification = other.specification;
182 this.where_ = other.where_;
183 this.visibility_ = other.visibility_;
184 this.view_style_ = other.view_style_;
185 this.rating_ = other.rating_;
191 * @see isac.util.CalcElement#getMathML()
193 public String getMathML() {
194 // TODO Auto-generated method stub
201 * @see isac.util.CalcElement#getType()
203 public int getType() {
204 return CALCEL_CALCHEAD;
207 public CalcHeadItemList getFind() {
211 public CalcHeadItemList getGiven() {
215 public CalcHeadItemList getRelate() {
219 public CalcHeadItemList getWhere() {
223 public void setFind(CalcHeadItemList el) {
227 public void setGiven(CalcHeadItemList el) {
231 public void setRelate(CalcHeadItemList el) {
235 public void setWhere(CalcHeadItemList el) {
239 public Specification getSpecification() {
240 return specification;
243 public void setSpecification(Specification specification) {
244 this.specification = specification;
247 public Position getPosition() {
251 public void setPosition(Position position) {
252 this.position = position;
255 //for XMLParserDigest
256 public void setResponse(Position position) {
257 this.position = position;
260 public String getBelongsTo() {
264 public void setBelongsTo(String string) {
268 public String getHead() {
273 * set the headline in the CalcHead; this is in general e.g.
274 * 'Problem(Reals,[by_calculus,maximum])' or for algebrasystem-like problems
275 * e.g. 'solve(x+1=2,x)'
277 public void setHead(String string) {
281 public int getCalcTreeID() {
285 public void setCalcTreeID(int id) {
289 public int getCalcHeadStatus() {
290 return calcHeadStatus;
294 * distinguish between (1) the _overall_-status of a CalcHead and (2) e.g.
295 * the MODEL_ITEM_CORRECT for model items as defined above HERE (2) IS MEANT !
297 * @see <isac.util.formulae.CalcHead#setStatusString(String)>
299 public void setCalcHeadStatus(int i) {
303 public void setCalcHeadStatus(String s) {//TOD0.WN041007 drop this NONSENSE
304 if (s.compareTo("correct") == 0) {
305 calcHeadStatus = (MODEL_ITEM_CORRECT);
306 } else if (s.compareTo("incorrect") == 0) {
307 calcHeadStatus = (MODEL_ITEM_INCORRECT);
311 public String getStatusString() {
316 * distinguish between (1) the _overall_-status of a CalcHead and (2) e.g.
317 * the MODEL_ITEM_CORRECT for model items as defined above HERE (1) IS MEANT !
319 * @see <isac.util.formulae.CalcHead#setCalcHeadStatus(int)>
321 public void setStatusString(String string) {//TOD0.WN041007 rename to
323 statusString = string; //TOD0.WN041007 calcHeadStatus = string;
324 setCalcHeadStatus(string);//TOD0.WN041007 drop this !!!
327 public boolean usesTheory(String thyID) {//TODO.WN040930 new type TheoryID
329 return this.specification.getTheory().equals(thyID);
332 public boolean usesSubTheoryOf(String thyID) {//TODO.WN040930 new type
334 System.err.println("TODO CalcHead.usesSubTheoryOf(" + thyID + ")");
339 public boolean usesProblem(ProblemID pid) {
340 return this.specification.getProblem().equals(pid);
343 public boolean usesProblemClass(ProblemID pid) {
344 CalcHeadCompoundID p = this.specification.getProblem();
345 return ((ProblemID) this.specification.getProblem())
346 .belongsToClass(pid);