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 ComplexPolar 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 current = (new Multiplication()).insert(current);
27
28 current = (new E()).insert(current);
29 current = (new Superscript()).insert(current);
30 current = (new Bracket()).insert(current);
31 current = (new I()).insert(current);
32 current = (new Multiplication()).insert(current);
33 current = (new VariableOrNumber()).insert(current);
34
35 return realPart;
36 }
37
38 /***
39 * Adds a new element (template) to the end of the list.
40 * Returns the new element.
41 */
42 public FormulaTreeStructure addElement() {
43 if (gotoImaginary) {
44 gotoImaginary = false;
45 FormulaTreeStructure imaginay = (FormulaTreeStructure) getChild(0);
46 imaginay = (FormulaTreeStructure) imaginay.getChild(0);
47 imaginay = (FormulaTreeStructure) imaginay.getChild(1);
48 imaginay = (FormulaTreeStructure) imaginay.getChild(1);
49 imaginay = (FormulaTreeStructure) imaginay.getChild(0);
50 imaginay = (FormulaTreeStructure) imaginay.getChild(1);
51
52 return imaginay;
53 }
54 else
55 return this;
56 }
57
58 /***
59 * The Creation of the corresponding linear expression of the formula.
60 */
61 public String createLinear(String linear) {
62 FormulaTreeStructure imaginay = (FormulaTreeStructure) getChild(0);
63 imaginay = (FormulaTreeStructure) imaginay.getChild(0);
64 FormulaTreeStructure realPart = (FormulaTreeStructure) imaginay.getChild(0);
65 imaginay = (FormulaTreeStructure) imaginay.getChild(1);
66 imaginay = (FormulaTreeStructure) imaginay.getChild(1);
67 imaginay = (FormulaTreeStructure) imaginay.getChild(0);
68 imaginay = (FormulaTreeStructure) imaginay.getChild(1);
69
70 linear = realPart.createLinear(linear + getTheOperator());
71 linear = imaginay.createLinear(linear + ",");
72 return linear + ")";
73 }
74 }