public void Execute(Shape changedShape, string identifier) { RationallyModel model = Globals.RationallyAddIn.Model; ForcesContainer forcesContainer = (ForcesContainer)Globals.RationallyAddIn.View.Children.First(c => c is ForcesContainer); if (forcesContainer.Children.Count == 0) { //insert header, if it is absent if ((forcesContainer.Children.Count == 0) || !forcesContainer.Children.Any(c => c is ForceHeaderRow)) { forcesContainer.Children.Insert(0, new ForceHeaderRow(Globals.RationallyAddIn.Application.ActivePage)); } //insert footer, if it is absent if ((forcesContainer.Children.Count == 0) || !forcesContainer.Children.Any(c => c is ForceTotalsRow)) { forcesContainer.Children.Add(new ForceTotalsRow(Globals.RationallyAddIn.Application.ActivePage)); } else if (forcesContainer.Children.Any(c => c is ForceTotalsRow)) { VisioShape toMove = forcesContainer.Children.First(c => c is ForceTotalsRow); int toMoveIndex = forcesContainer.Children.IndexOf(toMove); VisioShape toSwapWith = forcesContainer.Children.Last(); forcesContainer.Children[forcesContainer.Children.Count - 1] = toMove; forcesContainer.Children[toMoveIndex] = toSwapWith; } } Force newForce = new Force(ForceConcernComponent.DefaultConcern, ForceDescriptionComponent.DefaultDescription); model.Forces.Add(newForce); forcesContainer.Children.Insert(forcesContainer.Children.Count - 1, new ForceContainer(Globals.RationallyAddIn.Application.ActivePage, forcesContainer.Children.Count - 2, newForce.Id)); //update the model as well RepaintHandler.Repaint(forcesContainer); }
public void RegenerateForceIdentifiers() { int i = 0; ForcesContainer forcesContaineresContainer = (ForcesContainer)Globals.RationallyAddIn.View.Children.First(c => c is ForcesContainer); forcesContaineresContainer.Children.Where(c => c is ForceContainer).ToList().ForEach(c => ((ForceContainer)c).SetForceIdentifier(i++)); }
public void Execute(Shape changedShape, string identifier) { //get the corresponding view tree component VisioShape forceComponent = Globals.RationallyAddIn.View.GetComponentByShape(changedShape); //get his parent, or himself, if changedShape is the container already ForcesContainer forcesContainer = (ForcesContainer)Globals.RationallyAddIn.View.Children.First(c => c is ForcesContainer); //loop over forcecontainers. Return the one that a child matching changedShape OR forceComponent, for changedShape is the container itself ForceContainer forceContainer = forcesContainer.Children.Where(c => c is ForceContainer).Cast <ForceContainer>().ToList().FirstOrDefault(c => c.Children.Any(x => x.Shape.Equals(changedShape))) ?? (ForceContainer)forceComponent; forceContainer.Deleted = true; forceContainer.Shape.Delete(); }
public void Execute(RationallyView view, Shape changedShape) { ForcesContainer forcesContainer = (ForcesContainer)view.Children.First(c => c is ForcesContainer); foreach (ForceContainer forceContainer in forcesContainer.Children.Where(c => c is ForceContainer).Cast <ForceContainer>().ToList()) //find all candidate containers { if ((forceContainer.Children.Where(c => c.Shape.Equals(changedShape)).ToList().Count > 0) && !forceContainer.Deleted) //find the right container of changedShape and the container was not part of the selection at the querycancel shapedelete event { forceContainer.Deleted = true; forceContainer.Shape.Delete(); } } }
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(); }
public void Execute(RationallyView view, Shape changedShape) { ForcesContainer forcesContainer = (ForcesContainer)view.Children.First(c => c is ForcesContainer); ForceValueComponent forceValue = (ForceValueComponent)view.GetComponentByShape(changedShape); string forceVal = forceValue.Text == string.Empty ? "0" : forceValue.Text; Globals.RationallyAddIn.Model.Forces[forceValue.Index].ForceValueDictionary[forceValue.ForceAlternativeId] = forceVal; RepaintHandler.Repaint(forceValue); //repaint the force value, for coloring ForceTotalsRow forceTotalsRow = forcesContainer.Children.First(c => c is ForceTotalsRow) as ForceTotalsRow; if (forceTotalsRow != null) { RepaintHandler.Repaint(forceTotalsRow.Children.Where(c => c is ForceTotalComponent).FirstOrDefault(c => c.ForceAlternativeId == forceValue.ForceAlternativeId)); } }
public void Execute(RationallyModel model, Shape changedShape) { Log.Debug("Entered DeleteForceEventHandler."); //trace force row in view tree VisioShape forceComponent = Globals.RationallyAddIn.View.GetComponentByShape(changedShape); if (forceComponent is ForceContainer) { ForceContainer containerToDelete = (ForceContainer)forceComponent; if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing) { Log.Debug("Deleting all child components of the force container..."); containerToDelete.Children.Where(c => !c.Deleted).ToList().ForEach(c => { c.Deleted = true; c.Shape.Delete(); }); //schedule the missing delete events (children not selected during the manual delete) } ForcesContainer forcesContainer = (ForcesContainer)Globals.RationallyAddIn.View.Children.First(c => c is ForcesContainer); //update model if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing) { model.Forces.RemoveAll(force => force.Id == containerToDelete.Id); Log.Debug("Deleting force from model list of forces."); } //update view tree forcesContainer.Children.Remove(containerToDelete); if (!Globals.RationallyAddIn.Application.IsUndoingOrRedoing) { model.RegenerateForceIdentifiers(); Log.Debug("Regenerated force identifiers in model."); forcesContainer.MsvSdContainerLocked = true; } RepaintHandler.Repaint(forcesContainer); } }
public void Execute(Shape changedShape, string identifier) { RationallyModel model = Globals.RationallyAddIn.Model; ForcesContainer forcesContainer = (ForcesContainer)Globals.RationallyAddIn.View.Children.First(c => c is ForcesContainer); VisioShape currentComponent = new VisioShape(changedShape.ContainingPage) { Shape = changedShape }; int currentForceIndex = currentComponent.Index; int currentChildIndex = currentForceIndex + 1; //swap the forces in the model Force currentForce = model.Forces[currentForceIndex]; model.Forces[currentForceIndex] = model.Forces[currentForceIndex - 1]; model.Forces[currentForceIndex - 1] = currentForce; ForceContainer toMove = forcesContainer.Children.Where(c => c is ForceContainer).Cast <ForceContainer>().First(c => c.Index == currentForceIndex); ForceContainer toSwapWith = forcesContainer.Children.Where(c => c is ForceContainer).Cast <ForceContainer>().First(c => c.Index == currentForceIndex - 1); //update the index of the component and his children toMove.Children.ForEach(c => c.Index = currentForceIndex - 1); toMove.Index = currentForceIndex - 1; //same, for the other component toSwapWith.Children.ForEach(c => c.Index = currentForceIndex); toSwapWith.Index = currentForceIndex; VisioShape temp = forcesContainer.Children[currentChildIndex]; forcesContainer.Children[currentChildIndex] = forcesContainer.Children[currentChildIndex - 1]; forcesContainer.Children[currentChildIndex - 1] = temp; RepaintHandler.Repaint(); }
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)); } }