Questions

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

Moderators: SDS, support, admin

Post Reply
QbProg
Posts: 6
Joined: 11 Jul 2008, 10:38

Questions

Post by QbProg » 11 Jul 2008, 10:46

Hello there,
I have written to the "support" email some time ago, and got no answer. I'm trying here :)

I'm having troubles importing SVG files and accessing it's data. I don't know how to extract from sgPath , sgCurvePolygon , sgGradientPolygon, etcc... all the elementar entities of the objects. I'd like to get lines, arcs, splines,etc... from these compound entities.
Do you have any examples of using SVG sgPath entities and curve Polygons? Also TsgSVGPath is undocumented. Do you have any reference for it?

Do you also have any HPGL , CGM, SVG example files to make some test of our implementation ?

We are successfully using the library for DXF and DWG files, it is really fast and easy to use. Now we are extending to more file formats and options (SVG, 3d, etc...).

Thank you,
Thomas

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

Re: Questions

Post by support » 11 Jul 2008, 16:43

Hello Thomas,
I'm having troubles importing SVG files and accessing it's data. I don't know how to extract from sgPath , sgCurvePolygon , sgGradientPolygon, etcc... all the elementar entities of the objects. I'd like to get lines, arcs, splines,etc... from these compound entities.
Please try the following construction:

Code: Select all

var
  vImg := TsgSVGImage.Create;
...
begin
  vImg := TsgSVGImage.Create;
  vImg.Converter.Sections[csEntities].Entities[i];
...
SVG file format has some traits and they cause that SVG data appears in CAD Import VCL as TsgSVGInsert or TsgDXFInsert very often. Tsg...Insert contains TsgDXFBlock which stores all the other entities. But sometimes TsgDXFBlock stores only TsgSVGInsert or TsgDXFInsert, which in their turn contain TsgDXFBlock etc. Thus sometimes it is necessary to go through the low level hierarchy of TsgSVGInsert -> TsgDXFBlock -> TsgSVGInsert... until list of entities is available.

Entity -> Class
-----------------
sgPath -> TsgSVGPath
sgCurvePolygon -> TsgCADCurvePolygon
sgGradientPolygon -> TsgCADGradientPolygon
Do you have any examples of using SVG sgPath entities and curve Polygons?

The code downwards is based on the demo available at: http://www.cadsofttools.com/download/Template.zip

Code: Select all

procedure TForm1.PathExampleClick(Sender: TObject);
var
  vImg: TsgDXFImage;
  vPath: TsgSVGPath;
begin
  if not(sgPaintBox.Picture.Graphic is TsgDXFImage) then Exit;
  vImg := TsgDXFImage(sgPaintBox.Picture.Graphic);
  vPath := TsgSVGPath.Create;
  vImg.CurrentLayout.AddEntity(vPath);
  vPath.Parametrs := 'M100,200 C100,100 400,100 400,200';
  vPath.Color := clRed;
  vImg.Converter.Loads(vPath);
  vImg.ResetDrawingBox;
  vImg.Converter.Loads(vImg.CurrentLayout);
  vImg.RefreshCurrentLayout;
  sgPaintBox.FitToSize;
end;

Code: Select all

Also TsgSVGPath is undocumented. Do you have any reference for it? 
It is not documented because we plan to rebuild TsgSVGPath and this may cause some critical changes.
Do you also have any HPGL , CGM, SVG example files to make some test of our implementation ?
Can you please specify what exactly examples you would like to have?

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

QbProg
Posts: 6
Joined: 11 Jul 2008, 10:38

Re: Questions

Post by QbProg » 14 Jul 2008, 11:06

SVG file format has some traits and they cause that SVG data appears in CAD Import VCL as TsgSVGInsert or TsgDXFInsert very often. Tsg...Insert contains TsgDXFBlock which stores all the other entities. But sometimes TsgDXFBlock stores only TsgSVGInsert or TsgDXFInsert, which in their turn contain TsgDXFBlock etc. Thus sometimes it is necessary to go through the low level hierarchy of TsgSVGInsert -> TsgDXFBlock -> TsgSVGInsert... until list of entities is available.
Yes, I did so, but I missed the "Entities" array. Now I'm doing
function AddEntity ( Ent : TsgDXFEntity )

