Exemplo n.º 1
0
 public void Copy(DrawingLayer acopy, bool includeDrawObjects)
 {
     if (includeDrawObjects)
     {
         throw new Exception("not supported yet");
     }
     m_id      = acopy.m_id;
     m_name    = acopy.m_name;
     m_color   = acopy.m_color;
     m_width   = acopy.m_width;
     m_enabled = acopy.m_enabled;
     m_visible = acopy.m_visible;
 }
Exemplo n.º 2
0
        /// <summary>
        /// 加载文件
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public bool Load(string filename)
        {
            try
            {
                StreamReader sr = new StreamReader(filename);
                //XmlTextReader rd = new XmlTextReader(sr);
                XmlDocument doc = new XmlDocument();
                doc.Load(sr);
                sr.Dispose();
                XmlElement root = doc.DocumentElement;
                if (root.Name != "CanvasDataModel")
                {
                    return(false);
                }

                m_layers.Clear();
                m_undoBuffer.Clear();
                m_undoBuffer.Dirty = false;
                foreach (XmlElement childnode in root.ChildNodes)
                {
                    if (childnode.Name == "backgroundlayer")
                    {
                        XmlUtil.ParseProperties(childnode, m_backgroundLayer);
                        continue;
                    }
                    if (childnode.Name == "gridlayer")
                    {
                        XmlUtil.ParseProperties(childnode, m_gridLayer);
                        continue;
                    }
                    if (childnode.Name == "layer")
                    {
                        DrawingLayer l = DrawingLayer.NewLayer(childnode as XmlElement);
                        m_layers.Add(l);
                    }

                    if (childnode.Name == "property")
                    {
                        XmlUtil.ParseProperty(childnode, this);
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                DefaultLayer();
                Console.WriteLine("Load exception - {0}", e.Message);
            }

            return(false);
        }
Exemplo n.º 3
0
        public IDrawObject CreateObject(string type, UnitPoint point, ISnapPoint snappoint)
        {
            DrawingLayer layer = ActiveLayer as DrawingLayer;

            if (layer.Enabled == false)
            {
                return(null);
            }
            DrawTools.DrawObjectBase newobj = CreateObject(type);
            if (newobj != null)
            {
                newobj.Layer = layer;
                newobj.InitializeFromModel(point, layer, snappoint);
            }
            return(newobj as IDrawObject);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 绑定选项
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnOptions(object sender, EventArgs e)
        {
            DocumentForm doc = this.ActiveMdiChild as DocumentForm;

            if (doc == null)
            {
                return;
            }

            Options.OptionsDlg dlg = new Canvas.Options.OptionsDlg();
            dlg.Config.Grid.CopyFromLayer(doc.Model.GridLayer as GridLayer);
            dlg.Config.Background.CopyFromLayer(doc.Model.BackgroundLayer as BackgroundLayer);

            foreach (DrawingLayer layer in doc.Model.Layers)
            {
                dlg.Config.Layers.Add(new Options.OptionsLayer(layer));
            }

            ToolStripItem item = sender as ToolStripItem;

            dlg.SelectPage(item.Tag);

            if (dlg.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            dlg.Config.Grid.CopyToLayer((GridLayer)doc.Model.GridLayer);
            dlg.Config.Background.CopyToLayer((BackgroundLayer)doc.Model.BackgroundLayer);

            foreach (Options.OptionsLayer optionslayer in dlg.Config.Layers)
            {
                DrawingLayer layer = (DrawingLayer)doc.Model.GetLayer(optionslayer.Layer.Id);
                if (layer != null)
                {
                    optionslayer.CopyToLayer(layer);
                }
                else
                {
                    // delete layer
                }
            }

            doc.Canvas.DoInvalidate(true);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 新绘制图层
        /// </summary>
        /// <param name="xmlelement"></param>
        /// <returns></returns>
        public static DrawingLayer NewLayer(XmlElement xmlelement)
        {
            string id = xmlelement.GetAttribute("Id");

            if (id.Length == 0)
            {
                id = Guid.NewGuid().ToString();
            }

            DrawingLayer layer = new DrawingLayer(id, string.Empty, Color.White, 0.0f);

            foreach (XmlElement node in xmlelement.ChildNodes)
            {
                XmlUtil.ParseProperty(node, layer);
                if (node.Name != "items")
                {
                    continue;
                }

                foreach (XmlElement itemnode in node.ChildNodes)
                {
                    object item = DataModel.NewDrawObject(itemnode.Name);
                    if (item == null)
                    {
                        continue;
                    }

                    if (item != null)
                    {
                        XmlUtil.ParseProperties(itemnode, item);
                    }

                    if (item is ISerialize)
                    {
                        ((ISerialize)item).AfterSerializedIn();
                    }

                    if (item is IDrawObject)
                    {
                        layer.AddObject(item as IDrawObject);
                    }
                }
            }
            return(layer);
        }
Exemplo n.º 6
0
 void DeattachConnectionNode(INodePoint node)
 {
     foreach (var curLayer in m_canvas.Model.Layers)
     {
         DrawingLayer drawingLayer = curLayer as DrawingLayer;
         if (drawingLayer == null)
         {
             continue;
         }
         foreach (var curObj in drawingLayer.Objects)
         {
             if (!(curObj is DrawTools.RectBase))
             {
                 continue;
             }
             ((DrawTools.RectBase)curObj).DeattachConnectionCrvNode(node);
         }
     }
 }
Exemplo n.º 7
0
 public static DrawingLayer NewLayer(XmlElement xmlelement)
 {
     string id = xmlelement.GetAttribute("Id");
     if (id.Length == 0)
         id = Guid.NewGuid().ToString();
     DrawingLayer layer = new DrawingLayer(id, string.Empty, Color.White, 0.0f);
     foreach (XmlElement node in xmlelement.ChildNodes)
     {
         XmlUtil.ParseProperty(node, layer);
         if (node.Name == "items")
         {
             foreach (XmlElement itemnode in node.ChildNodes)
             {
                 object item = DataModel.CreateObject(itemnode.Name);
                 if (item == null)
                     continue;
                 if (item != null)
                     XmlUtil.ParseProperties(itemnode, item);
                 if (item is ISerialize)
                    ((ISerialize)item).AfterSerializedIn();
                 if (item is IDrawObject)
                     layer.AddObject(item as IDrawObject);
             }
         }
     }
     return layer;
 }
Exemplo n.º 8
0
 public void Copy(DrawingLayer acopy, bool includeDrawObjects)
 {
     if (includeDrawObjects)
         throw new Exception("not supported yet");
     m_id = acopy.m_id;
     m_name = acopy.m_name;
     m_color = acopy.m_color;
     m_width = acopy.m_width;
     m_enabled = acopy.m_enabled;
     m_visible = acopy.m_visible;
 }