How to open multiple files in the same window tabs

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

Moderators: support, SDS, admin

Post Reply
allen
Posts: 5
Joined: 03 Dec 2015, 06:21

How to open multiple files in the same window tabs

Post by allen » 19 Feb 2016, 03:13

hi
How to open multiple files in the same window tabs
Photo is "dwg trueview 2015"
Thank you very much
Image

FieldConsult
Posts: 54
Joined: 14 Mar 2015, 22:33

Re: How to open multiple files in the same window tabs

Post by FieldConsult » 22 Feb 2016, 20:30

HI,
That is something referred to the development, not to the library.
If you want to open multiple files at the same time, you must create a navigator for each file and associate the parent property of each navigator to each page of the PageControl (Control with multiples pages).

Cheers!!!
Last edited by FieldConsult on 24 Feb 2016, 22:19, edited 1 time in total.

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

Re: How to open multiple files in the same window tabs

Post by support » 24 Feb 2016, 16:24

Hello,

To display the contents of several drawing files in tabs, you will need to use two tabbed controls: TPageControl and TTabControl. TPageControl pages (TTabSheet) containing TsgDrawingNavigator instances will display the contents of drawing file layouts, while TTabControl will be used for switching between layouts (Model, Layout1, etc.). Special attention should be paid to operating with a several TsgCADImage objects. I would recommend to use TObjectList for this purpose, because TObjectList is intended for operation with an indefinite amount of objects like a dynamic array.

The code example below requires a TPageControl that fits into a client area, with no new pages created at design time, TTabControl with no tabs created at design time, aligned with the bottom of the client area,
TOpenPictureDialog and TMainMenu with one item (File) and two subitems (Open and Close). Each TPageControl page is created at runtime when you open a file and acts as a parent control for TsgDrawingNavigator. TTabControl tabs are created dynamically for a current drawing when you open a new file or switch between opened files.

Code: Select all

uses
   ..., CADImage, DWG, DXF, sgDrawingNavigator, Contnrs;

type
  TsgDrawingNavigatorClass = class of TsgDrawingNavigator;

  TForm1 = class(TForm)
   ...
    OpenPictureDialog1: TOpenPictureDialog;
    pcDrawings: TPageControl;
    tcLayouts: TTabControl;
   ...
    MainMenu1: TMainMenu;
    miFile: TMenuItem;
    miOpen: TMenuItem;
    miClose: TMenuItem;
   ...
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure miOpenClick(Sender: TObject);
    procedure miCloseClick(Sender: TObject);
    procedure pcDrawingsChange(Sender: TObject);
    procedure tcLayoutsChange(Sender: TObject);
  private
    FDNavigator: TsgDrawingNavigator;
    FCADImageList: TObjectList;
    FCurrentDrawing: TsgCADImage;
    procedure CreateNavigator(var ANavigator: TsgDrawingNavigator; const ANavigatorClass: TsgDrawingNavigatorClass; const AParent: TWinControl);
    procedure CreateFileTab(AFileName: string);
    procedure ViewDrawingLayouts(AIndex: Integer);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;


implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  FCADImageList := TObjectList.Create(True);
  tcLayouts.Visible := False;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if FCADImageList.Count > 0 then
    FCADImageList.Free;
end;

procedure TForm1.miOpenClick(Sender: TObject);
var
  vFileExt: string;
  vCADImage: TsgCADImage;
begin
  if OpenPictureDialog1.Execute then
  begin
    vFileExt := AnsiLowerCase(ExtractFileExt(OpenPictureDialog1.FileName));
    if (vFileExt = '.dxf') then
      vCADImage := TsgCADdxfImage.Create;
    if (vFileExt = '.dwg') then
      vCADImage := TsgDWGImage.Create;
    vCADImage.LoadFromFile(OpenPictureDialog1.FileName);
    FCADImageList.Add(vCADImage);
    CreateFileTab(ExtractFileName(OpenPictureDialog1.FileName));
  end;
end;

procedure TForm1.miCloseClick(Sender: TObject);
begin
  // Delete a TsgCADImage instance drawn on the active page from the list
  FCADImageList.Delete(pcDrawings.ActivePageIndex);
  FDNavigator.Picture.Graphic := nil;
  // Close the active page
  pcDrawings.ActivePage.Free;
  // If there are no drawings opened, clear the layout tabs
  if FCADImageList.Count = 0 then
  begin
    tcLayouts.Tabs.Clear;
    tcLayouts.Visible := False
  end
  // otherwise, show layouts of the previous drawing
  else
    ViewDrawingLayouts(pcDrawings.ActivePageIndex);
end;

procedure TForm1.CreateFileTab(AFileName: string);
var
  T: TTabSheet;
begin
  T := TTabSheet.Create(pcDrawings);
  with T do
  begin
    Visible := True;
    Caption := AFileName;
    PageControl := pcDrawings;
  end;
  PageControl1.ActivePage := T;
  CreateNavigator(FDNavigator, TsgDrawingNavigator, pcDrawings.ActivePage);
  ViewDrawingLayouts(pcDrawings.ActivePageIndex);
end;

procedure TForm1.CreateNavigator(var ANavigator: TsgDrawingNavigator; const ANavigatorClass: TsgDrawingNavigatorClass; const AParent: TWinControl);
begin
  ANavigator := ANavigatorClass.Create(Self);
  ANavigator.Parent := AParent;
  ANavigator.Align := alClient;
  ANavigator.AutoFocus := True;
  ANavigator.SysMenuIconsVisible := False;
  ANavigator.RectZooming := False;
  ANavigator.DoubleBuffered := True;
  ANavigator.Color := clWhite;
  ANavigator.ClipRectangle := False;
end;

procedure TForm1.ViewDrawingLayouts(AIndex: Integer);
var
  I: Integer;
begin
  FCurrentDrawing := TsgCADImage(FCADImageList.Items[AIndex]);
  tcLayouts.Tabs.Clear;
  for I := 0 to TsgCADImage(FCADImageList.Items[AIndex]).LayoutsCount - 1 do
    tcLayouts.Tabs.Add(TsgCADImage(FCADImageList.Items[AIndex]).Layouts[I].Name);
  tcLayouts.Visible := True;
  tcLayouts.TabIndex := 0;
  FDNavigator.Picture.Assign(FCurrentDrawing);
end;

procedure TForm1.tcLayoutsChange(Sender: TObject);
begin
  if tcLayouts.TabIndex >= 0 then
    TsgCADImage(FDNavigator.Picture.Graphic).CurrentLayout := FCurrentDrawing.Layouts[tcLayouts.TabIndex];
end;

procedure TForm1.pcDrawingsChange(Sender: TObject);
begin
  ViewDrawingLayouts(pcDrawings.ActivePageIndex);
end;

end.
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply