home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 July / Chip_1997-07_cd.bin / tema / mattes / ip / ip30 / data.1 / FLIPOLY.WBS < prev    next >
Text File  |  1996-09-21  |  4KB  |  114 lines

  1. ' ******************************************************************************
  2. ' FLPPOLY.WBS - FLIPS ANY SELECTED POLYGON EITHER HORIZONTALLY OR VERTICALLY
  3. '    '
  4. ' Version 1.0, Created by Knowledge Revolution
  5. ' (C) Copyright Knowledge Revolution 1995   All Rights Reserved
  6. '
  7. ' ******************************************************************************
  8.  
  9. Dim Doc as WMDocument
  10.  
  11. Function CheckSelection as boolean
  12. '--------------------------------------------------------------------------------
  13. '    This function checks to make sure the user has selected at least one polygon.
  14. '    If at least one polygon has been selected, the function returns as TRUE.
  15. '--------------------------------------------------------------------------------
  16.  
  17.     Dim index as integer
  18.     Dim B1 as WMBody
  19.     Dim CS as Boolean
  20.  
  21.     CheckSelection = false
  22.     If Doc.selection.count > 0 then
  23.         For index = 1 to Doc.selection.count
  24.             If Doc.selection.item(index).kind = "body" then
  25.                 If Doc.body(Doc.selection.item(index).id).kind = "polygon" then
  26.                     CheckSelection = True
  27.                     index = Doc.selection.count
  28.                 End if
  29.             End if
  30.         Next index
  31.     End if
  32.  
  33. End function
  34.  
  35. Function FlipDirection as string
  36. '--------------------------------------------------------------------------------
  37. '    This function asks the user which direction to flip the polygon.  It returns
  38. '    Horizontal, Vertical, or Cancel.
  39. '--------------------------------------------------------------------------------
  40.  
  41.     r%=answerbox("Flip polygon horizontal or vertical?","Horizontal","Vertical","Cancel")
  42.  
  43.     Select Case R
  44.         Case 1
  45.             FlipDirection = "Horizontal"
  46.         Case 2
  47.             FlipDirection = "Vertical"
  48.         Case 3
  49.             FlipDirection = "Cancel"
  50.     End Select
  51.  
  52. End Function
  53.  
  54. Sub FlipBodies (Direction as string)
  55. '--------------------------------------------------------------------------------
  56. '    This subroutine loops through all selected Working Model objects and flips
  57. '    all polygons it finds either horizontally or vertically.  This is done by
  58. '    looping through all the polygons vertices and changing the sign of the X field
  59. '    when flipping horizontally, and the Y field when flipping vertically.
  60. '--------------------------------------------------------------------------------
  61.  
  62.     Dim B1 as WMBody
  63.     Dim index1 as integer
  64.     Dim index2 as integer
  65.     Dim x as double
  66.     Dim y as double
  67.     Dim tempheight as WMCell
  68.  
  69.     If Direction <> "Cancel" then
  70.         For index1 = 1 to Doc.selection.count
  71.             If doc.selection.item(index1).kind = "body" then
  72.                 Set B1 = Doc.body(Doc.selection.item(index1).id)
  73.                 
  74.                 If B1.kind = "polygon" then
  75.  
  76.                     ' Curved bodies have vertices in polar coordinates, 
  77.                     ' so we need to make the body non-curved for the duration
  78.                     wasCurved = B1.Curved
  79.                     B1.Curved = FALSE
  80.  
  81.                     For index2 = 1 to B1.Vertexcount
  82.                         B1.GetVertex index2, x, y
  83.                         If Direction = "Horizontal" then
  84.                             B1.AddVertex index2, -x, y
  85.                         Elseif Direction = "Vertical" then
  86.                             B1.AddVertex index2, x, -y
  87.                         End if
  88.                         B1.DeleteVertex index2+1
  89.                     Next index2
  90.  
  91.                     B1.Curved = wasCurved
  92.  
  93.                 End if
  94.             End if
  95.         Next index1
  96.     End if
  97. End Sub
  98.  
  99. Sub Main()
  100. '--------------------------------------------------------------------------------
  101. '    The main subroutine first makes calls to check what WM objects the user has
  102. '    selected, displaying an error message if no polygons are selected.  It then
  103. '    calls the routine that flips all polygons.
  104. '--------------------------------------------------------------------------------
  105.  
  106.     Set Doc = WM.ActiveDocument
  107.     
  108.     If not CheckSelection then
  109.         msgbox "Incorrect selection.  To use the Mirror tool at least one polygon must be selected."
  110.     Else
  111.         FlipBodies(FlipDirection)
  112.     End if
  113.  
  114. End Sub