'use strict';
AIA.controller("DAController", ["$scope", "$rootScope", "$compile", "$http", "$log", "$location", "$timeout", "DA", "Modules", "$routeParams", "DataService",
function ($scope, $rootScope, $compile, $http, $log, $location, $timeout, DA, Modules, $routeParam, DataService) {
$scope.genderId = "";
$scope.BodyViewData;
$scope.selectedGenderBodyViewData;
$scope.imagePath = "";
$rootScope.BodyRegionData;
$rootScope.BodyRegionCordinatesData;
$scope.isTransparencyActivated;
$rootScope.BodyLayerData;
$rootScope.VocabTermData;
$scope.VocabTermTxt;
$scope.CommonData
$rootScope.TermNumberData;
$rootScope.BodySystemData
$scope.bodyViewId = 0;
$rootScope.bgartData;
$scope.drawnBodyRegions;
//view specific constants
$rootScope.voId;
$scope.layerNumber;
$scope.daCounter = 1;
$scope.bagartDetails;
$scope.transNumber = 50;
//for transarency scale
$scope.TBDrawStartX;
$scope.TBDrawStartY;
$rootScope.path = "~/../content/images/speeachBubbleClose.png";
$rootScope.isHighLight = false;
$rootScope.coloredImageCanvasList = [];
$rootScope.coloredImageMRCanvasList = [];
$rootScope.ColoredCanvasData = [];
$rootScope.grayImageDataList = [];
$rootScope.grayImageMRDataList = [];
$rootScope.updatedGrayDataList = [];
$rootScope.updatedGrayMRDataList = [];
$scope.isEligibleForHighlight = false;
$scope.doHighlightOrExtract = false;
$scope.isEligibleForHighlightBodyByTermList = false;
$scope.AnteriorView = "active";
$scope.zoomInOut = 75;
$scope.speechBubbleCounter = 0;
$scope.j = 0;
$scope.speechbubbleList = [];
$scope.speachBubbleArrayAnnotation = [];
$rootScope.multiAnnotationIsON = false;
$scope.previousGrayImageDataVar;
$scope.previousGrayCanvas;
$rootScope.updatedImageDataList = [];
$rootScope.updatedImageMRDataList = [];
$scope.previousSelectedTermList = [];
$scope.runningWorkers = [];
$scope.runningSearchWorkers = [];
$scope.runningBodyViewWorkers = [];
// This variable is used for unhighlight previously highlighted body portion, if multiAnnotation is false.
$scope.machedIcolorInBodyRegion = [];
$rootScope.MaskCanvasData = [];
//extract
$rootScope.isExtract = false;
$rootScope.whiteImageDataList = [];
$rootScope.whiteImageMRDataList = [];
$rootScope.previousHighlightList = [];
$rootScope.isViewChange = false;
$rootScope.isGenderChnage = false;
// to do it is setting but not using. need to check
$rootScope.updatedWhiteImageDataList = [];
$rootScope.updatedWhiteImageMRDataList = [];
//normal mode
$rootScope.isNormalMode = false;
$rootScope.isZoomed = false;
//navigator man functionality
$scope.navigatorImage;
$scope.NavigatorData;
$scope.navimgsrc;
$scope.dragdivleft = 0;
$scope.dragdivtop = 0;
$scope.IsSearchVisible = false;
$scope.shapesize = 1;
$scope.dragdivposition = {
"left": $scope.dragdivleft,
"top": $scope.dragdivtop
};
//array for bodyviewid correspoing to male female(used for gender change)
$scope.correspondingBodyViewIds = {
'1': '5',
'2': '6',
'3': '7',
'4': '8',
'9': '11',
'10': '12',
'5': '1',
'6': '2',
'7': '3',
'8': '4',
'11': '9',
'12': '10',
}
$scope.bodyViews = {
'Anterior': '1',
'Lateral': '2',
'Medial': '3',
'Posterior': '4',
'Lateral Arm': '5',
'Medial Arm': '6'
}
$scope.isBodylayerdataLoaded = false;
$scope.isBodyRegionDataLoaded = false;
//currentTitleFromJson shows the current BodyView Title
$scope.currentTitleFromJson;
$scope.showme = false;
$scope.IsVisible = function () {
$scope.scroll();
}
$scope.scroll = function () {
// $window.scrollTo(0, 0);
$("html,body").scrollTop(0);
//alert("scroll");
}
$scope.switchGender = function () {
var retrievedObject = localStorage.getItem('currentViewTitle');
if (retrievedObject == "Male Anterior") {
$scope.male = "active";
$scope.female = "";
}
else if (retrievedObject == "Female Anterior") {
$scope.male = "";
$scope.female = "active";
}
}
//get the DA body view list based on selected gender
//get the DA body view list based on selected gender
$scope.getDAViewList = function ($event) {
// debugger;
if ($('#MainImage') != null) {
$('#MainImage').remove();
}
$rootScope.currentActiveModuleTitle = Modules[0].Name;
$("#bodyViewList").empty();
//for default load
if ($event == null || $event == undefined) {
//if ((localStorage.getItem("genderId") != "")||(localStorage.getItem("genderId")!="null")) {
// $scope.genderId = localStorage.getItem("genderId");
//}
var selectedGender = localStorage.getItem("genderId");
if ((selectedGender == null)) {
$scope.genderId = "Male";
}
else
$scope.genderId = localStorage.getItem("genderId");
}
else {
$scope.genderId = $event.currentTarget.id;
}
localStorage.setItem("genderId", $scope.genderId);
var selectedGender = localStorage.getItem("genderId");
if (selectedGender != null) {
if (selectedGender == "Male") {
$('#Male').addClass('active');
$('#Female').removeClass("active");
}
else {
$('#Female').addClass('active');
$('#Male').removeClass("active");
}
}
$scope.selectedGenderBodyViewData = new jinqJs()
.from($scope.BodyViewData.BodyViews.view)
.where('_gender == ' + $scope.genderId)
.select();
if ($scope.selectedGenderBodyViewData != null || $scope.selectedGenderBodyViewData != undefined) {
angular.forEach($scope.selectedGenderBodyViewData, function (value, key) {
var userEthnicity;
var userModestysettings;
var curentEthnicity = localStorage.getItem("globalEthnicity");
if (typeof (curentEthnicity) !== "undefined" && curentEthnicity !== null) {
userEthnicity = curentEthnicity;
}
else {
userEthnicity = $rootScope.globalSetting.ethnicity;
}
var curentmodesty = localStorage.getItem("globalModesty");
if (typeof (curentmodesty) !== "undefined" && curentmodesty !== null) {
userModestysettings = curentmodesty;
}
else {
userModestysettings = $rootScope.globalSetting.modesty;
}
//var userSelectedSkintone = 'W';
//$scope.userModestySetting = 'Y'
var thumbnailImage;
if ((value._id == 1) || (value._id == 3) || (value._id == 5) || (value._id == 6) || (value._id == 7) || (value._id == 11))
thumbnailImage = ((value._thumbnailImage).replace('.jpg', '_' + userEthnicity + userModestysettings)) + '.jpg';
else {
thumbnailImage = ((value._thumbnailImage).replace('.jpg', '_' + userEthnicity)) + '.jpg';
}
$scope.imagePath = "~/../content/images/DA/" + $scope.zoomInOut + "/body-views/" + value._id + '/skintone/' + userEthnicity + '/' + thumbnailImage;
// debugger;
var $el = $('
'
+ ''
+ '
' + value._title + '
').appendTo('#bodyViewList');
$compile($el)($scope);
$(".sidebar").mCustomScrollbar({
autoHideScrollbar: true,
//theme:"rounded"
});
});
}
};
$scope.openView = function ($event) {
// debugger;
$rootScope.isLoading = true;
$('#spinner').css('visibility', 'visible');
$rootScope.currentBodyViewId = $event.currentTarget.id;
$rootScope.ViewTitle = $event.currentTarget.textContent;
localStorage.setItem("currentViewTitleFromJson", $event.currentTarget.textContent);
localStorage.setItem("currentBodyViewId", $event.currentTarget.id);
var u = $location.url();
$location.url('/da-body-view');
var view_list = angular.element($event.currentTarget);
var view_list_male_female = view_list.attr('title');
//$rootScope.Normal = "LeftButtonsDefaultState";
if (view_list_male_female == "Male") {
$rootScope.male = "active";
$rootScope.female = "";
}
else {
$rootScope.male = "";
$rootScope.female = "active";
}
}
//load json data for body view
$scope.loadDissectibleAnatomyData = function () {
$rootScope.ClearIframe();
//load common data
var commondataJsonPath = '~/../content/data/json/da/da_dat_common.json';
DataService.getAnotherJson(commondataJsonPath)
.then(
function (result) {
$rootScope.CommonData = result;
$http({ method: 'GET', url: '~/../content/data/json/da/da_dat_contentlist.json' }).success(function (data) {
$scope.BodyViewData = data;
$scope.getDAViewList();
})
.error(function (data, status, headers, config) {
console.log(data);
});
},
function (error) {
console.log(error.statusText)
}
)
//load body-views data
// $('#daLoaderLabel').css('visibility', 'hidden')
$rootScope.isLoading = false;
//push the details of open module in array $rootScope.openModules
$rootScope.openModules.push({ "ModuleId": 1 });
}
//da-body-views functions
$scope.openBodyView = function () {
//0. we will initially append container to load body
//check if localstorage has any settings
var curentEthnicity = localStorage.getItem("globalEthnicity");
if (typeof (curentEthnicity) !== "undefined" && curentEthnicity !== null) {
$rootScope.globalSetting.ethnicity = curentEthnicity;
}
var curentmodesty = localStorage.getItem("globalModesty");
if (typeof (curentmodesty) !== "undefined" && curentmodesty !== null) {
$rootScope.globalSetting.modesty = curentmodesty
}
//0.1
var currentBodyViewId = localStorage.getItem("currentBodyViewId");
console.log('currentBodyViewId pickjed from localStorage: ' + currentBodyViewId);
var openViews;
if ($rootScope.openViews != null || $rootScope.openViews != undefined) {
if ($rootScope.openViews.length > 0) {
openViews = new jinqJs()
.from($rootScope.openViews)
.where("BodyViewId == " + currentBodyViewId)
.select();
}
}
// 0.2 getting corresponding body view title
var counter = 1;
var tittle = localStorage.getItem("currentViewTitleFromJson");
if (openViews != null && openViews != undefined) {
angular.forEach(openViews, function (value, key) {
if (value.body - views == tittle) {
tittle = localStorage.getItem("currentViewTitleFromJson") + counter++;
$rootScope.currentActiveViewTitle = tittle;
localStorage.setItem("currentViewTitle", tittle);
}
});
}
else {
localStorage.setItem("currentViewTitle", tittle);
}
//0.3
$.jsPanel({
id: 'daImagePanel',
selector: '.daBodyView',
theme: 'success',
currentController: 'DAController',
parentSlug: 'da-view-list',
ajax: {
url: 'app/views/da/da-view.html'
},
title: localStorage.getItem("currentViewTitle"),
position: {
top: 70,
left: 1,
},
size: { width: $(window).outerWidth() - 10, height: $(window).outerHeight() - 110 },
});
//0.1
$rootScope.currentSlug = 'da-body-view';
//0.2
$rootScope.openViews.push(
{
"module": $rootScope.currentActiveModuleTitle, "body-views": tittle, "state": 'max', "BodyViewId": $rootScope.currentBodyViewId,
"slug": $rootScope.currentSlug
}
);
//0.3
var daBodyviewElement = angular.element(document.getElementById("daBodyview"));
$timeout(function () { $compile(daBodyviewElement.contents())($scope) }, 250);
//0.4 added some stylesheets
$('#daBodyview').css("height", $(window).outerHeight());
$('#daBodyview').css("width", $(window).outerWidth());
//1. load navigator man first
$scope.LoadBodyViewNavigatorImage();
$scope.loadSearchDataForBodyView();
$scope.currentTitleFromJson = localStorage.getItem("currentViewTitle");
$scope.layerNumber = 0;
//2.
console.log('currentBodyViewId just before sending: ' + currentBodyViewId);
$scope.loadBodyViewData(currentBodyViewId);
//2. load bodyRegion data
$rootScope.isLoading = true;
$rootScope.voId = localStorage.getItem("currentBodyViewId");
$('#daBodyview').css("height", $(window).outerHeight());
$('#daBodyview').css("width", $(window).outerWidth());
}
angular.element(document).ready(function () {
})
$scope.loadSearchDataForBodyView = function () {
console.log('loadSearchDataForBodyView');
var currentBodyViewId = localStorage.getItem("currentBodyViewId");
var searchWorker = new Worker('search-wp.js');
//push workers in array to further used the refernece to delete the workers
$scope.runningSearchWorkers.push({ 'workerName': searchWorker })
//console.log('for bodyRegionId = ' + bodyRegionId + ', time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"))
searchWorker.postMessage({
'currentBodyViewId': currentBodyViewId,
})
searchWorker.onmessage = function (e) {
//console.log('callback searchWorker , time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"));
$rootScope.TermNumberData = e.data.TermNumberData,
$rootScope.VocabTermData = e.data.VocabTermData,
$scope.vocabTermTxt = e.data.vocabTermTxt
$scope.VocabTermTxt = new jinqJs()
.from($scope.vocabTermTxt)
.distinct('_TermText', '_ActualTermNumber')
.orderBy([{ field: '_TermText', sort: 'asc' }])
.select('_ActualTermNumber', '_TermText', '_cdId');
console.log('JlinqActivity , time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"));
if ($scope.runningSearchWorkers != null || $scope.runningSearchWorkers != undefined) {
var workerCount = $scope.runningSearchWorkers.length;
if (workerCount > 0) {
for (var i = workerCount - 1; i >= 0; i--) {
var runningWorker = $scope.runningSearchWorkers[i].workerName;
runningWorker.terminate();
$scope.runningSearchWorkers.splice(i, 1);
// workerCount--;
}
}
}
}
}
$scope.loadBodyViewData = function (currentVoid) {
console.log('caller of worker sending currentVoid: ' + currentVoid);
var bodyViewWorker = new Worker('body-view-wp.js');
//push workers in array to further used the refernece to delete the workers
$scope.runningBodyViewWorkers.push({ 'workerName': bodyViewWorker })
bodyViewWorker.postMessage({
'currentViewId': currentVoid
});
bodyViewWorker.onmessage = function (e) {
//console.log('callback in extr');
$rootScope.BodyRegionData = e.data.bodyRegionData;
$rootScope.bgartData = e.data.bodyArtData;
$rootScope.BodyLayerData = e.data.bodyLayerData;
$scope.isBodylayerdataLoaded = true;
$scope.LoadDefaultLayerImage();
}
bodyViewWorker.onerror = function (e) {
alert('Error: Line ' + e.lineno + ' in ' + e.filename + ': ' + e.message);
};
}
//Code for displaying NavigatorImage for BodyView
$scope.LoadBodyViewNavigatorImage = function () {
var NavigatorManJsonPath = '~/../content/data/json/da/da_dat_orient_image.json';
$http({ method: 'GET', url: NavigatorManJsonPath })
.success(function (data) {
$scope.NavigatorData = data;
$scope.skinTone = $rootScope.globalSetting.ethnicity;
var navigatorManData = new jinqJs()
.from($scope.NavigatorData.Navigtor.ViewOrientation)
.where("_ViewOrientationId == " + $rootScope.currentBodyViewId)
.select();
if ((navigatorManData != null || navigatorManData != undefined) && (navigatorManData.length > 0)) {
var imageInfoForNavigator = new jinqJs()
.from(navigatorManData[0].ImageInfo)
.where("_Ethnicity == " + $scope.skinTone)
.select();
}
else {
console.log('NAVIGATOR.DATA.NOT.FOUND FOR BODY VIEW: ' + $rootScope.currentBodyViewId);
}
if (imageInfoForNavigator != null || imageInfoForNavigator != undefined) {
$scope.navigatorImage = imageInfoForNavigator;
var navImageModesty;
if (($scope.navigatorImage != null || $scope.navigatorImage != undefined) && ($scope.navigatorImage.length > 0)) {
angular.forEach($scope.navigatorImage, function (value, key) {
if (value._HaveModesty === $rootScope.globalSetting.modesty) {
navImageModesty = value._ImageName;
}
})
}
if (typeof (navImageModesty) === "undefined" || navImageModesty === null) {
navImageModesty = $scope.navigatorImage[0]._ImageName;
}
$scope.navimgsrc = "~/../content/images/DA/ethnicity/body-views/" + $scope.voId + '/' + $scope.skinTone + '/navigator_images/' + navImageModesty;
$('#navigatorDiv').css('visibility', 'visible');
$('#containment - wrapper').css('visibility', 'visible');
}
else {
console.log('NAVIGATOR.IMAGE.NOT.FOUND FOR BODY VIEW: ' + $rootScope.currentBodyViewId);
}
})
.error(function (data, status, headers, config) {
//1.
console.log('DATA.NOT.LOADED FOR:' + NavigatorManJsonPath + ', ERROR: ' + data);
//2.
// $scope.LoadBodyViewNavigatorImage()
});
}
$scope.LoadDefaultLayerImage = function () {
// debugger;
$rootScope.isNormalMode = true;
$scope.layerNumber = 0;
$scope.skinTone = $rootScope.globalSetting.ethnicity;
$rootScope.viewOrientationId = $rootScope.voId;
if ($rootScope.voId == 5) {
$rootScope.viewOrientationId = 1;
}
else if ($rootScope.voId == 6) {
$rootScope.viewOrientationId = 2;
}
else if ($rootScope.voId == 7) {
$rootScope.viewOrientationId = 3;
}
else if ($rootScope.voId == 8) {
$rootScope.viewOrientationId = 4;
}
else if ($rootScope.voId == 9) {
$rootScope.viewOrientationId = 5;
}
else if ($rootScope.voId == 10) {
$rootScope.viewOrientationId = 6;
}
else if ($rootScope.voId == 11) {
$rootScope.viewOrientationId = 5;
}
else if ($rootScope.voId == 12) {
$rootScope.viewOrientationId = 6;
}
$scope.CalculateImageCordinates($rootScope.viewOrientationId);
};
//calculate coordinates for body region images
$scope.CalculateImageCordinates = function (viewOrientationId) {
$scope.terminateCurrentlyRunningWPs();
var drawnBodyRegionCount = [];
if ($rootScope.MaskCanvasData != null || $rootScope.MaskCanvasData != undefined) {
var n = $rootScope.MaskCanvasData.length;
if (n > 0) {
for (var i = n - 1; i >= 0; i--) {
$rootScope.MaskCanvasData.splice(i, 1);
// workerCount--;
}
$rootScope.MaskCanvasData = null;
$rootScope.MaskCanvasData = [];
}
}
//set height of canvas div and left tool bar as per window size
$rootScope.BodyRegionCordinatesData = []; // create an empty array
$('#daBodyview').css('width', '100%');
$('#canvasDiv').css('height', $('#daImagePanel').outerHeight() - 104)
//$('#canvasDiv').css('width', $('#daImagePanel').outerWidth() - 100)
$('#leftToolBar').css('height', $('#daImagePanel').outerHeight())
//calculate image coordinates and draw image
var bodyRegionCoordinates = $rootScope.BodyRegionData.BodyRegionViews;
// var viewOrientationId = String($rootScope.voId);
$scope.bodyRegionCoordinates = new jinqJs()
.from($rootScope.BodyRegionData.BodyRegionViews.BodyRegionCordinates)
.where('_ViewOrientationId == ' + viewOrientationId)
.select();
console.log('viewOrientationId= ' + viewOrientationId + ', $scope.bodyRegionCoordinates length= ' + $scope.bodyRegionCoordinates.length)
// if ($rootScope.voId == 9 || $rootScope.voId == 11) {
$scope.bagartDetails = new jinqJs()
.from($rootScope.bgartData.BackgroundArts.BackgroundArtDetail)
.where('_ViewOrientationId == ' + viewOrientationId)
.select();
if ($scope.ColoredImageSRC != null && $scope.ColoredImageSRC.length > 0) {
$scope.ColoredImageSRC = null;
$scope.ColoredImageSRC = [];
$scope.flushCanvas();
}
else {
$scope.ColoredImageSRC = [];
}
if ($scope.bodyRegionCoordinates != null || $scope.bodyRegionCoordinates != undefined) {
angular.forEach($scope.bodyRegionCoordinates, function (value, key) {
if (value._HaveMirrorImage == 'Y') {
//DrawMirroredImage
//0. Scaling as per default zoom
var rectangle = scaleRectangle(value._X, value._Y, value._Height, value._Width, value._MirrorValue);
//1.Get image source
var src = $scope.GetImageSource(value._BodyRegionId);
$scope.imageSource = src;
//2.Draw mirror image
$scope.DrawMirroredImage(Math.round(rectangle.scaledHeight), Math.round(rectangle.scaledWidth), Math.round(rectangle.scaledX), Math.round(rectangle.scaledY), src, value._BodyRegionId, 'N');
// debugger;
$rootScope.BodyRegionCordinatesData.push(
{
"bodyRegionId": value._BodyRegionId, "Height": Math.round(rectangle.scaledHeight), "Width": Math.round(rectangle.scaledWidth),
"X": Math.round(rectangle.scaledX), "Y": Math.round(rectangle.scaledY), "IsMirror": 'Yes'
}
);
//3.GetMaskImageSource
var maskImageSrc = $scope.GetMaskImageSource($scope.imageSource);
// debugger;
//4 Draw Mask Mirror Image
$scope.DrawMirroredImage(Math.round(rectangle.scaledHeight), Math.round(rectangle.scaledWidth), Math.round(rectangle.scaledX), Math.round(rectangle.scaledY), maskImageSrc, value._BodyRegionId, 'Y');
//Draw Normal Image
//0. Scaling as per default zoom
var rectangle = scaleRectangle(value._X, value._Y, value._Height, value._Width, 0);
//1.Draw body region which have mirror image
$scope.DrawImage(Math.round(rectangle.scaledHeight), Math.round(rectangle.scaledWidth), Math.round(rectangle.scaledX), Math.round(rectangle.scaledY), src, value._BodyRegionId, 'N');
$scope.BodyRegionCordinatesData.push(
{
"bodyRegionId": value._BodyRegionId, "Height": Math.round(rectangle.scaledHeight), "Width": Math.round(rectangle.scaledWidth),
"X": Math.round(rectangle.scaledX), "Y": Math.round(rectangle.scaledY), "IsMirror": 'No'
}
);
//2.Draw body region for mask image
$scope.DrawImage(Math.round(rectangle.scaledHeight), Math.round(rectangle.scaledWidth), Math.round(rectangle.scaledX), Math.round(rectangle.scaledY), maskImageSrc, value._BodyRegionId, 'Y');
}
else {
//0.Scaling as per default zoom
var rectangle = scaleRectangle(value._X, value._Y, value._Height, value._Width, value._MirrorValue);
//1.Get image source
if (value._IsPrimary == 'N') {
var src = $scope.GetBackgroundImgSource(value._BodyRegionId);
$scope.imageSource = src;
}
else {
var src = $scope.GetImageSource(value._BodyRegionId);
$scope.imageSource = src;
}
//2.Draw body region which don't have mirror image
$scope.DrawImage(Math.round(rectangle.scaledHeight), Math.round(rectangle.scaledWidth), Math.round(rectangle.scaledX), Math.round(rectangle.scaledY), src, value._BodyRegionId, 'N');
$scope.BodyRegionCordinatesData.push(
{
"bodyRegionId": value._BodyRegionId, "Height": Math.round(rectangle.scaledHeight), "Width": Math.round(rectangle.scaledWidth),
"X": Math.round(rectangle.scaledX), "Y": Math.round(rectangle.scaledY), "IsMirror": 'No'
}
);
//3.GetMaskImageSource
var maskSRC = $scope.GetMaskImageSource($scope.imageSource);
//4.Draw body region for mask image
$scope.DrawImage(Math.round(rectangle.scaledHeight), Math.round(rectangle.scaledWidth), Math.round(rectangle.scaledX), Math.round(rectangle.scaledY), maskSRC, value._BodyRegionId, 'Y');
//draw figLeaf for modesty
$scope.figLaefImageName;
$scope.figLaefX;
$scope.figLaefY;
var gender;
if (localStorage.getItem("genderId") == 'Female') {
gender = 'F';
}
else {
gender = 'M';
}
if (((localStorage.getItem("genderId") == 'Female') && (value._BodyRegionId == 2)) || (value._BodyRegionId == 3)) {
if ($scope.bagartDetails != null || $scope.bagartDetails != undefined) {
var dtlOfBr = new jinqJs()
.from($scope.bagartDetails)
.where('_BodyRegionId == ' + value._BodyRegionId)
.select();
if (dtlOfBr != null || dtlOfBr != undefined) {
var dtlOfGender = new jinqJs()
.from(dtlOfBr)
.where('_Gender == ' + gender)
.select();
if (dtlOfGender != null || dtlOfGender != undefined) {
var dtlOfSktn = new jinqJs()
.from(dtlOfGender)
.where('_Skintone == +')
.select();
//multiple conditions are not working in where clause of JinQ so need multiple filtered variables
if ((dtlOfSktn != null || dtlOfSktn != undefined) && (dtlOfSktn.length > 0)) {
if ((parseInt(dtlOfSktn[0]._lns) <= parseInt($scope.layerNumber)) && (parseInt(dtlOfSktn[0]._lne) > parseInt($scope.layerNumber)) && (dtlOfSktn[0]._isfr == 'Y')) {
$scope.figLaefImageName = dtlOfSktn[0]._ImageId;
//$scope.figLaefX = filtereddata[0]._X;
//$scope.figLaefY = filtereddata[0]._Y;
var rectangle = scaleRectangle(value._X, value._Y, value._Height, value._Width, value._MirrorValue);
var src = "content/images/DA/" + $scope.zoomInOut + "/body-views/" + $rootScope.voId + "/layers/0/" + value._BodyRegionId + "/" + $scope.figLaefImageName;
$scope.DrawImage(rectangle.scaledHeight, rectangle.scaledWidth, rectangle.scaledX, rectangle.scaledY, src, 'modestyImg' + value._BodyRegionId, 'N')
}
}
}
}
}
}
}
});
$rootScope.isLoading = false;
$('#spinner').css('visibility', 'hidden');
}
if (($rootScope.globalSetting.modesty == 'Y')) {
if ($('.modestyImg') != null) {
$('.modestyImg').css('visibility', 'visible');
}
}
//set scrollbars on canvas and hide loading label
// debugger;
// var isiOSSafari = (navigator.userAgent.match(/like Mac OS X/i)) ? true : false;
var isiOSSafari = (navigator.userAgent.match(/iPad/i)) ? true : false;
//set scrollbars on canvas and hide loading label
// $('#daLoaderLabel').css('visibility', 'hidden')
$('#canvasDiv').css('overflow', 'scroll')
if (isiOSSafari) {
$('#canvasDiv').scrollLeft($('#canvasDiv').width() + 150)
}
else {
$('#canvasDiv').scrollLeft($('#canvasDiv').width() / 2)
}
// $('#canvasDiv').scrollLeft($scope.imageHorizontlScrollPosition)
$('#canvasDiv').scrollTop(50)
var abc = $rootScope.BodyRegionCordinatesData;
//debugger;
$('#layerChangeSlider').slider("option", "value", parseInt($scope.totalLayers) - parseInt($scope.layerNumber));
// $('#spinner').css('visibility', 'hidden');
$rootScope.isLoading = false;
//Dated:16-07-2016 Issue #4957 :While selecting the Zoom-in\Zoom-out button scroll should be go on top.
// #4976 :While changing gender male to female scroll bar is going on top.
var canvasDiv = document.getElementById('canvasDiv');
canvasDiv.scrollTop = 0;
//Navigator Code for dynamically calculating the height and width of Dragable Div on Navigator Image
var dragdivh = Math.floor(($('#canvasDiv').height() / $('#canvasDiv')[0].scrollHeight) * 119) //119px is the height of the image
if ($('#canvasDiv')[0].scrollWidth > $('#canvasDiv')[0].clientWidth) {
var dragdivw = 42
$scope.dragdivleft = 21;
$scope.dragdivtop = 0;
$scope.dragdivposition = {
"left": 21,
"top": 0
};
}
else {
var dragdivw = 83;
$scope.dragdivleft = 0;
$scope.dragdivtop = 0;
$scope.dragdivposition = {
"left": 0,
"top": 0
};
}
$('#draggable').css('width', dragdivw);
$('#draggable').css('height', dragdivh)
}
function scaleRectangle(x, y, height, width, mirrorValue) {
var nzoom = $scope.zoomInOut;
var existingZoon = 100;
var X = 0;
var scaledY = 0;
var scaledHeight = 0;
var scaledWidth = 0;
if (mirrorValue != 0) {
var mirroredX = parseInt(mirrorValue) + parseInt(x);
var newX = (mirroredX * nzoom);
mirroredX = (newX / existingZoon);
X = mirroredX;
}
else {
var newX = (x * nzoom);
X = (newX / existingZoon);
}
var newY = (y * nzoom);
var Y = (newY / existingZoon);
var newHeight = (height * nzoom);
var ht = (newHeight / existingZoon);
var newWidth = (width * nzoom);
var wt = (newWidth / existingZoon);
return {
scaledX: X,
scaledY: Y,
scaledHeight: ht,
scaledWidth: wt
}
}
$scope.GetMaskImageSource = function (src) {
if (src != null || src != undefined) {
if (src.match('.png')) {
var mciImage = src.replace('.png', '_mci.png')
}
else {
var mciImage = src.replace('.jpg', '_mci.png')
}
return mciImage;
}
else {
console.log('IMAGE.SOURCE.NOLT.FOUND');
}
}
$scope.GetImageSource = function (bodyRegionId) {
// debugger;
var dataLength = $rootScope.BodyLayerData.Layers.DataLayer.length;
//set max for LayerNumber input
$scope.totalLayers = dataLength - 1;
// debugger
$('#txtLayerNumber').attr('max', $scope.totalLayers);
$('#layerChangeSlider').slider("option", "max", $scope.totalLayers);
// $('#layerChangeSlider').slider("option", "value",parseInt($scope.totalLayers)-parseInt($scope.layerNumber));
$scope.one = 1;
$scope.userInput = parseInt($scope.layerNumber);
$scope.skinTone = $rootScope.globalSetting.ethnicity;
var SelectedLayerData = [];
SelectedLayerData = $rootScope.BodyLayerData.Layers.DataLayer[dataLength - $scope.userInput - 1];
if ((SelectedLayerData != null || SelectedLayerData != undefined))
if ($scope.layerNumber == 0) {
console.log('lNo: ' + $scope.layerNumber + ' and BodyRegion.length: ' + SelectedLayerData.BodyRegion.length);
if (SelectedLayerData.BodyRegion.length > 0) {
for (var z = 0; z < SelectedLayerData.BodyRegion.length; z++) {
var bodyRegion = SelectedLayerData.BodyRegion[z]._BodyRegionId;
var bodyRegionSkinTone = SelectedLayerData.BodyRegion[z].Image._SkintTone;
if ($rootScope.viewOrientationId == 3 && bodyRegionId == 1) {
console.log('$rootScope.voId: ' + $rootScope.voId);
if (bodyRegion == bodyRegionId && bodyRegionSkinTone == 'W') {
return "content/images/DA/" + $scope.zoomInOut + "/body-views/" + $rootScope.voId + "/layers/" + $scope.layerNumber + "/" + bodyRegionId + "/W/" + SelectedLayerData.BodyRegion[z].Image._ImageName;
}
}
else {
if (bodyRegion == bodyRegionId && bodyRegionSkinTone == $scope.skinTone) {
return "content/images/DA/" + $scope.zoomInOut + "/body-views/" + $rootScope.voId + "/layers/" + $scope.layerNumber + "/" + bodyRegionId + "/" + $scope.skinTone + "/" + SelectedLayerData.BodyRegion[z].Image._ImageName;
}
}
}
}
}
else {
// debugger;
//below 4 bodyviews have only single body region
if (($rootScope.voId == '9') || ($rootScope.voId == '11') || ($rootScope.voId == '10') || ($rootScope.voId == '12')) {
var bodyRegion = SelectedLayerData.BodyRegion._BodyRegionId;
return "content/images/DA/" + $scope.zoomInOut + "/body-views/" + $rootScope.voId + "/layers/" + $scope.layerNumber + "/" + bodyRegionId + "/" + SelectedLayerData.BodyRegion.Image._ImageName;
}
else // it is for other body view which have multiple body regions and layer no > 0
{
// debugger;
if (SelectedLayerData.BodyRegion.length > 0) {
for (var z = 0; z <= SelectedLayerData.BodyRegion.length; z++) {
var bodyRegion = SelectedLayerData.BodyRegion[z]._BodyRegionId;
if (bodyRegion == bodyRegionId) {
return "content/images/DA/" + $scope.zoomInOut + "/body-views/" + $rootScope.voId + "/layers/" + $scope.layerNumber + "/" + bodyRegionId + "/" + SelectedLayerData.BodyRegion[z].Image._ImageName;
}
}
}
}
}
}
$scope.GetBackgroundImgSource = function (bodyRegionId) {
// debugger;
var selectedGender;
if (localStorage.getItem("genderId") == "Male") {
selectedGender = 'M';
}
else {
selectedGender = 'F';
}
//filter data based on bodyRegion
$scope.bagartBodyRegionDetails = new jinqJs()
.from($scope.bagartDetails)
.where('_BodyRegionId == ' + bodyRegionId)
.select();
if ($scope.bagartBodyRegionDetails != null || $scope.bagartBodyRegionDetails != undefined) {
//filter bodyRegion data basd on skintone
$scope.bagartDetailsOnSktn = new jinqJs()
.from($scope.bagartBodyRegionDetails)
.where('_Skintone == ' + $scope.skinTone)
.select();
if ($scope.bagartDetailsOnSktn != null || $scope.bagartDetailsOnSktn != undefined) {
//only brid=2 is having different male,female image, other bodr region have common images for male, female
if (bodyRegionId == 2) {
for (var z = 0; z <= $scope.bagartDetailsOnSktn.length; z++) {
var gender = $scope.bagartDetailsOnSktn[z]._Gender;
if (gender == selectedGender) {
return "content/images/DA/" + $scope.zoomInOut + "/body-views/" + $rootScope.voId + "/layers/0/" + bodyRegionId + "/" + $scope.skinTone + "/" + $scope.bagartDetailsOnSktn[z]._ImageId;
}
}
}
else {
return "content/images/DA/" + $scope.zoomInOut + "/body-views/" + $rootScope.voId + "/layers/0/" + bodyRegionId + "/" + $scope.skinTone + "/" + $scope.bagartDetailsOnSktn[0]._ImageId;
}
}
}
}
$scope.DrawMirroredImage = function (h, w, x, y, src, bodyRegionId, isMaskImage) {
var FlipedImgCanvas = document.createElement('canvas');
FlipedImgCanvas.height = h;
FlipedImgCanvas.width = w;
FlipedImgCanvas.setAttribute("data-IsMirrored", "Y")
FlipedImgCanvas.style.position = "absolute";
FlipedImgCanvas.style.left = x + "px";
FlipedImgCanvas.style.top = y + "px";
if (isMaskImage == 'Y') {
FlipedImgCanvas.id = 'imageCanvas' + bodyRegionId + '_MR_mci';
FlipedImgCanvas.style.visibility = 'hidden'
}
else {
FlipedImgCanvas.id = 'imageCanvas' + bodyRegionId + '_MR';
if ($rootScope.isExtract == true) {
FlipedImgCanvas.style.visibility = 'visible'
}
else {
if ($rootScope.isHighLight == true && $rootScope.isZoomed == false) {
FlipedImgCanvas.style.visibility = 'hidden';
}
}
}
FlipedImgCanvas.addEventListener('click', function (evt) {
//to get correct data on multihighlight highlight
if ($scope.isLayerChange == true) {
$scope.isLayerChange = false;
}
if (evt.ctrlKey) {
$rootScope.multiAnnotationIsON = true;
}
else {
if (($rootScope.previousHighlightList != null || $rootScope.previousHighlightList != undefined) && ($rootScope.previousHighlightList.length > 0)) {
$rootScope.previousHighlightList = [];
}
$rootScope.multiAnnotationIsON = false;
}
//get mouse coordinate of mirror image click
var mousePos = $scope.getMousePos(evt);
var context = FlipedImgCanvas.getContext("2d");
var canvasId = context.canvas.getAttribute('id');
var mirrorCanvasX = context.canvas.offsetLeft;
var mirrorCanvasWidth = context.canvas.clientWidth;
var maskCanvasId = (canvasId.replace('_MR', '')) + '_mci';
var maskCanvas = document.getElementById(maskCanvasId);
var maskCanvasContext = maskCanvas.getContext("2d");
var canvasDiv = document.getElementById('canvasDiv');
var verticalScrollPosition = canvasDiv.scrollTop;
var horizontlScrollPosition = canvasDiv.scrollLeft;
var distanceXOnMirrorImage = (parseInt(mirrorCanvasX) + parseInt(mirrorCanvasWidth)) - (parseInt(mousePos.x) + horizontlScrollPosition);// - 135);
var mirrorXOnNormalImage = parseInt(maskCanvasContext.canvas.offsetLeft) + parseInt(distanceXOnMirrorImage);
var actulalX = mirrorXOnNormalImage
var actualY = mousePos.y + verticalScrollPosition
var pixelData = maskCanvasContext.getImageData(Math.round(actulalX - parseInt(maskCanvasContext.canvas.offsetLeft)), Math.round(actualY - y), 1, 1);
pixelData.data[0] = pixelData.data[0] - 9;
pixelData.data[1] = pixelData.data[1] - 9;
pixelData.data[2] = pixelData.data[2] - 9
var Red;
var Green;
var Blue;
var zero = "0";
if ((pixelData.data[0]).toString().length != 2) {
Red = zero.concat((pixelData.data[0]).toString())
}
else {
Red = (pixelData.data[0]).toString()
}
if ((pixelData.data[1]).toString().length != 2) {
Green = zero.concat((pixelData.data[1]).toString())
}
else {
Green = (pixelData.data[1]).toString()
}
if ((pixelData.data[2]).toString().length != 2) {
Blue = zero.concat((pixelData.data[2]).toString())
}
else {
Blue = (pixelData.data[2]).toString()
}
var RGBColor = (Red + Green + Blue);
if ($rootScope.isHighLight) {
if ($scope.machedIcolorInBodyRegion != null || $scope.machedIcolorInBodyRegion != undefined) {
if ($scope.machedIcolorInBodyRegion.length > 0) {
if ($rootScope.multiAnnotationIsON == false) {
for (var i = 0; i < $scope.machedIcolorInBodyRegion.length; i++) {
var bodyRegionId = $scope.machedIcolorInBodyRegion[i];
var grayCanvasID = 'imageCanvas' + bodyRegionId;
var grayCanvas = document.getElementById(grayCanvasID);
var grayCanvasContext = grayCanvas.getContext("2d");
if ($rootScope.grayImageDataList[bodyRegionId - 1] != null || $rootScope.grayImageDataList[bodyRegionId - 1] != undefined) {
var grayImageData = $rootScope.grayImageDataList[bodyRegionId - 1];
grayCanvasContext.putImageData(grayImageData, 0, 0);
}
// for mirrored canvas
if (bodyRegionId == 4 || bodyRegionId == 5 || bodyRegionId == 6) {
var grayCanvasID = 'imageCanvas' + bodyRegionId + '_MR';
var grayCanvasMR = document.getElementById(grayCanvasID);
var grayCanvasContextMR = grayCanvasMR.getContext("2d");
if ($rootScope.grayImageMRDataList[bodyRegionId] != null || grayImageMRDataList[bodyRegionId] != undefined) {
var grayImageDataMR = $rootScope.grayImageMRDataList[bodyRegionId];
grayCanvasContextMR.putImageData(grayImageDataMR, 0, 0);
}
}
}
}
}
}
$rootScope.previousHighlightList.push(RGBColor);
$scope.highLightBodyBasedOnIcolor(RGBColor);
}
if ($rootScope.isNormalMode == true) {
$rootScope.previousHighlightList.push(RGBColor);
}
var annotationText = $scope.GetAnnotationText(parseInt(RGBColor));
if ($('#speechBubbleTrns').length > 0)
$('#speechBubbleTrns').remove();
if ($rootScope.multiAnnotationIsON == true) {
// $scope.createDynamicSpeechBubble(evt, annotationText, evt.pageX + horizontlScrollPosition - $('#canvasDiv').offset().left, evt.pageY + verticalScrollPosition - $('#canvasDiv').offset().top);
$scope.MultiLanguageAnnationArray = [];
$scope.MultiLanguageAnnationArray.push(annotationText);
$scope.createDynamicSpeechBubble(evt, evt.pageX + horizontlScrollPosition - $('#canvasDiv').offset().left, evt.pageY + verticalScrollPosition - $('#canvasDiv').offset().top, true);
}
else {
if ($('#dot').length > 0) {
$('#dot').remove();
}
if ($('#sppeachBubble').length > 0) {
$('#sppeachBubble').remove();
// $scope.createDynamicSpeechBubble(evt, annotationText, evt.pageX + horizontlScrollPosition - $('#canvasDiv').offset().left, evt.pageY + verticalScrollPosition - $('#canvasDiv').offset().top);
$scope.MultiLanguageAnnationArray = [];
$scope.MultiLanguageAnnationArray.push(annotationText);
$scope.createDynamicSpeechBubble(evt, evt.pageX + horizontlScrollPosition - $('#canvasDiv').offset().left, evt.pageY + verticalScrollPosition - $('#canvasDiv').offset().top, true);
}
else {
// $scope.createDynamicSpeechBubble(evt, annotationText, evt.pageX + horizontlScrollPosition - $('#canvasDiv').offset().left, evt.pageY + verticalScrollPosition - $('#canvasDiv').offset().top);
$scope.MultiLanguageAnnationArray = [];
$scope.MultiLanguageAnnationArray.push(annotationText);
$scope.createDynamicSpeechBubble(evt, evt.pageX + horizontlScrollPosition - $('#canvasDiv').offset().left, evt.pageY + verticalScrollPosition - $('#canvasDiv').offset().top, true);
}
}
}, false);
FlipedImgCanvas.addEventListener('mousedown', function (evt) {
//alert('mousedown')
}, false);
FlipedImgCanvas.addEventListener('mouseup', function (evt) {
//alert('mouseup')
}, false);
var context = FlipedImgCanvas.getContext("2d");
var PI = Math.PI;
var PI2 = PI * 2;
var cw, ch, imgW, imgH, mouseX, mouseY;
var scaleFactor = 1.00;
//$scaler = $("#scaler");
//$scaler.val(scaleFactor);
//$scaler.hide();
var img = new Image();
img.onload = start;
// img.src = "~/../content/images/" + src;;
img.src = src;
function start() {
context.save();
context.translate(w, 0);
context.scale(-1, 1);
context.drawImage(img, 0, 0);
context.restore();
if (isMaskImage == 'N') {
$scope.ColoredImageSRC.push(
{
"bodyRegionId": bodyRegionId, "SRC": src,
"Height": h,
"Width": w,
"x": x,
"y": y,
"haveMirror": 'true'
}
);
// console.log('$rootScope.isListManagerSelected= ' + $rootScope.isListManagerSelected + ' length= ' + $scope.ColoredImageSRC.length)
if (($scope.ColoredImageSRC != null || $scope.ColoredImageSRC != undefined)) {
if ((($rootScope.viewOrientationId == '1') || ($rootScope.viewOrientationId == '4')) && ($scope.ColoredImageSRC.length == 9)) {
$scope.isEligibleForHighlight = true;
}
else if ((($rootScope.viewOrientationId == '2') || ($rootScope.viewOrientationId == '3')) && ($scope.ColoredImageSRC.length == 5)) {
$scope.isEligibleForHighlight = true;
}
else if (($rootScope.viewOrientationId == '5') && ($scope.ColoredImageSRC.length == 4)) {
$scope.isEligibleForHighlight = true;
}
else if (($rootScope.viewOrientationId == '6') && ($scope.ColoredImageSRC.length == 1)) {
$scope.isEligibleForHighlight = true;
}
else {
$scope.isEligibleForHighlight = false;
}
if ($scope.isEligibleForHighlight == true) {
if ($rootScope.isHighLight == true || ($rootScope.isListManagerSelected == true) || (($rootScope.isGenderChnage == true) && ($rootScope.isHighLight == true)) || (($rootScope.isViewChange == true) && ($rootScope.isHighLight == true))) {
$rootScope.isLoading = false;
$('#spinner').css('visibility', 'hidden');
$rootScope.isLoading = true;
$('#spinner').css('visibility', 'visible');
//$timeout(function () {
console.log('inside start of flipped. $scope.ColoredImageSRC.length= ' + $scope.ColoredImageSRC.length)
$rootScope.isHighLight = true;
console.log('just before highLightBody call');
$scope.highLightBody();
console.log('just after highLightBody call');
//}, 500);
}
}
}
// console.log('ColoredImageSRC. pushed and length: ' + $scope.ColoredImageSRC.length);
}
if (FlipedImgCanvas.id.match('_mci')) {
var maskImgData = context.getImageData(0, 0, w, h);
$rootScope.MaskCanvasData.push(
{
"bodyRegionId": bodyRegionId,
"canvasId": FlipedImgCanvas.id,
"maskData": maskImgData,
}
);
}
};
if (document.getElementById('canvasDiv') != null)
document.getElementById('canvasDiv').appendChild(FlipedImgCanvas);
}
$scope.DrawImage = function (h, w, x, y, src, bodyRegionId, isMaskImage) {
var imgCanvas = document.createElement('canvas');
imgCanvas.height = h;
imgCanvas.width = w;
imgCanvas.setAttribute("data-IsMirrored", "N")
imgCanvas.style.position = "absolute";
imgCanvas.style.left = x + "px";
imgCanvas.style.top = y + "px";
if (isMaskImage == 'Y') {
imgCanvas.style.visibility = 'hidden'
imgCanvas.id = 'imageCanvas' + bodyRegionId + '_mci';
}
else {
imgCanvas.id = 'imageCanvas' + bodyRegionId;
if (bodyRegionId == 3) {
//set z index of hip canavs to fix the issue caused by overlapping of arm canavs on hip canavs.
imgCanvas.style.zIndex = "100";
}
if (bodyRegionId.match('modestyImg')) {
//added class to further access this canavs to show and hide leaf as per modesty seting
imgCanvas.className = 'modestyImg'
imgCanvas.style.visibility = 'hidden'
//set z index to make leaf canvas on top of hip canavs
imgCanvas.style.zIndex = "200";
}
if (($rootScope.voId == 11 || $rootScope.voId == 9) && bodyRegionId == 6) {
imgCanvas.style.zIndex = "500";
}
if ($rootScope.isExtract == true) {
imgCanvas.style.visibility = 'visible'
}
else {
if ($rootScope.isHighLight == true && $rootScope.isZoomed == false) {
imgCanvas.style.visibility = 'hidden';
}
}
}
imgCanvas.addEventListener('click', function (evt) {
if ($scope.isLayerChange == true) {
$scope.isLayerChange = false;
}
if (evt.ctrlKey) {
$rootScope.multiAnnotationIsON = true;
}
else {
if (($rootScope.previousHighlightList != null || $rootScope.previousHighlightList != undefined) && ($rootScope.previousHighlightList.length > 0)) {
$rootScope.previousHighlightList = [];
}
$rootScope.multiAnnotationIsON = false;
}
var annotationText;
var context = imgCanvas.getContext("2d");
var canvasId = context.canvas.getAttribute('id');
var maskCanvasId;
//for leaf canvas
if (canvasId.match('modestyImg')) {
maskCanvasId = canvasId;
}
else {
maskCanvasId = canvasId + '_mci';
}
var maskCanvas = document.getElementById(maskCanvasId);
var maskCanvasContext = maskCanvas.getContext("2d");
var mousePos = $scope.getMousePos(evt);
// alert(mousePos.x + ',' + mousePos.y);
var canvasDiv = document.getElementById('canvasDiv');
var verticalScrollPosition = canvasDiv.scrollTop;
var horizontlScrollPosition = canvasDiv.scrollLeft;
//We substracted 135, as the difference between flex and html coordinates for same organ is 135
var actulalX = mousePos.x + horizontlScrollPosition;
var actualY = mousePos.y + verticalScrollPosition;
var RGBColor = $scope.GetRGBColor(maskCanvasContext, actulalX, actualY, x, y);
//Modesty ON
if (maskCanvasId.match('modestyImg') && RGBColor != '000000') {
RGBColor = DA[0].figLeafTermId;
annotationText = $scope.GetAnnotationBasedOnActualTermNo(RGBColor);
}
//Modesty On but clicked somewhre else, we did modesty check because the modesty image covers whole body region so if user will click to
//see the annotation apart from leaf then the actual click will be on modesty canvas, but for annotation er
//
else if (maskCanvasId.match('modestyImg') && RGBColor == '000000') {
//if ($rootScope.voId == 11) {
// maskCanvasId = 'imageCanvas6_mci';
// x = $('#imageCanvas6_mci').left;
// y = $('#imageCanvas6_mci').top;
//}
//else {
bodyRegionId = maskCanvasId.slice(-1);
maskCanvasId = 'imageCanvas' + bodyRegionId + '_mci';
// }
var maskCanvas = document.getElementById(maskCanvasId);
var maskCanvasContext = maskCanvas.getContext("2d");
RGBColor = $scope.GetRGBColor(maskCanvasContext, actulalX, actualY, x, y);
annotationText = $scope.GetAnnotationText(parseInt(RGBColor));
}
else {
RGBColor = $scope.GetRGBColor(maskCanvasContext, actulalX, actualY, x, y);
annotationText = $scope.GetAnnotationText(parseInt(RGBColor));
}
if ($rootScope.isHighLight == true) {
if ($scope.machedIcolorInBodyRegion != null || $scope.machedIcolorInBodyRegion != undefined) {
if ($scope.machedIcolorInBodyRegion.length > 0) {
if ($rootScope.multiAnnotationIsON == false) {
for (var i = 0; i < $scope.machedIcolorInBodyRegion.length; i++) {
var bodyRegionId = $scope.machedIcolorInBodyRegion[i];
var grayCanvasID = 'imageCanvas' + bodyRegionId;
var grayCanvas = document.getElementById(grayCanvasID);
var grayCanvasContext = grayCanvas.getContext("2d");
if ($rootScope.grayImageDataList[bodyRegionId - 1] != null || $rootScope.grayImageDataList[bodyRegionId - 1] != undefined) {
var grayImageData = $rootScope.grayImageDataList[bodyRegionId - 1];
grayCanvasContext.putImageData(grayImageData, 0, 0);
}
// for unhighlight the mirrored body region
if (bodyRegionId == 4 || bodyRegionId == 5 || bodyRegionId == 6) {
var grayCanvasID = 'imageCanvas' + bodyRegionId + '_MR';
var grayCanvasMR = document.getElementById(grayCanvasID);
var grayCanvasContextMR = grayCanvasMR.getContext("2d");
if ($rootScope.grayImageMRDataList[bodyRegionId] != null || $rootScope.grayImageMRDataList[bodyRegionId] != undefined) {
var grayImageDataMR = $rootScope.grayImageMRDataList[bodyRegionId];
grayCanvasContextMR.putImageData(grayImageDataMR, 0, 0);
}
}
}
}
}
}
$rootScope.previousHighlightList.push(RGBColor);
if (maskCanvasId.match('modestyImg') && RGBColor != '000000') { }
else
{
$scope.highLightBodyBasedOnIcolor(RGBColor);
}
}
if ($rootScope.isNormalMode == true) {
$rootScope.previousHighlightList.push(RGBColor);
}
if ($('#speechBubbleTrns').length > 0)
$('#speechBubbleTrns').remove();
if ($rootScope.multiAnnotationIsON == true) {
// $scope.createDynamicSpeechBubble(evt, annotationText, evt.pageX + horizontlScrollPosition - $('#canvasDiv').offset().left, evt.pageY + verticalScrollPosition - $('#canvasDiv').offset().top);
$scope.MultiLanguageAnnationArray = [];
$scope.MultiLanguageAnnationArray.push(annotationText);
$scope.createDynamicSpeechBubble(evt, evt.pageX + horizontlScrollPosition - $('#canvasDiv').offset().left, evt.pageY + verticalScrollPosition - $('#canvasDiv').offset().top, true);
}
else {
$scope.MultiLanguageAnnationArray = [];
console.log('1. annotationText: ' + annotationText);
if ($('#dot').length > 0) {
$('#dot').remove();
if ($('#sppeachBubble').length > 0) {
$('#sppeachBubble').remove();
}
// $scope.createDynamicSpeechBubble(evt, annotationText, evt.pageX + horizontlScrollPosition - $('#canvasDiv').offset().left, evt.pageY + verticalScrollPosition - $('#canvasDiv').offset().top);
$scope.MultiLanguageAnnationArray.push(annotationText);
console.log('2. annotationText: ' + annotationText + ' , length: ' + $scope.MultiLanguageAnnationArray.length);
$scope.createDynamicSpeechBubble(evt, evt.pageX + horizontlScrollPosition - $('#canvasDiv').offset().left, evt.pageY + verticalScrollPosition - $('#canvasDiv').offset().top, true);
}
else {
$scope.MultiLanguageAnnationArray = [];
$scope.MultiLanguageAnnationArray.push(annotationText);
console.log('3. annotationText: ' + annotationText + ' , length: ' + $scope.MultiLanguageAnnationArray.length);
$scope.createDynamicSpeechBubble(evt, evt.pageX + horizontlScrollPosition - $('#canvasDiv').offset().left, evt.pageY + verticalScrollPosition - $('#canvasDiv').offset().top, true);
}
}
}, false);
var PI = Math.PI;
var PI2 = PI * 2;
var cw, ch, imgW, imgH, mouseX, mouseY;
var scaleFactor = 1.00;
var context = imgCanvas.getContext('2d');
var img = new Image();
img.onload = start;
img.src = src;
function start() {
//debugger;
context.drawImage(img, 0, 0);
if (isMaskImage == 'N') {
if (bodyRegionId == 'modestyImg3' || bodyRegionId == 'modestyImg2') {
//do nothing
}
else {
$scope.ColoredImageSRC.push(
{
"bodyRegionId": bodyRegionId, "SRC": src,
"Height": h,
"Width": w,
"x": x,
"y": y,
"haveMirror": 'false'
}
);
if (($scope.ColoredImageSRC != null || $scope.ColoredImageSRC != undefined)) {
if ((($rootScope.viewOrientationId == '1') || ($rootScope.viewOrientationId == '4')) && ($scope.ColoredImageSRC.length == 9)) {
$scope.isEligibleForHighlight = true;
}
else if ((($rootScope.viewOrientationId == '2') || ($rootScope.viewOrientationId == '3')) && ($scope.ColoredImageSRC.length == 5)) {
$scope.isEligibleForHighlight = true;
}
else if (($rootScope.viewOrientationId == '5') && ($scope.ColoredImageSRC.length == 4)) {
$scope.isEligibleForHighlight = true;
}
else if (($rootScope.viewOrientationId == '6') && ($scope.ColoredImageSRC.length == 1)) {
$scope.isEligibleForHighlight = true;
}
else {
$scope.isEligibleForHighlight = false;
}
if ($scope.isEligibleForHighlight == true) {
if ($rootScope.isHighLight == true || ($rootScope.isListManagerSelected == true) || (($rootScope.isGenderChnage == true) && ($rootScope.isHighLight == true)) || (($rootScope.isViewChange == true) && ($rootScope.isHighLight == true))) {
$rootScope.isLoading = false;
$('#spinner').css('visibility', 'hidden');
$rootScope.isLoading = true;
$('#spinner').css('visibility', 'visible');
//$timeout(function () {
console.log('inside start of non flipped. $scope.ColoredImageSRC.length= ' + $scope.ColoredImageSRC.length)
$rootScope.isHighLight = true;
console.log('just before highLightBody call');
$scope.highLightBody();
console.log('just after highLightBody call');
//}, 500);
}
}
}
console.log('ColoredImageSRC. pushed and length: ' + $scope.ColoredImageSRC.length);
}
}
if (imgCanvas.id.match('_mci')) {
var maskImgData = context.getImageData(0, 0, w, h);
$rootScope.MaskCanvasData.push(
{
"bodyRegionId": bodyRegionId,
"canvasId": imgCanvas.id,
"maskData": maskImgData,
}
);
}
};
if (document.getElementById('canvasDiv') != null)
document.getElementById('canvasDiv').appendChild(imgCanvas);
}
$scope.highLightBodyBasedOnIcolor = function (RGBColor) {
//2. Find Actul Term No Based on Icolor.
var ActualTermNo = $scope.getActualTermNumber(RGBColor);
if (ActualTermNo != null) {
//3. Find Term No List Based on ActualTermNo
var TermList = $scope.getTermNumberList(ActualTermNo);
if (TermList != null) {
//4.
$scope.HighlightBodyByTermList(TermList);
}
}
}
$scope.HighlightBodyOnExtract = function () {
var multiTermList = [];
var CallBackBodyRegion = [];
if (($rootScope.previousHighlightList != null || $rootScope.previousHighlightList != undefined) && ($rootScope.previousHighlightList.length > 0)) {
angular.forEach($rootScope.previousHighlightList, function (value, key) {
var ActualTermNo = $scope.getActualTermNumber(value);
if (ActualTermNo != null) {
var TermList = $scope.getTermNumberList(ActualTermNo);
if (TermList != null) {
for (var i = 0; i < TermList.length; i++) {
multiTermList.push(TermList[i]);
}
}
}
// to do
});
}
//2. Find Actul Term No Based on Icolor.
//var ActualTermNo = $scope.getActualTermNumber(RGBColor);
////3. Find Term No List Based on ActualTermNo
//var TermList = $scope.getTermNumberList(ActualTermNo);
//terminate previous running workers to create space for new workers
$scope.terminateCurrentlyRunningWPs();
$timeout(function () {
var loopLength = 0;
if ((($rootScope.viewOrientationId == '1') || ($rootScope.viewOrientationId == '4')) && ($scope.ColoredImageSRC.length == 9)) {
loopLength = 9;
}
else if ((($rootScope.viewOrientationId == '2') || ($rootScope.viewOrientationId == '3')) && ($scope.ColoredImageSRC.length == 5)) {
loopLength = 5;
}
else if (($rootScope.viewOrientationId == '5') && ($scope.ColoredImageSRC.length == 4)) {
loopLength = 4;
}
else if (($rootScope.viewOrientationId == '6') && ($scope.ColoredImageSRC.length == 1)) {
loopLength = 1;
}
if (loopLength !== 0) {
for (var x = 0; x < loopLength; x++) {
if ($rootScope.MaskCanvasData[x] != null || $rootScope.MaskCanvasData[x] != undefined) {
var bodyRegionId = $rootScope.MaskCanvasData[x].bodyRegionId;
var canvasId = $rootScope.MaskCanvasData[x].canvasId;
var maskData = null;
maskData = $rootScope.MaskCanvasData[x].maskData;
var coloredImageDataVar = null;
var grayImageDataVar = null;
var white = null;
if (canvasId.match('_MR')) {
if ($rootScope.coloredImageMRCanvasList[bodyRegionId] != null || $rootScope.coloredImageMRCanvasList[bodyRegionId] != undefined) {
coloredImageDataVar = $rootScope.coloredImageMRCanvasList[bodyRegionId];
}
if ($rootScope.whiteImageMRDataList[bodyRegionId] != null || $rootScope.whiteImageMRDataList[bodyRegionId] != undefined) {
white = $rootScope.whiteImageMRDataList[bodyRegionId];
}
}
else {
if ($rootScope.coloredImageCanvasList[bodyRegionId - 1] != null || $rootScope.coloredImageCanvasList[bodyRegionId - 1] != undefined) {
coloredImageDataVar = $rootScope.coloredImageCanvasList[bodyRegionId - 1];
}
if ($rootScope.whiteImageDataList[bodyRegionId - 1] != null || $rootScope.whiteImageDataList[bodyRegionId - 1] != undefined) {
white = $rootScope.whiteImageDataList[bodyRegionId - 1];
}
}
var worker = new Worker('extract-wp.js');
//push workers in array to further used the refernece to delete the workers
$scope.runningWorkers.push({ 'workerName': worker })
console.log('for BRID = ' + bodyRegionId + ', coloredImageDataVar: ' + coloredImageDataVar + ', maskData= ' + maskData + ', white= ' + white)
if (coloredImageDataVar != null && maskData != null && white != null) {
worker.postMessage({
'termList': multiTermList,
'maskCanvasData': maskData,
'coloredImageData': coloredImageDataVar,
'grayImageData': white,
'bodyRegionId': bodyRegionId,
'canvasId': canvasId
});
}
//}
worker.onmessage = function (e) {
console.log('callback in extract for e.data.bodyRegionId: ' + e.data.bodyRegionId + ', time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"));
var updatedData = e.data.value;
var bodyRegionId = e.data.bodyRegionId;
var canvasId = (e.data.canvasId).replace('_mci', '');
//debugger;
//for (var i = 1; i <= updatedData.length; i++) {
var grayCanvasID = canvasId;
// var grayCanvasID = 'imageCanvas' + bodyRegionId;
var grayCanvas = document.getElementById(grayCanvasID);
var grayCanvasContext = grayCanvas.getContext("2d");
grayCanvasContext.putImageData(updatedData, 0, 0);
//to resolve lateral arm black issue in highlight mode
if ($rootScope.viewOrientationId == 5 && (bodyRegionId == 6 || bodyRegionId == 4)) {
var canavsWidth = parseInt(grayCanvas.width);
var canavsHeight = parseInt(grayCanvas.height);
console.log('canavsWidth= ' + canavsWidth + ', canavsHeight= ' + canavsHeight)
var imgData = grayCanvasContext.getImageData(0, 0, canavsWidth, canavsHeight);
var data = imgData.data;
var c = 0;
for (var i = 0; i < data.length; i += 4) {
if (data[i] == data[i + 1] && data[i + 1] == data[i + 2] && data[i + 2] === 0) {
data[i + 3] = 0;
}
}
grayCanvasContext.putImageData(imgData, 0, 0);
}
if ($rootScope.multiAnnotationIsON == true) {
//debugger;
if (canvasId.match('_MR'))
$rootScope.updatedWhiteImageMRDataList[bodyRegionId] = updatedData;
else
$rootScope.updatedWhiteImageDataList[bodyRegionId - 1] = updatedData;
}
else {
if (canvasId.match('_MR'))
$rootScope.whiteImageMRDataList[bodyRegionId] = e.data.value;
else {
if ($rootScope.whiteImageDataList[bodyRegionId - 1] != null || $rootScope.whiteImageDataList[bodyRegionId - 1] != undefined)
$rootScope.whiteImageDataList[bodyRegionId - 1] = e.data.value;
}
}
//if ((CallBackBodyRegion != null || CallBackBodyRegion[i] != undefined) && (CallBackBodyRegion.length > 0)) {
// if (CallBackBodyRegion.length == 6) {
// $rootScope.isLoading = false;
// $('#spinner').css('visibility', 'hidden');
// }
//}
$timeout(function () { $scope.DisableProgressBar() }, 1000);
};
worker.onerror = function (e) {
alert('Error: Line ' + e.lineno + ' in ' + e.filename + ': ' + e.message);
};
}
}
}
}, 50)
}
$scope.HighlightBodyByTermList = function (TermList) {
//if (($rootScope.updatedGrayMRDataList != null || $rootScope.updatedGrayMRDataList != undefined) && $rootScope.updatedGrayMRDataList.length > 0) {
// $rootScope.updatedGrayMRDataList = null;
// $rootScope.updatedGrayMRDataList = [];
//}
//if (($rootScope.updatedGrayDataList != null || $rootScope.updatedGrayDataList != undefined) && $rootScope.updatedGrayDataList.length > 0) {
// $rootScope.updatedGrayDataList = null;
// $rootScope.updatedGrayDataList = [];
//}
console.log('HighlightBodyByTermList is called');
// $scope.highlightedBR = null;
$scope.highlightedBR = [];
$scope.terminateCurrentlyRunningWPs();
$timeout(function () {
var loopLength = 0;
if ((($rootScope.viewOrientationId == '1') || ($rootScope.viewOrientationId == '4')) && ($scope.ColoredImageSRC.length == 9)) {
loopLength = 9;
}
else if ((($rootScope.viewOrientationId == '2') || ($rootScope.viewOrientationId == '3')) && ($scope.ColoredImageSRC.length == 5)) {
loopLength = 5;
}
else if (($rootScope.viewOrientationId == '5') && ($scope.ColoredImageSRC.length == 4)) {
loopLength = 4;
}
else if (($rootScope.viewOrientationId == '6') && ($scope.ColoredImageSRC.length == 1)) {
loopLength = 1;
}
for (var x = 0; x < loopLength; x++) {
if ($rootScope.MaskCanvasData[x] != null || $rootScope.MaskCanvasData[x] != undefined) {
var bodyRegionId = $rootScope.MaskCanvasData[x].bodyRegionId;
var canvasId = $rootScope.MaskCanvasData[x].canvasId;
var maskData = null;
maskData = $rootScope.MaskCanvasData[x].maskData;
var coloredImageDataVar = null;
var grayImageDataVar = null;
var white;
if (canvasId.match('_MR')) {
if ($rootScope.coloredImageMRCanvasList[bodyRegionId] != null || $rootScope.coloredImageMRCanvasList[bodyRegionId] != undefined) {
coloredImageDataVar = $rootScope.coloredImageMRCanvasList[bodyRegionId];
}
if ($rootScope.multiAnnotationIsON == true) {
//on layer change we need the fresh data not the updated one
if ($scope.isLayerChange == true) {
if ($rootScope.grayImageMRDataList[bodyRegionId] != null || $rootScope.grayImageMRDataList[bodyRegionId] != undefined) {
grayImageDataVar = $rootScope.grayImageMRDataList[bodyRegionId];
}
}
else {
if ($rootScope.updatedGrayDataList[bodyRegionId - 1] == null || $rootScope.updatedGrayDataList[bodyRegionId - 1] == undefined) {
if ($rootScope.grayImageMRDataList[bodyRegionId] != null || $rootScope.grayImageMRDataList[bodyRegionId] != undefined) {
grayImageDataVar = $rootScope.grayImageMRDataList[bodyRegionId];
}
}
else {
if ($rootScope.updatedGrayMRDataList[bodyRegionId] != null || $rootScope.updatedGrayMRDataList[bodyRegionId] != undefined) {
grayImageDataVar = $rootScope.updatedGrayMRDataList[bodyRegionId]
}
}
}
}
else {
if ($rootScope.grayImageMRDataList[bodyRegionId] != null || $rootScope.grayImageMRDataList[bodyRegionId] != undefined) {
grayImageDataVar = $rootScope.grayImageMRDataList[bodyRegionId];
}
}
}
else {
if ($rootScope.coloredImageCanvasList[bodyRegionId - 1] != null || $rootScope.coloredImageCanvasList[bodyRegionId - 1] != undefined) {
coloredImageDataVar = $rootScope.coloredImageCanvasList[bodyRegionId - 1];
}
if ($rootScope.multiAnnotationIsON == true) {
//on layer change we need the fresh data not the updated one
if ($scope.isLayerChange == true) {
if ($rootScope.grayImageDataList[bodyRegionId - 1] != null || $rootScope.grayImageDataList[bodyRegionId - 1] != undefined) {
grayImageDataVar = $rootScope.grayImageDataList[bodyRegionId - 1];
}
} else {
// this code is for the case where user first click on normal mode then extract then again highlight then we need to call highlight body in gray mode
//and then highlight the previously selected body regions at the time of normal mode.
if ($rootScope.updatedGrayDataList[bodyRegionId - 1] == null || $rootScope.updatedGrayDataList[bodyRegionId - 1] == undefined) {
if ($rootScope.grayImageDataList[bodyRegionId - 1] != null || $rootScope.grayImageDataList[bodyRegionId - 1] != undefined) {
grayImageDataVar = $rootScope.grayImageDataList[bodyRegionId - 1];
}
}
else {
if ($rootScope.updatedGrayDataList[bodyRegionId - 1] != null || $rootScope.updatedGrayDataList[bodyRegionId - 1] != undefined) {
// for normal case means without interdepency button case.
grayImageDataVar = $rootScope.updatedGrayDataList[bodyRegionId - 1];
}
}
}
}
else
if ($rootScope.grayImageDataList[bodyRegionId - 1] != null || $rootScope.grayImageDataList[bodyRegionId - 1] != undefined) {
grayImageDataVar = $rootScope.grayImageDataList[bodyRegionId - 1];
}
}
var worker = new Worker('term-number-wp.js');
//push workers in array to further used the refernece to delete the workers
$scope.runningWorkers.push({ 'workerName': worker })
// console.log('for bodyRegionId = ' + bodyRegionId+ ', time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"))
console.log('before worker call BRID: ' + bodyRegionId)
if (grayImageDataVar != null && coloredImageDataVar != null && maskData != null) {
worker.postMessage({
'termList': TermList,
'maskCanvasData': maskData,
'coloredImageData': coloredImageDataVar,
'grayImageData': grayImageDataVar,
'bodyRegionId': bodyRegionId,
'canvasId': canvasId
});
}
worker.onmessage = function (e) {
console.log('callback for e.data.bodyRegionId: ' + e.data.bodyRegionId + ', time: ' + new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1"));
var updatedData = e.data.value;
var bodyRegionId = e.data.bodyRegionId;
var canvasId = (e.data.canvasId).replace('_mci', '');
//debugger;
//for (var i = 1; i <= updatedData.length; i++) {
var grayCanvasID = canvasId;
//to do
var grayCanvas = document.getElementById(grayCanvasID);
if (grayCanvas != null) {
var grayCanvasContext = grayCanvas.getContext("2d");
//Niki remove previous data from canvas
var canvasHeight = grayCanvas.height + 'px';
var canvasWidth = grayCanvas.width + 'px';
//alert('height= ' + canvasHeight + ', width= ' + canvasWidth)
grayCanvasContext.clearRect(0, 0, canvasHeight, canvasWidth)
grayCanvasContext.putImageData(updatedData, 0, 0);
$scope.highlightedBR.push({ 'bodyRegionId': bodyRegionId });
}
//debugger;
if (canvasId.match('_MR')) {
$rootScope.updatedGrayMRDataList[bodyRegionId] = updatedData;
//alert('HighlightBodyByTermList, is mutiAnnotation on= ' + $rootScope.multiAnnotationIsON);
//$rootScope.updatedWhiteImageMRDataList[bodyRegionId] = updatedData;
}
else
$rootScope.updatedGrayDataList[bodyRegionId - 1] = updatedData;
//$scope.highlightedBR.push({ 'bodyRegionId': bodyRegionId });
console.log('$scope.highlightedBR.length= ' + $scope.highlightedBR.length)
if ($scope.highlightedBR != null || $scope.highlightedBR != undefined) {
if ((($rootScope.viewOrientationId == '1') || ($rootScope.viewOrientationId == '4')) && ($scope.highlightedBR.length == 9)) {
$scope.doAligneCanvasWithTerm = true;
}
else if ((($rootScope.viewOrientationId == '2') || ($rootScope.viewOrientationId == '3')) && ($scope.highlightedBR.length == 5)) {
$scope.doAligneCanvasWithTerm = true;
}
else if ((($rootScope.viewOrientationId == '5')) && ($scope.highlightedBR.length == 4)) {
$scope.doAligneCanvasWithTerm = true;
}
else if ((($rootScope.viewOrientationId == '6')) && ($scope.highlightedBR.length == 1)) {
$scope.doAligneCanvasWithTerm = true;
}
if ($scope.doAligneCanvasWithTerm == true) {
//debugger;
if ($scope.isHighlightBodyByBodySystem == true || $rootScope.isListManagerSelected == true)
$rootScope.isLoading = false;
$('#spinner').css('visibility', 'hidden');
$scope.isHighlightBodyByBodySystem = false;
if ($rootScope.isListManagerSelected == true)
$scope.aligneCanvasWithTerm();
}
}
//
};
worker.onerror = function (e) {
alert('Error: Line ' + e.lineno + ' in ' + e.filename + ': ' + e.message);
};
}
}
}, 100)
}
$scope.createTermListByPreviousTermsAndHighlight = function () {
var multiTermList = [];
angular.forEach($rootScope.previousHighlightList, function (value, key) {
//debugger;
var ActualTermNo = $scope.getActualTermNumber(value);
if (ActualTermNo != null) {
var TermList = $scope.getTermNumberList(ActualTermNo);
if (TermList != null) {
for (var i = 0; i < TermList.length; i++) {
multiTermList.push(TermList[i]);
}
}
}
});
console.log('createTermListByPreviousTermsAndHighlight is called');
if ((multiTermList != undefined || multiTermList != null) && multiTermList.length > 0) {
$timeout(function () { $scope.HighlightBodyByTermList(multiTermList); }, 50);
}
}
$scope.GetRGBColor = function (maskCanvasContext, actulalX, actualY, x, y) {
var pixelData = maskCanvasContext.getImageData(Math.round(actulalX - x), Math.round(actualY - y), 1, 1);
pixelData.data[0] = pixelData.data[0] - 9;
pixelData.data[1] = pixelData.data[1] - 9;
pixelData.data[2] = pixelData.data[2] - 9;
var Red;
var Green;
var Blue;
var zero = "0";
if ((pixelData.data[0]).toString().length != 2) {
Red = zero.concat((pixelData.data[0]).toString())
}
else {
Red = (pixelData.data[0]).toString()
}
if ((pixelData.data[1]).toString().length != 2) {
Green = zero.concat((pixelData.data[1]).toString())
}
else {
Green = (pixelData.data[1]).toString()
}
if ((pixelData.data[2]).toString().length != 2) {
Blue = zero.concat((pixelData.data[2]).toString())
}
else {
Blue = (pixelData.data[2]).toString()
}
var RGBColor = (Red + Green + Blue);
return RGBColor;
}
//get annotation from term number
$scope.GetAnnotationText = function (termNumber) {
//debugger;
var annotationText;
//0
var figLeafTermNo = 5868; // to do declare constant for this
if (parseInt(termNumber) != parseInt(figLeafTermNo)) {
$scope.TermNumber = termNumber;
if ($rootScope.TermNumberData != null || $rootScope.TermNumberData != undefined) {
$scope.matchedTermNoData = new jinqJs()
.from($rootScope.TermNumberData.TermData.Term)
.where('_TermNumber == ' + termNumber)
.select();
if ($scope.matchedTermNoData != null || $scope.matchedTermNoData != undefined) {
//1.
var actualTermNo = 0;
for (var z = 0; z < $scope.matchedTermNoData.length; z++) {
//send actual term no to get the term text.
actualTermNo = $scope.matchedTermNoData[0]._ActualTermNumber;
annotationText = $scope.GetAnnotationBasedOnActualTermNo(actualTermNo);
break;
};
//2.
}
else {
// send term no to vocab json data to get the text
}
}
}
return annotationText;
}
$scope.GetAnnotationBasedOnActualTermNo = function (actualTermNo) {
// debugger;
var Annotation;
$scope.ActualTermNo = actualTermNo;
if ($rootScope.VocabTermData != null || $rootScope.VocabTermData != undefined) {
$scope.matchedActualTermData = new jinqJs()
.from($rootScope.VocabTermData.VocabTerms.Term)
.where('_ActualTermNumber == ' + actualTermNo)
.select();
if ($scope.matchedActualTermData != null || $scope.matchedActualTermData != undefined) {
for (var z = 0; z <= $scope.matchedActualTermData.length; z++) {
//send actual term no to get the term text.
Annotation = $scope.matchedActualTermData[0]._TermText;
// alert("Annotation : " + Annotation);
break;
};
}
return Annotation;
}
else {
return null;
}
}
//layer change function
$scope.LayerChange = function () {
//if listanager is visisble then close it
$rootScope.isListManagerSelected = false;
$rootScope.CloseListManager();
$scope.isLayerChange = true;
$rootScope.isLoading = true;
$('#spinner').css('visibility', 'visible');
//1.
$scope.terminateCurrentlyRunningWPs();
var canvasDiv = document.getElementById('canvasDiv');
$scope.imageVerticalScrollPosition = canvasDiv.scrollTop;
$scope.imageHorizontlScrollPosition = canvasDiv.scrollLeft;
// debugger;
// $('#daLoaderLabel').css('visibility', 'visible');
if ($scope.isTransparencyActivated) {
//crete temp canavs to store the original data which will be used to chnange the transparency
if (document.getElementById('tempCanvas') != null) {
$('#tempCanvas').remove();
}
if ($('#speechBubbleTrns').length > 0) {
$('#speechBubbleTrns').remove();
}
var tempCanvas = document.createElement('canvas');
tempCanvas.id = 'tempCanvas';
$scope.tempCanvas = tempCanvas.id;
tempCanvas.height = $scope.transparencyCanvasHeight;
tempCanvas.width = $scope.transparencyCanvasWidth;
tempCanvas.style.position = "absolute";
tempCanvas.style.left = 200 + 'px';
tempCanvas.style.backgroundColor = "transparent";
tempCanvas.style.visibility = 'hidden';
if (document.getElementById('canvasDiv') != null)
document.getElementById('canvasDiv').appendChild(tempCanvas);
// //debugger;
var tCanvas = document.getElementById('transparencyCanvas');
var tCanvasContext = tCanvas.getContext('2d');
var tCanvasHeight = parseInt((tCanvas.style.height).replace('px', ''));
var tCanvasWidth = parseInt((tCanvas.style.width).replace('px', ''));
// var tCanvas = document.getElementById('transparencyCanvas');
if (tCanvas != null) {
clearTransCanvas();
}
var TransparencyBoxStartX = parseInt((tCanvas.style.left).replace('px', ''));
var TransparencyEndX = parseInt((tCanvas.style.left).replace('px', '')) + parseInt((tCanvas.style.width.replace('px', '')));
var TransparencyBoxStartY = parseInt((tCanvas.style.top).replace('px', ''));
var TransparencyBoxEndY = parseInt((tCanvas.style.top).replace('px', '')) + parseInt((tCanvas.style.height).replace('px', ''));
var transparencyBoxBottom = parseInt(TransparencyBoxStartY) + parseInt(tCanvasHeight);
var transparencyBoxRight = parseInt(TransparencyBoxStartX) + parseInt(tCanvasWidth);
var BodyRegionDictionary = $rootScope.BodyRegionCordinatesData;
$.each(BodyRegionDictionary, function (index, value) {
//debugger;
// alert(' $.each(BodyRegionDictionary1')
var bodyRegionRight = parseInt(value.X) + parseInt(value.Width);
var bodyRegionBottom = parseInt(value.Y) + parseInt(value.Height);
// alert(' $.each(BodyRegionDictionary3. bodyRegionRight: ' + bodyRegionRight + ', bodyRegionBottom: ' + bodyRegionBottom)
if (TransparencyBoxStartX <= bodyRegionRight && value.X <= transparencyBoxRight && TransparencyBoxStartY <= bodyRegionBottom && value.Y <= transparencyBoxBottom) {
//var transNumber = parseInt(document.getElementById("txtTransparencyChange").value);
// debugger;
$scope.layerNumber = parseInt(txtlayerNumber.value);
$scope.loadTransparencyImage(value.bodyRegionId, value.Height, value.Width, value.X, value.Y, value.IsMirror, TransparencyBoxStartX, transparencyBoxRight, TransparencyBoxStartY, transparencyBoxBottom, $scope, true, false);
}
})
}
else {
//1. Dated:13-07-2016 Issue #4965 : The layer number should not extend beyond its level through layer text box.
var dataLength = $rootScope.BodyLayerData.Layers.DataLayer.length;
if (parseInt($('#txtlayerNumber').val()) > (dataLength - 1)) {
$('#txtlayerNumber').val(dataLength - 1);
$scope.currentLayerNumber = parseInt(dataLength - 1);
$scope.layerNumber = parseInt(dataLength - 1);
}
else
$scope.currentLayerNumber = parseInt($('#txtlayerNumber').val());
$rootScope.isLoading = true;
$('#spinner').css('visibility', 'visible');
var canDiv = document.getElementById('canvasDiv');
var canDivChildCount = canDiv.childElementCount;
if (canDivChildCount > 0) {
canDiv.innerHTML = '';
}
//2.
$scope.CalculateImageCordinates($rootScope.viewOrientationId);
//3.
$('#canvasDiv').scrollLeft($scope.imageHorizontlScrollPosition)
$('#canvasDiv').scrollTop($scope.imageVerticalScrollPosition)
if ($scope.isHighlightBodyByBodySystem) {
$timeout(function () { $scope.DisableProgressBar() }, 20000);
}
else
{
$timeout(function () { $scope.DisableProgressBar() }, 2000);
}
}
$('#layerChangeSlider').slider("option", "value", parseInt($scope.totalLayers) - parseInt($scope.layerNumber));
}
$scope.DisableProgressBar = function () {
// alert('Disabled wait cursor is called');
if ($rootScope.isHighLight) {
//alert('isHighlight: ' + $scope.isHighLight);
//$('#btnHighLight').removeClass('btn btn-black');
//$('#btnHighLight').addClass('btn-primary');
$("#btnHighLight").addClass("btn-primary");
$("#btnHighLight").removeClass("btn-black");
if (!$("#btnNormalMode").hasClass("btn-black")) {
$("#btnNormalMode").addClass("btn-black");
}
if (!$("#btnExtract").hasClass("btn-black")) {
$("#btnExtract").addClass("btn-black");
}
if ($("#btnExtract").hasClass("btn-primary")) {
$("#btnExtract").removeClass("btn-primary");
}
if ($("#btnNormalMode").hasClass("btn-primary")) {
$("#btnNormalMode").removeClass("btn-primary");
}
console.log('highLightBody call from DisableProgressBar')
// $scope.highLightBody();
}
$rootScope.isLoading = false;
$('#spinner').css('visibility', 'hidden');
//alert('Disabled wait cursor is done.See val :' + $rootScope.isLoading);
}
$scope.changeLayer = function () {
//console.log('changeLayer');
// alert('slide')
}
$('layerChangeSlider').slider().on('slideStop', function (ev) {
var newVal = $('.span2').data('slider').getValue();
if (originalVal != newVal) {
}
});
$scope.getMousePos = function (evt) {
return {
x: Math.round(evt.pageX - $('#canvasDiv').offset().left),
y: Math.round(evt.pageY - $('#canvasDiv').offset().top)
}
}
$scope.createDynamicSpeechBubble = function (event, x, y, isAnnotationForTBox) {
if (isAnnotationForTBox == true) {
//1. In transparency box we shows two annotation at a time, so we need to decide the max length of annotation in btween two annotation because based on that
// we decide the size of speech bubble
$scope.longestAnnotation = $scope.MultiLanguageAnnationArray.reduce(function (firstAnnotation, seconAnnotation) { return firstAnnotation.length > seconAnnotation.length ? firstAnnotation : seconAnnotation; });
//2.
if (event.ctrlKey) {
console.log('ctrl pressed');
$scope.multiAnnotationIsON = true;
//2.1 create unique speech bubbles
$scope.speechBubbleCounter = $scope.speechBubbleCounter + 1;
var id = "speechBubble" + $scope.speechBubbleCounter;
//2.2 Get clicked locationa and find if it is already clicked earlier too on same location
var pointClicked = parseInt(x) + parseInt(y);
var isClickedOnSamePoint = $("#canvasDiv").find("div[id=" + pointClicked + "]").length;
console.log('isClickedOnSamePoint: ' + isClickedOnSamePoint);
// if user has not clciked on smae point then create speech bubble otherwise not
if (isClickedOnSamePoint == 0) {
console.log('not clicked on same point')
$scope.createSpeechBubbleBasedOnAnnotationLength(pointClicked, x, y, id);
$scope.speechbubbleList.push({ xaxis: x, yaxis: y, ids: id });
}
$('.appendDragg').draggable({
drag: function (evt) {
$(this).prev('div').css("display", "none");
var bor_id = $(this).next('div').attr('id');
var sub_id1 = $(this).attr('id');
var verticalScrollPosition = canvasDiv.scrollTop;
var horizontlScrollPosition = canvasDiv.scrollLeft;
if ($scope.speechbubbleList != null || $scope.speechbubbleList != undefined) {
for (var m = 0; m <= $scope.speechbubbleList.length - 1; m++) {
if ($scope.speechbubbleList[m].ids == sub_id1) {
$scope.angle1($scope.speechbubbleList[m].xaxis, $scope.speechbubbleList[m].yaxis, evt.pageX + horizontlScrollPosition - $('#canvasDiv').offset().left, evt.pageY + verticalScrollPosition - $('#canvasDiv').offset().top, bor_id);
break;
}
}
}
},
});
$('.dynCross').on('click', function (evt) {
$(this).parent().parent().parent().css('display', 'none');
});
}
else {
$scope.multiAnnotationIsON = false;
$(".com").css("display", "none");
$("#bord").css({ "width": "0px", "display": "none" });
var sppechBubbleDotHTML = ''
+ '
'
+ ''
+ '
'
+ '
'
+ '
';
$('#canvasDiv').append(sppechBubbleDotHTML);
if ($scope.MultiLanguageAnnationArray.length > 0) {
for (var i = 0; i <= $scope.MultiLanguageAnnationArray.length - 1; i++) {
var MultipleLanguage = $scope.MultiLanguageAnnationArray[i];
$("#sppeachBubble").append("
';
if ($scope.longest_annotationT1.length > $scope.longest_annotationT2.length) {
$("#sppeachBubble_annotation p").remove();
$('#canvasDiv').append(sppechBubbleDotHTML_annotation);
for (var l = 0; l <= $scope.annotationTextArrayT1.length - 1; l++) {
var MultipleLang_annotation_T1 = $scope.annotationTextArrayT1[l];
$("#sppeachBubble_annotation").append("
" + MultipleLang_annotation_T1 + "
");
}
$("#sppeachBubble_annotation").append("");
for (var k = 0; k <= $scope.annotationTextArrayT2.length - 1; k++) {
var MultipleLang_annotation_T2 = $scope.annotationTextArrayT2[k];
$("#sppeachBubble_annotation").append("
");
}
$("#sppeachBubble_annotation").append("");
for (var k = 0; k <= $scope.annotationTextArrayT2.length - 1; k++) {
var MultipleLang_annotation_T2 = $scope.annotationTextArrayT2[k];
$("#sppeachBubble_annotation").append("