summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/blueprint/BlueprintToolbar.js
blob: 77212981066d4c7098bb04b7d702e60f68651ecf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
var BlueprintToolbar = View.extend({

  el: "#blueprintToolbar",

  events: {
    "click [data-role=upload-floorplan]": 'showUploader',
    "click [data-role=toggle-orbit-mode]": 'toggleOrbitMode',
    "click [data-role=arrow-mode]": 'arrowMode',
    "click [data-role=polyline-mode]": 'polylineMode',
    "click [data-role=ortho-polyline-mode]": 'orthoPolylineMode',
    "click [data-role=eraser-mode]": 'eraserMode',
    "click [data-role=start-position-mode]": 'startPositionMode',
    "click [data-role=toggle-layout-settings]": 'toggleSettings',
  },

  initialize: function(opt){
    this.parent = opt.parent
    
    this.$modes = this.$('.mode')
    this.$toggleOrbitMode = this.$('[data-role=toggle-orbit-mode]')
    this.$arrowMode = this.$('[data-role=arrow-mode]')
    this.$polylineMode = this.$('[data-role=polyline-mode]')
    this.$orthoPolylineMode = this.$('[data-role=ortho-polyline-mode]')
    this.$eraserMode = this.$('[data-role=eraser-mode]')
    this.$startPositionMode = this.$('[data-role=start-position-mode]')
    
    this.orthoPolylineMode()
  },
  
  showUploader: function(){
    this.parent.scaler.show()
    this.parent.uploader.show()
  },
  
  toggleOrbitMode: function(state){
    this.parent.orbiting = typeof state == "boolean" ? state : ! this.parent.orbiting
    this.$toggleOrbitMode.toggleClass("inuse", ! this.parent.orbiting)
    this.parent.editor.resize()
    if (this.parent.orbiting) {
      controls.toggle(true)
      movements.lock()
    }
    else {
      controls.toggle(false)
      movements.unlock()
      movements.gravity(true)
      cam.rotationX = 0
      cam.rotationY = -cam.rotationY
      cam.x = this.parent.startPosition.x
      cam.y = viewHeight
      cam.z = this.parent.startPosition.z
    }
  },
  
  toggleSettings: function(){
    this.parent.settings.toggle()
    this.parent.notice.toggle( ! this.parent.data.isNew && ! this.parent.settings.visible() )
  },
  
  setActiveMode: function( $el ) {
    this.$modes.removeClass('active')
    $el.addClass('active')
  },
  
  arrowMode: function(){
    this.setActiveMode( this.$arrowMode )
    this.parent.map.ui.set_tool("arrow")
  },
  
  polylineMode: function(){
    this.setActiveMode( this.$polylineMode )
    this.parent.map.ui.set_tool("polyline")
  },
  
  orthoPolylineMode: function(){
    this.setActiveMode( this.$orthoPolylineMode )
    this.parent.map.ui.set_tool("ortho-polyline")
  },
  
  eraserMode: function(){
    this.setActiveMode( this.$eraserMode )
    this.parent.map.ui.set_tool("eraser")
  },

  startPositionMode: function(){
    this.setActiveMode( this.$startPositionMode )
    this.parent.map.ui.set_tool("start-position")
    this.parent.settings.hide()
    this.parent.notice.showStartPositionNotice()
  },
  
})