Example #1
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            // добавление изображения в словарь изображений схемы
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    SchemeView.Image image = new SchemeView.Image();
                    string           name  = Path.GetFileName(openFileDialog.FileName);
                    image.Name = imageDict.ContainsKey(name) ? "image" + (imageDict.Count + 1) : name;

                    using (FileStream fileStream = new FileStream(
                               openFileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                        image.Data = new byte[fileStream.Length];
                        fileStream.Read(image.Data, 0, image.Data.Length);
                    }

                    ImageInfo imageInfo = new ImageInfo(image, ImageNameIsUnique);
                    imageDict.Add(image.Name, image);
                    lbImages.SelectedIndex = lbImages.Items.Add(imageInfo);

                    // создание объекта для передачи изменений
                    SchemeView.SchemeChange change = new SchemeView.SchemeChange(SchemeView.ChangeType.ImageAdded);
                    change.Image = image;
                    editorData.TrySetSchemeChange(change);
                    editorData.SetFormTitle();
                    StartWaitForChange();
                }
                catch (Exception ex)
                {
                    ScadaUtils.ShowError(SchemePhrases.LoadImageError + ":\n" + ex.Message);
                }
            }
        }
Example #2
0
 /// <summary>
 /// Конструктор
 /// </summary>
 public Image(SchemeView.Image image)
 {
     Name = image.Name ?? "";
     Data = Convert.ToBase64String(image.Data == null ? new byte[0] : image.Data,
                                   Base64FormattingOptions.None);
     SetMediaType();
 }
Example #3
0
 /// <summary>
 /// Конструктор
 /// </summary>
 public ImageInfo(SchemeView.Image image, Func <string, bool> nameIsUniqueMethod)
 {
     Image              = image;
     Source             = null;
     Name               = image.Name;
     DataSize           = 0;
     ImageSize          = new SchemeView.Size(0, 0);
     Format             = "";
     NameIsUniqueMethod = nameIsUniqueMethod;
 }
Example #4
0
        private void btnSelect_Click(object sender, EventArgs e)
        {
            // установка выбранного изображения
            ImageInfo imageInfo = lbImages.SelectedItem as ImageInfo;

            if (imageInfo != null)
            {
                SelectedImage      = new SchemeView.Image();
                SelectedImage.Name = imageInfo.Name;
            }
            DialogResult = DialogResult.OK;
        }
Example #5
0
 public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
 {
     if (destinationType == typeof(string))
     {
         SchemeView.Image image = value as SchemeView.Image;
         return(image == null ?
                (Localization.UseRussian ? "(Нет)" : "(None)") :
                image.Name);
     }
     else
     {
         return(base.ConvertTo(context, culture, value, destinationType));
     }
 }
Example #6
0
        private void FrmImageDialog_Load(object sender, EventArgs e)
        {
            // перевод формы
            Localization.TranslateForm(this, "Scada.Scheme.FrmImageDialog");

            // установка видимости кнопок выбора изображения
            if (!CanSelectImage)
            {
                btnClear.Visible  = false;
                btnSelect.Visible = false;
            }

            // вывод словаря изображений схемы
            SchemeApp schemeApp = SchemeApp.GetSchemeApp();

            editorData = schemeApp.EditorData;
            if (editorData != null && editorData.SchemeView != null)
            {
                imageDict = schemeApp.EditorData.SchemeView.ImageDict;
            }

            if (imageDict != null)
            {
                lbImages.BeginUpdate();
                string           selName  = SelectedImage == null ? "" : SelectedImage.Name;
                SchemeView.Image selImage = null;

                foreach (SchemeView.Image image in imageDict.Values)
                {
                    if (image.Name == selName)
                    {
                        selImage = image;
                    }
                    else
                    {
                        lbImages.Items.Add(new ImageInfo(image, ImageNameIsUnique));
                    }
                }

                if (selImage != null)
                {
                    lbImages.SelectedIndex = lbImages.Items.Add(new ImageInfo(selImage, ImageNameIsUnique));
                }

                lbImages.EndUpdate();
                btnOpen.Enabled = true;
            }
        }
Example #7
0
 private void btnClear_Click(object sender, EventArgs e)
 {
     // установка выбранного изображения пустым
     SelectedImage = null;
     DialogResult  = DialogResult.OK;
 }