Exemple #1
0
 /// <summary>
 /// Creates a new value specification with an unlimited natural type.
 /// </summary>
 /// <param name="value">Initial value</param>
 public ValueSpecification(NUml.Uml2.UnlimitedNatural value)
 {
     NUml.Uml2.LiteralUnlimitedNatural literal = NUml.Uml2.Create.LiteralUnlimitedNatural();
     literal.Value  = value;
     adaptedElement = literal;
     valueType      = ValueTypes.UnlimitedNatural;
 }
        internal override void CommandOperation()
        {
            oldType           = PSMAttribute.Type;
            PSMAttribute.Type = Type;

            oldAlias = PSMAttribute.Alias;
            if (Alias != null)
            {
                PSMAttribute.Alias = Alias;
            }

            oldLower = PSMAttribute.Lower;
            oldUpper = PSMAttribute.Upper;

            if (customMultiplicity)
            {
                PSMAttribute.Lower = Lower;
                PSMAttribute.Upper = Upper;
            }

            oldDefault           = PSMAttribute.Default;
            PSMAttribute.Default = Default;

            oldName           = PSMAttribute.Name;
            PSMAttribute.Name = Name;

            AssociatedElements.Add(PSMAttribute.Class);
        }
        /// <summary>
        /// Checks whether the new multiplicity is a correct one
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CheckCorrectMultiplicity(object sender, RoutedEventArgs e)
        {
            TextBox        t      = (TextBox)sender;
            AssociationEnd oldEnd = (AssociationEnd)t.DataContext;

            NUml.Uml2.UnlimitedNatural oldUpper = oldEnd.Upper;
            uint?oldLower = oldEnd.Lower;

            Regex numbers = new Regex("^[0-9]+$");

            Match m = numbers.Match(((TextBox)sender).Text);

            if (m.Success) // correct numerical imput
            {
                if (t.Name.Equals("upperBox") && int.Parse(t.Text) >= oldLower)
                {
                    return;
                }
                else
                if (t.Name.Equals("lowerBox"))
                {
                    if (oldUpper.ToString().Equals("*") || int.Parse(t.Text) <= oldUpper.Value)
                    {
                        return;
                    }
                }
            }
            else
            if (t.Text.Equals("*") && t.Name.Equals("upperBox"))
            {
                return;
            }

            // New value refused

            ErrDialog ed = new ErrDialog();

            ed.SetText("Change element multiplicity\n", "Lower bound cannot be greater than upper bound");
            ed.Show();

            ((TextBox)sender).DataContext = null;
            ((TextBox)sender).DataContext = oldEnd;
            return;
        }
Exemple #4
0
        /// <summary>
        /// Processes one selected TreeView item. Generates commands for addition of PSMClasses, PSMStructuralRepresentatives and PSMAssociations
        /// </summary>
        /// <param name="T">The item to be processed</param>
        private void GenerateCommands(TreeClasses T)
        {
            #region Holders
            ElementHolder <PSMClass>            Child             = new ElementHolder <PSMClass>();
            ElementHolder <PSMAssociationChild> ChildAssociation  = new ElementHolder <PSMAssociationChild>();
            ElementHolder <PSMAssociation>      AssociationHolder = new ElementHolder <PSMAssociation>();
            #endregion

            #region Create new element

            if (T.RootClass == null)
            {
                NewPSMClassCommand c1 = NewPSMClassCommandFactory.Factory().Create(Controller.ModelController) as NewPSMClassCommand;
                c1.RepresentedClass = T.PIMClass;
                c1.CreatedClass     = Child;
                Commands.Add(c1);

                if (T.Represented != null) //Creating PSM Structural Representative
                {
                    SetRepresentedPSMClassCommand c1a = SetRepresentedPSMClassCommandFactory.Factory().Create(Controller) as SetRepresentedPSMClassCommand;
                    c1a.Set(T.Represented, Child);
                    Commands.Add(c1a);
                }

                //Put the newly created PSMClass to the diagram
                ElementToDiagramCommand <PSMClass, PSMElementViewHelper> c2 = ElementToDiagramCommandFactory <PSMClass, PSMElementViewHelper> .Factory().Create(Controller) as ElementToDiagramCommand <PSMClass, PSMElementViewHelper>;

                c2.IncludedElement = Child;
                Commands.Add(c2);
            }
            else //Connecting existing root
            {
                Child.Element = T.RootClass;
                RemovePSMClassFromRootsCommand c = RemovePSMClassFromRootsCommandFactory.Factory().Create(Controller) as RemovePSMClassFromRootsCommand;
                c.Set(Child);
                Commands.Add(c);
            }

            #endregion

            #region PSM Association

            #region Path generation
            //Prepare path for NestingJoin - Path from child to parent consisting of AssociationEnds (PIMSteps)
            List <NestingJoinStep> Path = new List <NestingJoinStep>();
            uint?Lower = 1;
            NUml.Uml2.UnlimitedNatural Upper = 1;
            TreeClasses t = T;
            while (t.ParentTC != null)
            {
                Path.Add(new NestingJoinStep()
                {
                    Association = t.Association, End = t.PIMClass, Start = t.ParentTC.PIMClass
                });
                Lower *= t.Lower;
                if (t.Upper.IsInfinity)
                {
                    Upper = NUml.Uml2.UnlimitedNatural.Infinity;
                }
                else if (!Upper.IsInfinity)
                {
                    Upper = Upper.Value * t.Upper.Value;
                }
                t = t.ParentTC;
            }

            #endregion

            //Add PSMAssociation connecting the parent to the PSMClass
            Commands.Add(new HolderConvertorCommand <PSMClass, PSMAssociationChild>(Child, ChildAssociation));
            NewPSMAssociationCommand c3 = NewPSMAssociationCommandFactory.Factory().Create(Controller.ModelController) as NewPSMAssociationCommand;
            c3.Set(new ElementHolder <PSMSuperordinateComponent>()
            {
                Element = SourcePSMClass
            }, ChildAssociation, AssociationHolder, null);

            //Set PSM association multiplicity
            c3.Upper = Upper;
            c3.Lower = Lower;
            c3.UsedGeneralizations = T.UsedGeneralizations;
            Commands.Add(c3);
            #endregion

            #region Nesting join
            //Set the nestingjoin
            AddSimpleNestingJoinCommand c4 = AddSimpleNestingJoinCommandFactory.Factory().Create(Controller.ModelController) as AddSimpleNestingJoinCommand;
            c4.Set(AssociationHolder, Path);
            Commands.Add(c4);
            #endregion

            #region Association to diagram
            //Add created PSMAssociations to the diagram
            ElementToDiagramCommand <PSMAssociation, PSMAssociationViewHelper> c5 = (ElementToDiagramCommand <PSMAssociation, PSMAssociationViewHelper>) ElementToDiagramCommandFactory <PSMAssociation, PSMAssociationViewHelper> .Factory().Create(Controller);

            c5.IncludedElement = AssociationHolder;
            Commands.Add(c5);
            #endregion
        }