Class: TECSCDE::View::MainView

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/tecscde/view/main_view.rb

Overview

MainView class

Constant Summary collapse

@@colors =

colors

nil
@@colormap =
nil

Constants included from Constants

Constants::ALIGN_CENTER, Constants::ALIGN_LEFT, Constants::ALIGN_RIGHT, Constants::CELLTYPE_NAME, Constants::CELL_NAME, Constants::CELL_NAME_L, Constants::CHAR_A, Constants::CHAR_Z, Constants::CHAR__, Constants::CURSOR_JOINING, Constants::CURSOR_JOIN_OK, Constants::CURSOR_NORMAL, Constants::CURSOR_PORT, Constants::Color_editable, Constants::Color_editable_cell, Constants::Color_highlight, Constants::Color_incomplete, Constants::Color_uneditable, Constants::Color_unjoin, Constants::DPI, Constants::GAP_ACTIVE, Constants::GAP_PORT, Constants::PAPER_COMMENT, Constants::PAPER_MARGIN, Constants::PORT_NAME, Constants::SCALE, Constants::SCALE_HEIGHT, Constants::SCALE_VAL_INI, Constants::SCALE_VAL_MAX, Constants::SCALE_VAL_MIN, Constants::SIGNATURE_NAME, Constants::TEXT_HORIZONTAL, Constants::TEXT_VERTICAL, Constants::TRIANGLE_HEIGHT, Constants::TRIANGLE_LEN

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, control) ⇒ MainView

Returns a new instance of MainView.



125
126
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/tecscde/view/main_view.rb', line 125

def initialize(model, control)
  @model = model
  @control = control
  @paper = :A3L
  @b_emphasize_cell_name = false
  @b_color_by_region = false
  MainView.setup_colormap

  @main_window = Gtk::Window.new(Gtk::Window::TOPLEVEL)
  @main_window_width = width = 900
  @main_window_height = height = 600
  @main_window.title = "TECSCDE - TECS Component Diagram Editor"
  @main_window.set_default_size(width, height)
  @main_window.sensitive = true
  @main_window.signal_connect("delete-event") do |_window, *_args|
    TECSCDE.quit(@model, @main_window)
    true
  end
  # KEY-PRESS event action
  @main_window.signal_connect("key-press-event") do |_win, event|
    if @entry_win.visible?
      # while cell name editing, send forward to Entry window
      event.set_window(@entry_win.window)
      event.put
    else
      @control.key_pressed(event.keyval & 0xff, event.state)
    end
  end
  @main_window.signal_connect("focus-in-event") do |win, event|
    # p "event:#{event.class} in"
  end
  @main_window.signal_connect("focus-out-event") do |win, event|
    # p "event:#{event.class} out"
  end
  @main_window.signal_connect("grab-broken-event") do |win, event|
    # p "event:#{event.class}"
  end
  @main_window.signal_connect("grab-focus") do |win|
    # p "event:grab-focus"
  end
  @main_window.signal_connect("grab-notify") do |win, arg1|
    # p "event:grab-notify"
  end

  create_hscale
  create_hbox

  @vbox = Gtk::VBox.new
  # @vbox.set_resize_mode Gtk::RESIZE_IMMEDIATE
  # p @vbox.resize_mode
  @main_window.add(@vbox)

  @scrolled_window = Gtk::ScrolledWindow.new
  # @scrolled_window.signal_connect("expose_event") { |win, evt|
  #   gdkWin = @scrolled_window.window
  #   gc = Gdk::GC.new gdkWin
  #   gdkWin.draw_rectangle( gc, true, 0, 0, 10000, 10000 )
  # }

  @vbox.pack_start(@scrolled_window)
  @vbox.pack_end(@hbox, false) # expand = false

  create_canvas
  @scrolled_window.set_size_request(width, height - SCALE_HEIGHT)

  @main_window.show_all

  create_edit_window
end

Class Method Details

.setup_colormapObject



1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
# File 'lib/tecscde/view/main_view.rb', line 1077

def self.setup_colormap
  if !@@colors.nil?
    return
  end

  @@colors = {}
  @@colormap = Gdk::Colormap.system

  [
    :black, :white, :gray, :yellow, :orange, :skyblue, :magenta, :red, :blue, :green,
    :cyan, :brown, :violet, :lavender, :MistyRose, :lightyellow, :LightCyan, :Beige,
    :PapayaWhip, :Violet, :pink
  ].each do |color_name|
    setup_colormap_1 color_name
  end
  setup_colormap_2(:ultraLightGreen, Gdk::Color.new(0xE000, 0xFF00, 0xE000))
  setup_colormap_1(Color_editable_cell)

  @@cell_paint_colors = [
    :MistyRose, :lightyellow, :LightCyan, :ultraLightGreen, :lavender, :Beige,
    :PapayaWhip, :Violet, :pink
  ]
  # plum: light purble (pastel)
  # pink: light magenta (pastel)
  # lavender: light blue (pastel)
  # lightyellow: light yellow (pastel)
  @@cell_paint_color_index = 0
  @@cell_file_to_color = {}
end

.setup_colormap_1(name) ⇒ Object



1107
1108
1109
1110
# File 'lib/tecscde/view/main_view.rb', line 1107

def self.setup_colormap_1(name)
  color = Gdk::Color.parse(name.to_s)
  setup_colormap_2(name, color)
end

.setup_colormap_2(name, color) ⇒ Object



1112
1113
1114
1115
# File 'lib/tecscde/view/main_view.rb', line 1112

def self.setup_colormap_2(name, color)
  @@colors[name] = color
  @@colormap.alloc_color(color, false, true)
end

Instance Method Details

#begin_edit_name(cell, time) ⇒ Object



996
997
998
999
1000
1001
1002
1003
1004
# File 'lib/tecscde/view/main_view.rb', line 996

def begin_edit_name(cell, time)
  @entry.set_text(cell.get_name)

  x, y, w, h = get_cell_name_edit_area(cell)
  # p "x=#{x} y=#{y} w=#{w} h=#{h}"
  @entry_win.window.move(x - 3, y - 6)    # Gdk level operation
  @entry_win.window.resize(w + 6, h + 8)  # Gdk level operation
  @entry_win.show_all
end

#canvas_gc_resetObject

—— handle CanvasGC ——#



1061
1062
1063
1064
1065
1066
1067
1068
1069
# File 'lib/tecscde/view/main_view.rb', line 1061

def canvas_gc_reset
  @canvas_gc.function = Gdk::GC::COPY
  @canvas_gc.fill = Gdk::GC::SOLID
  @canvas_gc.foreground = @@colors[Color_editable]

  @cairo_context_target.restore
  @cairo_context_target.save # prepare for next time
  @cairo_context_target.matrix = @cairo_matrix
end

#canvas_gc_set_line_width(width) ⇒ Object



1071
1072
1073
1074
1075
# File 'lib/tecscde/view/main_view.rb', line 1071

def canvas_gc_set_line_width(width)
  line_attr = @canvas_gc.line_attributes
  line_attr[0] = width
  @canvas_gc.set_line_attributes(*line_attr)
end

#clear_canvas_pixmapObject



309
310
311
312
313
314
315
316
# File 'lib/tecscde/view/main_view.rb', line 309

def clear_canvas_pixmap
  @canvas_gc.function = Gdk::GC::SET
  @canvas_gc.fill = Gdk::GC::SOLID
  @canvas_gc.foreground = Gdk::Color.new(255, 255, 255)
  @canvas_pixmap.draw_rectangle(@canvas_gc, true, 0, 0, @canvas_width, @canvas_height)
  canvas_gc_reset
  # p "color = #{@canvas_gc.foreground.red}, #{@canvas_gc.foreground.green}, #{@canvas_gc.foreground.blue}"
end

#create_canvasObject

create canvas



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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/tecscde/view/main_view.rb', line 202

def create_canvas
  @canvas = Canvas.new
  resize_canvas
  TECSCDE.logger.debug("canvas width=#{@canvas_width}, height=#{@canvas_height}")

  # BUTTON PRESS event action
  @canvas.signal_connect("button-press-event") do |_canvas, event| # canvas = @canvas
    TECSCDE.logger.debug("pressed #{event}")
    xd, yd = event.coords
    xm = dot2mm(xd)
    ym = dot2mm(yd)

    case event.event_type
    when Gdk::Event::BUTTON_PRESS   # single click or before ddouble, triple click
      click_count = 1
    when Gdk::Event::BUTTON2_PRESS  # double click
      click_count = 2
    when Gdk::Event::BUTTON3_PRESS  # triple click
      click_count = 3
    else
      click_count = 1
    end
    @control.pressed_on_canvas(xm, ym, event.state, event.button, event.time, click_count)
  end
  # BUTTON RELEASE event action
  @canvas.signal_connect("button-release-event") do |_canvas, event|
    TECSCDE.logger.debug("released #{event}")
    xd, yd = event.coords
    xm = dot2mm(xd)
    ym = dot2mm(yd)
    @control.released_on_canvas(xm, ym, event.state, event.button)
  end
  # MOTION event action
  @canvas.signal_connect("motion-notify-event") do |_canvas, event|
    TECSCDE.logger.debug("motion #{event}")
    xd, yd = event.coords
    xm = dot2mm(xd)
    ym = dot2mm(yd)
    @control.motion_on_canvas(xm, ym, event.state)
  end
  # EXPOSE event action
  @canvas.signal_connect("expose_event") do |_win, _evt|
    refresh_canvas
  end

  # add events to receive
  @canvas.add_events(Gdk::Event::POINTER_MOTION_MASK |
                      Gdk::Event::BUTTON_PRESS_MASK  |
                      Gdk::Event::BUTTON_RELEASE_MASK |
                      Gdk::Event::PROPERTY_CHANGE_MASK |
                      Gdk::Event::KEY_PRESS_MASK)

  @scrolled_window.add_with_viewport(@canvas)
  # it seems that gdkWindow is nil before window.show or realize
  @canvas.realize
  @gdk_window = @canvas.window
  @canvas_gc = Gdk::GC.new(@gdk_window)

  # prepare pixmap (buffer for canvas)
  #  pixmap cannot be resized, so we have the largest one at initial.
  @canvas_pixmap = Gdk::Pixmap.new(@gdk_window,
                                   @canvas_width  * SCALE_VAL_MAX / SCALE_VAL_INI,
                                   @canvas_height * SCALE_VAL_MAX / SCALE_VAL_INI,
                                   @gdk_window.depth)
  # @draw_target = @canvas_pixmap
  @cairo_context_pixmap = @canvas_pixmap.create_cairo_context
  @cairo_context_pixmap.save
  # @cairo_context_win = @gdk_window.create_cairo_context
  # @cairo_context_win.save
  @cairo_context_target = @cairo_context_pixmap
  @cairo_matrix = TECSCDE::View::CairoMatrix.new

  # prepare text renderer
  @pango_context = Gdk::Pango.context
  @pango_layout = Pango::Layout.new(@pango_context)
  @pango_matrix = Pango::Matrix.new.rotate!(90)
end

#create_edit_windowObject

———- Cell name editor ———#



982
983
984
985
986
987
988
989
990
991
992
993
994
# File 'lib/tecscde/view/main_view.rb', line 982

def create_edit_window
  @entry = Gtk::Entry.new
  @entry.set_has_frame(true)

  @entry_win = Gtk::Window.new(Gtk::Window::TOPLEVEL)
  @entry_win.add(@entry)
  @entry_win.realize
  @entry_win.window.reparent(@canvas.window, 0, 0) # Gdk level operation

  # these steps are to avoid to move ( 0, 0 ) at 1st appear
  @entry_win.show_all
  @entry_win.hide
end

#create_hboxObject

—— HBox ——#



337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/tecscde/view/main_view.rb', line 337

