topologicpy 0.7.64__py3-none-any.whl → 0.7.66__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
topologicpy/Graph.py CHANGED
@@ -264,7 +264,7 @@ class _DrawTree(object):
264
264
  return self.__str__()
265
265
 
266
266
  class Graph:
267
- def AdjacencyDictionary(graph, vertexLabelKey: str = "label", edgeKey: str = "Length", reverse: bool = False, mantissa: int = 6):
267
+ def AdjacencyDictionary(graph, vertexLabelKey: str = "label", edgeKey: str = "Length", includeWeights: bool = False, reverse: bool = False, mantissa: int = 6):
268
268
  """
269
269
  Returns the adjacency dictionary of the input Graph.
270
270
 
@@ -277,6 +277,8 @@ class Graph:
277
277
  If the vertexLabelKey does not exist, it will be created and the vertices are labelled numerically and stored in the vertex dictionary under this key. The default is "label".
278
278
  edgeKey : str , optional
279
279
  If set, the edges' dictionaries will be searched for this key to set their weight. If the key is set to "length" (case insensitive), the length of the edge will be used as its weight. If set to None, a weight of 1 will be used. The default is "Length".
280
+ includeWeights : bool , optional
281
+ If set to True, edge weights are included. Otherwise, they are not. The default is False.
280
282
  reverse : bool , optional
281
283
  If set to True, the vertices are sorted in reverse order (only if vertexKey is set). Otherwise, they are not. The default is False.
282
284
  mantissa : int , optional
@@ -326,22 +328,29 @@ class Graph:
326
328
  adjVertices = Graph.AdjacentVertices(graph, v)
327
329
  temp_list = []
328
330
  for adjVertex in adjVertices:
329
- if edgeKey == None:
330
- weight = 1
331
- elif "length" in edgeKey.lower():
332
- edge = Graph.Edge(graph, v, adjVertex)
333
- weight = Edge.Length(edge, mantissa=mantissa)
331
+ adjIndex = Vertex.Index(adjVertex, vertices)
332
+ if not adjIndex == None:
333
+ adjLabel = labels[adjIndex]
334
334
  else:
335
- edge = Graph.Edge(graph, v, adjVertex)
336
- weight = Dictionary.ValueAtKey(Topology.Dictionary(edge), edgeKey)
337
- if weight == None:
335
+ adjLabel = None
336
+ if includeWeights == True:
337
+ if edgeKey == None:
338
+ weight = 1
339
+ elif "length" in edgeKey.lower():
340
+ edge = Graph.Edge(graph, v, adjVertex)
338
341
  weight = Edge.Length(edge, mantissa=mantissa)
339
342
  else:
340
- weight = round(weight, mantissa)
341
- adjIndex = Vertex.Index(adjVertex, vertices)
342
- adjLabel = labels[adjIndex]
343
- if not adjIndex == None:
344
- temp_list.append((adjLabel, weight))
343
+ edge = Graph.Edge(graph, v, adjVertex)
344
+ weight = Dictionary.ValueAtKey(Topology.Dictionary(edge), edgeKey)
345
+ if weight == None:
346
+ weight = Edge.Length(edge, mantissa=mantissa)
347
+ else:
348
+ weight = round(weight, mantissa)
349
+ if not adjIndex == None:
350
+ temp_list.append((adjLabel, weight))
351
+ else:
352
+ if not adjIndex == None:
353
+ temp_list.append(adjLabel)
345
354
  temp_list.sort()
346
355
  adjDict[vertex_label] = temp_list
347
356
  return adjDict
@@ -548,7 +557,7 @@ class Graph:
548
557
  elif (len(gk) < 1) and (len(vk) > 0):
549
558
  d = vd
550
559
  if d:
551
- _ = Topology.SetDictionary(gv, d)
560
+ _ = Topology.SetDictionary(gv, d, silent=True)
552
561
  unique = False
553
562
  returnVertex = gv
554
563
  break
@@ -577,7 +586,7 @@ class Graph:
577
586
  keys = Dictionary.Keys(d)
578
587
  if isinstance(keys, list):
579
588
  if len(keys) > 0:
580
- _ = Topology.SetDictionary(new_edge, d)
589
+ _ = Topology.SetDictionary(new_edge, d, silent=True)
581
590
  graph_edges.append(new_edge)
582
591
  new_graph = Graph.ByVerticesEdges(graph_vertices, graph_edges)
583
592
  return new_graph
@@ -614,7 +623,7 @@ class Graph:
614
623
  if not silent:
615
624
  print("Graph.AddVertex - Error: The input vertex is not a valid vertex. Returning the input graph.")
616
625
  return graph
617
- _ = graph.AddVertices([vertex], tolerance)
626
+ _ = graph.AddVertices([vertex], tolerance) # Hook to core library
618
627
  return graph
619
628
 
620
629
  @staticmethod
@@ -654,7 +663,7 @@ class Graph:
654
663
  if not silent:
655
664
  print("Graph.AddVertices - Error: Could not find any valid vertices in the input list of vertices. Returning None.")
656
665
  return None
657
- _ = graph.AddVertices(vertices, tolerance)
666
+ _ = graph.AddVertices(vertices, tolerance) # Hook to core library
658
667
  return graph
659
668
 
660
669
  @staticmethod
@@ -688,7 +697,7 @@ class Graph:
688
697
  print("Graph.AdjacentVertices - Error: The input vertex is not a valid vertex. Returning None.")
689
698
  return None
690
699
  vertices = []
691
- _ = graph.AdjacentVertices(vertex, vertices)
700
+ _ = graph.AdjacentVertices(vertex, vertices) # Hook to core library
692
701
  return list(vertices)
693
702
 
694
703
  @staticmethod
@@ -730,7 +739,7 @@ class Graph:
730
739
  print("Graph.AllPaths - Error: The input vertexB is not a valid vertex. Returning None.")
731
740
  return None
732
741
  paths = []
733
- _ = graph.AllPaths(vertexA, vertexB, True, timeLimit, paths)
742
+ _ = graph.AllPaths(vertexA, vertexB, True, timeLimit, paths) # Hook to core library
734
743
  return paths
735
744
 
736
745
  @staticmethod
@@ -2478,20 +2487,179 @@ class Graph:
2478
2487
  from topologicpy.Cluster import Cluster
2479
2488
  from topologicpy.Topology import Topology
2480
2489
  from topologicpy.Aperture import Aperture
2490
+
2491
+ def _viaSharedTopologies(vt, sharedTops):
2492
+ verts = []
2493
+ eds = []
2494
+ for sharedTopology in sharedTops:
2495
+ if useInternalVertex == True:
2496
+ vst = Topology.InternalVertex(sharedTopology, tolerance)
2497
+ else:
2498
+ vst = Topology.CenterOfMass(sharedTopology)
2499
+ d1 = Topology.Dictionary(sharedTopology)
2500
+ d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 1) # shared topology
2501
+ if storeBREP:
2502
+ d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(sharedTopology), Topology.Type(sharedTopology), Topology.TypeAsString(sharedTopology)])
2503
+ d3 = mergeDictionaries2([d1, d2])
2504
+ vst = Topology.SetDictionary(vst, d3, silent=True)
2505
+ else:
2506
+ vst = Topology.SetDictionary(vst, d1, silent=True)
2507
+ verts.append(vst)
2508
+ tempe = Edge.ByStartVertexEndVertex(vt, vst, tolerance=tolerance)
2509
+ tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["Via_Shared_Topologies", 1])
2510
+ tempe = Topology.SetDictionary(tempe, tempd, silent=True)
2511
+ eds.append(tempe)
2512
+ return verts, eds
2513
+
2514
+ def _viaSharedApertures(vt, sharedAps):
2515
+ verts = []
2516
+ eds = []
2517
+ for sharedAp in sharedAps:
2518
+ if useInternalVertex == True:
2519
+ vsa = Topology.InternalVertex(sharedAp, tolerance)
2520
+ else:
2521
+ vsa = Topology.CenterOfMass(sharedAp)
2522
+ d1 = Topology.Dictionary(sharedAp)
2523
+ d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 2) # shared aperture
2524
+ vsa = Vertex.ByCoordinates(Vertex.X(vsa, mantissa=mantissa)+(tolerance*100), Vertex.Y(vsa, mantissa=mantissa)+(tolerance*100), Vertex.Z(vsa, mantissa=mantissa)+(tolerance*100))
2525
+ if storeBREP:
2526
+ d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(sharedAp), Topology.Type(sharedAp), Topology.TypeAsString(sharedAp)])
2527
+ d3 = mergeDictionaries2([d1, d2])
2528
+ vsa = Topology.SetDictionary(vsa, d3, silent=True)
2529
+ else:
2530
+ vsa = Topology.SetDictionary(vsa, d1, silent=True)
2531
+ verts.append(vsa)
2532
+ tempe = Edge.ByStartVertexEndVertex(vt, vsa, tolerance=tolerance)
2533
+ tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["Via_Shared_Apertures", 2])
2534
+ tempe = Topology.SetDictionary(tempe, tempd, silent=True)
2535
+ eds.append(tempe)
2536
+ return verts, eds
2537
+
2538
+ def _toExteriorTopologies(vt, exteriorTops):
2539
+ verts = []
2540
+ eds = []
2541
+ for exteriorTop in exteriorTops:
2542
+ if useInternalVertex == True:
2543
+ vet = Topology.InternalVertex(exteriorTop, tolerance)
2544
+ else:
2545
+ vet = Topology.CenterOfMass(exteriorTop)
2546
+ vet = Topology.SetDictionary(vet, Topology.Dictionary(exteriorTop), silent=True)
2547
+ d1 = Topology.Dictionary(exteriorTop)
2548
+ d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 3) # exterior topology
2549
+ if storeBREP:
2550
+ d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(exteriorTop), Topology.Type(exteriorTop), Topology.TypeAsString(exteriorTop)])
2551
+ d3 = mergeDictionaries2([d1, d2])
2552
+ vet = Topology.SetDictionary(vet, d3, silent=True)
2553
+ else:
2554
+ vet = Topology.SetDictionary(vet, d1, silent=True)
2555
+ verts.append(vet)
2556
+ tempe = Edge.ByStartVertexEndVertex(vt, vet, tolerance=tolerance)
2557
+ tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Exterior_Topologies", 3])
2558
+ tempe = Topology.SetDictionary(tempe, tempd, silent=True)
2559
+ eds.append(tempe)
2560
+ return verts, eds
2561
+
2562
+ def _toExteriorApertures(vt, exteriorAps):
2563
+ verts = []
2564
+ eds = []
2565
+ for exAp in exteriorAps:
2566
+ if useInternalVertex == True:
2567
+ vea = Topology.InternalVertex(exAp, tolerance)
2568
+ else:
2569
+ vea = Topology.CenterOfMass(exAp)
2570
+ d1 = Topology.Dictionary(exAp)
2571
+ d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 4) # exterior aperture
2572
+ vea = Vertex.ByCoordinates(Vertex.X(vea, mantissa=mantissa)+(tolerance*100), Vertex.Y(vea, mantissa=mantissa)+(tolerance*100), Vertex.Z(vea, mantissa=mantissa)+(tolerance*100))
2573
+ if storeBREP:
2574
+ d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(exAp), Topology.Type(exAp), Topology.TypeAsString(exAp)])
2575
+ d3 = mergeDictionaries2([d1, d2])
2576
+ vea = Topology.SetDictionary(vea, d3, silent=True)
2577
+ else:
2578
+ vea = Topology.SetDictionary(vea, d1, silent=True)
2579
+ verts.append(vea)
2580
+ tempe = Edge.ByStartVertexEndVertex(vt, vea, tolerance=tolerance)
2581
+ tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Exterior_Apertures", 4])
2582
+ tempe = Topology.SetDictionary(tempe, tempd, silent=True)
2583
+ eds.append(tempe)
2584
+ return verts, eds
2585
+
2586
+ def _toContents(vt, contents):
2587
+ verts = []
2588
+ eds = []
2589
+ for content in contents:
2590
+ if Topology.IsInstance(content, "Aperture"):
2591
+ content = Aperture.Topology(content)
2592
+ if useInternalVertex == True:
2593
+ vct = Topology.InternalVertex(content, tolerance)
2594
+ else:
2595
+ vct = Topology.CenterOfMass(content)
2596
+ vct = Vertex.ByCoordinates(Vertex.X(vct, mantissa=mantissa)+(tolerance*100), Vertex.Y(vct, mantissa=mantissa)+(tolerance*100), Vertex.Z(vct, mantissa=mantissa)+(tolerance*100))
2597
+ d1 = Topology.Dictionary(content)
2598
+ d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 5) # content
2599
+ if storeBREP:
2600
+ d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(content), Topology.Type(content), Topology.TypeAsString(content)])
2601
+ d3 = mergeDictionaries2([d1, d2])
2602
+ vct = Topology.SetDictionary(vct, d3, silent=True)
2603
+ else:
2604
+ vct = Topology.SetDictionary(vct, d1, silent=True)
2605
+ verts.append(vct)
2606
+ tempe = Edge.ByStartVertexEndVertex(vt, vct, tolerance=tolerance)
2607
+ tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Contents", 5])
2608
+ tempe = Topology.SetDictionary(tempe, tempd, silent=True)
2609
+ eds.append(tempe)
2610
+ return verts, eds
2611
+
2612
+ def _toOutposts(vt, otherTops):
2613
+ verts = []
2614
+ eds = []
2615
+ d = Topology.Dictionary(vt)
2616
+ if not d == None:
2617
+ keys = Dictionary.Keys(d)
2618
+ else:
2619
+ keys = []
2620
+ k = None
2621
+ for key in keys:
2622
+ if key.lower() == outpostsKey.lower():
2623
+ k = key
2624
+ if k:
2625
+ ids = Dictionary.ValueAtKey(d,k)
2626
+ outposts = outpostsByID(otherTops, ids, idKey)
2627
+ else:
2628
+ outposts = []
2629
+ for outpost in outposts:
2630
+ if useInternalVertex == True:
2631
+ vop = Topology.InternalVertex(outpost, tolerance=tolerance)
2632
+ else:
2633
+ vop = Topology.CenterOfMass(outpost)
2481
2634
 
2635
+ d1 = Topology.Dictionary(vop)
2636
+ d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 6) # outpost
2637
+ if storeBREP:
2638
+ d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(outpost), Topology.Type(outpost), Topology.TypeAsString(outpost)])
2639
+ d3 = mergeDictionaries2([d1, d2])
2640
+ vop = Topology.SetDictionary(vop, d3, silent=True)
2641
+ else:
2642
+ vop = Topology.SetDictionary(vop, d1, silent=True)
2643
+ verts.append(vop)
2644
+ tempe = Edge.ByStartVertexEndVertex(vt, vop, tolerance=tolerance)
2645
+ tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Outposts", 6])
2646
+ tempe = Topology.SetDictionary(tempe, tempd, silent=True)
2647
+ eds.append(tempe)
2648
+ return verts, eds
2649
+
2482
2650
  def mergeDictionaries(sources):
2483
2651
  if isinstance(sources, list) == False:
2484
2652
  sources = [sources]
2485
2653
  sinkKeys = []
2486
2654
  sinkValues = []
2487
- d = sources[0].GetDictionary()
2655
+ d = Topology.Dictionary(sources[0])
2488
2656
  if d != None:
2489
2657
  stlKeys = d.Keys()
2490
2658
  if len(stlKeys) > 0:
2491
2659
  sinkKeys = d.Keys()
2492
2660
  sinkValues = Dictionary.Values(d)
2493
2661
  for i in range(1,len(sources)):
2494
- d = sources[i].GetDictionary()
2662
+ d = Topology.Dictionary(sources[i])
2495
2663
  if d == None:
2496
2664
  continue
2497
2665
  stlKeys = d.Keys()
@@ -2582,12 +2750,27 @@ class Graph:
2582
2750
 
2583
2751
  def processCellComplex(item):
2584
2752
  topology, others, outpostsKey, idKey, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, toOutposts, useInternalVertex, storeBREP, tolerance = item
2585
- edges = []
2586
- vertices = []
2753
+ graph_vertices = []
2754
+ graph_edges = []
2587
2755
  cellmat = []
2756
+ # Store all the vertices of the cells of the cellComplex
2757
+ cells = Topology.Cells(topology)
2758
+ for cell in cells:
2759
+ if useInternalVertex == True:
2760
+ vCell = Topology.InternalVertex(cell, tolerance=tolerance)
2761
+ else:
2762
+ vCell = Topology.CenterOfMass(cell)
2763
+ d1 = Topology.Dictionary(cell)
2764
+ d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 0) # main topology
2765
+ if storeBREP:
2766
+ d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(cell), Topology.Type(cell), Topology.TypeAsString(cell)])
2767
+ d3 = mergeDictionaries2([d1, d2])
2768
+ vCell = Topology.SetDictionary(vCell, d3, silent=True)
2769
+ else:
2770
+ vCell = Topology.SetDictionary(vCell, d1, silent=True)
2771
+ graph_vertices.append(vCell)
2588
2772
  if direct == True:
2589
- cells = []
2590
- _ = topology.Cells(None, cells)
2773
+ cells = Topology.Cells(topology)
2591
2774
  # Create a matrix of zeroes
2592
2775
  for i in range(len(cells)):
2593
2776
  cellRow = []
@@ -2605,8 +2788,8 @@ class Graph:
2605
2788
  v1 = Topology.InternalVertex(cells[i], tolerance=tolerance)
2606
2789
  v2 = Topology.InternalVertex(cells[j], tolerance=tolerance)
2607
2790
  else:
2608
- v1 = cells[i].CenterOfMass()
2609
- v2 = cells[j].CenterOfMass()
2791
+ v1 = Topology.CenterOfMass(cells[i])
2792
+ v2 = Topology.CenterOfMass(cells[j])
2610
2793
  e = Edge.ByStartVertexEndVertex(v1, v2, tolerance=tolerance)
2611
2794
  mDict = mergeDictionaries(sharedt)
2612
2795
  if not mDict == None:
@@ -2617,12 +2800,11 @@ class Graph:
2617
2800
  values = ["Direct", 0]
2618
2801
  mDict = Dictionary.ByKeysValues(keys, values)
2619
2802
  if mDict:
2620
- e.SetDictionary(mDict)
2621
- edges.append(e)
2803
+ e = Topology.SetDictionary(e, mDict, silent=True)
2804
+ graph_edges.append(e)
2622
2805
  if directApertures == True:
2623
2806
  cellmat = []
2624
- cells = []
2625
- _ = topology.Cells(None, cells)
2807
+ cells = Topology.Cells(topology)
2626
2808
  # Create a matrix of zeroes
2627
2809
  for i in range(len(cells)):
2628
2810
  cellRow = []
@@ -2650,77 +2832,37 @@ class Graph:
2650
2832
  v1 = Topology.InternalVertex(cells[i], tolerance=tolerance)
2651
2833
  v2 = Topology.InternalVertex(cells[j], tolerance=tolerance)
2652
2834
  else:
2653
- v1 = cells[i].CenterOfMass()
2654
- v2 = cells[j].CenterOfMass()
2835
+ v1 = Topology.CenterOfMass(cells[i])
2836
+ v2 = Topology.CenterOfMass(cells[j])
2655
2837
  e = Edge.ByStartVertexEndVertex(v1, v2, tolerance=tolerance)
2656
2838
  mDict = mergeDictionaries(apTopList)
2839
+ if not mDict == None:
2840
+ keys = (Dictionary.Keys(mDict) or [])+["relationship", edgeCategoryKey]
2841
+ values = (Dictionary.Values(mDict) or [])+["Direct", 0]
2842
+ else:
2843
+ keys = ["relationship", edgeCategoryKey]
2844
+ values = ["Direct", 0]
2845
+ mDict = Dictionary.ByKeysValues(keys, values)
2657
2846
  if mDict:
2658
- e.SetDictionary(mDict)
2659
- edges.append(e)
2660
- if toOutposts and others:
2661
- d = Topology.Dictionary(topology)
2662
- if not d == None:
2663
- keys = Dictionary.Keys(d)
2664
- else:
2665
- keys = []
2666
- k = None
2667
- for key in keys:
2668
- if key.lower() == outpostsKey.lower():
2669
- k = key
2670
- if k:
2671
- ids = Dictionary.ValueAtKey(k)
2672
- outposts = outpostsByID(others, ids, idKey)
2673
- else:
2674
- outposts = []
2675
- for outpost in outposts:
2676
- if useInternalVertex == True:
2677
- vop = Topology.InternalVertex(outpost, tolerance=tolerance)
2678
- vcc = Topology.InternalVertex(topology, tolerance=tolerance)
2679
- else:
2680
- vop = Topology.CenterOfMass(outpost)
2681
- vcc = Topology.CenterOfMass(topology)
2682
- d1 = Topology.Dictionary(vcc)
2683
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 0) # main topology
2684
- if storeBREP:
2685
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(topology), Topology.Type(topology), Topology.TypeAsString(topology)])
2686
- d3 = mergeDictionaries2([d1, d2])
2687
- _ = vcc.SetDictionary(d3)
2688
- else:
2689
- _ = vcc.SetDictionary(d1)
2690
- d1 = Topology.Dictionary(vop)
2691
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 6) # outpost
2692
- if storeBREP:
2693
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(outpost), Topology.Type(outpost), Topology.TypeAsString(outpost)])
2694
- d3 = mergeDictionaries2([d1, d2])
2695
- _ = vop.SetDictionary(d3)
2696
- else:
2697
- _ = vop.SetDictionary(d1)
2698
- vertices.append(vcc)
2699
- vertices.append(vop)
2700
- tempe = Edge.ByStartVertexEndVertex(vcc, vop, tolerance=tolerance)
2701
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Outposts", 6])
2702
- _ = tempe.SetDictionary(tempd)
2703
- edges.append(tempe)
2704
-
2705
- cells = []
2706
- _ = topology.Cells(None, cells)
2847
+ e = Topology.SetDictionary(e, mDict, silent=True)
2848
+ graph_edges.append(e)
2849
+ cells = Topology.Cells(topology)
2707
2850
  if any([viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents]):
2708
2851
  for aCell in cells:
2709
2852
  if useInternalVertex == True:
2710
2853
  vCell = Topology.InternalVertex(aCell, tolerance=tolerance)
2711
2854
  else:
2712
- vCell = aCell.CenterOfMass()
2713
- faces = []
2714
- _ = aCell.Faces(None, faces)
2855
+ vCell = Topology.CenterOfMass(aCell)
2856
+ d = Topology.Dictionary(aCell)
2857
+ vCell = Topology.SetDictionary(vCell, d, silent=True)
2858
+ faces = Topology.Faces(aCell)
2715
2859
  sharedTopologies = []
2716
2860
  exteriorTopologies = []
2717
2861
  sharedApertures = []
2718
2862
  exteriorApertures = []
2719
- contents = []
2720
- _ = aCell.Contents(contents)
2863
+ cell_contents = Topology.Contents(aCell)
2721
2864
  for aFace in faces:
2722
- cells1 = []
2723
- _ = aFace.Cells(topology, cells1)
2865
+ cells1 = Topology.SuperTopologies(aFace, topology, topologyType="Cell")
2724
2866
  if len(cells1) > 1:
2725
2867
  sharedTopologies.append(aFace)
2726
2868
  apertures = Topology.Apertures(aFace)
@@ -2731,226 +2873,83 @@ class Graph:
2731
2873
  apertures = Topology.Apertures(aFace)
2732
2874
  for anAperture in apertures:
2733
2875
  exteriorApertures.append(anAperture)
2734
-
2735
2876
  if viaSharedTopologies:
2877
+ verts, eds = _viaSharedTopologies(vCell, sharedTopologies)
2878
+ graph_vertices += verts
2879
+ graph_edges += eds
2736
2880
  for sharedTopology in sharedTopologies:
2737
2881
  if useInternalVertex == True:
2738
2882
  vst = Topology.InternalVertex(sharedTopology, tolerance)
2739
2883
  else:
2740
- vst = sharedTopology.CenterOfMass()
2741
- d1 = sharedTopology.GetDictionary()
2742
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 1) # shared topology
2743
- if storeBREP:
2744
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(sharedTopology), Topology.Type(sharedTopology), Topology.TypeAsString(sharedTopology)])
2745
- d3 = mergeDictionaries2([d1, d2])
2746
- _ = vst.SetDictionary(d3)
2747
- else:
2748
- _ = vst.SetDictionary(d1)
2749
- vertices.append(vst)
2750
- tempe = Edge.ByStartVertexEndVertex(vCell, vst, tolerance=tolerance)
2751
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["Via_Shared_Topologies", 1])
2752
- _ = tempe.SetDictionary(tempd)
2753
- edges.append(tempe)
2884
+ vst = Topology.CenterOfMass(sharedTopology)
2885
+ d = Topology.Dictionary(sharedTopology)
2886
+ vst = Topology.SetDictionary(vst, d, silent=True)
2754
2887
  if toContents:
2755
- contents = []
2756
- _ = sharedTopology.Contents(contents)
2757
- for content in contents:
2758
- if Topology.IsInstance(content, "Aperture"):
2759
- content = Aperture.Topology(content)
2760
- if useInternalVertex == True:
2761
- vst2 = Topology.InternalVertex(content, tolerance)
2762
- else:
2763
- vst2 = content.CenterOfMass()
2764
- d1 = content.GetDictionary()
2765
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 5) # content
2766
- vst2 = Vertex.ByCoordinates(Vertex.X(vst2, mantissa=mantissa), Vertex.Y(vst2, mantissa=mantissa), Vertex.Z(vst2, mantissa=mantissa))
2767
- if storeBREP:
2768
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(content), Topology.Type(content), Topology.TypeAsString(content)])
2769
- d3 = mergeDictionaries2([d1, d2])
2770
- _ = vst2.SetDictionary(d3)
2771
- else:
2772
- _ = vst2.SetDictionary(d1)
2773
- vertices.append(vst2)
2774
- tempe = Edge.ByStartVertexEndVertex(vst, vst2, tolerance=tolerance)
2775
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Contents", 5])
2776
- _ = tempe.SetDictionary(tempd)
2777
- edges.append(tempe)
2888
+ shd_top_contents = Topology.Contents(sharedTopology)
2889
+ verts, eds = _toContents(vst, shd_top_contents)
2890
+ graph_vertices += verts
2891
+ graph_edges += eds
2892
+ if toOutposts and others:
2893
+ verts, eds = _toOutposts(vst, others)
2894
+ graph_vertices += verts
2895
+ graph_edges += eds
2778
2896
  if viaSharedApertures:
2779
- for sharedAp in sharedApertures:
2780
- if useInternalVertex == True:
2781
- vsa = Topology.InternalVertex(sharedAp, tolerance)
2782
- else:
2783
- vsa = sharedAp.CenterOfMass()
2784
- d1 = sharedAp.GetDictionary()
2785
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 2) # shared aperture
2786
- vsa = Vertex.ByCoordinates(Vertex.X(vsa, mantissa=mantissa)+(tolerance*100), Vertex.Y(vsa, mantissa=mantissa)+(tolerance*100), Vertex.Z(vsa, mantissa=mantissa)+(tolerance*100))
2787
- if storeBREP:
2788
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(sharedAp), Topology.Type(sharedAp), Topology.TypeAsString(sharedAp)])
2789
- d3 = mergeDictionaries2([d1, d2])
2790
- _ = vsa.SetDictionary(d3)
2791
- else:
2792
- _ = vsa.SetDictionary(d1)
2793
- vertices.append(vsa)
2794
- tempe = Edge.ByStartVertexEndVertex(vCell, vsa, tolerance=tolerance)
2795
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["Via_Shared_Apertures", 2])
2796
- _ = tempe.SetDictionary(tempd)
2797
- edges.append(tempe)
2897
+ verts, eds = _viaSharedTopologies(vCell, sharedApertures)
2898
+ graph_vertices += verts
2899
+ graph_edges += eds
2798
2900
  if toExteriorTopologies:
2901
+ verts, eds = _toExteriorTopologies(vCell, exteriorTopologies)
2902
+ graph_vertices += verts
2903
+ graph_edges += eds
2799
2904
  for exteriorTopology in exteriorTopologies:
2800
2905
  if useInternalVertex == True:
2801
2906
  vet = Topology.InternalVertex(exteriorTopology, tolerance)
2802
2907
  else:
2803
- vet = exteriorTopology.CenterOfMass()
2804
- _ = vet.SetDictionary(exteriorTopology.GetDictionary())
2805
- d1 = exteriorTopology.GetDictionary()
2806
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 3) # exterior topology
2807
- if storeBREP:
2808
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(exteriorTopology), Topology.Type(exteriorTopology), Topology.TypeAsString(exteriorTopology)])
2809
- d3 = mergeDictionaries2([d1, d2])
2810
- _ = vet.SetDictionary(d3)
2811
- else:
2812
- _ = vet.SetDictionary(d1)
2813
- vertices.append(vet)
2814
- tempe = Edge.ByStartVertexEndVertex(vCell, vet, tolerance=tolerance)
2815
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Exterior_Topologies", 3])
2816
- _ = tempe.SetDictionary(tempd)
2817
- edges.append(tempe)
2908
+ vet = Topology.CenterOfMass(exteriorTopology)
2909
+ d = Topology.Dictionary(exteriorTopology)
2910
+ vet = Topology.SetDictionary(vet, d, silent=True)
2818
2911
  if toContents:
2819
- contents = []
2820
- _ = exteriorTopology.Contents(contents)
2821
- for content in contents:
2822
- if Topology.IsInstance(content, "Aperture"):
2823
- content = Aperture.Topology(content)
2824
- if useInternalVertex == True:
2825
- vst2 = Topology.InternalVertex(content, tolerance)
2826
- else:
2827
- vst2 = content.CenterOfMass()
2828
- d1 = content.GetDictionary()
2829
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 5) # content
2830
- vst2 = Vertex.ByCoordinates(Vertex.X(vst2, mantissa=mantissa)+(tolerance*100), Vertex.Y(vst2, mantissa=mantissa)+(tolerance*100), Vertex.Z(vst2, mantissa=mantissa)+(tolerance*100))
2831
- if storeBREP:
2832
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(content), Topology.Type(content), Topology.TypeAsString(content)])
2833
- d3 = mergeDictionaries2([d1, d2])
2834
- _ = vst2.SetDictionary(d3)
2835
- else:
2836
- _ = vst2.SetDictionary(d1)
2837
- vertices.append(vst2)
2838
- tempe = Edge.ByStartVertexEndVertex(vet, vst2, tolerance=tolerance)
2839
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Contents", 5])
2840
- _ = tempe.SetDictionary(tempd)
2841
- edges.append(tempe)
2912
+ ext_top_contents = Topology.Contents(exteriorTopology)
2913
+ verts, eds = _toContents(vet, ext_top_contents)
2914
+ graph_vertices += verts
2915
+ graph_edges += eds
2916
+ if toOutposts and others:
2917
+ verts, eds = _toOutposts(vet, others)
2918
+ graph_vertices += verts
2919
+ graph_edges += eds
2842
2920
  if toExteriorApertures:
2843
- for exTop in exteriorApertures:
2844
- if useInternalVertex == True:
2845
- vea = Topology.InternalVertex(exTop, tolerance)
2846
- else:
2847
- vea = exTop.CenterOfMass()
2848
- d1 = exTop.GetDictionary()
2849
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 4) # exterior aperture
2850
- vea = Vertex.ByCoordinates(Vertex.X(vea, mantissa=mantissa)+(tolerance*100), Vertex.Y(vea, mantissa=mantissa)+(tolerance*100), Vertex.Z(vea, mantissa=mantissa)+(tolerance*100))
2851
- if storeBREP:
2852
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(exTop), Topology.Type(exTop), Topology.TypeAsString(exTop)])
2853
- d3 = mergeDictionaries2([d1, d2])
2854
- _ = vea.SetDictionary(d3)
2855
- else:
2856
- _ = vea.SetDictionary(d1)
2857
- vertices.append(vea)
2858
- tempe = Edge.ByStartVertexEndVertex(vCell, vea, tolerance=tolerance)
2859
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Exterior_Apertures", 4])
2860
- _ = tempe.SetDictionary(tempd)
2861
- edges.append(tempe)
2921
+ verts, eds = _toExteriorApertures(vCell, exteriorApertures)
2922
+ graph_vertices += verts
2923
+ graph_edges += eds
2862
2924
  if toContents:
2863
- contents = []
2864
- _ = aCell.Contents(contents)
2865
- for content in contents:
2866
- if Topology.IsInstance(content, "Aperture"):
2867
- content = Aperture.Topology(content)
2868
- if useInternalVertex == True:
2869
- vcn = Topology.InternalVertex(content, tolerance)
2870
- else:
2871
- vcn = content.CenterOfMass()
2872
- vcn = Vertex.ByCoordinates(Vertex.X(vcn, mantissa=mantissa)+(tolerance*100), Vertex.Y(vcn, mantissa=mantissa)+(tolerance*100), Vertex.Z(vcn, mantissa=mantissa)+(tolerance*100))
2873
- d1 = content.GetDictionary()
2874
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 5) # content
2875
- if storeBREP:
2876
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(content), Topology.Type(content), Topology.TypeAsString(content)])
2877
- d3 = mergeDictionaries2([d1, d2])
2878
- _ = vcn.SetDictionary(d3)
2879
- else:
2880
- _ = vcn.SetDictionary(d1)
2881
- vertices.append(vcn)
2882
- tempe = Edge.ByStartVertexEndVertex(vCell, vcn, tolerance=tolerance)
2883
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Contents", 5])
2884
- _ = tempe.SetDictionary(tempd)
2885
- edges.append(tempe)
2886
-
2887
- for aCell in cells:
2888
- if useInternalVertex == True:
2889
- vCell = Topology.InternalVertex(aCell, tolerance=tolerance)
2890
- else:
2891
- vCell = aCell.CenterOfMass()
2892
- d1 = aCell.GetDictionary()
2893
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 0) # main topology
2894
- if storeBREP:
2895
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(aCell), Topology.Type(aCell), Topology.TypeAsString(aCell)])
2896
- d3 = mergeDictionaries2([d1, d2])
2897
- _ = vCell.SetDictionary(d3)
2898
- else:
2899
- _ = vCell.SetDictionary(d1)
2900
- vertices.append(vCell)
2901
- return [vertices,edges]
2925
+ verts, eds = _toContents(vCell, cell_contents)
2926
+ graph_vertices += verts
2927
+ graph_edges += eds
2928
+ if toOutposts and others:
2929
+ verts, eds = toOutposts(vCell, others)
2930
+ graph_vertices += verts
2931
+ graph_edges += eds
2932
+ return [graph_vertices, graph_edges]
2902
2933
 
2903
2934
  def processCell(item):
2904
2935
  topology, others, outpostsKey, idKey, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, toOutposts, useInternalVertex, storeBREP, tolerance = item
2905
- vertices = []
2906
- edges = []
2936
+ graph_vertices = []
2937
+ graph_edges = []
2907
2938
  if useInternalVertex == True:
2908
2939
  vCell = Topology.InternalVertex(topology, tolerance=tolerance)
2909
2940
  else:
2910
- vCell = topology.CenterOfMass()
2911
- d1 = topology.GetDictionary()
2941
+ vCell = Topology.CenterOfMass(topology)
2942
+ d1 = Topology.Dictionary(topology)
2912
2943
  d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 0) # main topology
2913
2944
  if storeBREP:
2914
2945
  d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(topology), Topology.Type(topology), Topology.TypeAsString(topology)])
2915
2946
  d3 = mergeDictionaries2([d1, d2])
2916
- _ = vCell.SetDictionary(d3)
2947
+ vCell = Topology.SetDictionary(vCell, d3, silent=True)
2917
2948
  else:
2918
- _ = vCell.SetDictionary(d1)
2919
- vertices.append(vCell)
2920
- if toOutposts and others:
2921
- d = Topology.Dictionary(topology)
2922
- if not d == None:
2923
- keys = Dictionary.Keys(d)
2924
- else:
2925
- keys = []
2926
- k = None
2927
- for key in keys:
2928
- if key.lower() == outpostsKey.lower():
2929
- k = key
2930
- if k:
2931
- ids = Dictionary.ValueAtKey(d, k)
2932
- outposts = outpostsByID(others, ids, idKey)
2933
- else:
2934
- outposts = []
2935
- for outpost in outposts:
2936
- if useInternalVertex == True:
2937
- vop = Topology.InternalVertex(outpost, tolerance)
2938
- else:
2939
- vop = Topology.CenterOfMass(outpost)
2940
- tempe = Edge.ByStartVertexEndVertex(vCell, vop, tolerance=tolerance)
2941
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Outposts", 6])
2942
- _ = tempe.SetDictionary(tempd)
2943
- edges.append(tempe)
2944
- d1 = outpost.GetDictionary()
2945
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 6) # outpost
2946
- if storeBREP:
2947
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(outpost), Topology.Type(outpost), Topology.TypeAsString(outpost)])
2948
- d3 = mergeDictionaries2([d1, d2])
2949
- _ = vop.SetDictionary(d3)
2950
- else:
2951
- _ = vop.SetDictionary(d1)
2952
- vertices.append(vop)
2953
- if any([toExteriorTopologies, toExteriorApertures, toContents]):
2949
+ vCell = Topology.SetDictionary(vCell, d1, silent=True)
2950
+ graph_vertices.append(vCell)
2951
+ if any([toExteriorTopologies, toExteriorApertures, toContents, toOutposts]):
2952
+ cell_contents = Topology.Contents(topology)
2954
2953
  faces = Topology.Faces(topology)
2955
2954
  exteriorTopologies = []
2956
2955
  exteriorApertures = []
@@ -2959,123 +2958,82 @@ class Graph:
2959
2958
  apertures = Topology.Apertures(aFace)
2960
2959
  for anAperture in apertures:
2961
2960
  exteriorApertures.append(anAperture)
2962
- if toExteriorTopologies:
2963
- for exteriorTopology in exteriorTopologies:
2964
- if useInternalVertex == True:
2965
- vst = Topology.InternalVertex(exteriorTopology, tolerance)
2966
- else:
2967
- vst = exteriorTopology.CenterOfMass()
2968
- d1 = exteriorTopology.GetDictionary()
2969
- d1 = topology.GetDictionary()
2970
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 3) # exterior topology
2971
- if storeBREP:
2972
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(exteriorTopology), Topology.Type(exteriorTopology), Topology.TypeAsString(exteriorTopology)])
2973
- d3 = mergeDictionaries2([d1, d2])
2974
- _ = vst.SetDictionary(d3)
2975
- else:
2976
- _ = vst.SetDictionary(d1)
2977
- vertices.append(vst)
2978
- tempe = Edge.ByStartVertexEndVertex(vCell, vst, tolerance=tolerance)
2979
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Exterior_Topologies", 3])
2980
- _ = tempe.SetDictionary(tempd)
2981
- edges.append(tempe)
2982
- if toContents:
2983
- contents = []
2984
- _ = exteriorTopology.Contents(contents)
2985
- for content in contents:
2986
- if Topology.IsInstance(content, "Aperture"):
2987
- content = Aperture.Topology(content)
2988
- if useInternalVertex == True:
2989
- vst2 = Topology.InternalVertex(content, tolerance)
2990
- else:
2991
- vst2 = content.CenterOfMass()
2992
- vst2 = Vertex.ByCoordinates(Vertex.X(vst2, mantissa=mantissa)+(tolerance*100), Vertex.Y(vst2, mantissa=mantissa)+(tolerance*100), Vertex.Z(vst2, mantissa=mantissa)+(tolerance*100))
2993
- d1 = content.GetDictionary()
2994
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 5) # content
2995
- if storeBREP:
2996
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(content), Topology.Type(content), Topology.TypeAsString(content)])
2997
- d3 = mergeDictionaries2([d1, d2])
2998
- _ = vst2.SetDictionary(d3)
2999
- else:
3000
- _ = vst2.SetDictionary(d1)
3001
- vertices.append(vst2)
3002
- tempe = Edge.ByStartVertexEndVertex(vst, vst2, tolerance=tolerance)
3003
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Contents", 5])
3004
- _ = tempe.SetDictionary(tempd)
3005
- edges.append(tempe)
3006
- if toExteriorApertures:
3007
- for exTop in exteriorApertures:
3008
- if useInternalVertex == True:
3009
- vst = Topology.InternalVertex(exTop, tolerance)
3010
- else:
3011
- vst = exTop.CenterOfMass()
3012
- d1 = exTop.GetDictionary()
3013
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 4) # exterior aperture
3014
- vst = Vertex.ByCoordinates(Vertex.X(vst, mantissa=mantissa)+(tolerance*100), Vertex.Y(vst, mantissa=mantissa)+(tolerance*100), Vertex.Z(vst, mantissa=mantissa)+(tolerance*100))
3015
- if storeBREP:
3016
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(exTop), Topology.Type(exTop), Topology.TypeAsString(exTop)])
3017
- d3 = mergeDictionaries2([d1, d2])
3018
- _ = vst.SetDictionary(d3)
3019
- else:
3020
- _ = vst.SetDictionary(d1)
3021
- vertices.append(vst)
3022
- tempe = Edge.ByStartVertexEndVertex(vCell, vst, tolerance=tolerance)
3023
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Exterior_Apertures", 4])
3024
- _ = tempe.SetDictionary(tempd)
3025
- edges.append(tempe)
3026
- if toContents:
3027
- contents = []
3028
- _ = topology.Contents(contents)
3029
- for content in contents:
3030
- if Topology.IsInstance(content, "Aperture"):
3031
- content = Aperture.Topology(content)
3032
- if useInternalVertex == True:
3033
- vst = Topology.InternalVertex(content, tolerance)
3034
- else:
3035
- vst = content.CenterOfMass()
3036
- vst = Vertex.ByCoordinates(Vertex.X(vst, mantissa=mantissa)+(tolerance*100), Vertex.Y(vst, mantissa=mantissa)+(tolerance*100), Vertex.Z(vst, mantissa=mantissa)+(tolerance*100))
3037
- d1 = content.GetDictionary()
3038
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 5) # content
3039
- if storeBREP:
3040
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(content), Topology.Type(content), Topology.TypeAsString(content)])
3041
- d3 = mergeDictionaries2([d1, d2])
3042
- _ = vst.SetDictionary(d3)
3043
- else:
3044
- _ = vst.SetDictionary(d1)
3045
- vertices.append(vst)
3046
- tempe = Edge.ByStartVertexEndVertex(vCell, vst, tolerance=tolerance)
3047
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Contents", 5])
3048
- _ = tempe.SetDictionary(tempd)
3049
- edges.append(tempe)
3050
- return [vertices, edges]
2961
+ if toExteriorTopologies:
2962
+ verts, eds = _toExteriorTopologies(vCell, exteriorTopologies)
2963
+ graph_vertices += verts
2964
+ graph_edges += eds
2965
+ for exteriorTopology in exteriorTopologies:
2966
+ if useInternalVertex == True:
2967
+ vet = Topology.InternalVertex(exteriorTopology, tolerance)
2968
+ else:
2969
+ vet = Topology.CenterOfMass(exteriorTopology)
2970
+ d = Topology.Dictionary(exteriorTopology)
2971
+ vet = Topology.SetDictionary(vet, d, silent=True)
2972
+ if toContents:
2973
+ ext_top_contents = Topology.Contents(exteriorTopology)
2974
+ verts, eds = _toContents(vet, ext_top_contents)
2975
+ graph_vertices += verts
2976
+ graph_edges += eds
2977
+ if toOutposts and others:
2978
+ verts, eds = _toOutposts(vet, others)
2979
+ graph_vertices += verts
2980
+ graph_edges += eds
2981
+ if toExteriorApertures:
2982
+ verts, eds = _toExteriorApertures(vCell, exteriorApertures)
2983
+ graph_vertices += verts
2984
+ graph_edges += eds
2985
+ if toContents:
2986
+ verts, eds = _toContents(vCell, cell_contents)
2987
+ graph_vertices += verts
2988
+ graph_edges += eds
2989
+ if toOutposts and others:
2990
+ verts, eds = toOutposts(vCell, others)
2991
+ graph_vertices += verts
2992
+ graph_edges += eds
2993
+ return [graph_vertices, graph_edges]
3051
2994
 
3052
2995
  def processShell(item):
3053
2996
  topology, others, outpostsKey, idKey, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, toOutposts, useInternalVertex, storeBREP, tolerance = item
3054
- edges = []
3055
- vertices = []
2997
+ graph_edges = []
2998
+ graph_vertices = []
3056
2999
  facemat = []
3000
+ # Store all the vertices of the cells of the cellComplex
3001
+ faces = Topology.Faces(topology)
3002
+ for face in faces:
3003
+ if useInternalVertex == True:
3004
+ vFace = Topology.InternalVertex(face, tolerance=tolerance)
3005
+ else:
3006
+ vFace = Topology.CenterOfMass(face)
3007
+ d1 = Topology.Dictionary(face)
3008
+ d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 0) # main topology
3009
+ if storeBREP:
3010
+ d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(face), Topology.Type(face), Topology.TypeAsString(face)])
3011
+ d3 = mergeDictionaries2([d1, d2])
3012
+ vFace = Topology.SetDictionary(vFace, d3, silent=True)
3013
+ else:
3014
+ vFace = Topology.SetDictionary(vFace, d1, silent=True)
3015
+ graph_vertices.append(vFace)
3057
3016
  if direct == True:
3058
- topFaces = []
3059
- _ = topology.Faces(None, topFaces)
3017
+ faces = Topology.Faces(topology)
3060
3018
  # Create a matrix of zeroes
3061
- for i in range(len(topFaces)):
3019
+ for i in range(len(faces)):
3062
3020
  faceRow = []
3063
- for j in range(len(topFaces)):
3021
+ for j in range(len(faces)):
3064
3022
  faceRow.append(0)
3065
3023
  facemat.append(faceRow)
3066
- for i in range(len(topFaces)):
3067
- for j in range(len(topFaces)):
3024
+ for i in range(len(faces)):
3025
+ for j in range(len(faces)):
3068
3026
  if (i != j) and facemat[i][j] == 0:
3069
3027
  facemat[i][j] = 1
3070
3028
  facemat[j][i] = 1
3071
- sharedt = Topology.SharedEdges(topFaces[i], topFaces[j])
3029
+ sharedt = Topology.SharedEdges(faces[i], faces[j])
3072
3030
  if len(sharedt) > 0:
3073
3031
  if useInternalVertex == True:
3074
- v1 = Topology.InternalVertex(topFaces[i], tolerance=tolerance)
3075
- v2 = Topology.InternalVertex(topFaces[j], tolerance=tolerance)
3032
+ v1 = Topology.InternalVertex(faces[i], tolerance=tolerance)
3033
+ v2 = Topology.InternalVertex(faces[j], tolerance=tolerance)
3076
3034
  else:
3077
- v1 = topFaces[i].CenterOfMass()
3078
- v2 = topFaces[j].CenterOfMass()
3035
+ v1 = Topology.CenterOfMass(faces[i])
3036
+ v2 = Topology.CenterOfMass(faces[j])
3079
3037
  e = Edge.ByStartVertexEndVertex(v1, v2, tolerance=tolerance)
3080
3038
  mDict = mergeDictionaries(sharedt)
3081
3039
  if not mDict == None:
@@ -3086,63 +3044,70 @@ class Graph:
3086
3044
  values = ["Direct", 0]
3087
3045
  mDict = Dictionary.ByKeysValues(keys, values)
3088
3046
  if mDict:
3089
- e.SetDictionary(mDict)
3090
- edges.append(e)
3047
+ e = Topology.SetDictionary(e, mDict, silent=True)
3048
+ graph_edges.append(e)
3091
3049
  if directApertures == True:
3092
3050
  facemat = []
3093
- topFaces = []
3094
- _ = topology.Faces(None, topFaces)
3051
+ faces = Topology.Faces(topology)
3095
3052
  # Create a matrix of zeroes
3096
- for i in range(len(topFaces)):
3053
+ for i in range(len(faces)):
3097
3054
  faceRow = []
3098
- for j in range(len(topFaces)):
3055
+ for j in range(len(faces)):
3099
3056
  faceRow.append(0)
3100
3057
  facemat.append(faceRow)
3101
- for i in range(len(topFaces)):
3102
- for j in range(len(topFaces)):
3058
+ for i in range(len(faces)):
3059
+ for j in range(len(faces)):
3103
3060
  if (i != j) and facemat[i][j] == 0:
3104
3061
  facemat[i][j] = 1
3105
3062
  facemat[j][i] = 1
3106
- sharedt = Topology.SharedEdges(topFaces[i], topFaces[j])
3063
+ sharedt = Topology.SharedEdges(faces[i], faces[j])
3107
3064
  if len(sharedt) > 0:
3108
3065
  apertureExists = False
3109
3066
  for x in sharedt:
3110
3067
  apList = Topology.Apertures(x)
3111
3068
  if len(apList) > 0:
3069
+ apTopList = []
3070
+ for ap in apList:
3071
+ apTopList.append(ap)
3112
3072
  apertureExists = True
3113
3073
  break
3114
3074
  if apertureExists:
3115
3075
  if useInternalVertex == True:
3116
- v1 = Topology.InternalVertex(topFaces[i], tolerance=tolerance)
3117
- v2 = Topology.InternalVertex(topFaces[j], tolerance=tolerance)
3076
+ v1 = Topology.InternalVertex(faces[i], tolerance=tolerance)
3077
+ v2 = Topology.InternalVertex(faces[j], tolerance=tolerance)
3118
3078
  else:
3119
- v1 = topFaces[i].CenterOfMass()
3120
- v2 = topFaces[j].CenterOfMass()
3079
+ v1 = Topology.CenterOfMass(faces[i])
3080
+ v2 = Topology.CenterOfMass(faces[j])
3121
3081
  e = Edge.ByStartVertexEndVertex(v1, v2, tolerance=tolerance)
3122
- mDict = mergeDictionaries(apList)
3082
+ mDict = mergeDictionaries(apTopList)
3083
+ if not mDict == None:
3084
+ keys = (Dictionary.Keys(mDict) or [])+["relationship", edgeCategoryKey]
3085
+ values = (Dictionary.Values(mDict) or [])+["Direct", 0]
3086
+ else:
3087
+ keys = ["relationship", edgeCategoryKey]
3088
+ values = ["Direct", 0]
3089
+ mDict = Dictionary.ByKeysValues(keys, values)
3123
3090
  if mDict:
3124
- e.SetDictionary(mDict)
3125
- edges.append(e)
3126
-
3127
- topFaces = []
3128
- _ = topology.Faces(None, topFaces)
3129
- if any([viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents == True]):
3130
- for aFace in topFaces:
3091
+ e = Topology.SetDictionary(e, mDict, silent=True)
3092
+ graph_edges.append(e)
3093
+ faces = Topology.Faces(topology)
3094
+ if any([viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents]):
3095
+ for aFace in faces:
3131
3096
  if useInternalVertex == True:
3132
3097
  vFace = Topology.InternalVertex(aFace, tolerance=tolerance)
3133
3098
  else:
3134
- vFace = aFace.CenterOfMass()
3135
- _ = vFace.SetDictionary(aFace.GetDictionary())
3136
- fEdges = []
3137
- _ = aFace.Edges(None, fEdges)
3099
+ vFace = Topology.CenterOfMass(aFace)
3100
+ d = Topology.Dictionary(aFace)
3101
+ vFace = Topology.SetDictionary(vFace, d, silent=True)
3102
+ edges = Topology.Edges(aFace)
3138
3103
  sharedTopologies = []
3139
3104
  exteriorTopologies = []
3140
3105
  sharedApertures = []
3141
3106
  exteriorApertures = []
3142
- for anEdge in fEdges:
3143
- faces = []
3144
- _ = anEdge.Faces(topology, faces)
3145
- if len(faces) > 1:
3107
+ face_contents = Topology.Contents(aFace)
3108
+ for anEdge in edges:
3109
+ faces1 = Topology.SuperTopologies(anEdge, hostTopology=topology, topologyType="Face")
3110
+ if len(faces1) > 1:
3146
3111
  sharedTopologies.append(anEdge)
3147
3112
  apertures = Topology.Apertures(anEdge)
3148
3113
  for anAperture in apertures:
@@ -3153,387 +3118,168 @@ class Graph:
3153
3118
  for anAperture in apertures:
3154
3119
  exteriorApertures.append(anAperture)
3155
3120
  if viaSharedTopologies:
3121
+ verts, eds = _viaSharedTopologies(vFace, sharedTopologies)
3122
+ graph_vertices += verts
3123
+ graph_edges += eds
3156
3124
  for sharedTopology in sharedTopologies:
3157
3125
  if useInternalVertex == True:
3158
3126
  vst = Topology.InternalVertex(sharedTopology, tolerance)
3159
3127
  else:
3160
- vst = sharedTopology.CenterOfMass()
3161
- d1 = sharedTopology.GetDictionary()
3162
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 1) # shared topology
3163
- if storeBREP:
3164
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(sharedTopology), Topology.Type(sharedTopology), Topology.TypeAsString(sharedTopology)])
3165
- d3 = mergeDictionaries2([d1, d2])
3166
- _ = vst.SetDictionary(d3)
3167
- else:
3168
- _ = vst.SetDictionary(d1)
3169
- vertices.append(vst)
3170
- tempe = Edge.ByStartVertexEndVertex(vFace, vst, tolerance=tolerance)
3171
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["Via_Shared_Topologies", 1])
3172
- _ = tempe.SetDictionary(tempd)
3173
- edges.append(tempe)
3128
+ vst = Topology.CenterOfMass(sharedTopology)
3129
+ d = Topology.Dictionary(sharedTopology)
3130
+ vst = Topology.SetDictionary(vst, d, silent=True)
3174
3131
  if toContents:
3175
- contents = []
3176
- _ = sharedTopology.Contents(contents)
3177
- for content in contents:
3178
- if Topology.IsInstance(content, "Aperture"):
3179
- content = Aperture.Topology(content)
3180
- if useInternalVertex == True:
3181
- vst2 = Topology.InternalVertex(content, tolerance)
3182
- else:
3183
- vst2 = content.CenterOfMass()
3184
- vst2 = Vertex.ByCoordinates(Vertex.X(vst2, mantissa=mantissa)+(tolerance*100), Vertex.Y(vst2, mantissa=mantissa)+(tolerance*100), Vertex.Z(vst2, mantissa=mantissa)+(tolerance*100))
3185
- d1 = content.GetDictionary()
3186
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 5) # content
3187
- if storeBREP:
3188
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(content), Topology.Type(content), Topology.TypeAsString(content)])
3189
- d3 = mergeDictionaries2([d1, d2])
3190
- _ = vst2.SetDictionary(d3)
3191
- else:
3192
- _ = vst2.SetDictionary(d1)
3193
- vertices.append(vst2)
3194
- tempe = Edge.ByStartVertexEndVertex(vst, vst2, tolerance=tolerance)
3195
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Contents", 5])
3196
- _ = tempe.SetDictionary(tempd)
3197
- edges.append(tempe)
3132
+ shd_top_contents = Topology.Contents(sharedTopology)
3133
+ verts, eds = _toContents(vst, shd_top_contents)
3134
+ graph_vertices += verts
3135
+ graph_edges += eds
3136
+ if toOutposts and others:
3137
+ verts, eds = _toOutposts(vst, others)
3138
+ graph_vertices += verts
3139
+ graph_edges += eds
3198
3140
  if viaSharedApertures:
3199
- for sharedAp in sharedApertures:
3200
- if useInternalVertex == True:
3201
- vst = Topology.InternalVertex(sharedAp, tolerance)
3202
- else:
3203
- vst = sharedAp.CenterOfMass()
3204
- d1 = sharedAp.GetDictionary()
3205
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 2) # shared aperture
3206
- vst = Vertex.ByCoordinates(Vertex.X(vst, mantissa=mantissa)+(tolerance*100), Vertex.Y(vst, mantissa=mantissa)+(tolerance*100), Vertex.Z(vst, mantissa=mantissa)+(tolerance*100))
3207
- if storeBREP:
3208
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(sharedAp), Topology.Type(sharedAp), Topology.TypeAsString(sharedAp)])
3209
- d3 = mergeDictionaries2([d1, d2])
3210
- _ = vst.SetDictionary(d3)
3211
- else:
3212
- _ = vst.SetDictionary(d1)
3213
- vertices.append(vst)
3214
- tempe = Edge.ByStartVertexEndVertex(vFace, vst, tolerance=tolerance)
3215
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["Via_Shared_Apertures", 2])
3216
- _ = tempe.SetDictionary(tempd)
3217
- edges.append(tempe)
3141
+ verts, eds = _viaSharedTopologies(vFace, sharedApertures)
3142
+ graph_vertices += verts
3143
+ graph_edges += eds
3218
3144
  if toExteriorTopologies:
3145
+ verts, eds = _toExteriorTopologies(vFace, exteriorTopologies)
3146
+ graph_vertices += verts
3147
+ graph_edges += eds
3219
3148
  for exteriorTopology in exteriorTopologies:
3220
3149
  if useInternalVertex == True:
3221
- vst = Topology.InternalVertex(exteriorTopology, tolerance)
3222
- else:
3223
- vst = exteriorTopology.CenterOfMass()
3224
- d1 = exteriorTopology.GetDictionary()
3225
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 3) # exterior topology
3226
- if storeBREP:
3227
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(exteriorTopology), Topology.Type(exteriorTopology), Topology.TypeAsString(exteriorTopology)])
3228
- d3 = mergeDictionaries2([d1, d2])
3229
- _ = vst.SetDictionary(d3)
3150
+ vet = Topology.InternalVertex(exteriorTopology, tolerance)
3230
3151
  else:
3231
- _ = vst.SetDictionary(d1)
3232
- vertices.append(vst)
3233
- tempe = Edge.ByStartVertexEndVertex(vFace, vst, tolerance=tolerance)
3234
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Exterior_Apertures", 4])
3235
- _ = tempe.SetDictionary(tempd)
3236
- edges.append(tempe)
3152
+ vet = Topology.CenterOfMass(exteriorTopology)
3153
+ d = Topology.Dictionary(exteriorTopology)
3154
+ vet = Topology.SetDictionary(vet, d, silent=True)
3237
3155
  if toContents:
3238
- contents = []
3239
- _ = exteriorTopology.Contents(contents)
3240
- for content in contents:
3241
- if Topology.IsInstance(content, "Aperture"):
3242
- content = Aperture.Topology(content)
3243
- if useInternalVertex == True:
3244
- vst2 = Topology.InternalVertex(content, tolerance)
3245
- else:
3246
- vst2 = content.CenterOfMass()
3247
- vst2 = Vertex.ByCoordinates(Vertex.X(vst2, mantissa=mantissa)+(tolerance*100), Vertex.Y(vst2, mantissa=mantissa)+(tolerance*100), Vertex.Z(vst2, mantissa=mantissa)+(tolerance*100))
3248
- d1 = content.GetDictionary()
3249
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 5) # content
3250
- if storeBREP:
3251
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(content), Topology.Type(content), Topology.TypeAsString(content)])
3252
- d3 = mergeDictionaries2([d1, d2])
3253
- _ = vst2.SetDictionary(d3)
3254
- else:
3255
- _ = vst2.SetDictionary(d1)
3256
- vertices.append(vst2)
3257
- tempe = Edge.ByStartVertexEndVertex(vst, vst2, tolerance=tolerance)
3258
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Contents", 5])
3259
- _ = tempe.SetDictionary(tempd)
3260
- edges.append(tempe)
3156
+ ext_top_contents = Topology.Contents(exteriorTopology)
3157
+ verts, eds = _toContents(vet, ext_top_contents)
3158
+ graph_vertices += verts
3159
+ graph_edges += eds
3160
+ if toOutposts and others:
3161
+ verts, eds = _toOutposts(vet, others)
3162
+ graph_vertices += verts
3163
+ graph_edges += eds
3261
3164
  if toExteriorApertures:
3262
- for exTop in exteriorApertures:
3263
- if useInternalVertex == True:
3264
- vst = Topology.InternalVertex(exTop, tolerance)
3265
- else:
3266
- vst = exTop.CenterOfMass()
3267
- d1 = exTop.GetDictionary()
3268
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 4) # exterior aperture
3269
- vst = Vertex.ByCoordinates(Vertex.X(vst, mantissa=mantissa)+(tolerance*100), Vertex.Y(vst, mantissa=mantissa)+(tolerance*100), Vertex.Z(vst, mantissa=mantissa)+(tolerance*100))
3270
- if storeBREP:
3271
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(exTop), Topology.Type(exTop), Topology.TypeAsString(exTop)])
3272
- d3 = mergeDictionaries2([d1, d2])
3273
- _ = vst.SetDictionary(d3)
3274
- else:
3275
- _ = vst.SetDictionary(d1)
3276
- vertices.append(vst)
3277
- tempe = Edge.ByStartVertexEndVertex(vFace, vst, tolerance=tolerance)
3278
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Exterior_Apertures", 4])
3279
- _ = tempe.SetDictionary(tempd)
3280
- edges.append(tempe)
3165
+ verts, eds = _toExteriorApertures(vFace, exteriorApertures)
3166
+ graph_vertices += verts
3167
+ graph_edges += eds
3281
3168
  if toContents:
3282
- contents = []
3283
- _ = aFace.Contents(contents)
3284
- for content in contents:
3285
- if Topology.IsInstance(content, "Aperture"):
3286
- content = Aperture.Topology(content)
3287
- if useInternalVertex == True:
3288
- vst = Topology.InternalVertex(content, tolerance)
3289
- else:
3290
- vst = content.CenterOfMass()
3291
- vst = Vertex.ByCoordinates(Vertex.X(vst, mantissa=mantissa)+(tolerance*100), Vertex.Y(vst, mantissa=mantissa)+(tolerance*100), Vertex.Z(vst, mantissa=mantissa)+(tolerance*100))
3292
- d1 = content.GetDictionary()
3293
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 5) # content
3294
- if storeBREP:
3295
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(content), Topology.Type(content), Topology.TypeAsString(content)])
3296
- d3 = mergeDictionaries2([d1, d2])
3297
- _ = vst.SetDictionary(d3)
3298
- else:
3299
- _ = vst.SetDictionary(d1)
3300
- vertices.append(vst)
3301
- tempe = Edge.ByStartVertexEndVertex(vFace, vst, tolerance=tolerance)
3302
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Contents", 5])
3303
- _ = tempe.SetDictionary(tempd)
3304
- edges.append(tempe)
3305
-
3306
- for aFace in topFaces:
3307
- if useInternalVertex == True:
3308
- vFace = Topology.InternalVertex(aFace, tolerance)
3309
- else:
3310
- vFace = aFace.CenterOfMass()
3311
- d1 = aFace.GetDictionary()
3312
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 0) # main topology
3313
- if storeBREP:
3314
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(aFace), Topology.Type(aFace), Topology.TypeAsString(aFace)])
3315
- d3 = mergeDictionaries2([d1, d2])
3316
- _ = vFace.SetDictionary(d3)
3317
- else:
3318
- _ = vFace.SetDictionary(d1)
3319
- vertices.append(vFace)
3320
- if toOutposts and others:
3321
- d = Topology.Dictionary(topology)
3322
- if not d == None:
3323
- keys = Dictionary.Keys(d)
3324
- else:
3325
- keys = []
3326
- k = None
3327
- for key in keys:
3328
- if key.lower() == outpostsKey.lower():
3329
- k = key
3330
- if k:
3331
- ids = Dictionary.ValueAtKey(k)
3332
- outposts = outpostsByID(others, ids, idKey)
3333
- else:
3334
- outposts = []
3335
- for outpost in outposts:
3336
- if useInternalVertex == True:
3337
- vop = Topology.InternalVertex(outpost, tolerance)
3338
- vcc = Topology.InternalVertex(topology, tolerance)
3339
- else:
3340
- vop = Topology.CenterOfMass(outpost)
3341
- vcc = Topology.CenterOfMass(topology)
3342
- d1 = Topology.Dictionary(vcc)
3343
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 0) # main topology
3344
- if storeBREP:
3345
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(topology), Topology.Type(topology), Topology.TypeAsString(topology)])
3346
- d3 = mergeDictionaries2([d1, d2])
3347
- _ = vcc.SetDictionary(d3)
3348
- else:
3349
- _ = vcc.SetDictionary(d1)
3350
- vertices.append(vcc)
3351
- d1 = Topology.Dictionary(vop)
3352
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 6) # outpost
3353
- if storeBREP:
3354
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(topology), Topology.Type(topology), Topology.TypeAsString(topology)])
3355
- d3 = mergeDictionaries2([d1, d2])
3356
- _ = vop.SetDictionary(d3)
3357
- else:
3358
- _ = vop.SetDictionary(d1)
3359
- vertices.append(vcc)
3360
- tempe = Edge.ByStartVertexEndVertex(vcc, vop, tolerance=tolerance)
3361
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Outposts", 6])
3362
- _ = tempe.SetDictionary(tempd)
3363
- edges.append(tempe)
3364
- return [vertices, edges]
3169
+ verts, eds = _toContents(vFace, face_contents)
3170
+ graph_vertices += verts
3171
+ graph_edges += eds
3172
+ if toOutposts and others:
3173
+ verts, eds = toOutposts(vFace, others)
3174
+ graph_vertices += verts
3175
+ graph_edges += eds
3176
+ return [graph_vertices, graph_edges]
3365
3177
 
3366
3178
  def processFace(item):
3367
3179
  topology, others, outpostsKey, idKey, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, toOutposts, useInternalVertex, storeBREP, tolerance = item
3368
- vertices = []
3369
- edges = []
3370
-
3180
+ graph_vertices = []
3181
+ graph_edges = []
3371
3182
  if useInternalVertex == True:
3372
3183
  vFace = Topology.InternalVertex(topology, tolerance=tolerance)
3373
3184
  else:
3374
- vFace = topology.CenterOfMass()
3375
- d1 = topology.GetDictionary()
3185
+ vFace = Topology.CenterOfMass(topology)
3186
+ d1 = Topology.Dictionary(topology)
3376
3187
  d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 0) # main topology
3377
3188
  if storeBREP:
3378
3189
  d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(topology), Topology.Type(topology), Topology.TypeAsString(topology)])
3379
3190
  d3 = mergeDictionaries2([d1, d2])
3380
- _ = vFace.SetDictionary(d3)
3191
+ vFace = Topology.SetDictionary(vFace, d3, silent=True)
3381
3192
  else:
3382
- _ = vFace.SetDictionary(d1)
3383
- vertices.append(vFace)
3384
- if toOutposts and others:
3385
- d = Topology.Dictionary(topology)
3386
- if not d == None:
3387
- keys = Dictionary.Keys(d)
3388
- else:
3389
- keys = []
3390
- k = None
3391
- for key in keys:
3392
- if key.lower() == outpostsKey.lower():
3393
- k = key
3394
- if k:
3395
- ids = Dictionary.ValueAtKey(d, k)
3396
- outposts = outpostsByID(others, ids, idKey)
3397
- else:
3398
- outposts = []
3399
- for outpost in outposts:
3400
- if useInternalVertex == True:
3401
- vop = Topology.InternalVertex(outpost, tolerance)
3402
- else:
3403
- vop = Topology.CenterOfMass(outpost)
3404
- tempe = Edge.ByStartVertexEndVertex(vFace, vop, tolerance=tolerance)
3405
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Outposts", 6])
3406
- _ = tempe.SetDictionary(tempd)
3407
- edges.append(tempe)
3408
- if (toExteriorTopologies == True) or (toExteriorApertures == True) or (toContents == True):
3409
- fEdges = []
3410
- _ = topology.Edges(None, fEdges)
3193
+ vFace = Topology.SetDictionary(vFace, d1, silent=True)
3194
+ graph_vertices.append(vFace)
3195
+ if any([toExteriorTopologies, toExteriorApertures, toContents, toOutposts]):
3196
+ face_contents = Topology.Contents(topology)
3197
+ edges = Topology.Edges(topology)
3411
3198
  exteriorTopologies = []
3412
3199
  exteriorApertures = []
3413
-
3414
- for anEdge in fEdges:
3200
+ for anEdge in edges:
3415
3201
  exteriorTopologies.append(anEdge)
3416
3202
  apertures = Topology.Apertures(anEdge)
3417
3203
  for anAperture in apertures:
3418
3204
  exteriorApertures.append(anAperture)
3419
- if toExteriorTopologies:
3420
- for exteriorTopology in exteriorTopologies:
3421
- if useInternalVertex == True:
3422
- vst = Topology.InternalVertex(exteriorTopology, tolerance)
3423
- else:
3424
- vst = exteriorTopology.CenterOfMass()
3425
- d1 = exteriorTopology.GetDictionary()
3426
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 3) # exterior topology
3427
- if storeBREP:
3428
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(exteriorTopology), Topology.Type(exteriorTopology), Topology.TypeAsString(exteriorTopology)])
3429
- d3 = mergeDictionaries2([d1, d2])
3430
- _ = vst.SetDictionary(d3)
3431
- else:
3432
- _ = vst.SetDictionary(d1)
3433
- vertices.append(vst)
3434
- tempe = Edge.ByStartVertexEndVertex(vFace, vst, tolerance=tolerance)
3435
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Exterior_Topologies", 3])
3436
- _ = tempe.SetDictionary(tempd)
3437
- edges.append(tempe)
3438
- if toContents:
3439
- contents = []
3440
- _ = exteriorTopology.Contents(contents)
3441
- for content in contents:
3442
- if Topology.IsInstance(content, "Aperture"):
3443
- content = Aperture.Topology(content)
3444
- if useInternalVertex == True:
3445
- vst2 = Topology.InternalVertex(content, tolerance)
3446
- else:
3447
- vst2 = content.CenterOfMass()
3448
- vst2 = Vertex.ByCoordinates(Vertex.X(vst2, mantissa=mantissa)+(tolerance*100), Vertex.Y(vst2, mantissa=mantissa)+(tolerance*100), Vertex.Z(vst2, mantissa=mantissa)+(tolerance*100))
3449
- d1 = content.GetDictionary()
3450
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 5) # content
3451
- if storeBREP:
3452
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(content), Topology.Type(content), Topology.TypeAsString(content)])
3453
- d3 = mergeDictionaries2([d1, d2])
3454
- _ = vst2.SetDictionary(d3)
3455
- else:
3456
- _ = vst2.SetDictionary(d1)
3457
- vertices.append(vst2)
3458
- tempe = Edge.ByStartVertexEndVertex(vst, vst2, tolerance=tolerance)
3459
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Contents", 5])
3460
- _ = tempe.SetDictionary(tempd)
3461
- edges.append(tempe)
3462
- if toExteriorApertures:
3463
- for exTop in exteriorApertures:
3464
- if useInternalVertex == True:
3465
- vst = Topology.InternalVertex(exTop, tolerance)
3466
- else:
3467
- vst = exTop.CenterOfMass()
3468
- d1 = exTop.GetDictionary()
3469
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 4) # exterior aperture
3470
- vst = Vertex.ByCoordinates(Vertex.X(vst, mantissa=mantissa)+(tolerance*100), Vertex.Y(vst, mantissa=mantissa)+(tolerance*100), Vertex.Z(vst, mantissa=mantissa)+(tolerance*100))
3471
- if storeBREP:
3472
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(exTop), Topology.Type(exTop), Topology.TypeAsString(exTop)])
3473
- d3 = mergeDictionaries2([d1, d2])
3474
- _ = vst.SetDictionary(d3)
3475
- else:
3476
- _ = vst.SetDictionary(d1)
3477
- vertices.append(vst)
3478
- tempe = Edge.ByStartVertexEndVertex(vFace, vst, tolerance=tolerance)
3479
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Exterior_Apertures", 4])
3480
- _ = tempe.SetDictionary(tempd)
3481
- edges.append(tempe)
3482
- if toContents:
3483
- contents = []
3484
- _ = topology.Contents(contents)
3485
- for content in contents:
3486
- if Topology.IsInstance(content, "Aperture"):
3487
- content = Aperture.Topology(content)
3488
- if useInternalVertex == True:
3489
- vst = Topology.InternalVertex(content, tolerance)
3490
- else:
3491
- vst = content.CenterOfMass()
3492
- vst = Vertex.ByCoordinates(Vertex.X(vst, mantissa=mantissa)+(tolerance*100), Vertex.Y(vst, mantissa=mantissa)+(tolerance*100), Vertex.Z(vst, mantissa=mantissa)+(tolerance*100))
3493
- d1 = content.GetDictionary()
3494
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 5) # content
3495
- if storeBREP:
3496
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(content), Topology.Type(content), Topology.TypeAsString(content)])
3497
- d3 = mergeDictionaries2([d1, d2])
3498
- _ = vst.SetDictionary(d3)
3499
- else:
3500
- _ = vst.SetDictionary(d1)
3501
- vertices.append(vst)
3502
- tempe = Edge.ByStartVertexEndVertex(vFace, vst, tolerance=tolerance)
3503
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Contents", 5])
3504
- _ = tempe.SetDictionary(tempd)
3505
- edges.append(tempe)
3506
- return [vertices, edges]
3205
+ if toExteriorTopologies:
3206
+ verts, eds = _toExteriorTopologies(vFace, exteriorTopologies)
3207
+ graph_vertices += verts
3208
+ graph_edges += eds
3209
+ for exteriorTopology in exteriorTopologies:
3210
+ if useInternalVertex == True:
3211
+ vet = Topology.InternalVertex(exteriorTopology, tolerance)
3212
+ else:
3213
+ vet = Topology.CenterOfMass(exteriorTopology)
3214
+ d = Topology.Dictionary(exteriorTopology)
3215
+ vet = Topology.SetDictionary(vet, d, silent=True)
3216
+ if toContents:
3217
+ ext_top_contents = Topology.Contents(exteriorTopology)
3218
+ verts, eds = _toContents(vet, ext_top_contents)
3219
+ graph_vertices += verts
3220
+ graph_edges += eds
3221
+ if toOutposts and others:
3222
+ verts, eds = _toOutposts(vet, others)
3223
+ graph_vertices += verts
3224
+ graph_edges += eds
3225
+ if toExteriorApertures:
3226
+ verts, eds = _toExteriorApertures(vFace, exteriorApertures)
3227
+ graph_vertices += verts
3228
+ graph_edges += eds
3229
+ if toContents:
3230
+ verts, eds = _toContents(vFace, face_contents)
3231
+ graph_vertices += verts
3232
+ graph_edges += eds
3233
+ if toOutposts and others:
3234
+ verts, eds = toOutposts(vFace, others)
3235
+ graph_vertices += verts
3236
+ graph_edges += eds
3237
+ return [graph_vertices, graph_edges]
3238
+
3239
+
3507
3240
 
3508
3241
  def processWire(item):
3509
3242
  topology, others, outpostsKey, idKey, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, toOutposts, useInternalVertex, storeBREP, tolerance = item
3510
- edges = []
3511
- vertices = []
3243
+ graph_vertices = []
3244
+ graph_edges = []
3512
3245
  edgemat = []
3246
+ # Store all the vertices of the cells of the cellComplex
3247
+ edges = Topology.Edges(topology)
3248
+ for edge in edges:
3249
+ if useInternalVertex == True:
3250
+ vEdge = Topology.InternalVertex(edge, tolerance=tolerance)
3251
+ else:
3252
+ vEdge = Topology.CenterOfMass(edge)
3253
+ d1 = Topology.Dictionary(edge)
3254
+ d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 0) # main topology
3255
+ if storeBREP:
3256
+ d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(edge), Topology.Type(edge), Topology.TypeAsString(edge)])
3257
+ d3 = mergeDictionaries2([d1, d2])
3258
+ vEdge = Topology.SetDictionary(vEdge, d3, silent=True)
3259
+ else:
3260
+ vEdge = Topology.SetDictionary(vEdge, d1, silent=True)
3261
+ graph_vertices.append(vEdge)
3513
3262
  if direct == True:
3514
- topEdges = []
3515
- _ = topology.Edges(None, topEdges)
3263
+ edges = Topology.Edges(topology)
3516
3264
  # Create a matrix of zeroes
3517
- for i in range(len(topEdges)):
3265
+ for i in range(len(edges)):
3518
3266
  edgeRow = []
3519
- for j in range(len(topEdges)):
3267
+ for j in range(len(edges)):
3520
3268
  edgeRow.append(0)
3521
3269
  edgemat.append(edgeRow)
3522
- for i in range(len(topEdges)):
3523
- for j in range(len(topEdges)):
3270
+ for i in range(len(edges)):
3271
+ for j in range(len(edges)):
3524
3272
  if (i != j) and edgemat[i][j] == 0:
3525
3273
  edgemat[i][j] = 1
3526
3274
  edgemat[j][i] = 1
3527
- sharedt = Topology.SharedVertices(topEdges[i], topEdges[j])
3275
+ sharedt = Topology.SharedVertices(edges[i], edges[j])
3528
3276
  if len(sharedt) > 0:
3529
- try:
3530
- v1 = Edge.VertexByParameter(topEdges[i], 0.5)
3531
- except:
3532
- v1 = topEdges[j].CenterOfMass()
3533
- try:
3534
- v2 = Edge.VertexByParameter(topEdges[j], 0.5)
3535
- except:
3536
- v2 = topEdges[j].CenterOfMass()
3277
+ if useInternalVertex == True:
3278
+ v1 = Topology.InternalVertex(edges[i], tolerance=tolerance)
3279
+ v2 = Topology.InternalVertex(edges[j], tolerance=tolerance)
3280
+ else:
3281
+ v1 = Topology.CenterOfMass(edges[i])
3282
+ v2 = Topology.CenterOfMass(edges[j])
3537
3283
  e = Edge.ByStartVertexEndVertex(v1, v2, tolerance=tolerance)
3538
3284
  mDict = mergeDictionaries(sharedt)
3539
3285
  if not mDict == None:
@@ -3544,75 +3290,70 @@ class Graph:
3544
3290
  values = ["Direct", 0]
3545
3291
  mDict = Dictionary.ByKeysValues(keys, values)
3546
3292
  if mDict:
3547
- e.SetDictionary(mDict)
3548
- edges.append(e)
3293
+ e = Topology.SetDictionary(e, mDict, silent=True)
3294
+ graph_edges.append(e)
3549
3295
  if directApertures == True:
3550
3296
  edgemat = []
3551
- topEdges = []
3552
- _ = topology.Edges(None, topEdges)
3297
+ edges = Topology.Edges(topology)
3553
3298
  # Create a matrix of zeroes
3554
- for i in range(len(topEdges)):
3555
- edgeRow = []
3556
- for j in range(len(topEdges)):
3299
+ for i in range(len(edges)):
3300
+ cellRow = []
3301
+ for j in range(len(edges)):
3557
3302
  edgeRow.append(0)
3558
3303
  edgemat.append(edgeRow)
3559
- for i in range(len(topEdges)):
3560
- for j in range(len(topEdges)):
3304
+ for i in range(len(edges)):
3305
+ for j in range(len(edges)):
3561
3306
  if (i != j) and edgemat[i][j] == 0:
3562
3307
  edgemat[i][j] = 1
3563
3308
  edgemat[j][i] = 1
3564
- sharedt = Topology.SharedVertices(topEdges[i], topEdges[j])
3309
+ sharedt = Topology.SharedVertices(edges[i], edges[j])
3565
3310
  if len(sharedt) > 0:
3566
3311
  apertureExists = False
3567
3312
  for x in sharedt:
3568
3313
  apList = Topology.Apertures(x)
3569
3314
  if len(apList) > 0:
3315
+ apTopList = []
3316
+ for ap in apList:
3317
+ apTopList.append(ap)
3570
3318
  apertureExists = True
3571
3319
  break
3572
3320
  if apertureExists:
3573
- try:
3574
- v1 = Edge.VertexByParameter(topEdges[i], 0.5)
3575
- except:
3576
- v1 = topEdges[j].CenterOfMass()
3577
- try:
3578
- v2 = Edge.VertexByParameter(topEdges[j], 0.5)
3579
- except:
3580
- v2 = topEdges[j].CenterOfMass()
3321
+ if useInternalVertex == True:
3322
+ v1 = Topology.InternalVertex(edges[i], tolerance=tolerance)
3323
+ v2 = Topology.InternalVertex(edges[j], tolerance=tolerance)
3324
+ else:
3325
+ v1 = Topology.CenterOfMass(edges[i])
3326
+ v2 = Topology.CenterOfMass(edges[j])
3581
3327
  e = Edge.ByStartVertexEndVertex(v1, v2, tolerance=tolerance)
3582
- mDict = mergeDictionaries(apList)
3328
+ mDict = mergeDictionaries(apTopList)
3329
+ if not mDict == None:
3330
+ keys = (Dictionary.Keys(mDict) or [])+["relationship", edgeCategoryKey]
3331
+ values = (Dictionary.Values(mDict) or [])+["Direct", 0]
3332
+ else:
3333
+ keys = ["relationship", edgeCategoryKey]
3334
+ values = ["Direct", 0]
3335
+ mDict = Dictionary.ByKeysValues(keys, values)
3583
3336
  if mDict:
3584
- e.SetDictionary(mDict)
3585
- edges.append(e)
3586
-
3587
- topEdges = []
3588
- _ = topology.Edges(None, topEdges)
3589
- if (viaSharedTopologies == True) or (viaSharedApertures == True) or (toExteriorTopologies == True) or (toExteriorApertures == True) or (toContents == True):
3590
- for anEdge in topEdges:
3591
- try:
3592
- vEdge = Edge.VertexByParameter(anEdge, 0.5)
3593
- except:
3594
- vEdge = anEdge.CenterOfMass()
3595
- # d1 = anEdge.GetDictionary()
3596
- # d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 0) # main topology
3597
- # if storeBREP:
3598
- # d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(anEdge), Topology.Type(anEdge), Topology.TypeAsString(anEdge)])
3599
- # d3 = mergeDictionaries2([d1, d2])
3600
- # _ = vEdge.SetDictionary(d3)
3601
- # else:
3602
- # _ = vEdge.SetDictionary(d1)
3603
- # vertices.append(vEdge)
3604
- eVertices = []
3605
- _ = anEdge.Vertices(None, eVertices)
3337
+ e = Topology.SetDictionary(e, mDict, silent=True)
3338
+ graph_edges.append(e)
3339
+ edges = Topology.Edges(topology)
3340
+ if any([viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents]):
3341
+ for anEdge in edges:
3342
+ if useInternalVertex == True:
3343
+ vEdge = Topology.InternalVertex(anEdge, tolerance=tolerance)
3344
+ else:
3345
+ vEdge = Topology.CenterOfMass(anEdge)
3346
+ d = Topology.Dictionary(anEdge)
3347
+ vCell = Topology.SetDictionary(vEdge, d, silent=True)
3348
+ vertices = Topology.Vertices(anEdge)
3606
3349
  sharedTopologies = []
3607
3350
  exteriorTopologies = []
3608
3351
  sharedApertures = []
3609
3352
  exteriorApertures = []
3610
- contents = []
3611
- _ = anEdge.Contents(contents)
3612
- for aVertex in eVertices:
3613
- tempEdges = []
3614
- _ = aVertex.Edges(topology, tempEdges)
3615
- if len(tempEdges) > 1:
3353
+ edge_contents = Topology.Contents(anEdge)
3354
+ for aVertex in vertices:
3355
+ edges1 = Topology.SuperTopologies(aVertex, topology, topologyType="Edge")
3356
+ if len(edges1) > 1:
3616
3357
  sharedTopologies.append(aVertex)
3617
3358
  apertures = Topology.Apertures(aVertex)
3618
3359
  for anAperture in apertures:
@@ -3623,328 +3364,262 @@ class Graph:
3623
3364
  for anAperture in apertures:
3624
3365
  exteriorApertures.append(anAperture)
3625
3366
  if viaSharedTopologies:
3367
+ verts, eds = _viaSharedTopologies(vEdge, sharedTopologies)
3368
+ graph_vertices += verts
3369
+ graph_edges += eds
3626
3370
  for sharedTopology in sharedTopologies:
3627
- vst = sharedTopology.CenterOfMass()
3628
- d1 = sharedTopology.GetDictionary()
3629
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 1) # shared topology
3630
- if storeBREP:
3631
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(sharedTopology), Topology.Type(sharedTopology), Topology.TypeAsString(sharedTopology)])
3632
- d3 = mergeDictionaries2([d1, d2])
3633
- _ = vst.SetDictionary(d3)
3371
+ if useInternalVertex == True:
3372
+ vst = Topology.InternalVertex(sharedTopology, tolerance)
3634
3373
  else:
3635
- _ = vst.SetDictionary(d1)
3636
- vertices.append(vst)
3637
- tempe = Edge.ByStartVertexEndVertex(vEdge, vst, tolerance=tolerance)
3638
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["Via_Shared_Topologies", 1])
3639
- _ = tempe.SetDictionary(tempd)
3640
- edges.append(tempe)
3374
+ vst = Topology.CenterOfMass(sharedTopology)
3375
+ d = Topology.Dictionary(sharedTopology)
3376
+ vst = Topology.SetDictionary(vst, d, silent=True)
3641
3377
  if toContents:
3642
- contents = []
3643
- _ = sharedTopology.Contents(contents)
3644
- for content in contents:
3645
- if Topology.IsInstance(content, "Aperture"):
3646
- content = Aperture.Topology(content)
3647
- if useInternalVertex == True:
3648
- vst2 = Topology.InternalVertex(content, tolerance)
3649
- else:
3650
- vst2 = content.CenterOfMass()
3651
- vst2 = Vertex.ByCoordinates(Vertex.X(vst2, mantissa=mantissa)+(tolerance*100), Vertex.Y(vst2, mantissa=mantissa)+(tolerance*100), Vertex.Z(vst2, mantissa=mantissa)+(tolerance*100))
3652
- d1 = content.GetDictionary()
3653
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 5) # content
3654
- if storeBREP:
3655
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(content), Topology.Type(content), Topology.TypeAsString(content)])
3656
- d3 = mergeDictionaries2([d1, d2])
3657
- _ = vst2.SetDictionary(d3)
3658
- else:
3659
- _ = vst2.SetDictionary(d1)
3660
- vertices.append(vst2)
3661
- tempe = Edge.ByStartVertexEndVertex(vst, vst2, tolerance=tolerance)
3662
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Contents", 5])
3663
- _ = tempe.SetDictionary(tempd)
3664
- edges.append(tempe)
3378
+ shd_top_contents = Topology.Contents(sharedTopology)
3379
+ verts, eds = _toContents(vst, shd_top_contents)
3380
+ graph_vertices += verts
3381
+ graph_edges += eds
3382
+ if toOutposts and others:
3383
+ verts, eds = _toOutposts(vst, others)
3384
+ graph_vertices += verts
3385
+ graph_edges += eds
3665
3386
  if viaSharedApertures:
3666
- for sharedAp in sharedApertures:
3667
- if useInternalVertex == True:
3668
- vst = Topology.InternalVertex(sharedAp, tolerance)
3669
- else:
3670
- vst = sharedAp.CenterOfMass()
3671
- d1 = sharedAp.GetDictionary()
3672
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 2) # shared aperture
3673
- vst = Vertex.ByCoordinates(Vertex.X(vst, mantissa=mantissa)+(tolerance*100), Vertex.Y(vst, mantissa=mantissa)+(tolerance*100), Vertex.Z(vst, mantissa=mantissa)+(tolerance*100))
3674
- if storeBREP:
3675
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(sharedAp), Topology.Type(sharedAp), Topology.TypeAsString(sharedAp)])
3676
- d3 = mergeDictionaries2([d1, d2])
3677
- _ = vst.SetDictionary(d3)
3678
- else:
3679
- _ = vst.SetDictionary(d1)
3680
- vertices.append(vst)
3681
- tempe = Edge.ByStartVertexEndVertex(vEdge, vst, tolerance=tolerance)
3682
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["Via_Shared_Apertures", 2])
3683
- _ = tempe.SetDictionary(tempd)
3684
- edges.append(tempe)
3387
+ verts, eds = _viaSharedTopologies(vCell, sharedApertures)
3388
+ graph_vertices += verts
3389
+ graph_edges += eds
3685
3390
  if toExteriorTopologies:
3391
+ verts, eds = _toExteriorTopologies(vCell, exteriorTopologies)
3392
+ graph_vertices += verts
3393
+ graph_edges += eds
3686
3394
  for exteriorTopology in exteriorTopologies:
3687
- vst = exteriorTopology
3688
- vertices.append(exteriorTopology)
3689
- tempe = Edge.ByStartVertexEndVertex(vEdge, vst, tolerance=tolerance)
3690
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Exterior_Topologies", 3])
3691
- _ = tempe.SetDictionary(tempd)
3692
- edges.append(tempe)
3693
- if toContents:
3694
- contents = []
3695
- _ = vst.Contents(contents)
3696
- for content in contents:
3697
- if Topology.IsInstance(content, "Aperture"):
3698
- content = Aperture.Topology(content)
3699
- if useInternalVertex == True:
3700
- vst2 = Topology.InternalVertex(content, tolerance)
3701
- else:
3702
- vst2 = content.CenterOfMass()
3703
- vst2 = Vertex.ByCoordinates(Vertex.X(vst2, mantissa=mantissa)+(tolerance*100), Vertex.Y(vst2, mantissa=mantissa)+(tolerance*100), Vertex.Z(vst2, mantissa=mantissa)+(tolerance*100))
3704
- d1 = content.GetDictionary()
3705
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 5) # content
3706
- if storeBREP:
3707
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(content), Topology.Type(content), Topology.TypeAsString(content)])
3708
- d3 = mergeDictionaries2([d1, d2])
3709
- _ = vst2.SetDictionary(d3)
3710
- else:
3711
- _ = vst2.SetDictionary(d1)
3712
- vertices.append(vst2)
3713
- tempe = Edge.ByStartVertexEndVertex(vst, vst2, tolerance=tolerance)
3714
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Contents", 5])
3715
- _ = tempe.SetDictionary(tempd)
3716
- edges.append(tempe)
3717
- if toExteriorApertures:
3718
- for exTop in exteriorApertures:
3719
3395
  if useInternalVertex == True:
3720
- vst = Topology.InternalVertex(exTop, tolerance)
3721
- else:
3722
- vst = exTop.CenterOfMass()
3723
- d1 = exTop.GetDictionary()
3724
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 4) # exterior aperture
3725
- vst = Vertex.ByCoordinates(Vertex.X(vst, mantissa=mantissa)+(tolerance*100), Vertex.Y(vst, mantissa=mantissa)+(tolerance*100), Vertex.Z(vst, mantissa=mantissa)+(tolerance*100))
3726
- if storeBREP:
3727
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(exTop), Topology.Type(exTop), Topology.TypeAsString(exTop)])
3728
- d3 = mergeDictionaries2([d1, d2])
3729
- _ = vst.SetDictionary(d3)
3396
+ vet = Topology.InternalVertex(exteriorTopology, tolerance)
3730
3397
  else:
3731
- _ = vst.SetDictionary(d1)
3732
- vertices.append(vst)
3733
- tempe = Edge.ByStartVertexEndVertex(vEdge, vst, tolerance=tolerance)
3734
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Exterior_Apertures", 4])
3735
- _ = tempe.SetDictionary(tempd)
3736
- edges.append(tempe)
3398
+ vet = Topology.CenterOfMass(exteriorTopology)
3399
+ d = Topology.Dictionary(exteriorTopology)
3400
+ vet = Topology.SetDictionary(vet, d, silent=True)
3401
+ if toContents:
3402
+ ext_top_contents = Topology.Contents(exteriorTopology)
3403
+ verts, eds = _toContents(vet, ext_top_contents)
3404
+ graph_vertices += verts
3405
+ graph_edges += eds
3406
+ if toOutposts and others:
3407
+ verts, eds = _toOutposts(vet, others)
3408
+ graph_vertices += verts
3409
+ graph_edges += eds
3410
+ if toExteriorApertures:
3411
+ verts, eds = _toExteriorApertures(vEdge, exteriorApertures)
3412
+ graph_vertices += verts
3413
+ graph_edges += eds
3737
3414
  if toContents:
3738
- contents = []
3739
- _ = anEdge.Contents(contents)
3740
- for content in contents:
3741
- if Topology.IsInstance(content, "Aperture"):
3742
- content = Aperture.Topology(content)
3743
- if useInternalVertex == True:
3744
- vst = Topology.InternalVertex(content, tolerance)
3745
- else:
3746
- vst = content.CenterOfMass()
3747
- vst = Vertex.ByCoordinates(Vertex.X(vst, mantissa=mantissa)+(tolerance*100), Vertex.Y(vst, mantissa=mantissa)+(tolerance*100), Vertex.Z(vst, mantissa=mantissa)+(tolerance*100))
3748
- d1 = content.GetDictionary()
3749
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 5) # content
3750
- if storeBREP:
3751
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(content), Topology.Type(content), Topology.TypeAsString(content)])
3752
- d3 = mergeDictionaries2([d1, d2])
3753
- _ = vst.SetDictionary(d3)
3754
- else:
3755
- _ = vst.SetDictionary(d1)
3756
- vertices.append(vst)
3757
- tempe = Edge.ByStartVertexEndVertex(vEdge, vst, tolerance=tolerance)
3758
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Contents", 5])
3759
- _ = tempe.SetDictionary(tempd)
3760
- edges.append(tempe)
3761
- for anEdge in topEdges:
3762
- try:
3763
- vEdge = Edge.VertexByParameter(anEdge, 0.5)
3764
- except:
3765
- vEdge = anEdge.CenterOfMass()
3766
- d1 = anEdge.GetDictionary()
3767
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 0) # main topologuy
3768
- if storeBREP:
3769
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(anEdge), Topology.Type(anEdge), Topology.TypeAsString(anEdge)])
3770
- d3 = mergeDictionaries2([d1, d2])
3771
- _ = vEdge.SetDictionary(d3)
3772
- else:
3773
- _ = vEdge.SetDictionary(d1)
3774
- vertices.append(vEdge)
3775
-
3776
- if toOutposts and others:
3777
- d = Topology.Dictionary(topology)
3778
- if not d == None:
3779
- keys = Dictionary.Keys(d)
3780
- else:
3781
- keys = []
3782
- k = None
3783
- for key in keys:
3784
- if key.lower() == outpostsKey.lower():
3785
- k = key
3786
- if k:
3787
- ids = Dictionary.ValueAtKey(k)
3788
- outposts = outpostsByID(others, ids, idKey)
3789
- else:
3790
- outposts = []
3791
- for outpost in outposts:
3792
- if useInternalVertex == True:
3793
- vop = Topology.InternalVertex(outpost, tolerance)
3794
- vcc = Topology.InternalVertex(topology, tolerance)
3795
- else:
3796
- vop = Topology.CenterOfMass(outpost)
3797
- vcc = Topology.CenterOfMass(topology)
3798
- d1 = Topology.Dictionary(vcc)
3799
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 0) # main topology
3800
- if storeBREP:
3801
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(topology), Topology.Type(topology), Topology.TypeAsString(topology)])
3802
- d3 = mergeDictionaries2([d1, d2])
3803
- _ = vcc.SetDictionary(d3)
3804
- else:
3805
- _ = vcc.SetDictionary(d1)
3806
- vertices.append(vcc)
3807
- d1 = Topology.Dictionary(vop)
3808
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 6) # outpost
3809
- if storeBREP:
3810
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(topology), Topology.Type(topology), Topology.TypeAsString(topology)])
3811
- d3 = mergeDictionaries2([d1, d2])
3812
- _ = vop.SetDictionary(d3)
3813
- else:
3814
- _ = vop.SetDictionary(d1)
3815
- vertices.append(vop)
3816
- tempe = Edge.ByStartVertexEndVertex(vcc, vop, tolerance=tolerance)
3817
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Outposts", 6])
3818
- _ = tempe.SetDictionary(tempd)
3819
- edges.append(tempe)
3820
-
3821
- return [vertices, edges]
3415
+ verts, eds = _toContents(vEdge, edge_contents)
3416
+ graph_vertices += verts
3417
+ graph_edges += eds
3418
+ if toOutposts and others:
3419
+ verts, eds = toOutposts(vEdge, others)
3420
+ graph_vertices += verts
3421
+ graph_edges += eds
3422
+ return [graph_vertices, graph_edges]
3423
+
3424
+
3822
3425
 
3823
3426
  def processEdge(item):
3824
3427
  topology, others, outpostsKey, idKey, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, toOutposts, useInternalVertex, storeBREP, tolerance = item
3825
- vertices = []
3826
- edges = []
3827
-
3428
+ graph_vertices = []
3429
+ graph_edges = []
3828
3430
  if useInternalVertex == True:
3829
- try:
3830
- vEdge = Edge.VertexByParameter(topology, 0.5)
3831
- except:
3832
- vEdge = topology.CenterOfMass()
3431
+ vEdge = Topology.InternalVertex(topology, tolerance=tolerance)
3833
3432
  else:
3834
- vEdge = topology.CenterOfMass()
3835
-
3836
- d1 = vEdge.GetDictionary()
3433
+ vEdge = Topology.CenterOfMass(topology)
3434
+ d1 = Topology.Dictionary(topology)
3837
3435
  d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 0) # main topology
3838
3436
  if storeBREP:
3839
3437
  d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(topology), Topology.Type(topology), Topology.TypeAsString(topology)])
3840
3438
  d3 = mergeDictionaries2([d1, d2])
3841
- _ = vEdge.SetDictionary(d3)
3439
+ vEdge = Topology.SetDictionary(vEdge, d3, silent=True)
3842
3440
  else:
3843
- _ = vEdge.SetDictionary(topology.GetDictionary())
3844
-
3845
- vertices.append(vEdge)
3846
-
3847
- if toOutposts and others:
3848
- d = Topology.Dictionary(topology)
3849
- if not d == None:
3850
- keys = Dictionary.Keys(d)
3851
- else:
3852
- keys = []
3853
- k = None
3854
- for key in keys:
3855
- if key.lower() == outpostsKey.lower():
3856
- k = key
3857
- if k:
3858
- ids = Dictionary.ValueAtKey(d, k)
3859
- outposts = outpostsByID(others, ids, idKey)
3860
- else:
3861
- outposts = []
3862
- for outpost in outposts:
3863
- if useInternalVertex == True:
3864
- vop = Topology.InternalVertex(outpost, tolerance)
3865
- else:
3866
- vop = Topology.CenterOfMass(outpost)
3867
- tempe = Edge.ByStartVertexEndVertex(vEdge, vop, tolerance=tolerance)
3868
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Outposts", 6])
3869
- _ = tempe.SetDictionary(tempd)
3870
- edges.append(tempe)
3871
-
3872
- if (toExteriorTopologies == True) or (toExteriorApertures == True) or (toContents == True):
3873
- eVertices = []
3874
- _ = topology.Vertices(None, eVertices)
3441
+ vEdge = Topology.SetDictionary(vEdge, d1, silent=True)
3442
+ graph_vertices.append(vEdge)
3443
+ if any([toExteriorTopologies, toExteriorApertures, toContents, toOutposts]):
3444
+ edge_contents = Topology.Contents(topology)
3445
+ vertices = Topology.Vertices(topology)
3875
3446
  exteriorTopologies = []
3876
3447
  exteriorApertures = []
3877
- for aVertex in eVertices:
3448
+ for aVertex in vertices:
3878
3449
  exteriorTopologies.append(aVertex)
3879
3450
  apertures = Topology.Apertures(aVertex)
3880
3451
  for anAperture in apertures:
3881
3452
  exteriorApertures.append(anAperture)
3882
- if toExteriorTopologies:
3883
- for exteriorTopology in exteriorTopologies:
3884
- if useInternalVertex == True:
3885
- vst = Topology.InternalVertex(exteriorTopology, tolerance)
3886
- else:
3887
- vst = exteriorTopology.CenterOfMass()
3888
- d1 = exteriorTopology.GetDictionary()
3889
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 3) # exterior topology
3890
- if storeBREP:
3891
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(exteriorTopology), Topology.Type(exteriorTopology), Topology.TypeAsString(exteriorTopology)])
3892
- d3 = mergeDictionaries2([d1, d2])
3893
- _ = vst.SetDictionary(d3)
3894
- else:
3895
- _ = vst.SetDictionary(d1)
3896
- vertices.append(vst)
3897
- tempe = Edge.ByStartVertexEndVertex(vEdge, vst, tolerance=tolerance)
3898
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Exterior_Topologies", 3])
3899
- _ = tempe.SetDictionary(tempd)
3900
- edges.append(tempe)
3901
- if toContents:
3902
- contents = []
3903
- _ = vst.Contents(contents)
3904
- for content in contents:
3905
- if Topology.IsInstance(content, "Aperture"):
3906
- content = Aperture.Topology(content)
3907
- if useInternalVertex == True:
3908
- vst2 = Topology.InternalVertex(content, tolerance)
3909
- else:
3910
- vst2 = content.CenterOfMass()
3911
- vst2 = Vertex.ByCoordinates(Vertex.X(vst2, mantissa=mantissa)+(tolerance*100), Vertex.Y(vst2, mantissa=mantissa)+(tolerance*100), Vertex.Z(vst2, mantissa=mantissa)+(tolerance*100))
3912
- d1 = content.GetDictionary()
3913
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 5) # content
3914
- if storeBREP:
3915
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(content), Topology.Type(content), Topology.TypeAsString(content)])
3916
- d3 = mergeDictionaries2([d1, d2])
3917
- _ = vst2.SetDictionary(d3)
3918
- else:
3919
- _ = vst2.SetDictionary(d1)
3920
- vertices.append(vst2)
3921
- tempe = Edge.ByStartVertexEndVertex(vst, vst2, tolerance=tolerance)
3922
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Contents", 5])
3923
- _ = tempe.SetDictionary(tempd)
3924
- edges.append(tempe)
3925
- if toExteriorApertures:
3926
- for exTop in exteriorApertures:
3927
- if useInternalVertex == True:
3928
- vst = Topology.InternalVertex(exTop, tolerance)
3929
- else:
3930
- vst = exTop.CenterOfMass()
3931
- d1 = exTop.GetDictionary()
3932
- d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 4) # exterior aperture
3933
- vst = Vertex.ByCoordinates(Vertex.X(vst, mantissa=mantissa)+(tolerance*100), Vertex.Y(vst, mantissa=mantissa)+(tolerance*100), Vertex.Z(vst, mantissa=mantissa)+(tolerance*100))
3934
- if storeBREP:
3935
- d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(exTop), Topology.Type(exTop), Topology.TypeAsString(exTop)])
3936
- d3 = mergeDictionaries2([d1, d2])
3937
- _ = vst.SetDictionary(d3)
3938
- else:
3939
- _ = vst.SetDictionary(d1)
3940
- _ = vst.SetDictionary(exTop.GetDictionary())
3941
- vertices.append(vst)
3942
- tempe = Edge.ByStartVertexEndVertex(vEdge, vst, tolerance=tolerance)
3943
- tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Exterior_Apertures", 4])
3944
- _ = tempe.SetDictionary(tempd)
3945
- edges.append(tempe)
3453
+ if toExteriorTopologies:
3454
+ verts, eds = _toExteriorTopologies(vEdge, exteriorTopologies)
3455
+ graph_vertices += verts
3456
+ graph_edges += eds
3457
+ for exteriorTopology in exteriorTopologies:
3458
+ if useInternalVertex == True:
3459
+ vet = Topology.InternalVertex(exteriorTopology, tolerance)
3460
+ else:
3461
+ vet = Topology.CenterOfMass(exteriorTopology)
3462
+ d = Topology.Dictionary(exteriorTopology)
3463
+ vet = Topology.SetDictionary(vet, d, silent=True)
3464
+ if toContents:
3465
+ ext_top_contents = Topology.Contents(exteriorTopology)
3466
+ verts, eds = _toContents(vet, ext_top_contents)
3467
+ graph_vertices += verts
3468
+ graph_edges += eds
3469
+ if toOutposts and others:
3470
+ verts, eds = _toOutposts(vet, others)
3471
+ graph_vertices += verts
3472
+ graph_edges += eds
3473
+ if toExteriorApertures:
3474
+ verts, eds = _toExteriorApertures(vEdge, exteriorApertures)
3475
+ graph_vertices += verts
3476
+ graph_edges += eds
3477
+ if toContents:
3478
+ verts, eds = _toContents(vEdge, edge_contents)
3479
+ graph_vertices += verts
3480
+ graph_edges += eds
3481
+ if toOutposts and others:
3482
+ verts, eds = toOutposts(vEdge, others)
3483
+ graph_vertices += verts
3484
+ graph_edges += eds
3485
+ return [graph_vertices, graph_edges]
3486
+
3487
+
3488
+
3489
+
3490
+
3491
+
3492
+ # def processEdge(item):
3493
+ # topology, others, outpostsKey, idKey, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, toOutposts, useInternalVertex, storeBREP, tolerance = item
3494
+ # vertices = []
3495
+ # edges = []
3496
+
3497
+ # if useInternalVertex == True:
3498
+ # try:
3499
+ # vEdge = Edge.VertexByParameter(topology, 0.5)
3500
+ # except:
3501
+ # vEdge = topology.CenterOfMass()
3502
+ # else:
3503
+ # vEdge = topology.CenterOfMass()
3504
+
3505
+ # d1 = vEdge.GetDictionary()
3506
+ # d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 0) # main topology
3507
+ # if storeBREP:
3508
+ # d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(topology), Topology.Type(topology), Topology.TypeAsString(topology)])
3509
+ # d3 = mergeDictionaries2([d1, d2])
3510
+ # _ = vEdge.SetDictionary(d3)
3511
+ # else:
3512
+ # _ = vEdge.SetDictionary(topology.GetDictionary())
3513
+
3514
+ # vertices.append(vEdge)
3515
+
3516
+ # if toOutposts and others:
3517
+ # d = Topology.Dictionary(topology)
3518
+ # if not d == None:
3519
+ # keys = Dictionary.Keys(d)
3520
+ # else:
3521
+ # keys = []
3522
+ # k = None
3523
+ # for key in keys:
3524
+ # if key.lower() == outpostsKey.lower():
3525
+ # k = key
3526
+ # if k:
3527
+ # ids = Dictionary.ValueAtKey(d, k)
3528
+ # outposts = outpostsByID(others, ids, idKey)
3529
+ # else:
3530
+ # outposts = []
3531
+ # for outpost in outposts:
3532
+ # if useInternalVertex == True:
3533
+ # vop = Topology.InternalVertex(outpost, tolerance)
3534
+ # else:
3535
+ # vop = Topology.CenterOfMass(outpost)
3536
+ # tempe = Edge.ByStartVertexEndVertex(vEdge, vop, tolerance=tolerance)
3537
+ # tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Outposts", 6])
3538
+ # _ = tempe.SetDictionary(tempd)
3539
+ # edges.append(tempe)
3540
+
3541
+ # if (toExteriorTopologies == True) or (toExteriorApertures == True) or (toContents == True):
3542
+ # eVertices = []
3543
+ # _ = topology.Vertices(None, eVertices)
3544
+ # exteriorTopologies = []
3545
+ # exteriorApertures = []
3546
+ # for aVertex in eVertices:
3547
+ # exteriorTopologies.append(aVertex)
3548
+ # apertures = Topology.Apertures(aVertex)
3549
+ # for anAperture in apertures:
3550
+ # exteriorApertures.append(anAperture)
3551
+ # if toExteriorTopologies:
3552
+ # for exteriorTopology in exteriorTopologies:
3553
+ # if useInternalVertex == True:
3554
+ # vst = Topology.InternalVertex(exteriorTopology, tolerance)
3555
+ # else:
3556
+ # vst = exteriorTopology.CenterOfMass()
3557
+ # d1 = exteriorTopology.GetDictionary()
3558
+ # d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 3) # exterior topology
3559
+ # if storeBREP:
3560
+ # d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(exteriorTopology), Topology.Type(exteriorTopology), Topology.TypeAsString(exteriorTopology)])
3561
+ # d3 = mergeDictionaries2([d1, d2])
3562
+ # _ = vst.SetDictionary(d3)
3563
+ # else:
3564
+ # _ = vst.SetDictionary(d1)
3565
+ # vertices.append(vst)
3566
+ # tempe = Edge.ByStartVertexEndVertex(vEdge, vst, tolerance=tolerance)
3567
+ # tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Exterior_Topologies", 3])
3568
+ # _ = tempe.SetDictionary(tempd)
3569
+ # edges.append(tempe)
3570
+ # if toContents:
3571
+ # contents = []
3572
+ # _ = vst.Contents(contents)
3573
+ # for content in contents:
3574
+ # if Topology.IsInstance(content, "Aperture"):
3575
+ # content = Aperture.Topology(content)
3576
+ # if useInternalVertex == True:
3577
+ # vst2 = Topology.InternalVertex(content, tolerance)
3578
+ # else:
3579
+ # vst2 = content.CenterOfMass()
3580
+ # vst2 = Vertex.ByCoordinates(Vertex.X(vst2, mantissa=mantissa)+(tolerance*100), Vertex.Y(vst2, mantissa=mantissa)+(tolerance*100), Vertex.Z(vst2, mantissa=mantissa)+(tolerance*100))
3581
+ # d1 = content.GetDictionary()
3582
+ # d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 5) # content
3583
+ # if storeBREP:
3584
+ # d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(content), Topology.Type(content), Topology.TypeAsString(content)])
3585
+ # d3 = mergeDictionaries2([d1, d2])
3586
+ # _ = vst2.SetDictionary(d3)
3587
+ # else:
3588
+ # _ = vst2.SetDictionary(d1)
3589
+ # vertices.append(vst2)
3590
+ # tempe = Edge.ByStartVertexEndVertex(vst, vst2, tolerance=tolerance)
3591
+ # tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Contents", 5])
3592
+ # _ = tempe.SetDictionary(tempd)
3593
+ # edges.append(tempe)
3594
+ # if toExteriorApertures:
3595
+ # for exTop in exteriorApertures:
3596
+ # if useInternalVertex == True:
3597
+ # vst = Topology.InternalVertex(exTop, tolerance)
3598
+ # else:
3599
+ # vst = exTop.CenterOfMass()
3600
+ # d1 = exTop.GetDictionary()
3601
+ # d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 4) # exterior aperture
3602
+ # vst = Vertex.ByCoordinates(Vertex.X(vst, mantissa=mantissa)+(tolerance*100), Vertex.Y(vst, mantissa=mantissa)+(tolerance*100), Vertex.Z(vst, mantissa=mantissa)+(tolerance*100))
3603
+ # if storeBREP:
3604
+ # d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(exTop), Topology.Type(exTop), Topology.TypeAsString(exTop)])
3605
+ # d3 = mergeDictionaries2([d1, d2])
3606
+ # _ = vst.SetDictionary(d3)
3607
+ # else:
3608
+ # _ = vst.SetDictionary(d1)
3609
+ # _ = vst.SetDictionary(exTop.GetDictionary())
3610
+ # vertices.append(vst)
3611
+ # tempe = Edge.ByStartVertexEndVertex(vEdge, vst, tolerance=tolerance)
3612
+ # tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Exterior_Apertures", 4])
3613
+ # _ = tempe.SetDictionary(tempd)
3614
+ # edges.append(tempe)
3946
3615
 
3947
- return [vertices, edges]
3616
+ # return [vertices, edges]
3617
+
3618
+
3619
+
3620
+
3621
+
3622
+
3948
3623
 
3949
3624
  def processVertex(item):
3950
3625
  topology, others, outpostsKey, idKey, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, toOutposts, useInternalVertex, storeBREP, tolerance = item
@@ -3952,28 +3627,27 @@ class Graph:
3952
3627
  edges = []
3953
3628
 
3954
3629
  if toContents:
3955
- contents = []
3956
- _ = topology.Contents(contents)
3630
+ contents = Topology.Contents(topology)
3957
3631
  for content in contents:
3958
3632
  if Topology.IsInstance(content, "Aperture"):
3959
3633
  content = Aperture.Topology(content)
3960
3634
  if useInternalVertex == True:
3961
3635
  vst = Topology.InternalVertex(content, tolerance)
3962
3636
  else:
3963
- vst = content.CenterOfMass()
3964
- d1 = content.GetDictionary()
3637
+ vst = Topology.CenterOfMass(content)
3638
+ d1 = Topology.Dictionary(content)
3965
3639
  d1 = Dictionary.SetValueAtKey(d1, vertexCategoryKey, 5) # content
3966
3640
  vst = Vertex.ByCoordinates(Vertex.X(vst, mantissa=mantissa)+(tolerance*100), Vertex.Y(vst, mantissa=mantissa)+(tolerance*100), Vertex.Z(vst, mantissa=mantissa)+(tolerance*100))
3967
3641
  if storeBREP:
3968
3642
  d2 = Dictionary.ByKeysValues(["brep", "brepType", "brepTypeString"], [Topology.BREPString(content), Topology.Type(content), Topology.TypeAsString(content)])
3969
3643
  d3 = mergeDictionaries2([d1, d2])
3970
- _ = vst.SetDictionary(d3)
3644
+ vst = Topology.SetDictionary(vst, d3, silent=True)
3971
3645
  else:
3972
- _ = vst.SetDictionary(d1)
3646
+ vst = Topology.SetDictionary(vst, d1, silent=True)
3973
3647
  vertices.append(vst)
3974
3648
  tempe = Edge.ByStartVertexEndVertex(topology, vst, tolerance=tolerance)
3975
3649
  tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Contents", 5])
3976
- _ = tempe.SetDictionary(tempd)
3650
+ tempe = Topology.SetDictionary(tempe, tempd, silent=True)
3977
3651
  edges.append(tempe)
3978
3652
 
3979
3653
  if toOutposts and others:
@@ -3998,7 +3672,7 @@ class Graph:
3998
3672
  vop = Topology.CenterOfMass(outpost)
3999
3673
  tempe = Edge.ByStartVertexEndVertex(topology, vop, tolerance=tolerance)
4000
3674
  tempd = Dictionary.ByKeysValues(["relationship", edgeCategoryKey],["To_Outposts", 6])
4001
- _ = tempe.SetDictionary(tempd)
3675
+ tempd = Topology.SetDictionary(tempe, tempd, silent=True)
4002
3676
  edges.append(tempe)
4003
3677
 
4004
3678
  return [vertices, edges]
@@ -4007,7 +3681,15 @@ class Graph:
4007
3681
  if not Topology.IsInstance(topology, "Topology"):
4008
3682
  print("Graph.ByTopology - Error: The input topology is not a valid topology. Returning None.")
4009
3683
  return None
4010
- item = [topology, None, None, None, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, None, useInternalVertex, storeBREP, tolerance]
3684
+ c_cellComplexes = Topology.CellComplexes(topology)
3685
+ c_cells = Topology.Cells(topology)
3686
+ c_shells = Topology.Shells(topology)
3687
+ c_faces = Topology.Faces(topology)
3688
+ c_wires = Topology.Wires(topology)
3689
+ c_edges = Topology.Edges(topology)
3690
+ c_vertices = Topology.Vertices(topology)
3691
+ others = c_cellComplexes+c_cells+c_shells+c_faces+c_wires+c_edges+c_vertices
3692
+ item = [topology, others, outpostsKey, idKey, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, toOutposts, useInternalVertex, storeBREP, tolerance]
4011
3693
  vertices = []
4012
3694
  edges = []
4013
3695
  if Topology.IsInstance(topology, "CellComplex"):
@@ -4032,7 +3714,7 @@ class Graph:
4032
3714
  c_wires = Cluster.FreeWires(topology, tolerance=tolerance)
4033
3715
  c_edges = Cluster.FreeEdges(topology, tolerance=tolerance)
4034
3716
  c_vertices = Cluster.FreeVertices(topology, tolerance=tolerance)
4035
- others = c_cellComplexes+c_cells+c_shells+c_faces+c_wires+c_edges+c_vertices
3717
+ others = others+c_cellComplexes+c_cells+c_shells+c_faces+c_wires+c_edges+c_vertices
4036
3718
  parameters = [others, outpostsKey, idKey, direct, directApertures, viaSharedTopologies, viaSharedApertures, toExteriorTopologies, toExteriorApertures, toContents, toOutposts, useInternalVertex, storeBREP, tolerance]
4037
3719
 
4038
3720
  for t in c_cellComplexes:
@@ -4476,7 +4158,7 @@ class Graph:
4476
4158
  if not len(verticesA) == len(verticesB):
4477
4159
  print("Graph.Connect - Error: The input lists verticesA and verticesB have different lengths. Returning None.")
4478
4160
  return None
4479
- _ = graph.Connect(verticesA, verticesB, tolerance)
4161
+ _ = graph.Connect(verticesA, verticesB, tolerance) # Hook to core library
4480
4162
  return graph
4481
4163
 
4482
4164
  @staticmethod
@@ -4616,7 +4298,7 @@ class Graph:
4616
4298
  print("Graph.DegreeSequence - Error: The input graph is not a valid graph. Returning None.")
4617
4299
  return None
4618
4300
  sequence = []
4619
- _ = graph.DegreeSequence(sequence)
4301
+ _ = graph.DegreeSequence(sequence) # Hook to core library
4620
4302
  return sequence
4621
4303
 
4622
4304
  @staticmethod
@@ -4642,6 +4324,60 @@ class Graph:
4642
4324
  return None
4643
4325
  return graph.Density()
4644
4326
 
4327
+ @staticmethod
4328
+ def Depth(graph, vertex = None, tolerance: float = 0.0001, silent: bool = False):
4329
+ """
4330
+ Computes the maximum depth of the input graph rooted at the input vertex.
4331
+
4332
+ Parameters
4333
+ ----------
4334
+ graph : topologic_core.Graph
4335
+ The input graph.
4336
+ vertex : topologic_core.Vertex , optional
4337
+ The input root vertex. If not set, the first vertex in the graph is set as the root vertex. The default is None.
4338
+ tolerance : float , optional
4339
+ The desired tolerance. The default is 0.0001.
4340
+ silent : bool , optional
4341
+ If set to True, no error and warning messages are printed. Otherwise, they are. The default is False.
4342
+
4343
+ Returns
4344
+ -------
4345
+ int
4346
+ The calculated maximum depth of the input graph rooted at the input vertex.
4347
+
4348
+ """
4349
+ def dfs(node, depth, visited):
4350
+ visited.add(Vertex.Index(node, vertices, tolerance=tolerance))
4351
+ max_depth = depth
4352
+ for neighbor in Graph.AdjacentVertices(graph, node):
4353
+ if Vertex.Index(neighbor, vertices, tolerance=tolerance) not in visited:
4354
+ max_depth = max(max_depth, dfs(neighbor, depth + 1, visited))
4355
+ return max_depth
4356
+
4357
+ from topologicpy.Vertex import Vertex
4358
+ from topologicpy.Topology import Topology
4359
+
4360
+ if not Topology.IsInstance(graph, "Graph"):
4361
+ if not silent:
4362
+ print("Graph.Depth - Error: The input graph parameter is not a valid graph. Returning None.")
4363
+ return
4364
+
4365
+ vertices = Graph.Vertices(graph)
4366
+ if vertex == None:
4367
+ v_index = 0
4368
+ else:
4369
+ if not Topology.IsInstance(vertex, "Vertex"):
4370
+ if not silent:
4371
+ print("Graph.Depth - Error: The input rootVertex parameter is not a valid vertex. Returning None.")
4372
+ return None
4373
+ v_index = Vertex.Index(vertex, vertices, tolerance=tolerance)
4374
+ if v_index == None:
4375
+ if not silent:
4376
+ print("Graph.Depth - Error: Could not find the input root vertex in the graph's list of vertices. Returning None.")
4377
+ return None
4378
+ visited = set()
4379
+ return dfs(vertex, 1, visited) - 1
4380
+
4645
4381
  @staticmethod
4646
4382
  def DepthMap(graph, vertices=None, key: str = "depth", type: str = "topological", mantissa: int = 6, tolerance: float = 0.0001):
4647
4383
  """
