Re: Questions on Inkscape change events
![](https://secure.gravatar.com/avatar/bb65b6b3a109d97cf9f8d6c014ede042.jpg?s=120&d=mm&r=g)
On Wed, 5 Jan 2005 18:39:05 -0500, Brandi Soggs <soggsbh@...635...> wrote:
- Every time that a user changes an object, we will need to make the same
change on the same object in for the other users. For our purposes, document changes are visible changes- changes to the objects drawn or the creation of new objects. We've seen in the documentation that there is no central place that gathers changes. Ishmal suggested to us that we use the sp-canvas as an area that always gets "hit" by document changes. When a change reaches the sp-canvas, does it actually know all the details (what happened to which sp-item) or does it just know "A change has occurred! Redraw!" ?
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.
- We're curious how and where (both the techinque and the place in the
code) object ids are generated. We've had some trouble tracing it ourselves. We're going to need to control object id generations well enough to prevent two users from attempting to make two objects with the same id.
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.
- We're not certain how all of the arguments to the functions
(sp_item_build, sp_item_set, sp_item_write, sp_item_commit, sp_item_transform, and equivalent functions in sub-classes of sp-item). Presumably these arguments are the actual details of a change that has occurred.
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.
![](https://secure.gravatar.com/avatar/bb65b6b3a109d97cf9f8d6c014ede042.jpg?s=120&d=mm&r=g)
On Wed, 5 Jan 2005 20:46:26 -0400, bulia byak <buliabyak@...400...> wrote:
On Wed, 5 Jan 2005 18:39:05 -0500, Brandi Soggs <soggsbh@...635...> wrote:
- Every time that a user changes an object, we will need to make the same
change on the same object in for the other users. For our purposes, document changes are visible changes- changes to the objects drawn or the creation of new objects. We've seen in the documentation that there is no central place that gathers changes. Ishmal suggested to us that we use the sp-canvas as an area that always gets "hit" by document changes. When a change reaches the sp-canvas, does it actually know all the details (what happened to which sp-item) or does it just know "A change has occurred! Redraw!" ?
No, SPCanvas is way too low in the hierarchy for your purposes.
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