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

ISSUE #4721 - Change sequences to use viewpoints #5014

Merged
merged 22 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
237c97f
ISSUE #4926 - fetch frames doesn't skip or duplicate frames being fet…
The-Daniel Jun 11, 2024
89c5bf1
ISSUE #4926 - color converter functions work for non integer rgba values
The-Daniel Jun 11, 2024
003628c
ISSUE #4926 - fix incorrect color/transform types
The-Daniel Jun 11, 2024
1307ae4
ISSUE #4926 - sequences use viewpoints to manage state
The-Daniel Jun 12, 2024
0adee54
ISSUE #4926 - fix frame is loading state
The-Daniel Jun 14, 2024
201628c
ISSUE #4926 - tidy up stateDefViewpoint converter
The-Daniel Jun 14, 2024
dd66dff
ISSUE #4926 - fix console error saying object was undefined
The-Daniel Jun 14, 2024
eb11c08
ISSUE #4926 - remove redundant code
The-Daniel Jun 14, 2024
c8bcb9d
Merge branch 'staging' into ISSUE_4721
The-Daniel Jun 17, 2024
949906b
ISSUE #4721 - fix broken colour converter helper
The-Daniel Jun 19, 2024
64733dd
ISSUE #4721 - remove unnecessary Partial
The-Daniel Jun 19, 2024
9ce94b4
ISSUE #4721 - use put instead of dispatch
The-Daniel Jun 19, 2024
84995ba
ISSUE #4721 - use existing colour converter function
The-Daniel Jun 20, 2024
080c5d5
ISSUE #4721 - delete more unused sagas/actions
The-Daniel Jun 21, 2024
2407f2b
ISSUE #4721 - use takeEvery instead of takeLatest with weird promise …
The-Daniel Jun 24, 2024
60fe5d4
ISSUE #4721 - add viewpoints to selectorsHooks and actionsDispatchers
The-Daniel Jun 24, 2024
ec13aa4
ISSUE #4721 - simplify override group logic in state to viewpoint con…
The-Daniel Jun 24, 2024
eaea79e
ISSUE #4721 - revert unnecessary ternary operator
The-Daniel Jun 24, 2024
c05aad7
ISSUE #4721 - WIP move saga logic to sequencePlayer
The-Daniel Jun 25, 2024
fc50236
ISSUE #4721 - moved viewpoint fetching and setting logic from seq sag…
The-Daniel Jun 25, 2024
b89c4ff
Merge branch 'staging' into ISSUE_4721
The-Daniel Jun 28, 2024
ccdfe65
ISSUE #4721 - tidy up redux after adding immer for sequences
The-Daniel Jun 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend/src/v4/helpers/viewpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import { UnityUtil } from "@/globals/unity-util";
import { isEqual } from "lodash";
import { getState } from "../modules/store";
import { selectGetMeshesByIds, selectGetSharedIdsFromNodeIds, selectHiddenGeometryVisible, selectNodesBySharedIdsMap, selectTreeNodesList } from "../modules/tree";
import { selectColorOverrides, selectTransformations } from "../modules/viewerGui";
import { selectColorOverrides } from "../modules/viewerGui";
import { Viewer } from "../services/viewer/viewer";
import { selectTransformations } from "../modules/viewpoints/viewpoints.selectors";
import { hexToArray } from "./colors";

// This merges a viewpoint
Expand Down
56 changes: 55 additions & 1 deletion frontend/src/v4/modules/sequences/sequences.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { isEqual } from 'lodash';
import { isEqual, partition } from 'lodash';
import { formatMessage } from '@/v5/services/intl';
import { GLToHexColor } from '@/v4/helpers/colors';
import { hexToOpacity } from '@/v5/ui/themes/theme';
import { STEP_SCALE } from '../../constants/sequences';
import { Viewer } from '../../services/viewer/viewer';
import { getState } from '../store';
import { selectGetMeshesByIds, selectGetNodesIdsFromSharedIds } from '../tree';
import { IStateDefinitions } from './sequences.redux';

export const getSelectedFrame = (frames, endingDate) => {
const index = getSelectedFrameIndex(frames, endingDate);
Expand Down Expand Up @@ -181,3 +184,54 @@ export const resetMovedMeshes = (sharedIds: any[]) => {
}

};

export const convertStateDefToViewpoint = ({ color = [], transparency: hiddenAndTransparent = [], transformation = [] }: IStateDefinitions) => {
const [hidden, transparency] = partition(hiddenAndTransparent, ({ value }) => value === 0);
const hidden_group = { objects: [{ shared_ids: hidden[0]?.shared_ids || [] }] };

const colorOverrides = color.map(({ shared_ids = [], value }) => ({
color: GLToHexColor(value),
objects: [{ shared_ids }],
}));
const override_groups = transparency.reduce((acc, { value: transparencyValue, shared_ids: transparencyIds = [] }) => {
transparencyIds.forEach((transparencyId) => { // Find the associated colour of the transparent object
color.forEach(({ value: colorValue, shared_ids: colorIds = []}) => {
if (colorIds.includes(transparencyId)) {
const hexNoTransparency = GLToHexColor(colorValue);
const hex = hexToOpacity(hexNoTransparency, transparencyValue * 100);

const overrideGroup = acc.find(({ color: c }) => c === hex);
if (!!overrideGroup) { // If a group for this colour and opacity exists add it to that group
overrideGroup.objects[0].shared_ids.push(transparencyId);
} else { // Otherwise add a new group to the color_overrides
acc.push({
color: hex,
objects: [{ shared_ids: [transparencyId] }],
})
}

// Remove the duplicate object id (which doesn't have opacity in its hex) from the color_overrides
const existingColorOverride = acc.find(({ color: overrideColor }) => overrideColor === hexNoTransparency).objects[0].shared_ids;
const indexToRemove = existingColorOverride.indexOf(transparencyId);
existingColorOverride.splice(indexToRemove, 1);
return acc;
}
})
})
return acc;
}, colorOverrides);
The-Daniel marked this conversation as resolved.
Show resolved Hide resolved

const transformation_groups = transformation.map(({ shared_ids = [], value }) => ({
transformation: value,
objects: [{ shared_ids }],
}));

return ({
viewpoint: {
hidden_group,
override_groups,
transformation_groups,
hideIfc: false,
},
})
}
59 changes: 34 additions & 25 deletions frontend/src/v4/modules/sequences/sequences.redux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { findIndex } from 'lodash';
import { findIndex, isEmpty } from 'lodash';
import { createActions, createReducer } from 'reduxsauce';
import { STEP_SCALE } from '../../constants/sequences';
import { sortByField } from '../../helpers/sorting';

export const { Types: SequencesTypes, Creators: SequencesActions } = createActions({
fetchSequence: ['sequenceId'],
fetchSequenceList: [],
initializeSequences: [],
fetchSequenceSuccess: ['sequence'],
fetchSequenceListSuccess: ['sequences'],
updateSequence: ['sequenceId', 'newName'],
Expand All @@ -36,19 +35,16 @@ export const { Types: SequencesTypes, Creators: SequencesActions } = createActio
setOpenOnTodaySuccess: ['openOnToday'],
fetchFrame: ['date'],
prefetchFrames: [],
setStateDefinition: ['stateId', 'stateDefinition'],
setSelectedStateDefinition: ['stateDefinition'],
updateFrameWithViewpoint: ['sequenceId', 'stateId', 'viewpoint'],
setStepInterval: ['stepInterval'],
setStepScale: ['stepScale'],
fetchActivitiesDefinitions: ['sequenceId'],
fetchActivitiesDefinitionsSuccess: ['sequenceId', 'activities'],
setActivitiesPending: ['isPending'],
setFramePending: ['isPending'],
The-Daniel marked this conversation as resolved.
Show resolved Hide resolved
showSequenceDate: ['date'],
handleTransparenciesVisibility: ['transparencies'],
restoreModelDefaultVisibility: [],
updateSelectedStateDefinition: [],
clearColorOverrides: [],
clearTransformations: [],
reset: []
}, { prefix: 'SEQUENCES/' });

Expand All @@ -61,15 +57,19 @@ export interface ISequance {
model: string;
}

type IDefinition = {
type IColorDefinition = {
value: number[],
shared_id: string[],
shared_ids: string[],
};
type ITransparencyDefinition = {
value: number,
shared_ids: string[],
};

export type IStateDefinitions = {
transformation: IDefinition[],
color: IDefinition[],
transparency: IDefinition[],
transformation: IColorDefinition[],
color: IColorDefinition[],
transparency: ITransparencyDefinition[],
};

export interface ISequencesState {
Expand All @@ -78,9 +78,7 @@ export interface ISequencesState {
lastSelectedSequence: null | string;
selectedDate: null | Date;
lastSelectedDate: null | Date;
stateDefinitions: Record<string, IStateDefinitions>;
selectedStateDefinition: Record<string, IStateDefinitions>;
statesPending: boolean;
framePending: boolean;
stepInterval: number;
stepScale: STEP_SCALE;
hiddenGeometryVisible: boolean;
Expand All @@ -95,9 +93,7 @@ export const INITIAL_STATE: ISequencesState = {
lastSelectedSequence: null,
selectedDate: null,
lastSelectedDate: null,
stateDefinitions: {},
selectedStateDefinition: {},
statesPending: false,
framePending: true,
stepInterval: 1,
stepScale: STEP_SCALE.DAY,
hiddenGeometryVisible: true,
Expand Down Expand Up @@ -145,6 +141,10 @@ export const setActivitiesPending = (state = INITIAL_STATE, { isPending }) => {
return {...state, activitiesPending: isPending };
};

export const setFramePending = (state = INITIAL_STATE, { isPending }) => {
return {...state, framePending: isPending };
};

export const setSelectedSequenceSuccess = (state = INITIAL_STATE, { sequenceId }) => {
let lastSelectedSequence = state.lastSelectedSequence;

Expand Down Expand Up @@ -173,12 +173,21 @@ export const setLastSelectedDateSuccess = (state = INITIAL_STATE, { date }) =>
return {...state, lastSelectedDate: date};
};

export const setStateDefinition = (state = INITIAL_STATE, { stateId, stateDefinition}) => {
return {...state, stateDefinitions: {...state.stateDefinitions, [stateId]: stateDefinition}};
};
export const updateFrameWithViewpoint = (state = INITIAL_STATE, { sequenceId, stateId, viewpoint }) => {
if (isEmpty(viewpoint)) {
return state;
}
const sequenceToUpdate = state.sequences.find(({ _id }) => _id === sequenceId);
const frameToUpdate = sequenceToUpdate.frames.find(({ state: s }) => s === stateId);

if (!frameToUpdate) {
// If two successive dates correspond to the same frame updateFrameViewpoint can get called for a frame that has already been converted
return state;
}
Object.assign(frameToUpdate, viewpoint);
delete frameToUpdate.state;

export const setSelectedStateDefinition = (state = INITIAL_STATE, { stateDefinition }) => {
return { ...state, selectedStateDefinition: stateDefinition };
return state;
};

export const setStepInterval = (state = INITIAL_STATE, { stepInterval }) => {
Expand All @@ -199,11 +208,11 @@ export const reducer = createReducer(INITIAL_STATE, {
[SequencesTypes.UPDATE_SEQUENCE_SUCCESS]: updateSequenceSuccess,
[SequencesTypes.FETCH_ACTIVITIES_DEFINITIONS_SUCCESS]: fetchActivitiesDefinitionsSuccess,
[SequencesTypes.SET_ACTIVITIES_PENDING]: setActivitiesPending,
[SequencesTypes.SET_FRAME_PENDING]: setFramePending,
[SequencesTypes.SET_OPEN_ON_TODAY_SUCCESS]: setOpenOnTodaySuccess,
[SequencesTypes.SET_SELECTED_DATE_SUCCESS]: setSelectedDateSuccess,
[SequencesTypes.SET_LAST_SELECTED_DATE_SUCCESS]: setLastSelectedDateSuccess,
[SequencesTypes.SET_STATE_DEFINITION]: setStateDefinition,
[SequencesTypes.SET_SELECTED_STATE_DEFINITION]: setSelectedStateDefinition,
[SequencesTypes.UPDATE_FRAME_WITH_VIEWPOINT]: updateFrameWithViewpoint,
[SequencesTypes.SET_SELECTED_SEQUENCE_SUCCESS]: setSelectedSequenceSuccess,
[SequencesTypes.SET_STEP_INTERVAL]: setStepInterval,
[SequencesTypes.SET_STEP_SCALE]: setStepScale,
Expand Down
Loading
Loading