/*
Copyright (c) 2019 PTC Inc. and/or Its Subsidiary Companies. All Rights Reserved.
*/
#include "ProToolkit.h"
#include "ProParameter.h"
#include "ProUtil.h"
#include "ProNotify.h"
#include "ProParamval.h"
#include <PTApplsUnicodeUtils.h>
#include <ProWeld.h>
#include "TestError.h"
#include "UtilString.h"
int UsrWeldNotificationSet()
{
int status;
ProError ptk_get_text_func();
ProError ptk_get_path_func();
status = ProNotificationSet( PRO_DRAWING_WELD_SYMPATH_GET,
ptk_get_path_func );
status = ProNotificationSet( PRO_DRAWING_WELD_SYMTEXT_GET,
ptk_get_text_func );
return(0);
}
/*=====================================================*\
FUNCTION: ptk_get_path_func
PURPOSE: Set path of a user defined symbol for features containing
parameter named "SYMBOL"
\*====================================================*/
ProError ptk_get_path_func( ProDrawing p_draw, ProMdl p_model,
int feat_id, ProPath sym_def_file_path,
ProPath ptk_sym_def_path)
{
ProError status;
ProParameter param;
ProName name;
ProParamvalue value;
char filename[PRO_FILE_NAME_SIZE];
char unitname[PRO_LINE_SIZE];
char path[PRO_PATH_SIZE];
char unitpath[PRO_PATH_SIZE];
ProFeature afeat;
ProUnititem units;
/*---------------------------------------------------------------------*\
Check if feature being passed in contains a parameter named "SYMBOL"
\*---------------------------------------------------------------------*/
ProStringToWstring(name,"SYMBOL");
status=ProFeatureInit((ProSolid)p_model,feat_id,&afeat);
status = ProParameterInit((ProModelitem*)&afeat,name,¶m);
/*---------------------------------------------------------------------*\
Build new path using value of parameter string and return PRO_TK_NO_ERROR
to flag Pro/E to use this path instead of input path (sym_def_file_path)
\*---------------------------------------------------------------------*/
if(status == PRO_TK_NO_ERROR)
{
status = ProParameterValueWithUnitsGet(¶m,&value,&units);
ProWstringToString(filename,value.value.s_val);
strcpy(path,"/whole_path/user_symlib/");
strcat(path,filename);
ProWstringToString(unitname,units.name);
strcpy(unitpath,"/whole_path/user_symlib/");
strcat(unitpath,unitname);
ProStringToWstring( ptk_sym_def_path, path);
ProStringToWstring( ptk_sym_def_path, unitpath);
return PRO_TK_NO_ERROR;
}
return PRO_TK_E_NOT_FOUND;
}
/*=====================================================================*\
FUNCTION: ptk_get_text_func
PURPOSE: Modify symbol instance text based on sym_prompt_name values
\*=====================================================================*/
ProError ptk_get_text_func(ProDrawing p_draw,ProMdl p_model,int feat_id,
int sym_def_id,wchar_t sym_prompt_name[],
int sym_prompt_nm_idx, ProParamvalue* p_text,
ProParamvalue* p_ptk_text )
{
char tmp[PRO_LINE_SIZE],s_id[PRO_LINE_SIZE];
char name[PRO_LINE_SIZE], text_val[PRO_LINE_SIZE];
wchar_t ws_id[PRO_LINE_SIZE],text[PRO_LINE_SIZE];
ProFeature weld_fea;
int sequence_id;
ProError status;
ProParameter param;
ProParamvalue value;
ProUnititem units;
ProWstringToString(name,sym_prompt_name);
/*---------------------------------------------------------------------*\
Set sequence number
\*---------------------------------------------------------------------*/
if(strcmp(name,"seq_var")==0)
{
ProFeatureInit((ProSolid)p_model,feat_id,&weld_fea);
ProWeldSequenceIdGet(&weld_fea,&sequence_id);
ProTKSprintf(s_id,"%d",sequence_id);
ProStringToWstring(ws_id, s_id);
status = ProParamvalueSet(p_ptk_text,ws_id,PRO_PARAM_STRING);
return PRO_TK_NO_ERROR;
}
/*---------------------------------------------------------------------*\
Set sample text string from parameter value
\*---------------------------------------------------------------------*/
if(strcmp(name,"text")==0)
{
ProFeatureInit((ProSolid)p_model,feat_id,&weld_fea);
ProStringToWstring(text,"TESTING");
status = ProParameterInit((ProModelitem*)&weld_fea,text,¶m);
if(status == PRO_TK_NO_ERROR)
{
status =ProParameterValueWithUnitsGet(¶m,&value,&units);
ProWstringToString(text_val,value.value.s_val);
status = ProParamvalueSet(p_ptk_text,value.value.s_val,
PRO_PARAM_STRING);
return PRO_TK_NO_ERROR;
}
}
return PRO_TK_E_NOT_FOUND;
}