Use of svg and dom

Hello,
I’m using for the first time the fact I have a picture in a 4D field [DraWapp]Image initially imported from a svg file.
All is ok.

Then later, I open the record with the image field and I want to deal with the dom and refresh the picture on screen.

To get the dom : $ptr_dom_picture->:=SVG_Open_picture([DraWapp]Image)

Then I do things, like : SVG_SET_VISIBILITY ($ptr_LB_ref->{$line};$isVis) // $ptr_LB_ref-> is a array on svg ref items

Then here is the question !

I supposed that as the dom is catch from image itself, the redraw is automatic. Not for me.
What is wrong ?

Then, I tried to redraw by : SVG EXPORT TO PICTURE($ptr_dom_picture->;[DraWapp]Image;Copy XML data source)
Error 59 variable or parameter missing ?!?

To get it work - I mean refresh but I’m note sure it is well done (memory leaks…) I have to do :
C_PICTURE($picture)
SVG EXPORT TO PICTURE($ptr_dom_picture->;$picture;Copy XML data source)
[DraWapp]Image:=$picture

Where am I wrong ???

Thanks !

For a Field, I’ve been using:
$svg:=SVG_New
$ref:=SVG_New_rect ($svg;10;10;100;19)
[Table_1]picF:=SVG_Export_to_picture ($svg)
SVG_CLEAR ($svg)

SVG EXPORT TO PICTURE ($svg;[Table_1]picF) causes the error, a Field is not expected.

You can use SVG SET ATTRIBUTE(;“FormPicName”;…) to change only the displayed image. The change is immediate.
If you add the second * in SVG SET ATTRIBUTE(
;“FormPicName”;…;*) the DOM of the displayed image will also get the change.

Thanks,
yes it seems the second “*” works for variable only, not for field…

SVG SET ATTRIBUTE in my exemple is to set visibility on a specific id in the dom tree.
This is not for the main picture.

And still, I don’t know how to get an automatic redraw of the pict changing an attribute in the dom taken from my svg field itself…

Using “SVG EXPORT TO PICTURE” with a Field (with or without the second *) always causes an error for me.

Try this: [DraWapp]Image:=SVG_Export_to_picture ($ptr_dom_picture->) to redraw the image on the form.

Oh !
you mean no need to say “Copy XML data source” !

Yes I try this…

It works.

I’m not sure there is no side effect, but my field keeps the dom also, even with no indication.

Thanks, I continue to develop then !!!

SVG SET ATTRIBUTE is primarily for picture objects that are displayed and rendered on a form.
it won’t work on “off-screen” pictures, or during the On Load form event.

the * option modifies the internal DOM tree which serves as the “backend” of the SVG rendering tree (the 2 trees are different) which you can verify by calling PICTURE TO BLOB to convert the picture back to XML.

normally, when you call SVG EXPORT TO PICTURE (default=copy) you give away a copy of the DOM to the picture, so manipulating the DOM has no impact on the picture.

if you use the “own” option, you give away the DOM itself so you totally forfeit ownership of the DOM.

if you use the “get” option, you share the DOM with the picture. the picture will have a size of 0 (because it does not have its own DOM tree) and whatever changes you make to the DOM using DOM commands will be reflected on the picture. just remember to close the DOM when you are done with the picture.

Hi Keisuke :slight_smile:

Yes, primarily my question is with a picture object IN A FIELD “[DraWapp]Image” and displayed on a form.

I collect the dom tree with “SVG_Open_picture ([DraWapp]Image)”
I then parse and get all with ref by “SVG_ELEMENTS_TO_ARRAYS”
I present all in a listbox, with the possibility to set visibility to on and off using SVG SET ATTRIBUTE for some parts of the pict.

At that point, because I modify the dom got with « SVG_Open_picture », I was expected to get an automatic redraw, which is not the case.
First : why ? Why modifiying the dom attached to the picture has no immediate effect on display ?

Second: why I need to do
C_PICTURE($picture)
SVG EXPORT TO PICTURE($ptr_dom_picture->;$picture;Copy XML data source)
[DraWapp]Image:=$picture

or
[DraWapp]Image:=SVG_Export_to_picture ($ptr_dom_picture->)

??

Third: if I use « get » option, you say the picture wont have its own dom as it is shared…
But then, if I trash the dom and save my record, what append to the svg dom initialy in the picture ? Gone too ?

4D must provide something more clear about svg !!!
How did you learn ? By durty hands only ?

you might find the following examples useful:

“no-dom”
“embedded-dom”
“detached-dom”
“double-dom”

https://github.com/miyako/4d-tips-svg-cookbook

Thanks, but I knew that link, and my initial question is still accurate :frowning: