private static void AddSetByDerivedNos(INamedObjectContainer namedObjectContainer,
                                               NamedObjectSave namedObjectSetByDerived, bool instantiatedByBase)
        {
            NamedObjectSave existingNamedObject = null;

            foreach (NamedObjectSave namedObjectInDerived in namedObjectContainer.NamedObjects)
            {
                if (namedObjectInDerived.InstanceName == namedObjectSetByDerived.InstanceName)
                {
                    existingNamedObject = namedObjectInDerived;
                    break;
                }
            }

            if (existingNamedObject != null)
            {
                existingNamedObject.DefinedByBase      = true;
                existingNamedObject.InstantiatedByBase = instantiatedByBase;
            }
            else
            {
                NamedObjectSave namedObjectSave = namedObjectSetByDerived.Clone();

                namedObjectSave.SetDefinedByBaseRecursively(true);
                namedObjectSave.SetInstantiatedByBaseRecursively(instantiatedByBase);

                // This can't be set by derived because an object it inherits from has that already set
                namedObjectSave.SetSetByDerivedRecursively(false);


                namedObjectContainer.NamedObjects.Add(namedObjectSave);
            }
        }
        private static bool DragDropNosIntoElement(NamedObjectSave movingNos, IElement elementMovingInto)
        {
            bool succeeded = true;

            // moving to another element, so let's copy
            NamedObjectSave clonedNos = movingNos.Clone();

            UpdateNosAfterDragDrop(clonedNos, elementMovingInto);

            elementMovingInto.NamedObjects.Add(clonedNos);

            var referenceCheck = ProjectManager.VerifyReferenceGraph(elementMovingInto);

            if (referenceCheck == ProjectManager.CheckResult.Failed)
            {
                succeeded = false;
                // VerifyReferenceGraph (currently) shows a popup so we don't have to here
                //MessageBox.Show("This movement would result in a circular reference");

                elementMovingInto.NamedObjects.Remove(clonedNos);
            }

            if (succeeded)
            {
                // If an object which was on a Layer
                // is moved into another Element, then
                // the cloned object probably shouldn't
                // be on a layer.  Not sure if we want to 
                // see if there is a Layer with the same-name
                // but we maybe shouldn't assume that they mean
                // the same thing.
                clonedNos.LayerOn = null;

                BaseElementTreeNode treeNodeForElementMovedInto = GlueState.Self.Find.ElementTreeNode(elementMovingInto);
                treeNodeForElementMovedInto.UpdateReferencedTreeNodes();
                CodeGeneratorIElement.GenerateElementDerivedAndReferenced(elementMovingInto);

                MessageBox.Show("Copied\n" + movingNos + "\n\nto\n" + clonedNos);
            }
            return succeeded;
        }
Пример #3
0
        private static void AddSetByDerivedNos(INamedObjectContainer namedObjectContainer,
            NamedObjectSave namedObjectSetByDerived, bool instantiatedByBase)
        {
            NamedObjectSave existingNamedObject = null;

            foreach (NamedObjectSave namedObjectInDerived in namedObjectContainer.NamedObjects)
            {
                if (namedObjectInDerived.InstanceName == namedObjectSetByDerived.InstanceName)
                {
                    existingNamedObject = namedObjectInDerived;
                    break;
                }
            }

            if (existingNamedObject != null)
            {
                existingNamedObject.DefinedByBase = true;
                existingNamedObject.InstantiatedByBase = instantiatedByBase;
            }
            else
            {
                NamedObjectSave namedObjectSave = namedObjectSetByDerived.Clone();

                namedObjectSave.SetDefinedByBaseRecursively(true);
                namedObjectSave.SetInstantiatedByBaseRecursively(instantiatedByBase);

                // This can't be set by derived because an object it inherits from has that already set
                namedObjectSave.SetSetByDerivedRecursively(false);


                namedObjectContainer.NamedObjects.Add(namedObjectSave);
            }
        }