Friday, February 27, 2009

Changes under the hood for NaroCAD sketcher and OCAF Drivers

From our last blog entry the changes are pretty serious and the actual code is pretty experimental, so feel free to try the code out and report crashes.

What is the purpose of all these changes? To make NaroCAD react more lively on mouse-events and to simplify the creation of tools (and working with them). The target task is to make Extrude happen live and the same on all the other pieces.

NaroCAD is build on top of OpenCascade. The code was made to create a tree structure named OCAF Tree that represents all the data that are shown. For making the pieces right we rely on Ocaf changing. Anyway, the current code did not happen lively. If you had an older version of NaroCad and did an extrude, you got from scratch the shape (that was extruded) and the extrude that relied on it. If you built a line, the code was to preview the line and at the end you modified the OCAF tree.

What was changed for now?
- the shape-building infrastructure (named OCAF TFunction drivers) rely on a schema, that reduces greatly the lines of code (and makes it much clearer). The schema class refflects a subtree of OCAF that makes the user read a specifc structure. This will hide most of OCAF tree at least for building TFunction drivers from scratch
- the sketcher has a class named: Action2D that is registered to a factory named: Update2DModifier, class which gets 2D items that are needed to operate over the OCC view and OCAF tree and they can modify it. This refactor makes that every Action2D class gets mouse events and the life-creation event (onActivate event). As events are not only the shape creators but any Sketcher events like: Show line grid or Zoom. These changes simplify greatly the code of sketcher and reduce the lines of code from 860 lines to 410 (the logic was moved anyway to Action2d classes).

What should you expect from this changes:
- it will be easier to create a brand new sketcher action that updates lively. For now the actions will disable automatically after the mouse-up but this is going to change;
- the code is much cleaner and you will not need to insert more that 5 lines of code in sketcher to add a new action that gets all mouse events
- the code is experimental, so expect crashes and problems
- updates of the sketcher do not happen in a proper way (so wait a bit for fixes)

What do I plan to do next?
- to create an Action3D that will work on 3D modeller and to update lively the Extrude, Fillet and Cut
- enforce the Schema implementation to be used wider, so the Description code (that populates Object Properties), sketcher design code and modeller design code will have a reduced code and will not write an OCAF specific code. This will make it easier for every one not to make mistakes as reading out of the defined data domain and will make cleaner cases when the user reads wrong data.
- bug fixes

No comments: