Friday, January 7, 2011

Advanced Expression Evaluator using Boo and Extend it by Scripting

NaroCAD is free and opensource software and we enable technologies that .Net environment offers. One feature I've always wanted NaroCAD to have, is to use as much as .Net can, in general I refer to be able to use as large capabilities of the platform like inter-language interoperability, good performance, garbage collection, true generics, possibility to use advanced graphics as WPF.
We have already support of Boo, which in short brings to NaroCAD. a REPL like capability ("eval"). But to start to extend using Boo you will need to know using C# and to convert static code in dynamic Boo code, which is not trivial. .Net 5.0 is said to have REPL support, but till then, and waiting that NaroCAD will be updated to that platform, we have just Boo.
So, as I know that we have that power accessible, it will not be nice to use it? So I've added right now using Boo as an expression evaluator on double valued expressions. In short, if you write expressions that are in property grid, some dialogs (mostly Fillet/Fillet2D) or command line, they will be evaluated through Boo and will replace this value with computed one. Because Boo will precompile first this script, secondly it will execute it, you may see a small lag doing this, but at the end the result is what it matter.
So right now you can write as values: Math.Sin(Math.PI/6) instead of 0.5.
What if you will want to define your own expressions, like pi = Math.PI, and so on? The script evaluator will be provided and modifiable under file: BooEvaluator.boo. So you can experiment with it and you will have all tools to make it work. Also you will have a reference to ActionsGraph, meaning in short that this scripting if you will need to change or extend, can have access to all data of NaroCAD, so you will be able to compute for example how many rectangles you have in your scene and use it as helper function.

So look to following video description to see how it works:

No comments: