Sunday, February 28, 2010

How To Use NaroCAD To View A Custom Shape (Part I)

NaroCAD is build on top of OpenCascade library and it tries to make not only a wrapping over OpenCascade but also to simplify for .NET folks, like in workflow patterns like adding a new shape.

For this you will need to break down your shape in the following parts that will be described bellow:
- persistence (part I)
- function (part II)
- (meta)action (part III)

Persistence
NaroCAD keeps all data you view in a tree that can be saved and restored from xml. If your custom shape needs more than: a real (a double value), a color, a 3D point, another shape, or other defaults that NaroCAD provides, you will need to define your custom data that NaroCAD will save in the Document's tree.
Here I will define a Point2D class that is not defined by NaroCAD and someone may not want to use Point3D as a substitute for Point2D.
All objects that does keep custom data are named in NaroCAD's code language as Interpreters (or Attribute Interpreters) that make you store custom data. Those interpreters have to do two things: to inherit from AttributeInterpreterBase and to implement methods: Serialize and Deserialize.

public class Point2DInterpreter : AttributeInterpreterBase
{
public Point2DInterpreter() : base(){}
double X { get; private set; }
double Y { get; private set; }
public void SetCoordinate(double x, double y)
{
X = x;
Y = y;
OnModified();
}

public override void Serialize(AttributeData data)
{
data.WriteAttribute("X", X);
data.WriteAttribute("Y", Y);
}

public override void Deserialize(AttributeData data)
{
X = data.ReadAttributeDouble("X");
Y = data.ReadAttributeDouble("Y");
OnModified();
}

}

Some questions may occur on that custom code, like: what is OnModified? The constructor is mandatory to be defined? What is "AttributeData data" parameter defined in Serialize/Deserialize methods?
Let's answer one by one:
- OnModified() call announce NaroCAD's framework to make updates because your value was changed. If your Point2D was a part of a Line2D shape, the Line2D will get notified that it should generate the line
- The costructor is the default one and may not need to be defined (you can remove the line of constructor in the previous example) but you may use it to define your defaults there
- data variable is used to save and restore your data that defines your custom interpreter. When you define your Serialize method, you should save (write) all things that define your interpreter and you should do the load (read) at the Deserialize method. It is guaranteed that Serialize will be called always before Deserialize and the data will be always setup by a Serialize method of the same class. Deserialize call OnModify just because this Deserialize is mostly called on two events: Undo step (or Redo one) or on opening a file. Which makes sense to notify about changes to apply all on view
Before loading: AttributeInterpreterFactory.Register<Point2DInterpreter>(); should be called once. This is because this type may not be known at the runtime because .NET use lazy loading of code at least in the NaroCAD's code. This code is under PartModelling/DefaultInterpreters.cs so you may need to add this line there.

How you access attributes?
You may get access to two entities: a Document or a Node from that tree.
If you start with the Document, you can obtain the root node by: Document.Root property.
Any Node may have any number of AttributeInterpreters, and they can be either queried by using:
Point2DInterpreter aPoint = aNode.Get
<Point2DInterpreter>();
if(aPoint != null) //if there is an already setup point
{
aPoint.SetCoordinate(aPoint.X, aPoint.Y+10); //move the point 10 units over Y axis
}
If you will want just to setup or create in place, use directly Set method of node like following:
Point2DInterpreter aPoint = aNode.Set<Point2DInterpreter>(); //get the current Point2D
//or creates a new one of none exist
aPoint.SetCoordinate(aPoint.X, aPoint.Y+10); //move the point 10 units over Y axis

As you see the null test is not needed in those cases.

The following part in this mini series it will show how to create a custom OpenCascade shape that will be visible by adding a lua command to enable it.

Saturday, February 27, 2010

Dynamic Toolbar Progress


The toolbar that will be contextual progresses as it targets most of the misses (like crash selecting it, possibility to assign to a specific group, shared icon image cache with tree view). The work will continue on improving the code and integrate nicely with selected item.
The code was reviewed by bxtrx, and we will see most likely a close to complete dynamic toolbar at Tuesday.
Update: here is added a hardcoded context when selecting an hypothetical shape. This is a mockup but it will get more complete and will work on any regular selected shape.

Friday, February 26, 2010

Command line bug fixing

Fixed most of the critical bugs generated from the command line changes to tools.

As a new beta release is planned to be made at the end of next week, the development direction on the command line integration will be to improve the protection of these against invalid data/inputs, also will slightly improve the code through careful refactorings.
Other improvements will be made on the WPF GUI and existing tools accentuating more on practical use of the tools.

Thursday, February 25, 2010

Working On Contextual Information

I work to enable a context based workflow that will be enabled as a separate tab on the ribbon. This tries to enable the corresponding tools based on the selected shape/feature. This makes sense mostly for users that either don't want to look for tools, but also it can make the interface to appear "more intelligent". If the concept will work nice, I hope in time of tomorrow to be seen at least the concept how it works and what is it all about. This also will not insert clutter in the right mouse click.

Tuesday, February 23, 2010

Tree View Items Based On Capabilities

The tree displaying the items is shown now using custom icons. In this way shapes are also put in categories and if (in future) a new shape is created but there is no custom icon to differentiate in tree, it's icon can be taken from the category shape, or feature, that is defined in.
I will work to improve more the code in this area and to look to other improvements.
Nightly build is downloadable from here.

Monday, February 22, 2010

Unit Testing Fixing

As I use SharpDevelop as my primary IDE, I found unit testing debugging fairly hard as there is not such an advanced debugger as VS has. Anyway, the solution will be to be possible to run not only by me, but by anyone that do not have an integrated NUnit (like VS Express users) or not an very advanced debugger (as myself), to run them without it. The main change was to change the unit test's class library to a console application.
I also reviewed the capabilities code as it may be used to other components like a future right click to components.
This code needs some changes as it has to create too many children and the code there may get fuzzy and hard to debug. Also the capabilities old code had no clear separation between concepts and capabilities and capabilities did not had keys/values as most persons will expect from a dictionary like code.
The redesigned code it does the following: you can create a concept (like an abstract item likewise is: shape, feature, etc.) To any concept you can add capabilities (that is a key/value pair) and a relation of Is-A to another concept. In this way you can inherit all properties of another concept. Also a concept when is related with another and both the class and the related concept have a value, the capabilities are searched firstly in the current concept, later inside it's relations.

Here is how Rectangle based shape will get as default icon the Shape's icon:
var shapeConcept = Capabilities.AddConcept(ConceptNames.Shape);
shapeConcept.SetCapability(CapabilitiesNames.DefaultIcon, "../Resources/box.png");
(...)
Capabilities.AddRelation(FunctionNames.Rectangle, ConceptNames.Shape);

TreeView's code was updated for those changes but not all shapes are defined as right now with proper relations. Also, the capabilities code need to have more tests in the unit tests and to use it to find some misses. If everything will work fine, the concept can be extended for more inherited like code that just need to setup a key and a value for them and there is no need to create large class hierarchies for this.

Download the nightly build from here.

Bug fixing

Fixed the Lua scripts test suite, some of them were failing after the latest porting to command line. Now all test scripts are up to date and passing.

Fixed some command parsing and command line integration for circle, cone and cylinder.

Saturday, February 20, 2010

Post Beta Fixes

There is a nice as concept bug that was happening when working with Options dialog. This bug was fairly strange as if you will get am error like: "Cannot show page WizardStartPage because is already disposed" and was an Windows.Forms error.
This bug was not found in previous builds (previous from WPF refactor) as the Options wdialog was setup in a singleton and closing the dialog did internally a hide. Right now this dialog was recreated.

How Options dialog worked firstly: the Options dialog was a host and there is an Options' manager that delegate the options changing to custom pages. So the Options Host (the dialog) asks a page from Options Manager and displays it on it's section. So at the end it just happen that the host dialog should dispose the Options Manager page when it host that page. Did you lost the track? It's ok... I've did it for some times before I've found what was the cause.

Also a small fix is in installer as it propose to you to create a desktop icon to start the application. At the end you are proposed to start NaroCAD from installer.

Note: I'm trying to investigate the NGen issue so this (nightly) build will have NGen enabled. NGen precompile .NET assemblies and it will reduce the startup time enough much to worth the effort to be enabled. If you will get issues (like mouse will stop working, or UI freezes), please run this command as administrator (if you use Vista/Windows 7, press start, write cmd, and write click on the first result and chose "Run as Administrator"): "C:\Windows\Microsoft.NET\Framework\v2.0.50727\ngen.exe uninstall C:\NaroCAD\AppShell.exe" to revert those changes. The ngen call is queued, meaning that you're up to go from the time installer finish, but the compiling will be done in background just to not annoy you waiting some minutes at the end of installer.

