diff --git a/README.md b/README.md index 9e489c3..51c24eb 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,11 @@ app.py ----服务器的主程序 ## 更新日志 +* 2021年3月16号,前端+后端更新 + + * 新增:成功将spice网表和simulation设置参数传入后端 + * 待解决1:前端代码冗杂,缺乏层次 + * 待解决2:需要在后端根据传入参数进行电路仿真, 并将仿真结果传递回前端 * 2021年2月9号,前端更新 * 发现bug: 当schematic中没有组件时,spice的parse函数抛出错误 diff --git a/app.py b/app.py index d8ae518..2c7136a 100644 --- a/app.py +++ b/app.py @@ -23,6 +23,7 @@ class Application(tornado.web.Application): #引入Application类,重写方 (r'/spice4',spice.Spice_4_Handler), (r'/test',main.TestHandler), (r'/spice',spice.SpiceHandler), + (r'/simulation',spice.SimulationHandler), ] settings = dict( debug = False, #调试模式,修改后自动重启服务,不需要自动重启,生产情况下切勿开启,安全性 diff --git a/handler/__pycache__/spice.cpython-36.pyc b/handler/__pycache__/spice.cpython-36.pyc index def80ff..d71e480 100644 Binary files a/handler/__pycache__/spice.cpython-36.pyc and b/handler/__pycache__/spice.cpython-36.pyc differ diff --git a/handler/simulation.py b/handler/simulation.py new file mode 100644 index 0000000..869fb18 --- /dev/null +++ b/handler/simulation.py @@ -0,0 +1,49 @@ + +#----调用PySpice包---- +from PySpice.Doc.ExampleTools import find_libraries +from PySpice.Probe.Plot import plot +from PySpice.Spice.Library import SpiceLibrary +from PySpice.Spice.Netlist import Circuit +from PySpice.Unit import * +import PySpice.Logging.Logging as Logging +logger = Logging.setup_logging() + +#----调用模型库---- +libraries_path = 'D:\\Project_2020\\SPICE\\Pyspice\\libraries' +#libraries_path = find_libraries() +spice_library = SpiceLibrary(libraries_path) + +class Simulator_CZ : + + def __init__( self, title='simulation' ): + self.circuit = Circuit(title) + + + def Get_Spice( spice ): + self.circuit.raw_spice += ".include D:\\Project_2020\\SPICE\\PySpice\\libraries\cmos\\180nm_cmos.mod" + self.circuit.raw_spice += spice + + + def Sim(sim_type,properties): + parameter = self.Properties_Parse(sim_type,properties) + self.simulator = self.circuit.simulator(temperature=25, nominal_temperature=25) + if(sim_type == 'transient'): + self.analysis = self.simulator.transient(step_time = parameter['step_time'], + end_time = parameter['end_time'], + start_time = parameter['start_time'], + max_time = parameter['max_time'], + use_initial_condition = parameter['use_initial_condition']) + pass + elif(sim_type == 'dc' ): + pass + elif(sim_type == 'ac' ): + pass + else: + pass + + def Properties_Parse(sim_type,properties): + parameter = {} + if(sim_type == 'transient'): + parameter["step_time"] = 0 + pass + diff --git a/handler/spice.py b/handler/spice.py index c9d1300..218420f 100644 --- a/handler/spice.py +++ b/handler/spice.py @@ -13,13 +13,22 @@ class SpiceHandler(AuthBaseHandler): username = self.get_current_user() message = self.get_argument('spice') - print('SpiceHandler: '+username+' '+message) + print('SpiceHandler: '+username+' \n'+message) Mongo.connect(DataBase='example',Collection=username) Mongo.update(behavior=message,tags='spice') self.write("success") +class SimulationHandler(AuthBaseHandler): + @tornado.web.authenticated + def post(self,*args,**kwargs): + sim_type = self.get_argument('sim_type') + properties = self.get_argument('properties') + print("sim type:",sim_type) + print("property:",properties) + + self.write("success") class Schematic_Handler(AuthBaseHandler): diff --git a/static/schematic/css/tab.css b/static/schematic/css/tab.css new file mode 100644 index 0000000..38cb0d5 --- /dev/null +++ b/static/schematic/css/tab.css @@ -0,0 +1,44 @@ +/* Style the tab */ +.tab { + overflow: hidden; + border: 1px solid #ccc; + background-color: #f1f1f1; +} + +/* Style the buttons inside the tab */ +.tab .tablinks { + /* background-color: inherit; */ + background: inherit; + float: left; + border: none; + outline: none; + cursor: pointer; + padding: 14px 16px; + transition: 0.3s; + font-size: 17px; +} + +/* Change background color of buttons on hover */ +.tab .tablinks:hover { + background-color: #ddd; +} + +/* Create an active/current tablink class */ +.tab .tablinks.active { + background-color: #ccc; +} + +/* Style the tab content */ +.tabcontent { + display: none; + padding: 6px 12px; + border: 1px solid #ccc; + border-top: none; +} + + +.spice_input { + width: 500px; + border: 1px solid red; + text-align: right; +} \ No newline at end of file diff --git a/static/spice/bokeh_02.js b/static/spice/bokeh_02.js index 94f248e..68f0075 100644 --- a/static/spice/bokeh_02.js +++ b/static/spice/bokeh_02.js @@ -19,6 +19,8 @@ function Simulation(sim_type){ var properties = []; var sel = $("#"+sim_type+" input"); + alert(sim_type); + sel.each(function(){ var new_element = {}; var n = $(this)[0].name; @@ -29,7 +31,7 @@ function Simulation(sim_type){ var data = new Object(); - data["type"] = sim_type; + data["sim_type"] = sim_type; data["properties"] = properties; // data['spice'] = spice; // alert(spice); @@ -40,13 +42,15 @@ function Simulation(sim_type){ // alert(key + " "+ val); // } - // $.ajax({ - // type: 'POST', - // url: "/simulation", - // data: data, - // success: function (response) { - // alert(response); - // } - // }); + $.ajax({ + type: 'POST', + url: "/simulation", + data: data, + success: function (response) { + alert(response); + } + }); + +}; + -} diff --git a/template/schematic/schematic.html b/template/schematic/schematic.html index 319da5b..a8b9dbc 100644 --- a/template/schematic/schematic.html +++ b/template/schematic/schematic.html @@ -732,6 +732,27 @@ function get_spice(graph){ }; + + + + + @@ -752,6 +773,50 @@ function ajax_message(data) { }); } +// 由于ajax传递参数时,无法直接进行List的传递,故将属性List转换为了string然后进行传递 +function Simulator(sim_type){ + + // var properties = []; + var properties_send = ""; + var sel = $("#"+sim_type+" input"); + + // alert(sim_type); + + sel.each(function(){ + var new_element = {}; + var n = $(this)[0].name; + var v = $(this)[0].value; + + properties_send += n + "=" + v + ";"; + // new_element[n] = v ; + // properties.push(new_element); + }); + + + var data = new Object(); + data["sim_type"] = sim_type; + data["properties"] = properties_send; + // data['spice'] = spice; + // alert(spice); + + // for(var i=0; i @@ -832,8 +897,6 @@ function showProperties(graph,cell) } }; - - @@ -1141,15 +1204,20 @@ function showOutline(graph) var frame = document.createElement('div'); frame.setAttribute('id','bokeh_02'); + // var x = document.createElement('script'); + // x.setAttribute('src','static/spice/bokeh_02.js'); + // frame.appendChild(x); + var div_tab = document.createElement('div'); div_tab.setAttribute('class','tab'); - let sim_mode = ['transient', 'dc', 'ac']; + + var sim_mode = ['transient', 'dc', 'ac']; - let sim_mode_content = { + var sim_mode_content = { 'transient': { "key" :[ 'step_time', 'end_time', 'start_time','max_time','use_initial_condition'], - "value" :[ '', '', '0', 'None', 'False'] + "value" :[ '0.1 us', '20 us', '0', 'None', 'False'] }, 'dc': { "key" :[ "src","start","stop","step"], @@ -1200,13 +1268,15 @@ function showOutline(graph) input.setAttribute('value', the_mode['value'][j] ); td_input.appendChild(input); - form_div .appendChild(td_input); + form_div.appendChild(td_input); table.appendChild(form_div); } + var confirm = document.createElement('button'); confirm.setAttribute("type","submit"); - confirm.setAttribute('onclick',"Simulation('"+sim_mode[i] +"')"); + confirm.setAttribute('onclick',"Simulator('"+sim_mode[i] +"')"); + // confirm.onclick = function(){ Simulator(sim_mode[i]); }; confirm.innerHTML = "Confirm"; table.appendChild(confirm); @@ -1214,12 +1284,9 @@ function showOutline(graph) div_mode.appendChild(table); frame.appendChild(div_mode); - } + }; - var x = document.createElement('script'); - x.setAttribute('src','static/spice/bokeh_02.js'); - frame.appendChild(x); var w = document.body.clientWidth; var h = (document.body.clientHeight || document.documentElement.clientHeight);