コード例 #1
0
ファイル: ClassDiagramParser.cs プロジェクト: Geaz/sharpDox
 private void ParseFields(ClassDiagram classDiagram, IEnumerable<SDField> fields)
 {
     foreach (var field in fields.OrderBy(o => o.Name))
     {
         classDiagram.FieldRows.Add(new ClassDiagramRow(field.Identifier, "Field", field.Accessibility, field.Name));
     }
 }
コード例 #2
0
ファイル: ClassDiagramParser.cs プロジェクト: Geaz/sharpDox
 private void ParseMethods(ClassDiagram classDiagram, IEnumerable<SDMethod> methods)
 {
     foreach (var method in methods.OrderBy(o => o.Name))
     {
         classDiagram.MethodRows.Add(new ClassDiagramRow(method.Identifier, "Method", method.Accessibility, method.Name));
     }
 }
コード例 #3
0
ファイル: ClassDiagramParser.cs プロジェクト: Geaz/sharpDox
 private void ParseConstructors(ClassDiagram classDiagram, IEnumerable<SDMethod> constructors)
 {
     foreach (var constructor in constructors.OrderBy(o => o.Name))
     {
         classDiagram.ConstructorRows.Add(new ClassDiagramRow(constructor.Identifier, "Method", constructor.Accessibility, constructor.Name));
     }
 }
コード例 #4
0
ファイル: ClassDiagramParser.cs プロジェクト: Geaz/sharpDox
 private void ParseEvents(ClassDiagram classDiagram, IEnumerable<SDEvent> events)
 {
     foreach (var ev in events.OrderBy(o => o.Name))
     {
         classDiagram.EventRows.Add(new ClassDiagramRow(ev.Identifier, "Event", ev.Accessibility, ev.Name));
     }
 }
コード例 #5
0
        private double CalculateDiagramWidth(ClassDiagram classDiagram)
        {
            var allRows = GetAllRows(classDiagram);
            var headerWidth = (int)Math.Max(classDiagram.Name.GetWidth(14, Fonts.FontLight), classDiagram.Accessibility.GetWidth(11, Fonts.FontItalic));
            var maxWidthRows = allRows.Count > 0 ? allRows.Max(o => (int)o.Text.GetWidth(14, Fonts.FontLight)) : 0;

            return Math.Max(headerWidth, maxWidthRows) + 65;
        }
コード例 #6
0
 private List<ClassDiagramRow> GetAllRows(ClassDiagram classDiagram)
 {
     var allRows = new List<ClassDiagramRow>();
     allRows.AddRange(classDiagram.FieldRows);
     allRows.AddRange(classDiagram.PropertyRows);
     allRows.AddRange(classDiagram.MethodRows);
     allRows.AddRange(classDiagram.EventRows);
     return allRows;
 }
コード例 #7
0
        private void RenderAllRowSections(ClassDiagram classDiagram, int position)
        {
            var renderLine = FollowingSectionsNotEmpty(classDiagram, "Fields");
            position = RenderRowSection(classDiagram.FieldRows, position, _diagramSize, renderLine);

            renderLine = FollowingSectionsNotEmpty(classDiagram, "Properties");
            position = RenderRowSection(classDiagram.PropertyRows, position, _diagramSize, renderLine);

            renderLine = FollowingSectionsNotEmpty(classDiagram, "Methods");
            position = RenderRowSection(classDiagram.MethodRows, position, _diagramSize, renderLine);

            RenderRowSection(classDiagram.EventRows, position, _diagramSize, false);
        }
コード例 #8
0
        private int RenderHeader(ClassDiagram classDiagram, int position)
        {
            var formattedAccessibility = new FormattedText(classDiagram.Accessibility, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, Fonts.FontItalic, 10, Brushes.Black);
            _context.DrawText(formattedAccessibility, new Point((_diagramSize.Width - classDiagram.Accessibility.GetWidth(10, Fonts.FontItalic)) / 2, position));

            var formattedName = new FormattedText(classDiagram.Name, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, Fonts.FontLight, 12, Brushes.Black);
            _context.DrawText(formattedName, new Point((_diagramSize.Width - classDiagram.Name.GetWidth(12, Fonts.FontLight)) / 2, position += 15));
            position += 20;

            _context.DrawLine(new Pen(Brushes.Black, 1), new Point(1, position), new Point(_diagramSize.Width - 1, position));
            position += 10;
            return position;
        }
