I'm trying to redevelop from scratch a tool I had working (more or less), but in which the coding had got too tangled to take much further.
It is based very heavily on the sample CLineTool by Jim Foltz. I've appended my working copy of this, since I can't find a definitive newer version either in the Extension Warehouse or the Plugin Store on this site.
I want to start again to build the tool from scratch, this time trying to understand how the whole Tool class works, whereas last time I just fiddled with the existing code to adapt it, without really understanding quite a bit of how it works.
I've put together a 'skeleton' ruby module and class, called DrawFraming, which I will eventually use to draw wood/timber framing in standard UK softwood sizes. In its former mostly working version, it allows me to
- choose a standard cross-section of wood (by R-click from a menu), or define a custom size
- place one corner in the drawing by mouse click at first pick point
- choose what is to become the component's long axis, either normal to the face at the pick point, or using an arrow cursor key to toggle X, Y, or Z_axis lock on or off
- orient the cross section by mouse movement around the first pick point, drawing the outline as feedback
A second mouse click then creates the geometry for the cross-section in the chosen location, and then switches to the built-in PushPull Tool to pull it to the desired length, by inferencing or VCB input.
I had most of that working, but decided I wanted it to be cleaner code, and also want to understand how to get working properly some features that I couldn't get to work quite the way I want - like suspend and resume the DrawFraming tool during Zoom operations, for example, or resume DrawFraming after the PushPull tool finishes.
But I'm stuck at a couple of rather basic things which don't error, but don't work either, though as far as I can see they copy the relevant parts of Jim's code.
I attach the current draft skeleton. I've only implemented parts of initialize, activate, reset, onMouseMove, onSetCursorand onLButtonDown. The other Tool methods are just stubs.
I've got the tool to set the cursor image, but can't get it to display text at the cursor, nor to inference or display tooltips when hovering over existing drawing elements.
In lines 94-98, the code
# set the tooltip that should be displayed to this point
view.tooltip = @ip1.tooltip
...
# Display cursor text to give feedback at cursor
view.draw_text view.screen_coords(@ip1), "Test0"
does nothing.
In my older more complete version it DID work, and it does in the CLineTool too, but not here.
I'd like to understand why. Perhaps I haven't initialized something properly? Missed a few lines of the clinetool_main.rb code that matters?
Any clues would be most welcome.
Another small point puzzles me. The onSetCursor method where my cursor is displayed seems to get called on every mouse move. I tried putting
UI.set_cursor @cursor_id
in the activatemethod, but it does nothing there. Is this just the way it has to work? The Ruby API shows this code as an example, and it works, but it seems unnecessary to call it so often when I only have one cursor.
jwm_draw_framing.rbz
clinetool.rbz