gave 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,196 @@
1
+ <?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
2
+ <!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
3
+
4
+ <glade-interface>
5
+ <requires lib="gnome"/>
6
+
7
+ <widget class="GtkWindow" id="Fileselection">
8
+ <property name="visible">True</property>
9
+ <property name="title" translatable="yes">File Select</property>
10
+ <property name="type">GTK_WINDOW_TOPLEVEL</property>
11
+ <property name="window_position">GTK_WIN_POS_NONE</property>
12
+ <property name="modal">False</property>
13
+ <property name="default_width">500</property>
14
+ <property name="default_height">300</property>
15
+ <property name="resizable">True</property>
16
+ <property name="destroy_with_parent">True</property>
17
+ <signal name="delete_event" handler="on_Fileselection_delete_event" last_modification_time="Thu, 11 Mar 2004 08:23:28 GMT"/>
18
+
19
+ <child>
20
+ <widget class="GtkVBox" id="vbox1">
21
+ <property name="border_width">5</property>
22
+ <property name="visible">True</property>
23
+ <property name="homogeneous">False</property>
24
+ <property name="spacing">0</property>
25
+
26
+ <child>
27
+ <widget class="GtkHBox" id="hbox4">
28
+ <property name="border_width">5</property>
29
+ <property name="visible">True</property>
30
+ <property name="homogeneous">False</property>
31
+ <property name="spacing">0</property>
32
+
33
+ <child>
34
+ <widget class="GtkEntry" id="entry">
35
+ <property name="visible">True</property>
36
+ <property name="can_focus">True</property>
37
+ <property name="editable">True</property>
38
+ <property name="visibility">True</property>
39
+ <property name="max_length">0</property>
40
+ <property name="text" translatable="yes"></property>
41
+ <property name="has_frame">True</property>
42
+ <property name="invisible_char" translatable="yes">*</property>
43
+ <property name="activates_default">False</property>
44
+ <signal name="activate" handler="on_entry_activate" last_modification_time="Thu, 11 Mar 2004 10:32:12 GMT"/>
45
+ </widget>
46
+ <packing>
47
+ <property name="padding">0</property>
48
+ <property name="expand">True</property>
49
+ <property name="fill">True</property>
50
+ </packing>
51
+ </child>
52
+
53
+ <child>
54
+ <widget class="GtkButton" id="jump">
55
+ <property name="visible">True</property>
56
+ <property name="can_focus">True</property>
57
+ <property name="label" translatable="yes">jump</property>
58
+ <property name="use_underline">True</property>
59
+ <property name="relief">GTK_RELIEF_NORMAL</property>
60
+ <signal name="clicked" handler="on_jump_clicked" last_modification_time="Thu, 11 Mar 2004 08:03:05 GMT"/>
61
+ </widget>
62
+ <packing>
63
+ <property name="padding">0</property>
64
+ <property name="expand">False</property>
65
+ <property name="fill">False</property>
66
+ </packing>
67
+ </child>
68
+ </widget>
69
+ <packing>
70
+ <property name="padding">0</property>
71
+ <property name="expand">False</property>
72
+ <property name="fill">False</property>
73
+ </packing>
74
+ </child>
75
+
76
+ <child>
77
+ <widget class="GtkHPaned" id="hpaned1">
78
+ <property name="border_width">5</property>
79
+ <property name="visible">True</property>
80
+ <property name="can_focus">True</property>
81
+ <property name="position">0</property>
82
+
83
+ <child>
84
+ <widget class="GtkScrolledWindow" id="scrolledwindow1">
85
+ <property name="visible">True</property>
86
+ <property name="can_focus">True</property>
87
+ <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
88
+ <property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
89
+ <property name="shadow_type">GTK_SHADOW_NONE</property>
90
+ <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
91
+
92
+ <child>
93
+ <widget class="GtkTreeView" id="dirlist">
94
+ <property name="visible">True</property>
95
+ <property name="can_focus">True</property>
96
+ <property name="headers_visible">True</property>
97
+ <property name="rules_hint">False</property>
98
+ <property name="reorderable">False</property>
99
+ <property name="enable_search">True</property>
100
+ <signal name="cursor_changed" handler="on_dirlist_cursor_changed" last_modification_time="Thu, 11 Mar 2004 09:19:34 GMT"/>
101
+ </widget>
102
+ </child>
103
+ </widget>
104
+ <packing>
105
+ <property name="shrink">True</property>
106
+ <property name="resize">True</property>
107
+ </packing>
108
+ </child>
109
+
110
+ <child>
111
+ <widget class="GtkScrolledWindow" id="scrolledwindow2">
112
+ <property name="visible">True</property>
113
+ <property name="can_focus">True</property>
114
+ <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
115
+ <property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
116
+ <property name="shadow_type">GTK_SHADOW_NONE</property>
117
+ <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
118
+
119
+ <child>
120
+ <widget class="GtkTreeView" id="filelist">
121
+ <property name="visible">True</property>
122
+ <property name="can_focus">True</property>
123
+ <property name="headers_visible">True</property>
124
+ <property name="rules_hint">False</property>
125
+ <property name="reorderable">False</property>
126
+ <property name="enable_search">True</property>
127
+ <signal name="cursor_changed" handler="on_filelist_cursor_changed" last_modification_time="Thu, 11 Mar 2004 09:20:43 GMT"/>
128
+ </widget>
129
+ </child>
130
+ </widget>
131
+ <packing>
132
+ <property name="shrink">True</property>
133
+ <property name="resize">True</property>
134
+ </packing>
135
+ </child>
136
+ </widget>
137
+ <packing>
138
+ <property name="padding">0</property>
139
+ <property name="expand">True</property>
140
+ <property name="fill">True</property>
141
+ </packing>
142
+ </child>
143
+
144
+ <child>
145
+ <widget class="GtkHBox" id="hbox3">
146
+ <property name="border_width">5</property>
147
+ <property name="visible">True</property>
148
+ <property name="homogeneous">False</property>
149
+ <property name="spacing">15</property>
150
+
151
+ <child>
152
+ <widget class="GtkButton" id="ok">
153
+ <property name="width_request">110</property>
154
+ <property name="visible">True</property>
155
+ <property name="can_focus">True</property>
156
+ <property name="label">gtk-ok</property>
157
+ <property name="use_stock">True</property>
158
+ <property name="relief">GTK_RELIEF_NORMAL</property>
159
+ </widget>
160
+ <packing>
161
+ <property name="padding">0</property>
162
+ <property name="expand">False</property>
163
+ <property name="fill">False</property>
164
+ <property name="pack_type">GTK_PACK_END</property>
165
+ </packing>
166
+ </child>
167
+
168
+ <child>
169
+ <widget class="GtkButton" id="cancel">
170
+ <property name="width_request">110</property>
171
+ <property name="visible">True</property>
172
+ <property name="can_focus">True</property>
173
+ <property name="label">gtk-cancel</property>
174
+ <property name="use_stock">True</property>
175
+ <property name="relief">GTK_RELIEF_NORMAL</property>
176
+ <signal name="clicked" handler="on_cancel_clicked" last_modification_time="Thu, 11 Mar 2004 08:03:12 GMT"/>
177
+ </widget>
178
+ <packing>
179
+ <property name="padding">0</property>
180
+ <property name="expand">False</property>
181
+ <property name="fill">False</property>
182
+ <property name="pack_type">GTK_PACK_END</property>
183
+ </packing>
184
+ </child>
185
+ </widget>
186
+ <packing>
187
+ <property name="padding">0</property>
188
+ <property name="expand">False</property>
189
+ <property name="fill">False</property>
190
+ </packing>
191
+ </child>
192
+ </widget>
193
+ </child>
194
+ </widget>
195
+
196
+ </glade-interface>
@@ -0,0 +1,173 @@
1
+ =begin header
2
+ draw.rb - a part of gave.rb
3
+ =end
4
+
5
+ require "numru/gphys"
6
+
7
+
8
+ module NumRu
9
+ class VArray
10
+ def mapping
11
+ @mapping
12
+ end
13
+ end
14
+ class SubsetMapping
15
+ def maps
16
+ @maps
17
+ end
18
+ end
19
+ class VArrayComposite
20
+ alias _initialize initialize
21
+ alias :_slice []
22
+ def initialize(*arg)
23
+ _initialize(*arg)
24
+ @mapping2 = SubsetMapping.new(shape_current,[])
25
+ end
26
+ def [](*arg)
27
+ mapping = @mapping2.composite(SubsetMapping.new(shape_current, arg))
28
+ obj = self._slice(*arg)
29
+ obj.set_mapping(mapping) if obj.class==VArrayComposite
30
+ obj
31
+ end
32
+ def mapping
33
+ @mapping2
34
+ end
35
+ def set_mapping(map)
36
+ @mapping2 = map
37
+ end
38
+ end
39
+ end
40
+
41
+
42
+ include NumRu
43
+
44
+
45
+ class Draw_data
46
+ attr_accessor :gphys, :gphys2
47
+ attr_accessor :cont, :cont_i
48
+ attr_accessor :tone, :tone_i
49
+ attr_accessor :vector
50
+ attr_accessor :transpose
51
+ attr_accessor :type, :map_type, :map_draw, :map_pole
52
+ attr_accessor :title
53
+ attr_accessor :surface
54
+ # attr_accessor :missing_value
55
+ attr_reader :axis_x, :axis_y, :axis_z
56
+ def initialize
57
+ @axis_x = Axis.new
58
+ @axis_y = Axis.new
59
+ @axis_z = Axis.new
60
+ clear
61
+ end
62
+ def clear_var
63
+ @gphys = nil
64
+ @gphys2 = nil
65
+ @transpose = false
66
+ @axis_x.clear
67
+ @axis_y.clear
68
+ end
69
+ def clear
70
+ clear_var
71
+ @title = nil
72
+ @type = LINE
73
+ @map_type = nil
74
+ end
75
+ class Axis
76
+ attr_accessor :min, :max
77
+ attr_accessor :title, :unit
78
+ attr_accessor :log
79
+ def initialize
80
+ clear
81
+ end
82
+ def clear
83
+ @title=""
84
+ @unit=""
85
+ @log=false
86
+ end
87
+ end
88
+ end
89
+
90
+
91
+
92
+
93
+
94
+ class Draw
95
+ def initialize(n)
96
+ @winno = n
97
+ @height=400
98
+ @width=400
99
+ clear
100
+ end
101
+ def clear
102
+ @type = nil
103
+ # @miss=nil
104
+ @title = nil
105
+ @x_title=""; @x_unit=""
106
+ @y_title=""; @y_unit=""
107
+ @fig = Fig.new
108
+ @opened = false
109
+ end
110
+ def show
111
+ @window.show if defined?(@window)&&(!@window.nil?)
112
+ end
113
+ def draw_x(draw_data)
114
+ @xmin = draw_data.axis_x.min
115
+ @xmax = draw_data.axis_x.max
116
+ @ymin = draw_data.axis_y.min
117
+ @ymax = draw_data.axis_y.max
118
+ @gphys = draw_data.gphys
119
+ @gphys2 = draw_data.gphys2
120
+ @mapping = draw_data.gphys.data.mapping.slicer
121
+ # @miss = draw_data.missing_value
122
+ @title = draw_data.title
123
+ @transpose = draw_data.transpose
124
+ @logx = draw_data.axis_x.log
125
+ @logy = draw_data.axis_y.log
126
+ @x_title = draw_data.axis_x.title
127
+ @x_unit = draw_data.axis_x.unit
128
+ @y_title = draw_data.axis_y.title
129
+ @y_unit = draw_data.axis_y.unit
130
+ @type = draw_data.type
131
+ @maptype = draw_data.map_type
132
+ @map_draw = draw_data.map_draw
133
+ @map_pole = draw_data.map_pole
134
+ @cont = draw_data.cont
135
+ @cont_i = draw_data.cont_i
136
+ @tone = draw_data.tone
137
+ @tone_i = draw_data.tone_i
138
+ @vector = draw_data.vector
139
+ @surface = draw_data.surface
140
+ @fig.var_set(@gphys.funcs,@mapping,0)
141
+ @fig.var_set(@gphys2.funcs,@mapping,1) if @type == VECTOR
142
+ @fig.title_set(@x_title,@x_unit,@y_title,@y_unit, __FILE__,__LINE__)
143
+ if @window.nil?
144
+ open_graphics
145
+ end
146
+ draw(@draw_area)
147
+ @window.show
148
+ end
149
+ def save_code(filename)
150
+ file = File.open(filename,"w")
151
+ file.print(@fig.head+"\n\n")
152
+ file.print(@fig.var+"\n\n")
153
+ file.print(@fig.open+"\n\n")
154
+ file.print(@fig.draw+"\n\n")
155
+ file.print(@fig.close+"\n\n")
156
+ file.close
157
+ end
158
+ def save_image(filename)
159
+ begin
160
+ save_image_file(filename)
161
+ p "save image to #{filename}"
162
+ rescue
163
+ dialog = Gtk::Dialog.new.set_title("Error Message")
164
+ dialog.set_modal(true)
165
+ dialog.vbox.pack_start(Gtk::Label.new($!))
166
+ ok_button=Gtk::Button.new("OK")
167
+ ok_button.signal_connect("clicked"){dialog.destroy}
168
+ dialog.action_area.pack_start(ok_button)
169
+ dialog.show_all
170
+ end
171
+ end
172
+
173
+ end
@@ -0,0 +1,574 @@
1
+ require "numru/gave/draw"
2
+ require "numru/dcl"
3
+
4
+
5
+ if defined?(DCL.gtk_version)
6
+ GAVE_GTK_VERSION = DCL.gtk_version[0]
7
+ else
8
+ GAVE_GTK_VERSION = 1
9
+ end
10
+
11
+
12
+
13
+ if GAVE_GTK_VERSION == 1
14
+ require "gdk_imlib"
15
+ def save_image_file(filename)
16
+ geom = @pixmap.get_geometry
17
+ mask = Gdk::Bitmap.new(@draw_area.window, geom[2], geom[3])
18
+ imlib = Gtk::imlib.new(@pixmax, mask)
19
+ imlib.save(filename)
20
+ end
21
+ module Gdk
22
+ class Window
23
+ def size; get_geometry[2..3]; end
24
+ def draw_drawable(*arg); draw_pixmap(*arg); end
25
+ end
26
+ class Event
27
+ BUTTON_PRESS_MASK = Gdk::BUTTON_PRESS_MASK
28
+ BUTTON_MOTION_MASK = Gdk::BUTTON_MOTION_MASK
29
+ BUTTON_RELEASE_MASK = Gdk::BUTTON_RELEASE_MASK
30
+ end
31
+ end
32
+ elsif GAVE_GTK_VERSION == 2
33
+ def save_image_file(filename)
34
+ pixbuf = Gdk::Pixbuf.from_drawable(nil, @pixmap, 0, 0, -1, -1)
35
+ pixbuf.save(filename, "png")
36
+ end
37
+ end
38
+
39
+
40
+
41
+ class Mouse_Events
42
+ MOVE = 1
43
+ RESIZE = 2
44
+ attr_writer :height, :width
45
+ def initialize(height,width)
46
+ @height=height
47
+ @width=width
48
+ end
49
+ def length; @height<@width ? @height : @width; end
50
+ def xoffset; (@width-length)/2; end
51
+ def yoffset; (@height-length)/2; end
52
+ def pressed(px,py,l,r,b,t)
53
+ @move = false
54
+ @left,@right,@bottom,@top, = l,r,b,t
55
+ @axis = where(px,py,l,r,b,t)
56
+ if @axis then
57
+ if @axis==4 then
58
+ @move=MOVE
59
+ @bpx,@bpy, = px,py
60
+ p "begin move" if $DEBUG
61
+ else
62
+ @move=RESIZE
63
+ p "begin resize" if $DEBUG
64
+ end
65
+ else
66
+ @move = false
67
+ end
68
+ end
69
+ def released(px,py)
70
+ print "released:",px,",",py,"\n" if $DEBUG
71
+ if @move==MOVE then
72
+ @move=false
73
+ p "end move" if $DEBUG
74
+ dx=px-@bpx
75
+ dy=py-@bpy
76
+ [@left+dx,@right+dx,@bottom+dy,@top+dy]
77
+ elsif @move==RESIZE then
78
+ @move=false
79
+ p "end resize" if $DEBUG
80
+ l,r,b,t, = @left,@right,@bottom,@top
81
+ @left=nil;@right=nil;@bottom=nil;@top=nil
82
+ @bpx=nil;@bpy=nil
83
+ set(px,py,l,r,b,t)
84
+ end
85
+ end
86
+ def draged(w,px,py)
87
+ if @move==MOVE then
88
+ gc = w.style.fg_gc(w.state)
89
+ x = (@left+px-@bpx)*length+xoffset
90
+ y = (1-@top-py+@bpy)*length+yoffset
91
+ xl = length*(@right-@left)
92
+ yl = length*(@top-@bottom)
93
+ w.window.draw_rectangle(gc, false, x, y, xl, yl)
94
+ elsif @move==RESIZE then
95
+ l,r,b,t, = set(px,py,@left,@right,@bottom,@top)
96
+ gc = w.style.fg_gc(w.state)
97
+ x = l*length+xoffset
98
+ y = (1-t)*length+yoffset
99
+ xl = length*(r-l)
100
+ yl = length*(t-b)
101
+ w.window.draw_rectangle(gc, false, x, y, xl, yl)
102
+ end
103
+ end
104
+ def where(px,py,l,r,b,t)
105
+ width = 0.01
106
+ if (px>l-width)&&(px<r+width)&&(py>b-width)&&(py<t+width) then
107
+ if (px-l).abs < width then 0
108
+ elsif (px-r).abs < width then 1
109
+ elsif (py-b).abs < width then 2
110
+ elsif (py-t).abs < width then 3
111
+ else 4
112
+ end
113
+ else
114
+ false
115
+ end
116
+ end
117
+ def move?
118
+ @move
119
+ end
120
+ def set(px,py,l,r,b,t)
121
+ diff=0.05
122
+ lo,ro,bo,to, = [l,r,b,t]
123
+ if @axis==0 then
124
+ if px<diff then
125
+ lo=diff
126
+ elsif px>(r-diff) then
127
+ lo=r-diff
128
+ else
129
+ lo=px
130
+ end
131
+ elsif @axis==1 then
132
+ if px>(1-diff) then
133
+ ro=1-diff
134
+ elsif px<(l+diff) then
135
+ ro=l+diff
136
+ else
137
+ ro=px
138
+ end
139
+ elsif @axis==2 then
140
+ if py<diff then
141
+ bo=diff
142
+ elsif py>(t-diff) then
143
+ bo=t-diff
144
+ else
145
+ bo=py
146
+ end
147
+ elsif @axis==3 then
148
+ if py>(1-diff) then
149
+ to=1-diff
150
+ elsif py<(b+diff) then
151
+ to=b+diff
152
+ else
153
+ to=py
154
+ end
155
+ end
156
+ [lo,ro,bo,to]
157
+ end
158
+ end
159
+
160
+
161
+
162
+ class Draw
163
+ alias :_initialize :initialize
164
+ def initialize(n)
165
+ _initialize(n)
166
+ @pixmap = nil
167
+ end
168
+ alias :_clear :clear
169
+ def clear
170
+ _clear
171
+ @vxmin=0.2; @vxmax=0.8
172
+ @vymin=0.2; @vymax=0.8
173
+ @frame = Mouse_Events.new(@height,@width)
174
+ end
175
+ def open_graphics
176
+ set_env
177
+ @draw_area = Gtk::DrawingArea.new
178
+ @draw_area.set_size_request(@width,@height)
179
+ @draw_area.signal_connect("expose-event"){|w,p| expose_event(w,p) }
180
+ @draw_area.signal_connect("configure-event"){|w,p|
181
+ configure_event(w)
182
+ @width = w.allocation.width; @frame.width=@width
183
+ @height = w.allocation.height; @frame.height=@height
184
+ }
185
+ @draw_area.signal_connect("button-press-event"){|w,p|
186
+ if p.button==1 then
187
+ px = (p.x-@frame.xoffset)/@frame.length
188
+ py = 1 - (p.y-@frame.yoffset)/@frame.length
189
+ print "press:",px,",",py,"\n" if $DEBUG
190
+ @frame.pressed(px,py,@vxmin,@vxmax,@vymin,@vymax)
191
+ else
192
+ w.get_toplevel.hide
193
+ end
194
+ }
195
+ @draw_area.signal_connect("button-release-event"){|w,p|
196
+ px = (p.x-@frame.xoffset)/@frame.length
197
+ py = 1 - (p.y-@frame.yoffset)/@frame.length
198
+ if @frame.move?
199
+ @vxmin,@vxmax,@vymin,@vymax, = @frame.released(px,py)
200
+ draw(w)
201
+ end
202
+ }
203
+ @draw_area.signal_connect("motion-notify-event"){|w,p|
204
+ px = (p.x-@frame.xoffset)/@frame.length
205
+ py = 1 - (p.y-@frame.yoffset)/@frame.length
206
+ if @frame.move?
207
+ expose_event(w)
208
+ @frame.draged(w,px,py)
209
+ end
210
+ }
211
+ @draw_area.set_events(Gdk::Event::BUTTON_PRESS_MASK|Gdk::Event::BUTTON_MOTION_MASK|Gdk::Event::BUTTON_RELEASE_MASK)
212
+ aspect_frame = Gtk::AspectFrame.new(nil,0,0,1,true)
213
+ aspect_frame.add(@draw_area)
214
+ @window = Gtk::Window.new(TOPLEVEL).set_resizable(true)
215
+ @window.signal_connect("delete-event"){|w,p| w.hide; true}
216
+ @window.signal_connect("destroy"){exit}
217
+ @window.signal_connect("key-press-event"){|w,e|
218
+ key = Gdk::Keyval.to_name(e.keyval)
219
+ p key+" key press" if $DEBUG
220
+ if key=="q" then
221
+ w.hide
222
+ elsif key=="space" || key=="Return" then
223
+ $main.draw_next
224
+ end
225
+ }
226
+ @window.add(aspect_frame.show_all)
227
+ names = @gphys.funcs[0]
228
+ @window.set_title("#{@winno}: #{names[2]}@#{names[0]}")
229
+ @window.show
230
+ end
231
+
232
+ private
233
+ def set_env
234
+ DCL::swlset("LWAIT", false )
235
+ @fig.parm_set('DCL::sglset("LCNTL", false )', __FILE__,__LINE__)
236
+ @fig.parm_set('DCL::udlset("LMSG", false )', __FILE__,__LINE__)
237
+ @fig.parm_set('DCL::uglset("LMSG", false )', __FILE__,__LINE__)
238
+ @fig.parm_set('DCL::gllset("LMISS", true )', __FILE__,__LINE__)
239
+ end
240
+
241
+ private
242
+ def axis
243
+ @fig.figure_set('DCL::ussttl(x_title, x_unit, y_title, y_unit)', __FILE__,__LINE__)
244
+ @fig.figure_set('DCL::usdaxs', __FILE__,__LINE__)
245
+ @fig.figure_set('DCL::sglset("LCLIP", false )', __FILE__,__LINE__)
246
+ i=0
247
+ @gphys.lost_axes.each{|info|
248
+ @fig.figure_set("i=#{i}", __FILE__,__LINE__)
249
+ @fig.figure_set("DCL::sgtxzr(vxmax+0.01,vymax-0.03*i,\"#{info}\",0.02,0,-1,1)", __FILE__,__LINE__)
250
+ i+=1
251
+ }
252
+ end
253
+
254
+ private
255
+ def draw_1d(title)
256
+ @fig.figure_set('DCL::sgplzu(gphys0.coord(0).val, gphys0.val, 1, 3 )', __FILE__,__LINE__)
257
+ axis
258
+ @fig.figure_set("title = \"#{title}\"", __FILE__,__LINE__)
259
+ @fig.figure_set('DCL::uxsttl("t", title, 0 )', __FILE__,__LINE__)
260
+ end
261
+
262
+ private
263
+ def draw_2d(title,type)
264
+ if @transpose then
265
+ x = 1
266
+ y = 0
267
+ else
268
+ x = 0
269
+ y = 1
270
+ end
271
+
272
+ @fig.figure_set("DCL::uwsgxa(gphys0.coord(#{x}).val)", __FILE__,__LINE__)
273
+ @fig.figure_set("DCL::uwsgya(gphys0.coord(#{y}).val)", __FILE__,__LINE__)
274
+ @fig.figure_set('DCL::ueitlv', __FILE__,__LINE__)
275
+
276
+ if type == CONTOUR || type == MAP
277
+ if @tone
278
+ if @tone_i.nil?
279
+ min = @gphys.val.min
280
+ max = @gphys.val.max
281
+ dm = 0
282
+ else
283
+ min,dm = @tone_i
284
+ max = min+dm*(50-1)
285
+ end
286
+ if min!=max then
287
+ @fig.figure_set("DCL::uegtla(#{min}, #{max}, #{dm} )", __FILE__,__LINE__)
288
+ end
289
+ if @transpose
290
+ @fig.figure_set("DCL::#{@tone}(gphys0.val.transpose(#{x},#{y}))", __FILE__,__LINE__)
291
+ else
292
+ @fig.figure_set("DCL::#{@tone}(gphys0.val)", __FILE__,__LINE__)
293
+ end
294
+ end
295
+ if @cont
296
+ if @cont_i.nil?
297
+ min = @gphys.val.min
298
+ max = @gphys.val.max
299
+ dm = 0
300
+ else
301
+ min,dm = @cont_i
302
+ max = min+dm*(50-1)
303
+ end
304
+ if min!=max then
305
+ @fig.figure_set("DCL::udgcla(#{min}, #{max}, #{dm} )", __FILE__,__LINE__)
306
+ end
307
+ end
308
+ if @transpose
309
+ @fig.figure_set("DCL::udcntz(gphys0.val.transpose(#{x},#{y}))", __FILE__,__LINE__)
310
+ else
311
+ @fig.figure_set("DCL::udcntz(gphys0.val)", __FILE__,__LINE__)
312
+ end
313
+ elsif type == VECTOR
314
+ if @vector
315
+ @fig.figure_set("DCL::uglset('lnrmal', false)", __FILE__,__LINE__)
316
+ @fig.figure_set("DCL::ugrset('xfact1', #{@vector[0]})", __FILE__,__LINE__)
317
+ @fig.figure_set("DCL::ugrset('yfact1', #{@vector[1]})", __FILE__,__LINE__)
318
+ end
319
+ if @transpose
320
+ @fig.figure_set("DCL::ugvect(gphys0.val.transpose(#{x},#{y}), gphys1.val.transpose(#{x},#{y}))", __FILE__,__LINE__)
321
+ else
322
+ @fig.figure_set("DCL::ugvect(gphys0.val, gphys1.val)", __FILE__,__LINE__)
323
+ end
324
+ end
325
+ if type==CONTOUR || type==VECTOR then
326
+ axis
327
+ @fig.figure_set('DCL::uzrset("ROFFXT", 0.06)', __FILE__,__LINE__)
328
+ @fig.figure_set("title = \"#{title}\"", __FILE__,__LINE__)
329
+ @fig.figure_set('DCL::uxsttl("t", title, 0 )', __FILE__,__LINE__)
330
+ elsif type==MAP then
331
+ @fig.figure_set("DCL::umpglb", __FILE__,__LINE__)
332
+ if @map_draw
333
+ @fig.figure_set('DCL::umpmap("coast_world")', __FILE__,__LINE__)
334
+ end
335
+ @fig.figure_set('DCL::sglset("LCLIP", false )', __FILE__,__LINE__)
336
+ @fig.figure_set("title = \"#{title}\"", __FILE__,__LINE__)
337
+ @fig.figure_set("DCL::sgtxzv((vxmax+vxmin)/2,vymax+0.02,title,0.02,0.0,0,2)", __FILE__,__LINE__)
338
+ @fig.figure_set('DCL::sglset("LCLIP", true )', __FILE__,__LINE__)
339
+ end
340
+ end
341
+
342
+ private
343
+ def draw(drawing_area)
344
+ @fig.window_set(@xmin,@xmax,@ymin,@ymax, __FILE__,__LINE__)
345
+ @fig.viewport_set(@vxmin,@vxmax,@vymin,@vymax, __FILE__,__LINE__)
346
+ @fig.frame_clear
347
+ @fig.figure_clear
348
+ if @type == MAP then
349
+ itr = @maptype
350
+ lon,lat,rot = @map_pole
351
+ @fig.frame_set("DCL::grfrm", __FILE__,__LINE__)
352
+ @fig.frame_set("DCL::grsvpt(vxmin,vxmax,vymin,vymax)", __FILE__,__LINE__)
353
+ @fig.frame_set("DCL::grswnd(xmin,xmax,ymin,ymax)", __FILE__,__LINE__)
354
+ @fig.frame_set("DCL::grsmpl(#{lon},#{lat},#{rot})", __FILE__,__LINE__)
355
+ @fig.frame_set("DCL::grstrn(#{itr})", __FILE__,__LINE__)
356
+ @fig.frame_set("DCL::umpfit", __FILE__,__LINE__)
357
+ @fig.frame_set("DCL::grstrf", __FILE__,__LINE__)
358
+ else
359
+ itr = 1
360
+ itr += 2 if @logx; itr += 1 if @logy
361
+ @fig.frame_set("DCL::grfrm", __FILE__,__LINE__)
362
+ @fig.frame_set("DCL::grswnd(xmin,xmax,ymin,ymax)", __FILE__,__LINE__)
363
+ @fig.frame_set("DCL::grsvpt(vxmin,vxmax,vymin,vymax)", __FILE__,__LINE__)
364
+ @fig.frame_set("DCL::grstrn(#{itr})", __FILE__,__LINE__)
365
+ @fig.frame_set("DCL::grstrf", __FILE__,__LINE__)
366
+ end
367
+ @fig.figure_set('DCL::sglset("LCLIP", true )', __FILE__,__LINE__)
368
+ if @type == LINE then
369
+ draw_1d(@title)
370
+ elsif @type==CONTOUR || @type==MAP || @type==VECTOR then
371
+ draw_2d(@title,@type)
372
+ end
373
+ DCL::zgsdrw(drawing_area)
374
+ DCL::zgspmp(@pixmap)
375
+ reset
376
+ gphys0 = @gphys
377
+ gphys1 = @gphys2 if @type==VECTOR
378
+ codes = @fig.draw_eval
379
+ for j in 0...codes.length
380
+ eval *codes[j]
381
+ end
382
+ expose_event(drawing_area)
383
+ end
384
+
385
+ private
386
+ def reset
387
+ wsxmn,wsxmx,wsymn,wsymx,fact = DCL::swqrct
388
+ DCL::stswrc(wsxmn,wsxmx,wsymn,wsymx)
389
+ DCL::slinit(wsxmx-wsxmn,wsymx-wsymn,fact)
390
+ end
391
+
392
+ def expose_event(widget,event=nil)
393
+ if ! @pixmap.nil?
394
+ gc = widget.style.fg_gc(widget.state)
395
+ if event.nil?
396
+ size = widget.window.size
397
+ x0, y0 = [0, 0]
398
+ width, height = size
399
+ else
400
+ area = event.area
401
+ x0, y0 = [area.x, area.y]
402
+ width, height = [area.width, area.height]
403
+ end
404
+ widget.window.draw_drawable(gc, @pixmap, x0, y0, x0, y0, width, height)
405
+ end
406
+ false
407
+ end
408
+
409
+ private
410
+ def configure_event(widget)
411
+ size = widget.window.size
412
+ if (size[0]>0 && size[1]>0) then
413
+ @pixmap = Gdk::Pixmap.new(widget.window, size[0], size[1], -1)
414
+ @pixmap.draw_rectangle(widget.style.white_gc, true, 0, 0, size[0], size[1])
415
+ end
416
+ DCL::zgsdrw(widget)
417
+ DCL::zgspmp(@pixmap)
418
+ if !@opened then
419
+ DCL::sgopn(4)
420
+ @opened = true
421
+ else
422
+ reset
423
+ end
424
+ draw(widget)
425
+ true
426
+ end
427
+
428
+ private
429
+ class Fig
430
+ attr_reader :head, :var, :open, :close
431
+ def initialize
432
+ @head = ""
433
+ @var = ""
434
+ @open = ""
435
+ @window = Array.new
436
+ @viewport = Array.new
437
+ @title = Array.new
438
+ @parm = Array.new
439
+ @frame = Array.new
440
+ @figure = Array.new
441
+ @close = ""
442
+ if GAVE_GTK_VERSION == 1
443
+ @head = "require \"gtk\""
444
+ elsif GAVE_GTK_VERSION == 2
445
+ @head = "require \"gtk2\""
446
+ end
447
+ @head = <<"END"
448
+ require "numru/gphys"
449
+ require "numru/dcl"
450
+
451
+ include NumRu
452
+ END
453
+ @open = "DCL::gropn(1)"
454
+ ymin=@ymin; ymax=@ymax
455
+ vxmin=@vxmin; vxmax=@vxmax
456
+ vymin=@vymin; vymax=@vymax
457
+ @window[0] = "xmin = axisx[0]"
458
+ @window[1] = "xmax = axisx[-1]"
459
+ @window[2] = "ymin = 0.0"
460
+ @window[3] = "ymax = 1.0"
461
+ @viewport[0] = "vxmin = 0.2"
462
+ @viewport[1] = "vxmax = 0.8"
463
+ @viewport[2] = "vymin = 0.2"
464
+ @viewport[3] = "vymax = 0.8"
465
+ @title[0] = 'x_title = ""'
466
+ @title[1] = 'x_unit = ""'
467
+ @title[2] = 'y_title = ""'
468
+ @title[3] = 'y_unit = ""'
469
+ @close = "DCL::grcls"
470
+ end
471
+ def var_set(funcs,mapping,n)
472
+ @var = "" if n==0
473
+ filename, filetype, varname = funcs[0]
474
+ if filename.length==1
475
+ @var += "filename = \"#{filename[0]}\"\n"
476
+ else
477
+ @var += "filename = [\"#{filename.join('", "')}\"]\n"
478
+ end
479
+ @var += "varname = \"#{varname}\"\n"
480
+
481
+
482
+ if filetype.nil?
483
+ @var += "gphys#{n} = GPhys::IO.open(filename,varname)\n"
484
+ elsif filetype=="druby"
485
+ @var += "require \"drb/drb\"\n"
486
+ @var += "DRb.start_service\n"
487
+ @var += "class NArray\n"
488
+ @var += " def self._load(o) to_na(*Marshal::load(o)).ntoh end\n"
489
+ @var += "end\n"
490
+ @var += "ary = filename.split('/')\n"
491
+ @var += "host = 'druby://'+ary[2]\n"
492
+ @var += "path = ary[3..-1].join('/')\n"
493
+ @var += "tree = DRbObject.new(nil,host)\n"
494
+ @var += "gphys#{n} = tree.data(path)\n"
495
+ else
496
+ raise "filetype is invalid"
497
+ end
498
+
499
+ if funcs.length!=0
500
+ funcs[1..-1].each{|func|
501
+ @var += "gphys#{n} = gphys#{n}.cut(#{func[2].join(",")})\n"
502
+ @var += "gphys#{n} = gphys#{n}.#{func[0]}(#{func[1]})\n"
503
+ }
504
+ end
505
+ str = mapping.collect{|a|
506
+ if NArray===a
507
+ "NArray[#{a.to_a.join(",")}]"
508
+ else
509
+ a
510
+ end
511
+ }.join(",")
512
+ @var += "gphys#{n} = gphys#{n}[#{str}]\n"
513
+ end
514
+ def window_set(xmin,xmax,ymin,ymax, file,line)
515
+ @window[0] = "xmin = #{xmin}"
516
+ @window[1] = "xmax = #{xmax}"
517
+ @window[2] = "ymin = #{ymin}"
518
+ @window[3] = "ymax = #{ymax}"
519
+ @w_context = [file,line]
520
+ end
521
+ def viewport_set(vxmin,vxmax,vymin,vymax, file,line)
522
+ @viewport[0] = "vxmin = #{vxmin}"
523
+ @viewport[1] = "vxmax = #{vxmax}"
524
+ @viewport[2] = "vymin = #{vymin}"
525
+ @viewport[3] = "vymax = #{vymax}"
526
+ @v_context = [file,line]
527
+ end
528
+ def title_set(xt,xu,yt,yu, file,line)
529
+ @title[0] = "x_title = \"#{xt}\""
530
+ @title[1] = "x_unit = \"#{xu}\""
531
+ @title[2] = "y_title = \"#{yt}\""
532
+ @title[3] = "y_unit = \"#{yu}\""
533
+ @t_context = [file,line]
534
+ end
535
+ def parm_clear
536
+ @parm.clear
537
+ end
538
+ def parm_set(str,file,line)
539
+ @parm.push([str,file,line])
540
+ end
541
+ def frame_clear
542
+ @frame.clear
543
+ end
544
+ def frame_set(str,file,line)
545
+ @frame.push([str,file,line])
546
+ end
547
+ def figure_clear
548
+ @figure.clear
549
+ end
550
+ def figure_set(str,file,line)
551
+ @figure.push([str,file,line])
552
+ end
553
+ def draw_parm
554
+ end
555
+ def draw
556
+ [@window, @viewport, @title].collect{|a|
557
+ a.join("\n")
558
+ }.join("\n\n")+"\n\n"+
559
+ [@parm, @frame, @figure].collect{|a|
560
+ a.collect{|c| c[0]}.join("\n")
561
+ }.join("\n\n")
562
+ end
563
+ def draw_eval
564
+ codes = Array.new
565
+ @window.each{|c| codes.push [c, nil, *@w_context]}
566
+ @viewport.each{|c| codes.push [c, nil, *@v_context]}
567
+ @title.each{|c| codes.push [c, nil, *@t_context]}
568
+ [@parm, @frame, @figure].each{|a|
569
+ a.each{|c| codes.push [c[0], nil, c[1], c[2]]}
570
+ }
571
+ codes
572
+ end
573
+ end
574
+ end