Author Topic: Plugin to add snap options + icons  (Read 22622 times)

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5269
  • Made in England
    • View Profile
Plugin to add snap options + icons
« on: January 15, 2015, 20:55:43 pm »
This plugin adds a 'snap to grid' and 'snap to object' button in the View ToolStrip.

I admit I only know a certain percentage of what's going on here. I would love to just address the ViewToolStrip directly without going through all that 'for each whatever in whatever' rigmarole

« Last Edit: January 16, 2015, 08:41:09 am by EddyCurrent »
Filmed in Supermarionation

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8988
    • View Profile
Re: Plugin to add snap options + icons
« Reply #1 on: January 15, 2015, 22:48:39 pm »
Eddy,
That cannot work as it is.  At least, it does not "play well" with other software.

Although the snap buttons will be placed there, all the other ViewToolbarAddins one had before will be lost.

When you copy another plugin as a template, you must re-name the .dll to a new and unique name, so it does not crush the older one of that same name.  If you simply re-name the whole project, then it's taken care of automatically at compile time.

I changed mine to "Snap-ToolbarAddins", and then it works fine.

LLoyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5269
  • Made in England
    • View Profile
Re: Plugin to add snap options + icons
« Reply #2 on: January 16, 2015, 08:43:52 am »
Sorry, I thought I'd done that, renamed now and added.
Though I find this useful myself it was also a test and I wanted to see if anyone would enlighten me with regard to 'speaking' to the ToolStrips directly rather than through the grapevine as it is now.
« Last Edit: January 16, 2015, 08:56:05 am by EddyCurrent »
Filmed in Supermarionation

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8988
    • View Profile
Re: Plugin to add snap options + icons
« Reply #3 on: January 16, 2015, 12:32:35 pm »
Eddy,
I think there probably is information in the structure that indicates how many toolbar buttons there are.  I have not looked for it.  In the frame of things, parsing (and perhaps enumerating) all the buttons takes only a few microseconds.

In any case, it would be necessary to do so, if you wanted to re-order the buttons, or slip yours into the middle of the list.

LLoyd


"Pyro for Fun and Profit for More Than Fifty Years"

Offline BaNoBi

  • Droid
  • **
  • Posts: 51
    • View Profile
Re: Plugin to add snap options + icons
« Reply #4 on: January 16, 2015, 14:26:17 pm »
Eddy:

You can use this new functions:
Code: [Select]
        public enum ToolStripEnum
        {
                CAMToolStrip,
                EntityToolStrip,
                FileToolStrip,
                ViewToolStrip
        };

        static ToolStripContainer GetToolStripContainer()
        {
            Form f = ThisApplication.TopWindow;
            ToolStripContainer tsc = null;

            Control[] controls = f.Controls.Find("ToolStripContainer1", true);

            if (controls != null && controls.Length == 1)
            {
                tsc = (ToolStripContainer)controls[0];
            }
            else
            {
                foreach (Control c in f.Controls)
                {
                    if (c is ToolStripContainer)
                    {
                        tsc = (ToolStripContainer)c;

                        break;
                    }
                }
            }

            return tsc;
        }

        static Control GetToolStrip(ToolStripEnum toolStrip)
        {
            Control ctr = null;

            ToolStripContainer container = GetToolStripContainer();

            foreach (Control cc in container.TopToolStripPanel.Controls)
            {
                if (cc.GetType().ToString().EndsWith(toolStrip.ToString()))
                {
                    ctr = cc;

                    break;
                }
            }

            return ctr;
        }

For example, if you need the ViewToolStrip use this code:
Code: [Select]
Control toolStrip = GetToolStrip(ToolStripEnum.ViewToolStrip);

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5269
  • Made in England
    • View Profile
Re: Plugin to add snap options + icons
« Reply #5 on: January 16, 2015, 16:11:08 pm »
Thanks Vasco I'll have a good look at that.
Like someone else said, I was fully on board with K&R C but when OOP C++ came in I stopped programming. Trying to catch up is proving frustrating and time consuming, more time than I have 'spare' really.
« Last Edit: January 16, 2015, 16:24:31 pm by EddyCurrent »
Filmed in Supermarionation

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8988
    • View Profile
Re: Plugin to add snap options + icons
« Reply #6 on: January 16, 2015, 17:14:12 pm »
Trying to catch up is proving frustrating and time consuming, more time than I have 'spare' really.
----------
I FEEL your pain, Eddy! Me, too!  It's like walking on an alien planet to us old M/L and C programming guys.

Lloyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline Bubba

  • CNC Jedi
  • *****
  • Posts: 3356
    • View Profile
Re: Plugin to add snap options + icons
« Reply #7 on: January 16, 2015, 19:23:14 pm »
Trying to catch up is proving frustrating and time consuming, more time than I have 'spare' really.
----------
I FEEL your pain, Eddy! Me, too!  It's like walking on an alien planet to us old M/L and C programming guys.

Lloyd

A least you guys recognise the bell ring.. To me it's just a sound.. ;) :D ;D
My 2¢

Win11, CB(1.0)rc 1(64 bit) Mach3, ESS, G540, 4th Axis, Endurance Laser.

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5269
  • Made in England
    • View Profile
Re: Plugin to add snap options + icons
« Reply #8 on: January 16, 2015, 21:21:50 pm »

A least you guys recognise the bell ring.. To me it's just a sound.. ;) :D ;D

Most eloquent, I'll have to remember that one.

I've just been reading through this and it's made things a lot clearer. One thing I noticed though, people don't seem to make main() obvious, they use any old name for it.
http://csharp.net-tutorials.com/basics/visual-csharp-express/
« Last Edit: January 16, 2015, 22:12:08 pm by EddyCurrent »
Filmed in Supermarionation

Offline BaNoBi

  • Droid
  • **
  • Posts: 51
    • View Profile
Re: Plugin to add snap options + icons
« Reply #9 on: January 20, 2015, 10:23:44 am »
Hi Eddy,

One suggestion:
Add two global variables for the buttons, for the state of button is equal to the value of the propriety. Is more simple to check if the property is enable or not.

Code: [Select]
private static ToolStripItem tiSnapToGrid;
private static ToolStripItem tiSnapToObject;

...

static void TopWindow_Load(object sender, EventArgs e)
{
    Form f = ThisApplication.TopWindow;

    Control toolStrip = GetToolStrip(ToolStripEnum.ViewToolStrip);

    ViewToolStrip vts = toolStrip as ViewToolStrip;

    tiSnapToGrid = vts.Items.Add("");
    tiSnapToGrid.Click += new EventHandler(GridSnap_Click);
    tiSnapToGrid.ToolTipText = "Snap To Grid";
    tiSnapToGrid.Image = Resource1.Image2;
    ((ToolStripButton)tiSnapToGrid).Checked = CamBamConfig.Defaults.SnapToGrid;

    tiSnapToObject = vts.Items.Add("");
    tiSnapToObject.Click += new EventHandler(ObjectSnap_Click);
    tiSnapToObject.ToolTipText = "Snap To Object";
    tiSnapToObject.Image = Resource1.Image3;
    ((ToolStripButton)tiSnapToObject).Checked = CamBamConfig.Defaults.SnapToPoints;
}

static void GridSnap_Click(object sender, EventArgs e)
{
    CamBamConfig.Defaults.SnapToGrid = !CamBamConfig.Defaults.SnapToGrid;
    ((ToolStripButton)tiSnapToGrid).Checked = CamBamConfig.Defaults.SnapToGrid;
}

static void ObjectSnap_Click(object sender, EventArgs e)
{
    CamBamConfig.Defaults.SnapToPoints = !CamBamConfig.Defaults.SnapToPoints;
    ((ToolStripButton)tiSnapToObject).Checked = CamBamConfig.Defaults.SnapToPoints;
}
« Last Edit: January 20, 2015, 10:26:06 am by BaNoBi »

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5269
  • Made in England
    • View Profile
Re: Plugin to add snap options + icons
« Reply #10 on: January 20, 2015, 10:45:00 am »
Yes I like it. If I'd known how to do that I would have, thanks BaNoBi  ;D
Filmed in Supermarionation

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5269
  • Made in England
    • View Profile
Re: Plugin to add snap options + icons
« Reply #11 on: January 22, 2015, 14:59:58 pm »
New dll added with BaNoBi's excellent additions, now you can see if the snaps are enabled or disabled by the state of the icon buttons.

Thanks BaNoBi  ;D
Filmed in Supermarionation

Offline coolant slinger

  • Wookie
  • ****
  • Posts: 312
    • View Profile
Re: Plugin to add snap options + icons
« Reply #12 on: January 22, 2015, 18:15:35 pm »
I like that snap feature. Always thought that should be an icon.

Thanks

Offline Bubba

  • CNC Jedi
  • *****
  • Posts: 3356
    • View Profile
Re: Plugin to add snap options + icons
« Reply #13 on: January 22, 2015, 19:29:45 pm »
Very useful feature. Thanks Eddy. :D
My 2¢

Win11, CB(1.0)rc 1(64 bit) Mach3, ESS, G540, 4th Axis, Endurance Laser.

Offline spikec

  • Ewok
  • *
  • Posts: 9
    • View Profile
Re: Plugin to add snap options + icons
« Reply #14 on: January 30, 2015, 12:34:28 pm »
Ok, pardon my naivete, but I'm having trouble installing this because I haven't really messed with plugins before. I copied the latest "Snap_ToolbarAddins.dll" to C:\Program Files (x86)\CamBam plus 0.9.8\plugins.

Where does the "Snap_ToolbarAddins" folder go?

Thanks fellas, just an old guy trying to learn new tricks.