コード例 #9
0
        private Size CalculateDiagramSize(ClassDiagram classDiagram)
        {
            var allRows = GetAllRows(classDiagram);
            var headerWidth = (int)Math.Max(classDiagram.Name.GetWidth(12, Fonts.FontLight), classDiagram.Accessibility.GetWidth(10, Fonts.FontItalic));
            var maxWidthRows = allRows.Count > 0 ? allRows.Max(o => (int)o.Text.GetWidth(12, Fonts.FontLight)) : 0;
            var horizontalLineCount = CountSections(classDiagram);

            var size = new Size();
            size.Width = Math.Max(headerWidth, maxWidthRows) + 65;
            size.Height = (3 * 20) + (10 * (horizontalLineCount > 0 ? horizontalLineCount - 1 : 0)) + allRows.Count * 20;

            return size;
        }
コード例 #10
0
        public DrawingVisual RenderDiagram(ClassDiagram classDiagram)
        {
            _diagramSize = CalculateDiagramSize(classDiagram);

            var canvas = new DrawingVisual();
            _context = canvas.RenderOpen();

            int position = OFFSET;
            position = RenderHeader(classDiagram, position);
            RenderAllRowSections(classDiagram, position);
            RenderDiagramFrame(classDiagram);

            return canvas;
        }
コード例 #11
0
        public SvgRoot RenderConnectedDiagram(ClassDiagram classDiagram)
        {
            _classDiagram = classDiagram;
            _mainDiagram = _classDiagramSvgRenderer.RenderDiagram(_classDiagram);

            CalculateMainMarginsAndSize();
            PositionMainDiagram();
            DrawBaseTypes();
            DrawImplementedInterfaces();
            DrawUsedBy();
            DrawUses();

            return _mainDiagram;
        }
コード例 #12
0
        public ClassDiagram CreateClassDiagram(SDType type)
        {
            var attribute = type.IsAbstract && type.Kind.ToLower() != "interface" ? "abstract" : string.Empty;
            attribute = type.IsStatic ? "static" : attribute;

            _classDiagram = new ClassDiagram(type.Identifier, type.Name, type.Kind, type.Accessibility, attribute);

            ParseFields(type.Fields);
            ParseProperties(type.Properties);
            ParseMethods(type.Methods);
            ParseEvents(type.Events);

            return _classDiagram;
        }
コード例 #13
0
        public double CalculateDiagramHeight(ClassDiagram classDiagram)
        {
            var allRows = GetAllRows(classDiagram);
            var notEmptySections = 
                (classDiagram.FieldRows.Count != 0 ? 1 : 0) +
                (classDiagram.PropertyRows.Count != 0 ? 1 : 0) +
                (classDiagram.MethodRows.Count != 0 || classDiagram.ConstructorRows.Count != 0 ? 1 : 0) +
                (classDiagram.EventRows.Count != 0 ? 1 : 0);

            var allRowsHeight = allRows.Count * 25 + (notEmptySections > 0 ? (notEmptySections - 1) * 10 : 0);                

            //Das Firstrowoffset gibt den y wert der unterkante der ersten row an
            //damit der wert korrekt ist muss eine row (ohne margin) von der berechnung abgezogen werden
            return (FIRSTROW_OFFSET_Y - 15) + allRowsHeight;
        }
コード例 #14
0
        public SvgRoot RenderDiagram(ClassDiagram classDiagram)
        {
            _classDiagram = classDiagram;
            _diagramSize = new Size(CalculateDiagramWidth(classDiagram), CalculateDiagramHeight(classDiagram));

            _svgRoot = new SvgRoot() { Width = _diagramSize.Width, Height = _diagramSize.Height };
            _svgGraphic = new SvgGraphic(_svgRoot);
            _svgRoot.Add(_svgGraphic);

            RenderFrame();
            RenderHeader();
            RenderAllRowSections();

            return _svgRoot;
        }
コード例 #15
0
ファイル: ClassDiagramParser.cs プロジェクト: Geaz/sharpDox
        private void ParseProperties(ClassDiagram classDiagram, IEnumerable<SDProperty> properties)
        {
            foreach (var property in properties.OrderBy(o => o.Name))
            {
                var getSet = "";
                if (property.CanGet && property.CanSet)
                    getSet = " { get; set; }";
                else if (property.CanGet)
                    getSet = " { get; }";
                else if (property.CanSet)
                    getSet = " { set; }";

                classDiagram.PropertyRows.Add(new ClassDiagramRow(property.Identifier, "Properties", property.Accessibility, property.Name + getSet));
            }
        }
コード例 #16
0
        private double RenderAllRowSections(ClassDiagram classDiagram, double position)
        {
            var renderLine = FollowingSectionsNotEmpty(classDiagram, "Fields");
            position = RenderRowSection(classDiagram.FieldRows, "field", position, renderLine);

            renderLine = FollowingSectionsNotEmpty(classDiagram, "Properties");
            position = RenderRowSection(classDiagram.PropertyRows, "property", position, renderLine);

            renderLine = FollowingSectionsNotEmpty(classDiagram, "Methods");
            position = RenderRowSection(classDiagram.MethodRows, "method", position, renderLine);

            position = RenderRowSection(classDiagram.EventRows, "event", position, false);

            return position;
        }
