public draw_gates(Form2 f, System.Drawing.Graphics g, int zoom, object_property std_img_size, System.Reflection.Assembly myAssembly, int nor_of_rows, int n_ip) { this.f = f; int cur_row = 0; int max_right_pad = 0; gate.n_or = 0; simplify_expression se = new simplify_expression(f.logical_exp); foreach (String val in se.str.Split(',')) { draw_gate_row.list.Clear(); draw_gate_row dgr = new draw_gate_row(f, g, zoom, std_img_size, myAssembly, nor_of_rows, n_ip, val, cur_row); if (object_property.panel_width > max_right_pad) { max_right_pad = object_property.panel_width; } cur_row = dgr.nor_of_row_taken; } if (f.panel1.Width != max_right_pad + 400) { f.panel1.Width = max_right_pad + 400; f.ckt_refresh(); } }
private void draw_Gates(int zoom, System.Reflection.Assembly myAssembly, System.Drawing.Graphics g) { object_property std_img_size2 = new object_property(); std_img_size2.width = 50 + zoom; std_img_size2.height = 60 + zoom; std_img_size2.width_adj = 150 + zoom; std_img_size2.height_adj = 63 + zoom; draw_gates dg = new draw_gates(this, g, zoom, std_img_size2, myAssembly, nor_of_rows, n_ip); }
private void draw_line(int zoom, System.Reflection.Assembly myAssembly, System.Drawing.Graphics g) { object_property std_img_size = new object_property(); std_img_size.x = 20; std_img_size.y = 20; std_img_size.width = 50; std_img_size.height = 60; std_img_size.x_adj = -108; std_img_size.y_adj = 0; std_img_size.width_adj = 0; std_img_size.height_adj = 0; int input_space = 50 + zoom; draw_ip_lines ip_l = new draw_ip_lines(this, g, zoom, std_img_size, myAssembly, nor_of_rows, n_ip, input_space); }
public draw_ip_lines(Form2 f, System.Drawing.Graphics g, int zoom, object_property std_img_size, System.Reflection.Assembly myAssembly, int nor_of_rows, int n_ip, int v_gap = 60, int h_gap = 40) { this.f = f; this.g = g; this.nor_of_rows = nor_of_rows; this.n_ip = n_ip; _x = std_img_size.x; _y = std_img_size.y; this.zoom = zoom; this.myAssembly = myAssembly; this.std_img_size = std_img_size; imageHeight = std_img_size.height + zoom; //line gap imageWidth = std_img_size.width + zoom; width_gap = std_img_size.width + zoom + h_gap; //primary top level gap starting_top_gap = imageHeight / 4 + _y; //generating grids for not gates sum = starting_top_gap; not_gate_sapce = imageHeight / 2 + sum; //generating grids for horizontal ckt_input lines px_row = new object_property[nor_of_rows]; for (int i = 0; i < nor_of_rows; i++) { sum += imageHeight + v_gap; px_row[i] = new object_property(); px_row[i].x = _x; px_row[i].y = sum; } //normal input line depth is total depth total_depth = sum + imageHeight + v_gap; draw_inputs(); for (int j = 0; j < n_ip * 2; j++) { for (int i = 0; i < nor_of_rows; i++) { px_row[i].x = px_ip_points[j].x; if (object_property.test_mode) { if (j % 2 == 0) { draw_point(px_row[i].x, px_row[i].y); } } } } }
public gate(Form2 f, System.Drawing.Graphics g, int zoom, object_property std_img_size, System.Reflection.Assembly myAssembly, int nor_of_rows, int n_ip, String gate, String cur, int x, int y, int n_gate_ip, String gate_name, IList <String> from, int level, int belongs, int is_line = -1) { px_gate.width = img_width = std_img_size.width; px_gate.height = img_height = std_img_size.height; px_gate.px_ip = new int[n_gate_ip]; px_gate.gate_name = gate_name; this.level = level; top_side += new gate_property(img_height, n_gate_ip).single_side_height; int ip_gap = new gate_property(img_height, n_gate_ip).ip_gap; px_gate.ip_label = new String[n_gate_ip]; for (int i = 0; i < n_gate_ip; i++) { px_gate.px_ip[i] = top_side + y + ip_gap * i + 1; // draw_point d = new draw_point(f, g, zoom, x, px_gate.px_ip[i], System.Drawing.Color.Blue); } label = px_gate.label1 = gate; px_gate.label2 = cur; px_gate.belongs = belongs; px_gate.x = x; px_gate.y = y; px_gate.px_op[0] = x + img_width; px_gate.px_op[1] = y + img_height / 2; if (is_line == -1) { //drawing gate image px_gate.ip_label = from.ToArray(); draw_image di = new draw_image(g, myAssembly, gate_name + ".png", px_gate.x, px_gate.y, img_width, img_height, 0, true); } else { //drawing bypass line px_gate.ip_label[2] = from[0]; new draw_elbow(f, g, px_gate.x, px_gate.px_ip[is_line], px_gate.px_op[0], px_gate.px_op[1]); } label = Regex.Replace(label, "_[0-9]+", "_"); new draw_string(n_gate_ip + "-" + gate_name.ToUpper() + " " + label, g, x + 10, y + img_height, System.Drawing.Color.Red); Log.write_log("\n" + n_gate_ip + gate_name + " " + px_gate.label1 + "," + (x + 10) + "," + (y + img_height + 5) + "," + "Green\n"); }
public void draw_inputs() { //draw normal input line x1 = x2 = _x; y1 = _y; y2 = _y + total_depth; int x_gap_prev = _x; px_ip_points = new object_property[n_ip * 2]; for (int i = 0; i < n_ip; i++) { x_gap_prev = x2; y1 = _y; y2 = _y + total_depth; g.DrawLine(new Pen(Color.Brown, 1), new Point(x1, y1), new Point(x2, y2)); x1 += width_gap; x2 = x1; y1 = _y + starting_top_gap; g.DrawLine(new Pen(Color.Brown, 1), new Point(x1, y1), new Point(x2, y2)); g.DrawLine(new Pen(Color.Brown, 1), new Point(x_gap_prev, y1), new Point(x2, y1)); //getting row-col points px_ip_points[i + i] = new object_property(); px_ip_points[i + i].x = x_gap_prev; px_ip_points[i + i + 1] = new object_property(); px_ip_points[i + i + 1].x = x2; px_ip_points[i + i].label1 = new characters().letter[i].ToString(); px_ip_points[i + i + 1].label1 = new characters().letter[i].ToString() + "'"; place_gates(x2 + std_img_size.x_adj + zoom - zoom / 2, not_gate_sapce, std_img_size.width + zoom, std_img_size.height + zoom); //Assigning input letter to column new draw_string(px_ip_points[i + i].label1, g, x_gap_prev, _y - 15, System.Drawing.Color.Blue, 15); new draw_string(px_ip_points[i + i + 1].label1, g, x2, y1 - 5 - 15, System.Drawing.Color.Blue, 15); x1 += width_gap; x2 = x1; } f.panel1.Size = new Size(f.panel1.Size.Width, y2 + ((sum - not_gate_sapce) / nor_of_rows) / 2); }
public draw_gate_row(Form2 f, System.Drawing.Graphics g, int zoom, object_property std_img_size, System.Reflection.Assembly myAssembly, int nor_of_rows, int n_ip, String exp, int cur_row) { this.f = f; //getting grouped gates seperated by @ symbol divide_gates_for_row dgfr = new divide_gates_for_row(exp); gates = dgfr.gates; int max_row = 0; int i, j; i = j = 0; //inner_gate_max_x_axis = igad.inner_gate_max_x_axis; int cur_row2 = 0; cur_row2 += cur_row; int max_level = 0; gate_mat[,] gm_or = null; int nor_of_row_taken_or = gates.Split('+').Length; int col_or = 0, row_or = nor_of_row_taken_or; while (row_or != 2 && row_or != 3 && nor_of_row_taken_or != 1) { row_or = (row_or / 3) + (row_or % 3); col_or++; } col_or += 2; gm_or = new gate_mat[col_or, nor_of_row_taken_or]; String temp_or_str = ""; String[] temp_or = new String[col_or + 1]; //drawing gates gate_mat[,] gm = null; int belongs = 0; //spliting each gate foreach (String value in gates.Split('+')) { String temp_str = "", temp_str2 = "", val = ""; int completed = 0; val = value; if (gates.Split('+').Length != 1) { if (value[value.Length - 1] == '@') { val = value.Remove(value.Length - 1, 1); } } //simlifing gate that has more than 3 inputs int nor_of_row_taken2 = val.Split('@').Length; int col = 0, row = nor_of_row_taken2; while (row != 2 && row != 3 && nor_of_row_taken2 != 1) { row = (row / 3) + (row % 3); col++; } col += 2; gm = new gate_mat[col, nor_of_row_taken2]; String[] temp = new String[col + 1]; foreach (String v in val.Split('@')) { if (v == null) { continue; } temp[0] = add_str.add(temp[0], v, "_1"); } String[] str = val.Split('@'); int len = str.Length; j = 0; for (i = 0; i < len; i++) { if (Regex.IsMatch(str[i], "[(].+[)]")) { str[i] = str[i].Substring(1, str[i].Length - 2); } gm[j, i] = new gate_mat(); gm[j, i].cur = str[i]; gm[j, i].gate = str[i]; gm[j, i].level = 0; foreach (String s in str[i].Split('.')) { gm[j, i].from.Add(s); } foreach (String s in str[i].Split('ʘ')) { gm[j, i].from.Add(s); } } max_gate = 1; str = null; int k = 0; if (len != 1) { for (j = 1; j < col; j++) { k = 0; gm[j, k] = new gate_mat(); str = Regex.Split(temp[j - 1], "_" + j); len = str.Length; temp[j] = temp_str = temp_str2 = ""; if (len != 1) { for (i = 0; i < len; i++) { if ((i + 1) % 3 == 0 || (len % 3 != 0 && i == len - 1)) { temp_str = add_str.add(temp_str, str[i], "_" + j); temp_str2 += "(" + str[i] + ")"; temp[j] = add_str.add(temp[j], temp_str, "_" + (j + 1)); gm[j, k].from.Add(str[i]); //foreach (String ss in gm[j, k].from) // f.richTextBox1.AppendText("\n--from" + ss + "\n"); gm[j, k].cur = temp_str; gm[j, k].gate = temp_str2; temp_str = temp_str2 = ""; gm[j, k].level = j; k++; gm[j, k] = new gate_mat(); max_gate++; } else { gm[j, k].from.Add(str[i]); temp_str = add_str.add(temp_str, str[i], "_" + j); temp_str2 += "(" + str[i] + ")"; } max_row++; } } if (len == 1) { break; } } } f.richTextBox1.AppendText("\n"); String last_gate = ""; for (i = 0; i < col; i++) { for (j = 0; j < nor_of_row_taken2; j++) { if (gm[i, j] == null || gm[i, j].cur == "") { continue; } Log.write_log("-inner gates-" + "[" + j + "][" + i + "]" + gm[i, j].cur); new identify_gate_and_draw(f, g, zoom, std_img_size, myAssembly, nor_of_rows, n_ip, gm[i, j].gate, j, i, cur_row2, (max_row + gates.Split('+').Length), ++completed, gm[i, j].from, gm[i, j].cur, gm[i, j].level, belongs); if (gm[i, j].level > max_level) { max_level = gm[i, j].level; } last_gate = gm[i, j].cur; f.richTextBox1.AppendText("\n"); } } cur_row2 += nor_of_row_taken2; belongs++; temp_or_str = add_str.add(temp_or_str, last_gate, '+'); } nor_of_row_taken = cur_row2; //simlifing OR gate that has more than 3 inputs max_gate = 0; string replace = "__1"; temp_or_str = Regex.Replace(temp_or_str, "[+]", replace); temp_or[0] = temp_or_str; String[] str_or = Regex.Split(temp_or_str, replace); int len2 = str_or.Length; str_or = null; String temp_str_or = "", temp_str2_or = ""; int kk = 0; if (len2 != 1) { for (j = 1; j < col_or; j++) { kk = 0; gm_or[j, kk] = new gate_mat(); str_or = Regex.Split(temp_or[j - 1], "__" + j); len2 = str_or.Length; temp_or[j] = temp_str_or = temp_str2_or = ""; for (i = 0; i < len2; i++) { if ((i + 1) % 3 == 0 || (len2 % 3 != 0 && i == len2 - 1)) { temp_str_or = add_str.add(temp_str_or, str_or[i], "__" + j); temp_str2_or = add_str.add(temp_str2_or, "(" + str_or[i] + ")", '+'); temp_or[j] = add_str.add(temp_or[j], temp_str_or, "__" + (j + 1)); gm_or[j, kk].from.Add(str_or[i]); gm_or[j, kk].cur = temp_str_or; gm_or[j, kk].gate = temp_str2_or; temp_str_or = temp_str2_or = ""; gm_or[j, kk].level = j; kk++; gm_or[j, kk] = new gate_mat(); max_gate++; } else { gm_or[j, kk].from.Add(str_or[i]); temp_str_or = add_str.add(temp_str_or, str_or[i], "__" + j); temp_str2_or = add_str.add(temp_str2_or, "(" + str_or[i] + ")", '+'); } } if (len2 == 1) { break; } } } //drawing OR gate int completed2 = 0; for (i = 0; i < col_or; i++) { for (j = 0; j < nor_of_row_taken_or; j++) { if (gm_or[i, j] == null || gm_or[i, j].cur == "") { continue; } Log.write_log("-outer gates-" + "[" + j + "][" + i + "]" + gm_or[i, j].cur); new identify_gate_and_draw(f, g, zoom, std_img_size, myAssembly, nor_of_rows, n_ip, gm_or[i, j].gate, j, i + max_level, cur_row, max_gate, ++completed2, gm_or[i, j].from, gm_or[i, j].cur, gm_or[i, j].level + max_level, belongs, max_level, true); } } //connecting respective gates foreach (gate gt1 in draw_gate_row.list) { foreach (gate gt2 in draw_gate_row.list) { if (gt1.px_gate.label1 == gt2.px_gate.label1 || gt1.level > gt2.level) { continue; } if (gt2.px_gate.gate_name == "or" && (gt1.or_gate_pos == -1 && gt2.or_gate_pos > 1)) { continue; } if (gt2.px_gate.gate_name != "or" && (Math.Abs(gt2.level - gt1.level) > 1)) { continue; } if (gt2.px_gate.gate_name != "or") { if ((Math.Abs(gt2.level - gt1.level) > 1 && (gt2.px_gate.gate_name != "direct" ^ gt1.px_gate.gate_name != "direct")) || (gt2.px_gate.gate_name != "direct" && gt1.px_gate.belongs != gt2.px_gate.belongs)) { continue; } } if (gt1.px_gate.gate_name == "direct" && gt2.px_gate.gate_name == "direct" && gt1.px_gate.belongs != gt2.px_gate.belongs) { continue; } try { if (Regex.IsMatch(gt1.px_gate.label2, "^" + gt2.px_gate.ip_label[0] + "$")) { new draw_elbow(f, g, gt1.px_gate.px_op[0], gt1.px_gate.px_op[1], gt2.px_gate.x, gt2.px_gate.px_ip[0]); } } catch (Exception) { } try{ if (Regex.IsMatch(gt1.px_gate.label2, "^" + gt2.px_gate.ip_label[1] + "$")) { new draw_elbow(f, g, gt1.px_gate.px_op[0], gt1.px_gate.px_op[1], gt2.px_gate.x, gt2.px_gate.px_ip[1]); } } catch (Exception) { } try { if (Regex.IsMatch(gt1.px_gate.label2, "^" + gt2.px_gate.ip_label[2] + "$")) { new draw_elbow(f, g, gt1.px_gate.px_op[0], gt1.px_gate.px_op[1], gt2.px_gate.x, gt2.px_gate.px_ip[2]); } } catch (Exception) {} } } }
public identify_gate_and_draw(Form2 f, System.Drawing.Graphics g, int zoom, object_property std_img_size, System.Reflection.Assembly myAssembly, int nor_of_rows, int n_ip, String gate, int r, int c, int cur_row, int max_row, int completed, IList <String> from, String cur, int level, int belongs, int or_gate_pos = -1, bool is_it_or = false) { this.cur_row = cur_row; this.max_row = max_row; this.completed = completed; r += cur_row; this.f = f; this.g = g; if ((c - or_gate_pos) != -1) { or_gate_pos = c - or_gate_pos; } px_row = draw_ip_lines.px_row; if (px_row.Length > n_ip - 1) { x = (c + 1) * std_img_size.width_adj + px_row[n_ip - 1].x; } else { x = (c + 1) * std_img_size.width_adj + px_row[px_row.Length - 1].x; } if (px_row.Length > r) { y = px_row[r].y; } else { y = px_row[px_row.Length - 1].y; } f.richTextBox1.AppendText("\ncur_row" + cur_row + " max_row-" + max_row + " completed" + completed); Log.write_log("\n" + is_it_or + " cur_row" + cur_row + " max_row-" + max_row + " completed" + completed); f.richTextBox1.AppendText("\nPosition: row-" + r + ",col-" + c + "=" + gate + "\n"); Log.write_log("\nPosition: row-" + r + ",col-" + c + "=" + gate); Log.write_log("\nAxis: row-" + x + ",col-" + y + "=" + gate); Log.write_log("\nlevel:" + level + "belongs" + belongs + "\n\n"); if (object_property.test_mode) { new draw_point(f, g, zoom, x, y, System.Drawing.Color.Blue); } gate gt = null; String pattern0 = "[(]+[A-Z._0-9\'ʘ]+[)]+[+]"; String pattern1 = "[(]+[A-Z._0-9\'ʘ]+[)]+"; String pattern2 = "[(]+[A-Z._0-9\']+[)]+ʘ"; String pattern4_1 = "[(]+[A-Z._0-9\'ʘ]+[)]+"; //gate recognation if (Regex.IsMatch(gate, "^" + pattern1 + "$", RegexOptions.IgnoreCase) || Regex.IsMatch(gate, "^[A-Z]\'?$", RegexOptions.IgnoreCase)) { f.richTextBox1.AppendText("0single input : " + gate); Log.write_log("0single input : " + gate); gt = new gate(f, g, zoom, std_img_size, myAssembly, nor_of_rows, n_ip, gate, cur, x, y, 3, "direct", from, level, belongs, 2); gt.or_gate_pos = or_gate_pos; } if (Regex.IsMatch(gate, "^(" + pattern4_1 + "){2}$", RegexOptions.IgnoreCase)) { f.richTextBox1.AppendText("2-AND Gate: " + gate); Log.write_log("2-AND Gate: " + gate); gt = new gate(f, g, zoom, std_img_size, myAssembly, nor_of_rows, n_ip, gate, cur, x, y, 2, "and", from, level, belongs); } if (Regex.IsMatch(gate, "^(" + pattern4_1 + "){3}$", RegexOptions.IgnoreCase)) { f.richTextBox1.AppendText("3-AND Gate: " + gate); Log.write_log("3-AND Gate: " + gate); gt = new gate(f, g, zoom, std_img_size, myAssembly, nor_of_rows, n_ip, gate, cur, x, y, 3, "and", from, level, belongs); } if (Regex.IsMatch(gate, "^" + pattern2 + pattern1 + "$", RegexOptions.IgnoreCase)) { f.richTextBox1.AppendText("2-XOR Gate: " + gate); Log.write_log("2-XOR Gate: " + gate); gt = new gate(f, g, zoom, std_img_size, myAssembly, nor_of_rows, n_ip, gate, cur, x, y, 2, "xor", from, level, belongs); } if (Regex.IsMatch(gate, "^(" + pattern2 + "){2}" + pattern1 + "$", RegexOptions.IgnoreCase)) { f.richTextBox1.AppendText("3-XOR Gate: " + gate); Log.write_log("3-XOR Gate: " + gate); gt = new gate(f, g, zoom, std_img_size, myAssembly, nor_of_rows, n_ip, gate, cur, x, y, 3, "xor", from, level, belongs); } if (Regex.IsMatch(gate, "^" + pattern0 + pattern1 + "$", RegexOptions.IgnoreCase)) { f.richTextBox1.AppendText("2-OR Gate: " + gate); Log.write_log("2-OR Gate: " + gate); gt = new gate(f, g, zoom, std_img_size, myAssembly, nor_of_rows, n_ip, gate, cur, x, y, 2, "or", from, level, belongs); gt.or_gate_pos = or_gate_pos; } if (Regex.IsMatch(gate, "^(" + pattern0 + "){2}" + pattern1 + "$", RegexOptions.IgnoreCase)) { f.richTextBox1.AppendText("3-OR Gate: " + gate); Log.write_log("3-OR Gate: " + gate); gt = new gate(f, g, zoom, std_img_size, myAssembly, nor_of_rows, n_ip, gate, cur, x, y, 3, "or", from, level, belongs); gt.or_gate_pos = or_gate_pos; } if (Regex.IsMatch(gate, "^[A-Z]\'?[.][A-Z]\'?$", RegexOptions.IgnoreCase)) { f.richTextBox1.AppendText("2-AND Gate: " + gate); Log.write_log("2-AND Gate: " + gate); gt = new gate(f, g, zoom, std_img_size, myAssembly, nor_of_rows, n_ip, gate, cur, x, y, 2, "and", from, level, belongs); } if (Regex.IsMatch(gate, "^[A-Z]\'?[.][A-Z]\'?[.][A-Z]\'?$", RegexOptions.IgnoreCase)) { f.richTextBox1.AppendText("3-AND Gate: " + gate); Log.write_log("3-AND Gate: " + gate); gt = new gate(f, g, zoom, std_img_size, myAssembly, nor_of_rows, n_ip, cur, gate, x, y, 3, "and", from, level, belongs); } if (Regex.IsMatch(gate, "^[A-Z]ʘ[A-Z]$", RegexOptions.IgnoreCase) || Regex.IsMatch(gate, "^[(][A-Z]ʘ[A-Z][)]$", RegexOptions.IgnoreCase)) { f.richTextBox1.AppendText("2-XOR Gate: " + gate); Log.write_log("2-XOR Gate: " + gate); gt = new gate(f, g, zoom, std_img_size, myAssembly, nor_of_rows, n_ip, gate, cur, x, y, 2, "xor", from, level, belongs); } if (Regex.IsMatch(gate, "^[A-Z]ʘ[A-Z]ʘ[A-Z]$", RegexOptions.IgnoreCase) || Regex.IsMatch(gate, "^[(][A-Z]ʘ[A-Z]ʘ[A-Z][)]$", RegexOptions.IgnoreCase)) { f.richTextBox1.AppendText("3-XOR Gate: " + gate); Log.write_log("3-XOR Gate: " + gate); gt = new gate(f, g, zoom, std_img_size, myAssembly, nor_of_rows, n_ip, gate, cur, x, y, 3, "xor", from, level, belongs); } if (gt != null) { if (object_property.test_mode) { new draw_string(cur + " P:" + gt.or_gate_pos + " B:" + belongs + " L:" + level, g, x + 10, y - 15, System.Drawing.Color.Green); } connect_gate(gt, c); } }