Page 1 of 1
Turning layers on and off
Posted: 20 Oct 2006, 20:14
by AndyStephenson
Hi,
I am using the following code snippets to turn layers on and off:
sgImagePlan.LoadFromFile(DBTextPlanFilename.Caption);
sgImagePlan.Align := alNone;
sgImagePlan.Align := alClient;
Fimg := TsgDXFImage(sgImagePlan.Picture.Graphic);
Fimg.Converter.LayerByName(LayerName).Visible := true; //on
or
Fimg.Converter.LayerByName(LayerName).Visible := false; //on
sgImagePlan.Refresh;
It all works fine. But, the refresh call updates all of the drawing, so it's quite a visible flicker. Is there a better way to do this so that a minimalist repaint occurs?
...Andy
Posted: 23 Oct 2006, 11:10
by support
Hello Andy,
Set the following property to true:
Code: Select all
TsgImage.Parent.DoubleBuffered := true;
Sergey.
please post questions to the forum or write to
support@cadsofttools.com
Posted: 23 Oct 2006, 13:02
by AndyStephenson
Sergey,
I gave that a try, but I still get the whole of the image repainted.
What I would like is that only the active area of the layer that I have turned on or off is drawn, not the whole image.
Is this possible?
...Andy
Posted: 24 Oct 2006, 16:54
by support
Hello Andy,
The following example demonstrates how to redarw only necessary part of the drawing:
Code: Select all
<b>uses</b>
... sgConsts, SGImage, DXFImage, DXFConv;
<b>type</b>
TForm1 = <b>class</b>(TForm)
..
<b>procedure</b> btnSwitchLayerOnOffClick(Sender: TObject);
<b>private</b>
<i><font color="blue">{ Private declarations }</font id="blue"></i>
FImg: TsgDXFImage;
<b>procedure</b> TForm1.btnSwitchLayerOnOffClick(Sender: TObject);
<b>var</b>
I: Integer;
vRect: TRect;
<b>begin
if</b> FImg = <b>nil then</b>
Exit;
<b>for</b> I := <font color="blue">0</font id="blue"> <b>to</b> FImg.Converter.Counts[csLayers] - <font color="blue">1</font id="blue"> <b>do
begin
if</b> TsgDXFLayer(FImg.Converter.Sections[csLayers].Entities[I]).Name = '<font color="blue">LayerToFreeze</font id="blue">' <b>then</b>
TsgDXFLayer(FImg.Converter.Sections[csLayers].Entities[I]).Frozen := <b>not</b> TsgDXFLayer(FImg.Converter.Sections[csLayers].Entities[I]).Frozen;
<b>end</b>;
vRect.TopLeft := FImg.GetPoint(MakeFPoint(<font color="blue">..</font id="blue">, <font color="blue">..</font id="blue">, <font color="blue">..</font id="blue">));
vRect.BottomRight := FImg.GetPoint(MakeFPoint(<font color="blue">..</font id="blue">, <font color="blue">..</font id="blue">, <font color="blue">..</font id="blue">));
vRect.Left := vRect.Left + sgImage1.Left;
vRect.Right := vRect.Right + sgImage1.Left + <font color="blue">1</font id="blue">;
vRect.Top := vRect.Top + sgImage1.Top + <font color="blue">1</font id="blue">;
vRect.Bottom := vRect.Bottom + sgImage1.Top;
InvalidateRect(sgImage1.Parent.Handle, @vRect,false);
UpdateWindow(sgImage1.Parent.Handle)
<b>end</b>;
Two conditions:
<ul><li>You have to know what layer has to be frosen</li>
<li>You have to know the drawing coordinates of the area to be redrawn. Use this coordinates when calling function <b>TsgDXFImage.GetPoint</b></li></ul>
Sergey.
please post questions to the forum or write to
support@cadsofttools.com