User Tools

Site Tools


tutorials:rgg-code-structure

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorials:rgg-code-structure [2024/12/04 09:37] – [Working with several Files] tim2tutorials:rgg-code-structure [2025/01/10 11:16] (current) gaetan
Line 76: Line 76:
 ==== Queries ==== ==== Queries ====
  
-In GroIMP the project graph is considered to hold almost all information on the simulation. Therefore it can also be seen as a knowledge graph. To retrieve this knowledge rgg uses the [[tutorials:common_graph_queries|XL query system]]. To use this queries in a java block they have to be framed by ''(*...*)'' as shown in the examples below. In that way they return a collection object, which then can be like other java objects. Moreover GroIMP comes with a set of predefined  [[groimp-platform:xl-operators|Analytical Operators]] to analyze this collections.+In GroIMP the project graph is considered to hold almost all information on the simulation. Therefore it can also be seen as a knowledge graph. To retrieve this knowledge rgg uses the [[tutorials:common_graph_queries|XL query system]]. To use this queries in a java block they have to be framed by ''(*...*)'' as shown in the examples below. In that way they return a collection object, which then can be like other java objects. Moreover GroIMP comes with a set of predefined  [[:groimp-platform:xl-builtin-methods|Analytical methods]] to analyze this collections.
  
 As shown in the example below in ''%%count((*M*))%%'' this queries work with the concept of java objects. Therefore ''(*M*)'' is selecting all instances of Branch because Branch extends M. This also works with interfaces.  As shown in the example below in ''%%count((*M*))%%'' this queries work with the concept of java objects. Therefore ''(*M*)'' is selecting all instances of Branch because Branch extends M. This also works with interfaces. 
Line 108: Line 108:
 ===== XL Blocks ===== ===== XL Blocks =====
  
-While using XL rules mainly two operators are used: replacement rules(''%%==>%%'') and   execution rule (''%%::>%%''). +While using XL queries mainly two rules are used: replacement rules(''%%==>%%'') and execution rule (''%%::>%%''). 
    
  
Line 156: Line 156:
 ==== Working with several Files ==== ==== Working with several Files ====
  
-{{ :tutorials:file_explorer.png?200|}}+{{ :tutorials:file_explorer.png?260|}} 
 + 
 +In GroIMP it is possible to split your code into several files and folders to improve the structure and keep an overview. 
 +<color #ed1c24>It is highly recommended to only have public void functions in one file. Otherwise your project will have several rest buttons that do different things... </color> 
 + 
 + 
 +To use function from another file this file needs to be imported similar to a java class or package. 
 +Yet in the case of GroIMP all files are imported by their name without the directories, therefore to import all modules, and classes in ''param/parameters.rgg'' you just write: 
 +<code java> 
 +import parameters.YourModule; 
 +</code>  
 + 
 + 
 +To get this a bit clearer lets assume our parameters.rgg file contains the following code: 
 +<code java> 
 +public static int length = 1; 
 +public static float diameter = 0.1; 
 +module Leaf() ==> leaf3d(1); 
 +module Shoot() extends F(1); 
 +</code> 
 + 
 +To import one specific object once, you can simply do ''parameters.length'' as for example in ''A(parameters.length'' in the new RGG project. Or to use module: 
 +<code java> 
 +protected void init () 
 +
 +Axiom ==> parameters.Leaf(); 
 +
 +</code> 
 + 
 +If you want to use your module several times you can also import it one in the beginning and then reuse it: 
 + 
 +<code java> 
 +import parameters.Leaf; 
 +protected void init () 
 +
 +Axiom ==> Leaf()[RL(180) Leaf()]; 
 +
 +</code> 
 + 
 +Finally you can import all modules with the * operator: 
 +<code java> 
 +import parameters.*; 
 +protected void init () 
 +
 +Axiom ==> Shoot() Leaf()[RL(180) Leaf()]; 
 +
 +</code> 
 + 
 +This can also be done with the static variables using static import: 
 +<code java> 
 + 
 +import static parameters.*; 
 +protected void init () 
 +
 + Axiom ==> F(length,diameter); 
 +
 +</code>
  
-In GroIMP it is possible to split your code into several files. 
tutorials/rgg-code-structure.1733301426.txt.gz · Last modified: 2024/12/04 09:37 by tim2