Exemplo n.º 1
0
        protected override void LoadExample()
        {
            base.DefaultGridOrigin   = new NPointF(30, 30);
            base.DefaultGridCellSize = new NSizeF(70, 70);
            base.DefaultGridSpacing  = new NSizeF(50, 10);

            // begin view init
            view.BeginInit();

            // init view
            view.Grid.Visible = false;

            NSizeF handlesSize = new NSizeF(5, 5);

            view.TrackersAppearance.RotatedBoundsHandlesStyle.Size     = handlesSize;
            view.TrackersAppearance.RotatorHandlesStyle.Size           = handlesSize;
            view.TrackersAppearance.PinHandlesStyle.Size               = handlesSize;
            view.TrackersAppearance.GeometryBasePointHandlesStyle.Size = handlesSize;
            view.TrackersAppearance.GeometryMidPointHandlesStyle.Size  = handlesSize;
            view.TrackersAppearance.ShapeControlPointHandlesStyle.Size = handlesSize;
            view.TrackersAppearance.ShapeStartPlugHandlesStyle.Size    = handlesSize;
            view.TrackersAppearance.ShapeEndPlugHandlesStyle.Size      = handlesSize;

            // init document
            document.BeginInit();
            InitDocument();
            document.EndInit();

            // init form controls
            InitFormControls();

            // end view init
            view.EndInit();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets a random size in [minSize, maxSize] range
        /// </summary>
        /// <param name="minSize"></param>
        /// <param name="maxSize"></param>
        /// <returns></returns>
        protected NSizeF GetRandomSize(NSizeF minSize, NSizeF maxSize)
        {
            float width  = (float)(Random.Next(100) * Math.Abs(maxSize.Width - minSize.Width) / 100.0f + Math.Min(maxSize.Width, minSize.Width));
            float height = (float)(Random.Next(100) * Math.Abs(maxSize.Height - minSize.Height) / 100.0f + Math.Min(maxSize.Height, minSize.Height));

            return(new NSizeF(width, height));
        }
Exemplo n.º 3
0
        private void UpdatePortGeneralPropertiesControls(NPort port)
        {
            // can only disconnect the port if it is connected to any plugs
            disconnectPortButton.Enabled = (port.Plugs.Count != 0);

            // update port offset
            NSizeF offset = port.Offset;

            portOffsetXNumeric.Value = (decimal)offset.Width;
            portOffsetYNumeric.Value = (decimal)offset.Height;

            // populate the combo with available anchors
            INDiagramElementContainer searchRoot = port.GetRootForReferenceProperty("AnchorUniqueId");
            NFilter filter = port.GetFilterForReferenceProperty("AnchorUniqueId");

            NNodeList anchors = searchRoot.Descendants(null, -1);

            anchors.Insert(0, searchRoot);
            anchors = anchors.Filter(filter);

            anchorIdComboBox.Items.Clear();
            anchorIdComboBox.Items.AddRange((object[])(anchors.ToArray(typeof(object))));

            // select the currently chosen anchor
            for (int i = 0; i < anchorIdComboBox.Items.Count; i++)
            {
                Guid elemendGuid = (anchorIdComboBox.Items[i].Tag as INDiagramElement).UniqueId;
                if (elemendGuid.Equals(port.AnchorUniqueId))
                {
                    anchorIdComboBox.SelectedIndex = i;
                    break;
                }
            }
        }
Exemplo n.º 4
0
        protected void NDrawingView1_AsyncCustomCommand(object sender, EventArgs e)
        {
            NCallbackCustomCommandArgs args    = e as NCallbackCustomCommandArgs;
            NCallbackCommand           command = args.Command;
            string value = command.Arguments["value"].ToString();

            NNodeList decorators = NDrawingView1.Document.ActiveLayer.Descendants(DecoratorFilter, -1);
            int       i, count = decorators.Count;

            switch (command.Name)
            {
            case "background":
                ToggleDecoratorBackgroundShape background = (ToggleDecoratorBackgroundShape)Enum.Parse(typeof(ToggleDecoratorBackgroundShape), value);
                for (i = 0; i < count; i++)
                {
                    ((NToggleDecorator)decorators[i]).Background.Shape = background;
                }

                m_bClientSideRedrawRequired = true;
                break;

            case "symbol":
                ToggleDecoratorSymbolShape symbol = (ToggleDecoratorSymbolShape)Enum.Parse(typeof(ToggleDecoratorSymbolShape), value);
                for (i = 0; i < count; i++)
                {
                    ((NToggleDecorator)decorators[i]).Symbol.Shape = symbol;
                }

                m_bClientSideRedrawRequired = true;
                break;

            case "position":
                NContentAlignment alignment;
                NSizeF            offset;

                if (value == "Left")
                {
                    alignment = new NContentAlignment(ContentAlignment.TopLeft);
                    offset    = new NSizeF(11, 11);
                }
                else
                {
                    alignment = new NContentAlignment(ContentAlignment.TopRight);
                    offset    = new NSizeF(-11, 11);
                }

                for (i = 0; i < count; i++)
                {
                    NToggleDecorator decorator = (NToggleDecorator)decorators[i];
                    decorator.Alignment = alignment;
                    decorator.Offset    = offset;
                }

                m_bClientSideRedrawRequired = true;
                break;
            }
        }
Exemplo n.º 5
0
        protected string GetXMLText(int number, string initial, string weight)
        {
            string str  = number.ToString();
            NSizeF size = new NSizeF(10, 15);

            str += "<br/><font size='14'><b>" + initial + "</b></font><br/>";
            str += weight;
            return(str);
        }
        protected NRectangleF GetElementBounds(int column, int row)
        {
            NSizeF  size   = new NSizeF(45, 80);
            NPointF origin = new NPointF(45, 45);

            float x = origin.X + (column - 1) * size.Width;
            float y = origin.Y + (row - 1) * size.Height;

            return(new NRectangleF(x, y, size.Width, size.Height));
        }
Exemplo n.º 7
0
            void INCustomRequestCallback.OnCustomRequestCallback(NAspNetThinWebControl control, NRequestContext context, string argument)
            {
                NThinDiagramControl diagramControl = (NThinDiagramControl)control;
                NNodeList           decorators     = diagramControl.Document.ActiveLayer.Descendants(ShowHideSubtreeDecoratorFilter, -1);

                int i, count = decorators.Count;

                string[] data  = argument.Split('=');
                string   name  = data[0];
                string   value = data[1];

                switch (name)
                {
                case "background":
                    ToggleDecoratorBackgroundShape background = (ToggleDecoratorBackgroundShape)Enum.Parse(typeof(ToggleDecoratorBackgroundShape), value);
                    for (i = 0; i < count; i++)
                    {
                        ((NToggleDecorator)decorators[i]).Background.Shape = background;
                    }
                    break;

                case "symbol":
                    ToggleDecoratorSymbolShape symbol = (ToggleDecoratorSymbolShape)Enum.Parse(typeof(ToggleDecoratorSymbolShape), value);
                    for (i = 0; i < count; i++)
                    {
                        ((NToggleDecorator)decorators[i]).Symbol.Shape = symbol;
                    }
                    break;

                case "position":
                    NContentAlignment alignment;
                    NSizeF            offset;

                    if (value == "Left")
                    {
                        alignment = new NContentAlignment(ContentAlignment.TopLeft);
                        offset    = new NSizeF(11, 11);
                    }
                    else
                    {
                        alignment = new NContentAlignment(ContentAlignment.TopRight);
                        offset    = new NSizeF(-11, 11);
                    }

                    for (i = 0; i < count; i++)
                    {
                        NToggleDecorator decorator = (NToggleDecorator)decorators[i];
                        decorator.Alignment = alignment;
                        decorator.Offset    = offset;
                    }
                    break;
                }

                control.UpdateView();
            }
Exemplo n.º 8
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public NDiagramExampleUC()
        {
            InitializeComponent();

            view     = null;
            document = null;

            eventHandlingPauseCounter = 0;

            defaultGridOrigin   = new NPointF(15, 15);
            defaultGridCellSize = new NSizeF(100, 100);
            defaultGridSpacing  = new NSizeF(20, 20);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initializer constructor
        /// </summary>
        /// <param name="form">main application form</param>
        public NDiagramExampleUC(NMainForm form)
            : base(form)
        {
            InitializeComponent();

            view     = form.View;
            document = form.Document;
            eventHandlingPauseCounter = 0;

            defaultGridOrigin   = new NPointF(15, 15);
            defaultGridCellSize = new NSizeF(100, 100);
            defaultGridSpacing  = new NSizeF(20, 20);
        }
        private void AddRandomShape()
        {
            Array values = Enum.GetValues(typeof(BasicShapes));

            NBasicShapesFactory factory = new NBasicShapesFactory(document);
            NShape shape = factory.CreateShape((int)values.GetValue(Random.Next(values.Length)));

            NSizeF size = new NSizeF(Random.Next(10) + 30, Random.Next(10) + 30);

            shape.Bounds          = new NRectangleF(base.GetRandomPoint(view.Viewport), size);
            shape.Style.FillStyle = new NColorFillStyle(Color.GreenYellow);

            document.ActiveLayer.AddChild(shape);
        }
        protected void AddElement(NDrawingDocument document, NChemicalElement ce)
        {
            string str  = ce.number.ToString();
            NSizeF size = new NSizeF(10, 15);

            str += "<br/><font size='14'><b>" + ce.symbol + "</b></font><br/>";
            str += ce.weight;

            NShape element = null;

            element      = new NRectangleShape(GetElementBounds(ce.col, ce.row));
            element.Text = str;
            element.Style.InteractivityStyle = new NInteractivityStyle(true, null, ce.tooltip);
            element.Style.FillStyle          = ce.fillStyle;
            document.ActiveLayer.AddChild(element);
        }
Exemplo n.º 12
0
        protected void AddElement(NDrawingDocument document, NChemicalElement ce)
        {
            string str  = ce.number.ToString();
            NSizeF size = new NSizeF(10, 15);

            str += "<br/><font size='14'><b>" + ce.symbol + "</b></font><br/>";
            str += ce.weight;

            CursorType ct = CursorType.Default;

            if (ce.fillStyle == fsNonMetals)
            {
                ct = CursorType.Hand;
            }
            else if (ce.fillStyle == fsMetals)
            {
                ct = CursorType.Cross;
            }
            else if (ce.fillStyle == fsMatalloids)
            {
                ct = CursorType.SizeAll;
            }
            else if (ce.fillStyle == fsGases)
            {
                ct = CursorType.VSplit;
            }
            else if (ce.fillStyle == feMoccasin)
            {
                ct = CursorType.HSplit;
            }
            else if (ce.fillStyle == feGold)
            {
                ct = CursorType.Help;
            }
            else if (ce.fillStyle == feCentralGroup)
            {
                ct = CursorType.WaitCursor;
            }

            NShape element = null;

            element      = new NRectangleShape(GetElementBounds(ce.col, ce.row));
            element.Text = str;
            element.Style.InteractivityStyle = new NInteractivityStyle(true, null, null, ct);
            element.Style.FillStyle          = ce.fillStyle;
            document.ActiveLayer.AddChild(element);
        }
Exemplo n.º 13
0
        protected void AddElement(NDrawingDocument document, NChemicalElement ce)
        {
            string str  = ce.number.ToString();
            NSizeF size = new NSizeF(10, 15);

            str += "<br/><font size='14'><b>" + ce.symbol + "</b></font><br/>";
            str += ce.weight;

            NShape element = null;

            element      = new NRectangleShape(GetElementBounds(ce.col, ce.row));
            element.Text = str;
            string url = string.Format("http://www.google.com/search?hl=en&q={0}+chemical+element", HttpUtility.UrlEncode(ce.symbol.Replace("*", string.Empty)));

            element.Style.InteractivityStyle = new NInteractivityStyle(true, null, null, CursorType.Default, url);
            element.Style.FillStyle          = ce.fillStyle;
            document.ActiveLayer.AddChild(element);
        }
Exemplo n.º 14
0
        protected override void LoadExample()
        {
            m_NodeSize = new NSizeF(25, 25);
            m_Layout   = new NSpringLayout();

            // begin view init
            view.BeginInit();

            view.Grid.Visible            = false;
            view.HorizontalRuler.Visible = false;
            view.VerticalRuler.Visible   = false;

            // init document
            document.BeginInit();
            InitDocument();
            document.EndInit();

            // end view init
            view.EndInit();
        }
Exemplo n.º 15
0
        private void LayoutButton_Click(object sender, EventArgs e)
        {
            // get the shapes to layout
            NNodeList shapes = document.ActiveLayer.Children(NFilters.Shape2D);

            // create a layout context
            NLayoutContext layoutContext = new NLayoutContext();

            layoutContext.GraphAdapter         = new NShapeGraphAdapter();
            layoutContext.BodyAdapter          = new NShapeBodyAdapter(document);
            layoutContext.BodyContainerAdapter = new NDrawingBodyContainerAdapter(document);

            if (m_Layout != null)
            {
                // update the desired size
                NSizeF      desiredSize       = m_Layout.GetDesiredLayoutSize(shapes, layoutContext);
                NRectangleF desiredLayoutArea = new NRectangleF(layoutContext.BodyContainerAdapter.GetLayoutArea().Location, desiredSize);
                m_DesiredSizeShape.Bounds = desiredLayoutArea;

                // layout the shapes
                m_Layout.Layout(shapes, layoutContext);
            }
        }
Exemplo n.º 16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="row"></param>
 /// <param name="col"></param>
 /// <param name="origin"></param>
 /// <param name="size"></param>
 /// <param name="spacing"></param>
 /// <returns></returns>
 public NRectangleF GetGridCell(int row, int col, NPointF origin, NSizeF size, NSizeF spacing)
 {
     return(new NRectangleF(origin.X + col * (size.Width + spacing.Width),
                            origin.Y + row * (size.Height + spacing.Height),
                            size.Width, size.Height));
 }
Exemplo n.º 17
0
 public NMyDataObject(string shapeType, NSizeF shapeSize)
 {
     this.shapeType = shapeType;
     this.shapeSize = shapeSize;
 }