harmonic.mz.manager
Class DataManager

java.lang.Object
  |
  +--harmonic.mz.manager.DataManager

public class DataManager
extends java.lang.Object

This class maintains the model data state, application state, and module settings, in a large tree.

 Organization of tree with no module loaded:
 Root
  |--Application stuff
  |--module
  |--module
  |--model file
  |   |-----object list
  |   |-----view list
  |   |-----viewpoint list
  |   |-----etc
  |--model file
  |   |-----object list
  |   |-----view list
  |   |-----viewpoint list
  |   |-----etc
 


Field Summary
 harmonic.mz.docnode.GeneralSettings settings
           
 
Method Summary
 void addPrototype(java.lang.String catagory, Prototype pt)
          Sometimes it is usefull (for example in the case of the template and network editors) to for a data type to be avalible in a list that enables the user to create an instance of a type.
 void addSavedValue(ModelNode field)
          Add the node to the pool it preferes to be stored in according to field.getReferencePoolName(), assuming it is inserted into current file.
 void addSavedValue(ModelNode field, FileNode fileRoot)
          Add the node to the pool it preferes to be stored in according to field.getReferencePoolName(), in the given file.
 void addToGlobals(DataNode node)
          Adds node to global objects group
 void addToTemps(DataNode node)
          Adds node to temporaray objects group
 void addTreeListener(NodeListener listener)
          To monitor the entire database tree, add a listener here.
 void assignFromDefaultPrototype(ModelNode node)
           
 void beginBigAdd()
          Call before a large group of additions.
 void bindBindables(ModelNode root)
          Sync to bBound switch in ModelNode, usually after file read.
 void bindNode(ModelNode node, java.lang.String listName)
          Ask the specified node to "bind", which usually means take effect globaly.
 void checkSerialNo(DataNode node, FileNode fileRoot)
          This is called upon addition of nodes to make sure it and its children have valid serial numbers.
 void copyNodes(DataNode[] set, ModelNode destination, boolean bUnlink, boolean bKeepUndo)
           
 boolean doingBigAdd()
          Returns whether we are between beginBigAdd() and endBigAdd()
 void endBigAdd()
          Call after large group of additions if beginBigAdd() was called.
 void explodeCompositedObject(DataNode composite)
          This is a sort of localized undo.
 FileNode fileRoot(DataNode dbnode)
          Return the file that this node belongs too, or null.
 DataNode findNode_Full(java.lang.String s, DataNode p)
          For a string in the form "name.name.name" resolve the name to a ModelNode by searching through the file tree.
 DataNode findNode(java.lang.String s)
          Find the node of the given name under the current file
 DataNode findNode(java.lang.String searchName, DataNode subtree)
          Find the first node of the given name in under the given subtree
 java.util.Vector findNodesOfType(java.lang.String searchType, java.lang.String skipType, DataNode subtree)
           
 java.util.Vector findTagged(java.lang.String tag)
          Returns a list of objects tagged with given name in database.
 ModelNode getCurrent(ModelNode in, java.lang.String key)
          Get the current value at the given key.
 ShapeGroup getCurrentGroup()
          Returns the group objects are added to by addToCurrent().
 java.util.Vector getCurrents(ModelNode node)
          Return a list of current keys that indicates what this node is currently bound to.
 ModelNode getDefaultPrototype(java.lang.Class cls)
           
 java.util.Vector getDefaultPrototypes()
           
 harmonic.viewer3D.PaintStruct[] getPainterList(ShapeNode[] defs, boolean bRecursive)
          This is a utility to return all PaintStructs of group of ShapeDef's, and any children they have.
 java.util.Vector getPrototypes()
          Return the avalible prototypes.
 ModelNode getReferencePool(java.lang.String name, FileNode file)
          Find the root node to store value, used to store and to put up list of stored values.
 ModelNode getRoot()
          Returns the database root
 ShapeNode[] getShapeList()
          Retrieve list of all ShapeDefs in database.
 ShapeNode[] getShapeList(ModelNode file)
           
 ShapeNode[] getVisibleShapeList(ModelNode file, harmonic.viewer3D.Viewport viewport)
          Retrieve list of all ShapeDefs under given node, visible in given viewport
 boolean isInSubtree(DataNode root, DataNode node)
          Returns true if this is in the sub tree
 void makeDefaultPrototype(ModelNode node)
           
 void nameUnique(ModelNode node, java.lang.String preferredName)
          Give a node a uniqe name within the current file.
 DataNode nodeFromNumber(int serialNo, FileNode file)
          Return the node in the file with the given serial number
 void notifyListeners(NodeEvent event)
          Notifies listeners of the database tree
 long purge()
          Calls purgeInvisibleGeometries(), purgeUndoStackGeometries(), purgeUndo(), purgePickTables(true), purgeDisplayLists(), purgeAuxVerts() in the database, then runs the garbage collector.
 void purgeTree(DataNode dbnode)
          The idea here its to to make sure a sub tree that is to be irreversibly removed isn't still in memory because of the many pointers that are kept, especially by the listener system.
 void remove(DataNode[] nodes)
          Remove array of nodes.
 void remove(DataNode[] nodes, boolean bExplode)
           
 void removeFromCurrents(ModelNode node)
          Remove node from currents table.
 void removeTreeListener(NodeListener listener)
          Remove database tree listener
 void replace(ModelNode replace, ModelNode with)
          Replace 'replace' with 'with' in the parent of 'replace'
 void scanPrototypeFiles()
           
 void setCurrent(java.lang.String key, ModelNode value)
          Sets the value at the key in the current table of the current file
 void setCurrent(java.lang.String key, ModelNode node, FileNode file)
          Sets the value at the key in the current table of the given file
 ShapeGroup setCurrentGroup(ShapeGroup group)
          Sets the group objects are added to by addToCurrent().
 void setCurrentTag(java.lang.String tagName)
          Set the tag that will be applied to all newly created objects.
 void storePrototype(ModelNode node)
           
 void updateBindables(ModelNode root)
          Call updateBindable for currenly bound nodes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

