Пример #1
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);
        }
Пример #2
0
 private void Validate(GraphEntity graphEntity)
 {
     graphEntity?.Validate();
 }