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

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

先上效果图:

生成出来的G代码:

 

g.py源码:

#coding=utf-8
# -*- coding: UTF-8 -*-
#!/usr/bin/eny python
#coding:utf-8
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
    def get(self):
       self.render('g.html')
    def post(self,*args,**kwargs):
        x='X'
        y='Y'
        g='G01'
        k=0
        a1=0
        e=''
        a=int(self.get_argument('x'))
        b=int(self.get_argument('y'))
        c=int(self.get_argument('r'))
        d=int(self.get_argument('l'))
        j1=int(self.get_argument('f'))
        q=(b/2)+6
        k=(-(a/2))
        while k<a:
            a1=a1=1
            i=a1%2
            if i==1:
                k=k+(c/2)
            q=q*-1
            l=g+x+str(k)+y+str(q)
            e=e+l+'</br>'
        c1=-(a/2)
        c2=(b/2)
        l1='G00'+str(c1)+y+str(c2)+'</br>'+"Z5"+'</br>'
        l2=g+'Z'+str(d)+'F'+str(j1)+'</br>'
        l3=str(q)
        l4=g+'Y'+l3+'F'+str(j1)+'</br>'
        tou=l1+l2+l4
        w1='G00'+'Z20'+'</br>'
        w2='G00'+'X0Y0'
        zhong=tou+e+w1+w2
        self.write(zhong)

settings={
    }
application = tornado.web.Application([
    (r"/index", MainHandler),
],)
if __name__ == "__main__":
    application.listen(8000)
    tornado.ioloop.IOLoop.instance().start()

  

html源码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>在线G代码平面铣工具</title>
<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<center><div style="width:550px;height:900px id="wingMap">
<center><h1>在线G代码平面铣工具</h1></center>
​<form method="post" action="/index">
<form class="form-horizontal" role="form">
<label for="firstname" class="col-sm-2 control-label">毛坯长度</label>
<input type="text" name="x" class="form-control" id="firstname"
placeholder="请输入毛坯长度">
<label for="lastname" class="col-sm-2 control-label">毛坯宽度:</label>
<input type="text" name="y" class="form-control" id="lastname"
placeholder="请输入毛坯宽度:">
<label for="lastname" class="col-sm-2 control-label">刀具直径:</label>
<input type="text" name="r" class="form-control" id="lastname"
placeholder="请输入刀具直径:">
<label for="lastname" class="col-sm-2 control-label">下刀深度:</label>
<input type="text" name="l" class="form-control" id="lastname"
placeholder="请输入下刀深度:">
<label for="lastname" class="col-sm-2 control-label">进给速度:</label>
<input type="text" name="f" class="form-control" id="lastname"
placeholder="请输入进给速度F:">
<button type="submit" name="submit" class="btn btn-primary">生成</button>
</form>
</form>
</center>

效果图

服务端效果图:

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

 

posted @ 2018-05-17 14:56  sunny开始学坏  阅读(8521)  评论(0编辑  收藏  举报