Class: TECSCDE::TECSModel

Inherits:
TmObject show all
Includes:
ChangeSetControl, View::Constants
Defined in:
lib/tecscde/tecs_model.rb,
lib/tecscde/tecs_model/hbar.rb,
lib/tecscde/tecs_model/vbar.rb,
lib/tecscde/tecs_model/tm_cell.rb,
lib/tecscde/tecs_model/tm_join.rb,
lib/tecscde/tecs_model/tm_port.rb,
lib/tecscde/tecs_model/tm_c_port.rb,
lib/tecscde/tecs_model/tm_e_port.rb,
lib/tecscde/tecs_model/tm_region.rb,
lib/tecscde/tecs_model/tm_join_bar.rb,
lib/tecscde/tecs_model/tm_port_array.rb,
lib/tecscde/tecs_model/tm_uneditable.rb,
lib/tecscde/tecs_model/tm_c_port_array.rb,
lib/tecscde/tecs_model/tm_e_port_array.rb

Defined Under Namespace

Modules: TmUneditable Classes: HBar, PaperSpec, TmCPort, TmCPortArray, TmCell, TmEPort, TmEPortArray, TmJoin, TmJoinBar, TmPort, TmPortArray, TmRegion, VBar

Constant Summary collapse

TECSCDE_SCHEMA =

tool_info schema for tecscde

{
  tecscde: {
    cell_list: [:cell_location],    # array
    join_list: [:join_location]     # array
  },
  __tecscde: {
    paper: :paper                   # paper
  },
  paper: {
    type: "paper",                  # fixed string (type name)
    size: :string,                  # "A4", "A3", "A2"
    orientation: :string,           # "LANDSCAPE", "PORTRAIT"
  },
  cell_location: {
    type: "cell_location",          # fixed string (type name)
    region: :string,                # "rRegion::rReg"
    name: :string,                  # "CellName"
    location: [:number],            # [ x, y, w, h ]
    port_location: [:port_location] # array
  },
  port_location: {
    type: "port_location",          # fixed string (type name)
    port_name: :string,
    edge: :string,                  # "EDGE_TOP" | "EDGE_BOTTOM" | "EDGE_LEFT" | "EDGE_RIGHT"
    offset: :number                 # real number (mm) (>=0)
  },
  __port_location: {                # port_location optional
    subscript: :integer
  },
  join_location: {
    type: "join_location",          # fixed string (type name)
    call_region: :string,           # "rRegionParent::rRegionChild",
    call_cell: :string,             # "CellName",
    call_port: :string,             # "cPort",
    entry_region: :string,          # "rERegionParent::rERegionChild",
    entry_cell: :string,            # "ECellName",
    entry_port: :string,            # "ePort",
    bar_list: [:HBar, :VBar]        # mixed (HBar&VBar) array type
  },
  __join_location: {                # join_location optional
    call_port_subscript: :integer,  # >= 0
    entry_port_subscript: :integer, # >= 0
  },
  HBar: {
    type: "HBar",                   # fixed string (type name)
    position: :number,              # real number (mm), location in X-axis
  },
  VBar: {
    type: "VBar",                   # fixed string (type name)
    position: :number,              # real number (mm), location in Y-axis
  }
}
EDGE_TOP =

edges for join (connected by Bars from TmCPort to TmEPort)

0b00
EDGE_BOTTOM =
0b01
EDGE_LEFT =
0b10
EDGE_RIGHT =
0b11
CPGAP =

gap is length between parallel bars.

10
EPGAP =

(mm)

10
GAP =

(mm)

5
ALIGN =

(mm)

1.0
MAX_ERROR_IN_NOR =

acceptable error of position information in .cde file

0.5
MAX_ERROR_IN_TAN =
2
DIST_PORT =

minmal distance to next port (minimal interval)

4
PAPERS =
{
  A4L: PaperSpec.new(0, "A4", :A4L, "LANDSCAPE", "A4_LANDSCAPE", 190, 277),
  A3L: PaperSpec.new(1, "A3", :A3L, "LANDSCAPE", "A3_LANDSCAPE", 277, 400),
  A2L: PaperSpec.new(2, "A2", :A2L, "LANDSCAPE", "A2_LANDSCAPE", 400, 574),
}
NEAR_DIST =

name must be found in Cairo::Paper.constants

2
IDENTIFIER_RE =

(mm)

/[A-Za-z_][0-9A-Za-z_]*/

Constants included from View::Constants

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

Instance Attribute Summary collapse

Attributes inherited from TmObject

#owner

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ChangeSetControl

#add_change_set, #init_change_set, #modified?, #redo, #set_undo_point, #undo

Methods inherited from TmObject

#modified

Constructor Details