def create_hbox
  @hbox = Gtk::HBox.new
  #----- emphasize_cell_name button -----#
  @emphasize_cell_name_button = Gtk::ToggleButton.new("Emphasize Cell Name")
  @emphasize_cell_name_button.signal_connect("toggled") do |button|
    @b_emphasize_cell_name = button.active?
    paint_canvas
  end
  @hbox.pack_start(@emphasize_cell_name_button)

  #----- color by region button -----#
  # @color_by_region_button = Gtk::ToggleButton.new( "Color by Region" )
  @color_by_region_button = Gtk::CheckButton.new("Color by Region")
  @color_by_region_button.signal_connect("toggled") do |button|
    @b_color_by_region = button.active?
    # @color_by_region_button.label =  button.active? ? "Color by File" : "Color by Region"
    paint_canvas
  end
  @hbox.pack_start(@color_by_region_button)
  @hbox.pack_end(@hscale)
end

#create_hscaleObject

—— HScale ——#



360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/tecscde/view/main_view.rb', line 360

def create_hscale
  @scale_val = SCALE_VAL_INI
  @hscale = Gtk::HScale.new(SCALE_VAL_MIN, SCALE_VAL_MAX, 1)
  @hscale.set_digits(0) # 小数点以下
  @hscale.set_value(@scale_val)
  @hscale.set_size_request(@main_window_width, SCALE_HEIGHT)
  @hscale.signal_connect("value-changed") do |scale_self, _scroll_type|
    # set scale_val in the range [SCALE_VAL_MIN..SCALE_VAL_MAX]
    scale_val = scale_self.value
    if scale_val > SCALE_VAL_MAX
      scale_val = SCALE_VAL_MAX
    elsif scale_val < SCALE_VAL_MIN
      scale_val = SCALE_VAL_MIN
    end
    @scale_val = scale_val
    TECSCDE.logger.debug("scale_val=#{@scale_val}")

    resize_canvas
    paint_canvas
  end
end

#div_string(str) ⇒ Object

MainView#div_string

divide string near center at A-Z or ‘_’



1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
# File 'lib/tecscde/view/main_view.rb', line 1213

def div_string(str)
  len = str.length
  if len <= 4
    return [str, ""]
  end

  center = len / 2
  i = 0
  n = 0
  while (center / 2 > i) && (i < center) && !str[center + i].nil?
    char_i = str[center - i]
    char_j = str[center + i]
    if char_j == CHAR__ || (CHAR_A <= char_j && char_j <= CHAR_Z)
      n = center + i
      break
    elsif CHAR_A <= char_i && char_i <= CHAR_Z
      n = center - i
      break
    elsif char_i == CHAR__
      n = center - i + 1
      break
    end
    i += 1
  end
  if n > 0
    return [str[0, n], str[n, len]]
  else
    return [str[0, len / 2], str[len / 2, len]]
  end
end

#dot2mm(dot) ⇒ Object

convert dot to mm



1036
1037
1038
# File 'lib/tecscde/view/main_view.rb', line 1036

def dot2mm(dot)
  dot * 100 * 25.4 / DPI / @scale_val
end

#draw_bar_direct(bar) ⇒ Object

TView#draw_bar_direct

directly draw on Window



701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
# File 'lib/tecscde/view/main_view.rb', line 701

def draw_bar_direct(bar)
  draw_target_direct

  join = bar.get_join
  cport = join.cport
  bars = join.bars
  x, y = cport.get_position
  xm = mm2dot(x)
  ym = mm2dot(y)

  canvas_gc_set_line_width(2)

  bars.each do |bar2|
    if @control.highlighted_objects.include?(bar2)
      color = @@colors[Color_highlight]
    elsif join.editable?
      color = @@colors[Color_editable]
    else
      color = @@colors[Color_uneditable]
    end
    @canvas_gc.foreground = color
    @cairo_context_target.set_source_color(color)

    if bar2.horizontal?
      xm2 = mm2dot(bar2.get_position)
      @gdk_window.draw_line(@canvas_gc, xm, ym, xm2, ym)
      xm = xm2
    else # VBar
      ym2 = mm2dot(bar2.get_position)
      @gdk_window.draw_line(@canvas_gc, xm, ym, xm, ym2)
      ym = ym2
    end
  end

  canvas_gc_set_line_width(1)
  canvas_gc_reset

  draw_target_reset
end

#draw_cell(cell) ⇒ Object

—— Draw Contents on CANVAS ——#



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
# File 'lib/tecscde/view/main_view.rb', line 384

def draw_cell(cell)
  #----- calc position in dot -----#
  x, y, w, h = cell.get_geometry
  x1 = mm2dot(x)
  y1 = mm2dot(y)
  x2 = mm2dot(x + w)
  y2 = mm2dot(y + h)
  w1 = mm2dot(w)
  h1 = mm2dot(h)

  #----- paint cell -----#
  color = get_cell_paint_color(cell)
  # @canvas_gc.set_foreground color
  # @draw_target.draw_rectangle( @canvas_gc, true, x1, y1, w1, h1 )

  @cairo_context_target.rectangle(x1, y1, w1, h1)
  @cairo_context_target.set_source_color(color)
  @cairo_context_target.fill

  #----- setup color -----#
  if !cell.editable?
    # @canvas_gc.set_foreground @@colors[ Color_uneditable ]
    @cairo_context_target.set_source_color(@@colors[Color_uneditable])
  else
    # @canvas_gc.set_foreground @@colors[ Color_editable ]
    @cairo_context_target.set_source_color(@@colors[Color_editable])
  end

  #----- draw cell rect -----#
  # @draw_target.draw_rectangle( @canvas_gc, false, x1, y1, w1, h1 )
  # @cairo_context_target.rectangle(x1, y1, w1, h1)
  @cairo_context_target.rectangle(x1 + 0.5, y1 + 0.5, w1, h1)
  @cairo_context_target.set_line_width(1)
  @cairo_context_target.stroke

  gap = mm2dot(GAP_ACTIVE)
  gap = 2 if gap < 2 # if less than 2 dots, let gap 2 dots
  if cell.get_celltype&.is_active?
    # @draw_target.draw_rectangle( @canvas_gc, false, x1 + gap, y1 + gap, w1 - 2 * gap, h1 - 2 * gap )
    @cairo_context_target.rectangle(x1 + gap + 0.5, y1 + gap + 0.5, w1 - 2 * gap, h1 - 2 * gap)
    @cairo_context_target.set_line_width(1)
    @cairo_context_target.stroke
  end

  #----- draw entry ports triangle -----#
  cell.eports.each do |_name, eport|
    if !eport.array?
      draw_entry_port_triangle(eport)
    else
      if cell.editable? && eport.unsubscripted_array?
        # @canvas_gc.set_foreground @@colors[ :brown ]
        @cairo_context_target.set_source_color(@@colors[:brown])
      end
      # EPortArray
      eport.ports.each do |ep|
        draw_entry_port_triangle(ep)
      end
      if cell.editable? && eport.unsubscripted_array?
        # @canvas_gc.set_foreground @@colors[ Color_editable ]
        @cairo_context_target.set_source_color(@@colors[Color_editable])
      end
    end
  end

  #----- draw cell name & celltype name -----#
  cell_name = cell.get_name
  ct_name = cell.get_celltype.get_name
  label = cell_name.to_s + "\n" + ct_name.to_s
  unless cell.complete?
    # @canvas_gc.set_foreground @@colors[ Color_incomplete ]
    @cairo_context_target.set_source_color(@@colors[Color_incomplete])
  end
  # draw_text( x1 + w1/2, y1+h1/2, label, CELL_NAME, ALIGN_CENTER, TEXT_HORIZONTAL )

  if @b_emphasize_cell_name
    wmn, hmn = get_text_extent(cell_name.to_s, CELL_NAME_L, ALIGN_CENTER, TEXT_HORIZONTAL)
    if wmn > w
      s1, s2 = div_string(cell_name.to_s)
      draw_text(x1 + w1 / 2, y1 + h1 / 2 - mm2dot(hmn) / 2, s1, CELL_NAME_L, ALIGN_CENTER, TEXT_HORIZONTAL)
      draw_text(x1 + w1 / 2, y1 + h1 / 2 + mm2dot(hmn) / 2, s2, CELL_NAME_L, ALIGN_CENTER, TEXT_HORIZONTAL)
    else
      draw_text(x1 + w1 / 2, y1 + h1 / 2, cell_name.to_s, CELL_NAME_L, ALIGN_CENTER, TEXT_HORIZONTAL)
    end
  else
    wmn, hmn = get_text_extent(cell_name.to_s, CELL_NAME, ALIGN_CENTER, TEXT_HORIZONTAL)
    draw_text(x1 + w1 / 2, y1 + h1 / 2 + mm2dot(hmn) / 2, cell_name.to_s, CELL_NAME, ALIGN_CENTER, TEXT_HORIZONTAL)
    draw_text(x1 + w1 / 2, y1 + h1 / 2 - mm2dot(hmn) / 2, ct_name.to_s,   CELLTYPE_NAME, ALIGN_CENTER, TEXT_HORIZONTAL)
  end

  #----- draw port name -----#
  cell.cports.merge(cell.eports).each do |_name, port|
    if !port.array?
      set_port_color(port, cell)
      draw_port_name(port)
    else
      #--- prot array ---#
      port.ports.each do |pt|
        set_port_color pt, cell
        draw_port_name(pt)
      end
    end
  end

  canvas_gc_reset
end

#draw_cell_rect_direct(cell) ⇒ Object

TView#draw_cell_rect_direct

directly draw on Window highlighted cell rect



578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
# File 'lib/tecscde/view/main_view.rb', line 578

def draw_cell_rect_direct(cell)
  draw_target_direct

  #----- set line width -----#
  canvas_gc_set_line_width(2)
  # @cairo_context_target.set_line_width(2)

  #----- if uneditable change color ------#
  unless cell.editable?
    @canvas_gc.set_foreground(@@colors[Color_uneditable])
    # @cairo_context_target.set_source_color( @@colors[ Color_uneditable ] )
  end

  #----- calc position in dot -----#
  x, y, w, h = cell.get_geometry
  x1 = mm2dot(x)
  y1 = mm2dot(y)
  w1 = mm2dot(w)
  h1 = mm2dot(h)

  #----- draw cell rect -----#
  @gdk_window.draw_rectangle(@canvas_gc, false, x1, y1, w1, h1)
  # @cairo_context_target.rectangle(x1, y1, w1, h1)
  # @cairo_context_target.stroke

  #----- reset GC, line width -----#
  canvas_gc_reset
  canvas_gc_set_line_width(1)
  draw_target_reset
end

#draw_entry_port_triangle(eport) ⇒ Object



509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
# File 'lib/tecscde/view/main_view.rb', line 509

def draw_entry_port_triangle(eport)
  triangle_1_2 = mm2dot(TRIANGLE_LEN / 2)
  triangle_hi  = mm2dot(TRIANGLE_HEIGHT)
  x1, y1 = eport.get_position
  xe = mm2dot(x1)
  ye = mm2dot(y1)
  case eport.get_edge_side
  when TECSModel::EDGE_TOP
    points = [[xe - triangle_1_2, ye], [xe + triangle_1_2, ye], [xe, ye + triangle_hi]]
  when TECSModel::EDGE_BOTTOM
    points = [[xe - triangle_1_2, ye], [xe + triangle_1_2, ye], [xe, ye - triangle_hi]]
  when TECSModel::EDGE_LEFT
    points = [[xe, ye - triangle_1_2], [xe, ye + triangle_1_2], [xe + triangle_hi, ye]]
  when TECSModel::EDGE_RIGHT
    points = [[xe, ye - triangle_1_2], [xe, ye + triangle_1_2], [xe - triangle_hi, ye]]
  end
  # fill = true
  # @draw_target.draw_polygon( @canvas_gc, fill, points )
  @cairo_context_target.triangle(*points[0], *points[1], *points[2])
  @cairo_context_target.fill
end

#draw_highlight_objects(obj_list) ⇒ Object

TView#draw_highlight_objects



561
562
563
564
565
566
567
568
569
570
571
572
573
574
# File 'lib/tecscde/view/main_view.rb', line 561

