forked from adavidzh/SketchUpCMS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcms_EBAR.rb
More file actions
executable file
·168 lines (119 loc) · 4.44 KB
/
cms_EBAR.rb
File metadata and controls
executable file
·168 lines (119 loc) · 4.44 KB
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
# Tai Sakuma <sakuma@fnal.gov>
require 'sketchup'
require File.dirname(__FILE__) + '/sitecfg.rb'
require 'gratr'
require 'buildGeometryManager'
require 'buildDDLCallBacks'
require 'readXMLFiles'
require 'PartBuilder'
require 'solids'
require 'graph_functions.rb'
require 'graph_functions_DD'
load 'PosPartExecuter.rb'
load 'LogicalPartInstance.rb'
load 'LogicalPartDefiner.rb'
##__________________________________________________________________||
def cmsmain
read_xmlfiles
# read_xmlfiles_from_cache
draw_gratr
end
##__________________________________________________________________||
def draw_gratr
# all PosParts in the XML file
graphAll = GRATR::DirectedPseudoGraph.new
$posPartsManager.parts.each { |pp| graphAll.add_edge!(pp.parentName, pp.childName, pp) }
vertices = Hash[$logicalPartsManager.parts.map { |p| [p.name, LogicalPartInstance.new($geometryManager, p)] } ]
topName = :"cms:CMSE"
subNames = [:"ebalgo:ESPM"]
nameDepthList = [
{:name => :"eregalgo:EFAW", :depth => 10},
{:name => :"eregalgo:EBCOOL1", :depth => 2},
{:name => :"eregalgo:EBCOOL2", :depth => 2},
{:name => :"eregalgo:EBCOOL3", :depth => 2},
{:name => :"eregalgo:EBCOOL4", :depth => 2},
]
graphTopToSub = subgraph_from_to(graphAll, topName, subNames)
names = nameDepthList.collect { |e| e[:name] }
graphSubToNames = subgraph_from_to(graphAll, subNames, names)
graphNamesToDepths = graphAll.class.new
nameDepthList.each do |e|
graphNamesToDepths = graphNamesToDepths + subgraph_from_depth(graphAll, e[:name], e[:depth])
end
graph = graphTopToSub + graphSubToNames + graphNamesToDepths
edges = graph.adjacent(:"ebalgo:ESPM", {:direction => :in, :type => :edges})
edges[0, 5].each do |e|
graph.remove_edge! e
end
edges[17, 1].each do |e|
graph.remove_edge! e
end
edges[18, 18].each do |e|
graph.remove_edge! e
end
make_logicalPart_unique(graph, edges[5, 3], vertices, true)
graph = subgraph_trim_depth graph, :"ebalgo:ESPM#1", 4
make_logicalPart_unique(graph, edges[8, 3], vertices, true)
graph = subgraph_trim_depth graph, :"ebalgo:ESPM#2", 3
make_logicalPart_unique(graph, edges[11, 3], vertices, true)
graph = subgraph_trim_depth graph, :"ebalgo:ESPM#3", 2
graph = subgraph_trim_depth graph, :"ebalgo:ESPM", 1
graph = subgraph_from(graph, topName)
n_instances = n_paths(graph, topName)
graph.topsort.each do |v|
puts " %-30s %10d %s" % [v, n_instances[v], vertices[v].inspect]
end
draw_array graph, vertices, topName
end
##__________________________________________________________________||
def draw_array graph, vertexLabel, topName
Sketchup.active_model.definitions.purge_unused
start_time = Time.now
Sketchup.active_model.start_operation("Draw CMS", true)
posPartExecuter = PosPartExecuter.new $geometryManager
graph.edges.each do |edge|
posPart = edge.label
posPartExecuter.exec posPart, vertexLabel[edge.source], vertexLabel[edge.target]
end
graph.topsort.reverse.each do |v|
logicalPart = vertexLabel[v]
next if logicalPart.children.size > 0 and logicalPart.materialName.to_s =~ /Air$/
next if logicalPart.children.size > 0 and logicalPart.materialName.to_s =~ /free_space$/
logicalPart.placeSolid()
end
# $logicalPartsManager.get(topName).placeSolid()
graph.topsort.reverse.each do |v|
logicalPart = vertexLabel[v]
logicalPart.define()
end
lp = vertexLabel[topName.to_sym]
definition = lp.definition
if definition
entities = Sketchup.active_model.entities
transform = Geom::Transformation.new(Geom::Point3d.new(0, 0, 15.m))
solidInstance = entities.add_instance definition, transform
end
Sketchup.active_model.commit_operation
end_time = Time.now
puts "Time elapsed #{(end_time - start_time)*1000} milliseconds"
end
##__________________________________________________________________||
def read_xmlfiles
topDir = File.expand_path(File.dirname(__FILE__)) + '/'
xmlfileListTest = [
'GeometryExtended.xml'
]
xmlfileList = xmlfileListTest
xmlfileList.map! {|f| f = topDir + f }
p xmlfileList
geometryManager = buildGeometryManager()
callBacks = buildDDLCallBacks(geometryManager)
readXMLFiles(xmlfileList, callBacks)
end
##__________________________________________________________________||
def read_xmlfiles_from_cache
fillGeometryManager($geometryManager)
$geometryManager.reload_from_cache
end
##__________________________________________________________________||
cmsmain