Пример #1
0
        /// <summary>
        ///if layer is not inserted before, insert it into Layers
        /// </summary>
        /// <param name="layer"></param>
        public void Insert(GraphLayer layer)
        {
            foreach (GraphLayer l in mLayers)
            {
                if (layer == l)
                {
                    return;
                }
            }

            mLayers.Add(layer);
        }
Пример #2
0
        /// <summary>
        /// Default ctor
        /// </summary>
        public GraphAbstract()
        {
            mGraphInformation = new GraphInformation();

            Init();

//            Insert(DefaultLayer);
            mCurrentLayer = DefaultLayer;
            if (mCurrentLayer != null)
            {
                mCurrentLayer.Visible = true;
            }
        }
Пример #3
0
        /// <summary>
        /// Sets the shape in a layer.
        /// Use "default" to set the shape in the default layer.
        /// </summary>
        /// <param name="name"></param>
        public void SetLayer(string name)
        {
            GraphLayer layer = Site.Abstract.Layers[name];

            if (layer == null)
            {
                SetLayer(Site.Abstract.DefaultLayer);
            }
            else
            {
                SetLayer(Site.Abstract.Layers[name]);
            }
        }
Пример #4
0
        private void Init()
        {
            //the shape layers
            GraphLayer layer = new GraphLayer("Default", Color.WhiteSmoke, 100);

            layer.UseColor = false; //use colors only for upper layers

            mLayers = new GraphLayerCollection();
            mLayers.Add(layer);
            mLayers.ClearComplete += new EventHandler(Layers_ClearComplete);
            //the default layer

            BindEntityCollectionEvents();
        }
        /// <summary>
        /// Adds a layer to the collection
        /// </summary>
        /// <param name="layer"></param>
        /// <returns></returns>
        public int Add(GraphLayer layer)
        {
            for (int i = 0; i < InnerList.Count; i++)
            {
                if (layer == InnerList[i])
                {
                    return(i);
                }
            }

            int index = this.InnerList.Add(layer);

            layer.SetNumber(index);
            return(index);
        }