@@ -4719,7 +4455,33 @@ class Graph:
4719
4455
  if not Topology.IsInstance(graph, "Graph"):
4720
4456
  print("Graph.Diameter - Error: The input graph is not a valid graph. Returning None.")
4721
4457
  return None
4722
- return graph.Diameter()
4458
+
4459
+ def dfs(node, visited):
4460
+ visited.add(node)
4461
+ max_depth = 0
4462
+ farthest_node = node
4463
+ for neighbor in adj_dict[node]:
4464
+ if neighbor not in visited:
4465
+ depth, end_node = dfs(neighbor, visited)
4466
+ if depth + 1 > max_depth:
4467
+ max_depth = depth + 1
4468
+ farthest_node = end_node
4469
+ return max_depth, farthest_node
4470
+
4471
+ adj_dict = Graph.AdjacencyDictionary(graph, includeWeights=False)
4472
+
4473
+ # Step 1: Pick an arbitrary starting node (first node in the graph)
4474
+ start_node = next(iter(adj_dict))
4475
+
4476
+ # Step 2: Run DFS to find the farthest node from the start_node
4477
+ visited = set()
4478
+ _, farthest_node = dfs(start_node, visited)
4479
+
4480
+ # Step 3: Run DFS from the farthest node found to get the maximum depth
4481
+ visited.clear()
4482
+ diameter, _ = dfs(farthest_node, visited)
4483
+
4484
+ return diameter
4723
4485
 
