Warning, /firebird/firebird-ng/src/app/components/view-options/cartesian-grid-config/cartesian-grid-config.component.ts is written in an unsupported language. File is not indexed.
0001 import { Component, Inject, type OnInit } from '@angular/core';
0002 import { Vector3 } from 'three';
0003 import {MatCheckbox, MatCheckboxChange} from '@angular/material/checkbox';
0004 import {
0005 MAT_DIALOG_DATA,
0006 MatDialogActions,
0007 MatDialogContent,
0008 MatDialogRef,
0009 MatDialogTitle
0010 } from '@angular/material/dialog';
0011 import {EventDisplayService} from "phoenix-ui-components";
0012 import { Subscription } from 'rxjs';
0013 import {DecimalPipe} from "@angular/common";
0014 import {MatButton} from "@angular/material/button";
0015 import {MatMenuItem} from "@angular/material/menu";
0016 import {FormsModule} from "@angular/forms";
0017 import {MatSlider, MatSliderThumb} from "@angular/material/slider";
0018
0019 @Component({
0020 selector: 'app-cartesian-grid-config',
0021 templateUrl: './cartesian-grid-config.component.html',
0022 styleUrls: ['./cartesian-grid-config.component.scss'],
0023 imports: [
0024 MatDialogTitle,
0025 MatDialogContent,
0026 DecimalPipe,
0027 MatButton,
0028 MatMenuItem,
0029 MatCheckbox,
0030 FormsModule,
0031 MatSlider,
0032 MatSliderThumb,
0033 MatDialogActions
0034 ],
0035 standalone: true
0036 })
0037 export class CartesianGridConfigComponent implements OnInit {
0038 cartesianPos = new Vector3();
0039 originChangedSub: Subscription | null = null;
0040 stopShiftingSub: Subscription | null = null;
0041 showCartesianGrid!: boolean;
0042 gridConfig!: {
0043 showXY: boolean;
0044 showYZ: boolean;
0045 showZX: boolean;
0046 xDistance: number;
0047 yDistance: number;
0048 zDistance: number;
0049 sparsity: number;
0050 };
0051 scale!: number;
0052 shiftGrid!: boolean;
0053
0054 constructor(
0055 @Inject(MAT_DIALOG_DATA)
0056 public data: { gridVisible: boolean; scale: number },
0057 private dialogRef: MatDialogRef<CartesianGridConfigComponent>,
0058 private eventDisplay: EventDisplayService,
0059 ) {}
0060
0061 ngOnInit(): void {
0062 this.shiftGrid = this.eventDisplay.getThreeManager().shiftGrid;
0063 this.showCartesianGrid = this.data.gridVisible;
0064 this.scale = this.data.scale;
0065 this.gridConfig = this.eventDisplay.getUIManager().getCartesianGridConfig();
0066 this.cartesianPos = this.eventDisplay.getThreeManager().origin;
0067 }
0068
0069 onClose() {
0070 this.dialogRef.close();
0071 }
0072
0073 onSave(x: string, y: string, z: string) {
0074 const xNum = Number(x);
0075 const yNum = Number(y);
0076 const zNum = Number(z);
0077 this.shiftCartesianGridByValues(new Vector3(xNum * 10, yNum * 10, zNum * 10));
0078 }
0079
0080 shiftCartesianGridByPointer() {
0081 this.shiftGrid = true;
0082 this.eventDisplay.getUIManager().shiftCartesianGridByPointer();
0083 this.originChangedSub = this.eventDisplay
0084 .getThreeManager()
0085 .originChanged.subscribe((intersect) => {
0086 this.translateGrid(intersect);
0087 });
0088 this.stopShiftingSub = this.eventDisplay
0089 .getThreeManager()
0090 .stopShifting.subscribe((stop) => {
0091 if (stop) {
0092 this.originChangedSub?.unsubscribe();
0093 this.stopShiftingSub?.unsubscribe();
0094 }
0095 });
0096 this.onClose();
0097 }
0098
0099 shiftCartesianGridByValues(position: Vector3) {
0100 this.translateGrid(position);
0101 this.eventDisplay.getThreeManager().originChangedEmit(position);
0102 }
0103
0104 translateGrid(position: Vector3) {
0105 const finalPos = position;
0106 const initialPos = this.cartesianPos;
0107 const difference = new Vector3(
0108 finalPos.x - initialPos.x,
0109 finalPos.y - initialPos.y,
0110 finalPos.z - initialPos.z,
0111 );
0112 this.eventDisplay.getUIManager().translateCartesianGrid(difference.clone());
0113 this.eventDisplay
0114 .getUIManager()
0115 .translateCartesianLabels(difference.clone());
0116 this.cartesianPos = finalPos;
0117 }
0118
0119 addXYPlanes(zDistance: Event) {
0120 this.gridConfig.zDistance = Number(
0121 (zDistance.target as HTMLInputElement).value,
0122 );
0123 this.callSetShowCartesianGrid();
0124 }
0125
0126 addYZPlanes(xDistance: Event) {
0127 this.gridConfig.xDistance = Number(
0128 (xDistance.target as HTMLInputElement).value,
0129 );
0130 this.callSetShowCartesianGrid();
0131 }
0132
0133 addZXPlanes(yDistance: Event) {
0134 this.gridConfig.yDistance = Number(
0135 (yDistance.target as HTMLInputElement).value,
0136 );
0137 this.callSetShowCartesianGrid();
0138 }
0139
0140 changeSparsity(sparsity: Event) {
0141 this.gridConfig.sparsity = Number(
0142 (sparsity.target as HTMLInputElement).value,
0143 );
0144 this.callSetShowCartesianGrid();
0145 }
0146
0147 showXYPlanes(change: MatCheckboxChange) {
0148 this.gridConfig.showXY = change.checked;
0149 this.callSetShowCartesianGrid();
0150 }
0151
0152 showYZPlanes(change: MatCheckboxChange) {
0153 this.gridConfig.showYZ = change.checked;
0154 this.callSetShowCartesianGrid();
0155 }
0156
0157 showZXPlanes(change: MatCheckboxChange) {
0158 this.gridConfig.showZX = change.checked;
0159 this.callSetShowCartesianGrid();
0160 }
0161
0162 callSetShowCartesianGrid() {
0163 this.eventDisplay
0164 .getUIManager()
0165 .setShowCartesianGrid(
0166 this.showCartesianGrid,
0167 this.scale,
0168 this.gridConfig,
0169 );
0170 }
0171
0172 // helper function to calculate number of planes
0173 calcPlanes(dis: number) {
0174 return Math.max(
0175 0,
0176 1 + 2 * Math.floor((dis * 10) / (this.scale * this.gridConfig.sparsity)),
0177 );
0178 }
0179 }