As usually, download the nightly build from here.

Release NaroCAD 1.4Beta

Released NaroCAD 1.4Beta. The installer can be downloaded from here.

The new main feature added is the command line integration of the 2D shapes, 3d shapes and boolean tools. The coordinates, heights, radiuses, etc can now be inserted from command line. It is also possible to mix inputs from command line and mouse while drawing.

Friday, February 19, 2010

Bug Fixing and Continuous Integration (or almost)

NaroCAD is a 32 bit application just because it depends on OpenCascade on 32 bits build. As most of you have a Windows on 32 bits, they will not notice that are build problems if you have a Windows 64 machine. Most of problems will not appear on Visual Studio for the very simple reason that Visual Studio (at least Express version) is a 32 bits application and also it defaults on 32 bits. SharpDevelop (my IDE of choice) is a 64 bit application (because is a .NET application) but because it rely on a 32 bits debugger you will have to setup at least for the startup project a configuration just for 32 bits one. Things get really ugly when you want to use MSBuild build system (that is provided with .NET) and MSBuild as SharpDevelop is a 64 bit .NET program and gets a lot of abnormalities with mixed configurations.

I and bxtrx spend a lot of the start of the day to target those issues and eventually we solve them. The benefit of this project is really simple: we can automate the build, the installer and to upload the build. In fact as I write this blog, the build happens as it update the latest svn snapshot, revert (just in case) local changes, it runs a release build, it runs some tests (a subpart of our NUnit test suite), it creates the installer (just in case all previous things pass successfully) and upload to FTP.

I've also solved a bug that values set from command line do not update the seen shape. With all that things done, was a nice progress day.

So you can download it as usual as a nightly build.

Cylinder, thorus, sphere meta tools

Finalized porting to command line the 3D solids (cylinder, thorus, sphere). The box and cone were ported in the previous day. All of them are now integrated with the command line and can receive input from it. As functionality they work quite well.

The 2D, 3D and boolean tools were integrated with command line, NaroCAD is quite in good shape for a beta release. Will continue now with bug fixing and polishing the ported tools, about 68 bugs are waiting for fixing.

Thursday, February 18, 2010

Spline Added and Working on Fixes

Spline action was added to step actions. In itself was a bit tricky as it should dynamically add steps as the dependency are filled. I also worked to specific bugs as I finish the bxtrx fixes on parser to not state the unknown value for axis but I did not yet find why there is a command line fill will skip updating the screen. I will investigate tomorrow as the causes may be really a few (and I hope to get them).

Updated the nightly build. I also made this nightly build to run in just one step (some changes like updating version may still need to take extra step, but just from svn tree to making a downloadable file it takes just one step from developer standpoint). This is done using a nant script so it can permit some fuzzy logic in it in future, and to be more advanced than the equivalent batch file.

Box and Cone tools ported

Ported the Box and Cone to Meta Tools. They are now integrated with command line.
As additional feature improved the drawing animation to display segment lengths or shape height while drawing.

While porting identified the particular situations that are currently implemented in the tool code. Planning in the future to simplify these areas and cover them in combination with base classes functionality.



Sphere, Torus and Cylinder remained to be solved for tomorrow.

Wednesday, February 17, 2010

New build with even more fixes

As changes were setup in the code both on parallel line and in other fixes a new build is uploaded. Hopefully this build will show how much we advanced at the command line porting and you will enjoy it.

Download it from here.

Line normal/parallel to plane tool

Today finished porting the line parallel to plane and line normal to plane to meta tools. They work both from command line and mouse, also display hints.

Improved the Extrude meta tool but it still has some bugs to fix.
Tomorrow will continue with porting the 3D solids (sphere, cone, etc) to meta tools, hope to finish them in 2 days and get ready for the end of week beta release.

Tuesday, February 16, 2010

Editing and Extrude should work as expected

Today I've target bug fixes only. Was a nice day as some of bugs are really harder to reproduce and to spot.
They fall mostly in three categories:
- the line refactor made some cases when non all dependencies are fixed or completely filled to give exceptions
- editing mode works again (I think that did not work for some time)
- multiple extrudes should work without crashes

Line parallel with plane

The Extrude meta tool is finalized and activated in Naro; it has the same functionality as previously.

