Skip to content

Commit 7a955d7

Browse files
Merge pull request #786 from NREL/59994516_PluginDoors
I think this fixes the last issue, but now seeing issues that occur with. Thanks, I must have missed that.
2 parents 0b01b98 + 8ea7b27 commit 7a955d7

4 files changed

Lines changed: 57 additions & 39 deletions

File tree

openstudiocore/ruby/openstudio/sketchup_plugin/lib/interfaces/DrawingUtils.rb

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,47 +24,53 @@
2424
# Everything in this module should be strictly based on entities and not drawing interfaces.
2525
module DrawingUtils
2626

27-
27+
# returns true if entity is the base face of face
28+
def DrawingUtils.is_base_face(face, face_normal, face_points, entity)
29+
if (entity.class == Sketchup::Face and not entity.equal?(face))
30+
# Eliminate faces that are not parallel.
31+
# Another test would be to check if both are in the same plane.
32+
# There are some precision issues with 'face.plane' however.
33+
if (entity.normal.parallel?(face_normal))
34+
# Detect if the vertices of the entity are a subset of this face.
35+
if (face_points.is_subset_of?(entity.full_polygon.reduce.points))
36+
return true
37+
end
38+
end
39+
end
40+
return false
41+
end
42+
2843
# Strictly determined using Faces, not drawing interfaces.
2944
# Tries to match a face to a base face.
30-
def DrawingUtils.detect_base_face(face, force)
45+
def DrawingUtils.detect_base_face(face)
3146
base_face = nil
47+
first_guess = nil
3248

33-
if not force
34-
drawing_interface = face.drawing_interface
35-
if drawing_interface
36-
if drawing_interface.class == OpenStudio::SubSurface
37-
parent = drawing_interface.parent
38-
if parent
39-
base_face = parent.entity
40-
if base_face and base_face = Sketchup::Face
41-
return base_face
42-
else
43-
base_face = nil
44-
end
49+
# try the current parent as a first guess
50+
if drawing_interface = face.drawing_interface
51+
if drawing_interface.class == OpenStudio::SubSurface
52+
if parent = drawing_interface.parent
53+
if temp = parent.entity and temp.class == Sketchup::Face
54+
first_guess = temp
4555
end
46-
else
47-
# other classes don't have parent surfaces
48-
return nil
4956
end
5057
end
5158
end
5259

5360
face_normal = face.normal
5461
face_points = face.full_polygon.reduce.points
55-
56-
for child_entity in face.all_connected
57-
if (child_entity.class == Sketchup::Face and not child_entity.equal?(face))
58-
# Eliminate faces that are not parallel.
59-
# Another test would be to check if both are in the same plane.
60-
# There are some precision issues with 'face.plane' however.
61-
if (child_entity.normal.parallel?(face_normal))
62-
# Detect if the vertices of the entity are a subset of this face.
63-
if (face_points.is_subset_of?(child_entity.full_polygon.reduce.points))
64-
base_face = child_entity
65-
break
66-
end
67-
end
62+
63+
all_connected = face.all_connected
64+
if first_guess
65+
if all_connected.reject!{|e| e == first_guess}
66+
all_connected = [first_guess].concat(all_connected)
67+
end
68+
end
69+
70+
for entity in all_connected
71+
if is_base_face(face, face_normal, face_points, entity)
72+
base_face = entity
73+
break
6874
end
6975
end
7076
return(base_face)

openstudiocore/ruby/openstudio/sketchup_plugin/lib/interfaces/SubSurface.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def parent_from_entity
353353
Plugin.log(OpenStudio::Trace, "#{current_method_name}")
354354

355355
if (valid_entity?)
356-
if (base_face = DrawingUtils.detect_base_face(@entity, true))
356+
if (base_face = DrawingUtils.detect_base_face(@entity))
357357
return(base_face.drawing_interface)
358358
else
359359
return(super) # Return the space interface

openstudiocore/ruby/openstudio/sketchup_plugin/lib/interfaces/Surface.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,21 @@ def face_polygon
370370
# This is more dynamic than looking at @children which may not be up-to-date yet.
371371
child_faces = []
372372

373+
#puts "face_polygon = #{self}, #{@entity}"
374+
373375
# DLM: detect_base_face can be expensive, do we have to search all_connected? is there a way to cache the result of detect_base_face?
374376
for face in @entity.all_connected
375-
if (face.class == Sketchup::Face and @entity == DrawingUtils.detect_base_face(face, true))
376-
#puts "found child face->" + face.to_s
377-
child_faces << face
377+
if face.class == Sketchup::Face
378+
face_normal = face.normal
379+
face_points = face.full_polygon.reduce.points
380+
if DrawingUtils.is_base_face(face, face_normal, face_points, @entity)
381+
#puts "found child face->" + face.to_s
382+
child_faces << face
383+
end
378384
end
379385
end
386+
387+
#puts "child_faces = #{child_faces}"
380388

381389
reduced_polygon = Geom::Polygon.new(@entity.full_polygon.outer_loop.reduce) # Removes colinear points
382390
new_points = []

openstudiocore/ruby/openstudio/sketchup_plugin/lib/observers/SurfaceGroupEntitiesObserver.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def onElementAdded(entities, entity)
8282
# This is a brand new surface or a copy that had to be cleaned.
8383
if (@drawing_interface.class == Space)
8484

85-
base_face = DrawingUtils.detect_base_face(entity, true)
85+
base_face = DrawingUtils.detect_base_face(entity)
8686

8787
if (base_face.nil?)
8888
Plugin.log(OpenStudio::Info, "New Surface in Space")
@@ -172,9 +172,9 @@ def onElementAdded(entities, entity)
172172
base_face = nil
173173
if (@drawing_interface.class == Space)
174174
if (swapped)
175-
base_face = DrawingUtils.detect_base_face(entity.drawing_interface.entity, true)
175+
base_face = DrawingUtils.detect_base_face(entity.drawing_interface.entity)
176176
else
177-
base_face = DrawingUtils.detect_base_face(entity, true)
177+
base_face = DrawingUtils.detect_base_face(entity)
178178
end
179179
end
180180

@@ -235,6 +235,8 @@ def onElementAdded(entities, entity)
235235
original_surface.add_observers
236236

237237
new_surface = SubSurface.new_from_entity(original_entity)
238+
#puts "new_surface = #{new_surface}, #{new_surface.model_object.name}, #{new_surface.entity}"
239+
#puts "new_surface.parent = #{new_surface.parent}, #{new_surface.parent.model_object.name}, #{new_surface.parent.entity}"
238240

239241
# Must trigger the base surface to recalculate vertices to account for the new sub surface.
240242
original_surface.on_change_entity
@@ -244,8 +246,10 @@ def onElementAdded(entities, entity)
244246
Plugin.log(OpenStudio::Info, "Copy-paste/divide surface: new sub surface no swap")
245247
original_surface = entity.drawing_interface
246248

247-
SubSurface.new_from_entity(entity)
248-
249+
new_surface = SubSurface.new_from_entity(entity)
250+
#puts "new_surface = #{new_surface}, #{new_surface.model_object.name}, #{new_surface.entity}"
251+
#puts "new_surface.parent = #{new_surface.parent}, #{new_surface.parent.model_object.name}, #{new_surface.parent.entity}"
252+
249253
# Must trigger the base surface to recalculate vertices to account for the new sub surface.
250254
original_surface.on_change_entity
251255

0 commit comments

Comments
 (0)