WIP Add migration for flipping clipping planes that were created in OP (#9682)

pull/9706/head
Wieland Lindenthal 3 years ago committed by GitHub
parent 44a52aeb2f
commit 178e8abe50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 43
      db/migrate/20210713081724_flip_bcf_viewpoint_clipping_direction_selectively.rb
  2. 4
      modules/bim/app/models/bim/bcf/viewpoint.rb

@ -0,0 +1,43 @@
class FlipBcfViewpointClippingDirectionSelectively < ActiveRecord::Migration[6.1]
def up
flip_op_clipping_planes
end
def down
flip_op_clipping_planes
end
private
def flip_op_clipping_planes
viewpoints = select_viewpoints_created_in_op
viewpoints.each do |viewpoint|
new_json_viewpoint = flip_clipping_planes(viewpoint.json_viewpoint)
viewpoint.update_column(:json_viewpoint, new_json_viewpoint)
end
end
def select_viewpoints_created_in_op
join_condition = %{
bcf_viewpoints.json_viewpoint->>'clipping_planes' IS NOT NULL
AND
(
bcf_issues.markup IS NULL
OR
XPATH_EXISTS('/comment()[contains(., ''Created by OpenProject'')]', bcf_issues.markup)
)
}
::Bim::Bcf::Viewpoint.joins(:issue).where(join_condition)
end
def flip_clipping_planes(viewpoint)
viewpoint_dup = viewpoint.deep_dup
viewpoint_dup["clipping_planes"].each do |plane|
plane["direction"]["x"] *= -1
plane["direction"]["y"] *= -1
plane["direction"]["z"] *= -1
end
viewpoint_dup
end
end

@ -35,6 +35,10 @@ module Bim::Bcf
end
end
def clipping_planes?
json_viewpoint && json_viewpoint["clipping_planes"]
end
def snapshot=(file)
snapshot&.destroy
attach_files('first' => { 'file' => file, 'description' => 'snapshot' })

Loading…
Cancel
Save