/* Copyright (c) 2024 PTC Inc. and/or Its Subsidiary Companies. All Rights Reserved. */ /*--------------------------------------------------------------------*\ Pro/Toolkit includes -- include this first \*--------------------------------------------------------------------*/ #include <ProMenu.h> #include <ProToolkit.h> #include <ProUtil.h> /*--------------------------------------------------------------------*\ Application includes \*--------------------------------------------------------------------*/ #include <ProMechItem.h> #include <ProMechLoad.h> #include <ProMessage.h> #include <PTMechExamples.h> static ProFileName msgfile; /*=============================================================*\ FUNCTION : PTMechExForceLoad PURPOSE : To create force load. \*=============================================================*/ ProError PTMechExForceLoad() { ProMdl model; ProMechItem load_item; ProMechForceData f_data; ProMechVectoredValue f_vector, m_vector; ProMechStatus mech_status; ProMechExpression force_vector[] = {L"10", L"0", L"45"}; ProMechExpression moment_vector [] = {L"20", L"10", L"25"}; ProStringToWstring (msgfile, "msg_load.txt"); status = ProMdlCurrentGet (&model); PT_TEST_LOG_SUCC ("ProMdlCurrentGet"); /* Set references to the mechItem */ status = PTMechExReferencesSet (model, "tk_new_load_force", &load_item); PT_TEST_LOG ("PTMechExReferencesSet", status, status != PRO_TK_NO_ERROR && status != PRO_TK_BAD_INPUTS); if (status != PRO_TK_NO_ERROR) return PRO_TK_BAD_INPUTS; status = ProMechforcedataAlloc (&f_data); PT_TEST_LOG_SUCC ("ProMechforcedataAlloc"); /* Set the force type */ status = ProMechforcedataTypeSet (f_data, PRO_MECH_FORCE_TOTAL); PT_TEST_LOG_SUCC ("ProMechforcedataTypeSet"); /* create the vectored value for the Force component */ status = PTMechExComponentsVectoredValueCreate (3, force_vector, &f_vector); PT_TEST_LOG_SUCC ("PTMechExComponentsVectoredValueCreate"); /* assigns the force components */ status = ProMechforcedataForceSet (f_data, f_vector); PT_TEST_LOG_SUCC ("ProMechforcedataForceSet"); if (status != PRO_TK_NO_ERROR) return PRO_TK_GENERAL_ERROR; /* create the vectored value for the Moment component */ status = PTMechExComponentsVectoredValueCreate (3, moment_vector, &m_vector); PT_TEST_LOG_SUCC ("PTMechExComponentsVectoredValueCreate"); /* assigns the moment components */ status = ProMechforcedataMomentSet (f_data, m_vector); PT_TEST_LOG_SUCC ("ProMechforcedataMomentSet"); if (status != PRO_TK_NO_ERROR) return PRO_TK_GENERAL_ERROR; /* sets the force data to the item else returns CANT_ACCESS if not in proper Mechanica mode */ status = ProMechloadForcedataSet (&load_item, f_data); PT_TEST_LOG ("ProMechloadForcedataSet", status, status != PRO_TK_NO_ERROR && status != PRO_TK_CANT_ACCESS); PTMechExItemProcess (model, status, load_item); status = ProMechforcedataFree (f_data); PT_TEST_LOG_SUCC ("ProMechforcedataFree"); return PRO_TK_NO_ERROR; } /*=============================================================*\ FUNCTION : PTMechExPressureLoad PURPOSE : To create pressure load. \*=============================================================*/ ProError PTMechExPressureLoad() { ProMdl model; ProMechItem load_item; ProMechPressureData p_data; ProMechValue mech_val; ProMechStatus mech_status; ProStringToWstring (msgfile, "msg_load.txt"); status = ProMdlCurrentGet (&model); PT_TEST_LOG_SUCC ("ProMdlCurrentGet"); /* Set references to the mechItem */ status = PTMechExReferencesSet (model, "tk_new_load_press", &load_item); PT_TEST_LOG ("PTMechExReferencesSet", status, status != PRO_TK_NO_ERROR && status != PRO_TK_BAD_INPUTS); if (status != PRO_TK_NO_ERROR) return PRO_TK_BAD_INPUTS; status = ProMechpressuredataAlloc (&p_data); PT_TEST_LOG_SUCC ("ProMechpressuredataAlloc"); status = PTMechExValueByExpressionCreate (L"75", &mech_val); PT_TEST_LOG_SUCC ("PTMechExValueByExpressionCreate"); /* Set the value to pressure data */ status = ProMechpressuredataValueSet (p_data, mech_val); PT_TEST_LOG_SUCC ("ProMechpressuredataValueSet"); if (status != PRO_TK_NO_ERROR) return PRO_TK_GENERAL_ERROR; /* sets the pressure data to the item else returns CANT_ACCESS if not in proper Mechanica mode */ status = ProMechloadPressuredataSet (&load_item, p_data); PT_TEST_LOG ("ProMechloadPressuredataSet", status, status != PRO_TK_NO_ERROR && status != PRO_TK_CANT_ACCESS); PTMechExItemProcess (model, status, load_item); status = ProMechpressuredataFree (p_data); PT_TEST_LOG_SUCC ("ProMechpressuredataFree"); return PRO_TK_NO_ERROR; } /*=============================================================*\ FUNCTION : PTMechExBearingLoad PURPOSE : To create bearing load. \*=============================================================*/ ProError PTMechExBearingLoad() { ProMdl model; ProMechItem load_item; ProMechBearingData b_data; ProMechVectoredValue f_vector; ProMechStatus mech_status; ProMechExpression force_vector[] = {L"15", L"40", L"35"}; ProStringToWstring (msgfile, "msg_load.txt"); status = ProMdlCurrentGet (&model); PT_TEST_LOG_SUCC ("ProMdlCurrentGet"); /* Set references to the mechItem */ status = PTMechExReferencesSet (model, "tk_new_load_bear", &load_item); PT_TEST_LOG ("PTMechExReferencesSet", status, status != PRO_TK_NO_ERROR && status != PRO_TK_BAD_INPUTS); if (status != PRO_TK_NO_ERROR) return PRO_TK_BAD_INPUTS; status = ProMechbearingdataAlloc (&b_data); PT_TEST_LOG_SUCC ("ProMechbearingdataAlloc"); /* create the vectored value for the Force component */ status = PTMechExComponentsVectoredValueCreate (3, force_vector, &f_vector); PT_TEST_LOG_SUCC ("PTMechExComponentsVectoredValueCreate"); /* Set the value for bearing data */ status = ProMechbearingdataValueSet (b_data, f_vector); PT_TEST_LOG_SUCC ("ProMechbearingdataValueSet"); if (status != PRO_TK_NO_ERROR) return PRO_TK_GENERAL_ERROR; /* sets the bearing data to the item else returns CANT_ACCESS if not in proper Mechanica mode */ status = ProMechloadBearingdataSet (&load_item, b_data); PT_TEST_LOG ("ProMechloadBearingdataSet", status, status != PRO_TK_NO_ERROR && status != PRO_TK_CANT_ACCESS); PTMechExItemProcess (model, status, load_item); status = ProMechbearingdataFree (b_data); PT_TEST_LOG_SUCC ("ProMechbearingdataFree"); return PRO_TK_NO_ERROR; } /*=============================================================*\ FUNCTION : PTMechExGravityLoad PURPOSE : To create gravity load. \*=============================================================*/ ProError PTMechExGravityLoad() { ProMdl model; PTMechExGeomRef g_ref[] = {{PRO_MECH_MODEL, -1, -1, NULL}}; ProMechGeomref *n_surf; ProMechItem load_item; ProMechGravityData g_data; ProName tk_load_name; ProMechStatus mech_status; ProMechVectoredValue g_value; ProMechExpression gravity_vector[] = {L"0", L"1", L"0"}; ProStringToWstring (msgfile, "msg_load.txt"); status = ProMdlCurrentGet (&model); PT_TEST_LOG_SUCC ("ProMdlCurrentGet"); status = ProMechitemCreate ((ProSolid)model, PRO_SIMULATION_LOAD, &load_item); PT_TEST_LOG_SUCC ("ProMechitemCreate"); ProStringToWstring (tk_load_name, "tk_new_load_gravity"); status = ProMechitemNameSet (&load_item, tk_load_name); PT_TEST_LOG ("ProMechitemNameSet", status, status != PRO_TK_NO_ERROR && status != PRO_TK_GENERAL_ERROR); status = PTMechExGeomReferenceArrayCreate (1, g_ref, &n_surf); PT_TEST_LOG_SUCC ("PTMechExGeomReferenceArrayCreate"); /* Set the references to the mech item */ status = ProMechloadReferencesSet (&load_item, n_surf); PT_TEST_LOG_SUCC ("ProMechloadReferencesSet"); if (status != PRO_TK_NO_ERROR) return PRO_TK_BAD_INPUTS; status = ProMechgravitydataAlloc (&g_data); PT_TEST_LOG_SUCC ("ProMechgravitydataAlloc"); /* create the directional vectored value of the gravity component */ status = PTMechExDirVectorMagnitudeValueCreate (3, gravity_vector, L"40", &g_value); PT_TEST_LOG_SUCC ("PTMechExDirVectorMagnitudeValueCreate"); /* Set the value to the gravity data */ status = ProMechgravitydataValueSet (g_data, g_value); PT_TEST_LOG_SUCC ("ProMechgravitydataValueSet"); if (status != PRO_TK_NO_ERROR) return PRO_TK_GENERAL_ERROR; /* sets the gravity data to the item else returns CANT_ACCESS if not in proper Mechanica mode */ status = ProMechloadGravitydataSet (&load_item, g_data); PT_TEST_LOG ("ProMechloadGravitydataSet", status, status != PRO_TK_NO_ERROR && status != PRO_TK_CANT_ACCESS); PTMechExItemProcess (model, status, load_item); status = ProMechgravitydataFree (g_data); PT_TEST_LOG_SUCC ("ProMechgravitydataFree"); return PRO_TK_NO_ERROR; } /*=============================================================*\ FUNCTION : PTMechExCentrifLoad PURPOSE : To create centrifugal load. \*=============================================================*/ ProError PTMechExCentrifLoad() { ProMdl model; ProMechGeomref *n_surf; ProMechItem load_item; ProMechCentrifugalData c_data; ProName tk_load_name; ProMechValue mech_val; ProMechStatus mech_status; ProMechVectoredValue v_value, a_value; PTMechExGeomRef g_ref[] = {{PRO_MECH_MODEL, -1, -1, NULL}}; ProMechExpression c_vel[] = {L"1", L"0.5", L"-1"}; ProMechExpression acc_exp[] = {L"0", L"1", L"1"}; ProStringToWstring (msgfile, "msg_load.txt"); status = ProMdlCurrentGet (&model); PT_TEST_LOG_SUCC ("ProMdlCurrentGet"); /* creates the mech item */ status = ProMechitemCreate ((ProSolid)model, PRO_SIMULATION_LOAD, &load_item); PT_TEST_LOG_SUCC ("ProMechitemCreate"); /* sets the name to mech item */ ProStringToWstring (tk_load_name, "tk_new_load_centrif"); status = ProMechitemNameSet (&load_item, tk_load_name); PT_TEST_LOG ("ProMechitemNameSet", status, status != PRO_TK_NO_ERROR && status != PRO_TK_GENERAL_ERROR); status = PTMechExGeomReferenceArrayCreate (1, g_ref, &n_surf); PT_TEST_LOG_SUCC ("PTMechExGeomReferenceArrayCreate"); /* Set the references to the mechitem */ status = ProMechloadReferencesSet (&load_item, n_surf); PT_TEST_LOG_SUCC ("ProMechloadReferencesSet"); if (status != PRO_TK_NO_ERROR) return PRO_TK_BAD_INPUTS; status = ProMechcentrifugaldataAlloc (&c_data); PT_TEST_LOG_SUCC ("ProMechcentrifugaldataAlloc"); /* create the directional vectored value for the Velocity component */ status = PTMechExDirVectorMagnitudeValueCreate (3, c_vel, L"40", &v_value); PT_TEST_LOG_SUCC ("PTMechExDirVectorMagnitudeValueCreate"); status = ProMechcentrifugaldataVelocitySet (c_data, v_value); PT_TEST_LOG_SUCC ("ProMechcentrifugaldataVelocitySet"); /* create the directional vectored value for the Acceleration component */ status = PTMechExComponentsVectoredValueCreate (3, acc_exp, &a_value); PT_TEST_LOG_SUCC ("PTMechExComponentsVectoredValueCreate"); status = ProMechcentrifugaldataAccelerationSet (c_data, a_value); PT_TEST_LOG_SUCC ("ProMechcentrifugaldataAccelerationSet"); if (status != PRO_TK_NO_ERROR) return PRO_TK_GENERAL_ERROR; /* sets the centrifugal data to the item else return CANT_ACCESS if not in proper Mechanica mode */ status = ProMechloadCentrifugaldataSet (&load_item, c_data); PT_TEST_LOG ("ProMechloadCentrifugaldataSet", status, status != PRO_TK_NO_ERROR && status != PRO_TK_CANT_ACCESS); PTMechExItemProcess (model, status, load_item); status = ProMechcentrifugaldataFree (c_data); PT_TEST_LOG_SUCC ("ProMechcentrifugaldataFree"); return PRO_TK_NO_ERROR; } /*=============================================================*\ FUNCTION : PTMechExStructtempLoad PURPOSE : To create structural temperature load. \*=============================================================*/ ProError PTMechExStructtempLoad() { ProMdl model; ProMechGeomref *n_surf; ProMechItem load_item; ProMechStructtempData t_data; ProName tk_load_name; ProMechValue mech_val; ProMechStatus mech_status; PTMechExGeomRef t_ref[] = {{PRO_MECH_MODEL, -1, -1, NULL}}; ProStringToWstring (msgfile, "msg_load.txt"); status = ProMdlCurrentGet (&model); PT_TEST_LOG_SUCC ("ProMdlCurrentGet"); status = ProMechitemCreate ((ProSolid)model, PRO_SIMULATION_LOAD, &load_item); PT_TEST_LOG_SUCC ("ProMechitemCreate"); ProStringToWstring (tk_load_name, "tk_new_load_structtemp"); status = ProMechitemNameSet (&load_item, tk_load_name); PT_TEST_LOG ("ProMechitemNameSet", status, status != PRO_TK_NO_ERROR && status != PRO_TK_GENERAL_ERROR); status = PTMechExGeomReferenceArrayCreate (1, t_ref, &n_surf); PT_TEST_LOG_SUCC ("PTMechExGeomReferenceArrayCreate"); /* Set the references to the mechitem */ status = ProMechloadReferencesSet (&load_item, n_surf); PT_TEST_LOG_SUCC ("ProMechloadReferencesSet"); if (status != PRO_TK_NO_ERROR) return PRO_TK_BAD_INPUTS; status = ProMechstructtempdataAlloc (&t_data); PT_TEST_LOG_SUCC ("ProMechstructtempdataAlloc"); /* sets the temperature to the data */ status = ProMechstructtempdataReftempSet (t_data, L"90"); PT_TEST_LOG_SUCC ("ProMechstructtempdataReftempSet"); status = PTMechExValueByExpressionCreate (L"30", &mech_val); PT_TEST_LOG_SUCC ("PTMechExValueByExpressionCreate"); /* Set the value to the structural temperature data */ status = ProMechstructtempdataValueSet (t_data, mech_val); PT_TEST_LOG_SUCC ("ProMechstructtempdataValueSet"); if (status != PRO_TK_NO_ERROR) return PRO_TK_GENERAL_ERROR; /* seta the temperature data to the item else return CANT_ACCESS if not in proper Mechanica mode */ status = ProMechloadStructtempdataSet (&load_item, t_data); PT_TEST_LOG("ProMechloadStructtempdataSet", status, status != PRO_TK_NO_ERROR && status != PRO_TK_CANT_ACCESS); PTMechExItemProcess (model, status, load_item); status = ProMechstructtempdataFree (t_data); PT_TEST_LOG_SUCC ("ProMechstructtempdataFree"); return PRO_TK_NO_ERROR; } /*=============================================================*\ FUNCTION : PTMechExHeatLoad PURPOSE : To create heat load. \*=============================================================*/ ProError PTMechExHeatLoad() { ProMdl model; ProMechItem load_item; ProMechHeatData h_data; ProMechValue mech_val; ProMechStatus mech_status; ProStringToWstring (msgfile, "msg_load.txt"); status = ProMdlCurrentGet (&model); PT_TEST_LOG_SUCC ("ProMdlCurrentGet"); /* Set the references to the mechitem */ status = PTMechExReferencesSet (model, "tk_new_load_heat", &load_item); PT_TEST_LOG ("PTMechExReferencesSet", status, status != PRO_TK_NO_ERROR && status != PRO_TK_BAD_INPUTS); if (status != PRO_TK_NO_ERROR) return PRO_TK_BAD_INPUTS; status = ProMechheatdataAlloc (&h_data); PT_TEST_LOG_SUCC ("ProMechheatdataAlloc"); /* Set the heat data type */ status = ProMechheatdataTypeSet (h_data, PRO_MECH_HEAT_TOTAL); PT_TEST_LOG_SUCC ("ProMechheatdataTypeSet"); status = PTMechExValueByExpressionCreate (L"60", &mech_val); PT_TEST_LOG_SUCC ("PTMechExValueByExpressionCreate"); /* Set the value to the heat data */ status = ProMechheatdataValueSet (h_data, mech_val); PT_TEST_LOG_SUCC ("ProMechheatdataValueSet"); /* sets the heat data to the item else return CANT_ACCESS if not in proper Mechanica mode */ status = ProMechloadHeatdataSet (&load_item, h_data); PT_TEST_LOG ("ProMechloadHeatdataSet", status, status != PRO_TK_NO_ERROR && status != PRO_TK_CANT_ACCESS); if (status == PRO_TK_NO_ERROR) { PTMechExLoadsetCreate((ProSolid)model, "ThermLoadSet1"); /* check the existence of loadset or create the required */ status = PTMechExAddLoadinLoadset (model, "ThermLoadSet1", &load_item); PT_TEST_LOG_SUCC ("PTMechExAddLoadinLoadset"); status = ProMechitemStatusGet (&load_item, &mech_status); PT_TEST_LOG_SUCC ("ProMechitemStatusGet"); if (mech_status == PRO_MECH_ACTIVE) { /* Update the model with the created mech item */ status = ProMechitemUpdateComplete (&load_item); PT_TEST_LOG_SUCC ("ProMechitemUpdateComplete"); if (status == PRO_TK_NO_ERROR) { status = ProMessageDisplay (msgfile, "PTMechExLoad - Mechload created successfully", msgbuf); PT_TEST_LOG_SUCC ("ProMessageDisplay"); } } } else if (status == PRO_TK_CANT_ACCESS) { /* check for the invalid mechanica mode */ status = ProMessageDisplay (msgfile, "PTMechExLoad - Invalid Mechanica mode", msgbuf); PT_TEST_LOG_SUCC ("ProMessageDisplay"); } status = ProMechheatdataFree (h_data); PT_TEST_LOG_SUCC ("ProMechheatdataFree"); return PRO_TK_NO_ERROR; } /*=============================================================*\ FUNCTION : PTMechExItemProcess PURPOSE : To process mechitem. \*=============================================================*/ ProError PTMechExItemProcess (ProMdl model, ProError status, ProMechItem item) { ProMechStatus mech_status; if (status == PRO_TK_NO_ERROR) { /* check the existence of loadset or create the required */ PTMechExLoadsetCreate((ProSolid)model, "LoadSet1"); status = PTMechExAddLoadinLoadset (model, "LoadSet1", &item); PT_TEST_LOG_SUCC ("PTMechExAddLoadinLoadset"); status = ProMechitemStatusGet (&item, &mech_status); PT_TEST_LOG_SUCC ("ProMechitemStatusGet"); if (mech_status == PRO_MECH_ACTIVE) { /* Update the model for the created mech item */ status = ProMechitemUpdateComplete (&item); PT_TEST_LOG_SUCC ("ProMechitemUpdateComplete"); if (status == PRO_TK_NO_ERROR) { status = ProMessageDisplay (msgfile, "PTMechExLoad - Mechload created successfully", msgbuf); PT_TEST_LOG_SUCC ("ProMessageDisplay"); } } } else if (status == PRO_TK_CANT_ACCESS) { /* check for the invalid mechanica mode */ status = ProMessageDisplay (msgfile, "PTMechExLoad - Invalid Mechanica mode", msgbuf); PT_TEST_LOG_SUCC ("ProMessageDisplay"); return PRO_TK_BAD_INPUTS; } return PRO_TK_NO_ERROR; } /*=============================================================*\ FUNCTION : PTMechExReferencesSet PURPOSE : To set reference to mechitem. \*=============================================================*/ ProError PTMechExReferencesSet (ProMdl mdl, char* load_name, ProMechItem *item) { ProMdlType m_type; ProMechGeomref *n_surf; PTMechExGeomRef g_ref; ProMechItem l_item; ProName tk_load_name; ProSelection *sel; ProAsmcomppath comp_path, *c_path = NULL; int n_sel; ProStringToWstring (msgfile, "msg_load.txt"); status = ProMdlTypeGet (mdl, &m_type); PT_TEST_LOG_SUCC ("ProMdlTypeGet"); status = ProMessageDisplay (msgfile, "PTMechExLoad - Select surface for load", msgbuf); PT_TEST_LOG_SUCC ("ProMessageDisplay"); /* select the reference for item */ status = ProSelect ("surface", 1, NULL, NULL, NULL, NULL, &sel, &n_sel); PT_TEST_LOG ("ProSelect", status, (status != PRO_TK_NO_ERROR && status != PRO_TK_USER_ABORT)); if (status == PRO_TK_USER_ABORT) { status = ProMessageDisplay (msgfile, "PTMechExLoad - Invalid selection", msgbuf); PT_TEST_LOG_SUCC ("ProMessageDisplay"); } if (status != PRO_TK_NO_ERROR || n_sel <= 0) return PRO_TK_BAD_INPUTS; /* Get the modelitem of the selection */ status = ProSelectionModelitemGet (sel[0], &l_item); PT_TEST_LOG_SUCC ("ProSelectionModelitemGet"); if (status != PRO_TK_NO_ERROR) return PRO_TK_BAD_INPUTS; /* Assign the selection item id to the geom reference */ g_ref.type = PRO_MECH_SURFACE; g_ref.subtype = PRO_MECH_SURFACE_NORMAL; g_ref.id = l_item.id; /* check for the model type */ if (m_type == PRO_MDL_ASSEMBLY) { /* Check for the assembly type of model to get the path */ status = ProSelectionAsmcomppathGet (sel[0], &comp_path); PT_TEST_LOG_SUCC ("ProSelectionAsmcomppathGet"); if (comp_path.table_num == 0) c_path = NULL; else { c_path = (ProAsmcomppath *)&comp_path; g_ref.path = c_path; } } else g_ref.path = NULL; if (status != PRO_TK_NO_ERROR) { status = ProMessageDisplay (msgfile, "PTMechExLoad - Invalid selection", msgbuf); PT_TEST_LOG_SUCC ("ProMessageDisplay"); return PRO_TK_BAD_INPUTS; } /* creates the mech item */ status = ProMechitemCreate ((ProSolid)mdl, PRO_SIMULATION_LOAD, &l_item); PT_TEST_LOG_SUCC ("ProMechitemCreate"); /* assigns the specified item name */ ProStringToWstring (tk_load_name, load_name); status = ProMechitemNameSet (&l_item, tk_load_name); PT_TEST_LOG ("ProMechitemNameSet", status, status != PRO_TK_NO_ERROR && status != PRO_TK_GENERAL_ERROR); status = PTMechExGeomReferenceArrayCreate (1, &g_ref, &n_surf); PT_TEST_LOG_SUCC ("PTMechExGeomReferenceArrayCreate"); /* Set the above references to the created item */ status = ProMechloadReferencesSet (&l_item, n_surf); PT_TEST_LOG_SUCC ("ProMechloadReferencesSet"); *item = l_item; return PRO_TK_NO_ERROR; }