1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
module dataObjects.AbstractObject;
import dcollections.ArrayList;
//import tango.core.Array;
import tango.text.Util;
package import graphics.Renderer;
import graphics.Color;
import dataObjects.Bound;
import tango.io.Stdout;
char[] getFileName(char[] fullPath)
{
char[] delimiter = "/";
version (windows)
{
delimiter = "\\";
}
char[][] strList = split(fullPath, delimiter);
char[] retVal = strList[strList.length-1];
return retVal;
}
abstract class AbstractObject
{
protected:
ArrayList!(AbstractObject) _children;
// AbstractObject[] _children;
private:
AbstractObject _parent;
public:
char[] objectName;
this(AbstractObject parentObject = null)
{
_parent = parentObject;
_children = new ArrayList!(AbstractObject);
}
abstract void acceptRenderer(Renderer renderer);
Bound bound;
void calculateBounds(inout Bound globalBound)
{
if (!globalBound.newCountCycle)
{
globalBound.minX = bound.minX;
globalBound.maxX = bound.maxX;
globalBound.minY = bound.minY;
globalBound.maxY = bound.maxY;
globalBound.minZ = bound.minZ;
globalBound.maxZ = bound.maxZ;
globalBound.newCountCycle = true;
return;
}
if ( bound.minX < globalBound.minX)
globalBound.minX = bound.minX;
if ( bound.maxX > globalBound.maxX)
globalBound.maxX = bound.maxX;
if ( bound.minY < globalBound.minY)
globalBound.minY = bound.minY;
if ( bound.maxY > globalBound.maxY)
globalBound.maxY = bound.maxY;
if ( bound.minZ < globalBound.minZ)
globalBound.minZ = bound.minZ;
if ( bound.maxZ > globalBound.maxZ)
globalBound.maxZ = bound.maxZ;
}
bool visible;
/* Tree functionality */
AbstractObject parent() { return _parent; }
void appendChild(AbstractObject child)
{
_children.add(child);
// _children ~= child;
child._parent = this;
}
void removeChild(AbstractObject child)
{
_children.remove(child);
// remove(_children, child);
}
uint pos()
{
return parent._children.indexOf(this);
// return find(parent._children, this);
}
uint childCount()
{
return _children.length;
}
AbstractObject child(int pos)
{
if( pos > 0 || pos < _children.length )
return _children[pos];
else
return null;
}
}
template SingleColored()
{
protected Color color;
}