Problems with ChangeScale method
Posted: 15 May 2006, 14:48
Hi,
I'm using TsgImage and TsgDxfImage with delphi 2005.
I would like to display an area (define by a rectangle) of a dxf file into a tSgImage, but i've some problems (bug maybe) with TsgImage.changeScale method.
To do this, I've made the following procedure
I think there is something wrong with "MyImage.GetPoint(" and
"TsgImage.changeScale"
If someone as an solution, I would be great.
Thanks.
I'm using TsgImage and TsgDxfImage with delphi 2005.
I would like to display an area (define by a rectangle) of a dxf file into a tSgImage, but i've some problems (bug maybe) with TsgImage.changeScale method.
To do this, I've made the following procedure
I think there is something wrong with "MyImage.GetPoint(" and
"TsgImage.changeScale"
If someone as an solution, I would be great.
Thanks.
Code: Select all
Procedure TFormDxfPlan.ZoomOnRect(Xinf,YInf,XSup,YSup : Double);
Var
MyImage : TsgDXFImage;
RectWidth, RectHeight : double ;
sgWidth, sgHeight : Double;
ZoomFactor : double ;
RectCenter3D : TFPoint ;
ScreenRectCenter : Tpoint ;
ZoomInOneStep : boolean ;
begin
// Here we use sgImage1 (TsgImage) to display an autocad file (dwg or dxf format)
// with a TsgDXFImage
// This procedure is used to zoom on the rectangle define by the cad coordinates
// given in paramaters
// To display all the contens of the dwg file
sgImage1.Align := AlNone;
sgImage1.Align := alClient;
sgImage1.Refresh;
// MyImage has allready loaded the autocad file
MyImage := TsgDXFImage(sgImage1.Picture.Graphic);
// dimension of the rectangle to display
RectWidth := (XSup-XInf);
RectHeight := (YSup-YInf);
// dimension of the whole dxf image
sgWidth := MyImage.Width;
sgHeight := MyImage.Height;
// zoom factor needed to display the rect into sgimage
ZoomFactor := Min( (sgWidth / RectWidth) , (sgHeight / RectHeight) );
// Center Point of the rectangle
RectCenter3D.x := ((XSup+XInf)/ 2);
RectCenter3D.y := ((YSup+YInf)/ 2);
RectCenter3D.z := 0 ;
ZoomInOneStep := {TRue ;//} False ;
if ZoomInOneStep then
begin
// If ZoomInOneStep is true the scale is changed in one step (it dont works)
// convert rectcenter (cad coordinates) into screen coordinates
ScreenRectCenter := MyImage.GetPoint(RectCenter3D);
// Zoom factor is Ok but the view is not centered around ScreenRectCenter
// but around the center of MyImage
sgImage1.ChangeScale( True , ZoomFactor , ScreenRectCenter ) ;
end
else
begin
// if ZoomInOneStep is False the scale is change with many step
// to get a better result. It's better then in one step (closer to the rectangle to display)
// but not really good either
while sgImage1.Scale < ZoomFactor do
begin
// convert rectcenter (cad coordinates) into screen coordinates
// PROBLEM : for each step, this value must be updated but it s not
// It allways the walue of the first step that I get
ScreenRectCenter := MyImage.GetPoint(RectCenter3D);
sgImage1.ChangeScale( false , 1.2 , ScreenRectCenter ) ;
sgImage1.Refresh;
end;
end;
end;