There are several ways to initialize a SecGraph depending on the data that should be included:
(Since a SecGraph can be either a variable or a reference both are explained below)
From an existing Subgraph:
SecGraph sgr = new SecGraphRef("secGraph1",first((*RGGRoot*))); SecGraph sgi = new SecGraphImpl(workbench(),first((*RGGRoot*)));
This creates a SecGraph that contains a clone of the subgraph below the RGGRoot. This would work with any node.
From an existing SecGraph or GraphObject
SecGraph sgr = new SecGraphRef("secGraph1",sgi); SecGraph sgi = new SecGraphImpl(workbench(),gufi);
This creates a SecGraph that contains a clone of a given GraphObject or SecGraph. This allows users to duplicate graphs or to save a SecGraphImpl in a SecGraphRef.
Empty/with previous content
Using the constructors without an additional argument creates the object without adding anything. If a reference was used (SecGraphRef) this loads the old source, if a variable is created an empty graph is provided.
SecGraph sgr = new SecGraphRef("secGraph1"); SecGraph sgi = new SecGraphImpl(workbench());
To create an initial graph structure (and overwrite any existing old one) the following syntax can be used: (similar to the one of instantiations):
sgi ==> F [RL(30) F] F;
while execution RGG and XL function GroIMP is always
considering one graph as the current graph. without this
plugin that graph is always the ProjectGraph (the one that
holds the simulation). Yet with this plugin it is possible to
change the current graph during the execution of a rgg
function. This is done by the setCurrent() and
releaseCurrent() function as shown below. In the following
example the first and the third
println((*F))
would list all F from the
project graph while the second one list the F from the
SecGraph “secGraph1”. Moreover after running this
the angle of RL in secGraph1 would increase by 10.
public void example(){ SecGraphRef sgr1 = new SecGraphRef("secGraph1"); // get the reference to the secondary graph println((*F*)); // get all F's on the project graph (the current RGGGraph) sgr1.setCurrent(); // set secGraph1 to be the current RGGGraph println((*F*)); // get all F's on secGraph1 (the current RGGGraph) [ RL(x) ==> RL(x+10); // apply a rule on the current RGGGraph: secGraph1 ] sgr1.releaseCurrent(); // return to the previous RGGGraph: the ProjectGraph println((*F*));// get all F's on the project graph (the current RGGGraph) }
This feature can be nested on several secondary graphs:
SecGraphRef sg1 = new SecGraphRef("sg1"); SecGraphRef sg2 = new SecGraphRef("sg2"); sg1.setCurrent(); //execute on sg1 sg2.setCurrent(); //execute on sg2 sg2.releaseCurrent(); //execute on sg1 sg1.releaseCurrent();
Even so the current graph is changing, the java environment is not effected by this therefore it is possible use the same variables though the howl code. Only with the limitation that a Node can always only be added to one graph.
Two examples about that can be found: one about querying existing graph structure: examples:Graph Explorer/SecGraphQueryExample and on created secondaray graphs: examples:Graph Explorer/SecGraphCreationExample .
The Other way of executing on a certain secondary graph is with the apply(“functionName”) and the applyXL(“query”) function. The main limitation of this approach is that the applyXL function can only be used to read the graph not to manipulate it.
public void applyRGGfunction(){ SecGraphRef sgr = new SecGraphRef("one"); //apply command on the graph similar to the XL console sgr.applyXL("((*Node*))"); // execute RGG functions on the SecGraph sgr.apply("rggFunction"); sgr.applyXL("((*Node*))"); } /** * example function for execution */ public void rggFunction()[ M ==> M RL(90) M; ]
This can be seen in the example: examples:Graph Explorer/SecGraphCreationExample
If a secondary graph is constructed using Modules defined in
the RGG code, the graph reconstruction will fail after the
code is recompiled because the graph is looking for the old
classes. Therefore the option autoRecreate can be used with
sg.setAutoRecreate(true);
. This can be seen
in the example:
examples:Graph
Explorer/SecGraphSaveAndLoadExample