def draw_highlight_objects(obj_list)
  obj_list.each do |obj|
    if obj.is_a?(TECSModel::TmCell)
      draw_cell_rect_direct(obj)
      # draw_target_direct
      # draw_cell(obj)
      # draw_target_reset
    elsif obj.is_a?(TECSModel::TmPort)
      draw_port_direct(obj)
    elsif obj.is_a?(TECSModel::TmJoinBar)
      draw_bar_direct(obj)
    end
  end
end

#draw_join(join) ⇒ Object



646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
# File 'lib/tecscde/view/main_view.rb', line 646

def draw_join(join)
  cport = join.cport
  eport = join.eport
  bars = join.bars
  x, y = cport.get_position
  xm = mm2dot(x) + 0.5
  ym = mm2dot(y) + 0.5

  #----- setup color -----#
  unless join.editable?
    # @canvas_gc.set_foreground @@colors[ Color_uneditable ]
    @cairo_context_target.set_source_color(@@colors[Color_uneditable])
  end

  @cairo_context_target.move_to(xm, ym)
  #----- draw bars -----#
  bars.each do |bar|
    if bar.horizontal?
      xm2 = mm2dot(bar.get_position) + 0.5
      # @draw_target.draw_line( @canvas_gc, xm, ym, xm2, ym )
      @cairo_context_target.line_to(xm2, ym)
      xm = xm2
    else # VBar
      ym2 = mm2dot(bar.get_position) + 0.5
      # @draw_target.draw_line( @canvas_gc, xm, ym, xm, ym2 )
      @cairo_context_target.line_to(xm, ym2)
      ym = ym2
    end
  end
  @cairo_context_target.set_line_width(1)
  @cairo_context_target.stroke

  #----- draw signature name -----#
  if eport.get_joins[0] == join
    # draw only 1st entry port join

    if (eport.get_subscript.nil? || eport.get_subscript == 0) &&
        (join.cport.get_subscript.nil? || join.cport.get_subscript == 0)

      if bars[2].vertical?
        xm = mm2dot((bars[1].get_position + bars[3].get_position) / 2)
        ym = mm2dot(bars[2].get_position + 2)
      else
        xm = mm2dot((bars[0].get_position + bars[2].get_position) / 2)
        ym = mm2dot(bars[1].get_position + 2)
      end
      draw_text(xm, ym, join.get_signature.get_name.to_s, SIGNATURE_NAME, ALIGN_CENTER, TEXT_HORIZONTAL)
    end
  end

  canvas_gc_reset
end

#draw_port_direct(port) ⇒ Object



609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
# File 'lib/tecscde/view/main_view.rb', line 609

def draw_port_direct(port)
  draw_target_direct

  #----- set line width -----#
  @canvas_gc.set_foreground(@@colors[Color_highlight])
  # @cairo_context_target.set_source_color( @@colors[ Color_highlight ] )
  draw_port_name(port)

  if port.is_a?(TECSModel::TmEPort)
    draw_entry_port_triangle(port)
  end

  canvas_gc_set_line_width(2)
  x, y = port.get_position
  x1 = x2 = mm2dot(x)
  y1 = y2 = mm2dot(y)
  case port.get_edge_side
  when TECSModel::EDGE_TOP
    y1 -= 20
  when TECSModel::EDGE_BOTTOM
    y2 += 20
  when TECSModel::EDGE_LEFT
    x1 -= 20
  when TECSModel::EDGE_RIGHT
    x2 += 20
  end
  @gdk_window.draw_line(@canvas_gc, x1, y1, x2, y2)
  # @cairo_context_target.move_to( x1, y1 )
  # @cairo_context_target.line_to( x2, y2 )

  #----- reset GC, line width -----#
  canvas_gc_reset
  canvas_gc_set_line_width(1)

  draw_target_reset
end

#draw_port_name(port) ⇒ Object



531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
# File 'lib/tecscde/view/main_view.rb', line 531

def draw_port_name(port)
  x1, y1 = port.get_position
  xp = mm2dot(x1)
  yp = mm2dot(y1)
  case port.get_edge_side
  when TECSModel::EDGE_TOP
    alignment = ALIGN_LEFT
    direction = TEXT_VERTICAL
  when TECSModel::EDGE_BOTTOM
    alignment = ALIGN_RIGHT
    direction = TEXT_VERTICAL
  when TECSModel::EDGE_LEFT
    alignment = ALIGN_RIGHT
    direction = TEXT_HORIZONTAL
  when TECSModel::EDGE_RIGHT
    xp += 2
    alignment = ALIGN_LEFT
    direction = TEXT_HORIZONTAL
  end
  name = port.get_name.to_s
  subscript = port.get_subscript
  if subscript
    if subscript >= 0
      name += "[#{subscript}]"
    end
  end
  draw_text(xp, yp, name, PORT_NAME, alignment, direction)
end

#draw_target_directObject

TmView#draw_target_direct

change draw target to Window



324
325
326
327
# File 'lib/tecscde/view/main_view.rb', line 324

def draw_target_direct
  # @draw_target = @gdk_window
  # @cairo_context_target = @cairo_context_win
end

#draw_target_resetObject

TmView#draw_target_reset

reset draw target to canvasPixmap



331
332
333
334
# File 'lib/tecscde/view/main_view.rb', line 331

def draw_target_reset
  # @draw_target = @canvas_pixmap
  # @cairo_context_target = @cairo_context_pixmap
end

#draw_text(x, y, text, obj_type, alignment, direction) ⇒ Object

x::Integer(dot) y::Integer(dot) obj_type::CELL_NAME, SIGNATURE_NAME, PORT_NAME alignment::ALIGN_CENTER, ALIGN_LEFT



776
777
778
779
780
781
782
# File 'lib/tecscde/view/main_view.rb', line 776

def draw_text(x, y, text, obj_type, alignment, direction)
  if direction == TEXT_VERTICAL
    draw_text_v(x, y, text, obj_type, alignment)
  else
    draw_text_h(x, y, text, obj_type, alignment)
  end
