1 {
2 *****************************************************************************
3 *                                                                           *
4 *  This file is part of the ZCAD                                            *
5 *                                                                           *
6 *  See the file COPYING.modifiedLGPL.txt, included in this distribution,    *
7 *  for details about the copyright.                                         *
8 *                                                                           *
9 *  This program is distributed in the hope that it will be useful,          *
10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
12 *                                                                           *
13 *****************************************************************************
14 }
15 {
16 @author(Andrey Zubarev <zamtmn@yandex.ru>)
17 }
18 {$MODE OBJFPC}
19 unit uzccomimport;
20 {$INCLUDE def.inc}
21 interface
22 uses uzcinterface,uzgldrawcontext,uzeentityfactory,
23      {$IFNDEF DELPHI}dxfvectorialreader,svgvectorialreader,epsvectorialreader,fpvectorial,fileutil,{$ENDIF}
24      uzedrawingsimple,
25      uzeentcircle,uzeentarc,uzeentline,
26      uzegeometry,uzcshared,uzbtypesbase,uzclog,uzbtypes,
27      sysutils,uzbmemman,uzeconsts,
28      UGDBOpenArrayOfByte,uzeentity;
29 {$IFNDEF DELPHI}
30 procedure Import(name: GDBString;var drawing:TSimpleDrawing);
31 {$ENDIF}
32 implementation
33 {$IFNDEF DELPHI}
34 procedure Import(name: GDBString;var drawing:TSimpleDrawing);
35 var
36   Vec: TvVectorialDocument;
37   source:{TvVectorialPage}TvPage;
38   CurEntity: TvEntity;
39   i:integer;
40   pobj:PGDBObjEntity;
41   j{, k}: Integer;
42   CurSegment: TPathSegment;
43   Cur2DSegment: T2DSegment absolute CurSegment;
44   PosX, PosY: Double;
45   DC:TDrawContext;
46 begin
47     Vec := TvVectorialDocument.Create;
48      DC:=drawing.CreateDrawingRC;
49   try
50     Vec.ReadFromFile(name);
51     source:=Vec.GetPage(0);
52     for i := 0 to source.GetEntitiesCount - 1 do
53     begin
54       CurEntity := source.GetEntity(i);
55       if CurEntity is TvCircle then
56       begin
57            pobj := CreateInitObjFree(GDBCircleID,nil);
58            pgdbobjCircle(pobj)^.Radius:=TvCircle(CurEntity).Radius;
59            pgdbobjCircle(pobj)^.Local.P_insert.x:=TvCircle(CurEntity).x;
60            pgdbobjCircle(pobj)^.Local.P_insert.y:=TvCircle(CurEntity).y;
61            drawing{gdb}.GetCurrentRoot^.AddMi(@pobj);
62            PGDBObjEntity(pobj)^.BuildGeometry(drawing);
63            PGDBObjEntity(pobj)^.formatEntity(drawing,dc);
64       end
65  else if CurEntity is TvCircularArc then
66       begin
67            pobj := CreateInitObjFree(GDBArcID,nil);
68            pgdbobjArc(pobj)^.R:=TvCircularArc(CurEntity).Radius;
69            pgdbobjArc(pobj)^.Local.P_insert.x:=TvCircularArc(CurEntity).x;
70            pgdbobjArc(pobj)^.Local.P_insert.y:=TvCircularArc(CurEntity).y;
71            pgdbobjArc(pobj)^.StartAngle:=TvCircularArc(CurEntity).StartAngle*pi/180;
72            pgdbobjArc(pobj)^.EndAngle:=TvCircularArc(CurEntity).EndAngle*pi/180;
73            drawing{gdb}.GetCurrentRoot^.AddMi(@pobj);
74            PGDBObjEntity(pobj)^.BuildGeometry(drawing);
75            PGDBObjEntity(pobj)^.formatEntity(drawing,dc);
76       end
77   else if CurEntity is fpvectorial.TPath then
78       begin
79       fpvectorial.TPath(CurEntity).PrepareForSequentialReading;
80       for j := 0 to fpvectorial.TPath(CurEntity).Len - 1 do
81       begin
82         CurSegment := TPathSegment(fpvectorial.TPath(CurEntity).Next());
83 
84         case CurSegment.SegmentType of
85         stMoveTo:
86         begin
87           PosX := Cur2DSegment.X;
88           PosY := Cur2DSegment.Y;
89         end;
90         st2DLineWithPen,st2DLine, st3DLine:
91         begin
92            pobj := CreateInitObjFree(GDBLineID,nil);
93            PGDBObjLine(pobj)^.CoordInOCS.lBegin:=createvertex(PosX,PosY,0);
94            PosX := Cur2DSegment.X;
95            PosY := Cur2DSegment.Y;
96            PGDBObjLine(pobj)^.CoordInOCS.lEnd:=createvertex(PosX,PosY,0);
97            drawing{gdb}.GetCurrentRoot^.AddMi(@pobj);
98            PGDBObjEntity(pobj)^.BuildGeometry(drawing);
99            PGDBObjEntity(pobj)^.formatEntity(drawing,dc);
100         end;
101         end;
102       end;
103 
104       end;
105     end;
106   except
107         on Exception do
108         begin
109              ZCMsgCallBackInterface.TextMessage('Unsupported vector graphics format?',TMWOShowError);
110         end
111   end;
112   //finally
113     Vec.Free;
114   //end;
115 end;
116 {$ENDIF}
117 begin
118 end.
119