예제 #1
0
 public void TestLinerNodeDependency()
 {
     // [0]--->[1]
     Nodes._0.SetRequireNodes(new[] { Profiles._1 });
     NodeProcessor.SetBeRequiredNodes(new[] { Nodes._0, Nodes._1 });
     Assert.That(Nodes._1.Sources.Any(x => x.Equals(Profiles._0)));
 }
 public void SetUpBeforeEveryTest()
 {
     Nodes.Init();
     // [0]--->[1]--->[2]<---[3]    [4]
     Nodes._0.SetRequireNodes(new[] { Profiles._1 });
     Nodes._1.SetRequireNodes(new[] { Profiles._2 });
     Nodes._3.SetRequireNodes(new[] { Profiles._2 });
     NodeProcessor.SetBeRequiredNodes(new[] { Nodes._0, Nodes._1, Nodes._2, Nodes._3, Nodes._4 });
 }
예제 #3
0
 public void TestSomeNodeDependency()
 {
     Nodes.SetSomeNodeDependency();
     NodeProcessor.SetBeRequiredNodes(Nodes.All);
     // 0
     Assert.That(Nodes._0.Sources, Is.Empty);
     Assert.That(Nodes._0.Destinations.Count, Is.EqualTo(2));
     Assert.That(Nodes._0.Destinations.Any(x => x == Profiles._1));
     Assert.That(Nodes._0.Destinations.Any(x => x == Profiles._2));
     // 1
     Assert.That(Nodes._1.Destinations.Count, Is.EqualTo(1));
     Assert.That(Nodes._1.Sources.Any(x => x == Profiles._0));
     Assert.That(Nodes._1.Destinations.Count, Is.EqualTo(1));
     Assert.That(Nodes._1.Destinations.Any(x => x == Profiles._4));
     // 2
     Assert.That(Nodes._2.Sources.Count, Is.EqualTo(1));
     Assert.That(Nodes._2.Sources.Any(x => x == Profiles._0));
     Assert.That(Nodes._2.Destinations.Count, Is.EqualTo(2));
     Assert.That(Nodes._2.Destinations.Any(x => x == Profiles._3));
     Assert.That(Nodes._2.Destinations.Any(x => x == Profiles._4));
     // 3
     Assert.That(Nodes._3.Sources.Count, Is.EqualTo(2));
     Assert.That(Nodes._3.Sources.Any(x => x == Profiles._2));
     Assert.That(Nodes._3.Sources.Any(x => x == Profiles._5));
     Assert.That(Nodes._3.Destinations, Is.Empty);
     // 4
     Assert.That(Nodes._4.Sources.Count, Is.EqualTo(2));
     Assert.That(Nodes._4.Sources.Any(x => x == Profiles._1));
     Assert.That(Nodes._4.Sources.Any(x => x == Profiles._2));
     Assert.That(Nodes._4.Destinations.Count, Is.EqualTo(1));
     Assert.That(Nodes._4.Destinations.Any(x => x == Profiles._5));
     // 5
     Assert.That(Nodes._5.Sources.Count, Is.EqualTo(1));
     Assert.That(Nodes._5.Sources.Any(x => x == Profiles._4));
     Assert.That(Nodes._5.Destinations.Count, Is.EqualTo(2));
     Assert.That(Nodes._5.Destinations.Any(x => x == Profiles._3));
     Assert.That(Nodes._5.Destinations.Any(x => x == Profiles._6));
     // 6
     Assert.That(Nodes._6.Sources.Count, Is.EqualTo(1));
     Assert.That(Nodes._6.Sources.Any(x => x == Profiles._5));
     Assert.That(Nodes._6.Destinations, Is.Empty);
     // 7
     Assert.That(Nodes._7.Sources, Is.Empty);
     Assert.That(Nodes._7.Destinations.Count, Is.EqualTo(1));
     Assert.That(Nodes._7.Destinations.Any(x => x == Profiles._8));
     // 8
     Assert.That(Nodes._8.Sources.Count, Is.EqualTo(1));
     Assert.That(Nodes._8.Sources.Any(x => x == Profiles._7));
     Assert.That(Nodes._8.Destinations, Is.Empty);
     // 9
     Assert.That(Nodes._9.Sources, Is.Empty);
     Assert.That(Nodes._9.Destinations, Is.Empty);
 }
