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
265 266 267 268 269 270 271 272 273 |
# File 'lib/aims_project/app_controller.rb', line 265 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
179 180 181 |
# File 'lib/aims_project/app_controller.rb', line 179 def hide_inspector @inspector.hide end |
#inspector ⇒ Object
Get the inspector
166 167 168 169 170 171 |
# File 'lib/aims_project/app_controller.rb', line 166 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
127 128 129 130 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 159 |
# File 'lib/aims_project/app_controller.rb', line 127 def unless 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.new .append(fileMenu, "File") .append(editMenu, "Edit") .append(viewMenu, "Views") .append(toolsMenu, "Tools") , :process_menu_event end end |
#new_geometry_file(file = nil) ⇒ Object
Create a new geometry file
184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/aims_project/app_controller.rb', line 184 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 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 93 94 95 96 97 98 |
# 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, -1, "AimsViewer", DEFAULT_POSITION, size) = @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 notebook @notebook = Notebook.new(@frame) # Create the geometry notebook page @geomWindow = GeometryWindow.new(self, @notebook) # Create the control window # The base window is a horizontal splitter # Left side is a list of control files # right side is a Rich Text Control controlWindow = SplitterWindow.new(@notebook) @controlList = ListCtrl.new(controlWindow); @controlEditor = RichTextCtrl.new(controlWindow) controlWindow.split_horizontally(@controlList, @controlEditor) # Create the calculations window # Similar to the geometryWindow # Left side is a list control # Right side is a crystal viewer calcWindow = CalculationWindow.new(self, @notebook) # Add windows to the notebook @notebook.add_page(@geomWindow, 'Geometry') @notebook.add_page(controlWindow, "Control") @notebook.add_page(calcWindow, "Calculations") evt_notebook_page_changed(@notebook) {|evt| cp = @notebook.get_current_page if cp.respond_to? :show_inspector @notebook.get_current_page.show_inspector end } # Set the selected notebook page @notebook.set_selection(2) # @tree = ProjectTree.new(self, hsplitter) @frame.() # @toolbar = @frame.create_tool_bar # populate_toolbar(@toolbar) if @toolbar # Check off the current tool # set_tool # 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
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/aims_project/app_controller.rb', line 199 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}" @frame.set_title(file) @geomEditor.show @calcTree.hide if (project) erb = ERB.new(File.read(file)) show_geometry Aims::GeometryParser.parse_string(erb.result(project.get_binding)) else show_geometry Aims::GeometryParser.parse(file) end rescue Exception => dang error_dialog(dang) end end |
#process_menu_event(event) ⇒ Object
Process a menu event
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/aims_project/app_controller.rb', line 101 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
230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/aims_project/app_controller.rb', line 230 def save_geometry page = @notebook.get_current_page if (page.respond_to? :geometry) && not(page.geometry.nil?) geometry = @notebook.get_current_page.geometry begin geometry.save rescue Exception => e error_dialog(e) end end end |
#save_geometry_as ⇒ Object
Save the geometry
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/aims_project/app_controller.rb', line 243 def save_geometry_as page = @notebook.get_current_page if (page.respond_to? :geometry) && not(page.geometry.nil?) geometry = @notebook.get_current_page.geometry fd = TextEntryDialog.new(@frame, :message => "Save Geometry", :caption => "Specify name of geometry:") if Wx::ID_OK == fd.show_modal begin geom_name = fd.get_value new_geom = geometry.save_as(File.new(File.join(GEOMETRY_DIR, geom_name), "w")) @geomWindow.add_geometry(new_geom) rescue Exception => e error_dialog(e) end end else error_dialog("No geometry selected.") end end |
#save_image ⇒ Object
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/aims_project/app_controller.rb', line 275 def save_image begin page = @notebook.get_current_page if (page.respond_to? :image) image = page.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 else error_dialog("Sorry, could not generate an image.") end rescue Exception => e error_dialog(e) end end |
#set_status(string) ⇒ Object
161 162 163 |
# File 'lib/aims_project/app_controller.rb', line 161 def set_status(string) @frame.set_status_text(string) end |
#show_inspector ⇒ Object
Show the inspector
174 175 176 |
# File 'lib/aims_project/app_controller.rb', line 174 def show_inspector @inspector.show(true) end |