Page 1 of 1
Base operations with TsgCADdxfImage - please help
Posted: 05 Jan 2015, 17:28
by h.o.o.k
Hello cadsofttools team

Our company bought your library VCL Import 10 and please i need advice.
I need prepare this operation with DXF file through TsgCADdxfImage objekt.
Scale (zooming):
Why not work this?:
Code: Select all
vDrawing := TsgCADdxfImage.Create;
vDrawing.LoadFromFile('map.dxf');
vDrawing.GetExtents;
vDrawing.ScaleDrawMatrix(2,2,2);
vDrawing.GetExtents;
// ...draw on canvas
MyImage.Canvas.draw(0,0,vDrawing);
And moving with all??
Code: Select all
vDrawing := TsgCADdxfImage.Create;
vDrawing.LoadFromFile('map.dxf');
vDrawing.GetExtents;
vDrawing.ScaleDrawMatrix(2,2,2);
vDrawing.TranslateDrawMatrix(200,200,0);
// .. draw to canvas
MyImage.Canvas.draw(0,0,vDrawing);
this not work too:
Code: Select all
vDrawing := TsgCADdxfImage.Create;
vDrawing.LoadFromFile('map.dxf');
vDrawing.GetExtents;
TsgCADImageAccess(vDrawing).ApplyScale(rect(500,500,1000,1000));
vDrawing.GetExtents;
// .. draw to canvas
MyImage.Canvas.draw(0,0,vDrawing);
etc. vDrawing.Rotate(axisZ,90) work fine.
I must write than i need this operation without TsgDrawingNavigator , beceause TsgDrawingNavigator does not fit to my conception.
Exist some example code on this oepration only with TsgCADdxfImage ?
Thank you very much for some reply
Peter
Re: Base operations with TsgCADdxfImage - please help
Posted: 05 Jan 2015, 19:11
by support
Hello Peter,
You should set
TsgCADImage.CustomDraw property value to False, then initialize the drawing matrix before scaling. The following code is correct:
Code: Select all
uses
..., CADImage, DXF, sgFunction, sgConsts;
...
vDrawing.GetExtents;
vDrawing.CustomDraw := False;
// Initialize the drawing matrix
vDrawing.SetDrawMatrix(StdMat(MakeFPoint(1, -1, 1), cnstFPointZero));
// Scale the drawing matrix
vDrawing.ScaleDrawMatrix(2,2,2);
vDrawing.GetExtents;
// Draw on canvas
MyImage.Canvas.Draw(0, 0, vDrawing);
Mikhail
Re: Base operations with TsgCADdxfImage - please help
Posted: 05 Jan 2015, 20:10
by h.o.o.k
Hi Mikhail, beforehand thank you for quickly reply. In our company project implement time is running out

(
But.. code not work:
Code: Select all
vDrawing := TsgCADdxfImage.Create;
vDrawing.LoadFromFile('map.dxf');
vDrawing.GetExtents;
vDrawing.CustomDraw := False;
vDrawing.SetDrawMatrix(StdMat(MakeFPoint(1, -1, 1), cnstFPointZero));
vDrawing.ScaleDrawMatrix(2,2,2);
vDrawing.GetExtents;
//draw
Image1.Canvas.Draw(0, 0, vDrawing);
When i use
vDrawing.CustomDraw := False; so Image1´s canvas is white/clear.
This Code works fine and DXF is nicely drawed on Canvas
Code: Select all
vDrawing := TsgCADdxfImage.Create;
vDrawing.LoadFromFile('map.dxf');
vDrawing.GetExtents;
//draw
Image1.Canvas.Draw(0, 0, vDrawing);
What i do wrong ?

unfortunately i dont have time for VLC library code-diving

(
Thank you.
Re: Base operations with TsgCADdxfImage - please help
Posted: 06 Jan 2015, 20:07
by support
Hello Peter,
TImage canvas is white, because the drawing objects went off the canvas area and not visible after scaling. I would recommend to use the following code for scaling operation:
Code: Select all
TsgCADImageAccess = class(TsgCADImage);
...
procedure TForm1.ScaleDrawing(AValue: Double);
var
vRect: TRect;
begin
Image1.Picture := nil;
vRect := Rect(0, 0, Round(vDrawing.AbsWidth * AValue), Round(vDrawing.AbsHeight * AValue));
TsgCADImageAccess(vDrawing).ApplyScale(vRect);
Image1.Canvas.StretchDraw(vRect, vDrawing);
end;
This procedure uses
TsgCADImage.ApplyScale method for scaling the drawing relative to the point (0,0). Note that
TsgCADImage.CustomDraw property value is not set to False here.
Mikhail
Re: Base operations with TsgCADdxfImage - please help
Posted: 06 Jan 2015, 21:07
by h.o.o.k
Its true, thank you Mikhail, you are my rescuer
Please last question, i promise
I have a map of city in DXF/DWG. I need gets map scale 1:X of this file.
I think that:
Code: Select all
_oDxf.CustomDraw := False;
defM := StdMat(MakeFPoint(1,1,1), cnstFPointZero);
_oDxf.SetDrawMatrix(defM);
_oDxf.GetExtents;
//now i have loaded file in created scale 1:1 (?)
// my resolution in scale is METER.
dWidth := _oDxf.AbsWidth; // real widh of "dxf canvas" in pixels
dWorldWidth := Abs(_oDxf.CurrentLayout.Box.Left - _oDxf.CurrentLayout.Box.Right); // suppos that units ar meters
dPixelAsMeter := (PixelPerInch / 25.4 / 1000);
dMetersOnOnePixel = dWorldWidth / dWidth;
bMapScale = (1/dPixelAsMeter) * dMetersOnOnePixel;
Its true?
For gets world units i must use
_oDxf.CurrentLayout.Box or
_oDxf.Extends ?
Thanks again.
Peter
Re: Base operations with TsgCADdxfImage - please help
Posted: 08 Jan 2015, 15:49
by support
Hello Peter,
DXF drawings are measured in drawing units, so
dWidth and
dWorldWidth values in your code will be in decimal drawing units, not in pixels or meters as you supposed. In order to get the width/height in drawing units, I would recommend to use
TsgCADImage.AbsWidth and
TsgCADImage.AbsHeight properties whose values can also be calculated in the following way:
Code: Select all
vAbsWidth := Abs(_oDxf.Extents.Left - _oDxf.Extents.Right);
vAbsHeight := Abs(_oDxf.Extents.Top - _oDxf.Extents.Bottom);
_oDxf.CurrentLayout.Box returns the bounding rectangle coordinates for a current layout.
Note that a loaded drawing contains the additional empty space (borders) by default that affects its width and height. TsgCADImage.IsWithoutBorder property specifies whether to add a border or not.
Mikhail
Re: Base operations with TsgCADdxfImage - please help
Posted: 08 Jan 2015, 17:15
by h.o.o.k
Thanks Mikhail. But Still i dont understan how i cals how much DXF units is one pixel on screen. But I will fight

Thank you for your help on our project.
with respect
Peter
Re: Base operations with TsgCADdxfImage - please help
Posted: 09 Jan 2015, 18:28
by h.o.o.k
For all (maybe usefull)
When i set default Draw matrix
Code: Select all
m := StdMat(MakeFPoint(1,-1,1), cnstFPointZero);
//.. draw
So 1 CAD UNIT = 1px on display device.
Peter