#initialize(tecsgen) ⇒ TECSModel

@paper::PaperSpec : See PaperSpec @cell_list:: @cell_hash::{ Symbole(namespace_path) => TmCell } @join_list:: @view::TView @root_region::TmRegion @file_editing::String



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/tecscde/tecs_model.rb', line 167

def initialize(tecsgen)
  @cell_list = []
  @cell_hash = {}
  @join_list = []
  @tecsgen = tecsgen
  @paper = PAPERS[:A3L]

  # __tool_info__( "tecsgen" )
  @direct_import = []
  @import_path_opt = []
  @define    = []
  @cpp       = ""
  @file_editing = "untitled"
  @owner = nil
  init_change_set

  create_root_region
end

Instance Attribute Details

#file_editingObject (readonly)

Returns the value of attribute file_editing.



157
158
159
# File 'lib/tecscde/tecs_model.rb', line 157

def file_editing
  @file_editing
end

#paperObject

Returns the value of attribute paper.



157
158
159
# File 'lib/tecscde/tecs_model.rb', line 157

def paper
  @paper
end

Class Method Details

.get_alignmentObject

TECSModel.get_alignment

return::String : file name editing



380
381
382
# File 'lib/tecscde/tecs_model.rb', line 380

def self.get_alignment
  ALIGN
end

.get_sign_of_normal(edge_side) ⇒ Object

TECSModel.normal direction of edge

RETURN

1: if direction is positive, -1: negative



288
289
290
# File 'lib/tecscde/tecs_model.rb', line 288

def self.get_sign_of_normal(edge_side)
  (edge_side & 0b01) != 0 ? 1 : -1
end

.horizontal?(edge_side) ⇒ Boolean

Returns:

  • (Boolean)


298
299
300
# File 'lib/tecscde/tecs_model.rb', line 298

def self.horizontal?(edge_side)
  !vertical?(edge_side)
end

.opposite?(edge_side1, edge_side2) ⇒ Boolean

TECSModel.opposite?

this function can be applicable only when edge_side1, edge_side2 are parallel

Returns:

  • (Boolean)


311
312
313
# File 'lib/tecscde/tecs_model.rb', line 311

def self.opposite?(edge_side1, edge_side2)
  (((edge_side1 ^ edge_side2) & 0b01) != 0) ? true : false
end

.parallel?(edge_side1, edge_side2) ⇒ Boolean

TECSModel.parallel?

RETURN

true if parallel, false if right anble

Returns:

  • (Boolean)


304
305
306
307
# File 'lib/tecscde/tecs_model.rb', line 304

def self.parallel?(edge_side1, edge_side2)
  # p "edge val", edge_side1, edge_side2, edge_side1 ^ edge_side2
  (edge_side1 ^ edge_side2) < 0b10
end

.round_length_val(val) ⇒ Object

TECSModel.round_length_val



316
317
318
319
320
321
322
# File 'lib/tecscde/tecs_model.rb', line 316

def self.round_length_val(val)
  round_unit = TECSModel.get_alignment
  # round_unit = 0.25
  # (val / round_unit).round * round_unit
  (val / round_unit).round * round_unit
  # val
end

.vertical?(edge_side) ⇒ Boolean

TECSModel.vertical?

RETURN

true if vertical, false if horizontal

Returns:

  • (Boolean)


294
295
296
# File 'lib/tecscde/tecs_model.rb', line 294

def self.vertical?(edge_side)
  ((edge_side & 0b10) != 0) ? true : false
end

Instance Method Details

#add_cell_list_from_tecsgenObject

TECSModel#add_cell_list_from_tecsgen



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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
# File 'lib/tecscde/tecs_model.rb', line 427

def add_cell_list_from_tecsgen
  #----- set @file_editing -----#
  argv = TECSGEN.get_argv
  if argv.empty?
    @file_editing = ""
  else
    last_arg = argv[-1]
    if last_arg =~ /\.cde\Z/
      @file_editing = last_arg
    else
      if last_arg =~ /\.cdl\Z/
        @file_editing = last_arg.gsub(/\.cdl\Z/, ".cde")
      else
        @file_editing = last_arg + ".cde"
      end
    end
  end

  print "file_editing: #{@file_editing}\n"

  tecsgen_cell_list = @tecsgen.get_cell_list
  tecsgen_cell_list2 = []
  x = 10
  y = 10
  # x = @paper[ :width ] - 60
  # y = @paper[ :height ] -30

  cell_list = {} # ::Cell => TmCell
  return unless tecsgen_cell_list
  TECSCDE.logger.info("=== create cell ===")
  tecsgen_cell_list.each do |cell|
    # p cell.get_owner.get_namespace
    # p cell.get_owner.get_namespace_path
    if @cell_hash[cell.get_name] # duplicate cell in cdl file
      next
    end
    if cell.get_celltype.nil? # celltype not found error in cdl (tecsgen)
      TECSCDE.logger.info("add_cell: celltype not found: #{cell.get_name} #{cell.get_owner.get_namespace_path}")
      next
    end

    TECSCDE.logger.info("add_cell #{cell.get_name} #{cell.get_owner.get_namespace_path} #{cell.get_locale}")
    new_cell_ = create_cell_from_tecsgen(cell, x, y)
    tecsgen_cell_list2 << cell
    cell_list[cell] = new_cell_

    new_cell_.set_editable(cell.get_locale)

    x += 55
    if x >= @paper[:width] - 30
      x = 10
      y += 30
      if y >= @paper[:height] - 15
        y = 10
      end
    end
    # x -= 55
    # if x <= 10
    #   x =   @paper[ :width ] - 60
    #   y -= 30
    #   if y <= 50
    #     y = @paper[ :height ] -30
    #   end
    # end
  end

  set_location_from_tecsgen_old
  #------ validate and set location info from __tool_info( "tecscde" ) ------#
  # begin
  if validate || $b_force_apply_tool_info
    TECSCDE.logger.info("=== set_paper ===")
    set_paper_from_tecsgen

    TECSCDE.logger.info("=== set_cell_location ===")
    set_cell_location_from_tecsgen
  else
    TECSCDE.logger.error("validate error in __tool_info__( \"tecscde\" )")
  end

  TECSCDE.logger.info("=== create join ===")
  tecsgen_cell_list2.each do |cell|
    cell.get_join_list.get_items.each do |join|
      if join.get_array_member2.nil?
        create_join_from_tecsgen(cell, join, cell_list)
      else
        join.get_array_member2.each do |j|
          if j
            create_join_from_tecsgen(cell, j, cell_list)
          end
        end
      end
    end
  end

  if validate || $b_force_apply_tool_info
    TECSCDE.logger.info("=== set_join_location ===")
    set_join_location_from_tecsgen
  end
end

#base_directoriesObject



800
801
802
803
804
805
# File 'lib/tecscde/tecs_model.rb', line 800

def base_directories
  dirs = $base_dir.select do |dir, necessary|
    necessary
  end
  dirs.keys
end

#clip_x(x) ⇒ Object



384
385
386
387
388
389
390
391
392
# File 'lib/tecscde/tecs_model.rb', line 384

def clip_x(x)
  max = @paper.width - 2
  if x < 2
    x = 2
  elsif x > max
    x = max
  end
  x
end

#clip_y(y) ⇒ Object



394
395
396
397
398
399
400
401
402
# File 'lib/tecscde/tecs_model.rb', line 394

def clip_y(y)
  max = @paper.height - 2
  if y < 2
    y = 2
  elsif y > max
    y = max
  end
  y
end

#clone_for_undoObject

TECSModel.clone_for_undo



405
406
407
408
409
# File 'lib/tecscde/tecs_model.rb', line 405

def clone_for_undo
  bu = clone
  bu.copy_from(self)
  bu
end

#copy_from(model) ⇒ Object

TECSModel.setup_clone



412
413
414
415
416
417
418
419
420
# File 'lib/tecscde/tecs_model.rb', line 412

def copy_from(model)
  model.instance_variables.each do |iv|
    val = model.instance_variable_get(iv)
    instance_variable_set(iv, val)
  end
  @cell_list = model.instance_variable_get(:@cell_list).dup
  @cell_hash = model.instance_variable_get(:@cell_hash).dup
  @join_list = model.instance_variable_get(:@join_list).dup
end

#create_cell_from_tecsgen(cell, x, y) ⇒ Object

TECSModel#create_cell_from_tecsgen



528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
# File 'lib/tecscde/tecs_model.rb', line 528

def create_cell_from_tecsgen(cell, x, y)
  new_cell_ = new_cell(x, y, cell.get_celltype.get_name, cell.get_celltype.get_owner.get_namespace_path.to_s, cell)
  new_name = cell.get_name # automatically given name
  new_cell_.change_name(new_name)

  # decide cell box size from text width
  w, h = @view.get_text_extent(new_name, CELL_NAME, ALIGN_CENTER, TEXT_HORIZONTAL)
  w2, h = @view.get_text_extent(cell.get_celltype.get_name, CELLTYPE_NAME, ALIGN_CENTER, TEXT_HORIZONTAL)
  w = w2 if w2 > w
  w += 2
  h += 2
  w = 25 if w < 25
  h = 15 if h < 15
  new_cell_.set_geometry(x, y, w, h)
  new_cell_
end

#create_join_from_tecsgen(cell, join, cell_list) ⇒ Object

