Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Xml
- Imports System.Xml.Linq
- Imports System.IO
- Public Class Form1
- Public FILENAME As String = String.Empty
- Public models As Model
- Public productionBlocks As New Panel
- Public pictureBlocks As New List(Of PictureBox)
- Public gridsinfo As CubeGrid
- Public dictCount As New Dictionary(Of String, Integer)
- Public dictionay As New Dictionary(Of String, String)
- Public fileloader As New OpenFileDialog
- Dim NUMBER_OF_PANELS = 0
- Const MAIN_PANEL_WIDTH As Integer = 1000
- Const MAIN_PANEL_HEIGHT As Integer = 1000
- Const MAIN_PANEL_TOP As Integer = 50
- Const MAIN_PANEL_LEFT As Integer = 50
- Const PANEL_COLUMNS As Integer = 5
- Const PANEL_WIDTH_MARGIN As Integer = 10
- Const PANEL_HEIGHT_MARGIN As Integer = 10
- Const PANEL_WIDTH As Integer = (MAIN_PANEL_WIDTH / PANEL_COLUMNS) - PANEL_WIDTH_MARGIN
- Dim PANEL_ROWS As Integer = 0
- Dim PANEL_HEIGHT As Integer = 0
- Dim PICTURE_BOX_MARGIN As Integer = 0
- Dim PICTURE_BOX_WIDTH As Integer = PANEL_WIDTH
- Dim PICTURE_BOX_HEIGHT As Integer = 0
- Const PICTURE_BOX_TOP As Integer = 0
- Const PICTURE_BOX_LEFT As Integer = 0
- Dim LABEL_WIDTH As Integer = PANEL_WIDTH
- Dim LABEL_HEIGHT As Integer = 0
- Dim LABEL_TOP As Integer = 0
- Dim LABEL_LEFT As Int16 = 0
- Dim IMAGE_PATH As String = "E:\VS Projects\Resources\SE\Cubes\ArmorCenter.jpg"
- Public _model As Model
- Public mainPanel As New CubeGrid
- Public subPanels As New List(Of CubeBlock)
- Sub New()
- ' This call is required by the designer.
- InitializeComponent()
- End Sub
- Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles Me.Load
- End Sub
- Sub CalulateControlSizes(numberOfPanels As Integer)
- PANEL_ROWS = Math.Ceiling(NUMBER_OF_PANELS / PANEL_COLUMNS)
- 'PANEL_HEIGHT = (MAIN_PANEL_HEIGHT / PANEL_ROWS) - PANEL_HEIGHT_MARGIN
- PANEL_HEIGHT = 200
- PICTURE_BOX_MARGIN = 0.1 * PANEL_HEIGHT
- PICTURE_BOX_HEIGHT = 0.8 * PANEL_HEIGHT
- LABEL_HEIGHT = 0.1 * PANEL_HEIGHT
- LABEL_TOP = PICTURE_BOX_HEIGHT + PANEL_HEIGHT_MARGIN
- End Sub
- 'FindWords Function to get count of items
- Private Function FindWords(ByVal TextSearched As String, ByVal Paragraph As String) As Integer
- Dim location As Integer = 0
- Dim occurances As Integer = 0
- Do
- location = TextSearched.IndexOf(Paragraph, location)
- If location <> -1 Then
- occurances += 1
- location += Paragraph.Length
- End If
- Loop Until location = -1
- Return occurances
- End Function
- 'Open Button
- Private Sub PictureBox1_MouseEnter(sender As Object, e As EventArgs) Handles PictureBox1.MouseEnter
- PictureBox1.BorderStyle = BorderStyle.Fixed3D
- End Sub
- Private Sub PictureBox1_MouseLeave(sender As Object, e As EventArgs) Handles PictureBox1.MouseLeave
- PictureBox1.BorderStyle = BorderStyle.FixedSingle
- End Sub
- Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
- 'Resetting the list box when new file is loaded
- Try
- For Each item In ListBox1.Items
- ListBox1.Items.Remove(item)
- Next
- Catch ex As Exception
- End Try
- 'pre-load initialization
- fileloader.ShowDialog()
- FILENAME = fileloader.FileName
- models = New Model
- models.Load(FILENAME)
- 'Grabbing information from XML file
- 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()
- dictCount = blockNames.GroupBy(Function(x) x).ToDictionary(Function(x) x.Key, Function(y) y.Count)
- Dim display As String = models.print2.Select(Function(x) x.cubes.Select(Function(y) y.displayname)).SelectMany(Function(y) y).FirstOrDefault.ToString
- Dim gridsizeenum As String = models.print3.Select(Function(x) x.cubes.Select(Function(y) y.enumerator)).SelectMany(Function(y) y).FirstOrDefault.ToString
- 'Dim ownername As String = models.print4.Select(Function(x) x.cubes.Select(Function(y) y.ownername)).SelectMany(Function(y) y).FirstOrDefault.ToString
- 'Load items into the listbox
- For Each item In dictCount
- ListBox1.Items.Add(item.ToString)
- Next item
- 'a useless dictionary method [UN-USED]
- For Each key As String In dictCount.Keys.AsEnumerable()
- Dim keylist As String = "subTypeName = '{0}', count = '{1}'" + key.ToString + dictCount(key).ToString
- Next key
- 'Load Text from XML to the read only boxes
- InfluenceTextBox2.Text = "Grid Name: " + display.ToString
- InfluenceTextBox3.Text = "Grid Type: " + gridsizeenum.ToString + " Ship"
- 'InfluenceTextBox1.Text = "Owner Name: " + ownername.ToString
- 'Gui Displaying
- Dim reader As New StreamReader(FILENAME)
- Dim doc As XDocument = XDocument.Load(reader)
- Dim xmlstring As String = doc.ToString
- LightArmorBlockText.Text = "Qty: " + FindWords(xmlstring, "LargeBlockArmorBlock").ToString
- LightArmorSlopeText.Text = "Qty: " + FindWords(xmlstring, "LargeBlockArmorSlope").ToString
- LightArmorCornerText.Text = "Qty: " + FindWords(xmlstring, "LargeBlockArmorCorner").ToString
- LightArmorCornerInvertedText.Text = "Qty: " + FindWords(xmlstring, "LargeBlockArmorInvCorner").ToString
- 'Function to calculate oxygentanks and hydrogen tanks
- Dim tanks As Integer = FindWords(xmlstring, "MyObjectBuilder_OxygenTank").ToString
- Dim oxygentanks As Integer = tanks - FindWords(xmlstring, "LargeHydrogenTank").ToString
- OxygenTanksText.Text = "Qty: " + oxygentanks.ToString
- HydrogenTanksText.Text = "Qty: " + FindWords(xmlstring, "LargeHydrogenTank").ToString
- dictionay = blockNames.GroupBy(Function(x) x).ToDictionary(Function(x) x.Key, Function(y) y.Key)
- 'Procedural Control Generation
- _model = New Model()
- _model.Load(FILENAME)
- NUMBER_OF_PANELS = _model.print.cubes(0).cubeBlocks.Count
- CalulateControlSizes(NUMBER_OF_PANELS)
- mainPanel = _model.print.cubes(0)
- mainPanel.Height = MAIN_PANEL_HEIGHT
- mainPanel.Width = MAIN_PANEL_WIDTH
- mainPanel.Top = MAIN_PANEL_TOP
- mainPanel.Left = MAIN_PANEL_LEFT
- mainPanel.AutoScroll = True
- mainPanel.VerticalScroll.Visible = True
- mainPanel.HorizontalScroll.Visible = True
- Me.Controls.Add(mainPanel)
- For panelNumber As Integer = 0 To (NUMBER_OF_PANELS - 1)
- Dim row As Integer = Math.Floor(panelNumber / PANEL_COLUMNS)
- Dim col As Integer = panelNumber Mod PANEL_COLUMNS
- Dim newPanel As CubeBlock = _model.print.cubes(0).cubeBlocks(panelNumber)
- newPanel.Top = row * (PANEL_HEIGHT + PANEL_HEIGHT_MARGIN)
- newPanel.Left = col * (PANEL_WIDTH + PANEL_WIDTH_MARGIN)
- newPanel.Width = PANEL_WIDTH
- newPanel.Height = PANEL_HEIGHT
- mainPanel.Controls.Add(newPanel)
- subPanels.Add(newPanel)
- Dim newPicture As New PictureBox()
- newPicture.Height = PICTURE_BOX_HEIGHT
- newPicture.Width = PICTURE_BOX_WIDTH
- newPicture.Top = PICTURE_BOX_TOP
- newPicture.Left = PICTURE_BOX_LEFT
- newPicture.Image = Image.FromFile(IMAGE_PATH)
- newPanel.Controls.Add(newPicture)
- Dim newLabel As New Label
- newLabel.Height = LABEL_HEIGHT
- newLabel.Width = LABEL_WIDTH
- newLabel.Top = LABEL_TOP
- newLabel.Left = LABEL_LEFT
- newLabel.Text = newPanel.SubtypeName & "(" & newPanel.count & ")"
- newLabel.BackColor = SystemColors.Window
- newLabel.ForeColor = SystemColors.WindowText
- newPanel.Controls.Add(newLabel)
- Next panelNumber
- End Sub
- 'END OPEN BUTTON
- 'Contributors Section
- Private Sub InfluenceTopButton1_Click(sender As Object, e As EventArgs) Handles InfluenceTopButton1.Click
- Form2.Show()
- End Sub
- 'XML INPUT LOADING FUNCTION
- End Class
- Public Class Model
- Public print As New List(Of Model)
- Public print2 As New List(Of Model)
- Public print3 As New List(Of Model)
- Public print4 As New List(Of Model)
- Public _type As String
- Public _id As ID
- Public _display As String
- Public _display1 As String
- Public displayname As String
- Public enumerator As String
- Public cubes As List(Of CubeGrid)
- Public info As String
- Public Sub Load(filename As String)
- Dim reader As New StreamReader(filename)
- Dim doc As XDocument = XDocument.Load(reader)
- Dim firstNode As XElement = doc.FirstNode
- Dim xsiNs = firstNode.GetNamespaceOfPrefix("xsi")
- Dim drawingTypes = firstNode.Elements.FirstOrDefault()
- Dim drawingType = drawingTypes.Elements.FirstOrDefault()
- Dim drawingStr = drawingType.Name.LocalName
- print = doc.Descendants(drawingStr).Select(Function(x) New Model() With {
- ._type = x.Attribute(xsiNs + "type"), ._id = x.Elements("Id").Select(Function(y) New ID() With {
- .type = y.Attribute("Type"),
- .subtype = y.Attribute("Subtype")
- }).FirstOrDefault(),
- .cubes = x.Descendants("CubeGrid").Select(Function(y) New CubeGrid() With {
- .id = y.Element("EntityId"),
- .persistentFlags = y.Element("PersistentFlags"),
- .position = y.Descendants("Position").Select(Function(z) New location() With {
- .x = CType(z.Attribute("x"), Double),
- .y = CType(z.Attribute("y"), Double),
- .z = CType(z.Attribute("z"), Double)
- }).FirstOrDefault(),
- .forward = y.Descendants("Forward").Select(Function(z) New location() With {
- .x = CType(z.Attribute("x"), Double),
- .y = CType(z.Attribute("y"), Double),
- .z = CType(z.Attribute("z"), Double)
- }).FirstOrDefault(),
- .up = y.Descendants("Up").Select(Function(z) New location() With {
- .x = CType(z.Attribute("x"), Double),
- .y = CType(z.Attribute("y"), Double),
- .z = CType(z.Attribute("z"), Double)
- }).FirstOrDefault(),
- .orientation = y.Descendants("Orientation").Select(Function(z) New location() With {
- .w = CType(z.Element("W"), Double),
- .x = CType(z.Element("X"), Double),
- .y = CType(z.Element("Y"), Double),
- .z = CType(z.Element("Z"), Double)
- }).FirstOrDefault(),
- .cubeBlocks = y.Descendants("MyObjectBuilder_CubeBlock").Select(Function(z) New CubeBlock() With {
- .SubtypeName = z.Element("SubtypeName")
- }).ToList()
- }).ToList()
- }).ToList()
- print2 = doc.Descendants(drawingStr).Select(Function(x) New Model() With {
- .cubes = x.Descendants("CubeGrid").Select(Function(y) New CubeGrid() With {
- .displayname = y.Element("DisplayName")
- }).ToList()
- }).ToList()
- print3 = doc.Descendants(drawingStr).Select(Function(x) New Model() With {
- .cubes = x.Descendants("CubeGrid").Select(Function(y) New CubeGrid() With {
- .enumerator = y.Element("GridSizeEnum")
- }).ToList()
- }).ToList()
- 'Not Working - Gets owner name
- print4 = doc.Descendants(drawingStr).Select(Function(x) New Model() With {
- .cubes = x.Descendants("MyObjectBuilder_ShipBlueprintDefinition").Select(Function(y) New CubeGrid() With {
- .ownername = y.Element("DisplayName")
- }).ToList()
- }).ToList()
- End Sub
- End Class
- Public Class ID
- Public type As String
- Public subtype As String
- End Class
- Public Class CubeGrid
- Inherits Panel
- Public id As String
- Public persistentFlags As String
- Public position As location
- Public forward As location
- Public up As location
- Public orientation As location
- Public cubeBlocks As List(Of CubeBlock)
- Public displayname As String
- Public ownername As String
- Public enumerator As String
- End Class
- Public Class location
- Public w As Double
- Public x As Double
- Public y As Double
- Public z As Double
- End Class
- Public Class CubeBlock
- Inherits Panel
- Public SubtypeName As String
- Public username As String
- Public count As Integer
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement