private static void HandleAddLockTunnel(object parameter, IEnumerable <IViewModel> selection, ICompositionHost host, DocumentEditSite site) { var structureViewModels = selection.OfType <StructureViewModel>().WhereNotNull(); if (structureViewModels.Any()) { using (var transaction = structureViewModels.First().TransactionManager.BeginTransaction("Add Lock Tunnels", TransactionPurpose.User)) { foreach (var structureViewModel in structureViewModels) { SMRect leftRect, rightRect; BorderNodeViewModelHelpers.FindBorderNodePositions(structureViewModel, out leftRect, out rightRect); Structure model = (Structure)structureViewModel.Model; LockTunnel lockTunnel = model.MakeTunnel <LockTunnel>(model.PrimaryNestedDiagram, model.NestedDiagrams.First()); FlatSequenceTerminateLifetimeTunnel flatSequenceTerminateLifetimeTunnel = model.MakeTunnel <FlatSequenceTerminateLifetimeTunnel>(model.AncestorDiagram, model.NestedDiagrams.First()); lockTunnel.TerminateLifetimeTunnel = flatSequenceTerminateLifetimeTunnel; flatSequenceTerminateLifetimeTunnel.BeginLifetimeTunnel = lockTunnel; // Set both as rules were not consistently picking right one to adjust to other. lockTunnel.Top = leftRect.Y; lockTunnel.Left = leftRect.X; flatSequenceTerminateLifetimeTunnel.Top = lockTunnel.Top; flatSequenceTerminateLifetimeTunnel.Left = rightRect.X; } transaction.Commit(); } } }
private static void HandleAddIterateTunnel(object parameter, IEnumerable <IViewModel> selection, ICompositionHost host, DocumentEditSite site) { var structureViewModels = selection.OfType <LoopViewModel>().WhereNotNull(); if (structureViewModels.Any()) { using (var transaction = structureViewModels.First().TransactionManager.BeginTransaction("Add Iterate Tunnels", TransactionPurpose.User)) { foreach (var structureViewModel in structureViewModels) { SMRect leftRect, rightRect; BorderNodeViewModelHelpers.FindBorderNodePositions(structureViewModel, out leftRect, out rightRect); var model = (Structure)structureViewModel.Model; LoopIterateTunnel iterateTunnel = model.MakeBorderNode <LoopIterateTunnel>(); LoopTerminateLifetimeTunnel loopTerminateLifetimeTunnel = model.MakeBorderNode <LoopTerminateLifetimeTunnel>(); iterateTunnel.TerminateLifetimeTunnel = loopTerminateLifetimeTunnel; loopTerminateLifetimeTunnel.BeginLifetimeTunnel = iterateTunnel; // Set both as rules were not consistently picking right one to adjust to other. iterateTunnel.Top = leftRect.Y; iterateTunnel.Left = leftRect.X; loopTerminateLifetimeTunnel.Top = iterateTunnel.Top; loopTerminateLifetimeTunnel.Left = rightRect.X; } transaction.Commit(); } } }
private static void HandleAddUnwrapOptionTunnel(object parameter, IEnumerable <IViewModel> selection, ICompositionHost host, DocumentEditSite site) { var flatSequenceStructureViewModels = selection.OfType <StructureViewModel>().WhereNotNull(); if (flatSequenceStructureViewModels.Any()) { using (var transaction = flatSequenceStructureViewModels.First().TransactionManager.BeginTransaction("Add Unwrap Option Tunnels", TransactionPurpose.User)) { foreach (var structureViewModel in flatSequenceStructureViewModels) { Structure model = (Structure)structureViewModel.Model; SMRect leftRect, rightRect; BorderNodeViewModelHelpers.FindBorderNodePositions(structureViewModel, out leftRect, out rightRect); UnwrapOptionTunnel unwrapOptionTunnel = model.MakeTunnel <UnwrapOptionTunnel>(model.AncestorDiagram, model.NestedDiagrams.First()); unwrapOptionTunnel.Top = leftRect.Y; unwrapOptionTunnel.Left = leftRect.X; } transaction.Commit(); } } }