PageRenderTime 18ms CodeModel.GetById 12ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/R/iMode-class.R

http://github.com/tengfei/visnab
R | 104 lines | 73 code | 11 blank | 20 comment | 0 complexity | 455335de171055ea645180e19d836542 MD5 | raw file
  1## ======================================================================
  2## Enum used in iMode class
  3## ======================================================================
  4setSingleEnum("TooltipMode", levels = c("Off", "Identify", "Metainfo","Text",
  5                               "Position"))
  6setSingleEnum("TooltipPos", levels = c("TopLeft", "TopRight",
  7                                       "BottomLeft", "BottomRight",
  8                                       "Float"))
  9setSingleEnum("BrushMode", levels = c("Transient", "Persistent", "Off"))
 10setSingleEnum("PointBrushMode", levels = c("Off", "ColorAndGlyph",
 11                                  "ColorOnly", "GlyphOnly",
 12                                  "Shadow", "Unshadow"))
 13setSingleEnum("EdgeBrushMode", levels = c("Off", "ColorAndLine",
 14                                 "ColorOnly", "LineOnly", "Shadow", "Unshadow"))
 15setSingleEnum("DragMode",  levels = c("NoDrag", "ScrollHandDrag", "RubberBandDrag"))
 16setGeneric("getQtEnum", function(x,...) standardGeneric("getQtEnum"))
 17setMethod("getQtEnum", "DragModeSingleEnum", function(x){
 18  val <- switch(x,
 19                NoDrag = Qt$QGraphicsView$NoDrag,
 20                ScrollHandDrag = Qt$QGraphicsView$ScrollHandDrag,
 21                RubberBandDrag = Qt$QGraphicsView$RubberBandDrag)
 22})
 23
 24setSingleEnum("ZoomMode", levels = c("Vertical", "Horizontal", "Both", "Off"))
 25
 26## ======================================================================
 27## iMode class
 28## ======================================================================
 29setClass("iMode", contains = "VIRTUAL")
 30setMode <- function(name, modes,
 31                    contains = character(),
 32                    where = topenv(parent.frame())){
 33  nm <- paste(name, "Mode", sep = "")
 34  pars <- setParameters(nm, modes)
 35  parsName <- paste(nm, "Parameters", sep = "")
 36  setRefClass(nm, fields = list(pars = parsName),
 37              contains = c("iMode", "Item", contains),
 38              where = where,
 39              methods = list(
 40                initialize = function(t = as.character(class(.self)), ...){
 41                  .self$text <<- t 
 42                  callSuper(...)
 43                }))
 44}
 45
 46ScaleMode.gen <- setMode("Scale",
 47                          list(dragMode = "DragModeSingleEnum",
 48                               zoomMode = "ZoomModeSingleEnum"))
 49## ScaleMode.gen$methods(setScaleMode =
 50##                       function(md = c("dragMode", "zoomMode"), value){
 51##   .self$pars$field(md, value)
 52## })
 53ScaleMode <- function(dragMode = "ScrollHandDrag",
 54                      zoomMode = "Vertical",
 55                      ...){
 56  pars <- new("ScaleModeParameters", dragMode = dragMode, zoomMode = zoomMode)
 57  obj <- ScaleMode.gen$new(pars = pars, ...)
 58}
 59
 60
 61
 62BrushMode.gen <- setMode("Brush",
 63                          list(brushMode = "BrushModeSingleEnum",
 64                               pointBrushMode = "PointBrushModeSingleEnum",
 65                               edgeBrushMode = "EdgeBrushModeSingleEnum"))
 66
 67## BrushMode.gen$methods(setBrushMode =
 68##                       function(md = c("brushMode", "pointBrushMode", "edgeBrushMode"),
 69##                                value){
 70##   .self$pars$field(md, value)
 71## })
 72
 73BrushMode <- function(brushMode = "Off",
 74                      pointBrushMode = "Off",
 75                      edgeBrushMode = "Off",
 76                      ...){
 77  pars <- new("BrushModeParameters", brushMode = brushMode,
 78              pointBrushMode = pointBrushMode,
 79              edgeBrushMode = edgeBrushMode)
 80  obj <- BrushMode.gen$new(pars = pars, ...)
 81}
 82
 83setSingleEnum("Logical", levels = c("TRUE", "FALSE"))
 84IdentifyMode.gen <- setMode("Identify",
 85                            list(tooltipMode = "TooltipModeSingleEnum",
 86                                 tooltipPos = "TooltipPosSingleEnum",
 87                                 hoverMode = "LogicalSingleEnum"))
 88## IdentifyMode.gen$methods(setIdentifyMode =
 89##                       function(md = c("tooltipMode", "tooltipPos", "hoverMode"),
 90##                                value){
 91##   .self$pars$field(md, value)
 92## })
 93
 94IdentifyMode <- function(tooltipMode = "Off",
 95                         tooltipPos = "Float",
 96                         hoverMode = "FALSE",
 97                         ...){
 98  pars <- new("IdentifyModeParameters",
 99              tooltipMode = tooltipMode,
100              tooltipPos = tooltipPos,
101              hoverMode = hoverMode)
102  obj <- IdentifyMode.gen$new(pars = pars, ...)
103}
104