' TITLE:   		View.ActiveThemeSkeleton
' PURPOSE: 	Creates a skeleton shape graphic for each of the active  
'          		theme's selected shapes based upon the ratio and buffer 
'          		step distance specified in the enumeration section.
'
' AUTHOR: 	Brooks E. Kelley, 3DI TerraLogic Software, LLC.
' HISTORY:  	11/08/97, BEK - original coding
'
' NOTES:   	Use a larger buffer step denominator for more complex 
'          		shapes with lengthy perimeters.
'
' INPUTS: 	none
' OUTPUTS: 	one graphic per selected shape
' ====================================================================

' enumerations
theRatio 		           = 0.25 ' i.e 25%
theBufferStepDenominator = 1000 ' 1000, 5000, 10000

av.ShowMsg("Calculating" ++ (100 * theRatio).AsString + "% skeleton...")

' get required objects
theView = av.GetActiveDoc

theTheme               	          = theView.GetActiveThemes.Get(0)
theThemeFTab                  = theTheme.GetFTab
theThemeFTabShapeField = theThemeFTab.FindField("Shape")

' cycle through each of the selected record's shapes
for each rec in theThemeFTab.GetSelection

  thisShape                 = theThemeFTab.ReturnValue(theThemeFTabShapeField, rec).AsPolygon
  thisShapeArea         = thisShape.ReturnArea
  thisShapePerimeter = thisShape.ReturnLength    
    
  theBufferDist	     = -1 * (thisShapePerimeter / theBufferStepDenominator)
  theBufferStepDist = theBufferDist
    
  thatShape        = thisShape.ReturnBuffered(theBufferDist)
  thatShapeArea = thatShape.ReturnArea

  while (theRatio < (thatShapeArea / thisShapeArea))
  
    thatShape        = thisShape.ReturnBuffered(theBufferDist)
    thatShapeArea = thatShape.ReturnArea
    
    theBufferDist = theBufferDist + theBufferStepDist
  
  end

  ' project the shape
  thatProjectedShape = thatShape.ReturnProjected(theView.GetProjection)

  ' display it as a graphic
  thatShapeGraphic = GraphicShape.Make(thatProjectedShape)
  theView.GetGraphics.Add(thatShapeGraphic)
  theView.Invalidate
  
  ' report the skeleton ratios
  theDesignRatioStr = (100 * theRatio).SetFormat("dd.ddd").AsString
  theActualRatioStr  = (100 * (thatShape.ReturnArea / thisShapeArea)).SetFormat("dd.ddd").AsString
  
  theMsg = "Design:" + TAB + theDesignRatioStr + "%" + NL + 
                  "Actual:" + TAB + TAB + theActualRatioStr + "%"
  MsgBox.Info(theMsg, "Skeleton Ratios")

end 

av.ClearMsg

return TRUE


