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 { toast } from 'react-toastify'
import { createToastArguments } from '../../toasts/helpers/createToastArguments' import { createToastArguments } from '../../toasts/helpers/createToastArguments'
import { CurrentLanguage } from '../../internalisation/stores/currentLanguage' 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 * Compiles a simulation into a logicGate
* *
* @param simulaton The simulation to compile * @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') { if (mode === 'project') {
throw new SimulationError('Cannot compile project') throw new SimulationError('Cannot compile project')
} }
const translation = CurrentLanguage.getTranslation() 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> = { const result: DeepPartial<GateTemplate> = {
metadata: { metadata: {

View file

@ -13,6 +13,7 @@ import { Simulation, SimulationEnv } from './Simulation'
import { fromSimulationState } from '../../saving/helpers/fromState' import { fromSimulationState } from '../../saving/helpers/fromState'
import { saveStore } from '../../saving/stores/saveStore' import { saveStore } from '../../saving/stores/saveStore'
import { Wire } from './Wire' import { Wire } from './Wire'
import { cleanSimulation } from '../../simulation-actions/helpers/clean'
export interface GatePins { export interface GatePins {
inputs: Pin[] inputs: Pin[]
@ -116,6 +117,7 @@ export class Gate {
} }
this.ghostSimulation = fromSimulationState(state.simulation, 'gate') this.ghostSimulation = fromSimulationState(state.simulation, 'gate')
cleanSimulation(this.ghostSimulation)
const sortByPosition = (x: Gate, y: Gate) => const sortByPosition = (x: Gate, y: Gate) =>
x.transform.position[1] - y.transform.position[1] x.transform.position[1] - y.transform.position[1]
@ -136,13 +138,17 @@ export class Gate {
if (inputs.length !== this._pins.inputs.length) { if (inputs.length !== this._pins.inputs.length) {
throw new SimulationError( 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) { if (outputs.length !== this._pins.outputs.length) {
throw new SimulationError( 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) this.loadSave(save)
} catch (e) { } catch (e) {
throw new Error( throw new Error(
`An error occured while loading the save: ${ `An error occured while loading the save: ${e as Error}`
(e as Error).message
}`
) )
} }
} }