DeepCopy() public method

Performs a partial deepy copy based on the input element, the name field is left unchanged
public DeepCopy ( ProjectLayoutElement zElement, bool bInitializeCache ) : void
zElement ProjectLayoutElement The source element to copy from
bInitializeCache bool flag indicating whether to reinitialize the cache
return void
Example #1
0
        /// <summary>
        /// Performs a partial deepy copy based on the input element, the name field is left unchanged
        /// </summary>
        /// <param name="zLayout">The layout to copy from</param>
        /// <param name="bCopyRefs">Flag indicating whether to copy the refereces</param>
        public void DeepCopy(ProjectLayout zLayout, bool bCopyRefs = true)
        {
            width                       = zLayout.width;
            height                      = zLayout.height;
            defaultCount                = zLayout.defaultCount;
            dpi                         = zLayout.dpi;
            drawBorder                  = zLayout.drawBorder;
            buffer                      = zLayout.buffer;
            zoom                        = zLayout.zoom;
            exportCropDefinition        = zLayout.exportCropDefinition;
            combineReferences           = zLayout.combineReferences;
            exportNameFormat            = zLayout.exportNameFormat;
            exportRotation              = zLayout.exportRotation;
            exportWidth                 = zLayout.exportWidth;
            exportHeight                = zLayout.exportHeight;
            exportTransparentBackground = zLayout.exportTransparentBackground;
            if (null != zLayout.Element)
            {
                var listElements = new List <ProjectLayoutElement>();
                foreach (ProjectLayoutElement zElement in zLayout.Element)
                {
                    var zElementCopy = new ProjectLayoutElement(zElement.name);
                    zElementCopy.DeepCopy(zElement, true);
                    listElements.Add(zElementCopy);
                }
                Element = listElements.ToArray();
            }
            if (bCopyRefs && null != zLayout.Reference)
            {
                var listReferences = new List <ProjectLayoutReference>();
                foreach (var zReference in zLayout.Reference)
                {
                    var zReferenceCopy = new ProjectLayoutReference();
                    zReferenceCopy.DeepCopy(zReference);
                    listReferences.Add(zReferenceCopy);
                }
                Reference = listReferences.ToArray();
            }

            InitializeElementLookup();
        }
Example #2
0
 /// <summary>
 /// Performs a partial deepy copy based on the input element, the name field is left unchanged
 /// </summary>
 /// <param name="zLayout">The layout to copy from</param>
 /// <param name="bCopyRefs">Flag indicating whether to copy the refereces</param>
 public void DeepCopy(ProjectLayout zLayout, bool bCopyRefs = true)
 {
     width = zLayout.width;
     height = zLayout.height;
     defaultCount = zLayout.defaultCount;
     dpi = zLayout.dpi;
     drawBorder = zLayout.drawBorder;
     buffer = zLayout.buffer;
     combineReferences = zLayout.combineReferences;
     exportNameFormat = zLayout.exportNameFormat;
     exportRotation = zLayout.exportRotation;
     exportWidth = zLayout.exportWidth;
     exportHeight = zLayout.exportHeight;
     exportTransparentBackground = zLayout.exportTransparentBackground;
     if (null != zLayout.Element)
     {
         var listElements = new List<ProjectLayoutElement>();
         foreach (ProjectLayoutElement zElement in zLayout.Element)
         {
             var zElementCopy = new ProjectLayoutElement(zElement.name);
             zElementCopy.DeepCopy(zElement, true);
             listElements.Add(zElementCopy);
         }
         Element = listElements.ToArray();
     }
     if (bCopyRefs && null != zLayout.Reference)
     {
         var listReferences = new List<ProjectLayoutReference>();
         foreach (var zReference in zLayout.Reference)
         {
             var zReferenceCopy = new ProjectLayoutReference();
             zReferenceCopy.DeepCopy(zReference);
             listReferences.Add(zReferenceCopy);
         }
         Reference = listReferences.ToArray();
     }
 }
