Advertisement
Guest User

CurrentFile

a guest
Apr 24th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 13.92 KB | None | 0 0
  1. Imports System.Xml
  2. Imports System.Xml.Linq
  3. Imports System.IO
  4. Public Class Form1
  5.     Public FILENAME As String = String.Empty
  6.     Public models As Model
  7.     Public productionBlocks As New Panel
  8.     Public pictureBlocks As New List(Of PictureBox)
  9.     Public gridsinfo As CubeGrid
  10.  
  11.     Public dictCount As New Dictionary(Of String, Integer)
  12.     Public dictionay As New Dictionary(Of String, String)
  13.     Public fileloader As New OpenFileDialog
  14.  
  15.     Dim NUMBER_OF_PANELS = 0
  16.  
  17.     Const MAIN_PANEL_WIDTH As Integer = 1000
  18.     Const MAIN_PANEL_HEIGHT As Integer = 1000
  19.     Const MAIN_PANEL_TOP As Integer = 50
  20.     Const MAIN_PANEL_LEFT As Integer = 50
  21.  
  22.     Const PANEL_COLUMNS As Integer = 5
  23.     Const PANEL_WIDTH_MARGIN As Integer = 10
  24.     Const PANEL_HEIGHT_MARGIN As Integer = 10
  25.  
  26.     Const PANEL_WIDTH As Integer = (MAIN_PANEL_WIDTH / PANEL_COLUMNS) - PANEL_WIDTH_MARGIN
  27.  
  28.     Dim PANEL_ROWS As Integer = 0
  29.     Dim PANEL_HEIGHT As Integer = 0
  30.  
  31.     Dim PICTURE_BOX_MARGIN As Integer = 0
  32.  
  33.     Dim PICTURE_BOX_WIDTH As Integer = PANEL_WIDTH
  34.     Dim PICTURE_BOX_HEIGHT As Integer = 0
  35.     Const PICTURE_BOX_TOP As Integer = 0
  36.     Const PICTURE_BOX_LEFT As Integer = 0
  37.  
  38.     Dim LABEL_WIDTH As Integer = PANEL_WIDTH
  39.     Dim LABEL_HEIGHT As Integer = 0
  40.     Dim LABEL_TOP As Integer = 0
  41.     Dim LABEL_LEFT As Int16 = 0
  42.  
  43.     Dim IMAGE_PATH As String = "E:\VS Projects\Resources\SE\Cubes\ArmorCenter.jpg"
  44.  
  45.     Public _model As Model
  46.     Public mainPanel As New CubeGrid
  47.     Public subPanels As New List(Of CubeBlock)
  48.  
  49.  
  50.     Sub New()
  51.         ' This call is required by the designer.
  52.         InitializeComponent()
  53.     End Sub
  54.  
  55.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles Me.Load
  56.     End Sub
  57.  
  58.     Sub CalulateControlSizes(numberOfPanels As Integer)
  59.         PANEL_ROWS = Math.Ceiling(NUMBER_OF_PANELS / PANEL_COLUMNS)
  60.         'PANEL_HEIGHT = (MAIN_PANEL_HEIGHT / PANEL_ROWS) - PANEL_HEIGHT_MARGIN
  61.         PANEL_HEIGHT = 200
  62.  
  63.         PICTURE_BOX_MARGIN = 0.1 * PANEL_HEIGHT
  64.  
  65.         PICTURE_BOX_HEIGHT = 0.8 * PANEL_HEIGHT
  66.  
  67.         LABEL_HEIGHT = 0.1 * PANEL_HEIGHT
  68.         LABEL_TOP = PICTURE_BOX_HEIGHT + PANEL_HEIGHT_MARGIN
  69.  
  70.     End Sub
  71.  
  72.  
  73.  
  74.  
  75.     'FindWords Function to get count of items
  76.     Private Function FindWords(ByVal TextSearched As String, ByVal Paragraph As String) As Integer
  77.         Dim location As Integer = 0
  78.         Dim occurances As Integer = 0
  79.  
  80.         Do
  81.             location = TextSearched.IndexOf(Paragraph, location)
  82.             If location <> -1 Then
  83.                 occurances += 1
  84.                 location += Paragraph.Length
  85.             End If
  86.         Loop Until location = -1
  87.         Return occurances
  88.     End Function
  89.  
  90.  
  91.     'Open Button
  92.     Private Sub PictureBox1_MouseEnter(sender As Object, e As EventArgs) Handles PictureBox1.MouseEnter
  93.         PictureBox1.BorderStyle = BorderStyle.Fixed3D
  94.     End Sub
  95.  
  96.     Private Sub PictureBox1_MouseLeave(sender As Object, e As EventArgs) Handles PictureBox1.MouseLeave
  97.         PictureBox1.BorderStyle = BorderStyle.FixedSingle
  98.     End Sub
  99.  
  100.     Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
  101.         'Resetting the list box when new file is loaded
  102.         Try
  103.             For Each item In ListBox1.Items
  104.                 ListBox1.Items.Remove(item)
  105.             Next
  106.         Catch ex As Exception
  107.         End Try
  108.  
  109.         'pre-load initialization
  110.         fileloader.ShowDialog()
  111.         FILENAME = fileloader.FileName
  112.         models = New Model
  113.         models.Load(FILENAME)
  114.  
  115.         'Grabbing information from XML file
  116.         Dim blockNames As List(Of String) = models.print.Select(Function(x) x.cubes.Select(Function(y) y.cubeBlocks.Select(Function(z) z.SubtypeName)).SelectMany(Function(y) y).ToList()).FirstOrDefault()
  117.         dictCount = blockNames.GroupBy(Function(x) x).ToDictionary(Function(x) x.Key, Function(y) y.Count)
  118.         Dim display As String = models.print2.Select(Function(x) x.cubes.Select(Function(y) y.displayname)).SelectMany(Function(y) y).FirstOrDefault.ToString
  119.         Dim gridsizeenum As String = models.print3.Select(Function(x) x.cubes.Select(Function(y) y.enumerator)).SelectMany(Function(y) y).FirstOrDefault.ToString
  120.         'Dim ownername As String = models.print4.Select(Function(x) x.cubes.Select(Function(y) y.ownername)).SelectMany(Function(y) y).FirstOrDefault.ToString
  121.  
  122.         'Load items into the listbox
  123.         For Each item In dictCount
  124.             ListBox1.Items.Add(item.ToString)
  125.         Next item
  126.  
  127.         'a useless dictionary method [UN-USED]
  128.         For Each key As String In dictCount.Keys.AsEnumerable()
  129.             Dim keylist As String = "subTypeName = '{0}', count = '{1}'" + key.ToString + dictCount(key).ToString
  130.         Next key
  131.  
  132.         'Load Text from XML to the read only boxes
  133.         InfluenceTextBox2.Text = "Grid Name: " + display.ToString
  134.         InfluenceTextBox3.Text = "Grid Type: " + gridsizeenum.ToString + " Ship"
  135.         'InfluenceTextBox1.Text = "Owner Name: " + ownername.ToString
  136.  
  137.  
  138.  
  139.         'Gui Displaying
  140.         Dim reader As New StreamReader(FILENAME)
  141.         Dim doc As XDocument = XDocument.Load(reader)
  142.         Dim xmlstring As String = doc.ToString
  143.  
  144.         LightArmorBlockText.Text = "Qty: " + FindWords(xmlstring, "LargeBlockArmorBlock").ToString
  145.         LightArmorSlopeText.Text = "Qty: " + FindWords(xmlstring, "LargeBlockArmorSlope").ToString
  146.         LightArmorCornerText.Text = "Qty: " + FindWords(xmlstring, "LargeBlockArmorCorner").ToString
  147.         LightArmorCornerInvertedText.Text = "Qty: " + FindWords(xmlstring, "LargeBlockArmorInvCorner").ToString
  148.  
  149.  
  150.  
  151.         'Function to calculate oxygentanks and hydrogen tanks
  152.         Dim tanks As Integer = FindWords(xmlstring, "MyObjectBuilder_OxygenTank").ToString
  153.         Dim oxygentanks As Integer = tanks - FindWords(xmlstring, "LargeHydrogenTank").ToString
  154.         OxygenTanksText.Text = "Qty: " + oxygentanks.ToString
  155.         HydrogenTanksText.Text = "Qty: " + FindWords(xmlstring, "LargeHydrogenTank").ToString
  156.  
  157.  
  158.  
  159.  
  160.  
  161.         dictionay = blockNames.GroupBy(Function(x) x).ToDictionary(Function(x) x.Key, Function(y) y.Key)
  162.         'Procedural Control Generation
  163.  
  164.         _model = New Model()
  165.         _model.Load(FILENAME)
  166.  
  167.         NUMBER_OF_PANELS = _model.print.cubes(0).cubeBlocks.Count
  168.         CalulateControlSizes(NUMBER_OF_PANELS)
  169.  
  170.         mainPanel = _model.print.cubes(0)
  171.         mainPanel.Height = MAIN_PANEL_HEIGHT
  172.         mainPanel.Width = MAIN_PANEL_WIDTH
  173.         mainPanel.Top = MAIN_PANEL_TOP
  174.         mainPanel.Left = MAIN_PANEL_LEFT
  175.  
  176.         mainPanel.AutoScroll = True
  177.         mainPanel.VerticalScroll.Visible = True
  178.         mainPanel.HorizontalScroll.Visible = True
  179.         Me.Controls.Add(mainPanel)
  180.  
  181.         For panelNumber As Integer = 0 To (NUMBER_OF_PANELS - 1)
  182.             Dim row As Integer = Math.Floor(panelNumber / PANEL_COLUMNS)
  183.             Dim col As Integer = panelNumber Mod PANEL_COLUMNS
  184.  
  185.             Dim newPanel As CubeBlock = _model.print.cubes(0).cubeBlocks(panelNumber)
  186.             newPanel.Top = row * (PANEL_HEIGHT + PANEL_HEIGHT_MARGIN)
  187.             newPanel.Left = col * (PANEL_WIDTH + PANEL_WIDTH_MARGIN)
  188.             newPanel.Width = PANEL_WIDTH
  189.             newPanel.Height = PANEL_HEIGHT
  190.             mainPanel.Controls.Add(newPanel)
  191.             subPanels.Add(newPanel)
  192.  
  193.             Dim newPicture As New PictureBox()
  194.             newPicture.Height = PICTURE_BOX_HEIGHT
  195.             newPicture.Width = PICTURE_BOX_WIDTH
  196.             newPicture.Top = PICTURE_BOX_TOP
  197.             newPicture.Left = PICTURE_BOX_LEFT
  198.             newPicture.Image = Image.FromFile(IMAGE_PATH)
  199.             newPanel.Controls.Add(newPicture)
  200.  
  201.             Dim newLabel As New Label
  202.             newLabel.Height = LABEL_HEIGHT
  203.             newLabel.Width = LABEL_WIDTH
  204.             newLabel.Top = LABEL_TOP
  205.             newLabel.Left = LABEL_LEFT
  206.             newLabel.Text = newPanel.SubtypeName & "(" & newPanel.count & ")"
  207.             newLabel.BackColor = SystemColors.Window
  208.             newLabel.ForeColor = SystemColors.WindowText
  209.  
  210.             newPanel.Controls.Add(newLabel)
  211.  
  212.         Next panelNumber
  213.     End Sub
  214.     'END OPEN BUTTON
  215.  
  216.  
  217.     'Contributors Section
  218.     Private Sub InfluenceTopButton1_Click(sender As Object, e As EventArgs) Handles InfluenceTopButton1.Click
  219.         Form2.Show()
  220.     End Sub
  221.  
  222.  
  223.     'XML INPUT LOADING FUNCTION
  224. End Class
  225. Public Class Model
  226.     Public print As New List(Of Model)
  227.     Public print2 As New List(Of Model)
  228.     Public print3 As New List(Of Model)
  229.     Public print4 As New List(Of Model)
  230.     Public _type As String
  231.     Public _id As ID
  232.     Public _display As String
  233.     Public _display1 As String
  234.     Public displayname As String
  235.     Public enumerator As String
  236.     Public cubes As List(Of CubeGrid)
  237.     Public info As String
  238.     Public Sub Load(filename As String)
  239.         Dim reader As New StreamReader(filename)
  240.         Dim doc As XDocument = XDocument.Load(reader)
  241.         Dim firstNode As XElement = doc.FirstNode
  242.         Dim xsiNs = firstNode.GetNamespaceOfPrefix("xsi")
  243.         Dim drawingTypes = firstNode.Elements.FirstOrDefault()
  244.         Dim drawingType = drawingTypes.Elements.FirstOrDefault()
  245.         Dim drawingStr = drawingType.Name.LocalName
  246.         print = doc.Descendants(drawingStr).Select(Function(x) New Model() With {
  247.            ._type = x.Attribute(xsiNs + "type"), ._id = x.Elements("Id").Select(Function(y) New ID() With {
  248.                                               .type = y.Attribute("Type"),
  249.                                               .subtype = y.Attribute("Subtype")
  250.                                           }).FirstOrDefault(),
  251.            .cubes = x.Descendants("CubeGrid").Select(Function(y) New CubeGrid() With {
  252.                                                       .id = y.Element("EntityId"),
  253.                                                       .persistentFlags = y.Element("PersistentFlags"),
  254.                                                       .position = y.Descendants("Position").Select(Function(z) New location() With {
  255.                                                         .x = CType(z.Attribute("x"), Double),
  256.                                                         .y = CType(z.Attribute("y"), Double),
  257.                                                         .z = CType(z.Attribute("z"), Double)
  258.                                                       }).FirstOrDefault(),
  259.                                                       .forward = y.Descendants("Forward").Select(Function(z) New location() With {
  260.                                                         .x = CType(z.Attribute("x"), Double),
  261.                                                         .y = CType(z.Attribute("y"), Double),
  262.                                                         .z = CType(z.Attribute("z"), Double)
  263.                                                       }).FirstOrDefault(),
  264.                                                       .up = y.Descendants("Up").Select(Function(z) New location() With {
  265.                                                         .x = CType(z.Attribute("x"), Double),
  266.                                                         .y = CType(z.Attribute("y"), Double),
  267.                                                         .z = CType(z.Attribute("z"), Double)
  268.                                                       }).FirstOrDefault(),
  269.                                                       .orientation = y.Descendants("Orientation").Select(Function(z) New location() With {
  270.                                                         .w = CType(z.Element("W"), Double),
  271.                                                         .x = CType(z.Element("X"), Double),
  272.                                                         .y = CType(z.Element("Y"), Double),
  273.                                                         .z = CType(z.Element("Z"), Double)
  274.                                                       }).FirstOrDefault(),
  275.                                                       .cubeBlocks = y.Descendants("MyObjectBuilder_CubeBlock").Select(Function(z) New CubeBlock() With {
  276.                                                         .SubtypeName = z.Element("SubtypeName")
  277.                                                       }).ToList()
  278.                                                   }).ToList()
  279.         }).ToList()
  280.  
  281.  
  282.  
  283.         print2 = doc.Descendants(drawingStr).Select(Function(x) New Model() With {
  284.             .cubes = x.Descendants("CubeGrid").Select(Function(y) New CubeGrid() With {
  285.                 .displayname = y.Element("DisplayName")
  286.             }).ToList()
  287.         }).ToList()
  288.  
  289.         print3 = doc.Descendants(drawingStr).Select(Function(x) New Model() With {
  290.         .cubes = x.Descendants("CubeGrid").Select(Function(y) New CubeGrid() With {
  291.             .enumerator = y.Element("GridSizeEnum")
  292.             }).ToList()
  293.         }).ToList()
  294.  
  295.         'Not Working - Gets owner name
  296.         print4 = doc.Descendants(drawingStr).Select(Function(x) New Model() With {
  297.             .cubes = x.Descendants("MyObjectBuilder_ShipBlueprintDefinition").Select(Function(y) New CubeGrid() With {
  298.                 .ownername = y.Element("DisplayName")
  299.             }).ToList()
  300.         }).ToList()
  301.     End Sub
  302. End Class
  303. Public Class ID
  304.     Public type As String
  305.     Public subtype As String
  306. End Class
  307. Public Class CubeGrid
  308.     Inherits Panel
  309.  
  310.     Public id As String
  311.     Public persistentFlags As String
  312.     Public position As location
  313.     Public forward As location
  314.     Public up As location
  315.     Public orientation As location
  316.     Public cubeBlocks As List(Of CubeBlock)
  317.  
  318.     Public displayname As String
  319.     Public ownername As String
  320.     Public enumerator As String
  321. End Class
  322. Public Class location
  323.     Public w As Double
  324.     Public x As Double
  325.     Public y As Double
  326.     Public z As Double
  327. End Class
  328. Public Class CubeBlock
  329.     Inherits Panel
  330.  
  331.     Public SubtypeName As String
  332.     Public username As String
  333.     Public count As Integer
  334. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement