<commit_before>﻿using Blueprint41.Modeller.Schemas;
using Blueprint41.Modeller.Controls;
using Microsoft.Msagl;
using Microsoft.Msagl.Core.Geometry.Curves;
using Microsoft.Msagl.Core.Layout;
using Microsoft.Msagl.Core.Routing;
using Microsoft.Msagl.Drawing;
using Microsoft.Msagl.GraphViewerGdi;
using Microsoft.Msagl.Layout.Layered;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using DrawingNode = Microsoft.Msagl.Drawing.Node;
using System.Diagnostics;

namespace Blueprint41.Modeller.Schemas
{
    public partial class Modeller
    {
        public bool HasChanges { get; internal set; }

        public LayoutMethod ViewMode
        {
            get { return GraphEditor.Viewer.CurrentLayoutMethod; }
            set { GraphEditor.Viewer.CurrentLayoutMethod = value; }
        }

        private GraphEditor m_GraphEditor = null;
        public GraphEditor GraphEditor
        {
            get
            {
                return m_GraphEditor;
            }
            set
            {
                UnRegisterEvents();

                m_GraphEditor = value;

                if (m_GraphEditor != null)
                {
                    RebindControl();
                    RegisterEvents();
                }
            }
        }

        public delegate void BeforeReBindControl();
        public delegate void AfterReBindControl();

        public BeforeReBindControl BeforeReBind { get; set; }
        public AfterReBindControl AfterReBind { get; set; }

        /// <summary>
        /// A new graph, it will be null after assigning to the viewer
        /// </summary>
        internal Graph Graph { get; private set; }

        /// <summary>
        /// Graph's Geometry graph, it will be null after assigning to the viewer
        /// </summary>
        internal GeometryGraph GeometryGraph { get; private set; }

        private void MouseUp(object sender, MsaglMouseEventArgs e)
        {
            AutoResize();
        }

        private void NodeMouseUp(object sender, NodeEventArgs e)
        {
            Submodel.NodeLocalType entity = e?.Node?.UserData as Submodel.NodeLocalType;
            if (entity != null)
                entity.CaptureCoordinates();
        }

        private void RedoLayout(object sender, EventArgs e)
        {
            if (Model.GraphEditor.Viewer.Graph == null)
                return;

            if (ViewMode == LayoutMethod.UseSettingsOfTheGraph)
            {
                RebindControl();
                return;
            }

            GraphEditor.Viewer.CurrentLayoutMethod = ViewMode;
            GraphEditor.Viewer.NeedToCalculateLayout = true;
            GraphEditor.Viewer.Graph = Model.GraphEditor.Viewer.Graph;
            GraphEditor.Viewer.NeedToCalculateLayout = false;
            GraphEditor.Viewer.Graph = Model.GraphEditor.Viewer.Graph;
        }

        internal void UnRegisterEvents()
        {
            if (m_GraphEditor != null)
            {
                GraphEditor.RedoLayout -= RedoLayout;
                ((IViewer)m_GraphEditor.Viewer).MouseUp -= MouseUp;
                m_GraphEditor.NodeSelected -= NodeMouseUp;
            }
        }

        internal void RegisterEvents()
        {
            if (m_GraphEditor != null)
            {
                ((IViewer)m_GraphEditor.Viewer).MouseUp += MouseUp;
                m_GraphEditor.NodeSelected += NodeMouseUp;
                m_GraphEditor.RedoLayout += RedoLayout;
            }
        }

        public bool ShowRelationshipLabels
        {
            get { return m_ShowRelationshipLabels; }
            set
            {
                m_ShowRelationshipLabels = value;
                RebindControl();
            }
        }
        private bool m_ShowRelationshipLabels = true;

        private Submodel m_DisplayedSubmodel = null;
        public Submodel DisplayedSubmodel
        {
            get
            {
                return m_DisplayedSubmodel;
            }
            set
            {
                if (m_DisplayedSubmodel == value)
                    return;

                m_DisplayedSubmodel = value;
                RebindControl();
            }
        }

        private bool m_ShowInheritedRelationships = false;

        public bool ShowInheritedRelationships
        {
            get { return m_ShowInheritedRelationships; }
            set
            {
                m_ShowInheritedRelationships = value;
                RebindControl();
            }
        }

        public Submodel MainSubmodel { get; set; }

