Igor 5 лет назад
Родитель
Сommit
ebe3b37cba

+ 7 - 2
i18n/en/ui.json

@@ -93,7 +93,7 @@
   "var_menu_select_function": "Select a function",
   "expression_menu_select": "Select an expression",
   "math": "Mathematic",
-  "text": "Text",
+  "text_t": "Text",
   "arrangement": "Arrangement",
   "conversion": "Conversion",
   "$sin": "sin",
@@ -106,5 +106,10 @@
   "$negate": "negate",
   "$invert": "invert",
   "$max": "maximum",
-  "$min": "minimum"
+  "$min": "minimum",
+  "$substring": "substring",
+  "$length": "length",
+  "$uppercase": "uppercase",
+  "$lowercase": "lowercase",
+  "$charAt": "char_at"
 }

+ 7 - 2
i18n/es/ui.json

@@ -98,7 +98,7 @@
   "arrangement": "Arrangement",
   "conversion": "Conversion",
   "math": "Mathematic",
-  "text": "Text",
+  "text_t": "Text",
   "arrangement": "Arrangement",
   "conversion": "Conversion",
   "$sin": "sin",
@@ -111,5 +111,10 @@
   "$negate": "negate",
   "$invert": "invert",
   "$max": "maximum",
-  "$min": "minimum"
+  "$min": "minimum",
+  "$substring": "substring",
+  "$length": "length",
+  "$uppercase": "uppercase",
+  "$lowercase": "lowercase",
+  "$charAt": "char_at"
 }

+ 7 - 2
i18n/pt/ui.json

@@ -95,7 +95,7 @@
   "expression_menu_select": "Selecione uma expressão",
   "$sin": "sen",
   "math": "Matematica",
-  "text": "Texto",
+  "text_t": "Texto",
   "arrangement": "Arranjo",
   "conversion": "Conversao",
   "$sin": "seno",
@@ -108,5 +108,10 @@
   "$negate": "trocar_sinal",
   "$invert": "inverter_valor",
   "$max": "maximo",
-  "$min": "minimo"
+  "$min": "minimo",
+  "$substring": "subcadeia",
+  "$length": "comprimento",
+  "$uppercase": "caixa_alta",
+  "$lowercase": "caixa_baixa",
+  "$charAt": "texto_na_posicao"
 }

+ 72 - 13
js/visualUI/commands/variable_value_menu.js

@@ -12,13 +12,37 @@ export const VAR_OR_VALUE_TYPES = Object.freeze({only_variable: 1, only_value: 2
 	value_and_function: 6, all: 7});
 
 export function renderMenu (command, ref_object, dom_object, function_obj, size_field = 2, expression_element) {
+	console.log('\n\ndebugging: ');
+	console.log(command);
+	console.log(ref_object);
+	console.log(dom_object);
+	console.log(function_obj);
+	console.log(size_field);
+	console.log(expression_element);
+	console.log('fim\n\n');
+
+	// Verificar se o objeto atual trata-se de uma chamada de função e conferir se possui a quantidade correta de parâmetros
+	// Caso não possua, tem que adicionar as variáveis que servirão de parâmetros:
+	if (ref_object.function_called) {
+		if (ref_object.function_called.parameters_list) {
+
+			while (ref_object.function_called.parameters_list.length != ref_object.parameters_list.length) {
+				if (ref_object.parameters_list.length > ref_object.function_called.parameters_list.length) {
+					ref_object.parameters_list.pop();
+				} else {
+					ref_object.parameters_list.push(new Models.VariableValueMenu(VAR_OR_VALUE_TYPES.all, null, null, null, true));
+				}
+			}
+		}
+	}
+
 	var menu_var_or_value = '<div class="ui dropdown menu_var_or_value_dom" data-algo="12"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
 
 	if (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.only_variable) {
 
 		menu_var_or_value = '<div class="ui dropdown menu_var_or_value_dom"><div class="text"></div><i class="dropdown icon"></i><div class="menu menu_only_vars">';
 		menu_var_or_value += '</div>';
-	} 
+	}
 
 	if ((ref_object.variable_and_value == VAR_OR_VALUE_TYPES.variable_and_function) || (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.variable_and_value_opt) || (ref_object.variable_and_value == VAR_OR_VALUE_TYPES.all)) {
 		
@@ -76,17 +100,32 @@ export function renderMenu (command, ref_object, dom_object, function_obj, size_
 	addIVProgFunctionsToMenu(function_obj, menu_var_or_value, ref_object, expression_element);
 
     if (ref_object.content || ref_object.function_called) {
-    	// Verificar se a variável ainda existe:
-    	if (isVarInProgram(ref_object.content, function_obj)) {
-    		renderPreviousContent(function_obj, menu_var_or_value, ref_object, dom_object, command, expression_element);
-    	} else {
-    		if (ref_object.content && ref_object.content.type) {
+    	if (ref_object.content) {
+    		// Verificar se a variável ainda existe:
+    		if (isVarInProgram(ref_object.content, function_obj)) {
+    			renderPreviousContent(function_obj, menu_var_or_value, ref_object, dom_object, command, expression_element);
+	    	} else {
+	    		if (ref_object.content && ref_object.content.type) {
+	    			ref_object.content = null;
+	    			appendSelectText(ref_object, menu_var_or_value);
+	    		} else {
+	    			renderPreviousContent(function_obj, menu_var_or_value, ref_object, dom_object, command, expression_element);
+	    		}
+	    	}
+    	} else if (ref_object.function_called) {
+    		// Verificar se a função ainda existe:
+    		if (isFunctionInProgram(ref_object.function_called)) {
+    			renderPreviousContent(function_obj, menu_var_or_value, ref_object, dom_object, command, expression_element);
+    		} else {
     			ref_object.content = null;
+		     	ref_object.row = null;
+		     	ref_object.column = null;
+		     	delete ref_object.function_called;
+		     	delete ref_object.parameters_list;
     			appendSelectText(ref_object, menu_var_or_value);
-    		} else {
-    			renderPreviousContent(function_obj, menu_var_or_value, ref_object, dom_object, command, expression_element);
     		}
     	}
+
     } else {
     	appendSelectText(ref_object, menu_var_or_value);
     }
@@ -110,15 +149,18 @@ function appendSelectText (ref_object, menu_var_or_value) {
 	}
 }
 
-function isVarInProgram (var_obj, function_obj) {
-	// Verify in globals:
-	if (window.program_obj.globals) {
-		for (var i = 0; i < window.program_obj.globals.length; i++) {
-			if (window.program_obj.globals[i] == var_obj) {
+function isFunctionInProgram (function_called_obj) {
+	if (window.program_obj.functions) {
+		for (var i = 0; i < window.program_obj.functions.length; i++) {
+			if (window.program_obj.functions[i] == function_called_obj) {
 				return true;
 			}
 		}
 	}
+	return false;
+}
+
+function isVarInProgram (var_obj, function_obj) {
 	// Verify in locals:
 	if (function_obj.variables_list) {
 		for (var i = 0; i < function_obj.variables_list.length; i++) {
@@ -135,6 +177,14 @@ function isVarInProgram (var_obj, function_obj) {
 			}
 		}
 	}
+	// Verify in globals:
+	if (window.program_obj.globals) {
+		for (var i = 0; i < window.program_obj.globals.length; i++) {
+			if (window.program_obj.globals[i] == var_obj) {
+				return true;
+			}
+		}
+	}
 	return false;
 }
 
@@ -592,6 +642,15 @@ function addIVProgFunctionsToMenu (function_obj, menu_var_or_value, ref_object,
 			case Models.SYSTEM_FUNCTIONS_CATEGORIES.math:
 				sub_menu.find('.menu_math_functions').append(t);
 				break;
+			case Models.SYSTEM_FUNCTIONS_CATEGORIES.text:
+				sub_menu.find('.menu_text_functions').append(t);
+				break;
+			case Models.SYSTEM_FUNCTIONS_CATEGORIES.arrangement:
+				sub_menu.find('.menu_arrangement_functions').append(t);
+				break;
+			case Models.SYSTEM_FUNCTIONS_CATEGORIES.conversion:
+				sub_menu.find('.menu_conversion_functions').append(t);
+				break;
 		}	
 	}
 }

+ 35 - 0
js/visualUI/functions.js

@@ -26,6 +26,7 @@ window.studentGrade = null;
 const program = new Models.Program();
 
 window.system_functions = [];
+// Adding math functions:
 window.system_functions.push(new Models.SystemFunction('$sin', Types.REAL, 0, [new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true)],
   null, Models.SYSTEM_FUNCTIONS_CATEGORIES.math));
 window.system_functions.push(new Models.SystemFunction('$cos', Types.REAL, 0, [new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true)],
@@ -48,6 +49,40 @@ window.system_functions.push(new Models.SystemFunction('$max', Types.REAL, 0, [n
   null, Models.SYSTEM_FUNCTIONS_CATEGORIES.math));
 window.system_functions.push(new Models.SystemFunction('$min', Types.REAL, 0, [new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true)],
   null, Models.SYSTEM_FUNCTIONS_CATEGORIES.math));
+// Adding text functions:
+window.system_functions.push(new Models.SystemFunction('$substring', Types.TEXT, 0, [new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true),
+  new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true),new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true)],
+  null, Models.SYSTEM_FUNCTIONS_CATEGORIES.text));
+window.system_functions.push(new Models.SystemFunction('$length', Types.INTEGER, 0, [new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true)],
+  null, Models.SYSTEM_FUNCTIONS_CATEGORIES.text));
+window.system_functions.push(new Models.SystemFunction('$uppercase', Types.TEXT, 0, [new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true)],
+  null, Models.SYSTEM_FUNCTIONS_CATEGORIES.text));
+window.system_functions.push(new Models.SystemFunction('$lowercase', Types.TEXT, 0, [new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true)],
+  null, Models.SYSTEM_FUNCTIONS_CATEGORIES.text));
+window.system_functions.push(new Models.SystemFunction('$charAt', Types.TEXT, 0, [new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true), new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true)],
+  null, Models.SYSTEM_FUNCTIONS_CATEGORIES.text));
+// Adding arrangement functions:
+window.system_functions.push(new Models.SystemFunction('$numElements', Types.INTEGER, 0, [new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true)],
+  null, Models.SYSTEM_FUNCTIONS_CATEGORIES.arrangement));
+window.system_functions.push(new Models.SystemFunction('$matrixLines', Types.INTEGER, 0, [new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true)],
+  null, Models.SYSTEM_FUNCTIONS_CATEGORIES.arrangement));
+window.system_functions.push(new Models.SystemFunction('$matrixColumns', Types.INTEGER, 0, [new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true)],
+  null, Models.SYSTEM_FUNCTIONS_CATEGORIES.arrangement));
+// Adding conversion functions:
+window.system_functions.push(new Models.SystemFunction('$isReal', Types.BOOLEAN, 0, [new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true)],
+  null, Models.SYSTEM_FUNCTIONS_CATEGORIES.conversion));
+window.system_functions.push(new Models.SystemFunction('$isInt', Types.BOOLEAN, 0, [new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true)],
+  null, Models.SYSTEM_FUNCTIONS_CATEGORIES.conversion));
+window.system_functions.push(new Models.SystemFunction('$isBool', Types.BOOLEAN, 0, [new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true)],
+  null, Models.SYSTEM_FUNCTIONS_CATEGORIES.conversion));
+window.system_functions.push(new Models.SystemFunction('$castReal', Types.REAL, 0, [new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true)],
+  null, Models.SYSTEM_FUNCTIONS_CATEGORIES.conversion));
+window.system_functions.push(new Models.SystemFunction('$castInt', Types.INTEGER, 0, [new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true)],
+  null, Models.SYSTEM_FUNCTIONS_CATEGORIES.conversion));
+window.system_functions.push(new Models.SystemFunction('$castBool', Types.BOOLEAN, 0, [new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true)],
+  null, Models.SYSTEM_FUNCTIONS_CATEGORIES.conversion));
+window.system_functions.push(new Models.SystemFunction('$castString', Types.TEXT, 0, [new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.all, null, null, null, true)],
+  null, Models.SYSTEM_FUNCTIONS_CATEGORIES.conversion));
 /*const variable1 = new Models.Variable(Types.INTEGER, "a", 1);
 const parameter1 = new Models.Variable(Types.INTEGER, "par_1", 1);
 const command1 = new Models.Comment(new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.only_value, "Testing rendering commands"));

+ 1 - 1
js/visualUI/ivprog_elements.js

@@ -17,7 +17,7 @@ export const ARITHMETIC_COMPARISON = Object.freeze({greater_than:"greater_than",
 
 export const LOGIC_COMPARISON = Object.freeze({equals_to:"equals_to", not_equals_to:"not_equals_to", and:"and", or:"or"});
 
-export const SYSTEM_FUNCTIONS_CATEGORIES = Object.freeze({math:"math", text:"text", arrangement:"arrangement", conversion:"conversion"});
+export const SYSTEM_FUNCTIONS_CATEGORIES = Object.freeze({math:"math", text:"text_t", arrangement:"arrangement", conversion:"conversion"});
 
 export class Variable {