How to recognize on which entity is clicked?

Discuss and ask questions about CADViewX (Lite and Pro versions).

Moderators: support, SDS, admin

Post Reply
xavier
Posts: 27
Joined: 04 Dec 2012, 14:58

How to recognize on which entity is clicked?

Post by xavier » 05 Dec 2012, 20:45

Hello

In an application, I display on the screen a plan in dxf format. Then, I intercept mouse events.

On a mouse click, I transform the coordinates (in pixel) into coordinates CADimage (into mm) with the method "CADViewX.CADCoords ()".

From CADimage coordinates, I would find the entity on which the user clicked.

But I do not know what method or property use. Could you help me?

Thank you in advance.

support
Posts: 2930
Joined: 30 Mar 2005, 11:36
Contact:

Re: How to recognize on which entity is clicked?

Post by support » 07 Dec 2012, 15:25

Hello.
A DXF drawing measured in drawing units, not in mm or other physical units. Of course you can have information about correspondence between drawing units and some physical units. But the DXF file doesn't contain such data.
Mouse (screen 2D) coordinates can be transformed to CADImage (drawing 3D) coordinates. However there is no a method that defines if returned 3D coordinates belongs to some entity. You can try to realize own method for such task.
CADViewX Pro includes visual editing functionality that doesn't provided with CADViewX Lite. A part of editing functionality is selection by mouse. You can click on entity to select then access it using editor properties. Please take a look at the following topic:
http://www.cadsofttools.com/forum/viewt ... =16&t=2905

Alexander.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

xavier
Posts: 27
Joined: 04 Dec 2012, 14:58

Re: How to recognize on which entity is clicked?

Post by xavier » 07 Dec 2012, 17:46

Thank you for these precisions and for the link.
Unfortunately, it is not suitable for the application I'm developing.

In the application I'm developing, the user is limited in its possibilities. He can change a limited number of entities only.

Therefore, I do not give the user the accces the editor CADViewX. I created my own interface. I disabled components CADViewX (Explorer, Favorites, Properties, ToolBar, StatusBar, ...) and I intercept mouse events.

So I can not use:
"selected = CADViewX1.GetCADEditor (). Selected"
since the user can not select an entity.

When the user clicks, i can only compare mouse coordinates (2D screen) to CADImage coordinates (3D drawing).

I will try to develop my own method to detect the entity on which the user clicked. The method that I currently see is to cover all entities and compare mouse coordinates (2D screen) with Entity.Box coordinates (3D drawing). If you see a better track, do not hesitate to report it.

Thank you in advance.

support
Posts: 2930
Joined: 30 Mar 2005, 11:36
Contact:

Re: How to recognize on which entity is clicked?

Post by support » 07 Dec 2012, 18:16

But you can implement the code to Editor event handler. So entity will be deselected after you identify it:

Code: Select all

    this.Editor = CADViewX1.GetCADEditor();
    this.Editor.EditorEvent += new CADViewLib.ICADEditorEvents_EditorEventEventHandler(Editor_EditorEvent);
...
    private void Editor_EditorEvent(CADViewLib.TxCADEditorEventID ID, CADViewLib.CADImage AImage, CADViewLib.Entity AEntities)
    {
        CADViewLib.Entity selected = (CADViewLib.Entity)Editor.Selected;
        if (selected.Count == 1)
            MessageBox.Show((Editor.Selected.get_Entities(0)).CADHandle.ToString());
        Editor.Clear();
    }
Alexander.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

xavier
Posts: 27
Joined: 04 Dec 2012, 14:58

Re: How to recognize on which entity is clicked?

Post by xavier » 07 Dec 2012, 18:28

Thanks

xavier
Posts: 27
Joined: 04 Dec 2012, 14:58

Re: How to recognize on which entity is clicked?

Post by xavier » 11 Dec 2012, 14:10

Hello

I tested this method:

Code: Select all

 private void Editor_EditorEvent(CADViewLib.TxCADEditorEventID ID, CADViewLib.CADImage AImage, CADViewLib.Entity AEntities)
        {
            CADViewLib.Entity selected = (CADViewLib.Entity)Editor.Selected;
            if ([b]selected.Count [/b]== 1)
                MessageBox.Show((Editor.Selected.get_Entities(0)).CADHandle.ToString());
            Editor.Clear();
        }
But "selected.Count" is always zero.

have you any idea why?

Xavier

xavier
Posts: 27
Joined: 04 Dec 2012, 14:58

Re: How to recognize on which entity is clicked?

Post by xavier » 11 Dec 2012, 17:48

i always get :

selected.count = 0
selected.EntID = 0
selected.EntName = UP

even if i do a "Editor.selectAll" before

support
Posts: 2930
Joined: 30 Mar 2005, 11:36
Contact:

Re: How to recognize on which entity is clicked?

Post by support » 13 Dec 2012, 19:05

Hello.
CADEditor selects an entity by mouse left button click. All previously selected entities cleared when mouse left button is clicked. So Editor.SelectAll before does nothing. You can remove the snippet from EditorEvent handler and paste it after Editor.SelectAll to check in debug mode. Please note, selection can be done when Editor mode is active.

Code: Select all

 CADViewX.Mode == 0     //Viewer mode
 CADViewX.Mode == 1     //Editor mode
 CADViewX.Mode == 2     //Redline mode
Alexander.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

xavier
Posts: 27
Joined: 04 Dec 2012, 14:58

Re: How to recognize on which entity is clicked?

Post by xavier » 14 Dec 2012, 12:28

hello

I verified: CADViewX.Mode == 1(editor mode).
However, when I left click on an entity, I still get : selected.count == 0.

I program on windev Language. I thought that it might be related to Windev. So I test in c #:

Code: Select all

namespace TestCS
{
    public partial class Form1 : Form
    {
        CADViewLib.CADEditor Editor = new CADViewLib.CADEditor();

        private void Editor_EditorEvent(CADViewLib.TxCADEditorEventID ID, CADViewLib.CADImage AImage, CADViewLib.Entity AEntities)
         {
             CADViewLib.Entity selected = (CADViewLib.Entity)Editor.Selected;
             MessageBox.Show("count : " + selected.Count.ToString());
             if (selected.Count == 1)
                 MessageBox.Show((Editor.Selected.get_Entities(0)).CADHandle.ToString());
             Editor.Clear();
         }

        public Form1()
        {
            InitializeComponent();

            // fichier
            this.axCADViewX1.LoadFile("Z:\\ActiveX\\Exe\\Test.dxf");

            // Editor
            this.Editor = axCADViewX1.GetCADEditor();
            this.Editor.EditorEvent += new CADViewLib.ICADEditorEvents_EditorEventEventHandler(Editor_EditorEvent);

            MessageBox.Show("mode : " + axCADViewX1.Mode.ToString());
        }
    }
}
I get the same result: selected.count == 0 with Mode == 1

I don't understand...
Could you explain me.

Thanks

Xavier

xavier
Posts: 27
Joined: 04 Dec 2012, 14:58

Re: How to recognize on which entity is clicked?

Post by xavier » 03 Jan 2013, 13:56

hello

an idea of ​​why "selected.count" is equal to zero when I select an entity?

support
Posts: 2930
Joined: 30 Mar 2005, 11:36
Contact:

Re: How to recognize on which entity is clicked?

Post by support » 08 Jan 2013, 15:29

Hello Xavier.
We've used other CADViewX build number for testing. You're correct, the library available with downloading link doesn't allow to receive selected entities with the provided code. We have updated the library. Please reinstall it and use the same code snippet.

http://www.cadsofttools.com/download/cadviewx.zip

Alexander.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

xavier
Posts: 27
Joined: 04 Dec 2012, 14:58

Re: How to recognize on which entity is clicked?

Post by xavier » 08 Jan 2013, 16:34

Thanks

it works

Post Reply