/*
Copyright (c) 2019 PTC Inc. and/or Its Subsidiary Companies. All Rights Reserved.
*/
#include <ProToolkit.h>
#include <ProDtlnote.h>
#include <PTApplsUnicodeUtils.h>
/*====================================================================*\
FUNCTION : UsrSurfNoteCreate()
PURPOSE : Utility to create a note that documents the surface name or id.
\*====================================================================*/
int UsrSurfNoteCreate(
ProDrawing drawing,
ProSelection surf_sel, /* The surface - where the note leader
should be attached. */
ProVector pos) /* The location of the note itself */
{
ProDtlnotetext text;
ProName font;
ProDtlnoteline line;
ProModelitem modelitem;
ProName wname;
ProCharName name;
ProLine wstr;
ProCharLine str;
ProDtlnotedata ndata;
ProView view;
ProDtlattach attach, leader;
ProDtlnote note;
/*--------------------------------------------------------------------*\
Allocate a text item, and set its properties
\*--------------------------------------------------------------------*/
ProDtlnotetextAlloc(&text);
ProDtlnotetextHeightSet(text, -1.0);
ProDtlnotetextWidthSet(text, -1.0);
ProDtlnotetextSlantSet(text, 0.0);
ProDtlnotetextThicknessSet(text, 0.0);
ProStringToWstring(font, "font");
ProDtlnotetextFontSet(text, font);
/*--------------------------------------------------------------------*\
Get the name of the selected surface, form a string which
describes it, and add the string to the text item
\*--------------------------------------------------------------------*/
ProSelectionModelitemGet(surf_sel, &modelitem);
if(ProModelitemNameGet(&modelitem, wname) == PRO_TK_NO_ERROR)
ProWstringToString(name, wname);
else
ProTKSprintf(name, "id %d", modelitem.id);
ProTKSprintf(str, "Surface %s", name);
ProStringToWstring(wstr, str);
ProDtlnotetextStringSet(text, wstr);
/*--------------------------------------------------------------------*\
Allocate a new text line, and add the text item to it
\*--------------------------------------------------------------------*/
ProDtlnotelineAlloc(&line);
ProDtlnotelineTextAdd(line, text);
/*--------------------------------------------------------------------*\
Allocate a note description, and add the line to it
\*--------------------------------------------------------------------*/
ProDtlnotedataAlloc(drawing, &ndata);
ProDtlnotedataLineAdd(ndata, line);
/*--------------------------------------------------------------------*\
Set the attachment of the note itself
\*--------------------------------------------------------------------*/
ProSelectionViewGet(surf_sel, &view);
ProDtlattachAlloc(PRO_DTLATTACHTYPE_FREE, view, pos, NULL, &attach);
ProDtlnotedataAttachmentSet(ndata, attach);
/*--------------------------------------------------------------------*\
Add the note leader
\*--------------------------------------------------------------------*/
ProDtlattachAlloc(PRO_DTLATTACHTYPE_PARAMETRIC, NULL, NULL, surf_sel,
&leader);
ProDtlnotedataLeaderAdd(ndata, leader);
/*--------------------------------------------------------------------*\
Create the note
\*--------------------------------------------------------------------*/
ProDtlnoteCreate(drawing, NULL, ndata, ¬e);
/*--------------------------------------------------------------------*\
Display the note
\*--------------------------------------------------------------------*/
ProDtlnoteShow(¬e);
/*--------------------------------------------------------------------*\
Free the memory for the note description
\*--------------------------------------------------------------------*/
ProDtlnotedataFree(ndata);
}
int UsrSurfNoteCreateWrapper ()
{
ProDrawing drawing;
ProMouseButton button;
ProSelection *sel;
int n_sel;
ProVector pos;
ProFileName msgfil;
ProStringToWstring (msgfil, "msg_ugdrawing.txt");
ProMdlCurrentGet((ProMdl*)&drawing);
ProMessageDisplay(msgfil,"USER Select surface");
if(ProSelect("surface",1,NULL,NULL,NULL,NULL,&sel,&n_sel) !=
PRO_TK_NO_ERROR || n_sel < 1)
return(0);
ProMessageDisplay(msgfil,"USER Select note position");
if(ProMousePickGet(PRO_ANY_BUTTON, &button, pos) != PRO_TK_NO_ERROR)
return(0);
UsrSurfNoteCreate(drawing, sel[0], pos);
return (1);
}