home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / WINDOWS / EZNET.ZIP / EDITOR.ZIP / EDITOR.BAS next >
Encoding:
BASIC Source File  |  1996-05-05  |  17.1 KB  |  609 lines

  1. Attribute VB_Name = "EditorModule"
  2. Option Explicit
  3.  
  4. ' ---------------------------------------------------------------
  5. '  This procedure saves an EasyNet diagram in a sequential file.
  6. '  It saves:
  7. ' - the version number
  8. ' - the nodes count
  9. ' - the links count
  10. ' - every properties of each node (except Picture property)
  11. ' - every properties of each link.
  12. '
  13. '  Picture property is not saved but you may instead manage
  14. ' a correspondance between node types and pictures. For
  15. ' instance when you load your file, your VB application knows
  16. ' that node of type 1 have one icon, nodes of type 2 have another
  17. ' icon, etc...
  18. '
  19. '  This program is just an example to show how an EasyNet file
  20. ' may be saved to disk.
  21. '  Properties that applied to the whole diagram like FontSize or
  22. ' FontName are not saved here.
  23. '  You may proceed differently: for instance, use a binary or
  24. ' a random file and save only the properties you need for your
  25. ' application.
  26. '  You may consider this program as a starting point to write
  27. ' your EasyNet saving/loading procedures adapted to your needs.
  28. '
  29. ' THE CODE PROVIDED HEREUNDER IS PROVIDED AS IS WITHOUT WARRANTY
  30. ' OF ANY KIND.
  31. ' ---------------------------------------------------------------
  32. '
  33.  
  34. ' Following type is used for loading only.
  35.  
  36. Type ItemRec
  37.   Type As Integer
  38.   Data As Long
  39.   FillColor As Long
  40.   ForeColor As Long
  41.   DrawColor As Long
  42.   DrawWidth As Integer
  43.   DrawStyle As Integer
  44.   Sleeping As Integer
  45.   Hiding As Integer
  46.   ItemTag As String
  47.   Text As String
  48.   Shape As Integer
  49.   Transparent As Integer
  50.   Alignment As Integer
  51.   AutoSize As Integer
  52.   X1 As Long
  53.   Y1 As Long
  54.   X2 As Long
  55.   Y2 As Long
  56.   Oriented As Integer
  57.   LinkHead As Integer
  58.   OwnerNode As Long
  59.   SrcNode As Long
  60.   DstNode As Long
  61.   Points As Integer
  62. End Type
  63.  
  64. Sub SaveEasyNetFile(Net1 As Control, Filename$)
  65.   Dim i%, j%, length%, PointCount%
  66.   Dim TextLength%, TagLength%
  67.   Dim Text$, ItemTag$, s$, CR$
  68.   Dim nodeId&, owner&, Org&, Dst&, l&, item&, X1&, Y1&, X2&, Y2&
  69.   Dim NodeCount&, LinkCount&
  70.   Dim node() As Long
  71.   Dim link() As Long
  72.   Dim ptx() As Long
  73.   Dim pty() As Long
  74.  
  75.   CR = Chr$(13)
  76.  
  77.   With Net1
  78.     Open Filename For Output As 1
  79.     Print #1, "EASYNET VERSION = " + Format$(.Version)
  80.   
  81.     ' Node count
  82.     NodeCount = .GetNodesCount
  83.     Print #1, "Nodes = " + Format$(NodeCount)
  84.  
  85.     ' Link count
  86.     LinkCount = .GetLinksCount
  87.     Print #1, "Links = " + Format$(LinkCount)
  88.  
  89.     ' Allocate array to store node and link identifiers.
  90.     If NodeCount > 0 Then
  91.       ReDim node(1 To NodeCount)
  92.       .GetNodesArray NodeCount, node(1)
  93.     End If
  94.     If LinkCount > 0 Then
  95.       ReDim link(1 To LinkCount)
  96.       .GetLinksArray LinkCount, link(1)
  97.     End If
  98.  
  99.     '-----------
  100.     ' Save nodes
  101.     '-----------
  102.  
  103.     ' For each node:
  104.     '   - make it the current one
  105.     '   - save its properties in the file
  106.  
  107.     For i = 1 To NodeCount
  108.       item = node(i)
  109.  
  110.       ' Get text and its length
  111.       Text = .GetItemText(item)
  112.       TextLength = Len(Text)
  113.  
  114.       ' Get tag and its length
  115.       ItemTag = .GetItemTag(item)
  116.       TagLength = Len(ItemTag)
  117.  
  118.       ' Find owner
  119.       owner = 0
  120.       nodeId = .GetNodeOwner(item)
  121.       For j = 1 To NodeCount
  122.         If node(j) = nodeId Then
  123.           owner = j
  124.           Exit For
  125.         End If
  126.       Next
  127.  
  128.       ' Save current node properties
  129.       Print #1, "Begin Node " + Format$(i)
  130.       Print #1, "  Owner = " + Format$(owner)
  131.       Print #1, "  Type = " + Str(.GetItemShort(item))
  132.       Print #1, "  Data = " + Str(.GetItemLong(item))
  133.       Print #1, "  ForeColor = " + Str(.GetItemForeColor(item))
  134.       Print #1, "  FillColor = " + Str(.GetNodeFillColor(item))
  135.       Print #1, "  DrawColor = " + Str(.GetItemDrawColor(item))
  136.       Print #1, "  DrawWidth = " + Str(.GetItemDrawWidth(item))
  137.       Print #1, "  DrawStyle = " + Str(.GetItemDrawStyle(item))
  138.       Print #1, "  Alignment = " + Str(.GetNodeAlignment(item))
  139.       Print #1, "  AutoSize = " + Str(.GetNodeAutoSize(item))
  140.       Print #1, "  Shape = " + Str(.GetNodeShape(item))
  141.       .GetNodeRect item, X1, Y1, X2, Y2
  142.       Print #1, "  X1 = " + Str(X1)
  143.       Print #1, "  Y1 = " + Str(Y1)
  144.       Print #1, "  X2 = " + Str(X2)
  145.       Print #1, "  Y2 = " + Str(Y2)
  146.       If .IsNodeTransparent(item) = False Then
  147.         Print #1, "  Transparent = " + "0"
  148.       Else
  149.         Print #1, "  Transparent = " + "-1"
  150.       End If
  151.       If .IsItemSleeping(item) = False Then
  152.         Print #1, "  Sleeping = " + "0"
  153.       Else
  154.         Print #1, "  Sleeping = " + "-1"
  155.       End If
  156.       If .IsItemHiding(item) = False Then
  157.         Print #1, "  Hiding = " + "0"
  158.       Else
  159.         Print #1, "  Hiding = " + "-1"
  160.       End If
  161.       
  162.       If TextLength > 0 Then
  163.         s = Text
  164.         length = InStr(s, CR)
  165.         While length > 0
  166.           Print #1, "  Text =" + Left$(s, length - 1)
  167.           s = Mid$(s, length + 2)
  168.           length = InStr(s, CR)
  169.         Wend
  170.         Print #1, "  Text =" + s
  171.       End If
  172.       
  173.       If TagLength > 0 Then
  174.         s = ItemTag
  175.         length = InStr(s, CR)
  176.         While length > 0
  177.           Print #1, "  ItemTag =" + Left$(s, length - 1)
  178.           s = Mid$(s, length + 2)
  179.           length = InStr(s, CR)
  180.         Wend
  181.         Print #1, "  ItemTag =" + s
  182.       End If
  183.       Print #1, "End"
  184.     Next i
  185.  
  186.     '-----------
  187.     ' Save links
  188.     '-----------
  189.   
  190.     ' For each link:
  191.     '   - find its origin and destination nodes
  192.     '   - save its properties in the file
  193.  
  194.     For i = 1 To LinkCount
  195.       ' Make link the current item
  196.       item = link(i)
  197.  
  198.       ' Find origin
  199.       Org = 0
  200.       nodeId = .GetLinkOrg(item)
  201.       For j = 1 To NodeCount
  202.         If node(j) = nodeId Then
  203.           Org = j
  204.           Exit For
  205.         End If
  206.       Next
  207.  
  208.       ' Find destination
  209.       Dst = 0
  210.       nodeId = .GetLinkDst(item)
  211.       For j = 1 To NodeCount
  212.         If node(j) = nodeId Then
  213.           Dst = j
  214.           Exit For
  215.         End If
  216.       Next
  217.     
  218.       ' Get text and its length
  219.       Text = .GetItemText(item)
  220.       TextLength = Len(Text)
  221.  
  222.       ' Get tag and its length
  223.       ItemTag = .GetItemTag(item)
  224.       TagLength = Len(ItemTag)
  225.  
  226.       ' Get Number of points
  227.       PointCount = .GetLinkPointCount(item)
  228.  
  229.       ' Get points
  230.       If PointCount > 0 Then
  231.         ReDim ptx(1 To PointCount)
  232.         ReDim pty(1 To PointCount)
  233.         For l = 1 To PointCount
  234.           ptx(l) = .GetLinkPointX(item, l)
  235.           pty(l) = .GetLinkPointY(item, l)
  236.         Next
  237.       End If
  238.  
  239.       ' Save current link properties
  240.       Print #1, "Begin Link " + Format$(i)
  241.       Print #1, "  Type = " + Str(.GetItemShort(item))
  242.       Print #1, "  Data = " + Str(.GetItemLong(item))
  243.       Print #1, "  ForeColor = " + Str(.GetItemForeColor(item))
  244.       Print #1, "  DrawColor = " + Str(.GetItemDrawColor(item))
  245.       Print #1, "  DrawWidth = " + Str(.GetItemDrawWidth(item))
  246.       Print #1, "  DrawStyle = " + Str(.GetItemDrawStyle(item))
  247.       Print #1, "  LinkHead = " + Str(.GetLinkArrowHead(item))
  248.       Print #1, "  Src = " + Format$(Org)
  249.       Print #1, "  Dst = " + Format$(Dst)
  250.       If .IsLinkOriented(item) = False Then
  251.         Print #1, "  Oriented = " + "0"
  252.       Else
  253.         Print #1, "  Oriented = " + "-1"
  254.       End If
  255.       If .IsItemSleeping(item) = False Then
  256.         Print #1, "  Sleeping = " + "0"
  257.       Else
  258.         Print #1, "  Sleeping = " + "-1"
  259.       End If
  260.       If .IsItemHiding(item) = False Then
  261.         Print #1, "  Hiding = " + "0"
  262.       Else
  263.         Print #1, "  Hiding = " + "-1"
  264.       End If
  265.     
  266.       Print #1, "  Points = " + Format$(PointCount)
  267.       If PointCount > 0 Then
  268.         For l = 1 To PointCount
  269.           Print #1, "    " + Format$(ptx(l)) + "," + Format$(pty(l))
  270.         Next
  271.       End If
  272.       If TextLength > 0 Then
  273.         s = Text
  274.         length = InStr(s, CR)
  275.         While length > 0
  276.           Print #1, "  Text =" + Left$(s, length - 1)
  277.           s = Mid$(s, length + 2)
  278.           length = InStr(s, CR)
  279.         Wend
  280.         Print #1, "  Text =" + s
  281.       End If
  282.       If TagLength > 0 Then
  283.         s = ItemTag
  284.         length = InStr(s, CR)
  285.         While length > 0
  286.           Print #1, "  ItemTag =" + Left$(s, length - 1)
  287.           s = Mid$(s, length + 2)
  288.           length = InStr(s, CR)
  289.         Wend
  290.         Print #1, "  ItemTag =" + s
  291.       End If
  292.       Print #1, "End"
  293.     Next i
  294.     
  295.     Erase node
  296.     Erase link
  297.     Erase ptx
  298.     Erase pty
  299.  
  300.     ' Close file
  301.     Close
  302.   End With
  303. End Sub
  304.  
  305.  
  306. '----------------------------------------------------
  307. ' (See comment of SaveEasyNetFile subroutine.)
  308. '----------------------------------------------------
  309.  
  310. Sub OpenEasyNetFile(Net1 As Control, Filename$)
  311.   Dim s$, value$, keyword$, CRLF$
  312.   Dim length%, i%, NodeCount%, LinkCount%, Version%
  313.   Dim ir As ItemRec
  314.   Dim l&, item&
  315.   Dim ptx() As Long
  316.   Dim pty() As Long
  317.   Dim node() As Long
  318.   Dim owner() As Integer
  319.  
  320.   CRLF = Chr$(13) + Chr$(10)
  321.   Open Filename For Input As #1
  322.   
  323.   With Net1
  324.     Line Input #1, s  ' Version
  325.     Version = Val(Mid$(s, InStr(s, "=") + 1))
  326.     If Version <> .Version Then
  327.       MsgBox "File created by another EasyNet version!", 0, "Editor"
  328.       'Exit Sub
  329.     End If
  330.  
  331.     ' Node count
  332.     Line Input #1, s
  333.     NodeCount = Val(Mid$(s, InStr(s, "=") + 1))
  334.  
  335.     ' Link count
  336.     Line Input #1, s
  337.     LinkCount = Val(Mid$(s, InStr(s, "=") + 1))
  338.  
  339.     If NodeCount = 0 Then
  340.       Close
  341.       Exit Sub
  342.     End If
  343.   
  344.     ReDim node(1 To NodeCount)
  345.     ReDim owner(1 To NodeCount)
  346.  
  347.     ' Load all nodes
  348.     For i = 1 To NodeCount
  349.       Line Input #1, s  ' Skip Begin keyword
  350.       length = InStr(s, " ")
  351.       keyword = Left$(s, length - 1)
  352.     
  353.       If keyword = "Begin" Then
  354.         ' Default values
  355.         ir.Type = 0
  356.         ir.Data = 0
  357.         ir.ItemTag = ""
  358.         ir.Text = ""
  359.         ir.ForeColor = .GetItemForeColor(0)
  360.         ir.FillColor = .GetNodeFillColor(0)
  361.         ir.DrawColor = .GetItemDrawColor(0)
  362.         ir.DrawWidth = .GetItemDrawWidth(0)
  363.         ir.DrawStyle = .GetItemDrawStyle(0)
  364.         ir.Sleeping = .IsItemSleeping(0)
  365.         ir.Hiding = .IsItemHiding(0)
  366.         ir.Shape = .GetNodeShape(0)
  367.         ir.Alignment = .GetNodeAlignment(0)
  368.         ir.AutoSize = .GetNodeAutoSize(0)
  369.         ir.Transparent = .IsNodeTransparent(0)
  370.         ir.X1 = 0
  371.         ir.Y1 = 0
  372.         ir.X2 = 0
  373.         ir.Y2 = 0
  374.         ir.OwnerNode = 0
  375.  
  376.         Do
  377.           Line Input #1, s  ' Skip Begin keyword
  378.           s = LTrim$(s)
  379.           length = InStr(s, " ")
  380.           If length > 0 Then
  381.             keyword = Left$(s, length - 1)
  382.           Else
  383.            keyword = s
  384.           End If
  385.           If keyword = "End" Then
  386.             Exit Do
  387.           End If
  388.           value = Mid$(s, length + 2)
  389.  
  390.           ' Load each node property
  391.           Select Case keyword
  392.           Case "Type"
  393.             ir.Type = Val(value)
  394.           Case "Data"
  395.             ir.Data = Val(value)
  396.           Case "FillColor"
  397.             ir.FillColor = Val(value)
  398.           Case "ForeColor"
  399.             ir.ForeColor = Val(value)
  400.           Case "DrawColor"
  401.             ir.DrawColor = Val(value)
  402.           Case "DrawWidth"
  403.             ir.DrawWidth = Val(value)
  404.           Case "DrawStyle"
  405.             ir.DrawStyle = Val(value)
  406.           Case "Sleeping"
  407.             ir.Sleeping = Val(value)
  408.           Case "Hiding"
  409.             ir.Hiding = Val(value)
  410.           Case "Transparent"
  411.             ir.Transparent = Val(value)
  412.           Case "Alignment"
  413.             ir.Alignment = Val(value)
  414.           Case "AutoSize"
  415.             ir.AutoSize = Val(value)
  416.           Case "Shape"
  417.             ir.Shape = Val(value)
  418.           Case "X1"
  419.             ir.X1 = Val(value)
  420.           Case "X2"
  421.             ir.X2 = Val(value)
  422.           Case "Y1"
  423.             ir.Y1 = Val(value)
  424.           Case "Y2"
  425.             ir.Y2 = Val(value)
  426.           Case "Owner"
  427.             ir.OwnerNode = Val(value)
  428.           Case "ItemTag"
  429.             If ir.ItemTag = "" Then
  430.               ir.ItemTag = value
  431.             Else
  432.               ir.ItemTag = ir.ItemTag + CRLF + value
  433.             End If
  434.           Case "Text"
  435.             If ir.Text = "" Then
  436.               ir.Text = value
  437.             Else
  438.               ir.Text = ir.Text + CRLF + value
  439.             End If
  440.           End Select
  441.         Loop
  442.  
  443.         ' Create Node
  444.         item = .AddNodeItem
  445.  
  446.         ' For each node, store its identifier
  447.         ' (will be used for links loading and for owner nodes)
  448.         node(i) = item
  449.         owner(i) = ir.OwnerNode
  450.     
  451.         .SetItemShort item, ir.Type
  452.         .SetItemLong item, ir.Data
  453.         .SetNodeFillColor item, ir.FillColor
  454.         .SetItemForeColor item, ir.ForeColor
  455.         .SetItemDrawColor item, ir.DrawColor
  456.         .SetItemDrawWidth item, ir.DrawWidth
  457.         .SetItemDrawStyle item, ir.DrawStyle
  458.         .SetItemHiding item, ir.Hiding
  459.         .SetNodeAlignment item, ir.Alignment
  460.         .SetNodeAutoSize item, ir.AutoSize
  461.         .SetNodeShape item, ir.Shape
  462.         .SetNodeTransparent item, ir.Transparent
  463.         .SetNodeRect item, ir.X1, ir.Y1, ir.X2, ir.Y2
  464.         .SetItemTag item, ir.ItemTag
  465.         .SetItemText item, ir.Text
  466.         .SetItemSleeping item, ir.Sleeping   ' Must be last setting
  467.       End If
  468.     Next i
  469.  
  470.     ' Manage owner nodes
  471.     For i = 1 To NodeCount
  472.       If owner(i) <> 0 Then
  473.         .SetNodeOwner node(i), node(owner(i))
  474.       End If
  475.     Next i
  476.  
  477.     ' List of link
  478.     For i = 1 To LinkCount
  479.       Line Input #1, s  ' Skip Begin keyword
  480.       length = InStr(s, " ")
  481.       keyword = Left$(s, length - 1)
  482.     
  483.       If keyword = "Begin" Then
  484.         ' Default values
  485.         ir.Type = 0
  486.         ir.Data = 0
  487.         ir.ItemTag = ""
  488.         ir.Text = ""
  489.         ir.ForeColor = .GetItemForeColor(0)
  490.         ir.DrawColor = .GetItemDrawColor(0)
  491.         ir.DrawWidth = .GetItemDrawWidth(0)
  492.         ir.DrawStyle = .GetItemDrawStyle(0)
  493.         ir.Sleeping = .IsItemSleeping(0)
  494.         ir.Hiding = .IsItemHiding(0)
  495.         ir.Oriented = .IsLinkOriented(0)
  496.         ir.LinkHead = .GetLinkArrowHead(0)
  497.         ir.SrcNode = 0
  498.         ir.DstNode = 0
  499.         ir.Points = 0
  500.   
  501.         Do
  502.           Line Input #1, s  ' Skip Begin keyword
  503.           s = LTrim$(s)
  504.           length = InStr(s, " ")
  505.           If length > 0 Then
  506.             keyword = Left$(s, length - 1)
  507.           Else
  508.             keyword = s
  509.           End If
  510.           If keyword = "End" Then
  511.             Exit Do
  512.           End If
  513.           value = Mid$(s, length + 2)
  514.  
  515.           ' Load each link property
  516.           Select Case keyword
  517.           Case "Type"
  518.             ir.Type = Val(value)
  519.           Case "Data"
  520.             ir.Data = Val(value)
  521.           Case "ForeColor"
  522.             ir.ForeColor = Val(value)
  523.           Case "DrawColor"
  524.             ir.DrawColor = Val(value)
  525.           Case "DrawWidth"
  526.             ir.DrawWidth = Val(value)
  527.           Case "DrawStyle"
  528.             ir.DrawStyle = Val(value)
  529.           Case "Sleeping"
  530.             ir.Sleeping = Val(value)
  531.           Case "Hiding"
  532.             ir.Hiding = Val(value)
  533.           Case "Oriented"
  534.             ir.Oriented = Val(value)
  535.           Case "LinkHead"
  536.             ir.LinkHead = Val(value)
  537.           Case "ItemTag"
  538.             If ir.ItemTag = "" Then
  539.               ir.ItemTag = value
  540.             Else
  541.               ir.ItemTag = ir.ItemTag + CRLF + value
  542.             End If
  543.           Case "Text"
  544.             If ir.Text = "" Then
  545.               ir.Text = value
  546.             Else
  547.               ir.Text = ir.Text + CRLF + value
  548.             End If
  549.           Case "Src"
  550.             ir.SrcNode = node(Val(value))
  551.           Case "Dst"
  552.             ir.DstNode = node(Val(value))
  553.           Case "Points"
  554.             ir.Points = Val(value)
  555.  
  556.             ' Get points
  557.             If ir.Points > 0 Then
  558.               ReDim ptx(1 To ir.Points)
  559.               ReDim pty(1 To ir.Points)
  560.               For l = 1 To ir.Points
  561.                 Line Input #1, s  ' Read point
  562.                 s = LTrim$(s)
  563.                 length = InStr(s, ",")
  564.                 ptx(l) = Val(Left$(s, length - 1))
  565.                 pty(l) = Val(Mid$(s, length + 1))
  566.               Next l
  567.             End If
  568.           End Select
  569.         Loop
  570.  
  571.         ' Create Link
  572.         item = .AddLinkItem(ir.SrcNode, ir.DstNode)
  573.  
  574.         .SetItemShort item, ir.Type
  575.         .SetItemLong item, ir.Data
  576.         .SetItemForeColor item, ir.ForeColor
  577.         .SetItemDrawColor item, ir.DrawColor
  578.         .SetItemDrawWidth item, ir.DrawWidth
  579.         .SetItemDrawStyle item, ir.DrawStyle
  580.         .SetItemHiding item, ir.Hiding
  581.         .SetLinkOriented item, ir.Oriented
  582.         .SetLinkArrowHead item, ir.LinkHead
  583.         .SetItemTag item, ir.ItemTag
  584.         .SetItemText item, ir.Text
  585.         .SetLinkPointCount item, ir.Points
  586.         For l = 1 To ir.Points
  587.           .SetLinkPointX item, l, ptx(l)
  588.           .SetLinkPointY item, l, pty(l)
  589.         Next
  590.         .SetItemSleeping item, ir.Sleeping  ' Must be last setting
  591.       End If
  592.     Next i
  593.   End With
  594.   
  595.   ' Erase dynamic arrays
  596.   Erase ptx
  597.   Erase pty
  598.   Erase node
  599.   Erase owner
  600.  
  601.   ' Close file
  602.   Close
  603. End Sub
  604.  
  605.  
  606.  
  607.  
  608.  
  609.