private void CreareNod(int index, float x, float y) { counter = counter + 1; //incrementam numarul de noduri (porti logice) ShapeNode nod = diagram1.Factory.CreateShapeNode(x - 16, y - 16, 70, 70); // pozitia x, pozitia y, latima, inaltimea nod.Transparent = true; nod.EnabledHandles = AdjustmentHandles.Move; //sa se poata muta nodu pe diagrama fara a fi schimbata dimensiunea nodului nod.Tag = index + "|" + counter.ToString(); // tagu contine indexul porti logice din listview1 si numarul de la counter nod.ImageAlign = MindFusion.Drawing.ImageAlign.TopLeft; nod.TextFormat.Alignment = StringAlignment.Center; nod.TextFormat.LineAlignment = StringAlignment.Far; nod.AnchorPattern = PoartaLogica.Ancorare(index); // daca modificam dimensiunea 70, 70 trebuie modificate si puncetele de ancorare //setam imaginea si textul pentru nod (poarta logica) if (index == 0) //AND { nod.Image = imageList1.Images[0]; nod.Text = "AND"; } else if (index == 1) //OR { nod.Image = imageList1.Images[1]; nod.Text = "OR"; } else if (index == 2) //XOR { nod.Image = imageList1.Images[2]; nod.Text = "XOR"; } else if (index == 3) //NOT { nod.Image = imageList1.Images[3]; nod.Text = "NOT"; } else if (index == 4) //INPUT 0 { nod.Image = imageList1.Images[4]; nod.Text = labelCounter + "#IN: 0"; labelCounter = labelCounter + 1; } else if (index == 5) //INPUT 1 { nod.Image = imageList1.Images[5]; nod.Text = labelCounter + "#IN: 1"; labelCounter = labelCounter + 1; } else if (index == 6) //terminator { nod.Image = imageList1.Images[6]; nod.Text = "OUTPUT"; } }
private void generareRezultatToolStripMenuItem_Click(object sender, EventArgs e) { bool check = false; dt = null; dt = PoartaLogica.CreareTemplateDataTable(); //creare template tabela if (diagram1.Nodes.Count > 0) { foreach (ShapeNode sN in diagram1.Nodes) //parcurgem nodurile din diagrama { string[] f = sN.Tag.ToString().Split('|'); // tagu contine tip poarta | counter (ID) DiagramLinkCollection inputAnchorLinks = sN.IncomingLinks; //numarul de input intr-o poarta logica DiagramLinkCollection outputAnchorLinks = sN.OutgoingLinks; //numarul de output dintr-o poarta logica if (PoartaLogica.VerificareLegaturi(Int32.Parse(f[0]), inputAnchorLinks.Count, outputAnchorLinks.Count) == true) //verificam daca poarta logica este adecvat conectata { check = true; //incarcam diagrama intr-un DataTable DataRow dr = dt.NewRow(); if (inputAnchorLinks.Count == 0) //INPUT Gates { dr["FirstSourceID"] = "Inexistent"; dr["SecondSourceID"] = "Inexistent"; dr["FirstSourceType"] = "Inexistent"; dr["SecondSourceType"] = "Inexistent"; dr["InputID"] = sN.Text.Substring(0, 1); } else if (inputAnchorLinks.Count == 1) //OUTPUT & NOT Gates { string[] f1 = inputAnchorLinks[0].Origin.Tag.ToString().Split('|'); dr["FirstSourceID"] = f1[1]; dr["SecondSourceID"] = "Inexistent"; dr["FirstSourceType"] = f1[0]; dr["SecondSourceType"] = "Inexistent"; } else if (inputAnchorLinks.Count == 2) //AND, OR, XOR Gates { string[] f1 = inputAnchorLinks[0].Origin.Tag.ToString().Split('|'); string[] f2 = inputAnchorLinks[1].Origin.Tag.ToString().Split('|'); dr["FirstSourceID"] = f1[1]; dr["SecondSourceID"] = f2[1]; dr["FirstSourceType"] = f1[0]; dr["SecondSourceType"] = f2[0]; } if (outputAnchorLinks.Count == 0) //OUTPUT Gate { dr["DestinationID"] = "Inexistent"; dr["DestinationType"] = "Inexistent"; } else if (outputAnchorLinks.Count == 1) //ALL Gates expect OUTPUT { string[] f1 = outputAnchorLinks[0].Destination.Tag.ToString().Split('|'); dr["DestinationID"] = f1[1]; dr["DestinationType"] = f1[0]; } dr["CurrentID"] = f[1]; dr["CurrentType"] = f[0]; dr["OutputResult"] = "Server"; dr["FirstInput"] = "Server"; dr["SecondInput"] = "Server"; dr["GateName"] = sN.Text; dt.Rows.Add(dr); } else { check = false; MessageBox.Show("Circuitul logic este incorect! Verificati daca toate portile logice sunt conectate adecvat.", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } } //test //Form3 form3 = new Form3(dt); //form3.ShowDialog(); // if (check == true) { //Convertare DataSet - DataTable in byte[] BinaryFormatter bFormatter = new BinaryFormatter(); MemoryStream stream = new MemoryStream(); dt.RemotingFormat = SerializationFormat.Binary; bFormatter.Serialize(stream, dt); byte[] b = stream.ToArray(); stream.Close(); //trimiterea pe server /*ClientSocket.Poll returns true if: * connection is closed, reset, terminated or pending (meaning no active connection) * connection is active and there is data available for reading * ClientSocket.Available returns number of bytes available for reading * If both are true: * there is no data available to read so connection is not active */ if (ClientSocket.Poll(1000, SelectMode.SelectRead) && ClientSocket.Available == 0) { MessageBox.Show("Serverul nu este activ: " + "An existing connection was forcibly closed by the remote host"); conectareLaServerToolStripMenuItem.Enabled = true; conectareLaServerToolStripMenuItem.Visible = true; } else { ClientSocket.Send(b, 0, b.Length, SocketFlags.None); conectareLaServerToolStripMenuItem.Enabled = false; conectareLaServerToolStripMenuItem.Visible = false; //citirea de pe server //string rez = null; //byte[] rezultat = new byte[1024]; //int size = ClientSocket.Receive(rezultat); //rez = "Rezultatul generat: " + Encoding.ASCII.GetString(rezultat, 0, size); NetworkStream nStream = new NetworkStream(ClientSocket); byte[] rezultat = ReadToEnd(nStream); nStream.Close(); DataTable dt2 = null; stream = new MemoryStream(rezultat); if (stream.Length != 0) { dt2 = (DataTable)bFormatter.Deserialize(stream); } stream.Close(); if (dt2 != null) { Form3 form3 = new Form3(dt2); form3.ShowDialog(); } } } } else { MessageBox.Show("Nu se poate genera un rezultat daca portile logice si legaturile lor nu au fost plasate in diagrama.", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }