Example #1
0
    /// <summary>
    /// Reads a BXDVector3 with the given XmlReader and returns the reading.
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    private static BXDVector3 ReadBXDVector4_2(XmlReader reader)
    {
        BXDVector3 vec = new BXDVector3();

        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "X":
                // Assign the x value.
                vec.x = float.Parse(reader.ReadElementContentAsString());
                break;

            case "Y":
                // Assign the y value.
                vec.y = float.Parse(reader.ReadElementContentAsString());
                break;

            case "Z":
                // Assign the z value.
                vec.z = float.Parse(reader.ReadElementContentAsString());
                break;
            }
        }

        return(vec);
    }
Example #2
0
    /// <summary>
    /// Reads a PlanarJoint_Base from the given XmlReader.
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    private static PlanarJoint_Base ReadPlanarJoint_4_2(XmlReader reader)
    {
        // Create a new PlanarJoint_Base.
        PlanarJoint_Base planarJoint = (PlanarJoint_Base)SkeletalJoint_Base.JOINT_FACTORY(SkeletalJointType.PLANAR);

        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "BXDVector3":
                switch (reader["VectorID"])
                {
                case "Normal":
                    // Assign the BXDVector3 to the normal.
                    planarJoint.normal = ReadBXDVector4_2(reader.ReadSubtree());
                    break;

                case "BasePoint":
                    // Assign the BXDVector3 to the basePoint.s
                    planarJoint.basePoint = ReadBXDVector4_2(reader.ReadSubtree());
                    break;
                }
                break;
            }
        }

        return(planarJoint);
    }
Example #3
0
    /// <summary>
    /// Iterates through each child FieldNodeGroup and adds all FieldNodes to the given FieldNodeGroup.
    /// </summary>
    /// <param name="reader"></param>
    /// <param name="fieldNodeGroup"></param>
    private static void ReadFieldNodeGroup_2_2(XmlReader reader, FieldNodeGroup fieldNodeGroup)
    {
        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "Node":
                // Add the FieldNode to fieldNodeGroup.
                fieldNodeGroup.AddNode(ReadFieldNode_2_2(reader.ReadSubtree()));
                break;

            case "NodeGroup":
                // If an ID has not been assigned to the current FieldNodeGroup.
                if (fieldNodeGroup.NodeGroupID.Equals(BXDFProperties.BXDF_DEFAULT_NAME))
                {
                    // Assign the ID attribute value to the NodeGroupID property.
                    fieldNodeGroup.NodeGroupID = reader["ID"];
                }
                else
                {
                    // Creates a new FieldNodeGroup.
                    FieldNodeGroup childNodeGroup = new FieldNodeGroup(BXDFProperties.BXDF_DEFAULT_NAME);

                    // Re-iterate as the childNodeGroup.
                    ReadFieldNodeGroup_2_2(reader.ReadSubtree(), childNodeGroup);

                    // Add the processed FieldNodeGroup to fieldNodeGroup.
                    fieldNodeGroup.AddNodeGroup(childNodeGroup);
                }
                break;
            }
        }
    }
Example #4
0
    /// <summary>
    /// Reads a BXDQuaternion with the given XmlReader and returns the reading.
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    private static BXDQuaternion ReadBXDQuaternion_2_2(XmlReader reader)
    {
        BXDQuaternion quat = new BXDQuaternion();

        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "X":
                // Assign the X value.
                quat.X = float.Parse(reader.ReadElementContentAsString());
                break;

            case "Y":
                // Assign the Y value.
                quat.Y = float.Parse(reader.ReadElementContentAsString());
                break;

            case "Z":
                // Assign the Z value.
                quat.Z = float.Parse(reader.ReadElementContentAsString());
                break;

            case "W":
                // Assign the W value.
                quat.W = float.Parse(reader.ReadElementContentAsString());
                break;
            }
        }

        return(quat);
    }
