akremp@861
|
1 |
package isac.wsdialog;
|
akremp@861
|
2 |
|
mhochrei@1163
|
3 |
import isac.bridge.*;
|
akirchst@2133
|
4 |
import isac.session.SDialog;
|
mhochrei@1163
|
5 |
import isac.util.*;
|
rgradisc@1313
|
6 |
import isac.util.formulae.*;
|
rgradisc@1313
|
7 |
import isac.util.interfaces.*;
|
rgradisc@1313
|
8 |
import isac.util.tactics.*;
|
wneuper@2129
|
9 |
import isac.util.usersettings.UserSettings;
|
mhochrei@939
|
10 |
|
akremp@945
|
11 |
import java.io.Serializable;
|
mhochrei@954
|
12 |
import java.net.MalformedURLException;
|
mhochrei@1163
|
13 |
import java.rmi.*;
|
mhochrei@954
|
14 |
import java.rmi.registry.LocateRegistry;
|
mhochrei@952
|
15 |
import java.rmi.server.UnicastRemoteObject;
|
akremp@1022
|
16 |
import java.util.Vector;
|
akremp@867
|
17 |
|
wneuper@1978
|
18 |
import org.apache.log4j.Logger;
|
wneuper@1978
|
19 |
|
akremp@861
|
20 |
/**
|
wneuper@1815
|
21 |
* The DialogGuide moderates the communication between two instances working on
|
wneuper@1815
|
22 |
* the same CalcTree object. One of these instances is the user, the other a
|
wneuper@1815
|
23 |
* math engine. Most probably, the user's GUI, the DialogGuide and the math
|
wneuper@1815
|
24 |
* engine reside on different machines and communicate with each other by means
|
wneuper@1815
|
25 |
* of RMI.
|
akremp@1340
|
26 |
*
|
akremp@945
|
27 |
* @author Alan Krempler
|
akremp@867
|
28 |
*/
|
wneuper@1815
|
29 |
public class DialogGuide extends UnicastRemoteObject implements DGuide,
|
wneuper@1815
|
30 |
IToUser, Serializable {
|
rgradisc@1586
|
31 |
|
wneuper@1978
|
32 |
static Logger logger_ = Logger.getLogger(BridgeRMI.class.getName());
|
wneuper@1978
|
33 |
|
wneuper@1815
|
34 |
protected CalcTree calc_tree_;
|
wneuper@2082
|
35 |
|
akirchst@1881
|
36 |
//protected CalcHead calc_head_;
|
rgradisc@1618
|
37 |
|
wneuper@1815
|
38 |
protected CalcHead calc_head_sub_;
|
mhochrei@974
|
39 |
|
wneuper@1815
|
40 |
protected MathEngine math_engine_;
|
rgradisc@1618
|
41 |
|
wneuper@1815
|
42 |
protected int phase_;
|
akremp@861
|
43 |
|
akirchst@1881
|
44 |
private Vector datachange_listeners_;
|
akremp@1597
|
45 |
|
wneuper@1815
|
46 |
private IToWorksheet ui_control_listener_;
|
wneuper@2132
|
47 |
|
wneuper@2129
|
48 |
protected UserSettings user_settings_;
|
rgradisc@1618
|
49 |
|
akirchst@2133
|
50 |
protected SDialog session_dialog_;
|
akirchst@2133
|
51 |
|
akirchst@2133
|
52 |
protected String session_id_;
|
akirchst@2133
|
53 |
|
wneuper@1815
|
54 |
/**
|
wneuper@1815
|
55 |
* @param ME_path
|
wneuper@1815
|
56 |
* URL of the math engine to be used
|
wneuper@1815
|
57 |
* @throws RemoteException
|
wneuper@1815
|
58 |
*/
|
akirchst@2133
|
59 |
public DialogGuide(String ME_path, SDialog session_dialog, String session_id) throws RemoteException {
|
wneuper@1815
|
60 |
super();
|
wneuper@1815
|
61 |
this.rmiBind();
|
wneuper@1815
|
62 |
datachange_listeners_ = new Vector();
|
wneuper@1815
|
63 |
MathEngine.init(ME_path);
|
wneuper@1815
|
64 |
math_engine_ = MathEngine.getMathEngine();
|
wneuper@1815
|
65 |
phase_ = DIALOGPHASE_IDLE;
|
akirchst@2133
|
66 |
session_dialog_ = session_dialog;
|
akirchst@2133
|
67 |
session_id_ = session_id;
|
wneuper@1815
|
68 |
}
|
rgradisc@1618
|
69 |
|
wneuper@1815
|
70 |
/**
|
wneuper@1815
|
71 |
* at the beginning of a calculation as well as of a subproblem
|
wneuper@1815
|
72 |
*
|
wneuper@1815
|
73 |
* @param calc_head
|
wneuper@1815
|
74 |
* empty (formalization stored invisibly in the calcTree)
|
wneuper@1815
|
75 |
* @return calc_head with viestyle set
|
wneuper@1815
|
76 |
*/
|
wneuper@1815
|
77 |
// FIXME.WN040906 do NOT return calc_head, like Formula in solve-phase
|
wneuper@1815
|
78 |
// and like trymatch etc. see below
|
wneuper@1815
|
79 |
CalcHead startSpecifying(CalcHead calc_head) {
|
wneuper@2129
|
80 |
int calchead_view;
|
wneuper@2129
|
81 |
String setting_value;
|
wneuper@2132
|
82 |
|
wneuper@2129
|
83 |
// set viewstyle according to user settings
|
wneuper@2132
|
84 |
|
wneuper@2129
|
85 |
// dummy return of getValue() call until class is completed
|
wneuper@2129
|
86 |
// setting_value = user_settings_.getValue("DefaultCalcHeadView");
|
wneuper@2129
|
87 |
setting_value = null;
|
wneuper@2132
|
88 |
|
wneuper@2129
|
89 |
if (setting_value == null)
|
wneuper@2129
|
90 |
calchead_view = CalcHead.VIEWSTYLE_SINGLELINE;
|
wneuper@2129
|
91 |
else
|
wneuper@2132
|
92 |
calchead_view = Integer.parseInt(setting_value);
|
wneuper@2129
|
93 |
calc_head.setViewStyle(calchead_view);
|
wneuper@2132
|
94 |
|
wneuper@1815
|
95 |
phase_ = DIALOGPHASE_SPECIFY;
|
wneuper@2132
|
96 |
|
wneuper@2129
|
97 |
// dummy return of getValue() call until class is completed
|
wneuper@2129
|
98 |
// if (user_settings_.getValue("SkipSpecifyingPhase").equals("1")) {
|
wneuper@2132
|
99 |
|
wneuper@2129
|
100 |
if (true) {
|
wneuper@2129
|
101 |
calc_tree_.completeCalcHead();
|
wneuper@2129
|
102 |
try {
|
wneuper@2132
|
103 |
notifyUserAction(new UserAction(
|
wneuper@2132
|
104 |
IUIElement.UI_SPECIFY_CALCULATE_1));
|
wneuper@2129
|
105 |
} catch (RemoteException e) {
|
wneuper@2129
|
106 |
// TODO Auto-generated catch block
|
wneuper@2129
|
107 |
e.printStackTrace();
|
wneuper@2129
|
108 |
} catch (DialogProtocolException e) {
|
wneuper@2129
|
109 |
// TODO Auto-generated catch block
|
wneuper@2129
|
110 |
e.printStackTrace();
|
wneuper@2129
|
111 |
}
|
wneuper@2129
|
112 |
}
|
wneuper@2132
|
113 |
|
wneuper@1815
|
114 |
return calc_head; //WN040906 this is NOT completed !!!
|
wneuper@1815
|
115 |
// FIXME.WN040906 do NOT return calc_head, like Formula in solve-phase
|
wneuper@1815
|
116 |
}
|
wneuper@1815
|
117 |
|
wneuper@1815
|
118 |
// FIXME.WN040906 do NOT return calc_head, like Formula in solve-phase
|
akirchst@1890
|
119 |
public CalcTree startCalculation(int user_id, Formalization f,
|
wneuper@1815
|
120 |
int start_from, int requested_calchead_view) {
|
wneuper@1815
|
121 |
|
wneuper@2129
|
122 |
ICalcIterator temp_iterator;
|
wneuper@2132
|
123 |
|
wneuper@2082
|
124 |
calc_tree_ = math_engine_.startCalculation(f);
|
wneuper@2129
|
125 |
temp_iterator = calc_tree_.iterator();
|
wneuper@2129
|
126 |
try {
|
wneuper@2129
|
127 |
temp_iterator.moveRoot();
|
wneuper@2129
|
128 |
startSpecifying((CalcHead) temp_iterator.getFormula());
|
wneuper@2129
|
129 |
} catch (RemoteException e) {
|
wneuper@2129
|
130 |
// TODO Auto-generated catch block
|
wneuper@2129
|
131 |
e.printStackTrace();
|
wneuper@2129
|
132 |
}
|
wneuper@2129
|
133 |
// AK removed duplicate completeCalcHead() call 20050222
|
wneuper@2129
|
134 |
// the correct call is in startCalculation()
|
wneuper@2129
|
135 |
// calc_tree_.completeCalcHead();
|
wneuper@1815
|
136 |
|
wneuper@1815
|
137 |
// for the moment, all requests for a view are honored
|
wneuper@1815
|
138 |
// WN040825 calc_head_.setViewStyle(requested_calchead_view);
|
wneuper@1815
|
139 |
// --->startSpecifying
|
wneuper@1815
|
140 |
|
wneuper@1815
|
141 |
// for testing purposes: if starting an example from the collection,
|
wneuper@1815
|
142 |
// have everything filled in by the KI
|
wneuper@1815
|
143 |
// WN040825 if (start_from == STARTFROM_EXAMPLE) { --->startSpecifying ?
|
wneuper@1815
|
144 |
|
wneuper@1815
|
145 |
// old-style filling the fields of the calc-head by setting
|
wneuper@1815
|
146 |
// the HELP_ME flag
|
wneuper@1815
|
147 |
// calc_head_.setCalcHeadStatus(CalcHead.CALCHEAD_HELP_ME);
|
wneuper@1815
|
148 |
// }
|
wneuper@1815
|
149 |
|
wneuper@1815
|
150 |
// test code; this protocol is now controlled by the presentation layer
|
wneuper@1815
|
151 |
// do {
|
wneuper@1815
|
152 |
// checkCalcHead()
|
wneuper@1815
|
153 |
// } while (false); // status != ok
|
wneuper@1815
|
154 |
// newCalculation(calc_head_);
|
akirchst@1881
|
155 |
phase_ = DIALOGPHASE_SPECIFY;
|
wneuper@1815
|
156 |
//WN040825 return calc_head_;
|
wneuper@2082
|
157 |
return calc_tree_;
|
wneuper@1815
|
158 |
}
|
wneuper@1815
|
159 |
|
wneuper@1815
|
160 |
public void newCalculation(CalcHead calcHead) {
|
wneuper@1815
|
161 |
try {
|
akirchst@1881
|
162 |
calc_tree_.startSolving();
|
wneuper@1815
|
163 |
} catch (Exception e) {
|
wneuper@1815
|
164 |
// TODO Auto-generated catch block
|
wneuper@1815
|
165 |
e.printStackTrace();
|
wneuper@1815
|
166 |
}
|
wneuper@1815
|
167 |
// calc_tree_ = MathEngine.getMathEngine().startSolving(calcHead);
|
wneuper@1815
|
168 |
calc_tree_.addDataChangeListener(this);
|
wneuper@1978
|
169 |
phase_ = DIALOGPHASE_SOLVE;//WN041122 nein ???!!!???
|
wneuper@1815
|
170 |
}
|
rgradisc@1618
|
171 |
|
wneuper@1815
|
172 |
/*
|
wneuper@1815
|
173 |
* (non-Javadoc)
|
wneuper@1815
|
174 |
*
|
wneuper@1815
|
175 |
* @see isac.wsdialog.IToUser#calcChanged(isac.wsdialog.CalcChangedEvent)
|
wneuper@1815
|
176 |
*/
|
akirchst@1993
|
177 |
public void calcChanged(CalcChangedEvent event) throws RemoteException {
|
wneuper@2129
|
178 |
logger_.fatal(" WS<-. . : calcChanged (unc="
|
wneuper@1994
|
179 |
+ event.getLastUnchangedFormula().toSMLString() + ", del="
|
wneuper@1994
|
180 |
+ event.getLastDeletedFormula().toSMLString() + ", gen="
|
wneuper@1994
|
181 |
+ event.getLastGeneratedFormula().toSMLString());
|
wneuper@1815
|
182 |
ICalcElement calc_elem;
|
wneuper@1815
|
183 |
|
wneuper@2082
|
184 |
try {
|
wneuper@2082
|
185 |
for (int i = 0; i < datachange_listeners_.size(); i++) {
|
wneuper@2082
|
186 |
((IToUser) datachange_listeners_.elementAt(i))
|
wneuper@2082
|
187 |
.calcChanged(event);
|
wneuper@2082
|
188 |
}
|
wneuper@2082
|
189 |
ICalcIterator last_formula = event.getFirstChangedFormula();
|
wneuper@2082
|
190 |
// while searching for last formula, mark intermediate CalcHeads as
|
wneuper@2082
|
191 |
// not
|
wneuper@2082
|
192 |
// to be edited
|
wneuper@2082
|
193 |
// try {
|
wneuper@2132
|
194 |
// while (!last_formula.isLast()) {
|
wneuper@2132
|
195 |
// if (last_formula.getElement().getType() ==
|
wneuper@2132
|
196 |
// ICalcElement.CALCEL_CALCHEAD) {
|
wneuper@2132
|
197 |
// last_formula.getElement().setViewStyle(
|
wneuper@2132
|
198 |
// CalcHead.VIEWSTYLE_IN_CALC);
|
wneuper@2132
|
199 |
// }
|
wneuper@2132
|
200 |
// last_formula.moveDown();
|
wneuper@2132
|
201 |
// //TODO last_formula.moveDown.. WN040824 DG may limit the level
|
wneuper@2132
|
202 |
// // down
|
wneuper@2132
|
203 |
// }
|
wneuper@2132
|
204 |
//
|
wneuper@2132
|
205 |
// // for now, do not specify the CalcHead, just display it.
|
wneuper@2132
|
206 |
// calc_elem = last_formula.getElement();
|
wneuper@2132
|
207 |
//
|
wneuper@2132
|
208 |
// if (calc_elem.getType() == ICalcElement.CALCEL_CALCHEAD) {
|
wneuper@2132
|
209 |
// //WN040826 phase_ = DIALOGPHASE_SPECIFY; --->startSpecifying
|
wneuper@2132
|
210 |
// //WN040826
|
wneuper@2132
|
211 |
// //
|
wneuper@2132
|
212 |
// calc_elem.setViewStyle(CalcHead.VIEWSTYLE_SINGLELINE);--->startSpecifying
|
wneuper@2132
|
213 |
//
|
wneuper@2132
|
214 |
// //WN040826calc_head = startSpecifying((CalcHead) calc_elem);
|
wneuper@2132
|
215 |
// // --->startSpecifying
|
wneuper@2132
|
216 |
// startSpecifying((CalcHead) calc_elem);
|
wneuper@2132
|
217 |
// //WN040826 math_engine_.completeCalcHead(calc_head);
|
wneuper@2132
|
218 |
// // --->startSpecifying
|
wneuper@2132
|
219 |
// } else {
|
wneuper@2132
|
220 |
// phase_ = DIALOGPHASE_SOLVE;
|
wneuper@2132
|
221 |
// }
|
wneuper@2082
|
222 |
} catch (Exception e) {
|
wneuper@2082
|
223 |
e.printStackTrace();
|
wneuper@1815
|
224 |
}
|
wneuper@1815
|
225 |
}
|
akremp@1232
|
226 |
|
wneuper@1815
|
227 |
/**
|
wneuper@1815
|
228 |
* @deprecated Use {@link #notifyUserAction(IUserAction)}instead
|
wneuper@1815
|
229 |
*/
|
wneuper@1815
|
230 |
public void modifyCalcHead(CalcHead calc_head) {
|
wneuper@1815
|
231 |
// MathEngine.getMathEngine().modifyCalcHead(calc_head);
|
akirchst@1881
|
232 |
calc_tree_.modifyCalcHead(calc_head);
|
wneuper@1815
|
233 |
}
|
akremp@899
|
234 |
|
wneuper@1815
|
235 |
/*
|
wneuper@1815
|
236 |
* (non-Javadoc)
|
wneuper@1815
|
237 |
*
|
wneuper@1815
|
238 |
* @see isac.wsdialog.IToCalc#iterator()
|
wneuper@1815
|
239 |
*/
|
wneuper@1815
|
240 |
public ICalcIterator iterator() {
|
wneuper@2082
|
241 |
try {
|
wneuper@2082
|
242 |
return new DialogIterator((CalcIterator) calc_tree_.iterator());
|
wneuper@2082
|
243 |
} catch (Exception e) {
|
wneuper@2082
|
244 |
e.printStackTrace();
|
wneuper@2082
|
245 |
}
|
wneuper@2082
|
246 |
return null;
|
wneuper@2082
|
247 |
}
|
rgradisc@1618
|
248 |
|
wneuper@1994
|
249 |
/**
|
wneuper@1815
|
250 |
* @see isac.wsdialog.IToCalc#addListener(isac.wsdialog.IToUser)
|
wneuper@1815
|
251 |
*/
|
wneuper@2082
|
252 |
public boolean addDataChangeListener(IToUser listener)
|
wneuper@2082
|
253 |
throws RemoteException {
|
wneuper@1815
|
254 |
if (datachange_listeners_.contains(listener)) {
|
wneuper@1815
|
255 |
return false;
|
wneuper@1815
|
256 |
} else {
|
wneuper@1815
|
257 |
datachange_listeners_.add(listener);
|
wneuper@1815
|
258 |
}
|
wneuper@1815
|
259 |
return true;
|
wneuper@1815
|
260 |
}
|
rgradisc@1618
|
261 |
|
wneuper@2082
|
262 |
public boolean registerUIControlListener(IToWorksheet listener)
|
wneuper@2082
|
263 |
throws RemoteException {
|
wneuper@2082
|
264 |
// if (ui_control_listener_ != null) {
|
wneuper@2082
|
265 |
// ui_control_listener_.doUIAction(new UserAction(UI_DO_DETACH));
|
wneuper@2082
|
266 |
// }
|
wneuper@1815
|
267 |
ui_control_listener_ = listener;
|
wneuper@1815
|
268 |
return true;
|
wneuper@1815
|
269 |
}
|
rgradisc@1618
|
270 |
|
wneuper@1815
|
271 |
public Tactic fetchProposedTactic() {
|
wneuper@1815
|
272 |
return calc_tree_.fetchProposedTactic();
|
wneuper@1815
|
273 |
}
|
rgradisc@1618
|
274 |
|
wneuper@1815
|
275 |
public Tactic[] fetchApplicableTactics(int scope) {
|
wneuper@1815
|
276 |
return calc_tree_.fetchApplicableTactics(scope);
|
wneuper@1815
|
277 |
}
|
rgradisc@1618
|
278 |
|
wneuper@1815
|
279 |
/**
|
wneuper@1815
|
280 |
* @deprecated Use {@link #notifyUserAction(IUserAction)}instead
|
wneuper@1815
|
281 |
*/
|
wneuper@1815
|
282 |
public int setNextTactic(Tactic tactic) {
|
wneuper@1815
|
283 |
return calc_tree_.setNextTactic(tactic);
|
wneuper@1815
|
284 |
}
|
akremp@966
|
285 |
|
wneuper@1815
|
286 |
/**
|
wneuper@1815
|
287 |
* @deprecated Use {@link #notifyUserAction(IUserAction)}instead
|
wneuper@1815
|
288 |
*/
|
wneuper@1815
|
289 |
public int autoCalculate(int scope, int nSteps) {
|
wneuper@1815
|
290 |
return calc_tree_.autoCalculate(scope, nSteps);
|
wneuper@1815
|
291 |
}
|
rgradisc@1618
|
292 |
|
wneuper@1815
|
293 |
/**
|
wneuper@1815
|
294 |
* @deprecated Use {@link #notifyUserAction(IUserAction)}instead
|
wneuper@1815
|
295 |
*/
|
wneuper@1815
|
296 |
public void tryMatch(CalcHead ch, CalcHeadCompoundID problemID)
|
wneuper@1815
|
297 |
throws NotInSpecificationPhaseException {
|
rgradisc@1618
|
298 |
|
wneuper@1815
|
299 |
// MathEngine.getMathEngine().tryMatch(ch, problemID);
|
wneuper@1815
|
300 |
math_engine_.tryMatch(ch, problemID);
|
wneuper@1815
|
301 |
}
|
rgradisc@1618
|
302 |
|
wneuper@1815
|
303 |
/**
|
wneuper@1815
|
304 |
* @deprecated Use {@link #notifyUserAction(IUserAction)}instead
|
wneuper@1815
|
305 |
*/
|
wneuper@1815
|
306 |
public void tryRefine(CalcHead ch, CalcHeadCompoundID problemID)
|
wneuper@1815
|
307 |
throws NotInSpecificationPhaseException {
|
rgradisc@1618
|
308 |
|
wneuper@1815
|
309 |
// MathEngine.getMathEngine().tryRefine(ch , problemID);
|
wneuper@1815
|
310 |
math_engine_.tryRefine(ch, problemID);
|
wneuper@1815
|
311 |
}
|
rgradisc@1618
|
312 |
|
wneuper@1815
|
313 |
public ICalcIterator getActiveFormula() {
|
wneuper@1815
|
314 |
return calc_tree_.getActiveFormula();
|
wneuper@1815
|
315 |
}
|
rgradisc@1618
|
316 |
|
wneuper@1815
|
317 |
/**
|
wneuper@1980
|
318 |
* @throws RemoteException
|
wneuper@1815
|
319 |
* @deprecated Use {@link #notifyUserAction(IUserAction)}instead
|
wneuper@1815
|
320 |
*/
|
wneuper@2055
|
321 |
public int replaceFormula(CalcFormula newFormula) throws RemoteException {
|
wneuper@1815
|
322 |
return calc_tree_.replaceFormula(newFormula);
|
wneuper@1815
|
323 |
}
|
rgradisc@1618
|
324 |
|
wneuper@1815
|
325 |
/**
|
wneuper@1980
|
326 |
* @throws RemoteException
|
wneuper@1815
|
327 |
* @deprecated Use {@link #notifyUserAction(IUserAction)}instead
|
wneuper@1815
|
328 |
*/
|
wneuper@2055
|
329 |
public int appendFormula(CalcFormula newFormula) throws RemoteException {
|
wneuper@1815
|
330 |
return calc_tree_.appendFormula(newFormula);
|
wneuper@1815
|
331 |
}
|
akremp@1335
|
332 |
|
wneuper@1815
|
333 |
/**
|
wneuper@1815
|
334 |
* @deprecated Use {@link #notifyUserAction(IUserAction)}instead
|
wneuper@1815
|
335 |
*/
|
wneuper@1815
|
336 |
public void moveActiveFormula(ICalcIterator newActiveFormula) {
|
wneuper@1815
|
337 |
calc_tree_.moveActiveFormula(newActiveFormula);
|
wneuper@1815
|
338 |
}
|
wneuper@1815
|
339 |
|
wneuper@1815
|
340 |
/**
|
wneuper@1815
|
341 |
* Notify the Dialog Guide about interaction from the User
|
wneuper@1815
|
342 |
*
|
wneuper@1815
|
343 |
* @param action
|
wneuper@1815
|
344 |
* @return true, if the action has been processed, false if the processing
|
wneuper@1815
|
345 |
* the action has been denied
|
wneuper@1980
|
346 |
* @throws RemoteException
|
wneuper@1815
|
347 |
*
|
wneuper@1815
|
348 |
*/
|
wneuper@1815
|
349 |
public boolean notifyUserAction(IUserAction action)
|
wneuper@1980
|
350 |
throws DialogProtocolException, RemoteException {
|
wneuper@1815
|
351 |
int request = action.getActionID();
|
wneuper@2129
|
352 |
logger_.fatal(" WS->DG: notifyUserAction request= " + request);
|
wneuper@1815
|
353 |
|
wneuper@2129
|
354 |
//*********** set and check DIALOGPHASE *******************
|
wneuper@2129
|
355 |
// two userActions dont care about the dialogphase
|
wneuper@2129
|
356 |
switch (request) {
|
wneuper@2129
|
357 |
case (UI_CALCULATE_1):
|
wneuper@2129
|
358 |
if (getActiveFormula().onCalcHead()) {
|
wneuper@2129
|
359 |
request = UI_SPECIFY_CALCULATE_1;
|
wneuper@2129
|
360 |
phase_ = DIALOGPHASE_SPECIFY;
|
wneuper@2129
|
361 |
} else {
|
wneuper@2129
|
362 |
request = UI_SOLVE_CALCULATE_1;
|
wneuper@2129
|
363 |
phase_ = DIALOGPHASE_SOLVE;
|
wneuper@2129
|
364 |
}
|
wneuper@2132
|
365 |
break;
|
wneuper@2129
|
366 |
case (UI_CALCULATE_ALL):
|
wneuper@2129
|
367 |
if (getActiveFormula().onCalcHead()) {
|
wneuper@2129
|
368 |
request = UI_SPECIFY_CALCULATE_ALL;
|
wneuper@2129
|
369 |
phase_ = DIALOGPHASE_SPECIFY;
|
wneuper@2129
|
370 |
} else {
|
wneuper@2129
|
371 |
request = UI_SOLVE_CALCULATE_ALL;
|
wneuper@2129
|
372 |
phase_ = DIALOGPHASE_SOLVE;
|
wneuper@2129
|
373 |
}
|
wneuper@2129
|
374 |
}
|
wneuper@2132
|
375 |
|
wneuper@2129
|
376 |
// al other userActions belong to a certain dialogphase
|
wneuper@1815
|
377 |
switch (phase_) {
|
wneuper@1815
|
378 |
case DIALOGPHASE_IDLE:
|
wneuper@1815
|
379 |
throw new DialogProtocolException(request, phase_);
|
wneuper@1978
|
380 |
case DIALOGPHASE_SPECIFY:
|
wneuper@1815
|
381 |
if (request < UI_DUMMY_FIRST_SPECIFY
|
wneuper@1815
|
382 |
|| request > UI_DUMMY_LAST_SPECIFY)
|
wneuper@1815
|
383 |
throw new DialogProtocolException(request, phase_);
|
wneuper@1815
|
384 |
break;
|
wneuper@1815
|
385 |
case DIALOGPHASE_SOLVE:
|
wneuper@1815
|
386 |
if (request < UI_DUMMY_FIRST_SOLVE || request > UI_DUMMY_LAST_SOLVE)
|
wneuper@1815
|
387 |
throw new DialogProtocolException(request, phase_);
|
wneuper@1815
|
388 |
break;
|
wneuper@1815
|
389 |
}
|
wneuper@1815
|
390 |
|
wneuper@2129
|
391 |
//*********** handle IUserAction's **********************
|
wneuper@2129
|
392 |
CalcHead calc_head = new CalcHead();//?WN0502023?????????
|
wneuper@2082
|
393 |
try {
|
wneuper@2082
|
394 |
calc_head = (CalcHead) calc_tree_.iterator().getFormula();
|
wneuper@2082
|
395 |
} catch (Exception e) {
|
wneuper@2082
|
396 |
e.printStackTrace();
|
wneuper@2082
|
397 |
}
|
wneuper@1815
|
398 |
switch (request) {
|
wneuper@1815
|
399 |
case UI_SPECIFY_TRY_MATCH:
|
wneuper@1815
|
400 |
try {
|
akirchst@1881
|
401 |
tryMatch(calc_head, ((UserActionOnCalcHeadCompoundID) action)
|
wneuper@1815
|
402 |
.getObjectID());
|
wneuper@1815
|
403 |
} catch (NotInSpecificationPhaseException e) {
|
wneuper@1815
|
404 |
throw new DialogMathException(request, phase_, e);
|
wneuper@1815
|
405 |
}
|
wneuper@1815
|
406 |
break;
|
wneuper@1815
|
407 |
|
wneuper@1815
|
408 |
case UI_SPECIFY_TRY_REFINE:
|
wneuper@1815
|
409 |
try {
|
akirchst@1881
|
410 |
tryRefine(calc_head, ((UserActionOnCalcHeadCompoundID) action)
|
wneuper@1815
|
411 |
.getObjectID());
|
wneuper@1815
|
412 |
} catch (NotInSpecificationPhaseException e) {
|
wneuper@1815
|
413 |
throw new DialogMathException(request, phase_, e);
|
wneuper@1815
|
414 |
}
|
wneuper@1815
|
415 |
break;
|
wneuper@1815
|
416 |
|
wneuper@1815
|
417 |
case UI_SPECIFY_CHANGE_VIEW:
|
akirchst@1881
|
418 |
calc_head.setViewStyle(((UserActionOnInt) action).getInt());
|
wneuper@1815
|
419 |
break;
|
wneuper@1815
|
420 |
|
wneuper@1815
|
421 |
case UI_SPECIFY_COMPLETE_CALCHEAD:
|
akirchst@1881
|
422 |
calc_tree_.completeCalcHead();
|
wneuper@1815
|
423 |
// old-style filling the fields of the calc-head by setting
|
wneuper@1815
|
424 |
// the HELP_ME flag
|
wneuper@1815
|
425 |
// calc_head_.setCalcHeadStatus(CalcHead.CALCHEAD_HELP_ME);
|
wneuper@1815
|
426 |
// modifyCalcHead(calc_head_);
|
wneuper@1815
|
427 |
break;
|
wneuper@1815
|
428 |
case UI_SPECIFY_COMPLETE_METHOD:
|
wneuper@1815
|
429 |
case UI_SPECIFY_COMPLETE_THEORY:
|
wneuper@1815
|
430 |
case UI_SPECIFY_COMPLETE_PROBLEM:
|
wneuper@1815
|
431 |
case UI_SPECIFY_COMPLETE_GIVEN:
|
wneuper@1815
|
432 |
case UI_SPECIFY_COMPLETE_FIND:
|
wneuper@1815
|
433 |
case UI_SPECIFY_COMPLETE_RELATE:
|
wneuper@1815
|
434 |
throw new DialogNotImplementedException(request, phase_);
|
wneuper@1815
|
435 |
|
wneuper@1815
|
436 |
case UI_SPECIFY_CHECK_CALCHEAD:
|
akirchst@1881
|
437 |
modifyCalcHead(calc_head);
|
wneuper@1815
|
438 |
break;
|
wneuper@1815
|
439 |
|
wneuper@1815
|
440 |
// was: newCalculation()
|
wneuper@1815
|
441 |
case UI_SPECIFY_CALCULATE_1:
|
wneuper@1815
|
442 |
case UI_SPECIFY_CALCULATE_ALL:
|
akirchst@1881
|
443 |
modifyCalcHead(calc_head);
|
akirchst@1881
|
444 |
if (calc_head.getCalcHeadStatus() != CalcHead.CALCHEAD_CORRECT)
|
wneuper@1815
|
445 |
return false;
|
wneuper@1815
|
446 |
|
wneuper@1815
|
447 |
try {
|
akirchst@1881
|
448 |
calc_tree_.startSolving();
|
wneuper@1815
|
449 |
} catch (Exception e) {
|
wneuper@1815
|
450 |
// TODO Auto-generated catch block
|
wneuper@1815
|
451 |
e.printStackTrace();
|
wneuper@1815
|
452 |
}
|
wneuper@1815
|
453 |
// calc_tree_ = MathEngine.getMathEngine().startSolving(calcHead);
|
wneuper@1815
|
454 |
calc_tree_.addDataChangeListener(this);
|
wneuper@2129
|
455 |
//if (user_settings_.getValue(""))
|
wneuper@2129
|
456 |
calc_tree_.completeCalcHead();
|
wneuper@2129
|
457 |
//@@@@@@@WN050223
|
wneuper@2132
|
458 |
|
wneuper@1815
|
459 |
phase_ = DIALOGPHASE_SOLVE;
|
wneuper@1815
|
460 |
// fall through to calculate
|
wneuper@1815
|
461 |
|
wneuper@1815
|
462 |
case UI_SOLVE_CALCULATE_1:
|
wneuper@2132
|
463 |
//why not at (*) here ?
|
wneuper@1815
|
464 |
case UI_SOLVE_CALCULATE_ALL:
|
wneuper@1815
|
465 |
switch (request) {
|
wneuper@1815
|
466 |
case UI_SPECIFY_CALCULATE_ALL:
|
wneuper@1815
|
467 |
case UI_SOLVE_CALCULATE_ALL:
|
wneuper@1815
|
468 |
autoCalculate(SCOPE_CALCULATION, 0);
|
akremp@1620
|
469 |
break;
|
wneuper@2129
|
470 |
case UI_SPECIFY_CALCULATE_1://???
|
wneuper@2132
|
471 |
// break;
|
wneuper@1815
|
472 |
default:
|
wneuper@2129
|
473 |
autoCalculate(SCOPE_CALCULATION, 1);//why not at (*) above ?
|
wneuper@1815
|
474 |
break;
|
wneuper@1815
|
475 |
}
|
wneuper@1815
|
476 |
break;
|
rgradisc@1618
|
477 |
|
wneuper@1815
|
478 |
case UI_SOLVE_CALCULATE_SUBPROBLEM:
|
wneuper@1815
|
479 |
autoCalculate(SCOPE_SUBPROBLEM, 0);
|
wneuper@1815
|
480 |
break;
|
rgradisc@1618
|
481 |
|
wneuper@1815
|
482 |
case UI_SOLVE_EDIT_ACTIVE_FORMULA:
|
wneuper@1815
|
483 |
ui_control_listener_.doUIAction(new UserAction(UI_DO_EDIT_FORMULA));
|
wneuper@1815
|
484 |
break;
|
rgradisc@1618
|
485 |
|
wneuper@1815
|
486 |
case UI_SOLVE_EDIT_ACTIVE_FORMULA_COMPLETE:
|
wneuper@2082
|
487 |
CalcFormula formula = (CalcFormula) ((UserActionOnCalcElement) action)
|
wneuper@2082
|
488 |
.getCalcElement();
|
wneuper@2082
|
489 |
// if the position is null, the formula did not exist, so we try to
|
wneuper@2082
|
490 |
// append a new formula
|
wneuper@2082
|
491 |
if (formula.getPosition() == null) {
|
wneuper@2082
|
492 |
appendFormula(formula);
|
wneuper@2082
|
493 |
} else {
|
wneuper@2082
|
494 |
replaceFormula(formula);
|
wneuper@2082
|
495 |
}
|
wneuper@1815
|
496 |
break;
|
rgradisc@1618
|
497 |
|
wneuper@1815
|
498 |
case UI_SOLVE_APPEND_USER_FORMULA:
|
wneuper@1815
|
499 |
// appendFormula((Formula) ((UserActionOnCalcElement)
|
wneuper@1815
|
500 |
// action).getCalcElement());
|
wneuper@1815
|
501 |
ui_control_listener_
|
wneuper@1815
|
502 |
.doUIAction(new UserAction(UI_DO_APPEND_FORMULA));
|
wneuper@1815
|
503 |
break;
|
rgradisc@1618
|
504 |
|
wneuper@1815
|
505 |
case UI_SOLVE_MOVE_ACTIVE_FORMULA:
|
wneuper@1815
|
506 |
moveActiveFormula(((UserActionOnIterator) action).getPosition());
|
wneuper@1815
|
507 |
break;
|
rgradisc@1618
|
508 |
|
wneuper@1815
|
509 |
case UI_SOLVE_GET_PROPOSED_TACTIC:
|
wneuper@1815
|
510 |
throw new DialogNotImplementedException(request, phase_);
|
rgradisc@1618
|
511 |
|
wneuper@1815
|
512 |
case UI_SOLVE_GET_APPLICABLE_TACTICS:
|
wneuper@1815
|
513 |
throw new DialogNotImplementedException(request, phase_);
|
rgradisc@1618
|
514 |
|
wneuper@1815
|
515 |
case UI_SOLVE_SET_NEXT_TACTIC:
|
wneuper@1815
|
516 |
setNextTactic((Tactic) ((UserActionOnCalcElement) action)
|
wneuper@1815
|
517 |
.getCalcElement());
|
wneuper@1978
|
518 |
//WN041126 extracted from isac.bridge.CalcTree#setNextTactic @@@
|
wneuper@2082
|
519 |
//autoCalculate(SCOPE_CALCULATION, 1);
|
wneuper@1815
|
520 |
break;
|
rgradisc@1618
|
521 |
|
wneuper@1815
|
522 |
case UI_SOLVE_HELP_ENTERING_FORMULA:
|
wneuper@1815
|
523 |
throw new DialogNotImplementedException(request, phase_);
|
rgradisc@1618
|
524 |
|
wneuper@1815
|
525 |
case UI_SOLVE_SHOW_ASSUMPTIONS:
|
wneuper@1815
|
526 |
throw new DialogNotImplementedException(request, phase_);
|
rgradisc@1618
|
527 |
|
wneuper@1815
|
528 |
case UI_SOLVE_SHOW_DETAILS:
|
wneuper@1815
|
529 |
throw new DialogNotImplementedException(request, phase_);
|
rgradisc@1618
|
530 |
|
wneuper@1815
|
531 |
default:
|
wneuper@1815
|
532 |
throw new DialogUnknownActionException(request, phase_);
|
wneuper@1815
|
533 |
}
|
wneuper@1815
|
534 |
return true;
|
wneuper@1815
|
535 |
}
|
rgradisc@1618
|
536 |
|
wneuper@1815
|
537 |
private void rmiBind() {
|
wneuper@1815
|
538 |
if (System.getSecurityManager() == null) {
|
wneuper@1815
|
539 |
System.setSecurityManager(new RMISecurityManager());
|
wneuper@1815
|
540 |
}
|
rgradisc@1618
|
541 |
|
wneuper@1815
|
542 |
try {
|
wneuper@1815
|
543 |
LocateRegistry.createRegistry(1099);
|
wneuper@1815
|
544 |
} catch (java.rmi.RemoteException exc2) {
|
wneuper@1815
|
545 |
System.err.println("can not create registry: " + exc2.getMessage());
|
wneuper@1815
|
546 |
}
|
rgradisc@1618
|
547 |
|
wneuper@1815
|
548 |
String name = "//localhost/isac-DialogGuide";
|
wneuper@1815
|
549 |
try {
|
wneuper@1815
|
550 |
System.out.println("try to bind as " + name);
|
wneuper@1815
|
551 |
Naming.rebind(name, this);
|
wneuper@1815
|
552 |
System.out.println("Dialog Guide bound to " + name);
|
wneuper@2082
|
553 |
//WN040906 was Object Manager ...
|
wneuper@1815
|
554 |
} catch (java.rmi.ConnectException e) {
|
wneuper@1815
|
555 |
System.err.println("failed to contact as " + name
|
wneuper@1815
|
556 |
+ " (creating RMI-Server on localhost: 1099)");
|
wneuper@1815
|
557 |
} catch (RemoteException e) {
|
wneuper@1815
|
558 |
// TODO Auto-generated catch block
|
wneuper@1815
|
559 |
e.printStackTrace();
|
wneuper@1815
|
560 |
} catch (MalformedURLException e) {
|
wneuper@1815
|
561 |
// TODO Auto-generated catch block
|
wneuper@1815
|
562 |
e.printStackTrace();
|
wneuper@1815
|
563 |
}
|
wneuper@1815
|
564 |
}
|
rgradisc@1618
|
565 |
|
akirchst@2133
|
566 |
// public static void main(String[] args) {
|
akirchst@2133
|
567 |
// try {
|
akirchst@2133
|
568 |
// new DialogGuide(args[0]);
|
akirchst@2133
|
569 |
//
|
akirchst@2133
|
570 |
// } catch (RemoteException e) {
|
akirchst@2133
|
571 |
// e.printStackTrace();
|
akirchst@2133
|
572 |
// }
|
akirchst@2133
|
573 |
// }
|
rgradisc@1618
|
574 |
|
wneuper@2082
|
575 |
/*
|
wneuper@2082
|
576 |
* (non-Javadoc)
|
wneuper@2082
|
577 |
*
|
wneuper@2082
|
578 |
* @see isac.util.interfaces.IToCalc#startSolving()
|
wneuper@2082
|
579 |
*/
|
wneuper@2082
|
580 |
public void startSolving() throws Exception {
|
wneuper@2082
|
581 |
// TODO Auto-generated method stub
|
wneuper@1877
|
582 |
|
wneuper@2082
|
583 |
}
|
wneuper@1877
|
584 |
|
wneuper@2082
|
585 |
/*
|
wneuper@2082
|
586 |
* (non-Javadoc)
|
wneuper@2082
|
587 |
*
|
wneuper@2082
|
588 |
* @see isac.util.interfaces.IToCalc#completeCalcHead(isac.util.formulae.CalcHead)
|
wneuper@2082
|
589 |
*/
|
wneuper@2082
|
590 |
public void completeCalcHead(CalcHead calcHead) {
|
wneuper@2082
|
591 |
// TODO Auto-generated method stub
|
akirchst@1881
|
592 |
|
wneuper@2082
|
593 |
}
|
wneuper@1877
|
594 |
|
wneuper@2082
|
595 |
/*
|
wneuper@2082
|
596 |
* (non-Javadoc)
|
wneuper@2082
|
597 |
*
|
wneuper@2082
|
598 |
* @see isac.util.interfaces.IToCalc#completeCalcHead(isac.util.formulae.CalcHead,
|
wneuper@2082
|
599 |
* int)
|
wneuper@2082
|
600 |
*/
|
wneuper@2082
|
601 |
public void completeCalcHead(CalcHead calcHead, int completeItem) {
|
wneuper@2082
|
602 |
// TODO Auto-generated method stub
|
wneuper@2062
|
603 |
|
wneuper@2082
|
604 |
}
|
wneuper@2082
|
605 |
|
wneuper@2082
|
606 |
/*
|
wneuper@2082
|
607 |
* (non-Javadoc)
|
wneuper@2082
|
608 |
*
|
wneuper@2082
|
609 |
* @see isac.util.interfaces.IToCalc#completeCalcHead()
|
wneuper@2082
|
610 |
*/
|
wneuper@2082
|
611 |
public void completeCalcHead() throws RemoteException {
|
wneuper@2129
|
612 |
// TODO Auto-generated method stub WN050223
|
wneuper@2082
|
613 |
|
wneuper@2082
|
614 |
}
|
wneuper@2082
|
615 |
|
wneuper@2082
|
616 |
/**
|
wneuper@2082
|
617 |
* @deprecated Use {@link #notifyUserAction(IUserAction)}instead
|
wneuper@2082
|
618 |
*
|
wneuper@2082
|
619 |
* @see isac.util.interfaces.IToCalc#intermediateSteps(isac.util.interfaces.ICalcIterator)
|
wneuper@2082
|
620 |
*/
|
wneuper@2082
|
621 |
public int intermediateSteps(ICalcIterator i) throws RemoteException {
|
wneuper@2082
|
622 |
// TODO Auto-generated method stub
|
wneuper@2082
|
623 |
return 0;
|
wneuper@2082
|
624 |
}
|
wneuper@2082
|
625 |
|
wneuper@2082
|
626 |
/*
|
wneuper@2082
|
627 |
* (non-Javadoc)
|
wneuper@2082
|
628 |
*
|
wneuper@2082
|
629 |
* @see isac.util.interfaces.IToCalc#getElementsFromTo(isac.util.interfaces.ICalcIterator,
|
wneuper@2082
|
630 |
* isac.util.interfaces.ICalcIterator, java.lang.Integer, boolean)
|
wneuper@2082
|
631 |
*/
|
wneuper@2082
|
632 |
public Vector getElementsFromTo(ICalcIterator iterator_from,
|
wneuper@2082
|
633 |
ICalcIterator iterator_to, Integer level,
|
wneuper@2082
|
634 |
boolean result_includes_tactics) throws RemoteException {
|
wneuper@2082
|
635 |
// TODO Auto-generated method stub
|
wneuper@2082
|
636 |
return null;
|
wneuper@2082
|
637 |
}
|
wneuper@2069
|
638 |
|
wneuper@1815
|
639 |
} |