end

#draw_text_h(x, y, text, obj_type, alignment) ⇒ Object



784
785
786
787
788
# File 'lib/tecscde/view/main_view.rb', line 784

def draw_text_h(x, y, text, obj_type, alignment)
  # draw_text_h_gdk( x, y, text, obj_type, alignment )
  draw_text_h_cairo(x, y, text, obj_type, alignment)
  # draw_text_h_cairo_pango( x, y, text, obj_type, alignment )
end

#draw_text_h_cairo(x, y, text, obj_type, alignment) ⇒ Object

—– Cairo version —–#



826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
# File 'lib/tecscde/view/main_view.rb', line 826

def draw_text_h_cairo(x, y, text, obj_type, alignment)
  cr = @cairo_context_target
  cr.select_font_face(nil, # "courier", # font_family = "Times New Roman",
                      Cairo::FONT_SLANT_NORMAL,
                      Cairo::FONT_WEIGHT_NORMAL)
  cr.set_font_size(font_size(obj_type) / 1000)
  cr_te = cr.text_extents(text)
  # p "width=#{cr_te.width} x_bearing=#{cr_te.x_bearing} height=#{cr_te.height} y_bearing=#{cr_te.y_bearing}"
  case alignment
  when ALIGN_CENTER
    # calc text draww postion
    x2 = x - (cr_te.width + cr_te.x_bearing) / 2
    y2 = y - cr_te.y_bearing / 2
  when ALIGN_RIGHT
    x2 = x - cr_te.width - cr_te.x_bearing - mm2dot(GAP_PORT)
    y2 = y - cr_te.height - cr_te.y_bearing - 2
  when ALIGN_LEFT
    x2 = x + mm2dot(GAP_PORT)
    y2 = y - cr_te.height - cr_te.y_bearing - 2
  end
  cr.move_to(x2, y2)
  cr.show_text(text)
end

#draw_text_h_cairo_pango(x, y, text, obj_type, alignment) ⇒ Object

—– Cairo Pango version —–#



851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
# File 'lib/tecscde/view/main_view.rb', line 851

def draw_text_h_cairo_pango(x, y, text, obj_type, alignment)
  cr = @cairo_context_target
  # pfd = Pango::FontDescription.new( "Times" )
  pfd = Pango::FontDescription.new
  pfd.absolute_size = font_size(obj_type)
  plo = cr.create_pango_layout
  plo.font_description = pfd
  plo.alignment = alignment
  plo.set_text(text)
  rect2 = plo.get_pixel_extents[1]

  case alignment
  when ALIGN_CENTER
    # calc text draww postion
    x2 = x - rect2.rbearing / 2
    y2 = y - rect2.descent / 2
  when ALIGN_RIGHT
    x2 = x - rect2.rbearing - mm2dot(GAP_PORT)
    y2 = y - rect2.descent
  when ALIGN_LEFT
    x2 = x + mm2dot(GAP_PORT)
    y2 = y - rect2.descent
  end
  cr.move_to(x2, y2)
  cr.show_pango_layout(plo)
end

#draw_text_h_gdk(x, y, text, obj_type, alignment) ⇒ Object



790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
# File 'lib/tecscde/view/main_view.rb', line 790

def draw_text_h_gdk(x, y, text, obj_type, alignment)
  #----- Gdk Pango version -----#
  pc = @pango_context
  plo = @pango_layout
  pc.matrix = nil
  plo.text = text
  pfd = pc.font_description
  pfd.absolute_size = font_size(obj_type)
  plo.font_description = pfd
  plo.alignment = alignment
  # plo.context_changed          # ??
  rect2 = plo.get_pixel_extents[1]

  case alignment
  when ALIGN_CENTER
    # calc text draww postion
    x2 = x - rect2.rbearing / 2
    y2 = y - rect2.descent / 2
  when ALIGN_RIGHT
    x2 = x - rect2.rbearing - mm2dot(GAP_PORT)
    y2 = y - rect2.descent
  when ALIGN_LEFT
    x2 = x + mm2dot(GAP_PORT)
    y2 = y - rect2.descent
  end

  # pfd =  Pango::FontDescription.new
  # p pfd.size, pfd.variant, pfd.family
  # rect = plo.get_pixel_extents[0]
  # p rect.ascent, rect.descent, rect.lbearing, rect.rbearing
  # p rect2.ascent, rect2.descent, rect2.lbearing, rect2.rbearing

  @draw_target.draw_layout(@canvas_gc, x2, y2, plo)
end

#draw_text_v(x, y, text, obj_type, alignment) ⇒ Object

x::Integer(dot) y::Integer(dot) obj_type::CELL_NAME, SIGNATURE_NAME, PORT_NAME alignment::ALIGN_CENTER, ALIGN_LEFT



882
883
884
885
886
# File 'lib/tecscde/view/main_view.rb', line 882

def draw_text_v(x, y, text, obj_type, alignment)
  # draw_text_v_gdk( x, y, text, obj_type, alignment )
  draw_text_v_cairo(x, y, text, obj_type, alignment)
  # draw_text_v_cairo_pango( x, y, text, obj_type, alignment )
end

#draw_text_v_cairo(x, y, text, obj_type, alignment) ⇒ Object

—– Cairo version —–#



919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
# File 'lib/tecscde/view/main_view.rb', line 919

def draw_text_v_cairo(x, y, text, obj_type, alignment)
  cr = @cairo_context_target
  cr.select_font_face(nil, # "courier", # font_family = "Times New Roman",
                      Cairo::FONT_SLANT_NORMAL,
                      Cairo::FONT_WEIGHT_NORMAL)
  cr.set_font_size(font_size(obj_type) / 1000)
  cr_te = cr.text_extents(text)
  # p "width=#{cr_te.width} x_bearing=#{cr_te.x_bearing} height=#{cr_te.height} y_bearing=#{cr_te.y_bearing}"
  case alignment
  when ALIGN_CENTER # this case is not used & not checked
    # calc text draww postion
    x2 = x - 2
    y2 = y - (cr_te.width + cr_te.x_bearing) / 2
  when ALIGN_RIGHT
    x2 = x - 2
    y2 = y + cr_te.width + cr_te.x_bearing + mm2dot(GAP_PORT)
  when ALIGN_LEFT
    x2 = x - 2
    y2 = y - mm2dot(GAP_PORT)
  end
  @cairo_matrix.set_rotate90(x2, y2) # rotate around (0, 0) then shift (x2, y2)
  cr.matrix = @cairo_matrix
  cr.move_to(0, 0) # this assumes that (0, 0) is left bottom of strings
  cr.show_text(text)
  @cairo_matrix.set_rotate0
  cr.matrix = @cairo_matrix
