~sjdv1982/hivesystem/trunk

« back to all changes in this revision

Viewing changes to hiveguilib/HBlender/NodeTree.py

  • Committer: Sjoerd de Vries
  • Date: 2014-06-09 10:19:38 UTC
  • mfrom: (182.1.43 hive-view)
  • Revision ID: sjdv1982@gmail.com-20140609101938-7ji5g0buo09r0se6
merged with hive-view branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import bpy, bpy.types
2
2
import logging
3
 
 
 
3
from . import level
4
4
 
5
5
class FakeLink:
6
6
  def __init__(self, from_node, from_socket, to_node, to_socket):
23
23
    bntm = BlendManager.blendmanager.get_nodetree_manager(self.name)
24
24
    canvas = bntm.canvas    
25
25
    ids = [node.label for node in self.nodes]
26
 
    for id_ in canvas._nodes:
 
26
    for id_ in canvas.h()._nodes:
27
27
      if id_ not in ids:
28
28
        ret.append(id_)
29
29
    if ret:
42
42
      pair = l.from_node, l.from_socket, l.to_node, l.to_socket
43
43
      if pair in blinks: 
44
44
        continue      
 
45
      #print("NEW-CONNECTION", pair)
45
46
      new_connections.append(l)
46
47
    
47
48
    clinks = {(l.from_node, l.from_socket, l.to_node, l.to_socket) for l in self.links}
48
49
    for l in hcanvas._links:
49
50
      pair = l.from_node, l.from_socket, l.to_node, l.to_socket
50
51
      if pair not in clinks:
 
52
        #print("REMOVED-CONNECTION", pair)
51
53
        removed_connections.append(l)
52
54
    
53
55
    changed_nodes = []
60
62
        changed_nodes.append(l.to_node)
61
63
        
62
64
    for l in removed_connections:
63
 
      if l.from_node.label in deletions: continue
64
 
      if l.to_node.label in deletions: continue
 
65
      if l.from_node.identifier in deletions: continue
 
66
      if l.to_node.identifier in deletions: continue
65
67
      ok = hcanvas.gui_removes_connection(l)
66
68
      if not ok:
67
69
        logging.debug("removal of connection was disapproved, what to do?")
145
147
    bntm = BlendManager.blendmanager.get_nodetree_manager(self.name)
146
148
    canvas = bntm.canvas
147
149
    hcanvas = canvas.h()
148
 
    if hcanvas._adding: return
 
150
    if hcanvas._busy: return
149
151
    
150
152
    deletions = self._check_deletions()
151
153
    self._check_links(deletions)
182
184
  bl_label = 'Hive system workermap'
183
185
  # Icon identifier
184
186
  bl_icon = 'FORCE_MAGNETIC'
185
 
  """
186
187
  @classmethod
187
 
  def poll(cls, context): 
188
 
    #TODO: only show these in "advanced" mode
189
 
    return True
190
 
  """
 
188
  def poll(cls, context):     
 
189
    return level.active_workergui(context)
 
190
  
191
191
  
192
192
class SpydermapNodeTree(bpy.types.NodeTree, HiveNodeTree):
193
193
  # Description string
198
198
  bl_label = 'Hive system spydermap'
199
199
  # Icon identifier
200
200
  bl_icon = 'FORCE_LENNARDJONES'
201
 
  """
202
201
  @classmethod
203
 
  def poll(cls, context): 
204
 
    #TODO: only show these in "advanced" mode
205
 
    return True
206
 
  """
 
202
  def poll(cls, context):     
 
203
    return level.active_spydergui(context)
207
204
 
208
205
def draw_use_hive(self, context):
209
206
  if context.space_data.tree_type == "Hivemap":
210
207
    self.layout.prop(context.screen, "use_hive")
211
208
 
 
209
def draw_hive_level(self, context):
 
210
  if BlendManager.use_hive_get(context):
 
211
    self.layout.prop(context.screen, "hive_level")
 
212
    
212
213
def draw_spyderhive(self, context):
213
214
  from .BlendManager import blendmanager
214
215
  if context.space_data.tree_type == "Spydermap" and context.space_data.edit_tree is not None:
224
225
   get = BlendManager.use_hive_get,
225
226
   set = BlendManager.use_hive_set,
226
227
  ) 
227
 
  bpy.types.NODE_HT_header.append(draw_use_hive)
 
228
  bpy.types.Screen.hive_level = bpy.props.EnumProperty(
 
229
    name = "Hive level",
 
230
    description = "Hive logic level, unlocks more advanced hive features",
 
231
    items = (
 
232
      ("1", "1: SPARTA", "Level 1: Only use standard SPARTA nodes", 1),
 
233
      ("2", "2: Advanced SPARTA", "Level 2: Use all SPARTA nodes and parameters", 2),
 
234
      ("3", "3: Dragonfly", "Level 3: Also use Dragonfly nodes", 3),
 
235
      ("4", "4: Custom workers", "Level 4: Enable custom worker GUI", 4),
 
236
      ("5", "5: Spyder hives", "Level 5: Enable Spyder hive GUI for custom configuration", 5),
 
237
      ("6", "6: Advanced", "Level 6: Enable blocks, wasps and other advanced hive features", 6),
 
238
    ),
 
239
    update = BlendManager.change_hive_level
 
240
  )
 
241
  bpy.types.NODE_HT_header.append(draw_hive_level)
 
242
  bpy.types.NODE_HT_header.append(draw_use_hive)  
228
243
  bpy.types.NODE_HT_header.append(draw_spyderhive)
229
244
  
230
245
 
232
247
  bpy.utils.unregister_class(HivemapNodeTree)
233
248
  bpy.utils.unregister_class(WorkermapNodeTree)
234
249
  bpy.utils.unregister_class(SpydermapNodeTree)
235
 
  bpy.types.NODE_HT_header.remove(draw_use_hive)
 
250
  bpy.types.NODE_HT_header.remove(draw_hive_level)
 
251
  bpy.types.NODE_HT_header.remove(draw_use_hive)  
236
252
  bpy.types.NODE_HT_header.remove(draw_spyderhive)
 
 
b'\\ No newline at end of file'