Advertisement
Ivan_L

CreateCoorList

Apr 3rd, 2020
1,140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 9.24 KB | None | 0 0
  1. #include <Misc.au3>
  2. #include <Array.au3>
  3. #include <Constants.au3>
  4. #include <MsgBoxConstants.au3>
  5. #include <GUIConstants.au3>
  6. #include <FileConstants.au3>
  7. #include <File.au3>
  8. #include <WinAPIFiles.au3>
  9.  
  10. Local $GuiWidth = 100
  11. Local $GuiHeigh = 370
  12. Local $sFilePath = "C:\Program Files (x86)\AutoIt3\ScriptsForLaser/CustomCoordList.txt"
  13. Func NumButton($numButton)
  14. return 10+50*$numButton
  15. EndFunc
  16. Local $SetGUI =             GUICreate("Settings ",$GuiWidth,$GuiHeigh)
  17. Local $startPointSet =      GUICtrlCreateButton("Point Set",10,NumButton(0),80,40)
  18. Local $startAreaSet =       GUICtrlCreateButton("Area Set",10,NumButton(1),80,40)
  19. Local $ShowList =           GUICtrlCreateButton("Show Coord List",10,NumButton(2),80,40,$BS_MULTILINE)
  20. Local $Update =             GUICtrlCreateButton("Update Coord",10,NumButton(3),80,40,$BS_MULTILINE)
  21. Local $UpdateName =         GUICtrlCreateButton("Update Line Name",10,NumButton(4),80,40,$BS_MULTILINE)
  22. Local $DelCord =            GUICtrlCreateButton("Delete Line",10,NumButton(5),80,40,$BS_MULTILINE)
  23. Local $DeleteFile =         GUICtrlCreateButton("Delete File",10,NumButton(6),80,40,$BS_MULTILINE)
  24. Local $sOutString =         "Unknown"
  25. Local $sBoofer =            "Unknown"
  26. Local $sNameOfLine =        "Unknown"
  27. Local $sNewNameOfLine =     "Unknown"
  28. Local $aMousePos =          MouseGetPos()
  29. Local $mouseX =             $aMousePos[0]
  30. Local $mouseY =             $aMousePos[1]
  31. ;--------------------------------------------------------------------------------------------- 
  32. Func WriteToFile($sString)
  33. $hFileOpen = FileOpen($sFilePath,1)
  34.     If $hFileOpen = -1 Then
  35.         MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.")
  36.         Return False
  37.     EndIf
  38. FileWrite($hFileOpen,$sString&@CRLF)
  39. FileClose($hFileOpen)
  40. EndFunc
  41. ;---------------------------------------------------------------------------------------------
  42. Func StringSerch($sStringToFinde)
  43. Local $TypeCheck = "UNKNOWN"
  44. Local $iTypeCheck = -1
  45. Local $iIndexOfSubString = 0
  46. Local $i = 3
  47. Local $iResult = 0
  48. Local $aResult[$i] = [0,"UNKNOWN","UNKNOWN"]
  49. ;MsgBox("","",$aResult[0]&" "&$aResult[1]&" "&$aResult[2])
  50. Local $sResult = "UNKNOWN"
  51. Local $aLineArray[_FileCountLines ( $sFilePath )]
  52. Local $sSearchPoint = $sStringToFinde
  53. Local $iStringChekIndex = StringLen($sSearchPoint)
  54. _FileReadToArray ($sFilePath,$aLineArray)
  55.  
  56. for $line =1 to UBound($aLineArray)-1
  57.  
  58. $iIndexOfSubString = StringInStr($aLineArray[$line],$sSearchPoint)
  59.  
  60.     If $iIndexOfSubString>0 AND StringInStr($aLineArray[$line]," ",0,1,$iStringChekIndex,$iStringChekIndex+1)>0 Then
  61.     $iResult = $line
  62.     ExitLoop   
  63.     EndIf
  64.    
  65. Next
  66.  
  67.     If $iResult=0 Then
  68.         ;MsgBox("Result","","Not Found")
  69.         $sResult = "Not Found"
  70.     Else
  71.         $sResult = $aLineArray[$iResult]
  72.         ;MsgBox("result","",$sResult)
  73.        
  74.     EndIf
  75.    
  76.     $iTypeCheck = StringInStr($sResult,"p ")
  77.     If $iTypeCheck =1 Then
  78.         $TypeCheck = "Point"
  79.     Else
  80.         $TypeCheck = "Area"
  81.     EndIf
  82.    
  83.     $aResult[0] = $iResult
  84.     $aResult[1] = $TypeCheck
  85.     $aResult[2] = $sResult
  86.     ;MsgBox("","",$aResult[0]&" "&$aResult[1]&" "&$aResult[2])
  87.    
  88. Return $aResult
  89. EndFunc
  90. ;---------------------------------------------------------------------------------------------
  91. Func SetButton($sName)
  92. Local $namePoint = $sName
  93. Local $aCheckExist[3] = [0,"UNKNOWN","UNKNOWN"]
  94. $aCheckExist = StringSerch($sName)
  95. If $aCheckExist[0]>0 Then
  96.     MsgBox("Result","","Line "&$sName&" is allready exist!"&@CRLF&$aCheckExist[2])
  97. Else
  98.     while 1
  99.     Sleep (100)
  100.      If _IsPressed("01") Then
  101.          $aMousePos = MouseGetPos()
  102.          $mouseX = $aMousePos[0]
  103.          $mouseY = $aMousePos[1]
  104.         $sOutString = "p "&$namePoint&" x="&$mouseX&" y="&$mouseY
  105.         MsgBox("","",$sOutString)
  106.         ExitLoop
  107.     EndIf
  108.     WEnd
  109.     return $sOutString
  110. EndIf
  111. EndFunc
  112. ;---------------------------------------------------------------------------------------------
  113. Func SetNamePoint($sName,$sNewName)
  114. Local $sResult = "Unknown"
  115. Local $aSplitLine[5]
  116. $aSplitLine = StringSplit($sName, " ")
  117. $sResult = $aSplitLine[1]&" "&$sNewName&" "&$aSplitLine[3]&" "&$aSplitLine[4]
  118. return $sResult
  119. EndFunc
  120. ;---------------------------------------------------------------------------------------------
  121. Func SetNameArea($sName,$sNewName)
  122. Local $sResult = "Unknown"
  123. Local $aSplitLine[7]
  124. $aSplitLine = StringSplit($sName, " ")
  125. $sResult = $aSplitLine[1]&" "&$sNewName&" "&$aSplitLine[3]&" "&$aSplitLine[4]&" "&$aSplitLine[5]&" "&$aSplitLine[6]
  126. return $sResult
  127. EndFunc
  128. ;---------------------------------------------------------------------------------------------
  129. Func SetArea($sName)
  130. Local $nameArea = $sName
  131. Local $aCheckExist[3] = [0,"UNKNOWN","UNKNOWN"]
  132. $aCheckExist = StringSerch($sName)
  133. If $aCheckExist[0]>0 Then
  134.     MsgBox("Result","","Line "&$sName&" is allready exist!"&@CRLF&$aCheckExist[2])
  135. Else
  136.     while 1
  137.     while 1
  138.      If _IsPressed("01") Then
  139.          $aMousePos = MouseGetPos()
  140.          $mouseX = $aMousePos[0]
  141.          $mouseY = $aMousePos[1]
  142.         $sOutString = "a "&$nameArea&" Left="&$mouseX&" Top="&$mouseY
  143.         ExitLoop
  144.         EndIf  
  145.     WEnd
  146.     MsgBox("","",$sOutString)
  147.     while 1
  148.     If _IsPressed("01") Then
  149.          $aMousePos = MouseGetPos()
  150.          $mouseX = $aMousePos[0]
  151.          $mouseY = $aMousePos[1]
  152.         $sOutString = $sOutString&" Right="&$mouseX&" Bottom="&$mouseY
  153.         ExitLoop
  154.         EndIf
  155.     WEnd
  156.     MsgBox("","",$sOutString)
  157.     ExitLoop
  158.     WEnd
  159.     return $sOutString
  160. EndIf
  161. EndFunc
  162. ;---------------------------------------------------------------------------------------------
  163. Func Delete()
  164. FileDelete($sFilePath)
  165. EndFunc
  166. ;---------------------------------------------------------------------------------------------
  167. Func ShowList()
  168. ;$FileCheck  
  169. If   FileExists($sFilePath)>0 Then
  170.     $sFileRead = FileRead($sFilePath)
  171.     MsgBox("File content","",$sFileRead)
  172. Else
  173.     MsgBox("Error","","File not exist")
  174. EndIf
  175. EndFunc
  176. ;---------------------------------------------------------------------------------------------
  177. Func StringDelete($sStringToFinde)
  178. Local $aStatusArray[3] = [0,"UNKNOWN","UNKNOWN"]
  179. Local $aLinesArray[_FileCountLines ( $sFilePath )]
  180. $aStatusArray = StringSerch($sStringToFinde)
  181. If $aStatusArray[0]>0 Then
  182.     _FileReadToArray ($sFilePath,$aLinesArray)
  183.     Delete()
  184.     MsgBox("","","Index of Line: "&$aStatusArray[0]&" | Type of Line: "&$aStatusArray[1]&" | Line content: "&$aStatusArray[2])
  185.     _ArrayDelete($aLinesArray,$aStatusArray[0])
  186.     _FileWriteFromArray($sFilePath,$aLinesArray,1)
  187.     MsgBox("Result","",$aStatusArray[2]&" was deleted")
  188. Else
  189.     MsgBox("Result","","Line not found")
  190. EndIf
  191. EndFunc
  192. ;---------------------------------------------------------------------------------------------
  193. Func UpdateCoord($sName)
  194. Local $aStatusArray[3] = [0,"UNKNOWN","UNKNOWN"]
  195. Local $iTypeCheck = "Point"
  196. Local $aLinesArray[_FileCountLines ( $sFilePath )]
  197. Local $sNewData = "UNKNOWN"
  198. Local $aStatusArray = StringSerch($sName)
  199. If $aStatusArray[0]>0 Then
  200.     StringDelete($sName)
  201.     _FileReadToArray ($sFilePath,$aLinesArray)
  202.     Delete()
  203.    
  204.     If StringInStr($aStatusArray[1],"Area")>0 Then
  205.         $sNewData = SetArea($sName)
  206.     Else
  207.         $sNewData = SetButton($sName)
  208.     EndIf
  209.     _ArrayAdd($aLinesArray,$sNewData)
  210.     _FileWriteFromArray($sFilePath,$aLinesArray,1)
  211.     MsgBox("Result","",$aStatusArray[2]&" was updated to:"&@CRLF&$sNewData)
  212. Else
  213.     MsgBox("Result","","Can`t update Line")
  214. EndIf
  215. EndFunc
  216. ;---------------------------------------------------------------------------------------------
  217. Func UpdateName($sName,$sNewName)
  218. Local $aStatusArray[3] = [0,"UNKNOWN","UNKNOWN"]
  219. Local $iTypeCheck = "Point"
  220. Local $aLinesArray[_FileCountLines ( $sFilePath )]
  221. Local $sNewData = "UNKNOWN"
  222. Local $aStatusArray = StringSerch($sName)
  223. If $aStatusArray[0]>0 Then
  224.     StringDelete($sName)
  225.     _FileReadToArray ($sFilePath,$aLinesArray)
  226.     Delete()
  227.    
  228.     If StringInStr($aStatusArray[1],"Area")>0 Then
  229.         $sNewData = SetNameArea($aStatusArray[2],$sNewName)
  230.     Else
  231.         $sNewData = SetNamePoint($aStatusArray[2],$sNewName)
  232.     EndIf
  233.    
  234.     _ArrayAdd($aLinesArray,$sNewData)
  235.     _FileWriteFromArray($sFilePath,$aLinesArray,1)
  236.     MsgBox("Result","",$aStatusArray[2]&" was updated to:"&@CRLF&$sNewData)
  237. Else
  238.     MsgBox("Result","","Can`t update Line")
  239. EndIf
  240. EndFunc
  241. ;---------------------------------------------------------------------------------------------
  242. Func DeleteCoord()
  243. Local $sSearchPoint = InputBox("","Enter name of Line")
  244. StringDelete($sSearchPoint)
  245. EndFunc
  246. ;---------------------------------------------------------------------------------------------
  247. Local $iLeftDesktopWidth = 50
  248. Local $iLeftDesktopHeight =  @DesktopHeight - $GuiHeigh - 50
  249.  
  250. GUISetState(@SW_SHOW,$SetGUI)
  251. WinSetOnTop ("Settings","",1)
  252. WinMove("Settings","",$iLeftDesktopWidth,$iLeftDesktopHeight)
  253. While 1
  254. Sleep (50)
  255.     Switch GUIGetMsg()
  256.         Case $GUI_EVENT_CLOSE
  257.         ExitLoop
  258.        
  259.         Case $startPointSet
  260.         $sNameOfLine = InputBox(""," ","Enter name of Point")
  261.         $sBoofer = SetButton($sNameOfLine)
  262.         If StringLen($sBoofer)>2 Then
  263.         WriteToFile($sBoofer)
  264.         EndIf
  265.  
  266.         Case $startAreaSet
  267.         $sNameOfLine = InputBox(""," ","Enter name of Area")
  268.         $sBoofer = SetArea($sNameOfLine)
  269.         If StringLen($sBoofer)>2 Then
  270.         WriteToFile($sBoofer)
  271.         EndIf
  272.        
  273.         Case $DeleteFile
  274.         Delete()
  275.  
  276.         Case $ShowList
  277.         ShowList()
  278.  
  279.         Case $Update
  280.         $sNameOfLine = InputBox(""," ","Enter name of Line")
  281.         UpdateCoord($sNameOfLine)
  282.  
  283.         Case $UpdateName
  284.         $sNameOfLine = InputBox(""," ","Enter name of Line")
  285.         $sNewNameOfLine = InputBox(""," ","Enter new name of Line")
  286.         UpdateName($sNameOfLine,$sNewNameOfLine)
  287.  
  288.         Case $DelCord
  289.         DeleteCoord()
  290.        
  291.     EndSwitch      
  292. WEnd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement