Example #1
0
        public object BeginLoad(XmlElementReader element)
        {
            switch (element.Attribute("style").Text)
            {
            case "solid":
            default:
                Style = ConnectionStyle.Solid;
                break;

            case "dashed":
                Style = ConnectionStyle.Dashed;
                break;
            }
            switch (element.Attribute("flow").Text)
            {
            case "twoWay":
            default:
                Flow = ConnectionFlow.TwoWay;
                break;

            case "oneWay":
                Flow = ConnectionFlow.OneWay;
                break;
            }
            StartText = element.Attribute("startText").Text;
            MidText   = element.Attribute("midText").Text;
            EndText   = element.Attribute("endText").Text;

            var vertexElementList = new List <XmlElementReader>();

            vertexElementList.AddRange(element.Children);
            vertexElementList.Sort((a, b) => { return(a.Attribute("index").ToInt().CompareTo(b.Attribute("index").ToInt())); });

            foreach (var vertexElement in vertexElementList)
            {
                if (vertexElement.HasName("point"))
                {
                    var vertex = new Vertex();
                    vertex.Position = new Vector(vertexElement.Attribute("x").ToFloat(), vertexElement.Attribute("y").ToFloat());
                    VertexList.Add(vertex);
                }
                else if (vertexElement.HasName("dock"))
                {
                    var vertex = new Vertex();
                    // temporarily leave this vertex as a positional vertex;
                    // we can't safely dock it to a port until EndLoad().
                    VertexList.Add(vertex);
                }
            }

            return(vertexElementList);
        }
Example #2
0
 public void Load(XmlElementReader element)
 {
     Name = element.Attribute("name").Text;
     ClearDescriptions();
     AddDescription(element.Attribute("description").Text);
     Position        = new Vector(element.Attribute("x").ToFloat(), element.Attribute("y").ToFloat());
     Size            = new Vector(element.Attribute("w").ToFloat(), element.Attribute("h").ToFloat());
     IsDark          = element.Attribute("isDark").ToBool();
     Objects         = element["objects"].Text.Replace("|", "\r\n").Replace("\\\r\n", "|");
     ObjectsPosition = element["objects"].Attribute("at").ToCompassPoint(ObjectsPosition);
 }
