Method: HDLRuby::Viz::Node#to_svg

Defined in:
lib/HDLRuby/hruby_viz.rb

#to_svg(top = true, tx = 0, ty = 0, width = nil, height = nil) ⇒ Object

Generate in SVG format the graphical representation of the flow. +top+ tells if it is the top IC. +tx+ is the x translation of the full description. +ty+ is the y translation of the full description. +width+ is the forced width of the full description if any. +height+ is the forced height of the full description if any.



3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
# File 'lib/HDLRuby/hruby_viz.rb', line 3882

def to_svg(top = true, tx=0, ty=0, width=nil, height=nil)
  # puts "Node to_svg for node=#{self.name} top=#{top} type=#{@type}"
  # Compute the various sizes.
  x0,y0, x1,y1 = 0,0, @width*@scale, @height*@scale
  puts "x0,y0, x1,y1 = #{x0},#{y0}, #{x1}, #{y1}"
  bT = (@scale * 1.5)                # Border thickness
  pT = (bT / 5.0)                    # Port thickness
  wT = bT / 30.0                     # Wire thickness
  sF = @scale*0.4                    # Small font height
  mF = @scale*0.6                    # Medium font height
  lF = @scale*1.0                    # Large font height
  width  = (x1-x0)+bT*5 unless width
  height = (y1-y0)+bT*5 unless height
  # stx = (width - (x1-x0)-bT*5) / 2.0 # X translation of the top system
  # sty = (height - (y1-y0)-bT*5) / 2.0 # Y translation of the top system
  stx = (width - (x1-x0)) / 2.0 # X translation of the top system
  sty = (height - (y1-y0)) / 2.0 # Y translation of the top system
  puts "bT=#{bT} pT=#{pT} wT=#{wT} width=#{width} height=#{height}"
  # The initial visibility.
  visibility = top ? "visible" : "hidden"
  # The string used as suffix for style class names.
  @idC = "-" + self.name.gsub(/[:$]/,"-")
  # Generate the SVG code.
  if top then
    # It is the top node flow.
    # Generate the header.
    res = Viz.svg_header(self.name,x0,y0,width,height)
  else
    # It is not the top, no need of initialization.
    res = ""
  end

  # # Sets the styles.
  # res += "<style>\n"
  # # Fonts
  # res += ".small#{self.idC}  { font: #{sF}px monospace; }\n"
  # res += ".medium#{self.idC} { font: #{mF}px monospace; }\n"
  # res += ".large#{self.idC}  { font: #{lF}px monospace; }\n"
  # res += "</style>\n"

  # Generate the group containing all the flow description.
  res += "<g id=\"#{self.name}\" visibility=\"#{visibility}\" " +
         "transform=\"translate(#{tx},#{ty})\">\n"
  # Generate the rectangle of the bounding box.
  res += "<rect fill=\"#4682B4\" stroke=\"#007\" " +
    "stroke-width=\"#{@scale/4.0}\" " +
    # "x=\"#{x0-bT*2.5}\" y=\"#{y0-bT*2.5}\" "+
    "x=\"#{x0}\" y=\"#{y0}\" "+
    "width=\"#{width}\" height=\"#{height}\"/>\n"

  # Generate the group containing the top system and its contents.
  res += "<g transform=\"translate(#{stx},#{sty})\">\n"

  # Generate the node boxes.
  puts "Generate node box for self.type=#{self.type}"
  case self.type
  when :assign
    # The SVG object representing an assignment is to draw.
    res += assign_svg(self)
  when :seq, :par
    # The SVG objet repenting a block is to draw.
    res += block_svg(self)
    # Also generate its content.
    res += self.statement_svg_deep(self.branches[0])
    # And its arrows.
    @arrows.each { |x0,y0,x1,y1| res += arrow_svg(x0,y0,x1,y1) }
  end

  # Close the group containing the top system and its content.
  res += "</g>\n"
  # Close the group containing the description of the IC.
  res += "</g>\n"

  if top then
    # It is the top so close the SVG.
    res += "</svg>\n"
  end
  return res
end