4724
4486
  @staticmethod
4725
4487
  def Dictionary(graph):
@@ -4742,7 +4504,7 @@ class Graph:
4742
4504
  if not Topology.IsInstance(graph, "Graph"):
4743
4505
  print("Graph.Dictionary - Error: the input graph parameter is not a valid graph. Returning None.")
4744
4506
  return None
4745
- return graph.GetDictionary()
4507
+ return graph.GetDictionary() # Hook to core library
4746
4508
 
4747
4509
  @staticmethod
4748
4510
  def Distance(graph, vertexA, vertexB, type: str = "topological", mantissa: int = 6, tolerance: float = 0.0001):
@@ -4850,7 +4612,7 @@ class Graph:
4850
4612
  return None
4851
4613
  if not vertices:
4852
4614
  edges = []
4853
- _ = graph.Edges(edges, tolerance)
4615
+ _ = graph.Edges(edges, tolerance) # Hook to core library
4854
4616
  return edges
4855
4617
  else:
4856
4618
  vertices = [v for v in vertices if Topology.IsInstance(v, "Vertex")]
@@ -4858,7 +4620,7 @@ class Graph:
4858
4620
  print("Graph.Edges - Error: The input list of vertices does not contain any valid vertices. Returning None.")
4859
4621
  return None
4860
4622
  edges = []
4861
- _ = graph.Edges(vertices, tolerance, edges)
4623
+ _ = graph.Edges(vertices, tolerance, edges) # Hook to core library
4862
4624
  return list(dict.fromkeys(edges)) # remove duplicates
4863
4625
 
4864
4626
  @staticmethod
@@ -5693,13 +5455,23 @@ class Graph:
5693
5455
  dict_color = Dictionary.ValueAtKey(d, vertexColorKey)
5694
5456
  if not dict_color == None:
5695
5457
  vertex_color = dict_color
5696
- if not vertex_color in Color.CSSNamedColors():
5697
- vertex_color = defaultVertexColor
5698
- node_dict['color'] = vertex_color
5699
- r, g, b = Color.ByCSSNamedColor(vertex_color)
5700
- node_dict['r'] = r
5701
- node_dict['g'] = g
5702
- node_dict['b'] = b
5458
+ if isinstance(vertex_color, list):
5459
+ if len(vertex_color) >= 3:
5460
+ node_dict['color'] = Color.CSSNamedColor(vertex_color)
5461
+ r, g, b = vertex_color
5462
+ node_dict['r'] = r
5463
+ node_dict['g'] = g
5464
+ node_dict['b'] = b
5465
+ else:
5466
+ vertex_color = defaultVertexColor
5467
+ else:
5468
+ if not vertex_color in Color.CSSNamedColors():
5469
+ vertex_color = defaultVertexColor
5470
+ node_dict['color'] = vertex_color
5471
+ r, g, b = Color.ByCSSNamedColor(vertex_color)
5472
+ node_dict['r'] = r
5473
+ node_dict['g'] = g
5474
+ node_dict['b'] = b
5703
5475
 
5704
5476
  dict_size = None
5705
5477
  if isinstance(vertexSizeKey, str):
@@ -6527,9 +6299,53 @@ class Graph:
6527
6299
  print("Graph.IsolatedVertices - Error: The input graph is not a valid graph. Returning None.")
6528
6300
  return None
6529
6301
  vertices = []
6530
- _ = graph.IsolatedVertices(vertices)
6302
+ _ = graph.IsolatedVertices(vertices) # Hook to core library
6531
6303
  return vertices
6532
-
6304
+
6305
+ @staticmethod
6306
+ def IsTree(graph):
6307
+ """
6308
+ Returns True if the input graph has a hierarchical tree-like structure. Returns False otherwise.
6309
+
6310
+ Parameters
6311
+ ----------
6312
+ graph : topologic_core.Graph
6313
+ The input graph.
6314
+
6315
+ Returns
6316
+ -------
6317
+ bool
6318
+ True if the input graph has a hierarchical tree-like structure. False otherwise.
6319
+
6320
+ """
6321
+
6322
+ adj_dict = Graph.AdjacencyDictionary(graph, includeWeights=False)
6323
+ # Helper function for Depth-First Search (DFS)
6324
+ def dfs(node, parent, visited):
6325
+ visited.add(node)
6326
+ for neighbor in adj_dict[node]:
6327
+ if neighbor not in visited:
6328
+ if not dfs(neighbor, node, visited):
6329
+ return False
6330
+ elif neighbor != parent:
6331
+ # A cycle is detected
6332
+ return False
6333
+ return True
6334
+
6335
+ # Initialize visited set
6336
+ visited = set()
6337
+
6338
+ # Start DFS from the first node in the graph
6339
+ start_node = next(iter(adj_dict)) # Get an arbitrary starting node
6340
+ if not dfs(start_node, None, visited):
6341
+ return False
6342
+
6343
+ # Check if all nodes were visited (the graph is connected)
6344
+ if len(visited) != len(adj_dict):
6345
+ return False
6346
+
6347
+ return True
6348
+
6533
6349
  @staticmethod
6534
6350
  def JSONData(graph,
6535
6351
  verticesKey: str = "vertices",
@@ -7884,7 +7700,7 @@ class Graph:
7884
7700
  if not Topology.IsInstance(edge, "Edge"):
7885
7701
  print("Graph.RemoveEdge - Error: The input edge is not a valid edge. Returning None.")
7886
7702
  return None
7887
- _ = graph.RemoveEdges([edge], tolerance)
7703
+ _ = graph.RemoveEdges([edge], tolerance) # Hook to core library
7888
7704
  return graph
7889
7705
 
7890
7706
  @staticmethod
@@ -7916,7 +7732,7 @@ class Graph:
7916
7732
  print("Graph.RemoveVertex - Error: The input vertex is not a valid vertex. Returning None.")
7917
7733
  return None
7918
7734
  graphVertex = Graph.NearestVertex(graph, vertex)
7919
- _ = graph.RemoveVertices([graphVertex])
7735
+ _ = graph.RemoveVertices([graphVertex]) # Hook to core library
7920
7736
  return graph
7921
7737
 
7922
7738
  @staticmethod
@@ -7951,7 +7767,7 @@ class Graph:
7951
7767
  if len(dictionary.Keys()) < 1:
7952
7768
  print("Graph.SetDictionary - Warning: the input dictionary parameter is empty. Returning original input.")
7953
7769
  return graph
7954
- _ = graph.SetDictionary(dictionary)
7770
+ _ = graph.SetDictionary(dictionary) # Hook to core library
7955
7771
  return graph
7956
7772
 
7957
7773
  @staticmethod
@@ -8476,7 +8292,7 @@ class Graph:
8476
8292
  vertices = []
8477
8293
  if graph:
8478
8294
  try:
8479
- _ = graph.Vertices(vertices)
8295
+ _ = graph.Vertices(vertices) # Hook to core libraries
8480
8296
  except:
8481
8297
  vertices = []
8482
8298
  if not vertexKey == None: