Example #1
0
        public bool Equals(IAction other)
        {
            CellClickAction realOther = other as CellClickAction;

            if (realOther == null)
            {
                return(false);
            }
            if (this.mesh == realOther.mesh &&
                realOther.buttons == this.buttons &&
                realOther.cellIndex == this.cellIndex)
            {
                return(true);
            }
            return(false);
        }
Example #2
0
        private void PerformAction(bool?right, int closestEdge, int closestCell)
        {
            if (closestEdge != -1)
            {
                if (markedEdges.Contains(closestEdge))
                {
                    return;
                }
                if (noToggle && Mesh.Edges[closestEdge].State != EdgeState.Empty)
                {
                    return;
                }

                /*if (shiftPressed || controlPressed)
                 * {
                 *  if (shiftPressed)
                 *  {
                 *      if (lastShift == -1)
                 *          lastShift = closestEdge;
                 *      else
                 *      {
                 *          ColorJoinAction colorAction = new ColorJoinAction(Mesh, lastShift, closestEdge, true);
                 *          if (lastShift != closestEdge)
                 *              undoTree.Do(colorAction);
                 *          lastShift = -1;
                 *      }
                 *  }
                 *  else if (controlPressed)
                 *  {
                 *      if (lastControl == -1)
                 *          lastControl = closestEdge;
                 *      else
                 *      {
                 *          ColorJoinAction colorAction = new ColorJoinAction(Mesh, lastControl, closestEdge, false);
                 *          if (lastControl != closestEdge)
                 *              undoTree.Do(colorAction);
                 *          lastControl = -1;
                 *      }
                 *  }
                 *  UpdateChildControls();
                 *  return;
                 * }*/
                LoopClickAction action;
                if (right.HasValue)
                {
                    action = new LoopClickAction(Mesh, closestEdge, right.Value, autoMove, disallowFalseMove, useICInAuto, considerMultipleLoopsInAuto, useColoringInAuto, useCellColoringInAuto);
                }
                else
                {
                    if (Mesh.Edges[closestEdge].State == lastState)
                    {
                        return;
                    }
                    bool pretendRight = false;
                    switch (lastState)
                    {
                    case EdgeState.Filled:
                        if (Mesh.Edges[closestEdge].State == EdgeState.Excluded)
                        {
                            pretendRight = true;
                        }
                        break;

                    case EdgeState.Excluded:
                        if (Mesh.Edges[closestEdge].State == EdgeState.Empty)
                        {
                            pretendRight = true;
                        }
                        break;

                    case EdgeState.Empty:
                        if (Mesh.Edges[closestEdge].State == EdgeState.Filled)
                        {
                            pretendRight = true;
                        }
                        break;
                    }
                    action = new LoopClickAction(Mesh, closestEdge, pretendRight, autoMove, disallowFalseMove, useICInAuto, considerMultipleLoopsInAuto, useColoringInAuto, useCellColoringInAuto);
                }
                if (!undoTree.Do(action))
                {
                    /*
                     * redEdge = closestEdge;
                     * Thread thread = new Thread(new ThreadStart(ClearRed));
                     * thread.IsBackground = true;
                     * thread.Start();
                     */
                }
                else if (noToggle)
                {
                    /*
                     * if (MovePerformed != null)
                     *  MovePerformed(this, new MoveEventArgs(closestEdge, e.Button == MouseButtons.Left));
                     * */
                }
                else
                {
                    if (right.HasValue)
                    {
                        lastState = Mesh.Edges[closestEdge].State;
                    }
                    bool satisified = true;
                    bool nonempty   = false;
                    for (int i = 0; i < Mesh.Intersections.Count; i++)
                    {
                        if (Mesh.Intersections[i].FilledCount != 2 && Mesh.Intersections[i].FilledCount != 0)
                        {
                            satisified = false;
                            break;
                        }
                        if (Mesh.Intersections[i].Type != IntersType.Unknown)
                        {
                            nonempty = true;
                            if (!Mesh.TypeSatisfied(i))
                            {
                                satisified = false;
                                break;
                            }
                        }
                    }
                    if (satisified && nonempty)
                    {
                        Mesh copy = new Mesh(Mesh);
                        try
                        {
                            copy.Clear();
                            bool failed = false;
                            if (copy.TrySolve() != SolveState.Solved)
                            {
                                copy.SolverMethod = SolverMethod.Recursive;
                                //copy.UseIntersectCellInteractsInSolver = false;
                                copy.UseCellColoringTrials = false;
                                copy.UseCellColoring       = true;
                                copy.UseCellPairs          = false;
                                copy.UseCellPairsTopLevel  = true;
                                copy.UseColoring           = true;
                                copy.UseDerivedColoring    = true;
                                copy.UseEdgeRestricts      = true;
                                copy.UseMerging            = true;
                                copy.ConsiderMultipleLoops = true;
                                copy.ColoringCheats        = true;
                                if (copy.TrySolve() != SolveState.Solved)
                                {
                                    failed = true;
                                }
                            }
                            if (!failed)
                            {
                                bool done = true;
                                for (int i = 0; i < Mesh.Edges.Count; i++)
                                {
                                    if (copy.SolutionFound.Edges[i].State == EdgeState.Filled)
                                    {
                                        if (Mesh.Edges[i].State != EdgeState.Filled)
                                        {
                                            done = false;
                                        }
                                    }
                                    else if (Mesh.Edges[i].State == EdgeState.Filled)
                                    {
                                        done = false;
                                    }
                                }
                                if (done)
                                {
                                    FixPosition();
                                    copy.FullClear();
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                }
                UpdateChildControls();
            }
            else if (closestCell != -1)
            {
                if (noToggle && Mesh.Cells[closestCell].Color != 0)
                {
                    return;
                }
                CellClickAction action = new CellClickAction(Mesh, closestCell, right.Value);
                undoTree.Do(action);
                UpdateChildControls();
            }
        }