2
0

2 Commits d67b13ea85 ... 7397c05918

Autor SHA1 Nachricht Datum
  Igor 7397c05918 work in progress vor 2 Jahren
  Igor d472929a40 finished variables and parameters vor 2 Jahren
2 geänderte Dateien mit 77 neuen und 22 gelöschten Zeilen
  1. 58 3
      js/util/codeParser.js
  2. 19 19
      js/visualUI/globals.js

+ 58 - 3
js/util/codeParser.js

@@ -1,5 +1,29 @@
 
 import * as Models from '../visualUI/ivprog_elements';
+import { LocalizedStrings } from "./../services/localizedStringsService";
+
+function parseBoolean (var_value, dimensions) {
+  if (dimensions == 0)
+    return var_value == LocalizedStrings.getUI("logic_value_true");
+  if (dimensions == 1) {
+    var final_array = [];
+    var_value.forEach(function(el){
+      final_array.push(el == LocalizedStrings.getUI("logic_value_true"));
+    });
+    return final_array;
+  }
+  if (dimensions == 2) {
+    var final_array = [];
+    var_value.forEach(function(row){
+      var temp = [];
+      row.forEach(function(el){
+        temp.push(el == LocalizedStrings.getUI("logic_value_true"));
+      });
+      final_array.push(temp);
+    });
+    return final_array;
+  }
+}
 
 function parseGlobal (global_obj) {
 
@@ -10,8 +34,11 @@ function parseGlobal (global_obj) {
   
   new_global.is_constant = global_obj.is_const;
   new_global.columns = global_obj.columns;
-  new_global.dimension = global_obj.dimension;
+  new_global.dimensions = global_obj.dimension;
   new_global.rows = global_obj.rows;
+
+  if (global_obj.type == "boolean")
+    new_global.value = parseBoolean(global_obj.value, global_obj.dimension);
 	
 	window.program_obj.addGlobal(new_global);
 }
@@ -29,13 +56,16 @@ function parseParameter (parameter_obj) {
     parameter_obj.reference
   );
 
+  new_parameter.value = parameter_obj.value;
+
+  if (parameter_obj.type == "boolean" && parameter_obj.value)
+    new_parameter.value = parseBoolean(parameter_obj.value, parameter_obj.dimension);
+
   return new_parameter;
 }
 
 function parseFunction (function_obj) {
 
-  console.log(function_obj)
-  
   const new_function = new Models.Function(
     function_obj.name, 
     function_obj.return_type, 
@@ -56,6 +86,14 @@ function parseFunction (function_obj) {
     });
   }
 
+  if (function_obj.variables_list) {
+    function_obj.variables_list.forEach(function(el){
+      new_function.variables_list.push(parseParameter(el));
+    });
+  }
+
+  new_function.commands = parseCommands(function_obj.commands)
+
   window.program_obj.addFunction(new_function);
   
 }
@@ -73,4 +111,21 @@ export function parserCodeVisual (code_obj = null) {
   window.program_obj.functions = [];
   code_obj.functions.forEach(parseFunction);
 
+}
+
+function parseCommands (commands_block) {
+
+  console.log('bloco', commands_block)
+
+  if (Array.isArray(commands_block)) {
+    var temp = [];
+    commands_block.forEach(function(command) {
+      temp.push(parseCommands(command));
+    });
+    return temp;
+  }
+  else {
+    return null;
+  }
+  
 }

+ 19 - 19
js/visualUI/globals.js

@@ -310,7 +310,7 @@ function renderValues (global_var, global_container) {
 			ret += '<tr>';
 			if (global_var.type == Types.REAL) {
 				for (var k = 0; k < global_var.columns; k++) {
-					ret += '<td><span class="span_value_variable vector_var" data-index="'+k+'">'+global_var.value[k].toFixed(1)+'</span></td>';
+					ret += '<td><span class="span_value_variable vector_var" data-index="'+k+'">'+parseFloat(global_var.value[k]).toFixed(1)+'</span></td>';
 				}
 			} else {
 				for (var k = 0; k < global_var.columns; k++) {
@@ -334,7 +334,7 @@ function renderValues (global_var, global_container) {
 				for (var l = 0; l < global_var.rows; l++) {
     				ret += '<tr>';
     				for (var k = 0; k < global_var.columns; k++) {
-    					ret += '<td><span class="span_value_variable matrix_var" data-index="'+k+'" data-row="'+l+'">'+global_var.value[l][k].toFixed(1)+'</span>'+'</td>';
+    					ret += '<td><span class="span_value_variable matrix_var" data-index="'+k+'" data-row="'+l+'">'+parseFloat(global_var.value[l][k]).toFixed(1)+'</span>'+'</td>';
     				} 
     				ret += '</tr>';
 				}
@@ -621,7 +621,7 @@ function enableGlobalMatrixValueUpdate (global_var, row, index, parent_node) {
 
 	if (global_var.type == Types.REAL) {
 		input_field = $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
-			+ global_var.value[row][index].toFixed(1) + "' />" );
+			+ parseFloat(global_var.value[row][index]).toFixed(1) + "' />" );
 		input_field.insertBefore(parent_node.find('.span_value_variable'));
 	} else {
 		input_field = $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
@@ -649,7 +649,7 @@ function enableGlobalMatrixValueUpdate (global_var, row, index, parent_node) {
 			if (global_var.type == Types.REAL) {
 				global_var.value[row][index] = parseFloat(input_field.val().trim());
 
-				parent_node.find('.span_value_variable').text(global_var.value[row][index].toFixed(1));
+				parent_node.find('.span_value_variable').text(parseFloat(global_var.value[row][index]).toFixed(1));
 			} else {
 				if (global_var.type == Types.INTEGER) {
 					global_var.value[row][index] = parseInt(input_field.val().trim());
@@ -685,7 +685,7 @@ function enableGlobalMatrixValueUpdate (global_var, row, index, parent_node) {
 				if (global_var.type == Types.REAL) {
 					global_var.value[row][index] = parseFloat(input_field.val().trim());
 
-					parent_node.find('.span_value_variable').text(global_var.value[row][index].toFixed(1));
+					parent_node.find('.span_value_variable').text(parseFloat(global_var.value[row][index]).toFixed(1));
 				} else {
 					if (global_var.type == Types.INTEGER) {
 						global_var.value[row][index] = parseInt(input_field.val().trim());
@@ -697,7 +697,7 @@ function enableGlobalMatrixValueUpdate (global_var, row, index, parent_node) {
 				registerUserEvent(global_var.name, ActionTypes.CHANGE_GLOBAL_VALUE, global_var.value);
 			} else {
 				if (global_var.type == Types.REAL) {
-					parent_node.find('.span_value_variable').text(global_var.value[row][index].toFixed(1));
+					parent_node.find('.span_value_variable').text(parseFloat(global_var.value[row][index]).toFixed(1));
 				} else {
 					parent_node.find('.span_value_variable').text(global_var.value[row][index]);
 				}
@@ -716,7 +716,7 @@ function enableGlobalMatrixValueUpdate (global_var, row, index, parent_node) {
 		}
 		if(code == 27) {
 			if (global_var.type == Types.REAL) {
-				parent_node.find('.span_value_variable').text(global_var.value[row][index].toFixed(1));
+				parent_node.find('.span_value_variable').text(parseFloat(global_var.value[row][index]).toFixed(1));
 			} else {
 				parent_node.find('.span_value_variable').text(global_var.value[row][index]);
 			}
@@ -747,7 +747,7 @@ function enableGlobalValueUpdate (global_var, parent_node) {
 
 	if (global_var.type == Types.REAL) {
 		input_field = $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
-			+ global_var.value.toFixed(1) + "' />" );
+			+ parseFloat(global_var.value).toFixed(1) + "' />" );
 		input_field.insertBefore(parent_node.find('.span_value_variable'));
 	} else {
 		input_field = $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
@@ -775,7 +775,7 @@ function enableGlobalValueUpdate (global_var, parent_node) {
 		if (input_field.val().trim()) {
 			if (global_var.type == Types.REAL) {
 				global_var.value = parseFloat(input_field.val().trim());
-				parent_node.find('.span_value_variable').text(global_var.value.toFixed(1));
+				parent_node.find('.span_value_variable').text(parseFloat(global_var.value).toFixed(1));
 			} else{
 				if (global_var.type == Types.INTEGER) {
 					global_var.value = parseInt(input_field.val().trim());
@@ -790,7 +790,7 @@ function enableGlobalValueUpdate (global_var, parent_node) {
 			changed = true;
 		} else {
 			if (global_var.type == Types.REAL) {
-				parent_node.find('.span_value_variable').text(global_var.value.toFixed(1));
+				parent_node.find('.span_value_variable').text(parseFloat(global_var.value).toFixed(1));
 			} else {
 				parent_node.find('.span_value_variable').text(global_var.value);
 			}
@@ -819,7 +819,7 @@ function enableGlobalValueUpdate (global_var, parent_node) {
 			if (input_field.val().trim()) {
 				if (global_var.type == Types.REAL) {
 					global_var.value = parseFloat(input_field.val().trim());
-					parent_node.find('.span_value_variable').text(global_var.value.toFixed(1));
+					parent_node.find('.span_value_variable').text(parseFloat(global_var.value).toFixed(1));
 				} else {
 					if (global_var.type == Types.INTEGER) {
 						global_var.value = parseInt(input_field.val().trim());
@@ -833,7 +833,7 @@ function enableGlobalValueUpdate (global_var, parent_node) {
 				changed = true;
 			} else {
 				if (global_var.type == Types.REAL) {
-					parent_node.find('.span_value_variable').text(global_var.value.toFixed(1));
+					parent_node.find('.span_value_variable').text(parseFloat(global_var.value).toFixed(1));
 				} else {
 					parent_node.find('.span_value_variable').text(global_var.value);
 				}
@@ -856,7 +856,7 @@ function enableGlobalValueUpdate (global_var, parent_node) {
 		}
 		if(code == 27) {
 			if (global_var.type == Types.REAL) {
-				parent_node.find('.span_value_variable').text(global_var.value.toFixed(1));
+				parent_node.find('.span_value_variable').text(parseFloat(global_var.value).toFixed(1));
 			} else{
 				parent_node.find('.span_value_variable').text(global_var.value);
 			}
@@ -964,7 +964,7 @@ function enableGlobalVectorValueUpdate (global_var, index, parent_node) {
 
 	if (global_var.type == Types.REAL) {
 		input_field = $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
-			+ global_var.value[index].toFixed(1) + "' />" );
+			+ parseFloat(global_var.value[index]).toFixed(1) + "' />" );
 		input_field.insertBefore(parent_node.find('.span_value_variable'));
 	} else {
 		input_field = $( "<input type='text' class='width-dynamic input_name_function' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' value='"
@@ -993,7 +993,7 @@ function enableGlobalVectorValueUpdate (global_var, index, parent_node) {
 			if (global_var.type == Types.REAL) {
 				global_var.value[index] = parseFloat(input_field.val().trim());
 
-				parent_node.find('.span_value_variable').text(global_var.value[index].toFixed(1));
+				parent_node.find('.span_value_variable').text(parseFloat(global_var.value[index]).toFixed(1));
 			} else {
 
 				if (global_var.type == Types.INTEGER) {
@@ -1008,7 +1008,7 @@ function enableGlobalVectorValueUpdate (global_var, index, parent_node) {
 			changed = true;
 		} else {
 			if (global_var.type == Types.REAL) {
-				parent_node.find('.span_value_variable').text(global_var.value[index].toFixed(1));
+				parent_node.find('.span_value_variable').text(parseFloat(global_var.value[index]).toFixed(1));
 			} else {
 				parent_node.find('.span_value_variable').text(global_var.value[index]);
 			}
@@ -1037,7 +1037,7 @@ function enableGlobalVectorValueUpdate (global_var, index, parent_node) {
 				if (global_var.type == Types.REAL) {
 					global_var.value[index] = parseFloat(input_field.val().trim());
 
-					parent_node.find('.span_value_variable').text(global_var.value[index].toFixed(1));
+					parent_node.find('.span_value_variable').text(parseFloat(global_var.value[index]).toFixed(1));
 				} else {
 
 					if (global_var.type == Types.INTEGER) {
@@ -1052,7 +1052,7 @@ function enableGlobalVectorValueUpdate (global_var, index, parent_node) {
 				changed = true;
 			} else {
 				if (global_var.type == Types.REAL) {
-					parent_node.find('.span_value_variable').text(global_var.value[index].toFixed(1));
+					parent_node.find('.span_value_variable').text(parseFloat(global_var.value[index]).toFixed(1));
 				} else {
 					parent_node.find('.span_value_variable').text(global_var.value[index]);
 				}
@@ -1074,7 +1074,7 @@ function enableGlobalVectorValueUpdate (global_var, index, parent_node) {
 		}
 		if(code == 27) {
 			if (global_var.type == Types.REAL) {
-				parent_node.find('.span_value_variable').text(global_var.value[index].toFixed(1));
+				parent_node.find('.span_value_variable').text(parseFloat(global_var.value[index]).toFixed(1));
 			} else {
 				parent_node.find('.span_value_variable').text(global_var.value[index]);
 			}