Esempio n. 1
0
 public static Node BuildTree(this string text)
 {
     text = Regex.Replace(text, @"\s", "");
     var root = new Node("Tree");
     root.SetChildren(_BuildTree(text));
     return root;
 }
Esempio n. 2
0
 public static Node ReverseChildren(Node tree)
 {
     tree.SetChildren(tree.Orientation == OrientationKind.Horizontal
         ? tree.Childs.Select(ReverseChildren) // Horizontal layers are ordered alphabetically
         : tree.Childs.Select(ReverseChildren).Reverse());
     return tree;
 }
Esempio n. 3
0
        public static Node FindSiblingDependencies(Node node)
        {
            node.SetChildren(node.Childs.Select(FindSiblingDependencies).ToList());
            if (node.Parent == null) return node;
            var allSubDependencies = node.AllSubDependencies().ToList();
            var dependenciesWhereAncestorsAreSiblings = allSubDependencies
                .Select(dependency => AncestorIsSibling(node.Parent, dependency)).ToList();
            foreach (
                var sibling in
                    dependenciesWhereAncestorsAreSiblings
                        .Where(sibling => sibling != null && sibling != node))
            {
                node.SiblingDependencies.Add(sibling);
            }

            return node;
        }
Esempio n. 4
0
        public void CmdModel1()
        {
            var nodesList = OrderingTestFactory.CreateNodeList(
            @"
            ToolsMenuPackage -> CmdFac, GenImCmd
            CmdFac -> CommandBase
            CommandBase ->
            GenImCmd -> CommandBase, DevArch
            ViewDiaCmd -> CommandBase, DevArch
            MainWindow -> DevArch
            DevArch ->
            ");

            var newList = SiblingReorderer.LayOutSiblingNodes(nodesList);

            var tree = new Node("tree");
            tree.SetChildren(newList);

            DiagramGenerator.ReverseChildren(tree);
            BitmapRenderer.RenderTreeToBitmap(tree, true, new OutputSettings (TestExtesions.SlnDir + "ArchTest.png" ), false);
            Assert.IsFalse(tree.Childs.Last().Childs.Any(x => x.Name == "CommandBase"));
        }
Esempio n. 5
0
 /*
 public static void RemoveSingleChildAnonymous(Node tree)
 {
     foreach (var oldChild in tree.Childs.ToList())
     {
         RemoveSingleChildAnonymous(oldChild);
         if (oldChild is SiblingHolderNode)
         {
             if(!oldChild.Childs.Any())
                 tree.RemoveChild(oldChild);
             if(oldChild.Childs.Count == 1)
             {
                 var newChild = oldChild.Childs?.First();
                 tree.ReplaceChild(oldChild, newChild);
             }
         }
     }
 }*/
 private static Node FindSiblingPatterns(Node tree)
 {
     if (!tree.Childs.Any())
         return tree;
     if(!tree.Childs.Any(x => x.HasChildren())) {
         var baseClassPattern = PatternFinder.FindBaseClassPattern(tree.Childs);
         if (baseClassPattern != null)
         {
             tree.SetChildren(new List<Node>());
             tree.AddChild(new Node(baseClassPattern + "s"));
         }
         else
         {
             var namingPatterns = PatternFinder.FindNamingPatterns(tree.Childs.Select(x => x.Name)).ToList();
             if (namingPatterns.Any())
             {
                 foreach (var pattern in namingPatterns.ToList())
                 {
                     var followspattern = tree.Childs.Where(x => PatternFinder.FollowsPattern(x.Name,pattern)).ToList();
                     foreach (var node in followspattern)
                     {
                         tree.RemoveChild(node);
                     }
                     tree.AddChild(new Node(pattern + "s"));
                 }
             }
         }
     }
     tree.SetChildren(tree.Childs.Select(FindSiblingPatterns));
     return tree;
 }
Esempio n. 6
0
 private static new void Apply(Node tree)
 {
     tree.SetChildren(FindClasses(tree));
 }
 private static void TakeOver(Node parentNode, Node childNode)
 {
     parentNode.Orientation = childNode.Orientation;
     parentNode.SetChildren(childNode.Childs);
 }
Esempio n. 8
0
        public void MultipleHorizontalLayers()
        {
            var nodesList = OrderingTestFactory.CreateNodeList(
                @"ColorDataWithDepth ->
                LayerViewModel ->
                RootScope ->
                ArchView ->
                Hsl -> ColorDataWithDepth
                ColorRange -> ColorDataWithDepth
                HueRangeDivisor -> ColorRange
                BitmapRenderer -> LayerMapper
                LayerMapper -> HueRangeDivisor, LayerViewModel
                DevArch -> BitmapRenderer, ArchView, LayerMapper"
                );

            var newChildOrder = SiblingReorderer.LayOutSiblingNodes(nodesList);

            var assertLayout =
                @"
                [
                     [
                        DevArch,
                        [ArchView,BitmapRenderer]
                        LayerMapper
                        [
                            LayerViewModel,
                            [HueRangeDivisor, ColorRange]
                        ]
                    ]
                    Hsl
                ]
                ColorDataWithDepth
            ".BuildTree();

            var tree = new Node("tree");
            tree.SetChildren(newChildOrder);
            DiagramGenerator.ReverseChildren(tree);
            TestExtesions.TreeAssert.DoesNotContainDuplicates(tree);
            OrderingTestFactory.AssertLayout(assertLayout,tree);
        }
Esempio n. 9
0
        private static IEnumerable<Node> _BuildTree(this string text)
        {
            var nestedChildStart = 0;
            var depth = 0;
            var currentChildStartIndex = 0;
            var childEntries = new List<string>();
            for (var i = 0; i < text.Length; i++)
            {
                var c = text[i];
                if (c == '[')
                {
                    if (depth == 0)
                        nestedChildStart = i;
                    depth++;
                }
                if (c == ']')
                {
                    depth--;
                    if (depth == 0)
                    {
                        childEntries.Add(text.SubStrBetween(nestedChildStart, i + 1));
                        currentChildStartIndex = i + 1;
                    }
                }
                else if (c == ',' && depth == 0)
                {
                    childEntries.Add(text.SubStrBetween(currentChildStartIndex, i));
                    currentChildStartIndex = i + 1;
                }
            }
            if(currentChildStartIndex != text.Length)
                childEntries.Add(text.SubStrBetween(currentChildStartIndex, text.Length));

            foreach (var entry in childEntries)
            {
                if (entry.StartsWith("[") && entry.EndsWith("]"))
                {
                    var node = new Node("");
                    node.SetChildren(_BuildTree(entry.SubStrBetween(1, entry.Length - 1)));
                    yield return node;
                }
                else
                {
                    yield return new Node(entry);
                }
            }
        }
Esempio n. 10
0
        public void SoftwareEngineeringModel()
        {
            var nodesList = OrderingTestFactory.CreateNodeList(
                @"
                UiDb ->
                Prog ->
                SWProc ->
                ProjectProg ->
                TAD -> Prog
                LAD -> Prog
                QM -> UiDb, Prog, ProjectProg, SWProc
                ProjectSys -> ProjectProg
                SwArch -> TAD
                Erlang -> ProjectProg
                PPPM ->
                ProjectDist -> ProjectProg
                TAV -> Prog, Erlang
                Embsys -> Erlang, Prog, LAD
                SPI -> SWProc
                ProjectIndus -> ProjectSys
                CM ->
                MDSD -> Embsys, Erlang, LAD, ProjectSys
                ProjectChange -> UiDb, Prog, ProjectProg, SWProc
                IndustBestPractice -> ProjectSys, ProjectDist, ProjectProg, ProjectIndus
                ResearchMethods ->
                Thesis -> ResearchMethods, ProjectSys, ProjectDist, ProjectProg, ProjectIndus");

            var tree = new Node("tree");
            tree.SetChildren(nodesList);
            tree.RelayoutBasedOnDependencies();
            DiagramGenerator.ReverseChildren(tree);
            BitmapRenderer.RenderTreeToBitmap(tree, true, new OutputSettings (TestExtesions.SlnDir + "SEM.png"),false);
        }