Wednesday, December 23, 2009

Modifiers new infrastructure

Do you remember NewShapeModifier? NaroCAD's View framework is created around Modifiers (also named Actions) like: View Actions (Top, Left, Reset), Shape(circle, rectangle), Tools (Extrude, Cut, Boolean operations). NewShapeModifier was an action which starting from a specific function, creates an already made action. But because it tried to solve too many problems in a generic way, the code always was need some patching and was hard to use. The big advantage was also that it starts from the shape's definition (like a line will require two points, so the action will query first point, second point, and that's all).
Some of it's ideas were really nice, but they could not work nice as it was either: too generic or either too specific. Also, in the quest of solving a command line completion, the actions have no exposed granularity to be used interleaved command line values and mouse clicks.
For now there is an action that can be started with Control+Space and can be used just to test this actions.
Those actions are named for now MetaActions (I did not found another proper name).
Which are the big differences from the NewShapeModifer (NSM)?
- NSM creates a build action only from function names and are fixed. MetaActions (MA) are getting a dependency object to be filled in by action. If the action will want to use the function's name, it can do it right away. But after this it can customize the dependency like it can remove some unused steps.
-NSM do not let customize the draw step, intermediary solve of dependencies. MA let you change dependencies (remove/add if you want), setup some values as defaults, let you customize even the final shape that is drawn. MA also uses the previous document refactorings, so it will be a smaller chance to remain artifacts by persons that draw custom code.
- NSM because was a monolith that cannot be changed, some operations like: AutoFace (when lines create a profile, a face is generated), CalculateIntersections (compute local areas on face shapes), could not be customized to not be computed when do not make sense (like: a sphere do not expose any face so why to calculate intersections on the same plane). AutoReset: if true will mean that action will continue to draw the same shape that was doing initially. (like when you draw a sphere, to continue to draw spheres with the subsequent clicks). Right now those are properties can be setup right away.

The code is subject of change but the code gets really better and is as follows:

public class LineMetaAction: MetaActionBase
public override void FillUiDependencies (MetaActionDependencies dependency)
dependency.FunctionName = FunctionNames.Line;
dependency.CalculateIntersections = true;
dependency.AutoFace = true;
dependency.AutoReset = true;
To define a custom field you can do it like this:
class BooleanFuseMetaAction: MetaActionBase
public override void FillUiDependencies(MetaActionDependencies dependency)
dependency.FunctionName = FunctionNames.Boolean;
dependency.Steps[2].Integer = 0;
dependency.Steps[2].IsDefaultValue = true;
dependency.AutoReset = true;

The code is reduced for those shapes by 5-6 times also, because the modifiers' code is not exposed to those actions.

The following shapes work right now: all that are dependent of Point3D, Axis3D, Real (which can be computed as a distance of the last clicked point and the current click point). For now do not work Reference shapes and custom cases of Reference shapes (like Extrude) which should froze the plane.
I will try to continue porting and find issues of porting code of the actions to become metaactions, and at the end if there are no big issues, will wrap the steps to a command line interface.

No comments: