It's now time to test the whole application.
We didn't develop yet an interface that allows users to input their contributions, for example via a web page. We will do that in the next part of this tutorial. We can, however, simulate user input and create the picture by programmatically calling the service commands we created in the previous chapters. We will do this in the script that is called each time the application is started.
Whenever you create a new project, Obix creates a run system command file (run.sh on Unix systems, and run.bat on Windows systems) which is located in your project's root directory. Executing this system command runs the application. The first script executed each time an application starts is a service command located in the root library of the Obix source code directory and whose identifier-suffix is equal to the project's identifier-suffix. In our case the path to this service command is li_random_arcs.se_random_arcs.co_run. By default this command just displays a message on the system console. To create an SVG picture instead proceed as follows:
Edit the existing file se_random_arcs.osc in your project's sub-directory work/obix/source_code/li_random_arcs/.
Replace the existing code for command run with the code shown below and also add command run_simulation, so that the whole code for se_random_arcs.osc looks as follows:
service random_arcs
command run // this command is called when the application starts
in command_line_arguments type:indexed_string_list voidable:yes end
script
se_system.console.write_line ( "Project 'random_arcs' started." )
co_run_simulation
se_system.exit_with_success // TODO: add error handling and use
// 'se_system.exit_with_error' in case of an error,
// in order to inform the OS about the failure
end
end
command run_simulation
script
// add 3 contributions
se_contribution_list.add_from_strings ( &
first_name = "Giovanni" &
last_name = "Spiridigliotsky" &
random_number = "10" )
se_contribution_list.add_from_strings ( &
first_name = "Jean" &
last_name = "Dupont" &
random_number = "5" )
se_contribution_list.add_from_strings ( &
first_name = "Jennifer" &
last_name = "Amiladili" &
random_number = "15" )
// create the picture
se_picture_creator.create_picture ( show_contributor_names = yes )
end
end
endCompile and build your project by executing the compile_and_build system command.
Run your project by executing the run system command.
If everything went fine you should now see the following files in your projects root directory:
File contributions.json with the following content:
{"identifier":1, "first_name":"Giovanni", "last_name":"Spiridigliotsky", "random_number":10, "date_time":"2011-09-17 14:33:22"}
{"identifier":2, "first_name":"Jean", "last_name":"Dupont", "random_number":5, "date_time":"2011-09-17 14:33:28"}
{"identifier":3, "first_name":"Jennifer", "last_name":"Amiladili", "random_number":15, "date_time":"2011-09-17 14:33:28"}
File next_contribution_id.txt with the following content:
4
File picture.svg with the following content:
<?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="800" height="800" xmlns="http://www.w3.org/2000/svg" version="1.1"> <title>Arcs</title> <desc>Arcs created by random data provided by different sources</desc> <!-- draw a frame --> <rect x="1" y="1" width="799" height="799" fill="none" stroke="blue" stroke-width="1" /> <text x = "10" y = "22" font-family="Verdana" font-size = "11">Giovanni Spiridigliotsky</text> <path d="M 400 400 A 120 120 0 0 1 280 280" stroke="rgb(113,209,221)" fill="none" stroke-width="40" opacity="0.9"/> <text x = "10" y = "37" font-family="Verdana" font-size = "11">Jean Dupont</text> <path d="M 280 280 A 70 70 0 0 1 350 210" stroke="rgb(245,16,38)" fill="none" stroke-width="40" opacity="0.9"/> <text x = "10" y = "52" font-family="Verdana" font-size = "11">Jennifer Amiladili</text> <path d="M 350 210 A 170 170 0 0 1 520 380" stroke="rgb(99,204,140)" fill="none" stroke-width="40" opacity="0.9"/> </svg>
You can now open file picture.svg with any application that supports SVG files, for example:
Inkscape, a free and open source vector graphics editor
the latest version of any web-browser (except Microsoft Internet Explorer which doesn't support SVG files at the time of writing)
Here is an example of the result:
If you run the application 4 times the picture looks like this: