/// <summary>
        /// Initializes the layout algorithm and its layout data.
        /// </summary>
        private void InitializeLayout()
        {
            orthogonalEdgeRouter = new EdgeRouter {
                ConsiderNodeLabels = true
            };

            hl = new HierarchicLayout {
                OrthogonalRouting  = true,
                LayoutOrientation  = LayoutOrientation.LeftToRight,
                ConsiderNodeLabels = true
            };

            // outgoing edges must be routed to the right of the node
            // we use the same value for all edges, which is a strong port constraint that forces
            // the edge to leave at the east (right) side
            var east = PortConstraint.Create(PortSide.East, true);
            // incoming edges must be routed to the left of the node
            // we use the same value for all edges, which is a strong port constraint that forces
            // the edge to enter at the west (left) side
            var west = PortConstraint.Create(PortSide.West, true);

            MapperDelegate <IEdge, PortConstraint> sourceDelegate = edge => ((PortDescriptor)edge.SourcePort.Tag).X == 0 ? west : east;
            MapperDelegate <IEdge, PortConstraint> targetDelegate = edge => ((PortDescriptor)edge.TargetPort.Tag).X == 0 ? west : east;

            oerData = new PolylineEdgeRouterData {
                SourcePortConstraints = { Delegate = sourceDelegate },
                TargetPortConstraints = { Delegate = targetDelegate }
            };

            hlData = new HierarchicLayoutData {
                SourcePortConstraints = { Delegate = sourceDelegate },
                TargetPortConstraints = { Delegate = targetDelegate }
            };
        }
