70002596 A new event to override the Snap of the Mouse movement

Article 70002596
Type Wish
Product Engine
Version 1102
Date Added 11/21/2024 12:00:00 AM
Fixed 11.3.2.0 (11/21/2024 12:00:00 AM)
Submitted by Wayne Romer

Summary

A new event to override the Snap of the Mouse movement

Solution

In version 11.3.2 a new event OnFilterSnapPoint was added in vdDocument object

vdDocument doc;
doc.OnFilterSnapPoint += Doc_OnFilterSnapPoint;

doc.SnapMode = true;

//see also the doc.SnapModeAffect if you want to change to SnapModeFlags.All in order not to snap only when waiting a user point but in all actions
doc.SnapModeAffect = SnapModeFlags.All;
..........
        //snap every 0.5 drawing units relative to the Origin of the Current User Coordinate System
        //so the point result x,y,z to be multiple of selected snapspace (0.5)
        private void Doc_OnFilterSnapPoint(vdDocument sender, ref gPoint mousePosition, ref bool cancel)
        {
            double snapspace = 0.5;

            //fix snapspace to be between 2 > snapspace(in pixels) < 20

            //change the snap so if it is too small in current zoom multiply * 2 until to be at least 2 pixels size
            while ((snapspace / sender.ActiveActionRender.PixelSize) < 2.0) snapspace *= 2.0;
            //change the snap so if it is too big in current zoom divide with 2 until to be at least 100 pixels size
            while ((snapspace / sender.ActiveActionRender.PixelSize) > 100) snapspace /= 2.0;

            gPoint pt = sender.World2UserMatrix.Transform(mousePosition);
            pt.x -= pt.x % snapspace;
            pt.y -= pt.y % snapspace;
            pt.z -= pt.z % snapspace;
            gPoint ptworld = sender.User2WorldMatrix.Transform(pt);
            mousePosition = ptworld;
            cancel = true;

        }

Send comments on this topic.