// Class VRMLExtractor that builds a tree (java object) out of // a VMRL scene built with the External Authoring Interface. // Version of 2/25/98 import java.lang.*; import java.util.*; import vrml.external.field.*; import vrml.external.exception.*; import vrml.external.Node; import vrml.external.Browser; import Tree; public class VRMLExtractor extends Object { // Just to remember EventInTypes // EventInMFColor // EventInMFFloat // EventInMFInt32 // EventInMFNode // EventInMFRotation // EventInMFString // EventInMFVec2f // EventInMFVec3f // EventInSFBool // EventInSFColor // EventInSFFloat // EventInSFImage // EventInSFInt32 // EventInSFNode // EventInSFRotation // EventInSFString // EventInSFTime // EventInSFVec2f // EventInSFVec3f // Just to remember EventOutTypes // EventOutMField // EventOutMFColor // EventOutMFFloat // EventOutMFInt32 // EventOutMFNode // EventOutMFRotation // EventOutMFString // EventOutMFVec2f // EventOutMFVec3f // EventOutSFBool // EventOutSFColor // EventOutSFFloat // EventOutSFImage // EventOutSFInt32 // EventOutSFNode // EventOutSFRotation // EventOutSFString // EventOutSFTime // EventOutSFVec2f // EventOutSFVec3f // Just to remember FieldTypes // UnknownType = 0; // SFBOOL = 1; // SFIMAGE = 2; // SFTIME = 3; // SFCOLOR = 4; // MFCOLOR = 5; // SFFLOAT = 6; // MFFLOAT = 7; // SFINT32 = 8; // MFINT32 = 9; // SFNODE = 10; // MFNODE = 11; // SFROTATION = 12; // MFROTATION = 13; // SFSTRING = 14; // MFSTRING = 15; // SFVEC2F = 16; // MFVEC2F = 17; // SFVEC3F = 18; // MFVEC3F = 19; private Tree TheVRMLExtractorTree; private Node TheRootNode; public VRMLExtractor (Browser TheBrowser) throws InvalidNodeException { try { TheRootNode = TheBrowser.getNode("ROOT"); TheVRMLExtractorTree = new Tree(); } catch (InvalidNodeException TheException) { System.out.println("Problems getting root node: " + TheException); } TheVRMLExtractorTree = ExtractTree(TheRootNode); } private synchronized Tree ExtractTree(Node TheNode) throws InvalidEventOutException { Tree TheTree; TheTree = new Tree(); if (TheNode.getType().equals("Group")) { TheTree.NodeContent = new String("Group"); TheTree.AddChildren(AddEventOutMFNode(TheNode, "children")); } else { if (TheNode.getType().equals("Transform")) { TheTree.NodeContent = new String("Transform"); TheTree.AddChildren(AddEventOutSFVec3f(TheNode, "center")); TheTree.AddChildren(AddEventOutMFNode(TheNode, "children")); TheTree.AddChildren(AddEventOutSFRotation(TheNode, "rotation")); TheTree.AddChildren(AddEventOutSFVec3f(TheNode, "scale")); TheTree.AddChildren(AddEventOutSFRotation(TheNode, "scaleOrientation")); TheTree.AddChildren(AddEventOutSFVec3f(TheNode, "translation")); } else { if (TheNode.getType().equals("Shape")) { TheTree.NodeContent = new String("Shape"); TheTree.AddChildren(AddEventOutSFNode(TheNode, "appearance")); TheTree.AddChildren(AddEventOutSFNode(TheNode, "geometry")); } else { if (TheNode.getType().equals("Appearance")) { TheTree.NodeContent = new String("Appearance"); TheTree.AddChildren(AddEventOutSFNode(TheNode, "material")); // following lines commented because of a bug in the browser // that crash if texture and texturetransform are not explicitely defined // TheTree.AddChildren(AddEventOutSFNode(TheNode, "texture")); // TheTree.AddChildren(AddEventOutSFNode(TheNode, "textureTransform")); } else { if (TheNode.getType().equals("Material")) { TheTree.NodeContent = new String("Material"); TheTree.AddChildren(AddEventOutSFFloat(TheNode, "ambientIntensity")); TheTree.AddChildren(AddEventOutSFColor(TheNode, "diffuseColor")); TheTree.AddChildren(AddEventOutSFColor(TheNode, "emissiveColor")); TheTree.AddChildren(AddEventOutSFFloat(TheNode, "shininess")); TheTree.AddChildren(AddEventOutSFColor(TheNode, "specularColor")); TheTree.AddChildren(AddEventOutSFFloat(TheNode, "transparency")); } else { if (TheNode.getType().equals("TouchSensor")) { TheTree.NodeContent = new String("TouchSensor"); TheTree.AddChildren(AddEventOutSFBool(TheNode, "enabled")); TheTree.AddChildren(AddEventOutSFVec3f(TheNode, "hitNormal_changed")); TheTree.AddChildren(AddEventOutSFVec3f(TheNode, "hitPoint_changed")); TheTree.AddChildren(AddEventOutSFVec2f(TheNode, "hitTexCoord_changed")); TheTree.AddChildren(AddEventOutSFBool(TheNode, "isActive")); TheTree.AddChildren(AddEventOutSFBool(TheNode, "isOver")); TheTree.AddChildren(AddEventOutSFTime(TheNode, "touchTime")); } else { if (TheNode.getType().equals("Box")) { TheTree.NodeContent = new String("Box"); } else { if (TheNode.getType().equals("Cone")) { TheTree.NodeContent = new String("Cone"); } else { if (TheNode.getType().equals("Sphere")) { TheTree.NodeContent = new String("Sphere"); } else { if (TheNode.getType().equals("Cylinder")) { TheTree.NodeContent = new String("Cylinder"); } else { // other nodes... } } } } } } } } } } return TheTree; } public String toString() { String TheString; TheString = new String(); if (TheVRMLExtractorTree != null) { TheString = TheString.concat("#VRML V2.0 utf8\n\n" + BuildString(TheVRMLExtractorTree, 0)); } return TheString; } private String BuildString(Tree TheTree, int TheIndentLevel) { String TheString; String TheNodeContentString; TheString = new String(); TheNodeContentString = TheTree.NodeContent.toString(); if (TheNodeContentString.equals("Group")) { TheString = TheString.concat(Indent(TheIndentLevel) + "Group\n"); TheString = TheString.concat(Indent(TheIndentLevel) + "{\n"); TheString = TheString.concat(GetEventOutMFNode(TheTree, "children", TheIndentLevel + 1)); TheString = TheString.concat(Indent(TheIndentLevel) + "}\n"); } else { if (TheNodeContentString.equals("Transform")) { TheString = TheString.concat(Indent(TheIndentLevel) + "Transform\n"); TheString = TheString.concat(Indent(TheIndentLevel) + "{\n"); TheString = TheString.concat(GetEventOutSFVec3f(TheTree, "center", TheIndentLevel + 1)); TheString = TheString.concat(GetEventOutMFNode(TheTree, "children", TheIndentLevel + 1)); TheString = TheString.concat(GetEventOutSFRotation(TheTree, "rotation", TheIndentLevel + 1)); TheString = TheString.concat(GetEventOutSFVec3f(TheTree, "scale", TheIndentLevel + 1)); TheString = TheString.concat(GetEventOutSFRotation(TheTree, "scaleOrientation", TheIndentLevel + 1)); TheString = TheString.concat(GetEventOutSFVec3f(TheTree, "translation", TheIndentLevel + 1)); TheString = TheString.concat(Indent(TheIndentLevel) + "}\n"); } else { if (TheNodeContentString.equals("Shape")) { TheString = TheString.concat(Indent(TheIndentLevel) + "Shape\n"); TheString = TheString.concat(Indent(TheIndentLevel) + "{\n"); TheString = TheString.concat(GetEventOutSFNode(TheTree, "appearance", TheIndentLevel + 1)); TheString = TheString.concat(GetEventOutSFNode(TheTree, "geometry", TheIndentLevel + 1)); TheString = TheString.concat(Indent(TheIndentLevel) + "}\n"); } else { if (TheNodeContentString.equals("Appearance")) { // because of a bug in the browser don't expect to get // texture and texturetransform // (unless they are ALWAYS explicitely defined and you DID uncomment the // lines in the corresponding part in ExtractTree) TheString = TheString.concat(Indent(TheIndentLevel) + "Appearance\n"); TheString = TheString.concat(Indent(TheIndentLevel) + "{\n"); TheString = TheString.concat(GetEventOutSFNode(TheTree, "material", TheIndentLevel + 1)); // TheString = TheString.concat(GetEventOutSFNode(TheTree, "texture", TheIndentLevel + 1)); // TheString = TheString.concat(GetEventOutSFNode(TheTree, "textureTransform", TheIndentLevel + 1)); TheString = TheString.concat(Indent(TheIndentLevel) + "}\n"); } else { if (TheNodeContentString.equals("Material")) { TheString = TheString.concat(Indent(TheIndentLevel) + "Material\n"); TheString = TheString.concat(Indent(TheIndentLevel) + "{\n"); TheString = TheString.concat(GetEventOutSFFloat(TheTree, "ambientIntensity", TheIndentLevel + 1)); TheString = TheString.concat(GetEventOutSFColor(TheTree, "diffuseColor", TheIndentLevel + 1)); TheString = TheString.concat(GetEventOutSFColor(TheTree, "emissiveColor", TheIndentLevel + 1)); TheString = TheString.concat(GetEventOutSFFloat(TheTree, "shininess", TheIndentLevel + 1)); TheString = TheString.concat(GetEventOutSFColor(TheTree, "specularColor", TheIndentLevel + 1)); TheString = TheString.concat(GetEventOutSFFloat(TheTree, "transparency", TheIndentLevel + 1)); TheString = TheString.concat(Indent(TheIndentLevel) + "}\n"); } else { if (TheNodeContentString.equals("TouchSensor")) { TheString = TheString.concat(Indent(TheIndentLevel) + "TouchSensor\n"); TheString = TheString.concat(Indent(TheIndentLevel) + "{\n"); TheString = TheString.concat(GetEventOutSFBool(TheTree, "enabled", TheIndentLevel + 1)); TheString = TheString.concat(GetEventOutSFVec3f(TheTree, "hitNormal_changed", TheIndentLevel + 1)); TheString = TheString.concat(GetEventOutSFVec3f(TheTree, "hitPoint_changed", TheIndentLevel + 1)); TheString = TheString.concat(GetEventOutSFVec2f(TheTree, "hitTexCoord_changed", TheIndentLevel + 1)); TheString = TheString.concat(GetEventOutSFBool(TheTree, "isActive", TheIndentLevel + 1)); TheString = TheString.concat(GetEventOutSFBool(TheTree, "isOver", TheIndentLevel + 1)); TheString = TheString.concat(GetEventOutSFTime(TheTree, "touchTime", TheIndentLevel + 1)); TheString = TheString.concat(Indent(TheIndentLevel) + "}\n"); } else { if (TheNodeContentString.equals("Box")) { TheString = TheString.concat(Indent(TheIndentLevel) + "Box\n"); TheString = TheString.concat(Indent(TheIndentLevel) + "{\n"); // due to the fact that the box has NO exposed field // we cant get the actual values for its size // therefore, we assume that these values are the default values TheString = TheString.concat(Indent(TheIndentLevel + 1) + "size 2 2 2\n"); TheString = TheString.concat(Indent(TheIndentLevel) + "}\n"); } else { if (TheNodeContentString.equals("Cone")) { TheString = TheString.concat(Indent(TheIndentLevel) + "Cone\n"); TheString = TheString.concat(Indent(TheIndentLevel) + "{\n"); // due to the fact that the cone has NO exposed field // we cant get the actual values for its size // therefore, we assume that these values are the default values TheString = TheString.concat(Indent(TheIndentLevel + 1) + "bottomRadius 1\n"); TheString = TheString.concat(Indent(TheIndentLevel + 1) + "height 2\n"); TheString = TheString.concat(Indent(TheIndentLevel + 1) + "side TRUE \n"); TheString = TheString.concat(Indent(TheIndentLevel + 1) + "bottom TRUE\n"); TheString = TheString.concat(Indent(TheIndentLevel) + "}\n"); } else { if (TheNodeContentString.equals("Sphere")) { TheString = TheString.concat(Indent(TheIndentLevel) + "Sphere\n"); TheString = TheString.concat(Indent(TheIndentLevel) + "{\n"); // due to the fact that the sphere has NO exposed field // we cant get the actual values for its size // therefore, we assume that these values are the default values TheString = TheString.concat(Indent(TheIndentLevel + 1) + "radius 1\n"); TheString = TheString.concat(Indent(TheIndentLevel) + "}\n"); } else { if (TheNodeContentString.equals("Cylinder")) { TheString = TheString.concat(Indent(TheIndentLevel) + "Cylinder\n"); TheString = TheString.concat(Indent(TheIndentLevel) + "{\n"); // due to the fact that the cylinder has NO exposed field // we cant get the actual values for its size // therefore, we assume that these values are the default values TheString = TheString.concat(Indent(TheIndentLevel + 1) + "bottom TRUE\n"); TheString = TheString.concat(Indent(TheIndentLevel + 1) + "height 2\n"); TheString = TheString.concat(Indent(TheIndentLevel + 1) + "radius 1\n"); TheString = TheString.concat(Indent(TheIndentLevel + 1) + "side TRUE 1\n"); TheString = TheString.concat(Indent(TheIndentLevel + 1) + "top TRUE\n"); TheString = TheString.concat(Indent(TheIndentLevel) + "}\n"); } else { // other nodes... } } } } } } } } } } return TheString; } private Tree AddEventOutMFColor(Node TheNode, String TheEventOutName) { Tree TheBranch; Tree TheFirstSubBranch; EventOutMFColor TheEventOutMFColor; float[][] TheFloatValues; Float[][] TheFloatObjects; TheBranch = new Tree(TheEventOutName); try { TheEventOutMFColor = (EventOutMFColor) TheNode.getEventOut(TheEventOutName); TheFloatValues = TheEventOutMFColor.getValue(); TheFloatObjects = new Float[TheEventOutMFColor.getSize()][3]; for (int i = 0; i <= (TheEventOutMFColor.getSize()); i++) { for (int j = 0; j <= 2; j++) { TheFloatObjects[i][j] = new Float(TheFloatValues[i][j]); } } TheFirstSubBranch = new Tree(TheFloatObjects); TheBranch.AddChildren(TheFirstSubBranch); } catch (InvalidEventOutException TheException) { System.out.println("Problems getting EventOutMFColor for a node: " + TheException); } return TheBranch; } private Tree AddEventOutMFFloat(Node TheNode, String TheEventOutName) { Tree TheBranch; Tree TheFirstSubBranch; EventOutMFFloat TheEventOutMFFloat; float[] TheFloatValues; Float[] TheFloatObjects; TheBranch = new Tree(TheEventOutName); try { TheEventOutMFFloat = (EventOutMFFloat) TheNode.getEventOut(TheEventOutName); TheFloatValues = TheEventOutMFFloat.getValue(); TheFloatObjects = new Float[TheFloatValues.length]; for (int i = 0; i <= (TheFloatValues.length - 1); i++) { TheFloatObjects[i] = new Float(TheFloatValues[i]); } TheFirstSubBranch = new Tree(TheFloatObjects); TheBranch.AddChildren(TheFirstSubBranch); } catch (InvalidEventOutException TheException) { System.out.println("Problems getting EventOutMFFloat for a node: " + TheException); } return TheBranch; } private Tree AddEventOutMFInt32(Node TheNode, String TheEventOutName) { Tree TheBranch; Tree TheFirstSubBranch; EventOutMFInt32 TheEventOutMFInt32; int[] TheIntegerValues; Integer[] TheIntegerObjects; TheBranch = new Tree(TheEventOutName); try { TheEventOutMFInt32 = (EventOutMFInt32) TheNode.getEventOut(TheEventOutName); TheIntegerValues = TheEventOutMFInt32.getValue(); TheIntegerObjects = new Integer[TheIntegerValues.length]; for (int i = 0; i <= (TheIntegerValues.length - 1); i++) { TheIntegerObjects[i] = new Integer(TheIntegerValues[i]); } TheFirstSubBranch = new Tree(TheIntegerObjects); TheBranch.AddChildren(TheFirstSubBranch); } catch (InvalidEventOutException TheException) { System.out.println("Problems getting EventOutMFInt32 for a node: " + TheException); } return TheBranch; } private Tree AddEventOutMFNode(Node TheNode, String TheEventOutName) { Tree TheBranch; EventOutMFNode TheEventOutMFNode; Node[] TheChildrenNodes; TheBranch = new Tree(TheEventOutName); try { TheEventOutMFNode = (EventOutMFNode) TheNode.getEventOut(TheEventOutName); TheChildrenNodes = TheEventOutMFNode.getValue(); for (int i = 0; i <= (TheChildrenNodes.length - 1); i++) { TheBranch.AddChildren(ExtractTree(TheChildrenNodes[i])); } } catch (InvalidEventOutException TheException) { System.out.println("Problems getting EventOutMFNode for a node: " + TheException); } return TheBranch; } private Tree AddEventOutMFRotation(Node TheNode, String TheEventOutName) { Tree TheBranch; Tree TheFirstSubBranch; EventOutMFColor TheEventOutMFColor; float[][] TheFloatValues; Float[][] TheFloatObjects; TheBranch = new Tree(TheEventOutName); try { TheEventOutMFColor = (EventOutMFColor) TheNode.getEventOut(TheEventOutName); TheFloatValues = TheEventOutMFColor.getValue(); TheFloatObjects = new Float[TheEventOutMFColor.getSize()][4]; for (int i = 0; i <= (TheEventOutMFColor.getSize()); i++) { for (int j = 0; j <= 3; j++) { TheFloatObjects[i][j] = new Float(TheFloatValues[i][j]); } } TheFirstSubBranch = new Tree(TheFloatObjects); TheBranch.AddChildren(TheFirstSubBranch); } catch (InvalidEventOutException TheException) { System.out.println("Problems getting EventOutMFRotation for a node: " + TheException); } return TheBranch; } private Tree AddEventOutMFString(Node TheNode, String TheEventOutName) { Tree TheBranch; Tree TheFirstSubBranch; EventOutMFString TheEventOutMFString; String[] TheStringValues; TheBranch = new Tree(TheEventOutName); try { TheEventOutMFString = (EventOutMFString) TheNode.getEventOut(TheEventOutName); TheStringValues = TheEventOutMFString.getValue(); TheFirstSubBranch = new Tree(TheStringValues); TheBranch.AddChildren(TheFirstSubBranch); } catch (InvalidEventOutException TheException) { System.out.println("Problems getting EventOutMFString for a node: " + TheException); } return TheBranch; } private Tree AddEventOutMFVec2f(Node TheNode, String TheEventOutName) { Tree TheBranch; Tree TheFirstSubBranch; EventOutMFVec2f TheEventOutMFVec2f; float[][] TheFloatValues; Float[][] TheFloatObjects; TheBranch = new Tree(TheEventOutName); try { TheEventOutMFVec2f = (EventOutMFVec2f) TheNode.getEventOut(TheEventOutName); TheFloatValues = TheEventOutMFVec2f.getValue(); TheFloatObjects = new Float[TheEventOutMFVec2f.getSize()][2]; for (int i = 0; i <= (TheEventOutMFVec2f.getSize()); i++) { TheFloatObjects[i][0] = new Float(TheFloatValues[i][0]); TheFloatObjects[i][1] = new Float(TheFloatValues[i][1]); } TheFirstSubBranch = new Tree(TheFloatObjects); TheBranch.AddChildren(TheFirstSubBranch); } catch (InvalidEventOutException TheException) { System.out.println("Problems getting EventOutMFVec2f for a node: " + TheException); } return TheBranch; } private Tree AddEventOutMFVec3f(Node TheNode, String TheEventOutName) { Tree TheBranch; Tree TheFirstSubBranch; EventOutMFVec3f TheEventOutMFVec3f; float[][] TheFloatValues; Float[][] TheFloatObjects; TheBranch = new Tree(TheEventOutName); try { TheEventOutMFVec3f = (EventOutMFVec3f) TheNode.getEventOut(TheEventOutName); TheFloatValues = TheEventOutMFVec3f.getValue(); TheFloatObjects = new Float[TheEventOutMFVec3f.getSize()][3]; for (int i = 0; i <= (TheEventOutMFVec3f.getSize()); i++) { for (int j = 0; j <= 2; j++) { TheFloatObjects[i][j] = new Float(TheFloatValues[i][j]); } } TheFirstSubBranch = new Tree(TheFloatObjects); TheBranch.AddChildren(TheFirstSubBranch); } catch (InvalidEventOutException TheException) { System.out.println("Problems getting EventOutMFVec3f for a node: " + TheException); } return TheBranch; } private Tree AddEventOutSFBool(Node TheNode, String TheEventOutName) { Tree TheBranch; Tree TheFirstSubBranch; EventOutSFBool TheEventOutSFBool; boolean TheBooleanValue; TheBranch = new Tree(TheEventOutName); try { TheEventOutSFBool = (EventOutSFBool) TheNode.getEventOut(TheEventOutName); TheBooleanValue = TheEventOutSFBool.getValue(); TheFirstSubBranch = new Tree(new Boolean(TheBooleanValue)); TheBranch.AddChildren(TheFirstSubBranch); } catch (InvalidEventOutException TheException) { System.out.println("Problems getting EventOutSFBool for a node: " + TheException); } return TheBranch; } private Tree AddEventOutSFColor(Node TheNode, String TheEventOutName) { Tree TheBranch; Tree TheFirstSubBranch; EventOutSFColor TheEventOutSFColor; float[] TheFloatValues; Float[] TheFloatObjects; TheBranch = new Tree(TheEventOutName); try { TheEventOutSFColor = (EventOutSFColor) TheNode.getEventOut(TheEventOutName); TheFloatValues = TheEventOutSFColor.getValue(); TheFloatObjects = new Float[3]; for (int i = 0; i <= 2; i++) { TheFloatObjects[i] = new Float(TheFloatValues[i]); } TheFirstSubBranch = new Tree(TheFloatObjects); TheBranch.AddChildren(TheFirstSubBranch); } catch (InvalidEventOutException TheException) { System.out.println("Problems getting EventOutSFColor for a node: " + TheException); } return TheBranch; } private Tree AddEventOutSFFloat(Node TheNode, String TheEventOutName) { Tree TheBranch; Tree TheFirstSubBranch; EventOutSFFloat TheEventOutSFFloat; float TheFloatValue; TheBranch = new Tree(TheEventOutName); try { TheEventOutSFFloat = (EventOutSFFloat) TheNode.getEventOut(TheEventOutName); TheFloatValue = TheEventOutSFFloat.getValue(); TheFirstSubBranch = new Tree(new Float(TheFloatValue)); TheBranch.AddChildren(TheFirstSubBranch); } catch (InvalidEventOutException TheException) { System.out.println("Problems getting EventOutSFFloat for a node: " + TheException); } return TheBranch; } private Tree AddEventOutSFImage(Node TheNode, String TheEventOutName) { Tree TheBranch; Tree TheFirstSubBranch; Tree TheSecondSubBranch; Tree TheThirdSubBranch; Tree TheFourthSubBranch; EventOutSFImage TheEventOutSFImage; int TheWidth; int TheHeight; int TheNumComponents; byte[] ThePixelsValues; Byte[] ThePixelsObjects; TheBranch = new Tree(TheEventOutName); try { TheEventOutSFImage = (EventOutSFImage) TheNode.getEventOut(TheEventOutName); TheWidth = TheEventOutSFImage.getWidth(); TheHeight = TheEventOutSFImage.getHeight(); TheNumComponents = TheEventOutSFImage.getNumComponents(); ThePixelsValues = TheEventOutSFImage.getPixels(); TheFirstSubBranch = new Tree(new Integer(TheWidth)); TheBranch.AddChildren(TheFirstSubBranch); TheSecondSubBranch = new Tree(new Integer(TheHeight)); TheBranch.AddChildren(TheSecondSubBranch); TheThirdSubBranch = new Tree(new Integer(TheNumComponents)); TheBranch.AddChildren(TheThirdSubBranch); ThePixelsObjects = new Byte [ThePixelsValues.length]; for (int i = 0; i <= (ThePixelsValues.length - 1); i++) { ThePixelsObjects[i] = new Byte(ThePixelsValues[i]); } TheFourthSubBranch = new Tree(ThePixelsObjects); TheBranch.AddChildren(TheFourthSubBranch); } catch (InvalidEventOutException TheException) { System.out.println("Problems getting EventOutSFImage for a node: " + TheException); } return TheBranch; } private Tree AddEventOutSFInt32(Node TheNode, String TheEventOutName) { Tree TheBranch; Tree TheFirstSubBranch; EventOutSFInt32 TheEventOutSFInt32; int TheIntegerValue; TheBranch = new Tree(TheEventOutName); try { TheEventOutSFInt32 = (EventOutSFInt32) TheNode.getEventOut(TheEventOutName); TheIntegerValue = TheEventOutSFInt32.getValue(); TheFirstSubBranch = new Tree(new Integer(TheIntegerValue)); TheBranch.AddChildren(TheFirstSubBranch); } catch (InvalidEventOutException TheException) { System.out.println("Problems getting EventOutSFInt32 for a node: " + TheException); } return TheBranch; } private Tree AddEventOutSFNode(Node TheNode, String TheEventOutName) { Tree TheBranch; EventOutSFNode TheEventOutSFNode; Node TheChildNode; TheBranch = new Tree(TheEventOutName); try { TheEventOutSFNode = (EventOutSFNode) TheNode.getEventOut(TheEventOutName); TheChildNode = TheEventOutSFNode.getValue(); TheBranch.AddChildren(ExtractTree(TheChildNode)); } catch (InvalidEventOutException TheException) { System.out.println("Problems getting EventOutSFNode for a node: " + TheException); } return TheBranch; } private Tree AddEventOutSFRotation(Node TheNode, String TheEventOutName) { Tree TheBranch; Tree TheFirstSubBranch; EventOutSFRotation TheEventOutSFRotation; float[] TheFloatValues; Float[] TheFloatObjects; TheBranch = new Tree(TheEventOutName); try { TheEventOutSFRotation = (EventOutSFRotation) TheNode.getEventOut(TheEventOutName); TheFloatValues = TheEventOutSFRotation.getValue(); TheFloatObjects = new Float[4]; for (int i = 0; i <= 3; i++) { TheFloatObjects[i] = new Float(TheFloatValues[i]); } TheFirstSubBranch = new Tree(TheFloatObjects); TheBranch.AddChildren(TheFirstSubBranch); } catch (InvalidEventOutException TheException) { System.out.println("Problems getting EventOutSFRotation for a node: " + TheException); } return TheBranch; } private Tree AddEventOutSFString(Node TheNode, String TheEventOutName) { Tree TheBranch; Tree TheFirstSubBranch; EventOutSFString TheEventOutSFString; String TheStringValue; TheBranch = new Tree(TheEventOutName); try { TheEventOutSFString = (EventOutSFString) TheNode.getEventOut(TheEventOutName); TheStringValue = TheEventOutSFString.getValue(); TheFirstSubBranch = new Tree(new String(TheStringValue)); TheBranch.AddChildren(TheFirstSubBranch); } catch (InvalidEventOutException TheException) { System.out.println("Problems getting EventOutSFString for a node: " + TheException); } return TheBranch; } private Tree AddEventOutSFTime(Node TheNode, String TheEventOutName) { Tree TheBranch; Tree TheFirstSubBranch; EventOutSFTime TheEventOutSFTime; double TheDoubleValue; TheBranch = new Tree(TheEventOutName); try { TheEventOutSFTime = (EventOutSFTime) TheNode.getEventOut(TheEventOutName); TheDoubleValue = TheEventOutSFTime.getValue(); TheFirstSubBranch = new Tree(new Double(TheDoubleValue)); TheBranch.AddChildren(TheFirstSubBranch); } catch (InvalidEventOutException TheException) { System.out.println("Problems getting EventOutSFTime for a node: " + TheException); } return TheBranch; } private Tree AddEventOutSFVec2f(Node TheNode, String TheEventOutName) { Tree TheBranch; Tree TheFirstSubBranch; EventOutSFVec2f TheEventOutSFVec2f; float[] TheFloatValues; Float[] TheFloatObjects; TheBranch = new Tree(TheEventOutName); try { TheEventOutSFVec2f = (EventOutSFVec2f) TheNode.getEventOut(TheEventOutName); TheFloatValues = TheEventOutSFVec2f.getValue(); TheFloatObjects = new Float[2]; TheFloatObjects[0] = new Float(TheFloatValues[0]); TheFloatObjects[1] = new Float(TheFloatValues[1]); TheFirstSubBranch = new Tree(TheFloatObjects); TheBranch.AddChildren(TheFirstSubBranch); } catch (InvalidEventOutException TheException) { System.out.println("Problems getting EventOutSFVec2f for a node: " + TheException); } return TheBranch; } private Tree AddEventOutSFVec3f(Node TheNode, String TheEventOutName) { Tree TheBranch; Tree TheFirstSubBranch; EventOutSFVec3f TheEventOutSFVec3f; float[] TheFloatValues; Float[] TheFloatObjects; TheBranch = new Tree(TheEventOutName); try { TheEventOutSFVec3f = (EventOutSFVec3f) TheNode.getEventOut(TheEventOutName); TheFloatValues = TheEventOutSFVec3f.getValue(); TheFloatObjects = new Float[3]; for (int i = 0; i <= 2; i++) { TheFloatObjects[i] = new Float(TheFloatValues[i]); } TheFirstSubBranch = new Tree(TheFloatObjects); TheBranch.AddChildren(TheFirstSubBranch); } catch (InvalidEventOutException TheException) { System.out.println("Problems getting EventOutSFVec3f for a node: " + TheException); } return TheBranch; } private int FindBranchIndex(Tree TheTree, String TheString) { int TheIndex; int i; boolean Found; i = 0; Found = false; while (i < TheTree.BranchNumber() && !(Found)) { Found = (Found || TheTree.GetChild(i).NodeContent.toString().equals(TheString)); i++; } if (Found) { TheIndex = i - 1; } else { TheIndex = -1; } return TheIndex; } private String Indent(int TheIndentLevel) { String TheString; TheString = new String(); for (int i = 1; i <= TheIndentLevel; i++) { TheString = TheString.concat(" "); } return TheString; } private String GetEventOutMFColor(Tree TheTree, String TheString, int TheIndentLevel) { String TheOutputString; Float[][] TheFloatObjects; TheOutputString = new String(Indent(TheIndentLevel) + TheString + "\n" + Indent(TheIndentLevel) + "[\n"); TheFloatObjects = (Float[][]) TheTree.GetChild(FindBranchIndex(TheTree, TheString)).GetChild(0).NodeContent; for (int i = 0; i <= (TheFloatObjects.length - 1); i++) { TheOutputString = TheOutputString.concat(Indent(TheIndentLevel + 1)); for (int j = 0; j <= 1; j++) { TheOutputString = TheOutputString.concat(TheFloatObjects[i][j].toString() + " "); } TheOutputString = TheOutputString.concat(TheFloatObjects[i][2].toString()); TheOutputString = TheOutputString.concat("\n"); } TheOutputString = TheOutputString.concat(Indent(TheIndentLevel) + "]\n"); return TheOutputString; } private String GetEventOutMFFloat(Tree TheTree, String TheString, int TheIndentLevel) { String TheOutputString; Float[] TheFloatObjects; TheOutputString = new String(Indent(TheIndentLevel) + TheString + "\n" + Indent(TheIndentLevel) + "[\n"); TheFloatObjects = (Float[]) TheTree.GetChild(FindBranchIndex(TheTree, TheString)).GetChild(0).NodeContent; for (int i = 0; i <= (TheFloatObjects.length - 1); i++) { TheOutputString = TheOutputString.concat(Indent(TheIndentLevel + 1) + TheFloatObjects[i].toString() + "\n"); } TheOutputString = TheOutputString.concat(Indent(TheIndentLevel) + "]\n"); return TheOutputString; } private String GetEventOutMFInt32(Tree TheTree, String TheString, int TheIndentLevel) { String TheOutputString; Integer[] TheIntegerObjects; TheOutputString = new String(Indent(TheIndentLevel) + TheString + "\n" + Indent(TheIndentLevel) + "[\n"); TheIntegerObjects = (Integer[]) TheTree.GetChild(FindBranchIndex(TheTree, TheString)).GetChild(0).NodeContent; for (int i = 0; i <= (TheIntegerObjects.length - 1); i++) { TheOutputString = TheOutputString.concat(Indent(TheIndentLevel + 1) + TheIntegerObjects[i].toString() + "\n"); } TheOutputString = TheOutputString.concat(Indent(TheIndentLevel) + "]\n"); return TheOutputString; } private String GetEventOutMFNode(Tree TheTree, String TheString, int TheIndentLevel) { String TheOutputString; int TheIndex; Tree TheBranch; TheOutputString = new String(Indent(TheIndentLevel) + TheString + "\n" + Indent(TheIndentLevel) + "[\n"); TheIndex = FindBranchIndex(TheTree, TheString); TheBranch = TheTree.GetChild(TheIndex); for (int i = 0; i < TheBranch.BranchNumber(); i++) { TheOutputString = TheOutputString.concat(BuildString(TheBranch.GetChild(i), TheIndentLevel + 1)); } TheOutputString = TheOutputString.concat(Indent(TheIndentLevel) + "]\n"); return TheOutputString; } private String GetEventOutMFRotation(Tree TheTree, String TheString, int TheIndentLevel) { String TheOutputString; Float[][] TheFloatObjects; TheOutputString = new String(Indent(TheIndentLevel) + TheString + "\n" + Indent(TheIndentLevel) + "[\n"); TheFloatObjects = (Float[][]) TheTree.GetChild(FindBranchIndex(TheTree, TheString)).GetChild(0).NodeContent; for (int i = 0; i <= (TheFloatObjects.length - 1); i++) { TheOutputString = TheOutputString.concat(Indent(TheIndentLevel + 1)); for (int j = 0; j <= 2; j++) { TheOutputString = TheOutputString.concat(TheFloatObjects[i][j].toString() + " "); } TheOutputString = TheOutputString.concat(TheFloatObjects[i][3].toString()); TheOutputString = TheOutputString.concat("\n"); } TheOutputString = TheOutputString.concat(Indent(TheIndentLevel) + "]\n"); return TheOutputString; } private String GetEventOutMFString(Tree TheTree, String TheString, int TheIndentLevel) { String TheOutputString; String[] TheStringObjects; TheOutputString = new String(Indent(TheIndentLevel) + TheString + "\n" + Indent(TheIndentLevel) + "[\n"); TheStringObjects = (String[]) TheTree.GetChild(FindBranchIndex(TheTree, TheString)).GetChild(0).NodeContent; for (int i = 0; i <= (TheStringObjects.length - 1); i++) { TheOutputString = TheOutputString.concat(Indent(TheIndentLevel + 1) + TheStringObjects[i].toString() + "\n"); } TheOutputString = TheOutputString.concat(Indent(TheIndentLevel) + "]\n"); return TheOutputString; } private String GetEventOutMFVec2f(Tree TheTree, String TheString, int TheIndentLevel) { String TheOutputString; Float[][] TheFloatObjects; TheOutputString = new String(Indent(TheIndentLevel) + TheString + "\n" + Indent(TheIndentLevel) + "[\n"); TheFloatObjects = (Float[][]) TheTree.GetChild(FindBranchIndex(TheTree, TheString)).GetChild(0).NodeContent; for (int i = 0; i <= (TheFloatObjects.length - 1); i++) { TheOutputString = TheOutputString.concat(Indent(TheIndentLevel + 1)); TheOutputString = TheOutputString.concat(TheFloatObjects[i][0].toString() + " "); TheOutputString = TheOutputString.concat(TheFloatObjects[i][1].toString()); TheOutputString = TheOutputString.concat("\n"); } TheOutputString = TheOutputString.concat(Indent(TheIndentLevel) + "]\n"); return TheOutputString; } private String GetEventOutMFVec3f(Tree TheTree, String TheString, int TheIndentLevel) { String TheOutputString; Float[][] TheFloatObjects; TheOutputString = new String(Indent(TheIndentLevel) + TheString + "\n" + Indent(TheIndentLevel) + "[\n"); TheFloatObjects = (Float[][]) TheTree.GetChild(FindBranchIndex(TheTree, TheString)).GetChild(0).NodeContent; for (int i = 0; i <= (TheFloatObjects.length - 1); i++) { TheOutputString = TheOutputString.concat(Indent(TheIndentLevel + 1)); for (int j = 0; j <= 1; j++) { TheOutputString = TheOutputString.concat(TheFloatObjects[i][j].toString() + " "); } TheOutputString = TheOutputString.concat(TheFloatObjects[i][2].toString()); TheOutputString = TheOutputString.concat("\n"); } TheOutputString = TheOutputString.concat(Indent(TheIndentLevel) + "]\n"); return TheOutputString; } private String GetEventOutSFBool(Tree TheTree, String TheString, int TheIndentLevel) { String TheOutputString; Boolean TheBoolean; TheOutputString = new String(Indent(TheIndentLevel) + TheString); TheBoolean = (Boolean) TheTree.GetChild(FindBranchIndex(TheTree, TheString)).GetChild(0).NodeContent; TheOutputString = TheOutputString.concat(" " + TheBoolean.toString().toUpperCase() + "\n"); return TheOutputString; } private String GetEventOutSFColor(Tree TheTree, String TheString, int TheIndentLevel) { String TheOutputString; Float[] TheFloatObjects; TheOutputString = new String(Indent(TheIndentLevel) + TheString); TheFloatObjects = (Float[]) TheTree.GetChild(FindBranchIndex(TheTree, TheString)).GetChild(0).NodeContent; for (int i = 0; i <= 2; i++) { TheOutputString = TheOutputString.concat(" " + TheFloatObjects[i].toString()); } TheOutputString = TheOutputString.concat("\n"); return TheOutputString; } private String GetEventOutSFFloat(Tree TheTree, String TheString, int TheIndentLevel) { String TheOutputString; Float TheFloat; TheOutputString = new String(Indent(TheIndentLevel) + TheString); TheFloat = (Float) TheTree.GetChild(FindBranchIndex(TheTree, TheString)).GetChild(0).NodeContent; TheOutputString = TheOutputString.concat(" " + TheFloat.toString() + "\n"); return TheOutputString; } private String GetEventOutSFImage(Tree TheTree, String TheString, int TheIndentLevel) { String TheOutputString; int TheIndex; Tree TheBranch; Integer TheWidth; Integer TheHeight; Integer TheNumComponents; Byte[] ThePixelsObjects; TheOutputString = new String(Indent(TheIndentLevel) + TheString); TheBranch = TheTree.GetChild(FindBranchIndex(TheTree, TheString)); TheWidth = (Integer) TheBranch.GetChild(0).NodeContent; TheHeight = (Integer) TheBranch.GetChild(1).NodeContent; TheNumComponents = (Integer) TheBranch.GetChild(2).NodeContent; ThePixelsObjects = (Byte[]) TheBranch.GetChild(2).NodeContent; TheOutputString = TheOutputString.concat(" " + TheWidth.toString()); TheOutputString = TheOutputString.concat(" " + TheHeight.toString()); TheOutputString = TheOutputString.concat(" " + TheNumComponents.toString()); for (int i = 0; i <= (ThePixelsObjects.length - 1); i++) { TheOutputString = TheOutputString.concat(" " + ThePixelsObjects[i].toString()); } TheOutputString = TheOutputString.concat("\n"); return TheOutputString; } private String GetEventOutSFInt32(Tree TheTree, String TheString, int TheIndentLevel) { String TheOutputString; Integer TheInteger; TheOutputString = new String(Indent(TheIndentLevel) + TheString); TheInteger = (Integer) TheTree.GetChild(FindBranchIndex(TheTree, TheString)).GetChild(0).NodeContent; TheOutputString = TheOutputString.concat(" " + TheInteger.toString() + "\n"); return TheOutputString; } private String GetEventOutSFNode(Tree TheTree, String TheString, int TheIndentLevel) { String TheOutputString; Tree TheChildBranch; TheOutputString = new String(Indent(TheIndentLevel) + TheString + "\n"); TheChildBranch = TheTree.GetChild(FindBranchIndex(TheTree, TheString)).GetChild(0); TheOutputString = TheOutputString.concat(BuildString(TheChildBranch, TheIndentLevel + 1)); return TheOutputString; } private String GetEventOutSFRotation(Tree TheTree, String TheString, int TheIndentLevel) { String TheOutputString; Float[] TheFloatObjects; TheOutputString = new String(Indent(TheIndentLevel) + TheString); TheFloatObjects = (Float[]) TheTree.GetChild(FindBranchIndex(TheTree, TheString)).GetChild(0).NodeContent; for (int i = 0; i <= 3; i++) { TheOutputString = TheOutputString.concat(" " + TheFloatObjects[i].toString()); } TheOutputString = TheOutputString.concat("\n"); return TheOutputString; } private String GetEventOutSFString(Tree TheTree, String TheString, int TheIndentLevel) { String TheOutputString; String TheStringObject; TheOutputString = new String(Indent(TheIndentLevel) + TheString); TheStringObject = (String) TheTree.GetChild(FindBranchIndex(TheTree, TheString)).GetChild(0).NodeContent; TheOutputString = TheOutputString.concat(" " + TheStringObject.toString() + "\n"); return TheOutputString; } private String GetEventOutSFTime(Tree TheTree, String TheString, int TheIndentLevel) { String TheOutputString; Double TheDouble; TheOutputString = new String(Indent(TheIndentLevel) + TheString); TheDouble = (Double) TheTree.GetChild(FindBranchIndex(TheTree, TheString)).GetChild(0).NodeContent; TheOutputString = TheOutputString.concat(" " + TheDouble.toString() + "\n"); return TheOutputString; } private String GetEventOutSFVec2f(Tree TheTree, String TheString, int TheIndentLevel) { String TheOutputString; Float[] TheFloatObjects; TheOutputString = new String(Indent(TheIndentLevel) + TheString); TheFloatObjects = (Float[]) TheTree.GetChild(FindBranchIndex(TheTree, TheString)).GetChild(0).NodeContent; TheOutputString = TheOutputString.concat(" " + TheFloatObjects[0].toString()); TheOutputString = TheOutputString.concat(" " + TheFloatObjects[1].toString()); TheOutputString = TheOutputString.concat("\n"); return TheOutputString; } private String GetEventOutSFVec3f(Tree TheTree, String TheString, int TheIndentLevel) { String TheOutputString; Float[] TheFloatObjects; TheOutputString = new String(Indent(TheIndentLevel) + TheString); TheFloatObjects = (Float[]) TheTree.GetChild(FindBranchIndex(TheTree, TheString)).GetChild(0).NodeContent; for (int i = 0; i <= 2; i++) { TheOutputString = TheOutputString.concat(" " + TheFloatObjects[i].toString()); } TheOutputString = TheOutputString.concat("\n"); return TheOutputString; } }