Monday, June 28, 2010

UI Extensibility

NaroCAD extensibility was made to extend it as shapes. But sometimes is useless without adding your custom interface to call in this new functionality. This functionality is here. Some problems are still there. The biggest one is that the NaroCAD is not aware of plugins loaded so every time you reload the plugin, the new UI will be added again and again. But just restarting NaroCAD will make everything to go to defaults, so probably you will not have problems as long you extend.

Sunday, June 27, 2010

Plugin Sample and MetaAction Code Separation

Adding features makes a lot of code to be added in one place as and makes that code to have some problems known as anti-patterns. The biggest one is code coupling and which means that adding an external component will simply mean to change NaroCAD code.
In the last days I've tried to cleanup a bit the code just targeting this.
So I've decided to make a simple task: to add dynamically from Lua a new shape, that is a "SimpleLine" that is created by defining just its two points. The Line in NaroCAD is more powerful as it can express relations with other lines (the normal line shape is covered by the NaroCAD's line shape). Also I've wanted that this shape to be defined in a separate assembly as it would be an natural way to extend NaroCAD.
So what I've found out?
NaroCAD is written in an Object Oriented Programming (OOP) manner, meaning that most of the created entities are defined in (abstract) factories, and the factory have a registering mechanism. If you want to add your new shape, you will have to define your Function based class, and to register to the corresponding Factory (named intuitively as FunctionFactory). In a proper extend it was visible that Lua have no access to this entities and some were needed to exist.
This makes to show which factories are really exposed, and which are really coupled in NaroCAD's core. One of them was standing out: the MetaActions's Factory. As MetaActions were defined to a NaroCAD component named PartModelling under the CommandLineAction, the code was just inside PartModelling and at least no other external meta-action was possible to be registered (without making hacks).
The factories exposed are for: Functions, Lua methods, Inputs meaning new data sources for NaroCAD based actions, new Actions, new Options dialog pages and new custom Property Grid dialogs.
The single missing part is that you cannot add it to ribbon tab as the code, but excluding that you can do it just starting from Lua and your C# component, you can customize NaroCAD fairly dramatic. As you can register commands like Meta-Actions, you can add your custom command line tools. I will try to create a small tutorial how to create your custom shape and register it to NaroCAD as running and to make it working.
But as I thought that most of people wants just to create their custom OCC shape and to be ready to go, I've made a simple Lua API that you can execute your function (even registered in Lua) and fill its dependencies.
So I've created this SimpleLinePlugin that defines internally the SimpleLine function, and without registering to Lua (you should register your Function though), you can write a code as follows:
loadPlugin("SimpleLinePlugin");

defineShape("SimpleLine");
setPoint(100,100,0);
setPoint(200,200,0);
executeShape();

The SimpleLine function is defined as follows:
public class SimpleLine : FunctionBase
{
public SimpleLine() : base("SimpleLine")
{
// First point of line
Dependency.AddAttributeType(InterpreterNames.Point3D);
// Second point of line
Dependency.AddAttributeType(InterpreterNames.Point3D);
}

public override bool Execute()
{
// Get the two line points
var firstPoint = Dependency[0].Point3D.GpPnt;
var secondPoint = Dependency[1].Point3D.GpPnt;
if (firstPoint.IsEqual(secondPoint, OCPrecision.Confusion()))
return false;

var aEdge = new OCBRepBuilderAPI_MakeEdge(firstPoint, secondPoint).Edge();
var wire = new OCBRepBuilderAPI_MakeWire(aEdge).Wire();
Shape = wire;

return true;
}
And is registered by creating a class in the SimpleLinePlugin class library the class named: FunctionRegister and you should write the following:
public class FunctionRegister : PluginFunctionBase
{
public void Register()
{
FunctionFactory.Register<SimpleLine>();
}
}

Doing so, your Lua code will work as is.
A note: to make your plugin work, you should have as reference the PluginInterface.dll to your plugin to have acess to PluginFunctionBase type. Also the FunctionRegister class is hardcoded, so you will have to name it just as this to make your registering work.
So for now, excluding that you want to dramatically change the UI (mostly the Ribbon tabs), you can change almost all functionality of NaroCAD by registering from Lua a new plugin that can come with it's shapes, Lua commands, etc. I think that someone will use it and will add new things to NaroCAD.

Friday, June 25, 2010

Working on WPF Option Dialog (part II)

Cristian did a wonderful job an makes completely new WPF dialogs for Options dialogs. They match as look and feel with the Windows Forms dialogs. With this contribution is the next step to port to WPF the options dialog. Some events still need some wiring, but the WPF layout work is really done. Great job Cristian!

Wednesday, June 23, 2010

Easier Transform Editing

As the porting to WPF will continue but the priority is not that big to finish it right away, as the Options dialog works correct and probably will not be finished this iteration (and maybe yes), but another feature was really important. This feature is just simple as this: when you select a shape and you drag it, it will move in the plane this shape is drawn on.
As the code is made to make selection after the click is done (also is great to not make accidental moving).

Tuesday, June 22, 2010

Working on WPF Option Dialog

When NaroCAD started was based on Windows Forms and used only C# 2.0 features. As we picked VS 2008, we switched to use Windows Presentation Foundation (WPF) by using Ribbon interface, we did had experience have still some dialogs that are Windows.Forms. The advantage of using WPF instead WF is that a designer can assign styles to pages when on WF you cannot. The porting will have to workaround some different behaviors that are different and I will not expect in the next iteration to be done, but the implementation will be done in parallel and most likely will be compatible. I did not find for example the WF's LinkLabel control in WPF implemented as default control but I will look more for that. This control is used for making you to get easier access to help parts or to different links from help. Also the "automatically apply" behavior need to be implemented with different events I'm still not used at. So for now the controls will likely start separately and the default will still be the WF one until the code will stabilize and will give a similar behavior.

Thursday, June 17, 2010

NaroCAD 1.4.6 Released

NaroCAD makes another step forward. This release empathizes with user by improving parts that were annoying or not enough powerful on the transformations and with constraints. This work was focused on main user visible features:
- transformations are much improved. With this rewriting of them, combined transforms work correctly.
- you can delete shapes using Shift+Delete
- constrains are getting the love that make you likely to use them
- bug fixing of was directed to make this things to work right, the new transformations will work shapes-wide, the property grid gets also a more consistent behavior.

This release was made only two weeks from the previous one (we mostly tend to make a 3 weeks release) so this release is not that impressive in counting features, but was worked a lot on usage and the way that NaroCAD should behave.

So enjoy using this new version! Download it from here.

Monday, June 14, 2010

Constraining Bugs

Adding features in most cases change some internal parts of the code and make some things to break. The most disruptive changes in the previous week were using the generic transformations code that is more powerful and the constraint dialog. They in themselves are not made in a faulty way, but the old code did not used the new behaviors or the changes were not fully covering all shapes.

Today I've worked to target some of those bugs like following:

-point to point constraint is fixed (as was done by transforming the original shape).

-the Constraint Shape dialog when you closed it, it make to revert the action to default mode, but that make that code to execute twice and did lead to a crash if it was closed by clicking on the scene and pressing escape.

- ellipse shape did not have a constraint for major radius and minor one. On the same way, the Cone did have a minor radius that could not be setup as zero. as the fixed value constraints did share a lot of common code, the zero value for most of them is not a valid one (like picking a line length as being zero, or a circle range as zero). Right now you will use more successfully this dialog on all shapes and with all possible values.

- also it may happen in some cases that the MetaAction shape creation to be executed from multiple components (like activating via command line). To guard the code against those cases, there is done a Document.Transact operation stopping creating invalid shapes in scene document in meta-actions. 

- if  you will move your focus from one item to another in property grid, the settings will apply automatically. This is made for user to not forget to setup the value by pressing enter. Pressing enter is still available in case you want to check your value if works accordingly.

- lua unit tests have some invalid values and also were fixed.

A note: previously broken end of edge constraints or middle of edge constraints (that activate when you work with shapes), as of today they both seem working.

Friday, June 11, 2010

Constraint To Shape and Just This

Do you remember this? It was an effort to simplify selection of the simple constraints to user and to avoid the mistakes that user may do (like applying a Circle Radius constraint on a Line or a Sphere shape). Also did offered the option that if you that if you have the same constraint previously defined, to be reused when you setup the value.

Do you remember this one too? It was made to make possible to work reasonable with constraints by facilitating the removal if needed.

This also mean to you just 14 buttons on the toolbar of constraints (they are only 10, because some are sliding buttons so you may pick other grouped constraints). Can be reduced all under just one button and to remain easy to use?

This is what I've got to show: you pick the "Shape Constraint" from Constraint toolbar and you select the constraint. If the shape is known to accept constraint, the shape constraint list is shown. When you click a constraint you may pick the value for it and press apply (or just hit enter key). After you applied it, you may just click to other shape and edit it's constraints too. At the end you close the dialog and all shape constraints are applied all at once. The selection may be done either from scene and from tree of objects. 

What will mean for you? Just that constraints make sense in the idea that are really the ones you need, when you need them and you don't have to click around to apply some constraints. This dialog have a lot of fit and finish. When is unfocused, it is shown semitransparent. This unfocused may be that your selected shape have no possible constraints or you just misclick on an empty area.

Transformations fixing close to end

Merged and pushed into devel repository all latest fixes from transformations and also the new transforms code. Composite transformations on shapes like translates, rotates, scales applied from property grid seem to work correctly. Transformed shapes are properly identified on scene by the selected shape detection code. Extrude on auto generated faces (like a triangle made from lines) works well.
Remained to fix the Dimension tool, the only tool that remained broken by the transformation fixes.

Thursday, June 10, 2010

Changed How Transforms Work

I've added some experimental code that will handle in a better way the composed transforms. If all issues will be fixed, it will mean unlimited transforms and new constraints based on transformations that previously were not possible. This code basically remove the internal stored values for rotate, scale and translate, and only expose the transformation matrix and the pivot. Before any scale or rotate operation, the pivot will center the shape before applying the operations.

Transformations bug fixing

Currently in Naro we are using two coordinate systems: the shapes are generated in the origin of a local coordinate system and drawn on scene on a global coordinate system by applying a transformation on the shape.
Currently we're working at fixing this way of working, not only improving bugs but also improving user access to coordinates: the user works with global coordinates without knowing details about the internal representation of shape in local coordinates.
We finalized fixing shape generation, there are still details to improve in the property grid tabs and automatic generation of constraints.

Tuesday, June 8, 2010

Do you know that... !?

Pressing Shift key in many instances gives to you extra options in NaroCAD!? For example using it in editing points that appear when you select any common shape, it will appear a dialog for exact positioning.

Based on this idea, I've made a Shift and Delete keys will make to appear a dialog that will show all shapes/entities and you can delete them by double click them.

The reason of creating this dialog is that some entities are logical, are defined as not selectable by NaroCAD (elsewhere will only annoy you by selecting without you wanting that) or some are hard to select.

Monday, June 7, 2010

Constraints Ribbon Tab Cleanup and Point to Point Improvements

Constraints tab was a bit messy, it contains 10 icons for 3D shapes constraint and another 5 for the 2D ones. Right now they are more compact and are using just 10 icons to display the tools. Also are more logical in the sense that they are grouped by shape.

Other improvement was the Point to Point constraint. When you worked to Point To Point constraint you have to pick the two points that you want to constraint, and you will have in property grid the distance between those points you've selected and you can change it. Anyway, if you selected by mistake twice the same point, the constraint will not apply or you may not notice that the tree was changed previously. For this reason, there is a nice addition that it will be shown a dimension arrow to let you know that the constraint is well defined by user actions. Also the action was extended in case you picked two points from the same shape. If you pick two points from different shape, the propagation will move the destination shape to be separated on the distance you've just setup. On a similar way, Point to Point constraint, on the same shape will scale your current shape to keep strict the distance you did chose.

In this way for example when you will edit your rectangle's width, to keep the distance just as needed, the rectangle will scale accordingly, letting your original width as chosen, so there are cases when does not behave just as you expect. If you want a really fixed width, you have to pick the Rectangle's width constraint, not Point to Point one, which is much more generic.

Friday, June 4, 2010

NaroCAD 1.4.5 Released

NaroCAD 1.4.5 is released. It builds on top of 1.4.4 release and adds improvements on how you work building your shapes and many small changes are in place to make you feel more like at home. If earlier you may miss a property or two in the property grid by either is a bug or a missing, right now all are there. You also have the poly-line tool that is made from multiple lines. A locking point to point constraint is also handy. Another area that got an overhaul is the capability that command line can be used in more contexts, meaning that some constraints that previously were not possible to edit excluding just from property grid, they are right now there. Also a great overhaul is on solver. Creating extrudes with same height are not an issue right now, but this is not the only change, you will likely remark that a lot of the magic points really appear where you expect them.
Those are only the user seen released. The code did get cleanup, so if you just want to see a clean C#/.NET codebase, is a good place to start, is working better with transformations, and not only.
So why don't you just try it? Download it from here.

Thursday, June 3, 2010

Some Final Touches Before Release

Today was a bug fix day. You will find a lot of small annoyances fixed.
First of all all constraints like rectangle width one are right now working just on rectangle. Also all strings to property grid seem to be fixed regarding constraints.
Also it was possible to crash Naro if you launched the Zoom Window tool as some incompatible types were used internally.
When you change the name of shape, the tree view updates accordingly
Deleting a line will not make Naro crash.
Just if you wanna see how the release 1.4.5 will be, you can try the nightly build (the link is on the right side). Hopefully you will find a good constraint support and fewer crashes.

Bug fixing

Started preparing for release.
Reviewed the bugs reported until now, closed fixed bugs. 49 more bugs remained to be fixed from which 10 with higher priority.
Reviewed and finalized the polyline tool so that it automatically generates faces if a closed shape is drawn, also registered the polyline on solver so that magic points are detected on it.
Started investigating on the extrude on an automatic generated face that currently doesn't work. The problem might be related to transforms, the IsSame method doesn't return true when a shape from scene is compared with the shape from data tree because the one from scene has a transformation applied on it.

Wednesday, June 2, 2010

One Real Value Based Constraints...

There was a bug that if you apply two constraints of the same type (like: Circle Range with value 30 and Circle Range with value 50) NaroCAD will block. As this iteration did add ability for actions to use Command Line and because MetaActions were not powerful enough to handle those cases, a nice addition was to make this constraint to work as an action but to behave as a meta-action (namely to use the command line). As I've did this work, I found that the code that do this, can behave in this way: if you try to apply a Circle range, and you don't click on a circle, you will be notified. If your circle have already a constraint, you will be notified about this, but let you to introduce a new value.
The work being done, and separating the shape it work on (circle here) to the constraint (circle's range), the same code can be applied to a lot more shapes (namely: box's height, cone's height, cone's base radius, cone's top radius, cylinder radius, cylinder height, cylinder radius, sphere radius, torus major radius, torus minor radius) with minimal code. The most of code was just about setting up the events and writing it's strings and co.
As there are still some other actions that are not one value (mainly the rectangle width/height and line length) I will do tomorrow actions for them. Also I will fix the wrong strings or other problems that may appear to those actions.
So hopefully you will enjoy using this new extended palette of constraints.

Tuesday, June 1, 2010

Solver cleanup finished

Finalized the solver cleanup.
Currently while drawing, edges are detected, edge continuations are detected. Fixed the end point magic point detection.