asList() etc. no longer needed

This commit is contained in:
David Rose 2008-11-12 20:37:20 +00:00
parent cef263157d
commit c69c8680e8
15 changed files with 56 additions and 68 deletions

View File

@ -50,7 +50,7 @@ class DirectLights(NodePath):
light.removeNode() light.removeNode()
def deleteAll(self): def deleteAll(self):
for light in self.asList(): for light in self:
self.delete(light) self.delete(light)
def asList(self): def asList(self):

View File

@ -379,7 +379,7 @@ class DirectBoundingBox:
# Get a node path's bounds # Get a node path's bounds
nodeBounds = BoundingSphere() nodeBounds = BoundingSphere()
nodeBounds.extendBy(self.nodePath.node().getInternalBound()) nodeBounds.extendBy(self.nodePath.node().getInternalBound())
for child in self.nodePath.getChildrenAsList(): for child in self.nodePath.getChildren():
nodeBounds.extendBy(child.getBounds()) nodeBounds.extendBy(child.getBounds())
return nodeBounds.makeCopy() return nodeBounds.makeCopy()

View File

@ -72,7 +72,7 @@ class Mopath(DirectObject):
self.tNurbsCurve.append(node) self.tNurbsCurve.append(node)
else: else:
# Iterate over children if any # Iterate over children if any
for child in nodePath.getChildrenAsList(): for child in nodePath.getChildren():
self.__extractCurves(child) self.__extractCurves(child)
def calcTime(self, tIn): def calcTime(self, tIn):

View File

@ -14,16 +14,16 @@
# For iterating over children # For iterating over children
def getChildrenAsList(self): def getChildrenAsList(self):
"""Converts a node path's child NodePathCollection into a list""" """Converts a node path's child NodePathCollection into a list"""
return self.getChildren().asList() return self.getChildren()
def printChildren(self): def printChildren(self):
"""Prints out the children of the bottom node of a node path""" """Prints out the children of the bottom node of a node path"""
for child in self.getChildrenAsList(): for child in self.getChildren():
print child.getName() print child.getName()
def removeChildren(self): def removeChildren(self):
"""Deletes the children of the bottom node of a node path""" """Deletes the children of the bottom node of a node path"""
for child in self.getChildrenAsList(): for child in self.getChildren():
child.removeNode() child.removeNode()
def toggleVis(self): def toggleVis(self):
@ -37,20 +37,20 @@
def showSiblings(self): def showSiblings(self):
"""Show all the siblings of a node path""" """Show all the siblings of a node path"""
for sib in self.getParent().getChildrenAsList(): for sib in self.getParent().getChildren():
if sib.node() != self.node(): if sib.node() != self.node():
sib.show() sib.show()
def hideSiblings(self): def hideSiblings(self):
"""Hide all the siblings of a node path""" """Hide all the siblings of a node path"""
for sib in self.getParent().getChildrenAsList(): for sib in self.getParent().getChildren():
if sib.node() != self.node(): if sib.node() != self.node():
sib.hide() sib.hide()
def showAllDescendants(self): def showAllDescendants(self):
"""Show the node path and all its children""" """Show the node path and all its children"""
self.show() self.show()
for child in self.getChildrenAsList(): for child in self.getChildren():
child.showAllDescendants() child.showAllDescendants()
def isolate(self): def isolate(self):
@ -78,7 +78,7 @@
def lsNamesRecurse(self, indentString=' '): def lsNamesRecurse(self, indentString=' '):
"""Walk down a tree and print out the path""" """Walk down a tree and print out the path"""
for nodePath in self.getChildrenAsList(): for nodePath in self.getChildren():
type = nodePath.node().getType().getName() type = nodePath.node().getType().getName()
name = nodePath.getName() name = nodePath.getName()
print indentString + type + " " + name print indentString + type + " " + name
@ -261,7 +261,7 @@
outputString = '%s.setScale(%s, %s, %s)' % (name, fmtStr, fmtStr, fmtStr) outputString = '%s.setScale(%s, %s, %s)' % (name, fmtStr, fmtStr, fmtStr)
print outputString % (scale[0], scale[1], scale[2]) print outputString % (scale[0], scale[1], scale[2])
if fRecursive: if fRecursive:
for child in self.getChildrenAsList(): for child in self.getChildren():
child.printTransform(other, sd, fRecursive) child.printTransform(other, sd, fRecursive)
def iPos(self, other = None): def iPos(self, other = None):

