From 80744db9f98944b1237602ac0023498f9d62b381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1na=20Kohanov=C3=A1?= Date: Mon, 25 Jan 2021 13:01:06 +0100 Subject: [PATCH] #504 Restore NGL view settings --- js/components/preview/viewerControls/index.js | 20 +++++++- js/reducers/tracking/dispatchActions.js | 48 +++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/js/components/preview/viewerControls/index.js b/js/components/preview/viewerControls/index.js index 64200f48a..aa627c8ff 100644 --- a/js/components/preview/viewerControls/index.js +++ b/js/components/preview/viewerControls/index.js @@ -5,7 +5,7 @@ import React, { memo, useState, useContext, useEffect, useCallback } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { Button } from '../../common/Inputs/Button'; -import { Settings, Mouse, PersonalVideo, Undo, Redo } from '@material-ui/icons'; +import { Settings, Mouse, PersonalVideo, Undo, Redo, Restore } from '@material-ui/icons'; import { ButtonGroup, Grid, makeStyles, Tooltip } from '@material-ui/core'; import { SettingControls } from './settingsControls'; import DisplayControls from './displayControls/'; @@ -17,7 +17,8 @@ import { getCanRedo, getCanUndo, getUndoActionText, - getRedoActionText + getRedoActionText, + restoreNglViewSettings } from '../../../../js/reducers/tracking/dispatchActions'; import { NglContext } from '../../nglView/nglProvider'; @@ -32,6 +33,10 @@ const initDrawers = { [drawers.settings]: false, [drawers.display]: false, [draw const useStyles = makeStyles(theme => ({ button: { padding: theme.spacing(1) + }, + buttonMargin: { + padding: theme.spacing(1), + marginLeft: theme.spacing(8) } })); @@ -155,6 +160,17 @@ export const ViewerControls = memo(({}) => { + + + + diff --git a/js/reducers/tracking/dispatchActions.js b/js/reducers/tracking/dispatchActions.js index f0c784964..97ff46a7f 100644 --- a/js/reducers/tracking/dispatchActions.js +++ b/js/reducers/tracking/dispatchActions.js @@ -67,6 +67,7 @@ import { updateComponentRepresentationVisibilityAll, changeComponentRepresentation } from '../../../js/reducers/ngl/actions'; +import { NGL_PARAMS } from '../../components/nglView/constants'; import * as listType from '../../constants/listTypes'; import { assignRepresentationToComp } from '../../components/nglView/generatingObjects'; import { @@ -719,6 +720,53 @@ export const restoreAfterTargetActions = (stages, projectId) => async (dispatch, } }; +export const restoreNglViewSettings = stages => (dispatch, getState) => { + const state = getState(); + const majorView = stages.find(view => view.id === VIEWS.MAJOR_VIEW).stage; + const summaryView = stages.find(view => view.id === VIEWS.SUMMARY_VIEW).stage; + + const viewParams = state.nglReducers.viewParams; + + const currentActionList = state.trackingReducers.track_actions_list; + const orderedActionList = currentActionList.reverse((a, b) => a.timestamp - b.timestamp); + + let backgroundAction = orderedActionList.find(action => action.type === actionType.BACKGROUND_COLOR_CHANGED); + if (backgroundAction && backgroundAction.newSetting) { + let value = backgroundAction.newSetting; + dispatch(setNglBckGrndColor(value, majorView, summaryView)); + } + + let clipNearAction = orderedActionList.find(action => action.type === actionType.CLIP_NEAR); + if (clipNearAction && clipNearAction.newSetting) { + let value = clipNearAction.newSetting; + dispatch(setNglClipNear(value, viewParams[NGL_PARAMS.clipNear], majorView)); + } + + let clipFarAction = orderedActionList.find(action => action.type === actionType.CLIP_FAR); + if (clipFarAction && clipFarAction.newSetting) { + let value = clipFarAction.newSetting; + dispatch(setNglClipFar(value, viewParams[NGL_PARAMS.clipFar], majorView)); + } + + let clipDistAction = orderedActionList.find(action => action.type === actionType.CLIP_DIST); + if (clipDistAction && clipDistAction.newSetting) { + let value = clipDistAction.newSetting; + dispatch(setNglClipDist(value, viewParams[NGL_PARAMS.clipDist], majorView)); + } + + let fogNearAction = orderedActionList.find(action => action.type === actionType.FOG_NEAR); + if (fogNearAction && fogNearAction.newSetting) { + let value = fogNearAction.newSetting; + dispatch(setNglFogNear(value, viewParams[NGL_PARAMS.fogNear], majorView)); + } + + let fogFarAction = orderedActionList.find(action => action.type === actionType.FOG_FAR); + if (fogFarAction && fogFarAction.newSetting) { + let value = fogFarAction.newSetting; + dispatch(setNglFogFar(value, viewParams[NGL_PARAMS.fogFar], majorView)); + } +}; + const restoreNglStateAction = (orderedActionList, stages) => (dispatch, getState) => { let actions = orderedActionList.filter(action => action.type === actionType.NGL_STATE); let action = [...actions].pop();