Пример #1
0
        ///<inheritdoc/>
        protected override void ConfigureLayout()
        {
            OptionGroup toplevelGroup   = (OptionGroup)Handler.GetGroupByName(TOP_LEVEL);
            OptionGroup generalGroup    = (OptionGroup)toplevelGroup.GetGroupByName(GENERAL);
            string      operationChoice = (string)generalGroup[OPERATION].Value;

            transformer.Operation             = operationEnum[operationChoice];
            transformer.SubgraphLayoutEnabled = (bool)generalGroup[ACT_ON_SELECTION_ONLY].Value;

            transformer.RotationAngle = (int)toplevelGroup.GetValue(ROTATE, ROTATION_ANGLE);
            if ((bool)toplevelGroup.GetValue(ROTATE, APPLY_BEST_FIT_ROTATION) &&
                ((string)toplevelGroup.GetValue(GENERAL, OPERATION)).Equals(ROTATE))
            {
                CanvasControl cv = Context.Lookup <CanvasControl>();
                if (cv != null)
                {
                    var size = cv.InnerSize;
                    applyBestFitRotation      = true;
                    transformer.RotationAngle =
                        GraphTransformer.FindBestFitRotationAngle(CurrentLayoutGraph, size.Width, size.Height);
                }
            }
            else
            {
                applyBestFitRotation = false;
            }

            transformer.ScaleFactor   = (double)toplevelGroup.GetValue(SCALE, SCALE_FACTOR);
            transformer.ScaleNodeSize = (bool)toplevelGroup.GetValue(SCALE, SCALE_NODE_SIZE);

            transformer.TranslateX = (double)toplevelGroup.GetValue(TRANSLATE, TRANSLATE_X);
            transformer.TranslateY = (double)toplevelGroup.GetValue(TRANSLATE, TRANSLATE_Y);
            LayoutAlgorithm        = transformer;
        }
Пример #2
0
        private static void CommitValuesToForm(OptionHandler handler, GraphEditorForm form)
        {
            GraphControl         gc   = form.GraphControl;
            IGraph               g    = form.Graph;
            GraphEditorInputMode geim = form.GraphEditorInputMode;

            OptionGroup controlGroup = handler.GetGroupByName(UI_DEFAULTS);

            OptionGroup graphGroup   = handler.GetGroupByName(GRAPH_SETTINGS);
            OptionGroup sharingGroup = graphGroup.GetGroupByName(SHARING_SETTINGS);
            OptionGroup miscGroup    = handler.GetGroupByName(MISC_SETTINGS);

            gc.HitTestRadius           = (double)controlGroup[HitTestRadius].Value;
            geim.AutoRemoveEmptyLabels = (bool)controlGroup[AutoRemoveEmptyLabels].Value;

            form.GridWidth    = (int)controlGroup[GridWidth].Value;
            form.GridSnapType = (GridSnapTypes)controlGroup[GridSnapeType].Value;
            form.GridVisible  = (bool)controlGroup[GridVisible].Value;

            if (g != null)
            {
                g.NodeDefaults.Labels.AutoAdjustPreferredSize = g.EdgeDefaults.Labels.AutoAdjustPreferredSize = (bool)graphGroup[AutoAdjustPreferredLabelSize].Value;
                g.NodeDefaults.Ports.AutoCleanUp = g.EdgeDefaults.Ports.AutoCleanUp = (bool)graphGroup[AutoCleanupPorts].Value;

                g.NodeDefaults.ShareStyleInstance                  = (bool)sharingGroup[ShareDefaultNodeStyleInstance].Value;
                g.EdgeDefaults.ShareStyleInstance                  = (bool)sharingGroup[ShareDefaultEdgeStyleInstance].Value;
                g.NodeDefaults.Labels.ShareStyleInstance           = (bool)sharingGroup[ShareDefaultNodeLabelStyleInstance].Value;
                g.EdgeDefaults.Labels.ShareStyleInstance           = (bool)sharingGroup[ShareDefaultEdgeLabelStyleInstance].Value;
                g.NodeDefaults.Ports.ShareStyleInstance            = g.EdgeDefaults.Ports.ShareStyleInstance = (bool)sharingGroup[ShareDefaultPortStyleInstance].Value;
                g.NodeDefaults.Labels.ShareLayoutParameterInstance = (bool)sharingGroup[ShareDefaultNodeLabelModelParameter].Value;
                g.EdgeDefaults.Labels.ShareLayoutParameterInstance = (bool)sharingGroup[ShareDefaultEdgeLabelModelParameter].Value;
            }
            UndoEngine undoEngine = form.Graph.GetUndoEngine();

            if (undoEngine != null)
            {
                undoEngine.Size = (int)miscGroup[UndoEngine_Size].Value;
            }
        }
