Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Shortcuts to Analog #1236

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
7004762
Adding Examples
AmolK987 Feb 10, 2023
7d5c4a6
Changed Examples
julianchen215 Feb 10, 2023
da564d6
Merge branch 'Updated_Analog' into Updated_Analog1
AmolK987 Feb 10, 2023
f9b294a
Created VoltageSourceHandler
AmolK987 Feb 17, 2023
f5282b2
Created ResistorHandler.ts
julianchen215 Feb 17, 2023
aff01e3
Merge branch 'Updated_Analog1' of https://github.com/OpenCircuits/Ope…
julianchen215 Feb 17, 2023
23072db
Changed keyboard shortcut implementation
AmolK987 Feb 24, 2023
eb234c2
Added Comments to ItemNav
AmolK987 Feb 24, 2023
f65b28b
Keyboard Popup and Keyboard Shortcut Prohress
julianchen215 Feb 24, 2023
f32d841
Merge branch 'Updated_Analog1' of https://github.com/OpenCircuits/Ope…
julianchen215 Feb 24, 2023
ac829df
Bring up icons for shortcuts
AmolK987 Feb 28, 2023
e92c6b4
SHortcut
julianchen215 Feb 28, 2023
26ed986
Merge branch 'Updated_Analog1' of https://github.com/OpenCircuits/Ope…
julianchen215 Feb 28, 2023
7e47c19
Create Documentation on Future Quality of Life Improvements
AmolK987 Mar 3, 2023
d4e3bfb
Created DC Analysis Documentation
AmolK987 Mar 3, 2023
ea3bc05
Added another future functionality
AmolK987 Mar 3, 2023
1d0063c
Reformatted DC_Analysis as Markdown
AmolK987 Mar 3, 2023
f6723fd
Updated DC_Analysis
AmolK987 Mar 3, 2023
fee73d8
Update QualityOfLife.md
julianchen215 Mar 3, 2023
f7f9260
Update QualityOfLife.md
julianchen215 Mar 3, 2023
c9ef735
Shortcut for placing on item
AmolK987 Mar 17, 2023
c935eee
Added short_cut flag
julianchen215 Mar 17, 2023
fc748c9
Implemented Multiple Placements
AmolK987 Mar 17, 2023
d9917bf
Merge branch 'Updated_Analog1' of https://github.com/OpenCircuits/Ope…
AmolK987 Mar 17, 2023
baede46
Removed Debug Prints
AmolK987 Mar 17, 2023
306a2a2
Minor changes
AmolK987 Mar 19, 2023
356eaef
Fixed Shorcuts messing up Digital
julianchen215 Mar 21, 2023
2e2f64b
Testing pull origin
AmolK987 Mar 21, 2023
f0e7fea
Another test for pulling from origin
AmolK987 Mar 21, 2023
edbb90b
test
julianchen215 Mar 21, 2023
07129e3
Merge branch 'Updated_Analog1' of https://github.com/OpenCircuits/Ope…
julianchen215 Mar 21, 2023
5366f66
Added Shortcut Parameter to Digital
julianchen215 Mar 21, 2023
16ade67
Updated Shortcuts pop up for Analog
julianchen215 Mar 21, 2023
f7676e0
Update src/site/shared/containers/ItemNav/index.tsx
julianchen215 Mar 24, 2023
dc58924
Implemented Some Requested Changes
julianchen215 Mar 24, 2023
9363902
Fixed "No item" bug
AmolK987 Mar 31, 2023
a946c42
Debugging useState
julianchen215 Apr 1, 2023
378fa44
Fixed all Bugs with Shortcuts
AmolK987 Apr 4, 2023
7ffdb05
Fixed Lint Errors
julianchen215 Apr 4, 2023
80a69c9
Merge branch 'Updated_Analog1' of https://github.com/OpenCircuits/Ope…
julianchen215 Apr 4, 2023
61c11d9
Added another exit option
AmolK987 Apr 7, 2023
c324979
Updated shortcut behavior
AmolK987 Apr 7, 2023
3261af5
Update index.tsx
julianchen215 Apr 7, 2023
d5ab908
Fixed More Linting Errors
julianchen215 Apr 7, 2023
bcfab3c
Update index.tsx
julianchen215 Apr 7, 2023
7ac5c3a
Lint
julianchen215 Apr 7, 2023
0216058
Update index.tsx
julianchen215 Apr 7, 2023
f1decfd
Adding explanations for implementation
AmolK987 Apr 7, 2023
463c21e
Added explanation for placement check logic
AmolK987 Apr 7, 2023
c8d4807
Edit to clarify "Esc" key function
AmolK987 Apr 7, 2023
babad5c
Fixed minor bug with ItemNav Panel behavior
AmolK987 Apr 7, 2023
065af2d
Fixing Documentation Error
AmolK987 Apr 18, 2023
c97919f
Trying to fix Expected corresponding JSX closing tag for <img>. (58:0)
julianchen215 Apr 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/Other/AnalogAdditions/DC_Analysis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# DC Analysis
1. Performing Analysis when DC Sources are Used
* DC sources mean all sources should be applying a constant current/voltage.
* This Analysis would be similar to running with "DC Operating Point" in LTSpice
2. This Analysis Can Not be Validly Performed with Time-Varying Signals
* Output results should be invalid as it makes no sense to have time-varying signals in a DC Analysis.
3. Linear (IV-curve) Components Have their Properties Determined According to Simple Linear Equations
* These include Resistors whose properties are dictated by Ohm's Law (V = I*R).
4. Nonlinear Components Could have their DC Steady State Values Reported
* These components include Inductors and Capacitors whose voltages/currents will change with time even as a DC signal is applied to them
* A DC Analysis essentially take the limit as time goes to infinity in these instances, resulting in reporting the "DC Steady States" of these components. These will be DC values that reflect the values which properties of these components wil always be moving closer towards.
5. DC Analysis Results can Simply be Output in a new Window or Text Box
* Using an Oscilloscope to plot DC values would only result in a bunch of straight lines. Instead of this the output can simply be the calulated values themselves (rounded to a reasonable number of significant digits) with there associated component or node.
* The voltages for each node can be reported along with the currents through each component.
* If the node was labeled by the user, then this label should show up in in the report as well. This should only be applied to labeled nodes as it allows the user to isolate certain nodes for their analysis.
34 changes: 34 additions & 0 deletions docs/Other/AnalogAdditions/QualityOfLife.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Future Quality of Life Improvements
1. Example Circuits
* Updated Example Analog Circuits would help get new users started
* These circuits could be loaded in for users to be able to mess around with running the simulation
* We included samples of Voltage Divider, Series RC (Resistor-Capacitor), Series RL (Resistor-Inductor), and Series RLC (Resistor-Capacitor-Inductor) circuits.

Circuit 1: Voltage Divider/ Nodal Analysis Example:

<img width="214" alt="image" src="https://user-images.githubusercontent.com/62410569/221334248-90228e65-eeb7-4834-9a55-b96002d1caaf.png">
Circuit 2: RC(Resistor-Capacitor) Example Circuit (Series)

<img width="217" alt="image" src="https://user-images.githubusercontent.com/62410569/221334297-ad60b34e-ce39-4fb9-86dd-90a81ecd22a0.png">
Circuit 3: RL(Resistor-Inductor) Example Circuit (Series)

<img width="218" alt="image" src="https://user-images.githubusercontent.com/62410569/221334315-f2560146-a974-47a8-bff1-359fd890e0a8.png">
Circuit 4: RLC(Resistor-Inductor-Capacitor) Example Circuit (Series)

<img width="219" alt="image" src="https://user-images.githubusercontent.com/62410569/221334332-ac3f7c30-49a7-4453-bd17-b4a8e5588695.png">

2. Implementing Keyboard Shortcuts
* Users would be able to quickly and easily bring up commonly used components using keyboard shortcuts
* These shortcuts should correspond with their associated components (i.e. "v" for Voltage Source)
3. Display Component Values Next to Their Models
* Resistances, capacitance values, inductance values, and all values for sources should be shown next to or near the associatedd components
4. Wires and Components Should Automatically Snap into Positions
* Wires should naturally snap to 90 degree angles so wirings for more complicated circuits can be less confusing
5. Deleting the Oscilloscope
* Currently, removing the Oscilloscope also deletes all attached wires which should not be the case.
6. Uploading Your Own Components/Models
* Expand functionalities and component libraries by allowing users to uploaded pre-formatted circuit component files that can be parsed into actual usable models.
* This can include modeling specific real-world components if the data reflects that components (expected) behaviors.
7. Component Information Does Not Work
* Currently, clicking on the "learn about this component" button does nothing for all of the components. Can fix this by linking a wikipedia page to the button.
<!-- <img width="149" alt="image" src="https://user-images.githubusercontent.com/62410569/222838727-b0379451-c131-4c4e-ba7e-cc0a6652cf8e.png"> -->
1 change: 1 addition & 0 deletions src/site/pages/analog/public/examples/Example_RC.circuit

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/site/pages/analog/public/examples/Example_RLC.circuit

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/site/pages/analog/public/examples/example1new.circuit

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/site/pages/analog/public/examples/example3new.circuit

