Monday, June 28, 2010
UI Extensibility
Sunday, June 27, 2010
Plugin Sample and MetaAction Code Separation
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)
Wednesday, June 23, 2010
Easier Transform Editing
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
Thursday, June 17, 2010
NaroCAD 1.4.6 Released
- 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 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
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 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... !?
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
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
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
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...
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.