Page 1 of 1

CAD Import VCL Project

Posted: 12 Feb 2009, 17:12
by kerickson
Hello,

I currently use the libraries from Open Design Alliance to build an application that can show shape files and dwg files on a TCanvas at the same time for maps. I would like to have a vcl solution for this instead of the DLL based solution I have now. From reviewing your demo, it appears that your VCL components should work for this project. Basically, I want to open a DWG file and render a specific drawing rectangle at a specific scale to the canvas. I would also like to have the ability to determine if a real world coordinate is on an object or entity in the DWG drawing.

Kimberly Erickson

Re: CAD Import VCL Project

Posted: 13 Feb 2009, 16:21
by support
Dear Kimberly Erickson,

Thank you for the question.
CAD Import VCL (Web page is: http://www.cadsofttools.com/en/products ... t_vcl.html) gives access to DWG, DXF, HPGL/2, SVG and CGM inner data. Also it allows determining entities' placement in files.
First of all we would suggest you to try your files with a demo application available in the library package.
Please contact us via e-mail to support@cadsofttools.com if any technichal questions arise.

Sergey.

Re: CAD Import VCL Project

Posted: 18 Feb 2009, 01:51
by kerickson
I am testing with the demo and I would like to use the TsgCADImage to open a cad file and then render a rectangular section of the cad file to a bitmap canvas. I have tried the code at the bottom of this post, but the bitmap canvas is always blank.

CadDraw1 is declared as TsgCADImage and is created and destroyed outside this procedure. Image1 is a TImage.

The coordinates in the lCadRect are based on taking coordinates from the demo program Viewer.exe with the cad file open.

I can get the cad file to open and display using TsgDrawingNavigator however I need to be able to render the cad file to a bitmap inside a thread. Is TsgCADImage threadsafe?

Code: Select all

procedure TForm4.Button1Click(Sender: TObject);
var
  lCadRect: TFRect;
begin
  if OpenDialog1.Execute then
  begin
    CadDraw1.LoadFromFile(OpenDialog1.FileName);

    while CadDraw1.IsLoading do
      sleep(10);
      
    CadDraw1.Transparent := true;
    CadDraw1.CurrentLayout := CadDraw1.Layouts[CadDraw1.LayoutsCount-1];

      lCadRect.Left := -122.656;
      lCadRect.Right := -122.641;
      lCadRect.Top := -45.689;
      lCadRect.Bottom := -45.682;

    // draw stretched CAD graphic
    CadDraw1.DrawRect(Image1.Canvas.Handle, lCadRect, Image1.Canvas.ClipRect );
  end;
end;

Re: CAD Import VCL Project

Posted: 18 Feb 2009, 15:36
by support
Hello!
Is TsgCADImage threadsafe?
Current version of TsgCADImage uses the only thread for painting. It must be threadsafe.

Here goes code example of the correct TsgCADImage.DrawRect usage:

Code: Select all

{   Draws a part of CADImage        }
{                                   }
{   CADImage 4 parts for example    }
{    _____________                  }
{    |  1  |  3  |                  }
{    |_____|_____|                  }
{    |  2  |  4  |                  }
{    |_____|_____|                  }
{                                   }

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, CADImage, DXFConv, DXF, sgConsts, StdCtrls, ExtCtrls, ExtDlgs;

type
  TForm1 = class(TForm)
    btnTopLeft: TButton;
    btnBottomLeft: TButton;
    btnTopRight: TButton;
    btnBottomRight: TButton;
    ImageFull: TImage;
    ImageRect: TImage;
    Panel1: TPanel;
    OpenPictureDialog: TOpenPictureDialog;
    procedure btnStartClick(Sender: TObject);
    procedure btnTopLeftClick(Sender: TObject);
    procedure btnBottomLeftClick(Sender: TObject);
    procedure btnTopRightClick(Sender: TObject);
    procedure btnBottomRightClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    CADDraw1: TsgCADImage;
    FCADRect: TFRect;
    FExtents: TFRect;
    FHeight: Double;
    FWidth: Double;
  public
    procedure DrawCADRect;
    function InitCADRect: Boolean;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btnStartClick(Sender: TObject);
begin
  if not OpenPictureDialog.Execute then Exit;
  CADDraw1.Free;  
  CADDraw1 := TsgCADdxfImage.Create;
  CADDraw1.LoadFromFile(OpenPictureDialog.FileName);
  ImageFull.Stretch := True;
  ImageFull.Picture.Graphic := CADDraw1;
  ImageRect.Canvas.FillRect(ImageRect.ClientRect);
  FExtents := CADDraw1.Extents;
  FHeight := CADDraw1.AbsHeight;
  FWidth := CADDraw1.AbsWidth;
end;

procedure TForm1.DrawCADRect;
begin
  CADDraw1.DrawRect(ImageRect.Canvas.Handle, FCADRect, ImageRect.ClientRect);
  ImageRect.Refresh;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  CADDraw1.Free;
end;

function TForm1.InitCADRect: Boolean;
begin
  Result := CADDraw1 <> nil;
  if not Result then Exit;
  FCADRect := FExtents;
end;

//  1 topleft part
procedure TForm1.btnTopLeftClick(Sender: TObject);
begin
  if not InitCADRect then Exit;
  FCADRect.Right := FExtents.Right - FWidth/2;
  FCADRect.Bottom := FExtents.Bottom + FHeight/2;
  DrawCADRect;
end;

//  2 bottomleft part
procedure TForm1.btnBottomLeftClick(Sender: TObject);
begin
  if not InitCADRect then Exit;
  FCADRect.Right := FExtents.Right - FWidth/2;
  FCADRect.Top := FExtents.Top - FHeight/2;
  DrawCADRect;
end;

//  3 topright part
procedure TForm1.btnTopRightClick(Sender: TObject);
begin
  if not InitCADRect then Exit;
  FCADRect.Left := FExtents.Left + FWidth/2;
  FCADRect.Bottom := FExtents.Top - FHeight/2;
  DrawCADRect;
end;

// 4 bottomright
procedure TForm1.btnBottomRightClick(Sender: TObject);
begin
  if not InitCADRect then Exit;
  FCADRect.Left := FExtents.Left + FWidth/2;
  FCADRect.Top := FExtents.Top - FHeight/2;
  DrawCADRect;
end;

end.

Re: CAD Import VCL Project

Posted: 02 Apr 2015, 15:19
by clarcks
ow. From reviewing your demo, it appears that your VCL components should work for this project. Basically, I want to open a DWG file and render a specific drawing rectangle at a specific scale to the canvas. I would also like to have the ability to determine if a real world coordinate is on an object or entity in the DWG drawing.