1 package fr.ove.openmath.jome.model;
2
3 import java.util.*;
4 import fr.ove.openmath.jome.model.*;
5 import fr.ove.openmath.jome.model.events.ModelEvent;
6
7 /***
8 *
9 * @author © 1999 DIRAT Laurent
10 * @version 2.0 28/06/1999
11 */
12 public class ComplexCartesian extends KaryOperator {
13
14
15
16 private boolean gotoImaginary = true;
17
18 /***
19 * Inserts the instance in the formula tree structure.<BR>
20 * @param current the position in the formula tree where the operator is to be insert.
21 * @return the new current position int hte formula tree.
22 */
23 public FormulaTreeStructure insert(FormulaTreeStructure current) {
24 current = super.insert(current);
25 FormulaTreeStructure realPart = current;
26 realPart.setIsTemplate(false);
27 current = (new Addition()).insert(current);
28 realPart.setIsTemplate(true);
29
30 current = (new I()).insert(current);
31 current = (new Multiplication()).insert(current);
32 current = (new VariableOrNumber()).insert(current);
33
34 return realPart;
35 }
36
37 /***
38 * Adds a new element (template) to the end of the list.
39 * Returns the new element.
40 */
41 public FormulaTreeStructure addElement() {
42 if (gotoImaginary) {
43 gotoImaginary = false;
44 FormulaTreeStructure imaginay = (FormulaTreeStructure) getChild(0);
45 imaginay = (FormulaTreeStructure) imaginay.getChild(0);
46 imaginay = (FormulaTreeStructure) imaginay.getChild(1);
47 imaginay = (FormulaTreeStructure) imaginay.getChild(1);
48
49 return imaginay;
50 }
51 else
52 return this;
53 }
54
55 /***
56 * The Creation of the corresponding linear expression of the formula.
57 */
58 public String createLinear(String linear) {
59 FormulaTreeStructure imaginay = (FormulaTreeStructure) getChild(0);
60 imaginay = (FormulaTreeStructure) imaginay.getChild(0);
61 FormulaTreeStructure realPart = (FormulaTreeStructure) imaginay.getChild(0);
62 imaginay = (FormulaTreeStructure) imaginay.getChild(1);
63 imaginay = (FormulaTreeStructure) imaginay.getChild(1);
64
65 linear = realPart.createLinear(linear + getTheOperator());
66 linear = imaginay.createLinear(linear + ",");
67 return linear + ")";
68 }
69 }