View File

@ -7,13 +7,8 @@ from libpanda import *
# For iterating over children # For iterating over children
def asList(self): def asList(self):
"""Converts a NodePathCollection into a list""" """Converts a NodePathCollection into a list"""
if self.isEmpty(): print "Warning: NodePathCollection is no longer needed and deprecated. Iterate on the collection directly instead."
return [] return list(self)
else:
npList = []
for nodePathIndex in range(self.getNumPaths()):
npList.append(self.getPath(nodePathIndex))
return npList
Dtool_funcToMethod(asList, NodePathCollection) Dtool_funcToMethod(asList, NodePathCollection)
del asList del asList

View File

@ -28,7 +28,8 @@ del id
# For iterating over children # For iterating over children
def getChildrenAsList(self): def getChildrenAsList(self):
"""Converts a node path's child NodePathCollection into a list""" """Converts a node path's child NodePathCollection into a list"""
return self.getChildren().asList() print "Warning: NodePath.getChildren() is deprecated. Use getChildren() instead."
return list(self.getChildren())
Dtool_funcToMethod(getChildrenAsList, NodePath) Dtool_funcToMethod(getChildrenAsList, NodePath)
del getChildrenAsList del getChildrenAsList
@ -36,7 +37,7 @@ del getChildrenAsList
def printChildren(self): def printChildren(self):
"""Prints out the children of the bottom node of a node path""" """Prints out the children of the bottom node of a node path"""
for child in self.getChildrenAsList(): for child in self.getChildren():
print child.getName() print child.getName()
Dtool_funcToMethod(printChildren, NodePath) Dtool_funcToMethod(printChildren, NodePath)
del printChildren del printChildren
@ -44,8 +45,7 @@ del printChildren
def removeChildren(self): def removeChildren(self):
"""Deletes the children of the bottom node of a node path""" """Deletes the children of the bottom node of a node path"""
for child in self.getChildrenAsList(): self.getChildren().detach()
child.removeNode()
Dtool_funcToMethod(removeChildren, NodePath) Dtool_funcToMethod(removeChildren, NodePath)
del removeChildren del removeChildren
##################################################################### #####################################################################
@ -64,7 +64,7 @@ del toggleVis
def showSiblings(self): def showSiblings(self):
"""Show all the siblings of a node path""" """Show all the siblings of a node path"""
for sib in self.getParent().getChildrenAsList(): for sib in self.getParent().getChildren():
if sib.node() != self.node(): if sib.node() != self.node():
sib.show() sib.show()
Dtool_funcToMethod(showSiblings, NodePath) Dtool_funcToMethod(showSiblings, NodePath)
@ -73,7 +73,7 @@ del showSiblings
def hideSiblings(self): def hideSiblings(self):
"""Hide all the siblings of a node path""" """Hide all the siblings of a node path"""
for sib in self.getParent().getChildrenAsList(): for sib in self.getParent().getChildren():
if sib.node() != self.node(): if sib.node() != self.node():
sib.hide() sib.hide()
Dtool_funcToMethod(hideSiblings, NodePath) Dtool_funcToMethod(hideSiblings, NodePath)
@ -83,7 +83,7 @@ del hideSiblings
def showAllDescendants(self): def showAllDescendants(self):
"""Show the node path and all its children""" """Show the node path and all its children"""
self.show() self.show()
for child in self.getChildrenAsList(): for child in self.getChildren():
child.showAllDescendants() child.showAllDescendants()
Dtool_funcToMethod(showAllDescendants, NodePath) Dtool_funcToMethod(showAllDescendants, NodePath)
del showAllDescendants del showAllDescendants
@ -123,7 +123,7 @@ del lsNames
##################################################################### #####################################################################
def lsNamesRecurse(self, indentString=' '): def lsNamesRecurse(self, indentString=' '):
"""Walk down a tree and print out the path""" """Walk down a tree and print out the path"""
for nodePath in self.getChildrenAsList(): for nodePath in self.getChildren():
type = nodePath.node().getType().getName() type = nodePath.node().getType().getName()
name = nodePath.getName() name = nodePath.getName()
print indentString + type + " " + name print indentString + type + " " + name
@ -147,13 +147,10 @@ del reverseLsNames
##################################################################### #####################################################################
def getAncestry(self): def getAncestry(self):
"""Get a list of a node path's ancestors""" """Get a list of a node path's ancestors"""
node = self.node() print "NodePath.getAncestry() is deprecated. Use getAncestors() instead."""
if (self.hasParent()): ancestors = list(self.getAncestors())
ancestry = self.getParent().getAncestry() ancestors.reverse()
ancestry.append(self) return ancestors
return ancestry
else:
return [self]
Dtool_funcToMethod(getAncestry, NodePath) Dtool_funcToMethod(getAncestry, NodePath)
del getAncestry del getAncestry
@ -337,7 +334,7 @@ def printTransform(self, other = None, sd = 2, fRecursive = 0):
outputString = '%s.setScale(%s, %s, %s)' % (name, fmtStr, fmtStr, fmtStr) outputString = '%s.setScale(%s, %s, %s)' % (name, fmtStr, fmtStr, fmtStr)
print outputString % (scale[0], scale[1], scale[2]) print outputString % (scale[0], scale[1], scale[2])
if fRecursive: if fRecursive:
for child in self.getChildrenAsList(): for child in self.getChildren():
child.printTransform(other, sd, fRecursive) child.printTransform(other, sd, fRecursive)
Dtool_funcToMethod(printTransform, NodePath) Dtool_funcToMethod(printTransform, NodePath)
@ -1341,14 +1338,7 @@ Dtool_funcToMethod(flattenMultitex, NodePath)
del flattenMultitex del flattenMultitex
##################################################################### #####################################################################
def getNumDescendants(self): def getNumDescendants(self):
num = 0 return len(self.findAllMatches('**')) - 1
stack = [self]
while len(stack):
np = stack.pop()
numChildren = np.getNumChildren()
num += numChildren
stack.extend(np.getChildrenAsList())
return num
Dtool_funcToMethod(getNumDescendants, NodePath) Dtool_funcToMethod(getNumDescendants, NodePath)
del getNumDescendants del getNumDescendants
##################################################################### #####################################################################
@ -1358,10 +1348,10 @@ def removeNonCollisions(self):
while len(stack): while len(stack):
np = stack.pop() np = stack.pop()
# if there are no CollisionNodes under this node, remove it # if there are no CollisionNodes under this node, remove it
if np.findAllMatches('**/+CollisionNode').getNumPaths() == 0: if np.find('**/+CollisionNode').isEmpty():
np.detachNode() np.detachNode()
else: else:
stack.extend(np.getChildrenAsList()) stack.extend(np.getChildren())
Dtool_funcToMethod(removeNonCollisions, NodePath) Dtool_funcToMethod(removeNonCollisions, NodePath)
del removeNonCollisions del removeNonCollisions
##################################################################### #####################################################################
@ -1373,7 +1363,7 @@ def subdivideCollisions(self, numSolidsInLeaves):
TODO: better splitting logic at each level of the tree wrt spatial separation TODO: better splitting logic at each level of the tree wrt spatial separation
and cost of bounding volume tests vs. cost of collision solid tests and cost of bounding volume tests vs. cost of collision solid tests
""" """
colNps = self.findAllMatches('**/+CollisionNode').asList() colNps = self.findAllMatches('**/+CollisionNode')
for colNp in colNps: for colNp in colNps:
node = colNp.node() node = colNp.node()
numSolids = node.getNumSolids() numSolids = node.getNumSolids()

