19 lines
1.8 KiB
TypeScript
19 lines
1.8 KiB
TypeScript
import type {PierModel} from '../src/core/geometry';
|
|
import {keyplanEntities} from '../도면작성/project-views';
|
|
import {entityBounds} from '../도면작성/projection';
|
|
import {drawingSvg} from '../도면작성/svg';
|
|
import {LAYERS,type DrawingDocument} from '../도면작성/types';
|
|
|
|
/** Reuse the drawing workspace's actual model key plan, without a sample alignment. */
|
|
export function quantityPlanSvg(selected:PierModel,models:readonly PierModel[]):string{
|
|
const available=models.length?models:[selected];let scale=100;
|
|
for(let i=0;i<4;i++){const b=entityBounds(keyplanEntities(available,selected,scale*1.8,'',''));scale=Math.max(1,(b.maxX-b.minX)/220,(b.maxY-b.minY)/60);}
|
|
const entities=keyplanEntities(available,selected,scale*1.8,'',''),bounds=entityBounds(entities);
|
|
const doc:DrawingDocument={project:'',bridge:'',pier:selected.name,units:'mm',paper:{name:'PLAN',width:240,height:80},warnings:[],notes:[],settings:{paper:'A3',scale:'auto',dimensions:false,centers:true,elevations:false},views:[{id:'keyplan',title:'KEY PLAN',entities,bounds,geometryBounds:bounds,scale,slot:{x:10,y:10,width:220,height:60}}]};
|
|
return drawingSvg(doc,new Set(Object.keys(LAYERS) as (keyof typeof LAYERS)[]),false,'keyplan').replace('width="240mm" height="80mm"','width="640" height="213"').replaceAll('#00ffff','#087fcb').replaceAll('#00ff00','#173b55').replaceAll('#ff0000','#657f95');
|
|
}
|
|
export async function planPng(svg:string):Promise<string>{
|
|
const url=URL.createObjectURL(new Blob([svg],{type:'image/svg+xml'}));
|
|
try{const img=new Image();img.src=url;await img.decode();const canvas=document.createElement('canvas');canvas.width=1920;canvas.height=640;canvas.getContext('2d')!.drawImage(img,0,0,1920,640);return canvas.toDataURL('image/png').split(',')[1];}finally{URL.revokeObjectURL(url);}
|
|
}
|