onMouseMove()

in src/engine/tools23d/edittool.js [171:411]


  onMouseMove(x, y, zoom, distancesV, anglesA, rectsR, areaD, areaTool, textTool, posX, posY) {
    this.isOut = false;
    const ACCURACY = 2;
    let newLine = null;
    let newLine2 = null;
    let countLine = -1;
    let countLine2 = -1;
    for (let i = 0; i < distancesV.length; ++i) {
      /*console.log("kek");
      console.log(`${distancesV[i].line.getxS()}`);
      console.log(`${x}`);
      console.log(`${distancesV[i].line.getyS()}`);
      console.log(`${y}`);*/
      if (this.m_runningState) {
        if (newLine == null) {
          newLine = this.processingLine(distancesV[i].line, x, y);
        }
        if (newLine != null) {
          this.m_scene.remove(distancesV[i].line.getRenderObject());
          this.m_scene.remove(distancesV[i].text);
          distancesV[i].line = newLine;
          const strMsg = `${(
            zoom *
            Math.sqrt(
              (newLine.getxS() - newLine.getxE()) * (newLine.getxS() - newLine.getxE()) * this.m_xPixelSize * this.m_xPixelSize +
                // eslint-disable-next-line
                (newLine.getyS() - newLine.getyE()) * (newLine.getyS() - newLine.getyE()) * this.m_yPixelSize * this.m_yPixelSize
            )
          ).toFixed(2)} mm`;
          const text = new MeshText2D(strMsg);
          text.updateText(
            0.5 * (newLine.getxS() + newLine.getxE()) - 0.0,
            0.5 * (newLine.getyS() + newLine.getyE()) - 0.0,
            this.m_textWidthScr,
            MeshText2D.ALIGN_CENTER,
            MeshText2D.ALIGN_CENTER,
            this.m_textBgColor,
            this.m_textColor
          );
          distancesV[i].text = text;
          this.m_scene.add(distancesV[i].text);
          newLine = null;
          break;
        }
      } else {
        this.processingLine2(distancesV[i].line, x, y);
      }
    }
    if (this.m_runningState) {
      // text: recalculate distance
      if (newLine != null && distancesV.length !== 0 && countLine !== -1) {
        this.m_scene.remove(distancesV[distancesV.length - 1].line.getRenderObject());
        this.m_scene.remove(distancesV[distancesV.length - 1].text);
        distancesV[distancesV.length - 1].line = newLine;
        const strMsg = `${(
          zoom *
          Math.sqrt(
            (newLine.getxS() - newLine.getxE()) * (newLine.getxS() - newLine.getxE()) * this.m_xPixelSize * this.m_xPixelSize +
              // eslint-disable-next-line
              (newLine.getyS() - newLine.getyE()) * (newLine.getyS() - newLine.getyE()) * this.m_yPixelSize * this.m_yPixelSize
          )
        ).toFixed(ACCURACY)} mm`;
        const text = new MeshText2D(strMsg);
        text.updateText(
          0.5 * (newLine.getxS() + newLine.getxE()) - 0.0,
          0.5 * (newLine.getyS() + newLine.getyE()) - 0.0,
          this.m_textWidthScr,
          MeshText2D.ALIGN_CENTER,
          MeshText2D.ALIGN_CENTER,
          this.m_textBgColor,
          this.m_textColor
        );
        distancesV[distancesV.length - 1].text = text;
        this.m_scene.add(distancesV[distancesV.length - 1].text);
        newLine = null;
      }
    }

    countLine = -1;
    countLine2 = -1;
    //console.log('length area');
    //console.log(`${areaD.length}`);
    for (let a = 0; a < areaD.length; ++a) {
      if (this.m_runningState) {
        if (newLine === null && countLine === -1) {
          newLine = this.processingLine(areaD[a].line, x, y);
        }
        if (newLine != null) {
          countLine = a;
          break;
        }
      } else {
        this.processingLine2(areaD[a].line, x, y);
      }
    }
    for (let a = 0; a < areaD.length; ++a) {
      if (this.m_runningState) {
        if (newLine2 === null && a !== countLine) {
          newLine2 = this.processingLine(areaD[a].line, x, y);
        }
        if (newLine2 !== null) {
          countLine2 = a;
          break;
        }
      }
    }
    if (this.m_runningState && areaD.length !== 0 && countLine !== -1) {
      if (newLine !== null) {
        this.m_scene.remove(areaD[countLine].line.getRenderObject());
        areaD[countLine].line = newLine;
        newLine = null;
      }
      if (newLine2 !== null) {
        this.m_scene.remove(areaD[countLine2].line.getRenderObject());
        areaD[countLine2].line = newLine2;
        newLine2 = null;
      }
      console.log('AREA');
      //console.log(`${countLine}`);
      //console.log(`${countLine2}`);
      const pos = this.num(areaTool.m_last_lengths, countLine);
      //console.log(`${pos.begin}`);
      //console.log(`${pos.endl}`);
      this.m_scene.remove(areaD[pos.endl].text);
      /*need for 0 point*/
      areaTool.updateVertexes(zoom, posX, posY);

      console.log(`${areaTool.m_vertexes2[pos.endl].xS}`);
      const area = this.updateArea(areaTool.m_last_lengths, countLine, areaTool.m_vertexes2);
      const strMsgAr = `${area.toFixed(ACCURACY)} mm^2`;
      const textAr = new MeshText2D(strMsgAr);
      textAr.updateText(
        0.5 * (areaD[pos.endl].line.getxS() + areaD[pos.endl].line.getxE()) - 0.0,
        0.5 * (areaD[pos.endl].line.getyS() + areaD[pos.endl].line.getyE()) - 0.0,
        this.m_textWidthScr,
        MeshText2D.ALIGN_CENTER,
        MeshText2D.ALIGN_CENTER,
        this.m_textBgColor,
        this.m_textColor
      );
      areaD[pos.endl].text = textAr;
      this.m_scene.add(areaD[pos.endl].text);
      newLine = null;
    }

    countLine = -1;
    countLine2 = -1;
    for (let n = 0; n < anglesA.length; ++n) {
      if (this.m_runningState) {
        //console.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        if (newLine === null) {
          newLine = this.processingLine(anglesA[n].line1, x, y);
        }
        if (newLine2 === null) {
          newLine2 = this.processingLine(anglesA[n].line2, x, y);
        }
        if (newLine !== null || newLine2 !== null) {
          countLine = n;
          break;
        }
      } else {
        this.processingLine2(anglesA[n].line1, x, y);
        this.processingLine2(anglesA[n].line2, x, y);
      }
    }
    if (this.m_runningState && anglesA.length !== 0 && countLine !== -1) {
      if (newLine != null) {
        this.m_scene.remove(anglesA[countLine].line1.getRenderObject());
        anglesA[countLine].line1 = newLine;
        newLine = null;
      }
      if (newLine2 != null) {
        this.m_scene.remove(anglesA[countLine].line2.getRenderObject());
        anglesA[countLine].line2 = newLine2;
        newLine2 = null;
      }
      this.m_scene.remove(anglesA[countLine].text);
      const len1 = Math.sqrt(
        (anglesA[countLine].line1.getxS() - anglesA[countLine].line1.getxE()) *
          (anglesA[countLine].line1.getxS() - anglesA[countLine].line1.getxE()) +
          (anglesA[countLine].line1.getyS() - anglesA[countLine].line1.getyE()) *
            (anglesA[countLine].line1.getyS() - anglesA[countLine].line1.getyE())
      );
      const len2 = Math.sqrt(
        (anglesA[countLine].line2.getxS() - anglesA[countLine].line2.getxE()) *
          (anglesA[countLine].line2.getxS() - anglesA[countLine].line2.getxE()) +
          (anglesA[countLine].line2.getyS() - anglesA[countLine].line2.getyE()) *
            (anglesA[countLine].line2.getyS() - anglesA[countLine].line2.getyE())
      );
      const strMsg = `${(
        (Math.acos(
          ((anglesA[countLine].line1.getxS() - anglesA[countLine].line1.getxE()) *
            (anglesA[countLine].line2.getxS() - anglesA[countLine].line2.getxE()) +
            (anglesA[countLine].line1.getyS() - anglesA[countLine].line1.getyE()) *
              (anglesA[countLine].line2.getyS() - anglesA[countLine].line2.getyE())) /
            // eslint-disable-next-line
            (len1 * len2)
        ) /
          Math.PI) *
        180
      ).toFixed(2)}°`;
      const textA = new MeshText2D(strMsg);
      const Y_SHIFT_UP = 0.02;
      textA.updateText(
        anglesA[countLine].line1.getxS(),
        anglesA[countLine].line1.getyS() - Y_SHIFT_UP,
        this.m_textWidthScr,
        MeshText2D.ALIGN_CENTER,
        MeshText2D.ALIGN_TOP,
        this.m_textBgColor,
        this.m_textColor
      );
      anglesA[countLine].text = textA;
      this.m_scene.add(anglesA[countLine].text);
    }

    countLine = -1;
    for (let i = 0; i < textTool.m_textArr.length; ++i) {
      if (
        textTool.m_textArr[i].m_xMin <= x &&
        x <= textTool.m_textArr[i].m_xMax &&
        textTool.m_textArr[i].m_yMin <= y &&
        y <= textTool.m_textArr[i].m_yMax
      ) {
        if (this.m_runningState) {
          textTool.move(i, x - this.m_xInnerShift, y + this.m_yInnerShift, zoom, posX, posY);
        } else {
          this.processingText(textTool.m_textArr[i]);
          this.m_xInnerShift = x - textTool.m_textArr[i].m_xMin;
          this.m_yInnerShift = y - textTool.m_textArr[i].m_yMin;
        }
      }
    }
    this.isPointsExist = true;
    if (!this.isOut) {
      this.deletePoints();
      this.isPointsExist = false;
      this.freeArrays();
      this.isOut = true;
    }
  }