ansimionescu

Architecture: operators

Jun 14th, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. *** Overview
  2. Operators (wmOperatorType*) manage tools, so by defining a new wmOperatorType you create a new tool. Check out [1] for more info (and conventions) and [2] for a tutorial/more details.
  3. * Example 1: http://pastebin.com/uMfBNvZj
  4. * Example 2: http://pastebin.com/XUutURAc
  5.  
  6. *** Members
  7. * name
  8. e.g. ot->name = "(De)select All"
  9.  
  10. Human readable name for the UI. Capitalized.
  11.  
  12. * idname
  13. e.g. ot->idname = "MESH_OT_select_all"
  14.  
  15. It's an unique identifier; set it identical to the method name
  16. Format: <PREFIX>_OT_<action>_<details> (e.g. MESH_OT_select_all)
  17.  
  18. * description
  19. e.g. ot->description = "(De)select all vertices, edges or faces";
  20.  
  21. * srna
  22. e.g. PropertyRNA *prop = RNA_def_int(ot->srna, ...)
  23.  
  24. Operators can define a number of RNA properties (see [0]->N1).
  25. These can be set by the user and used by the operator to modify its behaviour.
  26.  
  27. * exec, invoke, modal, cancel
  28. e.g. ot->exec = edbm_select_all_exec
  29.  
  30. Every operator must define either exec or invoke.
  31. exec: Provided to run the operator without user interaction.
  32. Only if this is provided can the ot be recorded for a macro.
  33. invoke: Will execute after an event (e.g. getting mouse coordinates).
  34. modal: From the invoke callback, the ot can add itself as a handler,
  35. and receive further events in the modal callback.
  36. cancel: If the ot is cancelled (e.g. program quitting), this callback is called.
  37.  
  38. Return for exec, invoke and cancel:
  39. pass through: Means the operator passes on the event to other operators,
  40. as if the callback did not run.
  41. running modal: Indicates that the ot is still running and has registered
  42. itself to receive modal callbacks.
  43. cancelled, finished: Mean the execution of the ot has ended, successfully or not.
  44. The operator will be registered only for 'finished'.
  45.  
  46. * poll
  47. e.g. ot->poll= ED_operator_editmesh
  48.  
  49. Used to verify the ot can be executed in the current context. It's often shared for multiple operators. It's always called before executing the ot, so it may be used to gray out or hide UI elements that use this ot automatically.
  50.  
  51. *** Caveats:
  52. * Note the distinction between RNA properties and customdata. The properties should only store public parameters as seen by the user, these are saved as part of macro's and written to file. The customdata is an arbitrary pointer, typically to a C struct, that should only exist while the operator is running, an so it is not written to file.
  53.  
  54. * The invoke callback also takes properties as inputs and should take those into account. For example a transform operator might have a mode=rotate input, and should then start in rotation mode.
  55.  
  56. Home:
  57. [0] http://wiki.blender.org/index.php/User:Ansimionescu
  58. Reference:
  59. [1] http://wiki.blender.org/index.php/Dev:2.5/Source/Architecture/Operators
  60. [2] http://wiki.blender.org/index.php/Dev:2.5/Source/Architecture/Operators/Tutorial
Advertisement
Add Comment
Please, Sign In to add comment