コード例 #17
0
        public SvgRoot RenderDiagram(ClassDiagram classDiagram)
        {
            _diagramWidth = CalculateDiagramWidth(classDiagram);
            _svgRoot = new SvgRoot(100, _diagramWidth);

            var rect = new SvgRectangle(_svgRoot, 0.5, 0.5, _diagramWidth - 1, 100);
            rect.StrokeWidth = 1;
            rect.Stroke = "#979797";
            rect.Fill = "#FFFFFF";
            _svgRoot.AppendChild(rect.XmlElement);

            double position = 20.5d;
            position = RenderHeader(classDiagram, position);
            position = RenderAllRowSections(classDiagram, position);

            rect.Height = position - 9.5;
            _svgRoot.Height = position - 5;            
            return _svgRoot;
        }
コード例 #18
0
        private double RenderHeader(ClassDiagram classDiagram, double position)
        {
            var accessibility = new SvgText(_svgRoot, classDiagram.Accessibility, (_diagramWidth - classDiagram.Accessibility.GetWidth(11, Fonts.FontItalic)) / 2, position);
            accessibility.FontSize = 11;

            var name = new SvgLink(_svgRoot, classDiagram.Name, string.Format("{{{{type-link:{0}}}}}", classDiagram.TypeIdentifier), (_diagramWidth - classDiagram.Name.GetWidth(14, Fonts.FontLight)) / 2, position += 20);
            name.Text.FontSize = 14;

            position += 15;

            var path = new SvgPath(_svgRoot, string.Format("M0.5,{0}L{1},{0}", position.ToString("0.00", CultureInfo.InvariantCulture), _diagramWidth.ToString("0.00", CultureInfo.InvariantCulture)));
            path.StrokeWidth = 1;
            path.Stroke = "#979797";

            _svgRoot.AppendChild(accessibility.XmlElement);
            _svgRoot.AppendChild(name.XmlElement);
            _svgRoot.AppendChild(path.XmlElement);

            return position + 25;
        }
コード例 #19
0
ファイル: ClassDiagramParser.cs プロジェクト: Geaz/sharpDox
        public ClassDiagram CreateClassDiagram(SDType type, bool parseConnectedDiagrams = true)
        {
            var classDiagram = new ClassDiagram(type);
            classDiagram.IsProjectStranger = type.IsProjectStranger;

            if (parseConnectedDiagrams)
            {
                ParseTypes(classDiagram.BaseTypes, type.BaseTypes.Select(t => t.Type));
                ParseTypes(classDiagram.ImplementedInterfaces, type.ImplementedInterfaces.Select(t => t.Type));
                ParseTypes(classDiagram.Uses, type.Uses);
                ParseTypes(classDiagram.UsedBy, type.UsedBy);
            }

            ParseFields(classDiagram, type.Fields);
            ParseProperties(classDiagram, type.Properties);
            ParseConstructors(classDiagram, type.Constructors);
            ParseMethods(classDiagram, type.Methods);
            ParseEvents(classDiagram, type.Events);

            return classDiagram;
        }
コード例 #20
0
 private void RenderDiagramFrame(ClassDiagram classDiagram)
 {
     _context.DrawRectangle(Brushes.Transparent, new Pen(Brushes.Black, 1), new Rect(1, 1, _diagramSize.Width - 2, _diagramSize.Height - 2));
     _context.Close();
 }
コード例 #21
0
 private int CountSections(ClassDiagram classDiagram)
 {
     return (classDiagram.FieldRows.Count > 0 ? 1 : 0) + (classDiagram.PropertyRows.Count > 0 ? 1 : 0) +
            (classDiagram.MethodRows.Count > 0 ? 1 : 0) + (classDiagram.EventRows.Count > 0 ? 1 : 0);
 }
コード例 #22
0
        private bool FollowingSectionsNotEmpty(ClassDiagram classDiagram, string section)
        {
            var empty = true;

            switch (section)
            {
                case "Fields":
                    empty = classDiagram.PropertyRows.Count + classDiagram.MethodRows.Count +
                            classDiagram.EventRows.Count > 0;
                    break;
                case "Properties":
                    empty = classDiagram.MethodRows.Count + classDiagram.EventRows.Count > 0;
                    break;
                case "Methods":
                    empty = classDiagram.EventRows.Count > 0;
                    break;
            }

            return empty;
        }