public void Execute(Shape s, string context)
        {
            RationallyModel model = Globals.RationallyAddIn.Model;

            Log.Debug("Model found: " + (model != null));
            AlternativesContainer alternativesContainer = (AlternativesContainer)Globals.RationallyAddIn.View.Children.First(ch => ch is AlternativesContainer);

            Log.Debug("Alternatives container found in view tree: " + (alternativesContainer != null));
            Log.Debug("Alternatives count: " + model.Alternatives.Count);
            if (model.Alternatives.Count >= Constants.SupportedAmountOfAlternatives) //The view does not handling more than 3 alternatives well, by default.
            {
                AddAlternativeWithWarning alternativePopUp = new AddAlternativeWithWarning(model);
                if (alternativePopUp.ShowDialog() == DialogResult.OK)
                {
                    alternativesContainer?.AddAlternative(alternativePopUp.alternativeName.Text, alternativePopUp.alternativeStatus.SelectedItem.ToString());
                }
                alternativePopUp.Dispose();
            }
            else
            {
                AddAlternative alternativePopUp = new AddAlternative(model);
                if (alternativePopUp.ShowDialog() == DialogResult.OK)
                {
                    Log.Debug("About to enter AddAlternative method");
                    alternativesContainer?.AddAlternative(alternativePopUp.alternativeName.Text, alternativePopUp.alternativeStatus.SelectedItem.ToString());
                }
                alternativePopUp.Dispose();
            }
        }
        public void Execute(Shape s, string context)
        {
            RationallyModel model     = Globals.RationallyAddIn.Model;
            VisioShape      component = new VisioShape(Globals.RationallyAddIn.Application.ActivePage)
            {
                Shape = s
            };

            int          index         = component.Index;
            Alternative  alternative   = model.Alternatives[index];
            DialogResult confirmResult = MessageBox.Show("Are you sure you want to delete " + alternative.Title + "?", "Confirm Deletion", MessageBoxButtons.YesNo);

            if (confirmResult == DialogResult.Yes)
            {
                Shape shapeToPass;

                if (AlternativeShape.IsAlternativeContainer(s.Name))
                {
                    shapeToPass = s;
                }
                else //subpart of alternative container
                {
                    //trace alternatives container
                    AlternativesContainer alternativesContainer = (AlternativesContainer)Globals.RationallyAddIn.View.Children.First(c => c is AlternativesContainer);
                    //trace the correct alternative container
                    AlternativeShape alternativeShape = (AlternativeShape)alternativesContainer.Children.First(c => c is AlternativeShape && (component.Index == c.Index));

                    shapeToPass = alternativeShape.Shape;
                }
                //initiate a delete handler with the container's shape
                shapeToPass.Delete();
            }
        }
        public void Save()
        {
            if (Validate())
            {
                if (!File.Exists(Constants.StateResourceFile))
                {
                    File.Create(Constants.StateResourceFile);
                }
                //write current states to file
                using (ResXResourceWriter resx = new ResXResourceWriter(Constants.StateResourceFile))
                {
                    resx.AddResource("Root", "");
                    for (int i = 0; i < StateRows.Count; i++)
                    {
                        AlternativeState newAlternativeState;
                        Enum.TryParse(StateRows[i].NewState, out newAlternativeState);
                        resx.AddResource("alternativeState" + i, newAlternativeState);
                    }
                }
                //write current states to model
                //StateRows.ForEach(stateRow => Globals.RationallyAddIn.Model.AlternativeStateColors.Add(stateRow.NewState, stateRow.Color)); //NoLongerSupported


                //locate renamed alternative states
                Dictionary <string, string> stateRenames = new Dictionary <string, string>(); //<from,to>
                StateRows.Where(s => (s.OldState != s.NewState) && (s.OldState != null)).ToList().ForEach(s => stateRenames.Add(s.OldState, s.NewState));
                //update renamed alternative states
                Globals.RationallyAddIn.Model.Alternatives
                .Where(alternative => stateRenames.ContainsKey(alternative.Status)).ToList()
                .ForEach(alternative => alternative.Status = stateRenames[alternative.Status]);


                //update non-existent alternative states to the default state

                /*Globals.RationallyAddIn.Model.Alternatives
                 *  .Where(alternative => !Globals.RationallyAddIn.Model.AlternativeStateColors.ContainsKey(alternative.Status)).ToList()
                 *  .ForEach(alternative => alternative.Status = Globals.RationallyAddIn.Model.AlternativeStateColors.Keys.First());*/


                //repaint all currently present alternative state components
                AlternativesContainer alternativesContainer = (AlternativesContainer)Globals.RationallyAddIn.View.Children.FirstOrDefault(c => c is AlternativesContainer);
                //map all alternatives to their state component shape
                IEnumerable <AlternativeStateShape> toUpdate = alternativesContainer?.Children
                                                               .Select(alt => ((AlternativeShape)alt).Children.First(c => c is AlternativeStateShape))
                                                               .Cast <AlternativeStateShape>();
                toUpdate?.ToList().ForEach(stateComp => stateComp.Repaint());
            }
            else
            {
                MessageBox.Show("States must all have unique names", "Duplicate State Name Error");
            }
        }
        public void Execute(RationallyView view, Shape changedShape)
        {
            AlternativesContainer cont = (AlternativesContainer)view.Children.First(x => x is AlternativesContainer);

            foreach (AlternativeShape alternativeContainer in cont.Children.Where(c => c is AlternativeShape).Cast <AlternativeShape>().ToList())
            {
                if ((alternativeContainer.Children.Where(c => c.Shape.Equals(changedShape)).ToList().Count > 0) && !alternativeContainer.Deleted) //check if this alternative contains the to be deleted component and is not already deleted
                {
                    alternativeContainer.Deleted = true;
                    alternativeContainer.Shape.Delete(); //delete the parent wrapper of s
                }
            }
        }
