Class: TECSCDE::TECSModel::TmJoin

Inherits:
TECSCDE::TmObject show all
Includes:
TmUneditable
Defined in:
lib/tecscde/tecs_model/tm_join.rb

Instance Attribute Summary collapse

Attributes inherited from TECSCDE::TmObject

#owner

Instance Method Summary collapse

Methods included from TmUneditable

#editable?, #set_editable

Methods inherited from TECSCDE::TmObject

#copy_from, #model, #modified

Constructor Details

#initialize(cport, eport, tmodel) ⇒ TmJoin

Returns a new instance of TmJoin.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/tecscde/tecs_model/tm_join.rb', line 66

def initialize(cport, eport, tmodel)
  @cport = cport
  @eport = eport
  @owner = tmodel

  cport.set_join(self)
  eport.add_join(self)

  create_bars
  # @bars.each{ |bar| bar.set_join self }

  @editable = true
  modified {}
end

Instance Attribute Details

#barsObject (readonly)

Returns the value of attribute bars.



64
65
66
# File 'lib/tecscde/tecs_model/tm_join.rb', line 64

def bars
  @bars
end

#cportObject (readonly)

Returns the value of attribute cport.



64
65
66
# File 'lib/tecscde/tecs_model/tm_join.rb', line 64

def cport
  @cport
end

#eportObject (readonly)

Returns the value of attribute eport.



64
65
66
# File 'lib/tecscde/tecs_model/tm_join.rb', line 64

def eport
  @eport
end

Instance Method Details

#between?(x, a, b) ⇒ Boolean

TmJoin#between?

RETURN

true if x is between a & b

Returns:

  • (Boolean)


242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/tecscde/tecs_model/tm_join.rb', line 242

def between?(x, a, b)
  if a >= b
    if b <= x && x <= a
      true
    else
      false
    end
  else
    if a <= x && x <= b
      true
    else
      false
    end
  end
end

#change_bars(bars) ⇒ Object

TmJoin#change_bars bars



264
265
266
267
268
# File 'lib/tecscde/tecs_model/tm_join.rb', line 264

def change_bars(bars)
  modified do
    @bars = bars
  end
end

#clone_for_undoObject

TmJoin#clone_for_undo



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

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

#create_bar(bar, position) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/tecscde/tecs_model/tm_join.rb', line 94

def create_bar(bar, position)
  if bar.horizontal?
    TECSCDE::TECSModel::VBar.new(position, self)
  else
    TECSCDE::TECSModel::HBar.new(position, self)
  end
end

#create_barsObject

TmJoin#create_bars_to dest_port



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/tecscde/tecs_model/tm_join.rb', line 82

def create_bars
  if TECSCDE::TECSModel.parallel?(@cport.get_edge_side, @eport.get_edge_side)
    if TECSCDE::TECSModel.opposite?(@cport.get_edge_side, @eport.get_edge_side)
      create_bars_a
    else
      create_bars_e
    end
  else
    create_bars_c
  end
end

#create_bars_aObject

TmJoin#create_bars_a

(a) parallel opposite side generic



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/tecscde/tecs_model/tm_join.rb', line 104

def create_bars_a
  @bars = []

  @bars[0] = @cport.get_normal_bar_of_edge(self)

  posa = @cport.get_position_in_tangential_dir
  e1, e2 = @eport.get_cell.get_right_angle_edges_position(@cport.get_edge_side)
  # p "posa=#{posa} e1=#{e1}, e2=#{e2}"
  pos1 = ((posa - e1).abs > (posa - e2).abs) ? (e2 + GAP) : (e1 - Gap)
  @bars[1] = create_bar(@bars[0], pos1)

  pos2 = @eport.get_position_in_normal_dir + EPGAP * @eport.get_sign_of_normal
  @bars[2] = create_bar(@bars[1], pos2)

  pos3 = @eport.get_position_in_tangential_dir
  @bars[3] = create_bar(@bars[2], pos3)

  pos4 = @eport.get_position_in_normal_dir
  @bars[4] = create_bar(@bars[3], pos4)
end

#create_bars_cObject

TmJoin#create_bars_c

© right angle generic



127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/tecscde/tecs_model/tm_join.rb', line 127

