Class: AimsProject::AppController
- Inherits:
-
Wx::App
- Object
- Wx::App
- AimsProject::AppController
- Includes:
- Wx
- Defined in:
- lib/aims_project/app_controller.rb
Constant Summary collapse
- ID_NEW =
102
- ID_SAVE_IMAGE =
103
- ID_MOVE_CLIP_PLANE =
104
- ID_SAVE_AS =
105
- ID_INSPECTOR =
201
- ID_DELETE_ATOM =
301
Instance Attribute Summary collapse
-
#frame ⇒ Object
The root frame.
-
#project ⇒ Object
The project.
-
#working_dir ⇒ Object
Used to synchronize directory in open/save dialogs.
Instance Method Summary collapse
-
#error_dialog(exception) ⇒ Object
Display an error dialog for the exception.
-
#hide_inspector ⇒ Object
Hide the inspector.
-
#inspector ⇒ Object
Get the inspector.
-
#menubar ⇒ Object
Return the menubar.
-
#new_geometry_file(file = nil) ⇒ Object
Create a new geometry file.
-
#on_init ⇒ Object
Build the application.
-
#open_geometry_file(file = nil) ⇒ Object
(also: #open_file)
Display a file dialog and attempt to open and display the file.
-
#process_menu_event(event) ⇒ Object
Process a menu event.
- #save_geometry ⇒ Object
-
#save_geometry_as ⇒ Object
Save the geometry.
- #save_image ⇒ Object
- #set_status(string) ⇒ Object
-
#show_inspector ⇒ Object
Show the inspector.
Instance Attribute Details
#frame ⇒ Object
The root frame
28 29 30 |
# File 'lib/aims_project/app_controller.rb', line 28 def frame @frame end |
#project ⇒ Object
The project
22 23 24 |
# File 'lib/aims_project/app_controller.rb', line 22 def project @project end |
#working_dir ⇒ Object
Used to synchronize directory in open/save dialogs
25 26 27 |
# File 'lib/aims_project/app_controller.rb', line 25 def working_dir @working_dir end |
Instance Method Details
#error_dialog(exception) ⇒ Object
Display an error dialog for the exception
217 218 219 220 221 222 223 224 225 |
# File 'lib/aims_project/app_controller.rb', line 217 def error_dialog(exception) = if exception.is_a? String exception elsif exception.is_a? Exception exception. + "\n\n" + exception.backtrace[0..2].join("\n") end puts MessageDialog.new(@frame, , "Error", Wx::ICON_ERROR).show_modal end |
#hide_inspector ⇒ Object
Hide the inspector
142 143 144 |
# File 'lib/aims_project/app_controller.rb', line 142 def hide_inspector @inspector.hide end |
#inspector ⇒ Object
Get the inspector
128 129 130 131 132 133 |
# File 'lib/aims_project/app_controller.rb', line 128 def inspector if @inspector.nil? @inspector = Inspector.new(self, @frame) end @inspector end |
#menubar ⇒ Object
Return the menubar. If it is undefined, then define it and attach the event handler
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/aims_project/app_controller.rb', line 89 def unless @menubar fileMenu = Menu.new fileMenu.append(ID_NEW, "New Geometry ...") fileMenu.append(Wx::ID_OPEN, "Open ...\tCTRL+o") fileMenu.append(Wx::ID_SAVE, "Save Geometry\tCTRL+s") fileMenu.append(ID_SAVE_AS, "Save Geometry As...") fileMenu.append(ID_SAVE_IMAGE, "Export Image ...") fileMenu.append(Wx::ID_EXIT, "Exit") editMenu = Menu.new editMenu.append(ID_DELETE_ATOM, "Delete Atom\tCTRL+d") toolsMenu = Menu.new # toolsMenu.append(ID_ROTATE, "rotate", "Rotate", Wx::ITEM_CHECK) # toolsMenu.append(ID_ZOOM, "zoom", "Zoom", Wx::ITEM_CHECK) # toolsMenu.append(ID_PAN, "pan", "Pan", Wx::ITEM_CHECK) # toolsMenu.append(ID_MOVE_CLIP_PLANE, "move cilp plane", "Move", Wx::ITEM_CHECK) viewMenu = Menu.new viewMenu.append(ID_INSPECTOR, "inspector\tCTRL+i") @menubar = MenuBar.new @menubar.append(fileMenu, "File") @menubar.append(editMenu, "Edit") @menubar.append(viewMenu, "Views") # @menubar.append(toolsMenu, "Tools") @menubar, :process_menu_event end @menubar end |
#new_geometry_file(file = nil) ⇒ Object
Create a new geometry file
147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/aims_project/app_controller.rb', line 147 def new_geometry_file(file = nil) fd = TextEntryDialog.new(@frame, :message => "New Geometry", :caption => "Specify name of geometry:") if Wx::ID_OK == fd.show_modal begin geom_name = fd.get_value geometry = GeometryFile.new("") geometry = geometry.save_as(File.new(File.join(GEOMETRY_DIR, geom_name), "w")) @geomWindow.add_geometry(geometry) rescue Exception => e error_dialog(e) end end end |
#on_init ⇒ Object
Build the application
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 |
# File 'lib/aims_project/app_controller.rb', line 31 def on_init self.app_name = "AimsViewer" # Create the frame, toolbar and menubar and define event handlers size = [1000,700] @frame = Frame.new(nil, :title => "AimsViewer", :size => size) @statusbar = @frame. # This timer will cause the main thread to pass every 2 ms so that other threads # can get work done. # timer = Wx::Timer.new(self, Wx::ID_ANY) # evt_timer(timer.id) {Thread.pass} # timer.start(2) # Initialize the selection @selection = {} # Initialize the inspector @inspector = Inspector.new(self, @frame) # Create the geometry notebook page @geomWindow = GeometryWindow.new(self, @frame) frameSizer = VBoxSizer.new # frameSizer.add_item(@geomWindow, :proportion => 1, :flag => EXPAND) # @frame.set_sizer(frameSizer) @frame.() # Display @frame.show end |
#open_geometry_file(file = nil) ⇒ Object Also known as: open_file
Display a file dialog and attempt to open and display the file
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/aims_project/app_controller.rb', line 162 def open_geometry_file(file = nil) begin unless file fd = FileDialog.new(@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 puts "Opening #{file}" @geomWindow.open_geometry_file(file) @frame.set_title(file) rescue Exception => dang error_dialog(dang) end end |
#process_menu_event(event) ⇒ Object
Process a menu event
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/aims_project/app_controller.rb', line 63 def (event) case event.id when ID_INSPECTOR show_inspector when ID_DELETE_ATOM delete_atom when Wx::ID_OPEN open_file when Wx::ID_SAVE save_geometry when ID_NEW new_geometry_file when ID_SAVE_AS save_geometry_as when ID_SAVE_IMAGE save_image when Wx::ID_EXIT exit(0) else event.skip end end |
#save_geometry ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/aims_project/app_controller.rb', line 184 def save_geometry geometry = @geomWindow.geometry begin if geometry.file geometry.save else save_geometry_as end rescue Exception => e error_dialog(e) end end |
#save_geometry_as ⇒ Object
Save the geometry
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/aims_project/app_controller.rb', line 198 def save_geometry_as geometry = @geomWindow.geometry fd = FileDialog.new(@frame, :message => "Save Geometry", :style => FD_SAVE, :default_dir => @working_dir) if Wx::ID_OK == fd.show_modal begin @working_dir = fd.get_directory geom_name = fd.get_path new_geom = geometry.save_as(geom_name) @geomWindow.show_geometry(new_geom) rescue Exception => e error_dialog(e) end end end |
#save_image ⇒ Object
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/aims_project/app_controller.rb', line 227 def save_image begin image = @geomWindow.image fd = FileDialog.new(@frame, :message => "Save Image", :style => FD_SAVE, :default_dir => @working_dir) if Wx::ID_OK == fd.show_modal @working_dir = fd.get_directory puts "Writing #{fd.get_path}" image.mirror(false).save_file(fd.get_path) end rescue Exception => e error_dialog(e) end end |
#set_status(string) ⇒ Object
123 124 125 |
# File 'lib/aims_project/app_controller.rb', line 123 def set_status(string) @frame.set_status_text(string) end |
#show_inspector ⇒ Object
Show the inspector
136 137 138 139 |
# File 'lib/aims_project/app_controller.rb', line 136 def show_inspector @geomWindow.show_inspector @inspector.show(true) end |