Saturday, February 28, 2009

Live update for sketcher and others

Right now the Line and the Rectangle update nicely (even much better than the old implementation) as they are drawn using OpenCascade instead System.Drawing. Ellipse is done in the same way but it is still a bit unstable.

The PartModeller (3D modelling component of Naro) starts to be separated in Action3D classes. For now only the simple actions (like zoom, rotate, top view) are moved to Action3D class. The Extrude, Cut and Fillet are pretty hardcoded right now, but there are preparations for them to be moved to Action3D items.

PartModeller code will not decrease so much as moving to Action3D classes, because for now its code has a lot of logic that is more than PartModelling code (like update the visualization of the OCAF tree, in fact there are 2 Windows.Forms trees that are updated here: one for a user's eye, in a pretty form, and one in very a detailed way, for the developer). Very probably the future refactor will move this code out of the PartModelling controller code, because it's mostly a view code. (MVC pattern).

What would be next?
- Make ellipse work (and remove other bugs which are found)
- Make extrude work live as action, it will apply without creating again the extruded shape
- Make other actions to work in a live way
- Any other suggestions?

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

Friday, February 20, 2009

NaroCAD to have support for IronPython 2.0!

There was one attempt to work with IronPython in code under the path: branches/CipTests/IronPythonTests. You may find here a mini text editor that can execute simple IronPython code.

As there was a need for a command line interpreter, the code was integrated using the latest IronPython code. The C# code that integrates with IronPython seems to not be so compatible with the versions, as IPy 2.0 is based on DLR (Dynamic Language Runtime). This allows the API of IronPython 2.0 to be more generic and expose the DLR interface to work with. This means that with minimal change right now NaroCad will support in the same way any DLR capable language (like IronRuby).

What can you do right now with the IronPython integration?
- you may execute IronPython commands like this "Hello world" program:
from System.Windows.Forms import *
MessageBox.Show("hello from NaroCad")
- you may: execute the lines you write, load a file from disk, or save onto a disk your hard worked program
- pressing "Enter" to any line will execute your line of program, and in case the program will misbehave the exception will be shown to the user
- you can change all the properties of the command line editor like this: panel.CommandLineEditor.ShowLineNumbers = 1; or anything that reflects the CommandLineView public members (so you can hide/show the items in real time). The way to react with NaroCad internal API is a subject of change but this is a fully working concept
- the editor use the file: (or create a blank one if none exists), as the editor default text.

Here is the picture that values 1000 words.

Wednesday, February 18, 2009

Polyline drawing

Started implementing a polyline drawing tool that also detects the start of the drawing and connects it with the end of the polyline. In order to improve the code and also simplify the adding of new tools started refactoring the Sketcher classes. Estimated 1-2 more days of work to finish this task.

Tuesday, February 17, 2009

Marker dragging

Finished implementing dragging 2D shapes (line, ellipse, rectangle) by their markers. In this way an user can grab for example the corner of a rectangle and modify its width and height. The modifications on the shapes are displayed real time as the mouse moves.
Put the tasks done on TargetProcess. Thinking to try to put there all the tasks needed to make a first version release to see if I can get an estimation.

Will continue tomorrow with implementing the drawing of a polyline shape that ca be drawn as a closed contour allowing the shape to be extruded. Probably the polyline code will be implemented instead of the current line drawing code. Planning also to refactor the code and move code outside the Sketcher controller.

Monday, February 16, 2009

Improved Sketcher

Solved at the Sketcher the problems with mapping between the OpenCascade window and the Windows forms. Now the content fits properly the window, the grid is rendered properly and is rescaled when the window is rescaled.

Solved the problem at dragging a line by grabbing the markers. The line can be dragged. The operation needs further improvements to make it faster and easier to use.

Started Iteration 0.0.8

The task list is posted on Sourceforge.

Also the project Roadmap was updated to reflect the new iteration.

The schedule task list is the following:
Date: February 16 - 27, 2009
- Finish implementing the shape modifications by dragging the markers from the end of it, improve the Sketcher, estimated 3 days,
- Improve the 2d to 3d transition, estimated 1 day,
- Improve the Fillet feature by adding the radius and if possible a progressive radius change, estimated 1 day,
- Finish implementing the Cut feature with Ocaf, estimated 2 days,
- Add Command line functionality, estimated 1 day,
- Add nUnit testing, estimated 1 day,
- Put in place a documentation generation tool, estimated 1 day.

Lower priority tasks:
- Implement code to make the Extrude real time as the mouse moves,
- Solve the redrawing problems: the redrawing has flickering, there is also a bug that Naro gets the HDC/drawing drivers so that other windows
can't redraw themselves, when the window is double clicked and floating the window handle is lost and redrawing doesn't occur.

Friday, February 13, 2009

Closed Iteration 0.0.7

The tasks proposed for this iteration were mostly completed, even some of the lower priority tasks were finished:
- improved the Extrude code, added MidPlane extrusion,
- added a parametric modeling solver that propagates the changes on related entities. Ex: when an extrude is applied on a shape if the shape is changed also the extrude is regenerated,
- added logging with log4net,
- finished implementing the selection mechanism: when an object is selected on the tree list it is also selected in the graphical view and also in the property grid. The selection is made by clicking on an item from the tree and also dynamically on mouse over the items,
- shape modifications from property grid or from graphical view can all be reverted. The Undo/Redo mechanism works properly,
- started working at adding constraints and helpers. At the Sketcher adding markers at the shapes, almost implemented at the line code that allows the user to modify the line by dragging the markers from its ends,
- prepared an installer for the application,
- added for developers a debug window that shows the OCAF data tree, this will be useful on the development process at investigating the data changes,
- started refactoring the code. In order to integrate the command line the commands have to be decoupled from the view.

Tomorrow will prepare the list with the tasks for the iteration 0.0.8 and will also update the documentation.

Among the tasks that will be included in the next iteration are:
- finish implementing the shape modifications by dragging the markers from the end of it, improve the Sketcher,
- improve the 2d to 3d transition,
- improve the Fillet feature by adding the radius and if possible a progressive radius change,
- finish implementing Cut with OCAF and add also some Cut properties,
- code refactoring and cleanup,
- command line functionality,
- nUnit testing,
- put in place a documentation generation tool,
- start using TargetProcess for the development process.

Finished markers, started implementing marker dragging

Finished implementing markers at rectangle, ellipse and line. Made also code improvements at the Sketcher. Implemented at 2d line code that allows dragging and modifying the shape by moving the markers from its ends but redrawing isn't made properly yet.

Will continue with closing the current iteration.

Thursday, February 12, 2009

Implemented markers

Implemented a Marker class and modified the line class to display markers at the end of the segment. The markers will be added at the vertexes of all shapes allowing the user to draw them and modify the shape. The markers are not displayed yet properly, still working on it.

Put in place the TargetProcess Community Edition application. I like it, with many reports, the tracking looks good, the project progress can be monitored in high detail. Planning in the next days to move the tasks on TargetProcess to see how it works.

Wednesday, February 11, 2009


Started working at implementing some 2D and 3D constraints in the application. Read all the documentation available. Will try at the beginning to implement some helper that allows the user to grab the end of a segment and modify it.

Applied at Rally and TargetProcess for evaluating their community editions of Agile software development. Looked also at the others from the market like Mingle, XPlanner, VersionOne, Agilefant. Looked even at MSF Agile. By the end of the week I am planning to adopt one of these and use it for the development process.

Tuesday, February 10, 2009

Implemented MidPlane Extrusion

Finished implementing the MidPlane Extrusion type. This extrusion type creates the model having the sketch in the middle instead of having it as an extrusion base.

Implemented both types of extrusion using BRepPrimAPI_MakePrism, the code is simpler than when it is implemented with BRepFeat_MakePrism. Tried for half a day to make a good implementation using BRepFeat_MakePrism but didn't succeed, the Perform() method fails always. When will implement other types of extrusions (like extrude to shape) will have to make more tests with this functionality.

Will continue with the next task from the iteration that is to add some constraints in the application. As a result will add some constraint code at sketching or some helpers like vertex detection. Will also study how constraints will be integrated into the OCAF model.

Monday, February 9, 2009

Finished selection

Finished the code that selects the visual model when it is selected on the object tree view. The models are also selected dynamically when the mouse goes over the objects from the tree list.

Started making an algorithm library where will keep the code that implements model generation algorithms like Extrude, Fillet, Cut. Separated the Extrude code from the view code and moved it on the Algo library. This will also be needed when will add the command line functionality.

Started working at implementing an MidPlane Extrude type, prepared the code for adding multiple types of extrusion.

Started looking for a free software that offers support for Agile programming. Hope tomorrow to pick one and start preparing it for usage.

Tomorrow will finish implementing the MidPlane extrusion and will also start researching on constraints.

Sunday, February 8, 2009

A possible future fundation for Naro

Qt jumps to LGPL for future versions. This can bring a lot of new chances for projects like Naro to use different platforms.

This weekend I had tried to make on Linux using Mono an OpenCascade project. As they were some samples using Qt 4 I wanted do see how hard is to make all runs on top of Mono. So the rules are simple: make mono to run first and create a QT application that in it's own start an OpenCascade sample.

The good news is that I had used Ubuntu 9.04 which brings OpenCascade (6.2, not 6.3 which is the latest stable) libraries in the default repository! The same about Qt and Mono development (excluding that MonoDevelop IDE package is broken but will be fixed till the final release). So it can make NaroCad to be a very Ubuntu developer friendly project.

I took a Qt4/OCC working project and I had move all code in a QMake/QT library project. The changes are pretty minimalist (mostly is to move sources around and change the template of project from app to lib). Second step was to export to a C interface and I chose to export the main method using another function namely: startMain like this:


#include "QtGuiBackEnd_global.h"

extern "C"
int startMain(int argc, char** argv);


and in cpp file:

#include "qtguibackend.h"

#include <stdio.h>

int main(int argc, char** argv);

int startMain(int argc, char** argv)
printf("hello world from lib\n");
return main(argc, argv);

After test that all compiles I did the mono work that uses P/Invoke as is explained here.

So I created a class named Starter and the code is:

using System;
using System.Runtime.InteropServices;

public class Starter
[DllImport ("/home/ciprian/Desktop/QtGuiBackEnd/")]
private static extern int startMain (int argc, string[] argv);

public static void Main(string[] argv)
Console.WriteLine("Try start");
startMain(argv.Length, argv);

The path is hardcoded but can be changed easily using a .config file but I did decide to try the minimalist path lately and viola, here is the result you see.

Saturday, February 7, 2009

NaroCad Logging

Changed the C# logging mechanism with log4net. log4net is widely used in applications and it was easy to integrate it with Naro.

Will continue working at the tasks from the current iteration.

Friday, February 6, 2009

Using System.Reflection to get OCAF attributes applied to a Label

OCAF tree is the highlevel structure of data that stores the data in a tree formed by number in it's nodes, and extra data named attributes.

The NaroCAD C# code to access one specific attribute may be like this:

OCTDF_Label label = ...
// Check for integer attribute for an attribute
OCTDataStd_Integer integerAttr = new OCTDataStd_Integer();
if (label.FindAttribute(OCTDataStd_Integer.GetID(), integerAttr))
//using integerAttr...

How can we get the list of attribute types are attached to a label? As we don't have a real type introspection accessible using C++ code, or to C# (like from void * to decide which type of object is added, OpenCascade itself makes this thing a bit harder too, as is C++ code and NaroCad is C# code).

What is the solution to get the list of attributes then? We can scan the OCWrappers.dll assembly and to see which class have a method: GetId and invoke it to simulate the previous code:

Assembly assembly = Assembly.Load("OCWrappers");

foreach (Type type in assembly.GetTypes())

MethodInfo[] mis = type.GetMethods();
MethodInfo miGetId = null;
foreach(MethodInfo mi in mis)
if(mi.Name == ("GetID"))
miGetId = mi;
if(miGetId != null)
OCTDF_Attribute attrPtr = Activator.CreateInstance(type) as OCTDF_Attribute;
OCStandard_GUID attrGetId = miGetId.Invoke(type, new object[] {} ) as OCStandard_GUID;
if (childLabel.FindAttribute(attrGetId, attrPtr))
//code that gets the attribute name which is: type.Name
//calls may fail so we should skip missused called types

If you are curious, you may look to the NaroCad implementation which is a bit more improved as the assembly is preprocessed and cached, so only a small list of candidates will be applied to a label, and the OCWrappers assembly is not loaded before every label.

Thursday, February 5, 2009

Parametric modeling (3)

Uploaded on SVN an improved version of the Solver, improved also the descriptors (classes that connect OCAF with the object oriented hierarchy of the application). Now the application propagates changes, ex: if the rectangle is changed also the extrusion is regenerated. All the operations can be reverted, the Undo Redo works well.
Implemented a first version of the Extrude. The extrusion height can be changed.
Added a few more icons on the GUI and increased the toolbar size.

Tomorrow will implement some logging mechanism. Will also work at improving the Extrude.

Wednesday, February 4, 2009

Parametric modeling (2)

Finished the test project with a Solver that propagates the modifications in the data tree. For example if a rectangle is modified also the Extrude feature applied on it is regenerated. Uploaded the code on braches/newtestproject.

Implemented a Solver in Naro that works with the descriptors to register user operations as transactions that makes the operations undoable, also it propagates the changes into the data tree modifying related shapes.
The Solver started to work in Naro, as an example the operation through which the user modifies the width of a rectangle is undoable.

Tomorrow will continue working at the Extrude operation, will cleanup and stabilize the Solver and upload the code on SVN.

Tuesday, February 3, 2009

Parametric modeling

Investigated how to propagate automatically a modification into the OCAF hierarchy in order to enable parametric modeling. Looked at the TDF, TNaming classes also at the TFunction classes.

The problem is to find a way to get a list of Labels that hold references to the modified Label and regenerate the models that these Labels hold. Made tests with TDF_Tool.OutReferences and OutReferers and these doesn't seem to be made for this purpose. Also couldn't find a TFunction mechanism to propagate changes automatically. On the forum there are no details related to this. Internally also the TDF helpers seem to be implemented with a loop through all labels, they use filters but don't seem to have an optimized way to search for some referenced label.
In order to handle this problem I implemented a solver function that loops through the labels and identifies the ones that hold references to the modified ones. Will think also if it is an improvement to hold a back reference between labels.
Solved the Undo/Redo problem at the shape modification. This task was scheduled for next week, but solved it.

Tomorrow will finish implementing the shape regeneration code and will continue with the Extrude.

Monday, February 2, 2009

Extrude improvements

Started working at Extrude improvement. Today made Extrude tests on a simple application to understand how is the shape evolution registered at the OCAF level. Studied again the documentation and the sample apps provided with OCC.

Studied also the Extrude options that other applications provide and how it operates within the drawing area. Mainly it should have the properties: name, color, Sketch to be applied on, extrusion type (to depth, through all, mid plane, to next, to geometry, etc), maybe also some draft angle. First will try to implement a complete extrusion (selecting the sketch) and after that if time will allow will implement some other types of extrusion.

Tomorrow will start implementing Extrude.