Example #1
0
        private void GraphOnCreateIdentity(Guid id, PointF point, GraphGroup graphGroup = null)
        {
            Stack <GraphGroup> groups = new Stack <GraphGroup>();

            var entity = _diagram.Model?.GetEntity(id);

            if (entity != null)
            {
                RecurseEntityCreation(entity, point, groups);
            }
            else
            {
                var group = _diagram.Model?.GetGroup(id);
                if (group != null)
                {
                    RecurseGroupCreation(group, point, groups);
                }
            }

            while (groups.Count > 0)
            {
                var current = groups.Pop();
                current.RefreshBorder();
            }
        }
Example #2
0
        private void GraphOnCreateTemplate(Guid id, PointF point, GraphGroup graphGroup)
        {
            Stack <GraphGroup> groups = new Stack <GraphGroup>();

            var template = _diagram.Model?.GetEntityTemplate(id);

            if (template != null)
            {
                var entity = template.CreateEntity(template.Name);
                if (entity is IGroupElement groupElement && graphGroup?.GroupShape?.Identity is IGroup group)
                {
                    groupElement.SetParent(group);
                }
                var node = AddShape(_diagram.AddShape(entity, point));
                _graph.Selection.Clear();
                _graph.Selection.Add(node);
            }
            else
            {
                var tbTemplate = _diagram.Model?.GetTrustBoundaryTemplate(id);
                if (tbTemplate != null)
                {
                    var trustBoundary = tbTemplate.CreateTrustBoundary(tbTemplate.Name);
                    if (graphGroup?.GroupShape?.Identity is IGroup group)
                    {
                        trustBoundary.SetParent(group);
                    }
                    var node = AddShape(_diagram.AddShape(trustBoundary, point, new SizeF(600, 300)));
                    _graph.Selection.Clear();
                    _graph.Selection.Add(node);
                }
            }
        }
Example #3
0
        private void RecurseExistingGroups([NotNull] IGroup group,
                                           [NotNull] GraphGroup graphGroup, [NotNull] Stack <GraphGroup> groups)
        {
            groups.Push(graphGroup);

            if (group is ITrustBoundary trustBoundary && trustBoundary.Parent != null)
            {
                RecurseExistingGroups(trustBoundary.Parent, groups);
            }
        }
Example #4
0
        private void GraphOnCreateExternalInteractor(PointF point, GraphGroup graphGroup)
        {
            var interactor = _diagram.Model?.AddEntity <IExternalInteractor>();

            if (interactor != null)
            {
                if (graphGroup?.GroupShape?.Identity is IGroup group)
                {
                    interactor.SetParent(group);
                }
                var node = AddShape(_diagram.AddShape(interactor, point));
                _graph.Selection.Clear();
                _graph.Selection.Add(node);
            }
        }
Example #5
0
        private void GraphOnCreateTrustBoundary(PointF point, GraphGroup graphGroup)
        {
            var newGroup = _diagram.Model?.AddGroup <ITrustBoundary>();

            if (newGroup is ITrustBoundary trustBoundary)
            {
                if (graphGroup?.GroupShape?.Identity is IGroup group)
                {
                    trustBoundary.SetParent(group);
                }
                var node = AddShape(_diagram.AddShape(trustBoundary, point, new SizeF(600, 300)));
                _graph.Selection.Clear();
                _graph.Selection.Add(node);
            }
        }
Example #6
0
        private void GraphOnCreateProcess(PointF point, GraphGroup graphGroup)
        {
            var process = _diagram.Model?.AddEntity <IProcess>();

            if (process != null)
            {
                if (graphGroup?.GroupShape?.Identity is IGroup group)
                {
                    process.SetParent(group);
                }
                var node = AddShape(_diagram.AddShape(process, point));
                _graph.Selection.Clear();
                _graph.Selection.Add(node);
            }
        }
Example #7
0
        private void GraphOnCreateDataStore(PointF point, GraphGroup graphGroup)
        {
            var dataStore = _diagram.Model?.AddEntity <IDataStore>();

            if (dataStore != null)
            {
                if (graphGroup?.GroupShape?.Identity is IGroup group)
                {
                    dataStore.SetParent(group);
                }
                var node = AddShape(_diagram.AddShape(dataStore, point));
                _graph.Selection.Clear();
                _graph.Selection.Add(node);
            }
        }
Example #8
0
        public void DoLayout([NotNull] GraphGroup group, int spacingHorizontal, int spacingVertical)
        {
            var layout = new GoLayoutLayeredDigraph()
            {
                Document        = Doc,
                DirectionOption = GoLayoutDirection.Right,
                LayerSpacing    = spacingHorizontal,
                ColumnSpacing   = spacingVertical,
                Iterations      = 5,
                Network         = new GoLayoutLayeredDigraphNetwork(),
            };

            layout.Network.AddNodesAndLinksFromCollection(group, true);
            layout.PerformLayout();
        }
Example #9
0
        private GraphGroup GetPrimaryGroup()
        {
            GraphGroup result = Selection.Primary as GraphGroup;

            if (result == null)
            {
                foreach (var item in Selection)
                {
                    if (item is GraphGroup group)
                    {
                        result = group;
                        break;
                    }
                }
            }

            return(result);
        }
Example #10
0
        private GraphGroup GetParentGroup(PointF point)
        {
            GraphGroup result = null;

            var nodes = Document.PickObjects(point, false, null, 100);

            if (nodes?.Any() ?? false)
            {
                foreach (var node in nodes)
                {
                    if (node is GoRoundedRectangle rectangle &&
                        rectangle.Parent is GraphGroup group)
                    {
                        result = group;
                        break;
                    }
                }
            }

            return(result);
        }
Example #11
0
        private GoNode AddShape([NotNull] IShape shape)
        {
            GoNode result = null;

            GraphGroup parent = null;

            if (shape.Identity is IGroupElement child)
            {
                _groups.TryGetValue(child.ParentId, out parent);
            }

            if (shape is IEntityShape entityShape)
            {
                var node = new GraphEntity(entityShape, _dpiState);
                if (_actions != null)
                {
                    node.SetContextAwareActions(_actions);
                }
                node.SelectedShape       += OnSelectedShape;
                node.SelectedThreatEvent += OnSelectedThreatEvent;
                node.OpenDiagram         += OnOpenDiagram;
                if (parent == null)
                {
                    _graph.Doc.Add(node);
                }
                else
                {
                    parent.Add(node);
                }
                _entities.Add(shape.AssociatedId, node);

                node.Validate();

                result = node;
            }
            else if (shape is IGroupShape groupShape)
            {
                var group = new GraphGroup(groupShape, _dpiState);
                if (_actions != null)
                {
                    group.SetContextAwareActions(_actions);
                }
                group.SelectedShape += OnSelectedShape;
                if (parent == null)
                {
                    _graph.Doc.Add(group);
                }
                else
                {
                    parent.Add(group);
                }
                _groups.Add(shape.AssociatedId, group);

                group.Validate();

                result = group;
            }

            if (shape.Identity is IThreatEventsContainer container)
            {
                container.ThreatEventAdded   += OnThreatEventAddedToShape;
                container.ThreatEventRemoved += OnThreatEventRemovedFromShape;
            }

            return(result);
        }
Example #12
0
 private void Validate(GraphGroup graphGroup)
 {
     graphGroup?.Validate();
 }