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();
            }
        }
Ejemplo n.º 2
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.º 3
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.º 4
0
        private void Application_CellChangedEvent(Cell cell)
        {
            Shape changedShape = cell.Shape;

            // ReSharper disable once MergeSequentialChecksWhenPossible
            if ((changedShape == null) || !changedShape.Document.Template.Contains(Information.TemplateName) || (changedShape.CellExistsU[VisioFormulas.Cell_RationallyType, (short)VisExistsFlags.visExistsAnywhere] != Constants.CellExists)) //No need to continue when the shape is not part of our model.
            {
                return;
            }
            try
            {
                if (RelatedUrlComponent.IsRelatedUrlComponent(changedShape.Name) && cell.LocalName.Equals(VisioFormulas.Cell_HyperlinkAddress)) //Link has updated
                {
                    Log.Debug("Cell changed of hyperlink shape:" + changedShape.Name);
                    //find the container that holds all Related Documents
                    RelatedDocumentsContainer relatedDocumentsContainer = (RelatedDocumentsContainer)View.Children.First(c => c is RelatedDocumentsContainer);
                    //find the related document holding the changed shape (one of his children has Shape equal to changedShape)
                    RelatedDocumentContainer relatedDocumentContainer = relatedDocumentsContainer.Children.Where(c => c is RelatedDocumentContainer).Cast <RelatedDocumentContainer>().First(dc => dc.Children.Where(c => c.Shape.Equals(changedShape)).ToList().Count > 0);
                    //update the text of the URL display component to the new url
                    RelatedURLURLComponent relatedURLURLComponent = (RelatedURLURLComponent)relatedDocumentContainer.Children.First(c => c is RelatedURLURLComponent);
                    relatedURLURLComponent.Text = changedShape.Hyperlink.Address;
                }
                else if (Application.IsUndoingOrRedoing && CheckBoxStateComponent.IsCheckBoxStateComponent(changedShape.Name) && cell.LocalName.Equals(VisioFormulas.Cell_BackGroundColour))
                {
                    CheckBoxStateComponent checkBoxState = View.GetComponentByShape(changedShape) as CheckBoxStateComponent;
                    if (checkBoxState != null)
                    {
                        Model.PlanningItems[checkBoxState.Index].Finished = checkBoxState.Checked;
                    }
                }
                else if (Application.IsUndoingOrRedoing && ForceContainer.IsForceContainer(changedShape.Name) && cell.LocalName.Equals(VisioFormulas.Cell_Index))
                {
                    Log.Debug("Forceindex cell changed of forcecontainer. shape:" + changedShape.Name);
                    VisioShape forcesComponent = View.Children.FirstOrDefault(x => x is ForcesContainer);
                    if (forcesComponent != null)
                    {
                        rebuildTree = true; //Wait with the rebuild till the undo is done
                    }
                }
                else if (Application.IsUndoingOrRedoing && AlternativeShape.IsAlternativeContainer(changedShape.Name) && cell.LocalName.Equals(VisioFormulas.Cell_Index))
                {
                    Log.Debug("Alternative index cell changed of alternativecontainer. shape:" + changedShape.Name);
                    VisioShape alternativesComponent = View.Children.FirstOrDefault(x => x is AlternativesContainer);
                    if (alternativesComponent != null)
                    {
                        rebuildTree = true; //Wait with the rebuild till the undo is done
                    }
                }
                else if (Application.IsUndoingOrRedoing && RelatedDocumentContainer.IsRelatedDocumentContainer(changedShape.Name) && cell.LocalName.Equals(VisioFormulas.Cell_Index))
                {
                    Log.Debug("Document index cell changed of documentcontainer. shape:" + changedShape.Name);
                    VisioShape docComponent = View.Children.FirstOrDefault(x => x is RelatedDocumentsContainer);
                    if (docComponent != null)
                    {
                        rebuildTree = true; //Wait with the rebuild till the undo is done
                    }
                }
                else if (Application.IsUndoingOrRedoing && StakeholderContainer.IsStakeholderContainer(changedShape.Name) && cell.LocalName.Equals(VisioFormulas.Cell_Index))
                {
                    Log.Debug("Stakeholder index cell changed of stakeholdercontainer. shape:" + changedShape.Name);
                    VisioShape stakeholderComponent = View.Children.FirstOrDefault(x => x is StakeholdersContainer);
                    if (stakeholderComponent != null)
                    {
                        rebuildTree = true; //Wait with the rebuild till the undo is done
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, ex);
#if DEBUG
                throw;
#endif
            }
        }