Exemple #1
0
        public static DatumList CloneList(IEnumerable <Datum> original, Document document)
        {
            // makes a copy of all of the objects in the list, returning the new list
            // contained objects are cloned, but don't appear in the list (they do appear in the ID lookup table)
            // the new list will also contain any necessary objects referenced by these (e.g. textures)
            // links between objects will be updated if both halves are in the list, or broken if only the linking object (e.g. connector, paint splat)
            // is in the list
            DatumList newList = new DatumList();
            Mapping   mapID   = new Mapping();                     // lookup table from old to new IDs

            foreach (Datum data in original.Where(x => x != null)) // will ignore any missing objects in list
            {
                if (!mapID.ContainsKey(data.ID))                   // check is needed because containers will include contents, and original list could include both container and content if selected from page (select all especially)
                {
                    newList.Add(data.Clone(mapID));
                }
            }
            foreach (Datum data in original.Where(x => x != null))
            {
                // It would have been much easier to just iterate colNew, but we can't because the line below might modify the list
                mapID[data.ID].AddRequiredReferencesRecurseToContained(newList.Add, mapID);
            }
            foreach (Datum shape in newList.Values)
            {
                shape.UpdateReferencesIDsChanged(mapID, document);
            }
            return(newList);
        }
Exemple #2
0
        public static SharedImage PickTexture(Document document)
        {
            // returns nothing if cancelled
            if (g_SystemTextures == null)
            {
                try
                {
                    g_SystemTextures = new DatumList();
                    if (System.IO.File.Exists(Globals.Root.InternalFolder + System.IO.Path.DirectorySeparatorChar + "textures"))
                    {
                        using (DataReader reader = new DataReader(Globals.Root.InternalFolder + System.IO.Path.DirectorySeparatorChar + "textures", FileMarkers.SharedBitmap))
                        {
                            g_SystemTextures.Add(reader.ReadDataList(FileMarkers.SharedBitmap));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Utilities.LogSubError("Failed to load textures: " + ex.Message);
                    g_SystemTextures = new DatumList();
                }
            }

            frmTexture frm = new frmTexture(g_SystemTextures, document);

            if (frm.ShowDialog() != DialogResult.OK)
            {
                return(null);
            }
            return(frm.m_Chosen);
        }
Exemple #3
0
 public void Write(DatumList list)
 {
     if (list == null)
     {
         base.Write(Convert.ToInt16(0));
         return;
     }
     base.Write(Convert.ToInt16(list.Count));
     Debug.Assert(list.Count < short.MaxValue);
     foreach (Datum data in list.Values)
     {
         Write(data);
     }
 }
Exemple #4
0
        private readonly Document m_Document;         // document being edited

        public frmTexture(DatumList systemTextures, Document document)
        {
            InitializeComponent();
            m_Document = document;
            Strings.Translate(this);
            FillList(lstSystem, systemTextures);
            // can't just use document.SharedBitmapsList because that is all sorts of imported images
            DatumList colUsed = document.TexturesUsed();

            FillList(lstDocument, colUsed);
            if (colUsed.Count == 0)
            {
                tpDocument.Dispose();
            }
        }
Exemple #5
0
 private void FillList(ListView lst, DatumList dataList)
 {
     try
     {
         foreach (SharedImage texture in dataList.Values)
         {
             lst.Items.Add(new ListViewItem("")
             {
                 Tag = texture
             });
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Exemple #6
0
 public void lnkShare_Click(object sender, EventArgs e)
 {
     if (m_Style.IsShared)
     {
         // The link is un-sharing. need to detect if any buttons except this one use this style
         m_Button.SetStyleObject(null);
         DatumList list = new DatumList();
         Globals.Root.CurrentDocument.IterateEx(obj => obj.AddRequiredReferences(list.Add, Mapping.Ignore), false, false);
         m_Button.SetStyleObject(m_OriginalStyle);                 // either way we put the object back in the button itself in case the user cancels this screen
         if (list.Contains(m_Style) || m_Style.IsUserDefault)
         {
             // this style is referenced elsewhere.  Need to make a copy
             ButtonStyle newStyle = (ButtonStyle)m_Style.Clone(Mapping.Ignore);
             newStyle.Name     = "";
             newStyle.IsShared = false;
             m_Style           = newStyle;
         }
         else
         {
             // this style is not used elsewhere; we can just make it shared
             m_Style.IsShared = false;
             Globals.Root.CurrentDocument.RemoveButtonStyle(m_Style);
             // can keep the name
         }
     }
     else                                                   // otherwise we are sharing a previously custom style
     {
         string name = frmButtonStyleName.Display(m_Style); // Name will only be set if this was previously shared
         if (string.IsNullOrEmpty(name))
         {
             return;
         }
         m_Style.IsShared = true;
         m_Style.Name     = name;
         m_Transaction.Edit(Globals.Root.CurrentDocument);
         Globals.Root.CurrentDocument.AddButtonStyle(m_Style);
     }
     FillStylesList();
     ReflectCustomState();
     ctrStyle.DisplayStyle(m_Style);
 }