How to display DXF on a set size background

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

Moderators: SDS, support, admin

Post Reply
jasonz_2003
Posts: 24
Joined: 13 Apr 2006, 16:20

How to display DXF on a set size background

Post by jasonz_2003 » 05 May 2006, 06:00

Hi Sergey,

Thanks for the helps. Now a new question,

I would like the DXF drawing to be shown on a canvas of the size of the maxhining material. That is, If the material is of size 1000mm x 500mm, and the drawing(a circle for example)of size 100mm x 60mm, the circle should be show at corner of a background representing 1000mm x 500mm. The size of material should be setable by the user. I have tried the drawingBox of DXFImage, did not work. Please guide me this can be done. Please also advise How I can draw multiple copies of same DXF image on the same Canvas, as well as how to rotate the actual DXF image and then show the change. Sorry for so many questions. But only a little hint could save me days of effort. Thanks in advance.

Jason

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

Post by support » 05 May 2006, 19:12

Hi Jason,
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">I would like the DXF drawing to be shown on a canvas of the size of the maxhining material. That is, If the material is of size 1000mm x 500mm, and the drawing(a circle for example)of size 100mm x 60mm, the circle should be show at corner of a background representing 1000mm x 500mm. The size of material should be setable by the user. I have tried the drawingBox of DXFImage, did not work. Please guide me this can be done.<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
Could you explain more in detail. Do you need to display a part of the drawing? I mean any area on the drawing (rectangular, round etc.) as VIEWPORT does. DrawingBox allows to do it. But I'd like you pay attention that coordinate are set in World Coordinate System in this case (it means that you have to know exactly what part of the drawing you nee to display).
DrawingBox cuts off everything that lays behind its (DrawingBox) borders.
<blockquote id="quote"><font size="2" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">Please also advise How I can draw multiple copies of same DXF image on the same Canvas, as well as how to rotate the actual DXF image and then show the change. Sorry for so many questions. But only a little hint could save me days of effort. Thanks in advance.<hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote">
It is necessary to create TsgDXFImage class object for every necessary copy. It will allow to manage them (rotate, change background color etc.) separately of each others. You can also draw TsgDXFImage.Draw to a specified rectangle. In this case the same TsgDXFImage will draw. And if you rotate a view in one object it will rotate it in all the others.

Sergey.

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

jasonz_2003
Posts: 24
Joined: 13 Apr 2006, 16:20

Post by jasonz_2003 » 06 May 2006, 17:58

Hi Sergey,

Thanks for the reply. Sorry that I did no make my question clear.

The situation is like controling a CNC cutting. For example, the DXF file I read in contains a rectangle (140mm x 100mm). The material to be used for cutting is of size (2000mm x 1000mm). What I need is to display a Canvas of 2000mm x 1000mm and with the rectangle at the corner of the Cavas. This done, then I can duplicate the rectangle along the Canvas so the maching can cut the all rectangles in one go. Sometimes to make best use of the material, I need to rotate the graphic (rectangle) to best fit in the space (in real world coordinates). My problem is that once the sgPaintBox ReadFromFile to read in the DXF entity. I can not change the picture size anymore. I tried to use a second TsgImage control to read the DXF and set the sgPaintBox to size 2000x1000 and then Assign the picture on the second TsgImage to sgPaintBox. But displaied this way, the picture in sgPaintBox does not seem to belong to sgPaintBox as when I zoom the picture, the Canvas is zoomed but the rectangle is not zoomed. I am sure there should be a simpler way. Please help. Also, when I say to set the material size to 2000mm x 1000mm, it should be the CAD coordinates. I do not how I can set the picture size based on this size. Because I can not use GetPoint before the sgPaintBox is built.

I hope I have described clear. Need your help urgently. Thanks.

Jason

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

Post by support » 12 May 2006, 17:29

Hi Jason,

