-
Notifications
You must be signed in to change notification settings - Fork 3
1_Program_Flow
Initially, the g_painter
and g_schematic_controller
or g_board_controller
are setup
and initialized with the canvas element. Callbacks are set up to intercept user input.
the loop
function (in init_sch.js
and init_brd.js
) is setup as a callback to call
the redraw
function for the controller.
function loop() {
...
g_board_controller.redraw();
requestAnimationFrame( loop );
}
The controller sets up the various GUI elements in its init
function
bleepsixBoardController.prototype.init = function( canvas_id )
{
this.canvas = $("#" + canvas_id)[0];
this.context = this.canvas.getContext('2d');
...
this.guiToolbox = new guiBoardToolbox( "toolbox" );
this.guiToolbox.move( 0, 200);
this.guiLayer = new guiBoardLayer( "layer" );
this.guiLayer.move( 0, 450 );
...
and sets up the various callbacks:
...
$(canvas_id).mousemove( function(e) {
var xy = controller.canvas_coords_from_global( e.pageX, e.pageY );
controller.mouseMove( xy[0], xy[1] );
});
...
}
From the constructor, toolNav
or toolBoardNav
for the schematic or board respectively is the
default tool that's set.
function bleepsixBoardController( viewMode ) {
...
if (!brdControllerHeadless)
{
this.tool = new toolBoardNav ( undefined, undefined, this.viewMode );
this.tabCommunication = new bleepsixTabCommunication();
}
...
}
Where the brdControllerHeadless
allows for the nodejs server to run the same code without alteration.
Each tool is responsible for handing control off to another tool. Often times mouse information needs to be passed in.
If the tool exposes a function (or is it required to?) called drawOverlay
, this will be called by
the controller when redrawing the scene. This allows for tools to draw while active.
Many tools show the cursor position by setting the display_text
value in the global controller object.
toolBoardNav.prototype.drawOverlay = function()
{
if ( !this.mouse_drag_flag )
{
this.snap_world_xy = g_snapgrid.snapGrid( this.mouse_world_xy );
var s = this.cursorSize / 2;
g_painter.drawRectangle( this.snap_world_xy["x"] - s,
this.snap_world_xy["y"] - s,
this.cursorSize ,
this.cursorSize ,
this.cursorWidth ,
"rgb(128, 128, 128 )" );
g_board_controller.display_text = "x: " + this.snap_world_xy.x + ", y: " + this.snap_world_xy.y;
}
}
All state changes to the underlying kicad
object (e.g. g_board_controller.board.kicad_brd_json
) must be
done through the controllers opCommand
function. This allows for undo/redo functionality, as the
controller saves state (but only on a session by session basis) and is in charge of communicating
state back to the central server.
Here is an example from bleepsix/js/brdtool/toolBoardNavjs
:
...
var op = { source: "brd", destination: "brd" };
op.action = "update";
op.type = "flip";
op.id = id_ref_ar[ind].id;
op.data = { sourceLayer : src_layer, destinationLayer: dst_layer};
op.groupId = group_id;
g_board_controller.opCommand( op );
...
When changing state, it is the tools responsibility right now to update relevant auxiliary state, like the rats nest, highlighted nets, etc.
...
var map = g_board_controller.board.kicad_brd_json.brd_to_sch_net_map;
g_board_controller.board.updateRatsNest( undefined, undefined, map );
...
g_board_controller.board.getBoardNetCodesAndSubPads( netcode, undefined, hi_netcodes, sub_pad_ids );
g_board_controller.board.highlightNetCodesSubPads( hi_netcodes, sub_pad_ids );
g_board_controller.highlightSchematicNetsFromBoard( netcode );
...