....
// If Ent is TsgSVGPath
with TsgSVGPath(Ent) do begin
for i:= 0 to Ent.Count -1 do
AddEntity(Ent.Entities);
end;

and I recursively split inserts and blocks.

Do you also have any HPGL , CGM, SVG example files to make some test of our implementation ?
Can you please specify what exactly examples you would like to have?


If you have any, I would like to have some HPGL and CGM files in particular with common entities (lines,polylines,etc...) since I was not able to find anything on the web. Any reference would also be a great help. I would like to make some tests of our import commands..

Thank you for the answer,
Thomas

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

Re: Questions

Post by support » 14 Jul 2008, 13:55

SVG file format has some traits and they cause that SVG data appears in CAD Import VCL as TsgSVGInsert or TsgDXFInsert very often. Tsg...Insert contains TsgDXFBlock which stores all the other entities. But sometimes TsgDXFBlock stores only TsgSVGInsert or TsgDXFInsert, which in their turn contain TsgDXFBlock etc. Thus sometimes it is necessary to go through the low level hierarchy of TsgSVGInsert -> TsgDXFBlock -> TsgSVGInsert... until list of entities is available.
Yes, I did so, but I missed the "Entities" array. Now I'm doing
function AddEntity ( Ent : TsgDXFEntity )

....

Code: Select all

// If Ent is TsgSVGPath
with TsgSVGPath(Ent) do begin
for i:= 0 to Ent.Count -1 do
AddEntity(Ent.Entities[i]);
end;
and I recursively split inserts and blocks.
First of all we do not recommend to use structure with TsgSVGPath(Ent) do begin. Sometime it may give an arror.
Secondly, creating TsgSVGPath element must be implemented for several steps:
  • creating TsgSVGPath object;
  • adding single "path" to a TsgSVGPath object:

    Code: Select all

    TsgSVGPath.Parametrs := 'M100,200 C100,100 400,100 400,200';
  • calling TsgSVGPath object to the converter.
Is is very important to split the whole SVGPath string to pieces.
The whole string is:

d='"M3253 6745c-12 3-24 1-28-5-3-5-3-14 0-20 3-5 13-10 21-10 8 0 31-9 52-19 20-11 51-34 67-51l30-33-55 6c-30 3-70 9-89 13l-33 7 8-34c5-19 8-51 7-72 0-21-7-44-13-53-9-10-11-38-7-94 4-44 13-93 21-109 9-16 23-31 31-35 9-3 23-6 30-6 8 0 30 13 48 30 19 16 51 62 72 101 21 40 33 75 28 80-4 4-13 5-19 1-6-4-25-36-43-71-18-35-42-72-54-82-12-10-30-18-39-19-9 0-20 4-23 10-3 5-9 33-12 61l-6 51 25-16c19-13 31-14 51-7 15 6 35 27 46 49 11 22 22 52 25 67 3 15 12 38 21 51 15 24 15 24-22 25-21 0-47 4-58 9-15 6-5 9 34 9 43 1 60-4 78-21 18-17 26-19 36-9 9 9-4 27-63 86-41 41-91 81-110 89-19 8-45 18-57 21z m32-295c9-7 25-10 40-6 24 6 25 5 15-14-6-12-18-24-27-27-9-4-21 1-29 12-8 10-14 25-14 33 0 12 3 12 15 2z"'

It must be split on two pieces for two different TsgSVGPath objects:

