rgradisc@859
|
1 |
/*
|
rgradisc@859
|
2 |
* Created on Sep 11, 2003
|
wneuper@1719
|
3 |
* @author rgradisc
|
rgradisc@859
|
4 |
*/
|
rgradisc@859
|
5 |
package isac.bridge;
|
rgradisc@859
|
6 |
|
wneuper@1976
|
7 |
import isac.util.CalcChanged;
|
rgradisc@1202
|
8 |
import isac.util.CalcChangedEvent;
|
wneuper@2391
|
9 |
import isac.util.NotInSpecificationPhaseException;
|
wneuper@2265
|
10 |
import isac.util.StartSolvingException;
|
wneuper@1875
|
11 |
import isac.util.formulae.CalcHead;
|
wneuper@2051
|
12 |
import isac.util.formulae.CalcFormula;
|
wneuper@2391
|
13 |
import isac.util.formulae.CalcHeadCompoundID;
|
wneuper@2002
|
14 |
import isac.util.formulae.Position;
|
rgradisc@1311
|
15 |
import isac.util.interfaces.ICalcIterator;
|
rgradisc@1311
|
16 |
import isac.util.interfaces.IToCalc;
|
rgradisc@1311
|
17 |
import isac.util.interfaces.IToUser;
|
rgradisc@1311
|
18 |
import isac.util.tactics.Tactic;
|
rgradisc@1191
|
19 |
import isac.wsdialog.DialogGuide;
|
rgradisc@864
|
20 |
|
rgradisc@962
|
21 |
import java.io.Serializable;
|
rgradisc@989
|
22 |
import java.rmi.RemoteException;
|
rgradisc@1202
|
23 |
import java.util.Iterator;
|
rgradisc@956
|
24 |
import java.util.Vector;
|
rgradisc@884
|
25 |
|
wneuper@1875
|
26 |
import org.apache.log4j.Logger;
|
wneuper@1875
|
27 |
|
rgradisc@859
|
28 |
/**
|
wneuper@1976
|
29 |
* A CalcTree represents a Calculation: It is a tree which consists of one
|
wneuper@2002
|
30 |
* CalcHead at the top and abitrarily many Formulas and SubCalculations (with
|
wneuper@2002
|
31 |
* separate CalcHeads). This is the main interface between the Bridge and the
|
wneuper@2002
|
32 |
* Dialog. The CalcTree calls methods of the Math Engine, which in turn are
|
wneuper@2002
|
33 |
* delegated to the BridgeRMI object on the other side of the RMI connection
|
wneuper@2002
|
34 |
* ??????WN0409. The communication with the SML Kernel is completly hided from
|
wneuper@2002
|
35 |
* the Dialog and the Frontend.
|
wneuper@1976
|
36 |
*
|
wneuper@1976
|
37 |
* @author Richard Gradischnegg
|
rgradisc@859
|
38 |
*/
|
akirchst@1728
|
39 |
|
rgradisc@956
|
40 |
public class CalcTree implements IToCalc, Serializable {
|
rgradisc@884
|
41 |
|
wneuper@1976
|
42 |
private int id_;
|
rgradisc@968
|
43 |
|
wneuper@1976
|
44 |
private Vector listeners_;
|
rgradisc@884
|
45 |
|
wneuper@1976
|
46 |
private MathEngine mathEngine_;
|
rgradisc@870
|
47 |
|
wneuper@1976
|
48 |
private ICalcIterator hot_spot_;//WN040924 ..delete: control hotSpot --> DG
|
rgradisc@870
|
49 |
|
wneuper@1976
|
50 |
private IBridgeRMI bridgeRMI_;//WN040924 added for completeCalcHead & Co.
|
rgradisc@870
|
51 |
|
wneuper@1976
|
52 |
static Logger logger_ = Logger.getLogger(CalcTree.class.getName());
|
rgradisc@870
|
53 |
|
wneuper@1976
|
54 |
/**
|
wneuper@1976
|
55 |
* Start a new calculation. In case of failure, the constructor may change
|
wneuper@1976
|
56 |
* the formalization object to hint at incomplete or contradictory
|
wneuper@1976
|
57 |
* specifications. <br>
|
wneuper@1976
|
58 |
* Only complete calcHeads should be passed. <br>
|
wneuper@1976
|
59 |
* Check every CalcHead for completeness (with the static method
|
wneuper@1976
|
60 |
* checkcalcHead() before constructing a CalcTree ..TODO WN040824 shift to
|
wneuper@1976
|
61 |
* authoring-tools
|
wneuper@1976
|
62 |
*
|
wneuper@1976
|
63 |
* @param identification
|
wneuper@1976
|
64 |
* for the CalcTree as delivered by the SML-kernel
|
wneuper@1976
|
65 |
*/
|
wneuper@1976
|
66 |
CalcTree(MathEngine me, int id) {
|
wneuper@1976
|
67 |
this.id_ = id;
|
wneuper@1976
|
68 |
this.mathEngine_ = me;
|
wneuper@1976
|
69 |
this.bridgeRMI_ = me.getBridgeRMI();//WN040924
|
wneuper@1976
|
70 |
listeners_ = new Vector();
|
wneuper@1976
|
71 |
}
|
wneuper@1875
|
72 |
|
wneuper@1976
|
73 |
/**
|
wneuper@1976
|
74 |
* Attach another dialog to the existing calculation tree.
|
wneuper@1976
|
75 |
*
|
wneuper@1976
|
76 |
* @param dlg
|
wneuper@1976
|
77 |
* The new Dialog to be attached to this CalcTree
|
wneuper@1976
|
78 |
*/
|
wneuper@1976
|
79 |
public void attach(DialogGuide dg) {
|
wneuper@1976
|
80 |
listeners_.add(dg);
|
wneuper@1976
|
81 |
}
|
wneuper@1875
|
82 |
|
wneuper@1976
|
83 |
/**
|
wneuper@1976
|
84 |
* Get a new iterator referencing the root element of the calculation tree.
|
wneuper@1976
|
85 |
* <p>
|
wneuper@1976
|
86 |
* The functionality for navigating the calculation is implemented in the
|
wneuper@1976
|
87 |
* CalcIterator object.
|
wneuper@1976
|
88 |
*
|
wneuper@1976
|
89 |
* @return new instance of CalcIterator
|
wneuper@1976
|
90 |
*/
|
wneuper@1976
|
91 |
public ICalcIterator iterator() {
|
wneuper@1976
|
92 |
return new CalcIterator(this);
|
wneuper@1976
|
93 |
}
|
wneuper@1875
|
94 |
|
wneuper@1976
|
95 |
/**
|
wneuper@1976
|
96 |
* Makes the passed formula the active formula, i.e. the formula the next
|
wneuper@1976
|
97 |
* tactic is applied to.
|
wneuper@1976
|
98 |
*
|
wneuper@1976
|
99 |
* @param newActiveFormula
|
wneuper@1976
|
100 |
*/
|
wneuper@2002
|
101 |
public void moveActiveFormula(ICalcIterator cit) {
|
wneuper@2002
|
102 |
try {
|
wneuper@2002
|
103 |
Position p = mathEngine_.moveActiveFormula(id_, cit.getPosition());
|
wneuper@2002
|
104 |
// if (p == null)//WN0412 message ?!
|
wneuper@2002
|
105 |
// return false;
|
wneuper@2002
|
106 |
// else
|
wneuper@2002
|
107 |
// return true;
|
wneuper@2002
|
108 |
} catch (RemoteException e) {
|
wneuper@2002
|
109 |
// TODO Auto-generated catch block
|
wneuper@2002
|
110 |
e.printStackTrace();
|
wneuper@2002
|
111 |
}
|
wneuper@1976
|
112 |
}
|
wneuper@1875
|
113 |
|
wneuper@1976
|
114 |
/**
|
wneuper@1976
|
115 |
* @see isac.util.interfaces.IToCalc#startSolving()
|
wneuper@1976
|
116 |
*/
|
wneuper@1976
|
117 |
public void startSolving() throws Exception {
|
wneuper@2265
|
118 |
Tactic tac = this.fetchProposedTactic();
|
wneuper@2265
|
119 |
if (tac.getName().compareTo("Apply_Method") == 0)
|
wneuper@2265
|
120 |
this.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
|
wneuper@2265
|
121 |
else
|
wneuper@2265
|
122 |
new StartSolvingException (tac);
|
wneuper@1976
|
123 |
}
|
wneuper@1875
|
124 |
|
wneuper@1976
|
125 |
/**
|
wneuper@1976
|
126 |
* @see isac.util.interfaces.IToCalc#modifyCalcHead(isac.util.formulae.CalcHead)
|
wneuper@1976
|
127 |
*/
|
wneuper@1976
|
128 |
public void modifyCalcHead(CalcHead calcHead) {
|
wneuper@2129
|
129 |
logger_.fatal(" DG->BR: modifyCalcHead(" + calcHead.toSMLString());
|
wneuper@1976
|
130 |
CalcHead newCalcHead = null;
|
wneuper@1976
|
131 |
try {
|
wneuper@1976
|
132 |
//WN040924 newCalcHead = bridgeRMI.modifyCalcHead(calcHead);
|
wneuper@1976
|
133 |
bridgeRMI_.modifyCalcHead(calcHead);
|
wneuper@1976
|
134 |
//WN040924 calcHead.fillValuesfrom(newCalcHead);
|
wneuper@1976
|
135 |
} catch (RemoteException e) {
|
wneuper@1976
|
136 |
e.printStackTrace();
|
wneuper@1976
|
137 |
}
|
wneuper@1976
|
138 |
}
|
rgradisc@870
|
139 |
|
wneuper@1976
|
140 |
/**
|
wneuper@1976
|
141 |
* @see isac.util.interfaces.IToCalc#completeCalcHead(isac.util.formulae.CalcHead)
|
wneuper@1976
|
142 |
*/
|
wneuper@1976
|
143 |
public void completeCalcHead() {
|
wneuper@2129
|
144 |
logger_.fatal(" DG->BR: completeCalcHead()");
|
wneuper@1976
|
145 |
try {
|
wneuper@1976
|
146 |
//WN040924 newCalcHead = bridgeRMI.completeCalcHead(calcHead);
|
wneuper@1976
|
147 |
bridgeRMI_.completeCalcHead(this.id_);
|
wneuper@1976
|
148 |
//WN040924 calcHead.fillValuesfrom(newCalcHead);
|
wneuper@1976
|
149 |
} catch (RemoteException e) {
|
wneuper@1976
|
150 |
e.printStackTrace();
|
wneuper@1976
|
151 |
}
|
wneuper@1976
|
152 |
}
|
rgradisc@870
|
153 |
|
wneuper@1976
|
154 |
/**
|
wneuper@1976
|
155 |
* @see isac.util.interfaces.IToCalc#completeCalcHead(isac.util.formulae.CalcHead,
|
wneuper@1976
|
156 |
* int)
|
wneuper@1976
|
157 |
* @param calcHead
|
wneuper@1976
|
158 |
* eventually updated by the user
|
wneuper@1976
|
159 |
* @param completeItem
|
wneuper@1976
|
160 |
* requested by the DialogGuide
|
wneuper@1976
|
161 |
*
|
wneuper@1976
|
162 |
* WN040924 copied from MathEngine
|
wneuper@2265
|
163 |
* WN050429
|
wneuper@1976
|
164 |
*/
|
wneuper@1976
|
165 |
public void completeCalcHead(CalcHead calcHead, int completeItem) {
|
wneuper@2265
|
166 |
// CalcHead newCalcHead;
|
wneuper@2265
|
167 |
// try {
|
wneuper@2265
|
168 |
// //WN040924 newCalcHead = bridgeRMI.completeCalcHead(calcHead,
|
wneuper@2265
|
169 |
// // completeItem);
|
wneuper@2265
|
170 |
// bridgeRMI_.completeCalcHead(this.id_, calcHead, completeItem);
|
wneuper@2265
|
171 |
// //WN040924 calcHead.fillValuesfrom(newCalcHead);
|
wneuper@2265
|
172 |
// //TODO: Remove the following line!!
|
wneuper@2265
|
173 |
// calcHead.setCalcHeadStatus(CalcHead.MODEL_ITEM_CORRECT);
|
wneuper@2265
|
174 |
//
|
wneuper@2265
|
175 |
// } catch (RemoteException e) {
|
wneuper@2265
|
176 |
// e.printStackTrace();
|
wneuper@2265
|
177 |
// }
|
wneuper@1976
|
178 |
}
|
rgradisc@870
|
179 |
|
wneuper@1976
|
180 |
/**
|
wneuper@2002
|
181 |
* Calculate the next n steps starting from the active formula. The Tactic
|
wneuper@2002
|
182 |
* to be applied in this step may be preset by setNextTactic
|
wneuper@1997
|
183 |
*
|
wneuper@1997
|
184 |
* @param scope
|
wneuper@1997
|
185 |
* The scope parameter can have following values:
|
wneuper@1997
|
186 |
* <ul>
|
wneuper@1997
|
187 |
* <li>Stay in the current subproblem
|
wneuper@1997
|
188 |
* <li>Stay in the current subcalculation (e.g. repetitions)
|
wneuper@1997
|
189 |
* <li>Stay in the current calculation as a whole.
|
wneuper@1997
|
190 |
* </ul>
|
wneuper@1997
|
191 |
* Constants for this scopes are found in the IToCalc class
|
wneuper@1997
|
192 |
* @param nSteps
|
wneuper@1997
|
193 |
* Specifies the count of steps to be autocalculated. Passing 0
|
wneuper@1997
|
194 |
* for nSteps will calculate until reaching a final result.
|
wneuper@1997
|
195 |
* @return The method returns an unique id to identify the request when
|
wneuper@1997
|
196 |
* notifying about updates in the tree.
|
wneuper@2265
|
197 |
*
|
wneuper@2265
|
198 |
* WN0504 see differences to this method completely done by RG !
|
wneuper@1997
|
199 |
*/
|
wneuper@1997
|
200 |
public int autoCalculate(int scope, int nSteps) {
|
wneuper@2129
|
201 |
logger_.fatal(" DG->BR: autoCalculate(" + scope + ", " + nSteps + ")");
|
wneuper@1997
|
202 |
CalcChanged cc;
|
wneuper@1997
|
203 |
int transactionID = -1;
|
wneuper@1997
|
204 |
try {
|
wneuper@1997
|
205 |
cc = mathEngine_.autoCalculate(this.id_, scope, nSteps);
|
wneuper@1997
|
206 |
if (!(cc == null)) {
|
wneuper@1997
|
207 |
hot_spot_ = new CalcIterator(this, cc.getLastGenerated());
|
wneuper@1997
|
208 |
transactionID = generateTransactionID();
|
wneuper@1997
|
209 |
informListeners(new CalcIterator(this, cc.getLastUnchanged()),
|
wneuper@1997
|
210 |
new CalcIterator(this, cc.getLastDeleted()),
|
wneuper@1997
|
211 |
new CalcIterator(this, cc.getLastGenerated()),
|
wneuper@1997
|
212 |
transactionID);
|
wneuper@1997
|
213 |
}
|
wneuper@1997
|
214 |
} catch (RemoteException e) {
|
wneuper@1997
|
215 |
e.printStackTrace();
|
wneuper@1997
|
216 |
}
|
wneuper@1997
|
217 |
return transactionID;
|
wneuper@1997
|
218 |
}
|
wneuper@1997
|
219 |
|
wneuper@1997
|
220 |
/**
|
wneuper@1976
|
221 |
* Tries to replaces the active formula in the calculation tree by the
|
wneuper@1976
|
222 |
* passed formula. This could fail if no valid derivation from the preceding
|
wneuper@1976
|
223 |
* formula to the (new) active formula can be found.
|
wneuper@1976
|
224 |
* <p>
|
wneuper@1976
|
225 |
* Parts of the calculation after the replaced formula are likely to become
|
wneuper@1976
|
226 |
* invalid, listeners will be informed of this with the update message,
|
wneuper@1976
|
227 |
* which contains the last unchanged formula.
|
wneuper@1976
|
228 |
*
|
wneuper@1976
|
229 |
* @param newFormula
|
wneuper@1976
|
230 |
* @return The method will return 0 on success or a nonzero value indicating
|
wneuper@1976
|
231 |
* the status otherwise.
|
wneuper@1976
|
232 |
*/
|
wneuper@2051
|
233 |
public int replaceFormula(CalcFormula f) throws RemoteException {
|
wneuper@2129
|
234 |
logger_.fatal(" DG->BR: replaceFormula(" + f.toSMLString() + ")");
|
wneuper@1997
|
235 |
CalcChanged cc;
|
wneuper@1997
|
236 |
int transactionID = -1;
|
wneuper@1997
|
237 |
try {
|
wneuper@1997
|
238 |
cc = mathEngine_.replaceFormula(this.id_, f);
|
wneuper@1997
|
239 |
if (!(cc == null)) {
|
wneuper@1997
|
240 |
hot_spot_ = new CalcIterator(this, cc.getLastGenerated());
|
wneuper@1997
|
241 |
transactionID = generateTransactionID();
|
wneuper@1997
|
242 |
informListeners(new CalcIterator(this, cc.getLastUnchanged()),
|
wneuper@1997
|
243 |
new CalcIterator(this, cc.getLastDeleted()),
|
wneuper@1997
|
244 |
new CalcIterator(this, cc.getLastGenerated()),
|
wneuper@1997
|
245 |
transactionID);
|
wneuper@1997
|
246 |
}
|
wneuper@1997
|
247 |
} catch (RemoteException e) {
|
wneuper@1997
|
248 |
e.printStackTrace();
|
wneuper@1997
|
249 |
}
|
wneuper@2003
|
250 |
return 0;
|
wneuper@1976
|
251 |
}
|
wneuper@2002
|
252 |
|
wneuper@1976
|
253 |
/**
|
wneuper@1976
|
254 |
* Tries to append the passed formula after the active formula. This could
|
wneuper@1976
|
255 |
* fail if no valid derivation from the preceding formula to the (new)
|
wneuper@1976
|
256 |
* active formula can be found. The method will fail as well if the active
|
wneuper@1976
|
257 |
* formula is not the last formula in the (sub)calculation. Parts of the
|
wneuper@1976
|
258 |
* calculation might become invalid.
|
wneuper@1976
|
259 |
*
|
wneuper@1976
|
260 |
* @param newFormula
|
wneuper@1976
|
261 |
* @return The method will return 0 on success or a nonzero value indicating
|
wneuper@1976
|
262 |
* the status otherwise.
|
wneuper@1976
|
263 |
*/
|
wneuper@2051
|
264 |
public int appendFormula(CalcFormula f) throws RemoteException {
|
wneuper@2129
|
265 |
logger_.fatal(" DG->BR: appendFormula(" + f.toSMLString() + ")");
|
wneuper@2003
|
266 |
CalcChanged cc;
|
wneuper@2003
|
267 |
int transactionID = -1;
|
wneuper@2003
|
268 |
try {
|
wneuper@2003
|
269 |
cc = mathEngine_.appendFormula(this.id_, f);
|
wneuper@2003
|
270 |
if (!(cc == null)) {
|
wneuper@2003
|
271 |
hot_spot_ = new CalcIterator(this, cc.getLastGenerated());
|
wneuper@2003
|
272 |
transactionID = generateTransactionID();
|
wneuper@2003
|
273 |
informListeners(new CalcIterator(this, cc.getLastUnchanged()),
|
wneuper@2003
|
274 |
new CalcIterator(this, cc.getLastDeleted()),
|
wneuper@2003
|
275 |
new CalcIterator(this, cc.getLastGenerated()),
|
wneuper@2003
|
276 |
transactionID);
|
wneuper@2003
|
277 |
}
|
wneuper@2003
|
278 |
} catch (RemoteException e) {
|
wneuper@2003
|
279 |
e.printStackTrace();
|
wneuper@2003
|
280 |
}
|
wneuper@1976
|
281 |
return 0;
|
wneuper@1976
|
282 |
}
|
rgradisc@894
|
283 |
|
wneuper@2265
|
284 |
/**
|
wneuper@2082
|
285 |
* @see isac.util.interfaces.IToCalc#intermediateSteps()
|
wneuper@2082
|
286 |
*/
|
wneuper@2082
|
287 |
public int intermediateSteps(ICalcIterator ci) throws RemoteException {
|
wneuper@2129
|
288 |
logger_.fatal(" DG->BR: intermediateSteps(" + ci.toSMLString() + ")");
|
wneuper@2082
|
289 |
CalcChanged cc;
|
wneuper@2082
|
290 |
int transactionID = -1;
|
wneuper@2082
|
291 |
try {
|
wneuper@2082
|
292 |
cc = mathEngine_.intermediateSteps(this.id_, ci);
|
wneuper@2082
|
293 |
if (!(cc == null)) {
|
wneuper@2082
|
294 |
transactionID = generateTransactionID();
|
wneuper@2082
|
295 |
informListeners(new CalcIterator(this, cc.getLastUnchanged()),
|
wneuper@2082
|
296 |
new CalcIterator(this, cc.getLastDeleted()),
|
wneuper@2082
|
297 |
new CalcIterator(this, cc.getLastGenerated()),
|
wneuper@2082
|
298 |
transactionID);
|
wneuper@2082
|
299 |
}
|
wneuper@2082
|
300 |
} catch (RemoteException e) {
|
wneuper@2082
|
301 |
e.printStackTrace();
|
wneuper@2082
|
302 |
}
|
wneuper@2082
|
303 |
return 0;
|
wneuper@2082
|
304 |
}
|
wneuper@2082
|
305 |
|
wneuper@1976
|
306 |
/**
|
wneuper@1976
|
307 |
* Set a tactic for usage by autocalculate.
|
wneuper@1976
|
308 |
*
|
wneuper@1976
|
309 |
* @param tactic
|
wneuper@1976
|
310 |
* the Tactic to be used in the the next step
|
wneuper@1976
|
311 |
* @return The return value indicates success, failure or probable success
|
wneuper@1976
|
312 |
* at a later time.
|
wneuper@1976
|
313 |
*/
|
wneuper@1976
|
314 |
public int setNextTactic(Tactic tactic) {
|
wneuper@2129
|
315 |
logger_.fatal(" DG->BR: setNextTactic(" + tactic.toSMLString() + ")");
|
wneuper@1976
|
316 |
int result = -1;
|
wneuper@1976
|
317 |
try {
|
wneuper@1976
|
318 |
result = mathEngine_.setNextTactic(this.id_, tactic);
|
wneuper@1976
|
319 |
if (result == 0) {
|
wneuper@1976
|
320 |
hot_spot_.moveDown(); // move to the new formula/calcHead
|
wneuper@2002
|
321 |
// FIXXXME
|
wneuper@1976
|
322 |
informListeners((ICalcIterator) hot_spot_.clone(),
|
wneuper@1976
|
323 |
// FIXXXME: nothing changed, but if outcommented: subpbl shows
|
wneuper@2002
|
324 |
// Add_Given etc. ... discuss with LK !
|
wneuper@1976
|
325 |
(ICalcIterator) hot_spot_.clone(),
|
wneuper@1976
|
326 |
(ICalcIterator) hot_spot_.clone(),
|
wneuper@1976
|
327 |
generateTransactionID());
|
wneuper@1976
|
328 |
}
|
wneuper@1976
|
329 |
} catch (RemoteException e) {
|
wneuper@1976
|
330 |
// TODO Auto-generated catch block
|
wneuper@1976
|
331 |
e.printStackTrace();
|
wneuper@1976
|
332 |
}
|
wneuper@1976
|
333 |
return -1;
|
wneuper@1976
|
334 |
}
|
wneuper@2265
|
335 |
|
wneuper@2062
|
336 |
// public int setNextTactic(Tactic tactic) {
|
wneuper@2265
|
337 |
// logger_.fatal(" DG->BR: setNextTactic(" + tactic.toSMLString() + ")");
|
wneuper@2062
|
338 |
// int result = -1;
|
wneuper@2062
|
339 |
// ICalcIterator it;
|
wneuper@2062
|
340 |
// try {
|
wneuper@2062
|
341 |
// result = mathEngine_.setNextTactic(this.id_, tactic);
|
wneuper@2062
|
342 |
// //^^^^ should be CalcChanged !
|
wneuper@2062
|
343 |
// if (result == 0) {
|
wneuper@2062
|
344 |
// //hack before @@@ autoCalculate --->
|
wneuper@2062
|
345 |
// // isac.wsdialog.DialogGuide#notifyUserAction
|
wneuper@2062
|
346 |
// //works only if nothing is deleted by use in <Next Step>
|
wneuper@2062
|
347 |
// it = (ICalcIterator) hot_spot_.clone();
|
wneuper@2062
|
348 |
// hot_spot_.moveDown();
|
wneuper@2062
|
349 |
// informListeners((ICalcIterator) it, it,//thus deleted nodes
|
wneuper@2062
|
350 |
// // are not reported !!!
|
wneuper@2062
|
351 |
// (ICalcIterator) hot_spot_.clone(),
|
wneuper@2062
|
352 |
// generateTransactionID());
|
wneuper@2062
|
353 |
// }
|
wneuper@2062
|
354 |
// } catch (RemoteException e) {
|
wneuper@2062
|
355 |
// // TODO Auto-generated catch block
|
wneuper@2062
|
356 |
// e.printStackTrace();
|
wneuper@2062
|
357 |
// }
|
wneuper@2062
|
358 |
// return -1;
|
wneuper@2062
|
359 |
// }
|
wneuper@2062
|
360 |
|
wneuper@1976
|
361 |
/**
|
wneuper@1976
|
362 |
* Retrieve the tactic proposed by the SML-Kernel for the next step in the
|
wneuper@1976
|
363 |
* calculation.
|
wneuper@1976
|
364 |
*
|
wneuper@1976
|
365 |
* @return proposed tactic. Can be null, if the kernel does not know what to
|
wneuper@1976
|
366 |
* do next, or if the end of the calculation is reached
|
wneuper@1976
|
367 |
*/
|
wneuper@1976
|
368 |
public Tactic fetchProposedTactic() {
|
wneuper@2129
|
369 |
logger_.fatal(" DG->BR: fetchProposedTactic()");
|
wneuper@1976
|
370 |
try {
|
wneuper@2009
|
371 |
Tactic tac = mathEngine_.fetchProposedTactic(this.id_);
|
wneuper@2129
|
372 |
logger_.fatal(" DG<-BR: fetchProposedTactic <- "
|
wneuper@2062
|
373 |
+ tac.toSMLString());
|
wneuper@2009
|
374 |
return tac;
|
wneuper@1976
|
375 |
} catch (RemoteException e) {
|
wneuper@1976
|
376 |
// TODO Auto-generated catch block
|
wneuper@1976
|
377 |
e.printStackTrace();
|
wneuper@1976
|
378 |
}
|
wneuper@2129
|
379 |
logger_.fatal(" DG<-BR: fetchProposedTactic <- NULL helpless");
|
wneuper@1976
|
380 |
return null;
|
wneuper@1976
|
381 |
}
|
rgradisc@1107
|
382 |
|
wneuper@2265
|
383 |
// /**
|
wneuper@2265
|
384 |
// * Get a list of tactics applicable to the active formula.
|
wneuper@2265
|
385 |
// *
|
wneuper@2265
|
386 |
// * @param scope
|
wneuper@2265
|
387 |
// * The filter parameter selects the scope of search for
|
wneuper@2265
|
388 |
// * applicable tactics: all tactics / all tactics from the current
|
wneuper@2265
|
389 |
// * theory / all tactics from the (calculation) method being
|
wneuper@2265
|
390 |
// * applied.
|
wneuper@2265
|
391 |
// * @return Array with applyable tactics
|
wneuper@2265
|
392 |
// */
|
wneuper@2265
|
393 |
// public Tactic[] fetchApplicableTactics(int scope) {
|
wneuper@2265
|
394 |
// logger_.fatal(" DG->BR: fetchApplicableTactics(" + scope + ")");
|
wneuper@2265
|
395 |
// Tactic[] result = null;
|
wneuper@2265
|
396 |
// // try {
|
wneuper@2265
|
397 |
// // result = mathEngine_.fetchAppliableTactics(this.id_, scope);
|
wneuper@2265
|
398 |
// // } catch (RemoteException e) {
|
wneuper@2265
|
399 |
// // // TODO Auto-generated catch block
|
wneuper@2265
|
400 |
// // e.printStackTrace();
|
wneuper@2265
|
401 |
// // }
|
wneuper@2265
|
402 |
// return result;
|
wneuper@2265
|
403 |
// }
|
rgradisc@1107
|
404 |
|
wneuper@1976
|
405 |
/**
|
wneuper@1976
|
406 |
* Add a Listener to this CalcTree. Listeners will be informed about any
|
wneuper@1976
|
407 |
* changes in the CalcTree.
|
wneuper@1976
|
408 |
*
|
wneuper@1976
|
409 |
* @param listener
|
wneuper@1976
|
410 |
* the new Listener, has to implement the interface IToUser
|
wneuper@1976
|
411 |
* @return true, if the listener has been added successfully
|
wneuper@1976
|
412 |
*/
|
wneuper@1976
|
413 |
public boolean addDataChangeListener(IToUser listener) {
|
wneuper@2129
|
414 |
logger_.fatal(" DG->BR: addDataChangeListener(" + listener + ")");
|
wneuper@1976
|
415 |
if (listeners_.contains(listener)) {
|
wneuper@1976
|
416 |
return false;
|
wneuper@1976
|
417 |
} else {
|
wneuper@1976
|
418 |
listeners_.add(listener);
|
wneuper@1976
|
419 |
}
|
wneuper@1976
|
420 |
return true;
|
wneuper@1976
|
421 |
}
|
wneuper@1875
|
422 |
|
wneuper@1976
|
423 |
/**
|
wneuper@1976
|
424 |
* Retrieve the active formula in a CalcTree. This is the formula form where
|
wneuper@1976
|
425 |
* the calculation will continue.
|
wneuper@1976
|
426 |
*
|
wneuper@1976
|
427 |
* @return Iterator that marks the currently active formula
|
wneuper@1976
|
428 |
*/
|
wneuper@1976
|
429 |
public ICalcIterator getActiveFormula() {
|
wneuper@2265
|
430 |
logger_.fatal(" DG<>BR: getActiveFormula <- "
|
wneuper@2265
|
431 |
+ hot_spot_.toSMLString());
|
wneuper@1976
|
432 |
return (ICalcIterator) hot_spot_.clone();
|
wneuper@1976
|
433 |
}
|
wneuper@1976
|
434 |
|
wneuper@1976
|
435 |
/**
|
wneuper@1976
|
436 |
* Destruct this CalcTree: the sml-Representation of the CalcTree is
|
wneuper@1976
|
437 |
* disposed, the id can be used for a new CalcTree
|
wneuper@1976
|
438 |
*
|
wneuper@1976
|
439 |
* @return boolean value: success of operation (complete/failed) TODO
|
wneuper@1976
|
440 |
* WN040824 call mathEngine.destruct when WS is closed TODO WN040824
|
wneuper@1976
|
441 |
* call mathEngine.destruct when session is closed
|
wneuper@1976
|
442 |
*/
|
wneuper@1976
|
443 |
public boolean destruct() {
|
wneuper@1976
|
444 |
try {
|
wneuper@1976
|
445 |
return mathEngine_.destruct(this.id_);
|
wneuper@1976
|
446 |
} catch (RemoteException e) {
|
wneuper@1976
|
447 |
// TODO Auto-generated catch block
|
wneuper@1976
|
448 |
e.printStackTrace();
|
wneuper@1976
|
449 |
}
|
wneuper@1976
|
450 |
return false;
|
wneuper@1976
|
451 |
}
|
wneuper@1976
|
452 |
|
wneuper@1976
|
453 |
// send an update event to the registered listeners
|
wneuper@1976
|
454 |
private void informListeners(ICalcIterator lastUnchangedFormula,
|
wneuper@1976
|
455 |
ICalcIterator lastDeletedFormula,
|
wneuper@2002
|
456 |
ICalcIterator lastGeneratedFormula, int transactionID)
|
wneuper@2002
|
457 |
throws RemoteException {
|
wneuper@2009
|
458 |
logger_.fatal(" . . <-BR: informListeners (unc="
|
wneuper@1980
|
459 |
+ lastUnchangedFormula.toSMLString() + ", del="
|
wneuper@1980
|
460 |
+ lastDeletedFormula.toSMLString() + ", gen="
|
wneuper@1980
|
461 |
+ lastGeneratedFormula.toSMLString());
|
wneuper@1976
|
462 |
Iterator listn_it = listeners_.iterator();
|
wneuper@1980
|
463 |
//DialogGuide dg;
|
wneuper@1980
|
464 |
IToUser dg;
|
wneuper@1976
|
465 |
CalcChangedEvent e = new CalcChangedEvent(transactionID, true, // completed
|
wneuper@1976
|
466 |
lastUnchangedFormula, lastDeletedFormula, lastGeneratedFormula);
|
wneuper@1976
|
467 |
while (listn_it.hasNext()) {
|
wneuper@1980
|
468 |
dg = (IToUser) listn_it.next();
|
wneuper@1976
|
469 |
dg.calcChanged(e);
|
wneuper@1976
|
470 |
}
|
wneuper@1976
|
471 |
}
|
wneuper@1976
|
472 |
|
wneuper@1976
|
473 |
MathEngine getMathEngine() {
|
wneuper@1976
|
474 |
return mathEngine_;
|
wneuper@1976
|
475 |
}
|
wneuper@1976
|
476 |
|
wneuper@1976
|
477 |
public int getId() {
|
wneuper@1976
|
478 |
return id_;
|
wneuper@1976
|
479 |
}
|
wneuper@1976
|
480 |
|
wneuper@1976
|
481 |
// Special iterator hotSpot: marks the currently active formula of
|
wneuper@1976
|
482 |
// the calcTree
|
wneuper@1976
|
483 |
void setHotSpot(ICalcIterator iterator) {
|
wneuper@1976
|
484 |
hot_spot_ = iterator;
|
wneuper@1976
|
485 |
}
|
wneuper@1976
|
486 |
|
wneuper@1976
|
487 |
//WN0411 reminiscence to Dinopolis, drop it !?
|
wneuper@2062
|
488 |
//WN0501 ... _NO_: ... = return-value of autoCalculate,etc. =
|
wneuper@2062
|
489 |
// = CalcChangedEvent.transaction_id_
|
wneuper@1976
|
490 |
private int generateTransactionID() {
|
wneuper@1976
|
491 |
return (int) (Math.random() * 0xFFFF);
|
wneuper@1976
|
492 |
}
|
wneuper@1976
|
493 |
|
wneuper@2062
|
494 |
/*
|
wneuper@2062
|
495 |
* (non-Javadoc)
|
wneuper@2062
|
496 |
*
|
wneuper@2062
|
497 |
* @see isac.util.interfaces.IToCalc#getElementsFromTo(isac.util.interfaces.ICalcIterator,
|
wneuper@2062
|
498 |
* isac.util.interfaces.ICalcIterator, java.lang.Integer, boolean)
|
wneuper@2062
|
499 |
*/
|
wneuper@2062
|
500 |
public Vector getElementsFromTo(ICalcIterator iterator_from,
|
wneuper@2062
|
501 |
ICalcIterator iterator_to, Integer level,
|
wneuper@2062
|
502 |
boolean result_includes_tactics) throws RemoteException {
|
wneuper@2129
|
503 |
logger_.fatal(" DG->BR: getElementsFromTo("
|
wneuper@2062
|
504 |
+ iterator_from.toSMLString() + ", "
|
wneuper@2062
|
505 |
+ iterator_to.toSMLString() + level + ")");
|
wneuper@2065
|
506 |
try {
|
wneuper@2065
|
507 |
return mathEngine_.getElementsFromTo(this.id_, iterator_from,
|
wneuper@2265
|
508 |
iterator_to, level, result_includes_tactics);
|
wneuper@2265
|
509 |
} catch (RemoteException e) {
|
wneuper@2265
|
510 |
e.printStackTrace();
|
wneuper@2265
|
511 |
}
|
wneuper@2265
|
512 |
return null;
|
wneuper@2062
|
513 |
}
|
wneuper@2062
|
514 |
|
wneuper@2391
|
515 |
/**
|
wneuper@2391
|
516 |
* @see isac.util.interfaces.IToCalc#tryMatch(CalcHead, CalcHeadCompoundID)
|
wneuper@2391
|
517 |
* FIXXXME.WN050610 change to: tryMatch( CalcHeadCompoundID)
|
wneuper@2391
|
518 |
*/
|
wneuper@2391
|
519 |
public void tryMatch(CalcHead calcHead, CalcHeadCompoundID problemID)
|
wneuper@2391
|
520 |
throws NotInSpecificationPhaseException {
|
wneuper@2391
|
521 |
CalcHead newCalcHead = null;
|
wneuper@2391
|
522 |
try {
|
wneuper@2391
|
523 |
//WN040924 newCalcHead =
|
wneuper@2391
|
524 |
// bridgeRMI.tryMatch(calcHead.getCalcTreeID(), problemID);
|
wneuper@2391
|
525 |
bridgeRMI_.tryMatch(calcHead.getCalcTreeID(), problemID);
|
wneuper@2391
|
526 |
if (newCalcHead == null) {
|
wneuper@2391
|
527 |
throw new NotInSpecificationPhaseException();
|
wneuper@2391
|
528 |
}
|
wneuper@2391
|
529 |
calcHead.fillValuesfrom(newCalcHead);
|
wneuper@2391
|
530 |
} catch (RemoteException e) {
|
wneuper@2391
|
531 |
// TODO Auto-generated catch block
|
wneuper@2391
|
532 |
e.printStackTrace();
|
wneuper@2391
|
533 |
}
|
wneuper@2391
|
534 |
}
|
wneuper@2391
|
535 |
|
wneuper@2391
|
536 |
/**
|
wneuper@2391
|
537 |
* Refine a given problem for this CalcTree
|
wneuper@2391
|
538 |
*
|
wneuper@2391
|
539 |
* @param problemID
|
wneuper@2391
|
540 |
* @return CalcHead, if the operation was successful, else null
|
wneuper@2391
|
541 |
*/
|
wneuper@2391
|
542 |
public void tryRefine(CalcHead calcHead, CalcHeadCompoundID problemID)
|
wneuper@2391
|
543 |
throws NotInSpecificationPhaseException {
|
wneuper@2391
|
544 |
CalcHead newCalcHead = null;
|
wneuper@2391
|
545 |
try {
|
wneuper@2391
|
546 |
//WN040924 newCalcHead =
|
wneuper@2391
|
547 |
// bridgeRMI.tryRefine(calcHead.getCalcTreeID(), problemID);
|
wneuper@2391
|
548 |
bridgeRMI_.tryRefine(calcHead.getCalcTreeID(), problemID);
|
wneuper@2391
|
549 |
if (newCalcHead == null) {
|
wneuper@2391
|
550 |
throw new NotInSpecificationPhaseException();
|
wneuper@2391
|
551 |
}
|
wneuper@2391
|
552 |
calcHead.fillValuesfrom(newCalcHead);
|
wneuper@2391
|
553 |
} catch (RemoteException e) {
|
wneuper@2391
|
554 |
// TODO Auto-generated catch block
|
wneuper@2391
|
555 |
e.printStackTrace();
|
wneuper@2391
|
556 |
}
|
wneuper@2391
|
557 |
}
|
wneuper@2391
|
558 |
|
wneuper@1976
|
559 |
} |