private void DisplayRealGraph() { _graph.CreateGeometryGraph(); foreach (var navigationPoint in airfield.NavigationGraph.Vertices) { var dnode = _graph.Nodes.FirstOrDefault(node => node.Id.Equals(navigationPoint.Name)); if (dnode != null) { dnode.GeometryNode.BoundaryCurve = CreateLabelAndBoundary(navigationPoint, dnode); } else { MessageBox.Show($"Error Displaying {navigationPoint.Name}", "Display Error", MessageBoxButton.OK, MessageBoxImage.Error); } } LayoutHelpers.RouteAndLabelEdges(_graph.GeometryGraph, settings, _graph.GeometryGraph.Edges); _graphViewer = new GraphViewer { LayoutEditingEnabled = false, NeedToCalculateLayout = false }; _graphViewer.BindToPanel(GraphPanel); _graphViewer.MouseDown += MouseDownHandler; _graphViewer.MouseUp += MouseUpHandler; _graphViewer.Graph = _graph; }
void LayoutOneComponent(GeometryGraph component) { PrepareGraphForLayout(component); if (component.RootCluster.Clusters.Any()) { var layoutSettings = new SugiyamaLayoutSettings { FallbackLayoutSettings = new FastIncrementalLayoutSettings { AvoidOverlaps = true }, NodeSeparation = lgLayoutSettings.NodeSeparation, LayerSeparation = lgLayoutSettings.NodeSeparation, EdgeRoutingSettings = lgLayoutSettings.EdgeRoutingSettings, LayeringOnly = true }; var initialBc = new InitialLayoutByCluster(component, a => layoutSettings); initialBc.Run(); } else { LayoutHelpers.CalculateLayout(component, GetMdsLayoutSettings(), cancelToken); } var box = component.BoundingBox; box.Pad(lgLayoutSettings.NodeSeparation / 2); component.BoundingBox = box; }
public static void Layout(GeometryGraph graph) { foreach (Node n in graph.Nodes) { n.BoundaryCurve = CurveFactory.CreateEllipse(20.0, 10.0, new Point()); } foreach (Cluster c in graph.RootCluster.AllClustersDepthFirst()) { c.BoundaryCurve = c.BoundingBox.Perimeter(); } var settings = new FastIncrementalLayoutSettings(); settings.AvoidOverlaps = true; settings.NodeSeparation = 30; settings.RouteEdges = true; LayoutHelpers.CalculateLayout(graph, settings, new CancelToken()); foreach (Cluster c in graph.RootCluster.AllClustersDepthFirst()) { c.BoundaryCurve = c.BoundingBox.Perimeter(); } var bundlingsettings = new BundlingSettings() { EdgeSeparation = 5, CreateUnderlyingPolyline = true }; var router = new SplineRouter(graph, 10.0, 1.25, Math.PI / 6.0, bundlingsettings); router.Run(); graph.UpdateBoundingBox(); }
// Abstract the creation of the GeometryGraph and the node.CreateBoundary calls away in // a single call on the Diagram. public void Run() { drawingGraph.CreateGeometryGraph(); foreach (var node in drawingGraph.Nodes) { if (node is LabeledNode ln) { ln.CreateBoundary(); } } var routingSettings = new Microsoft.Msagl.Core.Routing.EdgeRoutingSettings { UseObstacleRectangles = true, BendPenalty = 100, EdgeRoutingMode = Microsoft.Msagl.Core.Routing.EdgeRoutingMode.StraightLine }; var settings = new SugiyamaLayoutSettings { ClusterMargin = 50, PackingAspectRatio = 3, PackingMethod = Microsoft.Msagl.Core.Layout.PackingMethod.Columns, RepetitionCoefficientForOrdering = 0, EdgeRoutingSettings = routingSettings, NodeSeparation = 50, LayerSeparation = 150 }; LayoutHelpers.CalculateLayout(drawingGraph.GeometryGraph, settings, null); _run(); }
private Dictionary <int, Tuple <double, double> > GeneratePositionsTable(List <MeasureSegmentController> partMeasureSegment, List <int> positionIndexes, double startingPosition) { double staffSpace = ViewModel.ViewModelLocator.Instance.Main.CurrentPageLayout.StaffSpace.MMToWPFUnit(); Dictionary <int, int> durationOfPosition = GetDurationOfPosition(partMeasureSegment, positionIndexes); int shortestDuration = durationOfPosition.Values.Where(x => x > 0).Min(); Dictionary <int, Tuple <double, double> > positions = new Dictionary <int, Tuple <double, double> >(); double currentStartPosition = startingPosition; for (int i = 0; i < durationOfPosition.Count; i++) { if (i == 0) { int currentDuration = durationOfPosition[positionIndexes[i]]; double previewSpacing = staffSpace * LayoutHelpers.SpacingValue(currentDuration, shortestDuration, 0.6); positions.Add(positionIndexes[i], Tuple.Create(currentStartPosition, previewSpacing)); } else { int currentDuration = durationOfPosition[positionIndexes[i]]; double previewSpacing = staffSpace * LayoutHelpers.SpacingValue(currentDuration, shortestDuration, 0.6); currentStartPosition += previewSpacing; positions.Add(positionIndexes[i], Tuple.Create(currentStartPosition, previewSpacing)); } } return(positions); }
static void Main(string[] args) { var drawingGraph = new Graph(); drawingGraph.AddNode("A").LabelText = "AText"; drawingGraph.AddNode("B").LabelText = "BText"; var e = drawingGraph.AddEdge("A", "B"); // now the drawing graph has nodes A,B and and an edge A -> B\ // the geometry graph is still null, so we are going to create it e.LabelText = "from " + e.SourceNode.LabelText + " to " + e.TargetNode.LabelText; drawingGraph.CreateGeometryGraph(); // Now the drawing graph elements point to the corresponding geometry elements, // however the node boundary curves are not set. // Setting the node boundaries foreach (var n in drawingGraph.Nodes) { // Ideally we should look at the drawing node attributes, and figure out, the required node size // I am not sure how to find out the size of a string rendered in SVG. Here, we just blindly assign to each node a rectangle with width 60 and height 40, and round its corners. n.GeometryNode.BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(60, 40, 3, 2, new Point(0, 0)); } AssignLabelsDimensions(drawingGraph); LayoutHelpers.CalculateLayout(drawingGraph.GeometryGraph, new SugiyamaLayoutSettings(), null); PrintSvgAsString(drawingGraph); }
public EditFormView(EditFormViewModel editFormViewModel) { this.editFormEntityViewModel = editFormViewModel.EditFormEntityViewModel; InitializeComponent(); LayoutHelpers.AddToolBarItems(this.ToolbarItems, this.editFormEntityViewModel.Buttons); Title = this.editFormEntityViewModel.FormSettings.Title; }
/// <summary> /// Simple unconstrained layout of graph used by multiscale layout /// </summary> /// <param name="graph"></param> /// <param name="edgeLengthMultiplier"></param> /// <param name="level">double in range [0,1] indicates how far down the multiscale stack we are /// 1 is at the top, 0 at the bottom, controls repulsive force strength and ideal edge length</param> private void SimpleLayout(GeometryGraph graph, double level, double edgeLengthMultiplier) { var settings = new FastIncrementalLayoutSettings { MaxIterations = 10, MinorIterations = 3, GravityConstant = 1.0 - level, RepulsiveForceConstant = Math.Log(edgeLengthMultiplier * level * 500 + Math.E), InitialStepSize = 0.6 }; foreach (var e in graph.Edges) { e.Length *= Math.Log(level * 500 + Math.E); } settings.InitializeLayout(graph, settings.MinConstraintLevel); do { #pragma warning disable 618 LayoutHelpers.CalculateLayout(graph, settings, null); #pragma warning restore 618 } while (settings.Iterations < settings.MaxIterations); }
public IViewerEdge RouteEdge(DrawingEdge drawingEdge) { var geomEdge = GeometryGraphCreator.CreateGeometryEdgeFromDrawingEdge(drawingEdge); var geomGraph = drawingGraph.GeometryGraph; LayoutHelpers.RouteAndLabelEdges(geomGraph, drawingGraph.LayoutAlgorithmSettings, new[] { geomEdge }); return(CreateEdge(drawingEdge, drawingGraph.LayoutAlgorithmSettings as LgLayoutSettings)); }
void EnlargeNode(IViewerNode node) { var geomNode = node.DrawingObject.GeometryObject as AglNode; geomNode.BoundaryCurve = geomNode.BoundaryCurve.OffsetCurve(geomNode.BoundingBox.Width / 2, new Point(1, 0)); LayoutHelpers.IncrementalLayout(gViewer.Graph.GeometryGraph, geomNode, gViewer.Graph.LayoutAlgorithmSettings as SugiyamaLayoutSettings); }
private static void LayoutGraph(GeometryGraph geometryGraph) { var settings = new Microsoft.Msagl.Layout.MDS.MdsLayoutSettings(); settings.EdgeRoutingSettings.EdgeRoutingMode = Microsoft.Msagl.Core.Routing.EdgeRoutingMode.StraightLine; LayoutHelpers.CalculateLayout(geometryGraph, settings, null); Console.WriteLine("layout done"); }
private void LayoutLinkedShapes(Graph graph, out Microsoft.Msagl.Core.Layout.GeometryGraph geometry) { var geomGraph = new Microsoft.Msagl.Core.Layout.GeometryGraph(); var layoutSettings = new Microsoft.Msagl.Layout.Layered.SugiyamaLayoutSettings(); Microsoft.Msagl.Core.Layout.Node EnsureNode(Node node) { var res = geomGraph.Nodes.FirstOrDefault(n => n.UserData == node); if (res == null) { var geomNode = new Microsoft.Msagl.Core.Layout.Node( Microsoft.Msagl.Core.Geometry.Curves.CurveFactory.CreateRectangle( ShapeSize, ShapeSize, new Microsoft.Msagl.Core.Geometry.Point() ), node ); geomGraph.Nodes.Add(geomNode); return(geomNode); } return(res); } foreach (var l in graph.Links) { var n1 = EnsureNode(l.Node1); var n2 = EnsureNode(l.Node2); var e = new Microsoft.Msagl.Core.Layout.Edge(n1, n2); geomGraph.Edges.Add(e); } LayoutHelpers.CalculateLayout(geomGraph, layoutSettings, null); foreach (var kv in nodesAndShapes) { var pos = geomGraph.Nodes.FirstOrDefault(n => n.UserData == kv.Key)?.Center; if (pos.HasValue) { kv.Value.X = (int)pos.Value.X + ShapeSize; kv.Value.Y = Diagram.Height - (int)pos.Value.Y + ShapeSize / 2; } } geometry = geomGraph; }
private void AddContent() { LayoutHelpers.AddToolBarItems(this.ToolbarItems, this.textPageScreenViewModel.Buttons); Title = this.textPageScreenViewModel.Title; Content = new Grid { Children = { new ScrollView { Content = GetScrollViewContent() }, GetTransitionGrid() } }; }
private void Update() { if (reposition) { PositionNodes(); Center(); reposition = false; } if (redraw) { RedrawEdges(); redraw = false; } if (relayout) { if (graphTask == null) { UpdateNodes(); graphTask = Task.Run(() => { LayoutHelpers.CalculateLayout(graph, settings, null); LayoutHelpers.RouteAndLabelEdges(graph, settings, graph.Edges); }); Forget(graphTask, () => { graphTask = null; reposition = true; redraw = true; }); relayout = false; } } if (reroute) { if (graphTask == null) { UpdateNodes(); graphTask = Task.Run(() => LayoutHelpers.RouteAndLabelEdges(graph, settings, graph.Edges)); Forget(graphTask, () => { graphTask = null; redraw = true; }); reroute = false; } } }
private void ArrangeMeasureContent(bool advancedLayout) //TODO split on more methods { SetPartSystemDimensions(_size.Width, _size.Height); SetPartSegmentCanvasPositions(advancedLayout); List <List <MeasureSegmentController> > partMeasuresList = GetMeasuresList(); if (!advancedLayout) { foreach (var partMeasureSegment in partMeasuresList) { Dictionary <int, double> durationTable = new Dictionary <int, double>(); List <List <int> > indexes = GetAllMeasureIndexes(partMeasureSegment); double measureWidth = partMeasureSegment.Select(x => x.Width).Max(); Tuple <double, double, double> attributesWidth = LayoutHelpers.GetAttributesWidth(partMeasureSegment); double maxClef = attributesWidth.Item1; double maxKey = attributesWidth.Item2; double maxTime = attributesWidth.Item3; durationTable.Add(-3, 0); durationTable.Add(-2, maxClef); durationTable.Add(-1, maxKey + maxClef); durationTable.Add(0, maxClef + maxKey + maxTime); List <int> positionIndexes = indexes.SelectMany(x => x).Distinct().ToList(); positionIndexes.Sort(); double startingPosition = durationTable[0] + _attributesLayout.AttributesRightOffset.TenthsToWPFUnit(); Dictionary <int, Tuple <double, double> > positions = GeneratePositionsTable(partMeasureSegment, positionIndexes, startingPosition); double targetWidth = measureWidth - durationTable[0]; LayoutHelpers.StretchPositionsToWidth(targetWidth, positions, positionIndexes); AddPositionsToDurationTable(durationTable, positionIndexes, positions); int lastDuration = durationTable.Keys.Max() + 1; //! adds one more which is measure duration (rigth barline position / calculating center position) durationTable.Add(lastDuration, measureWidth); //! Update measure segments content with calculated duration position table foreach (MeasureSegmentController measureSegment in partMeasureSegment) { measureSegment.ArrangeUsingDurationTable(durationTable); RedrawBeams(measureSegment, durationTable); } } } }
private static void DoCustomLayout(List <NodeShape> nodeShapes, List <BinaryLinkShape> linkShapes, ModelRoot modelRoot) { GeometryGraph graph = new GeometryGraph(); CreateDiagramNodes(nodeShapes, graph); CreateDiagramLinks(linkShapes, graph); AddDesignConstraints(linkShapes, modelRoot, graph); LayoutHelpers.CalculateLayout(graph, modelRoot.LayoutAlgorithmSettings, null); // Move model to positive axis. graph.UpdateBoundingBox(); graph.Translate(new Point(-graph.Left, -graph.Bottom)); UpdateNodePositions(graph); UpdateConnectors(graph); }
private void AddContent() { LayoutHelpers.AddToolBarItems(this.ToolbarItems, this.listPageCollectionViewModel.Buttons); Title = this.listPageCollectionViewModel.FormSettings.Title; Content = new Grid { Children = { ( page = new StackLayout { Padding = new Thickness(30), Children = { new Label { Style = LayoutHelpers.GetStaticStyleResource("HeaderStyle") } .AddBinding(Label.TextProperty, new Binding(nameof(ListPageCollectionViewModelBase.Title))), new CollectionView { Style = LayoutHelpers.GetStaticStyleResource("ListFormCollectionViewStyle"), ItemTemplate = LayoutHelpers.GetCollectionViewItemTemplate ( this.listPageCollectionViewModel.FormSettings.ItemTemplateName, this.listPageCollectionViewModel.FormSettings.Bindings ) } .AddBinding(ItemsView.ItemsSourceProperty, new Binding(nameof(ListPageCollectionViewModel <Domain.EntityModelBase> .Items))) } } ), ( transitionGrid = new Grid().AssignDynamicResource ( VisualElement.BackgroundColorProperty, "PageBackgroundColor" ) ) } }; }
/// <summary> /// The actual layout process /// </summary> protected override void RunInternal() { var openedClusters = modifiedNodes.OfType <Cluster>().Where(cl => !cl.IsCollapsed).ToArray(); if (openedClusters.Length > 0) { new InitialLayoutByCluster(graph, openedClusters, clusterSettings).Run(); } Visit(graph.RootCluster); // routing edges that cross cluster boundaries InitialLayoutByCluster.RouteParentEdges(graph, clusterSettings(graph.RootCluster).EdgeRoutingSettings); LayoutHelpers.RouteAndLabelEdges(graph, clusterSettings(graph.RootCluster), graph.Edges.Where(BetweenClusterOnTheRightLevel)); graph.UpdateBoundingBox(); ProgressComplete(); }
int ProcessMsaglFile(string inputFile) { try { LayoutAlgorithmSettings ls; var geomGraph = GeometryGraphReader.CreateFromFile(inputFile, out ls); if (ls == null) { ls = PickLayoutAlgorithmSettings(geomGraph.Edges.Count, geomGraph.Nodes.Count); } LayoutHelpers.CalculateLayout(geomGraph, ls, null); inputFile = SetMsaglOutputFileName(inputFile); WriteGeomGraph(inputFile, geomGraph); DumpFileToConsole(inputFile); } catch (Exception e) { //Console.WriteLine(e.ToString()); Console.WriteLine(e.Message); return(-1); } return(0); }
private void LayoutGraph(GeometryGraph geometryGraph) { if (this.NeedToCalculateLayout) { try { LayoutHelpers.CalculateLayout(geometryGraph, this.Graph.LayoutAlgorithmSettings, this.CancelToken); //if (MsaglFileToSave != null) //{ // drawingGraph.Write(MsaglFileToSave); // Console.WriteLine("saved into {0}", MsaglFileToSave); // Environment.Exit(0); //} } catch (OperationCanceledException) { //swallow this exception } } }
void ProcessGraph() { try { selectedObject = null; if (drawingGraph == null) { return; } graphCanvas.Visibility = Visibility.Hidden; // hide canvas while we lay it out asynchronously. ClearGraphViewer(); // Make nodes and edges if (LargeGraphBrowsing) { LayoutEditingEnabled = false; var lgsettings = new LgLayoutSettings( () => new Rectangle(0, 0, graphCanvas.RenderSize.Width, graphCanvas.RenderSize.Height), () => Transform, DpiX, DpiY, () => 0.1 * DpiX / CurrentScale /*0.1 inch*/); drawingGraph.LayoutAlgorithmSettings = lgsettings; lgsettings.ViewerChangeTransformAndInvalidateGraph += OGraphChanged; } if (NeedToCalculateLayout) { drawingGraph.CreateGeometryGraph(); //forcing the layout recalculation geometryGraphUnderLayout = drawingGraph.GeometryGraph; } PushGeometryIntoLayoutGraph(); graphCanvas.RaiseEvent(new RoutedEventArgs(LayoutStartEvent)); LayoutHelpers.CalculateLayout(geometryGraphUnderLayout, drawingGraph.LayoutAlgorithmSettings); TransferLayoutDataToWpf(); } catch (Exception e) { MessageBox.Show(e.ToString()); } }
static internal GeometryGraph CreateAndLayoutGraph() { double w = 30; double h = 20; GeometryGraph graph = new GeometryGraph(); Node a = new Node(new Ellipse(w, h, new P()), "a"); Node b = new Node(CurveFactory.CreateRectangle(w, h, new P()), "b"); Node c = new Node(CurveFactory.CreateRectangle(w, h, new P()), "c"); Node d = new Node(CurveFactory.CreateRectangle(w, h, new P()), "d"); graph.Nodes.Add(a); graph.Nodes.Add(b); graph.Nodes.Add(c); graph.Nodes.Add(d); Edge e = new Edge(a, b) { Length = 10 }; graph.Edges.Add(e); graph.Edges.Add(new Edge(b, c) { Length = 3 }); graph.Edges.Add(new Edge(b, d) { Length = 4 }); //graph.Save("c:\\tmp\\saved.msagl"); var settings = new Microsoft.Msagl.Layout.MDS.MdsLayoutSettings(); LayoutHelpers.CalculateLayout(graph, settings, null); return(graph); }
public ChildFormPageCS(IValidatable formValidatable) { this.formValidatable = formValidatable; this.formLayout = (EditFormLayout)this.formValidatable.GetType() .GetProperty(nameof(FormValidatableObject <string> .FormLayout)) .GetValue(this.formValidatable); Content = new AbsoluteLayout { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Fill, Children = { new ContentView { Content = new StackLayout { Style = LayoutHelpers.GetStaticStyleResource("ChildFormPopupViewStyle"), Children = { new Grid { Style = LayoutHelpers.GetStaticStyleResource("PopupHeaderStyle"), Children = { new Label { Style = LayoutHelpers.GetStaticStyleResource("PopupHeaderLabelStyle"), }.AddBinding(Label.TextProperty, new Binding("Title")) } }, new ScrollView { Style = LayoutHelpers.GetStaticStyleResource("ChildFormPopupScrollViewStyle"), Content = this.formLayout.ControlGroupBoxList.Aggregate ( new StackLayout(), (stackLayout, controlBox) => { if (controlBox.IsVisible == false) { return(stackLayout); } stackLayout.Children.Add ( new Label { Style = LayoutHelpers.GetStaticStyleResource("EditFormGroupHeaderStyle"), BindingContext = controlBox } .AddBinding ( Label.TextProperty, GetHeaderBinding(controlBox.HeaderBindings, $"{nameof(ControlGroupBox.GroupHeader)}") ) ); stackLayout.Children.Add ( new StackLayout { VerticalOptions = LayoutOptions.StartAndExpand, BindingContext = controlBox } .AddBinding(BindableLayout.ItemsSourceProperty, new Binding(".")) .SetDataTemplateSelector(EditFormViewHelpers.QuestionTemplateSelector) ); return(stackLayout); } ) }, new BoxView { Style = LayoutHelpers.GetStaticStyleResource("PopupFooterSeparatorStyle") }, new Grid { Style = LayoutHelpers.GetStaticStyleResource("PopupFooterStyle"), ColumnDefinitions = { new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) } }, Children = { new Button { Style = LayoutHelpers.GetStaticStyleResource("PopupCancelButtonStyle") } .AddBinding(Button.CommandProperty, new Binding("CancelCommand")) .SetGridColumn(1), new Button { Style = LayoutHelpers.GetStaticStyleResource("PopupAcceptButtonStyle") } .AddBinding(Button.CommandProperty, new Binding("SubmitCommand")) .SetGridColumn(2) } } } } } .AssignDynamicResource(VisualElement.BackgroundColorProperty, "PopupViewBackgroundColor") .SetAbsoluteLayoutBounds(new Rectangle(0, 0, 1, 1)) .SetAbsoluteLayoutFlags(AbsoluteLayoutFlags.All) } }; this.BackgroundColor = Color.Transparent; Visual = VisualMarker.Material; this.BindingContext = this.formValidatable; BindingBase GetHeaderBinding(MultiBindingDescriptor multiBindingDescriptor, string bindingName) { if (multiBindingDescriptor == null) { return(new Binding(bindingName)); } return(new MultiBinding { StringFormat = multiBindingDescriptor.StringFormat, Bindings = multiBindingDescriptor.Fields.Select ( field => new Binding($"{nameof(ControlGroupBox.BindingPropertiesDictionary)}[{field.ToBindingDictionaryKey()}].{nameof(IValidatable.Value)}") ) .Cast <BindingBase>() .ToList() }); } }
public ReadOnlyMultiSelectPageCS(IReadOnly multiSelectReadOnly) { this.multiSelectReadOnly = multiSelectReadOnly; this.multiSelectTemplateDescriptor = (MultiSelectTemplateDescriptor)this.multiSelectReadOnly.GetType() .GetProperty(nameof(MultiSelectReadOnlyObject <ObservableCollection <string>, string> .MultiSelectTemplate)) .GetValue(this.multiSelectReadOnly); Content = new AbsoluteLayout { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Fill, Children = { new ContentView { Content = new StackLayout { Style = LayoutHelpers.GetStaticStyleResource("MultiSelectPopupViewStyle"), Children = { new Grid { Style = LayoutHelpers.GetStaticStyleResource("PopupHeaderStyle"), Children = { new Label { Style = LayoutHelpers.GetStaticStyleResource("PopupHeaderLabelStyle"), }.AddBinding(Label.TextProperty, new Binding("Title")) } }, new Grid { Children = { new CollectionView { Style = LayoutHelpers.GetStaticStyleResource("MultiSelectPopupCollectionViewStyle"), ItemTemplate = EditFormViewHelpers.GetMultiSelectItemTemplateSelector(this.multiSelectTemplateDescriptor) } .AddBinding(ItemsView.ItemsSourceProperty, new Binding("Items")) .AddBinding(SelectableItemsView.SelectedItemsProperty, new Binding("SelectedItems")), new BoxView() } }, new BoxView { Style = LayoutHelpers.GetStaticStyleResource("PopupFooterSeparatorStyle") }, new Grid { Style = LayoutHelpers.GetStaticStyleResource("PopupFooterStyle"), ColumnDefinitions = { new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) } }, Children = { new Button { Style = LayoutHelpers.GetStaticStyleResource("PopupCancelButtonStyle") } .AddBinding(Button.CommandProperty, new Binding("CancelCommand")) .SetGridColumn(2) } } } } } .AssignDynamicResource(VisualElement.BackgroundColorProperty, "PopupViewBackgroundColor") .SetAbsoluteLayoutBounds(new Rectangle(0, 0, 1, 1)) .SetAbsoluteLayoutFlags(AbsoluteLayoutFlags.All) } }; this.BackgroundColor = Color.Transparent; Visual = VisualMarker.Material; this.BindingContext = this.multiSelectReadOnly; }
public ReadOnlyChildFormArrayPageCS(IReadOnly formArrayReadOnly) { this.formArrayReadOnly = formArrayReadOnly; this.formsCollectionDisplayTemplateDescriptor = (FormsCollectionDisplayTemplateDescriptor)this.formArrayReadOnly.GetType() .GetProperty(nameof(FormArrayReadOnlyObject <ObservableCollection <string>, string> .FormsCollectionDisplayTemplate)) .GetValue(this.formArrayReadOnly); Content = new AbsoluteLayout { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Fill, Children = { new ContentView { Content = new StackLayout { Style = LayoutHelpers.GetStaticStyleResource("FormArrayPopupViewStyle"), Children = { new Grid { Style = LayoutHelpers.GetStaticStyleResource("PopupHeaderStyle"), Children = { new Label { Style = LayoutHelpers.GetStaticStyleResource("PopupHeaderLabelStyle"), }.AddBinding(Label.TextProperty, new Binding(nameof(FormArrayReadOnlyObject <ObservableCollection <string>, string> .Title))) } }, new CollectionView { Style = LayoutHelpers.GetStaticStyleResource("FormArrayPopupCollectionViewStyle"), ItemTemplate = LayoutHelpers.GetCollectionViewItemTemplate ( this.formsCollectionDisplayTemplateDescriptor.TemplateName, this.formsCollectionDisplayTemplateDescriptor.Bindings ) } .AddBinding(ItemsView.ItemsSourceProperty, new Binding(nameof(FormArrayReadOnlyObject <ObservableCollection <string>, string> .Items))) .AddBinding(SelectableItemsView.SelectionChangedCommandProperty, new Binding(nameof(FormArrayReadOnlyObject <ObservableCollection <string>, string> .SelectionChangedCommand))) .AddBinding(SelectableItemsView.SelectedItemProperty, new Binding(nameof(FormArrayReadOnlyObject <ObservableCollection <string>, string> .SelectedItem))), new BoxView { Style = LayoutHelpers.GetStaticStyleResource("PopupFooterSeparatorStyle") }, new Grid { Style = LayoutHelpers.GetStaticStyleResource("PopupFooterStyle"), ColumnDefinitions = { new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) } }, Children = { new Button { Style = LayoutHelpers.GetStaticStyleResource("PopupDetailButtonStyle") } .AddBinding(Button.CommandProperty, new Binding(nameof(FormArrayReadOnlyObject <ObservableCollection <string>, string> .DetailCommand))) .SetGridColumn(2), new Button { Style = LayoutHelpers.GetStaticStyleResource("PopupCancelButtonStyle") } .AddBinding(Button.CommandProperty, new Binding(nameof(FormArrayReadOnlyObject <ObservableCollection <string>, string> .CancelCommand))) .SetGridColumn(3) } } } } } .AssignDynamicResource(VisualElement.BackgroundColorProperty, "PopupViewBackgroundColor") .SetAbsoluteLayoutBounds(new Rectangle(0, 0, 1, 1)) .SetAbsoluteLayoutFlags(AbsoluteLayoutFlags.All) } }; this.BackgroundColor = Color.Transparent; Visual = VisualMarker.Material; this.BindingContext = this.formArrayReadOnly; }
private void AddContent() { LayoutHelpers.AddToolBarItems(this.ToolbarItems, this.editFormEntityViewModel.Buttons); Title = editFormEntityViewModel.FormSettings.Title; BindingBase GetHeaderBinding(MultiBindingDescriptor multiBindingDescriptor, string bindingName) { if (multiBindingDescriptor == null) { return(new Binding(bindingName)); } return(new MultiBinding { StringFormat = multiBindingDescriptor.StringFormat, Bindings = multiBindingDescriptor.Fields.Select ( field => new Binding($"{nameof(ControlGroupBox.BindingPropertiesDictionary)}[{field.ToBindingDictionaryKey()}].{nameof(IValidatable.Value)}") ) .Cast <BindingBase>() .ToList() }); } Content = new Grid { Children = { ( page = new StackLayout { Padding = new Thickness(30), Children = { new Label { Style = LayoutHelpers.GetStaticStyleResource("HeaderStyle") } .AddBinding ( Label.TextProperty, GetHeaderBinding ( editFormEntityViewModel.FormSettings.HeaderBindings, $"{nameof(EditFormEntityViewModelBase.FormSettings)}.{nameof(DataFormSettingsDescriptor.Title)}" ) ), new ScrollView { Content = editFormEntityViewModel.FormLayout.ControlGroupBoxList.Aggregate ( new StackLayout(), (stackLayout, controlBox) => { if (controlBox.IsVisible == false) { return(stackLayout); } stackLayout.Children.Add ( new Label { Style = LayoutHelpers.GetStaticStyleResource("EditFormGroupHeaderStyle"), BindingContext = controlBox } .AddBinding ( Label.TextProperty, GetHeaderBinding(controlBox.HeaderBindings, $"{nameof(ControlGroupBox.GroupHeader)}") ) ); stackLayout.Children.Add ( new StackLayout { VerticalOptions = LayoutOptions.StartAndExpand, BindingContext = controlBox } .AddBinding(BindableLayout.ItemsSourceProperty, new Binding(".")) .SetDataTemplateSelector(EditFormViewHelpers.QuestionTemplateSelector) ); return(stackLayout); } ) } } } ), ( transitionGrid = new Grid().AssignDynamicResource ( VisualElement.BackgroundColorProperty, "PageBackgroundColor" ) ) } }; }
//takes a target Tree object and builds actual game nodes for it - using MSAGL as an intermediate representation for layout public void BuildTree(Tree target) { if (target == null) { return; //do not attempt to build a null tree - this means that a syntax error happened in a newick file } GameManager.DebugLog("Building tree with layout: " + eventManager.Current_Tree_State); ResetTreeContainer(); GeometryGraph asMSAGL = ToMSALGraph(target); List <GameObject> generatedNodes = new List <GameObject>(); //define how we want the tree to be layed out LayoutAlgorithmSettings settings; switch (eventManager.Current_Tree_State) { default: case InputEventManager.TreeState.BasicTree: settings = new Microsoft.Msagl.Layout.Layered.SugiyamaLayoutSettings(); break; case InputEventManager.TreeState.TerrainTree: case InputEventManager.TreeState.CircularTree: settings = new FastIncrementalLayoutSettings(); break; } //apply some extra settings and layout the graph according to all settings settings.EdgeRoutingSettings.EdgeRoutingMode = Microsoft.Msagl.Core.Routing.EdgeRoutingMode.StraightLine; settings.PackingMethod = PackingMethod.Compact; LayoutHelpers.CalculateLayout(asMSAGL, settings, null); //we want world space 0, 0 to be equivalent to graph space 0, 0 float offSetX = (float)asMSAGL.Nodes[0].Center.X; float offSetY = (float)asMSAGL.Nodes[0].Center.Y; //msal graph edge weights are enormous, like hundreds of meters of in world space - scale it down float scaleFactor = eventManager.Current_Tree_State == InputEventManager.TreeState.TerrainTree ? 1f / 30f : 1f / 250f; //build game objects using msagl graph as spatial layout foreach (Microsoft.Msagl.Core.Layout.Node node in asMSAGL.Nodes) { float x = ((float)node.Center.X - offSetX) * scaleFactor; float y = ((float)node.Center.Y - offSetY) * scaleFactor; GameObject newNode = Instantiate(nodePrefab, new Vector3( treeContainer.transform.position.x + x, treeContainer.transform.position.y + y, treeContainer.transform.position.z ), Quaternion.identity); newNode.transform.SetParent(treeContainer.transform); newNode.GetComponent <BasicNodeBehaviour>().attachNodeInfo((Node)node.UserData); newNode.GetComponentInChildren <InfoOnHover>()._Init(); node.UserData = newNode; generatedNodes.Add(newNode); foreach (Edge edge in node.Edges) { if (edge.Target == node) { Line l = newNode.transform.Find("Renderer").gameObject.AddComponent <Line>(); l.gameObject1 = newNode; l.gameObject2 = (GameObject)edge.Source.UserData; newNode.transform.SetParent(((GameObject)edge.Source.UserData).transform); if (newNode.GetComponent <BasicNodeBehaviour>().getAttachedNodeInfo().weightToParentSet()) { l.setLabel("" + newNode.GetComponent <BasicNodeBehaviour>().getAttachedNodeInfo().getWeightToParent()); } else { l.setLabel(""); } } } } if (eventManager.Current_Tree_State == InputEventManager.TreeState.TerrainTree) { Vector3 translation = new Vector3(0, -4, 0); treeContainer.transform.Translate(translation); treeContainer.transform.Rotate(90, 0, 0); List <GameObject> leafNodesList = new List <GameObject>(); foreach (GameObject node in generatedNodes) { //scale up the nodes a bit to make them clearer within the terrain float scale = node.GetComponentInChildren <MaintainNodeScale>().targetScale; node.GetComponentInChildren <MaintainNodeScale>().targetScale = 2 * scale; node.transform.hasChanged = true; if (node.GetComponent <BasicNodeBehaviour>().getAttachedNodeInfo().getNumberOfChildren() == 0) { leafNodesList.Add(node); } } generatedNodes[0].GetComponentInChildren <MaintainNodeScale>().targetScale = 4f; GameManager.DebugLog("Found " + leafNodesList.Count + " leaf nodes"); TreeTerrainBehaviour.instance.Activate(); TreeTerrainBehaviour.instance.ResetHeights(); leafNodes = leafNodesList.ToArray(); EnableOnFrameLoading(); } else { DisableOnFrameLoading(); //the player won't be moving while we aren't looking at terrain so we'll reset their position } if (eventManager.Draw_Tree_In_3D) { TreeConverter3D.Convert(treeContainer.transform.GetChild(0).gameObject); } //as a last step, reset the position of the player so they are close to the root of whatever tree they built player.GetComponent <PositionResetter>().ResetPosition(); }
private void AddContent() { AddToolBarItems(); Title = editFormEntityViewModel.FormSettings.Title; Content = new Grid { Children = { ( page = new StackLayout { Padding = new Thickness(30), Children = { new Label { Style = LayoutHelpers.GetStaticStyleResource("HeaderStyle") } .AddBinding(Label.TextProperty, new Binding("FormSettings.Title")), new CollectionView { SelectionMode = SelectionMode.Single, ItemTemplate = EditFormViewHelpers.QuestionTemplateSelector } .AddBinding(ItemsView.ItemsSourceProperty, new Binding("Properties")), } } ), ( transitionGrid = new Grid().AssignDynamicResource ( VisualElement.BackgroundColorProperty, "PageBackgroundColor" ) ) } }; void AddToolBarItems() { foreach (var button in editFormEntityViewModel.Buttons) { this.ToolbarItems.Add(BuildToolbarItem(button)); } } ToolbarItem BuildToolbarItem(CommandButtonDescriptor button) => new ToolbarItem { AutomationId = button.ShortString, Text = button.LongString, //IconImageSource = new FontImageSource //{ // FontFamily = EditFormViewHelpers.GetFontAwesomeFontFamily(), // Glyph = FontAwesomeIcons.Solid[button.ButtonIcon], // Size = 20 //}, Order = ToolbarItemOrder.Primary, Priority = 0, CommandParameter = button } .AddBinding(MenuItem.CommandProperty, new Binding(button.Command)) .SetAutomationPropertiesName(button.ShortString); }
private View GetScrollViewContent() { page = new StackLayout { Padding = new Thickness(30), Children = { new Label { Text = this.textPageScreenViewModel.Title, Style = LayoutHelpers.GetStaticStyleResource("HeaderStyle") } } }; foreach (var group in textPageScreenViewModel.FormSettings.TextGroups) { page.Children.Add(GetGroupHeader(group)); foreach (LabelItemDescriptorBase item in group.Labels) { switch (item) { case LabelItemDescriptor labelItemDescriptor: page.Children.Add(GetLabelItem(labelItemDescriptor)); break; case HyperLinkLabelItemDescriptor hyperLinkLabelItemDescriptor: page.Children.Add(GetHyperLinkLabelItem(hyperLinkLabelItemDescriptor)); break; case FormattedLabelItemDescriptor formattedItemDescriptor: page.Children.Add(GetFornattedLabelItem(formattedItemDescriptor)); break; default: throw new ArgumentException($"{nameof(item)}: 615C881A-3EA5-4681-AD72-482E055E728E"); } } } return(page); Label GetFornattedLabelItem(FormattedLabelItemDescriptor formattedItemDescriptor) { Label formattedLabel = new Label { FormattedText = new FormattedString { Spans = { } } }; foreach (SpanItemDescriptorBase item in formattedItemDescriptor.Items) { switch (item) { case SpanItemDescriptor spanItemDescriptor: formattedLabel.FormattedText.Spans.Add(GetSpanItem(spanItemDescriptor)); break; case HyperLinkSpanItemDescriptor hyperLinkSpanItemDescriptor: formattedLabel.FormattedText.Spans.Add(GetHyperLinkSpanItem(hyperLinkSpanItemDescriptor)); break; default: throw new ArgumentException($"{nameof(item)}: BD90BDA3-31E9-4FCC-999E-2486CB527E30"); } } return(formattedLabel); } Span GetHyperLinkSpanItem(HyperLinkSpanItemDescriptor spanItemDescriptor) => new Span { Text = spanItemDescriptor.Text, Style = LayoutHelpers.GetStaticStyleResource("TextFormHyperLinkSpanStyle"), GestureRecognizers = { new TapGestureRecognizer { CommandParameter = spanItemDescriptor.Url } .AddBinding(TapGestureRecognizer.CommandProperty, new Binding(path: "TapCommand")) } }; Span GetSpanItem(SpanItemDescriptor spanItemDescriptor) => new Span { Text = spanItemDescriptor.Text, Style = LayoutHelpers.GetStaticStyleResource("TextFormItemSpanStyle") }; Label GetHyperLinkLabelItem(HyperLinkLabelItemDescriptor labelItemDescriptor) => new Label { Text = labelItemDescriptor.Text, Style = LayoutHelpers.GetStaticStyleResource("TextFormHyperLinkLabelStyle"), GestureRecognizers = { new TapGestureRecognizer { CommandParameter = labelItemDescriptor.Url } .AddBinding(TapGestureRecognizer.CommandProperty, new Binding(path: "TapCommand")) } }; Label GetLabelItem(LabelItemDescriptor labelItemDescriptor) => new Label { Text = labelItemDescriptor.Text, Style = LayoutHelpers.GetStaticStyleResource("TextFormItemLabelStyle") }; Label GetGroupHeader(TextGroupDescriptor textGroupDescriptor) => new Label { Text = textGroupDescriptor.Title, Style = LayoutHelpers.GetStaticStyleResource("TextFormGroupHeaderStyle") }; }
public static void LayeredLayoutAbc() { double w = 30; double h = 20; GeometryGraph graph = new GeometryGraph(); MSAGLNode a = new MSAGLNode(new Ellipse(w, h, new Point()), "a"); MSAGLNode b = new MSAGLNode(CurveFactory.CreateRectangle(w, h, new Point()), "b"); MSAGLNode c = new MSAGLNode(CurveFactory.CreateRectangle(w, h, new Point()), "c"); graph.Nodes.Add(a); graph.Nodes.Add(b); graph.Nodes.Add(c); Edge ab = new Edge(a, b) { Length = 10 }; Edge bc = new Edge(b, c) { Length = 3 }; graph.Edges.Add(ab); graph.Edges.Add(bc); var settings = new SugiyamaLayoutSettings(); LayoutHelpers.CalculateLayout(graph, settings, null); WriteMessage("Layout progressed"); /*WriteMessage(""); * WriteMessage("Segments A->B"); * //OutputCurve(ab.Curve); * * WriteMessage(""); * WriteMessage("Segments B->C"); * //OutputCurve(bc.Curve); * * WriteMessage(""); * WriteMessage("Segments C->A"); * //OutputCurve(ca.Curve); * * foreach (var node in graph.Nodes) * { * WriteMessage(string.Format("{0}: {1} {2}", node.UserData, node.Center.X, node.Center.Y)); * }*/ /*var canvas = HtmlContext.document.getElementById("drawing").As<HtmlCanvasElement>(); * var ctx = canvas.getContext("2d").As<CanvasRenderingContext2D>(); * * var canvasHeight = canvas.height; * * var bounds = calcBounds(graph.Nodes); * * var xScale = canvas.width / bounds.Width; * var yScale = canvas.height / bounds.Height; * * var xShift = -bounds.Left * xScale; * var yShift = -(canvas.height - bounds.Top) * yScale; * * WriteMessage(string.Format("Scaling : {0} {1}", xScale, yScale)); * WriteMessage(string.Format("Shifting : {0} {1}", xShift, yShift)); * * foreach (var msaglEdge in graph.Edges) * { * DrawEdge(ctx, msaglEdge, xShift, yShift, xScale, yScale, canvasHeight); * } * * foreach (var msaglNode in graph.Nodes) * { * DrawNode(ctx, msaglNode, xShift, yShift, xScale, yScale, canvasHeight); * }*/ }