d="M3253 6745c-12 3-24 1-28-5-3-5-3-14 0-20 3-5 13-10 21-10 8 0 31-9 52-19 20-11 51-34 67-51l30-33-55 6c-30 3-70 9-89 13l-33 7 8-34c5-19 8-51 7-72 0-21-7-44-13-53-9-10-11-38-7-94 4-44 13-93 21-109 9-16 23-31 31-35 9-3 23-6 30-6 8 0 30 13 48 30 19 16 51 62 72 101 21 40 33 75 28 80-4 4-13 5-19 1-6-4-25-36-43-71-18-35-42-72-54-82-12-10-30-18-39-19-9 0-20 4-23 10-3 5-9 33-12 61l-6 51 25-16c19-13 31-14 51-7 15 6 35 27 46 49 11 22 22 52 25 67 3 15 12 38 21 51 15 24 15 24-22 25-21 0-47 4-58 9-15 6-5 9 34 9 43 1 60-4 78-21 18-17 26-19 36-9 9 9-4 27-63 86-41 41-91 81-110 89-19 8-45 18-57 21z"

and

d="'m32-295c9-7 25-10 40-6 24 6 25 5 15-14-6-12-18-24-27-27-9-4-21 1-29 12-8 10-14 25-14 33 0 12 3 12 15 2z"

After adding TsgSVGPath object to Converter it contains single polyline with a list of PFPoints in the PolyPoints property.
Do you also have any HPGL , CGM, SVG example files to make some test of our implementation ?
Can you please specify what exactly examples you would like to have?
If you have any, I would like to have some HPGL and CGM files in particular with common entities (lines,polylines,etc...) since I was not able to find anything on the web. Any reference would also be a great help. I would like to make some tests of our import commands..
Most of our files where received form our customers. That is why we can't share them. But we have some open links where CGM files could be found:
http://www.cgmopen.org/
http://docs.oasis-open.org/webcgm/test- ... index.html

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

QbProg
Posts: 6
Joined: 11 Jul 2008, 10:38

Re: Questions

Post by QbProg » 15 Jul 2008, 10:46

Hello,
thank you for your support, I think I made some mistakes telling what I'm trying to do
I'm not trying to write or create SVG paths. What I'd like to do is
- Open an SVG file. I do that with TsgSVGImage
- Read the entities inside the SVG files. I do that with the collection entities.
- While reading, expand any sgPath in relatively simple entities, if possilbe.

This is exactly what I do when I read DWG , DXF files.
I have a function that does the following (similar):

Code: Select all

---
var DOM: TsgSVGImage;
..... Load DOM ....
for I := 0 to DOM.Counts[csEntities] - 1 do begin
        Ent := Dom.Entities[i];
        ReadEntity(Ent);
    end;

procedure ReadEntity(Ent: TsgDXFEntity);
begin
  case Ent.EntType of
    ceLine:
      ...
    ceArc:
      ....
    ceInsert: // explode....
    cePath:
      // I try to get the sub entities. Is this correct?
      with TsgSVGPath(Ent) do begin
        for I := 0 to Count - 1 do
          Self.AddEntity(Entities[i]);
        end;
  end;
end;
Of course I handle blocks and inserts too, exploding them and calling the same function.

In fact I just want to extract line,arcs,and splines from SVG files to use them in our software. I'd like not to use, if possible, the parameters of the svgpath since I don't know how to handle it!

Thank you for the CGM references,

Thomas

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

Re: Questions

Post by support » 16 Jul 2008, 11:29

Hello Thomas,

Please try the following code:

Code: Select all

procedure TForm1.btnGetEntitiesClick(Sender: TObject);
var
  vImg: TsgSVGImage;

  procedure GetEntities(const ABlock: TsgDXFBlock);
  var
     I: Integer;
     vEnt: TsgDXFEntity;
  begin
    if ABlock = nil then Exit;
    for I := 0 to ABlock.Count - 1 do
    begin
      vEnt := ABlock.Entities[I];
      case vEnt.EntType of
        ceInsert: GetEntities(TsgDXFInsert(vEnt).Block);
        ceArc, ceLine, ceSpline, cePath:
         ListBox1.AddItem(vEnt.EntName, nil);
        else
          ListBox1.AddItem('Some other entity', nil);
      end;
    end;
  end;

begin
  if not(sgPaintBox.Picture.Graphic is TsgSVGImage) then Exit;
  vImg := TsgSVGImage(sgPaintBox.Picture.Graphic);

  GetEntities(vImg.CurrentLayout.PaperSpaceBlock);
end;
Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply