From 878848c548b947b6694b12982149ada5d8d70c4f Mon Sep 17 00:00:00 2001 From: AlexG1031 Date: Mon, 12 Feb 2024 13:02:49 -0500 Subject: [PATCH 1/7] Adjusted rpm and deg/s to rad/s --- .../component/settings-panel/settings-panel.component.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/component/settings-panel/settings-panel.component.html b/src/app/component/settings-panel/settings-panel.component.html index 3978b0a..aeb76b7 100644 --- a/src/app/component/settings-panel/settings-panel.component.html +++ b/src/app/component/settings-panel/settings-panel.component.html @@ -34,11 +34,11 @@ Input Speed From 21a717dc32c8a1e6fe8cc6caf81b59f6c9f33768 Mon Sep 17 00:00:00 2001 From: AlexG1031 Date: Thu, 15 Feb 2024 01:10:16 -0500 Subject: [PATCH 2/7] Settings panel now showcases rotational unit (rpm) within the textbox for input speed. --- .../settings-panel/settings-panel.component.html | 4 ++-- .../settings-panel/settings-panel.component.ts | 14 ++++++++++---- src/app/model/utils.ts | 6 ++++++ src/app/services/number-unit-parser.service.ts | 10 ++++++++-- src/app/services/settings.service.ts | 3 ++- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/app/component/settings-panel/settings-panel.component.html b/src/app/component/settings-panel/settings-panel.component.html index aeb76b7..90bb3c2 100644 --- a/src/app/component/settings-panel/settings-panel.component.html +++ b/src/app/component/settings-panel/settings-panel.component.html @@ -34,11 +34,11 @@ Input Speed diff --git a/src/app/component/settings-panel/settings-panel.component.ts b/src/app/component/settings-panel/settings-panel.component.ts index 7a51839..9b770ad 100644 --- a/src/app/component/settings-panel/settings-panel.component.ts +++ b/src/app/component/settings-panel/settings-panel.component.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core'; import { SettingsService } from 'src/app/services/settings.service'; -import { LengthUnit, AngleUnit, ForceUnit, GlobalUnit } from 'src/app/model/utils'; +import { LengthUnit, AngleUnit, ForceUnit, GlobalUnit, RotationUnit } from 'src/app/model/utils'; import { FormBuilder, Validators } from '@angular/forms'; import { NewGridComponent } from '../new-grid/new-grid.component'; import { MechanismService } from '../../services/mechanism.service'; @@ -35,6 +35,7 @@ export class SettingsPanelComponent { currentAngleUnit!: AngleUnit; // currentTorqueUnit!: TorqueUnit; currentGlobalUnit!: GlobalUnit; + currentRotationalUnit!: RotationUnit; rotateDirection!: boolean; currentSpeedSetting!: number; currentObjectScaleSetting!: number; @@ -43,6 +44,7 @@ export class SettingsPanelComponent { this.currentLengthUnit = this.settingsService.lengthUnit.value; this.currentAngleUnit = this.settingsService.angleUnit.value; this.currentGlobalUnit = this.settingsService.globalUnit.value; + this.currentRotationalUnit = this.settingsService.rotationalUnit.value; this.rotateDirection = this.settingsService.isInputCW.value; this.currentSpeedSetting = this.settingsService.inputSpeed.value; this.currentObjectScaleSetting = SettingsService.objectScale; @@ -65,7 +67,10 @@ export class SettingsPanelComponent { this.currentObjectScaleSetting = val; this.settingsForm.patchValue( { objectScale: this.currentObjectScaleSetting.toString() }, - { emitEvent: false } + { emitEvent: false }, + ); + this.settingsForm.patchValue( + { speed: this.nup.formatValueAndUnit(20, this.settingsService.rotationalUnit.getValue()) } ); //Werid place to put this but @@ -87,7 +92,8 @@ export class SettingsPanelComponent { }); this.settingsForm.controls['speed'].valueChanges.subscribe((val) => { if (this.settingsForm.controls['speed'].invalid) { - this.settingsForm.patchValue({ speed: this.currentSpeedSetting.toString() }); + this.settingsForm.patchValue({ speed: this.nup.formatValueAndUnit(Number(val), this.settingsService.rotationalUnit.getValue()), + }); } else { this.currentSpeedSetting = Number(val); this.settingsService.inputSpeed.next(this.currentSpeedSetting); @@ -213,7 +219,7 @@ export class SettingsPanelComponent { } } - numRegex = '^-?[0-9]+(.[0-9]{0,10})?$'; + numRegex = '^-?[0-9]+(\\.[0-9]{0,10})?\\s*[a-zA-Z]*$'; settingsForm = this.fb.group( { speed: ['', [Validators.required, Validators.pattern(this.numRegex)]], diff --git a/src/app/model/utils.ts b/src/app/model/utils.ts index ee5567d..3ab1791 100644 --- a/src/app/model/utils.ts +++ b/src/app/model/utils.ts @@ -21,6 +21,12 @@ export enum AngleUnit { NULL = 12, } +export enum RotationUnit { + RPM = 15, // revolutions per minute + DPS = 16, // degrees per second + RPS = 17, // Radians per second +} + export enum ForceUnit { LBF = 20, NEWTON = 21, diff --git a/src/app/services/number-unit-parser.service.ts b/src/app/services/number-unit-parser.service.ts index fd91c66..a8ca2da 100644 --- a/src/app/services/number-unit-parser.service.ts +++ b/src/app/services/number-unit-parser.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { LengthUnit, AngleUnit, ForceUnit } from '../model/utils'; +import { AngleUnit, ForceUnit, LengthUnit, RotationUnit } from '../model/utils'; @Injectable({ providedIn: 'root', @@ -7,7 +7,7 @@ import { LengthUnit, AngleUnit, ForceUnit } from '../model/utils'; export class NumberUnitParserService { constructor() {} - public formatValueAndUnit(value: number, units: LengthUnit | AngleUnit | ForceUnit): string { + public formatValueAndUnit(value: number, units: LengthUnit | AngleUnit | ForceUnit | RotationUnit): string { switch (units) { case LengthUnit.CM: return value.toFixed(2) + ' cm'; @@ -23,6 +23,12 @@ export class NumberUnitParserService { return value.toFixed(2) + ' lbf'; case ForceUnit.NEWTON: return value.toFixed(2) + ' N'; + case RotationUnit.RPM: + return value.toFixed(2) + ' rpm'; + case RotationUnit.RPS: + return value.toFixed(2) + ' rev/s'; + case RotationUnit.DPS: + return value.toFixed(2) + ' deg/s'; } return 'Error in formatValueAndUnit()'; } diff --git a/src/app/services/settings.service.ts b/src/app/services/settings.service.ts index a2a243c..6489c1e 100644 --- a/src/app/services/settings.service.ts +++ b/src/app/services/settings.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import { BehaviorSubject } from 'rxjs'; -import { LengthUnit, AngleUnit, GlobalUnit, ForceUnit } from '../model/utils'; +import { LengthUnit, AngleUnit, GlobalUnit, ForceUnit, RotationUnit } from '../model/utils'; @Injectable({ providedIn: 'root', @@ -9,6 +9,7 @@ export class SettingsService { lengthUnit = new BehaviorSubject(LengthUnit.CM); angleUnit = new BehaviorSubject(AngleUnit.DEGREE); forceUnit = new BehaviorSubject(ForceUnit.NEWTON); + rotationalUnit = new BehaviorSubject(RotationUnit.RPM); // inputTorque = new BehaviorSubject(TorqueUnit.CM_N); globalUnit = new BehaviorSubject(GlobalUnit.METRIC); isInputCW = new BehaviorSubject(true); From 1b5faf6928a13b9a2047974acd09c03e7e80e482 Mon Sep 17 00:00:00 2001 From: AlexG1031 Date: Mon, 19 Feb 2024 15:32:00 -0500 Subject: [PATCH 3/7] Update most comments based from what Kohmei mentioned. Still needs further testing. --- .../settings-panel.component.ts | 21 +++-- src/app/model/utils.ts | 2 +- .../services/number-unit-parser.service.ts | 77 +++++++++++++++++-- src/app/services/settings.service.ts | 4 +- 4 files changed, 89 insertions(+), 15 deletions(-) diff --git a/src/app/component/settings-panel/settings-panel.component.ts b/src/app/component/settings-panel/settings-panel.component.ts index 9b770ad..a5f1f7c 100644 --- a/src/app/component/settings-panel/settings-panel.component.ts +++ b/src/app/component/settings-panel/settings-panel.component.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core'; import { SettingsService } from 'src/app/services/settings.service'; -import { LengthUnit, AngleUnit, ForceUnit, GlobalUnit, RotationUnit } from 'src/app/model/utils'; +import { LengthUnit, AngleUnit, ForceUnit, GlobalUnit, AngVelUnit } from 'src/app/model/utils'; import { FormBuilder, Validators } from '@angular/forms'; import { NewGridComponent } from '../new-grid/new-grid.component'; import { MechanismService } from '../../services/mechanism.service'; @@ -35,7 +35,7 @@ export class SettingsPanelComponent { currentAngleUnit!: AngleUnit; // currentTorqueUnit!: TorqueUnit; currentGlobalUnit!: GlobalUnit; - currentRotationalUnit!: RotationUnit; + currentAngVelUnit!: AngVelUnit; rotateDirection!: boolean; currentSpeedSetting!: number; currentObjectScaleSetting!: number; @@ -44,7 +44,7 @@ export class SettingsPanelComponent { this.currentLengthUnit = this.settingsService.lengthUnit.value; this.currentAngleUnit = this.settingsService.angleUnit.value; this.currentGlobalUnit = this.settingsService.globalUnit.value; - this.currentRotationalUnit = this.settingsService.rotationalUnit.value; + this.currentAngVelUnit = this.settingsService.angVelUnit.value; this.rotateDirection = this.settingsService.isInputCW.value; this.currentSpeedSetting = this.settingsService.inputSpeed.value; this.currentObjectScaleSetting = SettingsService.objectScale; @@ -70,7 +70,7 @@ export class SettingsPanelComponent { { emitEvent: false }, ); this.settingsForm.patchValue( - { speed: this.nup.formatValueAndUnit(20, this.settingsService.rotationalUnit.getValue()) } + { speed: this.nup.formatValueAndUnit(this.currentSpeedSetting, this.settingsService.angVelUnit.getValue()) } ); //Werid place to put this but @@ -92,10 +92,17 @@ export class SettingsPanelComponent { }); this.settingsForm.controls['speed'].valueChanges.subscribe((val) => { if (this.settingsForm.controls['speed'].invalid) { - this.settingsForm.patchValue({ speed: this.nup.formatValueAndUnit(Number(val), this.settingsService.rotationalUnit.getValue()), - }); + const [success, value] = this.nup.parseAngVelString(val!, this.settingsService.angVelUnit.getValue()); + const str = this.nup.formatValueAndUnit(value, this.settingsService.angVelUnit.getValue()); + this.settingsForm.patchValue( + { speed: str}, + {emitEvent: false }); + this.settingsService.inputSpeed.next(value); + // this.settingsForm.patchValue({ speed: this.nup.formatValueAndUnit(value, this.settingsService.angVelUnit.getValue()) }); } else { this.currentSpeedSetting = Number(val); + this.settingsForm.patchValue({ speed:this.currentSpeedSetting.toString() }); + // this.settingsForm.patchValue({ speed: this.nup.formatValueAndUnit(this.currentSpeedSetting, this.settingsService.angVelUnit.getValue()) }); this.settingsService.inputSpeed.next(this.currentSpeedSetting); } this.mechanismSrv.updateMechanism(); @@ -219,7 +226,7 @@ export class SettingsPanelComponent { } } - numRegex = '^-?[0-9]+(\\.[0-9]{0,10})?\\s*[a-zA-Z]*$'; + numRegex = '^-?[0-9]+(.[0-9]{0,10})?$'; settingsForm = this.fb.group( { speed: ['', [Validators.required, Validators.pattern(this.numRegex)]], diff --git a/src/app/model/utils.ts b/src/app/model/utils.ts index 3ab1791..1fb076c 100644 --- a/src/app/model/utils.ts +++ b/src/app/model/utils.ts @@ -21,7 +21,7 @@ export enum AngleUnit { NULL = 12, } -export enum RotationUnit { +export enum AngVelUnit { RPM = 15, // revolutions per minute DPS = 16, // degrees per second RPS = 17, // Radians per second diff --git a/src/app/services/number-unit-parser.service.ts b/src/app/services/number-unit-parser.service.ts index a8ca2da..735bf94 100644 --- a/src/app/services/number-unit-parser.service.ts +++ b/src/app/services/number-unit-parser.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { AngleUnit, ForceUnit, LengthUnit, RotationUnit } from '../model/utils'; +import { AngleUnit, AngVelUnit, ForceUnit, LengthUnit } from '../model/utils'; @Injectable({ providedIn: 'root', @@ -7,7 +7,7 @@ import { AngleUnit, ForceUnit, LengthUnit, RotationUnit } from '../model/utils'; export class NumberUnitParserService { constructor() {} - public formatValueAndUnit(value: number, units: LengthUnit | AngleUnit | ForceUnit | RotationUnit): string { + public formatValueAndUnit(value: number, units: LengthUnit | AngleUnit | ForceUnit | AngVelUnit): string { switch (units) { case LengthUnit.CM: return value.toFixed(2) + ' cm'; @@ -23,11 +23,11 @@ export class NumberUnitParserService { return value.toFixed(2) + ' lbf'; case ForceUnit.NEWTON: return value.toFixed(2) + ' N'; - case RotationUnit.RPM: + case AngVelUnit.RPM: return value.toFixed(2) + ' rpm'; - case RotationUnit.RPS: + case AngVelUnit.RPS: return value.toFixed(2) + ' rev/s'; - case RotationUnit.DPS: + case AngVelUnit.DPS: return value.toFixed(2) + ' deg/s'; } return 'Error in formatValueAndUnit()'; @@ -115,6 +115,36 @@ export class NumberUnitParserService { } } + public parseAngVelString(input: string, desiredUnits: AngVelUnit): [boolean, number] { + let [value, unit] = this.preProcessInput(input); + + if (isNaN(value)) return [false, 0]; //If the value is not a number, return fail + if (unit.length == 0) return [true, value]; //No units means imply that we have the desired units + + let givenUnits: AngVelUnit; + + switch (unit) { + case 'rad/s': + case 'rps': + givenUnits = AngVelUnit.RPS; + break; + case 'rpm': + case 'rev/min': + givenUnits = AngVelUnit.RPM; + break; + case 'degree/second': + case 'degree/s': + case 'dps': + givenUnits = AngVelUnit.DPS; + break; + default: + return [false, value]; + } + if (givenUnits == desiredUnits) return [true, value]; + value = this.convertAngVel(value, givenUnits, desiredUnits); + return [true, value]; + } + public parseLengthString(input: string, desiredUnits: LengthUnit): [boolean, number] { let [value, unit] = this.preProcessInput(input); @@ -237,6 +267,43 @@ export class NumberUnitParserService { return value; } + private convertAngVel(value: number, givenUnits: AngVelUnit, desiredUnits: AngVelUnit) { + if (givenUnits == desiredUnits) return value; + switch (givenUnits) { + case AngVelUnit.DPS: + switch (desiredUnits) { + case AngVelUnit.RPM: + return (value / 360) * 60; + case AngVelUnit.RPS: + return value * (Math.PI / 180); + } + break; + case AngVelUnit.RPM: + switch (desiredUnits) { + case AngVelUnit.DPS: + return (value * 360) / 60; + case AngVelUnit.RPS: + return value * (2 * Math.PI) / 60; + } + break; + case AngVelUnit.RPS: + switch (desiredUnits) { + case AngVelUnit.RPM: + return value * (60 / ( 2 * Math.PI)); + case AngVelUnit.DPS: + return value * (180 / Math.PI); + } + break; + } + console.error( + 'Error in NumberUnitParserService.convertAngVel(): No valid conversion found between ' + + AngVelUnit[givenUnits] + + ' and ' + + AngVelUnit[desiredUnits] + ); + return value; + } + private convertForce(value: number, givenUnits: ForceUnit, desiredUnits: ForceUnit): number { if (givenUnits == desiredUnits) return value; switch (givenUnits) { diff --git a/src/app/services/settings.service.ts b/src/app/services/settings.service.ts index 6489c1e..ee9417f 100644 --- a/src/app/services/settings.service.ts +++ b/src/app/services/settings.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import { BehaviorSubject } from 'rxjs'; -import { LengthUnit, AngleUnit, GlobalUnit, ForceUnit, RotationUnit } from '../model/utils'; +import { LengthUnit, AngleUnit, GlobalUnit, ForceUnit, AngVelUnit } from '../model/utils'; @Injectable({ providedIn: 'root', @@ -9,7 +9,7 @@ export class SettingsService { lengthUnit = new BehaviorSubject(LengthUnit.CM); angleUnit = new BehaviorSubject(AngleUnit.DEGREE); forceUnit = new BehaviorSubject(ForceUnit.NEWTON); - rotationalUnit = new BehaviorSubject(RotationUnit.RPM); + angVelUnit = new BehaviorSubject(AngVelUnit.RPM); // inputTorque = new BehaviorSubject(TorqueUnit.CM_N); globalUnit = new BehaviorSubject(GlobalUnit.METRIC); isInputCW = new BehaviorSubject(true); From 7caca2205b07bbde23565a3755b84fc2079177c6 Mon Sep 17 00:00:00 2001 From: AlexG1031 Date: Wed, 21 Feb 2024 22:40:33 -0500 Subject: [PATCH 4/7] Believe textbox within settings works properly --- .../settings-panel.component.ts | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/app/component/settings-panel/settings-panel.component.ts b/src/app/component/settings-panel/settings-panel.component.ts index a5f1f7c..3b107d9 100644 --- a/src/app/component/settings-panel/settings-panel.component.ts +++ b/src/app/component/settings-panel/settings-panel.component.ts @@ -14,6 +14,8 @@ import { MatDialog } from '@angular/material/dialog'; import { EnableForcesComponent } from '../MODALS/enable-forces/enable-forces.component'; import { EnableWeldedComponent } from '../MODALS/enable-welded/enable-welded.component'; import { EnableEquationsComponent } from '../MODALS/enable-equations/enable-equations.component'; +import { getChartByID } from 'apexcharts'; +import { AnalysisGraphComponent } from '../analysis-graph/analysis-graph.component'; @Component({ selector: 'app-settings-panel', @@ -91,21 +93,25 @@ export class SettingsPanelComponent { this.mechanismSrv.updateMechanism(); }); this.settingsForm.controls['speed'].valueChanges.subscribe((val) => { - if (this.settingsForm.controls['speed'].invalid) { - const [success, value] = this.nup.parseAngVelString(val!, this.settingsService.angVelUnit.getValue()); - const str = this.nup.formatValueAndUnit(value, this.settingsService.angVelUnit.getValue()); - this.settingsForm.patchValue( - { speed: str}, - {emitEvent: false }); - this.settingsService.inputSpeed.next(value); - // this.settingsForm.patchValue({ speed: this.nup.formatValueAndUnit(value, this.settingsService.angVelUnit.getValue()) }); - } else { - this.currentSpeedSetting = Number(val); - this.settingsForm.patchValue({ speed:this.currentSpeedSetting.toString() }); - // this.settingsForm.patchValue({ speed: this.nup.formatValueAndUnit(this.currentSpeedSetting, this.settingsService.angVelUnit.getValue()) }); - this.settingsService.inputSpeed.next(this.currentSpeedSetting); - } + const [success, value] = this.nup.parseAngVelString( + val!, + this.settingsService.angVelUnit.getValue() + ); + if (!success) { + this.settingsForm.patchValue( + { speed: this.currentSpeedSetting.toString() }, + { emitEvent: false }, + ); + } else { + this.currentSpeedSetting = value; + this.settingsService.inputSpeed.next(value); + this.settingsForm.patchValue( + {speed: this.nup.formatValueAndUnit(value, this.settingsService.angVelUnit.getValue())}, + { emitEvent: false }, + ); + } this.mechanismSrv.updateMechanism(); + this.mechanismSrv.onMechUpdateState.next(2); }); this.settingsForm.controls['objectScale'].valueChanges.subscribe((val) => { if (this.settingsForm.controls['objectScale'].invalid) { @@ -120,6 +126,7 @@ export class SettingsPanelComponent { this.currentAngleUnit = ParseAngleUnit(String(val)); this.settingsService.angleUnit.next(this.currentAngleUnit); this.mechanismSrv.updateMechanism(); + // if (AnalysisGraphComponent.) }); this.settingsForm.controls['globalunit'].valueChanges.subscribe((val) => { this.currentGlobalUnit = ParseGlobalUnit(val); @@ -229,7 +236,7 @@ export class SettingsPanelComponent { numRegex = '^-?[0-9]+(.[0-9]{0,10})?$'; settingsForm = this.fb.group( { - speed: ['', [Validators.required, Validators.pattern(this.numRegex)]], + speed: ['', [Validators.required]], objectScale: ['', [Validators.required, Validators.pattern(this.numRegex)]], rotation: ['', { updateOn: 'change' }], lengthunit: ['', { updateOn: 'change' }], From 70aba92c47d3902a2d9c0dc130224e746cef7a28 Mon Sep 17 00:00:00 2001 From: AlexG1031 Date: Fri, 23 Feb 2024 09:08:15 -0500 Subject: [PATCH 5/7] Fixed the bug to showcase unit if the user does not insert a unit or types in a unit incorrectly --- src/app/component/settings-panel/settings-panel.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/component/settings-panel/settings-panel.component.ts b/src/app/component/settings-panel/settings-panel.component.ts index 3b107d9..88ff39b 100644 --- a/src/app/component/settings-panel/settings-panel.component.ts +++ b/src/app/component/settings-panel/settings-panel.component.ts @@ -99,7 +99,7 @@ export class SettingsPanelComponent { ); if (!success) { this.settingsForm.patchValue( - { speed: this.currentSpeedSetting.toString() }, + { speed: this.nup.formatValueAndUnit(this.currentSpeedSetting, this.settingsService.angVelUnit.getValue()) }, { emitEvent: false }, ); } else { From 3b2f79aed5feeecaa1e12dd3b3be04f76fd7d0df Mon Sep 17 00:00:00 2001 From: AlexG1031 Date: Fri, 23 Feb 2024 13:15:08 -0500 Subject: [PATCH 6/7] Showcase error message if user puts a negative sign in input speed textbox --- .../component/settings-panel/settings-panel.component.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/app/component/settings-panel/settings-panel.component.ts b/src/app/component/settings-panel/settings-panel.component.ts index 88ff39b..4c1a8fd 100644 --- a/src/app/component/settings-panel/settings-panel.component.ts +++ b/src/app/component/settings-panel/settings-panel.component.ts @@ -93,6 +93,9 @@ export class SettingsPanelComponent { this.mechanismSrv.updateMechanism(); }); this.settingsForm.controls['speed'].valueChanges.subscribe((val) => { + if (val?.includes('-')) { + this.sendNotification("Input Speed is a magnitude. Change cw or ccw from Input Direction"); + } const [success, value] = this.nup.parseAngVelString( val!, this.settingsService.angVelUnit.getValue() @@ -253,6 +256,10 @@ export class SettingsPanelComponent { NewGridComponent.sendNotification('This feature is coming soon!'); } + sendNotification(message: string): void { + NewGridComponent.sendNotification(message); + } + updateObjectScale() { this.svgGrid.updateObjectScale(); } From 53a7b2fca6b7f891502645deb120595e06682149 Mon Sep 17 00:00:00 2001 From: AlexG1031 Date: Mon, 26 Feb 2024 14:25:14 -0500 Subject: [PATCH 7/7] Units now update properly within analysis panel for ang, angVel and angAcc --- .../settings-panel.component.ts | 53 +++++++++++-------- src/app/model/utils.ts | 5 ++ src/app/services/mechanism.service.ts | 4 +- src/app/services/settings.service.ts | 3 +- 4 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/app/component/settings-panel/settings-panel.component.ts b/src/app/component/settings-panel/settings-panel.component.ts index 4c1a8fd..dae820a 100644 --- a/src/app/component/settings-panel/settings-panel.component.ts +++ b/src/app/component/settings-panel/settings-panel.component.ts @@ -1,21 +1,17 @@ import { Component } from '@angular/core'; import { SettingsService } from 'src/app/services/settings.service'; -import { LengthUnit, AngleUnit, ForceUnit, GlobalUnit, AngVelUnit } from 'src/app/model/utils'; +import { AngAccUnit, AngleUnit, AngVelUnit, ForceUnit, GlobalUnit, LengthUnit } from 'src/app/model/utils'; import { FormBuilder, Validators } from '@angular/forms'; import { NewGridComponent } from '../new-grid/new-grid.component'; import { MechanismService } from '../../services/mechanism.service'; import { Link, RealLink } from '../../model/link'; import { SvgGridService } from '../../services/svg-grid.service'; -import { AnimationBarComponent } from '../animation-bar/animation-bar.component'; -import { ToolbarComponent } from '../toolbar/toolbar.component'; import { NumberUnitParserService } from '../../services/number-unit-parser.service'; import { Coord } from '../../model/coord'; import { MatDialog } from '@angular/material/dialog'; import { EnableForcesComponent } from '../MODALS/enable-forces/enable-forces.component'; import { EnableWeldedComponent } from '../MODALS/enable-welded/enable-welded.component'; import { EnableEquationsComponent } from '../MODALS/enable-equations/enable-equations.component'; -import { getChartByID } from 'apexcharts'; -import { AnalysisGraphComponent } from '../analysis-graph/analysis-graph.component'; @Component({ selector: 'app-settings-panel', @@ -38,6 +34,7 @@ export class SettingsPanelComponent { // currentTorqueUnit!: TorqueUnit; currentGlobalUnit!: GlobalUnit; currentAngVelUnit!: AngVelUnit; + currentAngAccUnit!: AngAccUnit; rotateDirection!: boolean; currentSpeedSetting!: number; currentObjectScaleSetting!: number; @@ -47,6 +44,7 @@ export class SettingsPanelComponent { this.currentAngleUnit = this.settingsService.angleUnit.value; this.currentGlobalUnit = this.settingsService.globalUnit.value; this.currentAngVelUnit = this.settingsService.angVelUnit.value; + this.currentAngAccUnit = this.settingsService.angAccUnit.value; this.rotateDirection = this.settingsService.isInputCW.value; this.currentSpeedSetting = this.settingsService.inputSpeed.value; this.currentObjectScaleSetting = SettingsService.objectScale; @@ -86,6 +84,22 @@ export class SettingsPanelComponent { this.onChanges(); } + numRegex = '^-?[0-9]+(.[0-9]{0,10})?$'; + settingsForm = this.fb.group( + { + speed: ['', [Validators.required]], + objectScale: ['', [Validators.required, Validators.pattern(this.numRegex)]], + rotation: ['', { updateOn: 'change' }], + lengthunit: ['', { updateOn: 'change' }], + angleunit: ['', { updateOn: 'change' }], + torqueunit: ['', { updateOn: 'change' }], + globalunit: ['', { updateOn: 'change' }], + showMinorGrid: [true, { updateOn: 'change' }], + showMajorGrid: [true, { updateOn: 'change' }], + }, + { updateOn: 'blur' } + ); + onChanges(): void { this.settingsForm.controls['rotation'].valueChanges.subscribe((val) => { this.rotateDirection = String(val) === '0'; @@ -128,8 +142,19 @@ export class SettingsPanelComponent { this.settingsForm.controls['angleunit'].valueChanges.subscribe((val) => { this.currentAngleUnit = ParseAngleUnit(String(val)); this.settingsService.angleUnit.next(this.currentAngleUnit); + if (this.settingsService.angVelUnit.value === AngVelUnit.DPS) { + this.currentAngleUnit = AngleUnit.DEGREE; + this.currentAngVelUnit = AngVelUnit.DPS; + this.currentAngAccUnit = AngAccUnit.DPS_square; + } else { + this.currentAngleUnit = AngleUnit.RADIAN; + this.currentAngVelUnit = AngVelUnit.RPS; + this.currentAngAccUnit = AngAccUnit.RPS_square; + } + this.mechanismSrv.updateMechanism(); - // if (AnalysisGraphComponent.) + + this.mechanismSrv.onMechUpdateState.next(2); }); this.settingsForm.controls['globalunit'].valueChanges.subscribe((val) => { this.currentGlobalUnit = ParseGlobalUnit(val); @@ -236,22 +261,6 @@ export class SettingsPanelComponent { } } - numRegex = '^-?[0-9]+(.[0-9]{0,10})?$'; - settingsForm = this.fb.group( - { - speed: ['', [Validators.required]], - objectScale: ['', [Validators.required, Validators.pattern(this.numRegex)]], - rotation: ['', { updateOn: 'change' }], - lengthunit: ['', { updateOn: 'change' }], - angleunit: ['', { updateOn: 'change' }], - torqueunit: ['', { updateOn: 'change' }], - globalunit: ['', { updateOn: 'change' }], - showMinorGrid: [true, { updateOn: 'change' }], - showMajorGrid: [true, { updateOn: 'change' }], - }, - { updateOn: 'blur' } - ); - sendComingSoon(): void { NewGridComponent.sendNotification('This feature is coming soon!'); } diff --git a/src/app/model/utils.ts b/src/app/model/utils.ts index 1fb076c..1001cc3 100644 --- a/src/app/model/utils.ts +++ b/src/app/model/utils.ts @@ -27,6 +27,11 @@ export enum AngVelUnit { RPS = 17, // Radians per second } +export enum AngAccUnit { + RPS_square = 18, // rad per second square (rad/s^2) + DPS_square = 19, // degrees per second square (deg/s^2) +} + export enum ForceUnit { LBF = 20, NEWTON = 21, diff --git a/src/app/services/mechanism.service.ts b/src/app/services/mechanism.service.ts index 6ff0161..ea5cd4b 100644 --- a/src/app/services/mechanism.service.ts +++ b/src/app/services/mechanism.service.ts @@ -164,7 +164,7 @@ export class MechanismService { } updateLinkageUnits(fromUnits: LengthUnit, toUnits: LengthUnit) { - //Scale the linkage based on teh units + //Scale the linkage based on the units // For each joint, move the joint this.joints.forEach((joint) => { //If joint is of type Rev joint only, move the joint @@ -179,7 +179,7 @@ export class MechanismService { ); } }); - this.updateMechanism(); + // this.updateMechanism(); // this.settingsService.lengthUnit.subscribe((val) => { //For each jo // let unit = this.settingsService.lengthUnit.value; diff --git a/src/app/services/settings.service.ts b/src/app/services/settings.service.ts index ee9417f..bfdac6f 100644 --- a/src/app/services/settings.service.ts +++ b/src/app/services/settings.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import { BehaviorSubject } from 'rxjs'; -import { LengthUnit, AngleUnit, GlobalUnit, ForceUnit, AngVelUnit } from '../model/utils'; +import { LengthUnit, AngleUnit, GlobalUnit, ForceUnit, AngVelUnit, AngAccUnit } from '../model/utils'; @Injectable({ providedIn: 'root', @@ -10,6 +10,7 @@ export class SettingsService { angleUnit = new BehaviorSubject(AngleUnit.DEGREE); forceUnit = new BehaviorSubject(ForceUnit.NEWTON); angVelUnit = new BehaviorSubject(AngVelUnit.RPM); + angAccUnit = new BehaviorSubject(AngAccUnit.RPS_square); // inputTorque = new BehaviorSubject(TorqueUnit.CM_N); globalUnit = new BehaviorSubject(GlobalUnit.METRIC); isInputCW = new BehaviorSubject(true);