forked from une-young/indoorgml-modeler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndoorGmlModeler.rb
2671 lines (2121 loc) · 72.6 KB
/
IndoorGmlModeler.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# frozen_string_literal: true
require 'sketchup.rb'
require 'json'
require 'rexml/document'
# IndoorGml modeler
# copyright 2020 UNE.co.kr
# include Sketchup
module UNES
include Sketchup
include REXML
include Geom
module IndoorGmlModeler
module EditMode
NONE = 0
CELL = 1
NODE = 2
POI = 3
DOOR = 4
FLOOR = 5
VALIDATION = 6
end
class Element
attr_reader :name
attr_writer :name
attr_reader :id
attr_writer :id
def initialize
@name = ''
# @id = SecureRandom.base64(8).gsub("/","_").gsub(/=+$/,"")
@id = rand(36**8).to_s(36)
end
end
# transition node
class Node < Element
attr_reader :position
attr_writer :position
attr_reader :parent
attr_writer :parent
attr_reader :component
attr_writer :component
attr_accessor :component_id
attr_reader :node_type
attr_writer :node_type
attr_reader :anchor
attr_writer :anchor
# @@node_type_names = %w[NONE DOOR WINDOW ROOM]
def initialize
super
@position = Geom::Point3d.new
# node가 속한 객체 (cell space나 door 혹은 다른 것들)
@parent = nil
# node의 형상 entity (Component)
@component = nil
@component_id = nil
@node_type = 'NORMAL'
@anchor = Anchor.new
end
end
# anchor class
class Anchor
MAIN = UNES::IndoorGmlModeler
attr_reader :position
attr_writer :position
attr_reader :rotation
attr_writer :rotation
def initialize
# 위경도
@position = Geom::Point3d.new
@rotation = 0.0
end
def read(file_path)
lines = File.readlines(file_path)
return unless !lines.nil? && lines.length == 3
x = lines[0].to_f
y = lines[1].to_f
rotation = lines[2].to_f
@position = Geom::Point3d.new(x, y, 0)
@rotation = rotation
end
def write(file_path, id)
data = ''
data.concat(id)
data.concat('\n')
data.concat(@position.x.to_s)
data.concat('\n')
data.concat(@position.y.to_s)
data.concat('\n')
data.concat(@rotation.to_s)
File.write(file_path, data)
end
end
module CellType
SPACE = 0
DOOR = 1
WINDOW = 2
ELEVATOR = 3
STAIR = 4
end
module DoorType
PASSABLE = 0
ONESIDE = 1
NOTPASSABLE = 2
end
# module PoiType
# NONE = 0
# SPACE = 1
# ETC = 2
# end
module NodeType
NONE = 0
DOOR = 1
WINDOW = 2
ROOM = 3
end
# building
class Building < Element
attr_reader :floors
attr_writer :floors
def initialize
@floors = []
end
def to_hash
hash_list = []
@floors.each do |f|
hash_list.push f.to_hash
end
hash_list
end
end
# floor
class Floor < Element
attr_reader :height
attr_writer :height
attr_reader :elevation
attr_writer :elevation
attr_reader :group
attr_writer :group
def initialize(height, elevation)
@cells = []
@links = []
@doors = []
@nodes = []
@pois = []
@layer = nil
@height = height
@elevation = elevation
# @group = nil
# model = Sketchup.active_model
# depth = 1000 / 1.to_m # 1000 미터가 되기 위한 인치수를 구함
# width = 1000 / 1.to_m
# pts = []
# pts[0] = [-width, -depth, elevation]
# pts[1] = [width, -depth, elevation]
# pts[2] = [width, depth, elevation]
# pts[3] = [-width, depth, elevation]
# face = model.entities.add_face pts
# face.pushpull(-@height, false)
# @group = model.entities.add_group face.all_connected
# @group.hidden = true
end
def to_hash
{
name: @name,
elevation: @elevation,
height: @height
}
end
def is_in(entity, parent_group = nil)
return false if @group.nil? || entity.nil?
return false if @group.deleted?
return false if entity.deleted?
if parent_group.nil?
bounds = @group.bounds.intersect(entity.bounds)
else
outter_bounds = parent_group.bounds
inner_bounds = entity.bounds
min = inner_bounds.min
max = inner_bounds.max
world_min = min.transform(outter_bounds.transformation)
world_max = max.transform(outter_bounds.transformation)
world_bounds = Geom::BoundingBox.new
world_bounds.add world_min
world_bounds.add world_max
bounds = @group.bounds.intersect(world_bounds)
end
return false if bounds.empty?
true
end
end
# cell space
class Cell < Element
attr_reader :group
attr_writer :group
attr_reader :cell_type
attr_writer :cell_type
attr_reader :doors
attr_writer :doors
attr_reader :node
attr_writer :node
attr_reader :layer
attr_writer :layer
attr_accessor :group_id
@@cell_type_names = %w[SPACE DOOR WINDOW ELEVATOR STAIR]
def initialize
super
@group = nil
@cell_type = CellType::SPACE
@doors = []
@node = nil
# layer는 그냥 text 이름임
@layer = 'group 0'
@group_id = nil
end
def get_cell_type_name
@@cell_type_names[@cell_type]
end
class << self
def get_cell_type_by_name(cell_type_name)
counter = 0
@@cell_type_names.each do |n|
return counter if cell_type_name == n
counter += 1
end
-1
end
end
def has_entity(entity)
false if entity.nil?
if @group.is_a?(Sketchup::Group)
true unless @group.entities.find_index(entity).nil?
end
false
end
end
# transition link
class Link < Element
attr_reader :node1
attr_writer :node1
attr_reader :node2
attr_writer :node2
attr_reader :line
attr_writer :line
def initialize
super
@node1 = nil
@node2 = nil
# 노드 사이 연결을 나타내는 line (polyline이 될수도 있음)
@line = nil
end
def isSame(n1, n2)
return true if @node1 == n1 && @node2 == n2
return true if @node1 == n2 && @node2 == n1
false
end
def to_hash
{
node1_id: @node1.id,
node1_name: @node1.name,
node2_id: @node2.id,
node2_name: @node2.name
}
end
def update_line
return false if @node1.component.deleted?
point1 = @node1.component.bounds.center
point1 = point1.transform(node1.parent.group.transformation) if @node1.parent.is_a?(Cell)
return false if @node2.component.deleted?
point2 = @node2.component.bounds.center
point2 = point2.transform(node2.parent.group.transformation) if @node2.parent.is_a?(Cell)
entities = Sketchup.active_model.active_entities
entities.erase_entities @line unless @line.nil?
@line = entities.add_cline(point1, point2)
end
end
# cell space 사이의 transition을 만들기 위해 필요한 객체
class Door < Element
attr_reader :face
attr_writer :face
attr_reader :group
attr_writer :group
attr_reader :door_type
attr_writer :door_type
attr_reader :node
attr_writer :node
attr_reader :face_vertices
attr_writer :face_vertices
@@door_type_names = %w[PASSABLE ONESIDE NOTPASSABLE]
def initialize
super
@face = nil
@group = nil
@door_type = DoorType::PASSABLE
@node = nil
@face_vertices = []
end
def update_door_face
# 겹치는 face를 찾음
if @face.nil? || @face.deleted?
model = Sketchup.active_model
i = 0
while i < model.entities.length() do
e = model.entities[i]
if e.is_a?(Sketchup::Face) && !e.deleted?
result = e.bounds.intersect(node.component.bounds)
unless result.empty?
@face = e
break
end
end
i += 1
end
end
end
def get_door_type_name
@@door_type_names[@door_type]
end
end
class Poi < Element
attr_reader :component
attr_writer :component
attr_reader :poi_type1
attr_writer :poi_type1
attr_reader :poi_type2
attr_writer :poi_type2
attr_reader :poi_type3
attr_writer :poi_type3
attr_reader :position
attr_writer :position
# @@poi_type_names = %w[NONE SPACE ETC]
def initialize
super
# poi 3차원 형태 인스턴스
@component = nil
@poi_type1 = 'NONE'
@poi_type2 = 'NONE'
@poi_type3 = 'NONE'
@position = Geom::Point3d.new
end
# def get_poi_type_name
# @@poi_type_names[@poi_type]
# end
end
class IndoorGmlEntitiesObserver < Sketchup::EntitiesObserver
MAIN = UNES::IndoorGmlModeler
def onElementAdded(entities, entity)
return if entity.deleted?
puts "onElementAdded: #{entity.entityID}"
return if MAIN.deleted_cells.nil? || MAIN.deleted_cells.empty?
cell = MAIN.deleted_cells[entity.entityID]
return if cell.nil?
restore_cell(entity, cell)
node_component = cell.group.entities.select { |e| e.entityID == cell.node.component_id }
node = MAIN.deleted_nodes[node_component[0].entityID]
return if node.nil?
restore_node(node_component[0], node)
end
def restore_cell(entity, cell)
puts cell
MAIN.cells.push(cell) unless cell.nil?
puts "cell count:#{MAIN.cells.length}"
MAIN.deleted_cells.delete(entity.entityID)
cell.group = entity
end
def restore_node(entity, node)
puts node
MAIN.nodes.push(node) unless node.nil?
puts "node count:#{MAIN.nodes.length}"
MAIN.deleted_nodes.delete(entity.entityID)
node.component = entity
end
def onElementModified(entities, entity)
puts "onElementModified: #{entity.entityID }"
end
def onElementRemoved(entities, entity_id)
puts "onElementRemoved: #{entity_id}"
cell = MAIN.cells.select { |c| c.group.deleted? }
return if cell.nil? || cell.empty?
if cell.is_a?(Array)
cell.each do |c|
deleteCell(entity_id, c)
end
else
deleteCell(entity_id, cell)
end
node = MAIN.nodes.select { |n| n.component.deleted? }
return if node.nil?
if node.is_a?(Array)
node.each do |n|
deleteNode(n.component_id, n)
end
else
deleteNode(n.component_id, node)
end
end
def deleteCell(entity_id, cell)
puts cell
MAIN.cells.delete(cell) unless cell.nil?
puts "cell count:#{MAIN.cells.length}"
MAIN.deleted_cells[entity_id] = cell
end
def deleteNode(entity_id, node)
puts node
# delete link
links = MAIN.get_links_by_node(node)
links.each do |l|
MAIN.links.delete(l)
entities = Sketchup.active_model.active_entities
entities.erase_entities l.line unless l.line.deleted?
l.line = nil
end
MAIN.nodes.delete(node) unless node.nil?
puts "node count:#{MAIN.nodes.length}"
MAIN.deleted_nodes[entity_id] = node
end
end
class CellObserver < Sketchup::EntityObserver
MAIN = UNES::IndoorGmlModeler
def onChangeEntity(entity)
return if entity.deleted?
return unless entity.is_a?(Sketchup::Group)
cell = MAIN.find_cell_by_group_id entity.entityID
MAIN.links.each do |l|
l.update_line if l.node1 == cell.node
l.update_line if l.node2 == cell.node
end
end
end
class NodeObserver < Sketchup::EntityObserver
MAIN = UNES::IndoorGmlModeler
def onChangeEntity(entity)
return if entity.deleted?
return unless entity.is_a?(Sketchup::ComponentInstance)
node = MAIN.finde_node_by_component_id(entity.entityID)
return if node.nil?
MAIN.links.each do |l|
l.update_line if l.node1 == node
l.update_line if l.node2 == node
end
end
end
class SelectionChangeObserver < Sketchup::SelectionObserver
MAIN = UNES::IndoorGmlModeler
def onSelectionAdded(selection, _entity)
MAIN.on_selection_change(selection)
end
def onSelectionBulkChange(selection)
MAIN.on_selection_change(selection)
end
def onSelectionCleared(selection)
MAIN.on_selection_change(selection)
end
def onSelectionRemoved(selection, _entity)
MAIN.on_selection_change(selection)
end
def onSelectedRemoved(selection, _entity)
MAIN.on_selection_change(selection)
end
end
class AppObserver < Sketchup::AppObserver
MAIN = UNES::IndoorGmlModeler
def onNewModel(model)
observe_model(model)
end
def onOpenModel(model)
observe_model(model)
end
def expectsStartupModelNotifications
true
end
private
def observe_model(model)
model.selection.add_observer(SelectionChangeObserver.new)
model.entities.add_observer(IndoorGmlEntitiesObserver.new)
MAIN.clean_variables
MAIN.update_materials
end
end
class << self
attr_reader :cells
attr_writer :cells
attr_accessor :nodes
attr_reader :doors
attr_writer :doors
attr_reader :links
attr_writer :links
attr_accessor :deleted_cells
attr_accessor :deleted_nodes
attr_accessor :deleted_links
attr_reader :edit_mode
attr_writer :edit_mode
def initialize_data
@command = UI::Command.new('MainTool') do
begin
Sketchup.active_model.select_tool(MainTool.new)
rescue StandardError => e
puts e.message
puts e.backtrace
end
end
clean_variables
end
def clean_variables
@nodes = []
@links = []
@cells = []
@doors = []
@pois = []
@model = Sketchup.active_model
@cell_creation_count = 0
@door_creation_count = 0
@node_creation_count = 0
@link_creation_count = 0
@poi_creation_count = 0
@floor_creation_count = 0
@edit_mode = EditMode::NONE
@building = Building.new
# 삭제된 cell,node들 (unde/redo 대책)
# key는 entityID
@deleted_cells = {}
@deleted_nodes = {}
@deleted_links = {}
floor = Floor.new(3.5 / 1.to_m, 0) # 1층
floor.name = @name = "Floor#{@floor_creation_count}"
@floor_creation_count += 1
@building.floors.push floor
end
def update_materials
materials = Sketchup.active_model.materials
@cell_material = materials.add('indoor_cell')
@cell_material.color = Sketchup::Color.new('red')
@cell_material.alpha = 0.3
@stair_material = materials.add('indoor_stair')
@stair_material.color = Sketchup::Color.new('yellow')
@stair_material.alpha = 0.3
@door_material = materials.add('indoor_door')
@door_material.color = Sketchup::Color.new('green')
@door_material.alpha = 0.8
@node_material = materials.add('indoor_link')
@node_material.color = Sketchup::Color.new('blue')
end
def create_link(node1, node2)
return nil if is_link_exist(node1, node2)
link = Link.new
link.node1 = node1
link.node2 = node2
return false if node1.component.deleted?
point1 = node1.component.bounds.center
point1 = point1.transform(node1.parent.group.transformation) if node1.parent.is_a?(Cell)
return false if node2.component.deleted?
point2 = node2.component.bounds.center
point2 = point2.transform(node2.parent.group.transformation) if node2.parent.is_a?(Cell)
entities = @model.active_entities
link.line = entities.add_cline(point1, point2)
link
end
def get_link(node1,node2)
@links.each do |l|
return l if l.isSame(node1, node2)
end
nil
end
def get_links_by_node(node)
node_links = []
@links.each do |l|
if l.node1.id == node.id || l.node2.id == node.id
node_links.push(l)
end
end
node_links
end
def get_links_by_id(node_id1, node_id2)
node_links = []
@links.each do |l|
if (l.node1.id == node_id1 && l.node2.id == node_id2) || (l.node1.id == node_id2 && l.node2.id == node_id1)
node_links.push(l)
end
end
node_links
end
def is_link_exist(node1, node2)
@links.each do |l|
return true if l.isSame(node1, node2)
end
false
end
# TODO: 함수가 너무 길어서 줄여야 할듯.
# TODO: You shoude shorten this function.
def create_cell(entity)
cell = nil
if entity.is_a?(Sketchup::Face)
unless is_cell_exist(entity)
cell = Cell.new
all_connected = entity.all_connected
all_connected.push entity
group = Sketchup.active_model.entities.add_group all_connected
unless group.manifold?
group.explode
return nil
end
cell.group = group
end
elsif entity.is_a?(Sketchup::Group)
cell = get_cell(entity)
if cell.nil?
cell = Cell.new
cell.group = entity
end
elsif entity.is_a?(Sketchup::ComponentInstance)
cell = get_cell(entity)
if cell.nil?
cell = Cell.new
cell.group = entity
end
end
unless cell.nil?
cell.name = 'cell_' + @cell_creation_count.to_s
node = create_node(cell)
#group_name = cell.group.name
# node를 cell 그룹에 추가
# add node to cell group
a = (cell.group.explode.find_all { |e| e if e.respond_to?(:bounds) }).uniq
a.push node.component
group = Sketchup.active_model.entities.add_group a
cell.group = group
cell.group_id = group.entityID
cell.node = node
# cell.group.name = "#{cell.name}@@@#{cell.id}"
#cell.group.name = group_name
cell.group.material = @cell_material
cell.group.name = cell.name if cell.group.name.length.zero?
a.each do |e|
e.material = @cell_material if e.is_a?(Sketchup::Face)
end
cell.group.add_observer(CellObserver.new)
@cell_creation_count += 1
@cells.push(cell)
end
# node link 갱신
# update node-link
# space cell 이라고 해도 옆에 door나 stair cell이 있을 경우 처리를 해야 하기 때문에 호출 해야 한다.
# You shoude call 'update_all_nodes' even if cell type is SPACE. because, There are another door or stair cells.
update_all_nodes
cell
end
# 모든 node-link를 갱신한다. door의 경우 인접 cell과 연결한다.
# Update all node-links. If cell type is a door, link adjacented cells
def update_all_nodes
@nodes.each do |n|
next unless n.parent.is_a?(Cell)
result = get_intersected_cells_from_node(n) if n.parent.cell_type == CellType::DOOR
result = get_vertical_intersected_cells_from_node(n) if n.parent.cell_type == CellType::STAIR
next if result.nil?
result.each do |c|
# link가 존재하지 않는다면 link를 생성
next if is_link_exist(c.node, n)
link = create_link c.node, n
@links.push link unless link.nil?
end
end
end
def get_vertical_intersected_cells_from_node(node)
intersected = []
@cells.each do |c|
next if c == node.parent
result = c.group.bounds.intersect(node.parent.group.bounds)
puts "#{result.depth},#{result.diagonal},#{result.width},#{result.height}" unless result.empty?
intersected.push c if !result.empty? && result.depth.to_f == 0.0
end
intersected
end
def get_intersected_cells_from_node(node)
intersected = []
@cells.each do |c|
next if c == node.parent
result = c.group.bounds.intersect(node.parent.group.bounds)
puts "#{result.depth},#{result.diagonal},#{result.width},#{result.height}" unless result.empty?
intersected.push c unless result.empty?
end
intersected
end
def find_cell_by_group_id(entityID)
@cells.each do |c|
next if c.group.deleted?
return c if c.group.entityID == entityID
end
nil
end
def finde_node_by_component_id(entity_id)
@nodes.each do |n|
next if n.component.deleted?
return n if n.component.entityID == entity_id
end
nil
end
def create_node(element)
nil if element.nil?
center = nil
center = element.group.bounds.center if element.is_a?(Cell)
if element.is_a?(Door)
center = element.group.bounds.center if element.face.nil? && !element.group.nil?
center = element.face.bounds.center if element.group.nil? && !element.face.nil?
end
# component instance를 반환
instance = create_sphere(center, 0.25 / 1.to_m, @node_material)
node = Node.new
node.name = 'node_' + @node_creation_count.to_s
node.parent = element
element.node = node
node.component = instance
node.component_id = instance.entityID
node.position = center
node.component.add_observer(NodeObserver.new)
@node_creation_count += 1
@nodes.push(node)
node
end
def is_cell_exist(face)
cell_exist = false
@cells.each do |c|
if c.has_entity face
cell_exist = true
break
end
end
cell_exist
end
# group에서 cell을 가져온다 없으면 nil
def get_cell(group)
@cells.each do |c|
return c if c.group == group
end
nil
end
# id로 cell을 가져온다.
def get_cell_by_id(id)
@cells.each do |c|
return c if c.id == id
end
nil
end
# name으로 cell을 가져온다. 중복되었으면 첫번째만
def get_cell_by_name(name)
@cells.each do |c|
return c if c.name == name
end
nil
end
# id로 poi를 가져온다.
def get_poi_by_id(id)
@pois.each do |p|
return p if p.id == id
end
nil
end
# ide로 node를 가져온다.
def get_node_by_id(id)
@nodes.each do |n|
return n if n.id == id
end
nil
end
# 이름으로 node를 가져온다.
def get_node_by_name(name)
@nodes.each do |n|
return n if n.name == name
end
nil
end
def get_node(component)
@nodes.each do |n|
return n if n.component == component
end
nil
end
# group 혹은 componentInstance에서 poi를 생성한다.
def create_poi(entity)
if entity.is_a?(Sketchup::ComponentInstance)
if get_poi(entity).nil?
poi = Poi.new
poi.name = 'poi_' + @poi_creation_count.to_s