Class: Depiction

Inherits:
ApplicationRecord show all
Includes:
Housekeeping, Shared::DataAttributes, Shared::IsData, Shared::PolymorphicAnnotator, Shared::Tags
Defined in:
app/models/depiction.rb

Overview

A depiction is the linkage between an image and a data object. For example an image may depiction a ColletingEvent, CollectionObject, or OTU.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Shared::PolymorphicAnnotator

#annotated_object_is_persisted?

Methods included from Shared::IsData

#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar

Methods included from Shared::DataAttributes

#import_attributes, #internal_attributes, #keyword_value_hash, #reject_data_attributes

Methods included from Shared::Tags

#reject_tags, #tag_with, #tagged?, #tagged_with?

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods inherited from ApplicationRecord

transaction_with_retry

Instance Attribute Details

#depiction_object_idInteger

Returns the id of the object being depicted.

Returns:

  • (Integer)

    the id of the object being depicted



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/models/depiction.rb', line 45

class Depiction < ApplicationRecord
  include Housekeeping
  include Shared::Tags
  include Shared::DataAttributes
  include Shared::IsData
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:depiction_object)

  acts_as_list scope: [:project_id, :depiction_object_type, :depiction_object_id]

  belongs_to :image, inverse_of: :depictions
  belongs_to :sled_image, inverse_of: :depictions
  has_one :sqed_depiction, dependent: :destroy

  accepts_nested_attributes_for :image
  accepts_nested_attributes_for :sqed_depiction, allow_destroy: true

  validates_presence_of :depiction_object
  validates_uniqueness_of :sled_image_id, scope: [:project_id, :sled_image_x_position, :sled_image_y_position], allow_nil: true, if: Proc.new {|n| !n.sled_image_id.nil?}

  after_update :remove_media_observation2, if: Proc.new {|d| d.depiction_object_type_previously_was == 'Observation' && d.depiction_object.type_was == 'Observation::Media' }
  after_destroy :remove_media_observation, if: Proc.new {|d| d.depiction_object_type == 'Observation' && d.depiction_object.type == 'Observation::Media' }

  after_update :destroy_image_stub_collection_object, if: Proc.new {|d| d.depiction_object_type_previously_was == 'CollectionObject' && d.depiction_object_type == 'CollectionObject' }

  def from_sled?
    !sled_image_id.nil?
  end

  def sled_extraction_path(size = :thumb)
    if from_sled?
      x, y, w, h = svg_view_box.split(' ')

      box_width, box_height = nil, nil
      case size
      when :thumb, :medium
        box_width = Image::DEFAULT_SIZES[size][:width]
        box_height = Image::DEFAULT_SIZES[size][:height]
      when :original
        box_width = w.to_i
        box_height = h.to_i
      end

      "#{image_id}/scale_to_box/#{x.to_i}/#{y.to_i}/#{w.to_i}/#{h.to_i}/#{box_width}/#{box_height}"
    else
      raise 'This is not a sled derived depiction'
    end
  end

  private

  def remove_media_observation2
    if v = depiction_object_id_previously_was
      o = Observation::Media.find(v)
      if o.depictions.size == 0
        o.destroy!
      end
    end
  end

  def remove_media_observation
    if depiction_object.depictions.size == 0
      depiction_object.destroy!
    end
  end

  def destroy_image_stub_collection_object
    if sqed_depiction.present? 
      if v = depiction_object_id_previously_was
        o = CollectionObject.find(v)
        if o.is_image_stub?
          o.destroy!
        end
      end
    end
  end

end

#depiction_object_typeString

Returns the type of object being depicted, a TW class that can be depicted (e.g. CollectionObject, CollectingEvent).

Returns:

  • (String)

    the type of object being depicted, a TW class that can be depicted (e.g. CollectionObject, CollectingEvent)



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/models/depiction.rb', line 45

class Depiction < ApplicationRecord
  include Housekeeping
  include Shared::Tags
  include Shared::DataAttributes
  include Shared::IsData
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:depiction_object)

  acts_as_list scope: [:project_id, :depiction_object_type, :depiction_object_id]

  belongs_to :image, inverse_of: :depictions
  belongs_to :sled_image, inverse_of: :depictions
  has_one :sqed_depiction, dependent: :destroy

  accepts_nested_attributes_for :image
  accepts_nested_attributes_for :sqed_depiction, allow_destroy: true

  validates_presence_of :depiction_object
  validates_uniqueness_of :sled_image_id, scope: [:project_id, :sled_image_x_position, :sled_image_y_position], allow_nil: true, if: Proc.new {|n| !n.sled_image_id.nil?}

  after_update :remove_media_observation2, if: Proc.new {|d| d.depiction_object_type_previously_was == 'Observation' && d.depiction_object.type_was == 'Observation::Media' }
  after_destroy :remove_media_observation, if: Proc.new {|d| d.depiction_object_type == 'Observation' && d.depiction_object.type == 'Observation::Media' }

  after_update :destroy_image_stub_collection_object, if: Proc.new {|d| d.depiction_object_type_previously_was == 'CollectionObject' && d.depiction_object_type == 'CollectionObject' }

  def from_sled?
    !sled_image_id.nil?
  end

  def sled_extraction_path(size = :thumb)
    if from_sled?
      x, y, w, h = svg_view_box.split(' ')

      box_width, box_height = nil, nil
      case size
      when :thumb, :medium
        box_width = Image::DEFAULT_SIZES[size][:width]
        box_height = Image::DEFAULT_SIZES[size][:height]
      when :original
        box_width = w.to_i
        box_height = h.to_i
      end

      "#{image_id}/scale_to_box/#{x.to_i}/#{y.to_i}/#{w.to_i}/#{h.to_i}/#{box_width}/#{box_height}"
    else
      raise 'This is not a sled derived depiction'
    end
  end

  private

  def remove_media_observation2
    if v = depiction_object_id_previously_was
      o = Observation::Media.find(v)
      if o.depictions.size == 0
        o.destroy!
      end
    end
  end

  def remove_media_observation
    if depiction_object.depictions.size == 0
      depiction_object.destroy!
    end
  end

  def destroy_image_stub_collection_object
    if sqed_depiction.present? 
      if v = depiction_object_id_previously_was
        o = CollectionObject.find(v)
        if o.is_image_stub?
          o.destroy!
        end
      end
    end
  end

end

#image_idInteger

Returns the id of the image that stores the depiction.

Returns:

  • (Integer)

    the id of the image that stores the depiction



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/models/depiction.rb', line 45

class Depiction < ApplicationRecord
  include Housekeeping
  include Shared::Tags
  include Shared::DataAttributes
  include Shared::IsData
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:depiction_object)

  acts_as_list scope: [:project_id, :depiction_object_type, :depiction_object_id]

  belongs_to :image, inverse_of: :depictions
  belongs_to :sled_image, inverse_of: :depictions
  has_one :sqed_depiction, dependent: :destroy

  accepts_nested_attributes_for :image
  accepts_nested_attributes_for :sqed_depiction, allow_destroy: true

  validates_presence_of :depiction_object
  validates_uniqueness_of :sled_image_id, scope: [:project_id, :sled_image_x_position, :sled_image_y_position], allow_nil: true, if: Proc.new {|n| !n.sled_image_id.nil?}

  after_update :remove_media_observation2, if: Proc.new {|d| d.depiction_object_type_previously_was == 'Observation' && d.depiction_object.type_was == 'Observation::Media' }
  after_destroy :remove_media_observation, if: Proc.new {|d| d.depiction_object_type == 'Observation' && d.depiction_object.type == 'Observation::Media' }

  after_update :destroy_image_stub_collection_object, if: Proc.new {|d| d.depiction_object_type_previously_was == 'CollectionObject' && d.depiction_object_type == 'CollectionObject' }

  def from_sled?
    !sled_image_id.nil?
  end

  def sled_extraction_path(size = :thumb)
    if from_sled?
      x, y, w, h = svg_view_box.split(' ')

      box_width, box_height = nil, nil
      case size
      when :thumb, :medium
        box_width = Image::DEFAULT_SIZES[size][:width]
        box_height = Image::DEFAULT_SIZES[size][:height]
      when :original
        box_width = w.to_i
        box_height = h.to_i
      end

      "#{image_id}/scale_to_box/#{x.to_i}/#{y.to_i}/#{w.to_i}/#{h.to_i}/#{box_width}/#{box_height}"
    else
      raise 'This is not a sled derived depiction'
    end
  end

  private

  def remove_media_observation2
    if v = depiction_object_id_previously_was
      o = Observation::Media.find(v)
      if o.depictions.size == 0
        o.destroy!
      end
    end
  end

  def remove_media_observation
    if depiction_object.depictions.size == 0
      depiction_object.destroy!
    end
  end

  def destroy_image_stub_collection_object
    if sqed_depiction.present? 
      if v = depiction_object_id_previously_was
        o = CollectionObject.find(v)
        if o.is_image_stub?
          o.destroy!
        end
      end
    end
  end

