Skip to content

Commit

Permalink
UI Config storage updates
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed May 26, 2024
1 parent 9c9c44e commit 924a22f
Show file tree
Hide file tree
Showing 11 changed files with 342 additions and 74 deletions.
1 change: 1 addition & 0 deletions firebird-ng/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component } from '@angular/core';
import { RouterOutlet, RouterModule, Router} from '@angular/router';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import {BehaviorSubject, Subject} from "rxjs";
@Component({
selector: 'app-root',
standalone: true,
Expand Down
16 changes: 16 additions & 0 deletions firebird-ng/src/app/game-controller.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { GameControllerService } from './game-controller.service';

describe('GameControllerService', () => {
let service: GameControllerService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(GameControllerService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
9 changes: 9 additions & 0 deletions firebird-ng/src/app/game-controller.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Injectable } from '@angular/core';

@Injectable({
providedIn: 'root'
})
export class GameControllerService {

constructor() { }
}
6 changes: 3 additions & 3 deletions firebird-ng/src/app/input-config/input-config.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<div class="container mt-3">
<h3>Event display source control</h3>

<form [formGroup]="geoForm">
<form >
<div class="mt-4">
<h5>Geometry source</h5>
<select class="form-control" formControlName="selectedGeometry">
<select class="form-control" [formControl]="selectedGeometry">
<option value="epic-central-optimized">EIC ePIC Central Detector optimized</option>
<option value="https://eic.github.io/epic/artifacts/tgeo/epic_bhcal.root">epic_bhcal.root</option>
<option value="https://eic.github.io/epic/artifacts/tgeo/epic_calorimeters.root">epic_calorimeters.root</option>
Expand Down Expand Up @@ -42,7 +42,7 @@ <h5>Geometry source</h5>

<div class="mt-4">
<h5>Selected events</h5>
<select class="form-control mt-2" formControlName="selectedEvent">
<select class="form-control mt-2" REMformControlName="selectedEvent">
<option value="Central detector">Central detector</option>
<option value="Far forward">Far forward</option>
</select>
Expand Down
87 changes: 65 additions & 22 deletions firebird-ng/src/app/input-config/input-config.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// event-display-source.component.ts
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { GeometryService } from '../geometry.service';
import { FormBuilder, FormGroup, FormControl } from '@angular/forms';
import { UserConfigService } from "../user-config.service";
import { ReactiveFormsModule } from '@angular/forms';
import {RouterLink} from '@angular/router';
import {ConfigProperty} from "../utils/config-property";

@Component({
selector: 'app-input-config',
Expand All @@ -14,31 +15,73 @@ import {RouterLink} from '@angular/router';
})
export class InputConfigComponent implements OnInit {

geoForm: FormGroup;
selectedGeometry: FormControl<string | null>;

constructor(private fb: FormBuilder, private geometryService: GeometryService) {
this.geoForm = this.fb.group({
selectedGeometry: ['eic geometry'],
geoOptEnabled: [false],
selectedEvent: ['Central detector'],
geoPostEnabled: [false]
});
constructor(private configService: UserConfigService) {
this.selectedGeometry = new FormControl();
// this.selectedGeometry.valueChanges.subscribe(
// value => this.configService.selectedGeometry.value=value??""
// );
// this.configService.selectedGeometry.changes$.subscribe(
// value => this.selectedGeometry.setValue(value, { emitEvent: false })
// );
// this.geoForm = this.fb.group(this.stateFromConfig());
//
// this.geoForm.valueChanges.subscribe(value => {
// this.geometryService.saveGeoConfig(value);
// console.log(value);
// });
}

//geoForm: FormGroup;

//
// constructor(private fb: FormBuilder, private configService: UserConfigService) {
// this.geoForm = this.fb.group(this.stateFromConfig());
//
// this.geoForm.valueChanges.subscribe(value => {
// this.geometryService.saveGeoConfig(value);
// console.log(value);
// });
// }
//
// stateFromConfig(): any {
// return {
// selectedGeometry: this.configService.selectedGeometry,
// geoOptEnabled: [false],
// selectedEvent: ['Central detector'],
// geoPostEnabled: [false]
// }
// }
//

this.geoForm.valueChanges.subscribe(value => {
this.geometryService.saveGeoConfig(value);
console.log(value);
});
bindConfigToControl<Type>(control: FormControl<Type | null>, config: ConfigProperty<Type> ) {
control.setValue(config.value, { emitEvent: false })
control.valueChanges.subscribe(
value => {
if(value !== null) {
config.value=value;
}
}
);
config.changes$.subscribe(
value => {
control.setValue(value, { emitEvent: false })
}
);
}

ngOnInit(): void {
const savedSettings = this.geometryService.getState();
if (savedSettings) {
this.geoForm.setValue(savedSettings);
}

this.geometryService.state$.subscribe(state => {
this.geoForm.setValue(state, { emitEvent: false });
});
//this.selectedGeometry.setValue(this.configService.selectedGeometry.value, { emitEvent: false })
this.bindConfigToControl(this.selectedGeometry, this.configService.selectedGeometry);
// const savedSettings = this.geometryService.getState();
// if (savedSettings) {
// this.geoForm.setValue(savedSettings);
// }
//
// this.geometryService.state$.subscribe(state => {
// this.geoForm.setValue(state, { emitEvent: false });
// });
}

}
97 changes: 50 additions & 47 deletions firebird-ng/src/app/main-display/main-display.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from "../utils/three.utils";
import {mergeMeshList, MergeResult} from "../utils/three-geometry-merge";
import {PhoenixThreeFacade} from "../utils/phoenix-three-facade";
import {BehaviorSubject, Subject} from "rxjs";


@Component({
Expand All @@ -42,9 +43,12 @@ export class MainDisplayComponent implements OnInit {

/** The Default color of elements if not set */
defaultColor: Color = new Color(0x2fd691);


private renderer: THREE.Renderer|null = null;
private camera: THREE.Camera|null = null;
private scene: THREE.Scene|null = null;
private stats: any|null = null; // Stats JS display from UI manager

private threeFacade: PhoenixThreeFacade;

Expand Down Expand Up @@ -192,6 +196,12 @@ export class MainDisplayComponent implements OnInit {
};

handleGamepadInput () {

// Update stats display that showing FPS, etc.
if (this.stats) {
this.stats.update();
}

const gamepads = navigator.getGamepads();
for (const gamepad of gamepads) {
if (gamepad) {
Expand Down Expand Up @@ -261,6 +271,8 @@ export class MainDisplayComponent implements OnInit {
// camera.position.z += zoomAxis * 0.1; // Adjust zoom sensitivity
// }



// Zooming using buttons
const zoomInButton = gamepad.buttons[2];
const zoomOutButton = gamepad.buttons[0];
Expand All @@ -284,51 +296,6 @@ export class MainDisplayComponent implements OnInit {
}

break; // Only use the first connected gamepad

//
//
// if (Math.abs(xAxis) > 0.1 || Math.abs(yAxis) > 0.1) {
// // Get the current radius and angles in spherical coordinates relative to the target
// const radius = controls.target.distanceTo(camera.position);
// const phi = Math.atan2(
// Math.sqrt((camera.position.x - controls.target.x) ** 2 + (camera.position.z - controls.target.z) ** 2),
// (camera.position.y - controls.target.y)
// );
// const theta = Math.atan2(camera.position.z - controls.target.z, camera.position.x - controls.target.x);
//
// // Adjust theta (azimuthal angle) based on the x-axis of the joystick
// const newTheta = theta - xAxis * 0.1;
//
// // Adjust phi (polar angle) based on the y-axis of the joystick
// const newPhi = phi - yAxis * 0.1;
//
// // Ensure the phi is clamped to prevent the camera from flipping over
// const clampedPhi = Math.max(0.1, Math.min(Math.PI - 0.1, newPhi));
//
// // Convert updated spherical coordinates back to Cartesian coordinates
// camera.position.x = controls.target.x + radius * Math.sin(clampedPhi) * Math.cos(newTheta);
// camera.position.y = controls.target.y + radius * Math.cos(clampedPhi);
// camera.position.z = controls.target.z + radius * Math.sin(clampedPhi) * Math.sin(newTheta);
//
// camera.lookAt(controls.target);
// controls.update();
// }


//
// //console.log(`Using gamepad at index ${gamepad.index}: ${gamepad.id}`);
// gamepad.axes.forEach((axis, index) => {
// if (axis !== 0) {
// console.log(`Axis ${index}: ${axis.toFixed(4)}`);
// }
// });
// gamepad.buttons.forEach((button, index) => {
// if (button.pressed) {
// console.log(`Button ${index} is pressed with value ${button.value}`);
// }
// });
// // Stop after processing the first connected gamepad
// break;
}
}
};
Expand All @@ -355,7 +322,7 @@ export class MainDisplayComponent implements OnInit {
defaultEventFile: {
// (Assuming the file exists in the `src/assets` directory of the app)
//eventFile: 'assets/herwig_18x275_5evt.json',
eventFile: 'assets/events/herwig_5x41_5evt_showers.json',
eventFile: 'assets/events/pythia8.json',
eventType: 'json' // or zip
},
}
Expand All @@ -376,7 +343,7 @@ export class MainDisplayComponent implements OnInit {
const globalPlane = new THREE.Plane( new THREE.Vector3( - 1, 0, 0 ), 0.1 );

const gui = new GUI({
container: document.getElementById("lil-gui-place") ?? undefined,
// container: document.getElementById("lil-gui-place") ?? undefined,

});
gui.title("Debug");
Expand All @@ -398,11 +365,47 @@ export class MainDisplayComponent implements OnInit {
.getLoadingManager()
.addProgressListener((progress) => (this.loadingProgress = progress));

this.stats = (this.eventDisplay.getUIManager() as any).stats;


threeManager.setAnimationLoop(()=>{this.handleGamepadInput()});


let beSubject = new BehaviorSubject('a');

beSubject.next('b');

beSubject.subscribe(value => {
console.log('BehaviorSubject: Subscription received the value ', value);

// Subscription received B. It would not happen
// for an Observable or Subject by default.
});

beSubject.next('c');
// Subscription received C.

beSubject.next('d');
// Subscription received D.

// Subject.

let subject = new Subject();

subject.next('b');

subject.subscribe(value => {
console.log('Subject: Subscription received the value ', value);

// Subscription won't receive anything at this point.
});

subject.next('c');
// Subscription received C.

subject.next('d');


//const events_url = "https://eic.github.io/epic/artifacts/sim_dis_10x100_minQ2=1000_epic_craterlake.edm4hep.root/sim_dis_10x100_minQ2=1000_epic_craterlake.edm4hep.root"
//const events_url = "https://eic.github.io/epic/artifacts/sim_dis_10x100_minQ2=1000_epic_craterlake.edm4hep.root"
// const events_url = "assets/events/sim_dis_10x100_minQ2=1000_epic_craterlake.edm4hep.root"
Expand Down
13 changes: 11 additions & 2 deletions firebird-ng/src/app/root-geometry.processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ export class RootGeometryProcessor {
"SweeperMag",
"AnalyzerMag",
"ZDC",
"LFHCAL",
"HcalFarForward"
//"LFHCAL",
"HcalFarForward",
"InnerTrackingSupport"
];

subDetectorsRules: DetectorGeometryFineTuning[] = [
Expand Down Expand Up @@ -111,6 +112,14 @@ export class RootGeometryProcessor {
{pattern: "*/EcalEndcapP_layer1_0*", action: EditActions.RemoveChildren},
]
},
{
namePattern: "*/LFHCAL_*",
editRules: [
{pattern: "*/LFHCAL_8M*", action: EditActions.SetGeoBit, geoBit: GeoAttBits.kVisThis},
{pattern: "*/LFHCAL_8M*", action: EditActions.UnsetGeoBit, geoBit: GeoAttBits.kVisDaughters},
{pattern: "*/LFHCAL_8M*", action: EditActions.UnsetGeoBit, geoBit: GeoAttBits.kVisNone},
]
},
{
namePattern: "*/HcalEndcapPInsert_23*",
editRules: [
Expand Down
16 changes: 16 additions & 0 deletions firebird-ng/src/app/user-config.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { UserConfigService } from './user-config.service';

describe('UserConfigService', () => {
let service: UserConfigService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(UserConfigService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
14 changes: 14 additions & 0 deletions firebird-ng/src/app/user-config.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Injectable } from '@angular/core';
import {ConfigProperty} from "./utils/config-property";

@Injectable({
providedIn: 'root'
})
export class UserConfigService {

public selectedGeometry: ConfigProperty<string>;

constructor() {
this.selectedGeometry = new ConfigProperty("selectedGeometry", "epic-central-optimized");
}
}
Loading

0 comments on commit 924a22f

Please sign in to comment.