Пример #3
0
        protected override Task RunModule()
        {
            IMapperRegistry registry      = CurrentIGraph.MapperRegistry;
            OptionGroup     toplevelGroup = Handler.GetGroupByName(TOP_LEVEL);

            if ((bool)toplevelGroup[ClearAllConstraints].Value)
            {
                //deregistriere den Mapper, d.h. port constraints werden nicht mehr vorgegeben.
                registry.RemoveMapper(PortConstraintKeys.TargetPortConstraintDpKey);
                registry.RemoveMapper(PortConstraintKeys.SourcePortConstraintDpKey);
                sourcePCMapper = null;
                targetPCMapper = null;
            }
            else
            {
                registry.RemoveMapper(PortConstraintKeys.TargetPortConstraintDpKey);
                registry.RemoveMapper(PortConstraintKeys.SourcePortConstraintDpKey);

                if (sourcePCMapper == null)
                {
                    sourcePCMapper = new DictionaryMapper <IEdge, PortConstraint>();
                }
                if (targetPCMapper == null)
                {
                    targetPCMapper = new DictionaryMapper <IEdge, PortConstraint>();
                }

                string             scope      = (string)toplevelGroup[Scope].Value;
                OptionGroup        spcg       = (OptionGroup)toplevelGroup.GetGroupByName(SourcePortConstraints);
                OptionGroup        tpcg       = (OptionGroup)toplevelGroup.GetGroupByName(TargetPortConstraints);
                PortConstraintType sourceType = (PortConstraintType)spcg[PortConstraintStr].Value;
                bool strongSource             = (bool)spcg[StrongPortConstraint].Value;
                PortConstraintType targetType = (PortConstraintType)tpcg[PortConstraintStr].Value;
                bool strongTarget             = (bool)spcg[StrongPortConstraint].Value;

                foreach (IEdge edge in CurrentIGraph.Edges)
                {
                    bool isSelected = false;
                    switch (scope)
                    {
                    case ScopeAllEdges:
                        isSelected = true;
                        break;

                    case ScopeSelectedEdges:
                        isSelected = IsSelected(Context, edge);
                        break;

                    case ScopeEdgesAtSelectedNodes:
                        IPort sourcePort = edge.SourcePort;
                        IPort targetPort = edge.TargetPort;
                        isSelected = IsSelected(Context, sourcePort) ||
                                     IsSelected(Context, targetPort) ||
                                     IsSelected(Context, sourcePort.Owner) ||
                                     IsSelected(Context, targetPort.Owner);
                        break;
                    }
                    if (isSelected)
                    {
                        sourcePCMapper[edge] = CreatePortConstraint(edge, sourceType, true, strongSource);
                        targetPCMapper[edge] = CreatePortConstraint(edge, targetType, false, strongTarget);
                    }
                }

                registry.AddMapper(PortConstraintKeys.SourcePortConstraintDpKey,
                                   sourcePCMapper);
                registry.AddMapper(PortConstraintKeys.TargetPortConstraintDpKey,
                                   targetPCMapper);
            }
            return(Task.FromResult <object>(null));
        }
        private void ConfigureOutputRestrictions()
        {
            bool viewInfoIsAvailable = false;

            double[] visibleRect = GetVisibleRectangle();
            double   x = 0, y = 0, w = 0, h = 0;

            if (visibleRect != null)
            {
                viewInfoIsAvailable = true;
                x = visibleRect[0];
                y = visibleRect[1];
                w = visibleRect[2];
                h = visibleRect[3];
            }
            OptionGroup restrictionGroup = Handler.GetGroupByName(RESTRICTIONS);
            string      restrictionType  = (string)restrictionGroup[RESTRICT_OUTPUT].Value;
            OptionGroup currentGroup     = null;

            if (restrictionType != NONE)
            {
                if (restrictionType.Equals(OUTPUT_CAGE) || restrictionType.Equals(OUTPUT_ELLIPTICAL_CAGE))
                {
                    currentGroup = (OptionGroup)restrictionGroup.GetGroupByName(BOUNDS);
                }
                else
                {
                    currentGroup = (OptionGroup)restrictionGroup.GetGroupByName(restrictionType);
                }
            }
            switch (restrictionType)
            {
            case NONE: {
                organic.ComponentLayoutEnabled = true;
                organic.OutputRestriction      = OutputRestriction.None;
                break;
            }

            case OUTPUT_CAGE: {
                if (!viewInfoIsAvailable || !(bool)currentGroup[RECT_CAGE_USE_VIEW].Value)
                {
                    x = (double)currentGroup[CAGE_X].Value;
                    y = (double)currentGroup[CAGE_Y].Value;
                    w = (double)currentGroup[CAGE_WIDTH].Value;
                    h = (double)currentGroup[CAGE_HEIGHT].Value;
                }
                organic.OutputRestriction =
                    OutputRestriction.CreateRectangularCageRestriction(x, y, w, h);
                organic.ComponentLayoutEnabled = false;
                break;
            }

            case OUTPUT_AR: {
                double ratio;
                if ((bool)currentGroup[AR_CAGE_USE_VIEW].Value && viewInfoIsAvailable)
                {
                    ratio = w / h;
                }
                else
                {
                    ratio = (double)currentGroup[CAGE_RATIO].Value;
                }
                organic.OutputRestriction      = OutputRestriction.CreateAspectRatioRestriction(ratio);
                organic.ComponentLayoutEnabled = true;
                ((ComponentLayout)organic.ComponentLayout).PreferredSize = new YDimension(ratio * 100, 100);
                break;
            }

            case OUTPUT_ELLIPTICAL_CAGE: {
                if (!viewInfoIsAvailable || !((bool)currentGroup[RECT_CAGE_USE_VIEW].Value))
                {
                    x = (double)currentGroup[CAGE_X].Value;
                    y = (double)currentGroup[CAGE_Y].Value;
                    w = (double)currentGroup[CAGE_WIDTH].Value;
                    h = (double)currentGroup[CAGE_HEIGHT].Value;
                }
                organic.OutputRestriction =
                    OutputRestriction.CreateEllipticalCageRestriction(x, y, w, h);
                organic.ComponentLayoutEnabled = false;
                break;
            }
            }
        }
        ///<inheritdoc/>
        protected override void ConfigureLayout()
        {
            LayoutGraph      graph = CurrentLayoutGraph;
            HierarchicLayout hl    = new HierarchicLayout();

            LayoutAlgorithm = hl;

            //  mark incremental elements if required
            IDataMap    incrementalElements;
            OptionGroup generalGroup  = (OptionGroup)Handler.GetGroupByName(GENERAL);
            OptionGroup currentGroup  = (OptionGroup)generalGroup.GetGroupByName(INTERACTION);
            OptionGroup groupingGroup = (OptionGroup)Handler.GetGroupByName(GROUPING);

            bool fromSketch        = (bool)currentGroup[USE_DRAWING_AS_SKETCH].Value;
            bool incrementalLayout = (bool)currentGroup[SELECTED_ELEMENTS_INCREMENTALLY].Value;
            bool selectedElements  = !IsEdgeSelectionEmpty() || !IsNodeSelectionEmpty();

            if (incrementalLayout && selectedElements)
            {
                // create storage for both nodes and edges
                incrementalElements = Maps.CreateHashedDataMap();
                // configure the mode
                hl.LayoutMode = LayoutMode.Incremental;
                IIncrementalHintsFactory ihf = hl.CreateIncrementalHintsFactory();

                foreach (Node node in graph.Nodes)
                {
                    if (IsSelected(node))
                    {
                        incrementalElements.Set(node, ihf.CreateLayerIncrementallyHint(node));
                    }
                }

                foreach (Edge edge in graph.Edges)
                {
                    if (IsSelected(edge))
                    {
                        incrementalElements.Set(edge, ihf.CreateSequenceIncrementallyHint(edge));
                    }
                }
                graph.AddDataProvider(HierarchicLayout.IncrementalHintsDpKey, incrementalElements);
            }
            else if (fromSketch)
            {
                hl.LayoutMode = LayoutMode.Incremental;
            }
            else
            {
                hl.LayoutMode = LayoutMode.FromScratch;
            }


            // cast to implementation simplex
            var np = (SimplexNodePlacer)hl.NodePlacer;

            np.BarycenterMode  = (bool)generalGroup[SYMMETRIC_PLACEMENT].Value;
            np.StraightenEdges = (bool)Handler.GetValue(EDGE_SETTINGS, EDGE_STRAIGHTENING_OPTIMIZATION_ENABLED);

            hl.ComponentLayoutEnabled = (bool)generalGroup[LAYOUT_COMPONENTS_SEPARATELY].Value;

            currentGroup = (OptionGroup)generalGroup.GetGroupByName(MINIMUM_DISTANCES);

            hl.MinimumLayerDistance = (double)currentGroup[MINIMUM_LAYER_DISTANCE].Value;
            hl.NodeToEdgeDistance   = (double)currentGroup[NODE_TO_EDGE_DISTANCE].Value;
            hl.NodeToNodeDistance   = (double)currentGroup[NODE_TO_NODE_DISTANCE].Value;
            hl.EdgeToEdgeDistance   = (double)currentGroup[EDGE_TO_EDGE_DISTANCE].Value;

            NodeLayoutDescriptor nld = hl.NodeLayoutDescriptor;
            EdgeLayoutDescriptor eld = hl.EdgeLayoutDescriptor;

            currentGroup = (OptionGroup)Handler.GetGroupByName(EDGE_SETTINGS);

            hl.AutomaticEdgeGrouping = (bool)currentGroup[AUTOMATIC_EDGE_GROUPING_ENABLED].Value;

            string edgeRoutingChoice = (string)currentGroup[EDGE_ROUTING].Value;

            eld.RoutingStyle = edgeRoutingEnum[edgeRoutingChoice];
            eld.MinimumFirstSegmentLength = (double)currentGroup[MINIMUM_FIRST_SEGMENT_LENGTH].Value;
            eld.MinimumLastSegmentLength  = (double)currentGroup[MINIMUM_LAST_SEGMENT_LENGTH].Value;

            eld.MinimumDistance = (double)currentGroup[MINIMUM_EDGE_DISTANCE].Value;
            eld.MinimumLength   = (double)currentGroup[MINIMUM_EDGE_LENGTH].Value;

            eld.MinimumSlope = (double)currentGroup[MINIMUM_SLOPE].Value;

            eld.SourcePortOptimization = (bool)currentGroup[PC_OPTIMIZATION_ENABLED].Value;
            eld.TargetPortOptimization = (bool)currentGroup[PC_OPTIMIZATION_ENABLED].Value;

            var isIncrementalModeEnabled = (fromSketch || (incrementalLayout && selectedElements));
            var recursiveRoutingMode     = Handler.GetValue(EDGE_SETTINGS, RECURSIVE_EDGE_ROUTING);

            if (!isIncrementalModeEnabled && recursiveRoutingMode == RECURSIVE_EDGE_ROUTING_DIRECTED)
            {
                eld.RecursiveEdgeStyle = RecursiveEdgeStyle.Directed;
            }
            else if (!isIncrementalModeEnabled && recursiveRoutingMode == RECURSIVE_EDGE_ROUTING_UNDIRECTED)
            {
                eld.RecursiveEdgeStyle = RecursiveEdgeStyle.Undirected;
            }
            else
            {
                eld.RecursiveEdgeStyle = RecursiveEdgeStyle.Off;
            }

            nld.MinimumDistance    = Math.Min(hl.NodeToNodeDistance, hl.NodeToEdgeDistance);
            nld.MinimumLayerHeight = 0;

            OptionGroup rankGroup            = (OptionGroup)Handler.GetGroupByName(RANKS);
            string      layerAlignmentChoice = (string)rankGroup[LAYER_ALIGNMENT].Value;

            nld.LayerAlignment = alignmentEnum[layerAlignmentChoice];

            ol = (OrientationLayout)hl.OrientationLayout;
            string orientationChoice = (string)generalGroup[ORIENTATION].Value;

            ol.Orientation = orientEnum[orientationChoice];

            OptionGroup labelingGroup = (OptionGroup)Handler.GetGroupByName(LABELING);

            currentGroup = (OptionGroup)labelingGroup.GetGroupByName(LABELING_EDGE_PROPERTIES);
            string el = (string)currentGroup[EDGE_LABELING].Value;

            if (!el.Equals(EDGE_LABELING_NONE))
            {
                if (el.Equals(EDGE_LABELING_GENERIC))
                {
                    var la = new GenericLabeling();
                    la.MaximumDuration = 0;
                    la.PlaceNodeLabels = false;
                    la.PlaceEdgeLabels = true;
                    la.AutoFlipping    = true;
                    la.ProfitModel     = new SimpleProfitModel();
                    hl.PrependStage(la);
                }
                else if (el.Equals(EDGE_LABELING_HIERARCHIC))
                {
                    bool copactEdgeLabelPlacement = (bool)currentGroup[COMPACT_EDGE_LABEL_PLACEMENT].Value;
                    if (hl.NodePlacer is SimplexNodePlacer)
                    {
                        np.LabelCompaction = copactEdgeLabelPlacement;
                    }
                    hl.IntegratedEdgeLabeling = true;
                }
            }
            else
            {
                hl.IntegratedEdgeLabeling = false;
            }

            currentGroup = (OptionGroup)labelingGroup.GetGroupByName(NODE_PROPERTIES);
            if ((bool)currentGroup[CONSIDER_NODE_LABELS].Value)
            {
                hl.ConsiderNodeLabels = true;
                hl.NodeLayoutDescriptor.NodeLabelMode = NodeLabelMode.ConsiderForDrawing;
            }
            else
            {
                hl.ConsiderNodeLabels = false;
            }

            string rp = (string)rankGroup[RANKING_POLICY].Value;

            hl.FromScratchLayeringStrategy = rankingPolicies[rp];
            if (rp.Equals(BFS_LAYERS))
            {
                CurrentLayoutGraph.AddDataProvider(BFSLayerer.CoreNodesDpKey, new SelectedNodesDP(this));
            }

            hl.ComponentArrangementPolicy = componentAlignmentEnum[(string)rankGroup[COMPONENT_ARRANGEMENT_POLICY].Value];

            //configure AsIsLayerer
            Object layerer = (hl.LayoutMode == LayoutMode.FromScratch)
                         ? hl.FromScratchLayerer
                         : hl.FixedElementsLayerer;

//      if (layerer is OldLayererWrapper) {
//        layerer = ((OldLayererWrapper)layerer).OldLayerer;
//      }
            if (layerer is AsIsLayerer)
            {
                AsIsLayerer ail = (AsIsLayerer)layerer;
                currentGroup          = (OptionGroup)rankGroup.GetGroupByName(FROM_SKETCH_PROPERTIES);
                ail.NodeHalo          = (double)currentGroup[HALO].Value;
                ail.NodeScalingFactor = (double)currentGroup[SCALE].Value;
                ail.MinimumNodeSize   = (double)currentGroup[MINIMUM_SIZE].Value;
                ail.MaximumNodeSize   = (double)currentGroup[MAXIMUM_SIZE].Value;
            }

            //configure grouping
            np.GroupCompactionStrategy = groupHorizCompactionEnum[(string)groupingGroup[GROUP_HORIZONTAL_COMPACTION].Value];

            if (!fromSketch && groupStrategyEnum[(string)groupingGroup[GROUP_LAYERING_STRATEGY].Value])
            {
                GroupAlignmentPolicy alignmentPolicy = groupAlignmentEnum[(string)groupingGroup[GROUP_ALIGNMENT].Value];
                hl.GroupAlignmentPolicy   = alignmentPolicy;
                hl.CompactGroups          = (bool)groupingGroup[GROUP_ENABLE_COMPACTION].Value;
                hl.RecursiveGroupLayering = true;
            }
            else
            {
                hl.RecursiveGroupLayering = false;
            }

            OptionGroup swimGroup = (OptionGroup)Handler.GetGroupByName(SWIMLANES);

            if ((bool)swimGroup[TREAT_ROOT_GROUPS_AS_SWIMLANES].Value)
            {
                TopLevelGroupToSwimlaneStage stage = new TopLevelGroupToSwimlaneStage();
                stage.OrderSwimlanesFromSketch = (bool)swimGroup[USE_ORDER_FROM_SKETCH].Value;
                stage.Spacing = (double)swimGroup[SWIMLANE_SPACING].Value;
                hl.AppendStage(stage);
            }

            hl.BackLoopRouting = (bool)Handler.GetValue(EDGE_SETTINGS, BACKLOOP_ROUTING);
            hl.MaximumDuration = ((int)Handler.GetValue(GENERAL, MAXIMUM_DURATION)) * 1000;


            bool gridEnabled = (bool)Handler.GetValue(GRID, GRID_ENABLED);

            if (gridEnabled)
            {
                hl.GridSpacing = (double)Handler.GetValue(GRID, GRID_SPACING);
                String             portAssignment = (string)Handler.GetValue(GRID, GRID_PORT_ASSIGNMENT);
                PortAssignmentMode gridPortAssignment;
                switch (portAssignment)
                {
                case GRID_PORT_ASSIGNMENT_ON_GRID:
                    gridPortAssignment = PortAssignmentMode.OnGrid;
                    break;

                case GRID_PORT_ASSIGNMENT_ON_SUBGRID:
                    gridPortAssignment = PortAssignmentMode.OnSubgrid;
                    break;

                default:
                    gridPortAssignment = PortAssignmentMode.Default;
                    break;
                }
                graph.AddDataProvider(HierarchicLayoutCore.NodeLayoutDescriptorDpKey,
                                      new NodeLayoutDescriptorAdapter(hl.NodeLayoutDescriptor, graph, gridPortAssignment));
            }
        }