Esempio n. 2
0
        /// <inheritdoc />
        protected override ILayoutAlgorithm CreateConfiguredLayout(GraphControl graphControl)
        {
            var labeling = new GenericLabeling();

            labeling.AutoFlipping         = true;
            labeling.OptimizationStrategy = OptimizationStrategyItem;
            if (labeling.OptimizationStrategy == OptimizationStrategy.None)
            {
                labeling.ProfitModel = new SimpleProfitModel();
            }

            labeling.RemoveNodeOverlaps = !AllowNodeOverlapsItem;
            labeling.RemoveEdgeOverlaps = !AllowEdgeOverlapsItem;
            labeling.PlaceEdgeLabels    = PlaceEdgeLabelsItem;
            labeling.PlaceNodeLabels    = PlaceNodeLabelsItem;
            labeling.ReduceAmbiguity    = ReduceAmbiguityItem;

            var selectionOnly = ConsiderSelectedFeaturesOnlyItem;

            labeling.AffectedLabelsDpKey = null;
            ILayoutAlgorithm layout = labeling;

            if (graphControl.Selection != null && selectionOnly)
            {
                labeling.AffectedLabelsDpKey = SelectedLabelsStage.ProviderKey;
                layout = new SelectedLabelsStage(labeling);
            }

            AddPreferredPlacementDescriptor(graphControl.Graph, LabelPlacementAlongEdgeItem, LabelPlacementSideOfEdgeItem, LabelPlacementOrientationItem, LabelPlacementDistanceItem);
            SetupEdgeLabelModels(graphControl);

            return(layout);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates the layout with an appropriate layout data which is selected by the layout combo box.
        /// </summary>
        private void CreateLayout()
        {
            switch (layoutComboBox.SelectedIndex)
            {
            default:
            case 0:
                layout = new HierarchicLayout();
                var hierarchicLayoutData = new HierarchicLayoutData();
                layoutData   = hierarchicLayoutData;
                abortHandler = hierarchicLayoutData.AbortHandler;
                break;

            case 1:
                layout = new OrganicLayout
                {
                    QualityTimeRatio      = 1.0,
                    MaximumDuration       = 1200000,
                    MultiThreadingAllowed = true
                };
                var organicLayoutData = new OrganicLayoutData();
                layoutData   = organicLayoutData;
                abortHandler = organicLayoutData.AbortHandler;
                break;

            case 2:
                layout = new OrthogonalLayout {
                    CrossingReduction = true
                };
                var orthogonalLayoutData = new OrthogonalLayoutData();
                layoutData   = orthogonalLayoutData;
                abortHandler = orthogonalLayoutData.AbortHandler;
                break;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="algorithm"></param>
        public DistributeLayoutPanel(ILayoutAlgorithm algorithm)
        {
            InitializeComponent();
            m_algorithm = algorithm;

            DistributeLayout distribute = (DistributeLayout)algorithm;
        }
Esempio n. 5
0
 public AsyncThreadArgument(
     [NotNull] ILayoutAlgorithm <TVertex, TEdge, TGraph> algorithm,
     bool showAllStates)
 {
     Algorithm     = algorithm;
     ShowAllStates = showAllStates;
 }
 public NodeResizingStage(ILayoutAlgorithm layout) : base(layout)
 {
     this.layout         = layout;
     LayoutOrientation   = LayoutOrientation.LeftToRight;
     PortBorderGapRatio  = 0;
     MinimumPortDistance = 0;
 }
Esempio n. 7
0
 public TagCloudVisualizer(IFileReader fileReader, IWordProcessor wordProcessor,
                           ILayoutAlgorithm layoutAlgorithm, IVisualizer visualizer)
 {
     this.fileReader      = fileReader;
     this.wordProcessor   = wordProcessor;
     this.layoutAlgorithm = layoutAlgorithm;
     this.visualizer      = visualizer;
 }
 public void Draw(ILayoutAlgorithm layout, Rect drawingArea)
 {
     NodeConstraints defaults;
     defaults.maximumNormalizedNodeSize = k_DefaultMaximumNormalizedNodeSize;
     defaults.maximumNodeSizeInPixels = k_DefaultMaximumNodeSizeInPixels;
     defaults.aspectRatio = k_DefaultAspectRatio;
     Draw(layout, drawingArea, defaults);
 }
Esempio n. 9
0
 public ForceDirectedLayoutAlgorithm(
     IVertexAndEdgeListGraph visitedGraph
     )
     : base(visitedGraph)
 {
     this.preLayoutAlgorithm = new RandomLayoutAlgorithm(visitedGraph, this.Positions);
     this.potential          = new DirectedForcePotential(this);
     this.potentials         = new VertexPointFDictionary();
 }
        private async void OnLoaded(object sender, EventArgs e)
        {
            PopulateLayoutComboBox();
            await GenerateGraph();

            directedComboBox.SelectedIndex = 1;
            layoutComboBox.SelectedIndex   = 1;
            currentLayout = layouts[(string)layoutComboBox.SelectedItem];
        }
Esempio n. 11
0
        string ILayoutAlgorithmFactory <TVertex, TEdge, TGraph> .GetAlgorithmType(ILayoutAlgorithm <TVertex, TEdge, TGraph> algorithm)
        {
            Contract.Requires(algorithm != null);
            var laf = (ILayoutAlgorithmFactory <TVertex, TEdge, TGraph>) this;

            Contract.Ensures(Contract.Result <string>() == null || laf.AlgorithmTypes.Contains(Contract.Result <string>()));

            return(default(string));
        }
 public ForceDirectedLayoutAlgorithm(
     IVertexAndEdgeListGraph visitedGraph
     )
     : base(visitedGraph)
 {
     this.preLayoutAlgorithm=new RandomLayoutAlgorithm(visitedGraph,this.Positions);
     this.potential=new DirectedForcePotential(this);
     this.potentials=new VertexPointFDictionary();
 }
        public string GetAlgorithmType(ILayoutAlgorithm <TVertex, TEdge, TGraph> algorithm)
        {
            /*if ( algorithm is DoubleTreeLayoutAlgorithm<TVertex, TEdge, TGraph> )
             *      return "DoubleTree";
             *
             * if ( algorithm is BalloonTreeLayoutAlgorithm<TVertex, TEdge, TGraph> )
             * return "BalloonTree";*/

            return(string.Empty);
        }
 private void InitializeLayoutComboBox()
 {
     layoutComboBox.ItemsSource   = layoutAlgorithms.Keys;
     layoutComboBox.SelectedIndex = 0;
     layoutAlgorithm = layoutAlgorithms[(string)layoutComboBox.SelectedValue];
     layoutComboBox.SelectionChanged += async(sender, e) => {
         layoutAlgorithm = layoutAlgorithms[(string)layoutComboBox.SelectedValue];
         await DoLayout(true);
     };
 }
Esempio n. 15
0
 public CircularCloudLayouter(ILayoutAlgorithm layoutAlgorithm, Point center)
 {
     this.layoutAlgorithm = layoutAlgorithm;
     if (center.X < 0 || center.Y < 0)
     {
         throw new ArgumentException("Center with negative coordinates is not allowed!");
     }
     layoutAlgorithm.SetCenterPoint(center);
     rectangles = new List <Rectangle>();
 }
Esempio n. 16
0
 public ForceDirectedLayoutAlgorithm(
     IVertexAndEdgeListGraph visitedGraph,
     IPotential potential,
     ILayoutAlgorithm preLayoutAlgorithm
     )
     : base(visitedGraph)
 {
     this.preLayoutAlgorithm = preLayoutAlgorithm;
     this.potential          = potential;
     this.potentials         = new VertexPointFDictionary();
 }
Esempio n. 17
0
        public CBGridLayoutPanel(ILayoutAlgorithm layout)
        {
            InitializeComponent();
            m_algorithm = layout;

            CBGridLayout grid = (CBGridLayout)layout;
            this.krTextBox.Text = grid.Kr.ToString();
            this.kaTextBox.Text = grid.Ka.ToString();
            this.iterationTextBox.Text = grid.Iteration.ToString();
            this.marginTextBox.Text = grid.Margin.ToString();
        }
 public ForceDirectedLayoutAlgorithm(
     IVertexAndEdgeListGraph visitedGraph,
     IPotential potential,
     ILayoutAlgorithm preLayoutAlgorithm
     )
     : base(visitedGraph)
 {
     this.preLayoutAlgorithm=preLayoutAlgorithm;
     this.potential=potential;
     this.potentials=new VertexPointFDictionary();
 }
        ///<inheritdoc/>
        protected override void ConfigureLayout()
        {
            OptionGroup layoutGroup   = Handler.GetGroupByName(GENERAL);
            var         partialLayout = new PartialLayout
            {
                MinimumNodeDistance   = (int)layoutGroup[MIN_NODE_DIST].Value,
                ConsiderNodeAlignment = (bool)layoutGroup[CONSIDER_SNAPLINES].Value,
                SubgraphPlacement     =
                    subgraphPlacementStrategies[
                        (string)layoutGroup[SUBGRAPH_POSITION_STRATEGY].Value]
            };

            string componentAssignmentStr = (string)layoutGroup[MODE_COMPONENT_ASSIGNMENT].Value;

            partialLayout.ComponentAssignmentStrategy =
                componentAssignment[componentAssignmentStr];

            partialLayout.LayoutOrientation =
                layoutOrientation[(string)layoutGroup[ORIENTATION_MAIN_GRAPH].Value];

            partialLayout.EdgeRoutingStrategy =
                routingStrategies[(string)layoutGroup[ROUTING_TO_SUBGRAPH].Value];

            ILayoutAlgorithm subgraphLayout = null;

            if (componentAssignmentStr != MODE_COMPONENT_SINGLE)
            {
                var subGraphLayoutStr = (string)layoutGroup[SUBGRAPH_LAYOUT].Value;
                switch (subGraphLayoutStr)
                {
                case SUBGRAPH_LAYOUT_IHL:
                    subgraphLayout = new HierarchicLayout();
                    break;

                case SUBGRAPH_LAYOUT_ORGANIC:
                    subgraphLayout = new OrganicLayout();
                    break;

                case SUBGRAPH_LAYOUT_CIRCULAR:
                    subgraphLayout = new CircularLayout();
                    break;

                case SUBGRAPH_LAYOUT_ORTHOGONAL:
                    subgraphLayout = new OrthogonalLayout();
                    break;

                default:
                    break;
                }
            }
            partialLayout.CoreLayout = subgraphLayout;

            LayoutAlgorithm = partialLayout;
        }
Esempio n. 20
0
 public ApplicationCore(ReaderFinder readerFinder,
                        IImageBuilder tagCloudImageBuilder, ILayoutAlgorithm layoutAlgorithm,
                        IImageSaver imageSaver,
                        Filter filter, WordConverter wordConverter)
 {
     this.filter               = filter;
     this.wordConverter        = wordConverter;
     this.readerFinder         = readerFinder;
     this.tagCloudImageBuilder = tagCloudImageBuilder;
     this.imageSaver           = imageSaver;
     this.layoutAlgorithm      = layoutAlgorithm;
 }
Esempio n. 21
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="algorithm"></param>
        public GridLayoutPanel(ILayoutAlgorithm algorithm)
        {
            InitializeComponent();
            m_algorithm = algorithm;

            GridLayout grid = (GridLayout)algorithm;
            this.annealingRepeats.Text = grid.Kmax.ToString();
            this.naturalLength.Text = grid.NaturalLength.ToString();
            this.initialT.Text = grid.InitialT.ToString();
            this.defMargin.Text = grid.DefMargin.ToString();
            this.scratchCheckBox.Checked = (grid.SubIndex == 0);
        }
        private static int EvaluateEdgeCrossing(
            [NotNull] IEdgeSet <object, IEdge <object> > compoundGraph,
            [NotNull] ILayoutAlgorithm <object, IEdge <object>, CompoundGraph <object, IEdge <object> > > algorithm,
            [NotNull] IReadOnlyDictionary <object, Size> verticesSizes)
        {
            int crossings = 0;

            foreach (IEdge <object> edge in compoundGraph.Edges)
            {
                Point uPos1  = algorithm.VerticesPositions[edge.Source];
                Point vPos1  = algorithm.VerticesPositions[edge.Target];
                Size  uSize1 = verticesSizes[edge.Source];
                Size  vSize1 = verticesSizes[edge.Target];

                Point uPoint1 = LayoutUtils.GetClippingPoint(uSize1, uPos1, vPos1);
                Point vPoint1 = LayoutUtils.GetClippingPoint(vSize1, vPos1, uPos1);
                foreach (IEdge <object> edge2 in compoundGraph.Edges)
                {
                    if (ReferenceEquals(edge, edge2))
                    {
                        continue;
                    }

                    Point uPos2  = algorithm.VerticesPositions[edge.Source];
                    Point vPos2  = algorithm.VerticesPositions[edge.Target];
                    Size  uSize2 = verticesSizes[edge.Source];
                    Size  vSize2 = verticesSizes[edge.Target];

                    Point uPoint2 = LayoutUtils.GetClippingPoint(uSize2, uPos2, vPos2);
                    Point vPoint2 = LayoutUtils.GetClippingPoint(vSize2, vPos2, uPos2);

                    Vector v1 = vPoint1 - uPoint1;
                    Vector v2 = vPoint2 - uPoint2;

                    if (v1 == v2 || v1 == -v2)
                    {
                        continue; // Parallel edges
                    }
                    double t2 = (uPoint1.Y - uPoint2.Y + (uPoint2.X - uPoint1.X) * v1.Y / v1.X) / (v2.Y - v2.X * v1.Y / v1.X);
                    double t1 = (uPoint2.X - uPoint1.X + t2 * v2.X) / v1.X;

                    Point p  = uPoint1 + t1 * v1;
                    bool  b1 = t1 > 0 && (p - uPoint1).Length < (vPoint1 - uPoint1).Length;
                    bool  b2 = t2 > 0 && (p - uPoint2).Length < (vPoint2 - uPoint2).Length;

                    if (b1 && b2)
                    {
                        ++crossings;
                    }
                }
            }
            return(crossings);
        }
Esempio n. 23
0
File: ConsoleUI.cs Progetto: lgnv/di
 public ConsoleUi(IReader[] readers,
                  IImageBuilder tagCloudImageCreator, ILayoutAlgorithm layoutAlgorithm,
                  IImageSaver imageSaver,
                  Filter filter, WordConverter wordConverter)
 {
     this.filter               = filter;
     this.wordConverter        = wordConverter;
     this.readers              = readers;
     this.tagCloudImageCreator = tagCloudImageCreator;
     this.imageSaver           = imageSaver;
     this.layoutAlgorithm      = layoutAlgorithm;
 }
        private async void ShortestPathForm_Load(object sender, EventArgs e)
        {
            RegisterCommands();
            PopulateLayoutComboBox();

            directedComboBox.SelectedIndex = 0;
            layoutComboBox.SelectedIndex   = 1;
            currentLayout = layouts[(string)layoutComboBox.SelectedItem];
            layoutComboBox.SelectedIndexChanged += layoutComboBox_SelectedIndexChanged;

            await GenerateGraph();
        }
Esempio n. 25
0
    public void Draw(ILayoutAlgorithm layout, Rect totalDrawingArea, NodeConstraints nodeConstraints)
    {
        PrepareLegend(layout.vertices);

        var drawingArea = new Rect(totalDrawingArea);
        var legendArea = new Rect(totalDrawingArea);
        legendArea.width = EstimateLegendWidth() + k_BorderSize * 2;
        legendArea.x = drawingArea.xMax - legendArea.width;
        drawingArea.width -=  legendArea.width;

        DrawGraph(layout, drawingArea, nodeConstraints);
        DrawLegend(legendArea);
    }
Esempio n. 26
0
 private void InitializeLayoutComboBox()
 {
     foreach (var algorithm in layoutAlgorithms.Keys)
     {
         layoutComboBox.ComboBox.Items.Add(algorithm);
     }
     layoutComboBox.SelectedIndex = 0;
     layoutAlgorithm = layoutAlgorithms[(string)layoutComboBox.SelectedItem];
     layoutComboBox.SelectedIndexChanged += (sender, e) => {
         layoutAlgorithm = layoutAlgorithms[(string)layoutComboBox.SelectedItem];
         DoLayout(true);
     };
 }
        public string GetAlgorithmType(ILayoutAlgorithm <TVertex, TEdge, TGraph> algorithm)
        {
            if (algorithm is DoubleTreeLayoutAlgorithm <TVertex, TEdge, TGraph> )
            {
                return("DoubleTree");
            }

            if (algorithm is BalloonTreeLayoutAlgorithm <TVertex, TEdge, TGraph> )
            {
                return("BalloonTree");
            }

            return(string.Empty);
        }
        /// <inheritdoc />
        public string GetAlgorithmType(ILayoutAlgorithm <TVertex, TEdge, TGraph> algorithm)
        {
            if (algorithm is null)
            {
                throw new ArgumentNullException(nameof(algorithm));
            }

            if (algorithm is CircularLayoutAlgorithm <TVertex, TEdge, TGraph> )
            {
                return(CircularAlgorithm);
            }
            if (algorithm is SimpleTreeLayoutAlgorithm <TVertex, TEdge, TGraph> )
            {
                return(TreeAlgorithm);
            }
            if (algorithm is FRLayoutAlgorithm <TVertex, TEdge, TGraph> frAlgorithm)
            {
                if (frAlgorithm.Parameters is BoundedFRLayoutParameters)
                {
                    return(BoundedFRAlgorithm);
                }
                return(FRAlgorithm);
            }
            if (algorithm is KKLayoutAlgorithm <TVertex, TEdge, TGraph> )
            {
                return(KKAlgorithm);
            }
            if (algorithm is ISOMLayoutAlgorithm <TVertex, TEdge, TGraph> )
            {
                return(ISOMAlgorithm);
            }
            if (algorithm is LinLogLayoutAlgorithm <TVertex, TEdge, TGraph> )
            {
                return(LinLogAlgorithm);
            }
            if (algorithm is SugiyamaLayoutAlgorithm <TVertex, TEdge, TGraph> )
            {
                return(SugiyamaAlgorithm);
            }
            if (algorithm is CompoundFDPLayoutAlgorithm <TVertex, TEdge, TGraph> )
            {
                return(CompoundFDPAlgorithm);
            }
            if (algorithm is RandomLayoutAlgorithm <TVertex, TEdge, TGraph> )
            {
                return(RandomAlgorithm);
            }
            return(string.Empty);
        }
Esempio n. 29
0
        private void SetupLayouts()
        {
            // create TreeLayout
            var treeLayout = new TreeLayout {
                LayoutOrientation = LayoutOrientation.LeftToRight
            };

            treeLayout.PrependStage(new FixNodeLayoutStage());
            layouts.Add(treeLayout);
            layoutMapper["Tree"] = treeLayout;
            layoutComboBox.Items.Add("Tree");

            // create BalloonLayout
            var balloonLayout = new BalloonLayout
            {
                FromSketchMode    = true,
                CompactnessFactor = 1.0,
                AllowOverlaps     = true
            };

            balloonLayout.PrependStage(new FixNodeLayoutStage());
            layouts.Add(balloonLayout);
            layoutMapper["Balloon"] = balloonLayout;
            layoutComboBox.Items.Add("Balloon");

            // create OrganicLayout
            var organicLayout = new OrganicLayout {
                MinimumNodeDistance = 40,
                Deterministic       = true
            };

            organicLayout.PrependStage(new FixNodeLayoutStage());
            layouts.Add(organicLayout);
            layoutMapper["Organic"] = organicLayout;
            layoutComboBox.Items.Add("Organic");

            // create OrthogonalLayout
            var orthogonalLayout = new OrthogonalLayout();

            orthogonalLayout.PrependStage(new FixNodeLayoutStage());
            layouts.Add(orthogonalLayout);
            layoutMapper["Orthogonal"] = orthogonalLayout;
            layoutComboBox.Items.Add("Orthogonal");

            // set it as initial value
            currentLayout = treeLayout;
            layoutComboBox.SelectedIndex = 0;
        }
 public ForceDirectedLayoutAlgorithm(IVertexAndEdgeListGraph visitedGraph)
     : base(visitedGraph)
 {
     this.preLayoutAlgorithm = null;
     this.potential = null;
     this.currentIteration = 0;
     this.maxIteration = 500;
     this.potentials = new VertexPointFDictionary();
     this.maxMovement = 50f;
     this.heat = 1f;
     this.heatDecayRate = 0.99f;
     this.syncRoot = null;
     this.preLayoutAlgorithm = new RandomLayoutAlgorithm(visitedGraph, base.Positions);
     this.potential = new DirectedForcePotential(this);
     this.potentials = new VertexPointFDictionary();
 }
 public ForceDirectedLayoutAlgorithm(IVertexAndEdgeListGraph visitedGraph, IPotential potential, ILayoutAlgorithm preLayoutAlgorithm)
     : base(visitedGraph)
 {
     this.preLayoutAlgorithm = null;
     this.potential = null;
     this.currentIteration = 0;
     this.maxIteration = 500;
     this.potentials = new VertexPointFDictionary();
     this.maxMovement = 50f;
     this.heat = 1f;
     this.heatDecayRate = 0.99f;
     this.syncRoot = null;
     this.preLayoutAlgorithm = preLayoutAlgorithm;
     this.potential = potential;
     this.potentials = new VertexPointFDictionary();
 }
Esempio n. 32
0
        private async Task RunLayout(ILayoutAlgorithm layout, LayoutData layoutData)
        {
            var executor = new LayoutExecutor(graphControl, layout)
            {
                LayoutData      = layoutData,
                Duration        = TimeSpan.FromMilliseconds(500),
                AnimateViewport = true
            };

            try {
                await executor.Start();
            } catch (Exception e) {
                MessageBox.Show(this, "Layout did not complete successfully.\n" + e.Message);
            }
            EnableButtons();
        }
        /// <inheritdoc />
        public string GetAlgorithmType(ILayoutAlgorithm <TVertex, TEdge, TGraph> algorithm)
        {
            if (algorithm is null)
            {
                throw new ArgumentNullException(nameof(algorithm));
            }

            if (algorithm is DoubleTreeLayoutAlgorithm <TVertex, TEdge, TGraph> )
            {
                return(DoubleTreeAlgorithm);
            }
            if (algorithm is BalloonTreeLayoutAlgorithm <TVertex, TEdge, TGraph> )
            {
                return(BalloonTreeAlgorithm);
            }
            return(string.Empty);
        }
        ///<summary> Uses some of the demo settings to further configure the core layout algorithm </summary>
        private void ConfigureCoreLayout(ILayoutAlgorithm coreLayout)
        {
            int minNodeDistance = (int)handler.GetItemByName(MinimumNodeDistance).Value;

            if (coreLayout is OrthogonalLayout)
            {
                ((OrthogonalLayout)coreLayout).GridSpacing = minNodeDistance;
            }
            else if (coreLayout is HierarchicLayout)
            {
                ((HierarchicLayout)coreLayout).MinimumLayerDistance = minNodeDistance;
            }
            else if (coreLayout is CircularLayout)
            {
                ((CircularLayout)coreLayout).SingleCycleLayout.MinimumNodeDistance = minNodeDistance;
                ((CircularLayout)coreLayout).BalloonLayout.MinimumNodeDistance     = minNodeDistance;
            }
        }
        /// <summary>
        /// Perform the layout operation
        /// </summary>
        private async Task ApplyLayout(ILayoutAlgorithm layout, LayoutData layoutData, bool animateViewport)
        {
            // layout starting, disable button
            hlLayoutButton.IsEnabled        = false;
            orthoEdgeRouterButton.IsEnabled = false;
            // do the layout
            var executor = new LayoutExecutor(graphControl, layout)
            {
                LayoutData      = layoutData,
                Duration        = TimeSpan.FromSeconds(1),
                AnimateViewport = animateViewport
            };
            await executor.Start();

            // layout finished, enable layout button again
            hlLayoutButton.IsEnabled        = true;
            orthoEdgeRouterButton.IsEnabled = true;
        }
        public string GetAlgorithmType(ILayoutAlgorithm <TVertex, TEdge, TGraph> algorithm)
        {
            if (algorithm == null)
            {
                return(string.Empty);
            }

            int index = algorithm.GetType().Name.IndexOf("LayoutAlgorithm");

            if (index == -1)
            {
                return(string.Empty);
            }

            string algoType = algorithm.GetType().Name;

            return(algoType.Substring(0, algoType.Length - index));
        }
Esempio n. 37
0
        /// <inheritdoc />
        protected override ILayoutAlgorithm CreateConfiguredLayout(GraphControl graphControl)
        {
            var layout = new PartialLayout();

            layout.ConsiderNodeAlignment       = AlignNodesItem;
            layout.MinimumNodeDistance         = MinimumNodeDistanceItem;
            layout.SubgraphPlacement           = SubgraphPlacementItem;
            layout.ComponentAssignmentStrategy = ComponentAssignmentStrategyItem;
            layout.LayoutOrientation           = OrientationItem;
            layout.EdgeRoutingStrategy         = RoutingToSubgraphItem;
            layout.AllowMovingFixedElements    = MoveFixedElementsItem;

            ILayoutAlgorithm subgraphLayout = null;

            if (ComponentAssignmentStrategyItem != ComponentAssignmentStrategy.Single)
            {
                switch (SubgraphLayoutItem)
                {
                case EnumSubgraphLayouts.Hierarchic:
                    subgraphLayout = new HierarchicLayout();
                    break;

                case EnumSubgraphLayouts.Organic:
                    subgraphLayout = new OrganicLayout();
                    break;

                case EnumSubgraphLayouts.Circular:
                    subgraphLayout = new CircularLayout();
                    break;

                case EnumSubgraphLayouts.Orthogonal:
                    subgraphLayout = new OrthogonalLayout();
                    break;
                }
            }
            layout.CoreLayout = subgraphLayout;

            return(layout);
        }
        protected override void Apply(LayoutGraphAdapter adapter, ILayoutAlgorithm layout, CopiedLayoutGraph layoutGraph)
        {
            var graph = adapter.AdaptedGraph;

            // check if only selected elements should be laid out
            var layoutOnlySelection = layout is BpmnLayout && ((BpmnLayout)layout).Scope == Scope.SelectedElements;

            // mark 'flow' edges, i.e. sequence flows, default flows and conditional flows
            adapter.AddDataProvider(BpmnLayout.SequenceFlowEdgesDpKey, Mappers.FromDelegate <IEdge, bool>(IsSequenceFlow));

            // mark boundary interrupting edges for the BalancingPortOptimizer
            adapter.AddDataProvider(BpmnLayout.BoundaryInterruptingEdgesDpKey, Mappers.FromDelegate((IEdge edge) => edge.SourcePort.Style is EventPortStyle));

            // mark conversations, events and gateways so their port locations are adjusted
            adapter.AddDataProvider(PortLocationAdjuster.AffectedNodesDpKey,
                                    Mappers.FromDelegate((INode node) => (node.Style is ConversationNodeStyle || node.Style is EventNodeStyle || node.Style is GatewayNodeStyle)));

            // add NodeHalos around nodes with event ports or specific exterior labels so the layout keeps space for the event ports and labels as well
            AddNodeHalos(adapter, graph, layoutOnlySelection);

            // add PreferredPlacementDescriptors for labels on sequence, default or conditional flows to place them at source side
            AddEdgeLabelPlacementDescriptors(adapter);

            // mark nodes, edges and labels as either fixed or affected by the layout and configure port constraints and incremental hints
            MarkFixedAndAffectedItems(adapter, layoutOnlySelection);

            // mark associations and message flows as undirected so they have less impact on layering
            EdgeDirectedness.Delegate = edge => (IsMessageFlow(edge) || IsAssociation(edge)) ? 0 : 1;

            // add layer constraints for start events, sub processes and message flows
            AddLayerConstraints(graph);

            // add EdgeLayoutDescriptor to specify minimum edge length for edges
            AddMinimumEdgeLength(MinimumEdgeLength);

            base.Apply(adapter, layout, layoutGraph);
        }
        private static Size EvaluateCanvasSize(
            [NotNull] IVertexSet <object> compoundGraph,
            [NotNull] ILayoutAlgorithm <object, IEdge <object>, CompoundGraph <object, IEdge <object> > > algorithm,
            [NotNull] IReadOnlyDictionary <object, Size> verticesSizes)
        {
            var topLeft     = new Point(double.PositiveInfinity, double.PositiveInfinity);
            var bottomRight = new Point(double.NegativeInfinity, double.NegativeInfinity);

            foreach (object v in compoundGraph.Vertices)
            {
                Point pos  = algorithm.VerticesPositions[v];
                Size  size = verticesSizes[v];

                topLeft.X = Math.Min(topLeft.X, pos.X - size.Width / 2.0);
                topLeft.Y = Math.Min(topLeft.Y, pos.Y - size.Height / 2.0);

                bottomRight.X = Math.Max(bottomRight.X, pos.X + size.Width / 2.0);
                bottomRight.Y = Math.Max(bottomRight.Y, pos.Y + size.Height / 2.0);
            }

            Vector sizeVector = bottomRight - topLeft;

            return(new Size(sizeVector.X, sizeVector.Y));
        }
Esempio n. 40
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="algo"></param>
 /// <param name="subIdx"></param>
 public void InitiateLayout(ILayoutAlgorithm algo, int subIdx)
 {
     m_con.DoLayout(algo, subIdx, true);
 }
Esempio n. 41
0
 private void SetAlgorithm(TabPage page)
 {
     ILayoutPanel panel = (ILayoutPanel)page.Controls[0];
     m_algorithm = panel.Algorithm;
 }
Esempio n. 42
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="algorithm"></param>
 public CircularLayoutPanel(ILayoutAlgorithm algorithm)
 {
     InitializeComponent();
     m_algorithm = algorithm;
 }
Esempio n. 43
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="algorithm"></param>
 public AlignLayoutPanel(ILayoutAlgorithm algorithm)
 {
     InitializeComponent();
     m_algorithm = algorithm;
 }
Esempio n. 44
0
        /// <summary>
        /// Do object layout.
        /// </summary>
        /// <param name="algorithm">ILayoutAlgorithm</param>
        /// <param name="subIdx">int</param>
        /// <param name="isRecorded">Whether to record this change.</param>
        public void DoLayout(ILayoutAlgorithm algorithm, int subIdx, bool isRecorded)
        {
            if (m_canvas == null)
                return;
            List<EcellObject> systemList = GetSystemList();
            List<EcellObject> nodeList = new List<EcellObject>();
            int nodeNum = 0;
            // Check Selected nodes when the layout algorithm uses selected objects.
            if (algorithm.GetLayoutType() == LayoutType.Selected)
            {
                foreach (EcellObject node in GetNodeList())
                {
                    node.IsLayouted = m_canvas.GetObject(node.Key, node.Type).Selected;
                    nodeList.Add(node);
                    if (node.IsLayouted)
                        nodeNum++;
                }
            }
            else if (algorithm.GetLayoutType() == LayoutType.Whole)
            {
                foreach (EcellObject node in GetNodeList())
                {
                    node.IsLayouted = true;
                    nodeList.Add(node);
                    nodeNum++;
                }
            }
            // Do Layout
            try
            {
                algorithm.DoLayout(subIdx, false, systemList, nodeList);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                Util.ShowNoticeDialog(MessageResources.ErrLayout);
                return;
            }

            // Set Layout.
            foreach (EcellObject system in systemList)
            {
                if (!system.IsLayouted)
                    continue;
                system.IsLayouted = false;
                NotifySetPosition(system);
            }
            int i = 0;
            int allcount = nodeList.Count;
            int count = 0;
            string mes = MessageResources.MessageLayout;
            Progress(mes, 100, 50);
            foreach (EcellObject node in nodeList)
            {
                if (!node.IsLayouted)
                {
                    Progress(mes, 100, count * 50 / allcount + 50);
                    count++;
                    continue;
                }

                i++;
                node.IsLayouted = false;
                PPathwayObject obj = m_canvas.GetObject(node.Key, node.Type);
                if (obj is PPathwayEntity)
                {
                    foreach (PPathwayEdge edge in ((PPathwayEntity)obj).Edges)
                    {
                        edge.VIndex = -1;
                        edge.PIndex = -1;
                    }
                }

                if (isRecorded)
                {
                    if (i != nodeNum)
                        NotifyDataChanged(node.Key,node,isRecorded, false);
                    else
                        NotifyDataChanged(node.Key, node, isRecorded, true);
                }
                else
                {
                    if (i != nodeNum)
                        NotifySetPosition(node);
                    else
                        NotifySetPosition(node);
                }
                Progress(mes, 100, count * 50 / allcount + 50);
                count++;
            }
            Progress(mes, 100, 100);
        }
Esempio n. 45
0
    private void DrawGraph(ILayoutAlgorithm layout, Rect drawingArea, NodeConstraints nodeConstraints)
    {
        // add border, except on right-hand side where the legend will provide necessary padding
        drawingArea = new Rect(drawingArea.x + k_BorderSize,
                drawingArea.y + k_BorderSize,
                drawingArea.width - k_BorderSize,
                drawingArea.height - k_BorderSize * 2);

        var b = new Bounds(Vector3.zero, Vector3.zero);
        foreach (var c in layout.vertices)
        {
            b.Encapsulate(new Vector3(c.position.x, c.position.y, 0.0f));
        }

        // Increase b by maximum node size (since b is measured between node centers)
        b.Expand(new Vector3(nodeConstraints.maximumNormalizedNodeSize, nodeConstraints.maximumNormalizedNodeSize, 0));

        var scale = new Vector2(drawingArea.width / b.size.x, drawingArea.height / b.size.y);
        var offset = new Vector2(-b.min.x, -b.min.y);

        Vector2 nodeSize = ComputeNodeSize(scale, nodeConstraints);

        GUI.BeginGroup(drawingArea);

        foreach (var e in layout.edges)
        {
            Vector2 v0 = ScaleVertex(layout.vertices[e.source].position, offset, scale);
            Vector2 v1 = ScaleVertex(layout.vertices[e.destination].position, offset, scale);
            DrawEdge(v0, v1, layout.vertices[e.source].propagatedWeight);
        }

        int index = 0;
        foreach (var v in layout.vertices)
        {
            DrawNode(v, ScaleVertex(v.position, offset, scale) - nodeSize / 2, nodeSize, index.ToString());
            index++;
        }

        GUI.EndGroup();
    }