/*
* Created by yvesb on 10/10/2016.
*/
/*
* MathGraph32 Javascript : Software for animating online dynamic mathematics figures
* https://www.mathgraph32.org/
* @Author Yves Biton (yves.biton@sesamath.net)
* @License: GNU AGPLv3 https://www.gnu.org/licenses/agpl-3.0.html
*/
import CAffLiePt from '../objets/CAffLiePt'
import CElementGraphique from '../objets/CElementGraphique'
import Color from '../types/Color'
import TikzColor from '../types/TikzColor'
import { chaineNombre, ConvRadDeg, getStr } from '../kernel/kernel'
import { adaptStringTikz } from '../kernel/kernelAdd'
import StyleEncadrement from '../types/StyleEncadrement'
import Fonte from '../types/Fonte'
import NatObj from '../types/NatObj'
export default CAffLiePt
CAffLiePt.prototype.depDe4Rec = function (p) {
const dep = CElementGraphique.prototype.depDe4Rec.call(this, p) || this.angText.depDe4Rec(p)
if (this.pointLie === null) { return dep } else { return dep || this.pointLie.depDe4Rec(p) || this.angText.depDe4Rec(p) }
}
CAffLiePt.prototype.compHist = function () {
let res = CElementGraphique.prototype.compHist.call(this)
if (!this.pointLie) res += '\nAbsolute position: (' + this.xNom + '; ' + this.yNom + ')'
res += '\n' + 'Font size: ' + this.taillePolice
let ch = ' Horizontal align: '
switch (this.alignementHorizontal) {
case CAffLiePt.alignHorLeft :
ch += 'right'
break
case CAffLiePt.alignHorCent :
ch += 'center'
break
case CAffLiePt.alignHorRight :
ch += 'left'
}
res += ch
ch = ' Vertical align: '
switch (this.alignementVertical) {
case CAffLiePt.alignVerTop :
ch += 'bottom'
break
case CAffLiePt.alignHorCent :
ch += 'middle'
break
case CAffLiePt.alignHorRight :
ch += 'top'
}
res += ch
if (this.effacementFond) {
res += '\nBackground erase with color: ' + this.couleurFond.rgb()
}
// Sauf pour les macros qui ont le style d'encadrement 3D on donne le style d'encadrement
// et l'angle d'affichage
if (!this.estDeNature(NatObj.NMacro)) {
ch = '\nFrame style: '
switch (this.encadrement) {
case 0:
ch += 'no frame'
break
case 1:
ch += 'simple frame'
break
default:
ch += '3D frame'
}
res += ch
}
res += '\nOffset: (' + this.decX + ', ' + this.decY + ')'
return res
}
CAffLiePt.prototype.addTikzColors = function (stb, vect) {
let st = CElementGraphique.prototype.addTikzColors.call(this, stb, vect)
if (this.effacementFond) {
const coulFond = this.couleurFond
if (coulFond !== Color.black) {
const code = TikzColor.colorString(coulFond)
if (!TikzColor.containsColor(vect, coulFond)) {
vect.push(code)
st += '\\definecolor{' + code + '}{rgb}{' +
chaineNombre(coulFond.getRed() / 255, 2) + ',' +
chaineNombre(coulFond.getGreen() / 255, 2) + ',' +
chaineNombre(coulFond.getBlue() / 255, 2) + '}' + '\n'
}
}
}
return st
}
CAffLiePt.prototype.tikz = function (dimf, nomaff, coefmult, bu) {
const list = this.listeProprietaire
const ang = String(this.angText.rendValeurRadian() * ConvRadDeg)
let x0 = this.xNom + this.decX
let y0 = this.yNom + this.decY
let style = ''
switch (this.alignementVertical) {
case CAffLiePt.alignVerLow :
style = 'above '
y0 += 2
break
case CAffLiePt.alignVerTop :
style = 'below '
y0 -= 2
}
switch (this.alignementHorizontal) {
case CAffLiePt.alignHorLeft :
style += 'right '
x0 -= 2
break
case CAffLiePt.alignHorRight :
x0 += 2
style += 'left '
}
const x = list.tikzXcoord(x0, dimf, bu)
const y = list.tikzYcoord(y0, dimf, bu)
style += ',' + this.tikzCouleur() + ','
if (this.encadrement !== StyleEncadrement.Sans) {
style += 'draw=' + this.tikzCouleur() + ','
const dinsepx = list.tikzLongueur(2, dimf, bu)
const dinsepy = list.tikzLongueur(4, dimf, bu)
const insepx = chaineNombre(dinsepx, 2)
const insepy = chaineNombre(dinsepy, 2)
style += 'inner xsep =' + insepx + 'cm,inner ysep =' + insepy + 'cm,'
}
if (this.effacementFond) style += 'fill=' + TikzColor.colorString(this.couleurFond) + ','
let ch = Fonte.remplaceUnicodeParLatex(this.chaineAAfficher)
ch = ch.replace(/\n/g, '\\\\')
ch = Fonte.traiteCodesDiese(ch)
ch = adaptStringTikz(ch)// Pour remplacer les % par \%
if (ang === '0') {
return '\\node at ' + '(' + chaineNombre(x, 3) + ', ' + chaineNombre(y, 3) +
') [align=left,' + style + ',font= \\sf ' + this.tikzFont(dimf, this.taillePolice, coefmult, bu) + '] {' + ch + '};'
} else {
return '\\node at ' + '(' + chaineNombre(x, 3) + ', ' + chaineNombre(y, 3) + ') [rotate=' + ang + ',align=left,' + style + 'font= \\sf ' +
this.tikzFont(dimf, this.taillePolice, coefmult, bu) + '] {' + ch + '};'
}
}
CAffLiePt.prototype.adaptRes = function (coef) {
CElementGraphique.prototype.adaptRes.call(this, coef)
this.xNom *= coef
this.yNom *= coef
this.taillePolice *= coef
}
CAffLiePt.prototype.estDefiniParObjDs = function (listeOb) {
const res = this.angText.estDefiniParObjDs(listeOb)
if (this.pointLie == null) return res
else return res && this.pointLie.estDefPar(listeOb)
}
CAffLiePt.prototype.infoAngle = function () {
const chval = this.angText.chaineInfo()
return '\n' + getStr('Angle') + ' : ' + chval
}
/**
* Renvoie true si l'affichage est un objet final de construction
* et son angle d'affichage dépend d'un des objets sources de la construction
* @returns {boolean}
*/
CAffLiePt.prototype.estFinalEtAngleEstDynamique = function () {
return ((this.impProto !== null) && this.angText.depDe(this.impProto))
}