[WORK] План комнаты: тип установки (потолок/стол/стена/стойка), перетаскивание мышью, слой покрытия (круги захвата и конус камеры)

This commit is contained in:
root committed 2026-11-06 18:39:28 +03:00
1 parent 1e9338d618
commit caa11f25b6
3 files changed
+129 -1

No files matched your search

+25
View File
@@ -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)
+20
View File
@@ -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")
+84 -1
View File
@@ -164,7 +164,14 @@ svg{width:100%;height:520px;background:#0a0e13;border:1px solid var(--line);bord
<span class="muted">длина</span><input type="number" id="ll" value="10" min="3" max="60" style="max-width:80px" onchange="renderLayout()">
<button class="btn sm ghost" onclick="downloadSvgFrom('layout')">Скачать SVG</button>
</div>
<label style="display:inline-flex;gap:6px;align-items:center;margin:0 12px 8px 0">
<input type="checkbox" id="showcov" onchange="renderPlanDrag()"> показывать покрытие
</label>
<div class="muted" style="display:inline-block;margin-bottom:8px">
перетаскивайте устройства мышью · 🟠 потолочный · 🟢 настольный · 🔵 камера
</div>
<div id="layoutbox"><span class="muted">соберите состав</span></div>
<div id="plancoords" class="muted" style="margin-top:8px"></div>
</div>
</section>
@@ -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='<span class="muted">соберите состав</span>';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=`<div class="box bad">${esc(r.error)}</div>`;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=`<svg id="plansvg" viewBox="0 0 ${W} ${H}" style="background:#0a0e13;border:1px solid #30363d;border-radius:10px;width:100%;height:560px">`;
s+=`<rect x="${pad}" y="${pad}" width="${PLAN.w*scale}" height="${PLAN.l*scale}" fill="#0f1620" stroke="#2e4a6b" stroke-width="2"/>`;
s+=`<text x="${pad}" y="${pad-10}" fill="#8b949e" font-size="11">${PLAN.w} × ${PLAN.l} м</text>`;
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+=`<circle cx="${cx}" cy="${cy}" r="${d.pickup_m*scale}" fill="${COL[d.mount]}" opacity="0.10"/>`;
}
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+=`<path d="M ${cx} ${cy} L ${x1.toFixed(0)} ${y1.toFixed(0)} A ${len.toFixed(0)} ${len.toFixed(0)} 0 0 1 ${x2.toFixed(0)} ${y2.toFixed(0)} Z" fill="#2f81f7" opacity="0.15"/>`;
}
s+=`<g class="pmove" data-i="${i}" style="cursor:move" transform="translate(${cx},${cy})">`;
s+=`<circle r="14" fill="#161b22" stroke="${COL[d.mount]||'#8b949e'}" stroke-width="2"/>`;
s+=`<text y="4" text-anchor="middle" fill="${COL[d.mount]||'#8b949e'}" font-size="10">${d.mount==='ceiling'?'П':d.mount==='table'?'С':d.mount==='wall'?'К':'О'}</text>`;
s+=`<text y="30" text-anchor="middle" fill="#8b949e" font-size="9">${esc(d.model).slice(0,14)}</text>`;
s+=`</g>`;
});
s+='</svg>';
$('#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='<span class="muted">соберите состав</span>';return;}