private void RemoveDisplayForAClickType(ClickPositionOnImage clickPositionToRemove)
        {
            switch (clickPositionToRemove.PositionType)
            {
            case ClickPositionOnImageTypes.BottomMostPartOfModel:
                ImageCanvas.RemoveDisplayObject(DisplayMarkerNames.BottomMostPartOfModel);
                break;

            case ClickPositionOnImageTypes.LeftEndOfRotatingDisc:
                ImageCanvas.RemoveDisplayObject(DisplayMarkerNames.LeftEndOfRotatingDisc);
                ImageCanvas.RemoveDisplayObject(DisplayMarkerNames.CenterLine);
                ImageCanvas.RemoveDisplayObject(DisplayMarkerNames.DashedLineJoiningTwoEdgesOfDisc);
                break;

            case ClickPositionOnImageTypes.RightEndOfRotatingDisc:
                //undo the rotation
                ImageCanvas.SetImage(_currentImage);

                ImageCanvas.RemoveDisplayObject(DisplayMarkerNames.RightEndOfRotatingDisc);
                ImageCanvas.RemoveDisplayObject(DisplayMarkerNames.CenterLine);
                ImageCanvas.RemoveDisplayObject(DisplayMarkerNames.DashedLineJoiningTwoEdgesOfDisc);
                break;

            case ClickPositionOnImageTypes.MarkerLeftFromCenter:
                ImageCanvas.RemoveDisplayObject(DisplayMarkerNames.MarkerLeftFromCenter);
                break;

            case ClickPositionOnImageTypes.MarkerRightFromCenter:
                ImageCanvas.RemoveDisplayObject(DisplayMarkerNames.MarkerRightFromCenter);
                break;
            }
        }
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.ParentCanvas = ((System.Windows.Controls.Canvas)(target));
                return;

            case 2:
                this.HelpCanvas = ((System.Windows.Controls.Canvas)(target));
                return;

            case 3:
                this.ClickHelpImage = ((System.Windows.Controls.Image)(target));
                return;

            case 4:
                this.ClickHelpText = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 5:
                this.ClickHelpText1 = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 6:
                this.ClickHelpText2 = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 7:
                this.ClickHelpText3 = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 8:
                this.ImageCanvas = ((Ajubaa.IBModeler.UI.GetCameraParamsInputThroughImgPoints.ImageCanvas)(target));
                return;

            case 9:
                this.Requirements = ((System.Windows.Controls.Button)(target));

            #line 35 "..\..\..\AutoConfigureSettings.xaml"
                this.Requirements.Click += new System.Windows.RoutedEventHandler(this.OpenRequirementsWindow);

            #line default
            #line hidden
                return;

            case 10:
                this.AutoConfigure = ((System.Windows.Controls.Button)(target));

            #line 40 "..\..\..\AutoConfigureSettings.xaml"
                this.AutoConfigure.Click += new System.Windows.RoutedEventHandler(this.Return);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }
        private void PreviousClick(object sender, RoutedEventArgs e)
        {
            ImageCanvas.RemoveAllMarkers();
            var handler = ProcessPreviousImgEvent;

            if (handler != null)
            {
                handler(this, new EventArgs());
            }
        }
        private void UndoRealignLeftEdge()
        {
            var leftEdge = ClickSequences.FirstOrDefault(x => x.PositionType == ClickPositionOnImageTypes.LeftEndOfRotatingDisc);

            if (leftEdge == null)
            {
                throw new Exception("Left edge not found in the list.");
            }

            //rotate and reposition
            SetClickPositions(_leftEdgePositionBeforeRotation, leftEdge);

            //update left edge display
            ImageCanvas.RemoveDisplayObject(DisplayMarkerNames.LeftEndOfRotatingDisc);
            MarkPositionOnCanvas(_leftEdgePositionBeforeRotation, ClickPositionOnImageTypes.LeftEndOfRotatingDisc);
        }
        public void ProcessImage(string imagePath, List <ClickPositionOnImage> copyPositions, double rotateImageBy, int currentImageNumber, int totalImageCount)
        {
            _leftEdgePositionBeforeRotation = new Point(0, 0);
            _rotationAngleToRealign         = rotateImageBy;

            _imageName = Path.GetFileName(imagePath);

            //the dimensions of the _currentImage and the image canvas should be the same so rotation will work right
            _currentImage = MainProcessor.ResizeJpg(imagePath, null, (int)ImageCanvas.Width, (int)ImageCanvas.Height);

            //rotate image if edges of disc are defined and a rotation angle is already specified
            if (copyPositions != null && copyPositions.Exists(x => x.PositionType == ClickPositionOnImageTypes.LeftEndOfRotatingDisc) &&
                copyPositions.Exists(x => x.PositionType == ClickPositionOnImageTypes.RightEndOfRotatingDisc) &&
                _rotationAngleToRealign > 0)
            {
                var rotatedImg = MainProcessor.RotateImg(_currentImage, (float)_rotationAngleToRealign, _bkColor);
                ImageCanvas.SetImage(rotatedImg);
            }
            else
            {
                ImageCanvas.SetImage(_currentImage);
            }

            ClickSequences = GetClickSequencesForFirstImage();
            if (copyPositions != null)
            {
                foreach (var copyPosition in copyPositions)
                {
                    CopyPositions(copyPosition);
                }
            }

            //do not ask for the bottom most part, if it is not the first image
            if (currentImageNumber > 1)
            {
                ClickSequences.Remove(ClickSequences.FirstOrDefault(x => x.PositionType == ClickPositionOnImageTypes.BottomMostPartOfModel));
            }

            SetNextClickPositionType();

            Status.Text = string.Format("Image {0} of {1}", currentImageNumber, totalImageCount);

            Previous.Visibility = currentImageNumber > 1? Visibility.Visible : Visibility.Hidden;
            Next.Content        = currentImageNumber == totalImageCount ? "Save" : "Next";
        }
 private void Next_Click(object sender, RoutedEventArgs e)
 {
     if (CurrentClickPositionOnImageType != ClickPositionOnImageTypes.None)
     {
         MessageBox.Show("Please mark all positions before going to the next image.");
         return;
     }
     ImageCanvas.RemoveAllMarkers();
     if (IndividualImgProcessedEvent != null)
     {
         if (ClickSequences != null)
         {
             IndividualImgProcessedEvent(this, new IndividualImgProcessedEventArgs
             {
                 ClickPositions = ClickSequences, RotateImageBy = _rotationAngleToRealign,
                 ImageName      = _imageName
             });
         }
     }
 }
        private void MarkPositionOnCanvas(Point position, ClickPositionOnImageTypes positionType)
        {
            switch (positionType)
            {
            case ClickPositionOnImageTypes.BottomMostPartOfModel:
                ImageCanvas.MarkWithHorizontalLine(position, DisplayMarkerNames.BottomMostPartOfModel);
                break;

            case ClickPositionOnImageTypes.LeftEndOfRotatingDisc:
                ImageCanvas.DrawRectangleOnLeft(position, DisplayMarkerNames.LeftEndOfRotatingDisc);
                break;

            case ClickPositionOnImageTypes.RightEndOfRotatingDisc:
                ImageCanvas.DrawRectangleOnRight(position, DisplayMarkerNames.RightEndOfRotatingDisc);
                //draw center line
                var leftPosition = ClickSequences.FirstOrDefault(x => x.PositionType == ClickPositionOnImageTypes.LeftEndOfRotatingDisc);
                if (leftPosition != null && leftPosition.Processed)
                {
                    var centerPosition = new Point {
                        X = leftPosition.ClickXPos + ((position.X - leftPosition.ClickXPos) / 2.0), Y = 0
                    };
                    ImageCanvas.MarkWithVerticalDashedLine(centerPosition, DisplayMarkerNames.CenterLine);
                    ImageCanvas.GetDashedLineJoiningTwoEdgesOfDisc(new Point {
                        X = leftPosition.ClickXPos, Y = leftPosition.ClickYPos
                    }, position, DisplayMarkerNames.DashedLineJoiningTwoEdgesOfDisc);
                }
                break;

            case ClickPositionOnImageTypes.MarkerLeftFromCenter:
                ImageCanvas.AddMarkerDisplay(position, DisplayMarkerNames.MarkerLeftFromCenter);
                break;

            case ClickPositionOnImageTypes.MarkerRightFromCenter:
                ImageCanvas.AddMarkerDisplay(position, DisplayMarkerNames.MarkerRightFromCenter);
                break;
            }
        }
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.ParentCanvas = ((System.Windows.Controls.Canvas)(target));
                return;

            case 2:
                this.StatusPanel = ((System.Windows.Controls.StackPanel)(target));
                return;

            case 3:
                this.Status = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 4:
                this.HelpCanvas = ((System.Windows.Controls.Canvas)(target));
                return;

            case 5:
                this.ClickHelpImage = ((System.Windows.Controls.Image)(target));
                return;

            case 6:
                this.ClickHelpText = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 7:
                this.ClickHelpText1 = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 8:
                this.ClickHelpText2 = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 9:
                this.ClickHelpText3 = ((System.Windows.Controls.TextBlock)(target));
                return;

            case 10:
                this.ImageCanvas = ((Ajubaa.IBModeler.UI.GetCameraParamsInputThroughImgPoints.ImageCanvas)(target));
                return;

            case 11:
                this.Previous = ((System.Windows.Controls.Button)(target));

            #line 48 "..\..\..\IndividualImgHandler.xaml"
                this.Previous.Click += new System.Windows.RoutedEventHandler(this.PreviousClick);

            #line default
            #line hidden
                return;

            case 12:
                this.Undo = ((System.Windows.Controls.Button)(target));

            #line 53 "..\..\..\IndividualImgHandler.xaml"
                this.Undo.Click += new System.Windows.RoutedEventHandler(this.UndoClick);

            #line default
            #line hidden
                return;

            case 13:
                this.Next = ((System.Windows.Controls.Button)(target));

            #line 58 "..\..\..\IndividualImgHandler.xaml"
                this.Next.Click += new System.Windows.RoutedEventHandler(this.Next_Click);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }
        void OnMouseDown(object sender, MouseButtonEventArgs mouseButtonEventArgs)
        {
            var position = mouseButtonEventArgs.GetPosition(ImageCanvas);

            if (CurrentClickPositionOnImageType == ClickPositionOnImageTypes.None)
            {
                return;
            }

            if (!AllowedRangeHelper.IsInAllowedRange(position, ImageCanvas.Width, ImageCanvas.Height, CurrentClickPositionOnImageType, ClickSequences))
            {
                return;
            }

            var matchingInList = ClickSequences.FirstOrDefault(x => x.PositionType == CurrentClickPositionOnImageType);

            if (matchingInList == null)
            {
                throw new Exception("Click type could not be recognized.");
            }

            if (CurrentClickPositionOnImageType == ClickPositionOnImageTypes.RightEndOfRotatingDisc)
            {
                //get the left edge position
                var leftEdge = ClickSequences.FirstOrDefault(x => x.PositionType == ClickPositionOnImageTypes.LeftEndOfRotatingDisc);
                if (leftEdge == null)
                {
                    throw new Exception("Left edge not found in the list.");
                }

                //get rotation angle to realign the left and right edges
                var rotationAngleToRealign = MainProcessor.GetRotationAngleToRealign(leftEdge,
                                                                                     new ClickPositionOnImage
                {
                    ClickXPos     = position.X, ClickYPos = position.Y,
                    PositionType  = ClickPositionOnImageTypes.RightEndOfRotatingDisc,
                    AllowedHeight = ImageCanvas.Height, AllowedWidth = ImageCanvas.Width
                });

                //realign the x and y positions of the ends of the disc in line with the rotated image
                var newRightEdgePosition = RotationHelper.GetRotatedPosition(rotationAngleToRealign, position);

                if (newRightEdgePosition == null || !(0 <= newRightEdgePosition.Value.X && newRightEdgePosition.Value.X < ImageCanvas.Width) ||
                    !(0 <= newRightEdgePosition.Value.Y && newRightEdgePosition.Value.Y < ImageCanvas.Height))
                {
                    MessageBox.Show("Either the selection of the top left and right corners of the disc is wrong or the disc in the photo is in too much slanting.");
                    return;
                }

                var leftEdgePositionBeforeRotation = new Point(leftEdge.ClickXPos, leftEdge.ClickYPos);
                var newLeftEdgePosition            = RotationHelper.GetRotatedPosition(rotationAngleToRealign, leftEdgePositionBeforeRotation);
                if (newLeftEdgePosition == null || !(0 <= newLeftEdgePosition.Value.X && newLeftEdgePosition.Value.X < ImageCanvas.Width) ||
                    !(0 <= newLeftEdgePosition.Value.Y && newLeftEdgePosition.Value.Y < ImageCanvas.Height))
                {
                    MessageBox.Show("Either the selection of the top left and right corners of the disc is wrong or the disc in the photo is in too much slanting.");
                    return;
                }

                _rotationAngleToRealign         = rotationAngleToRealign;
                _leftEdgePositionBeforeRotation = leftEdgePositionBeforeRotation;

                //the dimensions of the _currentImage and the image canvas are the same so rotation will work right
                var rotatedImg = MainProcessor.RotateImg(_currentImage, (float)_rotationAngleToRealign, _bkColor);

                ImageCanvas.SetImage(rotatedImg);

                //set the realigned click positions for top left edge and top right edge
                SetClickPositions(newRightEdgePosition.Value, matchingInList);
                SetClickPositions(newLeftEdgePosition.Value, leftEdge);

                //update left edge display
                ImageCanvas.RemoveDisplayObject(DisplayMarkerNames.LeftEndOfRotatingDisc);
                MarkPositionOnCanvas(newLeftEdgePosition.Value, ClickPositionOnImageTypes.LeftEndOfRotatingDisc);

                //update right edge display
                MarkPositionOnCanvas(newRightEdgePosition.Value, CurrentClickPositionOnImageType);
            }
            else
            {
                SetClickPositions(position, matchingInList);
                MarkPositionOnCanvas(position, CurrentClickPositionOnImageType);
            }

            SetNextClickPositionType();
        }