module Xumlidot::Diagram::Xmi::Klass

Draw the klass

Public Instance Methods

draw_diagram(options) click to toggle source

Draws a diagram element i.e. the part which is rendered

# File lib/xumlidot/diagram/xmi/klass.rb, line 44
def draw_diagram(options)
  xml = %(<uml:DiagramElement preferredShapeType="Class" subject="#{id}" xmi:id="#{id}de">
    </uml:DiagramElement>)

  return xml if @definition.superklass.empty? && @definition.inherited_modules.empty?
  return xml unless options.inheritance

  xml += draw_diagram_generalisation
end
draw_diagram_composition(composee) click to toggle source
# File lib/xumlidot/diagram/xmi/klass.rb, line 112
def draw_diagram_composition(composee)
  %(<uml:DiagramElement fromDiagramElement="#{id}de" preferredShapeType="Association" subject="#{association_id}" toDiagramElement="#{composee.id}de">
  </uml:DiagramElement>)
end
draw_diagram_generalisation() click to toggle source
# File lib/xumlidot/diagram/xmi/klass.rb, line 54
def draw_diagram_generalisation
  xml = ''

  if ! @definition.superklass.empty?
    xml += %(<uml:DiagramElement fromDiagramElement="#{@definition.superklass.id}de" preferredShapeType="Generalization" subject="#{gen_id}" toDiagramElement="#{id}de">
    </uml:DiagramElement>)
  end

  return xml if @definition.inherited_modules.empty?

  @definition.inherited_modules.each do |m|
    next if m.empty?

    xml += %(<uml:DiagramElement fromDiagramElement="#{m.id}de" preferredShapeType="Generalization" subject="#{gen_id}" toDiagramElement="#{id}de">
    </uml:DiagramElement>)
  end

  xml
end
draw_klass(options) click to toggle source
# File lib/xumlidot/diagram/xmi/klass.rb, line 33
def draw_klass(options)
  definition.name.extend(Name)
  xmi = "<ownedMember isAbstract=\"false\" isActive=\"false\" isLeaf=\"false\" name=\"#{definition.name.to_xmi}\" visibility=\"public\" xmi:id=\"#{id}\" xmi:type=\"uml:Class\">"
  xmi += draw_model_inheritance if options.inheritance
  xmi += extend_and_draw(attributes)
  xmi += extend_and_draw(class_methods)
  xmi += extend_and_draw(instance_methods)
  xmi += "</ownedMember>"
end
draw_model_composition(composee) click to toggle source
# File lib/xumlidot/diagram/xmi/klass.rb, line 101
def draw_model_composition(composee)
  %(<ownedMember isAbstract="false" isDerived="false" isLeaf="false" xmi:id="#{association_id}" xmi:type="uml:Association">
      <memberEnd xmi:idref="#{association_end_id}"/>
      <ownedEnd aggregation="none" association="#{association_id}" isDerived="false" isDerivedUnion="false" isLeaf="false" isNavigable="true" isReadOnly="false" isStatic="false" type="#{id}" xmi:id="9JMZlYaD.AACASCI" xmi:type="uml:Property">
      </ownedEnd>
      <memberEnd xmi:idref="#{composee.association_end_id}"/>
    <ownedEnd aggregation="composite" association="#{association_id}" isDerived="false" isDerivedUnion="false" isLeaf="false" isNavigable="true" isReadOnly="false" isStatic="false" type="#{composee.id}" xmi:id="9JMZlYaD.AACASCK" xmi:type="uml:Property">
    </ownedEnd>
    </ownedMember>)
end
draw_model_inheritance() click to toggle source

Inheritance has to be drawn both as part of the model and as a part of the diagram

general = id = IMPORTANT; will be used to draw the lines in the diagram

# File lib/xumlidot/diagram/xmi/klass.rb, line 80
def draw_model_inheritance
  return '' if @definition.superklass.empty? && @definition.inherited_modules.empty?

  xml = ''

  if ! @definition.superklass.empty?
    xml += %(<generalization general="#{@definition.superklass.id}" xmi:id="#{gen_id}" xmi:type="uml:Generalization">
      </generalization>)
  end

  return xml if @definition.inherited_modules.empty?

  @definition.inherited_modules.each do |m|
    next if m.empty?

    xml += %(<generalization general="#{m.id}" xmi:id="#{gen_id}" xmi:type="uml:Generalization">
      </generalization>)
  end
  xml
end
extend_and_draw(collection) click to toggle source

Im not happy with this - xmi should not have to know about types and it should be a method

# File lib/xumlidot/diagram/xmi/klass.rb, line 119
def extend_and_draw(collection)
  collection.map do |member|
    case member
    when ::Xumlidot::Types::MethodSignature
      member.extend(::Xumlidot::Diagram::Xmi::MethodSignature)
    when ::Xumlidot::Types::Attribute
      member.extend(::Xumlidot::Diagram::Xmi::Attribute)
    end
    member.draw
  end.join(' ')
end