home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2002 March / PCWMAR02.iso / software / turbocad / v8trial / TurboCADv8ProfessionalNoReg.exe / Data.Cab / F40632_modSelInfo.bas < prev    next >
Encoding:
BASIC Source File  |  2001-10-16  |  8.8 KB  |  308 lines

  1. Attribute VB_Name = "modSelInfo"
  2. '******************************************************************'
  3. '*                                                                *'
  4. '*                      TurboCAD for Windows                      *'
  5. '*                   Copyright (c) 1993 - 2001                    *'
  6. '*             International Microcomputer Software, Inc.         *'
  7. '*                            (IMSI)                              *'
  8. '*                      All rights reserved.                      *'
  9. '*                                                                *'
  10. '******************************************************************'
  11.  
  12. Option Explicit
  13.  
  14. Const lyrname As String = "_SelInfo"
  15.  
  16. Public Sub ShowSelForm()
  17.     frmSelInfo.Show
  18. End Sub
  19.  
  20. Sub ClearInfoLayer()
  21.     On Error Resume Next
  22.     Dim lyr As Layer
  23.     
  24.     Set lyr = ActiveDrawing.Layers.Item(lyrname)
  25.     If Not lyr Is Nothing Then
  26.         lyr.Clear
  27.     End If
  28.     ActiveDrawing.ActiveView.Refresh
  29. End Sub
  30.  
  31. Sub PrintInfoToFile(ByVal fname As String, ByVal all As Boolean)
  32.     On Error GoTo BadFile
  33.     Dim sel As Selection
  34.     Dim grs As Graphics
  35.     Dim gfc As Graphic
  36.     
  37.     Open fname For Output As #1
  38.     
  39.     On Error Resume Next
  40.     
  41.     If all Then
  42.         Set grs = ActiveDrawing.Graphics
  43.         For Each gfc In grs
  44.             PrintGraphicInfoToFile gfc, 0
  45.         Next
  46.     Else
  47.         Set sel = ActiveDrawing.Selection
  48.         For Each gfc In sel
  49.             PrintGraphicInfoToFile gfc, 0
  50.         Next
  51.     End If
  52.     Close #1
  53.     MsgBox "File '" & fname & "' saved."
  54.     Exit Sub
  55.     
  56. BadFile:
  57.     MsgBox "Could not open file '" & fname & "'!"
  58. End Sub
  59.  
  60. Private Sub PrintGraphicInfoToFile(gfc As Graphic, lvl As Integer)
  61.     On Error Resume Next
  62.     Dim i, count As Integer
  63.     Dim s As String
  64.     
  65.     Print #1, ""
  66.     Print #1, "--------"
  67.     Print #1, "Graphic At Level " & lvl & ":"
  68.     Print #1, "   ID " & gfc.ID
  69.     Print #1, " Name " & gfc.Name
  70.     Print #1, " Type " & gfc.Type
  71.     s = "<Err>"
  72.     s = gfc.RegenType
  73.     Print #1, "Regen " & s
  74.     s = ""
  75.     If gfc.Builtin Then s = s & "Bilt "
  76.     If gfc.Closed Then s = s & "Clsd "
  77.     If gfc.Cosmetic Then s = s & "Cosm "
  78.     If gfc.Deleted Then s = s & "Dele "
  79.     If gfc.Editable Then s = s & "Edit "
  80.     If gfc.Unbounded Then s = s & "Ubnd "
  81.     If gfc.Visible Then s = s & "Vis  "
  82.     Print #1, "Flags " & s
  83.     
  84.     count = gfc.Vertices.count
  85.     Print #1, ""
  86.     Print #1, "      " & count & " Vertices:"
  87.     Dim vtx As Vertex
  88.     For i = 0 To count - 1
  89.         Set vtx = gfc.Vertices(i)
  90.         Print #1,
  91.         Print #1, "[" & i & "] at (" & vtx.x & ", " & vtx.y & ", " & vtx.z & ")"
  92.         s = ""
  93.         If vtx.PenDown Then s = s & "Down " Else s = s & "Up   "
  94.         If vtx.Bulge Then s = s & "Blge "
  95.         If vtx.Calculated Then s = s & "Calc "
  96.         If vtx.Editable Then s = s & "Edit "
  97.         If vtx.Linkable Then s = s & "Link "
  98.         If vtx.Selectable Then s = s & "Sel  "
  99.         If vtx.Snappable Then s = s & "Snap "
  100.         Print #1, "Flags " & s
  101.     Next i
  102.     
  103.     Print #1, ""
  104.     PrintPropertiesToFile gfc.Properties
  105.     
  106.     Dim blk As Block
  107.     Set blk = gfc.Block
  108.     If Not blk Is Nothing Then
  109.         s = blk.Name
  110.         Print #1, ""
  111.         Print #1, "      Block: " & s
  112.         Set vtx = blk.Anchor
  113.         Print #1,
  114.         Print #1, "Anchor at (" & vtx.x & ", " & vtx.y & ", " & vtx.z & ")"
  115.         count = blk.Graphics.count
  116.         Print #1, ""
  117.         Print #1, "      " & count & " Children:"
  118.         For i = 0 To count - 1
  119.             PrintGraphicInfoToFile blk.Graphics(i), lvl + 1
  120.         Next i
  121.         Print #1, "      End Block"
  122.     End If
  123.     
  124.     'Sanity check
  125.     If lvl > 4 Then Exit Sub
  126.     
  127.     count = gfc.Graphics.count
  128.     Print #1, ""
  129.     Print #1, "      " & count & " Children:"
  130.     For i = 0 To count - 1
  131.         PrintGraphicInfoToFile gfc.Graphics(i), lvl + 1
  132.     Next i
  133. End Sub
  134.  
  135.  
  136. Sub DrawVertices(ByVal all As Boolean)
  137.     Dim sel As Selection
  138.     Dim grs As Graphics
  139.     Dim gfc As Graphic
  140.     Dim bbox As BoundingBox
  141.     Dim sclX, sclY As Double
  142.     
  143.     If all Then
  144.         Set grs = ActiveDrawing.Graphics
  145.         For Each gfc In grs
  146.             Set bbox = gfc.CalcBoundingBox
  147.             sclX = Abs(bbox.Max.x - bbox.Min.x)
  148.             sclY = Abs(bbox.Max.y - bbox.Min.y)
  149.             If sclX < sclY Then sclX = sclY
  150.             DrawGraphicVertices gfc, 0, sclX
  151.         Next
  152.     Else
  153.         Set sel = ActiveDrawing.Selection
  154.         For Each gfc In sel
  155.             Set bbox = gfc.CalcBoundingBox
  156.             sclX = Abs(bbox.Max.x - bbox.Min.x)
  157.             sclY = Abs(bbox.Max.y - bbox.Min.y)
  158.             If sclX < sclY Then sclX = sclY
  159.             DrawGraphicVertices gfc, 0, sclX
  160.         Next
  161.     End If
  162. End Sub
  163.  
  164. Private Sub DrawGraphicVertices(gfc As Graphic, lvl As Integer, ByVal scl As Double)
  165.     On Error Resume Next
  166.     Dim i, count As Integer
  167.     Dim s As String
  168.     Dim r, x, y, z As Double
  169.     Dim lyr As Layer
  170.     Dim vtx As Vertex
  171.     Dim gi, gr1, gr2 As Graphic
  172.     
  173.     'Find or create special layer
  174.     Set lyr = gfc.Drawing.Layers.Item(lyrname)
  175.     If lyr Is Nothing Then
  176.         Set lyr = gfc.Drawing.Layers.Add(lyrname)
  177.     End If
  178.     
  179.     If lyr Is Nothing Then
  180.         MsgBox "Couldn't access layer '" & lyrname & "'"
  181.         Exit Sub
  182.     End If
  183.     
  184.     Set gi = lyr.Add
  185.     If gi Is Nothing Then
  186.         MsgBox "Couldn't add graphic to layer"
  187.         Exit Sub
  188.     End If
  189.     
  190.     r = scl * 0.125
  191.     z = (-lvl - 1) * scl / 4
  192.     count = gfc.Vertices.count
  193.     Set gr2 = lyr.Add
  194.     For i = 0 To count - 1
  195.         Set vtx = gfc.Vertices(i)
  196.         x = vtx.x
  197.         y = vtx.y
  198.         Set gr1 = lyr.AddCircle(x, y, z)
  199.         gr2.Vertices.Add x, y, z
  200.     Next
  201.     gr2.Properties("PenColor") = &HFF00
  202.     
  203.     'Sanity check
  204.     If lvl > 4 Then Exit Sub
  205.         
  206.     count = gfc.Graphics.count
  207.     For i = 0 To count - 1
  208.         lvl = lvl + 1
  209.         DrawGraphicVertices gfc.Graphics(i), lvl, scl
  210.     Next
  211. End Sub
  212.  
  213. Public Sub DebugPrintSelInfo()
  214.     DebugPrintInfo False
  215. End Sub
  216.  
  217. Sub DebugPrintInfo(ByVal all As Boolean)
  218.     On Error Resume Next
  219.     Dim sel As Selection
  220.     Dim grs As Graphics
  221.     Dim gfc As Graphic
  222.     
  223.     If all Then
  224.         Set grs = ActiveDrawing.Graphics
  225.         For Each gfc In grs
  226.             DebugPrintGraphicInfo gfc, 0
  227.         Next
  228.     Else
  229.         Set sel = ActiveDrawing.Selection
  230.         For Each gfc In sel
  231.             DebugPrintGraphicInfo gfc, 0
  232.         Next
  233.     End If
  234. End Sub
  235.  
  236. Private Sub DebugPrintGraphicInfo(gfc As Graphic, lvl As Integer)
  237.     On Error Resume Next
  238.     Dim i, count As Integer
  239.     Dim s As String
  240.     
  241.     Debug.Print ""
  242.     Debug.Print "--------"
  243.     Debug.Print "Graphic At Level " & lvl & ":"
  244.     Debug.Print "   ID " & gfc.ID
  245.     Debug.Print " Name " & gfc.Name
  246.     Debug.Print " Type " & gfc.Type
  247.     s = "<Err>"
  248.     s = gfc.RegenType
  249.     Debug.Print "Regen " & s
  250.     s = ""
  251.     If gfc.Builtin Then s = s & "Bilt "
  252.     If gfc.Closed Then s = s & "Clsd "
  253.     If gfc.Cosmetic Then s = s & "Cosm "
  254.     If gfc.Deleted Then s = s & "Dele "
  255.     If gfc.Editable Then s = s & "Edit "
  256.     If gfc.Unbounded Then s = s & "Ubnd "
  257.     If gfc.Visible Then s = s & "Vis  "
  258.     Debug.Print "Flags " & s
  259.     
  260.     count = gfc.Vertices.count
  261.     Debug.Print ""
  262.     Debug.Print "      " & count & " Vertices:"
  263.     Dim vtx As Vertex
  264.     For i = 0 To count - 1
  265.         Set vtx = gfc.Vertices(i)
  266.         Debug.Print
  267.         Debug.Print "[" & i & "] at (" & vtx.x & ", " & vtx.y & ", " & vtx.z & ")"
  268.         s = ""
  269.         If vtx.PenDown Then s = s & "Down " Else s = s & "Up   "
  270.         If vtx.Bulge Then s = s & "Blge "
  271.         If vtx.Calculated Then s = s & "Calc "
  272.         If vtx.Editable Then s = s & "Edit "
  273.         If vtx.Linkable Then s = s & "Link "
  274.         If vtx.Selectable Then s = s & "Sel  "
  275.         If vtx.Snappable Then s = s & "Snap "
  276.         Debug.Print "Flags " & s
  277.     Next i
  278.     
  279.     Dim blk As Block
  280.     Set blk = gfc.Block
  281.     If Not blk Is Nothing Then
  282.         s = blk.Name
  283.         Debug.Print ""
  284.         Debug.Print "      Block: " & s
  285.         Set vtx = blk.Anchor
  286.         Debug.Print
  287.         Debug.Print "Anchor at (" & vtx.x & ", " & vtx.y & ", " & vtx.z & ")"
  288.         count = blk.Graphics.count
  289.         Debug.Print ""
  290.         Debug.Print "      " & count & " Children:"
  291.         For i = 0 To count - 1
  292.             DebugPrintGraphicInfo blk.Graphics(i), lvl + 1
  293.         Next i
  294.         Debug.Print "      End Block"
  295.     End If
  296.     
  297.     'Sanity check
  298.     If lvl > 4 Then Exit Sub
  299.     
  300.     count = gfc.Graphics.count
  301.     Debug.Print ""
  302.     Debug.Print "      " & count & " Children:"
  303.     For i = 0 To count - 1
  304.         DebugPrintGraphicInfo gfc.Graphics(i), lvl + 1
  305.     Next i
  306. End Sub
  307.  
  308.