Class: TECSCDE::Control
Constant Summary collapse
- MODE_LIST =
- @window
-
Gtk::Window
@model::Model @view::View @mode::Symbol: :NEW_CELL, :POINTER @cport_joining::TmCPort # :SM_JOINING starting cell @celltype_tree_view::CelltypeTreeView @attr_tree_view::AttrTreeView @prev_time::Integer: event time (milli second)
[:MODE_NONE, :MODE_NEW_CELL, :MODE_POINTER]
- SUBMODE_LIST =
[ :SM_NONE, :SM_JOINING, :SM_SURROUNDING_CELLS, :SM_MOVING_CELL_BAR, :SM_MOVING_CPORT, :SM_MOVING_EPORT, :SM_MOVING_CELL_EDGE, :SM_EDIT_CELL_NAME ]
Instance Attribute Summary collapse
-
#highlighted_objects ⇒ Object
readonly
Returns the value of attribute highlighted_objects.
Instance Method Summary collapse
- #add_celltype_list ⇒ Object
- #change_preferences(paper: nil) ⇒ Object
-
#create_new_operation_window ⇒ Object
—– palette —–#.
-
#find_near(xm, ym) ⇒ Object
find_near object RETURN::TmCell, TmPort, TmJoin.
-
#initialize(model) ⇒ Control
constructor
A new instance of Control.
- #key_pressed(keyval, state) ⇒ Object
-
#motion_on_canvas(xm, ym, state) ⇒ Object
mouse moved on canvas.
- #on_cell_name_entry_active(entry) ⇒ Object
- #on_cell_name_entry_focus_out(entry) ⇒ Object
- #on_cell_region_entry_active(entry) ⇒ Object
- #on_cell_region_entry_focus_out(entry) ⇒ Object
- #on_export ⇒ Object
- #on_new_cell ⇒ Object
- #on_pointer ⇒ Object
- #on_quit ⇒ Object
- #on_redo ⇒ Object
-
#on_save ⇒ Object
—– operations for palette —–#.
- #on_undo ⇒ Object
- #preferences ⇒ Object
-
#pressed_on_canvas(xm, ym, state, button, time, click_count) ⇒ Object
mouse pressed on canvas button::Integer: mouse button number state::GdkModifierType: modifier key state time::Integer: milli second click_count::Integer: 1=single click, 2=double click.
-
#released_on_canvas(xm, ym, state, button) ⇒ Object
mouse released on canvas.
- #set_attr_operation_widgets(window, celltype_tree_view, attr_tree_view, cell_name_entry, cell_region_entry, cell_frame) ⇒ Object
-
#set_view(view) ⇒ Object
—– end of palette operations —–#.
-
#update ⇒ Object
Control#update.
Constructor Details
#initialize(model) ⇒ Control
Returns a new instance of Control.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/tecscde/control.rb', line 109 def initialize(model) @nest = -1 @model = model @highlighted_objects = TECSCDE::HighlightedObjects.new @mode = :MODE_NONE @sub_mode = :SM_NONE @cport_joining = nil @prev_time = 0 create_new_operation_window add_celltype_list @highlighted_objects.set_attr_tree_view(@attr_tree_view, @cell_name_entry, @cell_region_entry, @cell_frame) @highlighted_objects.update_attr_tree_view @last_xm = @last_ym = 0 end |
Instance Attribute Details
#highlighted_objects ⇒ Object (readonly)
Returns the value of attribute highlighted_objects.
107 108 109 |
# File 'lib/tecscde/control.rb', line 107 def highlighted_objects @highlighted_objects end |
Instance Method Details
#add_celltype_list ⇒ Object
477 478 479 480 481 482 483 |
# File 'lib/tecscde/control.rb', line 477 def add_celltype_list ctl = @model.get_celltype_list return unless ctl ctl.each do |ct| @celltype_tree_view.add(ct) end end |
#change_preferences(paper: nil) ⇒ Object
213 214 215 |
# File 'lib/tecscde/control.rb', line 213 def change_preferences(paper: nil) @model.paper = paper.to_sym end |
#create_new_operation_window ⇒ Object
—– palette —–#
218 219 220 221 222 |
# File 'lib/tecscde/control.rb', line 218 def create_new_operation_window @palette = TECSCDE::Palette.new(self) # @palette.get_entry_cell_name # @palette.get_attrTreeView end |
#find_near(xm, ym) ⇒ Object
find_near object
RETURN::TmCell, TmPort, TmJoin
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 |
# File 'lib/tecscde/control.rb', line 450 def find_near(xm, ym) @model.get_cell_list.each do |cell| port = cell.get_near_port(xm, ym) if port # p "found port" return port end if cell.near?(xm, ym) # p "found cell" return cell end end # find nearest bar min_dist = 999999999 = nil @model.get_join_list.each do |join| , dist = join.(xm, ym) if dist < min_dist min_dist = dist = end end end |
#key_pressed(keyval, state) ⇒ Object
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 |
# File 'lib/tecscde/control.rb', line 395 def key_pressed(keyval, state) return if @sub_mode == :SM_EDIT_CELL_NAME case keyval when 0xff # delete key @highlighted_objects.each do |object| if object.is_a?(TECSModel::TmJoinBar) object.get_join.delete elsif object.is_a?(TECSModel::TmCell) object.delete elsif object.is_a?(TECSModel::TmPort) object.delete_highlighted end end @highlighted_objects.reset when 0x63 # Insert @highlighted_objects.each do |object| if object.is_a?(TECSModel::TmPort) object.insert(state.shift_mask? ? :before : :after) end end when 0x51, 0x52, 0x53, 0x54 case keyval when 0x51 # left arrow x_inc = - TECSModel.get_alignment y_inc = 0 when 0x52 # up arrow x_inc = 0.0 y_inc = - TECSModel.get_alignment when 0x53 # right arrow x_inc = TECSModel.get_alignment y_inc = 0 when 0x54 # down arrow x_inc = 0.0 y_inc = TECSModel.get_alignment end @highlighted_objects.each do |obj| obj.move(x_inc, y_inc) end when 0x50 # home when 0x57 # end when 0x55 # PageUp when 0x56 # PageDown else = "key_pressed: keyval=%02x" % [keyval] TECSCDE.logger.info() end if @sub_mode != :SM_EDIT_CELL_NAME update end @model.set_undo_point end |
#motion_on_canvas(xm, ym, state) ⇒ Object
mouse moved on canvas
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/tecscde/control.rb', line 325 def motion_on_canvas(xm, ym, state) x_inc = xm - @last_xm y_inc = ym - @last_ym q, r = x_inc.divmod(TECSModel.get_alignment) x_inc2 = TECSModel.get_alignment * q @last_xm = xm - r q, r = y_inc.divmod(TECSModel.get_alignment) y_inc2 = TECSModel.get_alignment * q @last_ym = ym - r case @sub_mode when :SM_MOVING_CELL_BAR @highlighted_objects.each do || .move(x_inc2, y_inc2) end @view.refresh_canvas @view.draw_highlight_objects(@highlighted_objects) when :SM_MOVING_CPORT, :SM_MOVING_EPORT @highlighted_objects.each do |port| port.move(x_inc2, y_inc2) end update @view.refresh_canvas @view.draw_highlight_objects(@highlighted_objects) when :SM_JOINING object = find_near(xm, ym) if object.is_a?(TECSModel::TmEPort) if object.get_signature == @cport_joining.get_signature @view.set_cursor(TECSCDE::CURSOR_JOIN_OK) end # update end when :SM_NONE object = find_near(xm, ym) if object.is_a?(TECSModel::TmCPort) @view.set_cursor(TECSCDE::CURSOR_PORT) else @view.set_cursor(TECSCDE::CURSOR_NORMAL) end end end |
#on_cell_name_entry_active(entry) ⇒ Object
168 169 170 171 172 173 |
# File 'lib/tecscde/control.rb', line 168 def on_cell_name_entry_active(entry) @b_cell_renaming = true @highlighted_objects.change_cell_name(entry.text) @b_cell_renaming = false update end |
#on_cell_name_entry_focus_out(entry) ⇒ Object
175 176 177 178 179 180 |
# File 'lib/tecscde/control.rb', line 175 def on_cell_name_entry_focus_out(entry) return if @b_cell_renaming # to avoid nested message box dialog in error case @highlighted_objects.change_cell_name(entry.text) update end |
#on_cell_region_entry_active(entry) ⇒ Object
182 183 184 185 186 187 |
# File 'lib/tecscde/control.rb', line 182 def on_cell_region_entry_active(entry) # @b_cell_renaming = true # @highlighted_objects.change_cell_name entry.text # @b_cell_renaming = false # update end |
#on_cell_region_entry_focus_out(entry) ⇒ Object
189 190 191 192 193 194 195 |
# File 'lib/tecscde/control.rb', line 189 def on_cell_region_entry_focus_out(entry) # to avoid nested message box dialog in error case # if ! @b_cell_renaming # @highlighted_objects.change_cell_name entry.text # update # end end |
#on_export ⇒ Object
133 134 135 136 137 138 139 140 |
# File 'lib/tecscde/control.rb', line 133 def on_export fname = @model.file_editing.sub(/\.[Cc][Dd][Ee]\Z/, ".pdf") if !(fname =~ /\.pdf\Z/) fname += ".pdf" end TECSCDE.logger.info("export to #{fname}") @view.export(fname) end |
#on_new_cell ⇒ Object
147 148 149 150 |
# File 'lib/tecscde/control.rb', line 147 def on_new_cell @mode = :MODE_NEW_CELL TECSCDE.logger.info("mode: new") end |
#on_pointer ⇒ Object
142 143 144 145 |
# File 'lib/tecscde/control.rb', line 142 def on_pointer TECSCDE.logger.info("mode: pointer") @mode = :MODE_POINTER end |
#on_quit ⇒ Object
164 165 166 |
# File 'lib/tecscde/control.rb', line 164 def on_quit TECSCDE.quit(@model) end |
#on_redo ⇒ Object
158 159 160 161 162 |
# File 'lib/tecscde/control.rb', line 158 def on_redo @model.redo @highlighted_objects.reset update end |
#on_save ⇒ Object
—– operations for palette —–#
128 129 130 131 |
# File 'lib/tecscde/control.rb', line 128 def on_save TECSCDE.logger.info("save") @model.save(@model.file_editing) end |
#on_undo ⇒ Object
152 153 154 155 156 |
# File 'lib/tecscde/control.rb', line 152 def on_undo @model.undo @highlighted_objects.reset update end |
#preferences ⇒ Object
207 208 209 210 211 |
# File 'lib/tecscde/control.rb', line 207 def preferences { paper: @model.paper } end |
#pressed_on_canvas(xm, ym, state, button, time, click_count) ⇒ Object
mouse pressed on canvas
button::Integer: mouse button number state::GdkModifierType: modifier key state time::Integer: milli second click_count::Integer: 1=single click, 2=double click
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 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/tecscde/control.rb', line 245 def pressed_on_canvas(xm, ym, state, , time, click_count) # p "button=#{button} state=#{state} time=#{time} sub_mode=#{@sub_mode}" if @sub_mode == :SM_EDIT_CELL_NAME name = @view.end_edit_name # p "end_edit_name name=#{name}" @highlighted_objects.change_cell_name(name) @sub_mode = :SM_NONE end @prev_time = time return unless == 1 object = find_near(xm, ym) if object.is_a?(TECSModel::TmCell) && click_count == 2 if object.editable? # p "begin_edit_name" @view.begin_edit_name(object, time) @highlighted_objects.reset(object) @sub_mode = :SM_EDIT_CELL_NAME end elsif object.is_a?(TECSModel::TmCell) || object.is_a?(TECSModel::TmJoinBar) @sub_mode = :SM_MOVING_CELL_BAR # p "FOUND Cell or Bar" if state.shift_mask? @highlighted_objects.add(object) elsif state.control_mask? @highlighted_objects.add_del(object) elsif !@highlighted_objects.include?(object) @highlighted_objects.reset(object) end @view.draw_highlight_objects(@highlighted_objects) elsif object.is_a?(TECSModel::TmCPort) # p "FOUND TmCPort" if state.shift_mask? @sub_mode = :SM_MOVING_CPORT @highlighted_objects.add(object) elsif state.control_mask? @sub_mode = :SM_MOVING_CPORT @highlighted_objects.reset(object) elsif object.get_join.nil? @sub_mode = :SM_JOINING @highlighted_objects.reset @cport_joining = object @view.set_cursor(TECSCDE::CURSOR_JOINING) else TECSCDE.(<<~MESSAGE, :OK) Call port has already been joined. Delete existing join before creating new join. If you want to highlighted port, click with pressing shift key. MESSAGE end elsif object.is_a?(TECSModel::TmEPort) @sub_mode = :SM_MOVING_EPORT if state.shift_mask? @highlighted_objects.add(object) elsif state.control_mask? @highlighted_objects.add_del(object) else # p "FOUND TmEPort" @highlighted_objects.reset(object) end else # p "NOT FOUND" if @mode == :MODE_NEW_CELL ctn, nsp = @celltype_tree_view.selected if ctn cell = @model.new_cell(xm, ym, ctn, nsp) @model.set_undo_point end @highlighted_objects.reset(cell) else @highlighted_objects.reset end end @last_xm = xm @last_ym = ym end |
#released_on_canvas(xm, ym, state, button) ⇒ Object
mouse released on canvas
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/tecscde/control.rb', line 371 def released_on_canvas(xm, ym, state, ) case @sub_mode when :SM_MOVING_CELL_BAR # update @model.set_undo_point when :SM_MOVING_CPORT, :SM_MOVING_EPORT # update @model.set_undo_point when :SM_JOINING object = find_near(xm, ym) if object.is_a?(TECSModel::TmEPort) if object.get_signature == @cport_joining.get_signature join = @model.new_join(@cport_joining, object) @model.set_undo_point end # update end end @view.set_cursor(TECSCDE::CURSOR_NORMAL) return if @sub_mode == :SM_EDIT_CELL_NAME update @sub_mode = :SM_NONE end |
#set_attr_operation_widgets(window, celltype_tree_view, attr_tree_view, cell_name_entry, cell_region_entry, cell_frame) ⇒ Object
197 198 199 200 201 202 203 204 205 |
# File 'lib/tecscde/control.rb', line 197 def (window, celltype_tree_view, attr_tree_view, cell_name_entry, cell_region_entry, cell_frame) @window = window @celltype_tree_view = celltype_tree_view @attr_tree_view = attr_tree_view @cell_name_entry = cell_name_entry @cell_region_entry = cell_region_entry @cell_frame = cell_frame @highlighted_objects.set_attr_tree_view(@attr_tree_view, @cell_name_entry, @cell_region_etnry, @cell_frame) end |
#set_view(view) ⇒ Object
—– end of palette operations —–#
226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/tecscde/control.rb', line 226 def set_view(view) @view = view @attr_tree_view.set_view(view) # keep controlWindow above mainWindow @window.set_transient_for(@view.get_window) @window.window.set_group(@view.get_window.window) @window.window.raise @palette.set_view(view) end |
#update ⇒ Object
Control#update
486 487 488 489 |
# File 'lib/tecscde/control.rb', line 486 def update @highlighted_objects.update_attr_tree_view @view.paint_canvas end |