diff --git a/LipidCreator/StructureEditor/LipidStructure.cs b/LipidCreator/StructureEditor/LipidStructure.cs index 2ca6c7b..5978ebc 100644 --- a/LipidCreator/StructureEditor/LipidStructure.cs +++ b/LipidCreator/StructureEditor/LipidStructure.cs @@ -16,9 +16,10 @@ public class NodeProjection public NodeState nodeState = NodeState.Enabled; public PointF previousShift; - public NodeProjection() + public NodeProjection(NodeState state = NodeState.Enabled) { previousShift = new PointF(shift.X, shift.Y); + nodeState = state; } public NodeProjection(NodeProjection copy) @@ -129,6 +130,12 @@ public StructureEdge(PointF s, PointF e) start = s; end = e; } + + public StructureEdge(StructureEdge copy) + { + start = new PointF(copy.start.X, copy.start.Y); + end = new PointF(copy.end.X, copy.end.Y); + } } @@ -150,6 +157,23 @@ public Bond(LipidStructure _lipidStructure, int start, int end, bool doubleBond) isDoubleBond = doubleBond; } + public Bond(Bond copy) + { + startId = copy.startId; + endId = copy.endId; + isDoubleBond = copy.isDoubleBond; + if (copy.edgeSingle != null) edgeSingle = new StructureEdge(copy.edgeSingle); + foreach (var edge in copy.edgesDouble) + { + edgesDouble.Add(new StructureEdge(edge)); + } + foreach (var kvp in copy.bondProjections) + { + bondProjections.Add(kvp.Key, kvp.Value); + } + lipidStructure = copy.lipidStructure; + } + public void toggleState() { @@ -188,6 +212,7 @@ public void toggleCharge() public class LipidStructure { public List nodes = new List(); + public HashSet additionalNodes = new HashSet(); public List bonds = new List(); public List additionalBonds = new List(); public Dictionary idToNode = new Dictionary(); @@ -216,6 +241,7 @@ public class LipidStructure public HashSet specialAtoms = new HashSet(){"N", "O", "P", "S"}; public Dictionary freeElectrons = new Dictionary(){{"C", 4}, {"N", 3}, {"O", 2}, {"P", 3}, {"S", 2}}; public int projectionIds = 1; + public int currentNodeId = 0; @@ -308,6 +334,8 @@ public LipidStructure(string file_name, Form form) nodes.Add(sn); idToNode.Add(nodeId, sn); } + + currentNodeId = Math.Max(currentNodeId, nodeId); } catch(Exception ex){ Console.WriteLine(ex); @@ -440,7 +468,7 @@ public LipidStructure(string file_name, Form form) foreach (var bond in bonds) bond.bondProjections.Add(0, bond.isDoubleBond); currentProjection = 0; - computeBonds(); + computeBonds(bonds); changeFragment(); countNodeConnections(); } @@ -460,11 +488,20 @@ public void addFragment(string fragmentName, bool isPositive) node.nodeProjections.Add(newProjectionId, new NodeProjection(node.nodeProjections[currentProjection])); foreach (var decorator in node.decorators) decorator.nodeProjections.Add(newProjectionId, new NodeProjection(decorator.nodeProjections[currentProjection])); } + foreach (var bond in bonds) bond.bondProjections.Add(newProjectionId, bond.bondProjections[currentProjection]); + List bondsToAdd = new List(); foreach (var bond in additionalBonds) { - if (bond.bondProjections.ContainsKey(currentProjection)) bond.bondProjections.Add(newProjectionId, bond.bondProjections[currentProjection]); + if (bond.bondProjections.ContainsKey(currentProjection)) + { + Bond newBond = new Bond(bond); + newBond.bondProjections.Add(newProjectionId, bond.bondProjections[currentProjection]); + bondsToAdd.Add(newBond); + } } + foreach (Bond bond in bondsToAdd) additionalBonds.Add(bond); + computeBonds(additionalBonds); countNodeConnections(); } @@ -528,6 +565,12 @@ public void computeBonds(List checkBonds) StructureNode nodeB = idToNode[bond.startId]; StructureNode nodeE = idToNode[bond.endId]; + + if (!nodeB.nodeProjections.ContainsKey(currentProjection) || !nodeE.nodeProjections.ContainsKey(currentProjection)) + { + deleteBonds.Add(bond); + continue; + } float xB = nodeB.position.X + nodeB.nodeProjections[currentProjection].shift.X; float yB = nodeB.position.Y + nodeB.nodeProjections[currentProjection].shift.Y; @@ -579,6 +622,48 @@ public void computeBonds(List checkBonds) + public void addNode(int x, int y) + { + if (currentProjection == 0) return; + + nodeFont = new Font("Arial", fontSize * factor); + Size size = TextRenderer.MeasureText(graphics, "C", nodeFont); + float w = size.Width * 0.9f; + float h = size.Height * 0.9f; + RectangleF drawRect = new RectangleF(x - w * 0.5f, y - h * 0.5f, w, h); + StructureNode sn = new StructureNode(this, ++currentNodeId, new PointF(x, y), drawRect, "C"); + + + int fragId = currentFragment.id; + sn.nodeProjections.Add(fragId, new NodeProjection(fragId == currentProjection ? NodeState.Enabled : NodeState.Hidden)); + + nodes.Add(sn); + additionalNodes.Add(sn); + idToNode.Add(currentNodeId, sn); + + computeBonds(); + } + + + public StructureNode removeNode(StructureNode node) + { + if (currentProjection == 0 || !additionalNodes.Contains(node) || !node.nodeProjections.ContainsKey(currentProjection)) return node; + + node.nodeProjections.Remove(currentProjection); + if (node.nodeProjections.Count == 0) + { + additionalNodes.Remove(node); + nodes.Remove(node); + idToNode.Remove(node.id); + } + + computeBonds(); + + return null; + } + + + public void addBond(StructureNode start, StructureNode end) { if (currentProjection == 0) return; @@ -590,12 +675,25 @@ public void addBond(StructureNode start, StructureNode end) } + + public void removeBond(Bond bond) + { + if (currentProjection == 0) return; + if (!additionalBonds.Contains(bond)) return; + additionalBonds.Remove(bond); + computeBonds(additionalBonds); + countNodeConnections(); + } + + public Graphics setClipping(Graphics g, Form form) { // set up all clipping Graphics clippingGraphics = form.CreateGraphics(); foreach (var node in nodes) { + if (!node.nodeProjections.ContainsKey(currentProjection)) continue; + NodeProjection nodeProjection = node.nodeProjections[currentProjection]; if (!developmentView && (node.nodeProjections[currentProjection].nodeState == NodeState.Hidden || node.isCarbon)) continue; @@ -632,8 +730,11 @@ public void countNodeConnections() foreach (var bond in bonds) { - NodeProjection proStart = idToNode[bond.startId].nodeProjections[currentProjection]; - NodeProjection proEnd = idToNode[bond.endId].nodeProjections[currentProjection]; + + StructureNode nodeB = idToNode[bond.startId]; + StructureNode nodeE = idToNode[bond.endId]; + NodeProjection proStart = nodeB.nodeProjections[currentProjection]; + NodeProjection proEnd = nodeE.nodeProjections[currentProjection]; if (proStart.nodeState == NodeState.Enabled && proEnd.nodeState == NodeState.Enabled) { @@ -649,8 +750,10 @@ public void countNodeConnections() { if (!bond.bondProjections.ContainsKey(currentProjection)) continue; - NodeProjection proStart = idToNode[bond.startId].nodeProjections[currentProjection]; - NodeProjection proEnd = idToNode[bond.endId].nodeProjections[currentProjection]; + StructureNode nodeB = idToNode[bond.startId]; + StructureNode nodeE = idToNode[bond.endId]; + NodeProjection proStart = nodeB.nodeProjections[currentProjection]; + NodeProjection proEnd = nodeE.nodeProjections[currentProjection]; if (proStart.nodeState == NodeState.Enabled && proEnd.nodeState == NodeState.Enabled) { @@ -701,6 +804,9 @@ public void drawEdges(Graphics g, Form form) foreach (var bond in bonds) { + + if (!idToNode[bond.startId].nodeProjections.ContainsKey(currentProjection) || !idToNode[bond.endId].nodeProjections.ContainsKey(currentProjection)) continue; + NodeProjection proStart = idToNode[bond.startId].nodeProjections[currentProjection]; NodeProjection proEnd = idToNode[bond.endId].nodeProjections[currentProjection]; @@ -788,9 +894,10 @@ public void drawNodes(Graphics g) int minY = (1 << 30); int maxY = -(1 << 30); - foreach (var node in nodes) { + if (!node.nodeProjections.ContainsKey(currentProjection)) continue; + NodeProjection nodeProjection = node.nodeProjections[currentProjection]; PointF nodePoint = new PointF(node.boundingBox.X + nodeProjection.shift.X, node.boundingBox.Y + nodeProjection.shift.Y); if (!developmentView && (nodeProjection.nodeState == NodeState.Hidden)) continue; diff --git a/LipidCreator/StructureEditor/StructureEditor.Designer.cs b/LipidCreator/StructureEditor/StructureEditor.Designer.cs index 4c850ae..452a393 100644 --- a/LipidCreator/StructureEditor/StructureEditor.Designer.cs +++ b/LipidCreator/StructureEditor/StructureEditor.Designer.cs @@ -74,7 +74,10 @@ partial class LipidCreatorStructureEditor public Button actionChangeAtomState = new Button(); public Button actionChangeBondState = new Button(); public Button actionChangeGlobalCharge = new Button(); + public Button actionDrawAtom = new Button(); public Button actionDrawBond = new Button(); + public Button actionRemoveAtom = new Button(); + public Button actionRemoveBond = new Button(); public Button actionFinalView = new Button(); public Button actionMoveAtom = new Button(); @@ -127,45 +130,66 @@ private void InitializeComponent() this.Controls.Add(actionChangeBondState); actionChangeBondState.Size = new Size(120, 25); actionChangeBondState.Text = "Change bond state"; - actionChangeBondState.Location = new Point(10, 45); + actionChangeBondState.Location = new Point(10, actionChangeAtomState.Top + 35); actionChangeBondState.Click += actionChangeBondStateClicked; this.Controls.Add(actionChangeGlobalCharge); actionChangeGlobalCharge.Size = new Size(120, 25); actionChangeGlobalCharge.Text = "Change global charge"; - actionChangeGlobalCharge.Location = new Point(10, 80); + actionChangeGlobalCharge.Location = new Point(10, actionChangeBondState.Top + 35); actionChangeGlobalCharge.Click += actionChangeGlobalChargeClicked; + this.Controls.Add(actionDrawAtom); + actionDrawAtom.Size = new Size(120, 25); + actionDrawAtom.Text = "Draw atom"; + actionDrawAtom.Location = new Point(10, actionChangeGlobalCharge.Top + 35); + actionDrawAtom.Click += actionDrawAtomClicked; + this.Controls.Add(actionDrawBond); actionDrawBond.Size = new Size(120, 25); actionDrawBond.Text = "Draw bond"; - actionDrawBond.Location = new Point(10, 115); + actionDrawBond.Location = new Point(10, actionDrawAtom.Top + 35); actionDrawBond.Click += actionDrawBondClicked; + this.Controls.Add(actionRemoveAtom); + actionRemoveAtom.Size = new Size(120, 25); + actionRemoveAtom.Text = "Remove atom"; + actionRemoveAtom.Location = new Point(10, actionDrawBond.Top + 35); + actionRemoveAtom.Click += actionRemoveAtomClicked; + + this.Controls.Add(actionRemoveBond); + actionRemoveBond.Size = new Size(120, 25); + actionRemoveBond.Text = "Remove bond"; + actionRemoveBond.Location = new Point(10, actionRemoveAtom.Top + 35); + actionRemoveBond.Click += actionRemoveBondClicked; + this.Controls.Add(actionMoveAtom); actionMoveAtom.Size = new Size(120, 25); actionMoveAtom.Text = "Move atom"; - actionMoveAtom.Location = new Point(10, 150); + actionMoveAtom.Location = new Point(10, actionRemoveBond.Top + 35); actionMoveAtom.Click += actionMoveAtomClicked; this.Controls.Add(actionFinalView); actionFinalView.Size = new Size(120, 25); actionFinalView.Text = "Final View"; - actionFinalView.Location = new Point(10, 195); + actionFinalView.Location = new Point(10, actionMoveAtom.Top + 55); actionFinalView.Click += actionFinalViewClicked; actionButtons.Add(actionChangeAtomState); actionButtons.Add(actionChangeBondState); + actionButtons.Add(actionDrawAtom); actionButtons.Add(actionDrawBond); + actionButtons.Add(actionRemoveAtom); + actionButtons.Add(actionRemoveBond); actionButtons.Add(actionMoveAtom); this.Controls.Add(positiveFragmentsListBox); positiveFragmentsListBox.Width = 130; positiveFragmentsListBox.Height = 300; - positiveFragmentsListBox.Location = new Point(10, 245); + positiveFragmentsListBox.Location = new Point(10, actionFinalView.Top + 35); positiveFragmentsListBox.KeyUp += fragmentKeyPressed; positiveFragmentsListBox.SelectedIndexChanged += fragmentClicked; positiveFragmentsListBox.DoubleClick += positiveFragmentDoubleClicked; @@ -173,36 +197,36 @@ private void InitializeComponent() this.Controls.Add(negativeFragmentsListBox); negativeFragmentsListBox.Width = 130; negativeFragmentsListBox.Height = 300; - negativeFragmentsListBox.Location = new Point(150, 245); + negativeFragmentsListBox.Location = new Point(150, actionFinalView.Top + 35); negativeFragmentsListBox.KeyUp += fragmentKeyPressed; negativeFragmentsListBox.SelectedIndexChanged += fragmentClicked; negativeFragmentsListBox.DoubleClick += negativeFragmentDoubleClicked; + this.Controls.Add(removePositiveFragmentButton); + removePositiveFragmentButton.Location = new Point(positiveFragmentsListBox.Left + positiveFragmentsListBox.Width - 25, positiveFragmentsListBox.Top + positiveFragmentsListBox.Height); + removePositiveFragmentButton.Size = new Size(25, 25); + removePositiveFragmentButton.Text = "-"; + removePositiveFragmentButton.Click += removePositiveFragment; + this.Controls.Add(addPositiveFragmentButton); - addPositiveFragmentButton.Location = new Point(90, 540); + addPositiveFragmentButton.Location = new Point(removePositiveFragmentButton.Left - removePositiveFragmentButton.Width, removePositiveFragmentButton.Top); addPositiveFragmentButton.Size = new Size(25, 25); addPositiveFragmentButton.Text = "+"; addPositiveFragmentButton.Click += addPositiveFragment; - this.Controls.Add(removePositiveFragmentButton); - removePositiveFragmentButton.Location = new Point(115, 540); - removePositiveFragmentButton.Size = new Size(25, 25); - removePositiveFragmentButton.Text = "-"; - removePositiveFragmentButton.Click += removePositiveFragment; + this.Controls.Add(removeNegativeFragmentButton); + removeNegativeFragmentButton.Location = new Point(negativeFragmentsListBox.Left + negativeFragmentsListBox.Width - 25, negativeFragmentsListBox.Top + negativeFragmentsListBox.Height); + removeNegativeFragmentButton.Size = new Size(25, 25); + removeNegativeFragmentButton.Text = "-"; + removeNegativeFragmentButton.Click += removeNegativeFragment; this.Controls.Add(addNegativeFragmentButton); - addNegativeFragmentButton.Location = new Point(230, 540); + addNegativeFragmentButton.Location = new Point(removeNegativeFragmentButton.Left - removeNegativeFragmentButton.Width, removeNegativeFragmentButton.Top); addNegativeFragmentButton.Size = new Size(25, 25); addNegativeFragmentButton.Text = "+"; addNegativeFragmentButton.Click += addNegativeFragment; - this.Controls.Add(removeNegativeFragmentButton); - removeNegativeFragmentButton.Location = new Point(255, 540); - removeNegativeFragmentButton.Size = new Size(25, 25); - removeNegativeFragmentButton.Text = "-"; - removeNegativeFragmentButton.Click += removeNegativeFragment; - diff --git a/LipidCreator/StructureEditor/StructureEditor.cs b/LipidCreator/StructureEditor/StructureEditor.cs index 4379e81..925693a 100644 --- a/LipidCreator/StructureEditor/StructureEditor.cs +++ b/LipidCreator/StructureEditor/StructureEditor.cs @@ -9,7 +9,7 @@ namespace LipidCreatorStructureEditor { public enum MouseState {MouseDefault, MouseDown, MouseDownMove}; - public enum Action {Idle, ChangeAtom, ChangeAtomSelect, ChangeBond, DrawBond, MoveAtom, MoveAtomSelect}; + public enum Action {Idle, ChangeAtom, ChangeAtomSelect, ChangeBond, DrawAtom, DrawBond, RemoveAtom, RemoveBond, MoveAtom, MoveAtomSelect}; public partial class LipidCreatorStructureEditor : Form { @@ -69,16 +69,16 @@ private void DrawScene(Graphics g) var mouse = PointToClient(Cursor.Position); - if (((action == Action.ChangeAtom || action == Action.MoveAtom) && mouseState != MouseState.MouseDownMove) || action == Action.DrawBond) + if (((action == Action.ChangeAtom || action == Action.MoveAtom) && mouseState != MouseState.MouseDownMove) || action == Action.DrawBond || action == Action.DrawAtom || action == Action.RemoveAtom) { - if (currentNode != null) + if (currentNode != null && currentNode.nodeProjections.ContainsKey(lipidStructure.currentProjection)) { NodeProjection nodeProjection = currentNode.nodeProjections[lipidStructure.currentProjection]; Pen pen = new Pen(Color.DeepSkyBlue, 2); g.DrawEllipse(pen, currentNode.position.X + nodeProjection.shift.X - cursorCircleRadius, currentNode.position.Y + nodeProjection.shift.Y - cursorCircleRadius, cursorCircleRadius * 2, cursorCircleRadius * 2); } } - else if (action == Action.ChangeBond) + else if (action == Action.ChangeBond || action == Action.RemoveBond) { if (currentBond != null) { @@ -93,6 +93,7 @@ private void DrawScene(Graphics g) { foreach (var node in moveNodes) { + if (!node.nodeProjections.ContainsKey(lipidStructure.currentProjection)) continue; NodeProjection nodeProjection = node.nodeProjections[lipidStructure.currentProjection]; Pen pen = new Pen(Color.DeepSkyBlue, 2); g.DrawEllipse(pen, node.position.X + nodeProjection.shift.X - cursorCircleRadius, node.position.Y + nodeProjection.shift.Y - cursorCircleRadius, cursorCircleRadius * 2, cursorCircleRadius * 2); @@ -100,7 +101,7 @@ private void DrawScene(Graphics g) } lipidStructure.drawEdges(g, this); - if (mouseState == MouseState.MouseDownMove && action == Action.DrawBond && drawStart != null) + if (mouseState == MouseState.MouseDownMove && action == Action.DrawBond && drawStart != null && drawStart.nodeProjections.ContainsKey(lipidStructure.currentProjection)) { NodeProjection nodeProjection = drawStart.nodeProjections[lipidStructure.currentProjection]; Graphics clippingGraphics = lipidStructure.setClipping(g, this); @@ -126,6 +127,7 @@ private void DrawScene(Graphics g) // mark all atoms within the selection box foreach (var node in lipidStructure.nodes) { + if (!node.nodeProjections.ContainsKey(lipidStructure.currentProjection)) continue; NodeProjection nodeProjection = node.nodeProjections[lipidStructure.currentProjection]; double xm = node.position.X + nodeProjection.shift.X; double ym = node.position.Y + nodeProjection.shift.Y; @@ -161,6 +163,19 @@ private void mouseUp(Object sender, MouseEventArgs e) lipidStructure.computeBonds(); updateStructure(); } + else if (action == Action.RemoveBond && currentBond != null) + { + lipidStructure.removeBond(currentBond); + currentBond = null; + lipidStructure.computeBonds(); + updateStructure(); + } + else if (action == Action.RemoveAtom && currentNode != null) + { + currentNode = lipidStructure.removeNode(currentNode); + lipidStructure.computeBonds(); + updateStructure(); + } else if (action == Action.MoveAtomSelect) { action = Action.MoveAtom; @@ -169,6 +184,12 @@ private void mouseUp(Object sender, MouseEventArgs e) { action = Action.ChangeAtom; } + else if (action == Action.DrawAtom && currentNode == null) + { + var mouse = PointToClient(Cursor.Position); + lipidStructure.addNode(mouse.X, mouse.Y); + updateStructure(); + } break; case MouseState.MouseDownMove: @@ -183,6 +204,13 @@ private void mouseUp(Object sender, MouseEventArgs e) lipidStructure.computeBonds(); updateStructure(); } + else if (action == Action.RemoveBond && currentBond != null) + { + lipidStructure.removeBond(currentBond); + currentBond = null; + lipidStructure.computeBonds(); + updateStructure(); + } else if (action == Action.DrawBond) { if (currentNode != null) @@ -208,6 +236,7 @@ private void mouseUp(Object sender, MouseEventArgs e) // mark all atoms within the selection box foreach (var node in lipidStructure.nodes) { + if (!node.nodeProjections.ContainsKey(lipidStructure.currentProjection)) continue; NodeProjection nodeProjection = node.nodeProjections[lipidStructure.currentProjection]; double xm = node.position.X + nodeProjection.shift.X; double ym = node.position.Y + nodeProjection.shift.Y; @@ -227,6 +256,7 @@ private void mouseUp(Object sender, MouseEventArgs e) // mark all atoms within the selection box foreach (var node in lipidStructure.nodes) { + if (!node.nodeProjections.ContainsKey(lipidStructure.currentProjection)) continue; NodeProjection nodeProjection = node.nodeProjections[lipidStructure.currentProjection]; double xm = node.position.X + nodeProjection.shift.X; double ym = node.position.Y + nodeProjection.shift.Y; @@ -304,11 +334,12 @@ private void mouseMove(Object sender, MouseEventArgs e) PointF mouse = PointToClient(Cursor.Position); - if (action == Action.ChangeAtom || action == Action.MoveAtom || action == Action.DrawBond) + if (action == Action.ChangeAtom || action == Action.MoveAtom || action == Action.DrawBond || action == Action.RemoveAtom) { double minDist = 1e10; foreach (var node in lipidStructure.nodes) { + if (!node.nodeProjections.ContainsKey(lipidStructure.currentProjection)) continue; NodeProjection nodeProjection = node.nodeProjections[lipidStructure.currentProjection]; double dist = Math.Pow(node.position.X + nodeProjection.shift.X - mouse.X, 2) + Math.Pow(node.position.Y + nodeProjection.shift.Y - mouse.Y, 2); if (dist <= Math.Pow(10 + cursorCircleRadius, 2) && dist < minDist) @@ -338,7 +369,7 @@ private void mouseMove(Object sender, MouseEventArgs e) } } - else if (action == Action.ChangeBond) + else if (action == Action.ChangeBond || action == Action.RemoveBond) { double minDistC = 1e10; foreach (var bond in lipidStructure.bonds) @@ -408,45 +439,47 @@ private void mouseMove(Object sender, MouseEventArgs e) } } } - - - - - private void actionChangeAtomStateClicked(Object sender, EventArgs e) + + + + + + + + + + + private void buttonClicked(Button actionButton, Action newAction) { moveNodes.Clear(); foreach (var button in actionButtons) button.BackColor = Color.FromArgb(255, 255, 255); - if (action == Action.ChangeAtom) + if (action == newAction) { - actionChangeAtomState.BackColor = Color.FromArgb(255, 255, 255); + actionButton.BackColor = Color.FromArgb(255, 255, 255); action = Action.Idle; } - else + else { - actionChangeAtomState.BackColor = Color.FromArgb(210, 210, 210); - action = Action.ChangeAtom; + actionButton.BackColor = Color.FromArgb(210, 210, 210); + action = newAction; } updateStructure(); } + + + + + private void actionChangeAtomStateClicked(Object sender, EventArgs e) + { + buttonClicked(actionChangeAtomState, Action.ChangeAtom); + } private void actionChangeBondStateClicked(Object sender, EventArgs e) { - moveNodes.Clear(); - foreach (var button in actionButtons) button.BackColor = Color.FromArgb(255, 255, 255); - if (action == Action.ChangeBond) - { - actionChangeBondState.BackColor = Color.FromArgb(255, 255, 255); - action = Action.Idle; - } - else - { - actionChangeBondState.BackColor = Color.FromArgb(210, 210, 210); - action = Action.ChangeBond; - } - updateStructure(); + buttonClicked(actionChangeBondState, Action.ChangeBond); } @@ -461,21 +494,33 @@ private void actionChangeGlobalChargeClicked(Object sender, EventArgs e) + private void actionDrawAtomClicked(Object sender, EventArgs e) + { + buttonClicked(actionDrawAtom, Action.DrawAtom); + } + + + + + private void actionRemoveAtomClicked(Object sender, EventArgs e) + { + buttonClicked(actionRemoveAtom, Action.RemoveAtom); + } + + + + + private void actionRemoveBondClicked(Object sender, EventArgs e) + { + buttonClicked(actionRemoveBond, Action.RemoveBond); + } + + + + private void actionDrawBondClicked(Object sender, EventArgs e) { - foreach (var button in actionButtons) button.BackColor = Color.FromArgb(255, 255, 255); - moveNodes.Clear(); - if (action == Action.DrawBond) - { - actionDrawBond.BackColor = Color.FromArgb(255, 255, 255); - action = Action.Idle; - } - else - { - actionDrawBond.BackColor = Color.FromArgb(210, 210, 210); - action = Action.DrawBond; - } - updateStructure(); + buttonClicked(actionDrawBond, Action.DrawBond); } @@ -483,19 +528,7 @@ private void actionDrawBondClicked(Object sender, EventArgs e) private void actionMoveAtomClicked(Object sender, EventArgs e) { - foreach (var button in actionButtons) button.BackColor = Color.FromArgb(255, 255, 255); - moveNodes.Clear(); - if (action == Action.MoveAtom) - { - actionMoveAtom.BackColor = Color.FromArgb(255, 255, 255); - action = Action.Idle; - } - else - { - actionMoveAtom.BackColor = Color.FromArgb(210, 210, 210); - action = Action.MoveAtom; - } - updateStructure(); + buttonClicked(actionMoveAtom, Action.MoveAtom); } @@ -726,6 +759,7 @@ private void computeFragmentMass(Object sender, EventArgs e) bool useAdduct = false; foreach (var node in lipidStructure.nodes) { + if (!node.nodeProjections.ContainsKey(lipidStructure.currentProjection)) continue; NodeProjection nodeProjection = node.nodeProjections[lipidStructure.currentProjection]; if (nodeProjection.nodeState != NodeState.Enabled) continue; diff --git a/LipidCreator/data/LipidDataTables/ms2fragments.csv b/LipidCreator/data/LipidDataTables/ms2fragments.csv index 4be7a08..07e4a4b 100644 --- a/LipidCreator/data/LipidDataTables/ms2fragments.csv +++ b/LipidCreator/data/LipidDataTables/ms2fragments.csv @@ -708,10 +708,10 @@ BMP,FA [yy:y](+C3H4O) + HG(GP),FA2(+C3H4O) + HG(GP),1,FA2;HG,0,-2,-1,0,0,0,,, BMP,FA [xx:x](+C3H4O) + HG(GP),FA1(+C3H4O) + HG(GP),1,FA1;HG,0,-2,-1,0,0,0,,, BMP,FA [xx:x](+C3H5O4P),FA1(+C3H5O4P),1,FA1;HG,-3,-7,-4,0,0,0,,, BMP,FA [yy:y](+C3H5O4P),FA2(+C3H5O4P),1,FA2;HG,-3,-7,-4,0,0,0,,, -BMP,FA [xx:x](+C3H6O2),FA1(+C3H6O2),1,FA1;HG,-3,-6,-6,0,1,0,,, -BMP,FA [yy:y](+C3H6O2),FA2(+C3H6O2),1,FA2;HG,-3,-6,-6,0,1,0,,, -BMP,FA [xx:x](+C3H4O),FA1(+C3H4O),1,FA1;HG,-3,-8,-7,0,1,0,,, -BMP,FA [yy:y](+C3H4O),FA2(+C3H4O),1,FA2;HG,-3,-8,-7,0,1,0,,, +BMP,FA [xx:x](+C3H6O2),FA1(+C3H6O2),1,FA1;HG,-3,-6,-6,0,-1,0,,, +BMP,FA [yy:y](+C3H6O2),FA2(+C3H6O2),1,FA2;HG,-3,-6,-6,0,-1,0,,, +BMP,FA [xx:x](+C3H4O),FA1(+C3H4O),1,FA1;HG,-3,-8,-7,0,-1,0,,, +BMP,FA [yy:y](+C3H4O),FA2(+C3H4O),1,FA2;HG,-3,-8,-7,0,-1,0,,, BMP,FA [xx:x],FA1,1,FA1,0,-1,0,0,0,0,,, BMP,FA [yy:y],FA2,1,FA2,0,-1,0,0,0,0,,, BMP,GP(153),GP(153),-1,HG,-3,-6,-3,0,0,0,,,