View File

@ -19,6 +19,7 @@ def asTuple(self):
""" """
Returns the vector as a tuple. Returns the vector as a tuple.
""" """
return (self[0], self[1], self[2]) print "Warning: VBase3.asTuple() is no longer needed and deprecated. Use the vector directly instead."
return tuple(self)
Dtool_funcToMethod(asTuple, VBase3) Dtool_funcToMethod(asTuple, VBase3)
del asTuple del asTuple

View File

@ -19,6 +19,8 @@ def asTuple(self):
""" """
Returns the vector as a tuple. Returns the vector as a tuple.
""" """
return (self[0], self[1], self[2], self[3]) print "Warning: VBase4.asTuple() is no longer needed and deprecated. Use the vector directly instead."
return tuple(self)
Dtool_funcToMethod(asTuple, VBase4) Dtool_funcToMethod(asTuple, VBase4)
del asTuple del asTuple

View File

@ -1042,7 +1042,7 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
'gui item %s not in base.guiItems' % 'gui item %s not in base.guiItems' %
self.guiId) self.guiId)
# Destroy children # Destroy children
for child in self.getChildrenAsList(): for child in self.getChildren():
childGui = self.guiDict.get(child.getName()) childGui = self.guiDict.get(child.getName())
if childGui: if childGui:
childGui.destroy() childGui.destroy()
@ -1071,7 +1071,7 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
print space + 'Pos: ' + self.getPos().pPrintValues() print space + 'Pos: ' + self.getPos().pPrintValues()
print space + 'Scale: ' + self.getScale().pPrintValues() print space + 'Scale: ' + self.getScale().pPrintValues()
# Print out children info # Print out children info
for child in self.getChildrenAsList(): for child in self.getChildren():
messenger.send(DGG.PRINT + child.getName(), [indent + 2]) messenger.send(DGG.PRINT + child.getName(), [indent + 2])
def copyOptions(self, other): def copyOptions(self, other):

View File

@ -90,7 +90,7 @@ class DirectScrolledFrame(DirectFrame):
def destroy(self): def destroy(self):
# Destroy children of the canvas # Destroy children of the canvas
for child in self.canvas.getChildrenAsList(): for child in self.canvas.getChildren():
childGui = self.guiDict.get(child.getName()) childGui = self.guiDict.get(child.getName())
if childGui: if childGui:
childGui.destroy() childGui.destroy()

View File

@ -2351,7 +2351,7 @@ class LevelEditor(NodePath, DirectObject):
if DNAClassEqual(dnaNode, DNA_VIS_GROUP): if DNAClassEqual(dnaNode, DNA_VIS_GROUP):
return [[nodePath, dnaNode]] return [[nodePath, dnaNode]]
childVisGroups = [] childVisGroups = []
children = nodePath.getChildrenAsList() children = nodePath.getChildren()
for child in children: for child in children:
childVisGroups = (childVisGroups + self.getDNAVisGroups(child)) childVisGroups = (childVisGroups + self.getDNAVisGroups(child))
return childVisGroups return childVisGroups
@ -3492,14 +3492,14 @@ class LevelEditor(NodePath, DirectObject):
if (DNAClassEqual(dnaNode, DNA_FLAT_BUILDING) or if (DNAClassEqual(dnaNode, DNA_FLAT_BUILDING) or
DNAClassEqual(dnaNode, DNA_LANDMARK_BUILDING)): DNAClassEqual(dnaNode, DNA_LANDMARK_BUILDING)):
base.direct.reparent(nodePath, fWrt = 1) base.direct.reparent(nodePath, fWrt = 1)
children = nodePath.getChildrenAsList() children = nodePath.getChildren()
for child in children: for child in children:
self.reparentStreetBuildings(child) self.reparentStreetBuildings(child)
def consolidateStreetBuildings(self): def consolidateStreetBuildings(self):
# First put everything under the ATR group so the leftover # First put everything under the ATR group so the leftover
# can be easily deleted # can be easily deleted
originalChildren = self.NPToplevel.getChildrenAsList() originalChildren = self.NPToplevel.getChildren()
self.addGroup(self.NPToplevel) self.addGroup(self.NPToplevel)
atrGroup = self.NPParent atrGroup = self.NPParent
atrGroup.setName('ATR') atrGroup.setName('ATR')
@ -3543,7 +3543,7 @@ class LevelEditor(NodePath, DirectObject):
self.updateBarricadeDict(side, int(origBarricadeNum), sequenceNum) self.updateBarricadeDict(side, int(origBarricadeNum), sequenceNum)
def adjustPropChildren(self, nodePath, maxPropOffset = -4): def adjustPropChildren(self, nodePath, maxPropOffset = -4):
for np in nodePath.getChildrenAsList(): for np in nodePath.getChildren():
dnaNode = self.findDNANode(np) dnaNode = self.findDNANode(np)
if dnaNode: if dnaNode:
if DNAClassEqual(dnaNode, DNA_PROP): if DNAClassEqual(dnaNode, DNA_PROP):
@ -3581,7 +3581,7 @@ class LevelEditor(NodePath, DirectObject):
def makeLongStreet(self): def makeLongStreet(self):
bldgGroup = self.consolidateStreetBuildings() bldgGroup = self.consolidateStreetBuildings()
bldgs = bldgGroup.getChildrenAsList() bldgs = bldgGroup.getChildren()
numBldgs = len(bldgs) numBldgs = len(bldgs)
streetLength = self.calcLongStreetLength(bldgs)/2.0 streetLength = self.calcLongStreetLength(bldgs)/2.0
ref = None ref = None
@ -3615,19 +3615,19 @@ class LevelEditor(NodePath, DirectObject):
parent = self.panel.component('hull')) parent = self.panel.component('hull'))
if streetCurveFilename: if streetCurveFilename:
modelFile = loader.loadModel(Filename.fromOsSpecific(streetCurveFilename)) modelFile = loader.loadModel(Filename.fromOsSpecific(streetCurveFilename))
#curves = modelFile.findAllMatches('**/+ClassicNurbsCurve').asList() #curves = modelFile.findAllMatches('**/+ClassicNurbsCurve')
curves = {'inner':[], 'outer':[],'innersidest':[], 'outersidest':[]} curves = {'inner':[], 'outer':[],'innersidest':[], 'outersidest':[]}
curvesInner = modelFile.findAllMatches('**/*curve_inner*').asList() curvesInner = modelFile.findAllMatches('**/*curve_inner*')
print("-------------- curvesInner-----------------") print("-------------- curvesInner-----------------")
print curvesInner print curvesInner
curvesOuter = modelFile.findAllMatches('**/*curve_outer*').asList() curvesOuter = modelFile.findAllMatches('**/*curve_outer*')
print("---------------- curvesOuter---------------") print("---------------- curvesOuter---------------")
print curvesOuter print curvesOuter
curveInnerSideSts = modelFile.findAllMatches('**/*curveside_inner*').asList() curveInnerSideSts = modelFile.findAllMatches('**/*curveside_inner*')
print("--------- curveInnerSideSts----------") print("--------- curveInnerSideSts----------")
print curveInnerSideSts print curveInnerSideSts
curveOuterSideSts = modelFile.findAllMatches('**/*curveside_outer*').asList() curveOuterSideSts = modelFile.findAllMatches('**/*curveside_outer*')
print("----------- curveOuterSideSits ----------") print("----------- curveOuterSideSits ----------")
print curveOuterSideSts print curveOuterSideSts
@ -3758,7 +3758,7 @@ class LevelEditor(NodePath, DirectObject):
base.direct.grid.fHprSnap = 0 base.direct.grid.fHprSnap = 0
self.panel.fPlaneSnap.set(0) self.panel.fPlaneSnap.set(0)
bldgGroup = self.consolidateStreetBuildings() bldgGroup = self.consolidateStreetBuildings()
bldgs = bldgGroup.getChildrenAsList() bldgs = bldgGroup.getChildren()
# streetWidth puts buildings on the edge of the street, not the middle # streetWidth puts buildings on the edge of the street, not the middle
currPoint = Point3(0) currPoint = Point3(0)
@ -3924,7 +3924,7 @@ class LevelEditor(NodePath, DirectObject):
base.direct.grid.fHprSnap = 0 base.direct.grid.fHprSnap = 0
self.panel.fPlaneSnap.set(0) self.panel.fPlaneSnap.set(0)
bldgGroup = self.consolidateStreetBuildings() bldgGroup = self.consolidateStreetBuildings()
bldgs = bldgGroup.getChildrenAsList() bldgs = bldgGroup.getChildren()
# streetWidth puts buildings on the edge of the street, not the middle # streetWidth puts buildings on the edge of the street, not the middle
currPoint = Point3(0) currPoint = Point3(0)