TECSModel#create_join_from_tecsgen



546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
# File 'lib/tecscde/tecs_model.rb', line 546

def create_join_from_tecsgen(cell, join, cell_list)
  # p join.get_name
  object = cell.get_celltype.find(join.get_name)
  # p "OBJECT CLASS #{object.class}"
  if object.instance_of?(::Port)
    return unless object.get_port_type == :CALL
    return if object.is_require?
    lhs_cell = cell_list[cell]
    cport = lhs_cell.get_cport_for_new_join(join.get_name, join.get_subscript)
    if cport.nil?
      TECSCDE.logger.error("#{@name}.#{join.get_name} not found")
      return
    end
    rhs_cell = cell_list[join.get_cell]
    if rhs_cell.nil? # not joined in cdl (tecsgen)
      return
    end
    # eport = rhs_cell.eports[ join.get_port_name ]
    eport = rhs_cell.get_eport_for_new_join(join.get_port_name, join.get_rhs_subscript1)
    # p "new_join #{lhs_cell.get_name}.#{cport.get_name} => #{rhs_cell.get_name}.#{eport.get_name}"
    new_join_ = new_join(cport, eport)
    new_join_.set_editable(join.get_locale)
  else
    cell_list[cell].set_attr(join.get_name, join.get_rhs.to_CDL_str)
  end
end

#create_root_regionObject

TECSModel#create_root_region



373
374
375
376
# File 'lib/tecscde/tecs_model.rb', line 373

def create_root_region
  nsp = NamespacePath.new("::", true)
  @root_region = TmRegion.new(nsp, self)
end

#define_macrosObject



807
808
809
# File 'lib/tecscde/tecs_model.rb', line 807

def define_macros
  $define
end

#delete_cell(cell) ⇒ Object

TECSModel#delete_cell

don’t call externally, use TmCell#delete instead



237
238
239
240
241
242
# File 'lib/tecscde/tecs_model.rb', line 237

def delete_cell(cell)
  modified do
    @cell_list.delete(cell)
    @cell_hash.delete(cell.get_name) # mikan region
  end
end

#delete_join(join) ⇒ Object

TECSModel#delete_join

don’t call externally. call TmJoin#delete instead



280
281
282
283
284
# File 'lib/tecscde/tecs_model.rb', line 280

def delete_join(join)
  modified do
    @join_list.delete(join)
  end
end

#direct_importsObject



818
819
820
821
822
823
824
825
# File 'lib/tecscde/tecs_model.rb', line 818

def direct_imports
  imports = Import.get_list
  return [] if imports.empty?
  imports = imports.select do |_path, import|
    (import.is_imported? == false) && (import.get_cdl_name != @file_editing)
  end
  imports.values.map(&:get_cdl_name)
end

#generate_cports_lines(cports, indet_width = 4) ⇒ Object



839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
# File 'lib/tecscde/tecs_model.rb', line 839

def generate_cports_lines(cports, indet_width = 4)
  lines = []
  cports.each do |_name, cport|
    if cport.array?
      cport.ports.each do |call_port|
        join = call_port.get_join
        next unless join
        entry_port = join. eport
        subscript = if entry_port.get_subscript
                      "[ #{entry_port.get_subscript} ]"
                    else
                      ""
                    end
        lines << "#{call_port.get_name}[ #{call_port.get_subscript} ] = #{entry_port.get_cell.get_name}.#{entry_port.get_name}#{subscript};"
      end
    else
      join = cport.get_join
      next unless join
      entry_port = join.eport
      subscript = if entry_port.get_subscript
                    "[ #{entry_port.get_subscript} ]"
                  else
                    ""
                  end
      lines << "#{cport.get_name} = #{entry_port.get_cell.get_name}.#{entry_port.get_name}#{subscript};"
    end
  end
  lines
end

#get_cell_listObject

TECSModel#get_cell_list ***



325
326
327
# File 'lib/tecscde/tecs_model.rb', line 325

def get_cell_list
  @cell_list
end

#get_celltype_listObject

TECSModel#get_celltype_list ***



344
345
346
347
# File 'lib/tecscde/tecs_model.rb', line 344

def get_celltype_list
  return unless @tecsgen
  @tecsgen.get_celltype_list
end

#get_edge_side_val(edge_side_name) ⇒ Object

TECSModel#get_edge_side_val



970
971
972
973
974
975
976
977
978
979
980
981
982
983
# File 'lib/tecscde/tecs_model.rb', line 970

def get_edge_side_val(edge_side_name)
  case edge_side_name
  when "EDGE_TOP"
    EDGE_TOP
  when "EDGE_BOTTOM"
    EDGE_BOTTOM
  when "EDGE_LEFT"
    EDGE_LEFT
  when "EDGE_RIGHT"
    EDGE_RIGHT
  else
    0 # same as EDGE_TOP
  end
