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