automatic cleaning of integrated circuits

This commit is contained in:
Matei Adriel 2019-07-25 15:14:54 +03:00
parent 266aa4db49
commit cddb050dfe
3 changed files with 22 additions and 8 deletions

View file

@ -9,20 +9,30 @@ import { templateStore } from '../../saving/stores/templateStore'
import { toast } from 'react-toastify'
import { createToastArguments } from '../../toasts/helpers/createToastArguments'
import { CurrentLanguage } from '../../internalisation/stores/currentLanguage'
import { fromSimulationState } from '../../saving/helpers/fromState'
import { cleanSimulation } from '../../simulation-actions/helpers/clean'
import { getSimulationState } from '../../saving/helpers/getState'
/**
* Compiles a simulation into a logicGate
*
* @param simulaton The simulation to compile
*/
export const compileIc = ({ mode, name, gates }: SimulationState) => {
export const compileIc = (state: SimulationState) => {
const { mode, name, gates } = state
if (mode === 'project') {
throw new SimulationError('Cannot compile project')
}
const translation = CurrentLanguage.getTranslation()
const inputCount = simulationInputCount(gates)
const outputCount = simulationOutputCount(gates)
const simulation = fromSimulationState(state)
cleanSimulation(simulation)
const cleanState = getSimulationState(simulation)
const inputCount = simulationInputCount(cleanState.gates)
const outputCount = simulationOutputCount(cleanState.gates)
const result: DeepPartial<GateTemplate> = {
metadata: {

View file

@ -13,6 +13,7 @@ import { Simulation, SimulationEnv } from './Simulation'
import { fromSimulationState } from '../../saving/helpers/fromState'
import { saveStore } from '../../saving/stores/saveStore'
import { Wire } from './Wire'
import { cleanSimulation } from '../../simulation-actions/helpers/clean'
export interface GatePins {
inputs: Pin[]
@ -116,6 +117,7 @@ export class Gate {
}
this.ghostSimulation = fromSimulationState(state.simulation, 'gate')
cleanSimulation(this.ghostSimulation)
const sortByPosition = (x: Gate, y: Gate) =>
x.transform.position[1] - y.transform.position[1]
@ -136,13 +138,17 @@ export class Gate {
if (inputs.length !== this._pins.inputs.length) {
throw new SimulationError(
`Input count needs to match with the container gate`
`Input count needs to match with the container gate: ${
inputs.length
} !== ${this._pins.inputs.length}`
)
}
if (outputs.length !== this._pins.outputs.length) {
throw new SimulationError(
`Output count needs to match with the container gate`
`Output count needs to match with the container gate: ${
outputs.length
} !== ${this._pins.outputs.length}`
)
}

View file

@ -318,9 +318,7 @@ export class SimulationRenderer {
this.loadSave(save)
} catch (e) {
throw new Error(
`An error occured while loading the save: ${
(e as Error).message
}`
`An error occured while loading the save: ${e as Error}`
)
}
}