Nearest Point

Discuss and ask questions about CAD VCL (Delphi and C++ Builder).

Moderators: SDS, support, admin

Post Reply
techrasoft
Posts: 10
Joined: 20 Oct 2005, 07:54
Location: USA

Nearest Point

Post by techrasoft » 20 Oct 2005, 07:56

When the user clicks the mouse button, how can I calculate the nearest point or intersection? I basically need to figure out snapping the mouse like in AutoCad.

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

Post by support » 20 Oct 2005, 16:02

Hello,

Step 1.

Call <b>TsgDXFImage.GetCADCoords</b> function for obtaining real coordinates of entities.
For example:

Code: Select all

<b>var</b>
  vRect: TRect;
<b>begin</b>
...
  vRect := FImage.PictureRect;
  RealPoint := TsgDXFImage(FImage.Picture.Graphic).GetCADCoords(X / (vRect.Right - vRect.Left), (FImage.Height - Y) / (vRect.Bottom - vRect.Top))
Where:

<i>RealPoint</i> is an instance of <i>TFPoint</i>;
FImage is an instance of <i>TImage</i> or <i>TsgDXFImage</i>;
<i>X</i>, <i>Y</i> are the mouse coordinates above <i>FImage</i> obgect in pixels.

Step 2.

Call <i>TsgDXFConverter.Iterate(Proc: TsgCADEntityProc; var Params: TsgCADIterate)</i> for getting access to every entity and its data.

<b><i>procedure</b> ReadCADEntities(Entity: TsgDXFEntity);</i> - this is a user's procedure which gets entities one by one while iterating. There is an example in in SimpleImport demo in CADImportVCL\Delphi\Demos\SimpleImport folder(http://www.cadsofttools.com/download/CADImportVCL.zip).

<i>FCADParams: TsgCADIterate;</i> - returned iteration parameters

<i>Converter.Iterate(ReadCADEntities, FCADParams);</i> - call this procedure to start iteration.

Sergey.

please post questions to the forum or write to support@cadsofttools.com

techrasoft
Posts: 10
Joined: 20 Oct 2005, 07:54
Location: USA

Post by techrasoft » 20 Oct 2005, 22:39

Ok...How do I make it draw a snap box around the point as the mouse moves over the point, like in AutoCad.

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

Post by support » 21 Oct 2005, 10:13

Hello,

It is possible to implement it yourself.
It is necessary to use DXFImage.GetPoint first for obtaining snapping point coordinates on the canvas and then draw box on the canvas.

At present CADImportVCL (http://www.cadsofttools.com/download/CADImportVCL.zip) does not support snapping. But this feature is in our tasks list.

Sergey.

please post questions to the forum or write to support@cadsofttools.com

Post Reply