Example #5
0
    /// <summary>
    /// Reads the properties contained in the XML BXDF file specified and returns
    /// the corresponding FieldDefinition.
    /// </summary>
    /// <param name="path"></param>
    /// <param name="useValidation"></param>
    /// <returns></returns>
    private static FieldDefinition ReadProperties_2_2(string path, out string result, bool useValidation = true)
    {
        // The FieldDefinition to be returned.
        FieldDefinition fieldDefinition = null;

        XmlReaderSettings settings = new XmlReaderSettings();

        if (useValidation)
        {
            settings.Schemas.Add(XmlSchema.Read(new StringReader(BXDF_XSD_2_2), null));
            settings.ValidationType = ValidationType.Schema;
        }
        else
        {
            settings.ValidationType = ValidationType.None;
        }

        XmlReader reader = XmlReader.Create(path, settings);

        try
        {
            foreach (string name in IOUtilities.AllElements(reader))
            {
                switch (name)
                {
                case "BXDF":
                    // Assign a value to fieldDefinition with the given GUID attribute.
                    fieldDefinition = FieldDefinition.Factory(new Guid(reader["GUID"]));
                    break;

                case "PropertySet":
                    // Reads the current element as a PropertySet.
                    ReadPropertySet_2_2(reader.ReadSubtree(), fieldDefinition);
                    break;

                case "NodeGroup":
                    // Reads the root FieldNodeGroup.
                    ReadFieldNodeGroup_2_2(reader.ReadSubtree(), fieldDefinition.NodeGroup);
                    break;
                }
            }

            result = "Success.";

            return(fieldDefinition);
        }
        catch (Exception e)// A variety of exceptions can take place if the file is invalid, but we will always want to return null.
        {
            result = e.Message;

            // If the file is invalid, return null.
            return(null);
        }
        finally
        {
            // Closes the reader.
            reader.Close();
        }
    }
Example #6
0
    /// <summary>
    /// Reads a JointDriver from the given XmlReader.
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    private static JointDriver ReadJointDriver_2_0(XmlReader reader)
    {
        JointDriver driver = null;

        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "DriveType":
                // Initialize the driver.
                driver = new JointDriver((JointDriverType)Enum.Parse(typeof(JointDriverType), reader.ReadElementContentAsString()));
                break;

            case "PortA":
                // Assign a value to portA.
                driver.portA = reader.ReadElementContentAsInt();
                break;

            case "PortB":
                // Assign a value to portB.
                driver.portB = reader.ReadElementContentAsInt();
                break;

            case "LowerLimit":
                // Assign a value to the lowerLimit.
                driver.lowerLimit = float.Parse(reader.ReadElementContentAsString());
                break;

            case "UpperLimit":
                // Assign a value to the upperLimit.
                driver.upperLimit = float.Parse(reader.ReadElementContentAsString());
                break;

            case "SignalType":
                // Assign a value to isCan.
                driver.isCan = reader.ReadElementContentAsString().Equals("CAN") ? true : false;
                break;

            case "ElevatorDriverMeta":
                // Add an ElevatorDriverMeta.
                driver.AddInfo(ReadElevatorDriverMeta_2_0(reader.ReadSubtree()));
                break;

            case "PneumaticDriverMeta":
                // Add a PneumaticsDriverMeta.
                driver.AddInfo(ReadPneumaticDriverMeta_2_0(reader.ReadSubtree()));
                break;

            case "WheelDriverMeta":
                // Add a WheelDriverMeta.
                driver.AddInfo(ReadWheelDriverMeta_2_0(reader.ReadSubtree()));
                break;
            }
        }

        return(driver);
    }
Example #7
0
    /// <summary>
    /// Reads the skeleton contained in the XML BXDJ file specified and
    /// returns the corresponding RigidNode_Base.
    /// </summary>
    /// <param name="path"></param>
    /// <param name="useValidation"></param>
    private static RigidNode_Base ReadSkeleton_4_2(string path, bool useValidation = true)
    {
        RigidNode_Base        root  = null;
        List <RigidNode_Base> nodes = new List <RigidNode_Base>();

        XmlReaderSettings settings = new XmlReaderSettings();

        if (useValidation)// if the schema should be validated, then run the BXDJ against the schema to make sure all the value are there, oftentimes robot instace invalid issues are found here
        {
            settings.Schemas.Add(XmlSchema.Read(new StringReader(BXDJ_XSD_4_2), null));
            settings.ValidationType = ValidationType.Schema;
        }
        else
        {
            settings.ValidationType = ValidationType.None;
        }

        XmlReader reader = XmlReader.Create(path, settings);

        try
        {
            foreach (string name in IOUtilities.AllElements(reader)) // iterates over all the top level data
            {
                switch (name)                                        // handles reading the different XML tags
                {
                case "DriveTrainType":
                    // Reads the current element as a drive train type.
                    root.driveTrainType = (RigidNode_Base.DriveTrainType)Enum.Parse(typeof(RigidNode_Base.DriveTrainType), reader.ReadElementContentAsString());
                    break;

                case "SoftwareExportedWith":
                    // Reads the current element as a drive train type.
                    root.exportedWith = (RigidNode_Base.SoftwareExportedWith)Enum.Parse(typeof(RigidNode_Base.SoftwareExportedWith), reader.ReadElementContentAsString());
                    break;

                case "Node":
                    // Reads the current element as a node.
                    ReadNode_4_2(reader.ReadSubtree(), nodes, ref root);
                    break;
                }
            }
        }
        catch (Exception)// A variety of exceptions can take place if the file is invalid, but we will always want to return null.
        {
            // If the file is invalid, return null.
            return(null);
        }
        finally
        {
            // Closes the reader.
            reader.Close();
        }

        return(nodes[0]);// returns the base node of the skeleton
    }
