aims_project_windows 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,245 @@
1
+
2
+ module AimsProject
3
+ class AppController < Wx::App
4
+
5
+ include Wx
6
+
7
+ ID_NEW = 102
8
+ ID_SAVE_IMAGE = 103
9
+ ID_MOVE_CLIP_PLANE = 104
10
+ ID_SAVE_AS = 105
11
+
12
+ ID_INSPECTOR = 201
13
+
14
+ ID_DELETE_ATOM = 301
15
+
16
+ @frame = nil
17
+ @menubar = nil
18
+ @inspector = nil
19
+ @statusbar = nil
20
+
21
+ # The project
22
+ attr_accessor :project
23
+
24
+ # Used to synchronize directory in open/save dialogs
25
+ attr_accessor :working_dir
26
+
27
+ # The root frame
28
+ attr_accessor :frame
29
+
30
+ # Build the application
31
+ def on_init
32
+
33
+ self.app_name = "AimsViewer"
34
+ # Create the frame, toolbar and menubar and define event handlers
35
+ size = [1000,700]
36
+ @frame = Frame.new(nil, -1, "AimsViewer", DEFAULT_POSITION, size)
37
+ @statusbar = @frame.create_status_bar
38
+
39
+ # This timer will cause the main thread to pass every 2 ms so that other threads
40
+ # can get work done.
41
+ timer = Wx::Timer.new(self, Wx::ID_ANY)
42
+ evt_timer(timer.id) {Thread.pass}
43
+ timer.start(2)
44
+
45
+ # Initialize the selection
46
+ @selection = {}
47
+
48
+ # Initialize the inspector
49
+ @inspector = Inspector.new(self, @frame)
50
+
51
+ # Create the geometry notebook page
52
+ @geomWindow = GeometryWindow.new(self, @frame)
53
+ frameSizer = VBoxSizer.new
54
+ # frameSizer.add_item(@geomWindow, :proportion => 1, :flag => EXPAND)
55
+ # @frame.set_sizer(frameSizer)
56
+ @frame.set_menu_bar(menubar)
57
+
58
+ # Display
59
+ @frame.show
60
+ end
61
+
62
+ # Process a menu event
63
+ def process_menu_event(event)
64
+ case event.id
65
+ when ID_INSPECTOR
66
+ show_inspector
67
+ when ID_DELETE_ATOM
68
+ delete_atom
69
+ when Wx::ID_OPEN
70
+ open_file
71
+ when Wx::ID_SAVE
72
+ save_geometry
73
+ when ID_NEW
74
+ new_geometry_file
75
+ when ID_SAVE_AS
76
+ save_geometry_as
77
+ when ID_SAVE_IMAGE
78
+ save_image
79
+ when Wx::ID_EXIT
80
+ exit(0)
81
+ else
82
+ event.skip
83
+ end
84
+
85
+ end
86
+
87
+
88
+ # Return the menubar. If it is undefined, then define it and attach the event handler
89
+ def menubar
90
+ unless @menubar
91
+ fileMenu = Menu.new
92
+ fileMenu.append(ID_NEW, "New Geometry ...")
93
+ fileMenu.append(Wx::ID_OPEN, "Open ...\tCTRL+o")
94
+ fileMenu.append(Wx::ID_SAVE, "Save Geometry\tCTRL+s")
95
+ fileMenu.append(ID_SAVE_AS, "Save Geometry As...")
96
+ fileMenu.append(ID_SAVE_IMAGE, "Export Image ...")
97
+ fileMenu.append(Wx::ID_EXIT, "Exit")
98
+
99
+ editMenu = Menu.new
100
+ editMenu.append(ID_DELETE_ATOM, "Delete Atom\tCTRL+d")
101
+
102
+ toolsMenu = Menu.new
103
+ # toolsMenu.append(ID_ROTATE, "rotate", "Rotate", Wx::ITEM_CHECK)
104
+ # toolsMenu.append(ID_ZOOM, "zoom", "Zoom", Wx::ITEM_CHECK)
105
+ # toolsMenu.append(ID_PAN, "pan", "Pan", Wx::ITEM_CHECK)
106
+ # toolsMenu.append(ID_MOVE_CLIP_PLANE, "move cilp plane", "Move", Wx::ITEM_CHECK)
107
+
108
+ viewMenu = Menu.new
109
+ viewMenu.append(ID_INSPECTOR, "inspector\tCTRL+i")
110
+
111
+
112
+ @menubar = MenuBar.new
113
+ @menubar.append(fileMenu, "File")
114
+ @menubar.append(editMenu, "Edit")
115
+ @menubar.append(viewMenu, "Views")
116
+ @menubar.append(toolsMenu, "Tools")
117
+
118
+ evt_menu @menubar, :process_menu_event
119
+ end
120
+ @menubar
121
+ end
122
+
123
+ def set_status(string)
124
+ @frame.set_status_text(string)
125
+ end
126
+
127
+ # Get the inspector
128
+ def inspector
129
+ if @inspector.nil?
130
+ @inspector = Inspector.new(self, @frame)
131
+ end
132
+ @inspector
133
+ end
134
+
135
+ # Show the inspector
136
+ def show_inspector
137
+ @geomWindow.show_inspector
138
+ @inspector.show(true)
139
+ end
140
+
141
+ # Hide the inspector
142
+ def hide_inspector
143
+ @inspector.hide
144
+ end
145
+
146
+ # Create a new geometry file
147
+ def new_geometry_file(file = nil)
148
+ fd = TextEntryDialog.new(@frame, :message => "New Geometry", :caption => "Specify name of geometry:")
149
+ if Wx::ID_OK == fd.show_modal
150
+ begin
151
+ geom_name = fd.get_value
152
+ geometry = GeometryFile.new("")
153
+ geometry = geometry.save_as(File.new(File.join(GEOMETRY_DIR, geom_name), "w"))
154
+ @geomWindow.add_geometry(geometry)
155
+ rescue Exception => e
156
+ error_dialog(e)
157
+ end
158
+ end
159
+ end
160
+
161
+ # Display a file dialog and attempt to open and display the file
162
+ def open_geometry_file(file = nil)
163
+ begin
164
+ unless file
165
+ fd = FileDialog.new(@frame, :message => "Open", :style => FD_OPEN, :default_dir => @working_dir)
166
+ if ID_OK == fd.show_modal
167
+ file = fd.get_path
168
+ @working_dir = fd.get_directory
169
+ else
170
+ return
171
+ end
172
+ end
173
+ puts "Opening #{file}"
174
+ @geomWindow.open_geometry_file(file)
175
+ @frame.set_title(file)
176
+
177
+
178
+ rescue Exception => dang
179
+ error_dialog(dang)
180
+ end
181
+ end
182
+ alias_method :open_file, :open_geometry_file
183
+
184
+ def save_geometry
185
+ geometry = @geomWindow.geometry
186
+ begin
187
+ if geometry.file
188
+ geometry.save
189
+ else
190
+ save_geometry_as
191
+ end
192
+ rescue Exception => e
193
+ error_dialog(e)
194
+ end
195
+ end
196
+
197
+ # Save the geometry
198
+ def save_geometry_as
199
+
200
+ geometry = @geomWindow.geometry
201
+
202
+ fd = FileDialog.new(@frame, :message => "Save Geometry", :style => FD_SAVE, :default_dir => @working_dir)
203
+ if Wx::ID_OK == fd.show_modal
204
+ begin
205
+ @working_dir = fd.get_directory
206
+ geom_name = fd.get_path
207
+ new_geom = geometry.save_as(geom_name)
208
+ @geomWindow.show_geometry(new_geom)
209
+ rescue Exception => e
210
+ error_dialog(e)
211
+ end
212
+ end
213
+
214
+ end
215
+
216
+ # Display an error dialog for the exception
217
+ def error_dialog(exception)
218
+ message = if exception.is_a? String
219
+ exception
220
+ elsif exception.is_a? Exception
221
+ exception.message + "\n\n" + exception.backtrace[0..2].join("\n")
222
+ end
223
+ puts message
224
+ MessageDialog.new(@frame, message, "Error", Wx::ICON_ERROR).show_modal
225
+ end
226
+
227
+ def save_image
228
+
229
+ begin
230
+ image = @geomWindow.image
231
+ fd = FileDialog.new(@frame, :message => "Save Image", :style => FD_SAVE, :default_dir => @working_dir)
232
+ if Wx::ID_OK == fd.show_modal
233
+ @working_dir = fd.get_directory
234
+ puts "Writing #{fd.get_path}"
235
+ image.mirror(false).save_file(fd.get_path)
236
+ end
237
+
238
+ rescue Exception => e
239
+ error_dialog(e)
240
+ end
241
+ end
242
+
243
+ end
244
+ end
245
+
@@ -0,0 +1,95 @@
1
+ #
2
+ # copyright 2012, Joshua Shapiro
3
+ # joshua.shapiro@gmail.com
4
+ #
5
+ # This file is part of AimsProjectManager.
6
+ #
7
+ # AimsProjectManager is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # AimsProjectManager is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ #
18
+ module Aims
19
+
20
+ # Adds display behavior to atoms.
21
+ class Atom
22
+
23
+ @@black = nil
24
+ @@white = nil
25
+ @@blue = nil
26
+ @@red = nil
27
+ @@green = nil
28
+ @@dark = nil
29
+ @@light = nil
30
+ @@yellow = nil
31
+ @@orange = nil
32
+ @@graypurple = nil
33
+
34
+ def material
35
+ unless @@yellow
36
+ @@yellow = AimsProject::Material.new(1,1,0,1)
37
+ end
38
+
39
+ unless @@black
40
+ @@lback = AimsProject::Material.new(0,0,0,1)
41
+ end
42
+
43
+ unless @@white
44
+ @@lback = AimsProject::Material.new(1,1,1,1)
45
+ end
46
+
47
+ unless @@blue
48
+ @@blue = AimsProject::Material.new(0,0,1,1)
49
+ end
50
+
51
+ unless @@red
52
+ @@red = AimsProject::Material.new(1,0.4,0.4,1)
53
+ end
54
+
55
+ unless @@green
56
+ @@green = AimsProject::Material.new(0,1,0,1)
57
+ end
58
+
59
+ unless @@orange
60
+ @@orange = AimsProject::Material.new(1, 0.5, 0, 1)
61
+ end
62
+
63
+ unless @@graypurple
64
+ @@graypurple = AimsProject::Material.new(0.45, 0.55, 0.55, 1)
65
+ end
66
+
67
+ unless @@dark
68
+ @@dark = AimsProject::Material.new(0.2,0.2,0.2,1)
69
+ end
70
+
71
+ unless @@light
72
+ @@light = AimsProject::Material.new(1,1,1,1)
73
+ end
74
+
75
+ case self.species
76
+ when /Ga/
77
+ @@dark
78
+ when /As/
79
+ @@light
80
+ when /In/
81
+ @@graypurple
82
+ when /P/
83
+ @@orange
84
+ when /Si/
85
+ @@yellow
86
+ when /C/
87
+ @@red
88
+ else
89
+ @@blue
90
+ end
91
+ end
92
+ end
93
+
94
+
95
+ end