Class: AimsProject::GeometryWindow

Inherits:
Wx::Panel
  • Object
show all
Includes:
Wx
Defined in:
lib/aims_project/geometry_window.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, parent) ⇒ GeometryWindow

Returns a new instance of GeometryWindow.



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
# File 'lib/aims_project/geometry_window.rb', line 9

def initialize(app, parent)
  
  super(parent)
  @app = app
        
  # Initialize the selection of atoms
  @selection = {}
  
  # Tracks whether changes in inspector should update the unit cell
  @update_unit_cell = false
  
  # Get an inspector window to add into
  @inspector_window = @app.inspector.add_inspector_window
  
  # This is a model/controller for the inspector to pass to the crystal viewer
  @options = CrystalViewerOptions.new(@inspector_window)
  
  # Top level is a splitter
  topSplitterWindow = SplitterWindow.new(self)
  sizer = VBoxSizer.new
  sizer.add_item(topSplitterWindow, :proportion => 1, :flag => EXPAND)
  
  set_sizer(sizer)
  @console = GeometryConsole.new(self, topSplitterWindow)
  
  # The bottom is a vertical splitter
  geomWindowSplitter = SplitterWindow.new(topSplitterWindow)
  @geomEditor = GeometryEditor.new(self, geomWindowSplitter)
  @geomViewer = CrystalViewer.new(self, geomWindowSplitter, @options)
  
  geomWindowSplitter.split_vertically(@geomEditor, @geomViewer)
  
  # Add top and bottom sides together
  topSplitterWindow.split_horizontally(geomWindowSplitter, @console, -100)
  layout
  
  # Define events
  evt_list_item_selected(@console) {|evt|
    open_geometry_file(evt.get_item.get_data)
  }
  
  show_geometry(GeometryFile.new)
  
  
end

Instance Attribute Details

#update_unit_cellObject

Returns the value of attribute update_unit_cell.



7
8
9
# File 'lib/aims_project/geometry_window.rb', line 7

def update_unit_cell
  @update_unit_cell
end

Instance Method Details

#display_exception(e) ⇒ Object



126
127
128
# File 'lib/aims_project/geometry_window.rb', line 126

def display_exception(e)
  @console.print(e.message, Wx::RED)
end

#geometryObject

Get the currently displayed geometry



91
92
93
# File 'lib/aims_project/geometry_window.rb', line 91

def geometry
  @original_uc
end

#imageObject



86
87
88
# File 'lib/aims_project/geometry_window.rb', line 86

def image
  @geomViewer.image
end

#nudge_selected_atoms(x, y, z) ⇒ Object



118
119
120
121
122
123
124
# File 'lib/aims_project/geometry_window.rb', line 118

def nudge_selected_atoms(x,y,z)
  if @selection[:atoms]
    @selection[:atoms].each{|a| a.displace!(x,y,z)}
  end
  @geomViewer.draw_scene
  @geomEditor.update
end

#open_geometry_file(file = nil) ⇒ Object

Display a file dialog and attempt to open and display the file



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/aims_project/geometry_window.rb', line 61

def open_geometry_file(file = nil)
  begin
    unless file
      fd = FileDialog.new(@app.frame, :message => "Open", :style => FD_OPEN, :default_dir => @working_dir)
      if ID_OK == fd.show_modal
        file = fd.get_path
        @working_dir = fd.get_directory
      else
        return
      end
    end
    @app.set_status "Opening #{file}"

    if (@app.project)
      show_geometry GeometryFile.new(File.new(file), @app.project.get_binding)
    else
      show_geometry GeometryFile.new(File.new(file))
    end


  rescue Exception => dang
    @app.error_dialog(dang)
  end
end

#select_atom(atom) ⇒ Object



109
110
111
112
113
114
115
116
# File 'lib/aims_project/geometry_window.rb', line 109

def select_atom(atom)
  @selection[:atoms] = [atom]
  puts "Selection:" 
  puts @selection[:atoms].each{|a| puts a.format_geometry_in}
  @geomEditor.select_atom(atom)
  @console.echo("\n" + atom.to_s)
  @console.prompt
end

#show_geometry(geometry) ⇒ Object

Display the given geometry



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/aims_project/geometry_window.rb', line 96

def show_geometry(geometry)
  begin
    @original_uc = geometry
    @geomViewer.unit_cell = @original_uc
   rescue AimsProjectException => e
    @app.error_dialog(e)
  ensure
    @geomEditor.unit_cell = @original_uc
  end
  # @inspector.update(@geomViewer)
  # @geomViewer.draw_scene
end

#show_inspectorObject



56
57
58
# File 'lib/aims_project/geometry_window.rb', line 56

def show_inspector
  @app.inspector.show_inspector_window(@inspector_window)
end

#update_viewerObject

Apply UI settings to viewer and re-render



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/aims_project/geometry_window.rb', line 131

def update_viewer
  
  puts "GeometryWindow.update_viewer"

  if @original_uc and self.update_unit_cell
    if @correct.get_value
      # @geomViewer.unit_cell = @original_uc.correct
      new_geom = @original_uc.repeat(@x_repeat.get_value, @y_repeat.get_value, @z_repeat.get_value).correct
    else
      # @geomViewer.unit_cell = @original_uc
      new_geom = @original_uc.repeat(@x_repeat.get_value, @y_repeat.get_value, @z_repeat.get_value)
    end
    @geomViewer.unit_cell = new_geom
    @geomEditor.unit_cell = new_geom
    self.update_unit_cell = false
  end

  # @geomViewer.repeat = [@inspector.x_repeat, @inspector.y_repeat, @inspector.z_repeat]
  @geomViewer.show_bonds = @show_bonds.get_value
  @geomViewer.bond_length = @bond_length.get_value
  @geomViewer.lighting = @show_lighting.get_value
  @geomViewer.show_supercell = @show_cell.get_value
  @geomViewer.show_xclip = @show_xclip.get_value
  @geomViewer.show_yclip = @show_yclip.get_value
  @geomViewer.show_zclip = @show_zclip.get_value
  @geomViewer.background.alpha = ((@transparent_bg.get_value) ? 0 : 1)
  @geomViewer.draw_scene
end