CanvasObject is used as an intelligent container for other robotic simulation objects. In itself, it does nothing.
CanvasObject.tcl can be used anywhere a group of managable objects will be graphically instanciated. A prime example of this is an array of LEDs.
|
An empty Canvas isn't much. All it shows is the title. |
There are several proc[edures] in CanvasObject.tcl. We are interested in three of them.
proc new { {CanvasObject} {NameOfCanv} {canvcolor}
{textcolor} {title} } \
{
  # CanvasObject = Unique name for the canvas object.
  # NameOfCanv = Graphical name of object.
  # canvcolor = Color of the background.
  # textcolor = Color of the title.
  # title = Text that shows in the canvas.
The parameters CanvasName and NameOnCanv are constants.
proc IncludeObject { {CanvasObject} {objecthandler} {objectname} } \
{
  # CanvasObject = Name for this canvas object.
  # objecthandler = Method for updating $objectname.
  # objectname = name of object to update.
Once you have created a CanvasObject using ::Canvas::new, you can hand it objects to manage. That is done with ::Canvas::IncludeObject. Objecthandler is a statement that will update the object. Usually it is little more than "ThisThing_update MyObject".
  # Update all objects that have been registered for CanvasObject.
proc UpdateAll { {CanvasObject} } \
{
  # CanvasObject = Name for this canvas object.
When ::Canvas::UpdateAll is called, it calls each of the objecthandlers for the objects it has been asked to manage.
First we declare a CanvasObject using ::Canvas::new.
set canvasname [::Canvas::new led .oper_interf.left \
{#7f6f7f} {#000000} {Led Monitor}]
We can now declare one or more objects to be managed by it.
set labelname [::Canvas::IncludeObject led ::Led::update green0But]
::Led::new green0But $labelname {$::LED_byte1 & 0x01} 7 3 "#00ff00" "#006000"
pack $labelname -side top
The object to managed is green0But. It's objecthandler is ::Led::update.
::Canvas::UpdateAll led
When ::Canvas::UpdateAll is called for this canvas object (here named led), it will call each objecthandler for each object. In this example there is only one object. So a single call is made:
::Led::update green0But
The important functionality of CanvasObject is duplicated in the tk primitive "canvas" and in NotifyObject. If I had written Notify first I probably would never have written CanvasObject. Eventually I may eliminate CanvasObject in favor of NotifyObject.