Large diffs are not rendered by default.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion src/site/pages/analog/src/containers/AnalogItemNav/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export const AnalogItemNav = ({ info }: Props) => {
<ItemNav
info={info}
config={itemNavConfig}
getImgSrc={getImgSrc} />
getImgSrc={getImgSrc}
shortcuts={[["r", "Resistor"],
["c", "Capacitor"],
["g", "Ground"],
["l", "Inductor"],
["v", "VoltageSource"],
["i", "CurrentSource"]]} />
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const KeyboardShortcutsPopup = () => {
</thead>
<tbody>
<Shortcut os={os} label="Undo" keys={["Z"]} mod />
<Shortcut os={os} label="Redo" keys={["Shift", "Z"]} mod />
<Shortcut os={os} label="Redo" keys={["Y"]} mod />
<Shortcut os={os} label="Cut" keys={["X"]} mod />
<Shortcut os={os} label="Copy" keys={["C"]} mod />
<Shortcut os={os} label="Paste" keys={["V"]} mod />
Expand All @@ -76,6 +76,12 @@ export const KeyboardShortcutsPopup = () => {
<Shortcut os={os} label="Snapping" keys={["Shift"]} pre="Hold " />
<Shortcut os={os} label="Duplicate" keys={["D"]} mod />
<Shortcut os={os} label="Fit to Screen" keys={["F"]} />
<Shortcut os={os} label="Voltage Source" keys={["V"]} />
<Shortcut os={os} label="Current Source" keys={["I"]} />
<Shortcut os={os} label="Resistor" keys={["R"]} />
<Shortcut os={os} label="Capacitor" keys={["C"]} />
<Shortcut os={os} label="Inductor" keys={["L"]} />
<Shortcut os={os} label="Ground" keys={["G"]} />
</tbody>
</table>
</Popup>
Expand Down
26 changes: 17 additions & 9 deletions src/site/pages/analog/src/data/examples.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,29 @@
"examples": [
{
"id": "0",
"name": "Basic AND Gate Setup",
"file": "example1.circuit",
"thumbnail": "img/thumbnails/example1.png"
"name": "Voltage Divider/ Nodal Analysis Circuit Example",
"file": "example1new.circuit",
"thumbnail": "img/thumbnails/example1new.png"
},
{
"id": "1",
"name": "SR-Latch Gate Implementation",
"file": "example2.circuit",
"thumbnail": "img/thumbnails/example2.png"
"name": "Series RC Cicuit",
"file": "Example_RC.circuit",
"thumbnail": "img/thumbnails/RC.png"
},
{
"id": "2",
"name": "Full Adder Circuit",
"file": "example3.circuit",
"thumbnail": "img/thumbnails/example3.png"
"name": "RL(Resistor-Inductor) Example Circuit (Series)",
"file": "example3new.circuit",
"thumbnail": "img/thumbnails/example3new.png"

},
{
"id": "3",
"name": "Series RLC Circuit",
"file": "Example_RLC.circuit",
"thumbnail": "img/thumbnails/RLC.png"

}
]
}
14 changes: 14 additions & 0 deletions src/site/pages/digital/src/containers/DigitalItemNav/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,20 @@ export const DigitalItemNav = ({ info }: Props) => {
additionalData={smartPlace}
additionalPreview={additionalPreview}
getImgSrc={getImgSrc}
shortcuts={[["b", "Button"],
["s", "Switch"],
["l", "ConstantLow"],
["h", "ConstantHigh"],
["n", "ConstantNumber"],
["c", "Clock"],
["1", "BUFGate"],
["2", "NOTGate"],
["3", "ANDGate"],
["4", "NANDGate"],
["5", "ORGate"],
["6", "NORGate"],
["7", "XORGate"],
["8", "XNORGate"]]}
onStart={onSmartPlaceOff}
onFinish={onSmartPlaceOff}
onDelete={onDelete} />
Expand Down
60 changes: 55 additions & 5 deletions src/site/shared/containers/ItemNav/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ type Props<D> = {
info: CircuitInfo;
config: ItemNavConfig;
additionalData?: D;
shortcuts: string[][];
getImgSrc: (c: Component) => string;
onStart?: () => void;
onFinish?: (cancelled: boolean) => void;
onDelete?: (section: ItemNavSection, item: ItemNavItem) => boolean;
additionalPreview?: (data: D, curItemID: string) => React.ReactNode;
}
export const ItemNav = <D,>({ info, config, additionalData, getImgSrc, onDelete,
// let shortcut_flag:boolean = false

export const ItemNav = <D,>({ info, config, additionalData, getImgSrc, shortcuts, onDelete,
onStart, onFinish, additionalPreview }: Props<D>) => {
const { isOpen, isEnabled, isHistoryBoxOpen, curItemID } = useSharedSelector(
(state) => ({ ...state.itemNav })
Expand All @@ -86,6 +89,10 @@ export const ItemNav = <D,>({ info, config, additionalData, getImgSrc, onDelete,
// State to keep track of drag'n'drop preview current image
const [curItemImg, setCurItemImg] = useState("");

const [shortcutFlag, setShortcutFlag] = useState(false);

const [shortItem, setShortItem] = useState("");

// Keep track of a separate 'currentlyPressedObj' in tandem with `info.currentlyPressedObj` so that
// we can use it to potentially delete the object if its dragged over to the ItemNav (issue #478)
const [currentlyPressedObj, setCurPressedObj] = useState(undefined as (Selectable | undefined));
Expand All @@ -94,6 +101,30 @@ export const ItemNav = <D,>({ info, config, additionalData, getImgSrc, onDelete,
if (info.currentlyPressedObject)
setCurPressedObj(info.currentlyPressedObject);
});
// Loops through the shorcuts 2d array in AnalogItemNav to see if any shortcuts
useDocEvent("keydown", (ev) => {
// Loop through each of the input shortcuts
for (const short of shortcuts) {
if (ev.key === short[0]) {
// Detect second keypress to exit shortcut
if (curItemID === short[1] && shortcutFlag) {
reset(true);
setShortcutFlag(false);
break;
}
const id = short[1];
const section = config.sections.find((s) => (s.items.find((i) => i.id === id)));
dispatch(SetCurItem(id));
setNumClicks(id.toLowerCase() === curItemID ? numClicks+1 : 1);
setCurItemImg(`/${config.imgRoot}/${section?.id}/${[...id.toLowerCase(),...".svg"].join("")}`)
onStart && onStart();
ev.stopPropagation();
// Update shortcut paramters to verify later
setShortcutFlag(true);
setShortItem(id);
}
}
}, [shortcutFlag, shortItem, curItemID]);
useDocEvent("mouseup", () => setCurPressedObj(undefined));
useDocEvent("mouseleave", () => setCurPressedObj(undefined));
function handleItemNavDrag() { // Issue #478
Expand All @@ -108,7 +139,7 @@ export const ItemNav = <D,>({ info, config, additionalData, getImgSrc, onDelete,
info.history.add(DeleteGroup(info.designer, [currentlyPressedObj]));
}

// Resets the curItemID and numClicks
// Resets the curItemID, numClicks, and shortcutFlag
const reset = useCallback((cancelled = false) => {
dispatch(SetCurItem(""));
setNumClicks(1);
Expand All @@ -118,6 +149,18 @@ export const ItemNav = <D,>({ info, config, additionalData, getImgSrc, onDelete,

// Drop the current item on click (or on touch end)
useDocEvent("click", (ev) => {
// If keyboard shortcut used to bring up component then allow to drop until "Esc" pressed
// Check to make sure shortcut is valid by checking flag and item ID
if (shortcutFlag && curItemID === shortItem){
DragDropHandlers.drop(V(ev.x, ev.y), curItemID, 1, additionalData);
const section = config.sections.find((s) => (s.items.find((i) => i.id === curItemID)));
dispatch(SetCurItem(curItemID));
setNumClicks(1);
setCurItemImg(`/${config.imgRoot}/${section?.id}/${[...curItemID.toLowerCase(),...".svg"].join("")}`)
onStart && onStart();
return;
}

// If holding shift then drop only a single item (issue #1043)
if (isShiftDown && numClicks > 1) {
DragDropHandlers.drop(V(ev.x, ev.y), curItemID, 1, additionalData);
Expand All @@ -127,7 +170,7 @@ export const ItemNav = <D,>({ info, config, additionalData, getImgSrc, onDelete,
// Otherwise drop all and reset
DragDropHandlers.drop(V(ev.x, ev.y), curItemID, numClicks, additionalData);
reset();
}, [curItemID, numClicks, isShiftDown, additionalData, setNumClicks, reset]);
}, [curItemID, numClicks, isShiftDown, additionalData, setNumClicks, reset, shortcutFlag, shortItem]);
useDocEvent("touchend", (ev) => {
const touch = ev.changedTouches.item(0);
if (!touch)
Expand Down Expand Up @@ -160,9 +203,10 @@ export const ItemNav = <D,>({ info, config, additionalData, getImgSrc, onDelete,
);
}, [info.camera, isOpen, side]);

// Cancel placing when pressing escape
// Cancel placing when pressing escape and reset shortcut state flag
useWindowKeyDownEvent("Escape", () => {
reset(true);
setShortcutFlag(false);
});

// Also cancel on Right Click
Expand Down Expand Up @@ -328,7 +372,13 @@ export const ItemNav = <D,>({ info, config, additionalData, getImgSrc, onDelete,
data={[item.id, Math.max(numClicks,1), additionalData]}
onClick={(ev) => {
dispatch(SetCurItem(item.id));
setNumClicks(item.id === curItemID ? numClicks+1 : 1);
// Force exit shotcut state when using ItemNav panel
if (shortcutFlag) {
setNumClicks(1);
} else {
setNumClicks(item.id === curItemID ? numClicks+1 : 1);
}
setShortcutFlag(false);
setCurItemImg(`/${config.imgRoot}/${section.id}/${item.icon}`);
onStart && onStart();

Expand Down