home *** CD-ROM | disk | FTP | other *** search
/ BUG 11 / BUGCD1998_02.ISO / aplic / turbocad / tcw.z / lincopy.bas < prev    next >
BASIC Source File  |  1997-05-05  |  3KB  |  146 lines

  1. 'Sample that shows how to do a linear copy of selected graphics
  2. '
  3. ' Author    : Tamara Cartwright
  4. ' Date        : 01/26/97
  5.  
  6.  
  7. ' Misc
  8. Global Const NULL     = 0
  9.  
  10. dim v1 as long
  11. dim v2 as long
  12. dim copies as long
  13. dim hActive as long
  14.  
  15. sub Main
  16.  
  17.     'Get drawing handle
  18.     hActive = TCWDrawingActive()
  19.  
  20.     if (hActive = NULL) then
  21.         MsgBox "Need active drawing."
  22.         'Terminate Program
  23.         Stop
  24.     end if
  25.  
  26.     'Get number of copies from the user
  27.     copies = Val(InputBox$("Input number of copies to make"))
  28.  
  29.     'create a vertex
  30.     v1 = TCWVertexCreate(0.0, 0.0, 0.0)
  31.  
  32.     if (v1 = NULL) then
  33.         MsgBox "Cannot create vertex"
  34.         Stop
  35.     end if
  36.  
  37.     v2 = TCWVertexCreate(0.0, 0.0, 0.0)
  38.     if (V2 = NULL) then
  39.         MsgBox "Cannot create vertex"
  40.         Stop
  41.     end if
  42.  
  43.     'click on screen to get points
  44.     result = TCWGetPoint(v1,"Get first point", NULL, NULL, 0, 1)
  45.     result = TCWGetPoint(v2,"Get second point", NULL, NULL, 0, 1)
  46.  
  47.     If copies = 0 Then
  48.         MsgBox "No copies desired, finished!"        
  49.         Stop
  50.     end if
  51.  
  52.     'Go and copy away
  53.     DoCopy
  54.  
  55.     'Need to delete the two vertex objects that we created above
  56.     TCWVertexDispose v1
  57.     TCWVertexDispose v2
  58.  
  59. End Sub
  60.  
  61. Sub DoCopy ()
  62.     Dim gCount As Long
  63.     Dim sCount As Long
  64.     Dim ga As Long
  65.     dim g as Long
  66.  
  67.     dim i as integer
  68.     dim j as integer
  69.     dim result as long
  70.  
  71.     dim dx as double
  72.     dim dy as double
  73.     dim dz as double
  74.  
  75.  
  76.     'Get selection count to see that we have something selected
  77.     sCount = TCWSelectionCount
  78.  
  79.     if (sCount = NULL) then
  80.         MsgBox "Program requires at least one graphic to be selected."
  81.         'Terminate the program
  82.         Stop
  83.     end if
  84.     
  85.     'Calculate the delta between the points for the copy
  86.     dx = (TCWGetX(v2) - TCWGetX(v1))
  87.     dy = (TCWGetY(v2) - TCWGetY(v1))
  88.     dz = (TCWGetZ(v2) - TCWGetZ(v1))
  89.  
  90.     for i = 1 to copies
  91.         'Get total graphics in drawing
  92.         gCount = TCWGraphicCount(hActive)
  93.  
  94.         'loop through selected graphics making copies
  95.         for j = 0 to sCount-1
  96.             ga = TCWSelectionAt(j)
  97.             if (ga = NULL) then
  98.                 MsgBox "Lost Selection?"
  99.                 Stop
  100.             end if
  101.  
  102.             'make copy of selected graphic
  103.             g = TCWGraphicCopy(ga)
  104.  
  105.             'add copy to the drawing
  106.             result = TCWGraphicAppend(NULL, g)
  107.         next j
  108.  
  109.         'Deselect the original graphics
  110.          TCWDeSelectAll
  111.         
  112.         'Select the newly added graphics that we just copied
  113.         'they will be at gCount+1...
  114.         for j = 0 to sCount-1
  115.             ga = TCWGraphicAt(hActive, gCount+j)
  116.  
  117.             if (ga = NULL) then
  118.                 MsgBox "Cannot find new copied graphic"
  119.                 stop
  120.             end if
  121.  
  122.             'select the graphic
  123.             result = TCWGraphicPropertySet(ga, "Selected", 1)
  124.         next j
  125.  
  126.         'move the selection on the vector
  127.         TCWSelectionMove dx, dy, dz
  128.  
  129.         'Select the newly added graphics that we just copied again,
  130.         'TCWSelectionMove loses the selection state
  131.         for j = 0 to sCount-1
  132.             ga = TCWGraphicAt(hActive, gCount+j)
  133.             if (ga = NULL) then
  134.                 MsgBox "Lost selection"
  135.                 stop
  136.             end if
  137.  
  138.             'set selected
  139.             result = TCWGraphicPropertySet(ga, "Selected", 1)
  140.         next j
  141.  
  142.     next i
  143.  
  144. End Sub
  145.  
  146.