Add 3D view mode specific settings and tracking planets/moons to the interactive figures

This commit is contained in:
Jeffrey SubbaRao 2019-05-22 12:33:15 -05:00
Родитель 667a8f33c5
Коммит 5c8ee5c074
3 изменённых файлов: 29 добавлений и 2 удалений

Просмотреть файл

@ -334,7 +334,7 @@ class BaseWWTWidget(HasTraits):
elif mode in VIEW_MODES_3D:
self._send_msg(event='set_viewer_mode', mode=solar_system_mode)
self.current_mode = mode
self._last_sent_view_mode=solar_system_mode
self._last_sent_view_mode = solar_system_mode
else:
raise ValueError('mode should be one of {0}'.format('/'.join(VIEW_MODES_2D + VIEW_MODES_3D)))
@ -643,6 +643,9 @@ class BaseWWTWidget(HasTraits):
'foreground_alpha': self.foreground_opacity*100}
state['layers'] = self.layers._serialize_state()
if self.current_mode in VIEW_MODES_3D:
self.solar_system._add_settings_to_serialization(state)
with open(file,'w') as file_obj:
json.dump(state,file_obj)

Просмотреть файл

@ -123,7 +123,6 @@ function loadWwtFigure() {
event: 'set_viewer_mode',
mode: viewSettings['mode']
});
wwt.gotoRaDecZoom(viewSettings['ra'], viewSettings['dec'], viewSettings['fov'], true);
if (viewSettings['mode'] == 'sky') {
var foregroundState = wwtIntialState['foreground_settings'];
@ -149,6 +148,17 @@ function loadWwtFigure() {
loadTableLayer(layerInfo);
}
});
if (!viewSettings['tracked_object_id']) { //Not tracking or trivially track sun (id=0)
wwt.gotoRaDecZoom(viewSettings['ra'], viewSettings['dec'], viewSettings['fov'], true);
}
else {
var targetCamera = wwtlib.CameraParameters.create(0, 0, viewSettings['fov'] * 6, 0, 0, wwtlib.WWTControl.singleton.renderContext.viewCamera.opacity);
targetCamera.target = viewSettings['tracked_object_id'];
targetCamera.set_RA(viewSettings['ra'] / 15.); //convert from degrees to hrs
targetCamera.set_dec(viewSettings['dec']);
wwtlib.WWTControl.singleton.gotoTarget3(targetCamera, false, true);
}
}

Просмотреть файл

@ -16,6 +16,7 @@ class SolarSystem(HasTraits):
super(SolarSystem, self).__init__()
self.base_widget = base_wwt_widget
self.observe(self._on_trait_change, type='change')
self._tracked_obj_id = 0 #Default to tracking sun
def _on_trait_change(self, changed):
# This method gets called anytime a trait gets changed. Since this class
@ -85,5 +86,18 @@ class SolarSystem(HasTraits):
if obj in mappings:
self.base_widget._send_msg(event='track_object', code=mappings[obj])
self._tracked_obj_id = mappings[obj]
else:
raise ValueError('the given object cannot be tracked')
def _add_settings_to_serialization(self, wwt_state):
for trait in self.traits().values():
wwt_name = trait.metadata.get('wwt')
if wwt_name:
trait_val = trait.get(self)
if isinstance(trait_val, u.Quantity):
trait_val = trait_val.value
wwt_state['wwt_settings'].append({'name': wwt_name, 'value': trait_val})
wwt_state['view_settings']['tracked_object_id'] = self._tracked_obj_id