end

#is_metadata_depictionBoolean?

Returns If true then this depiction depicts data that describes the entity, rather than the entity itself. For example, a CollectionObject depiction of a insect, vs. a picture of some text that says “the specimen is blue”.

Returns:

  • (Boolean, nil)

    If true then this depiction depicts data that describes the entity, rather than the entity itself. For example, a CollectionObject depiction of a insect, vs. a picture of some text that says “the specimen is blue”



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/models/depiction.rb', line 45

class Depiction < ApplicationRecord
  include Housekeeping
  include Shared::Tags
  include Shared::DataAttributes
  include Shared::IsData
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:depiction_object)

  acts_as_list scope: [:project_id, :depiction_object_type, :depiction_object_id]

  belongs_to :image, inverse_of: :depictions
  belongs_to :sled_image, inverse_of: :depictions
  has_one :sqed_depiction, dependent: :destroy

  accepts_nested_attributes_for :image
  accepts_nested_attributes_for :sqed_depiction, allow_destroy: true

  validates_presence_of :depiction_object
  validates_uniqueness_of :sled_image_id, scope: [:project_id, :sled_image_x_position, :sled_image_y_position], allow_nil: true, if: Proc.new {|n| !n.sled_image_id.nil?}

  after_update :remove_media_observation2, if: Proc.new {|d| d.depiction_object_type_previously_was == 'Observation' && d.depiction_object.type_was == 'Observation::Media' }
  after_destroy :remove_media_observation, if: Proc.new {|d| d.depiction_object_type == 'Observation' && d.depiction_object.type == 'Observation::Media' }

  after_update :destroy_image_stub_collection_object, if: Proc.new {|d| d.depiction_object_type_previously_was == 'CollectionObject' && d.depiction_object_type == 'CollectionObject' }

  def from_sled?
    !sled_image_id.nil?
  end

  def sled_extraction_path(size = :thumb)
    if from_sled?
      x, y, w, h = svg_view_box.split(' ')

      box_width, box_height = nil, nil
      case size
      when :thumb, :medium
        box_width = Image::DEFAULT_SIZES[size][:width]
        box_height = Image::DEFAULT_SIZES[size][:height]
      when :original
        box_width = w.to_i
        box_height = h.to_i
      end

      "#{image_id}/scale_to_box/#{x.to_i}/#{y.to_i}/#{w.to_i}/#{h.to_i}/#{box_width}/#{box_height}"
    else
      raise 'This is not a sled derived depiction'
    end
  end

  private

  def remove_media_observation2
    if v = depiction_object_id_previously_was
      o = Observation::Media.find(v)
      if o.depictions.size == 0
        o.destroy!
      end
    end
  end

  def remove_media_observation
    if depiction_object.depictions.size == 0
      depiction_object.destroy!
    end
  end

  def destroy_image_stub_collection_object
    if sqed_depiction.present? 
      if v = depiction_object_id_previously_was
        o = CollectionObject.find(v)
        if o.is_image_stub?
          o.destroy!
        end
      end
    end
  end

end

#project_idInteger

Returns the project ID.

Returns:

  • (Integer)

    the project ID



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/models/depiction.rb', line 45

