Browse Source

Continuando os comandos

Igor 6 years ago
parent
commit
3c738ee5b4

+ 2 - 1
css/ivprog-visual-1.0.css

@@ -129,7 +129,8 @@ body {
 }
 
 .function_name_div, .function_return_div, .function_name_parameter, .created_div_valor_var, .function_return, .var_value_menu_div, .variable_rendered, .variable_rendered div, .var_attributed,
-.expression_operand_1, .expression_operand_2, .operator, .div_comment_text, .value_rendered, .parameters_function_called, .parameters_function_called div {
+.expression_operand_1, .expression_operand_2, .operator, .div_comment_text, .value_rendered, .parameters_function_called, .parameters_function_called div, .expression_elements,
+.expression_element, .var_rendered {
 	display: inline;
 }
 

+ 2 - 4
js/visualUI/commands.js

@@ -168,10 +168,8 @@ export function genericCreateCommand (command_type) {
 			return new Models.Writer([new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true)]);
 
 		case Models.COMMAND_TYPES.attribution:
-			var root_node = new Models.ExpressionNode(null, new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true),
-			 	null, null);
-
-			return new Models.Attribution(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_variable, null, null, null, false), [root_node]);
+			return new Models.Attribution(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_variable, null, null, null, false), 
+				[]);
 
 		case Models.COMMAND_TYPES.functioncall:
 			return new Models.FunctionCall(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.only_function, null, null, null, false), null);

+ 79 - 12
js/visualUI/commands/attribution.js

@@ -15,31 +15,98 @@ export function createFloatingCommand () {
 export function renderCommand (command, function_obj) {
 
 	var el = $('<div class="ui attribution command_container"> <i class="ui icon small arrow left command_drag"></i> <i class="ui icon times red button_remove_command"></i> <div class="var_attributed"></div> <span class="text_attr_receives">'+LocalizedStrings.getUI('text_receives')+'</span> '
-		 + '<div class="expression_operand_1"></div> </div>');
+		 + '<div class="expression_elements"></div> </div>');
 	el.data('command', command);
 
 	VariableValueMenu.renderMenu(command, command.variable, el.find('.var_attributed'), function_obj);
-	command.expression[0].content = new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, null, null, null, true);
-	VariableValueMenu.renderMenu(command, command.expression[0].content, el.find('.expression_operand_1'), function_obj);
+
+	command.expression.push("(");
+
+	command.expression.push(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, "1", null, null, true));
+
+	command.expression.push(Models.ARITHMETIC_TYPES.plus);
+
+	command.expression.push(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, window.program_obj.functions[0].variables_list[0], null, 
+		new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, new Models.Variable(Types.REAL, "variable_2", 1), true), null, null, true));
+
+
+	command.expression.push(")");
+
+	command.expression.push(Models.ARITHMETIC_TYPES.minus);
+
+	command.expression.push(new Models.VariableValueMenu(VariableValueMenuManagement.VAR_OR_VALUE_TYPES.all, "2", null, null, true));
+
+	/*VariableValueMenu.renderMenu(command, command.expression[0].content, el.find('.expression_operand_1'), function_obj);*/
 
 	addHandlers(command, function_obj, el);
 
+	renderExpression(command, function_obj, el);
+
 	return el;
 
-	/*var el = $('<div class="ui attribution command_container"> <i class="ui icon small arrow left command_drag"></i> <i class="ui icon times red button_remove_command"></i> <div class="var_attributed"></div> <span class="text_attr_receives">'+LocalizedStrings.getUI('text_receives')+'</span> '
-		 + '<div class="expression_operand_1"></div> </div>');
-	$(el).data('command', command);
+}
 
+function renderExpression(command, function_obj, el) {
 
-	VariableValueMenu.renderMenu(command, command.variable, $(el).find('.var_attributed'), function_obj);
+	var expression_div = el.find('.expression_elements');
+	expression_div.text('');
+	
+	for (var i = 0; i < command.expression.length; i++) {
 
-	VariableValueMenu.renderMenu(command, command.expression, $(el).find('.expression_operand_1'), function_obj);
+		if (command.expression[i].type) {
 
-	addHandlers(command, function_obj, el);
+			var temp = $('<div class="expression_element"></div>');
+			temp.data('ref_element', command.expression[i]);
+			temp.data('ref_index', i);
+
+			expression_div.append(temp);
+
+			VariableValueMenu.renderMenu(command, command.expression[i], temp, function_obj);
 
-	return el;*/
+		} else if (command.expression[i] == "(" || command.expression[i] == ")") {
+
+			var temp = $('<div class="expression_element">'+command.expression[i]+'</div>');
+			temp.data('ref_element', command.expression[i]);
+			temp.data('ref_index', i);
+
+			expression_div.append(temp);
+
+		} else {
+
+			var temp = '<div class="expression_element">';
+
+			switch(command.expression[i]) {
+				case Models.ARITHMETIC_TYPES.plus:
+					temp += '+';
+					break;
+				case Models.ARITHMETIC_TYPES.minus:
+					temp += '-';
+					break;
+				case Models.ARITHMETIC_TYPES.multiplication:
+					temp += '*';
+					break;
+				case Models.ARITHMETIC_TYPES.division:
+					temp += '/';
+					break;
+				case Models.ARITHMETIC_TYPES.module:
+					temp += '%';
+					break;
+			}
+
+			temp += '</div>';
+			temp = $(temp);
+			temp.data('ref_element', command.expression[i]);
+			temp.data('ref_index', i);
+
+			expression_div.append(temp);
+
+		}
+
+	}
 }
 
+
+
 function addHandlers (command, function_obj, attribution_dom) {
 
 	attribution_dom.find('.button_remove_command').on('click', function() {
@@ -51,7 +118,7 @@ function addHandlers (command, function_obj, attribution_dom) {
 
 export function renderMenuOperations (command, ref_object, dom_object, menu_var_or_value, function_obj, variable_selected) {
 
-	console.log("recebido o seguinte DOM: ");
+	/*console.log("recebido o seguinte DOM: ");
 	console.log(dom_object);
 
 	if (dom_object.hasClass('var_attributed')) {
@@ -97,7 +164,7 @@ export function renderMenuOperations (command, ref_object, dom_object, menu_var_
     				menu_operations.find('.text').text('');
     		}
         }
-    });
+    });*/
 }
 
 function createExpressionAround (command, ref_object, dom_object, function_obj) {

+ 124 - 3
js/visualUI/commands/variable_value_menu.js

@@ -61,6 +61,129 @@ export function renderMenu (command, ref_object, dom_object, function_obj, size_
     addVariablesToMenu(function_obj, menu_var_or_value, ref_object);
 
     addFunctionsToMenu(function_obj, menu_var_or_value, ref_object);
+
+    if (ref_object.content) {
+    	renderPreviousContent(function_obj, menu_var_or_value, ref_object, dom_object, command);
+    }
+}
+
+function renderPreviousContent (function_obj, menu_var_or_value, ref_object, dom_object, command) {
+
+	
+	if (ref_object.function_called) {
+
+	} else if (ref_object.content.type) { 
+		var temp = $('<div class="variable_rendered"></div>');
+		temp.insertBefore(menu_var_or_value);
+		menu_var_or_value.remove();
+		temp.append(variableValueMenuCode(command, ref_object, dom_object, function_obj));
+
+		var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
+		context_menu += '<div class="item" data-clear="true">'+LocalizedStrings.getUI('btn_clear')+'</div>';
+		context_menu += '</div></div>';
+
+		context_menu = $(context_menu);
+
+		context_menu.insertAfter( dom_object.find('.variable_rendered') );
+
+		context_menu.dropdown({
+			onChange: function(value, text, $selectedItem) {
+		     if ($selectedItem.data('clear')) {
+		     	dom_object.text('');
+
+		     	ref_object.content = null;
+		     	ref_object.row = null;
+		     	ref_object.column = null;
+
+		     	renderMenu(command, ref_object, dom_object, function_obj);
+		     }
+	      }
+		});
+
+	} else {
+		var temp = $('<div class="value_rendered"></div>');
+		temp.insertBefore(menu_var_or_value);
+		menu_var_or_value.remove();
+		temp.append(variableValueMenuCode(command, ref_object, dom_object, function_obj));
+
+
+		var context_menu = '<div class="ui dropdown context_menu_clear"><div class="text"></div><i class="dropdown icon"></i><div class="menu">';
+		context_menu += '<div class="item" data-clear="true">'+LocalizedStrings.getUI('btn_clear')+'</div>';
+		context_menu += '</div></div>';
+
+		context_menu = $(context_menu);
+
+		context_menu.insertAfter( temp );
+
+		context_menu.dropdown({
+			onChange: function(value, text, $selectedItem) {
+		     if ($selectedItem.data('clear')) {
+		     	dom_object.text('');
+
+		     	ref_object = new Models.VariableValueMenu(ref_object.variable_and_value, null, null, null, ref_object.include_constant);
+
+		     	dom_object.find('.value_rendered').remove();
+				dom_object.find('.context_menu_clear').remove();
+				dom_object.find('.width-dynamic-minus').remove();
+
+		     	renderMenu(command, ref_object, dom_object, function_obj);
+		     }
+	      }
+		});
+
+		temp.on('click', function(e) {
+			temp.remove();
+			temp.empty();
+			temp.remove();
+			dom_object.empty();
+			dom_object.append('<span class="menu_var_or_value_dom"> </span>');
+			
+			openInputToValue(command, ref_object, dom_object, menu_var_or_value, function_obj);
+		});
+	}
+}
+
+function variableValueMenuCode (command, variable_obj, dom_object, function_obj) {
+
+	console.log("o que chegou: ");
+	console.log(variable_obj);
+
+	var ret = '';
+	if (variable_obj.function_called) {
+
+		ret += variable_obj.function_called.name + ' ( ';
+
+		if (variable_obj.parameters_list) {
+			for (var i = 0; i < variable_obj.parameters_list.length; i++) {
+				ret += variableValueMenuCode(command, variable_obj.parameters_list[i], dom_object, function_obj);
+				if ((i + 1) < variable_obj.parameters_list.length) {
+					ret += ', ';
+				}
+			}
+		}
+
+		ret += ' )';
+	} else if (variable_obj.content.type) {
+
+		ret += variable_obj.content.name;
+
+		if (variable_obj.content.dimensions == 1) {
+			ret += ' [ ' + variableValueMenuCode(command, variable_obj.column, dom_object, function_obj) + ' ] ';
+		}
+
+		if (variable_obj.content.dimensions == 2) {
+			ret += ' [ ' + variableValueMenuCode(command, variable_obj.row, dom_object, function_obj) + ' ] ';
+			ret += ' [ ' + variableValueMenuCode(command, variable_obj.column, dom_object, function_obj) + ' ] ';
+		}
+
+
+	} else {
+
+		ret += variable_obj.content;
+	}
+
+	return ret;
+
 }
 
 function addFunctionsToMenu (function_obj, menu_var_or_value, ref_object) {
@@ -96,8 +219,6 @@ function addVariablesToMenu (function_obj, menu_var_or_value, ref_object) {
 				}
 			}
 		}
-
-		
 	}
 
 	if (function_obj.parameters_list) {
@@ -363,7 +484,7 @@ function openInputToValue (command, ref_object, dom_object, menu_var_or_value, f
 		}
 	});
 
-	$(rendered).on('click', function(e) {
+	rendered.on('click', function(e) {
 		rendered.remove();
 		rendered.empty();
 		rendered.remove();

+ 4 - 5
js/visualUI/functions.js

@@ -17,16 +17,15 @@ import WatchJS from 'melanke-watchjs';
 var counter_new_functions = 0;
 var counter_new_parameters = 0;
 
-let domConsole = null;
-
+let domConsole = null; 
 const program = new Models.Program();
-const mainFunction = new Models.Function(LocalizedStrings.getUI("start"), Types.VOID, 0, [], true, false, []);
+const variable1 = new Models.Variable(Types.REAL, "variable_1", 1, 1);
+const mainFunction = new Models.Function(LocalizedStrings.getUI("start"), Types.VOID, 0, [], true, false, [variable1]);
 mainFunction.function_comment = new Models.Comment(LocalizedStrings.getUI('text_comment_main'));
 const parameter1 = new Models.Variable(Types.INTEGER, "par_1", 1);
-const variable1 = new Models.Variable(Types.REAL, "variable_1", 1);
 const command1 = new Models.Comment(new Models.VariableValueMenu(VariableValueMenu.VAR_OR_VALUE_TYPES.only_value, "Testing rendering commands"));
 
-const sumFunction = new Models.Function("soma", Types.INTEGER, 0, [parameter1], false, false, [variable1], null, [command1]);
+const sumFunction = new Models.Function("soma", Types.INTEGER, 0, [parameter1], false, false, [], null, [command1]);
 
 program.addFunction(mainFunction);
 program.addFunction(sumFunction);

+ 3 - 4
js/visualUI/ivprog_elements.js

@@ -76,17 +76,16 @@ export class Expression {
     this.operator = operator;
   }
 }
-
+/*
 export class ExpressionNode {
 
-  constructor (parent_node, content, left_node, right_node) {
-    this.parent_node = parent_node;
+  constructor (content, left_node, right_node) {
     this.content = content;
     this.left_node = left_node;
     this.right_node = right_node;
     
   }
-}
+}*/
 
 export class IfTrue {