Exemple #1
0
        private void CopyDiagramObjects(ModelEntity.Diagram problemDiagram, ModelEntity.Diagram solutionDiagram, IEnumerable <ElementInstantiation> instantiations)
        {
            var solutionObjects = from problemObject in problemDiagram.Objects
                                  let instantiation = instantiations.FirstOption(i => i.Element.Id == problemObject.EaObject.ElementID)
                                                      let solutionElement = instantiation.SelectMany(i => i.Instance)
                                                                            let elementId = solutionElement.Fold(e => e.Id, () => problemObject.EaObject.ElementID)
                                                                                            select Tuple.Create(problemObject, elementId);

            solutionObjects.ForEach((problemObject, elementId) =>
            {
                solutionDiagram.AddObject(elementId,
                                          left: problemObject.EaObject.left, right: problemObject.EaObject.right,
                                          top: problemObject.EaObject.top, bottom: problemObject.EaObject.bottom);
            });
        }
Exemple #2
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);
        }