/*
	Copyright (c) 2024 PTC Inc. and/or Its Subsidiary Companies. All Rights Reserved.
*/



/*---------------------- Pro/Toolkit Includes ------------------------*/
#include <ProToolkit.h>
#include <ProGraphic.h>

/*---------------------- Application Includes ------------------------*/
#include <TestError.h>

/*---------------------- Function Prototypes -------------------------*/
ProError UserGetLine();


/*=====================================================================*\
    Input a point, p2, drawing a rubber banded line from p1
\*=====================================================================*/
ProError UserGetLine(ProPoint3d p1, ProPoint3d p2)
{
    ProMouseButton button;
    ProPoint3d op2;
    ProDrawMode old_graphics_mode;
    ProError err;

/*---------------------------------------------------------------------*\
    Set the drawing mode to COMPLEMENT
\*---------------------------------------------------------------------*/
    err=ProGraphicsModeSet(PRO_DRAW_COMPLEMENT_MODE,&old_graphics_mode);
    ERROR_CHECK("UserGetLine","ProGraphicsModeSet",err);

/*---------------------------------------------------------------------*\
    Start a line from the input position.
\*---------------------------------------------------------------------*/
    ProGraphicsPenPosition(p1);

/*---------------------------------------------------------------------*\
    Get the first sample mouse position, and draw a line to it
\*---------------------------------------------------------------------*/
    err=ProMouseTrack(0,&button,p2);
    ERROR_CHECK("UserGetLine","ProMouseTrack",err);
    ProGraphicsLineDraw(p2);

/*---------------------------------------------------------------------*\
    Remember the position.
\*---------------------------------------------------------------------*/
    op2[0]=p2[0];
    op2[1]=p2[1];
    op2[2]=p2[2];

    while(1)
    {
/*---------------------------------------------------------------------*\
        If the user hit a button
\*---------------------------------------------------------------------*/
        if(button)
            break;

/*---------------------------------------------------------------------*\
        Sample the mouse
\*---------------------------------------------------------------------*/
        err=ProMouseTrack(0,&button,p2);
	ERROR_CHECK("UserGetLine","ProMouseTrack(2)",err);

/*---------------------------------------------------------------------*\
        Undraw the prevous rubber band line.
        (Just redraw the line to the previous position.)
\*---------------------------------------------------------------------*/
        ProGraphicsPenPosition(p1);
        ProGraphicsLineDraw(op2);
        op2[0]=p2[0];
        op2[1]=p2[1];
        op2[2]=p2[2];

/*---------------------------------------------------------------------*\
        Draw a line to the new position.
\*---------------------------------------------------------------------*/
        ProGraphicsPenPosition(p1);
        ProGraphicsLineDraw(p2);
    }

/*---------------------------------------------------------------------*\
    Undraw the rubber band line.
\*---------------------------------------------------------------------*/
    ProGraphicsLineDraw(p1);

/*---------------------------------------------------------------------*\
    Set the drawing mode back to SET
\*---------------------------------------------------------------------*/
    ProGraphicsModeSet(PRO_DRAW_SET_MODE,&old_graphics_mode);

    return(button);
}