end

#get_join_listObject

TECSModel#get_join_list ***



330
331
332
# File 'lib/tecscde/tecs_model.rb', line 330

def get_join_list
  @join_list
end

#get_region_by_location(x, y) ⇒ Object

TECSModel#get_region_by_location



368
369
370
# File 'lib/tecscde/tecs_model.rb', line 368

def get_region_by_location(x, y)
  @root_region # mikan
end

#get_region_from_namespace_path(nsp) ⇒ Object

TECSModel#get_region_from_namespace_path



356
357
358
359
360
361
362
363
364
365
# File 'lib/tecscde/tecs_model.rb', line 356

def get_region_from_namespace_path(nsp)
  path_array = nsp.get_path
  region = @root_region
  i = 0
  while i < path_array.length
    region = region.get_region(path_array[i])
    i += 1
  end
  region
end

#get_region_from_tecsgen_region(tecsgen_region) ⇒ Object

TECSModel#get_region_from_tecsgen_region



350
351
352
353
# File 'lib/tecscde/tecs_model.rb', line 350

def get_region_from_tecsgen_region(tecsgen_region)
  nsp = tecsgen_region.get_namespace_path
  get_region_from_namespace_path(nsp)
end

#import_pathsObject



811
812
813
814
815
816
# File 'lib/tecscde/tecs_model.rb', line 811

def import_paths
  tecspath = $tecspath.gsub(/\\/, '\\\\\\\\')
  $import_path.reject do |path|
    path =~ Regexp.new("\\A#{tecspath}")
  end
end

#modelObject



422
423
424
# File 'lib/tecscde/tecs_model.rb', line 422

def model
  self
end

#new_cell(xm, ym, celltype_name, ct_namespace_path, tecsgen_cell = nil) ⇒ Object

TECSModel#new_cell ***

namespace_path::String : namespace path string of celltype



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/tecscde/tecs_model.rb', line 188

def new_cell(xm, ym, celltype_name, ct_namespace_path, tecsgen_cell = nil)
  ct_nsp = NamespacePath.analyze(ct_namespace_path)
  ct_nsp.append!(celltype_name.to_sym)
  ct = Namespace.find(ct_nsp)
  if ct.nil?
    TECSCDE.logger.error("TM9999 celltype #{ct_nsp}: not found for cell #{@name}")
    return
  end

  if tecsgen_cell
    region = get_region_from_tecsgen_region(tecsgen_cell.get_region)
  else
    region = get_region_by_location(xm, ym)
  end
  new_cell2(xm, ym, ct, region, tecsgen_cell)
end

#new_cell2(xm, ym, celltype, region, tecsgen_cell) ⇒ Object

celltype::Celltype : in tecsgen (should be changed to TmCelltype) region:TmRegion : tecsgen_cell:Cell : in tecsgen



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
# File 'lib/tecscde/tecs_model.rb', line 208

def new_cell2(xm, ym, celltype, region, tecsgen_cell)
  modified do
    name = celltype.get_name.to_s.gsub(/t(.*)/, '\\1').to_sym
    if @cell_hash[name]
      count = 0
      while @cell_hash[(name.to_s + count.to_s).to_sym]
        count += 1
      end
      name = (name.to_s + count.to_s).to_sym
    end

    cell = TmCell.new(name, celltype, xm, ym, region, tecsgen_cell)
    @cell_list << cell
    @cell_hash[name] = cell

    w, h = @view.get_text_extent(name, CELL_NAME, ALIGN_CENTER, TEXT_HORIZONTAL)
    w2, h = @view.get_text_extent(celltype.get_name, CELL_NAME, ALIGN_CENTER, TEXT_HORIZONTAL)
    w += 2
    w = w2 if w2 > w
    w = 20 if w < 20
    h = 13 if h < 13
    cell.set_geometry(xm, ym, w, h)

    return cell
  end
end

#new_join(cport, eport) ⇒ Object

TECSModel#new_join ***



270
271
272
273
274
275
276
# File 'lib/tecscde/tecs_model.rb', line 270

def new_join(cport, eport)
  modified do
    join = TmJoin.new(cport, eport, self)
    @join_list << join
    return join
  end
end

#port_location(ports) ⇒ Object



869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
# File 'lib/tecscde/tecs_model.rb', line 869

def port_location(ports)
  ports.map do |port|
    if port.array?
      port.ports.map do |child|
        {
          type: "port_location",
          port_name: port.get_name,
          subscript: port.get_subscript,
          edge: port.get_edge_side_name,
          offset: port.offset
        }
      end
    else
      {
        type: "port_location",
        port_name: port.get_name,
        edge: port.get_edge_side_name,
        offset: port.offset
      }
    end
  end
