Layer drawing order

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

Moderators: SDS, support, admin

Post Reply
AndyStephenson
Posts: 8
Joined: 10 Oct 2006, 12:08
Location: United Kingdom

Layer drawing order

Post by AndyStephenson » 20 Oct 2006, 20:37

Hi,

How can I control the drawing order of the layers? i.e. how can I send a layer to the back of the drawing so that if it's a solid colour, I can still the the other entities on top of it.

...Andy

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

Post by support » 23 Oct 2006, 16:41

Hello Andy,

The following code demonstrates how to draw entities from the layer <font color="blue">BottomLayer</font id="blue"> in the first turn (under all the other entities).

Code: Select all

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

<b>type</b>
  TForm1 = <b>class</b>(TForm)
    ...
    sgImage1: TsgImage;
    btnOpen: TButton;
    bntLayousOrder: TButton;
    <b>procedure</b> btnOpenClick(Sender: TObject);
    <b>procedure</b> bntLayousOrderClick(Sender: TObject);
  <b>private</b>
    FImg: TsgDXFImage;
...

<b>procedure</b> TForm1.btnOpenClick(Sender: TObject);
<b>begin</b>
  sgImage1.LoadFromFile(<font color="blue">'c:\Layers.dxf'</font id="blue">);
  <b>if</b> sgImage1.Picture.Graphic <b>is</b> TsgDXFImage <b>then</b>
    FImg := TsgDXFImage(sgImage1.Picture.Graphic)
  <b>else
  begin</b>
    FImg := <b>nil</b>;
    Exit;
  <b>end</b>;
  sgImage1.Align := alClient;
<b>end</b>;

<b>procedure</b> TForm4.bntLayousOrderClick(Sender: TObject);
<b>var</b>
  I, BottomHandle : Integer;
  vEntity: TsgDXFEntity;
  SortTable: TsgDXFSortEntsTable;
  HandleList: TList;
<b>begin
  if</b> FImg = <b>nil then</b>
    Exit;

  HandleList := TList.Create;
  SortTable := TsgDXFSortEntsTable.Create;
  BottomHandle := MaxInt;

  <b>for</b> I := <font color="blue">0</font id="blue"> <b>to</b> FImg.Converter.Counts[csEntities] - <font color="blue">1</font id="blue"> <b>do
  begin</b>
    vEntity := FImg.Converter.Sections[csEntities].Entities[I];
    SortTable.HandlesOld.Add(Pointer(vEntity.Handle));
    <b>if</b> vEntity.Layer.Name = <font color="blue">'BottomLayer'</font id="blue"> <b>then</b>
      HandleList.Add(vEntity);
    <b>if</b> BottomHandle > vEntity.Handle <b>then</b>
      BottomHandle := vEntity.Handle;
  <b>end</b>;

  Inc(BottomHandle);
  <b>for</b> I := <font color="blue">0</font id="blue"> <b>to</b> FImg.Converter.Counts[csEntities] - <font color="blue">1</font id="blue"> <b>do
  begin</b>
    FImg.Converter.Sections[csEntities].Entities[I].Handle := BottomHandle + HandleList.Count + I;
    SortTable.HandlesNew.Add(Pointer(TsgDXFEntity(FImg.Converter.Sections[csEntities].Entities[I]).Handle));
  <b>end</b>;

  <b>for</b> I := <font color="blue">0</font id="blue"> <b>to</b> HandleList.Count - <font color="blue">1</font id="blue"> <b>do</b>
    TsgDXFEntity(HandleList[I]).Handle := BottomHandle + I;

  FImg.Converter.Sections[csTables].AddEntity(SortTable);
  FImg.Converter.Loads(SortTable);
  FImg.Converter.SortEntities;

<b>end</b>;
Sergey.

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

Post Reply