class Depiction < ApplicationRecord
  include Housekeeping
  include Shared::Tags
  include Shared::DataAttributes
  include Shared::IsData
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:depiction_object)

  acts_as_list scope: [:project_id, :depiction_object_type, :depiction_object_id]

  belongs_to :image, inverse_of: :depictions
  belongs_to :sled_image, inverse_of: :depictions
  has_one :sqed_depiction, dependent: :destroy

  accepts_nested_attributes_for :image
  accepts_nested_attributes_for :sqed_depiction, allow_destroy: true

  validates_presence_of :depiction_object
  validates_uniqueness_of :sled_image_id, scope: [:project_id, :sled_image_x_position, :sled_image_y_position], allow_nil: true, if: Proc.new {|n| !n.sled_image_id.nil?}

  after_update :remove_media_observation2, if: Proc.new {|d| d.depiction_object_type_previously_was == 'Observation' && d.depiction_object.type_was == 'Observation::Media' }
  after_destroy :remove_media_observation, if: Proc.new {|d| d.depiction_object_type == 'Observation' && d.depiction_object.type == 'Observation::Media' }

  after_update :destroy_image_stub_collection_object, if: Proc.new {|d| d.depiction_object_type_previously_was == 'CollectionObject' && d.depiction_object_type == 'CollectionObject' }

  def from_sled?
    !sled_image_id.nil?
  end

  def sled_extraction_path(size = :thumb)
    if from_sled?
      x, y, w, h = svg_view_box.split(' ')

      box_width, box_height = nil, nil
      case size
      when :thumb, :medium
        box_width = Image::DEFAULT_SIZES[size][:width]
        box_height = Image::DEFAULT_SIZES[size][:height]
      when :original
        box_width = w.to_i
        box_height = h.to_i
      end

      "#{image_id}/scale_to_box/#{x.to_i}/#{y.to_i}/#{w.to_i}/#{h.to_i}/#{box_width}/#{box_height}"
    else
      raise 'This is not a sled derived depiction'
    end
  end

  private

  def remove_media_observation2
    if v = depiction_object_id_previously_was
      o = Observation::Media.find(v)
      if o.depictions.size == 0
        o.destroy!
      end
    end
  end

  def remove_media_observation
    if depiction_object.depictions.size == 0
      depiction_object.destroy!
    end
  end

  def destroy_image_stub_collection_object
    if sqed_depiction.present? 
      if v = depiction_object_id_previously_was
        o = CollectionObject.find(v)
        if o.is_image_stub?
          o.destroy!
        end
      end
    end
  end

end

#sled_image_idInteger

Returns If present this depiction was derived from sled.

Returns:

  • (Integer)

    If present this depiction was derived from sled



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/models/depiction.rb', line 45

class Depiction < ApplicationRecord
  include Housekeeping
  include Shared::Tags
  include Shared::DataAttributes
  include Shared::IsData
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:depiction_object)

  acts_as_list scope: [:project_id, :depiction_object_type, :depiction_object_id]

  belongs_to :image, inverse_of: :depictions
  belongs_to :sled_image, inverse_of: :depictions
  has_one :sqed_depiction, dependent: :destroy

  accepts_nested_attributes_for :image
  accepts_nested_attributes_for :sqed_depiction, allow_destroy: true

  validates_presence_of :depiction_object
  validates_uniqueness_of :sled_image_id, scope: [:project_id, :sled_image_x_position, :sled_image_y_position], allow_nil: true, if: Proc.new {|n| !n.sled_image_id.nil?}

  after_update :remove_media_observation2, if: Proc.new {|d| d.depiction_object_type_previously_was == 'Observation' && d.depiction_object.type_was == 'Observation::Media' }
  after_destroy :remove_media_observation, if: Proc.new {|d| d.depiction_object_type == 'Observation' && d.depiction_object.type == 'Observation::Media' }

  after_update :destroy_image_stub_collection_object, if: Proc.new {|d| d.depiction_object_type_previously_was == 'CollectionObject' && d.depiction_object_type == 'CollectionObject' }

  def from_sled?
    !sled_image_id.nil?
  end

  def sled_extraction_path(size = :thumb)
    if from_sled?
      x, y, w, h = svg_view_box.split(' ')

      box_width, box_height = nil, nil
      case size
      when :thumb, :medium
        box_width = Image::DEFAULT_SIZES[size][:width]
        box_height = Image::DEFAULT_SIZES[size][:height]
      when :original
        box_width = w.to_i
        box_height = h.to_i
      end

      "#{image_id}/scale_to_box/#{x.to_i}/#{y.to_i}/#{w.to_i}/#{h.to_i}/#{box_width}/#{box_height}"
    else
      raise 'This is not a sled derived depiction'
    end
  end

  private

  def remove_media_observation2
    if v = depiction_object_id_previously_was
      o = Observation::Media.find(v)
      if o.depictions.size == 0
        o.destroy!
      end
    end
  end

  def remove_media_observation
    if depiction_object.depictions.size == 0
      depiction_object.destroy!
    end
  end

  def destroy_image_stub_collection_object
    if sqed_depiction.present? 
      if v = depiction_object_id_previously_was
        o = CollectionObject.find(v)
        if o.is_image_stub?
          o.destroy!
        end
      end
    end
  end

end

#sled_image_x_positionInteger

Returns Not null if sled_image_is present. The column (top left 0,0) derived from.

Returns:

  • (Integer)

    Not null if sled_image_is present. The column (top left 0,0) derived from



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/models/depiction.rb', line 45

class Depiction < ApplicationRecord
  include Housekeeping
  include Shared::Tags
  include Shared::DataAttributes
  include Shared::IsData
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:depiction_object)

  acts_as_list scope: [:project_id, :depiction_object_type, :depiction_object_id]

  belongs_to :image, inverse_of: :depictions
  belongs_to :sled_image, inverse_of: :depictions
  has_one :sqed_depiction, dependent: :destroy

  accepts_nested_attributes_for :image
  accepts_nested_attributes_for :sqed_depiction, allow_destroy: true

  validates_presence_of :depiction_object
  validates_uniqueness_of :sled_image_id, scope: [:project_id, :sled_image_x_position, :sled_image_y_position], allow_nil: true, if: Proc.new {|n| !n.sled_image_id.nil?}

  after_update :remove_media_observation2, if: Proc.new {|d| d.depiction_object_type_previously_was == 'Observation' && d.depiction_object.type_was == 'Observation::Media' }
  after_destroy :remove_media_observation, if: Proc.new {|d| d.depiction_object_type == 'Observation' && d.depiction_object.type == 'Observation::Media' }

  after_update :destroy_image_stub_collection_object, if: Proc.new {|d| d.depiction_object_type_previously_was == 'CollectionObject' && d.depiction_object_type == 'CollectionObject' }

  def from_sled?
    !sled_image_id.nil?
  end

  def sled_extraction_path(size = :thumb)
    if from_sled?
      x, y, w, h = svg_view_box.split(' ')

      box_width, box_height = nil, nil
      case size
      when :thumb, :medium
        box_width = Image::DEFAULT_SIZES[size][:width]
        box_height = Image::DEFAULT_SIZES[size][:height]
      when :original
        box_width = w.to_i
        box_height = h.to_i
      end

      "#{image_id}/scale_to_box/#{x.to_i}/#{y.to_i}/#{w.to_i}/#{h.to_i}/#{box_width}/#{box_height}"
    else
      raise 'This is not a sled derived depiction'
    end
  end

  private

  def remove_media_observation2
    if v = depiction_object_id_previously_was
      o = Observation::Media.find(v)
      if o.depictions.size == 0
        o.destroy!
      end
    end
  end

  def remove_media_observation
    if depiction_object.depictions.size == 0
      depiction_object.destroy!
    end
  end

  def destroy_image_stub_collection_object
    if sqed_depiction.present? 
      if v = depiction_object_id_previously_was
        o = CollectionObject.find(v)
        if o.is_image_stub?
          o.destroy!
        end
      end
    end
  end

end

#sled_image_y_positionInteger

Returns Not null if sled_image_is present. The row (top left 0,0) derived from.

Returns:

  • (Integer)

    Not null if sled_image_is present. The row (top left 0,0) derived from



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/models/depiction.rb', line 45

class Depiction < ApplicationRecord
  include Housekeeping
  include Shared::Tags
  include Shared::DataAttributes
  include Shared::IsData
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:depiction_object)

  acts_as_list scope: [:project_id, :depiction_object_type, :depiction_object_id]

  belongs_to :image, inverse_of: :depictions
  belongs_to :sled_image, inverse_of: :depictions
  has_one :sqed_depiction, dependent: :destroy

  accepts_nested_attributes_for :image
  accepts_nested_attributes_for :sqed_depiction, allow_destroy: true

  validates_presence_of :depiction_object
  validates_uniqueness_of :sled_image_id, scope: [:project_id, :sled_image_x_position, :sled_image_y_position], allow_nil: true, if: Proc.new {|n| !n.sled_image_id.nil?}

  after_update :remove_media_observation2, if: Proc.new {|d| d.depiction_object_type_previously_was == 'Observation' && d.depiction_object.type_was == 'Observation::Media' }
  after_destroy :remove_media_observation, if: Proc.new {|d| d.depiction_object_type == 'Observation' && d.depiction_object.type == 'Observation::Media' }

  after_update :destroy_image_stub_collection_object, if: Proc.new {|d| d.depiction_object_type_previously_was == 'CollectionObject' && d.depiction_object_type == 'CollectionObject' }

  def from_sled?
    !sled_image_id.nil?
  end

  def sled_extraction_path(size = :thumb)
    if from_sled?
      x, y, w, h = svg_view_box.split(' ')

      box_width, box_height = nil, nil
      case size
      when :thumb, :medium
        box_width = Image::DEFAULT_SIZES[size][:width]
        box_height = Image::DEFAULT_SIZES[size][:height]
      when :original
        box_width = w.to_i
        box_height = h.to_i
      end

      "#{image_id}/scale_to_box/#{x.to_i}/#{y.to_i}/#{w.to_i}/#{h.to_i}/#{box_width}/#{box_height}"
    else
      raise 'This is not a sled derived depiction'
    end
  end

  private

  def remove_media_observation2
    if v = depiction_object_id_previously_was
      o = Observation::Media.find(v)
      if o.depictions.size == 0
        o.destroy!
      end
    end
  end

  def remove_media_observation
    if depiction_object.depictions.size == 0
      depiction_object.destroy!
    end
  end

  def destroy_image_stub_collection_object
    if sqed_depiction.present? 
      if v = depiction_object_id_previously_was
        o = CollectionObject.find(v)
        if o.is_image_stub?
          o.destroy!
        end
      end
    end
  end

end

#svg_clipxml?

Returns a clipping mask to isolate some portion of the picture.

Returns:

  • (xml, nil)

    a clipping mask to isolate some portion of the picture



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/models/depiction.rb', line 45

class Depiction < ApplicationRecord
  include Housekeeping
  include Shared::Tags
  include Shared::DataAttributes
  include Shared::IsData
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:depiction_object)

  acts_as_list scope: [:project_id, :depiction_object_type, :depiction_object_id]

  belongs_to :image, inverse_of: :depictions
  belongs_to :sled_image, inverse_of: :depictions
  has_one :sqed_depiction, dependent: :destroy

  accepts_nested_attributes_for :image
  accepts_nested_attributes_for :sqed_depiction, allow_destroy: true

  validates_presence_of :depiction_object
  validates_uniqueness_of :sled_image_id, scope: [:project_id, :sled_image_x_position, :sled_image_y_position], allow_nil: true, if: Proc.new {|n| !n.sled_image_id.nil?}

  after_update :remove_media_observation2, if: Proc.new {|d| d.depiction_object_type_previously_was == 'Observation' && d.depiction_object.type_was == 'Observation::Media' }
  after_destroy :remove_media_observation, if: Proc.new {|d| d.depiction_object_type == 'Observation' && d.depiction_object.type == 'Observation::Media' }

  after_update :destroy_image_stub_collection_object, if: Proc.new {|d| d.depiction_object_type_previously_was == 'CollectionObject' && d.depiction_object_type == 'CollectionObject' }

  def from_sled?
    !sled_image_id.nil?
  end

  def sled_extraction_path(size = :thumb)
    if from_sled?
      x, y, w, h = svg_view_box.split(' ')

      box_width, box_height = nil, nil
      case size
      when :thumb, :medium
        box_width = Image::DEFAULT_SIZES[size][:width]
        box_height = Image::DEFAULT_SIZES[size][:height]
      when :original
        box_width = w.to_i
        box_height = h.to_i
      end

      "#{image_id}/scale_to_box/#{x.to_i}/#{y.to_i}/#{w.to_i}/#{h.to_i}/#{box_width}/#{box_height}"
    else
      raise 'This is not a sled derived depiction'
    end
  end

  private

  def remove_media_observation2
    if v = depiction_object_id_previously_was
      o = Observation::Media.find(v)
      if o.depictions.size == 0
        o.destroy!
      end
    end
  end

  def remove_media_observation
    if depiction_object.depictions.size == 0
      depiction_object.destroy!
    end
  end

  def destroy_image_stub_collection_object
    if sqed_depiction.present? 
      if v = depiction_object_id_previously_was
        o = CollectionObject.find(v)
        if o.is_image_stub?
          o.destroy!
        end
      end
    end
  end

end

#svg_view_boxString?

Returns sets the clipping box, identical dimensions to clip for rectangles.

Returns:

  • (String, nil)

    sets the clipping box, identical dimensions to clip for rectangles



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/models/depiction.rb', line 45

