comparison Applications/StoneWebViewer/WebApplication/app.js @ 1701:b5a8bf32d969

new configuration options: "CombinedToolEnabled", "CombinedToolBehaviour" and "DownloadAsJpegEnabled"
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 27 Nov 2020 12:21:26 +0100
parents f1bd464dc3e1
children bc40b6450261
comparison
equal deleted inserted replaced
1700:f1bd464dc3e1 1701:b5a8bf32d969
40 if (arg[0] == key) { 40 if (arg[0] == key) {
41 return arg[1]; 41 return arg[1];
42 } 42 }
43 } 43 }
44 } 44 }
45
46
47 // https://stackoverflow.com/a/21797381/881731
48 function Base64ToArrayBuffer(base64) {
49 var binary_string = window.atob(base64);
50 var len = binary_string.length;
51 var bytes = new Uint8Array(len);
52 for (var i = 0; i < len; i++) {
53 bytes[i] = binary_string.charCodeAt(i);
54 }
55 return bytes.buffer;
56 }
57
58
59 function SaveDataUriScheme(filename, dataUriScheme) {
60 var mimeType = dataUriScheme.split(',')[0].split(':')[1].split(';')[0];
61 var base64 = dataUriScheme.split(',')[1];
62
63 var blob = new Blob([ Base64ToArrayBuffer(base64) ], {
64 type: mimeType
65 });
66
67 var link = document.createElement('a');
68 link.href = window.URL.createObjectURL(blob);
69 link.download = filename;
70 link.click();
71 };
72
73
74 // Check out "enum WebViewerAction" in "StoneWebViewer.cpp" for the
75 // possible values
76 function ConvertMouseAction(config, defaultAction)
77 {
78 if (config === undefined) {
79 return defaultAction;
80 }
81 if (config == "Windowing") {
82 return stone.WebViewerAction.WINDOWING;
83 }
84 else if (config == "Zoom") {
85 return stone.WebViewerAction.ZOOM;
86 }
87 else if (config == "Pan") {
88 return stone.WebViewerAction.PAN;
89 }
90 else if (config == "Rotate") {
91 return stone.WebViewerAction.ROTATE;
92 }
93 else if (config == "Crosshair") {
94 return stone.WebViewerAction.CROSSHAIR;
95 }
96 else {
97 alert('Unsupported mouse action in the configuration file: ' + config);
98 return stone.WebViewerAction.PAN;
99 }
100 }
101
45 102
46 103
47 Vue.component('viewport', { 104 Vue.component('viewport', {
48 props: [ 'left', 'top', 'width', 'height', 'canvasId', 'active', 'series', 'viewportIndex', 105 props: [ 'left', 'top', 'width', 'height', 'canvasId', 'active', 'series', 'viewportIndex',
49 'showInfo' ], 106 'showInfo' ],
713 770
714 this.showWindowing = true; 771 this.showWindowing = true;
715 } 772 }
716 }, 773 },
717 774
718 FormatDate(date) { 775 FormatDate: function(date)
776 {
719 if (date === undefined || 777 if (date === undefined ||
720 date.length == 0) { 778 date.length == 0) {
721 return ''; 779 return '';
722 } 780 }
723 else { 781 else {
731 var month = date.replace(/^([0-9]{4})([0-9]{2})([0-9]{2})$/, '$2'); 789 var month = date.replace(/^([0-9]{4})([0-9]{2})([0-9]{2})$/, '$2');
732 var day = date.replace(/^([0-9]{4})([0-9]{2})([0-9]{2})$/, '$3'); 790 var day = date.replace(/^([0-9]{4})([0-9]{2})([0-9]{2})$/, '$3');
733 return format.replace(/YYYY/g, year).replace(/MM/g, month).replace(/DD/g, day); 791 return format.replace(/YYYY/g, year).replace(/MM/g, month).replace(/DD/g, day);
734 } 792 }
735 } 793 }
794 },
795
796 DownloadJpeg: function()
797 {
798 var canvas = document.getElementById(this.GetActiveCanvas());
799 SaveDataUriScheme('StoneWebViewerScreenshot.jpg', canvas.toDataURL('image/jpeg'));
800 },
801
802 SetCombinedToolActions: function()
803 {
804 var left = stone.WebViewerAction.WINDOWING;
805 var middle = stone.WebViewerAction.PAN;
806 var right = stone.WebViewerAction.ZOOM;
807
808 var behaviour = this.globalConfiguration['CombinedToolBehaviour'];
809 if (behaviour !== undefined) {
810 left = ConvertMouseAction(behaviour['LeftMouseButton'], left);
811 middle = ConvertMouseAction(behaviour['MiddleMouseButton'], middle);
812 right = ConvertMouseAction(behaviour['RightMouseButton'], right);
813 }
814
815 this.SetMouseButtonActions(left, middle, right);
736 } 816 }
737 }, 817 },
738 818
739 mounted: function() { 819 mounted: function() {
740 this.SetViewportLayout('1x1'); 820 this.SetViewportLayout('1x1');
757 stone.Setup(Module); 837 stone.Setup(Module);
758 stone.SetOrthancRoot('..', true); 838 stone.SetOrthancRoot('..', true);
759 stone.SetSoftwareRendering(localStorage.settingSoftwareRendering == '1'); 839 stone.SetSoftwareRendering(localStorage.settingSoftwareRendering == '1');
760 console.warn('Stone properly initialized'); 840 console.warn('Stone properly initialized');
761 841
842 app.SetCombinedToolActions();
843
762 var selectedStudies = getParameterFromUrl('selectedStudies'); 844 var selectedStudies = getParameterFromUrl('selectedStudies');
763 var study = getParameterFromUrl('study'); 845 var study = getParameterFromUrl('study');
764 var series = getParameterFromUrl('series'); 846 var series = getParameterFromUrl('series');
765 847
766 if (selectedStudies !== undefined) { 848 if (selectedStudies !== undefined) {