end

#draw_text_v_cairo_pango(x, y, text, obj_type, alignment) ⇒ Object

—– Cairo Pango version —–#



948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
# File 'lib/tecscde/view/main_view.rb', line 948

def draw_text_v_cairo_pango(x, y, text, obj_type, alignment)
  cr = @cairo_context_target
  # pfd = Pango::FontDescription.new( "Times" )
  pfd = Pango::FontDescription.new
  pfd.absolute_size = font_size(obj_type)
  # p "font_size=#{font_size( obj_type )}"
  plo = cr.create_pango_layout
  plo.font_description = pfd
  plo.alignment = alignment
  plo.set_text(text)
  rect2 = plo.get_pixel_extents[1]
  # p "descent=#{rect2.descent}, rbearing=#{rect2.rbearing}"

  case alignment
  when ALIGN_CENTER
    # calc text draww postion
    x2 = x - rect2.descent / 2
    y2 = y - rect2.rbearing / 2
  when ALIGN_RIGHT
    x2 = x
    y2 = y + rect2.rbearing + mm2dot(GAP_PORT)
  when ALIGN_LEFT
    x2 = x
    y2 = y - mm2dot(GAP_PORT)
  end

  matrix = Cairo::Matrix.new(0, -1, 1, 0, x2, y2)
  cr.matrix = matrix
  cr.move_to(0, 0) # this assumes that (0, 0) is left bottom of strings
  cr.show_text(text)
  cr.matrix = Cairo::Matrix.new(1, 0, 0, 1, 0, 0)
end

#draw_text_v_gdk(x, y, text, obj_type, alignment) ⇒ Object

—– Gdk Pango version —–#



889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
# File 'lib/tecscde/view/main_view.rb', line 889

def draw_text_v_gdk(x, y, text, obj_type, alignment)
  pc = @pango_context
  plo = @pango_layout
  pm = @pango_matrix
  pc.matrix = pm
  plo.text = text
  pfd = pc.font_description
  pfd.absolute_size = font_size(obj_type)
  plo.font_description = pfd
  plo.alignment = alignment
  # plo.context_changed
  rect2 = plo.get_pixel_extents[1]

  case alignment
  when ALIGN_CENTER
    # calc text draww postion
    x2 = x - rect2.descent / 2
    y2 = y - rect2.rbearing / 2
  when ALIGN_RIGHT
    x2 = x - rect2.descent
    y2 = y + mm2dot(GAP_PORT)
  when ALIGN_LEFT
    x2 = x - rect2.descent
    y2 = y - rect2.rbearing - mm2dot(GAP_PORT)
  end

  @draw_target.draw_layout(@canvas_gc, x2, y2, plo)
end

#end_edit_nameObject



1006
1007
1008
1009
1010
# File 'lib/tecscde/view/main_view.rb', line 1006

def end_edit_name
  name = @entry.text
  @entry_win.hide
  name
end

#export(fname) ⇒ Object

—— export ——#



1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
# File 'lib/tecscde/view/main_view.rb', line 1150

def export(fname)
  begin
    if File.exist?(fname)
      File.unlink(fname)
    end
  rescue => evar
    TECSCDE.message_box("fail to remove #{fname}\n#{evar}", :OK)
    return
  end

  scale_val_bak = @scale_val
  @scale_val = 72.0 / TECSCDE::DPI * 100 # PDF surface = 72 DPI,  mm2dot assume 100 DPI by default
  target_bak = @cairo_context_target

  paper = @model.paper.cairo_paper_class
  paper_width = paper.width("pt") - mm2dot(PAPER_MARGIN * 2)
  paper_height = paper.height("pt") - mm2dot(PAPER_MARGIN * 2)
  begin
    surface = Cairo::PDFSurface.new(fname, paper.width("pt"), paper.height("pt"))
    @cairo_context_target = Cairo::Context.new(surface)

    #----- set paper margin -----#
    @cairo_matrix.set_base_shift(mm2dot(PAPER_MARGIN), mm2dot(PAPER_MARGIN))
    @cairo_context_target.matrix = @cairo_matrix

    #----- clip in rectangle frame -----#
    @cairo_context_target.rectangle(0, 0, paper_width, paper_height)
    @cairo_context_target.clip(false) # preserve = false
    @cairo_context_target.save # (* pair *)   # must be saved initially

    #----- draw contents of PDF -----#
    paint_canvas

    #----- draw model name -----#
    draw_text(paper_width, paper_height, @model.file_editing, PAPER_COMMENT, ALIGN_RIGHT, TEXT_HORIZONTAL)

    #----- draw rectangle frame around paper -----#
    @cairo_context_target.rectangle(0, 0, paper_width, paper_height)
    @cairo_context_target.stroke

    #----- complete PDF file -----#
    surface.finish

    #----- reset context -----#
    # cairo_context_target: unnecessary because the context is abandoned after this
    # @cairo_matrix.set_base_shift( 0, 0 )
    # @cairo_context_target.matrix = @cairo_matrix
    # @cairo_context_target.restore   # (* pair *)
  rescue => evar
    TECSCDE.logger.error(evar)
    TECSCDE.message_box("fail to writ to #{fname}\n#{evar}", :OK)
  ensure
    @cairo_context_target = target_bak
    @cairo_matrix.set_base_shift(0, 0)
    @scale_val = scale_val_bak
    surface&.finish
  end

  paint_canvas
end

