Author Topic: Double Drag behavior  (Read 3231 times)

0 Members and 1 Guest are viewing this topic.

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Double Drag behavior
« on: August 19, 2008, 03:31:21 PM »
I've been using this jig class but have noticed a problem.

When I'm dragging the ent I get two ghost copies. One on my cursor and one at double the distance and direction from the start point of the drag to the current cursor point.
When I drop the ent it is fine. Only the ent on my cursor is placed on the drawing and it is where I picked. The double ghost thing is bugging me. Probably a logic problem but I don't see it.

I've tried to keep the class as simple as possible.
What might be causing this behavior?

Code: [Select]
public class JigEnt : DrawJig
    {
        #region private member fields

        private Point3d previousCursorPosition;

        private Point3d currentCursorPosition;

        private Entity entityToDrag;

        #endregion

        Autodesk.AutoCAD.ApplicationServices.Document doc =
            acadApp.DocumentManager.MdiActiveDocument;

        public void DragEnt(
            ObjectId EntObjectID,
            Point3d StartPoint)
        {
            try
            {
                using (Transaction trans = doc.TransactionManager.StartTransaction())
                {
                    // Assign the Entity based on the ObjectID provided
                    entityToDrag = (Entity)trans.GetObject(EntObjectID, OpenMode.ForWrite);
                    //Initialize cursor position
                    previousCursorPosition = StartPoint;
                    doc.Editor.Drag(this);
                    trans.Commit();
                }               
            }
            catch (System.Exception)
            {
               
            }

        }

        protected override SamplerStatus Sampler(JigPrompts prompts)
        {
            //Get the current cursor position
            PromptPointResult userFeedback = prompts.AcquirePoint();
            currentCursorPosition = userFeedback.Value;

            if (CursorHasMoved())
            {
                //Get the vector of the move
                Vector3d displacementVector = previousCursorPosition.GetVectorTo(currentCursorPosition);
               
                //Transform the ent to the new location
                entityToDrag.TransformBy(Matrix3d.Displacement(displacementVector));
               
                //Save the cursor position
                previousCursorPosition = currentCursorPosition;

                return SamplerStatus.OK;
            }
            else
            {
                return SamplerStatus.NoChange;
            }
        }

        protected override bool WorldDraw(WorldDraw draw)
        {
            draw.Geometry.Draw(entityToDrag);
            return true;
        }

        private bool CursorHasMoved()
        {
            return !(currentCursorPosition == previousCursorPosition);
        }

    }
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

Glenn R

  • Guest
Re: Double Drag behavior
« Reply #1 on: August 19, 2008, 03:39:36 PM »
At first scan, your CursorHasMoved function looks...wrong.

It should probably be:

Code: [Select]
return (currentCursorPosition != previousCursorPosition);

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: Double Drag behavior
« Reply #2 on: August 19, 2008, 04:14:06 PM »
I'm not sure if
(WrongnessOf(return !(currentCursorPosition == previousCursorPosition)
>
WrongnessOf(return (currentCursorPosition != previousCursorPosition)))

but making that change didn't change the behavior.

My mistake is probably much much dumber than that.

It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

Glenn R

  • Guest
Re: Double Drag behavior
« Reply #3 on: August 19, 2008, 04:23:58 PM »
Like I said - scan ie quick.

I still think that judging by your method name, it should be as I suggested. I'll have to dig up some of my jig code to do a deeper analysis, but I'm tired and might do that tomorrow.

For others that may want to help, you haven't mentioned the following:

AutoCAD version
.NET Framework version
.NET Framework version being targeted (if applicable)
Visual Studio version

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: Double Drag behavior
« Reply #4 on: August 19, 2008, 05:02:06 PM »
I do appreciate your scan.

AutoCAD 2008
.NET framework 2.0 (using and targeted)
VS 2008 (framework 2.0 selected)
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8722
  • AKA Daniel
Re: Double Drag behavior
« Reply #5 on: August 20, 2008, 06:40:44 AM »
I’m using pretty much the same routine as you ( except my entity-to-drag is not database resident )
without any issues, you might try using a clone of your entity, then use the final coordinates of the jig to transform your original entity. 
If that makes sense .

Glenn R

  • Guest
Re: Double Drag behavior
« Reply #6 on: August 20, 2008, 06:59:42 AM »
CloneMeForDragging or some such if memory serves....