// delete block / data type private void mnuBlockDelete_Click(object sender, EventArgs e) { if (treeView1.SelectedNode.Tag is PlcBlock) { PlcBlock block = (PlcBlock)treeView1.SelectedNode.Tag; DialogResult dlg = MessageBox.Show("Do you really want to delete the block " + block.Name + "?", "Delete block", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlg == DialogResult.Yes) { block.Delete(); IterateThroughDevices(project); } } if (treeView1.SelectedNode.Tag is PlcStruct) { PlcStruct block = (PlcStruct)treeView1.SelectedNode.Tag; DialogResult dlg = MessageBox.Show("Do you really want to delete the data type " + block.Name + "?", "Delete data type", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlg == DialogResult.Yes) { block.Delete(); IterateThroughDevices(project); } } }
/// <summary> /// Try to get Meta data from MetaTree. If the data are not in the tree, try to create and add it. /// All the calculation of the offsets will be made in this method. the tree has two parts, one for MetaData and one for The Mappings. /// The mappings have only a Reference of the Meta data, so you shouldn't change the Offsets while using. /// </summary> private static PlcObject GetMetaData(ITree tree, Type t) { var nodePathStack = new Stack <string>(); var name = NormalizeTypeName(t.FullName); nodePathStack.Push(RootNodeName); nodePathStack.Push(MetaDataNodeName); nodePathStack.Push(name); var path = PlcMetaDataTreePath.CreateAbsolutePath(nodePathStack.Reverse().ToArray()); var offset = 0; if (!tree.TryGet(path, ref offset, out var obj)) { var byteOffset = 0; var bitOffset = 0; nodePathStack.Pop(); var parent = new PlcStruct(name, t); PlcObject.AddPlcObjectToTree(parent, tree, PlcMetaDataTreePath.CreateAbsolutePath(nodePathStack.Reverse().ToArray())); nodePathStack.Push(parent.Name); PlcObject pred = null; DebugOutPut("{0}{{", name); foreach (var pi in t.GetTypeInfo().DeclaredProperties) { var plcObject = PlcObjectFactory.CreatePlcObject(pi); if (plcObject is PlcArray plcObjectArray && (plcObjectArray.LeafElementType ?? plcObjectArray.ArrayType) is PlcStruct) { plcObjectArray.ArrayType = GetMetaData(tree, plcObjectArray.ElemenType); } else if (plcObject is PlcStruct) { plcObject = new PlcObjectRef(plcObject.Name, GetMetaData(tree, pi.PropertyType)); } var hasCustomOffset = PlcObjectFactory.GetOffsetFromAttribute(pi, ref byteOffset, ref bitOffset); AddPlcObject(tree, pred, plcObject, nodePathStack, ref byteOffset, ref bitOffset, hasCustomOffset); pred = plcObject; }
private void mnuBlockDelete_Click(object sender, EventArgs e) { // delete block / data type if (treeView1.SelectedNode.Tag is PlcBlock) { PlcBlock block = (PlcBlock)treeView1.SelectedNode.Tag; if (MessageYesNo("Do you really want to delete the block " + block.Name + "?", "Delete block") == DialogResult.Yes) { try { block.Delete(); IterateThroughDevices(project); } catch (Exception ex) { MessageError(ex.Message, "Exception"); } } } else if (treeView1.SelectedNode.Tag is PlcStruct) { PlcStruct block = (PlcStruct)treeView1.SelectedNode.Tag; if (MessageYesNo("Do you really want to delete the data type " + block.Name + "?", "Delete data type") == DialogResult.Yes) { try { block.Delete(); IterateThroughDevices(project); } catch (Exception ex) { MessageError(ex.Message, "Exception"); } } } }
private void exportToolStripMenuItem_Click(object sender, EventArgs e) { // nothing selected if (treeView1.SelectedNode == null) { return; } // only blocks and structs if (!(treeView1.SelectedNode.Tag is PlcBlock) && !(treeView1.SelectedNode.Tag is PlcStruct)) { return; } FolderBrowserDialog folderDialog = new FolderBrowserDialog(); folderDialog.Description = "Select export path"; folderDialog.SelectedPath = Application.StartupPath + "\\Export"; DialogResult res = folderDialog.ShowDialog(); // ok now save if (res == DialogResult.OK) { try { // for plcBlocks like OB,FB,FC if (treeView1.SelectedNode.Tag is PlcBlock) { PlcBlock block = (PlcBlock)treeView1.SelectedNode.Tag; if (block.IsConsistent) { string fPath = Application.StartupPath + "\\Export\\" + block.ProgrammingLanguage.ToString() + "_" + block.Name + "_" + "V" + block.HeaderVersion.ToString() + ".xml"; fPath = GetNextFileName(fPath); FileInfo f = new FileInfo(fPath); block.Export(f, ExportOptions.None); MessageOK("File " + Path.GetFileName(fPath) + " has beed exported", "Export"); } else { MessageError("Block " + block.Name + " is not consistent. Please compile", "Export"); } } // for data types if (treeView1.SelectedNode.Tag is PlcStruct) { PlcStruct block = (PlcStruct)treeView1.SelectedNode.Tag; if (block.IsConsistent) { string fPath = Application.StartupPath + "\\Export\\plcType_" + block.Name + "_" + block.ModifiedDate.ToShortDateString() + ".xml"; fPath = GetNextFileName(fPath); FileInfo f = new FileInfo(fPath); block.Export(f, ExportOptions.None); MessageOK("File " + Path.GetFileName(fPath) + " has beed exported", "Export"); } else { MessageError("Data type " + block.Name + " is not consistent. Please compile", "Export"); } } } catch (Exception ex) { MessageError(ex.Message, "Exception"); } } }
private void button2_Click(object sender, EventArgs e) { // nothing selected if (treeView1.SelectedNode == null) { return; } // only blocks and structs if (!(treeView1.SelectedNode.Tag is PlcBlock) && !(treeView1.SelectedNode.Tag is PlcStruct)) { return; } FolderBrowserDialog folderDialog = new FolderBrowserDialog(); folderDialog.Description = "Select export path"; folderDialog.SelectedPath = Application.StartupPath + "\\Export"; DialogResult res = folderDialog.ShowDialog(); // ok now save if (res == DialogResult.OK) { try { // for plcBlocks like OB,FB,FC if (treeView1.SelectedNode.Tag is PlcBlock) { PlcBlock block = (PlcBlock)treeView1.SelectedNode.Tag; string fPath = Application.StartupPath + "\\Export\\plcBlock_" + block.ProgrammingLanguage.ToString() + "_" + block.Name + ".xml"; fPath = getNextFileName(fPath); FileInfo f = new FileInfo(fPath); block.Export(f, ExportOptions.None); MessageBox.Show("File " + f + " has beed exported", "Export", MessageBoxButtons.OK, MessageBoxIcon.Information); } // fpr data types if (treeView1.SelectedNode.Tag is PlcStruct) { PlcStruct block = (PlcStruct)treeView1.SelectedNode.Tag; string fPath = Application.StartupPath + "\\Export\\plcBlock_" + block.Name + ".xml"; fPath = getNextFileName(fPath); FileInfo f = new FileInfo(fPath); block.Export(f, ExportOptions.None); MessageBox.Show("File " + f + " has beed exported", "Export", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }