Example #1
0
        /// <summary>
        /// Method used to create a new element's name based on the range of available names.
        /// Excluded are names used by the child elements embedded in the given parent element.
        /// </summary>
        /// <param name="parent">Parent element, embedding the model element.</param>
        /// <param name="modelElement">ModelElement to create the name for.</param>
        /// <returns>Created name for the given ModelElement. </returns>
        public virtual string CreateName(ModelElement parent, ModelElement modelElement)
        {
            if (parent is IDomainModelOwnable && modelElement is IDomainModelOwnable)
            {
                if (!(modelElement as IDomainModelOwnable).DomainElementHasName)
                {
                    return(null);
                }

                DomainClassInfo infoParent = parent.GetDomainClass();
                DomainClassInfo infoChild  = modelElement.GetDomainClass();

                IModelElementParentProvider parentprovider = (parent as IDomainModelOwnable).GetDomainModelServices().ElementParentProvider;
                foreach (DomainRoleInfo roleInfo in infoParent.AllDomainRolesPlayed)
                {
                    if (roleInfo.IsSource)
                    {
                        //if (roleInfo.OppositeDomainRole.RolePlayer.Id == infoChild.Id)
                        if (infoChild.IsDerivedFrom(roleInfo.OppositeDomainRole.RolePlayer))
                        {
                            if ((modelElement as IDomainModelOwnable).Store.DomainDataAdvDirectory.IsEmbeddingRelationship(roleInfo.DomainRelationship.Id))
                            {
                                int    counter = 0;
                                string name    = (modelElement as IDomainModelOwnable).DomainElementTypeDisplayName;
                                while (true)
                                {
                                    bool bFound = false;
                                    IList <ElementLink> links = DomainRoleInfo.GetElementLinks <ElementLink>(parent, roleInfo.Id);

                                    foreach (ElementLink c in links)
                                    {
                                        if ((DomainRoleInfo.GetTargetRolePlayer(c) as IDomainModelOwnable).DomainElementName == name + counter.ToString())
                                        {
                                            bFound = true;
                                            break;
                                        }
                                    }

                                    if (!bFound)
                                    {
                                        return(name + counter.ToString());
                                    }

                                    counter++;
                                }
                            }
                        }
                    }
                }
            }

            return(null);
        }
        /* There are two versions of CreateElementToolPrototype here.
         * One deals with each Component subtype separately: if you add a new subtype, you need to add more here.
         * The other automatically deals with eacn Component subtype, using DSL reflection info.
         *
         * See http://msdn.microsoft.com/library/bb126279.aspx#groups
         */

        /*
         * /// <summary>
         * /// Toolbox initialization, called for each element tool on the toolbox.
         * /// This version deals with each Component subtype separately.
         * /// </summary>
         * /// <param name="store"></param>
         * /// <param name="domainClassId">Identifies the domain class this tool should instantiate.</param>
         * /// <returns>prototype of the object or group of objects to be created by tool</returns>
         * protected override ElementGroupPrototype CreateElementToolPrototype(Store store, Guid domainClassId)
         * {
         *
         *  if (domainClassId == Resistor.DomainClassId)
         *  {
         *      Resistor resistor = new Resistor(store);
         *
         *      // Must initialize these in order of initialization:
         *      // DSLT v1 bug affecting derived relationships.
         *      resistor.T1 = new ComponentTerminal(store);
         *      resistor.T2 = new ComponentTerminal(store);
         *
         *      resistor.T1.Name = "t1";
         *      resistor.T2.Name = "t2";
         *
         *      ElementGroup elementGroup = new ElementGroup(store.DefaultPartition);
         *      elementGroup.AddGraph(resistor, true);
         *      // AddGraph includes the embedded parts.
         *
         *      return elementGroup.CreatePrototype();
         *  }
         *  else if (domainClassId == Capacitor.DomainClassId)
         *  {
         *      Capacitor capacitor = new Capacitor(store);
         *
         *      // Must initialize these in order of initialization:
         *      // DSLT v1 bug affecting derived relationships.
         *      capacitor.T1 = new ComponentTerminal(store);
         *      capacitor.T2 = new ComponentTerminal(store);
         *
         *      capacitor.T1.Name = "t1";
         *      capacitor.T2.Name = "t2";
         *
         *      ElementGroup elementGroup = new ElementGroup(store.DefaultPartition);
         *      elementGroup.AddGraph(capacitor, true);
         *      // AddGraph includes the embedded parts.
         *
         *      return elementGroup.CreatePrototype();
         *  }
         *
         *  else if (domainClassId == Transistor.DomainClassId)
         *  {
         *      Transistor transistor = new Transistor(store);
         *
         *      // Must initialize these in order of initialization:
         *      // DSLT v1 bug affecting derived relationships.
         *      transistor.Base = new ComponentTerminal(store);
         *      transistor.Collector = new ComponentTerminal(store);
         *      transistor.Emitter = new ComponentTerminal(store);
         *
         *      transistor.Base.Name = "base";
         *      transistor.Collector.Name = "collector";
         *      transistor.Emitter.Name = "emitter";
         *
         *      // Create an ElementGroup for the Toolbox.
         *      ElementGroup elementGroup = new ElementGroup(store.DefaultPartition);
         *      elementGroup.AddGraph(transistor, true);
         *      // AddGraph includes the embedded parts
         *
         *      return elementGroup.CreatePrototype();
         *  }
         *
         *  else
         *  {
         *      return base.CreateElementToolPrototype(store, domainClassId);
         *  }
         *
         *
         * }
         *
         */

        /// <summary>
        /// Toolbox initialization for components with fixed embedded parts.
        /// This deals with all the subclasses of Component, adding an instance for each relationship derived from ComponentHasTerminals.
        /// The benefit of this approach is that it does not need to be adjusted for each new Component subclass.
        /// Called for each element tool on the toolbox.
        /// </summary>
        /// <param name="store"></param>
        /// <param name="domainClassId">Identifies the domain class this tool should instantiate.</param>
        /// <returns>prototype of the object or group of objects to be created by tool</returns>
        protected override ElementGroupPrototype CreateElementToolPrototype(Store store, Guid domainClassId)
        {
            // Called for each element tool on the toolbox.
            // Get the class meta info for this class.
            DomainClassInfo thisClassInfo = store.DomainDataDirectory.FindDomainClass(domainClassId);

            if (!thisClassInfo.IsDerivedFrom(Component.DomainClassId))
            {
                // Not one of those we're interested in: defer to base method.
                return(base.CreateElementToolPrototype(store, domainClassId));
            }
            else
            {
                // Construct an instance of this type. Use the constructor that takes a store and a variable number of property bindings.
                Component component = (Component)thisClassInfo.ImplementationClass. // get the actual class from the meta info
                                      InvokeMember(                                 // method in System.Reflection.Type
                    "",
                    System.Reflection.BindingFlags.CreateInstance                   // invoke the constructor
                    | System.Reflection.BindingFlags.OptionalParamBinding,          // which has a params binding
                    null,                                                           // no special binder
                    null,                                                           //no target object since we want the constructor
                    new object[] { store });                                        // Called like "new Resistor(store)"

                // Now add whatever ComponentTerminals it has.
                // Each Component subtype sources several subrelationships of ComponentHasComponentTerminal.
                // Go through the metainfo about each role the class plays in relationships.
                foreach (DomainRoleInfo role in thisClassInfo.LocalDomainRolesPlayed)
                {
                    // Pick out the roles that are one end of a relationship to a Terminal.
                    if (role.DomainRelationship.IsDerivedFrom(ComponentHasComponentTerminal.DomainClassId) &&
                        !role.DomainRelationship.ImplementationClass.IsAbstract)
                    {
                        ComponentTerminal terminal = new ComponentTerminal(store);
                        // Fill in the instance name with the name of the role - just a convenience.
                        // The role at the Terminal end of the relationship is the one called "T1" or "collector" or some such.
                        terminal.Name = role.OppositeDomainRole.Name.ToLowerInvariant();
                        // Instantiate the relationship with the constructor that takes the component and terminal.
                        role.DomainRelationship.ImplementationClass.InvokeMember("", System.Reflection.BindingFlags.CreateInstance,
                                                                                 null, null,
                                                                                 new object[] { component, terminal });
                    }
                }
                // Create an Element Group Prototype containing this tree.
                ElementGroup elementGroup = new ElementGroup(store.DefaultPartition);
                elementGroup.AddGraph(component, true, true); // AddGraph includes the embedded elements.
                elementGroup.AddRange(component.ComponentTerminals, true);
                ElementGroupPrototype egp = elementGroup.CreatePrototype();
                return(egp);
            }
        }