Finalized a first version of line parallel with plane tool. It needs some bug fixing before activation in Naro. While working at this tool found improvements and fixes at the Meta Tools base classes. Also extended the Line Function class (the class that knows how to generate OpenCascade lines); the class can take two extra arguments that specify the type of line generated and a reference (ex: type is "parallel line" that has a reference to a plane to which it is parallel to). This extension will make easier to implement also the line normal to a surface tool.
Hoping in half of day to finish both these tools then will continue with the 3D shapes like cone, box, etc that are estimated to take around 2-3 days to finish.

The hints added at the line, rectangle, circle and boolean tools seem to work well. They are also useful as helpers for the user to know what's the next action to do.

Currently the work is on schedule for the 1.4 Beta planned for the end of the week (on Friday evening or Saturday).

Monday, February 15, 2010

Fixes on Command Line

Today were fixed last remaining issues with relative coordinates (like the relative coordinate did not update from mouse inputs, just from other command line which may not be the expected case in a lot of situations). Also the bugs in numbering of shapes were largely addressed by attaching per document this and the possibility to froze it. I also looked to a bug in duplicate shape creation.

Extrude meta tool

Today worked at implementing Extrude as meta tool so that it ca be integrated with the command line and receive input also from command line. The porting is almost finished, the functionality is similar with the previous one, it only has some shape selection bugs.
While porting this tool fixed problems encountered in the meta tools base classes and also tried to simplify the existing code.

Tomorrow will fix the Extrude bugs and will port also the line parallel with surface and line normal to surface tools.

Friday, February 12, 2010

Hints on Action Steps

One of the benefits of rewriting actions is to provide useful step information. With just adding some extra information for every step, this information can be shown to user. So user can get a proper hint message.

So all actions ported to a step based action can take advantage of this. Also this is enable for now just for line action but will be extended for all useful actions.

Also some logic error were fixed and the hints updates regardless of how you complete the shape's parameters: either by command line or by clicks.

You can download this build from here.

Bug fixing

Continuing until the end of this week to fix bugs starting with the critical ones.

There are two main directions that we follow:
- at the end of the week the command line should work perfect for the "line" command to get inputs from mouse and keyboard and will be able to demonstrate the complete functionality,
- as less than half of the tools are ported to States to be integrated with command lines, switching between tools with States and regular tools might put the command controller in unstable states that leads to crashes. We hope to stabilize this hybrid working mode until all tools are ported to States.

Thursday, February 11, 2010

Command Line Latest Fixes

Command Line may work badly for some enable/disable actions with the yesterday release and may cause multiple headaches, but at least you were warned. So, the today's build fix more (if not most) of that problems but if you still want a more stable build, wait for one or two more days.

This updated fix release can be downloaded from here.

Wednesday, February 10, 2010

Preview Build for Command Line and WPF Completion

NaroCAD gets forward in usability and look&feel, but also in functionality.

WPF porting of the "old" NaroCAD was ported to WPF equivalents, so as of today only OpenCascade View and the Grid View are non WPF controls (OpenCascade is for obvious reasons), but the TreeView and Lua dialogs are also ported. Are also applied WPF styles to frames and controls, giving to NaroCAD a dark-cool appearance.

Internal changes are also disruptive so you may expect crashes and some problems with this preview build as the actions can be defined as intermediate states shapes. Also the shapes can be filled (some of them, that are ported to the new command line components) with mixed data from command line control and mouse clicks. Command line for points will be able to use relative coordinate in this way: a regular coordinate is setup as 0, 0, 0 (or any floating point way like: i.e. -0.231, .23, 10 ) and the subsequent coordinates can be defined by reusing the old coordinate simply by keeping a blank space between commas or adding/substracting using the r letter like: 0, , -23r (meaning that X coordinate is 0, Y coordinate is from previous Y and Z is the previous Z subtracted 23).
As we will continue to make it more stable you will enjoy rich help from one side and simpler definitions for creating new shapes and so.
An interesting opinion from a free software creator points out that if you will want that your (free) project to change in the direction that you intend to, you should contribute with it. The topic generator gets the idea that anyone that gets in a community, it should stride to get a role. So, just in case you are interested in contributing to NaroCAD, just as testing this release or adapting it to your specific needs, you can drop here a line.
To try this release, download it from here.

Tuesday, February 9, 2010

Command Line prototype working

