Using a cad file for a floor plan
Moderators: SDS, support, admin
Using a cad file for a floor plan
I'm using Delphi 7 and ould like to illustrate the state of some sensors on a plant floor.
We would like to have 2 layers
1- floor plan,
2- a layer containing all the sensors as rectangles
I would like to be able to fill the rectangles with green if OK and Red if error.
I would also like to llow the user to click on a spreasheet and have the drawing zoom in on the selected sensor.
Thanks
We would like to have 2 layers
1- floor plan,
2- a layer containing all the sensors as rectangles
I would like to be able to fill the rectangles with green if OK and Red if error.
I would also like to llow the user to click on a spreasheet and have the drawing zoom in on the selected sensor.
Thanks
Hello,
The following code demonstrates how to get access to entities of the necessary layer ('WWW' in this example), how to make a simple action with them (for example to fill entity by red color) and how to zoom by mous click.
Sergey
please post questions to the forum or write to support@cadsofttools.com
The following code demonstrates how to get access to entities of the necessary layer ('WWW' in this example), how to make a simple action with them (for example to fill entity by red color) and how to zoom by mous click.
Code: Select all
<b>uses</b>
..., SGImage, DXFImage, DXFConv, sgConsts;
<b>type</b>
TForm1 = <b>class</b>(TForm)
...
sgImage1: TsgImage;
...
<b>private</b>
...
Img: TsgDXFImage;
FCADParams: TsgCADIterate;
<b>procedure</b> DoCADEntities(Entity: TsgDXFEntity);
...
<b>end</b>;
//open file
<b>procedure</b> TForm1.Open1Click(Sender: TObject);
<b>begin
if not</b> OpenDialog1.Execute <b>then</b> Exit;
sgImage1.LoadFromFile(OpenDialog1.FileName);
<b>if</b> sgImage1.Picture.Graphic <b>is</b> TsgDXFImage <b>then</b>
Img := TsgDXFImage(sgImage1.Picture.Graphic)
<b>else</b>
Img := <b>nil</b>;
<b>end</b>;
//iterate through the all entities of the file
<b>procedure</b> TForm1.FindSensors1Click(Sender: TObject);
<b>begin</b>
...
<b>if</b> Img = <b>nil then</b> Exit;
Img.Converter.Params := @FCADParams;
Img.CurrentLayout.Iterate(Img.Converter, DoCADEntities);
...
<b>end</b>;
//check whether rectangle belongs to the necessary layer ('WWW' for instance) and fill it by red color
<b>procedure</b> TForm1.DoCADEntities(Entity: TsgDXFEntity);
<b>var</b>
L: TsgDXFLayer;
vHighlightArea: array of TPoint;
I: Integer;
vPoint: TPoint;
<b>begin</b>
L := EntLayer(Entity, FCADParams.Insert);
<b>if</b> Entity <b>is</b> TsgDXFPolyLine <b>then
begin
if</b> L.Name = 'www' <b>then
begin</b>
SetLength(vHighlightArea, 0);
<b>for</b> I := 0 <b>to</b> TsgDXFPolyline(Entity).PolyPoints.Count - 1 <b>do
begin</b>
vPoint := Img.GetPoint(TFPoint(TsgDXFPolyline(Entity).PolyPoints.Items[I]^));
SetLength(vHighlightArea, Length(vHighlightArea) + 1);
vHighlightArea[Length(vHighlightArea) - 1] := vPoint;
<b>end</b>;
sgImage1.Canvas.Brush.Color := clRed;
sgImage1.Canvas.Polygon(vHighlightArea);
sgImage1.Canvas.Brush.Color := clWhite;
<b>end</b>;
<b>end</b>;
<b>end</b>;
//zoom on left mouse click
<b>procedure</b> TForm1.sgImage1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
<b>var</b>
vPoint: TPoint;
<b>begin</b>
sgImage1.Zoom := false;
vPoint.X := X;
vPoint.Y := Y;
<b>if</b> (Button = mbLeft) <b>and</b> (<b>not</b> sgImage1.Empty) <b>then</b>
sgImage1.ChangeScale(False, 2, vPoint);
<b>end</b>;
please post questions to the forum or write to support@cadsofttools.com