Example #8
0
    /// <summary>
    /// Reads the skeleton contained in the XML BXDJ file specified and
    /// returns the corresponding RigidNode_Base.
    /// </summary>
    /// <param name="path"></param>
    /// <param name="useValidation"></param>
    private static RigidNode_Base ReadSkeleton_5_0(string path, bool useValidation = true)
    {
        RigidNode_Base        root  = null;
        List <RigidNode_Base> nodes = new List <RigidNode_Base>();

        XmlReaderSettings settings = new XmlReaderSettings();

        if (useValidation)
        {
            settings.Schemas.Add(XmlSchema.Read(new StringReader(BXDJ_XSD_5_0), null));
            settings.ValidationType = ValidationType.Schema;
        }
        else
        {
            settings.ValidationType = ValidationType.None;
        }

        XmlReader reader = XmlReader.Create(path, settings);

        try
        {
            foreach (string name in IOUtilities.AllElements(reader))
            {
                switch (name)
                {
                case "DriveTrainType":
                    ReadNode_5_0(reader.ReadSubtree(), nodes, ref root);
                    break;

                case "Node":
                    // Reads the current element as a node.
                    ReadNode_5_0(reader.ReadSubtree(), nodes, ref root);
                    break;
                }
            }
        }
        catch (Exception)// A variety of exceptions can take place if the file is invalid, but we will always want to return null.
        {
            // If the file is invalid, return null.
            return(null);
        }
        finally
        {
            // Closes the reader.
            reader.Close();
        }

        return(nodes[0]);
    }
Example #9
0
    /// <summary>
    /// Read a RobotSensor from the given XmlReader.
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    private static RobotSensor ReadRobotSensor_4_2(XmlReader reader)
    {
        RobotSensor robotSensor = null;

        //throw (new Exception("Reading thing"));
        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "SensorType":
                // Initialize the RobotSensor.
                robotSensor = new RobotSensor((RobotSensorType)Enum.Parse(typeof(RobotSensorType), reader.ReadElementContentAsString()));
                break;

            case "SensorPortNumberA":
                // Assign a value to the 1st port.
                robotSensor.portA = float.Parse(reader.ReadElementContentAsString());
                break;

            case "SensorSignalTypeA":
                // Assign a value to the 2nd port.
                robotSensor.conTypePortA = (SensorConnectionType)Enum.Parse(typeof(SensorConnectionType), reader.ReadElementContentAsString());
                break;

            case "SensorPortNumberB":
                // Assign a port type to the 1st port
                robotSensor.portB = float.Parse(reader.ReadElementContentAsString());
                break;

            case "SensorSignalTypeB":
                // Assign a port type to the 1st port
                robotSensor.conTypePortB = (SensorConnectionType)Enum.Parse(typeof(SensorConnectionType), reader.ReadElementContentAsString());
                break;

            case "SensorConversionFactor":
                // assings the generic conversion facter, this is a different type/ unit for every robot (CPR in encoders)
                robotSensor.conversionFactor = double.Parse(reader.ReadElementContentAsString());
                if (robotSensor.conversionFactor == 0)
                {
                    robotSensor.conversionFactor = 1;
                }
                break;
            }
        }

        return(robotSensor);
    }
Example #10
0
    /// <summary>
    /// Read a RobotSensor from the given XmlReader.
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    private static RobotSensor ReadRobotSensor_5_0(XmlReader reader)
    {
        RobotSensor robotSensor = null;

        //throw (new Exception("Reading thing"));
        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "SensorType":
                // Initialize the RobotSensor.
                robotSensor = new RobotSensor((RobotSensorType)Enum.Parse(typeof(RobotSensorType), reader.ReadElementContentAsString()));
                break;

            case "SensorPortNumberA":
                // Assign a value to the port.
                robotSensor.portA = float.Parse(reader.ReadElementContentAsString());
                break;

            case "SensorSignalTypeA":
                // Assign a value to the port.
                robotSensor.conTypePortA = (SensorConnectionType)Enum.Parse(typeof(SensorConnectionType), reader.ReadElementContentAsString());
                break;

            case "SensorPortNumberB":
                // Assign a value to the port.
                robotSensor.portB = float.Parse(reader.ReadElementContentAsString());
                break;

            case "SensorSignalTypeB":
                // Assign a value to the port.
                robotSensor.conTypePortB = (SensorConnectionType)Enum.Parse(typeof(SensorConnectionType), reader.ReadElementContentAsString());
                break;

            case "SensorConversionFactor":
                // Assign a value to useSecondarySource.
                robotSensor.conversionFactor = double.Parse(reader.ReadElementContentAsString());
                if (robotSensor.conversionFactor == 0)
                {
                    robotSensor.conversionFactor = 1;
                }
                break;
            }
        }

        return(robotSensor);
    }
Example #11
0
    /// <summary>
    /// Reads a LinearJoint_Base from the given XmlReader.
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    private static LinearJoint_Base ReadLinearJoint_3_0(XmlReader reader)
    {
        // Create a new LinearJoint_Base.
        LinearJoint_Base linearJoint = (LinearJoint_Base)SkeletalJoint_Base.JOINT_FACTORY(SkeletalJointType.LINEAR);

        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "BXDVector3":
                switch (reader["VectorID"])
                {
                case "BasePoint":
                    // Assign the BXDVector3 to the basePoint.
                    linearJoint.basePoint = ReadBXDVector3_3_0(reader.ReadSubtree());
                    break;

                case "Axis":
                    // Assign the BXDVector3 to the axis.
                    linearJoint.axis = ReadBXDVector3_3_0(reader.ReadSubtree());
                    break;
                }
                break;

            case "LinearLowLimit":
                // Assign a value to the linearLimitLow.
                linearJoint.hasLowerLimit  = true;
                linearJoint.linearLimitLow = float.Parse(reader.ReadElementContentAsString());
                break;

            case "LinearUpperLimit":
                // Assign a value to the linearLimitHigh.
                linearJoint.hasUpperLimit   = true;
                linearJoint.linearLimitHigh = float.Parse(reader.ReadElementContentAsString());
                break;

            case "CurrentLinearPosition":
                // Assign a value to the currentLinearPosition.
                linearJoint.currentLinearPosition = float.Parse(reader.ReadElementContentAsString());
                break;
            }
        }

        return(linearJoint);
    }
Example #12
0
    /// <summary>
    /// Reads a BallJoint_Base from the given XmlReader.
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    private static BallJoint_Base ReadBallJoint_3_0(XmlReader reader)
    {
        // Create a new BallJoint_Base.
        BallJoint_Base ballJoint = (BallJoint_Base)SkeletalJoint_Base.JOINT_FACTORY(SkeletalJointType.BALL);

        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "BXDVector3":
                // Read the BXDVector3 as the basePoint.
                ballJoint.basePoint = ReadBXDVector3_3_0(reader.ReadSubtree());
                break;
            }
        }

        return(ballJoint);
    }
Example #13
0
    /// <summary>
    /// Reads a BoxCollider with the given XmlReader.
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    private static PropertySet.BoxCollider ReadBoxCollider_2_2(XmlReader reader)
    {
        // Create the BoxCollider.
        PropertySet.BoxCollider boxCollider = null;

        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "BXDVector3":
                // Reads the scale properties and initializes the BoxCollider.
                boxCollider = new PropertySet.BoxCollider(ReadBXDVector3_2_2(reader.ReadSubtree()));
                break;
            }
        }

        return(boxCollider);
    }
Example #14
0
    /// <summary>
    /// Reads an ElevatorDriverMeta from the given XmlReader.
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    private static ElevatorDriverMeta ReadElevatorDriverMeta_3_0(XmlReader reader)
    {
        // Create a new ElevatorDriveMeta.
        ElevatorDriverMeta elevatorDriverMeta = new ElevatorDriverMeta();

        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "ElevatorType":
                // Assign the type to the current element value.
                elevatorDriverMeta.type = (ElevatorType)Enum.Parse(typeof(ElevatorType), reader.ReadElementContentAsString());
                break;
            }
        }

        return(elevatorDriverMeta);
    }
Example #15
0
    /// <summary>
    /// Reads a MeshCollider with the given XmlReader.
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    private static PropertySet.MeshCollider ReadMeshCollider_2_2(XmlReader reader)
    {
        // Create the MeshCollider.
        PropertySet.MeshCollider meshCollider = null;

        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "Convex":
                // Reads the convex property and initializes the MeshCollider.
                meshCollider = new PropertySet.MeshCollider(reader.ReadElementContentAsBoolean());
                break;
            }
        }

        return(meshCollider);
    }
Example #16
0
    /// <summary>
    /// Reads a SphereCollider with the given XmlReader.
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    private static PropertySet.SphereCollider ReadSphereCollider_2_2(XmlReader reader)
    {
        // Create the SphereCollider.
        PropertySet.SphereCollider sphereCollider = null;

        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "Scale":
                // Reads the scale property and initializes the SphereCollider.
                sphereCollider = new PropertySet.SphereCollider(float.Parse(reader.ReadElementContentAsString()));
                break;
            }
        }

        return(sphereCollider);
    }
Example #17
0
    /// <summary>
    /// Reads a RotationalJoint_Base from the given XmlReader.
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    private static RotationalJoint_Base ReadRotationalJoint_3_0(XmlReader reader)
    {
        // Create a new RotationalJoint_Base.
        RotationalJoint_Base rotationalJoint = (RotationalJoint_Base)SkeletalJoint_Base.JOINT_FACTORY(SkeletalJointType.ROTATIONAL);

        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "BXDVector3":
                switch (reader["VectorID"])
                {
                case "BasePoint":
                    // Read the BXDVector3 as the basePoint.
                    rotationalJoint.basePoint = ReadBXDVector3_3_0(reader.ReadSubtree());
                    break;

                case "Axis":
                    // Read the BXDVector3 as the axis.
                    rotationalJoint.axis = ReadBXDVector3_3_0(reader.ReadSubtree());
                    break;
                }
                break;

            case "AngularLowLimit":
                // Assign the current element value to angularLimitLow.
                rotationalJoint.hasAngularLimit = true;
                rotationalJoint.angularLimitLow = float.Parse(reader.ReadElementContentAsString());
                break;

            case "AngularHighLimit":
                // Assign the current element value to angularLimitHigh.
                rotationalJoint.angularLimitHigh = float.Parse(reader.ReadElementContentAsString());
                break;

            case "CurrentAngularPosition":
                // Assign the current element value to currentAngularPosition.
                rotationalJoint.currentAngularPosition = float.Parse(reader.ReadElementContentAsString());
                break;
            }
        }

        return(rotationalJoint);
    }
Example #18
0
    /// <summary>
    /// Reads the subtree of a PropertySet element.
    /// </summary>
    /// <param name="reader"></param>
    /// <param name="fieldDefinition"></param>
    private static void ReadPropertySet_2_2(XmlReader reader, FieldDefinition fieldDefinition)
    {
        // Creates a new PropertySet.
        PropertySet propertySet = new PropertySet();

        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "PropertySet":
                // Assigns the ID attribute value to the PropertySetID property.
                propertySet.PropertySetID = reader["ID"];
                break;

            case "BoxCollider":
                // Assigns the BoxCollider read by the XmlReader to the PropertySet's Collider property.
                propertySet.Collider = ReadBoxCollider_2_2(reader.ReadSubtree());
                break;

            case "SphereCollider":
                // Assigns the SphereCollider read by the XmlReader to the PropertySet's Collider property.
                propertySet.Collider = ReadSphereCollider_2_2(reader.ReadSubtree());
                break;

            case "MeshCollider":
                // Assigns the MeshCollider read by the XmlReader to the PropertySet's Collider property.
                propertySet.Collider = ReadMeshCollider_2_2(reader.ReadSubtree());
                break;

            case "Friction":
                // Assings the Friction attribute value to the Friction property.
                propertySet.Friction = reader.ReadElementContentAsInt();
                break;

            case "Mass":
                // Assings the Mass attribute value to the Mass property.
                propertySet.Mass = float.Parse(reader.ReadElementContentAsString());
                break;
            }
        }

        // Adds the PropertySet to the fieldDefinition.
        fieldDefinition.AddPropertySet(propertySet);
    }
Example #19
0
    /// <summary>
    /// Reads a Polynomial from the given XmlReader.
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    private static Polynomial ReadPolynomial_3_0(XmlReader reader)
    {
        // Initialize a list of floats.
        List <float> coeff = new List <float>();

        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "Coefficient":
                // Add a new coefficient to the list of floats.
                coeff.Add(float.Parse(reader.ReadElementContentAsString()));
                break;
            }
        }

        // Convert the list of floats to a Polynomial.
        return(new Polynomial(coeff.ToArray()));
    }
Example #20
0
    /// <summary>
    /// Reads the subtree of a FieldNode and returns the result.
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    private static FieldNode ReadFieldNode_2_2(XmlReader reader)
    {
        FieldNode node = null;

        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "Node":
                node = new FieldNode(reader["ID"]);
                break;

            case "BXDVector3":
                // Read the BXDVector3 as the node's position.
                node.Position = ReadBXDVector3_2_2(reader.ReadSubtree());
                break;

            case "BXDQuaternion":
                // Read the BXDVector3 as the node's rotation.
                node.Rotation = ReadBXDQuaternion_2_2(reader.ReadSubtree());
                break;

            case "SubMeshID":
                // Assign the MeshID attribute value to the SubMeshID property.
                node.SubMeshID = reader.ReadElementContentAsInt();
                break;

            case "CollisionMeshID":
                // Assign the CollisionMeshID attribute value to the CollisionMeshID property.
                node.CollisionMeshID = reader.ReadElementContentAsInt();
                break;

            case "PropertySetID":
                // Assign the PropertySetID attribute value to the PropertySetID property.
                node.PropertySetID = reader.ReadElementContentAsString();
                break;
            }
        }

        return(node);
    }
Example #21
0
    /// <summary>
    /// Reads a PneumaticDriverMeta from the given XmlReader.
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    private static PneumaticDriverMeta ReadPneumaticDriverMeta_3_0(XmlReader reader)
    {
        // Create a new pneumaticDriverMeta.
        PneumaticDriverMeta pneumaticDriverMeta = new PneumaticDriverMeta();

        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "WidthMM":
                // Assign the current element value to widthMM.
                pneumaticDriverMeta.widthMM = reader.ReadElementContentAsInt();
                break;

            case "PressurePSI":
                // Assign the current element value to pressurePSI.
                pneumaticDriverMeta.pressurePSI = float.Parse(reader.ReadElementContentAsString());
                break;
            }
        }

        return(pneumaticDriverMeta);
    }
Example #22
0
    /// <summary>
    /// Read a RobotSensor from the given XmlReader.
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    private static RobotSensor ReadRobotSensor_3_0(XmlReader reader)
    {
        RobotSensor robotSensor = null;

        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "SensorType":
                // Initialize the RobotSensor.
                robotSensor = new RobotSensor((RobotSensorType)Enum.Parse(typeof(RobotSensorType), reader.ReadElementContentAsString()));
                break;

            case "SensorModule":
                // Assign a value to the module.
                short m = (short)reader.ReadElementContentAsInt();
                break;

            case "SensorPort":
                // Assign a value to the port.
                short s = (short)reader.ReadElementContentAsInt();
                break;

            case "Polynomial":
                // Create a polynomial and assign it to the equation.
                Polynomial e = ReadPolynomial_3_0(reader.ReadSubtree());
                break;

            case "UseSecondarySource":
                // Assign a value to useSecondarySource.
                reader.ReadElementContentAsBoolean();
                break;
            }
        }

        return(robotSensor);
    }