Example #3
0
            /// <summary>
            /// DeletingRule: typeof(ORMSolutions.ORMArchitect.Core.ObjectModel.ModelContainsRecognizedPhrase)
            /// Regenerate names when a recognized phrase with relational-targeted aliases is deleting
            /// </summary>
            private static void RecognizedPhraseDeletingRule(ElementDeletingEventArgs e)
            {
                ORMCore.ModelContainsRecognizedPhrase link = (ORMCore.ModelContainsRecognizedPhrase)e.ModelElement;
                Store           store          = link.Store;
                DomainClassInfo relationalInfo = store.DomainDataDirectory.GetDomainClass(RelationalNameGenerator.DomainClassId);

                foreach (ORMCore.NameAlias alias in link.RecognizedPhrase.AbbreviationCollection)
                {
                    if (relationalInfo.IsDerivedFrom(alias.NameConsumerDomainClass))
                    {
                        foreach (Schema schema in store.ElementDirectory.FindElements <Schema>(true))
                        {
                            ValidateSchemaNamesChanged(schema);
                        }
                        break;
                    }
                }
            }
Example #4
0
        internal virtual bool internalCanMerge(VDWidget origianlTargetWidget, ProtoElementBase sourceRootElement, ElementGroupPrototype elementGroupPrototype)
        {
            if (elementGroupPrototype == null)
            {
                throw new ArgumentNullException("elementGroupPrototype");
            }

            if (sourceRootElement != null)
            {
                DomainClassInfo rootElementDomainInfo = this.Partition.DomainDataDirectory.GetDomainClass(sourceRootElement.DomainClassId);
                if (rootElementDomainInfo.IsDerivedFrom(VDWidget.DomainClassId))
                {
                    return(MergeManager.Instance.CanMerge(rootElementDomainInfo.Id, this.GetDomainClass().Id));
                }
            }

            return(base.CanMerge(sourceRootElement, elementGroupPrototype));
        }
