/*
Copyright (c) 2019 PTC Inc. and/or Its Subsidiary Companies. All Rights Reserved.
*/
/*---------------------- Pro/Toolkit Includes ------------------------*/
#include "ProToolkit.h"
#include "ProGraphic.h"
#include <PTApplsUnicodeUtils.h>
/*---------------------- Application Includes ------------------------*/
#include "TestError.h"
/*---------------------- Function Prototypes -------------------------*/
int UserPolyline();
ProError UserGetLine();
int UserPolyline()
{
ProPoint3d p1, p2;
ProMouseButton button;
ProLine w_font;
ProError err;
int font_id, np=1;
char text[80];
wchar_t w_text[80];
ProTextAttribute text_atts,old_atts;
/*---------------------------------------------------------------------*\
Get the id of the font called "filled".
\*---------------------------------------------------------------------*/
ProStringToWstring(w_font,"filled.ndx");
err=ProTextFontNameToId(w_font,&font_id);
ERROR_CHECK("UserPolyline","ProTextFontNameToId",err);
/*---------------------------------------------------------------------*\
Get the current text attributes and remember them
\*---------------------------------------------------------------------*/
ProTextAttributesCurrentGet(&old_atts);
memcpy(&text_atts,&old_atts,sizeof(ProTextAttribute));
/*---------------------------------------------------------------------*\
Modify the text attributes, font = 'filled',
height = double the default, and slant = 10 degrees (italic)
*---------------------------------------------------------------------*/
text_atts.font_id = font_id;
text_atts.height *= 2.0;
text_atts.slant_angle = 10.0;
ProTextFontIdCurrentSet(font_id);
ProTextHeightCurrentSet(text_atts.height);
ProTextSlantAngleCurrentSet(text_atts.slant_angle);
/*---------------------------------------------------------------------*\
Get the first point from the user
\*---------------------------------------------------------------------*/
err=ProMousePickGet(PRO_LEFT_BUTTON,&button,p1);
ERROR_CHECK("UserPolyline","ProMousePickGet(p1)",err);
/*---------------------------------------------------------------------*\
Label it with some text
\*---------------------------------------------------------------------*/
ProTKSprintf(text,"Point %d",np++);
ProStringToWstring(w_text,text);
ProGraphicsTextDisplay(p1,w_text);
while(1)
{
/*---------------------------------------------------------------------*\
Get a new point (using example 6.6)
\*---------------------------------------------------------------------*/
button = UserGetLine(p1,p2);
/*---------------------------------------------------------------------*\
If the user hit the middle or right button, finish up.
\*---------------------------------------------------------------------*/
if((button & PRO_RIGHT_BUTTON) ||
(button & PRO_MIDDLE_BUTTON))
break;
/*---------------------------------------------------------------------*\
Draw a line between the new point and the previous one
\*---------------------------------------------------------------------*/
ProGraphicsPenPosition(p1);
ProGraphicsLineDraw(p2);
/*---------------------------------------------------------------------*\
Label the new point with some text
\*---------------------------------------------------------------------*/
ProTKSprintf(text,"Point %d",np++);
ProStringToWstring(w_text,text);
ProGraphicsTextDisplay(p2,w_text);
/*---------------------------------------------------------------------*\
Remember the point
\*---------------------------------------------------------------------*/
p1[0] = p2[0];
p1[1] = p2[1];
p1[2] = p2[2];
}
/*---------------------------------------------------------------------*\
Restore the original text attributes
\*---------------------------------------------------------------------*/
ProTextFontIdCurrentSet(old_atts.font_id);
ProTextHeightCurrentSet(old_atts.height);
ProTextWidthFactorCurrentSet(old_atts.width_factor);
ProTextRotationAngleCurrentSet(old_atts.rot_angle);
ProTextSlantAngleCurrentSet(old_atts.slant_angle);
}