View File

@ -132,7 +132,7 @@ class ParticleEffect(NodePath):
# Remove all forces from the particles # Remove all forces from the particles
for fg in self.forceGroupDict.values(): for fg in self.forceGroupDict.values():
for f in fg.asList(): for f in fg:
particles.removeForce(f) particles.removeForce(f)
def removeAllParticles(self): def removeAllParticles(self):

View File

@ -680,7 +680,7 @@ class MopathRecorder(AppShell, DirectObject):
def getChildIds(self, nodePath): def getChildIds(self, nodePath):
ids = [nodePath.id()] ids = [nodePath.id()]
kids = nodePath.getChildrenAsList() kids = nodePath.getChildren()
for kid in kids: for kid in kids:
ids += self.getChildIds(kid) ids += self.getChildIds(kid)
return ids return ids

View File

@ -181,7 +181,7 @@ class MemoryExplorer(Pmw.MegaWidget, DirectObject):
self.rootItem.getVertexBytes()) self.rootItem.getVertexBytes())
btIndex = 1 btIndex = 1
for item in self.rootItem.getChildrenAsList(): for item in self.rootItem.getChildren():
self.buttons[btIndex]['width'] = self.getBTWidth(item.getVertexBytes(), self.buttons[btIndex]['width'] = self.getBTWidth(item.getVertexBytes(),
self.rootItem.getVertexBytes()) self.rootItem.getVertexBytes())
btIndex += 1 btIndex += 1
@ -222,7 +222,7 @@ class MemoryExplorer(Pmw.MegaWidget, DirectObject):
else: else:
self.addSelfCtrl(item, item.getVertexBytes()) self.addSelfCtrl(item, item.getVertexBytes())
for child in item.getChildrenAsList(): for child in item.getChildren():
self.addChildCtrl(child, item.getVertexBytes()) self.addChildCtrl(child, item.getVertexBytes())
self.setTitle(item.getPathName(), item.getVertexBytes()) self.setTitle(item.getPathName(), item.getVertexBytes())
@ -238,7 +238,7 @@ class MemoryExplorer(Pmw.MegaWidget, DirectObject):
self.buildList(self.render2dItem) self.buildList(self.render2dItem)
def buildList(self, parentItem): def buildList(self, parentItem):
for nodePath in parentItem.nodePath.getChildrenAsList(): for nodePath in parentItem.nodePath.getChildren():
item = MemoryExplorerItem(parentItem, nodePath) item = MemoryExplorerItem(parentItem, nodePath)
parentItem.addChild(item) parentItem.addChild(item)
self.buildList(item) self.buildList(item)

View File

@ -176,7 +176,7 @@ class SceneGraphExplorerItem(TreeItem):
def GetSubList(self): def GetSubList(self):
sublist = [] sublist = []
for nodePath in self.nodePath.getChildrenAsList(): for nodePath in self.nodePath.getChildren():
item = SceneGraphExplorerItem(nodePath, self.isItemEditable) item = SceneGraphExplorerItem(nodePath, self.isItemEditable)
sublist.append(item) sublist.append(item)
return sublist return sublist