Example #23
0
    /// <summary>
    /// Reads a RigidNode_Base with the given reader, list of nodes, and root node reference.
    /// </summary>
    /// <param name="reader"></param>
    /// <param name="nodes"></param>
    /// <param name="root"></param>
    private static void ReadNode_3_0(XmlReader reader, List <RigidNode_Base> nodes, ref RigidNode_Base root)
    {
        int parentID = -1;

        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "Node":
                // Adds a new node to the list of RigidNode_Bases.
                nodes.Add(RigidNode_Base.NODE_FACTORY(new Guid(reader["GUID"])));
                break;

            case "ParentID":
                // Stores this ID for later use.
                parentID = reader.ReadElementContentAsInt();

                if (parentID == -1)     // If this is the root...
                {
                    root = nodes[nodes.Count - 1];
                }
                break;

            case "ModelFileName":
                // Assigns the ModelFileName property to the ModelFileName element value.
                nodes[nodes.Count - 1].ModelFileName = reader.ReadElementContentAsString();
                break;

            case "ModelID":
                // Assigns the ModelFullID property to the ModelID element value.
                nodes[nodes.Count - 1].ModelFullID = reader.ReadElementContentAsString();
                break;

            case "BallJoint":
                // Reads the current element as a BallJoint.
                nodes[parentID].AddChild(ReadBallJoint_3_0(reader.ReadSubtree()), nodes[nodes.Count - 1]);
                break;

            case "CylindricalJoint":
                // Reads the current element as a CylindricalJoint.
                nodes[parentID].AddChild(ReadCylindricalJoint_3_0(reader.ReadSubtree()), nodes[nodes.Count - 1]);
                break;

            case "LinearJoint":
                // Reads the current element as a LinearJoint.
                nodes[parentID].AddChild(ReadLinearJoint_3_0(reader.ReadSubtree()), nodes[nodes.Count - 1]);
                break;

            case "PlanarJoint":
                // Reads the current element as a PlanarJoint.
                nodes[parentID].AddChild(ReadPlanarJoint_3_0(reader.ReadSubtree()), nodes[nodes.Count - 1]);
                break;

            case "RotationalJoint":
                // Reads the current elemenet as a RotationalJoint.
                nodes[parentID].AddChild(ReadRotationalJoint_3_0(reader.ReadSubtree()), nodes[nodes.Count - 1]);
                break;

            case "JointDriver":
                // Add a joint driver to the skeletal joint of the current node.
                nodes[nodes.Count - 1].GetSkeletalJoint().cDriver = ReadJointDriver_3_0(reader.ReadSubtree());
                break;

            case "RobotSensor":
                nodes[nodes.Count - 1].GetSkeletalJoint().attachedSensors.Add(ReadRobotSensor_3_0(reader.ReadSubtree()));
                break;
            }
        }
    }
Example #24
0
    /// <summary>
    /// Reads a WheelDriverMeta from the given XmlReader.
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    private static WheelDriverMeta ReadWheelDriverMeta_3_0(XmlReader reader)
    {
        // Create new WheelDriveMeta.
        WheelDriverMeta wheelDriverMeta = new WheelDriverMeta();

        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "WheelType":
                // Assign a value to the type.
                wheelDriverMeta.type = (WheelType)Enum.Parse(typeof(WheelType), reader.ReadElementContentAsString());
                break;

            case "WheelRadius":
                // Assign a value to the radius.
                wheelDriverMeta.radius = float.Parse(reader.ReadElementContentAsString());
                break;

            case "WheelWidth":
                // Assign a value to the width.
                wheelDriverMeta.width = float.Parse(reader.ReadElementContentAsString());
                break;

            case "BXDVector3":
                // Assign a value to the center.
                wheelDriverMeta.center = ReadBXDVector3_3_0(reader.ReadSubtree());
                break;

            case "ForwardAsympSlip":
                // Assign a value to the forwardAsympSlip.
                wheelDriverMeta.forwardAsympSlip = float.Parse(reader.ReadElementContentAsString());
                break;

            case "ForwardAsympValue":
                // Assign a value to the forwardAsympValue.
                wheelDriverMeta.forwardAsympValue = float.Parse(reader.ReadElementContentAsString());
                break;

            case "ForwardExtremeSlip":
                // Assign a value to the forwardExtremeSlip.
                wheelDriverMeta.forwardExtremeSlip = float.Parse(reader.ReadElementContentAsString());
                break;

            case "ForwardExtremeValue":
                // Assign a value to the forwardExtremeValue.
                wheelDriverMeta.forwardExtremeValue = float.Parse(reader.ReadElementContentAsString());
                break;

            case "SideAsympSlip":
                // Assign a value to the sideAsympSlip.
                wheelDriverMeta.sideAsympSlip = float.Parse(reader.ReadElementContentAsString());
                break;

            case "SideAsympValue":
                // Assign a value to the sideAsympValue.
                wheelDriverMeta.sideAsympValue = float.Parse(reader.ReadElementContentAsString());
                break;

            case "SideExtremeSlip":
                // Assign a value to the sideExtremeSlip.
                wheelDriverMeta.sideExtremeSlip = float.Parse(reader.ReadElementContentAsString());
                break;

            case "SideExtremeValue":
                // Assign a value to the sideExtremeValue.
                wheelDriverMeta.sideExtremeValue = float.Parse(reader.ReadElementContentAsString());
                break;

            case "IsDriveWheel":
                // Assign a value to isDriveWheel.
                wheelDriverMeta.isDriveWheel = reader.ReadElementContentAsBoolean();
                break;
            }
        }

        return(wheelDriverMeta);
    }