First of please accept our apologies for the long silence.
There are two ways to solve this problem.
1. CAD Import VCL (available on: http://www.cadsofttools.com/download/cadimportvcl.zip) contains DXFImage.pas in the correspondent ..\cadimportvcl\Delphi\<b>Lib</b>.. folders.
It is nesessary to move declaration of

Code: Select all

<b>procedure</b> Draw(Canvas: TCanvas; <b>const</b> Rect: TRect); <b>override</b>;
from <b>protected</b> to <b>public</b>.
Then use the following code as an example:

Code: Select all

<b>uses</b>
  ...
  SGImage, DXFImage, sgConsts;
<b>type</b>
  TForm1 = <b>class</b>(TForm)
  sgImage1: TsgImage;
  ...
  <b>private</b>
    FImg1, FImg2: TsgDXFImage;
<b>procedure</b> TForm1.Duplicate1Click(Sender: TObject);
<b>begin</b>
  FImg1 := TsgDXFImage.Create;
  FImg1.LoadFromFile('c:\Rect_big.dxf');
  FImg2 := TsgDXFImage.Create;
  FImg2.IsWithoutBorder := True;
  FImg2.LoadFromFile('c:\Rect_small.dxf');
  // sgImage1 contains big file FImg1 ('c:\Rect_big.dxf')
  sgImage1.Picture.Graphic := FImg1;
  sgImage1.Width := FImg1.Width;
  sgImage1.Height := FImg1.Height;
  TsgDXFImage(sgImage1.Picture.Graphic).IsWithoutBorder := True;
<b>end</b>;

<b>procedure</b> TForm1.sgImage1Paint(Sender: TObject);
<b>var</b>
  vRect: TRect;
  vWidth, vHeight: Integer;
<b>begin
  if</b> (FImg1 = <b>nil</b>) <b>or</b> (FImg2 = <b>nil</b>) <b>then</b> Exit;
  vWidth := FImg2.Width;
  vHeight := FImg2.Height;
  // Left direction
  vRect := Rect(0, 0, vWidth, vHeight);
  FImg2.Draw(sgImage1.Canvas, vRect);
  vRect.Left := vRect.Left + vWidth;
  vRect.Right := vRect.Right + vWidth;
  FImg2.Draw(sgImage1.Canvas, vRect);
  vRect.Left := vRect.Left + vWidth;
  vRect.Right := vRect.Right + vWidth;
  FImg2.Draw(sgImage1.Canvas, vRect);
  // Bottom direction
  vRect := Rect(0, vHeight, vWidth, vHeight <b>shl</b> 1);
  FImg2.Draw(sgImage1.Canvas, vRect);
  vRect.Top := vRect.Top + vHeight;
  vRect.Bottom := vRect.Bottom + vHeight;
  FImg2.Draw(sgImage1.Canvas, vRect);
  //rotated
  FImg2.Rotate(axisZ, -90);
  FImg2.RefreshCurrentLayout;
  vRect := Rect(vWidth, vHeight, vWidth+FImg2.Width, vHeight+FImg2.Height);
  FImg2.Draw(sgImage1.Canvas, vRect);
  FImg2.Rotate(axisZ, 90);
<b>end</b>;
2. CAD Import VCL contains a demo in the ..\cadimportvcl\Delphi\Demos\TextChange+Color2LineWeight\.. folder. We would like you to pay attention on the following code from this demo:

Code: Select all

<b>procedure</b> TForm1.sbAddScaledFilesClick(Sender: TObject);
<b>var</b>
  vCAD: TsgDXFImage;
<b>begin</b>
  Orbit3D.Visible := False;
  fmAddScaledFile := TfmAddScaledFile.Create(self);
  fmAddScaledFile.ShowModal;
  <b>if</b> fmAddScaledFile.FilesCount <> 0 <b>then
  begin</b>
    vCAD := TsgDXFImage(fmAddScaledFile.CADFile);
    btnLayers.Enabled := True;
    <b>if</b> cbShowLineWeight.Checked <b>then</b>
      vCAD.ColorToLineWeight.Text :=  Memo1.Text
    <b>else</b>
      vCAD.ColorToLineWeight.Text :=  '';
    sgPaintBox.Picture.Graphic := vCAD;
    Img := TsgDXFImage(sgPaintBox.Picture.Graphic);
    sgPaintBox.Width := Round(TsgDXFImage(fmAddScaledFile.CADFile).AbsWidth);
    sgPaintBox.Height := Round(TsgDXFImage(fmAddScaledFile.CADFile).AbsHeight);
    sgPaintBox.Invalidate;
    EnableScales;
    sb3DOrbit.Enabled := True;
    sb3DOrbit.Down := False;
    miSaveAs.Enabled := True;
    miSaveToDXF.Enabled := miSaveAs.Enabled;
  <b>end</b>;
  fmAddScaledFile.Free;
<b>end</b>;
Sergey

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

jasonz_2003
Posts: 24
Joined: 13 Apr 2006, 16:20

Post by jasonz_2003 » 12 May 2006, 19:18

Hi Sergey,

Thanks for the reply.

I am using C++ with C++Builder. If I change the .pas file, do I need to add the file to my project so as to include it into compile? I tried it but got .dcu files cannot be found error?

Jason

Evgeny
Posts: 115
Joined: 16 Mar 2004, 11:04
Location: Russia

Post by Evgeny » 29 May 2006, 19:40

Hi Jason,
Please use new version:
http://www.cadsofttools.com/download/cadimportvcl.zip
If your problem still exists please write us to support@cadsofttools.com
Thank you.
Kind regards,
Evgeny

Post Reply