class Depiction < ApplicationRecord
  include Housekeeping
  include Shared::Tags
  include Shared::DataAttributes
  include Shared::IsData
  include Shared::PolymorphicAnnotator
  polymorphic_annotates(:depiction_object)

  acts_as_list scope: [:project_id, :depiction_object_type, :depiction_object_id]

  belongs_to :image, inverse_of: :depictions
  belongs_to :sled_image, inverse_of: :depictions
  has_one :sqed_depiction, dependent: :destroy

  accepts_nested_attributes_for :image
  accepts_nested_attributes_for :sqed_depiction, allow_destroy: true

  validates_presence_of :depiction_object
  validates_uniqueness_of :sled_image_id, scope: [:project_id, :sled_image_x_position, :sled_image_y_position], allow_nil: true, if: Proc.new {|n| !n.sled_image_id.nil?}

  after_update :remove_media_observation2, if: Proc.new {|d| d.depiction_object_type_previously_was == 'Observation' && d.depiction_object.type_was == 'Observation::Media' }
  after_destroy :remove_media_observation, if: Proc.new {|d| d.depiction_object_type == 'Observation' && d.depiction_object.type == 'Observation::Media' }

  after_update :destroy_image_stub_collection_object, if: Proc.new {|d| d.depiction_object_type_previously_was == 'CollectionObject' && d.depiction_object_type == 'CollectionObject' }

  def from_sled?
    !sled_image_id.nil?
  end

  def sled_extraction_path(size = :thumb)
    if from_sled?
      x, y, w, h = svg_view_box.split(' ')

      box_width, box_height = nil, nil
      case size
      when :thumb, :medium
        box_width = Image::DEFAULT_SIZES[size][:width]
        box_height = Image::DEFAULT_SIZES[size][:height]
      when :original
        box_width = w.to_i
        box_height = h.to_i
      end

      "#{image_id}/scale_to_box/#{x.to_i}/#{y.to_i}/#{w.to_i}/#{h.to_i}/#{box_width}/#{box_height}"
    else
      raise 'This is not a sled derived depiction'
    end
  end

  private

  def remove_media_observation2
    if v = depiction_object_id_previously_was
      o = Observation::Media.find(v)
      if o.depictions.size == 0
        o.destroy!
      end
    end
  end

  def remove_media_observation
    if depiction_object.depictions.size == 0
      depiction_object.destroy!
    end
  end

  def destroy_image_stub_collection_object
    if sqed_depiction.present? 
      if v = depiction_object_id_previously_was
        o = CollectionObject.find(v)
        if o.is_image_stub?
          o.destroy!
        end
      end
    end
  end

end

Instance Method Details

#destroy_image_stub_collection_objectObject (private)



111
112
113
114
115
116
117
118
119
120
# File 'app/models/depiction.rb', line 111

def destroy_image_stub_collection_object
  if sqed_depiction.present? 
    if v = depiction_object_id_previously_was
      o = CollectionObject.find(v)
      if o.is_image_stub?
        o.destroy!
      end
    end
  end
end

#from_sled?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'app/models/depiction.rb', line 70

def from_sled?
  !sled_image_id.nil?
end

#remove_media_observationObject (private)



105
106
107
108
109
# File 'app/models/depiction.rb', line 105

def remove_media_observation
  if depiction_object.depictions.size == 0
    depiction_object.destroy!
  end
end

#remove_media_observation2Object (private)



96
97
98
99
100
101
102
103
# File 'app/models/depiction.rb', line 96

def remove_media_observation2
  if v = depiction_object_id_previously_was
    o = Observation::Media.find(v)
    if o.depictions.size == 0
      o.destroy!
    end
  end
end

#sled_extraction_path(size = :thumb) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/models/depiction.rb', line 74

def sled_extraction_path(size = :thumb)
  if from_sled?
    x, y, w, h = svg_view_box.split(' ')

    box_width, box_height = nil, nil
    case size
    when :thumb, :medium
      box_width = Image::DEFAULT_SIZES[size][:width]
      box_height = Image::DEFAULT_SIZES[size][:height]
    when :original
      box_width = w.to_i
      box_height = h.to_i
    end

    "#{image_id}/scale_to_box/#{x.to_i}/#{y.to_i}/#{w.to_i}/#{h.to_i}/#{box_width}/#{box_height}"
  else
    raise 'This is not a sled derived depiction'
  end
end