Ejemplo n.º 5
0
        public void Execute(Shape changedShape, string identifier)
        {
            RationallyModel       model = Globals.RationallyAddIn.Model;
            AlternativesContainer alternativesContainer = (AlternativesContainer)Globals.RationallyAddIn.View.Children.First(c => c is AlternativesContainer);

            VisioShape toChangeComponent = Globals.RationallyAddIn.View.GetComponentByShape(changedShape);
            int        currentIndex      = toChangeComponent.Index;

            AlternativeShape toChange = (AlternativeShape)alternativesContainer.Children.First(c => (int)c.Shape.CellsU[VisioFormulas.Cell_Index].ResultIU == currentIndex);
            //locate the alternative that we are going to swap with
            AlternativeShape other = (AlternativeShape)alternativesContainer.Children.First(c => (int)c.Shape.CellsU[VisioFormulas.Cell_Index].ResultIU == currentIndex + 1);

            //swap the items in the model
            model.Alternatives[currentIndex].GenerateIdentifier(currentIndex + 1);
            model.Alternatives[currentIndex + 1].GenerateIdentifier(currentIndex);

            string higherIndex = model.Alternatives[currentIndex].IdentifierString;
            string oldIndex    = model.Alternatives[currentIndex + 1].IdentifierString;

            Alternative one = model.Alternatives[currentIndex];

            model.Alternatives[currentIndex]     = model.Alternatives[currentIndex + 1];
            model.Alternatives[currentIndex + 1] = one;

            //update the index of the component and his children
            toChange.Index = currentIndex + 1;

            //same, for the other component
            other.Index = currentIndex;

            //update the related force column value identifiers
            ForcesContainer forcesContainer = (ForcesContainer)Globals.RationallyAddIn.View.Children.FirstOrDefault(c => c is ForcesContainer);

            //set all force value cells with id "higherIndex" to "temp"
            //set all force value cells with id "oldIndex" to "higherIndex"
            //set all force value cells with id "temp" to "oldIndex"
            forcesContainer?.Children.Where(c => c is ForceContainer).Cast <ForceContainer>().ToList().ForEach(fc => fc.Children.Where(fcc => fcc is ForceValueComponent && (((ForceValueComponent)fcc).AlternativeIdentifierString == higherIndex)).Cast <ForceValueComponent>().ToList().ForEach(fvc => fvc.AlternativeIdentifierString = "temp"));
            forcesContainer?.Children.Where(c => c is ForceContainer).Cast <ForceContainer>().ToList().ForEach(fc => fc.Children.Where(fcc => fcc is ForceValueComponent && (((ForceValueComponent)fcc).AlternativeIdentifierString == oldIndex)).Cast <ForceValueComponent>().ToList().ForEach(fvc => fvc.AlternativeIdentifierString    = higherIndex));
            forcesContainer?.Children.Where(c => c is ForceContainer).Cast <ForceContainer>().ToList().ForEach(fc => fc.Children.Where(fcc => fcc is ForceValueComponent && (((ForceValueComponent)fcc).AlternativeIdentifierString == "temp")).Cast <ForceValueComponent>().ToList().ForEach(fvc => fvc.AlternativeIdentifierString      = oldIndex));
            //swap the elements in the view tree
            VisioShape temp = alternativesContainer.Children[currentIndex];

            alternativesContainer.Children[currentIndex]     = alternativesContainer.Children[currentIndex + 1];
            alternativesContainer.Children[currentIndex + 1] = temp;


            RepaintHandler.Repaint();
        }
