Skip to content

Commit

Permalink
merge edge into this PR
Browse files Browse the repository at this point in the history
  • Loading branch information
koji committed Nov 14, 2023
1 parent eae9421 commit 8022d16
Showing 1 changed file with 122 additions and 96 deletions.
218 changes: 122 additions & 96 deletions components/src/hardware-sim/BaseDeck/BaseDeck.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import * as React from 'react'

import {
RobotType,
getDeckDefFromRobotType,
ModuleModel,
ModuleLocation,
getModuleDef2,
LabwareDefinition2,
getPositionFromSlotId,
inferModuleOrientationFromXCoordinate,
LabwareLocation,
OT2_ROBOT_TYPE,
STAGING_AREA_LOAD_NAME,
STANDARD_SLOT_LOAD_NAME,
TRASH_BIN_LOAD_NAME,
WASTE_CHUTE_LOAD_NAME,
SINGLE_SLOT_FIXTURES,
STAGING_AREA_RIGHT_SLOT_FIXTURE,
TRASH_BIN_ADAPTER_FIXTURE,
WASTE_CHUTE_CUTOUT,
WASTE_CHUTE_FIXTURES,
} from '@opentrons/shared-data'

import { RobotCoordinateSpace } from '../RobotCoordinateSpace'
import { Module } from '../Module'
import { LabwareRender } from '../Labware'
import { FlexTrash } from '../Deck/FlexTrash'
import { DeckFromData } from '../Deck/DeckFromData'
import { DeckFromLayers } from '../Deck/DeckFromLayers'
import { SlotLabels } from '../Deck'
import { COLORS } from '../../ui-style-constants'

Expand All @@ -32,10 +30,18 @@ import { StagingAreaFixture } from './StagingAreaFixture'
import { WasteChuteFixture } from './WasteChuteFixture'
// import { WasteChuteStagingAreaFixture } from './WasteChuteStagingAreaFixture'

import type { DeckConfiguration } from '@opentrons/shared-data'
import type {
DeckConfiguration,
LabwareDefinition2,
LabwareLocation,
ModuleLocation,
ModuleModel,
RobotType,
SingleSlotCutoutFixtureId,
WasteChuteCutoutFixtureId,
} from '@opentrons/shared-data'
import type { TrashLocation } from '../Deck/FlexTrash'
import type { StagingAreaLocation } from './StagingAreaFixture'
import type { WasteChuteLocation } from './WasteChuteFixture'
import type { WellFill } from '../Labware'