예제 #4
0
        public void TestLinerNodeDependency()
        {
            var nodes = new[] { Nodes._0, Nodes._1 };

            // [0]--->[1]
            Nodes._0.SetRequireNodes(new[] { Profiles._1 });
            NodeProcessor.SetBeRequiredNodes(nodes);

            var result = sortStrategy.Sort(nodes).ToArray();
            var node0  = result.FirstOrDefault(x => x.Profile == Profiles._0);
            var node1  = result.FirstOrDefault(x => x.Profile == Profiles._1);

            Assert.That(node0, Is.Not.Null);
            Assert.That(node0.Position.x, Is.Zero);
            Assert.That(node0.Position.y, Is.Zero);
            Assert.That(node1, Is.Not.Null);
            Assert.That(node1.Position.x, Is.EqualTo(node0.Position.x + d + (w / 2.0F)).Within(e));
            Assert.That(node1.Position.y, Is.EqualTo(node0.Position.y).Within(e));
        }
예제 #5
0
        public AsmdefGraphView(IEnumerable <Assembly> assemblies)
        {
            var assemblyArr = assemblies.ToArray();

            // zoom可能に
            SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
            // 背景を黒に
            Insert(0, new GridBackground());
            // ドラッグによる移動可能に
            this.AddManipulator(new SelectionDragger());
            // ドラッグで描画範囲を動かせるように
            this.AddManipulator(new ContentDragger());
            // ノードの追加
            asmdefNodeDict = new Dictionary <string, IAsmdefNodeView>();
            foreach (var asm in assemblyArr)
            {
                var node = new AsmdefNode(asm.name, contentContainer);
                AddElement(node);
                asmdefNodeDict.Add(node.title, node);
            }
            // 依存の整理
            var nodeProfiles = assemblyArr
                               .Select((x, i) => new NodeProfile(new NodeId(i), x.name))
                               .ToDictionary(x => x.Name);
            var dependencies = new List <IDependencyNode>(nodeProfiles.Count);

            // 依存先の設定
            foreach (var asm in assemblyArr)
            {
                if (nodeProfiles.TryGetValue(asm.name, out var profile))
                {
                    var requireProfiles = asm.assemblyReferences
                                          .Where(x => nodeProfiles.ContainsKey(x.name))
                                          .Select(x => nodeProfiles[x.name]);
                    var dep = new HashSetDependencyNode(profile);
                    dep.SetRequireNodes(requireProfiles);
                    dependencies.Add(dep);
                }
            }
            // 依存元の設定
            NodeProcessor.SetBeRequiredNodes(dependencies);

            // 依存先にのみラインを追加
            foreach (var dep in dependencies)
            {
                if (!asmdefNodeDict.TryGetValue(dep.Profile.Name, out var fromNode))
                {
                    continue;
                }
                foreach (var dest in dep.Destinations)
                {
                    if (!asmdefNodeDict.TryGetValue(dest.Name, out var toNode))
                    {
                        continue;
                    }
                    fromNode.RightPort.Connect(toNode.LeftPort);
                }
            }

            // Portに接続数を追記
            foreach (var dep in dependencies)
            {
                if (asmdefNodeDict.TryGetValue(dep.Profile.Name, out var node))
                {
                    node.LeftPort.Label  = $"RefBy({dep.Sources.Count})";
                    node.RightPort.Label = $"RefTo({dep.Destinations.Count})";
                }
            }

            // ノードの場所を整列
            var sortStrategy = new AlignSortStrategy(AlignParam.Default(), Vector2.zero);
            var sortedNode   = sortStrategy.Sort(dependencies);

            foreach (var node in sortedNode)
            {
                if (asmdefNodeDict.TryGetValue(node.Profile.Name, out var nodeView))
                {
                    nodeView.SetPositionXY(node.Position);
                }
            }
        }