def create_bars_c
  @bars = []

  @bars[0] = @cport.get_normal_bar_of_edge(self)

  pos1 = @eport.get_position_in_normal_dir + EPGAP * @eport.get_sign_of_normal
  @bars[1] = create_bar(@bars[0], pos1)

  pos2 = @eport.get_position_in_tangential_dir
  @bars[2] = create_bar(@bars[1], pos2)

  pos3 = @eport.get_position_in_normal_dir
  @bars[3] = create_bar(@bars[2], pos3)
end

#create_bars_eObject

TmJoin#create_bars_e

(e) parallel same side generic



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/tecscde/tecs_model/tm_join.rb', line 144

def create_bars_e
  @bars = []

  @bars[0] = @cport.get_normal_bar_of_edge(self)

  posa = @cport.get_position_in_tangential_dir
  e1, e2 = @eport.get_cell.get_right_angle_edges_position(@cport.get_edge_side)
  pos1 = ((posa - e1).abs > (posa - e2).abs) ? (e2 + GAP) : (e1 - Gap)
  @bars[1] = create_bar(@bars[0], pos1)

  pos2 = @eport.get_position_in_normal_dir + EPGAP * @eport.get_sign_of_normal
  @bars[2] = create_bar(@bars[1], pos2)

  pos3 = @eport.get_position_in_tangential_dir
  @bars[3] = create_bar(@bars[2], pos3)

  pos4 = @eport.get_position_in_normal_dir
  @bars[4] = create_bar(@bars[3], pos4)
end

#deleteObject

TmJoin#delete ***



276
277
278
279
280
281
282
283
# File 'lib/tecscde/tecs_model/tm_join.rb', line 276

def delete
  return unless editable?
  modified do
    @cport.delete_join
    @eport.delete_join(self)
    @owner.delete_join(self)
  end
end

#get_near_bar(xm, ym) ⇒ Object

TmJoin#get_near_bar ***



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

def get_near_bar(xm, ym)
  xs, ys = @cport.get_position
  xe = xs
  ye = ys
  min_dist = 999999999
  min_bar = nil
  @bars.each do |bar|
    if bar.horizontal?
      xe = bar.get_position
      if between?(xm, xs, xe) && near?(ym, ys)
        dist = (ym - ys).abs
        if dist < min_dist
          min_dist = dist
          min_bar = bar
        end
      end
    else # VBar
      ye = bar.get_position
      if between?(ym, ys, ye) && near?(xm, xs)
        dist = (xm - xs).abs
        if dist < min_dist
          min_dist = dist
          min_bar = bar
        end
      end
    end
    xs = xe
    ys = ye
  end
  [min_bar, min_dist]
end

#get_signatureObject

TmJoin#get_signature ***



271
272
273
# File 'lib/tecscde/tecs_model/tm_join.rb', line 271

def get_signature
  @cport.get_signature
end

#moved_cport(x_inc, y_inc) ⇒ Object



164
165
166
167
168
169
170
# File 'lib/tecscde/tecs_model/tm_join.rb', line 164

def moved_cport(x_inc, y_inc)
  if @bars[0].instance_of?(TECSCDE::TECSModel::VBar)
    @bars[0].moved(y_inc)
  else
    @bars[0].moved(x_inc)
  end
end

#moved_eport(x_inc, y_inc) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/tecscde/tecs_model/tm_join.rb', line 172

def moved_eport(x_inc, y_inc)
  TECSCDE.logger.debug("moved_eport=(#{x_inc} #{y_inc})")
  len = @bars.length

  if len >= 5
    if @bars[len - 4].instance_of?(TECSCDE::TECSModel::VBar)
      @bars[len - 4].moved(y_inc)
    else
      @bars[len - 4].moved(x_inc)
    end
  end

  if len >= 4
    if @bars[len - 3].instance_of?(TECSCDE::TECSModel::VBar)
      @bars[len - 3].moved(y_inc)
    else
      @bars[len - 3].moved(x_inc)
    end
  end

  if len >= 3
    if @bars[len - 2].instance_of?(TECSCDE::TECSModel::VBar)
      @bars[len - 2].moved(y_inc)
    else
      @bars[len - 2].moved(x_inc)
    end
  end

  if @bars[len - 1].instance_of?(TECSCDE::TECSModel::VBar)
    @bars[len - 1].moved(y_inc)
  else
    @bars[len - 1].moved(x_inc)
  end
end

#near?(x, a) ⇒ Boolean

TmJoin#near?

Returns:

  • (Boolean)


259
260
261
# File 'lib/tecscde/tecs_model/tm_join.rb', line 259

def near?(x, a)
  (x - a).abs < NEAR_DIST
end