GhCanvasViewport

Hello @stevebaer
Thanks for GhCanvasViewport
I made a few changes to enable window dragging and added a views list. However, I encountered an issue when switching the view to Top, Right, or Front; using right-click resulted in rotation. How can I disable this rotation?

Additionally, I added a button to toggle the visibility of the window, but I’m having trouble figuring out how to implement it

using System;
using System.Drawing;
using Grasshopper.GUI.Canvas;
using Grasshopper.GUI;
using Grasshopper;
using System.Windows.Forms;
using Grasshopper.Kernel;
using System.Security.Cryptography;

namespace GhCanvasViewport
{
    public class GhCanvasViewportInfo : GH_AssemblyInfo
    {
        public static ToolStripButton showView = new ToolStripButton();
        static CanvasViewport _canvasViewport;
        public GhCanvasViewportInfo()
        {
            if (_canvasViewport == null)
            {
                _canvasViewport = new CanvasViewport();
                _canvasViewport.AddToMenu();
            }
        }

        public override string Name
        {
            get
            {
                return "GhCanvasViewport";
            }
        }
        public override string Version
        {
            get
            {
                // use AssemblyInformationalVersion since this can be patched easily during CI builds
                // to keep it in sync with the yak package version
                return System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).ProductVersion;
            }
        }
        public override Bitmap Icon
        {
            get
            {
                //Return a 24x24 pixel bitmap to represent this GHA library.
                return null;
            }
        }
        public override string Description
        {
            get
            {
                //Return a short string describing the purpose of this GHA library.
                return "";
            }
        }
        public override Guid Id
        {
            get
            {
                return new Guid("406bd915-c42a-4f97-8ce4-4934600b43ff");
            }
        }

        public override string AuthorName
        {
            get
            {
                //Return a string identifying you or your company.
                return "";
            }
        }
        public override string AuthorContact
        {
            get
            {
                //Return a string representing your preferred contact details.
                return "";
            }
        }
    }

    public class DisableSolverPriority : GH_AssemblyPriority
    {
        public override GH_LoadingInstruction PriorityLoad()
        {
            Instances.CanvasCreated += Instances_CanvasCreated;
            return GH_LoadingInstruction.Proceed;
        }

        private void Instances_CanvasCreated(GH_Canvas canvas)
        {
            Instances.CanvasCreated -= Instances_CanvasCreated;

            GH_DocumentEditor editor = Instances.DocumentEditor;
            if (editor == null)
            {
                Instances.ActiveCanvas.DocumentChanged += ActiveCanvas_DocumentChanged;
                return;
            }
            AddViewoprtButton(editor);
        }

        private void ActiveCanvas_DocumentChanged(GH_Canvas sender, GH_CanvasDocumentChangedEventArgs e)
        {
            Instances.ActiveCanvas.DocumentChanged -= ActiveCanvas_DocumentChanged;

            GH_DocumentEditor editor = Instances.DocumentEditor;
            if (editor == null)
            {
                return;
            }
            AddViewoprtButton(editor);
        }

        private void AddViewoprtButton(GH_DocumentEditor editor)
        {

            ToolStrip oldToolbar = editor.Controls[0].Controls[1] as ToolStrip;
            GhCanvasViewportInfo.showView.Image = Properties.Resources.console;

            GhCanvasViewportInfo.showView.ImageScaling = ToolStripItemImageScaling.SizeToFit;
            GhCanvasViewportInfo.showView.ToolTipText = "GH Viewport";
            GhCanvasViewportInfo.showView.Checked = false;

            oldToolbar.Items.Insert(1, GhCanvasViewportInfo.showView);
        }
    }
}
2 Likes

Update, the code works fine now except the navigation problem when choose top, right, front views.

GhCanvasViewport.zip (10.5 MB)

2 Likes

If you have nice additions to make, I would suggest creating small pull requests on github that I can review and hopefully integrate into the GhCanvasViewport project.

2 Likes

Pull requests sent

2 Likes