Skip to content

Commit

Permalink
feat(app): bind clipping state with UI menu
Browse files Browse the repository at this point in the history
  • Loading branch information
9inpachi committed Apr 11, 2021
1 parent 854e543 commit 40bbba0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
15 changes: 14 additions & 1 deletion packages/phoenix-event-display/src/event-display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export class EventDisplay {
private ui: UIManager;
/** Loading manager for loadable resources */
private loadingManager: LoadingManager;
/** State manager for managing event display state. */
private stateManager: StateManager;

/**
* Create the Phoenix event display and intitialize all the elements.
Expand Down Expand Up @@ -64,7 +66,7 @@ export class EventDisplay {
// Initialize the UI with configuration
this.ui.init(configuration);
// Set up for the state manager
new StateManager().setEventDisplay(this);
this.getStateManager().setEventDisplay(this);

// Animate loop
const uiLoop = () => {
Expand Down Expand Up @@ -181,6 +183,17 @@ export class EventDisplay {
return this.loadingManager;
}

/**
* Get the state manager that manages event display's state.
* @returns The state manager.
*/
public getStateManager() {
if (!this.stateManager) {
this.stateManager = new StateManager();
}
return this.stateManager;
}

// **********************
// * LOADING GEOMETRIES *
// **********************
Expand Down
10 changes: 6 additions & 4 deletions packages/phoenix-event-display/src/managers/state-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EventDisplay } from '../event-display';
import { Camera } from 'three';
import { PhoenixMenuNode } from '../ui/phoenix-menu/phoenix-menu-node';
import { loadFile, saveFile } from '../helpers/file';
import { ActiveVariable } from '../helpers/active-variable';

/**
* A singleton manager for managing the scene's state.
Expand All @@ -12,9 +13,9 @@ export class StateManager {
/** Root node of the phoenix menu. */
phoenixMenuRoot: PhoenixMenuNode;
/** Whether the clipping is enabled or not. */
clippingEnabled: boolean;
clippingEnabled = new ActiveVariable(false);
/** Angle of the clipping. */
clippingAngle: number;
clippingAngle = new ActiveVariable(0);
/** The active camera. */
activeCamera: Camera;
/** The event display. */
Expand Down Expand Up @@ -103,6 +104,7 @@ export class StateManager {
jsonData['eventDisplay']?.['cameraPosition']
);
if (jsonData['eventDisplay']?.['clippingAngle']) {
this.setClippingEnabled(true);
this.eventDisplay.getUIManager().setClipping(true);
this.eventDisplay
.getUIManager()
Expand All @@ -116,15 +118,15 @@ export class StateManager {
* @param clipping Whether the clipping is enabled or not.
*/
setClippingEnabled(clipping: boolean) {
this.clippingEnabled = clipping;
this.clippingEnabled.update(clipping);
}

/**
* Set the angle of clipping.
* @param angle Angle fo clipping.
*/
setClippingAngle(angle: number) {
this.clippingAngle = angle;
this.clippingAngle.update(angle);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
*ngFor="let object of showingCollection; index as i"
[attr.id]="object.uuid"
[ngClass]="{
'active-object': activeObject && activeObject.value === object.uuid
'active-object':
activeObject && activeObject.value === object.uuid
}"
>
<td>#{{ i }}</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('CollectionsInfoOverlayComponent', () => {
spyOn(eventDisplayService, 'getActiveObjectId').and.callThrough();

component.ngOnInit();
component.activeObject.uuid = ROW_ID;
component.activeObject.value = ROW_ID;

expect(eventDisplayService.getActiveObjectId).toHaveBeenCalled();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<mat-menu #menu>
<mat-checkbox
class="mat-menu-item"
[checked]="clippingEnabled"
(click)="$event.stopPropagation()"
(change)="toggleClipping($event)"
>Clipping
Expand All @@ -10,6 +11,7 @@
max="180"
step="1"
thumbLabel
[value]="clippingAngle"
(click)="$event.stopPropagation()"
(input)="changeClippingAngle($event)"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@ import { EventDisplayService } from '../../../services/event-display.service';
})
export class ObjectClippingComponent {
clippingEnabled: boolean;
clippingAngle: number;

constructor(private eventDisplay: EventDisplayService) {}
constructor(private eventDisplay: EventDisplayService) {
const stateManager = this.eventDisplay.getStateManager();
stateManager.clippingEnabled.onUpdate(
(clippingValue) => (this.clippingEnabled = clippingValue)
);
stateManager.clippingAngle.onUpdate(
(value) => (this.clippingAngle = value)
);
}

changeClippingAngle(change: MatSliderChange) {
const angle = change.value;
Expand Down

0 comments on commit 40bbba0

Please sign in to comment.