Splitting commands in states give to user two benefits:
- it can give local help for user like: please input the next coordinate
- it can make a command line to be consistent and to extract information regarding your used command

As of the latest change the command line works with simple commands to fill the points for line and to execute empty commands.
The code have still too much dependencies from my taste but is a fully working concept where the user can introduce coordinates both via mouse clicks and command line. This may be found interesting when you work with tools like extrude or fillet, where mouse may not be that precise, but picking of the shape may be wanted to be done manually.
This makes to fix some bugs like: when you start typing a command, the command line action was not activated. Also, state actions that were depending on inputs, may have problems to not get initial data. As those changes are fixed, probably other related bugs may be fixed too.

Monday, February 8, 2010

Meta Animations

Worked at using the State code on Meta Commands (commands supporting integration with command line).
The two functions that I needed to be supported were to be able to add additional animations while drawing shapes and to be able to implement a more than trivial custom animation at any tool overriding the generic provided one.

After a few code adjustments succeeded to implement an animation at rectangle drawing that shows realtime the length of the segment drawn. To implement this I also added a new Dimension function that draws a dimension between two points. This will be added also as tool as it might be useful on scene drawing.

Still couldn't implement on the new Meta Commands for Extrude a custom animation that duplicates the existing one. Solved a mouse point retrieving issue, still need to improve the drawing code.

From this week testing intensified on the current functionality, the bugs started flowing. We should be able to solve by the end of the week at least the critical ones.

Sunday, February 7, 2010

Improving the states code

After a class of shapes can be separated in states, the next step is to create custom commands. As of today most work was focused for common cases like resolving automatically with minimum setup old actions to the new code.The new actions work as you fill states and you have to write in advance which steps do you need for that action to complete and the current code will try to automatically fill the Inputs and to give the data for the action.
The "old" actions were working by querying application resources (like: OpenCascade's context, OpenCascade's View, mouse clicks) named Inputs. What will happen if an action will need a new resource that was not "invented" at the moment of defining it? It is needed the same solution: an extensible framework to give to that action as Inputs code already exist. So the Inputs are now accessible to any state based action via it's dependency class that is needed to be filled.
I did also worked to the command line parser to create "stages". I use other name just to differentiate with States name. Those stages are for known command line definitions that I will try to fill them tomorrow in the command line. They are mapped to command line states. So if a command line will ask for a double, or integer, the command line may offer that to user.
Small fix: WPF treeview was fixed in filtering part so most probably is functionally equivalent with the old code.

Saturday, February 6, 2010

Going to Vienna and some impressions

I was away for around 10 days but I want in special to share some of the very great impressions I had there. Firstly is very cold. Not as in Siberia. But for certain for me was a drop in temperatures from around 10 degrees to -10 degrees (Celsius) as I went from Madrid to Vienna.
What you will find there are great places as Schoenbrunn palace and park, great museum of Natural Science.
German is everywhere but knowing to say Danke (thanks) is nice and you have a lot of people recommending to you popular foods like schnitzel.
Was also an occasion to see my twin brother and my 3 months old nice.
I really hope that if you are in a trip and you don't know what to see, to try to take some time to see Vienna.
Getting back I am getting prepared to add new great things to Naro so stay tuned!

Thursday, February 4, 2010

New State pattern tools, WPF porting progress

Enabled in Naro the Boolean (Fuse, Subtract, Intersect), Point, Line Tools to work with State pattern so that they can be integrated with the command line and can receive input from both command line and mouse.

Replaced the tree view control with the new WPF version of the tree view control. The tree view searching functionality is disabled for the moment, the searching implementation will be ported tomorrow.

Monday, February 1, 2010

State pattern porting

After implementing the Rectangle tool with States pattern (tool that has 3 points as dependencies) ported the Circle tool to State pattern (tool that receives as inputs an axis that defines the location and orientation and a radius). Almost finished also porting the Extrude tool to States and started porting also the booleans. Planning tomorrow to finish porting all these tools that are covering the major situations encountered among the tools. The porting of other tools should be faster as they are similar to the tools above. While developing these also improved/fixed the code from command line action implemented with States.

Meanwhile my colleague made progresses at adding styles for the WPF elements, this should allow easy change of layout and colors for any component. Hoping by the end of the week to replace also the tree view list with its WPF component for each we already have some code finished. After these will remain to port the property grid control and the OpenCascade OpenGL control.

Latest screenshot: