Page 1 of 1

Nearest Point

Posted: 20 Oct 2005, 07:56
by techrasoft
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.

Posted: 20 Oct 2005, 16:02
by support
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

Posted: 20 Oct 2005, 22:39
by techrasoft
Ok...How do I make it draw a snap box around the point as the mouse moves over the point, like in AutoCad.

Posted: 21 Oct 2005, 10:13
by support
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