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

  1. '******************************************************************
  2. '*                                                                *
  3. '*                      TurboCAD for Windows                      *
  4. '*                   Copyright (c) 1993 - 1996                    *
  5. '*             International Microcomputer Software, Inc.         *
  6. '*                            (IMSI)                              *
  7. '*                      All rights reserved.                      *
  8. '*                                                                *
  9. '******************************************************************
  10. '
  11. ' Filename: FNDINTRS.BAS
  12. '
  13. ' Author:    Pat Garner
  14. '
  15. ' Date:        1/14/97
  16. '
  17. '
  18. ' Scriptname:    Find Intersection
  19. '
  20. ' Version:        1.0
  21. '
  22. ' Description:    Script inserts a point graphic
  23. '                at the point where two non
  24. '                intersecting lines meet.
  25. '
  26. '
  27. '
  28. ' Revision History:
  29. '
  30. '              - 1.0    User must select two line graphics and then run script.
  31. '            Script will check that there are only two single lines
  32. '            currently part of the selection.
  33. '            Script then:    
  34. '                        1) gets handle of selected lines
  35. '                        2) gets handle of both vertices
  36. '                        3) gets all vertices coordinates
  37. '                        4) determine which end of lines is closer
  38. '                        5) calculate angle of lines
  39. '                        6) calcutate coordinates of intersect
  40. '                        7) insert point object at coordinates
  41. '
  42. '
  43. ' Tcadapi Functions used:
  44. '                            -
  45. '
  46. '
  47. ' TODO:
  48. '        - Put App in select dragger mode.
  49. '        - Prompt user for selection, first graphic
  50. '            - Msgbox
  51. '            - Status Bar Prompt
  52. '        - Wait until the user clicks
  53. '        - Check selected graphic to be sure it's a single line.(function?)
  54. '            - Get graphics handle
  55. '            - TCWVertexCount: more than two?
  56. '                - Yes    - Inform user that graphic is incorrect
  57. '                            - Ding, MsgBox "Please ...
  58. '                            - Ding, Status Bar Prompt "Wrong Graphic Type...
  59. '                        - Deselect graphic
  60. '                        - Return Null (zero)
  61. '                - No    - Return handle of graphic
  62. '        - Prompt user for selection, seccond graphic
  63. '            - Msgbox
  64. '            - Status Bar Prompt
  65. '        - Wait until the user clicks
  66. '        - Check selected graphic to be sure it's a single line.(function?)
  67. '            - Get graphics handle
  68. '            - TCWVertexCount: more than two?
  69. '                - Yes    - Inform user that graphic is incorrect
  70. '                            - Ding, MsgBox "Please ...
  71. '                            - Ding, Status Bar Prompt "Wrong Graphic Type...
  72. '                        - Deselect graphic
  73. '                        - Return Null (zero)
  74. '                - No    - Return handle of graphic
  75. '        - Query for vertex handles
  76. '        - Query for vertex coordinates
  77. '        - Determine closer end of lines
  78. '        - Calculate angle relative to that end
  79. '        - Calculate intersection of lines
  80. '        - Insert point object at intersection
  81. '        - Deselect two line graphics
  82. '        - TCWViewportRedraw
  83. '        - TCWViewportExtents
  84. '
  85. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  86.  
  87.  
  88.  
  89.  
  90. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  91. '
  92. ' * General Script Constants
  93. Global Const MAX_LINES = 2                    ' * Maximum number of line graphics 
  94. '
  95. Global Const MAX_VERTICES = 2                ' * Maximum number of vertices that a 
  96. '                                            ' * line graphic may contain.  
  97. '
  98. Global Const MAX_COORDS = 2                    ' * Maximum number of coordinate values
  99. '
  100. '
  101. ' * Error Reporting Constants
  102. '
  103. Global Const SILENT        = 1                    ' * Write err message info to error file
  104. Global Const MSG_BOX    = 2                    ' * Diplay err message info in a message box
  105. Global Const ALL        = 3                    ' * Use error both methods
  106. Global Const NONE        = 0                    ' * Don't do any error reporting
  107. Global Const ERR_FILE    = "C:\VIRPNT.ERR"    ' * Error file name
  108. Global Const SCRIPT_FILE = "VIRTPNT.BAS"    ' * Script file name
  109. Global Const ERR_SET    = 0                    ' * Error file does not exit if 0
  110. Global Const ERR_METHOD = MSG_BOX            ' * Set ERR_METHOD behavior
  111. Global Const ERR_TRUE    = 1                    ' * For ERR_STOP ending script execution
  112. Global Const ERR_FALSE    = 0                    ' * For ERR_STOP not ending script exection
  113. Global Const ERR_STOP    = ERR_TRUE            ' * Set ERR_STOP behavior
  114. '
  115. Global Const NULL        = 0
  116. Global Const MY_TRUE    = 1                    ' * For use with TCWPenDown
  117. Global Const MY_FALSE    = 0                    ' * For use with TCWPenDown
  118. Global Const GK_GRAPHIC    = &H0B                ' * TurboCAD graphic kind - generic graphic
  119. Global Const GK_ARC        = &H02                ' * TurboCAD graphic kind - arc graphic
  120. '
  121. '
  122. ' * This constant should be
  123. ' *  set to 1 to display the
  124. ' *  splash dialog or 0 to 
  125. ' *  not display it.
  126. Global Const DISPLAY_SPLASH = 1
  127. '
  128. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  129.  
  130.  
  131.  
  132.  
  133. ''SUBROUTINE: MAIN'''''''''''''''''''''''''''''''''''''''''''''
  134. '
  135. ' * Parameters: None
  136. ' * 
  137. ' *
  138. ' * Return Value: None
  139. ' * 
  140. ' *
  141. ' * Description:
  142. ' *
  143. ' *        Main is the conductor of the program
  144. ' *         and like a music conductor, tells
  145. ' *         the other parts of the program when
  146. ' *         it's time to do their thing.
  147. ' *
  148. ' *
  149. Sub main ()
  150.  
  151.     Dim hDrawing        As Long        ' * Handle to active drawing
  152.     Dim hG                As Long        ' * Handle to graphic
  153.     Dim counter            As Long        ' * Generic loop counter
  154.     Dim gNum            As Integer    ' * Number of graphics in the current drawing
  155.     Dim lNum            As Integer    ' * Number of line graphics in current drawing
  156.     Dim vNum            As Integer    ' * Number vertices to a graphic
  157.     Dim hGraphic(2)        As Long        ' * Array for line graphic's handles
  158.     Dim hVertex(2,2)    As Long        ' * Array for line graphic's vertices' handles
  159.     Dim vCoor(2,2,2)    As Double    ' * Array for vertices' coordinates
  160.     Dim vCoorPoint(2)    As Double    ' * Array for point object's coordinates
  161.  
  162.     
  163.     InitializeScript
  164.     
  165.     if DISPLAY_SPLASH = 1 then
  166.     
  167.         DoUI
  168.  
  169.     end if
  170.  
  171.  
  172.     hDrawing = TCWDrawingActive
  173.     gNum = TCWGraphicCount ( hDrawing )
  174.  
  175.  
  176.     if gNum < 2 then
  177.  
  178.         MsgBox "Must have at least two line graphics in current drawing!"
  179.         END
  180.  
  181.     end if
  182.  
  183.  
  184.     for counter = 0 to gNum-1
  185.  
  186.         hG = TCWGraphicAt ( hDrawing, ( counter ) )
  187.         vNum = TCWVertexCount ( hG )
  188.         if vNum = 2 then lNum = lNum + 1
  189.  
  190.     next
  191.  
  192.  
  193.  
  194.     if lNum < 2 then
  195.  
  196.         MsgBox "Must have at least two line graphics in current drawing!"
  197.         END
  198.  
  199.     end if
  200.  
  201.  
  202.     GetGraphicsHandles hGraphic
  203.     GetVertexHandles hGraphic, hVertex
  204.  
  205.     
  206.     GetVertexCoordinates hVertex, vCoor
  207.     CalculateIntersectCoordinates vCoor, vCoorPoint
  208.  
  209.     
  210.     InsertPointObject vCoorPoint, hDrawing
  211.  
  212. End Sub
  213. '
  214. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  215.  
  216.  
  217.  
  218.  
  219. ''SUBROUTINE: InitializeScript'''''''''''''''''''''''''''''''''
  220. '
  221. ' * Parameters: None
  222. ' *
  223. ' * 
  224. ' * Return Value: None
  225. ' *
  226. ' * 
  227. ' * Description:
  228. ' *
  229. ' *        Script Setup Stuff
  230. ' *
  231. ' *
  232. Sub InitializeScript ()
  233.  
  234.     TCWClearError    ' * Clear any error out of the error buffer.
  235.  
  236.     
  237.     if ERR_SET = 1 then DoErrSetValue
  238.  
  239.         
  240.     ' * ADD YOUR CODE HERE *
  241.  
  242. End Sub
  243. '
  244. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  245.  
  246.  
  247.  
  248.  
  249. ''FUNCTION: GetLineHandle''''''''''''''''''''''''''''''''''''''
  250. '
  251. ' * Parameters: ByVal strPrompt As String    -    String containing the 
  252. ' *                                                 status bar message.
  253. ' * 
  254. ' *
  255. ' * Return Value:    Long
  256. ' * 
  257. ' * 
  258. ' * Description:    
  259. ' * 
  260. ' *        This subroutine uses TCWGetPoint to 
  261. ' *         get the user to select a point on 
  262. ' *         the current drawing.  The function
  263. ' *         then checks to see if there is a 
  264. ' *         line graphic at that point.  If so, 
  265. ' *         function returns lines graphic's
  266. ' *         handle.  If there is not a line 
  267. ' *         graphic present at the user's 
  268. ' *         selected point, the function
  269. ' *         displays a message box alerting
  270. ' *         the user of this and then asks
  271. ' *         the user to select another point.
  272. ' * 
  273. ' *  
  274. Function GetLineHandle ( ByVal strPrompt As String ) As Long
  275.  
  276.     Dim hVertex        As Long
  277.     Dim hGraphic    As Long
  278.     Dim rVal        As Long
  279.  
  280.  
  281.     hVertex = TCWVertexCreate(0,0,0) 
  282.  
  283.  
  284.     while rVal = 0 
  285.  
  286.         tcwgetpoint hVertex, strPrompt, NULL, NULL, &H0040, 1
  287.         hGraphic = TCWVertexFindGraphic (hVertex)
  288.  
  289.         vNum = TCWVertexCount (hGraphic)
  290.         if vNum = 2 then rVal = hGraphic
  291.  
  292.     wend
  293.  
  294.     GetLineHandle = rVal
  295.  
  296. End Function
  297. '
  298. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  299.  
  300.  
  301.  
  302. ''SUBROUTINE: GetGraphicsHandles'''''''''''''''''''''''''''''''
  303. '
  304. ' * Parameters: ByRef GraphicHandleArray() As Long
  305. ' *
  306. ' * 
  307. ' * Return Value: None
  308. ' *
  309. ' * 
  310. ' * Description:
  311. ' *
  312. ' *        This subroutine cycles through the selected
  313. ' *         graphics and loads each grahic's handle
  314. ' *         into an array which will be used later to
  315. ' *         retrieve other values for the script.
  316. ' * 
  317. ' *
  318. Sub GetGraphicsHandles ( ByRef GraphicHandleArray() As Long )
  319.  
  320.     Dim counter            As Long
  321.     Dim strPrompt(2)    As String
  322.  
  323.     strPrompt(1) = "Please select first line"
  324.     strPrompt(2) = "Please select second line"
  325.     
  326.     
  327.     for counter = 1 to MAX_LINES
  328.  
  329.         GraphicHandleArray( counter - 1 ) = GetLineHandle ( strPrompt( counter ) )
  330.  
  331.     next
  332.     
  333. End Sub
  334. '
  335. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  336.  
  337.  
  338.  
  339.  
  340. ''SUBROUTINE: GetVertexHandles'''''''''''''''''''''''''''''''''
  341. '
  342. ' * Parameters:    ByRef GraphicHandleArray() As Long 
  343. ' *                ByRef VertexHandleArray() As Long
  344. ' * 
  345. ' * 
  346. ' * Return Value: None
  347. ' * 
  348. ' * 
  349. ' * Description:
  350. ' *
  351. ' *        This subroutine uses the graphics handles
  352. ' *         stored in GraphicHandleArray() to 
  353. ' *         the handles for each graphic's vertices
  354. ' *         then store them in VertexHandleArray().
  355. ' *
  356. ' *
  357. Sub GetVertexHandles (    ByRef GraphicHandleArray() As Long, _ 
  358.                         ByRef VertexHandleArray() As Long )
  359.  
  360.     dim gCounter as long
  361.     dim vCounter as long
  362.  
  363.     
  364.     for gCounter = 0 to (MAX_LINES - 1)
  365.  
  366.     
  367.         for vCounter = 0 to MAX_VERTICES-1
  368.  
  369.     
  370.             VertexHandleArray( gCounter, ( vCounter ) ) = _ 
  371.              TCWVertexAt ( GraphicHandleArray( gCounter ), vCounter )
  372.  
  373.             CheckReturnValue "GetVertexHandles: TCWVertexAt", _ 
  374.              VertexHandleArray( gCounter, ( vCounter ) )
  375.  
  376.     
  377.         next
  378.  
  379.     
  380.     next
  381.  
  382. End Sub
  383. '
  384. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  385.  
  386.  
  387.  
  388.  
  389. ''SUBROUTINE: GetVertexCoordinates'''''''''''''''''''''''''''''
  390. '
  391. ' * Parameters: ByRef VertexHandleArray() As Long
  392. ' *                ByRef VertexCoordArray() As Double
  393. ' *
  394. ' * 
  395. ' * Return Value: None
  396. ' * 
  397. ' *
  398. ' * Description:
  399. ' *
  400. ' *        This subroutine takes the vertex handles
  401. ' *         stored in the VertexHandleArray to 
  402. ' *         retrieve the vertex coordinates for the
  403. ' *         two selected line graphics and store 
  404. ' *         then in VertexCoordArray().
  405. ' * 
  406. ' *
  407. Sub GetVertexCoordinates (    ByRef VertexHandleArray() As Long, _ 
  408.                             ByRef VertexCoordArray() As Double )
  409.  
  410.     dim gCounter as long
  411.     dim vCounter as long
  412.     dim cCounter as long
  413.  
  414.     for gCounter = 0 to MAX_LINES
  415.  
  416.         for vCounter = 0 to MAX_VERTICES
  417.  
  418.             for cCounter = 0 to MAX_COORDS
  419.  
  420.                 if cCounter = 0 then
  421.  
  422.                     VertexCoordArray(gCounter, vCounter, cCounter) _
  423.                                     = TCWGetX(VertexHandleArray(gCounter, vCounter))
  424.  
  425.                     CheckReturnValue "GetVertexCoordinates: TCWGetX ", _
  426.                                     VertexCoordArray(gCounter, vCounter, cCounter)
  427.                 end if
  428.  
  429.     
  430.                 if cCounter = 1 then
  431.  
  432.     
  433.                     VertexCoordArray(gCounter, vCounter, cCounter) _
  434.                                     = TCWGetY(VertexHandleArray(gCounter, vCounter))
  435.  
  436.                     CheckReturnValue "GetVertexCoordinates: TCWGetX ", _
  437.                                     VertexCoordArray(gCounter, vCounter, cCounter)
  438.  
  439.     
  440.                 end if
  441.  
  442.     
  443.             next
  444.  
  445.     
  446.         next
  447.  
  448.  
  449.     next
  450.  
  451. End Sub
  452. '
  453. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  454.  
  455.  
  456.  
  457.  
  458. ''SUBROUTINE: CalculateIntersectCoordinates''''''''''''''''''''
  459. '
  460. ' * Parameters: ByRef VCA() As Double - Vertex Coordinate Array
  461. ' *                ByRef PCA() As Double - Point Coordinate Array
  462. ' *
  463. ' * 
  464. ' * Return Value: None
  465. ' * 
  466. ' *
  467. ' * Description:
  468. ' *
  469. ' *        This subroutine takes the vertex coordinates
  470. ' *         that's been gathered from the selected line
  471. ' *         graphics and calculates the x and y values
  472. ' *         for the 'virtual' intersection of the two
  473. ' *         lines.  The resulting x and y values are
  474. ' *         then stored in PCA() (point coordinate array)
  475. ' *         for use in the point insertion subroutine.
  476. ' * 
  477. ' *
  478. ' * Note:
  479. ' *        
  480. ' *        When using the vertex coordinate array VCA()
  481. ' *         each value is indexed with a base of 0.  The
  482. ' *         first line graphic is 0, the second 1.  The
  483. ' *         first vertex is 0,0 and the second is 0,1.
  484. ' *         The vertex x/y gets a little more confusing:
  485. ' *         x of the first vertex of the first line would
  486. ' *         be 0,0,0 and y, 0,0,1.
  487. ' * 
  488. ' *
  489. Sub CalculateIntersectCoordinates ( ByRef VCA() As Double, _ 
  490.                                     ByRef PCA() As Double )
  491.  
  492.     Dim a11 As Double
  493.     Dim a12 As Double
  494.  
  495.     Dim b1     As Double
  496.     Dim b2    As Double
  497.  
  498.     Dim a21 As Double
  499.     Dim a22 As Double
  500.  
  501.     Dim x11 As Double
  502.     Dim x12 As Double
  503.  
  504.     Dim x21 As Double
  505.     Dim x22 As Double
  506.  
  507.     Dim y11    As Double
  508.     Dim y12 As Double
  509.  
  510.     Dim y21 As Double
  511.     Dim y22 As Double
  512.  
  513.     Dim x    As Double
  514.     Dim y    As Double
  515.     Dim d    As Double
  516.  
  517.             '''''''''''
  518.             '  L  V  C
  519.             '  i  e  o
  520.             '  n  r  o
  521.             '  e  t  r
  522.             '     e  d
  523.             '     x  s
  524.             '
  525.             ' -1 -1 -1
  526.             '
  527.     x11 = VCA( 0, 0, 0 )
  528.     x12 = VCA( 0, 1, 0 )
  529.  
  530.     x21 = VCA( 1, 0, 0 )
  531.     x22 = VCA( 1, 1, 0 )
  532.  
  533.     y11 = VCA( 0, 0, 1 )
  534.     y12 = VCA( 0, 1, 1 )
  535.  
  536.     y21 = VCA( 1, 0, 1 )
  537.     y22 = VCA( 1, 1, 1 )
  538.  
  539.  
  540.     a11    = ( y12 - y11 )
  541.     a12    = - ( x12 - x11 )
  542.  
  543.     a21    = ( y22 - y21 )
  544.     a22    = - ( x22 - x21 )
  545.  
  546.     b1    = ( ( y12 - y11 ) * x11 ) - ( ( x12 - x11 ) * y11 )
  547.     b2    = ( ( y22 - y21 ) * x21 ) - ( ( x22 - x21 ) * y21 )
  548.  
  549.     d    = ( ( a11 * a22 ) - ( a21 * a12 ) )
  550.  
  551.  
  552.     if d = 0 then
  553.  
  554.         MsgBox "No virtual intersection possible!"
  555.         END
  556.  
  557.     end if
  558.  
  559.  
  560.     x = ( ( a22 * b1 ) - ( a12 * b2 ) ) / d
  561.     y = ( ( a11 * b2 ) - ( a21 * b1 ) ) / d
  562.  
  563.     PCA( 0 ) = x
  564.     PCA( 1 ) = y
  565.  
  566. End Sub
  567. '
  568. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  569.  
  570.  
  571.  
  572.  
  573. ''SUBROUTINE: InsertPointObject''''''''''''''''''''''''''''''''
  574. '
  575. ' * Parameters:    ByRef PCA() As Double
  576. ' *                ByVal hDrawing As Long
  577. ' *
  578. ' * 
  579. ' * Return Value: None
  580. ' * 
  581. ' *
  582. ' * Description:
  583. ' *
  584. ' *        This subroutine uses the x and  y
  585. ' *         values stored in PCA() to insert
  586. ' *         a new point graphic at the 'virtual'
  587. ' *         intersection of the two selected
  588. ' *         line graphics.
  589. ' *
  590. ' *
  591. Sub InsertPointObject ( ByRef PCA() As Double, ByVal hDrawing As Long )
  592.  
  593.     Dim hParentGraphic    As Long
  594.     Dim hCircleGraphic    As Long
  595.     Dim hCrossGraphic    As Long    
  596.     Dim hVertex1        As Long
  597.     Dim hVertex2        As Long
  598.     Dim hVertex3        As Long
  599.     Dim hVertex4        As Long
  600.  
  601.  
  602.     hParentGraphic    = TCWGraphicCreate ( GK_GRAPHIC, "" )
  603.  
  604.         hTempGraphic = TCWCircleCenterAndPoint ( _ 
  605.                                                     PCA#( 0 ), _ 
  606.                                                     PCA#( 1 ), _ 
  607.                                                     0#,    _ 
  608.                                                     ( PCA#( 0 ) + .05# ), _ 
  609.                                                     ( PCA#( 1 ) + .05# ), _ 
  610.                                                     0# _ 
  611.                                                  )
  612.  
  613.             hCircleGraphic = TCWGraphicCopy ( hTempGraphic )
  614.             TCWGraphicDispose hTempGraphic
  615.  
  616.         TCWGraphicAppend hParentGraphic, hCircleGraphic
  617.  
  618.  
  619.         hCrossGraphic    = TCWGraphicCreate ( GK_GRAPHIC, "" )
  620.         
  621.             hVertex1 = TCWVertexCreate ( PCA#( 0 ) - .15#,    PCA#( 1 ),            0# )
  622.             hVertex2 = TCWVertexCreate ( PCA#( 0 ) + .15#,    PCA#( 1 ),            0# )
  623.             hVertex3 = TCWVertexCreate ( PCA#( 0 ),            PCA#( 1 ) - .15,    0# )
  624.             hVertex4 = TCWVertexCreate ( PCA#( 0 ),            PCA#( 1 ) + .15,    0# )
  625.  
  626.             TCWPenDown hVertex1, MY_FALSE
  627.             TCWPenDown hVertex2, MY_TRUE
  628.             TCWPenDown hVertex3, MY_FALSE
  629.             TCWPenDown hVertex4, MY_TRUE
  630.         
  631.             TCWGraphicVertexAdd hCrossGraphic, hVertex1
  632.             TCWGraphicVertexAdd hCrossGraphic, hVertex2
  633.             TCWGraphicVertexAdd hCrossGraphic, hVertex3
  634.             TCWGraphicVertexAdd hCrossGraphic, hVertex4
  635.  
  636.         TCWGraphicAppend hParentGraphic, hCrossGraphic
  637.  
  638.  
  639.     TCWGraphicAppend NULL, hParentGraphic
  640.  
  641.  
  642.     TCWGraphicDraw hParentGraphic, 0
  643.  
  644.  
  645.     TCWUndoRecordStart hDrawing, "Virtual Point"
  646.  
  647.         TCWUndoRecordAddGraphic hDrawing, hParentGraphic
  648.  
  649.     TCWUndoRecordEnd hDrawing
  650.  
  651.  
  652. End Sub
  653. '
  654. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  655.  
  656.  
  657.  
  658.  
  659. ''SUBROUTINE: CheckReturnValue'''''''''''''''''''''''''''''''''
  660. '
  661. ' * Parameters: None
  662. ' * 
  663. ' *
  664. ' * Return Value: None
  665. ' * 
  666. ' *
  667. ' * Description:
  668. ' *
  669. ' *        This subroutine is used to check the return
  670. ' *         value from API calls that return a value
  671. ' *         such as a handle to a graphic when called.
  672. ' *         If the value returned is NULL(0), then the
  673. ' *         for some reason the function was not able
  674. ' *         to complete successfully so another function
  675. ' *         is then called from another subroutine to
  676. ' *         grab the current error string reported from
  677. ' *         the last function called.
  678. ' * 
  679. ' *
  680. Sub CheckReturnValue (    ByVal FunctionString as String, _ 
  681.                         ByVal ReturnValue As Long )
  682.  
  683.     if ReturnValue = 0 then
  684.  
  685.         CheckForTCWError FunctionString & " = " & ReturnValue & " "
  686.  
  687.     end if
  688.  
  689. End Sub
  690. '
  691. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  692.  
  693.  
  694.  
  695.  
  696.  
  697. ''SUBROUTINE: ErrAction''''''''''''''''''''''''''''''''''''''''
  698. '
  699. ' * Parameters: ByVal ErrString As String
  700. ' * 
  701. ' *
  702. ' * Return Value: None
  703. ' * 
  704. ' *
  705. ' * Description:
  706. ' *
  707. ' *        This function report errors using the
  708. ' *         method specified by the ERR_METHOD
  709. ' *         constant value which is set in this
  710. ' *         script's constant section.
  711. ' *
  712. ' *
  713. Sub ErrAction ( ByVal ErrString As String )
  714.  
  715.     select case ERR_METHOD
  716.  
  717.         case SILENT
  718.  
  719.             open ERR_FILE for append as # 10
  720.  
  721.                 print # 10, ErrString
  722.  
  723.             close
  724.  
  725.             if ERR_SET = 0 then    ToggleErrSet
  726.  
  727.         case MSG_BOX
  728.  
  729.             MsgBox ErrString & Chr$( 10 ) & "Please press OK to terminate script", _
  730.                                              MB_OK, "Find Intersection Error"
  731.  
  732.             if ERR_STOP = ERR_TRUE then    STOP
  733.  
  734.         case ALL
  735.  
  736.             open ERR_FILE for append as # 10
  737.  
  738.                 print # 10, ErrString
  739.  
  740.             close
  741.  
  742.         
  743.             MsgBox ErrString & Chr$( 10 ) & "Please press OK to terminate script", _
  744.                                              MB_OK, "Find Intersection Error"
  745.  
  746.         
  747.             if ERR_SET = 0 then    ToggleErrSet
  748.             if ERR_STOP = ERR_TRUE then    STOP
  749.  
  750.  
  751.         case NONE
  752.  
  753.             ' * No error reporting method active
  754.  
  755.     end select
  756.  
  757. End Sub
  758. '
  759. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  760.  
  761.  
  762.  
  763.  
  764. ''SUBROUTINE: CheckForTCWError'''''''''''''''''''''''''''''''''
  765. '
  766. ' * Parameters: ByVal errString As String
  767. ' * 
  768. ' *
  769. ' * Return Value: None
  770. ' * 
  771. ' *
  772. ' * Description:
  773. ' *
  774. ' *        This subroutine checks to see 
  775. ' *         if a Tcadapi call generated 
  776. ' *         an error.
  777. ' *
  778. ' *
  779. Sub CheckForTCWError ( ByVal errString As String )
  780.  
  781.     dim errCurrent    as string
  782.  
  783.     errCurrent = TCWLastErrorGet
  784.  
  785.  
  786.     if errCurrent <> "" then
  787.  
  788.         ErrAction errString & " " & errCurrent
  789.  
  790.     end if
  791.  
  792.     TCWClearError
  793.  
  794. End Sub
  795. '
  796. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  797.  
  798.  
  799.  
  800.  
  801. ''SUBROUTINE: DoErrSetValue''''''''''''''''''''''''''''''''''''
  802. '
  803. ' * Parameters: None
  804. ' *
  805. ' * Return Value: None
  806. ' *
  807. ' * Description:
  808. ' *
  809. ' *        This subroutine removes the current
  810. ' *         log file from the drive and then
  811. ' *         calls the subroutine to reset the 
  812. ' *         constant value in this script's 
  813. ' *         source file.
  814. ' * 
  815. ' *
  816. Sub DoErrSetValue ()
  817.  
  818.     kill ERR_FILE
  819.     Toggle "ERR_SET"
  820.  
  821. End Sub
  822. '
  823. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  824.  
  825.  
  826.  
  827.  
  828. ''SUBROUTINE: Toggle'''''''''''''''''''''''''''''''''''''''''''
  829. '
  830. ' * Parameters: ByVal strConstant As String
  831. ' *
  832. ' * Return Value: None
  833. ' *
  834. ' * Description:
  835. ' *
  836. ' *        This subroutine toggles the current
  837. ' *         value of the constant in this 
  838. ' *         script's source file specified
  839. ' *         by strConstant.
  840. ' *
  841. ' *
  842. Sub Toggle ( ByVal strConstant As String )
  843.  
  844.     Dim sLength        As Long
  845.     Dim cString        As String
  846.     Dim cResult        As Long
  847.     Dim mResult        As Long
  848.     Dim writeval    As Integer
  849.     Dim counter        As Long
  850.  
  851.  
  852.     fLength = filelen ( SCRIPT_FILE )
  853.     sLength = (len ( strConstant ) )
  854.  
  855.  
  856.     open SCRIPT_FILE for input as #1
  857.  
  858.  
  859.         for counter = 0 to fLength 
  860.  
  861.  
  862.             seek #1, counter
  863.             cString = input ( sLength, #1 )
  864.  
  865.             if cString = strConstant then
  866.  
  867.                 msgbox cString
  868.  
  869.                 counter = counter + sLength
  870.                 seek #1, counter
  871.  
  872.                 cString = input ( 1, #1 )
  873.                 msgbox cString
  874.                 
  875.                 exit for
  876.                 
  877.             end if
  878.  
  879.  
  880.         next
  881.  
  882.  
  883.     close #1
  884.  
  885.  
  886.     if cString = "0" then
  887.  
  888.         writeval = 1
  889.  
  890.     else
  891.  
  892.         writeval = 0
  893.  
  894.     end if
  895.  
  896.  
  897.     open SCRIPT_FILE for output as #1
  898.  
  899.         seek #1, counter
  900.         write #1, writeval
  901.  
  902.     close #1
  903.  
  904. End Sub
  905. '
  906. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  907.  
  908.  
  909.  
  910.  
  911. ''SUBROUTINE: DoUI'''''''''''''''''''''''''''''''''''''''''''''
  912. '
  913. ' * Parameters: None
  914. ' * 
  915. ' *
  916. ' * Return Value: None
  917. ' * 
  918. ' * 
  919. ' * Description:    
  920. ' * 
  921. ' *        This is the script's user interface subroutine.
  922. ' *         It's actually a dialog box definition that serves
  923. ' *         as a "template" for later creating a variable of
  924. ' *         of this type and them using the enable function
  925. ' *        'Dialog' to display it and return values.  The  
  926. ' *         dialog definition is done in a manner very similar 
  927. ' *         to creating user defined variables with the type 
  928. ' *         function in basic or the struct function in C.
  929. ' *         By utilizing several of the UI objects available
  930. ' *         you can actually create quite a useful interface 
  931. ' *         for setting script values and options as well as
  932. ' *         guiding the user through script setup with a 
  933. ' *         "wizard" like interface.  
  934. ' * 
  935. ' *  
  936. Sub DoUI ()
  937.  
  938.     Begin Dialog UI 60, 60, 240, 184, "Virtual Intersection Finder"
  939.  
  940.         Text        30,    30,    200, 200,    "The Virtual Intersection Finder script allows you to choose two lines and will then place a point graphic at the 'virtual' intersection of the two lines." 
  941.         
  942.         CheckBox    30, 100, 200, 10, "&Display this dialog every time this script is run?", .chkDisplay
  943.      
  944.         OKbutton     80, 170, 40, 12
  945.         CancelButton 120, 170, 40, 12
  946.     
  947.     End Dialog
  948.     
  949.  
  950.     Dim UIDlg As UI
  951.     UIDlg.chkDisplay = 1
  952.     button = Dialog ( UIDlg )
  953.  
  954.  
  955.     if button = 0 then
  956.  
  957.         END
  958.  
  959.     else 
  960.  
  961.         if UIDlg.chkDisplay = 0 then
  962.  
  963.             Toggle "Global Const DISPLAY_SPLASH = "
  964.  
  965.         end if
  966.             
  967.     end if
  968.  
  969. End Sub
  970. '
  971. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  972.  
  973.  
  974.  
  975.  
  976.  
  977.  
  978.