end

#rename_cell(cell, new_name) ⇒ Object

TECSModel#rename_cell

old_name::Symbol

cell

TmCell

don’t call externally, use TmCell#change_name instead



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/tecscde/tecs_model.rb', line 248

def rename_cell(cell, new_name)
  modified do
    raise "cell name not Symbol" unless new_name.is_a?(Symbol)
    if cell.get_name == new_name
      return true
    end

    unless IDENTIFIER_RE =~ new_name
      TECSCDE.message_box("'#{new_name}' has unsuitable character for identifier", nil)
      return false
    end
    if @cell_hash[new_name]
      TECSCDE.message_box("'#{new_name}' already exists", nil)
      return false
    end
    @cell_hash.delete(cell.get_name)
    @cell_hash[new_name] = cell
    return true
  end
end

#renderObject



780
781
782
783
# File 'lib/tecscde/tecs_model.rb', line 780

def render
  erb = ERB.new(File.read(File.join(__dir__, "templates", "main.cde.erb")), nil, "-")
  erb.result(binding)
end

#render_partial(file, indent_width: 8, **kw) ⇒ Object



785
786
787
788
789
790
791
792
793
794
795
796
797
798
# File 'lib/tecscde/tecs_model.rb', line 785

def render_partial(file, indent_width: 8, **kw)
  erb = ERB.new(File.read(File.join(__dir__, "templates", file)), nil, "-")
  b = binding
  kw.each do |name, value|
    b.local_variable_set(name, value)
  end
  lines = erb.result(b).lines
  string = lines.first.dup
  lines[1..-1].each do |line|
    string << " " * indent_width
    string << line
  end
  string
end

#save(filename) ⇒ Object

save data ***



772
773
774
775
776
777
778
# File 'lib/tecscde/tecs_model.rb', line 772

def save(filename)
  File.open(filename, "w") do |file|
    file.write(render)
  end
rescue => ex
  TECSCDE.message_box("fail to save #{filename}\n#{ex}", :OK)
end

#set_cell_location_from_tecsgenObject



592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
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
645
646
647
648
649
650
651
652
653
654
655
656
657
# File 'lib/tecscde/tecs_model.rb', line 592

def set_cell_location_from_tecsgen
  info = TOOL_INFO.get_tool_info(:tecscde)
  if info.nil? || info[:cell_list].nil?
    return
  end

  #----- cell location -----#
  info[:cell_list].each do |cell_location|
    # region = cell_location[ :region ].to_sym
    name = cell_location[:name].to_sym
    loc = cell_location[:location]
    if loc.length != 4
      TECSCDE.logger.error("#{name}: cell_location.location: array length is not inconsistent, #{loc.length} for 4")
      next
    end
    cell = @cell_hash[name]
    if cell
      # p "apply location: #{cell.get_name}"
      cell.set_geometry(*loc)

      #------ port location -----#
      cell_location[:port_location].each do |port_location|
        # mikan offset not set yet
        port_name = port_location[:port_name].to_sym
        edge = get_edge_side_val(port_location[:edge])
        offset = port_location[:offset]
        subscript = port_location[:subscript]
        port = cell.cports[port_name]
        if port.nil?
          port = cell.eports[port_name]
        end
        if port.nil?
          TECSCDE.logger.info("port '#{port_name}' not found")
          next
        end
        if subscript
          unless port.array?
            TECSCDE.logger.info("port '#{port_name}' : 'subscript' specified but not array")
            next
          end
          if subscript < 0
            TECSCDE.logger.info("port '#{port_name}' : 'subscript' negative valude specified")
            next
          end
          port = port.ports[subscript] # array
          if port.nil?
            TECSCDE.logger.info("port '#{port_name}' : 'subscript=#{subscript}' out of range")
            next
          end
        else
          if port.array?
            TECSCDE.logger.info("port '#{port_name}' : array but no 'subscript' specified")
            next
          end
        end
        port.set_position(edge, offset)
      end
    else
      @cell_hash.each do |a, _b|
        TECSCDE.logger.info(a)
      end
      TECSCDE.logger.info("not apply location: #{name}")
      next
    end
  end
end

#set_join_location_from_tecsgenObject



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
698
699
700
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
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
# File 'lib/tecscde/tecs_model.rb', line 659