settings

public harmonic.mz.docnode.GeneralSettings settings
Method Detail

getRoot

public ModelNode getRoot()
Returns the database root


addToGlobals

public void addToGlobals(DataNode node)
Adds node to global objects group


addToTemps

public void addToTemps(DataNode node)
Adds node to temporaray objects group


setCurrentTag

public void setCurrentTag(java.lang.String tagName)
Set the tag that will be applied to all newly created objects.


getCurrent

public ModelNode getCurrent(ModelNode in,
                            java.lang.String key)
Get the current value at the given key. Every model file has a table of currents, used to save the user the effort of having to respecify the same information again and again. Used for colors, DimentionFactors, etc. If the file group of in is null it is because it has not been added to the tree yet, or its parent has not been added. In this case it is a pretty good assumption that the file to use should be the current file.


getCurrents

public java.util.Vector getCurrents(ModelNode node)
Return a list of current keys that indicates what this node is currently bound to. (This will usually be an empty array, sometimes an array of one element, and rarely mulitple elements).


setCurrent

public void setCurrent(java.lang.String key,
                       ModelNode value)
Sets the value at the key in the current table of the current file

Parameters:
key - Value's key

setCurrent

public void setCurrent(java.lang.String key,
                       ModelNode node,
                       FileNode file)
Sets the value at the key in the current table of the given file

Parameters:
key - Values key
node - Value to set
file - File to get table from

removeFromCurrents

public void removeFromCurrents(ModelNode node)
Remove node from currents table.


getCurrentGroup

public ShapeGroup getCurrentGroup()
Returns the group objects are added to by addToCurrent(). This is controled by the setCurrentGroup(). This idea turns out to not be that general and may be removed.


setCurrentGroup

public ShapeGroup setCurrentGroup(ShapeGroup group)
Sets the group objects are added to by addToCurrent(). This idea turns out to not be that general and may be removed.


storePrototype

public void storePrototype(ModelNode node)

beginBigAdd

public void beginBigAdd()
Call before a large group of additions.


endBigAdd

public void endBigAdd()
Call after large group of additions if beginBigAdd() was called.


doingBigAdd

public boolean doingBigAdd()
Returns whether we are between beginBigAdd() and endBigAdd()


getShapeList

public ShapeNode[] getShapeList()
Retrieve list of all ShapeDefs in database.


getVisibleShapeList

public ShapeNode[] getVisibleShapeList(ModelNode file,
                                       harmonic.viewer3D.Viewport viewport)
Retrieve list of all ShapeDefs under given node, visible in given viewport


getShapeList

public ShapeNode[] getShapeList(ModelNode file)

getPainterList

public harmonic.viewer3D.PaintStruct[] getPainterList(ShapeNode[] defs,
                                                      boolean bRecursive)
This is a utility to return all PaintStructs of group of ShapeDef's, and any children they have.


nameUnique

public void nameUnique(ModelNode node,
                       java.lang.String preferredName)
Give a node a uniqe name within the current file. Note: this used to rely on a table of names. No longer. It now searches for matches as maintaining name table was problematic.


nodeFromNumber

public DataNode nodeFromNumber(int serialNo,
                               FileNode file)
Return the node in the file with the given serial number


isInSubtree

public boolean isInSubtree(DataNode root,
                           DataNode node)
Returns true if this is in the sub tree


findNode_Full

public DataNode findNode_Full(java.lang.String s,
                              DataNode p)
For a string in the form "name.name.name" resolve the name to a ModelNode by searching through the file tree.


findTagged

public java.util.Vector findTagged(java.lang.String tag)
Returns a list of objects tagged with given name in database.


findNode

public DataNode findNode(java.lang.String searchName,
                         DataNode subtree)
Find the first node of the given name in under the given subtree


findNodesOfType

public java.util.Vector findNodesOfType(java.lang.String searchType,
                                        java.lang.String skipType,
                                        DataNode subtree)

findNode

public DataNode findNode(java.lang.String s)
Find the node of the given name under the current file


getReferencePool

public ModelNode getReferencePool(java.lang.String name,
                                  FileNode file)
Find the root node to store value, used to store and to put up list of stored values.

Parameters:
name - Value group's name
file - Model file too look in

addSavedValue

public void addSavedValue(ModelNode field)
Add the node to the pool it preferes to be stored in according to field.getReferencePoolName(), assuming it is inserted into current file.


addSavedValue

public void addSavedValue(ModelNode field,
                          FileNode fileRoot)
Add the node to the pool it preferes to be stored in according to field.getReferencePoolName(), in the given file. This is intended for small values like colors that the user intends to store for later use. This is related to the setCurrentValue() idea.


bindNode

public void bindNode(ModelNode node,
                     java.lang.String listName)
Ask the specified node to "bind", which usually means take effect globaly. This is for viewpoints, ucs, etc. There is a list of comparable bindeables under the same parent, and only one is current at a time. Using the term "bind" to differentiate with "current" settings like colors.


bindBindables

public void bindBindables(ModelNode root)
Sync to bBound switch in ModelNode, usually after file read.


updateBindables

public void updateBindables(ModelNode root)
Call updateBindable for currenly bound nodes


fileRoot

public FileNode fileRoot(DataNode dbnode)
Return the file that this node belongs too, or null. This "caches" its findings for speed. If this node has not been added to any tree owned by a file, null is returned.


checkSerialNo

public void checkSerialNo(DataNode node,
                          FileNode fileRoot)
This is called upon addition of nodes to make sure it and its children have valid serial numbers. Durning file read, serial number is assigned from file before tree is build so it will not changes here.

The serialNo for a node will never be reassigned. No two nodes from the same file will have the same number


copyNodes

public void copyNodes(DataNode[] set,
                      ModelNode destination,
                      boolean bUnlink,
                      boolean bKeepUndo)

explodeCompositedObject

public void explodeCompositedObject(DataNode composite)
This is a sort of localized undo. Reparent all children of composited object to objects parents, and remove composited object. This is the reverse of prepare composited objects, although it doent look at the copy setting. Children to free are in the NodeSetFields.


remove

public void remove(DataNode[] nodes)
Remove array of nodes. If a node has dependances, it can't be deleted unless all of its dependances are in the list.


remove

public void remove(DataNode[] nodes,
                   boolean bExplode)

replace

public void replace(ModelNode replace,
                    ModelNode with)
Replace 'replace' with 'with' in the parent of 'replace'


purge

public long purge()
Calls purgeInvisibleGeometries(), purgeUndoStackGeometries(), purgeUndo(), purgePickTables(true), purgeDisplayLists(), purgeAuxVerts() in the database, then runs the garbage collector. The major purge clears the undo, the minor purge does not. The major purge in general may make irreversable changes to the memory state, the minorPurge only makes reversable changes.

Returns:
Number of bytes freed

purgeTree

public void purgeTree(DataNode dbnode)
The idea here its to to make sure a sub tree that is to be irreversibly removed isn't still in memory because of the many pointers that are kept, especially by the listener system. Some of the steps taken here are to minimize the trouble cause if this node is still referenced some where, which can happen so easily. It is crucial that it then doent reference anything else.


addTreeListener

public void addTreeListener(NodeListener listener)
To monitor the entire database tree, add a listener here. This should be used with caution to avoid preformance problems. Listener really needs to check the event is relevant to it and likly update asynrchonously.


removeTreeListener

public void removeTreeListener(NodeListener listener)
Remove database tree listener


notifyListeners

public void notifyListeners(NodeEvent event)
Notifies listeners of the database tree


addPrototype

public void addPrototype(java.lang.String catagory,
                         Prototype pt)
Sometimes it is usefull (for example in the case of the template and network editors) to for a data type to be avalible in a list that enables the user to create an instance of a type. If a module wants to make one of these types avalible to instantiate for a template, add the prototype here. It needs to have a public no-arg constructor, for the default Prototype.instantiate() to work.


getPrototypes

public java.util.Vector getPrototypes()
Return the avalible prototypes.

Returns:
Returns a vector of Class references.

makeDefaultPrototype

public void makeDefaultPrototype(ModelNode node)

getDefaultPrototype

public ModelNode getDefaultPrototype(java.lang.Class cls)

assignFromDefaultPrototype

public void assignFromDefaultPrototype(ModelNode node)

getDefaultPrototypes

public java.util.Vector getDefaultPrototypes()

scanPrototypeFiles

public void scanPrototypeFiles()