Exemplo n.º 1
0
        private void LoadScheme(string path)
        {
            filename    = path;
            modified    = false;
            dragElement = null;
            connectLine = null;
            menuElement = null;
            move        = false;
            scheme?.Dispose();
            scheme = null;

            if (string.IsNullOrEmpty(path))
            {
                scheme   = new DrawableScheme(pictureBox.Width, pictureBox.Height);
                filename = null;
            }
            else
            {
                try
                {
                    using (var file = File.Open(path, FileMode.Open))
                        scheme = DrawableSchemeStorage.Load(file);
                }
                catch (Exception exception)
                {
                    ShowError(String.Format(Resource.Localization.Error_PathOpen, path), exception);

                    filename = null;
                    scheme   = new DrawableScheme(pictureBox.Width, pictureBox.Height);
                }
            }

            DrawScheme();
        }
Exemplo n.º 2
0
        public static string Save(DrawableScheme scheme)
        {
            #region arguments check

            if (scheme == null)
            {
                throw new ArgumentNullException(nameof(scheme));
            }

            #endregion

            return(JsonConvert.SerializeObject(scheme));
        }
Exemplo n.º 3
0
        private void LoadScheme(Scheme source)
        {
            filename    = null;
            modified    = false;
            dragElement = null;
            connectLine = null;
            menuElement = null;
            move        = false;
            scheme?.Dispose();

            scheme = DrawableScheme.FromScheme(source, pictureBox.Width, pictureBox.Height);

            DrawScheme();
        }
Exemplo n.º 4
0
        public static void Save(DrawableScheme scheme, Stream stream)
        {
            #region arguments check

            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (!stream.CanWrite)
            {
                throw new ArgumentException("The stream must be writeable.", nameof(stream));
            }

            #endregion

            using (var streamWriter = new StreamWriter(stream))
                streamWriter.Write(DrawableSchemeStorage.Save(scheme));
        }
Exemplo n.º 5
0
        public static DrawableScheme FromScheme(Scheme scheme, int width, int height)
        {
            var elementX = 0;
            var elementY = 0;

            var drawableInputs = scheme.Inputs.Select(i => {
                var input = new DrawableInput(i.Name, elementX, elementY, ElementWidth, ElementHeight);
                elementY += GapHeight + ElementHeight;
                return(input);
            }).ToArray();

            elementX += GapWidth + ElementWidth;
            elementY  = 0;


            var drawableComponents = new List <DrawableComponent>();

            foreach (var layer in scheme.ComponentLayers)
            {
                drawableComponents.AddRange(layer.Select(c => {
                    var component = new DrawableComponent(c.Name, c.Type, c.Input, elementX, elementY, ElementWidth, ElementHeight);
                    elementY     += GapHeight + ElementHeight;
                    return(component);
                }).ToArray());

                elementX += GapWidth + ElementWidth;
                elementY  = 0;
            }

            var drawableOutputs = scheme.Outputs.Select(o => {
                var output = new DrawableOutput(o.Name, o.Input, elementX, elementY, ElementWidth, ElementHeight);
                elementY  += GapHeight + ElementHeight;
                return(output);
            }).ToArray();

            var drawableScheme = new DrawableScheme(drawableInputs, drawableOutputs, drawableComponents, null, width, height);

            drawableScheme.RestoreLines();

            return(drawableScheme);
        }