def set_join_location_from_tecsgen
  info = TOOL_INFO.get_tool_info(:tecscde)
  if info.nil?
    return
  end

  #----- join location -----#
  info[:join_list].each do |jl|
    # jl[ :call_region ]
    cp_cell_nspath = jl[:call_cell].to_sym
    cp_name = jl[:call_port].to_sym
    cp_subscript = jl[:call_port_subscript]
    # jl[ :entry_region ]
    ep_cell_nspath = jl[:entry_cell].to_sym
    ep_name = jl[:entry_port].to_sym
    ep_subscript = jl[:entry_port_subscript]

    bl = jl[:bar_list]
    bar_list = []
    bl.each do |bar|
      bar_list << [bar[:type], bar[:position]]
    end

    # cp_cell_nspath, cp_name, ep_cell_nspath, ep_name, bar_list = jl.get_location
    # p "set_location_from_tecsgen, #{cp_cell_nspath}, #{cp_name}, #{ep_cell_nspath}, #{ep_name}, #{bar_list}"
    cp_cell = @cell_hash[cp_cell_nspath]
    ep_cell = @cell_hash[ep_cell_nspath]
    # check existance of cells
    next if cp_cell.nil?
    next if ep_cell.nil?
    cport = cp_cell.cports[cp_name]
    if cport.is_a?(TmCPortArray)
      if cp_subscript.nil?
        TECSCDE.logger.error("TM9999 location information ignored #{cp_name} is array but not specified subscript")
        next
      end
      cport = cport.get_member(cp_subscript)
    else
      if cp_subscript
        TECSCDE.logger.error("TM9999 #{cp_name} is not array but specified subscript")
      end
    end
    eport = ep_cell.eports[ep_name]
    if eport.is_a?(TmEPortArray)
      if ep_subscript.nil?
        TECSCDE.logger.error("TM9999 location information ignored #{ep_name} is array but not specified subscript")
        next
      end
      eport = eport.get_member(ep_subscript)
    else
      if ep_subscript
        TECSCDE.logger.error("TM9999 #{ep_name} is not array but specified subscript")
      end
    end
    # p "1 #{cp_name} #{cp_subscript} #{ep_name} #{ep_subscript} #{cport} #{eport}"

    # check existance of cport & eport and direction of bar & edge (must be in right angle)
    # mikan necessary more than 2 bars
    next if cport.nil?
    next if eport.nil?
    next unless eport.include?(cport.get_join(cp_subscript))
    next unless bar_list.length >= 2
    # p "2"
    bar_type = bar_list[0][0].to_sym
    next if TECSModel.vertical?(cport.get_edge_side) && bar_type == :VBar
    next if TECSModel.horizontal?(cport.get_edge_side) && bar_type == :HBar
    # p "3"
    len = bar_list.length

    normal_pos = bar_list[len - 1][1]
    tan_pos = bar_list[len - 2][1]
    # p "normal_pos=#{normal_pos}, eport_normal=#{eport.get_position_in_normal_dir}"
    # p "tan_pos=#{tan_pos}, eport_tan=#{eport.get_position_in_tangential_dir}"
    # check if normal_pos & tan_pos can be evaluated and the position of bars goal
    if !normal_pos.nil? && !tan_pos.nil? &&
        ((normal_pos - eport.get_position_in_normal_dir).abs <= MAX_ERROR_IN_NOR) &&
        ((tan_pos - eport.get_position_in_tangential_dir).abs <= MAX_ERROR_IN_TAN)
      # p "4"
      bars = []
      bar_list.each do |bar_info|
        # bar_list: array of [ IDENTIFER, position ] => bars ( array of HBar or VBar )
        pos = bar_info[1]
        if !pos.nil? && bar_info[0].to_sym == :HBar
          bar = HBar.new(pos, cport.get_join)
          bars << bar
        elsif !pos.nil? && bar_info[0].to_sym == :VBar
          bar = VBar.new(pos, cport.get_join)
          bars << bar
        else
          bars = []
          break
        end
      end
      # mikan length more than 2
      len = bars.length
      if len >= 0.1
        bars[len - 1].set_position(eport.get_position_in_normal_dir)
        bars[len - 2].set_position(eport.get_position_in_tangential_dir)
        # p "bar changed for #{cp_cell_nspath}.#{cport.get_name}"
        cport.get_join.change_bars(bars)
      end
    end
  end
end

#set_location_from_tecsgen_oldObject

TECSModel#set_location_from_tecsgen

get location information from cde file and apply it to TmCell & TmJoin



897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
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
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
# File 'lib/tecscde/tecs_model.rb', line 897

