]> git.gag.com Git - debian/openrocket/blob - src/net/sf/openrocket/rocketcomponent/RocketComponent.java
Undo/redo system enhancements, DnD for component tree, bug fixes
[debian/openrocket] / src / net / sf / openrocket / rocketcomponent / RocketComponent.java
1 package net.sf.openrocket.rocketcomponent;
2
3 import java.awt.Color;
4 import java.util.ArrayList;
5 import java.util.Collection;
6 import java.util.Collections;
7 import java.util.EmptyStackException;
8 import java.util.Iterator;
9 import java.util.List;
10 import java.util.NoSuchElementException;
11 import java.util.Stack;
12
13 import javax.swing.event.ChangeListener;
14
15 import net.sf.openrocket.logging.TraceException;
16 import net.sf.openrocket.util.BugException;
17 import net.sf.openrocket.util.ChangeSource;
18 import net.sf.openrocket.util.Coordinate;
19 import net.sf.openrocket.util.LineStyle;
20 import net.sf.openrocket.util.MathUtil;
21 import net.sf.openrocket.util.UniqueID;
22
23
24 public abstract class RocketComponent implements ChangeSource, Cloneable,
25                 Iterable<RocketComponent> {
26         
27         /*
28          * Text is suitable to the form
29          *    Position relative to:  <title>
30          */
31         public enum Position {
32                 /** Position relative to the top of the parent component. */
33                 TOP("Top of the parent component"),
34                 /** Position relative to the middle of the parent component. */
35                 MIDDLE("Middle of the parent component"),
36                 /** Position relative to the bottom of the parent component. */
37                 BOTTOM("Bottom of the parent component"),
38                 /** Position after the parent component (for body components). */
39                 AFTER("After the parent component"),
40                 /** Specify an absolute X-coordinate position. */
41                 ABSOLUTE("Tip of the nose cone");
42                 
43                 private String title;
44                 
45                 Position(String title) {
46                         this.title = title;
47                 }
48                 
49                 @Override
50                 public String toString() {
51                         return title;
52                 }
53         }
54         
55         ////////  Parent/child trees
56         /**
57          * Parent component of the current component, or null if none exists.
58          */
59         private RocketComponent parent = null;
60         
61         /**
62          * List of child components of this component.
63          */
64         private List<RocketComponent> children = new ArrayList<RocketComponent>();
65         
66
67         ////////  Parameters common to all components:
68         
69         /**
70          * Characteristic length of the component.  This is used in calculating the coordinate
71          * transformations and positions of other components in reference to this component.
72          * This may and should be used as the "true" length of the component, where applicable.
73          * By default it is zero, i.e. no translation.
74          */
75         protected double length = 0;
76         
77         /**
78          * Positioning of this component relative to the parent component.
79          */
80         protected Position relativePosition;
81         
82         /**
83          * Offset of the position of this component relative to the normal position given by
84          * relativePosition.  By default zero, i.e. no position change.
85          */
86         protected double position = 0;
87         
88
89         // Color of the component, null means to use the default color
90         private Color color = null;
91         private LineStyle lineStyle = null;
92         
93
94         // Override mass/CG
95         private double overrideMass = 0;
96         private boolean massOverriden = false;
97         private double overrideCGX = 0;
98         private boolean cgOverriden = false;
99         
100         private boolean overrideSubcomponents = false;
101         
102
103         // User-given name of the component
104         private String name = null;
105         
106         // User-specified comment
107         private String comment = "";
108         
109         // Unique ID of the component
110         // TODO: CRITICAL: Sort out usage of ID and undo defect
111         private String id = null;
112         
113         /**
114          * When invalidated is non-null this component cannot be used anymore.
115          * This is a safety mechanism to prevent accidental use after calling {@link #copyFrom(RocketComponent)}.
116          */
117         private TraceException invalidated = null;
118         
119         ////  NOTE !!!  All fields must be copied in the method copyFrom()!  ////
120         
121
122
123         /**
124          * Default constructor.  Sets the name of the component to the component's static name
125          * and the relative position of the component.
126          */
127         public RocketComponent(Position relativePosition) {
128                 // These must not fire any events, due to Rocket undo system initialization
129                 this.name = getComponentName();
130                 this.relativePosition = relativePosition;
131                 newID();
132         }
133         
134         
135
136
137
138         ////////////  Methods that must be implemented  ////////////
139         
140
141         /**
142          * Static component name.  The name may not vary of the parameters, it must be static.
143          */
144         public abstract String getComponentName(); // Static component type name
145         
146         /**
147          * Return the component mass (regardless of mass overriding).
148          */
149         public abstract double getComponentMass(); // Mass of non-overridden component
150         
151         /**
152          * Return the component CG and mass (regardless of CG or mass overriding).
153          */
154         public abstract Coordinate getComponentCG(); // CG of non-overridden component
155         
156
157         /**
158          * Return the longitudal (around the y- or z-axis) unitary moment of inertia.  
159          * The unitary moment of inertia is the moment of inertia with the assumption that
160          * the mass of the component is one kilogram.  The inertia is measured in
161          * respect to the non-overridden CG.
162          * 
163          * @return   the longitudal unitary moment of inertia of this component.
164          */
165         public abstract double getLongitudalUnitInertia();
166         
167         
168         /**
169          * Return the rotational (around the x-axis) unitary moment of inertia.  
170          * The unitary moment of inertia is the moment of inertia with the assumption that
171          * the mass of the component is one kilogram.  The inertia is measured in
172          * respect to the non-overridden CG.
173          * 
174          * @return   the rotational unitary moment of inertia of this component.
175          */
176         public abstract double getRotationalUnitInertia();
177         
178         
179         /**
180          * Test whether this component allows any children components.  This method must
181          * return true if and only if {@link #isCompatible(Class)} returns true for any
182          * rocket component class.
183          * 
184          * @return      <code>true</code> if children can be attached to this component, <code>false</code> otherwise.
185          */
186         public abstract boolean allowsChildren();
187         
188         /**
189          * Test whether the given component type can be added to this component.  This type safety
190          * is enforced by the <code>addChild()</code> methods.  The return value of this method
191          * may change to reflect the current state of this component (e.g. two components of some
192          * type cannot be placed as children).
193          * 
194          * @param type  The RocketComponent class type to add.
195          * @return      Whether such a component can be added.
196          */
197         public abstract boolean isCompatible(Class<? extends RocketComponent> type);
198         
199         
200         /* Non-abstract helper method */
201         /**
202          * Test whether the given component can be added to this component.  This is equivalent
203          * to calling <code>isCompatible(c.getClass())</code>.
204          * 
205          * @param c  Component to test.
206          * @return   Whether the component can be added.
207          * @see #isCompatible(Class)
208          */
209         public final boolean isCompatible(RocketComponent c) {
210                 checkState();
211                 return isCompatible(c.getClass());
212         }
213         
214         
215
216         /**
217          * Return a collection of bounding coordinates.  The coordinates must be such that
218          * the component is fully enclosed in their convex hull.
219          * 
220          * @return      a collection of coordinates that bound the component.
221          */
222         public abstract Collection<Coordinate> getComponentBounds();
223         
224         /**
225          * Return true if the component may have an aerodynamic effect on the rocket.
226          */
227         public abstract boolean isAerodynamic();
228         
229         /**
230          * Return true if the component may have an effect on the rocket's mass.
231          */
232         public abstract boolean isMassive();
233         
234         
235
236
237
238         ////////////  Methods that may be overridden  ////////////
239         
240
241         /**
242          * Shift the coordinates in the array corresponding to radial movement.  A component
243          * that has a radial position must shift the coordinates in this array suitably.
244          * If the component is clustered, then a new array must be returned with a
245          * coordinate for each cluster.
246          * <p>
247          * The default implementation simply returns the array, and thus produces no shift.
248          * 
249          * @param c   an array of coordinates to shift.
250          * @return    an array of shifted coordinates.  The method may modify the contents
251          *                        of the passed array and return the array itself.
252          */
253         public Coordinate[] shiftCoordinates(Coordinate[] c) {
254                 checkState();
255                 return c;
256         }
257         
258         
259         /**
260          * Called when any component in the tree fires a ComponentChangeEvent.  This is by 
261          * default a no-op, but subclasses may override this method to e.g. invalidate 
262          * cached data.  The overriding method *must* call 
263          * <code>super.componentChanged(e)</code> at some point.
264          * 
265          * @param e  The event fired
266          */
267         protected void componentChanged(ComponentChangeEvent e) {
268                 // No-op
269                 checkState();
270         }
271         
272         
273
274
275         /**
276          * Return a descriptive name of the component.
277          * 
278          * The description may include extra information about the type of component,
279          * e.g. "Conical nose cone".
280          * 
281          * @return A string describing the component.
282          */
283         @Override
284         public final String toString() {
285                 if (name.equals(""))
286                         return getComponentName();
287                 else
288                         return name;
289         }
290         
291         
292         public final void printStructure() {
293                 System.out.println("Rocket structure from '" + this.toString() + "':");
294                 printStructure(0);
295         }
296         
297         private void printStructure(int level) {
298                 String s = "";
299                 
300                 for (int i = 0; i < level; i++) {
301                         s += "  ";
302                 }
303                 s += this.toString() + " (" + this.getComponentName() + ")";
304                 System.out.println(s);
305                 
306                 for (RocketComponent c : children) {
307                         c.printStructure(level + 1);
308                 }
309         }
310         
311         
312         /**
313          * Make a deep copy of the rocket component tree structure from this component
314          * downwards for copying purposes.  Each component in the copy will be assigned
315          * a new component ID, making it a safe copy.  This method does not fire any events.
316          * 
317          * @return A deep copy of the structure.
318          */
319         public final RocketComponent copy() {
320                 RocketComponent clone = copyWithOriginalID();
321                 
322                 Iterator<RocketComponent> iterator = clone.deepIterator(true);
323                 while (iterator.hasNext()) {
324                         iterator.next().newID();
325                 }
326                 return clone;
327         }
328         
329         
330
331         /**
332          * Make a deep copy of the rocket component tree structure from this component
333          * downwards while maintaining the component ID's.  The purpose of this method is
334          * to allow copies to be created with the original ID's for the purpose of the
335          * undo/redo mechanism.  This method should not be used for other purposes,
336          * such as copy/paste.  This method does not fire any events.
337          * <p>
338          * This method must be overridden by any component that refers to mutable objects, 
339          * or if some fields should not be copied.  This should be performed by
340          * <code>RocketComponent c = super.copyWithOriginalID();</code> and then cloning/modifying
341          * the appropriate fields.
342          * <p>
343          * This is not performed as serializing/deserializing for performance reasons.
344          * 
345          * @return A deep copy of the structure.
346          */
347         protected RocketComponent copyWithOriginalID() {
348                 checkState();
349                 RocketComponent clone;
350                 try {
351                         clone = (RocketComponent) this.clone();
352                 } catch (CloneNotSupportedException e) {
353                         throw new BugException("CloneNotSupportedException encountered, " +
354                                         "report a bug!", e);
355                 }
356                 
357                 // Reset all parent/child information
358                 clone.parent = null;
359                 clone.children = new ArrayList<RocketComponent>();
360                 
361                 // Add copied children to the structure without firing events.
362                 for (RocketComponent child : this.children) {
363                         RocketComponent childCopy = child.copyWithOriginalID();
364                         // Don't use add method since it fires events
365                         clone.children.add(childCopy);
366                         childCopy.parent = clone;
367                 }
368                 
369                 return clone;
370         }
371         
372         
373         //////////////  Methods that may not be overridden  ////////////
374         
375
376
377         ////////// Common parameter setting/getting //////////
378         
379         /**
380          * Return the color of the object to use in 2D figures, or <code>null</code>
381          * to use the default color.
382          */
383         public final Color getColor() {
384                 checkState();
385                 return color;
386         }
387         
388         /**
389          * Set the color of the object to use in 2D figures.  
390          */
391         public final void setColor(Color c) {
392                 checkState();
393                 if ((color == null && c == null) ||
394                                 (color != null && color.equals(c)))
395                         return;
396                 
397                 this.color = c;
398                 fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
399         }
400         
401         
402         public final LineStyle getLineStyle() {
403                 checkState();
404                 return lineStyle;
405         }
406         
407         public final void setLineStyle(LineStyle style) {
408                 checkState();
409                 if (this.lineStyle == style)
410                         return;
411                 this.lineStyle = style;
412                 fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
413         }
414         
415         
416
417
418         /**
419          * Get the current override mass.  The mass is not necessarily in use
420          * at the moment.
421          * 
422          * @return  the override mass
423          */
424         public final double getOverrideMass() {
425                 checkState();
426                 return overrideMass;
427         }
428         
429         /**
430          * Set the current override mass.  The mass is not set to use by this
431          * method.
432          * 
433          * @param m  the override mass
434          */
435         public final void setOverrideMass(double m) {
436                 checkState();
437                 overrideMass = Math.max(m, 0);
438                 if (massOverriden)
439                         fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
440         }
441         
442         /**
443          * Return whether mass override is active for this component.  This does NOT
444          * take into account whether a parent component is overriding the mass.
445          * 
446          * @return  whether the mass is overridden
447          */
448         public final boolean isMassOverridden() {
449                 checkState();
450                 return massOverriden;
451         }
452         
453         /**
454          * Set whether the mass is currently overridden.
455          * 
456          * @param o  whether the mass is overridden
457          */
458         public final void setMassOverridden(boolean o) {
459                 checkState();
460                 if (massOverriden != o) {
461                         massOverriden = o;
462                         fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
463                 }
464         }
465         
466         
467
468
469
470         /**
471          * Return the current override CG.  The CG is not necessarily overridden.
472          * 
473          * @return  the override CG
474          */
475         public final Coordinate getOverrideCG() {
476                 checkState();
477                 return getComponentCG().setX(overrideCGX);
478         }
479         
480         /**
481          * Return the x-coordinate of the current override CG.
482          * 
483          * @return      the x-coordinate of the override CG.
484          */
485         public final double getOverrideCGX() {
486                 checkState();
487                 return overrideCGX;
488         }
489         
490         /**
491          * Set the current override CG to (x,0,0).
492          * 
493          * @param x  the x-coordinate of the override CG to set.
494          */
495         public final void setOverrideCGX(double x) {
496                 checkState();
497                 if (MathUtil.equals(overrideCGX, x))
498                         return;
499                 this.overrideCGX = x;
500                 if (isCGOverridden())
501                         fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
502                 else
503                         fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
504         }
505         
506         /**
507          * Return whether the CG is currently overridden.
508          * 
509          * @return  whether the CG is overridden
510          */
511         public final boolean isCGOverridden() {
512                 checkState();
513                 return cgOverriden;
514         }
515         
516         /**
517          * Set whether the CG is currently overridden.
518          * 
519          * @param o  whether the CG is overridden
520          */
521         public final void setCGOverridden(boolean o) {
522                 checkState();
523                 if (cgOverriden != o) {
524                         cgOverriden = o;
525                         fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
526                 }
527         }
528         
529         
530
531         /**
532          * Return whether the mass and/or CG override overrides all subcomponent values
533          * as well.  The default implementation is a normal getter/setter implementation,
534          * however, subclasses are allowed to override this behavior if some subclass
535          * always or never overrides subcomponents.  In this case the subclass should
536          * also override {@link #isOverrideSubcomponentsEnabled()} to return
537          * <code>false</code>.
538          * 
539          * @return      whether the current mass and/or CG override overrides subcomponents as well.
540          */
541         public boolean getOverrideSubcomponents() {
542                 checkState();
543                 return overrideSubcomponents;
544         }
545         
546         
547         /**
548          * Set whether the mass and/or CG override overrides all subcomponent values
549          * as well.  See {@link #getOverrideSubcomponents()} for details.
550          * 
551          * @param override      whether the mass and/or CG override overrides all subcomponent.
552          */
553         public void setOverrideSubcomponents(boolean override) {
554                 checkState();
555                 if (overrideSubcomponents != override) {
556                         overrideSubcomponents = override;
557                         fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
558                 }
559         }
560         
561         /**
562          * Return whether the option to override all subcomponents is enabled or not.
563          * The default implementation returns <code>false</code> if neither mass nor
564          * CG is overridden, <code>true</code> otherwise.
565          * <p>
566          * This method may be overridden if the setting of overriding subcomponents
567          * cannot be set.
568          * 
569          * @return      whether the option to override subcomponents is currently enabled.
570          */
571         public boolean isOverrideSubcomponentsEnabled() {
572                 checkState();
573                 return isCGOverridden() || isMassOverridden();
574         }
575         
576         
577
578
579         /**
580          * Get the user-defined name of the component.
581          */
582         public final String getName() {
583                 return name;
584         }
585         
586         /**
587          * Set the user-defined name of the component.  If name==null, sets the name to
588          * the default name, currently the component name.
589          */
590         public final void setName(String name) {
591                 checkState();
592                 if (name == null || name.matches("^\\s*$"))
593                         this.name = getComponentName();
594                 else
595                         this.name = name;
596                 fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
597         }
598         
599         
600         /**
601          * Return the comment of the component.  The component may contain multiple lines
602          * using \n as a newline separator.
603          * 
604          * @return  the comment of the component.
605          */
606         public final String getComment() {
607                 checkState();
608                 return comment;
609         }
610         
611         /**
612          * Set the comment of the component.
613          * 
614          * @param comment  the comment of the component.
615          */
616         public final void setComment(String comment) {
617                 checkState();
618                 if (this.comment.equals(comment))
619                         return;
620                 if (comment == null)
621                         this.comment = "";
622                 else
623                         this.comment = comment;
624                 fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
625         }
626         
627         
628
629         /**
630          * Returns the unique ID of the component.
631          * 
632          * @return      the ID of the component.
633          */
634         public final String getID() {
635                 return id;
636         }
637         
638         /**
639          * Generate a new ID for this component.
640          */
641         private final void newID() {
642                 this.id = UniqueID.uuid();
643         }
644         
645         
646
647
648         /**
649          * Get the characteristic length of the component, for example the length of a body tube
650          * of the length of the root chord of a fin.  This is used in positioning the component
651          * relative to its parent.
652          * 
653          * If the length of a component is settable, the class must define the setter method
654          * itself.
655          */
656         public final double getLength() {
657                 checkState();
658                 return length;
659         }
660         
661         /**
662          * Get the positioning of the component relative to its parent component.
663          * This is one of the enums of {@link Position}.  A setter method is not provided,
664          * but can be provided by a subclass.
665          */
666         public final Position getRelativePosition() {
667                 checkState();
668                 return relativePosition;
669         }
670         
671         
672         /**
673          * Set the positioning of the component relative to its parent component.
674          * The actual position of the component is maintained to the best ability.
675          * <p>
676          * The default implementation is of protected visibility, since many components
677          * do not support setting the relative position.  A component that does support
678          * it should override this with a public method that simply calls this
679          * supermethod AND fire a suitable ComponentChangeEvent.
680          * 
681          * @param position      the relative positioning.
682          */
683         protected void setRelativePosition(RocketComponent.Position position) {
684                 checkState();
685                 if (this.relativePosition == position)
686                         return;
687                 
688                 // Update position so as not to move the component
689                 if (this.parent != null) {
690                         double thisPos = this.toRelative(Coordinate.NUL, this.parent)[0].x;
691                         
692                         switch (position) {
693                         case ABSOLUTE:
694                                 this.position = this.toAbsolute(Coordinate.NUL)[0].x;
695                                 break;
696                         
697                         case TOP:
698                                 this.position = thisPos;
699                                 break;
700                         
701                         case MIDDLE:
702                                 this.position = thisPos - (this.parent.length - this.length) / 2;
703                                 break;
704                         
705                         case BOTTOM:
706                                 this.position = thisPos - (this.parent.length - this.length);
707                                 break;
708                         
709                         default:
710                                 throw new BugException("Unknown position type: " + position);
711                         }
712                 }
713                 
714                 this.relativePosition = position;
715                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
716         }
717         
718         
719
720
721         /**
722          * Get the position value of the component.  The exact meaning of the value is
723          * dependent on the current relative positioning.
724          * 
725          * @return  the positional value.
726          */
727         public final double getPositionValue() {
728                 checkState();
729                 return position;
730         }
731         
732         
733         /**
734          * Set the position value of the component.  The exact meaning of the value
735          * depends on the current relative positioning.
736          * <p>
737          * The default implementation is of protected visibility, since many components
738          * do not support setting the relative position.  A component that does support
739          * it should override this with a public method that simply calls this
740          * supermethod AND fire a suitable ComponentChangeEvent.
741          * 
742          * @param value         the position value of the component.
743          */
744         public void setPositionValue(double value) {
745                 checkState();
746                 if (MathUtil.equals(this.position, value))
747                         return;
748                 this.position = value;
749         }
750         
751         
752
753         ///////////  Coordinate changes  ///////////
754         
755         /**
756          * Returns coordinate c in absolute coordinates.  Equivalent to toComponent(c,null).
757          */
758         public Coordinate[] toAbsolute(Coordinate c) {
759                 checkState();
760                 return toRelative(c, null);
761         }
762         
763         
764         /**
765          * Return coordinate <code>c</code> described in the coordinate system of 
766          * <code>dest</code>.  If <code>dest</code> is <code>null</code> returns
767          * absolute coordinates.
768          * <p>
769          * This method returns an array of coordinates, each of which represents a
770          * position of the coordinate in clustered cases.  The array is guaranteed
771          * to contain at least one element.  
772          * <p>
773          * The current implementation does not support rotating components.
774          * 
775          * @param c    Coordinate in the component's coordinate system.
776          * @param dest Destination component coordinate system.
777          * @return     an array of coordinates describing <code>c</code> in coordinates
778          *                         relative to <code>dest</code>.
779          */
780         public final Coordinate[] toRelative(Coordinate c, RocketComponent dest) {
781                 checkState();
782                 double absoluteX = Double.NaN;
783                 RocketComponent search = dest;
784                 Coordinate[] array = new Coordinate[1];
785                 array[0] = c;
786                 
787                 RocketComponent component = this;
788                 while ((component != search) && (component.parent != null)) {
789                         
790                         array = component.shiftCoordinates(array);
791                         
792                         switch (component.relativePosition) {
793                         case TOP:
794                                 for (int i = 0; i < array.length; i++) {
795                                         array[i] = array[i].add(component.position, 0, 0);
796                                 }
797                                 break;
798                         
799                         case MIDDLE:
800                                 for (int i = 0; i < array.length; i++) {
801                                         array[i] = array[i].add(component.position +
802                                                         (component.parent.length - component.length) / 2, 0, 0);
803                                 }
804                                 break;
805                         
806                         case BOTTOM:
807                                 for (int i = 0; i < array.length; i++) {
808                                         array[i] = array[i].add(component.position +
809                                                         (component.parent.length - component.length), 0, 0);
810                                 }
811                                 break;
812                         
813                         case AFTER:
814                                 // Add length of all previous brother-components with POSITION_RELATIVE_AFTER
815                                 int index = component.parent.children.indexOf(component);
816                                 assert (index >= 0);
817                                 for (index--; index >= 0; index--) {
818                                         RocketComponent comp = component.parent.children.get(index);
819                                         double length = comp.getTotalLength();
820                                         for (int i = 0; i < array.length; i++) {
821                                                 array[i] = array[i].add(length, 0, 0);
822                                         }
823                                 }
824                                 for (int i = 0; i < array.length; i++) {
825                                         array[i] = array[i].add(component.position + component.parent.length, 0, 0);
826                                 }
827                                 break;
828                         
829                         case ABSOLUTE:
830                                 search = null; // Requires back-search if dest!=null
831                                 if (Double.isNaN(absoluteX)) {
832                                         absoluteX = component.position;
833                                 }
834                                 break;
835                         
836                         default:
837                                 throw new BugException("Unknown relative positioning type of component" +
838                                                 component + ": " + component.relativePosition);
839                         }
840                         
841                         component = component.parent; // parent != null
842                 }
843                 
844                 if (!Double.isNaN(absoluteX)) {
845                         for (int i = 0; i < array.length; i++) {
846                                 array[i] = array[i].setX(absoluteX + c.x);
847                         }
848                 }
849                 
850                 // Check whether destination has been found or whether to backtrack
851                 // TODO: LOW: Backtracking into clustered components uses only one component 
852                 if ((dest != null) && (component != dest)) {
853                         Coordinate[] origin = dest.toAbsolute(Coordinate.NUL);
854                         for (int i = 0; i < array.length; i++) {
855                                 array[i] = array[i].sub(origin[0]);
856                         }
857                 }
858                 
859                 return array;
860         }
861         
862         
863         /**
864          * Recursively sum the lengths of all subcomponents that have position 
865          * Position.AFTER.
866          * 
867          * @return  Sum of the lengths.
868          */
869         private final double getTotalLength() {
870                 checkState();
871                 double l = 0;
872                 if (relativePosition == Position.AFTER)
873                         l = length;
874                 for (int i = 0; i < children.size(); i++)
875                         l += children.get(i).getTotalLength();
876                 return l;
877         }
878         
879         
880
881         /////////// Total mass and CG calculation ////////////
882         
883         /**
884          * Return the (possibly overridden) mass of component.
885          * 
886          * @return The mass of the component or the given override mass.
887          */
888         public final double getMass() {
889                 checkState();
890                 if (massOverriden)
891                         return overrideMass;
892                 return getComponentMass();
893         }
894         
895         /**
896          * Return the (possibly overridden) center of gravity and mass.
897          * 
898          * Returns the CG with the weight of the coordinate set to the weight of the component.
899          * Both CG and mass may be separately overridden.
900          * 
901          * @return The CG of the component or the given override CG.
902          */
903         public final Coordinate getCG() {
904                 checkState();
905                 if (cgOverriden)
906                         return getOverrideCG().setWeight(getMass());
907                 
908                 if (massOverriden)
909                         return getComponentCG().setWeight(getMass());
910                 
911                 return getComponentCG();
912         }
913         
914         
915         /**
916          * Return the longitudal (around the y- or z-axis) moment of inertia of this component.
917          * The moment of inertia is scaled in reference to the (possibly overridden) mass
918          * and is relative to the non-overridden CG.
919          * 
920          * @return    the longitudal moment of inertia of this component.
921          */
922         public final double getLongitudalInertia() {
923                 checkState();
924                 return getLongitudalUnitInertia() * getMass();
925         }
926         
927         /**
928          * Return the rotational (around the y- or z-axis) moment of inertia of this component.
929          * The moment of inertia is scaled in reference to the (possibly overridden) mass
930          * and is relative to the non-overridden CG.
931          * 
932          * @return    the rotational moment of inertia of this component.
933          */
934         public final double getRotationalInertia() {
935                 checkState();
936                 return getRotationalUnitInertia() * getMass();
937         }
938         
939         
940
941         ///////////  Children handling  ///////////
942         
943
944         /**
945          * Adds a child to the rocket component tree.  The component is added to the end
946          * of the component's child list.  This is a helper method that calls 
947          * {@link #addChild(RocketComponent,int)}.
948          * 
949          * @param component  The component to add.
950          * @throws IllegalArgumentException  if the component is already part of some 
951          *                                                                       component tree.
952          * @see #addChild(RocketComponent,int)
953          */
954         public final void addChild(RocketComponent component) {
955                 checkState();
956                 addChild(component, children.size());
957         }
958         
959         
960         /**
961          * Adds a child to the rocket component tree.  The component is added to 
962          * the given position of the component's child list.
963          * <p>
964          * This method may be overridden to enforce more strict component addition rules.  
965          * The tests should be performed first and then this method called.
966          * 
967          * @param component  The component to add.
968          * @param position   Position to add component to.
969          * @throws IllegalArgumentException  If the component is already part of 
970          *                                                                       some component tree.
971          */
972         public void addChild(RocketComponent component, int position) {
973                 checkState();
974                 if (component.parent != null) {
975                         throw new IllegalArgumentException("component " + component.getComponentName() +
976                                         " is already in a tree");
977                 }
978                 if (!isCompatible(component)) {
979                         throw new IllegalStateException("Component " + component.getComponentName() +
980                                         " not currently compatible with component " + getComponentName());
981                 }
982                 
983                 children.add(position, component);
984                 component.parent = this;
985                 
986                 fireAddRemoveEvent(component);
987         }
988         
989         
990         /**
991          * Removes a child from the rocket component tree.
992          * 
993          * @param n  remove the n'th child.
994          * @throws IndexOutOfBoundsException  if n is out of bounds
995          */
996         public final void removeChild(int n) {
997                 checkState();
998                 RocketComponent component = children.remove(n);
999                 component.parent = null;
1000                 fireAddRemoveEvent(component);
1001         }
1002         
1003         /**
1004          * Removes a child from the rocket component tree.  Does nothing if the component
1005          * is not present as a child.
1006          * 
1007          * @param component             the component to remove
1008          * @return                              whether the component was a child
1009          */
1010         public final boolean removeChild(RocketComponent component) {
1011                 checkState();
1012                 if (children.remove(component)) {
1013                         component.parent = null;
1014                         fireAddRemoveEvent(component);
1015                         return true;
1016                 }
1017                 return false;
1018         }
1019         
1020         
1021
1022
1023         /**
1024          * Move a child to another position.
1025          * 
1026          * @param component     the component to move
1027          * @param position      the component's new position
1028          * @throws IllegalArgumentException If an illegal placement was attempted.
1029          */
1030         public final void moveChild(RocketComponent component, int position) {
1031                 checkState();
1032                 if (children.remove(component)) {
1033                         children.add(position, component);
1034                         fireAddRemoveEvent(component);
1035                 }
1036         }
1037         
1038         
1039         /**
1040          * Fires an AERODYNAMIC_CHANGE, MASS_CHANGE or OTHER_CHANGE event depending on the
1041          * type of component removed.
1042          */
1043         private void fireAddRemoveEvent(RocketComponent component) {
1044                 Iterator<RocketComponent> iter = component.deepIterator(true);
1045                 int type = ComponentChangeEvent.TREE_CHANGE;
1046                 while (iter.hasNext()) {
1047                         RocketComponent c = iter.next();
1048                         if (c.isAerodynamic())
1049                                 type |= ComponentChangeEvent.AERODYNAMIC_CHANGE;
1050                         if (c.isMassive())
1051                                 type |= ComponentChangeEvent.MASS_CHANGE;
1052                 }
1053                 
1054                 fireComponentChangeEvent(type);
1055         }
1056         
1057         
1058         public final int getChildCount() {
1059                 checkState();
1060                 return children.size();
1061         }
1062         
1063         public final RocketComponent getChild(int n) {
1064                 checkState();
1065                 return children.get(n);
1066         }
1067         
1068         public final RocketComponent[] getChildren() {
1069                 checkState();
1070                 return children.toArray(new RocketComponent[0]);
1071         }
1072         
1073         
1074         /**
1075          * Returns the position of the child in this components child list, or -1 if the
1076          * component is not a child of this component.
1077          * 
1078          * @param child  The child to search for.
1079          * @return  Position in the list or -1 if not found.
1080          */
1081         public final int getChildPosition(RocketComponent child) {
1082                 checkState();
1083                 return children.indexOf(child);
1084         }
1085         
1086         /**
1087          * Get the parent component of this component.  Returns <code>null</code> if the component
1088          * has no parent.
1089          * 
1090          * @return  The parent of this component or <code>null</code>.
1091          */
1092         public final RocketComponent getParent() {
1093                 checkState();
1094                 return parent;
1095         }
1096         
1097         /**
1098          * Get the root component of the component tree.
1099          * 
1100          * @return  The root component of the component tree.
1101          */
1102         public final RocketComponent getRoot() {
1103                 checkState();
1104                 RocketComponent gp = this;
1105                 while (gp.parent != null)
1106                         gp = gp.parent;
1107                 return gp;
1108         }
1109         
1110         /**
1111          * Returns the root Rocket component of this component tree.  Throws an 
1112          * IllegalStateException if the root component is not a Rocket.
1113          * 
1114          * @return  The root Rocket component of the component tree.
1115          * @throws  IllegalStateException  If the root component is not a Rocket.
1116          */
1117         public final Rocket getRocket() {
1118                 checkState();
1119                 RocketComponent r = getRoot();
1120                 if (r instanceof Rocket)
1121                         return (Rocket) r;
1122                 throw new IllegalStateException("getRocket() called with root component "
1123                                 + r.getComponentName());
1124         }
1125         
1126         
1127         /**
1128          * Return the Stage component that this component belongs to.  Throws an
1129          * IllegalStateException if a Stage is not in the parentage of this component.
1130          * 
1131          * @return      The Stage component this component belongs to.
1132          * @throws      IllegalStateException   if a Stage component is not in the parentage.
1133          */
1134         public final Stage getStage() {
1135                 checkState();
1136                 RocketComponent c = this;
1137                 while (c != null) {
1138                         if (c instanceof Stage)
1139                                 return (Stage) c;
1140                         c = c.getParent();
1141                 }
1142                 throw new IllegalStateException("getStage() called without Stage as a parent.");
1143         }
1144         
1145         /**
1146          * Return the stage number of the stage this component belongs to.  The stages
1147          * are numbered from zero upwards.
1148          * 
1149          * @return   the stage number this component belongs to.
1150          */
1151         public final int getStageNumber() {
1152                 checkState();
1153                 if (parent == null) {
1154                         throw new IllegalArgumentException("getStageNumber() called for root component");
1155                 }
1156                 
1157                 RocketComponent stage = this;
1158                 while (!(stage instanceof Stage)) {
1159                         stage = stage.parent;
1160                         if (stage == null || stage.parent == null) {
1161                                 throw new IllegalStateException("getStageNumber() could not find parent " +
1162                                                 "stage.");
1163                         }
1164                 }
1165                 return stage.parent.getChildPosition(stage);
1166         }
1167         
1168         
1169         /**
1170          * Find a component with the given ID.  The component tree is searched from this component
1171          * down (including this component) for the ID and the corresponding component is returned,
1172          * or null if not found.
1173          * 
1174          * @param idToFind  ID to search for.
1175          * @return    The component with the ID, or null if not found.
1176          */
1177         public final RocketComponent findComponent(String idToFind) {
1178                 checkState();
1179                 Iterator<RocketComponent> iter = this.deepIterator(true);
1180                 while (iter.hasNext()) {
1181                         RocketComponent c = iter.next();
1182                         if (c.getID().equals(idToFind))
1183                                 return c;
1184                 }
1185                 return null;
1186         }
1187         
1188         
1189         public final RocketComponent getPreviousComponent() {
1190                 checkState();
1191                 if (parent == null)
1192                         return null;
1193                 int pos = parent.getChildPosition(this);
1194                 if (pos < 0) {
1195                         StringBuffer sb = new StringBuffer();
1196                         sb.append("Inconsistent internal state: ");
1197                         sb.append("this=").append(this).append('[')
1198                                         .append(System.identityHashCode(this)).append(']');
1199                         sb.append(" parent.children=[");
1200                         for (int i = 0; i < parent.children.size(); i++) {
1201                                 RocketComponent c = parent.children.get(i);
1202                                 sb.append(c).append('[').append(System.identityHashCode(c)).append(']');
1203                                 if (i < parent.children.size() - 1)
1204                                         sb.append(", ");
1205                         }
1206                         sb.append(']');
1207                         throw new IllegalStateException(sb.toString());
1208                 }
1209                 assert (pos >= 0);
1210                 if (pos == 0)
1211                         return parent;
1212                 RocketComponent c = parent.getChild(pos - 1);
1213                 while (c.getChildCount() > 0)
1214                         c = c.getChild(c.getChildCount() - 1);
1215                 return c;
1216         }
1217         
1218         public final RocketComponent getNextComponent() {
1219                 checkState();
1220                 if (getChildCount() > 0)
1221                         return getChild(0);
1222                 
1223                 RocketComponent current = this;
1224                 RocketComponent parent = this.parent;
1225                 
1226                 while (parent != null) {
1227                         int pos = parent.getChildPosition(current);
1228                         if (pos < parent.getChildCount() - 1)
1229                                 return parent.getChild(pos + 1);
1230                         
1231                         current = parent;
1232                         parent = current.parent;
1233                 }
1234                 return null;
1235         }
1236         
1237         
1238         ///////////  Event handling  //////////
1239         //
1240         // Listener lists are provided by the root Rocket component,
1241         // a single listener list for the whole rocket.
1242         //
1243         
1244         /**
1245          * Adds a ComponentChangeListener to the rocket tree.  The listener is added to the root
1246          * component, which must be of type Rocket (which overrides this method).  Events of all
1247          * subcomponents are sent to all listeners.
1248          * 
1249          * @throws IllegalStateException - if the root component is not a Rocket
1250          */
1251         public void addComponentChangeListener(ComponentChangeListener l) {
1252                 checkState();
1253                 getRocket().addComponentChangeListener(l);
1254         }
1255         
1256         /**
1257          * Removes a ComponentChangeListener from the rocket tree.  The listener is removed from
1258          * the root component, which must be of type Rocket (which overrides this method).
1259          * Does nothing if the root component is not a Rocket.  (The asymmetry is so
1260          * that listeners can always be removed just in case.)
1261          * 
1262          * @param l  Listener to remove
1263          */
1264         public void removeComponentChangeListener(ComponentChangeListener l) {
1265                 if (parent != null) {
1266                         getRoot().removeComponentChangeListener(l);
1267                 }
1268         }
1269         
1270         
1271         /**
1272          * Adds a <code>ChangeListener</code> to the rocket tree.  This is identical to 
1273          * <code>addComponentChangeListener()</code> except that it uses a 
1274          * <code>ChangeListener</code>.  The same events are dispatched to the
1275          * <code>ChangeListener</code>, as <code>ComponentChangeEvent</code> is a subclass 
1276          * of <code>ChangeEvent</code>.
1277          * 
1278          * @throws IllegalStateException - if the root component is not a <code>Rocket</code>
1279          */
1280         public void addChangeListener(ChangeListener l) {
1281                 checkState();
1282                 getRocket().addChangeListener(l);
1283         }
1284         
1285         /**
1286          * Removes a ChangeListener from the rocket tree.  This is identical to
1287          * removeComponentChangeListener() except it uses a ChangeListener.
1288          * Does nothing if the root component is not a Rocket.  (The asymmetry is so
1289          * that listeners can always be removed just in case.)
1290          * 
1291          * @param l  Listener to remove
1292          */
1293         public void removeChangeListener(ChangeListener l) {
1294                 if (this.parent != null) {
1295                         getRoot().removeChangeListener(l);
1296                 }
1297         }
1298         
1299         
1300         /**
1301          * Fires a ComponentChangeEvent on the rocket structure.  The call is passed to the 
1302          * root component, which must be of type Rocket (which overrides this method).
1303          * Events of all subcomponents are sent to all listeners.
1304          * 
1305          * If the component tree root is not a Rocket, the event is ignored.  This is the 
1306          * case when constructing components not in any Rocket tree.  In this case it 
1307          * would be impossible for the component to have listeners in any case.
1308          *  
1309          * @param e  Event to send
1310          */
1311         protected void fireComponentChangeEvent(ComponentChangeEvent e) {
1312                 checkState();
1313                 if (parent == null) {
1314                         /* Ignore if root invalid. */
1315                         return;
1316                 }
1317                 getRoot().fireComponentChangeEvent(e);
1318         }
1319         
1320         
1321         /**
1322          * Fires a ComponentChangeEvent of the given type.  The source of the event is set to
1323          * this component.
1324          * 
1325          * @param type  Type of event
1326          * @see #fireComponentChangeEvent(ComponentChangeEvent)
1327          */
1328         protected void fireComponentChangeEvent(int type) {
1329                 fireComponentChangeEvent(new ComponentChangeEvent(this, type));
1330         }
1331         
1332         
1333         /**
1334          * Checks whether this component has been invalidated and should no longer be used.
1335          * This is a safety check that in-place replaced components are no longer used.
1336          * All non-trivial methods should call this method as the first thing, unless the
1337          * method may be used in debugging cases.
1338          * 
1339          * @throws      BugException    if this component has been invalidated by {@link #copyFrom(RocketComponent)}.
1340          */
1341         protected void checkState() {
1342                 if (invalidated != null) {
1343                         throw new BugException("This component has been invalidated.  Cause is the point of invalidation.",
1344                                         invalidated);
1345                 }
1346         }
1347         
1348         
1349         ///////////  Iterator implementation  //////////
1350         
1351         /**
1352          * Private inner class to implement the Iterator.
1353          * 
1354          * This iterator is fail-fast if the root of the structure is a Rocket.
1355          */
1356         private class RocketComponentIterator implements Iterator<RocketComponent> {
1357                 // Stack holds iterators which still have some components left.
1358                 private final Stack<Iterator<RocketComponent>> iteratorstack =
1359                                         new Stack<Iterator<RocketComponent>>();
1360                 
1361                 private final Rocket root;
1362                 private final int treeModID;
1363                 
1364                 private final RocketComponent original;
1365                 private boolean returnSelf = false;
1366                 
1367                 // Construct iterator with component's child's iterator, if it has elements
1368                 public RocketComponentIterator(RocketComponent c, boolean returnSelf) {
1369                         
1370                         RocketComponent gp = c.getRoot();
1371                         if (gp instanceof Rocket) {
1372                                 root = (Rocket) gp;
1373                                 treeModID = root.getTreeModID();
1374                         } else {
1375                                 root = null;
1376                                 treeModID = -1;
1377                         }
1378                         
1379                         Iterator<RocketComponent> i = c.children.iterator();
1380                         if (i.hasNext())
1381                                 iteratorstack.push(i);
1382                         
1383                         this.original = c;
1384                         this.returnSelf = returnSelf;
1385                 }
1386                 
1387                 public boolean hasNext() {
1388                         checkState();
1389                         checkID();
1390                         if (returnSelf)
1391                                 return true;
1392                         return !iteratorstack.empty(); // Elements remain if stack is not empty
1393                 }
1394                 
1395                 public RocketComponent next() {
1396                         Iterator<RocketComponent> i;
1397                         
1398                         checkState();
1399                         checkID();
1400                         
1401                         // Return original component first
1402                         if (returnSelf) {
1403                                 returnSelf = false;
1404                                 return original;
1405                         }
1406                         
1407                         // Peek first iterator from stack, throw exception if empty
1408                         try {
1409                                 i = iteratorstack.peek();
1410                         } catch (EmptyStackException e) {
1411                                 throw new NoSuchElementException("No further elements in " +
1412                                                 "RocketComponent iterator");
1413                         }
1414                         
1415                         // Retrieve next component of the iterator, remove iterator from stack if empty
1416                         RocketComponent c = i.next();
1417                         if (!i.hasNext())
1418                                 iteratorstack.pop();
1419                         
1420                         // Add iterator of component children to stack if it has children
1421                         i = c.children.iterator();
1422                         if (i.hasNext())
1423                                 iteratorstack.push(i);
1424                         
1425                         return c;
1426                 }
1427                 
1428                 private void checkID() {
1429                         if (root != null) {
1430                                 if (root.getTreeModID() != treeModID) {
1431                                         throw new IllegalStateException("Rocket modified while being iterated");
1432                                 }
1433                         }
1434                 }
1435                 
1436                 public void remove() {
1437                         throw new UnsupportedOperationException("remove() not supported by " +
1438                                         "RocketComponent iterator");
1439                 }
1440         }
1441         
1442         /**
1443          * Returns an iterator that iterates over all children and sub-children.
1444          * 
1445          * The iterator iterates through all children below this object, including itself if
1446          * returnSelf is true.  The order of the iteration is not specified
1447          * (it may be specified in the future).
1448          * 
1449          * If an iterator iterating over only the direct children of the component is required,
1450          * use  component.getChildren().iterator()
1451          * 
1452          * @param returnSelf boolean value specifying whether the component itself should be 
1453          *                                       returned
1454          * @return An iterator for the children and sub-children.
1455          */
1456         public final Iterator<RocketComponent> deepIterator(boolean returnSelf) {
1457                 checkState();
1458                 return new RocketComponentIterator(this, returnSelf);
1459         }
1460         
1461         /**
1462          * Returns an iterator that iterates over all children and sub-children.
1463          * 
1464          * The iterator does NOT return the component itself.  It is thus equivalent to
1465          * deepIterator(false).
1466          * 
1467          * @see #iterator()
1468          * @return An iterator for the children and sub-children.
1469          */
1470         public final Iterator<RocketComponent> deepIterator() {
1471                 checkState();
1472                 return new RocketComponentIterator(this, false);
1473         }
1474         
1475         
1476         /**
1477          * Return an iterator that iterates of the children of the component.  The iterator
1478          * does NOT recurse to sub-children nor return itself.
1479          * 
1480          * @return An iterator for the children.
1481          */
1482         public final Iterator<RocketComponent> iterator() {
1483                 checkState();
1484                 return Collections.unmodifiableList(children).iterator();
1485         }
1486         
1487         
1488
1489
1490         /**
1491          * Compare component equality based on the ID of this component.  Only the
1492          * ID and class type is used for a basis of comparison.
1493          */
1494         @Override
1495         public boolean equals(Object obj) {
1496                 if (this == obj)
1497                         return true;
1498                 if (obj == null)
1499                         return false;
1500                 if (this.getClass() != obj.getClass())
1501                         return false;
1502                 RocketComponent other = (RocketComponent) obj;
1503                 return this.id.equals(other.id);
1504         }
1505         
1506         
1507
1508         @Override
1509         public int hashCode() {
1510                 return id.hashCode();
1511         }
1512         
1513         
1514
1515         ////////////  Helper methods for subclasses
1516         
1517
1518
1519
1520         /**
1521          * Helper method to add rotationally symmetric bounds at the specified coordinates.
1522          * The X-axis value is <code>x</code> and the radius at the specified position is
1523          * <code>r</code>. 
1524          */
1525         protected static final void addBound(Collection<Coordinate> bounds, double x, double r) {
1526                 bounds.add(new Coordinate(x, -r, -r));
1527                 bounds.add(new Coordinate(x, r, -r));
1528                 bounds.add(new Coordinate(x, r, r));
1529                 bounds.add(new Coordinate(x, -r, r));
1530         }
1531         
1532         
1533         protected static final Coordinate ringCG(double outerRadius, double innerRadius,
1534                         double x1, double x2, double density) {
1535                 return new Coordinate((x1 + x2) / 2, 0, 0,
1536                                 ringMass(outerRadius, innerRadius, x2 - x1, density));
1537         }
1538         
1539         protected static final double ringMass(double outerRadius, double innerRadius,
1540                         double length, double density) {
1541                 return Math.PI * (MathUtil.pow2(outerRadius) - MathUtil.pow2(innerRadius)) *
1542                                         length * density;
1543         }
1544         
1545         protected static final double ringLongitudalUnitInertia(double outerRadius,
1546                         double innerRadius, double length) {
1547                 // 1/12 * (3 * (r1^2 + r2^2) + h^2)
1548                 return (3 * (MathUtil.pow2(innerRadius) + MathUtil.pow2(outerRadius)) + MathUtil.pow2(length)) / 12;
1549         }
1550         
1551         protected static final double ringRotationalUnitInertia(double outerRadius,
1552                         double innerRadius) {
1553                 // 1/2 * (r1^2 + r2^2)
1554                 return (MathUtil.pow2(innerRadius) + MathUtil.pow2(outerRadius)) / 2;
1555         }
1556         
1557         
1558
1559         ////////////  OTHER
1560         
1561
1562         /**
1563          * Loads the RocketComponent fields from the given component.  This method is meant
1564          * for in-place replacement of a component.  It is used with the undo/redo
1565          * mechanism and when converting a finset into a freeform fin set.
1566          * This component must not have a parent, otherwise this method will fail.
1567          * <p>
1568          * The fields are copied by reference, and the supplied component must not be used
1569          * after the call, as it is in an undefined state.  This is enforced by invalidating
1570          * the source component.
1571          * 
1572          * TODO: MEDIUM: Make general to copy all private/protected fields...
1573          */
1574         protected void copyFrom(RocketComponent src) {
1575                 checkState();
1576                 
1577                 if (this.parent != null) {
1578                         throw new UnsupportedOperationException("copyFrom called for non-root component "
1579                                         + this);
1580                 }
1581                 
1582                 // Set parents and children
1583                 this.children = src.children;
1584                 src.children = new ArrayList<RocketComponent>();
1585                 
1586                 for (RocketComponent c : this.children) {
1587                         c.parent = this;
1588                 }
1589                 
1590                 // Set all parameters
1591                 this.length = src.length;
1592                 this.relativePosition = src.relativePosition;
1593                 this.position = src.position;
1594                 this.color = src.color;
1595                 this.lineStyle = src.lineStyle;
1596                 this.overrideMass = src.overrideMass;
1597                 this.massOverriden = src.massOverriden;
1598                 this.overrideCGX = src.overrideCGX;
1599                 this.cgOverriden = src.cgOverriden;
1600                 this.overrideSubcomponents = src.overrideSubcomponents;
1601                 this.name = src.name;
1602                 this.comment = src.comment;
1603                 this.id = src.id;
1604                 
1605                 src.invalidated = new TraceException();
1606         }
1607         
1608 }