Example #3
0
        public ProjectLayoutElement GetOverrideElement(ProjectLayoutElement zElement, int nCardIndex, List<string> arrayLine, DeckLine zDeckLine)
        {
            Dictionary<string, int> dictionaryOverrideColumns;
            string sNameLower = zElement.name.ToLower();
            DictionaryElementOverrides.TryGetValue(sNameLower, out dictionaryOverrideColumns);
            if (null == dictionaryOverrideColumns)
            {
                return zElement;
            }

            var zOverrideElement = new ProjectLayoutElement();
            zOverrideElement.DeepCopy(zElement, false);
            zOverrideElement.name = zElement.name;

            foreach (string sKey in dictionaryOverrideColumns.Keys)
            {
                Type zType = typeof(ProjectLayoutElement);
                PropertyInfo zProperty = zType.GetProperty(sKey);
                if (null != zProperty && zProperty.CanWrite)
                {
                    MethodInfo zMethod = zProperty.GetSetMethod();
                    int nOverrideValueColumnIdx = dictionaryOverrideColumns[sKey];
                    if (arrayLine.Count <= nOverrideValueColumnIdx)
                    {
                        continue;
                    }
                    string sValue = arrayLine[nOverrideValueColumnIdx].Trim();

                    // Note: TranslateString maintains an element name based cache, the key is critical to make this translation unique
                    sValue = TranslateString(sValue, nCardIndex, zDeckLine, zOverrideElement, sKey).String;

                    if (!string.IsNullOrEmpty(sValue))
                    {
                        if (zProperty.PropertyType == typeof(string))
                        {
                            zMethod.Invoke(zOverrideElement, new object[] { sValue });
                        }
                        else if (zProperty.PropertyType == typeof(float))
                        {
                            float fValue;
                            if (float.TryParse(sValue, out fValue))
                            {
                                zMethod.Invoke(zOverrideElement, new object[] { fValue });
                            }
                        }
                        else if (zProperty.PropertyType == typeof(bool))
                        {
                            bool bValue;
                            if (bool.TryParse(sValue, out bValue))
                            {
                                zMethod.Invoke(zOverrideElement, new object[] { bValue });
                            }
                        }
                        else if (zProperty.PropertyType == typeof(Int32))
                        {
                            int nValue;
                            if (int.TryParse(sValue, out nValue))
                            {
                                zMethod.Invoke(zOverrideElement, new object[] { nValue });
                            }
                        }
                    }
                }
            }
            zOverrideElement.InitializeCache(); // any cached items must be recached
            return zOverrideElement;
        }
Example #4
0
        private void AddElements(IEnumerable<string> collectionNames, ProjectLayoutElement zBaseElement)
        {
            // construct a new list of elements
            var listElements = new List<ProjectLayoutElement>();
            if (null != LayoutManager.Instance.ActiveLayout.Element)
            {
                listElements.AddRange(LayoutManager.Instance.ActiveLayout.Element);
            }

            foreach (string sName in collectionNames)
            {
                string sTrimmed = sName.Trim();
                if (m_dictionaryItems.ContainsKey(sTrimmed)) // no duplicates!
                {
                    continue;
                }
                var zCardElement = new ProjectLayoutElement(sTrimmed);

                if (null != zBaseElement)
                {
                    zCardElement.DeepCopy(zBaseElement, true);
                }
                else
                {
                    zCardElement.lineheight = 14;
                    zCardElement.SetElementColor(Color.Black);
                    zCardElement.SetElementFont(new Font("Arial", 12));
                }
                listElements.Add(zCardElement);
                ListViewItem zLvi = CreateListViewItem(zCardElement);
                listViewElements.Items.Add(zLvi);
            }

            var zLayout = LayoutManager.Instance.ActiveLayout;
            if (null == zLayout.Element ||
                // it is possible nothing was added if all names were duplicates (skip in that case)
                zLayout.Element.Length < listElements.Count)
            {
                // UserAction
                SetupLayoutUndo(listElements);

                // assign the new list to the actual project layout
                LayoutManager.Instance.ActiveLayout.Element = listElements.ToArray();
                LayoutManager.Instance.FireLayoutUpdatedEvent(true);
            }
        }