141 lines
5.3 KiB
JavaScript
141 lines
5.3 KiB
JavaScript
import { parse } from "svg-parser";
|
|
|
|
import SvgNode from './SvgNode.js'
|
|
import SvgNodes from './SvgNodes.js'
|
|
|
|
export default class {
|
|
async parse(xml) {
|
|
let result1 = parse(xml);
|
|
|
|
this.svg = result1.children.filter((x) => x.tagName == "svg")[0];
|
|
}
|
|
|
|
/**
|
|
* Получить слои документа. Имя слоя можно получить через поле id.
|
|
* @returns
|
|
*/
|
|
get_layers() {
|
|
return this.svg.children.filter((x) => x.tagName == "g");
|
|
}
|
|
|
|
/**
|
|
* Получить данные масштаба карты.
|
|
* @returns {w, h, k, u} Ширина в мм, высота в мм, k * v[px] = v[мм], юниты (mm, cm, inch)
|
|
*/
|
|
get_map_scale() {
|
|
// console.log(this.svg)
|
|
let vb = this.svg.properties.viewBox.split(" ").map((x) => parseFloat(x));
|
|
let w = this.svg.properties.width;
|
|
let h = this.svg.properties.height;
|
|
|
|
let units = {
|
|
in: 25.4,
|
|
mm: 1,
|
|
cm: 10,
|
|
px: 0.0846646,
|
|
// '%': 1
|
|
};
|
|
|
|
const u = Object.keys(units).filter((x) => w.endsWith(x))[0];
|
|
if (!u) throw "Unsupported units";
|
|
|
|
w = Math.round(parseFloat(w.substring(0, w.length - u.length)) * units[u] * 100) / 100;
|
|
h = Math.round(parseFloat(h.substring(0, h.length - u.length)) * units[u] * 100) / 100;
|
|
let k = vb[2] / w;
|
|
|
|
return { w, h, k, u };
|
|
}
|
|
|
|
/**
|
|
* Достать из слоя опордные скважины
|
|
* @param {*} layer Слой в котором 2 последние группы содержат опорные скважины.
|
|
* @returns { w1, w2 } Опрорные скважины
|
|
*/
|
|
extract_anchor(layer) {
|
|
let w1 = this.extract_well(layer.children[layer.children.length - 1]);
|
|
let w2 = this.extract_well(layer.children[layer.children.length - 2]);
|
|
|
|
return { w1, w2 };
|
|
}
|
|
|
|
_flat(node) {
|
|
if (!node.children) return [node];
|
|
return node.children.reduce((s, c) => s.concat(this._flat(c)), [node]);
|
|
}
|
|
|
|
/**
|
|
* Получить из группы данные скважины (имя, координаты)
|
|
* @param {*} pivot_group Svg группа
|
|
* @returns { {x, y, name} }
|
|
*/
|
|
extract_well(pivot_group) {
|
|
let flat = this._flat(pivot_group);
|
|
let ellipse = flat.filter((x) => x.tagName == "circle" || x.tagName == "ellipse")[0];
|
|
let tr = ellipse.properties.transform
|
|
.replace("matrix(", "")
|
|
.replace(")", "")
|
|
.split(" ")
|
|
.map((x) => parseFloat(x));
|
|
|
|
let text = flat.filter((x) => x.type == "text")[0];
|
|
let name = text.value;
|
|
return { x: tr[4], y: tr[5], name };
|
|
}
|
|
|
|
build_tp_layer(wells, settings){
|
|
const sc = this.get_map_scale()
|
|
|
|
function t2r(tons){
|
|
// tonns/mm2 = tonns/cm2 / 100. S(mm)=Pi*r*r=tons/tons_in_cm2*100. r = sqrt(tons/tons_in_cm2*100 / PI)
|
|
return Math.sqrt(tons / settings.tons_in_cm2 * 100 / Math.PI)
|
|
}
|
|
|
|
let {styles} = settings
|
|
|
|
let defs = new SvgNode("defs")
|
|
defs.append(SvgNodes.defs.simple.radialGradient("rg_opt", "#fff", "#B86B41"))
|
|
defs.append(SvgNodes.defs.simple.radialGradient("rg_wpt", "#fff", "#67c2e5"))
|
|
|
|
let svg = SvgNodes.group(['<metadata id="CorelCorpID_WWPTCorel-Layer"/>']).set_attr("id", "WWPT")
|
|
// Круги
|
|
svg.append(wells.map((x) => SvgNodes.ring_sectors(1.5 * sc.k, t2r(x.wlpt) * sc.k, [{v: x.wopt, style: styles.opt}, {v: x.wwpt, style: styles.wpt}]).move(x.lx, x.ly)));
|
|
// Знак скважины
|
|
svg.append(wells.map((x) => SvgNodes.circle(1.5 * sc.k).move(x.lx, x.ly).set_style(styles.wellhead)));
|
|
// Имя скважины
|
|
svg.append(wells.map((x) => SvgNodes.text(x.well).move(x.lx + styles.wellhead.dx * sc.k, x.ly + styles.wellhead.dy * sc.k).set_style(styles.wellhead)));
|
|
// Обводненность
|
|
svg.append(wells.map((x) => SvgNodes.text(`${Math.round(x.wlf * 1000)/10 || ''}%`).move(x.lx + styles.wlf.dx * sc.k, x.ly + styles.wlf.dy * sc.k).set_style(styles.wlf)));
|
|
|
|
return {defs, svg}
|
|
}
|
|
|
|
build_ti_layer(wells, settings){
|
|
const sc = this.get_map_scale()
|
|
|
|
function t2r(tons){
|
|
// tonns/mm2 = tonns/cm2 / 100. S(mm)=Pi*r*r=tons/tons_in_cm2*100. r = sqrt(tons/tons_in_cm2*100 / PI)
|
|
return Math.sqrt(tons / settings.tons_in_cm2 * 100 / Math.PI)
|
|
}
|
|
|
|
let {styles} = settings
|
|
|
|
let defs = SvgNodes.container()
|
|
defs.append(SvgNodes.defs.simple.radialGradient("rg1", "#fff", "#c1ff5e"))
|
|
|
|
let svg = SvgNodes.group(['<metadata id="CorelCorpID_WWITCorel-Layer"/>']).set_attr("id", "WWIT")
|
|
// Круги
|
|
// let g_rings = SvgNodes.group(['<metadata id="CorelCorpID_WWITRingsCorel-Layer"/>']).set_attr("id", "Круги")
|
|
// svg.append(g_rings)
|
|
svg.append(wells.map((x) => SvgNodes.circle(t2r(x.wwit) * sc.k).set_style(styles.wit).move(x.lx, x.ly)));
|
|
// Знак скважины
|
|
svg.append(wells.map((x) => SvgNodes.circle(1.5 * sc.k).move(x.lx, x.ly).set_style(styles.wellhead)));
|
|
// Имя скважины
|
|
svg.append(wells.map((x) => SvgNodes.text(x.well).move(x.lx + styles.wellhead.dx * sc.k, x.ly + styles.wellhead.dy * sc.k).set_style(styles.wellhead)));
|
|
// Обводненность
|
|
svg.append(wells.map((x) => SvgNodes.text(`${Math.round(x.wlf * 1000)/10 || ''}%`).move(x.lx + styles.wlf.dx * sc.k, x.ly + styles.wlf.dy * sc.k).set_style(styles.wlf)));
|
|
|
|
return {defs, svg}
|
|
}
|
|
|
|
}
|