Commit 14c82955 authored by Aayush's avatar Aayush

suggested changes done in parser and ascii_art UI

parent 6b121e84
Pipeline #1572 failed with stage
in 0 seconds
......@@ -73,8 +73,7 @@
"mknob_steps": "# of steps",
"mknob_steps_tt": "number of dial positions for the knob",
"mknob_size": "size",
"mknob_size_tt": "size of the knob",
"submit_tt": "submit ascii_art to parser"
"mknob_size_tt": "size of the knob"
}
},
"gatom": {
......@@ -279,6 +278,10 @@
},
"canvas": {
"paste_clipboard_prompt": "Warnung: Sie sind dabei, Pd-Code einzufügen, der außerhalb von Pd erstellt wurde. Möchten Sie fortfahren?",
"ascii_art": {
"submit": "Submit Button",
"submit_tt": "submit ascii_art to parser"
},
"save_dialog": {
"prompt": "Speichern der Änderungen in",
"yes": "Ja",
......
......@@ -72,8 +72,7 @@
"mknob_steps": "# of steps",
"mknob_steps_tt": "number of dial positions for the knob",
"mknob_size": "size",
"mknob_size_tt": "size of the knob",
"submit_tt": "submit ascii_art to parser"
"mknob_size_tt": "size of the knob"
}
},
"gatom": {
......@@ -278,6 +277,10 @@
},
"canvas": {
"paste_clipboard_prompt": "Warning: you are about to paste Pd code that came from somewhere outside of Pd. Do you want to continue?",
"ascii_art": {
"submit": "Submit Button",
"submit_tt": "submit ascii_art to parser"
},
"save_dialog": {
"prompt": "Do you want to save the changes you made in",
"yes": "Yes",
......
......@@ -9,7 +9,7 @@
//for tracking connection path
function tracking_connection(curr_row, curr_col, next_row, next_col ,
string_array ,visited_array) {
var next_character,curr_character;
var next_character,curr_character,end_index;
curr_character = string_array[curr_row][curr_col];
next_character = string_array[next_row][next_col];
......@@ -35,7 +35,7 @@ function tracking_connection(curr_row, curr_col, next_row, next_col ,
next_row, next_col-1 , string_array ,visited_array);
}
break;
case "+" : if (character == "|") {
case "+" : if (curr_character == "|") {
if (string_array[next_row][next_col+1] == "-") {
// go in right direction
end_index = tracking_connection( next_row, next_col,
......@@ -45,20 +45,20 @@ function tracking_connection(curr_row, curr_col, next_row, next_col ,
end_index = tracking_connection( next_row, next_col,
next_row, next_col-1 , string_array ,visited_array);
}
} else if (character == "-") {
} else if (curr_character == "-") {
// Character following "+" will be "|" and it point to down direction
end_index = tracking_connection( next_row, next_col,
next_row+1, next_col , string_array ,visited_array);
}
break;
case "X" : if (character == "\\") {
case "X" : if (curr_character == "\\") {
// go bottom right
end_index = tracking_connection(next_row, next_col,
next_row+1, next_col+1 , string_array ,visited_array);
// for the next use of "X"
visited_array[next_row][next_col] = 0;
} else if (character == "/") {
} else if (curr_character == "/") {
end_index = tracking_connection(next_row,next_col,
next_row+1, next_col-1); // go bottom left
visited_array[next_row][next_column] = 0;
......@@ -90,8 +90,7 @@ function parse_ascii_art(ascii_art) {
i,
j,
temp_index,
start_index,
start;
start_index;
string_array.push([]);
visited_array.push([]);
......@@ -101,9 +100,12 @@ function parse_ascii_art(ascii_art) {
for (i = 0, j = 0 ; i < ascii_art.length ; i++, j++) {
var array=[];
//reading the character of string
var temp = ascii_art[i] ;
var temp = ascii_art[i],
array = [],
s_temp,
start;
string_array[row][j]=temp;
visited_array[row][j]=0;
......@@ -115,14 +117,14 @@ function parse_ascii_art(ascii_art) {
visited_array.push([]);
array.push(i);
} else {
temp_index = new INDEX(row, j);
//Start of the object/message
if ((characters_stack.length == 0) && temp == "[") {
characters_stack.push(1);
//to store the start_index of object/msgbox
start_index = temp_index;
start_index = temp_index;
// to slice the string from start to end of object/msgbox
start = i;
state = "invalid";
......@@ -136,7 +138,7 @@ function parse_ascii_art(ascii_art) {
characters_stack.pop();
if (characters_stack.length == 0) {
s_temp = ascii_art.slice(start+1,i-1);
s_temp = ascii_art.slice(start+1,i);
obj_msg_array.push({index1:start_index, index2:temp_index,
type:1, string:s_temp});
state ="valid";
......@@ -146,13 +148,13 @@ function parse_ascii_art(ascii_art) {
characters_stack.pop();
if (characters_stack.length == 0) {
s_temp = ascii_art.slice(start+1,i-1);
s_temp = ascii_art.slice(start+1,i);
obj_msg_array.push({index1:start_index, index2:temp_index,
type:0, string:s_temp});
state = "valid";
}
} else if (temp == "]") {
characters_stack.pop();
state = "invalid";
......@@ -166,10 +168,11 @@ function parse_ascii_art(ascii_art) {
// Finding the connection's end points
for (i = 0 ; i < row ; i++) {
for (j = 0 ; j < string_array[i].length ; j++) {
var flag = 1;
// visited_array to travel a connection path only once
var temp = string_array[i][j];
var temp = string_array[i][j],
flag = 1,
end_index;
if (visited_array[i][j] == 0) {
switch(temp) {
case "|": start_index = new INDEX(i-1, j);
......@@ -195,66 +198,66 @@ function parse_ascii_art(ascii_art) {
// be a single element connection
case "X": start_index = new INDEX(i, j);
end_index = new INDEX(i, j);
visited_array[i][j]=1;
visited_array[i][j] = 1;
break;
default : flag = 0;
visited_array[i][j]=1;
visited_array[i][j] = 1;
break;
}
visited_array[i][j]=1;
visited_array[i][j] = 1;
}
if (flag == 1) {
connections_array.push({index1:start_index, index2:end_index});
}
}
}
//Finding the mapping between connections and Objects/Messages
for (i = 0 ; i< connections_array.length ; i++) {
start_index = connections_array[i].index1;
end_index = connections_array[i].index2;
max_distance1 = Infinity;
max_distance2 = Infinity;
inlet_object_index=0;
outlet_object_index=0;
start_point = 0;
end_point = 0;
state_flag = 0;
var start_index = connections_array[i].index1,
end_index = connections_array[i].index2,
max_distance1 = Infinity,
max_distance2 = Infinity,
inlet_object_index=0,
outlet_object_index=0,
start_point = 0,
end_point = 0,
state_flag = 0;
for (j = 0 ; j < obj_msg_array.length ; j++) {
start = obj_msg_array[j].index1;
end = obj_msg_array[j].index2;
var start = obj_msg_array[j].index1,
end = obj_msg_array[j].index2;
if ( start_index.x == end.x ) {
if ( start_index.x == end.x ) {
if ( Math.min( Math.abs(start_index.y - start.y) ,
Math.abs(start_index.y - end.y) ) < max_distance1 ) {
outlet_object_index=j;
max_distance1 = Math.abs(start_index.y - start.y);
state_flag= state_flag+ 1;
if ( Math.abs(start_index.y - start.y) < Math.abs(start_index.y - end.y) ) {
start_point = 0;
} else {
start_point = 1;
}
outlet_object_index=j;
max_distance1 = Math.abs(start_index.y - start.y);
state_flag= state_flag+ 1;
if ( Math.abs(start_index.y - start.y) < Math.abs(start_index.y - end.y) ) {
start_point = 0;
} else {
start_point = 1;
}
}
}
}
if ( end_index.x == start.x ){
if ( end_index.x == start.x ){
if ( Math.min( Math.abs(end_index.y - start.y) ,
Math.abs(end_index.y - end.y) ) < max_distance2 ) {
inlet_object_index=j;
max_distance2 = Math.abs(end_index.y - end.y);
state_flag= state_flag+ 1;
if ( Math.abs(start_index.y - start.y) < Math.abs(start_index.y - end.y) ) {
end_point = 0;
} else {
end_point = 1;
inlet_object_index=j;
max_distance2 = Math.abs(end_index.y - end.y);
state_flag= state_flag+ 1;
if ( Math.abs(start_index.y - start.y) < Math.abs(start_index.y - end.y) ) {
end_point = 0;
} else {
end_point = 1;
}
}
}
}
}
......@@ -262,41 +265,40 @@ function parse_ascii_art(ascii_art) {
{
state= "valid";
} else {
state = "invalid"
state = "invalid";
}
objects_connections_map.push({start_object:outlet_object_index,
end_object:inlet_object_index,
start_point:start_point,
end_point:end_point});
}
var pd_message = "";
var pd_message = "#N Canvas 400 800 12";
for ( i = 0; i < obj_msg_array.length ; i++) {
type = obj_msg_array[i].type;
x1 = obj_msg_array[i].index1.x;
y1 = obj_msg_array[i].index1.y;
str = obj_msg_array[i].string;
var type = obj_msg_array[i].type,
x1 = obj_msg_array[i].index1.x,
y1 = obj_msg_array[i].index1.y,
str = obj_msg_array[i].string;
str.replace(";\n"," ");
point_x = y1*20 + 100;
point_y = x1*20 + 50;
point_x = point_x.toString();
var point_x = y1*20 + 100,
point_y = x1*20 + 50;
point_x = point_x.toString(),
point_y = point_y.toString();
if ( type == 1 ) {
pd_message = pd_message + "#X obj " + point_x + " " + point_y + " " + str + ";\n";
} else {
pd_message = pd_message + "#X msg " + point_x + " " + point_y + " " + str + ";\n";
}
}
for (i = 0; i < objects_connections_map.length ; i++) {
str= "#X connect " + objects_connections_map[i].start_object + " "
+ objects_connections_map[i].start_point + " "
......@@ -304,8 +306,7 @@ function parse_ascii_art(ascii_art) {
+ objects_connections_map[i].end_point + ";\n";
pd_message = pd_message + str;
}
alert(pd_message);
var parser_data = {pd_message:pd_message,
state:state};
return parser_data;
......
......@@ -431,8 +431,8 @@ var canvas_events = (function() {
var art = document.getElementById("ascii_art_text_area").value;
var parsed_art = pd_ascii_art.parse_ascii_art(art);
// to check the create pd_message
document.getElementById("ascii_art_text_area").innerHTML = parsed_art.pd_message;
canvas_events[canvas_events.get_previous_state()]();
document.getElementById("ascii_art_text_area").innerHTML = parsed_art.pd_message;
canvas_events[canvas_events.get_previous_state()]();
},
scalar_draggable_mousemove: function(evt) {
var new_x = evt.pageX,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment