Skip to content

Commit

Permalink
Merge pull request #213 from PMKS-Web/undo-redo
Browse files Browse the repository at this point in the history
  • Loading branch information
KohmeiK committed Apr 6, 2024
2 parents c8d621d + 6e81fe9 commit 84b8d2b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/app/component/new-grid/new-grid.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
font-weight: lighter;

#unitsLabel {
poition: absolute;
position: absolute;
top: 30px;
right: 30px;
}
Expand Down
16 changes: 8 additions & 8 deletions src/app/component/toolbar/toolbar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
<mat-icon>bug_report</mat-icon>
Debug
</button>
<!-- <button mat-button (click)='handleUndo()' matTooltip='Undo' [disabled]='!canUndo()' matTooltipShowDelay='1000'>-->
<!-- <mat-icon>undo</mat-icon>-->
<!-- Undo-->
<!-- </button>-->
<!-- <button mat-button (click)='handleRedo()' matTooltip='Redo' [disabled]='!canRedo()' matTooltipShowDelay='1000'>-->
<!-- <mat-icon>redo</mat-icon>-->
<!-- Redo-->
<!-- </button>-->
<button mat-button (click)='handleUndo()' matTooltip='Undo' [disabled]='!canUndo()' matTooltipShowDelay='1000'>
<mat-icon>undo</mat-icon>
Undo
</button>
<button mat-button (click)='handleRedo()' matTooltip='Redo' [disabled]='!canRedo()' matTooltipShowDelay='1000'>
<mat-icon>redo</mat-icon>
Redo
</button>
<button mat-button (click)='openRightPanelSettings()' matTooltip='Change Linkage Settings' matTooltipShowDelay='1000'>
<mat-icon>settings</mat-icon>
Settings
Expand Down
12 changes: 11 additions & 1 deletion src/app/selected-tab.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { MechanismService } from './services/mechanism.service';
import { SynthesisBuilderService } from './services/synthesis/synthesis-builder.service';
import { ActiveObjService } from 'src/app/services/active-obj.service';

export enum TabID {
SYNTHESIZE,
Expand All @@ -18,7 +19,11 @@ export class SelectedTabService {
private _tabNum: BehaviorSubject<TabID>;
private _tabVisible: BehaviorSubject<boolean>;

constructor(private synthesis: SynthesisBuilderService, private mechanism: MechanismService) {
constructor(
private synthesis: SynthesisBuilderService,
private mechanism: MechanismService,
private activeObjService: ActiveObjService
) {
this._tabNum = new BehaviorSubject<TabID>(TabID.EDIT);
this._tabVisible = new BehaviorSubject<boolean>(true);
}
Expand All @@ -28,6 +33,11 @@ export class SelectedTabService {
let previousTab = this.getCurrentTab();
let isDifferentTab = previousTab !== tabID;

// when switching from synthesis to edit/analyze tab, clear selected synthesis pose, if it exists
if (previousTab === TabID.SYNTHESIZE && this.activeObjService.getSelectedObjType() === "SynthesisPose") {
this.activeObjService.updateSelectedObj(null);
}

this._tabNum.next(tabID);
this._tabVisible.next(true);

Expand Down
8 changes: 7 additions & 1 deletion src/app/services/active-obj.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { RealLink } from '../model/link';
import { Coord } from '../model/coord';
import { SynthesisPose } from './synthesis/synthesis-util';

export type ActiveObjType = "Nothing" | "Joint" | "Force" | "Link" | "Grid" | "SynthesisPose";

@Injectable({
providedIn: 'root',
})
export class ActiveObjService {
objType: string = 'Nothing';
objType: ActiveObjType = 'Nothing';
selectedJoint!: RealJoint;
prevSelectedJoint!: RealJoint;
selectedForce!: Force;
Expand All @@ -35,6 +37,10 @@ export class ActiveObjService {
}
}

getSelectedObjType(): ActiveObjType {
return this.objType;
}

fakeUpdateSelectedObj() {
//Don't actually update the selected object, just emit the event so subscribers can update
this.onActiveObjChange.emit(this.objType);
Expand Down

0 comments on commit 84b8d2b

Please sign in to comment.