Problems in CAD Editor demo

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

Moderators: SDS, support, admin

AlexUS
Posts: 53
Joined: 05 Dec 2006, 14:44

Post by AlexUS » 15 Dec 2006, 14:26

Hi Sergey
I made something like navigation image in Editor where I want to put navigation image NavImage: TsgImage on which I want to draw red rectangle that shows part of AutoCAD tgat is visible in main image (it's useful if zoom is used). And I have two questions:
1. Is it possible to copy main sgImage into NavImage easier and faster then i've done it?

Code: Select all

  NavImage.LoadFromFile(OpenDialog.FileName);
  NavImage.Align := alNone;
  NavImage.Align := alClient;
I mean not using LoadFromFile
2. How can I get coordinates of part of image that is shown in main sgImage (for drawinf rectangle in navigation image)?

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

Post by support » 15 Dec 2006, 15:39

Hello Alex,
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">I made something like navigation image in Editor where I want to put navigation image NavImage: TsgImage on which I want to draw red rectangle that shows part of AutoCAD tgat is visible in main image (it's useful if zoom is used). And I have two questions:
1. Is it possible to copy main sgImage into NavImage easier and faster then i've done it?

Code: Select all

  NavImage.LoadFromFile(OpenDialog.FileName);
  NavImage.Align := alNone;
  NavImage.Align := alClient;
I mean not using LoadFromFile<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">

Try to use <b>NavImage.Picture.Graphic.Assign(sgImage.Picture.Graphic)</b>. But it is important to remember that in this case both <b>TsgDXFImage</b> object stored in the <b>TsgImage.Picture.Graphic</b> have common TsgDXFConverter. It means that when changing entities in the first <b>TsgDXFImage</b>, entities in the other <b>TsgDXFImage</b> will be changed too.
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">2. How can I get coordinates of part of image that is shown in main sgImage (for drawinf rectangle in navigation image)?<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
If possible, please describe in detail what task do you have. It looks like there is some marker over the main <b>sgImage</b> and the other <b>sgImage</b> has to view area under the marker. Isn't it?

Sergey.

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

AlexUS
Posts: 53
Joined: 05 Dec 2006, 14:44

Post by AlexUS » 18 Dec 2006, 10:51

Hi, Sergey
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">Try to use NavImage.Picture.Graphic.Assign(sgImage.Picture.Graphic)<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
I've tried to use NavImage.Picture.Graphic.Assign in NavImage.Picture.Graphic.Assign:\

Code: Select all

  sgImage.LoadFromFile(OpenDialog.FileName);
  NavImage.Picture.Graphic.Assign(sgImage.Picture.Graphic);
But it causes the access violation mistake.
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">
If possible, please describe in detail what task do you have. It looks like there is some marker over the main sgImage and the other sgImage has to view area under the marker. Isn't it?
<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
Yes, you are right. I want to make another little TsgImage (NavImage) that will show whole opened image and show by rectangle visible part of main TsgImage (but main image is not the image with marker.) Image with marker is to be navigation image with its mouse events. I want to make possible to move this marker and accordingly will change visible part of main image (in case of more than 100% zoom) .

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

Post by support » 18 Dec 2006, 15:39

Hello Alex,

<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">I've tried to use NavImage.Picture.Graphic.Assign in NavImage.Picture.Graphic.Assign:\

Code: Select all

  sgImage.LoadFromFile(OpenDialog.FileName);
  NavImage.Picture.Graphic.Assign(sgImage.Picture.Graphic);
But it causes the access violation mistake.<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">

Possibly <b>NavImage.Picture.Graphic = nil</b>. If yes, call <b>LoadFromFile(OpenDialog.FileName);</b>
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">Yes, you are right. I want to make another little TsgImage (NavImage) that will show whole opened image and show by rectangle visible part of main TsgImage (but main image is not the image with marker.) Image with marker is to be navigation image with its mouse events. I want to make possible to move this marker and accordingly will change visible part of main image (in case of more than 100% zoom) .<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
Please, wait a little. We need to make some tests.

Sergey.

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

AlexUS
Posts: 53
Joined: 05 Dec 2006, 14:44

Post by AlexUS » 18 Dec 2006, 17:04

Hi, Sergey
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">Please, wait a little. We need to make some tests.<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
Ok. Thank you!
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">Possibly NavImage.Picture.Graphic = nil. If yes, call LoadFromFile(OpenDialog.FileName);<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
You are right: NavImage.Picture.Graphic = nil and with LoadFromFile(OpenDialog.FileName) it works. I started from the question how to make it faster without calling LoadFromFile(OpenDialog.FileName).
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">1. Is it possible to copy main sgImage into NavImage easier and faster then i've done it?

Code: Select all

  NavImage.LoadFromFile(OpenDialog.FileName);
  NavImage.Align := alNone;
  NavImage.Align := alClient;<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
Because if CAD-file is huge it takes twice more time to open one document in Editor. I want to make copy of image without calling LoadFromFile, if it possible.

AlexUS
Posts: 53
Joined: 05 Dec 2006, 14:44

Post by AlexUS » 19 Dec 2006, 13:19

Hi, Sergey
I have another one question.
I use combobox for scaling image in definite scale values. For example,

Code: Select all

sgImage.ChangeScale(True, 0.1, CurPos);
is 10% scale. Isn't it?
And does current scale value equal to 1/(1/sgImage.Scale)*100 (in percents)?
And how can I get coordinates of central point of current visible part of image (that i see on form). This question is connected with previous bacause in navigation it's needed to have the same coordinates.

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

Post by support » 19 Dec 2006, 18:24

Hi, Alex.

<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">
I use combobox for scaling image in definite scale values. For example,

Code: Select all

  sgImage.ChangeScale(True, 0.1, CurPos);
is 10% scale. Isn't it?<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
If you use this function just like it is written, it is 10% scale.
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">And does current scale value equal to 1/(1/sgImage.Scale)*100 (in percents)?<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
Yes, it does. Make it simpler: sgImage.Scale * 100

<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">And how can I get coordinates of central point of current visible part of image (that i see on form). This question is connected with previous bacause in navigation it's needed to have the same coordinates.<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
It is necessary to use the following properties:
<b>X</b> coordinate - <b>sgImage1.Parent.Width div 2</b>
<b>Y</b> coordinate -<b>sgImage1.Parent.Height div 2</b>.

Sergey.


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

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

Post by support » 20 Dec 2006, 14:56

<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by AlexUS</i>
<br />Hi, Sergey
...
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">
If possible, please describe in detail what task do you have. It looks like there is some marker over the main sgImage and the other sgImage has to view area under the marker. Isn't it?
<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
Yes, you are right. I want to make another little TsgImage (NavImage) that will show whole opened image and show by rectangle visible part of main TsgImage (but main image is not the image with marker.) Image with marker is to be navigation image with its mouse events. I want to make possible to move this marker and accordingly will change visible part of main image (in case of more than 100% zoom) .
<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">

Hi Alex,

Here goes a code of a simple demo which has two <b>TsgImage</b> objects. <b>sgImage1</b> contains loaded CAD file and views only a part of the image.
<b>NavImage</b> contains a copy of the loaded CAD file and views the whole image.
<b>Note</b>: both images has common <b>Converter</b>. That is if you change entities' properties in one image, they will be changed in the another too.
<b>sgImage1</b> changes view respectively to mouse cursor position over <b>NavImage</b>.

Code: Select all

<b>uses</b>
  ... SGImage, DXFImage, sgConsts;

<b>type</b>
  TForm1 = <b>class</b>(TForm)
    ...
    btnOpenFile: TButton;
    sgImage1: TsgImage;
    NavImage: TsgImage;
    OpenDialog1: TOpenDialog;
    <b>procedure</b> btnOpenFileClick(Sender: TObject);
    <b>procedure</b> NavImageMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  <b>private</b>
    { Private declarations }
    FImg: TsgDXFImage;
  ...

<b>procedure</b> TForm1.btnOpenFileClick(Sender: TObject);
<b>var</b>
  vGraph: TGraphic;
<b>begin
  if not</b> OpenDialog1.Execute <b>then</b>
    Exit;
  sgImage1.LoadFromFile(OpenDialog1.FileName);
  vGraph := TGraphicClass(sgImage1.Picture.Graphic.ClassType).Create;
  vGraph.Assign(sgImage1.Picture.Graphic);
  <b>if</b> sgImage1.Picture.Graphic <b>is</b> TsgDXFImage <b>then
  begin</b>
    sgImage1.Align := alNone;
    NavImage.Picture.Graphic := vGraph;
    NavImage.Align := alClient;

    FImg := TsgDXFImage(sgImage1.Picture.Graphic);
  <b>end
  else
  begin</b>
    FImg := <b>nil</b>;    
  <b>end</b>;
  vGraph.Free;
<b>end</b>;

<b>procedure</b> TForm1.NavImageMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
<b>var</b>
  vPoint, vPoint2: TFPoint;
  FRect: TFRect;

  <b>procedure</b> CalcParamsForShowPoint(<b>var</b> Location: TFPoint;
      AsgImage: TsgImage; <b>var</b> APoint: TFPoint; <b>var</b> ARect: TFRect);
  <b>var</b>
    vPoint: TPoint;
    vRect: TRect;
    R: Double;
  <b>begin</b>
    vPoint := FImg.GetPoint(Location);
    APoint := MakeFPoint(vPoint.X, vPoint.Y, 0);
    vRect := AsgImage.PictureRect;
    <b>if</b> AsgImage.UsePictureRect <b>then
      begin</b>
        vRect.Left := vRect.Left - AsgImage.Left;
        vRect.Right := vRect.Right - AsgImage.Left;
        vRect.Top := vRect.Top - AsgImage.Top;
        vRect.Bottom := vRect.Bottom - AsgImage.Top;
      <b>end</b>;
      ARect := MakeFRect(vRect.Left, vRect.Top, 0, vRect.Right, vRect.Bottom, 0);
      <b>if not</b> AsgImage.UsePictureRect <b>then
      begin</b>
        APoint.X := APoint.X + ARect.Left;
        APoint.Y := APoint.Y + ARect.Top;
      <b>end</b>;
  <font color="blue"><i>//TFRect top must be greater than bottom</i></font id="blue">
    R := ARect.Top;
    ARect.Top := ARect.Bottom;
    ARect.Bottom := R;
  <b>end</b>;

<b>begin
  if</b> FImg = <b>nil then</b>
    Exit;
  sgImage1.Align := alNone;

  vPoint := FImg.GetCADCoords(X/NavImage.Width , 1 - Y/NavImage.Height);

  FRect := FImg.Extents;
  CalcParamsForShowPoint(vPoint, sgImage1, vPoint2, FRect);
  sgImage1.ShowPoint(vPoint2, 100, FRect);
<b>end</b>;

<b>end</b>.
<b>Important</b>: this code works with <b>CAD Import VCL</b> beta version: http://www.cadsofttools.com/download/CA ... 010906.zip

Sergey.

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

AlexUS
Posts: 53
Joined: 05 Dec 2006, 14:44

Post by AlexUS » 22 Dec 2006, 16:40

Hi, Sergey
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">Here goes a code of a simple demo which has two TsgImage objects. sgImage1 contains loaded CAD file and views only a part of the image<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
Thank you very much. I've tested this code and it works perfectly. It's exactly what i wanted to do. But I have one problem.
How to get coordinates of visible part sgImage1 for drawing rectangle on NavImage that shows what part of image does user see?

AlexUS
Posts: 53
Joined: 05 Dec 2006, 14:44

Post by AlexUS » 28 Dec 2006, 15:03

Hi, Sergey
Can you please help me in using your component? Have you seen my question that I posted few days ago?
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">How to get coordinates of visible part sgImage1 for drawing rectangle on NavImage that shows what part of image does user see?<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
It's steel problem that i can't solve. I hope on your help

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

Post by support » 28 Dec 2006, 15:41

Hi Alex,

Do you want to get coordinates on the sgImage1 for further drawing rectangle on the NavImage?

Or you need to draw on the sgImage1 area selected by rectangle on the NavImage?

Sergey.

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

AlexUS
Posts: 53
Joined: 05 Dec 2006, 14:44

Post by AlexUS » 03 Jan 2007, 14:05

Hi, Sergey!
By the way I wish you a Happy New Year!!! I wish all the best in 2007 for you and for whole your team of CAD Soft Tools.

I want to draw on NavImage rectangle that shows the visible part of whole image according to point of view and current scale. It's for showing user what exactly part of image he does see in sgImage1.

AlexUS
Posts: 53
Joined: 05 Dec 2006, 14:44

Post by AlexUS » 09 Jan 2007, 13:29

Hi, Sergey
What is the relation between TsgDXFLine.Thickness and TsgDXFLine.SetLWeight.
If I use TsgDXFLine(Entity).Thickness := 100 and TsgDXFLine(Entity).SetLWeight (100) I receive different results.
And what about my previous question?

Alex

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

Post by support » 10 Jan 2007, 14:17

Hello Alex,

First of all thank you very much for the congratulations. From the name of all CADSoftTools team let me wish you in the come new year wealth, health and success in all your beginings.

According to your questions:

<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">I want to draw on NavImage rectangle that shows the visible part of whole image according to point of view and current scale. It's for showing user what exactly part of image he does see in sgImage1.<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
Here go two ways of solving this task:

<b>The first one</b>:

Code: Select all

<b>uses</b>
  ... SGImage, DXFImage, sgConsts, DXFConv;

<b>type</b>
  TForm1 = <b>class</b>(TForm)
    ...
    btnOpenFile: TButton;
    sgImage1: TsgImage;
    NavImage: TsgImage;
    OpenDialog1: TOpenDialog;
    <b>procedure</b> btnOpenFileClick(Sender: TObject);
    <b>procedure</b> NavImageMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    <b>procedure</b> FormCreate(Sender: TObject);
  <b>private</b>
    <font color="blue"><i>{ Private declarations }</i></font id="blue">
    FImg: TsgDXFImage;
    OldNavRect: TRect;
...

<b>var</b>
  Form1: TForm1;

<b>implementation</b>

{$R *.dfm}

<b>function</b> GetRealPointUsingsgImagePoint(AImage: TImage; X, Y: Integer): TFPoint;
<b>var</b>
  vRect: TRect;
  vXScaled, vYScaled: Extended;
<b>begin</b>
  vRect := TsgImage(AImage).PictureRect;
  <b>if</b> ((vRect.Right - vRect.Left) <= AImage.Width) <b>or</b> ((vRect.Bottom - vRect.Top) <= AImage.Height) <b>then
  begin</b>
    vXScaled := X / (vRect.Right - vRect.Left);
    vYScaled := (AImage.Height - Y) / (vRect.Bottom - vRect.Top);
  <b>end
  else
  begin</b>
    vXScaled := (-(vRect.Left  - AImage.Left) + X) / (vRect.Right - vRect.Left);
    vYScaled := 1 - (Y - (vRect.Top - AImage.Top)) / (vRect.Bottom - vRect.Top);
  <b>end</b>;
  Result := TsgDXFImage(AImage.Picture.Graphic).GetCADCoords(vXScaled, vYScaled);
<b>end</b>;

<b>procedure</b> TForm1.btnOpenFileClick(Sender: TObject);
<b>var</b>
  vGraph: TGraphic;
  vCenter: TPoint;
  ScaleSizes: Boolean;
<b>begin
  if not</b> OpenDialog1.Execute <b>then</b>
    Exit;
  sgImage1.LoadFromFile(OpenDialog1.FileName);
  vGraph := TGraphicClass(sgImage1.Picture.Graphic.ClassType).Create;
  vGraph.Assign(sgImage1.Picture.Graphic);
  <b>if</b> sgImage1.Picture.Graphic <b>is</b> TsgDXFImage <b>then
  begin</b>
    sgImage1.Align := alNone;
    NavImage.Picture.Graphic := vGraph;
    NavImage.Align := alClient;
    ScaleSizes := true;
    vCenter.X := sgImage1.Width <b>shr</b> 1;
    vCenter.Y := sgImage1.Height <b>shr</b> 1;
    sgImage1.ChangeScale(ScaleSizes, NavImage.Scale * 8, vCenter);

    FImg := TsgDXFImage(sgImage1.Picture.Graphic);
  <b>end
  else
  begin</b>
    FImg := <b>nil</b>;
  <b>end</b>;
  vGraph.Free;
<b>end</b>;

<b>procedure</b> TForm1.NavImageMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
<b>var</b>
  vPoint, vPoint2: TFPoint;
  FRect: TFRect;
  OldPenMode: TPenMode;
  NewNavRect: TRect;
  vImg: TsgDXFImage;

  <b>procedure</b> CalcParamsForShowPoint(<b>var</b> Location: TFPoint;
      AsgImage: TsgImage; <b>var</b> APoint: TFPoint; <b>var</b> ARect: TFRect);
  <b>var</b>
    vPoint: TPoint;
    vRect: TRect;
    R: Double;
  <b>begin</b>
    vPoint := FImg.GetPoint(Location);
    APoint := MakeFPoint(vPoint.X, vPoint.Y, 0);
    vRect := AsgImage.PictureRect;
    <b>if</b> AsgImage.UsePictureRect <b>then
      begin</b>
        vRect.Left := vRect.Left - AsgImage.Left;
        vRect.Right := vRect.Right - AsgImage.Left;
        vRect.Top := vRect.Top - AsgImage.Top;
        vRect.Bottom := vRect.Bottom - AsgImage.Top;
      <b>end</b>;
      ARect := MakeFRect(vRect.Left, vRect.Top, 0, vRect.Right, vRect.Bottom, 0);
      <b>if not</b> AsgImage.UsePictureRect <b>then
      begin</b>
        APoint.X := APoint.X + ARect.Left;
        APoint.Y := APoint.Y + ARect.Top;
      <b>end</b>;
  <font color="blue"><i>//The TFRect top must be greater than bottom</i></font id="blue">
    R := ARect.Top;
    ARect.Top := ARect.Bottom;
    ARect.Bottom := R;
  <b>end</b>;

<b>begin
  if</b> FImg = <b>nil then</b>
    Exit;

  sgImage1.Align := alNone;
  vPoint := GetRealPointUsingsgImagePoint(NavImage, X ,Y);
  NewNavRect.Left := X - NavImage.ClientWidth <b>div</b> 16;
  NewNavRect.Top := Y - NavImage.ClientHeight <b>div</b> 16;
  NewNavRect.Right := X + NavImage.ClientWidth <b>div</b> 16;
  NewNavRect.Bottom := Y + NavImage.ClientHeight <b>div</b> 16;

  CalcParamsForShowPoint(vPoint, sgImage1, vPoint2, FRect);
  sgImage1.ShowPoint(vPoint2, 8 * NavImage.Scale * 100, FRect);

  OldPenMode := NavImage.Canvas.Pen.Mode;

  NavImage.Canvas.Brush.Style := bsClear;
  NavImage.Canvas.Pen.Mode := pmXor;
  NavImage.Canvas.Pen.Color := <b>not</b> NavImage.Canvas.Brush.Color;

  NavImage.Canvas.Rectangle(OldNavRect);

  NavImage.Canvas.Rectangle(NewNavRect);
  OldNavRect := NewNavRect;

  NavImage.Canvas.Pen.Mode := OldPenMode;
<b>end</b>;

<b>procedure</b> TForm1.FormCreate(Sender: TObject);
<b>begin</b>
  OldNavRect := Rect(0,0,0,0);
<b>end</b>;

<b>end</b>.
<b>The second one</b>:

Code: Select all

<b>uses</b>
  ... SGImage, DXFImage, sgConsts, DXFConv;

<b>type</b>
  TForm2 = <b>class</b>(TForm)
    ...
    btnOpenFile: TButton;
    NavImage: TsgImage;
    sgImage1: TsgImage;
    OpenDialog1: TOpenDialog;
    <b>procedure</b> btnOpenFileClick(Sender: TObject);
    <b>procedure</b> NavImageMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    <b>procedure</b> FormCreate(Sender: TObject);
    <b>procedure</b> NavImagePaint(Sender: TObject);
  <b>private</b>
    <font color="blue"><i>{ Private declarations }</i></font id="blue">
    OldNavRect: TRect;
...

<b>var</b>
  Form2: TForm2;

<b>implementation</b>

{$R *.dfm}

<b>function</b> GetRealPointUsingsgImagePoint(AImage: TImage; X, Y: Integer): TFPoint;
<b>var</b>
  vRect: TRect;
  vXScaled, vYScaled: Extended;
<b>begin</b>
  vRect := TsgImage(AImage).PictureRect;
  <b>if</b> ((vRect.Right - vRect.Left) <= AImage.Width) <b>or</b> ((vRect.Bottom - vRect.Top) <= AImage.Height) <b>then
  begin</b>
    vXScaled := X / (vRect.Right - vRect.Left);
    vYScaled := (AImage.Height - Y) / (vRect.Bottom - vRect.Top);
  <b>end
  else
  begin</b>
    vXScaled := (-(vRect.Left  - AImage.Left) + X) / (vRect.Right - vRect.Left);
    vYScaled := 1 - (Y - (vRect.Top - AImage.Top)) / (vRect.Bottom - vRect.Top);
  <b>end</b>;
  Result := TsgDXFImage(AImage.Picture.Graphic).GetCADCoords(vXScaled, vYScaled);
<b>end</b>;

<b>procedure</b> TForm2.btnOpenFileClick(Sender: TObject);
<b>begin
  if</b> OpenDialog1.Execute <b>then</b>
    NavImage.LoadFromFile(OpenDialog1.FileName);
  <b>if</b> NavImage.Picture.Graphic <b>is</b> TsgDXFImage <b>then</b>
    NavImage.Align := alClient;
<b>end</b>;

<b>procedure</b> TForm2.NavImageMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
<b>var</b>
  FRect: TFRect;
  vImg: TsgDXFImage;
<b>begin</b>
  vImg := TsgDXFImage(NavImage.Picture.Graphic);
  <b>if</b> vImg = <b>nil then</b>
    Exit;
  OldNavRect.Left := X - NavImage.ClientWidth <b>div</b> 16;
  OldNavRect.Top := Y - NavImage.ClientHeight <b>div</b> 16;
  OldNavRect.Right := X + NavImage.ClientWidth <b>div</b> 16;
  OldNavRect.Bottom := Y + NavImage.ClientHeight <b>div</b> 16;

  FRect.TopLeft := GetRealPointUsingsgImagePoint(NavImage, OldNavRect.Left, OldNavRect.Top);
  FRect.BottomRight := GetRealPointUsingsgImagePoint(NavImage, OldNavRect.Right, OldNavRect.Bottom);

  vImg.DrawRect(sgImage1.Canvas.Handle, FRect, sgImage1.ClientRect);
<b>end</b>;

<b>procedure</b> TForm2.FormCreate(Sender: TObject);
<b>begin</b>
  OldNavRect := Rect(0,0,0,0);
<b>end</b>;

<b>procedure</b> TForm2.NavImagePaint(Sender: TObject);
<b>begin</b>
  NavImage.Canvas.Brush.Style := bsClear;
  NavImage.Canvas.Rectangle(OldNavRect);
<b>end</b>;

<b>end</b>.
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">If I use TsgDXFLine(Entity).Thickness := 100 and TsgDXFLine(Entity).SetLWeight (100) I receive different results.<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
TsgDXFLine(Entity).SetLWeight converts entered value to AutoCAD units type (into the 100 of millimeters, thus TsgDXFLine(Entity).SetLWeight(100) means 1 millimeter for lineweight).
TsgDXFLine(Entity).Thickness sets this value as is. We do not recommend to use TsgDXFLine(Entity).Thickness, because it will be changed in future versions of the library.

Sergey.

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

AlexUS
Posts: 53
Joined: 05 Dec 2006, 14:44

Post by AlexUS » 11 Jan 2007, 13:00

Hi, Sergey.
Thank you for your reply about rect drawing on NavImage. Unfortunately it's not exactly what I wanted to make. Do you remember, I asked:
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">I want to draw on NavImage rectangle that shows the visible part of whole image according to point of view and current scale. It's for showing user what exactly part of image he does see in sgImage1.<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
I mean that:
1. Center of little rectangle on NavImage sets the center of visible part on sgImage1
2. TopLeft and BottomRight coordinates of rectangle on NavImage depends on current scale of sgImage1 and borders of visible part of sgImage1. But in your examples rectangle has constant size
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">NewNavRect.Left := X - NavImage.ClientWidth div 16;
NewNavRect.Top := Y - NavImage.ClientHeight div 16;
NewNavRect.Right := X + NavImage.ClientWidth div 16;
NewNavRect.Bottom := Y + NavImage.ClientHeight div 16;<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
I want to make rectangle show exactly what i see in main image. If i make zoomout on sgImage1 - rectangle becomes bigger, if i make zoomin - rectangle becomes smaller.
And this rectangle shows borders of current visible part on sgImage1. If I move rectangle on NavImage - changes visible part on sgImage1, if I change visible part of sgImage1 (zoom or move) - rectangle on navImage resizes and moves according to that changes.

About TsgDXFPoint: thank you but you forgot to tell me about what properties you reserved for changing it's form (point, cross, etc. )

Thank you very much for supporting!
I'm going to buy your component in a few days and apart i hope on supporting in ordering and other questions.

Post Reply