Get Parent Vertex from a JGraphX Tree - jgraphx

Suppose I have a graph like this:
Suppose I also have a reference to the (Object) cell 573. Is there a way I can get a reference to its parent in the graph, the (Object) cell 792? Can't seem to find an answer in the api. I'm still pretty new to JGraphX.

I found a way that seems to work pretty well: As I draw my graph from my Java data structure (in the form of a tree) I store in a hashmap key-value pairs for each element in the Java data structure and its corresponding object in the jgraph. That way I can easily get the corresponding jgraphx cell for any node in the tree of my data structure.

Related

EaselJS - Storing Shape Graphics in Database

I'm using EaselJS for a project, and have the need to store the details of various 'Shape' objects in a database, so that they can be re-drawn at another time.
My project has the 'Stage' set up so that I can drag-draw a box, which is saved into the database when completed. I intend to make it usable for drawing polygons also.
My database has a table in it called 'polyshapes', which stores the Shape.id, Shape.name, Shape.x, Shape.y, Shape.rotation. It also has a field called 'graphics' where I can store some sort of text string representing the Shape.graphics object.
When I draw a box, I'm able to store a string of the 'graphics' using: JSON.stringify(Myshape.graphics).
When I load this shape from the database, I create a new createjs.Shape() object, and then use Myshape.graphics = JSON.parse(graphicsString) to load the graphics.
Unfortunately this doesn't seem to work, as it doesn't load the required functions within the object.
I have also tried just individually updating some specific graphics attributes such as 'command', '_instructions', '_stroke', '_strokeStyle'. But I still can get the required graphic to re-draw.
Ideally, I'd only need to store the 'instructions' attribute of the Shape.graphics when I drag-draw it, and then when loading from the DB, I would just use a method to re-create those graphics when provided with the 'instructions' data. However I can't seem to see a suitable method for doing this.
I have also looked into the decodePath() graphics method. This would be useful, except that there doesn't appear to be an inverse method 'encodePath()' to allow me to serialize it in the first place.
How can I store the Shape.graphics data in a database, and then recall it later to rebuild a new Shape() object?
Thanks,
Hugh.

How to get order of intersection points that create and remove after moving an object in arrangement?

I want to get the sequence of events or intersection points that created and removed in the arrangement after moving a circular object form one position to another and I don't know how to do this using CGAL lib.
Use, what we refer to as, observers; see the example program examples/Arrangement_on_surface_2/observer.cpp and the doc. at https://doc.cgal.org/latest/Arrangement_on_surface_2/classCGAL_1_1Arr__observer.html
In particular, populate the following observer member functions
after_create_vertex (Vertex_handle v)
after_remove_vertex ()

Check whether the given object is a list?

How can we check whether the given object is a list or other type
in velocity. In that list i have another list which i need to iterate again.
I also have another data in the parent list which i want to print while iterating parent list. But the problem is the child list object also get printing with actual data. So i want to print the data by checking whether its list or not. Any help is much appreciated.
Before you get any remarks on using too much logic in templates, try this reflection based approach :
velocity (test instanceof)

Parsing same element name in iphone

I am not getting that how to differentiate same element name for eg City,Area in two different trees. So help me for this in parsing the same element name in iphone.
<Contacts id="1">
<Fname>Siddharth</Lname>
<Lname>Chopra</Lname>
<Currentaddress>
<Area>Aundh</Area>
<City>Pune</City>
<Phone>8796xxxx</Phone>
</Currentaddress>
<Permanentaddress>
<Area>Bhatar</Area>
<City>Surat</City>
<Phone>989825xxxx</Phone>
</Permanentaddress>
</Contacts>
In your class create an mutable array, that you'll use as a stack.
if a new element starts, create a object representing it (a custom (managed) object, or a dictionary) and add it to the array. In didFoundCharacter: alter the object, that is last on the array. If didEndElement: is called, save it either to core data, a file, sql or in memory to another array. and remove it from the array.
If the elements <Area>,<City> or <Phone>are handled, you'll know, that the object on the second last position is the address, they belong to. either <Currentaddress> or <Permanetaddress>.
You have to set a flag in didstartElement, the value of the flag will let you know, which parent tree is under parsing process.

How to use GtkTreeView correctly

I am using a TreeView with a ListStore as model. When the user clicks on a row I want to take some action but not using the values in the cells, but using the data I created the row from...
Currently I have the TreeView, the TreeModel (ListStore) and my own data (which I ironically call model)..
So the Questions are:
Is it "right" to have a model - an object representation of the data I want to display and fill a ListStore with that data to display in a TreeView, or would it be better to implement an own version of TreeModel (wrapping my data-model) to display the data?
And also:
If someone double-clicks in a row I can get the RowActivated event (using C#/Gtk#) which provides a Path to the activated row. With that I can get a TreeIter and using that I can get the value of a cell. But what is the best practice to find the data object from which the row was constructed in the first place?\
(Somehow this question got me to the first one - by thinking would getting the data object more easy if I tried to implement my own TreeModel...)
It's quite awkward/difficult to implement TreeModel, so most people simply synch the data from their "real" model into a TreeStore or ListStore.
The columns in the store do not have to match the columns in the view in any way. For example, you can have a column that contains your real managed data objects.
When you add a cellrenderer to a TreeView (visual) column, you can add mappings between its properties and the columns of the store. For example, you could map one store column to the font of a text cellrenderer, and another store column to the text property of the same cellrenderer. Each time the cellrenderer is used to render a particular cell, the mappings will be used to retrieve the values from the store and apply them to the properties of the renderer before it renders.
Here's an example of a mapping:
treeView.AppendColumn ("Title", renderer, "text", 0, "editable", 4);
This maps store column 0 to the renderer's text GTK property and maps store column 4 to the editable property. For GTK property names you can check the GTK docs. Note that the example above uses a convenience method that adds a column, adds a renderer to it and add an arbitrary number of mapping via params. To add mappings directly to a column, for example a column with multiple renderers, pack the renderers into the column then use TreeViewColumn.AddAttribute or TreeViewColumn.SetAttributes.
You can also set up a custom data function that will be used instead of mappings. This allows you to set the properties of the renderer directly, given a TreeIter and the store - so, if all the data you want to display is trivially derived from your real data objects, you could even have your store only contain a single column of these objects, and use data funcs for all the view columns.
Here's an example of a data func that does exactly what the mapping example above does:
treeColumn.SetCellDataFunc (renderer, delegate (TreeViewColumn col,
CellRenderer cell, TreeModel model, TreeIter iter)
{
var textCell = (CellRendererText) cell;
textCell.Text = (string) model.GetValue (iter, 0);
textCell.Editable = (bool) model.GetValue (iter, 4);
});
Obviously data functions are much more powerful because they enable you not only to use properties of more complex GTK objects, but also to implement more complex display logic - for example, lazily processing derived values only when the cell is actually rendered.