Advertisement
Guest User

cur

a guest
Apr 26th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 13.63 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 System.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.cubes.cubeBlocks.Select(Function(x) x.SubtypeName).ToList()
  117.         dictCount = blockNames.GroupBy(Function(x) x).ToDictionary(Function(x) x.Key, Function(y) y.Count)
  118.         Dim display As String = models.print2.cubes.displayname
  119.         Dim gridsizeenum As String = models.print3.cubes.enumerator
  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 blockNames
  124.             ListBox1.Items.Add(item.ToString)
  125.         Next item
  126.  
  127.         For Each Item As Object In ListBox1.Items
  128.             TextBox1.Text += (Item & ",")
  129.         Next
  130.  
  131.         'Load Text from XML to the read only boxes
  132.         InfluenceTextBox2.Text = "Grid Name: " + display.ToString
  133.         InfluenceTextBox3.Text = "Grid Type: " + gridsizeenum.ToString + " Ship"
  134.         'InfluenceTextBox1.Text = "Owner Name: " + ownername.ToString
  135.  
  136.  
  137.  
  138.         'Gui Displaying
  139.         Dim reader As New StreamReader(FILENAME)
  140.         Dim doc As XDocument = XDocument.Load(reader)
  141.         Dim xmlstring As String = doc.ToString
  142.         'Function to calculate oxygentanks and hydrogen tanks
  143.         Dim tanks As Integer = FindWords(xmlstring, "MyObjectBuilder_OxygenTank").ToString
  144.         Dim oxygentanks As Integer = tanks - FindWords(xmlstring, "LargeHydrogenTank").ToString
  145.         dictionay = blockNames.GroupBy(Function(x) x).ToDictionary(Function(x) x.Key, Function(y) y.Key)
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.         'Procedural Control Generation
  154.         _model = New Model()
  155.         _model.Load(FILENAME)
  156.  
  157.         NUMBER_OF_PANELS = _model.print.cubes.cubeBlocks.Count
  158.         CalulateControlSizes(NUMBER_OF_PANELS)
  159.  
  160.         mainPanel = _model.print.cubes
  161.         mainPanel.Height = MAIN_PANEL_HEIGHT
  162.         mainPanel.Width = MAIN_PANEL_WIDTH
  163.         mainPanel.Top = MAIN_PANEL_TOP
  164.         mainPanel.Left = MAIN_PANEL_LEFT
  165.         mainPanel.BackColor = Color.FromArgb(24, 24, 24)
  166.         mainPanel.ForeColor = Color.White
  167.  
  168.         mainPanel.AutoScroll = True
  169.         mainPanel.VerticalScroll.Visible = True
  170.         mainPanel.HorizontalScroll.Visible = True
  171.         Me.Controls.Add(mainPanel)
  172.         'mainPanel.BringToFront()
  173.  
  174.         For panelNumber As Integer = 0 To (NUMBER_OF_PANELS - 1)
  175.             Dim row As Integer = Math.Floor(panelNumber / PANEL_COLUMNS)
  176.             Dim col As Integer = panelNumber Mod PANEL_COLUMNS
  177.  
  178.             Dim newPanel As CubeBlock = _model.print.cubes.cubeBlocks(panelNumber)
  179.             newPanel.Top = row * (PANEL_HEIGHT + PANEL_HEIGHT_MARGIN)
  180.             newPanel.Left = col * (PANEL_WIDTH + PANEL_WIDTH_MARGIN)
  181.             newPanel.Width = PANEL_WIDTH
  182.             newPanel.Height = PANEL_HEIGHT
  183.             newPanel.BackColor = Color.FromArgb(24, 24, 24)
  184.             newPanel.ForeColor = Color.White
  185.             mainPanel.Controls.Add(newPanel)
  186.  
  187.             subPanels.Add(newPanel)
  188.  
  189.             Dim blockname As String = newPanel.SubtypeName
  190.  
  191.             Dim newPicture As New PictureBox()
  192.             newPicture.Height = 64
  193.             newPicture.Width = 64
  194.             newPicture.Top = PICTURE_BOX_TOP
  195.             newPicture.Left = PICTURE_BOX_LEFT
  196.             newPicture.BackgroundImageLayout = ImageLayout.Stretch
  197.             newPicture.BackgroundImage = DirectCast(My.Resources.ResourceManager.GetObject(blockname), Bitmap)
  198.             newPicture.BackColor = Color.FromArgb(24, 24, 24)
  199.             newPanel.Controls.Add(newPicture)
  200.             FlowLayoutPanel1.Controls.Add(newPicture)
  201.  
  202.             Dim newLabel As New Label
  203.             newLabel.Height = LABEL_HEIGHT
  204.             newLabel.Width = LABEL_WIDTH
  205.             newLabel.Top = LABEL_TOP
  206.             newLabel.Left = LABEL_LEFT
  207.             newLabel.BackColor = Color.Transparent
  208.             newLabel.ForeColor = Color.White
  209.             newLabel.Text = newPanel.SubtypeName & "(" & newPanel.count & ")"
  210.  
  211.             newPanel.Controls.Add(newLabel)
  212.             'FlowLayoutPanel1.Controls.Add(newLabel)
  213.         Next panelNumber
  214.     End Sub
  215.     'END OPEN BUTTON
  216.  
  217.  
  218.     'Contributors Section
  219.     Private Sub InfluenceTopButton1_Click(sender As Object, e As EventArgs) Handles InfluenceTopButton1.Click
  220.         'Form2.Show()
  221.     End Sub
  222.  
  223.  
  224.     'XML INPUT LOADING FUNCTION
  225. End Class
  226. Public Class Model
  227.     Public print As Model
  228.     Public print2 As Model
  229.     Public print3 As Model
  230.     Public print4 As Model
  231.     Public _type As String
  232.     Public _id As ID
  233.     Public _display As String
  234.     Public _display1 As String
  235.     Public displayname As String
  236.     Public enumerator As String
  237.     Public cubes As New CubeGrid
  238.     Public info As String
  239.     Public Sub Load(filename As String)
  240.         Dim reader As New StreamReader(filename)
  241.         Dim doc As XDocument = XDocument.Load(reader)
  242.         Dim firstNode As XElement = doc.FirstNode
  243.         Dim xsiNs = firstNode.GetNamespaceOfPrefix("xsi")
  244.         Dim drawingTypes = firstNode.Elements.FirstOrDefault()
  245.         Dim drawingType = drawingTypes.Elements.FirstOrDefault()
  246.         Dim drawingStr = drawingType.Name.LocalName
  247.         print = doc.Descendants(drawingStr).Select(Function(x) New Model() With {
  248.            ._type = x.Attribute(xsiNs + "type"), ._id = x.Elements("Id").Select(Function(y) New ID() With {
  249.                                               .type = y.Attribute("Type"),
  250.                                               .subtype = y.Attribute("Subtype")
  251.                                           }).FirstOrDefault(),
  252.            .cubes = x.Descendants("CubeGrid").Select(Function(y) New CubeGrid() With {
  253.                                                       .id = y.Element("EntityId"),
  254.                                                       .persistentFlags = y.Element("PersistentFlags"),
  255.                                                       .position = y.Descendants("Position").Select(Function(z) New location() With {
  256.                                                         .x = CType(z.Attribute("x"), Double),
  257.                                                         .y = CType(z.Attribute("y"), Double),
  258.                                                         .z = CType(z.Attribute("z"), Double)
  259.                                                       }).FirstOrDefault(),
  260.                                                       .forward = y.Descendants("Forward").Select(Function(z) New location() With {
  261.                                                         .x = CType(z.Attribute("x"), Double),
  262.                                                         .y = CType(z.Attribute("y"), Double),
  263.                                                         .z = CType(z.Attribute("z"), Double)
  264.                                                       }).FirstOrDefault(),
  265.                                                       .up = y.Descendants("Up").Select(Function(z) New location() With {
  266.                                                         .x = CType(z.Attribute("x"), Double),
  267.                                                         .y = CType(z.Attribute("y"), Double),
  268.                                                         .z = CType(z.Attribute("z"), Double)
  269.                                                       }).FirstOrDefault(),
  270.                                                       .orientation = y.Descendants("Orientation").Select(Function(z) New location() With {
  271.                                                         .w = CType(z.Element("W"), Double),
  272.                                                         .x = CType(z.Element("X"), Double),
  273.                                                         .y = CType(z.Element("Y"), Double),
  274.                                                         .z = CType(z.Element("Z"), Double)
  275.                                                       }).FirstOrDefault(),
  276.                                                       .cubeBlocks = y.Descendants("MyObjectBuilder_CubeBlock").GroupBy(Function(z) CType(z.Element("SubtypeName"), String)).Select(Function(z) New CubeBlock() With {
  277.                                                         .SubtypeName = z.Key,
  278.                                                         .count = z.Count
  279.                                                       }).OrderBy(Function(z) z.SubtypeName).ToList()
  280.                                                   }).FirstOrDefault()
  281.         }).FirstOrDefault
  282.  
  283.  
  284.  
  285.         print2 = doc.Descendants(drawingStr).Select(Function(x) New Model() With {
  286.             .cubes = x.Descendants("CubeGrid").Select(Function(y) New CubeGrid() With {
  287.                 .displayname = y.Element("DisplayName")
  288.             }).FirstOrDefault
  289.         }).FirstOrDefault()
  290.  
  291.         print3 = doc.Descendants(drawingStr).Select(Function(x) New Model() With {
  292.         .cubes = x.Descendants("CubeGrid").Select(Function(y) New CubeGrid() With {
  293.             .enumerator = y.Element("GridSizeEnum")
  294.             }).FirstOrDefault
  295.         }).FirstOrDefault
  296.  
  297.         'Not Working - Gets owner name
  298.         print4 = doc.Descendants(drawingStr).Select(Function(x) New Model() With {
  299.             .cubes = x.Descendants("MyObjectBuilder_ShipBlueprintDefinition").Select(Function(y) New CubeGrid() With {
  300.                 .ownername = y.Element("DisplayName")
  301.             }).FirstOrDefault
  302.         }).FirstOrDefault
  303.     End Sub
  304. End Class
  305. Public Class ID
  306.     Public type As String
  307.     Public subtype As String
  308. End Class
  309. Public Class CubeGrid
  310.     Inherits Panel
  311.  
  312.     Public id As String
  313.     Public persistentFlags As String
  314.     Public position As location
  315.     Public forward As location
  316.     Public up As location
  317.     Public orientation As location
  318.     Public cubeBlocks As List(Of CubeBlock)
  319.  
  320.     Public displayname As String
  321.     Public ownername As String
  322.     Public enumerator As String
  323. End Class
  324. Public Class location
  325.     Public w As Double
  326.     Public x As Double
  327.     Public y As Double
  328.     Public z As Double
  329. End Class
  330. Public Class CubeBlock
  331.     Inherits Panel
  332.  
  333.     Public SubtypeName As String
  334.     Public username As String
  335.     Public count As Integer
  336. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement