Re: Questions on Inkscape change events

On Wed, 5 Jan 2005 18:39:05 -0500, Brandi Soggs <soggsbh@...635...> wrote:
No, SPCanvas is way too low in the hierarchy for your purposes. I think what you need to watch is the SPRepr system. It's similar to DOM, i.e. it stores a representation of the source document, and is changed whenever everything is changed on canvas and elsewhere (and remember that "invisible" changes may affect visible objects, e.g. if you change a gradient definition in <defs> that will change all visible objects that use this gradient). Also reprs are what maintains the undo stack, so in principle you can hook into sp_document_maybe_done (a function which is called as soon as an undoable action is finished) and sync your repr copy with the master repr tree. Or you can look into the topmost undo stack record and see what exactly has changed. Or, if you are interested in one particular node, you can attach a listener to that node and you will be called whenever that node changes.
When sp_object_invoke_build is called (which happens both when the object is built from source on document load and when a new object is created), it runs sp_object_get_unique_id. That function checks if there is already an object with that id and if so, generates a new unique id and assigns to that object, otherwise leaves the old id alone and returns.
SPItem is a subclass of SPObject. SPItems represents all objects that are visible on canvas. All SPObjects, in turn, are generated from SPRepr nodes (though one repr may have more than one SPObject attached to it). All the functions you listed are standard methods of SPObjects and its subclasses, that are called at various stages of their lifetime, not necessarily associated with some user action.
For example, sp_item_write and other *_write functions update the repr of this object, i.e. if the object has changed they bring the repr to sync. This may happen in lots of different situations, and the different levels of hierarchy handle their corresponding aspects of repr updating.
For example any SPObject must have an id, and therefore sp_object_private_write writes the object's id into its repr:
sp_repr_set_attr (repr, "id", object->id);
Then, if this spobject is also an spitem, sp_item_write runs. It sets those attrs which are common to all visible items, i.e. transform and style.
Then, SPRect is a subclass of SPItem, and sp_rect_write updates those attributes which are specific to rects (x, y, rx, ry). It does not have to worry about the id or transform because that was already taken care of by its parents.
Similar hierarchies work for other standard methods (build, write_transform etc). However, you probably don't need all this. What matters for you is that SPRepr ends up with complete updates from all changed objects, and you can take what you need from there. It's the easiest for those new to the code, because the SPRepr tree is the closest thing we have to the actual SVG code, yet it is always up-to-date in memory (e.g. the XML editor is simply a visualization of the SPRepr tree).
P.S. I'm posting a copy to the inkscape-devel list, hope you don't mind. Please feel free to ask any other questions on that list, me and others will be glad to help.

On Wed, 5 Jan 2005 20:46:26 -0400, bulia byak <buliabyak@...400...> wrote:
On the other hand, if you want just to mirror the appearance of a document in some other window, but don't care about the structure of the document, then SPCanvas is just what you need. It's just a screen picture which, if you hook it up properly, will reflect the state of the document. Currently Inkscape does this when you do Edit>Duplicate Window: a new window with a new canvas is created, and when you edit the document in any of these windows, the image in the other window updates at once. At the same time, each window can have its own zoom and selection.
The hierarchy is like this:
SPDesktop: this roughly corresponds to the editing window; this class holds the selection, the current tool, the current zoom, the reference to the current document etc.
SPDesktopWidget: this is contained in SPDesktop and holds together all the widgets in the editing window, including its SPCanvas.
SPCanvas: this is a drawing canvas that displays SPCanvasItems.
SPCanvasItem: most SPCanvasItems are service things such as selection frame and arrows, shape controls, text cursor, etc. These SPCanvasItems are displayed without antialiasing.
SPCanvasArena: this is a special SPCanvasItem which is always one per SPCanvas. It contains the SVG drawing itself, i.e. all the shapes, etc. Each object is visualized as one of NRArenaItems within an SPCanvasArena.
NRArenaItems: these exist within an SPCanvasArena. They are always displayed with antialiasing. An SPObject (which, remember, roughly corresponds to an SVG tree node) has a list of SPArenaItems that display it. If you are editing the document in one window only, this list usually contains a single SPArenaItem that is within that window's arena (which is shown on that window's canvas). If you open the same document in another window, each SPObject will get a second NRArenaItem for that window. Like SPObjects, NRArenaItems are categorized into types, but there are much less types of NRArenaItems: only group, shape, glyphs, and image. For example, rectangles and spirals are different subclasses of SPObject, but they both generate NRArenaShapes (i.e. NRArenaItems that display shapes). The updating of NRArenaItems when their parent SPObject is updated is done by the *_update method of the corresponding SPObject class (e.g. sp_rect_update).
Hope this helps. I may have messed up something, so please correct me where I am wrong.
participants (1)
-
bulia byak