@@ -61,13 +61,13 @@ import {
61
61
} from '../../../js/reducers/ngl/actions' ;
62
62
import * as listType from '../../constants/listTypes' ;
63
63
import { assignRepresentationToComp } from '../../components/nglView/generatingObjects' ;
64
- import {
65
- deleteObject ,
66
- setOrientation ,
67
- setNglBckGrndColor ,
68
- setNglClipNear ,
69
- setNglClipFar ,
70
- setNglClipDist ,
64
+ import {
65
+ deleteObject ,
66
+ setOrientation ,
67
+ setNglBckGrndColor ,
68
+ setNglClipNear ,
69
+ setNglClipFar ,
70
+ setNglClipDist ,
71
71
setNglFogNear ,
72
72
setNglFogFar
73
73
} from '../../../js/reducers/ngl/dispatchActions' ;
@@ -1707,34 +1707,18 @@ const addRepresentation = (action, parentKey, representation, nglView, update, s
1707
1707
dispatch ( addComponentRepresentation ( parentKey , newRepresentation , skipTracking ) ) ;
1708
1708
} ;
1709
1709
1710
- const handleUpdateRepresentationAction = ( action , isAdd , nglView ) => ( dispatch , getState ) => {
1711
- if ( action ) {
1712
- dispatch ( updateRepresentation ( isAdd , action . change , action . object_id , action . representation , nglView ) ) ;
1713
- }
1714
- } ;
1715
-
1716
- const updateRepresentation = ( isAdd , change , parentKey , representation , nglView ) => ( dispatch , getState ) => {
1717
- const comp = nglView . stage . getComponentsByName ( parentKey ) . first ;
1718
- const r = comp . reprList . find ( rep => rep . uuid === representation . uuid || rep . uuid === representation . lastKnownID ) ;
1719
- if ( r && change ) {
1720
- let key = change . key ;
1721
- let value = isAdd ? change . value : change . oldValue ;
1722
-
1723
- r . setParameters ( { [ key ] : value } ) ;
1724
- representation . params [ key ] = value ;
1725
-
1726
- dispatch ( updateComponentRepresentation ( parentKey , representation . uuid , representation ) ) ;
1727
- }
1728
- } ;
1729
-
1730
1710
const removeRepresentation = ( action , parentKey , representation , nglView , skipTracking = false ) => (
1731
1711
dispatch ,
1732
1712
getState
1733
1713
) => {
1734
1714
const comp = nglView . stage . getComponentsByName ( parentKey ) . first ;
1735
1715
let foundedRepresentation = undefined ;
1736
1716
comp . eachRepresentation ( r => {
1737
- if ( r . uuid === representation . uuid || r . uuid === representation . lastKnownID ) {
1717
+ if (
1718
+ r . uuid === representation . uuid ||
1719
+ r . uuid === representation . lastKnownID ||
1720
+ r . repr . type === representation . type
1721
+ ) {
1738
1722
foundedRepresentation = r ;
1739
1723
}
1740
1724
} ) ;
@@ -1745,32 +1729,69 @@ const removeRepresentation = (action, parentKey, representation, nglView, skipTr
1745
1729
if ( comp . reprList . length === 0 ) {
1746
1730
dispatch ( deleteObject ( nglView , nglView . stage , true ) ) ;
1747
1731
} else {
1748
- dispatch ( removeComponentRepresentation ( parentKey , representation , skipTracking ) ) ;
1732
+ dispatch ( removeComponentRepresentation ( parentKey , foundedRepresentation , skipTracking ) ) ;
1749
1733
}
1734
+ } else {
1735
+ console . log ( `Not found representation:` , representation ) ;
1750
1736
}
1751
1737
} ;
1752
1738
1753
- const handleChangeRepresentationAction = ( action , isAdd , nglView ) => ( dispatch , getState ) => {
1739
+ const handleUpdateRepresentationAction = ( action , isAdd , nglView ) => ( dispatch , getState ) => {
1754
1740
if ( action ) {
1755
- dispatch ( changeRepresentation ( isAdd , action , nglView ) ) ;
1741
+ dispatch ( updateRepresentation ( isAdd , action . change , action . object_id , action . representation , nglView ) ) ;
1756
1742
}
1757
1743
} ;
1758
1744
1759
- const changeRepresentation = ( isAdd , action , nglView ) => ( dispatch , getState ) => {
1760
- let oldRepresentation = action . oldRepresentation ;
1761
- let newRepresentation = action . newRepresentation ;
1745
+ const updateRepresentation = ( isAdd , change , parentKey , representation , nglView ) => ( dispatch , getState ) => {
1746
+ const comp = nglView . stage . getComponentsByName ( parentKey ) . first ;
1747
+ const r = comp . reprList . find ( rep => rep . uuid === representation . uuid || rep . uuid === representation . lastKnownID ) ;
1748
+ if ( r && change ) {
1749
+ let key = change . key ;
1750
+ let value = isAdd ? change . value : change . oldValue ;
1751
+
1752
+ r . setParameters ( { [ key ] : value } ) ;
1753
+ representation . params [ key ] = value ;
1762
1754
1763
- if ( isAdd === true ) {
1764
- dispatch ( changeComponentRepresentation ( action . object_id , oldRepresentation , newRepresentation ) ) ;
1765
- dispatch ( addRepresentation ( action , action . object_id , newRepresentation , nglView , isAdd , true ) ) ;
1766
- dispatch ( removeRepresentation ( action , action . object_id , oldRepresentation , nglView , true ) ) ;
1767
- } else {
1768
- dispatch ( changeComponentRepresentation ( action . object_id , newRepresentation , oldRepresentation ) ) ;
1769
- dispatch ( addRepresentation ( action , action . object_id , oldRepresentation , nglView , isAdd , true ) ) ;
1770
- dispatch ( removeRepresentation ( action , action . object_id , newRepresentation , nglView , true ) ) ;
1755
+ dispatch ( updateComponentRepresentation ( parentKey , representation . uuid , representation ) ) ;
1771
1756
}
1772
1757
} ;
1773
1758
1759
+ const handleChangeRepresentationAction = ( action , isAdd , nglView ) => ( dispatch , getState ) => {
1760
+ if ( action ) {
1761
+ let representation = action . newRepresentation ;
1762
+ let type = action . oldRepresentation . type ;
1763
+ dispatch ( changeMolecularRepresentation ( action , representation , type , action . object_id , nglView ) ) ;
1764
+ }
1765
+ } ;
1766
+
1767
+ const changeMolecularRepresentation = ( action , representation , type , parentKey , nglView ) => ( dispatch , getState ) => {
1768
+ const newRepresentationType = type ;
1769
+
1770
+ //const newRepresentationType = e.target.value;
1771
+ const oldRepresentation = JSON . parse ( JSON . stringify ( representation ) ) ;
1772
+ //const nglView = getNglView(objectsInView[parentKey].display_div);
1773
+ const comp = nglView . stage . getComponentsByName ( parentKey ) . first ;
1774
+
1775
+ // add representation to NGL
1776
+ const newRepresentation = assignRepresentationToComp (
1777
+ newRepresentationType ,
1778
+ oldRepresentation . params ,
1779
+ comp ,
1780
+ oldRepresentation . lastKnownID
1781
+ ) ;
1782
+
1783
+ action . newRepresentation = newRepresentation ;
1784
+ action . oldRepresentation = representation ;
1785
+
1786
+ // add new representation to redux
1787
+ dispatch ( addComponentRepresentation ( parentKey , newRepresentation , true ) ) ;
1788
+
1789
+ // remove previous representation from NGL
1790
+ dispatch ( removeRepresentation ( action , parentKey , representation , nglView , true ) ) ;
1791
+
1792
+ dispatch ( changeComponentRepresentation ( parentKey , oldRepresentation , newRepresentation ) ) ;
1793
+ } ;
1794
+
1774
1795
const handleMoleculeGroupAction = ( action , isSelected , stageSummaryView , majorViewStage ) => ( dispatch , getState ) => {
1775
1796
const state = getState ( ) ;
1776
1797
if ( action ) {
@@ -1921,7 +1942,7 @@ export const mergeActions = (trackAction, list) => {
1921
1942
}
1922
1943
} ;
1923
1944
1924
- const needsToBeMerged = ( trackAction ) => {
1945
+ const needsToBeMerged = trackAction => {
1925
1946
return trackAction . merge !== undefined ? trackAction . merge : false ;
1926
1947
} ;
1927
1948
0 commit comments