public void writeXMLFile(BodyParts input) { StreamWriter writer = new StreamWriter(DEFAULT_OUTPUT); String xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; xml += input.toXML(); writer.Write(xml); writer.Close(); }
public BodyParts parse() { BodyParts bodyparts = new BodyParts(); XmlDocument doc = new XmlDocument(); doc.Load(this.xmlFile); XmlNode xNode = doc.DocumentElement; if ((xNode.Name == Constants.FILENAME) && (xNode.HasChildNodes)) { foreach (XmlNode node in xNode.ChildNodes) { //parse BODYPART tags if (node.Name == Constants.BODYPART_ELEMENT) { BodyPart bodypart = new BodyPart(node.Attributes["NAME"].Value); //parse ORIENTATION tags foreach (XmlNode child in node.ChildNodes) { if (child.Name == Constants.ORIENTATION_ELEMENT) { Orientation o = new Orientation(); //fill in orientation objects based on imagefile, label, desc tags foreach (XmlNode grandchild in child.ChildNodes) { if (grandchild.Name == Constants.IMAGEFILE_ELEMENT) { o.Imagefile = grandchild.Attributes["NAME"].Value; } else if (grandchild.Name == Constants.DESCRIPTION_ELEMENT) { o.Description = grandchild.Attributes["NAME"].Value; } else if (grandchild.Name == Constants.LABEL_ELEMENT) { o.Label = grandchild.Attributes["NAME"].Value; } } bodypart.Orientations.Add(o); } } bodyparts.Bodyparts.Add(bodypart); } } } return bodyparts; }
private void InitializeInterface() { orientationMatrix = new int[SimilarActivitiesForm.ConfusingActivities.Count][]; //orientationIndex = new int[SimilarActivitiesForm.ConfusingActivities.Count][]; SXML.Reader sreader = new SXML.Reader(Constants.MASTER_DIRECTORY, TroubleshootModel.SelectedFolder); if (sreader.validate() == false) { throw new Exception("Error Code 0: XML format error - sensors.xml does not match sensors.xsd!"); } else { this.sensors = sreader.parse(Constants.MAX_CONTROLLERS); } for (int i = 0; (i < OrientationForm.orientationMatrix.Length); i++) { OrientationForm.orientationMatrix[i] = new int[this.sensors.Sensors.Count]; // this.orientationIndex[i] = new int[this.sensors.Sensors.Count]; for (int j = 0; (j < this.sensors.Sensors.Count); j++) { OrientationForm.orientationMatrix[i][j] = -1; // this.orientationIndex[i][j] = 0; } } BodyXML.Parser parser = new BodyXML.Parser(Constants.MASTER_DIRECTORY); this.bodyParts = parser.parse(); this.body_parts=new ArrayList(); this.body_parts_orientations= new ArrayList(); this.body_parts_orientations_names= new ArrayList(); int maxImageWidth = 0; int maxImageHeight = 0; foreach (BodyPart bodyPart in this.bodyParts.Bodyparts) { this.body_parts.Add(bodyPart.Label); ArrayList orientations= new ArrayList(); ArrayList names=new ArrayList(); foreach (BodyXML.Orientation orientation in bodyPart.Orientations){ System.Drawing.Image orientationImage=(System.Drawing.Image) new System.Drawing.Bitmap(Constants.NEEDED_FILES_PATH + "images\\orientations\\"+orientation.Imagefile); if (orientationImage.Width > maxImageWidth) maxImageWidth = orientationImage.Width; if (orientationImage.Height > maxImageHeight) maxImageHeight = orientationImage.Height; orientations.Add(orientationImage); names.Add(orientation.Label); } this.body_parts_orientations.Add(orientations); this.body_parts_orientations_names.Add(names); } this.bodyPartCurrentIndex = 0; this.orientationCurrentIndex = 0; this.activityCurrentIndex = 0; //this.pictureBox1.Width = maxImageWidth+Constants.WIDGET_SPACING*2; //this.pictureBox1.Height = maxImageHeight + Constants.WIDGET_SPACING * 2; //this.panel1.Width = this.pictureBox1.Width + Constants.WIDGET_SPACING * 2; //this.panel1.Height = this.pictureBox1.Height + Constants.WIDGET_SPACING * 2; this.panel1.BackColor = System.Drawing.Color.White; //this.button1.Location = new System.Drawing.Point(this.panel1.Location.X, this.panel1.Location.Y + this.panel1.Location.Y); //this.button2.Location = new System.Drawing.Point(this.panel1.Location.X, this.panel1.Location.Y + this.button1.Location.Y+this.button1.Width+Constants.WIDGET_SPACING); this.pictureBox1.Image = (System.Drawing.Image)((ArrayList)this.body_parts_orientations[this.bodyPartCurrentIndex])[this.orientationCurrentIndex]; this.label2.Text = (string)((ArrayList)this.body_parts_orientations_names[this.bodyPartCurrentIndex])[this.orientationCurrentIndex]; this.label1.Text = "During " + (string)SimilarActivitiesForm.ConfusingActivities[activityCurrentIndex] + ", how does your "+(string)this.body_parts[this.bodyPartCurrentIndex]+" look like?"; }