コード例 #1
0
        /// <summary>
        /// Builds the properties for the labels's <see cref="ILabelModel"/> type.
        /// </summary>
        protected virtual void BuildModelProperties(IPropertyBuildContext <ILabel> context)
        {
            ValueGetterDelegate <Type> labelModelGetter = new ValueGetterDelegate <Type>(
                delegate {
                var type = context.CurrentInstance.LayoutParameter.Model.GetType();
                while (!type.IsPublic)
                {
                    type = type.BaseType;
                }
                return(type);
            });
            ValueSetterDelegate <Type> labelModelSetter = new ValueSetterDelegate <Type>(
                delegate(Type value) {
                IGraph graph = context.Lookup(typeof(IGraph)) as IGraph;
                if (graph != null)
                {
                    ILabelModel model = Activator.CreateInstance(value) as ILabelModel;
                    if (model != null)
                    {
                        ILabelModelParameterFinder finder =
                            model.Lookup(typeof(ILabelModelParameterFinder)) as ILabelModelParameterFinder;
                        ILabelModelParameter parameter;
                        ILabel subject = context.CurrentInstance;
                        if (finder != null)
                        {
                            parameter = finder.FindBestParameter(subject, model, subject.GetLayout());
                        }
                        else
                        {
                            parameter = model.CreateDefaultParameter();
                        }
                        graph.SetLabelLayoutParameter(subject, parameter);
                    }
                }
            });
            ILabel currentLabel;

            currentLabel = context.CurrentInstance;
            if (currentLabel == null)
            {
                return;
            }
            if (currentLabel.Owner is IEdge)
            {
                context.AddEntry(EdgeLabelModelProperty,
                                 labelModelGetter,
                                 labelModelSetter, null);
            }

            if (currentLabel.Owner is INode)
            {
                context.AddEntry(NodeLabelModelProperty, labelModelGetter, labelModelSetter, null);
            }

            if (currentLabel.Owner is IPort)
            {
                context.AddEntry(PortLabelModelProperty, labelModelGetter, labelModelSetter, null);
            }
        }
コード例 #2
0
            /// <summary>
            /// Finds the label model parameter that describes the given label layout best.
            /// </summary>
            /// <remarks>
            /// Sometimes the layout cannot be met exactly, then the nearest location is used.
            /// </remarks>
            public ILabelModelParameter FindBestParameter(ILabel label, ILabelModel model, IOrientedRectangle labelLayout)
            {
                var wrapperModel = model as RotatableNodeLabelModelDecorator;
                var styleWrapper = wrapperModel.GetNodeStyleWrapper(label);

                if (!wrapperModel.UseNodeRotation || styleWrapper == null || styleWrapper.Angle == 0)
                {
                    return
                        (wrapperModel.CreateWrappingParameter(wrappedFinder.FindBestParameter(label, wrapperModel.Wrapped,
                                                                                              labelLayout)));
                }

                var node          = label.Owner as INode;
                var rotatedCenter = styleWrapper.GetRotatedPoint(labelLayout.GetCenter(), node, false);
                var rotatedLayout = styleWrapper.GetRotatedLayout(node);

                var rectangle = new OrientedRectangle(labelLayout);

                rectangle.Angle -= rotatedLayout.GetRadians();
                rectangle.SetCenter(rotatedCenter);

                return
                    (wrapperModel.CreateWrappingParameter(wrappedFinder.FindBestParameter(label, wrapperModel.Wrapped, rectangle)));
            }