public override string SaveStimulusToXml()
        {
            if(m_doStructure == null)
                throw new System.Exception("No structure was defined for the stimulus '" + m_strName + "'.");

            if(m_doBodyPart == null)
                throw new System.Exception("No bodypart was defined for the stimulus '" + m_strName + "'.");

            if(m_thPrimaryAttachment != null && m_thPrimaryAttachment.BodyPart != null &&
                m_thSecondaryAttachment != null && m_thSecondaryAttachment.BodyPart != null)
            {
                AnimatTools.Interfaces.StdXml oXml = new AnimatTools.Interfaces.StdXml();

                oXml.AddElement("Stimuli");
                SaveXml(ref oXml);

                return oXml.Serialize();
            }
            else
                return "";
        }
        public override string SaveStimulusToXml()
        {
            if(m_doOrganism == null)
                throw new System.Exception("No organism was defined for the stimulus '" + m_strName + "'.");

            if(m_doNode == null)
                throw new System.Exception("No node was defined for the stimulus '" + m_strName + "'.");

            if(m_doNode != null && m_thMuscle != null && m_thMuscle.BodyPart != null && m_strMuscleLengthData != null && m_strMuscleLengthData.Length > 0)
            {
                AnimatTools.Interfaces.StdXml oXml = new AnimatTools.Interfaces.StdXml();

                oXml.AddElement("Stimuli");
                SaveXml(ref oXml);

                return oXml.Serialize();
            }
            else
                return "";
        }
        protected virtual AnimatTools.DataObjects.Physical.BodyPart CreateNewBodyPart(AnimatTools.Framework.DataObject doParent, ref bool bNewJoint)
        {
            AnimatTools.DataObjects.Physical.RigidBody bpPart = null;
            bNewJoint = true;

            if(Editor.CommandBar.CommandMode == AnimatTools.Forms.BodyPlan.Command.enumCommandMode.AddBodies)
            {
                bpPart = (AnimatTools.DataObjects.Physical.RigidBody) Editor.CommandBar.SelectedBodyPartType.CreateNewBodyPart(doParent);

                Editor.PhysicalStructure.NewBodyIndex++;
                bpPart.Name = "Body_" + Editor.PhysicalStructure.NewBodyIndex.ToString();
            }
            else if(Editor.CommandBar.CommandMode == AnimatTools.Forms.BodyPlan.Command.enumCommandMode.PasteBodies)
            {
                IDataObject data = Clipboard.GetDataObject();

                if(data!= null && data.GetDataPresent("AnimatLab.Body.XMLFormat"))
                {
                    string strXml = (string) data.GetData("AnimatLab.Body.XMLFormat");
                    if(strXml != null && strXml.Trim().Length > 0 )
                    {
                        AnimatTools.Interfaces.StdXml oXml = new AnimatTools.Interfaces.StdXml();
                        oXml.Deserialize(strXml);
                        oXml.FindElement("CopyData");
                        oXml.FindChildElement("RigidBody");

                        AnimatTools.DataObjects.Physical.PhysicalStructure doStruct = this.Editor.PhysicalStructure;
                        AnimatTools.DataObjects.Physical.PhysicalStructure doTempStruct = new AnimatTools.DataObjects.Physical.PhysicalStructure(null);
                        AnimatTools.DataObjects.Simulation doSim = Util.Simulation;
                        bpPart = (AnimatTools.DataObjects.Physical.RigidBody) doSim.CreateObject(ref oXml, "RigidBody", doParent);
                        bpPart.LoadData(ref doSim, ref doTempStruct, ref oXml);

                        //If the part we are pasting used to be a root object then we need to add a joint to it
                        if(bpPart.JointToParent == null && bpPart.UsesAJoint)
                        {
                            //create the joint to the parent
                            Joints.Joint_DX bpJointToParent = (Joints.Joint_DX) Editor.CommandBar.SelectedJointType.CreateNewBodyPart(bpPart);

                            bpJointToParent.Device = m_d3dDevice;
                            //set the joint's parent
                            doStruct.NewJointIndex++;
                            bpJointToParent.Name = "Joint_" + doStruct.NewJointIndex.ToString();

                            //set the location of the joint
                            bpJointToParent.DxLocation = new Vector3(0, 0, 0);

                            //add the joint to the new part
                            bpPart.JointToParent = bpJointToParent;
                        }

                    }
                }

                if(bpPart == null)
                {
                    bpPart = (AnimatTools.DataObjects.Physical.RigidBody) Editor.CommandBar.SelectedBodyPartType.CreateNewBodyPart(doParent);
                    Editor.PhysicalStructure.NewBodyIndex++;
                    bpPart.Name = "Body_" + Editor.PhysicalStructure.NewBodyIndex.ToString();
                }

                if(bpPart.JointToParent != null && Editor.CommandBar.SelectedJointType != null && bpPart.JointToParent.Type == Editor.CommandBar.SelectedJointType.Type)
                    bNewJoint = false;
                else
                    bpPart.JointToParent = null;
            }
            else
                throw new System.Exception("Command mode must be either AddBodies or PasteBodies to create a new body part.");

            return bpPart;
        }