Class: Nebula::WebClient::Setting

Inherits:
Object
  • Object
show all
Defined in:
lib/nebula/webclient/setting.rb

Overview

The configuration of the Nebula Viewer, including its scale, the border and some other advanced configurations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Setting

Returns a new instance of Setting.

Parameters:

  • args (Hash) (defaults to: {})
    • :width => [String] or [Fixnum] Width of the viewer.

    • :height => [String] or [Fixnum] Height of the viewer.

    • :border => [Border] Border setting of the viewer.

    • :menu_docking => [Symbol] Docking position of the main menu, one of :bottom, :right.

    • :render_mode => [Symbol] Default rendering mode of the viewer, one of :realistic, :fantastic, :technical.

      realistic:  Realistic rendering mode, with global shadow and lights.
      fanstastic: Fantastic rendering mode, with realistic shadows and multiple texture-mapping.
      technical:  Technical rendering mode, with triangles in different colors.
      
    • :language => Language package to be loaded, one of :english, :french, :simplified_chinese, :traditional_chinese, :japanese.



66
67
68
69
70
71
72
73
# File 'lib/nebula/webclient/setting.rb', line 66

def initialize(args = {})
  @width = args[:width] || 640
  @height = args[:height] || 480
  @border = args[:border] || Border.new
  @menu_docking = args[:menu_docking] || :bottom
  @render_mode = args[:render_mode] || :realistic
  @language = args[:language] || :english
end

Instance Attribute Details

#borderObject

Returns the value of attribute border.



108
109
110
# File 'lib/nebula/webclient/setting.rb', line 108

def border
  @border
end

#heightObject

Returns the value of attribute height.



107
108
109
# File 'lib/nebula/webclient/setting.rb', line 107

def height
  @height
end

#languageObject

Returns the value of attribute language.



111
112
113
# File 'lib/nebula/webclient/setting.rb', line 111

def language
  @language
end

Returns the value of attribute menu_docking.



109
110
111
# File 'lib/nebula/webclient/setting.rb', line 109

def menu_docking
  @menu_docking
end

#render_modeObject

Returns the value of attribute render_mode.



110
111
112
# File 'lib/nebula/webclient/setting.rb', line 110

def render_mode
  @render_mode
end

#widthObject

Returns the value of attribute width.



106
107
108
# File 'lib/nebula/webclient/setting.rb', line 106

def width
  @width
end

Instance Method Details

#to_json(uri = nil) ⇒ String

Generate the JSON code of the setting.

Parameters:

  • uri (String) (defaults to: nil)

    Uri of the model to be loaded, empty for nothing.

Returns:

  • (String)

    A JSON string.



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/nebula/webclient/setting.rb', line 93

def to_json(uri = nil)
  s = ''
  s << '{width:' << Encoder.str(width)
  s << ',height:' << Encoder.str(height)
  s << ',border:' << Encoder.str(border) if border.width > 0
  s << ',menuDocking:' << Encoder.str(menu_docking) if menu_docking != :bottom
  s << ',renderMode:' << Encoder.str(RenderModes[render_mode]) if render_mode != :realistic
  s << ',language:' << Encoder.str(Languages[language]) if language != :english
  s << ',uri' << Encoder.js(uri) if uri
  s << '}'
  s
end

#to_url_parameters(uri = nil) ⇒ String

Generate the url parameters to describe the settings.

Parameters:

  • uri (String) (defaults to: nil)

    Uri of the model to be loaded, empty for nothing.

Returns:

  • (String)

    A encoded string as a url parameter (query).



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/nebula/webclient/setting.rb', line 78

def to_url_parameters(uri = nil)
  s = ''
  s << '?w=' << Encoder.str(width)
  s << '&h=' << Encoder.str(height)
  s << '&b=' << Encoder.url(border) if border.width > 0
  s << '&m=' << Encoder.str(menu_docking) if menu_docking != :bottom
  s << '&r=' << Encoder.str(RenderModes[render_mode]) if render_mode != :default
  s << '&l=' << Encoder.str(Languages[language]) if language != :english
  s << '&u=' << Encoder.url(uri) if uri
  s
end