public void OnceFilter()
        {
            var graph = DirectedLabeledGraph.Create(
                Tuple.Create("1", "a", "2"),
                Tuple.Create("2", "a", "1")
                );

            var expected = LabeledTree.Node("1",
                                            LabeledTree.Edge("a", LabeledTree.Node <string, string>("2")));

            var filter = DirectedLabeledGraph.TraverseEdgeOnlyOnce(EqualityComparer <string> .Default);

            AssertEqual(expected, graph.ToTree(filter));
        }
        public EntityModified Execute(SolutionEntity solutionEntity)
        {
            Repo.SaveAllDiagrams();

            var modified =
                from currentDiagram in GetCurrentDiagramContaining(solutionEntity)
                from solution in SolutionInstantiationGraph.Create(Repo, solutionEntity)
                let solutionTree = solution.Graph.ToTree(DirectedLabeledGraph.TraverseEdgeOnlyOnce <ModelEntity.Connector>())
                                   let preMarkedSolutionTree = SelectRootWithAlternatives(solutionTree)
                                                               from markedSolutionTree in Selector.GetSelectedDependencies(preMarkedSolutionTree)
                                                               let markedSolution = solution.WithSelection(markedSolutionTree.NodeLabels)
                                                                                    let targetPackage = Repo.FindPackageContaining(solutionEntity)
                                                                                                        let instantiatedSolution                                              = markedSolution.InstantiateSelectedItems(targetPackage)
                                                                                                                                                     let _1                   = instantiatedSolution.InstantiateMissingSolutionConnectors()
                                                                                                                                                                       let _2 = instantiatedSolution.CreateDiagramElements(currentDiagram)
                                                                                                                                                                                select EntityModified.Modified;

            return(modified.GetOrElse(EntityModified.NotModified));
        }
Пример #3
0
        /// <summary>
        /// Adds diagram objects for every solution item in the graph to <c>diagram</c>.
        /// </summary>
        /// <param name="diagramRepo"></param>
        /// <param name="diagram"></param>
        /// <param name="problemSpace"></param>
        /// <returns></returns>
        public Unit CreateDiagramElements(ModelEntity.Diagram diagram)
        {
            var tree       = Graph.ToTree(DirectedLabeledGraph.TraverseEdgeOnlyOnce <ModelEntity.Connector>());
            var rootObject = diagram.GetObject(tree.Label.Instance.Value).Value;
            var vNull      = Convert.ToInt32(
                rootObject.EaObject.left - ((tree.Leafs() - 1) / 2d) * 120);
            var width  = rootObject.EaObject.right - rootObject.EaObject.left;
            var hNull  = rootObject.EaObject.top;
            var height = rootObject.EaObject.top - rootObject.EaObject.bottom;

            if (vNull < 10)
            {
                vNull = 10;
            }

            Graph.TraverseEdgesBF((from, via, to) =>
            {
                var objectData = from childInstance in to.Instance
                                 where !diagram.GetObject(childInstance).IsDefined
                                 from parentInstance in @from.Instance
                                 from parentObject in diagram.GetObject(parentInstance)
                                 select Tuple.Create(parentObject, childInstance);

                objectData.ForEach((parentObject, childInstance) =>
                {
                    var lhl     = tree.LeftHandLeafs(to);
                    var l       = tree.Leafs(to);
                    var level   = tree.Level(to);
                    var vOffset = Convert.ToInt32(
                        vNull + (lhl + (l - 1) / 2d) * 120);
                    var hOffset = hNull - (150 * level);

                    diagram.AddObject(childInstance.Id,
                                      left: vOffset, right: vOffset + width,
                                      top: hOffset, bottom: hOffset - height);
                });
            });
            Repo.Reload(diagram);

            return(Unit.Instance);
        }