diff --git a/ops/work/web/combine_core.py b/ops/work/web/combine_core.py index 3b3cdc1..f013018 100644 --- a/ops/work/web/combine_core.py +++ b/ops/work/web/combine_core.py @@ -244,6 +244,31 @@ class Core: d = self.POSITIONS_ROLE.get(role, {"in": ["LAN"], "out": ["—"]}) return list(d["in"]), list(d["out"]) or ["—"], "role" + # ── тип установки устройства ── + CEILING = r"^VCM|^CM50|^CS10-D|^CLS120|^MSpeaker|^RCH|^AVHub" + TABLE = r"^CM20|^CS10\b|^CP50|^CPE|^CP965|^CTP|^MTouch|^PA\d|^VCR" + WALL = r"^UVC|^SmartVision|^MB-CAM|MeetingDisplay|^ETV" + RACK = r"^MCore|^MeetingEye|^MeetingBar|^MeetingBoard|^PVB|^PVT|^AP08|^AVBridge|^VCH|^WPP" + + def mount_class(self, name): + n = str(name) + if re.match(self.CEILING, n, re.I): + return "ceiling" + if re.match(self.TABLE, n, re.I): + return "table" + if re.match(self.WALL, n, re.I): + return "wall" + if re.match(self.RACK, n, re.I): + return "rack" + return "other" + + def coverage(self, name): + """Радиус захвата микрофона и угол обзора камеры (из данных).""" + a = self.attrs.get(norm(name), {}) + return {"pickup_m": a.get("audio.pickup_m"), + "fov_h": a.get("camera.fov_h"), + "zoom": a.get("camera.zoom_optical") or a.get("camera.zoom_hybrid")} + # ── комплектация ── def package(self, name): k = norm(name) diff --git a/ops/work/web/services/svc_draw.py b/ops/work/web/services/svc_draw.py index 75bc743..e3230da 100644 --- a/ops/work/web/services/svc_draw.py +++ b/ops/work/web/services/svc_draw.py @@ -260,11 +260,31 @@ def heatmap(q, body): return {"svg": "".join(parts), "mics": total, "cams": len(cams)} +def plan(q, body): + """Данные плана: устройства с типом установки и начальными координатами.""" + w, l = _room(q) + items = _items(q) + devices, x, y = [], 0.15, 0.15 + for r in items: + model, qty = r[0], r[1] + mount = C.mount_class(model) + cov = C.coverage(model) + for n in range(qty): + devices.append({"model": model, "mount": mount, + "x": round(x, 3), "y": round(0.15 + 0.12 * n, 3), + "pickup_m": cov["pickup_m"], "fov_h": cov["fov_h"]}) + x = x + 0.12 if x < 0.8 else 0.15 + return {"w": w, "l": l, "devices": devices, + "legend": {"ceiling": "потолочный", "table": "настольный", + "wall": "настенный", "rack": "стойка", "other": "прочее"}} + + serve({ "/diagram": diagram, "/cables": cables, "/rack": rack, "/ipplan": ipplan, "/layout": layout, + "/plan": plan, "/heatmap": heatmap, }, int(sys.argv[1]) if len(sys.argv) > 1 else 8104, "draw") diff --git a/ops/work/web/webui.html b/ops/work/web/webui.html index f16610a..31fb7a5 100644 --- a/ops/work/web/webui.html +++ b/ops/work/web/webui.html @@ -164,7 +164,14 @@ svg{width:100%;height:520px;background:#0a0e13;border:1px solid var(--line);bord длина + +
+ перетаскивайте устройства мышью · 🟠 потолочный · 🟢 настольный · 🔵 камера +
соберите состав
+
@@ -212,7 +219,7 @@ function showTab(n){ document.querySelectorAll('.tab').forEach(t=>t.classList.toggle('on',t.dataset.t===n)); ['build','cables','diagram','layout','heat','matrix','docs','ask'].forEach(x=>$('#sec-'+x).classList.toggle('hidden',x!==n)); if(n==='matrix')loadMatrix(); - if(n==='layout')renderLayout(); + if(n==='layout')renderPlanDrag(); if(n==='heat')renderHeatmap(); } @@ -422,6 +429,82 @@ async function doAsk(){ function itemsQuery(){ return Object.keys(SEL).map(k=>'item='+encodeURIComponent(k+':'+SEL[k].qty)).join('&'); } +let PLAN=null; +async function renderPlanDrag(){ + const ks=Object.keys(SEL); + if(!ks.length){$('#layoutbox').innerHTML='соберите состав';return;} + const w=$('#lw').value, l=$('#ll').value; + const r=await J(`${SVC.draw}/plan?host=${$('#host').value}&w=${w}&l=${l}&${itemsQuery()}`); + if(r.error){$('#layoutbox').innerHTML=`
${esc(r.error)}
`;return;} + PLAN=r; + drawPlan(); +} +function drawPlan(){ + if(!PLAN)return; + const scale=52, pad=60; + const W=PLAN.w*scale+pad*2, H=PLAN.l*scale+pad*2; + const showCov=$('#showcov')&&$('#showcov').checked; + const COL={ceiling:'#d29922', table:'#3fb950', wall:'#2f81f7', rack:'#a371f7', other:'#8b949e'}; + let s=``; + s+=``; + s+=`${PLAN.w} × ${PLAN.l} м`; + PLAN.devices.forEach((d,i)=>{ + const cx=pad+d.x*PLAN.w*scale, cy=pad+d.y*PLAN.l*scale; + if(showCov && d.pickup_m){ + s+=``; + } + if(showCov && d.fov_h){ + const len=PLAN.l*scale*0.9, a=Math.PI/2, half=d.fov_h*Math.PI/360; + const x1=cx+len*Math.cos(a-half), y1=cy+len*Math.sin(a-half); + const x2=cx+len*Math.cos(a+half), y2=cy+len*Math.sin(a+half); + s+=``; + } + s+=``; + s+=``; + s+=`${d.mount==='ceiling'?'П':d.mount==='table'?'С':d.mount==='wall'?'К':'О'}`; + s+=`${esc(d.model).slice(0,14)}`; + s+=``; + }); + s+=''; + $('#layoutbox').innerHTML=s; + bindDrag(scale, pad); +} +function bindDrag(scale, pad){ + const svg=$('#plansvg'); + if(!svg)return; + let dragging=null; + svg.querySelectorAll('.pmove').forEach(g=>{ + g.addEventListener('mousedown',ev=>{ + ev.preventDefault(); + dragging={g, i:+g.dataset.i}; + }); + }); + function pt(ev){ + const rect=svg.getBoundingClientRect(); + const vb=svg.viewBox.baseVal; + const sx=vb.width/rect.width, sy=vb.height/rect.height; + return {x:(ev.clientX-rect.left)*sx, y:(ev.clientY-rect.top)*sy}; + } + function move(ev){ + if(!dragging)return; + const p=pt(ev); + const d=PLAN.devices[dragging.i]; + d.x=Math.min(0.98,Math.max(0.02,(p.x-pad)/(PLAN.w*scale))); + d.y=Math.min(0.98,Math.max(0.02,(p.y-pad)/(PLAN.l*scale))); + dragging.g.setAttribute('transform',`translate(${pad+d.x*PLAN.w*scale},${pad+d.y*PLAN.l*scale})`); + drawPlanPositionsOnly(); + } + function up(){dragging=null;} + svg.addEventListener('mousemove',move); + svg.addEventListener('mouseup',up); + svg.addEventListener('mouseleave',up); +} +function drawPlanPositionsOnly(){ + // обновляем только подписи координат, не перерисовывая точки (чтобы не рвать drag) + const info=$('#plancoords'); + if(!info||!PLAN)return; + info.textContent=PLAN.devices.map(d=>`${d.model} (${(d.x*PLAN.w).toFixed(1)}, ${(d.y*PLAN.l).toFixed(1)}) м`).join(' · '); +} async function renderLayout(){ const ks=Object.keys(SEL); if(!ks.length){$('#layoutbox').innerHTML='соберите состав';return;}