分享

Python打造一个在线G代码生成器

 imelee 2019-12-05

用tornado框架做后端……,用bootstrap做前端

先上效果图:

生成出来的G代码:

 

g.py源码:

  1. #coding=utf-8
  2. # -*- coding: UTF-8 -*-
  3. #!/usr/bin/eny python
  4. #coding:utf-8
  5. #!/usr/bin/env python
  6. # -*- coding:utf-8 -*-
  7. import tornado.ioloop
  8. import tornado.web
  9. class MainHandler(tornado.web.RequestHandler):
  10. def get(self):
  11. self.render('g.html')
  12. def post(self,*args,**kwargs):
  13. x='X'
  14. y='Y'
  15. g='G01'
  16. k=0
  17. a1=0
  18. e=''
  19. a=int(self.get_argument('x'))
  20. b=int(self.get_argument('y'))
  21. c=int(self.get_argument('r'))
  22. d=int(self.get_argument('l'))
  23. j1=int(self.get_argument('f'))
  24. q=(b/2)+6
  25. k=(-(a/2))
  26. while k<a:
  27. a1=a1=1
  28. i=a1%2
  29. if i==1:
  30. k=k+(c/2)
  31. q=q*-1
  32. l=g+x+str(k)+y+str(q)
  33. e=e+l+'</br>'
  34. c1=-(a/2)
  35. c2=(b/2)
  36. l1='G00'+str(c1)+y+str(c2)+'</br>'+"Z5"+'</br>'
  37. l2=g+'Z'+str(d)+'F'+str(j1)+'</br>'
  38. l3=str(q)
  39. l4=g+'Y'+l3+'F'+str(j1)+'</br>'
  40. tou=l1+l2+l4
  41. w1='G00'+'Z20'+'</br>'
  42. w2='G00'+'X0Y0'
  43. zhong=tou+e+w1+w2
  44. self.write(zhong)
  45. settings={
  46. }
  47. application = tornado.web.Application([
  48. (r"/index", MainHandler),
  49. ],)
  50. if __name__ == "__main__":
  51. application.listen(8000)
  52. tornado.ioloop.IOLoop.instance().start()

  

html源码:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>在线G代码平面铣工具</title>
  6. <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
  7. <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
  8. <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  9. </head>
  10. <body>
  11. <center><div style="width:550px;height:900px id="wingMap">
  12. <center><h1>在线G代码平面铣工具</h1></center>
  13. ​<form method="post" action="/index">
  14. <form class="form-horizontal" role="form">
  15. <label for="firstname" class="col-sm-2 control-label">毛坯长度</label>
  16. <input type="text" name="x" class="form-control" id="firstname"
  17. placeholder="请输入毛坯长度">
  18. <label for="lastname" class="col-sm-2 control-label">毛坯宽度:</label>
  19. <input type="text" name="y" class="form-control" id="lastname"
  20. placeholder="请输入毛坯宽度:">
  21. <label for="lastname" class="col-sm-2 control-label">刀具直径:</label>
  22. <input type="text" name="r" class="form-control" id="lastname"
  23. placeholder="请输入刀具直径:">
  24. <label for="lastname" class="col-sm-2 control-label">下刀深度:</label>
  25. <input type="text" name="l" class="form-control" id="lastname"
  26. placeholder="请输入下刀深度:">
  27. <label for="lastname" class="col-sm-2 control-label">进给速度:</label>
  28. <input type="text" name="f" class="form-control" id="lastname"
  29. placeholder="请输入进给速度F:">
  30. <button type="submit" name="submit" class="btn btn-primary">生成</button>
  31. </form>
  32. </form>
  33. </center>

效果图

服务端效果图:

生成速度非常快(10w行代码只要几秒)!

 

转载于:https://www.cnblogs.com/ksxh/p/9051109.html

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多