The actions in 3D have a non uniform input code. This makes it really hard both to extend and to make things working in an environment like: multi-click because the click may have a completely different meaning. Also, some actions in 3D do not need a click at all: like (Top will setup the view to make things appear in top).
For that reason there was a need to be able to define different non uniform inputs to the actions to work with, that remains simple enough for the user. The multiple inputs have some limitations, like the most similar ones to share a very similar code. The most common case is the mouse click on a view: the simple click may mean many things: this click may have more meanings like:
- the point projected to a 3D plane, or even more, to be aligned to all closed geometry (so it should pass through a solver) when you draw a 2D shape like a line;
- may look for the object which is under the mouse, or to extract the plane for it
For that reason, there is a pressing need for combining the inputs (to not duplicate code is another reason).At the end of the consuming of events stand the actions, which say which inputs and pipes are needed.
So, as a rough scheme: Input -> Optionally pipe -> Optionally pipe -> Action3D
Here is the code for a pretty complex action:
public class Line3D : Action3d
{
Mouse3dEventsPipe mouseIn;
ViewInput viewIn;
DocumentInput doc;
public Line3D()
: base("Line3D", new List() { "View", "Mouse3dPosition", "Document" })
{
}
protected override void OnSetup()
{
viewIn = Inputs["View"] as ViewInput;
mouseIn = Inputs["Mouse3dPosition"] as Mouse3dEventsPipe;
mouseIn.HasDataNotify += OnRecievedData;
doc = Inputs["Document"] as DocumentInput;
}
public override void Deactivate()
{
base.Deactivate();
mouseIn.HasDataNotify -= OnRecievedData;
}
List points = new List();
void OnRecievedData(Object data)
{
(...)
So from scratch this action can change only the View, Mouse3dPosition and Document.
Also, in the past was not done, but right now it is, the actions have a deactivate code, this will prevent actions from remaining in an uncertain state at any moment, no matter is canceled or so. This avoids a lot of cases of leaks.
Also, the deactivate cleans automatically all links and break the graph of Inputs and Pipes, it makes the Inputs ready for the next action.
Was it worth doing?
Both in short and long terms it was: it is possible almost to not a single code to create a brand new action without a copy, it is possible to give a (new) meaning to mouse click, the code is safer (as there is a Deactivate method) and also less prone to errors (as it works with less components that need to be saved).
Based on the last two weeks refactor, it enables NaroCAD to work with a new infrastructure, it is of a much higher level than the previous code, it is better detached, it propagates automatically the events, it is debuggable. The actions don't do copy-paste both in 2D and in 3D to achieve a multi-click action.
Anyway, the single action in 3D that works with multiclick is Line for now. I will continue to work for the others. Also, I would like to add the possibility that if mouse stands on a face for more than 3 seconds, to be selected as the face to be drawn.
As there are many refactored parts, I will try also to write documentation to this so if you feel courageous a bit and you like C#, and you want to look a bit at OpenCascade, it will be a great start to extend the NaroCAD code. It will let you to use NaroCAD as the base software and extend it where you need it.
What is the achievement over the last three weeks of refactor?
Note: NaroCAD also has a debug window (in case you did not know it) that makes almost instant navigation to the scene tree.
No comments:
Post a Comment