interface BaseDeckProps {
Expand Down Expand Up @@ -64,7 +70,8 @@ interface BaseDeckProps {
lightFill?: string
darkFill?: string
children?: React.ReactNode
isOnDevice?: boolean
showSlotLabels?: boolean
isOnDevice? boolean
}

export function BaseDeck(props: BaseDeckProps): JSX.Element {
Expand All @@ -80,35 +87,44 @@ export function BaseDeck(props: BaseDeckProps): JSX.Element {
deckConfig = STANDARD_SLOT_DECK_CONFIG_FIXTURE,
showExpansion = true,
children,
isOnDevice,
showSlotLabels = true,
isOnDevice = false,
} = props
const deckDef = getDeckDefFromRobotType(robotType)

const singleSlotFixtures = deckConfig.filter(
fixture => fixture.loadName === STANDARD_SLOT_LOAD_NAME
const singleSlotFixtures = deckConfig.filter(fixture =>
SINGLE_SLOT_FIXTURES.includes(
fixture.fixtureId as SingleSlotCutoutFixtureId
)
)
const stagingAreaFixtures = deckConfig.filter(
fixture => fixture.loadName === STAGING_AREA_LOAD_NAME
fixture => fixture.fixtureId === STAGING_AREA_RIGHT_SLOT_FIXTURE
)
const trashBinFixtures = deckConfig.filter(
fixture => fixture.loadName === TRASH_BIN_LOAD_NAME
fixture => fixture.fixtureId === TRASH_BIN_ADAPTER_FIXTURE
)
const wasteChuteFixtures = deckConfig.filter(
fixture => fixture.loadName === WASTE_CHUTE_LOAD_NAME
fixture =>
WASTE_CHUTE_FIXTURES.includes(
fixture.fixtureId as WasteChuteCutoutFixtureId
) && fixture.fixtureLocation === WASTE_CHUTE_CUTOUT
)

return (
<RobotCoordinateSpace
viewBox={`${deckDef.cornerOffsetFromOrigin[0]} ${deckDef.cornerOffsetFromOrigin[1]} ${deckDef.dimensions[0]} ${deckDef.dimensions[1]}`}
>
{robotType === OT2_ROBOT_TYPE ? (
<DeckFromData def={deckDef} layerBlocklist={deckLayerBlocklist} />
<DeckFromLayers
robotType={robotType}
layerBlocklist={deckLayerBlocklist}
/>
) : (
<>
{singleSlotFixtures.map(fixture => (
<SingleSlotFixture
key={fixture.fixtureId}
cutoutLocation={fixture.fixtureLocation}
key={fixture.fixtureLocation}
cutoutId={fixture.fixtureLocation}
deckDefinition={deckDef}
slotClipColor={darkFill}
fixtureBaseColor={lightFill}
Expand All @@ -117,18 +133,18 @@ export function BaseDeck(props: BaseDeckProps): JSX.Element {
))}
{stagingAreaFixtures.map(fixture => (
<StagingAreaFixture
key={fixture.fixtureId}
key={fixture.fixtureLocation}
// TODO(bh, 2023-10-09): typeguard fixture location
cutoutLocation={fixture.fixtureLocation as StagingAreaLocation}
cutoutId={fixture.fixtureLocation as StagingAreaLocation}
deckDefinition={deckDef}
slotClipColor={darkFill}
fixtureBaseColor={lightFill}
/>
))}
{trashBinFixtures.map(fixture => (
<React.Fragment key={fixture.fixtureId}>
<React.Fragment key={fixture.fixtureLocation}>
<SingleSlotFixture
cutoutLocation={fixture.fixtureLocation}
cutoutId={fixture.fixtureLocation}
deckDefinition={deckDef}
slotClipColor={COLORS.transparent}
fixtureBaseColor={lightFill}
Expand All @@ -144,88 +160,98 @@ export function BaseDeck(props: BaseDeckProps): JSX.Element {
))}
{wasteChuteFixtures.map(fixture => (
<WasteChuteFixture
key={fixture.fixtureId}
key={fixture.fixtureLocation}
// TODO(bh, 2023-10-09): typeguard fixture location
cutoutLocation={fixture.fixtureLocation as WasteChuteLocation}
cutoutId={fixture.fixtureLocation as typeof WASTE_CHUTE_CUTOUT}
deckDefinition={deckDef}
slotClipColor={darkFill}
fixtureBaseColor={lightFill}
/>
))}
</>
)}
{moduleLocations.map(
({
moduleModel,
moduleLocation,
nestedLabwareDef,
nestedLabwareWellFill,
innerProps,
moduleChildren,
onLabwareClick,
}) => {
const slotDef = deckDef.locations.orderedSlots.find(
s => s.id === moduleLocation.slotName
)
const moduleDef = getModuleDef2(moduleModel)
return slotDef != null ? (
<Module
key={`${moduleModel} ${slotDef.id}`}
def={moduleDef}
x={slotDef.position[0]}
y={slotDef.position[1]}
orientation={inferModuleOrientationFromXCoordinate(
slotDef.position[0]
)}
innerProps={innerProps}
>
{nestedLabwareDef != null ? (
<>
{moduleLocations.map(
({
moduleModel,
moduleLocation,
nestedLabwareDef,
nestedLabwareWellFill,
innerProps,
moduleChildren,
onLabwareClick,
}) => {
const slotPosition = getPositionFromSlotId(
moduleLocation.slotName,
deckDef
)

const moduleDef = getModuleDef2(moduleModel)
return slotPosition != null ? (
<Module
key={`${moduleModel} ${moduleLocation.slotName}`}
def={moduleDef}
x={slotPosition[0]}
y={slotPosition[1]}
orientation={inferModuleOrientationFromXCoordinate(
slotPosition[0]
)}
innerProps={innerProps}
>
{nestedLabwareDef != null ? (
<LabwareRender
definition={nestedLabwareDef}
onLabwareClick={onLabwareClick}
wellFill={nestedLabwareWellFill}
isOnDevice={isOnDevice}
/>
) : null}
{moduleChildren}
</Module>
) : null
}
)}
{labwareLocations.map(
({
labwareLocation,
definition,
labwareChildren,
wellFill,
onLabwareClick,
}) => {
if (
labwareLocation === 'offDeck' ||
!('slotName' in labwareLocation)
) {
return null
}

const slotPosition = getPositionFromSlotId(
labwareLocation.slotName,
deckDef
)

return slotPosition != null ? (
<g
key={labwareLocation.slotName}
transform={`translate(${slotPosition[0].toString()},${slotPosition[1].toString()})`}
cursor={onLabwareClick != null ? 'pointer' : ''}
>
<LabwareRender
definition={nestedLabwareDef}
definition={definition}
onLabwareClick={onLabwareClick}
wellFill={nestedLabwareWellFill}
wellFill={wellFill ?? undefined}
isOnDevice={isOnDevice}
/>
) : null}
{moduleChildren}
</Module>
) : null
}
)}
{labwareLocations.map(
({
labwareLocation,
definition,
labwareChildren,
wellFill,
onLabwareClick,
}) => {
const slotDef = deckDef.locations.orderedSlots.find(
s =>
labwareLocation !== 'offDeck' &&
'slotName' in labwareLocation &&
s.id === labwareLocation.slotName
)
return slotDef != null ? (
<g
key={slotDef.id}
transform={`translate(${slotDef.position[0]},${slotDef.position[1]})`}
cursor={onLabwareClick != null ? 'pointer' : ''}
>
<LabwareRender
definition={definition}
onLabwareClick={onLabwareClick}
wellFill={wellFill ?? undefined}
isOnDevice={isOnDevice}
/>
{labwareChildren}
</g>
) : null
}
)}
{isOnDevice ? (
<SlotLabels robotType={robotType} color={darkFill} />
) : null}
{labwareChildren}
</g>
) : null
}
)}
{showSlotLabels ? (
<SlotLabels robotType={robotType} color={darkFill} />
) : null}
</>
{children}
</RobotCoordinateSpace>
)
Expand Down

0 comments on commit 8022d16

Please sign in to comment.