Class: ChemScanner::ChemDraw::Graphic
- Defined in:
- lib/chem_scanner/chem_draw/node/graphic.rb
Overview
CDX Graphic parser
Constant Summary collapse
- GRAPHIC_BRACKET_TYPE =
6
Constants included from BaseValue
BaseValue::ARROW_NOGO_CROSS, BaseValue::CDXML_ARROW_TYPE, BaseValue::CDXML_ATOM_EXTERNAL_CONNECTION_TYPE, BaseValue::CDXML_CDX_POINT, BaseValue::CDXML_GRAPHIC_TYPE, BaseValue::CDXML_LINE_TYPE, BaseValue::CDXML_NODE_TYPE, BaseValue::CDXML_ORBITAL_TYPE, BaseValue::CDXML_OVAL_TYPE, BaseValue::TEXT_ATTRIBUTES
Instance Attribute Summary collapse
-
#arrow_head ⇒ Object
readonly
Returns the value of attribute arrow_head.
-
#arrow_id ⇒ Object
readonly
Returns the value of attribute arrow_id.
-
#head ⇒ Object
readonly
Returns the value of attribute head.
-
#line_type ⇒ Object
readonly
Returns the value of attribute line_type.
-
#orbital_type ⇒ Object
readonly
Returns the value of attribute orbital_type.
-
#oval_type ⇒ Object
readonly
Returns the value of attribute oval_type.
-
#polygon ⇒ Object
readonly
Returns the value of attribute polygon.
-
#tail ⇒ Object
readonly
Returns the value of attribute tail.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from BaseNode
Instance Method Summary collapse
- #build_orbital_polygon ⇒ Object
- #cross? ⇒ Boolean
-
#initialize(parser, parser_type, id) ⇒ Graphic
constructor
A new instance of Graphic.
- #line ⇒ Object
- #line? ⇒ Boolean
- #parse_node(tag, _id, data) ⇒ Object
- #post_parse_node ⇒ Object
- #segment ⇒ Object
- #vector ⇒ Object
Methods inherited from BaseNode
#assign_center, #bounding_box, #cdx_read, #cdxml_read, #center_x, #center_y, #get_tempid, #pre_parse_node, #read, #set_cdx, #set_cdxml
Methods included from BaseValue
#binary_chunks, #cdx_styles, #cdx_text, #cdxml_text, #do_unhandled, #point_2d, #point_3d, #polygon_from_bb, #read_bounding_box, #read_ids, #read_int, #read_type, #read_value
Constructor Details
#initialize(parser, parser_type, id) ⇒ Graphic
Returns a new instance of Graphic.
12 13 14 15 16 |
# File 'lib/chem_scanner/chem_draw/node/graphic.rb', line 12 def initialize(parser, parser_type, id) super(parser, parser_type, id) @line_type = 0 end |
Instance Attribute Details
#arrow_head ⇒ Object (readonly)
Returns the value of attribute arrow_head.
7 8 9 |
# File 'lib/chem_scanner/chem_draw/node/graphic.rb', line 7 def arrow_head @arrow_head end |
#arrow_id ⇒ Object (readonly)
Returns the value of attribute arrow_id.
7 8 9 |
# File 'lib/chem_scanner/chem_draw/node/graphic.rb', line 7 def arrow_id @arrow_id end |
#head ⇒ Object (readonly)
Returns the value of attribute head.
7 8 9 |
# File 'lib/chem_scanner/chem_draw/node/graphic.rb', line 7 def head @head end |
#line_type ⇒ Object (readonly)
Returns the value of attribute line_type.
7 8 9 |
# File 'lib/chem_scanner/chem_draw/node/graphic.rb', line 7 def line_type @line_type end |
#orbital_type ⇒ Object (readonly)
Returns the value of attribute orbital_type.
7 8 9 |
# File 'lib/chem_scanner/chem_draw/node/graphic.rb', line 7 def orbital_type @orbital_type end |
#oval_type ⇒ Object (readonly)
Returns the value of attribute oval_type.
7 8 9 |
# File 'lib/chem_scanner/chem_draw/node/graphic.rb', line 7 def oval_type @oval_type end |
#polygon ⇒ Object (readonly)
Returns the value of attribute polygon.
7 8 9 |
# File 'lib/chem_scanner/chem_draw/node/graphic.rb', line 7 def polygon @polygon end |
#tail ⇒ Object (readonly)
Returns the value of attribute tail.
7 8 9 |
# File 'lib/chem_scanner/chem_draw/node/graphic.rb', line 7 def tail @tail end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/chem_scanner/chem_draw/node/graphic.rb', line 7 def type @type end |
Instance Method Details
#build_orbital_polygon ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/chem_scanner/chem_draw/node/graphic.rb', line 59 def build_orbital_polygon return unless @orbital_type == 256 && @oval_type == 3 p1 = Geometry::Point.new(@left, @bottom) p2 = Geometry::Point.new(@left, @top) p3 = Geometry::Point.new(@right, @top) p4 = Geometry::Point.new(@right, @bottom) @polygon = Geometry::Polygon.new([p1, p2, p3, p4]) end |
#cross? ⇒ Boolean
89 90 91 |
# File 'lib/chem_scanner/chem_draw/node/graphic.rb', line 89 def cross? false end |
#line ⇒ Object
85 86 87 |
# File 'lib/chem_scanner/chem_draw/node/graphic.rb', line 85 def line segment.to_line end |
#line? ⇒ Boolean
70 71 72 |
# File 'lib/chem_scanner/chem_draw/node/graphic.rb', line 70 def line? @type == 1 && @arrow_id.nil? && (@arrow_head.nil? || @arrow_head.zero?) end |
#parse_node(tag, _id, data) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/chem_scanner/chem_draw/node/graphic.rb', line 18 def parse_node(tag, _id, data) case @props_ref[tag] when "Arrow_Type" @arrow_head = read_type(tag, data, CDXML_ARROW_TYPE) when "Line_Type" @line_type = read_type(tag, data, CDXML_LINE_TYPE) when "Graphic_Type" @type = read_type(tag, data, CDXML_GRAPHIC_TYPE) # Graphic objects are the only objects whose kCDXProp_BoundingBox # property has a special meaning, representing a pair of points # rather than a rectangle. when "BoundingBox" then @polygon = read_value(tag, data) when "SupersededBy" then @arrow_id = read_value(tag, data) when "3DMajorAxisEnd" then @right, @top = read_value(tag, data) when "3DMinorAxisEnd" then @left, @bottom = read_value(tag, data) when "Orbital_Type" @orbital_type = read_type(tag, data, CDXML_ORBITAL_TYPE) when "Oval_Type" @oval_type = read_type(tag, data, CDXML_OVAL_TYPE) else do_unhandled(tag) end end |
#post_parse_node ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/chem_scanner/chem_draw/node/graphic.rb', line 41 def post_parse_node # When dealing with orbital, boundingbox is not reliable build_orbital_polygon if @type == 5 # In case of Graphic is arrow # Treat as arrow if is a line, no "SupersededBy" and has "BoundingBox" return unless @type == 1 && @arrow_id.nil? && !@polygon.nil? vertices = @polygon.vertices # start point ~ head sp = vertices[1] # end point ~ tail ep = vertices[3] @head = { x: sp.x, y: sp.y } @tail = { x: ep.x, y: ep.y } end |
#segment ⇒ Object
74 75 76 77 78 79 |
# File 'lib/chem_scanner/chem_draw/node/graphic.rb', line 74 def segment Geometry::Segment.new_by_arrays( [@tail[:x], @tail[:y]], [@head[:x], @head[:y]], ) end |
#vector ⇒ Object
81 82 83 |
# File 'lib/chem_scanner/chem_draw/node/graphic.rb', line 81 def vector segment.to_vector end |