def __init__(self, theFig, theLineNum): super(SVGTreeNodeMain, self).__init__(theFig, theLineNum) # PpTokenCount object for my children only, set on finalise self._tokenCounterChildren = PpTokenCount.PpTokenCount() ## PpTokenCount object for me and my my children , set on finalise #self._tokenCounterTotal = PpTokenCount.PpTokenCount() # Total number of significant tokens in all children self._numChildSigTokens = 0 # Mandatory override of the bounding box object self._bb = PlotNode.PlotNodeBboxBoxy() if theFig is None: # Root node, children only self._dataMap = None else: self._dataMap = {} # Take a copy of the include graph data self._dataMap['numToks'] = theFig.numTokens self._dataMap['condComp'] = theFig.condComp # A PpTokenCount.PpTokenCount() object for this node only. self._dataMap['tokenCntr'] = theFig.tokenCounter self._dataMap['findLogic'] = theFig.findLogic # A list of tuples of (Coord.Pt, Cooord.Box, attributes) that are to be # written last as <rect class="invis" ... self._triggerS = [] # We have two passes self._numPassesToPlotSelf = 2
def testBbSpaceChildren(self): """Tests PlotNode() set/get bbSpaceChildren.""" myObj = PlotNode.PlotNodeBbox() #print '\nTRACE myObj', myObj myObj.bbSpaceChildren = Coord.Dim(42, 'px') #print '\nTRACE myObj', myObj self.assertEqual(myObj.bbSpaceChildren, Coord.Dim(42, 'px'))
def testCentre_02(self): """Tests PlotNode() get the centre point.""" myObj = PlotNode.PlotNodeBbox() myObj.width = Coord.Dim(3, 'in') self.assertEqual(myObj.width, Coord.Dim(3, 'in')) myObj.depth = Coord.Dim(1, 'in') self.assertEqual(myObj.depth, Coord.Dim(1, 'in')) myPad = Coord.Pad( Coord.Dim(0.1, 'in'), # prev Coord.Dim(0.3, 'in'), # next Coord.Dim(0.5, 'in'), # parent Coord.Dim(0.7, 'in'), # child ) myObj.bbSelfPadding = myPad myObj.bbSpaceChildren = Coord.Dim(0.9, 'in') self.assertEqual( myObj.plotPointCentre( Coord.Pt( Coord.Dim(0.0, 'in'), Coord.Dim(0.0, 'in'), ), ), Coord.Pt( Coord.Dim(1.6, 'in'), Coord.Dim(1.0, 'in'), ), )
def testWidthDepth(self): """Tests PlotNode() set/get width and depth.""" myObj = PlotNode.PlotNodeBbox() myObj.width = Coord.Dim(42, 'in') myObj.depth = Coord.Dim(1, 'in') self.assertEqual(myObj.width, Coord.Dim(42, 'in')) self.assertEqual(myObj.depth, Coord.Dim(1, 'in'))
def testBbSpacePaddingNullNode(self): """Tests PlotNode() set/get bbSpacePadding on a null node.""" myObj = PlotNode.PlotNodeBbox() myObj.width = None myObj.depth = None myPad = Coord.Pad( Coord.Dim(1, 'px'), # prev Coord.Dim(2, 'px'), # next Coord.Dim(3, 'px'), # parent Coord.Dim(4, 'px'), # child ) myObj.bbSelfPadding = myPad self.assertEqual( myObj.bbSelfPadding, Coord.Pad( Coord.Dim(1, 'px'), Coord.Dim(2, 'px'), Coord.Dim(3, 'px'), Coord.Dim(4, 'px'), )) self.assertEqual( myObj.bbSelfWidth, Coord.Dim(0, None), ) self.assertEqual( myObj.bbSelfDepth, Coord.Dim(0, None), )
def setUp(self): self._pnbcObj = PlotNode.PlotNodeBboxBoxy() self._pnbcObj.width = Coord.Dim(12, 'mm') self._pnbcObj.depth = Coord.Dim(8, 'mm') #print '\nTRACE self._pnbcObj', self._pnbcObj self._pnbcObj.bbSelfPadding = Coord.Pad( Coord.Dim(1, 'mm'), # prev Coord.Dim(3, 'mm'), # next Coord.Dim(5, 'mm'), # parent Coord.Dim(7, 'mm'), # child ) self._pnbcObj.bbSpaceChildren = Coord.Dim(16, 'mm') self.assertEqual(True, self._pnbcObj.bbChildrenWidth is None) self.assertEqual(True, self._pnbcObj.bbChildrenDepth is None) self.assertEqual(0, self._pnbcObj.numChildren) self._pnbcObj.extendChildBbox( Coord.Box( Coord.Dim(15, 'mm'), Coord.Dim(7, 'mm'), )) # Child box now w:15, d:7 self.assertEqual(1, self._pnbcObj.numChildren) self.assertEqual(self._pnbcObj.bbChildrenWidth, Coord.Dim(15, 'mm')) self.assertEqual(self._pnbcObj.bbChildrenDepth, Coord.Dim(7, 'mm')) self._pnbcObj.extendChildBbox( Coord.Box( Coord.Dim(31, 'mm'), Coord.Dim(29, 'mm'), )) # Child box now w:15+31=46, d:max(7,29)=29 self.assertEqual(2, self._pnbcObj.numChildren) self.assertEqual(self._pnbcObj.bbChildrenWidth, Coord.Dim(46, 'mm')) self.assertEqual(self._pnbcObj.bbChildrenDepth, Coord.Dim(29, 'mm')) self._pnbcObj.extendChildBbox( Coord.Box( Coord.Dim(11, 'mm'), Coord.Dim(9, 'mm'), )) # Child box now w:46+11=57, d:max(29,9)=29 self.assertEqual(3, self._pnbcObj.numChildren) self.assertEqual(self._pnbcObj.bbChildrenWidth, Coord.Dim(57, 'mm')) self.assertEqual(self._pnbcObj.bbChildrenDepth, Coord.Dim(29, 'mm')) # Logical datum self._logicalDatum = Coord.Pt( Coord.Dim(21, 'mm'), Coord.Dim(180, 'mm'), )
def testSigma_03(self): """Tests PlotNode() get sigma width and depth (parent is null node).""" myObj = PlotNode.PlotNodeBbox() myObj.width = None self.assertEqual(myObj.width, None) myObj.depth = None self.assertEqual(myObj.depth, None) myPad = Coord.Pad( Coord.Dim(0.5, 'in'), # prev Coord.Dim(0.5, 'in'), # next Coord.Dim(0.5, 'in'), # parent Coord.Dim(0.5, 'in'), # child ) myObj.bbSelfPadding = myPad myObj.bbSpaceChildren = Coord.Dim(0.5, 'in') self.assertEqual(myObj.bbSpaceChildren, Coord.Dim(0.5, 'in')) myObj.bbChildren = Coord.Box( Coord.Dim(4, 'in'), Coord.Dim(2.5, 'in'), ) self.assertEqual( myObj.bbChildrenWidth, Coord.Dim(4, 'in'), ) self.assertEqual( myObj.bbChildrenDepth, Coord.Dim(2.5, 'in'), ) self.assertEqual(myObj.bbChildren, Coord.Box( Coord.Dim(4, 'in'), Coord.Dim(2.5, 'in'), )) self.assertEqual( myObj.bbSigmaWidth, Coord.Dim(4.0, 'in'), ) self.assertEqual( myObj.bbSigmaDepth, Coord.Dim(2.5, 'in'), ) self.assertEqual( myObj.bbSigma, Coord.Box( Coord.Dim(4.0, 'in'), Coord.Dim(2.5, 'in'), ))
def testBbSpacePadding(self): """Tests PlotNode() set/get bbSpacePadding.""" myObj = PlotNode.PlotNodeBbox() myObj.width = Coord.Dim(12, 'px') myObj.depth = Coord.Dim(6, 'px') #print '\nTRACE myObj', myObj myPad = Coord.Pad( Coord.Dim(1, 'px'), # prev Coord.Dim(2, 'px'), # next Coord.Dim(3, 'px'), # parent Coord.Dim(4, 'px'), # child ) #print '\nTRACE myPad setting', myPad myObj.bbSelfPadding = myPad #print '\nTRACE myObj setting done', myObj a = myObj.bbSelfPadding self.assertEqual( myObj.bbSelfPadding, Coord.Pad( Coord.Dim(1, 'px'), Coord.Dim(2, 'px'), Coord.Dim(3, 'px'), Coord.Dim(4, 'px'), )) #print '\nTRACE myObj', myObj self.assertEqual( myObj.bbSelfWidth, # 1 + 12 + 2 = 15 Coord.Dim(15, 'px'), ) self.assertEqual( myObj.bbSelfDepth, # 3 + 6 + 4 Coord.Dim(13, 'px'), ) #print #print str(myObj) self.assertEqual( str(myObj), """|.......PlotNode: w=Dim(12px), d=Dim(6px) |bbSpaceChildren: None |..bbSelfPadding: Pad(prev=Dim(1px), next=Dim(2px), parent=Dim(3px), child=Dim(4px)) |.....bbChildren: None |........bbSigma: Box(width=Dim(15px), depth=Dim(13px))""", )
def setUp(self): self._pnbcObj = PlotNode.PlotNodeBboxRoundy() self._pnbcObj.width = Coord.Dim(12, 'mm') self._pnbcObj.depth = Coord.Dim(8, 'mm') #print '\nTRACE self._pnbcObj', self._pnbcObj self._pnbcObj.bbSelfPadding = Coord.Pad( Coord.Dim(1, 'mm'), # prev Coord.Dim(3, 'mm'), # next Coord.Dim(5, 'mm'), # parent Coord.Dim(7, 'mm'), # child ) self._pnbcObj.bbSpaceChildren = Coord.Dim(16, 'mm') self.assertEqual(True, self._pnbcObj.bbChildrenWidth is None) self.assertEqual(True, self._pnbcObj.bbChildrenDepth is None) self.assertEqual(0, self._pnbcObj.numChildren) # Logical datum self._logicalDatum = Coord.Pt( Coord.Dim(21, 'mm'), Coord.Dim(180, 'mm'), )
def testBbChildren(self): """Tests PlotNode() set/get bbChildren.""" myObj = PlotNode.PlotNodeBbox() myObj.bbChildren = Coord.Box( Coord.Dim(1, 'px'), Coord.Dim(2, 'px'), ) self.assertEqual(myObj.bbChildren, Coord.Box( Coord.Dim(1, 'px'), Coord.Dim(2, 'px'), )) self.assertEqual( myObj.bbChildrenWidth, Coord.Dim(1, 'px'), ) self.assertEqual( myObj.bbChildrenDepth, Coord.Dim(2, 'px'), )
def testCtor(self): """Tests PlotNode() constructor empty.""" myObj = PlotNode.PlotNodeBbox() self.assertEqual(myObj.width, None) self.assertEqual(myObj.depth, None)
def testBbChildren_00(self): """TestPlotNodeBboxWithChildren.testBbChildren_00() - three children.""" myObj = PlotNode.PlotNodeBbox() myObj.width = Coord.Dim(12, 'mm') myObj.depth = Coord.Dim(8, 'mm') #print '\nTRACE myObj', myObj myObj.bbSelfPadding = Coord.Pad( Coord.Dim(1, 'mm'), # prev Coord.Dim(3, 'mm'), # next Coord.Dim(5, 'mm'), # parent Coord.Dim(7, 'mm'), # child ) myObj.bbSpaceChildren = Coord.Dim(16, 'mm') self.assertEqual(True, myObj.bbChildrenWidth is None) self.assertEqual(True, myObj.bbChildrenDepth is None) self.assertEqual(0, myObj.numChildren) myObj.extendChildBbox( Coord.Box( Coord.Dim(15, 'mm'), Coord.Dim(7, 'mm'), )) # Child box now w:15, d:7 self.assertEqual(1, myObj.numChildren) self.assertEqual(myObj.bbChildrenWidth, Coord.Dim(15, 'mm')) self.assertEqual(myObj.bbChildrenDepth, Coord.Dim(7, 'mm')) myObj.extendChildBbox( Coord.Box( Coord.Dim(31, 'mm'), Coord.Dim(29, 'mm'), )) # Child box now w:15+31=46, d:max(7,29)=29 self.assertEqual(2, myObj.numChildren) self.assertEqual(myObj.bbChildrenWidth, Coord.Dim(46, 'mm')) self.assertEqual(myObj.bbChildrenDepth, Coord.Dim(29, 'mm')) myObj.extendChildBbox( Coord.Box( Coord.Dim(11, 'mm'), Coord.Dim(9, 'mm'), )) # Child box now w:46+11=57, d:max(29,9)=29 self.assertEqual(3, myObj.numChildren) self.assertEqual(myObj.bbChildrenWidth, Coord.Dim(57, 'mm')) self.assertEqual(myObj.bbChildrenDepth, Coord.Dim(29, 'mm')) # bbSigma: # Width is 57mm as children are wider than me # Depth is 5 + 8 + 7 + 16 + 29 = 65mm #print #print 'myObj.bbSigma:', myObj.bbSigma self.assertEqual(myObj.bbSigma, Coord.Box( Coord.Dim(57, 'mm'), Coord.Dim(65, 'mm'), )) # Set my datum up myD = Coord.Pt( Coord.Dim(135, 'mm'), Coord.Dim(19, 'mm'), ) # x should be 135 + 0.5 * (57-(1+12+3) + 1) = 135 + 0.5 * 41 + 1 = 156.5 #print #print 'myObj.plotPointSelf:', myObj.plotPointSelf(myD) self.assertEqual( myObj.plotPointSelf(myD), Coord.Pt( Coord.Dim(156.5, 'mm'), Coord.Dim(24, 'mm'), )) #childBboxDatum #print #print 'myObj.childBboxDatum:', myObj.childBboxDatum(myD) self.assertEqual(myObj.childBboxDatum(myD), Coord.Pt( Coord.Dim(135, 'mm'), Coord.Dim(55, 'mm'), ))