Class: AimsProject::GeometryWindow
- Inherits:
-
Wx::Panel
- Object
- Wx::Panel
- AimsProject::GeometryWindow
- Includes:
- Wx
- Defined in:
- lib/aims_project/geometry_window.rb
Instance Attribute Summary collapse
-
#update_unit_cell ⇒ Object
Returns the value of attribute update_unit_cell.
Instance Method Summary collapse
-
#add_geometry(geometry) ⇒ Object
Add a geometry with the given name.
-
#geometry ⇒ Object
Get the currently displayed geometry.
- #image ⇒ Object
-
#initialize(app, parent) ⇒ GeometryWindow
constructor
A new instance of GeometryWindow.
- #nudge_selected_atoms(x, y, z) ⇒ Object
-
#open_geometry_file(file = nil) ⇒ Object
Display a file dialog and attempt to open and display the file.
- #select_atom(atom) ⇒ Object
-
#show_geometry(geometry) ⇒ Object
Display the given geometry.
- #show_inspector ⇒ Object
-
#update_viewer ⇒ Object
Apply UI settings to viewer and re-render.
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 54 55 56 57 58 59 |
# 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) # The top is a list control @geomList = ListCtrl.new(topSplitterWindow) app.project.geometries.sort{|a,b| a <=> b}.each{|geom| li = ListItem.new li.set_text(File.basename(geom)) li.set_data(geom) @geomList.insert_item(li) } # 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(@geomList, geomWindowSplitter, 100) layout # Define events evt_list_item_selected(@geomList) {|evt| open_geometry_file(evt.get_item.get_data) } end |
Instance Attribute Details
#update_unit_cell ⇒ Object
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
#add_geometry(geometry) ⇒ Object
Add a geometry with the given name
62 63 64 65 66 67 68 69 70 |
# File 'lib/aims_project/geometry_window.rb', line 62 def add_geometry(geometry) @app.project.geometries << geometry li = ListItem.new li.set_text(File.basename(geometry.file)) li.set_data(geometry.file) li.set_state(LIST_STATE_SELECTED) @geomList.insert_item(li) @geomList.sort{|a,b| a <=> b} end |
#geometry ⇒ Object
Get the currently displayed geometry
108 109 110 |
# File 'lib/aims_project/geometry_window.rb', line 108 def geometry @original_uc end |
#image ⇒ Object
103 104 105 |
# File 'lib/aims_project/geometry_window.rb', line 103 def image @geomViewer.image end |
#nudge_selected_atoms(x, y, z) ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/aims_project/geometry_window.rb', line 133 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
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/aims_project/geometry_window.rb', line 78 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
126 127 128 129 130 131 |
# File 'lib/aims_project/geometry_window.rb', line 126 def select_atom(atom) @selection[:atoms] = [atom] puts "Selection:" puts @selection[:atoms].each{|a| puts a.format_geometry_in} @geomEditor.select_atom(atom) end |
#show_geometry(geometry) ⇒ Object
Display the given geometry
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/aims_project/geometry_window.rb', line 113 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_inspector ⇒ Object
73 74 75 |
# File 'lib/aims_project/geometry_window.rb', line 73 def show_inspector @app.inspector.show_inspector_window(@inspector_window) end |
#update_viewer ⇒ Object
Apply UI settings to viewer and re-render
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/aims_project/geometry_window.rb', line 142 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 |