Example #3
0
        public bool Load()
        {
            try
            {
                if (new FileInfo(FileName).Length == 0)
                {
                    // this is an empty file, probably thanks to our Explorer New->Trizbort Map menu option.
                    Settings.Reset();
                    return(true);
                }

                var doc = new XmlDocument();
                doc.Load(FileName);
                var root = new XmlElementReader(doc.DocumentElement);

                if (!root.HasName("trizbort"))
                {
                    throw new InvalidDataException(string.Format("Not a {0} map file.", Application.ProductName));
                }

                // file version
                var versionNumber = root.Attribute("version").Text;
                setVersion(versionNumber);

                // load info
                Title       = root["info"]["title"].Text;
                Author      = root["info"]["author"].Text;
                Description = root["info"]["description"].Text;
                History     = root["info"]["history"].Text;

                // load all elements
                var map = root["map"];
                var mapConnectionToLoadState = new Dictionary <Connection, object>();
                foreach (var element in map.Children)
                {
                    if (element.HasName("room"))
                    {
                        // Changed the constructor used for elements when loading a file for a significant speed increase
                        var room = new Room(this, Elements.Count + 1);
                        room.ID = element.Attribute("id").ToInt(room.ID);
                        room.Load(element);
                        Elements.Add(room);
                    }
                    else if (element.HasName("line"))
                    {
                        // Changed the constructor used for elements when loading a file for a significant speed increase
                        var connection = new Connection(this, Elements.Count + 1);
                        connection.ID = element.Attribute("id").ToInt(connection.ID);
                        var loadState = connection.BeginLoad(element);
                        if (loadState != null)
                        {
                            mapConnectionToLoadState.Add(connection, loadState);
                        }
                        Elements.Add(connection);
                    }
                }

                // connect them together
                foreach (var pair in mapConnectionToLoadState)
                {
                    var connection = pair.Key;
                    var state      = pair.Value;
                    connection.EndLoad(state);
                }

                // load settings last, since their load can't be undone
                Settings.Reset();
                Settings.Load(root["settings"]);
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(Program.MainForm, string.Format("There was a problem loading the map:\n\n{0}", ex.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
Example #4
0
        public bool Load()
        {
            try
              {
            if (new FileInfo(FileName).Length == 0)
            {
              // this is an empty file, probably thanks to our Explorer New->Trizbort Map menu option.
              Settings.Reset();
              return true;
            }

            var doc = new XmlDocument();
            doc.Load(FileName);
            var root = new XmlElementReader(doc.DocumentElement);

            if (!root.HasName("trizbort"))
              throw new InvalidDataException(string.Format("Not a {0} map file.", Application.ProductName));

            // file version
            var versionNumber = root.Attribute("version").Text;
            setVersion(versionNumber);

            // load info
            Title = root["info"]["title"].Text;
            Author = root["info"]["author"].Text;
            Description = root["info"]["description"].Text;
            History = root["info"]["history"].Text;

            // load all elements
            var map = root["map"];
            var mapConnectionToLoadState = new Dictionary<Connection, object>();
            foreach (var element in map.Children)
            {
              if (element.HasName("room"))
              {
            // Changed the constructor used for elements when loading a file for a significant speed increase
            var room = new Room(this, Elements.Count + 1);
            room.ID = element.Attribute("id").ToInt(room.ID);
            room.Load(element);
            Elements.Add(room);
              }
              else if (element.HasName("line"))
              {
            // Changed the constructor used for elements when loading a file for a significant speed increase
            var connection = new Connection(this, Elements.Count + 1);
            connection.ID = element.Attribute("id").ToInt(connection.ID);
            var loadState = connection.BeginLoad(element);
            if (loadState != null)
            {
              mapConnectionToLoadState.Add(connection, loadState);
            }
            Elements.Add(connection);
              }
            }

            // connect them together
            foreach (var pair in mapConnectionToLoadState)
            {
              var connection = pair.Key;
              var state = pair.Value;
              connection.EndLoad(state);
            }

            // load settings last, since their load can't be undone
            Settings.Reset();
            Settings.Load(root["settings"]);
            return true;
              }
              catch (Exception ex)
              {
            MessageBox.Show(Program.MainForm, string.Format("There was a problem loading the map:\n\n{0}", ex.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            return false;
              }
        }
Example #5
0
        public object BeginLoad(XmlElementReader element)
        {
            switch (element.Attribute("style").Text)
              {
            case "solid":
            default:
              Style = ConnectionStyle.Solid;
              break;
            case "dashed":
              Style = ConnectionStyle.Dashed;
              break;
              }
              switch (element.Attribute("flow").Text)
              {
            case "twoWay":
            default:
              Flow = ConnectionFlow.TwoWay;
              break;
            case "oneWay":
              Flow = ConnectionFlow.OneWay;
              break;
              }
              StartText = element.Attribute("startText").Text;
              MidText = element.Attribute("midText").Text;
              EndText = element.Attribute("endText").Text;
              if (element.Attribute("color").Text != "") { ConnectionColor = ColorTranslator.FromHtml(element.Attribute("color").Text); }

              var vertexElementList = new List<XmlElementReader>();
              vertexElementList.AddRange(element.Children);
              vertexElementList.Sort((a, b) => a.Attribute("index").ToInt().CompareTo(b.Attribute("index").ToInt()));

              foreach (var vertexElement in vertexElementList)
              {
            if (vertexElement.HasName("point"))
            {
              var vertex = new Vertex();
              vertex.Position = new Vector(vertexElement.Attribute("x").ToFloat(), vertexElement.Attribute("y").ToFloat());
              VertexList.Add(vertex);
            }
            else if (vertexElement.HasName("dock"))
            {
              var vertex = new Vertex();
              // temporarily leave this vertex as a positional vertex;
              // we can't safely dock it to a port until EndLoad().
              VertexList.Add(vertex);
            }
              }

              return vertexElementList;
        }
Example #6
0
 public void Load(XmlElementReader element)
 {
     Name = element.Attribute("name").Text;
     ClearDescriptions();
     AddDescription(element.Attribute("description").Text);
     Position = new Vector(element.Attribute("x").ToFloat(), element.Attribute("y").ToFloat());
     Size = new Vector(element.Attribute("w").ToFloat(), element.Attribute("h").ToFloat());
     IsDark = element.Attribute("isDark").ToBool();
     Objects = element["objects"].Text.Replace("|","\r\n").Replace("\\\r\n", "|");
     ObjectsPosition = element["objects"].Attribute("at").ToCompassPoint(ObjectsPosition);
 }
Example #7
0
 public void Load(XmlElementReader element)
 {
     Name = element.Attribute("name").Text;
     ClearDescriptions();
     AddDescription(element.Attribute("description").Text);
     Position = new Vector(element.Attribute("x").ToFloat(), element.Attribute("y").ToFloat());
     Size = new Vector(element.Attribute("w").ToFloat(), element.Attribute("h").ToFloat());
     IsDark = element.Attribute("isDark").ToBool();
     if (element.Attribute("roomFill").Text != "") { RoomFill = ColorTranslator.FromHtml(element.Attribute("roomFill").Text); }
     if (element.Attribute("secondFill").Text != "") { SecondFill = ColorTranslator.FromHtml(element.Attribute("secondFill").Text); }
     if (element.Attribute("secondFillLocation").Text != "") { SecondFillLocation = element.Attribute("secondFillLocation").Text; }
     if (element.Attribute("roomBorder").Text != "") { RoomBorder = ColorTranslator.FromHtml(element.Attribute("roomBorder").Text); }
     if (element.Attribute("roomLargeText").Text != "") { RoomLargeText = ColorTranslator.FromHtml(element.Attribute("roomLargeText").Text); }
     if (element.Attribute("roomSmallText").Text != "") { RoomSmallText = ColorTranslator.FromHtml(element.Attribute("roomSmallText").Text); }
     Objects = element["objects"].Text.Replace("|", "\r\n").Replace("\\\r\n", "|");
     ObjectsPosition = element["objects"].Attribute("at").ToCompassPoint(ObjectsPosition);
 }