Ejemplo n.º 6
0
        public void RegenerateAlternativeIdentifiers()
        {
            if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing) //Don't update the view during an undo, since the undo does that for us
            {
                int i = 0;
                AlternativesContainer alternativesContainer = (AlternativesContainer)Globals.RationallyAddIn.View.Children.First(c => c is AlternativesContainer);
                alternativesContainer.Children.Where(c => c is AlternativeShape).ToList().ForEach(c => ((AlternativeShape)c).Index = i++);
            }
            int j = 0;

            foreach (Alternative a in Alternatives)
            {
                a.GenerateIdentifier(j);
                j++;
            }
        }
Ejemplo n.º 7
0
        public void Execute(RationallyModel model, Shape changedShape)
        {
            Log.Debug("Entered delete alternative event handler.");
            //store the rationally type of the last shape, which is responsible for ending the undo scope
            if (string.IsNullOrEmpty(Globals.RationallyAddIn.LastDelete) && (Globals.RationallyAddIn.StartedUndoState == 0) && !Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
            {
                Log.Debug("Starting undo scope.");
                Globals.RationallyAddIn.LastDelete       = changedShape.Name;
                Globals.RationallyAddIn.StartedUndoState = Globals.RationallyAddIn.Application.BeginUndoScope(DeleteUndoScope);
            }

            //trace alternative container in view tree
            VisioShape alternativeComponent = Globals.RationallyAddIn.View.GetComponentByShape(changedShape);

            AlternativeShape delete = alternativeComponent as AlternativeShape;

            if (delete != null)
            {
                model.Forces.ForEach(force => force.ForceValueDictionary.Remove(delete.Id));
                AlternativeShape containerToDelete = delete;
                if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
                {
                    Log.Debug("deleting children of the alternative to delete");
                    containerToDelete.Children.Where(c => !c.Deleted).ToList().ForEach(c =>
                    {
                        c.Deleted = true;
                        c.Shape.DeleteEx((short)VisDeleteFlags.visDeleteNormal);
                    }); //schedule the missing delete events (children not selected during the manual delete)
                }
                AlternativesContainer alternativesContainer = (AlternativesContainer)Globals.RationallyAddIn.View.Children.First(c => c is AlternativesContainer);
                //update model
                model.Alternatives.RemoveAll(a => a.Id == containerToDelete.Id);
                Log.Debug("Alternative removed from alternatives container.");
                //update view tree
                alternativesContainer.Children.Remove(containerToDelete);

                model.RegenerateAlternativeIdentifiers();
                Log.Debug("Identifiers regenerated of alternatives.");
                if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
                {
                    alternativesContainer.MsvSdContainerLocked = true;
                }
                RepaintHandler.Repaint();
            }
        }
Ejemplo n.º 8
0
        public bool DeleteFromTree(Shape s)
        {
            foreach (VisioShape c in Children)
            {
                if (c.Shape.Equals(s))
                {
                    Children.Remove(c);
                    AlternativesContainer container = c as AlternativesContainer;
                    container?.RemoveAlternativesFromModel();
                    return(true);
                }

                if (c is RationallyContainer)
                {
                    RationallyContainer container = c as RationallyContainer;
                    if (container.DeleteFromTree(s))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 9
0
        private void Application_ShapeAddedEvent(Shape s)
        {
            Log.Debug("Shape added with name: " + s.Name);
            if (s.Document.Template.Contains(Information.TemplateName) && (s.CellExistsU[VisioFormulas.Cell_RationallyType, (short)VisExistsFlags.visExistsAnywhere] == Constants.CellExists) && !View.ExistsInTree(s))
            {
                try
                {
                    switch (s.CellsU[VisioFormulas.Cell_RationallyType].ResultStr[VisioFormulas.Value])
                    {
                    case "alternativeAddStub":
                        if (!Application.IsUndoingOrRedoing)
                        {
                            int scopeId = Application.BeginUndoScope(Messages.Scope_AddAlternative);
                            s.Delete();
                            AlternativesContainer alternativesContainer = Globals.RationallyAddIn.View.Children.FirstOrDefault(ch => ch is AlternativesContainer) as AlternativesContainer;
                            alternativesContainer?.AddAlternative("Title", default(AlternativeState).GetName());

                            Application.EndUndoScope(scopeId, true);
                        }
                        break;

                    case "forceAddStub":
                        if (!Application.IsUndoingOrRedoing)
                        {
                            int scopeId = Application.BeginUndoScope(Messages.Scope_AddForce);
                            s.Delete();
                            MarkerEventHandlerRegistry.HandleEvent("forces.add", null, null);
                            Application.EndUndoScope(scopeId, true);
                        }
                        break;

                    case "relatedDocumentAddStub":
                        if (!Application.IsUndoingOrRedoing)
                        {
                            int scopeId = Application.BeginUndoScope(Messages.Scope_AddFile);
                            s.Delete();
                            MarkerEventHandlerRegistry.HandleEvent("relatedDocuments.addRelatedFile", null, null);
                            Application.EndUndoScope(scopeId, true);
                        }
                        break;

                    case "relatedUrlAddStub":
                        if (!Application.IsUndoingOrRedoing)
                        {
                            int scopeId = Application.BeginUndoScope(Messages.Scope_AddUrl);
                            s.Delete();
                            MarkerEventHandlerRegistry.HandleEvent("relatedDocuments.addRelatedUrl", null, null);
                            Application.EndUndoScope(scopeId, true);
                        }
                        break;

                    case "stakeholderAddStub":
                        if (!Application.IsUndoingOrRedoing)
                        {
                            int scopeId = Application.BeginUndoScope(Messages.Scope_AddStakeholder);
                            s.Delete();
                            StakeholdersContainer stakeholdersContainer = View.Children.FirstOrDefault(ch => ch is StakeholdersContainer) as StakeholdersContainer;
                            stakeholdersContainer?.AddStakeholder("<<name>>", "<<role>>");

                            Application.EndUndoScope(scopeId, true);
                        }
                        break;

                    case "planningItemStub":
                        if (!Application.IsUndoingOrRedoing)
                        {
                            int scopeId = Application.BeginUndoScope(Messages.Scope_AddPlanningItem);
                            s.Delete();
                            PlanningContainer planningContainer = View.Children.FirstOrDefault(ch => ch is PlanningContainer) as PlanningContainer;
                            planningContainer?.AddPlanningItem();

                            Application.EndUndoScope(scopeId, true);
                        }
                        break;

                    default:
                        View.AddToTree(s, true);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex, ex);
#if DEBUG
                    throw;
#endif
                }
            }
        }
Ejemplo n.º 10
0
 public override void AddToTree(Shape s, bool allowAddOfSubpart)
 {
     if (AlternativesContainer.IsAlternativesContainer(s.Name))
     {
         if (Children.Exists(x => AlternativesContainer.IsAlternativesContainer(x.Name)))
         {
             if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
             {
                 MessageBox.Show(Messages.OneAlternativesContainerAllowed, Messages.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 s.DeleteEx((short)VisDeleteFlags.visDeleteNormal);
             }
         }
         else
         {
             Children.Add(new AlternativesContainer(Page, s));
         }
     }
     else if (RelatedDocumentsContainer.IsRelatedDocumentsContainer(s.Name))
     {
         if (Children.Exists(x => RelatedDocumentsContainer.IsRelatedDocumentsContainer(x.Name)))
         {
             if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
             {
                 MessageBox.Show(Messages.OneRelatedDocumentsContainerAllowed, Messages.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 s.DeleteEx((short)VisDeleteFlags.visDeleteNormal);
             }
         }
         else
         {
             RelatedDocumentsContainer rdc = new RelatedDocumentsContainer(Page, s);
             Children.Add(rdc);
         }
     }
     else if (ForcesContainer.IsForcesContainer(s.Name))
     {
         if (Children.Exists(x => ForcesContainer.IsForcesContainer(x.Name)))
         {
             if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
             {
                 MessageBox.Show(Messages.OneForcesContainerAllowed, Messages.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 s.DeleteEx((short)VisDeleteFlags.visDeleteNormal);
             }
         }
         else
         {
             ForcesContainer forcesContainer = new ForcesContainer(Page, s);
             Children.Add(forcesContainer);
         }
     }
     else if (InformationContainer.IsInformationContainer(s.Name))
     {
         if (Children.Exists(x => InformationContainer.IsInformationContainer(x.Name)))
         {
             if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
             {
                 MessageBox.Show(Messages.OneInformationContainerAllowed, Messages.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 s.DeleteEx((short)VisDeleteFlags.visDeleteNormal);
             }
         }
         else
         {
             InformationContainer informationContainer = new InformationContainer(Page, s);
             Children.Add(informationContainer);
         }
     }
     else if (TitleLabel.IsTitleLabel(s.Name))
     {
         if (Children.Exists(x => TitleLabel.IsTitleLabel(x.Name)))
         {
             if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
             {
                 MessageBox.Show(Messages.OneTitleAllowed, Messages.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 s.DeleteEx((short)VisDeleteFlags.visDeleteNormal);
             }
         }
         else
         {
             TitleLabel titleLabel = new TitleLabel(Page, s);
             Children.Add(titleLabel);
         }
     }
     else if (StakeholdersContainer.IsStakeholdersContainer(s.Name))
     {
         if (Children.Exists(x => StakeholdersContainer.IsStakeholdersContainer(x.Name)))
         {
             if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
             {
                 MessageBox.Show(Messages.OneStakeholdersContainerAllowed, Messages.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 s.DeleteEx((short)VisDeleteFlags.visDeleteNormal);
             }
         }
         else
         {
             StakeholdersContainer stakeholdersContainer = new StakeholdersContainer(Page, s);
             Children.Add(stakeholdersContainer);
         }
     }
     else if (PlanningContainer.IsPlanningContainer(s.Name))
     {
         if (Children.Exists(x => PlanningContainer.IsPlanningContainer(x.Name)))
         {
             if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing)
             {
                 MessageBox.Show(Messages.OnePlanningContainerAllowed, Messages.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 s.DeleteEx((short)VisDeleteFlags.visDeleteNormal);
             }
         }
         else
         {
             PlanningContainer planningContainer = new PlanningContainer(Page, s);
             Children.Add(planningContainer);
         }
     }
     else if (allowAddOfSubpart)
     {
         Children.ForEach(r => r.AddToTree(s, true));
     }
 }