#font_size(obj_type) ⇒ Object

font_size

obj_type::Integer CELL_NAME, SIGNATURE_NAME, PORT_NAME



1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
# File 'lib/tecscde/view/main_view.rb', line 1042

def font_size(obj_type)
  case obj_type
  when CELL_NAME
    base_size = 10500
  when CELLTYPE_NAME
    base_size = 10500
  when CELL_NAME_L
    base_size = 16000
  when SIGNATURE_NAME
    base_size = 9000
  when PORT_NAME
    base_size = 9000
  when PAPER_COMMENT
    base_size = 10500
  end
  base_size * @scale_val / 100.0 * DPI / 96.0
end

#get_cell_name_edit_area(cell) ⇒ Object



1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
# File 'lib/tecscde/view/main_view.rb', line 1012

def get_cell_name_edit_area(cell)
  name = cell.get_name
  obj_type = CELL_NAME
  alignment = ALIGN_CENTER
  direction = TEXT_HORIZONTAL
  wmn, hmn = get_text_extent(name, obj_type, alignment, direction)
  xm, ym, wm, hm = cell.get_geometry
  x = mm2dot(xm + (wm - wmn) / 2)
  y = mm2dot(ym + hm / 2 + 1)
  # y = mm2dot( ym + hm / 2 - hmn )
  w = mm2dot(wmn)
  h = mm2dot(hmn)

  [x, y, w, h]
end

#get_cell_paint_color(cell) ⇒ Object

—– cell paint colors —–#



1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
# File 'lib/tecscde/view/main_view.rb', line 1119

def get_cell_paint_color(cell)
  if @b_color_by_region
    region = cell.get_region
    color = @@cell_file_to_color[region]
    if color
      return color
    end
    obj = region
  else
    tecsgen_cell = cell.get_tecsgen_cell
    if tecsgen_cell.nil? || cell.editable?
      return @@colors[Color_editable_cell]
    end
    file = tecsgen_cell.get_locale[0]
    color = @@cell_file_to_color[file]
    if color
      return color
    end
    obj = file
  end
  if @@cell_paint_color_index >= @@cell_paint_colors.length
    @@cell_paint_color_index = 0
  end
  col_name = @@cell_paint_colors[@@cell_paint_color_index]
  @@cell_file_to_color[obj] = @@colors[col_name]
  @@cell_paint_color_index += 1
  # p "col_name:#{col_name} index:#{@@cell_paint_color_index}"
  @@colors[col_name]
end

#get_text_extent(text, obj_type, alignment, direction) ⇒ Object

—– draw and utility for text —–#



743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
# File 'lib/tecscde/view/main_view.rb', line 743

def get_text_extent(text, obj_type, alignment, direction)
  pc = @pango_context
  plo = @pango_layout
  if direction != TEXT_VERTICAL
    pc.matrix = nil
    plo.text = text.to_s
    pfd = pc.font_description
    pfd.absolute_size = font_size(obj_type)
    plo.font_description = pfd
    plo.alignment = alignment
    # plo.context_changed          # ??
    # rect2 = plo.get_pixel_extents[1]
    # return [ dot2mm(rect2.rbearing), dot2mm(rect2.descent) ]
    rect2 = plo.pixel_extents[1]
    [dot2mm(rect2.x + rect2.width), dot2mm(rect2.y + rect2.height)]
  else
    pm = @pango_matrix
    pc.matrix = pm
    plo.text = text.to_s
    pfd = pc.font_description
    pfd.absolute_size = font_size(obj_type)
    plo.font_description = pfd
    plo.alignment = alignment
    # plo.context_changed
    rect2 = plo.get_pixel_extents[1]
    [dot2mm(rect2.descent), dot2mm(rect2.rbearing)]
  end
end

#get_windowObject



195
196
197
# File 'lib/tecscde/view/main_view.rb', line 195

def get_window
  @main_window
end

#mm2dot(mm) ⇒ Object

convert mm to dot



1031
1032
1033
# File 'lib/tecscde/view/main_view.rb', line 1031

def mm2dot(mm)
  (@scale_val * mm * DPI / 25.4 / 100).to_i
end

#paint_canvasObject



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/tecscde/view/main_view.rb', line 280

def paint_canvas
  clear_canvas_pixmap

  #----- draw cells -----#
  @model.get_cell_list.each do |cell|
    draw_cell(cell)
  end

  #----- draw joins -----#
  # draw linew before draw texts (if other colors are used, it is better to lay texts upper side)
  @model.get_join_list.each do |join|
    draw_join(join)
  end

  refresh_canvas
end

#refresh_canvasObject



297
298
299
300
# File 'lib/tecscde/view/main_view.rb', line 297

def refresh_canvas
  @gdk_window.draw_drawable(@canvas_gc, @canvas_pixmap, 0, 0, 0, 0, @canvas_width, @canvas_height)
  draw_highlight_objects(@control.highlighted_objects)
end

#resize_canvasObject



302
303
304
305
306
307
# File 'lib/tecscde/view/main_view.rb', line 302

def resize_canvas
  @canvas_height = Integer(mm2dot(@model.paper.height))
  @canvas_width  = Integer(mm2dot(@model.paper.width))
  @canvas.set_size_request(@canvas_width, @canvas_height)
  # @scrolled_window.queue_draw
end

#set_cursor(cursor) ⇒ Object



318
319
320
# File 'lib/tecscde/view/main_view.rb', line 318

def set_cursor(cursor)
  @canvas.window.cursor = cursor
end

#set_port_color(port, cell) ⇒ Object

set_port_color



491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
# File 'lib/tecscde/view/main_view.rb', line 491

def set_port_color(port, cell)
  if port.complete?
    if cell.editable?
      color_name = Color_editable
    else
      color_name = Color_uneditable
    end
  else
    if port.is_a?(TECSModel::TmCPort) && !port.optional?
      color_name = Color_incomplete
    else
      color_name = Color_unjoin
    end
  end
  # @canvas_gc.set_foreground @@colors[ color_name ]
  @cairo_context_target.set_source_color(@@colors[color_name])
end