Example #25
0
    /// <summary>
    /// Reads a JointDriver from the given XmlReader.
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    private static JointDriver ReadJointDriver_4_2(XmlReader reader)
    {
        JointDriver driver = null;

        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "DriveType":
                // Initialize the driver.
                driver = new JointDriver((JointDriverType)Enum.Parse(typeof(JointDriverType), reader.ReadElementContentAsString()));
                break;

            case "Port1":
                // Assign a value to port1.
                driver.port1 = reader.ReadElementContentAsInt();
                break;

            case "Port2":
                // Assign a value to port2.
                driver.port2 = reader.ReadElementContentAsInt();
                break;

            case "InputGear":
                // Assign a value to InputGear
                driver.InputGear = reader.ReadElementContentAsDouble();
                break;

            case "OutputGear":
                // Assign a value to OutputGear
                driver.OutputGear = reader.ReadElementContentAsDouble();
                break;

            case "LowerLimit":
                // Assign a value to the lowerLimit.
                driver.lowerLimit = float.Parse(reader.ReadElementContentAsString());
                break;

            case "UpperLimit":
                // Assign a value to the upperLimit.
                driver.upperLimit = float.Parse(reader.ReadElementContentAsString());
                break;

            case "HasBrake":
                // Assign a value to the upperLimit.
                driver.hasBrake = reader.ReadElementContentAsBoolean();
                break;

            case "SignalType":
                // Assign a value to isCan.
                driver.isCan = reader.ReadElementContentAsString().Equals("CAN") ? true : false;
                break;

            case "ElevatorDriverMeta":
                // Add an ElevatorDriverMeta.
                driver.AddInfo(ReadElevatorDriverMeta_4_2(reader.ReadSubtree()));
                break;

            case "PneumaticDriverMeta":
                // Add a PneumaticsDriverMeta.
                driver.AddInfo(ReadPneumaticDriverMeta_4_2(reader.ReadSubtree()));
                break;

            case "WheelDriverMeta":
                // Add a WheelDriverMeta.
                driver.AddInfo(ReadWheelDriverMeta_4_2(reader.ReadSubtree()));
                break;
            }
        }

        return(driver);
    }
Example #26
0
    /// <summary>
    /// Reads a CylindricalJoint_Base from the given XmlReader.
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    private static CylindricalJoint_Base ReadCylindricalJoint_3_0(XmlReader reader)
    {
        // Create a new CylindricalJoint_Base.
        CylindricalJoint_Base cylindricalJoint = (CylindricalJoint_Base)SkeletalJoint_Base.JOINT_FACTORY(SkeletalJointType.CYLINDRICAL);

        foreach (string name in IOUtilities.AllElements(reader))
        {
            switch (name)
            {
            case "BXDVector3":
                switch (reader["VectorID"])
                {
                case "BasePoint":
                    // Assign the BXDVector3 to the basePoint.
                    cylindricalJoint.basePoint = ReadBXDVector3_3_0(reader.ReadSubtree());
                    break;

                case "Axis":
                    // Assign the BXDVector3 to the axis.
                    cylindricalJoint.axis = ReadBXDVector3_3_0(reader.ReadSubtree());
                    break;
                }
                break;

            case "AngularLowLimit":
                // Assign a value to the angularLimitLow.
                cylindricalJoint.hasAngularLimit = true;
                cylindricalJoint.angularLimitLow = float.Parse(reader.ReadElementContentAsString());
                break;

            case "AngularHighLimit":
                // Assign a value to the angularLimitHigh.
                cylindricalJoint.angularLimitHigh = float.Parse(reader.ReadElementContentAsString());
                break;

            case "LinearStartLimit":
                // Assign a value to the linearLimitStart.
                cylindricalJoint.hasLinearStartLimit = true;
                cylindricalJoint.linearLimitStart    = float.Parse(reader.ReadElementContentAsString());
                break;

            case "LinearEndLimit":
                // Assign a value to the linearLimitEnd.
                cylindricalJoint.hasLinearEndLimit = true;
                cylindricalJoint.linearLimitEnd    = float.Parse(reader.ReadElementContentAsString());
                break;

            case "CurrentLinearPosition":
                // Assign a value to the currentLinearPosition.
                cylindricalJoint.currentLinearPosition = float.Parse(reader.ReadElementContentAsString());
                break;

            case "CurrentAngularPosition":
                // Assign a value to the currentAngularPosition.
                cylindricalJoint.currentAngularPosition = float.Parse(reader.ReadElementContentAsString());
                break;
            }
        }

        return(cylindricalJoint);
    }