Ejemplo n.º 1
0
 private void RelationBoxHide()
 {
     selectedRelationEdgeVertex = null;
     RelationGroupBox.Visible   = false;
     OnChangingToEmptyRelation();
     RelationGroupBox.Invalidate();
 }
Ejemplo n.º 2
0
        // Relations ---------------------------------------------------------------------------------

        private void ChooseRelation(Type chosenRelationType)
        {
            selectedRelationType = chosenRelationType;
            OnRelationBoxShow();
            if (selectedRelationEdgeVertex.IsInParentRelation())
            {
                if (contextMenuStrip1.Items[0].Enabled)
                {
                    NegateContextMenuItemsEnabled();
                }
                deleteRelationButton.Enabled = true;
                if (selectedRelationEdgeVertex.ParentRelation.GetType() != selectedRelationType)
                {
                    SwapRelationsForSelected();
                }
            }
            else
            {
                chooseRelationEdgeLabel.Visible = true;
            }

            RelationGroupBox.Invalidate();
            bitMap.Invalidate();
        }
Ejemplo n.º 3
0
        private void BitMap_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                centreXTextBox.Text = e.X.ToString();
                centreYTextBox.Text = e.Y.ToString();

                if (currentPolygon == null)
                {
                    AddNewPolygon(e.Location);
                    bitMap.Invalidate();
                }
                else if (inAddPolygonMode)
                {
                    var vertex = GetVertexAtPosition(e.Location);
                    if (vertex == null)
                    {
                        var newVertex = new Vertex(e.Location, currentPolygon.Last.Value);
                        currentPolygon.Last.Value.next = newVertex;
                        currentPolygon.AddLast(newVertex);
                        bitMap.Invalidate();
                    }
                    else if (currentPolygon.Count >= 3 && vertex.prev == null)
                    {
                        vertex.prev = currentPolygon.Last.Value;
                        currentPolygon.Last.Value.next = vertex;
                        ReverseIfNotClockwise();
                        TurnOffAddPolygonMode();
                    }
                }
            }
            else if (e.Button == MouseButtons.Right && Control.ModifierKeys == Keys.Control && currentPolygon != null)
            {
                Vertex edgeVertex           = GetEdgeVertex(e.Location, 2 * eps)?.Value;
                bool   gotTwoDifferentEdges = selectedRelationEdgeVertex != null && edgeVertex != null &&
                                              selectedRelationEdgeVertex != edgeVertex;
                bool inChoosingEdgeMode = gotTwoDifferentEdges && chooseRelationEdgeLabel.Visible;
                if (inChoosingEdgeMode && !edgeVertex.IsInParentRelation())
                {
                    // Adding new relation
                    AddRelationForSelected(v1: selectedRelationEdgeVertex, v3: edgeVertex);
                    RelationBoxHide();
                    RelationGroupBox.Invalidate();
                    bitMap.Invalidate();
                }
                else if (inChoosingEdgeMode)
                {
                    MessageBox.Show("Nie możesz dodać dwóch relacji dla jednej krawędzi", "Błąd",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    if (gotTwoDifferentEdges) // We are swaping from existent relation to not null edge
                    {
                        OnChangingToEmptyRelation();
                    }

                    selectedRelationEdgeVertex = edgeVertex;
                    if (selectedRelationEdgeVertex != null)
                    {
                        RelationGroupBox.Visible = true;
                        if (selectedRelationEdgeVertex.IsInParentRelation())
                        {
                            ChooseRelation(selectedRelationEdgeVertex.ParentRelation.GetType());
                        }
                        else
                        {
                            OnRelationBoxShow();
                            RelationGroupBox.Invalidate();
                            bitMap.Invalidate();
                        }
                        contextMenuStrip1.Show(bitMap, e.Location);
                    }
                    else if (RelationGroupBox.Visible)
                    {
                        RelationBoxHide();
                        bitMap.Invalidate();
                    }
                }
            }
            else if (e.Button == MouseButtons.Right && Control.ModifierKeys == Keys.Shift)
            {
                selectedVertex = GetVertexAtPosition(e.Location);
                if (selectedVertex != null)
                {
                    mouseDownUpAttach(false);
                    contextMenuStrip2.Show(bitMap, e.Location);
                    unlockToolStripMenuItem.Enabled = selectedVertex.Locked;
                    lockToolStripMenuItem.Enabled   = !selectedVertex.Locked;
                    bitMap.Invalidate();
                }
            }
        }