def set_location_from_tecsgen_old
  # set cell location
  @tecsgen.get_cell_location_list.each do |cl|
    cell_nspath, x, y, w, h, port_location_list = cl.get_location
    # p "set_location_from_tecsgen", cell_nspath, x, y, w, h, port_location_list
    cell = @cell_hash[cell_nspath.to_s.to_sym]
    # p "apply location: #{cell&.get_name}"
    cell&.set_geometry(x, y, w, h)
  end

  # set join location
  @tecsgen.get_join_location_list.each do |jl|
    cp_cell_nspath, cp_name, ep_cell_nspath, ep_name, bar_list = jl.get_location
    cp_subscript = nil # kari
    ep_subscript = nil
    # p "set_location_from_tecsgen, #{cp_cell_nspath}, #{cp_name}, #{ep_cell_nspath}, #{ep_name}, #{bar_list}"
    cp_cell = @cell_hash[cp_cell_nspath.to_s.to_sym]
    ep_cell = @cell_hash[ep_cell_nspath.to_s.to_sym]
    # check existance of cells
    next if cp_cell.nil? || ep_cell.nil?
    cport = cp_cell.cports[cp_name.to_sym]
    eport = ep_cell.eports[ep_name.to_sym]
    # p "1 #{cp_name} #{ep_name} #{cport} #{eport}"

    # check existance of cport & eport and direction of bar & edge (must be in right angle)
    # mikan necessary more than 2 bars
    next if cport.nil? || eport.nil?
    next unless eport.include?(cport.get_join(cp_subscript))
    next unless bar_list.length >= 2
    # p "2"
    bar_type = bar_list[0][0]
    next if TECSModel.vertical?(cport.get_edge_side) && bar_type == :VBar
    next if TECSModel.horizontal?(cport.get_edge_side) && bar_type == :HBar
    # p "3"
    len = bar_list.length
    # bar_list: [ [:HBar, pos]
    normal_pos = bar_list[len - 1][1].eval_const(nil)
    tan_pos = bar_list[len - 2][1].eval_const(nil)
    # p "normal_pos=#{normal_pos}, eport_normal=#{eport.get_position_in_normal_dir}"
    # p "tan_pos=#{tan_pos}, eport_tan=#{eport.get_position_in_tangential_dir}"
    # check if normal_pos & tan_pos can be evaluated and the position of bars goal
    if !normal_pos.nil? && !tan_pos.nil? &&
        ((normal_pos - eport.get_position_in_normal_dir).abs <= MAX_ERROR_IN_NOR) &&
        ((tan_pos - eport.get_position_in_tangential_dir).abs <= MAX_ERROR_IN_TAN)
      # p "4"
      bars = []
      bar_list.each do |bar_info|
        # bar_list: array of [ IDENTIFER, position ] => bars ( array of HBar or VBar )
        pos = bar_info[1].eval_const(nil)
        if !pos.nil? && bar_info[0] == :HBar
          bar = HBar.new(pos, cport.get_join)
          bars << bar
        elsif !pos.nil? && bar_info[0] == :VBar
          bar = VBar.new(pos, cport.get_join)
          bars << bar
        else
          bars = []
          break
        end
      end
      # mikan length more than 2
      len = bars.length
      if len >= 2
        bars[len - 1].set_position(eport.get_position_in_normal_dir)
        bars[len - 2].set_position(eport.get_position_in_tangential_dir)
        # p "bar changed for #{cp_cell_nspath}.#{cport.get_name}"
        cport.get_join.change_bars(bars)
      end
    end
  end
end

#set_paper_from_tecsgenObject



573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
# File 'lib/tecscde/tecs_model.rb', line 573

def set_paper_from_tecsgen
  info = TOOL_INFO.get_tool_info(:tecscde)
  return if info.nil? || info[:paper].nil?

  #----- paper -----#
  paper_info = info[:paper]
  return unless paper_info
  size = paper_info[:size]
  orientation = paper_info[:orientation]
  paper = nil
  PAPERS.each do |_name, spec|
    if spec.size == size && spec.orientation == orientation
      TECSCDE.logger.info("paper found #{spec.name}")
      paper = spec
    end
  end
  @paper = paper if paper
end

#set_view(view) ⇒ Object

TECSModel#set_view ***



339
340
341
# File 'lib/tecscde/tecs_model.rb', line 339

def set_view(view)
  @view = view
end

#tecsgenObject



827
828
829
830
831
832
833
834
835
836
837
# File 'lib/tecscde/tecs_model.rb', line 827

def tecsgen
  {
    tecscde_version: TECSCDE::VERSION,
    cde_format_version: TECSCDE::FORMAT_VERSION,
    save_date: DateTime.now,
    base_dir: base_directories,
    define_macro: define_macros,
    import_path: import_paths,
    direct_import: direct_imports
  }
end

#validateObject

TECSModel#validate

validate JSON format data in tool_info( “tecscde” )



766
767
768
769
# File 'lib/tecscde/tecs_model.rb', line 766

def validate
  validator = TOOL_INFO::VALIDATOR.new(:tecscde, TECSCDE_SCHEMA)
  validator.validate
end