Example #5
0
        /// <summary>
        /// Determines whether this instance [can merge layer] the specified root element.
        /// </summary>
        /// <param name="rootElement">The root element.</param>
        /// <param name="elementGroupPrototype">The element group prototype.</param>
        /// <returns>
        ///     <c>true</c> if this instance [can merge layer] the specified root element; otherwise, <c>false</c>.
        /// </returns>
        private bool CanMergeLayer(ProtoElementBase rootElement, ElementGroupPrototype elementGroupPrototype)
        {
            if (elementGroupPrototype == null)
            {
                throw new ArgumentNullException("elementGroupPrototype");
            }

            if (rootElement != null)
            {
                DomainClassInfo rootElementDomainInfo =
                    Partition.DomainDataDirectory.GetDomainClass(rootElement.DomainClassId);

                if (rootElementDomainInfo.IsDerivedFrom(Layer.DomainClassId))
                {
                    return(Component.GetLayerLevel(rootElement.DomainClassId) == Level);
                }
            }
            return(false);
        }
Example #6
0
        public override bool ModelCanMerge(CopyPaste.ModelProtoElement protoElement, CopyPaste.ModelProtoGroup protoGroup)
        {
            if (protoElement != null)
            {
                DomainClassInfo elementDomainInfo = this.Partition.DomainDataDirectory.GetDomainClass(protoElement.DomainClassId);
                if (elementDomainInfo.IsDerivedFrom(global::Tum.PDE.LanguageDSL.DomainClass.DomainClassId))
                {
                    if (protoGroup.Operation == ModelProtoGroupOperation.Move)
                    {
                        foreach (global::Tum.PDE.LanguageDSL.LibraryModelContextHasClasses link in DomainRoleInfo.GetElementLinks <global::Tum.PDE.LanguageDSL.LibraryModelContextHasClasses>(this, global::Tum.PDE.LanguageDSL.LibraryModelContextHasClasses.LibraryModelContextDomainRoleId))
                        {
                            if (link.DomainClass.Id == protoElement.ElementId)
                            {
                                return(false);
                            }
                        }
                    }
                    return(true);
                }
                else if (elementDomainInfo.IsDerivedFrom(global::Tum.PDE.LanguageDSL.DomainRelationship.DomainClassId))
                {
                    if (protoGroup.Operation == ModelProtoGroupOperation.Move)
                    {
                        foreach (global::Tum.PDE.LanguageDSL.LibraryModelContextHasRelationships link in DomainRoleInfo.GetElementLinks <global::Tum.PDE.LanguageDSL.LibraryModelContextHasRelationships>(this, global::Tum.PDE.LanguageDSL.LibraryModelContextHasRelationships.LibraryModelContextDomainRoleId))
                        {
                            if (link.DomainRelationship.Id == protoElement.ElementId)
                            {
                                return(false);
                            }
                        }
                    }

                    // see if source and target domain classes are copied here
                    List <ModelProtoElement> elements = protoGroup.GetEmbeddedElements(this.Partition, protoElement);
                    for (int i = 0; i < elements.Count; i++)
                    {
                        if (elements[i].Name == "DomainRole")
                        {
                            List <ModelProtoLink> links = protoGroup.GetReferenceLinks(this.Partition, elements[i]);
                            foreach (ModelProtoLink link in links)
                            {
                                if (link.Name == "DomainRoleReferencesRolePlayer")
                                {
                                    ModelProtoRolePlayer rP = link.GetTargetRolePlayer(this.Partition);
                                    // see if the target element is beeing copied or is already in the model
                                    if (!protoGroup.HasProtoElementFor(rP.RolePlayerId, this.Partition))
                                    {
                                        ModelElement m = this.Store.ElementDirectory.FindElement(rP.RolePlayerId);
                                        if (m == null)
                                        {
                                            if (!this.MetaModel.HasElement(rP.ElementName))
                                            {
                                                return(false);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    return(true);
                }
            }
            return(false);
        }