Advertisement
Guest User

Untitled

a guest
May 17th, 2018
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include once "aulib/file/AuFile.bas"
  2. #include once "aulib/collection/AuList.bas"
  3.  
  4. using AuLib
  5.  
  6. type control
  7.     as string objectName
  8.     as string objectType
  9.     as string controlType
  10. end type
  11.  
  12. type font
  13.     as string fontName = "Arial"
  14.     as single size = 9
  15. end type
  16.  
  17. type form
  18.     as string objectName
  19.     as string text
  20.     as integer wdth
  21.     as integer hght
  22.     as ubyte backColorR
  23.     as ubyte backColorG
  24.     as ubyte backColorB
  25.    
  26.     as font fnt
  27. end type
  28.  
  29. type label
  30.     as string objectName
  31.     as string text
  32.     as boolean autoSize
  33.     as integer tabIndex
  34.     as integer wdth
  35.     as integer hght
  36.     as integer px
  37.     as integer py
  38.    
  39.     as font fnt
  40. end type
  41.  
  42. type textBox
  43.     as string objectName
  44.     as string text
  45.     as string passwordChar
  46.     as integer maxLength = 32767
  47.     as integer tabIndex
  48.     as integer wdth
  49.     as integer hght
  50.     as integer px
  51.     as integer py
  52.     as boolean multiLine
  53.    
  54.     as font fnt
  55. end type
  56.  
  57. type button
  58.     as string objectName
  59.     as string text
  60.     as boolean autoSize
  61.     as integer tabIndex
  62.     as integer wdth
  63.     as integer hght
  64.     as integer px
  65.     as integer py
  66.    
  67.     as font fnt
  68. end type
  69.  
  70. type spinner
  71.     as string objectName
  72.     as integer tabIndex
  73.     as integer wdth
  74.     as integer hght
  75.     as integer px
  76.     as integer py
  77. end type
  78.  
  79. type grid
  80.     as string objectName
  81.     as integer tabIndex
  82.     as integer wdth
  83.     as integer hght
  84.     as integer px
  85.     as integer py
  86. end type
  87.  
  88. function parseObjectTag(tag as string) as string
  89.     tag = trim(tag, "<")
  90.     tag = trim(tag, ">")
  91.     return tag
  92. end function
  93.  
  94. function trimNewLine(content as string) as string
  95.     return rTrim(content, !"\n")
  96.     '= left(frm.VFP_properties, len(frm.VFP_properties)-1)
  97. end function
  98.  
  99. dim as AuFile file
  100. dim as boolean inObject = false
  101. dim as string currentObject
  102.  
  103.  
  104.  
  105. dim as form frm
  106.  
  107. DeclareList(control)
  108. dim as controlList controls
  109. dim as control ptr cnt
  110.  
  111. DeclareList(label)
  112. dim as labelList labels
  113. dim as label ptr lbl
  114.  
  115. DeclareList(textbox)
  116. dim as textboxList textboxes
  117. dim as textbox ptr txt
  118.  
  119. DeclareList(button)
  120. dim as buttonList buttons
  121. dim as button ptr btn
  122.  
  123. DeclareList(spinner)
  124. dim as spinnerList spinners
  125. dim as spinner ptr spn
  126.  
  127. DeclareList(grid)
  128. dim as gridList grids
  129. dim as grid ptr grd
  130.  
  131. file.openRead("Properties_Output.txt")
  132.  
  133. do
  134.     'Read line
  135.     dim as string curLine = file.readLine()
  136.    
  137.     if(NOT inObject) then
  138.         'Expect the start of an object
  139.         inObject = true
  140.         select case curLine
  141.         case "<FORM>"
  142.             currentObject = parseObjectTag(curLine)
  143.            
  144.         case "<LABEL>"
  145.             currentObject = parseObjectTag(curLine)
  146.             lbl = new label
  147.             cnt = new control
  148.             cnt->objectType = currentObject
  149.             cnt->controlType = "Label"
  150.            
  151.         case "<TEXTBOX>", "<EDITBOX>"
  152.             currentObject = parseObjectTag(curLine)
  153.             txt = new textbox
  154.             cnt = new control
  155.             cnt->objectType = "TEXTBOX"
  156.             cnt->controlType = "TextBox"
  157.             if(currentObject = "TEXTBOX") then
  158.                 txt->multiLine = false
  159.             else
  160.                 txt->multiLine = true
  161.             end if
  162.            
  163.         case "<COMMANDBUTTON>"
  164.             currentObject = parseObjectTag(curLine)
  165.             btn = new button
  166.             cnt = new control
  167.             cnt->objectType = currentObject
  168.             cnt->controlType = "Button"
  169.            
  170.         case "<SPINNER>"
  171.             currentObject = parseObjectTag(curLine)
  172.             spn = new spinner
  173.             cnt = new control
  174.             cnt->objectType = currentObject
  175.             cnt->controlType = "NumericUpDown"
  176.            
  177.         case "<GRID>"
  178.             currentObject = parseObjectTag(curLine)
  179.             grd = new grid
  180.             cnt = new control
  181.             cnt->objectType = currentObject
  182.             cnt->controlType = "DataGridView"
  183.            
  184.         case else
  185.             inObject = false
  186.            
  187.         end select
  188.        
  189.     else
  190.         'Expect properties or end of object tag
  191.        
  192.         if(curLine = "<END_" + currentObject + ">") then
  193.             'No longer expecting object properties
  194.             inObject = false
  195.            
  196.             select case currentObject
  197.             case "FORM"
  198.                
  199.             case "LABEL"
  200.                 cnt->objectName = lbl->objectName
  201.                 controls.add(*cnt)
  202.                 delete cnt
  203.                
  204.                 labels.add(*lbl)
  205.                 delete lbl
  206.                
  207.             case "TEXTBOX", "EDITBOX"
  208.                 cnt->objectName = txt->objectName
  209.                 controls.add(*cnt)
  210.                 delete cnt
  211.                
  212.                 textboxes.add(*txt)
  213.                 delete txt
  214.                
  215.             case "COMMANDBUTTON"
  216.                 cnt->objectName = btn->objectName
  217.                 controls.add(*cnt)
  218.                 delete cnt
  219.                
  220.                 buttons.add(*btn)
  221.                 delete btn
  222.                
  223.             case "SPINNER"
  224.                 cnt->objectName = spn->objectName
  225.                 controls.add(*cnt)
  226.                 delete cnt
  227.                
  228.                 spinners.add(*spn)
  229.                 delete spn
  230.                
  231.             case "GRID"
  232.                 cnt->objectName = grd->objectName
  233.                 controls.add(*cnt)
  234.                 delete cnt
  235.                
  236.                 grids.add(*grd)
  237.                 delete grd
  238.                
  239.             end select
  240.            
  241.         else
  242.             'Feed properties to the object
  243.             dim as string prop = left(curLine,instr(curLine," ")-1)
  244.             dim as integer numVal = val(mid(curLine, inStrRev(curLine, " ")+1, len(curLine)))
  245.             dim as string strVal = mid(curLine, inStrRev(curLine, "=")+3, len(curLine) - inStrRev(curLine, "=") - 3)
  246.             dim as boolean boolVal = iif(UCASE(strVal) = "T", true, false)
  247.            
  248.             'Current object
  249.             select case currentObject
  250.             case "FORM"
  251.                 select case prop
  252.                 case "Name"
  253.                     frm.objectName = strVal
  254.                 case "Caption"
  255.                     frm.text = strVal
  256.                 case "Width"
  257.                     frm.wdth = numVal
  258.                 case "Height"
  259.                     frm.hght = numVal
  260.                 case "BackColor"
  261.                     frm.backColorR = val(left(str(numVal), inStr(str(numVal), ",")-1))
  262.                     frm.backColorG = val(mid(str(numVal), inStr(str(numVal), ",")+1, inStr(str(numVal), ",")-1))
  263.                     frm.backColorB = val(right(str(numVal), inStr(str(numVal), ",")-1))
  264.                 end select
  265.                
  266.             case "LABEL"
  267.                 select case prop
  268.                 case "Name"
  269.                     lbl->objectName = strVal
  270.                 case "Caption"
  271.                     lbl->text = strVal
  272.                 case "AutoSize"
  273.                     lbl->autoSize = boolVal
  274.                 case "TabIndex"
  275.                     lbl->tabIndex = numVal
  276.                 case "Width"
  277.                     lbl->wdth = numVal
  278.                 case "Height"
  279.                     lbl->hght = numVal
  280.                 case "Left"
  281.                     lbl->px = numVal
  282.                 case "Top"
  283.                     lbl->py = numVal
  284.                 case "FontName"
  285.                     btn->fnt.fontName = strVal
  286.                 end select
  287.                
  288.             case "TEXTBOX", "EDITBOX"
  289.                 select case prop
  290.                 case "Name"
  291.                     txt->objectName = strVal
  292.                 case "PasswordChar"
  293.                     txt->passwordChar = strVal
  294.                 case "MaxLength"
  295.                     txt->maxLength = numVal
  296.                 case "TabIndex"
  297.                     txt->tabIndex = numVal
  298.                 case "Width"
  299.                     txt->wdth = numVal
  300.                 case "Height"
  301.                     txt->hght = numVal
  302.                 case "Left"
  303.                     txt->px = numVal
  304.                 case "Top"
  305.                     txt->py = numVal
  306.                 case "FontName"
  307.                     btn->fnt.fontName = strVal
  308.                 end select
  309.                
  310.             case "COMMANDBUTTON"
  311.                 select case prop
  312.                 case "Name"
  313.                     btn->objectName = strVal
  314.                 case "Caption"
  315.                     btn->text = strVal
  316.                 case "AutoSize"
  317.                     btn->autoSize = numVal
  318.                 case "Width"
  319.                     btn->wdth = numVal
  320.                 case "Height"
  321.                     btn->hght = numVal
  322.                 case "Left"
  323.                     btn->px = numVal
  324.                 case "Top"
  325.                     btn->py = numVal
  326.                 case "FontName"
  327.                     btn->fnt.fontName = strVal
  328.                 end select
  329.                
  330.             case "SPINNER"
  331.                 select case prop
  332.                 case "Name"
  333.                     spn->objectName = strVal
  334.                 case "Width"
  335.                     spn->wdth = numVal
  336.                 case "Height"
  337.                     spn->hght = numVal
  338.                 case "Left"
  339.                     spn->px = numVal
  340.                 case "Top"
  341.                     spn->py = numVal
  342.                 case "FontName"
  343.                     btn->fnt.fontName = strVal
  344.                 end select
  345.                
  346.             case "GRID"
  347.                 select case prop
  348.                 case "Name"
  349.                     grd->objectName = strVal
  350.                 case "Width"
  351.                     grd->wdth = numVal
  352.                 case "Height"
  353.                     grd->hght = numVal
  354.                 case "Left"
  355.                     grd->px = numVal
  356.                 case "Top"
  357.                     grd->py = numVal
  358.                 case "FontName"
  359.                     btn->fnt.fontName = strVal
  360.                 end select
  361.             end select
  362.         end if
  363.     end if
  364. loop until(file.endOfFile)
  365. file.closeFile()
  366.  
  367. for i as integer = 0 to controls.length()-1
  368.     select case controls.item[i].objectType
  369.     case ""
  370.     end select
  371. next i
  372.  
  373. 'var jj = 1
  374. 'print labels.item[jj].objectName
  375. 'print labels.item[jj].text
  376. 'print labels.item[jj].wdth
  377. 'print labels.item[jj].hght
  378. 'print labels.item[jj].px
  379. 'print labels.item[jj].py
  380.  
  381. 'Create the designer file
  382. file.openWrite(frm.objectName + ".Designer.cs")
  383. file.print("namespace ConnorsMasterPiece")
  384. file.print("{")
  385. file.print("    partial class frmTest3")
  386. file.print("    {")
  387. file.print("        /// <summary>")
  388. file.print("        /// Required designer variable.")
  389. file.print("        /// </summary>")
  390. file.print("        private System.ComponentModel.IContainer components = null;")
  391. file.print("        ")
  392. file.print("        /// <summary>")
  393. file.print("        /// Clean up any resources being used.")
  394. file.print("        /// </summary>")
  395. file.print(!"        /// <param name=\"disposing\">true if managed resources should be disposed; otherwise, false.</param>")
  396. file.print("        protected override void Dispose(bool disposing)")
  397. file.print("        {")
  398. file.print("            if (disposing && (components != null))")
  399. file.print("            {")
  400. file.print("                components.Dispose();")
  401. file.print("            }")
  402. file.print("            base.Dispose(disposing);")
  403. file.print("        }")
  404. file.print("        ")
  405. file.print("        #region Windows Form Designer generated code")
  406. file.print("        /// <summary>")
  407. file.print("        /// Required method for Designer support - do not modify")
  408. file.print("        /// the contents of this method with the code editor.")
  409. file.print("        /// </summary>")
  410. file.print("        ")
  411. file.print("        private void InitializeComponent()")
  412. file.print("        {")
  413.  
  414. for i as integer = 0 to controls.length()-1
  415.     dim as string mainLine
  416.     mainLine = "this." + controls.item[i].objectName + " = new System.Windows.Forms."
  417.     file.print("            " + mainLine + controls.item[i].controlType + "();")
  418. next i
  419.  
  420. for i as integer = 0 to controls.length()-1
  421.     select case controls.item[i].objectType
  422.     case "SPINNER"
  423.         file.print("            ((System.ComponentModel.ISupportInitialize)(this." + controls.item[i].objectName + ")).BeginInit();")
  424.     case "GRID"
  425.         file.print("            ((System.ComponentModel.ISupportInitialize)(this." + controls.item[i].objectName + ")).BeginInit();")
  426.     end select
  427. next i
  428.  
  429. file.print("            this.SuspendLayout();")
  430.  
  431. for i as integer = 0 to controls.length()-1
  432.     file.print("            //")
  433.     file.print("            // " + controls.item[i].objectName)
  434.     file.print("            //")
  435. next i
  436.  
  437. file.print("            //")
  438. file.print("            // " + frm.objectName)
  439. file.print("            //")
  440. file.print("            this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);")
  441. file.print("            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;")
  442. file.print("            this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(" + str(frm.backColorR) + ")))), ((int)(((byte)(" + str(frm.backColorG) + ")))), ((int)(((byte)(" + str(frm.backColorB) + ")))));")
  443. file.print("            this.ClientSize = new System.Drawing.Size(" + str(frm.wdth) + ", " + str(frm.hght) + ");")
  444.  
  445. for i as integer = controls.length()-1 to 0 step -1
  446.     file.print("            this.Controls.Add(this." + controls.item[i].objectName + ");")
  447. next i
  448.  
  449. file.print(!"            this.Font = new System.Drawing.Font(\"" + frm.fnt.fontName + !"\", " + str(frm.fnt.size) + "F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));")
  450. file.print(!"            this.Name = \"" + frm.objectName + !"\";")
  451.  
  452. for i as integer = 0 to controls.length()-1
  453.     select case controls.item[i].objectType
  454.     case "SPINNER"
  455.         file.print("            ((System.ComponentModel.ISupportInitialize)(this." + controls.item[i].objectName + ")).EndInit();")
  456.     case "GRID"
  457.         file.print("            ((System.ComponentModel.ISupportInitialize)(this." + controls.item[i].objectName + ")).EndInit();")
  458.     end select
  459. next i
  460.  
  461. file.print("            this.ResumeLayout(false);")
  462. file.print("            this.PerformLayout();")
  463. file.print("            ")
  464. file.print("        }")
  465. file.print("        ")
  466. file.print("        #endregion")
  467. file.print("        ")
  468.  
  469. for i as integer = 0 to controls.length()-1
  470.     file.print("        private System.Windows.Forms." + controls.item[i].controlType + " " + controls.item[i].objectName + ";")
  471. next i
  472.  
  473. file.print("    }")
  474. file.print("}")
  475. file.closeFile()
  476.  
  477. 'Create the main .cs file
  478. file.openWrite(frm.objectName + ".cs")
  479. file.print("using System;")
  480. file.print("using System.Collections.Generic;")
  481. file.print("using System.ComponentModel;")
  482. file.print("using System.Data;")
  483. file.print("using System.Drawing;")
  484. file.print("using System.Linq;")
  485. file.print("using System.Text;")
  486. file.print("using System.Threading.Tasks;")
  487. file.print("using System.Windows.Forms;")
  488. file.print()
  489. file.print("namespace _NAMESPACE_")
  490. file.print("{")
  491. file.print("    public partial class " + frm.objectName + " : Form")
  492. file.print("    {")
  493. file.print("        public " + frm.objectName + "()")
  494. file.print("        {")
  495. file.print("            InitializeComponent();")
  496. file.print("        }")
  497. file.print("    }")
  498. file.print("}")
  499. file.closeFile()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement