Añadidas rotativas, hay un bug de que no se pasan las dimensiones de maquina

This commit is contained in:
imnavajas
2023-12-27 10:42:31 +01:00
parent 998a182a9d
commit 7ec64ebf0c
2 changed files with 145 additions and 52 deletions

View File

@ -483,8 +483,6 @@
<dt class="col-6 fw-semibold"><?= lang("Presupuestos.previewForma") ?></dt>
<dd id="pv_rot_bn_forma" class="col-6 text-left">TBD</dd>
<dt class="col-6 fw-semibold"><?= lang("Presupuestos.previewFormas") ?></dt>
<dd id="pv_rot_bn_nFormas" class="col-6 text-left">TBD</dd>
</dl>
</div>
</div>
@ -562,8 +560,6 @@
<dt class="col-6 fw-semibold"><?= lang("Presupuestos.previewForma") ?></dt>
<dd id="pv_rot_color_forma" class="col-6 text-left">TBD</dd>
<dt class="col-6 fw-semibold"><?= lang("Presupuestos.previewFormas") ?></dt>
<dd id="pv_rot_color_nFormas" class="col-6 text-left">TBD</dd>
</dl>
</div>
</div>
@ -773,13 +769,13 @@ $('#tab-pv-colorhq').on( "click", function() {
$('#tab-pv-rot-bn').on( "click", function() {
getObjetoLP('rot_bn');
previewRotativa('rot_bn');
} );
$('#tab-pv-rot-color').on( "click", function() {
getObjetoLP('rot_color');
previewRotativa('rot_color');
} );
@ -791,8 +787,7 @@ $('#tab-pv-cubierta').on( "click", function() {
$('#tab-pv-esquema-cubierta').on( "click", function() {
getObjetoEC();
previewEsquemaCubierta(objEC);
previewEsquemaCubierta('ec');
} );

View File

@ -2,9 +2,6 @@
var _isCosido = true;
var _offsetSolapas = 2; // millimeters
var objEC;
var pvObj;
@ -96,15 +93,125 @@ function previewInteriorPlana(lpTagName) {
_pvPlana.update();
}
function previewRotativa(lpTagName) {
function previewEsquemaCubierta(objEC) {
// Local parameters
let styleText = {size: 12, family: 'Public Sans'};
let margenTop = 3;
let guardaV = 0;
guardaH = 0;
// Get the preview Object parameters
getObjetoLP(lpTagName);
// Calculos
// Configuracion de las guardas
// Guarda vertical
if (pvObj.nFormasV > 1) {
guardaV = 3;
}
// Guarda horizontal
if (pvObj.nFormasH > 1) {
guardaH = 3;
}
// Constantes relativas al libro
let LVo = pvObj.altoForma / 2;
let LHo = pvObj.anchoForma / 2;
// offset Y
let nTopForms = (pvObj.altoImpresion / 2.0 - margenTop) / (LVo + guardaV);
let yOffset = LVo * getDecimalPart(nTopForms);
//console.log(yOffset);
// Clear the canvas element
$('#pv_' + pvObj.idIndex + '_shape').empty();
// Get the element for placing the graphical elements
var divRotativa = document.getElementById('pv_' + pvObj.idIndex + '_shape');
var _pvRotativa = new Two({fitted: true}).appendTo(divRotativa);
// Calculate the center of the canvas element
var origenRotativa = new Two.Vector(_pvRotativa.width / 2, _pvRotativa.height / 2);
var areaMaquinaRotativa = _pvRotativa.makeRectangle(
origenRotativa.x,
origenRotativa.y,
pvObj.anchoMaquina,
pvObj.altoMaquina);
areaMaquinaRotativa.stroke = 'black';
areaMaquinaRotativa.fill = '#E69F6E';
areaMaquinaRotativa.linewidth = 1;
var areaImpresionRotativa = _pvRotativa.makeRectangle(
origenRotativa.x,
origenRotativa.y,
pvObj.anchoImpresion,
pvObj.altoImpresion);
areaImpresionRotativa.stroke = 'red';
areaImpresionRotativa.fill = '#FCEAF1';
areaImpresionRotativa.linewidth = 1;
var areaClickRotativa = _pvRotativa.makeRectangle(
origenRotativa.x,
origenRotativa.y - (pvObj.altoImpresion / 2 - pvObj.altoClick / 2),
pvObj.anchoImpresion - 10,
pvObj.altoClick);
areaClickRotativa.stroke = 'blue';
//areaClickRotativa.fill = '#FCEAF1';
areaClickRotativa.linewidth = 2;
var formas = [];
for (let iV = 0; iV < pvObj.nFormasV; iV++) {
for (let iH = 0; iH < pvObj.nFormasH; iH++) {
let _offsetX = ((((pvObj.nFormasH - 1) - 2 * iH) * LHo) + (((pvObj.nFormasH - 1) / 2 - iH) * guardaH));
let _offsetY = ((((pvObj.nFormasV - 1) - 2 * iV) * LVo) + (((pvObj.nFormasV - 1) / 2 - iV) * guardaV));
formas[iV + iH] = _pvRotativa.makeRectangle(
origenRotativa.x + _offsetX,
(origenRotativa.y - yOffset) + _offsetY,
pvObj.anchoForma,
pvObj.altoForma);
formas[iV + iH].stroke = 'grey';
formas[iV + iH].fill = '#F4F8F2';
formas[iV + iH].linewidth = 1;
// Texts
_pvRotativa.makeText(pvObj.altoForma, (origenRotativa.x + _offsetX) + (pvObj.anchoForma / 2 - 25), ((origenRotativa.y - yOffset) + _offsetY), styleText);
_pvRotativa.makeText(pvObj.anchoForma, (origenRotativa.x + _offsetX), ((origenRotativa.y - yOffset) + _offsetY) + (pvObj.altoForma / 2 - 15), styleText);
}
}
// Texts
//_pvPlana.makeText(cubiertaObj.altoLibro, origenPlana.x + (fullBookWith / 2 - 25), origenPlana.y, styles);
//_pvPlana.makeText(fullBookWith, origenPlana.x, origenPlana.y + (cubiertaObj.altoLibro / 2 - 15), styles);
_pvRotativa.update();
}
function getDecimalPart(floatNumber) {
let int_part = Math.trunc(floatNumber); // returns 3
let float_part = Number((floatNumber - int_part).toFixed(2)); // return 0.2
return float_part;
}
function previewEsquemaCubierta(lpTagName) {
// Variables locales
let altoLibro, anchoLibro, lomoLibro, anchoSolapa, anchoCubierta, altoSangrado, anchoSangrado;
let styleCotas = {size: 12, family: 'Public Sans'};
// Get the preview Object parameters
getObjetoLP(lpTagName);
// Definicion de los parametros del Esquema de Cubierta (EC)
if (objEC.anchoSolapa == 0) {
if (pvObj.anchoSolapa == 0) {
anchoSangrado = 600; // px
altoSangrado = (anchoSangrado * 0.647 > 350) ? anchoSangrado * 0.647 : 350; // px
altoLibro = altoSangrado * 0.97;
@ -142,7 +249,7 @@ function previewEsquemaCubierta(objEC) {
sangrado.fill = '#FCEAF1';
sangrado.linewidth = 1;
if (objEC.anchoSolapa != 0) {
if (pvObj.anchoSolapa != 0) {
var solapas = previewEC.makeRectangle(
origenEC.x,
origenEC.y,
@ -172,8 +279,8 @@ function previewEsquemaCubierta(objEC) {
previewEC.makeText("Solapa 1", origenEC.x + anchoLibro + (lomoLibro + anchoSolapa) / 2, origenEC.y, stylesSolapa);
previewEC.makeText("Solapa 2", origenEC.x - anchoLibro - (lomoLibro + anchoSolapa) / 2, origenEC.y, stylesSolapa);
// Textos Cotas Solapas
previewEC.makeText(objEC.anchoSolapa + " mm", origenEC.x - anchoLibro - (lomoLibro + anchoSolapa) / 2, origenEC.y - (altoLibro / 3) + 15, styleCotas);
previewEC.makeText(objEC.anchoSolapa + " mm", origenEC.x + anchoLibro + (lomoLibro + anchoSolapa) / 2, origenEC.y - (altoLibro / 3) + 15, styleCotas);
previewEC.makeText(pvObj.anchoSolapa + " mm", origenEC.x - anchoLibro - (lomoLibro + anchoSolapa) / 2, origenEC.y - (altoLibro / 3) + 15, styleCotas);
previewEC.makeText(pvObj.anchoSolapa + " mm", origenEC.x + anchoLibro + (lomoLibro + anchoSolapa) / 2, origenEC.y - (altoLibro / 3) + 15, styleCotas);
}
@ -245,11 +352,11 @@ function previewEsquemaCubierta(objEC) {
previewEC.makeText(sangradoTexto, origenEC.x + (lomoLibro / 2 + anchoLibro + anchoSolapa + 20), origenEC.y, styleSangrado).rotation = -Math.PI / 2;
previewEC.makeText(sangradoTexto, origenEC.x - (lomoLibro / 2 + anchoLibro + anchoSolapa + 20), origenEC.y, styleSangrado).rotation = -Math.PI / 2;
// Cotas
previewEC.makeText(objEC.lomoLibro + " mm", origenEC.x, origenEC.y + (altoLibro / 3) + 15, styleCotas);
previewEC.makeText(objEC.anchoLibro + offsetSolapaValor + " mm", origenEC.x - (lomoLibro / 2 + anchoLibro / 2), origenEC.y - (altoLibro / 3) + 15, styleCotas);
previewEC.makeText(objEC.anchoLibro + offsetSolapaValor + " mm", origenEC.x + (lomoLibro / 2 + anchoLibro / 2), origenEC.y - (altoLibro / 3) + 15, styleCotas);
previewEC.makeText(objEC.altoLibro + (2 * sangradoValor) + " mm", origenEC.x + (lomoLibro / 2 + anchoLibro + anchoSolapa) + 50, origenEC.y, styleCotas).rotation = -Math.PI / 2;
previewEC.makeText((2 * objEC.anchoLibro) + (2 * (objEC.anchoSolapa + offsetSolapaValor)) + objEC.lomoLibro + (2 * sangradoValor) + " mm",
previewEC.makeText(pvObj.lomoLibro + " mm", origenEC.x, origenEC.y + (altoLibro / 3) + 15, styleCotas);
previewEC.makeText(pvObj.anchoLibro + offsetSolapaValor + " mm", origenEC.x - (lomoLibro / 2 + anchoLibro / 2), origenEC.y - (altoLibro / 3) + 15, styleCotas);
previewEC.makeText(pvObj.anchoLibro + offsetSolapaValor + " mm", origenEC.x + (lomoLibro / 2 + anchoLibro / 2), origenEC.y - (altoLibro / 3) + 15, styleCotas);
previewEC.makeText(pvObj.altoLibro + (2 * sangradoValor) + " mm", origenEC.x + (lomoLibro / 2 + anchoLibro + anchoSolapa) + 50, origenEC.y, styleCotas).rotation = -Math.PI / 2;
previewEC.makeText((2 * pvObj.anchoLibro) + (2 * (pvObj.anchoSolapa + offsetSolapaValor)) + pvObj.lomoLibro + (2 * sangradoValor) + " mm",
origenEC.x,
origenEC.y + (altoLibro / 2) + 50,
styleCotas);
@ -267,30 +374,6 @@ function getLomoLibro() {
return parseFloat(_anchoLomo.toFixed(2));
}
function getObjetoEC() {
let _anchoLomo = 0;
$("#tableLineasPresupuesto tbody tr:visible td input[id*='_lomo']").each(function () {
_anchoLomo += parseFloat($(this).val());
});
objEC = {
altoLibro: getDimensionLibro().alto,
anchoLibro: getDimensionLibro().ancho,
anchoSolapa: parseFloat($('#solapas_ancho').val()),
lomoLibro: parseFloat(_anchoLomo.toFixed(2))
};
// Update preview info fields
$('#pv_ec_pg').attr("href", $('#pv_ec_pg').attr('sk-url') + $('#lp_cubierta_papel').val());
$('#pv_ec_pi').attr("href", $('#pv_ec_pi').attr('sk-url') + $('#lp_cubierta_papelImpresion').val());
$('#pv_ec_mi').attr("href", $('#pv_ec_mi').attr('sk-url') + $('#lp_cubierta_maquina').val());
$('#pv_ec_libro').text(objEC.anchoLibro + "X" + objEC.altoLibro);
$('#pv_ec_lomo').text(objEC.lomoLibro);
$('#pv_ec_solapas').text(objEC.anchoSolapa);
(objEC.anchoSolapa != 0) ? $('.pv-ec-solapas').show() : $('.pv-ec-solapas').hide();
}
function getObjetoLP(lpName) {
@ -341,16 +424,32 @@ function getObjetoLP(lpName) {
(pvObj.anchoSolapa != 0) ? $('.pv-solapas').show() : $('.pv-solapas').hide();
// Custom overwrites
switch (pvObj.idIndex){
switch (pvObj.idIndex) {
case 'cubierta':
pvObj.anchoForma = ((2 * pvObj.anchoLibro) + (2 * (pvObj.anchoSolapa + _offsetSolapas)) + pvObj.lomoLibro);
$(pvName + '_forma').text(pvObj.anchoForma + "x" + pvObj.altoForma);
break;
case 'ec':
$(pvName + '_pg').attr("href", $(pvName + '_pg').attr('sk-url') + $('#lp_cubierta_papel').val());
$(pvName + '_pi').attr("href", $(pvName + '_pi').attr('sk-url') + $('#lp_cubierta_papelImpresion').val());
$(pvName + '_mi').attr("href", $(pvName + '_mi').attr('sk-url') + $('#lp_cubierta_maquina').val());
$('#pv_ec_lomo').text(pvObj.lomoLibro);
break;
case 'rot_bn':
case 'rot_color':
pvObj.anchoMaquina = 520;
pvObj.altoMaquina= 800;
pvObj.anchoImpresion= 515;
pvObj.altoImpresion= 800;
pvObj.nFormasH = 1;
pvObj.nFormasV = 3;
pvObj.altoClick = 305;
break;
default:
break;
}
}
@ -363,11 +462,10 @@ function getVisibleTabs() {
$("#" + $(this).attr('id').replace('lp_', 'tab-pv-')).show();
$("#" + $(this).attr('id').replace('lp_', 'tab-pv-esquema-')).show();
} else if ($(this).attr('id').indexOf('_data') > -1) {
// Discard
} else if ($(this).attr('id').indexOf('lp_rot_') > -1) {
// Do nothing here
} else if ($(this).attr('id').indexOf('_rot') > -1) {
$("#" + $(this).attr('id').replace('lp_rot_', 'tab-pv-rot-')).show();
}
else {
} else {
$("#" + $(this).attr('id').replace('lp_', 'tab-pv-')).show();
}