public WSNCanvas Duplicate() { WSNCanvas duplicate = new WSNCanvas(); duplicate.LoadFromXml(this.Clone()); duplicate.Node.Text = this.Node.Text + "-Copy"; bool nameExist = true; while (nameExist) { nameExist = false; foreach (TreeNode node in this.Node.Parent.Nodes) { if (node.Text.Equals(duplicate.Node.Text, StringComparison.CurrentCultureIgnoreCase)) { duplicate.Node.Text = duplicate.Node.Text + "-Copy"; nameExist = true; break; } } } return(duplicate); }
public WSNCanvas Duplicate() { WSNCanvas duplicate = new WSNCanvas(); duplicate.LoadFromXml(this.Clone()); duplicate.Node.Text = this.Node.Text + "-Copy"; bool nameExist = true; while (nameExist) { nameExist = false; foreach (TreeNode node in this.Node.Parent.Nodes) { if (node.Text.Equals(duplicate.Node.Text, StringComparison.CurrentCultureIgnoreCase)) { duplicate.Node.Text = duplicate.Node.Text + "-Copy"; nameExist = true; break; } } } return duplicate; }
/// <summary> /// Load model from XML string /// </summary> /// <param name="xml"></param> /// <param name="PNDocRes"></param> /// <returns></returns> public static WSNModel LoadModelFromXML(string xml, XmlDocument PNDocRes) { WSNModel model = new WSNModel(); do { XmlDocument doc = new XmlDocument(); try { doc.LoadXml(xml); } catch { } XmlNodeList nodes = null; do { nodes = doc.GetElementsByTagName(XmlTag.TAG_DECLARATION); if (nodes == null || nodes.Count != 1) { break; } model.Declaration = nodes.Item(0).InnerText; } while (false); do { nodes = doc.GetElementsByTagName(XmlTag.TAG_NETWORK); if (nodes == null) { break; } // mlqvu -- load attributes for network tag XmlNode firstNetworkNode = nodes[0]; if (firstNetworkNode == null) { break; } if (model.mExtendInfo == null) { model.mExtendInfo = new WSNExtendInfo(); } try { String noID = firstNetworkNode.Attributes[XmlTag.ATTR_mID].Value; model.mExtendInfo.mID = long.Parse(noID); String noPacket = firstNetworkNode.Attributes[XmlTag.ATTR_NUMOFPACKETS].Value; model.mExtendInfo.mNumberPacket = Int32.Parse(noPacket); String noSensor = firstNetworkNode.Attributes[XmlTag.ATTR_NUMOFSENSORS].Value; model.mExtendInfo.mNumberSensor = Int32.Parse(noSensor); String maxSensorBufferSize = firstNetworkNode.Attributes[XmlTag.ATTR_SENSOR_MAX_BUFFER_SIZE].Value; model.mExtendInfo.mSensorMaxBufferSize = Int32.Parse(maxSensorBufferSize); String maxSensorQueueSize = firstNetworkNode.Attributes[XmlTag.ATTR_SENSOR_MAX_QUEUE_SIZE].Value; model.mExtendInfo.mSensorMaxQueueSize = Int32.Parse(maxSensorQueueSize); String maxChannelBufferSize = firstNetworkNode.Attributes[XmlTag.ATTR_CHANNEL_MAX_BUFFER_SIZE].Value; model.mExtendInfo.mChannelMaxBufferSize = Int32.Parse(maxChannelBufferSize); } catch (Exception e) { } LTSCanvas canvas = null; foreach (XmlElement node in nodes[0].ChildNodes) { canvas = new WSNCanvas(node.GetAttribute(XmlTag.ATTR_NAME)); canvas.LoadFromXml(node); model.Processes.Add(canvas); } } while (false); } while (false); return(model); }
/// <summary> /// Combine code for receive place on abstract sensor /// </summary> /// <param name="canvas">Canvas contain sensor/channel item</param> /// <param name="places">places list</param> /// <param name="channels">channel list</param> /// <param name="sensors">sensor list</param> /// <param name="ws">sensor item</param> /// <param name="transition">trans contain channels instance</param> /// <param name="isSensorAbstract">mark sensor abstract</param> /// <param name="isChannelAbstract">mark channel abstract</param> public static void embedReceiveAbstractSensor(WSNCanvas canvas, IList<WSNChannel> channels, WSNSensor ws, XmlElement transition) { switch (ws.NodeType) { case SensorType.Source: setXmlNodeData(transition, "Guard", GBK_SENSOR_SOURCE_TRANSITION_BROADCASTING); setXmlNodeData(transition, "Program", initSensorSource(channels, ws.ID)); break; case SensorType.Intermediate: setXmlNodeData(transition, "Guard", String.Format(GBK_SENSOR_INTER_TRANSITION_BROADCASTING, ws.ID)); setXmlNodeData(transition, "Program", initSensorAbstractSend(channels, ws.ID)); break; default: break; } }
public PNGenerationHelper buildHelperAfterCluster(String newFileName) { PNGenerationHelper helper = null; do { if (CurrentActiveTab is WSNTabItem) { helper = new PNGenerationHelper(newFileName, CurrentActiveTab); break; } if ((CurrentActiveTab is PNTabItem) == false) break; XmlDocument pnDoc = new XmlDocument(); try { pnDoc.Load(CurrentActiveTab.FileName); } catch { MessageBox.Show("Error when reading PN file!"); } IList<WSNCanvas> listCanvas = new List<WSNCanvas>(); KWSNGenerationHelper tempHelper = new KWSNGenerationHelper(newFileName, CurrentActiveTab); XmlDocument doc = tempHelper.GenerateXML(); XmlElement wsnNode = doc.ChildNodes[0] as XmlElement; XmlElement networkNode = wsnNode.GetElementsByTagName(XmlTag.TAG_NETWORK)[0] as XmlElement; foreach (XmlElement process in networkNode.ChildNodes) { WSNCanvas kCanvas = new WSNCanvas(process.GetAttribute(XmlTag.ATTR_NAME)); kCanvas.LoadFromXml(process); listCanvas.Add(kCanvas); } helper = new PNGenerationHelper(newFileName, CurrentActiveTab); } while (false); return helper; }
/// <summary> /// Build connector for broadcast mode /// </summary> /// <param name="docOut">Xmldocument output</param> /// <param name="transitions">trans contain channels instance</param> /// <param name="canvas"></param> /// <param name="places"></param> /// <param name="arcs"></param> /// <param name="mapData"></param> /// <param name="_sensors"></param> /// <param name="channels"></param> /// <param name="abstractSensor"></param> /// <param name="abstractChannel"></param> public static void buildConnectorBroadcast2(XmlDocument docOut, XmlElement transitions, WSNCanvas canvas, XmlElement places, XmlElement arcs, Hashtable mapData, List<WSNSensor> _sensors, List<WSNChannel> channels, bool abstractSensor, bool abstractChannel) { // connect the model float xPos, yPos, fTmp; int fromId, toId; WSNPNData fromData, toData; foreach (WSNChannel channel in channels) { if (channel.Neighbor) continue; fromId = ((WSNSensor)channel.From).ID; toId = ((WSNSensor)channel.To).ID; fromData = (WSNPNData)mapData[channel.ID]; toData = (WSNPNData)mapData[toId]; // second arc arcs.AppendChild(buildArc(docOut, fromData.outNode.name + fromData.nodeId, toData.inNode.name + toData.nodeId, computeCenterXY(fromData, toData))); } foreach (WSNSensor ws in _sensors) { if (ws.NodeType == SensorType.Sink) continue; int wsId = ws.ID; List<WSNChannel> channelList = new List<WSNChannel>(); foreach (WSNChannel wc in channels) { if (((WSNSensor)wc.From).ID == wsId) channelList.Add(wc); } WSNPNData fData = (WSNPNData)mapData[ws.ID]; WSNPNData tData; float xChannel = 0f; float yChannel = 0f; int iCount = 0; foreach (WSNChannel wc in channels) { if (((WSNSensor)wc.From).ID != ws.ID) continue; iCount++; tData = (WSNPNData)mapData[wc.ID]; xChannel += tData.inNode.pos.x; yChannel += tData.inNode.pos.y; } xChannel = xChannel / iCount; yChannel = yChannel / iCount; fTmp = Math.Abs(fData.outNode.pos.x - xChannel) / 2; xPos = Math.Min(fData.outNode.pos.x, xChannel) + fTmp; fTmp = Math.Abs(fData.outNode.pos.y - yChannel) / 2; yPos = Math.Min(fData.outNode.pos.y, yChannel) + fTmp; String tranName = "BroadCasting_" + wsId; XmlElement tran = buildTransistion(docOut, tranName, xPos, yPos); // Check abstract and build code if (abstractSensor) embedReceiveAbstractSensor(canvas, channels, ws, tran); transitions.AppendChild(tran); WSNPNData wsFrom = (WSNPNData)mapData[wsId]; if (abstractChannel) { do { if (channelList.Count == 1) { transitions.RemoveChild(tran); WSNChannel wc = channelList[0]; WSNPNData wsDataTo = (WSNPNData)mapData[wc.ID]; arcs.AppendChild(buildArc(docOut, wsFrom.outNode.name + wsId, wsDataTo.inNode.name + wc.ID)); break; } float xtmp, ytmp, x, y; foreach (WSNChannel c in channelList) { String placeConnName = "BroadCasted" + c.ID; WSNPNData placeData = (WSNPNData)mapData[c.ID]; xtmp = Math.Abs(placeData.outNode.pos.x - xPos) / 2; ytmp = Math.Abs(placeData.outNode.pos.y - yPos) / 2; x = Math.Min(placeData.outNode.pos.x, xPos) + xtmp; y = Math.Min(placeData.outNode.pos.y, yPos) + ytmp; XmlElement placeConn = buildPlace(docOut, placeConnName, x, y); places.AppendChild(placeConn); arcs.AppendChild(buildArc(docOut, tranName, placeConnName)); arcs.AppendChild(buildArc(docOut, placeConnName, placeData.inNode.name + c.ID)); } arcs.AppendChild(buildArc(docOut, wsFrom.outNode.name + wsId, tranName)); } while (false); } else { // Full channel arcs.AppendChild(buildArc(docOut, wsFrom.outNode.name + wsId, tranName)); if (ws.NodeType == SensorType.Source && abstractSensor) arcs.AppendChild(buildArc(docOut, tranName, wsFrom.outNode.name + wsId)); foreach (WSNChannel wc in channelList) { WSNPNData wsDataTo = (WSNPNData)mapData[wc.ID]; arcs.AppendChild(buildArc(docOut, tranName, wsDataTo.inNode.name + wc.ID)); } } } }
private void addProcessToolStripMenuItem_Click(object sender, EventArgs e) { if (Canvas != null) Canvas.Visible = false; TreeNode node = TreeView_Structure.Nodes[0].Nodes[Parsing.PROCESSES_NODE_NAME].Nodes.Add("Network_" + pcounter); Canvas = new WSNCanvas("Network_" + pcounter); Canvas.Node = node; node.Tag = Canvas; TreeView_Structure.SelectedNode = node; AddNewProcess(Canvas); //add the first StateItem classitem = CreateItem(); classitem.IsInitialState = true; Canvas.StateCounter++; classitem.X = 100 / Canvas.Zoom; classitem.Y = 100 / Canvas.Zoom; AddCanvasItem(classitem); Canvas.Refresh(); SetDirty(); pcounter++; }
private void TreeView_Structure_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Node.Parent != null && e.Node.Parent.Text == Parsing.PROCESSES_NODE_NAME) { toolStripContainer1.Visible = true; if (Canvas != null && Canvas.Visible) Canvas.Visible = false; Canvas = (e.Node.Tag as WSNCanvas); if (Canvas != null) { Canvas.Visible = true; this.Button_AddLink.Checked = false; this.Button_AddNewState.Checked = false; this.Button_Delete.Enabled = Canvas.itemSelected; } textEditorControl.Visible = false; } else if (e.Node.Text == Parsing.DECLARATION_NODE_NAME) { toolStripContainer1.Visible = false; textEditorControl.Visible = true; if (e.Node.Tag != null && textEditorControl.Text != e.Node.Tag.ToString()) textEditorControl.Text = e.Node.Tag.ToString(); } RaiseIsDirtyChanged(); }
private void duplicateProcessToolStripMenuItem_Click(object sender, EventArgs e) { if (TreeView_Structure.SelectedNode != null) { if (TreeView_Structure.SelectedNode.Parent != null && TreeView_Structure.SelectedNode.Parent.Text == Parsing.PROCESSES_NODE_NAME) { WSNCanvas currentCanvas = TreeView_Structure.SelectedNode.Tag as WSNCanvas; WSNCanvas duplicatedCanvas = currentCanvas.Duplicate(); TreeNode node = TreeView_Structure.Nodes[0].Nodes[Parsing.PROCESSES_NODE_NAME].Nodes.Add(duplicatedCanvas.Node.Text); duplicatedCanvas.Node = node; node.Tag = duplicatedCanvas; TreeView_Structure.SelectedNode = node; AddNewProcess(duplicatedCanvas); duplicatedCanvas.Refresh(); this.Canvas = duplicatedCanvas; SetDirty(); } } }
/// <summary> /// Load model from XML string /// </summary> /// <param name="xml"></param> /// <param name="PNDocRes"></param> /// <returns></returns> public static WSNModel LoadModelFromXML(string xml, XmlDocument PNDocRes) { WSNModel model = new WSNModel(); do { XmlDocument doc = new XmlDocument(); try { doc.LoadXml(xml); } catch { } XmlNodeList nodes = null; do { nodes = doc.GetElementsByTagName(XmlTag.TAG_DECLARATION); if (nodes == null || nodes.Count != 1) break; model.Declaration = nodes.Item(0).InnerText; } while (false); do { nodes = doc.GetElementsByTagName(XmlTag.TAG_NETWORK); if (nodes == null) break; // mlqvu -- load attributes for network tag XmlNode firstNetworkNode = nodes[0]; if (firstNetworkNode == null) break; if (model.mExtendInfo == null) model.mExtendInfo = new WSNExtendInfo(); try { String noID = firstNetworkNode.Attributes[XmlTag.ATTR_mID].Value; model.mExtendInfo.mID = long.Parse(noID); String noPacket = firstNetworkNode.Attributes[XmlTag.ATTR_NUMOFPACKETS].Value; model.mExtendInfo.mNumberPacket = Int32.Parse(noPacket); String noSensor = firstNetworkNode.Attributes[XmlTag.ATTR_NUMOFSENSORS].Value; model.mExtendInfo.mNumberSensor = Int32.Parse(noSensor); String maxSensorBufferSize = firstNetworkNode.Attributes[XmlTag.ATTR_SENSOR_MAX_BUFFER_SIZE].Value; model.mExtendInfo.mSensorMaxBufferSize = Int32.Parse(maxSensorBufferSize); String maxSensorQueueSize = firstNetworkNode.Attributes[XmlTag.ATTR_SENSOR_MAX_QUEUE_SIZE].Value; model.mExtendInfo.mSensorMaxQueueSize = Int32.Parse(maxSensorQueueSize); String maxChannelBufferSize = firstNetworkNode.Attributes[XmlTag.ATTR_CHANNEL_MAX_BUFFER_SIZE].Value; model.mExtendInfo.mChannelMaxBufferSize = Int32.Parse(maxChannelBufferSize); } catch (Exception e) { } LTSCanvas canvas = null; foreach (XmlElement node in nodes[0].ChildNodes) { canvas = new WSNCanvas(node.GetAttribute(XmlTag.ATTR_NAME)); canvas.LoadFromXml(node); model.Processes.Add(canvas); } } while (false); } while (false); return model; }