Пример #6
0
        /// <summary>
        /// Deserialization constructor
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        public GraphAbstract(SerializationInfo info, StreamingContext context)
        {
            #region Version test
            //test the version, warn if the build or major is different
            Version currentversion = Assembly.GetExecutingAssembly().GetName().Version;
            Version fileversion    = new Version(info.GetString("NetronGraphLibVersion"));
            int     diff           = currentversion.CompareTo(fileversion);

            if (fileversion.Minor != currentversion.Minor || fileversion.Major != currentversion.Major)
            {
                DialogResult res = MessageBox.Show("The graph was saved in version " + fileversion.ToString() + " while the current graph library has version " + currentversion.ToString() + ". It is not guaranteed that the graph will appeare as it was when saved. Are you sure you want to open the graph?", "Different version", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (res == DialogResult.No)
                {
                    return;
                }
            }
            #endregion

            this.mShapes      = info.GetValue("mShapes", typeof(ShapeCollection)) as ShapeCollection;
            this.mConnections = info.GetValue("mConnections", typeof(ConnectionCollection)) as ConnectionCollection;


            this.mGraphInformation = info.GetValue("mGraphInformation", typeof(GraphInformation)) as GraphInformation;

            this.mLayers = info.GetValue("mLayers", typeof(GraphLayerCollection)) as GraphLayerCollection;

            if (mLayers != null)
            {
                GraphLayer layer = mLayers["Default"];
                if (layer == null)
                {
                    layer          = new GraphLayer("Default", Color.WhiteSmoke, 100);
                    layer.UseColor = false; //use colors only for upper layers
                    mLayers.Add(layer);
                }

                mCurrentLayer = DefaultLayer;

                if (mCurrentLayer != null)
                {
                    mCurrentLayer.Visible = true;
                }
                mLayers.ClearComplete += new EventHandler(Layers_ClearComplete);
            }

            BindEntityCollectionEvents();
        }
Пример #7
0
        /// <summary>
        /// 设置编号为layerIndex的Layer为CurrentLayer,并设置前一个激活的Layer为不可见
        /// </summary>
        /// <param name="layerIndex"></param>
        /// <returns></returns>
        public bool ActiveLayer(int layerIndex)
        {
            GraphLayer layer = mLayers[layerIndex];

            if (layer != null)
            {
                if (mCurrentLayer != null)
                {
                    mCurrentLayer.Visible = false;
                }
                mCurrentLayer = layer;
                layer.Visible = true;
                return(true);
            }

            return(false);
        }
Пример #8
0
        /// <summary>
        /// return the shapes of layer
        /// </summary>
        /// <param name="layerName"></param>
        /// <returns></returns>
        public ShapeCollection ShapesOfLayer(string layerName)
        {
            ShapeCollection shapes = new ShapeCollection();
            GraphLayer      layer  = Layers[layerName];

            if (layer != null)
            {
                foreach (Shape shape in Shapes)
                {
                    if (shape.Layer == layer)
                    {
                        shapes.Add(shape);
                    }
                }
            }
            return(shapes);
        }
Пример #9
0
        /// <summary>
        /// return the connections of layer
        /// </summary>
        /// <param name="layerName"></param>
        /// <returns></returns>
        public ConnectionCollection ConnectionsOfLayer(string layerName)
        {
            ConnectionCollection connections = new ConnectionCollection();
            GraphLayer           layer       = Layers[layerName];

            if (layer != null)
            {
                foreach (Connection connection in Connections)
                {
                    if (connection.Layer == layer)
                    {
                        connections.Add(connection);
                    }
                }
            }
            return(connections);
        }
Пример #10
0
        /// <summary>
        /// 设置layerName的Layer为CurrentLayer,并设置前一个激活的Layer为不可见
        /// </summary>
        /// <param name="layerName"></param>
        /// <returns>激活成功则返回true</returns>
        public bool ActiveLayer(string layerName)
        {
            GraphLayer layer = mLayers[layerName];

            if (layer != null)
            {
                foreach (GraphLayer l in mLayers)
                {
                    l.Visible = false;
                }

                mCurrentLayer = layer;
                layer.Visible = true;
                Site.Invalidate();
                return(true);
            }

            return(false);
        }
Пример #11
0
 /// <summary>
 /// Puts the connection in a layer
 /// </summary>
 /// <param name="layer"></param>
 protected override void SetLayer(GraphLayer layer)
 {
     base.SetLayer(layer);
     if (layer == GraphAbstract.DefaultLayer)
     {
         LineColor = Color.FromArgb(255, mLineColor);
     }
     else
     {
         if (Layer.UseColor)
         {
             LineColor = Color.FromArgb((int)(Layer.Opacity * 255f / 100), Layer.LayerColor);
         }
         else
         {
             LineColor = Color.FromArgb((int)(Layer.Opacity * 255f / 100), mLineColor);
         }
     }
 }
Пример #12
0
        /// <summary>
        /// Override the Entity.SetLayer to adapt the shape's appearance in function of the
        /// layer's parameters.
        /// </summary>
        /// <param name="layer">a pre-defined or added graph-layer</param>
        protected override void SetLayer(GraphLayer layer)
        {
            if (layer == null)
            {
                return;
            }
            base.SetLayer(layer);
            if (layer == Site.Abstract.DefaultLayer)
            {
                mShapeColor = Color.FromArgb(255, ShapeColor);
                if (Pen == null)
                {
                    Pen = new Pen(Brushes.Black, PenWidth);
                }
                TextColor = Color.FromArgb(255, TextColor);
            }
            else
            {
                int alpha = (int)(Layer.Opacity * 255f / 100);
                if (Layer.UseColor)
                {
                    mShapeColor = Color.FromArgb(alpha, Layer.LayerColor);
                }
                else
                {
                    mShapeColor = Color.FromArgb((int)(Layer.Opacity * 255f / 100), ShapeColor);
                }

                if (Pen == null)
                {
                    Pen = new Pen(Color.FromArgb(alpha, Color.Black), PenWidth);
                }
                else
                {
                    Pen = new Pen(Color.FromArgb(alpha, Pen.Color), PenWidth);
                }
                TextColor = Color.FromArgb(alpha, TextColor);
            }
        }
 /// <summary>
 /// Removes a graph-layer from the collection
 /// </summary>
 /// <param name="layer"></param>
 public void Remove(GraphLayer layer)
 {
     InnerList.Remove(layer);
 }
Пример #14
0
 /// <summary>
 /// Sets the layer the entity belongs to
 /// </summary>
 /// <param name="layer"></param>
 protected virtual void SetLayer(GraphLayer layer)
 {
     mLayer = layer;
     return;
 }