        internal void RebindControl()
        {
            if (GraphEditor == null || DisplayedSubmodel == null)
                return;

            BeforeReBind.Invoke();

            GraphEditor.Graph = null;

            Graph = new Graph("graph");
            GeometryGraph = new Microsoft.Msagl.Core.Layout.GeometryGraph();

            foreach (var node in DisplayedSubmodel.Node)
            {<commit_msg>add graph margin box<commit_after>﻿using Blueprint41.Modeller.Schemas;
using Blueprint41.Modeller.Controls;
using Microsoft.Msagl;
using Microsoft.Msagl.Core.Geometry.Curves;
using Microsoft.Msagl.Core.Layout;
using Microsoft.Msagl.Core.Routing;
using Microsoft.Msagl.Drawing;
using Microsoft.Msagl.GraphViewerGdi;
using Microsoft.Msagl.Layout.Layered;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using DrawingNode = Microsoft.Msagl.Drawing.Node;
using System.Diagnostics;

namespace Blueprint41.Modeller.Schemas
{
    public partial class Modeller
    {
        public bool HasChanges { get; internal set; }

        public LayoutMethod ViewMode
        {
            get { return GraphEditor.Viewer.CurrentLayoutMethod; }
            set { GraphEditor.Viewer.CurrentLayoutMethod = value; }
        }

        private GraphEditor m_GraphEditor = null;
        public GraphEditor GraphEditor
        {
            get
            {
                return m_GraphEditor;
            }
            set
            {
                UnRegisterEvents();

                m_GraphEditor = value;

                if (m_GraphEditor != null)
                {
                    RebindControl();
                    RegisterEvents();
                }
            }
        }

        public delegate void BeforeReBindControl();
        public delegate void AfterReBindControl();

        public BeforeReBindControl BeforeReBind { get; set; }
        public AfterReBindControl AfterReBind { get; set; }

        /// <summary>
        /// A new graph, it will be null after assigning to the viewer
        /// </summary>
        internal Graph Graph { get; private set; }

        /// <summary>
        /// Graph's Geometry graph, it will be null after assigning to the viewer
        /// </summary>
        internal GeometryGraph GeometryGraph { get; private set; }

        private void MouseUp(object sender, MsaglMouseEventArgs e)
        {
            AutoResize();
        }

        private void NodeMouseUp(object sender, NodeEventArgs e)
        {
            Submodel.NodeLocalType entity = e?.Node?.UserData as Submodel.NodeLocalType;
            if (entity != null)
                entity.CaptureCoordinates();
        }

        private void RedoLayout(object sender, EventArgs e)
        {
            if (Model.GraphEditor.Viewer.Graph == null)
                return;

            if (ViewMode == LayoutMethod.UseSettingsOfTheGraph)
            {
                RebindControl();
                return;
            }

            GraphEditor.Viewer.CurrentLayoutMethod = ViewMode;
            GraphEditor.Viewer.NeedToCalculateLayout = true;
            GraphEditor.Viewer.Graph = Model.GraphEditor.Viewer.Graph;
            GraphEditor.Viewer.NeedToCalculateLayout = false;
            GraphEditor.Viewer.Graph = Model.GraphEditor.Viewer.Graph;
        }

        internal void UnRegisterEvents()
        {
            if (m_GraphEditor != null)
            {
                GraphEditor.RedoLayout -= RedoLayout;
                ((IViewer)m_GraphEditor.Viewer).MouseUp -= MouseUp;
                m_GraphEditor.NodeSelected -= NodeMouseUp;
            }
        }

        internal void RegisterEvents()
        {
            if (m_GraphEditor != null)
            {
                ((IViewer)m_GraphEditor.Viewer).MouseUp += MouseUp;
                m_GraphEditor.NodeSelected += NodeMouseUp;
                m_GraphEditor.RedoLayout += RedoLayout;
            }
        }

        public bool ShowRelationshipLabels
        {
            get { return m_ShowRelationshipLabels; }
            set
            {
                m_ShowRelationshipLabels = value;
                RebindControl();
            }
        }
        private bool m_ShowRelationshipLabels = true;

        private Submodel m_DisplayedSubmodel = null;
        public Submodel DisplayedSubmodel
        {
            get
            {
                return m_DisplayedSubmodel;
            }
            set
            {
                if (m_DisplayedSubmodel == value)
                    return;

                m_DisplayedSubmodel = value;
                RebindControl();
            }
        }

        private bool m_ShowInheritedRelationships = false;

        public bool ShowInheritedRelationships
        {
            get { return m_ShowInheritedRelationships; }
            set
            {
                m_ShowInheritedRelationships = value;
                RebindControl();
            }
        }

        public Submodel MainSubmodel { get; set; }

        internal void RebindControl()
        {
            if (GraphEditor == null || DisplayedSubmodel == null)
                return;

            BeforeReBind.Invoke();

            GraphEditor.Graph = null;

            Graph = new Graph("graph");
            GeometryGraph = new Microsoft.Msagl.Core.Layout.GeometryGraph();
            GeometryGraph.Margins = 4;

            foreach (var node in DisplayedSubmodel.Node)
            {
{'fraction_non_alphanumeric': 0.07453234606391271, 'fraction_numerical': 0.0012665627435697584, 'mean_word_length': 1.6186224489795917, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3860980', 'n_tokens_mistral': 2655, 'n_tokens_neox': 2517, 'n_words': 569}