OpenRoads Designer CONNECT Edition SDK Help

Vertical alignment creator

Description

  • This is a custom interactive tool for creating vertical alignment (called as Profile) on existing horizontal alignment.

  • The user is prompted to select a horizontal alignment upon which to create a simple vertical alignment, profile is then created for the selected horizontal alignment.

  • The VerticalAlignmentCreator class which extends DgnElementSetTool which handles different events to interact with UI, the VerticalAlignmentCreator class overrides the events here in this tool.

Remarks

  • This sample code is a part of ManagedSDKExample which you get with SDK installation under "examples" section in SDK installation directory.

  • If you encounter any error while using DgnElementSetTool class, make sure to add a reference to Bentley.DgnDisplayNet.dll by selecting Project > Add Reference or change the projects .csproj file to add reference to this dll.

  • The dll location will be "C:\Program Files\Bentley\OpenRoads Designer CE 10.11\OpenRoadsDesigner\Bentley.DgnDisplayNet.dll".

Source Code


//Required References
using Bentley.DgnPlatformNET;
using Bentley.DgnPlatformNET.Elements;
using Bentley.CifNET.LinearGeometry;
using Bentley.GeometryNET;
using Bentley.CifNET.GeometryModel.SDK;
using Bentley.CifNET.SDK.Edit;
using System;

namespace ManagedSDKExample
{
    class VerticalAlignmentCreator : DgnElementSetTool
    {
        internal void CreateVerticalAlignment(Element el)
        {
            ConsensusConnectionEdit con = ConsensusConnectionEdit.GetActive();
            Alignment al = Alignment.CreateFromElement(con, el);

            DPoint3d[] points = { new DPoint3d(100, 100), new DPoint3d(600, 110), new DPoint3d(1000, 105) };
            ProfileElement element = ProfileElement.Create1(450.0, 750.0, points);
            if (element != null)
            {
                con.StartTransientMode();
                var edit = al.CreateProfileByProfileElement(element, true, false);
                con.PersistTransients();
            }
        }

        protected override void OnPostInstall()
        {
            base.BeginPickElements();
            AccuSnap.LocateEnabled = true;
            AccuSnap.SnapEnabled = false;
            base.OnPostInstall();
            NotificationManager.OutputPrompt("Select a horizontal alignment.");
        }

        protected override bool OnPostLocate(HitPath path, out string cantAcceptReason)
        {
            //checks that hitpath is not null
            if (path == null)
            {
                cantAcceptReason = "HitPath is null.";
                return false;
            }

            //checks that the cursor element is not null
            Element el = path.GetCursorElement();
            if (el == null)
            {
                cantAcceptReason = "There is no element at cursor.";
                return false;
            }

            //checks that the cursor element is a civil element
            if (el.ElementType != MSElementType.LineString && el.ElementType != MSElementType.ComplexString)
            {
                cantAcceptReason = "This is not a civil element.";
                return false;
            }

            ConsensusConnectionEdit con = ConsensusConnectionEdit.GetActive();
            Alignment al = (el.ParentElement == null) ? Alignment.CreateFromElement(con, el) : Alignment.CreateFromElement(con, el.ParentElement);
            if (al == null)
            {
                cantAcceptReason = "This is not a civil element.";
                return false;
            }

            cantAcceptReason = String.Empty;
            return true;
        }

        //gets alignment on click
        protected override bool OnDataButton(DgnButtonEvent ev)
        {
            HitPath hitPath = DoLocate(ev, true, 0);
            if (hitPath == null)
                return false;

            Element el = hitPath.GetCursorElement();
            if (el == null)
                return false;

            CreateVerticalAlignment(el);
            return true;
        }

        protected override void OnRestartTool()
        {
            InstallNewInstance();
        }

        public override StatusInt OnElementModify(Element element)
        {
            return StatusInt.Error;
        }

        public static void InstallNewInstance()
        {
            VerticalAlignmentCreator tool = new VerticalAlignmentCreator();
            tool.InstallTool();
        }
    }
}