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


/*====================================================================*\
FILE    : PTMechExItemInfo.c
PURPOSE : Writes info. for Mechanica items 
\*====================================================================*/

/*--------------------------------------------------------------------*\
  Pro/Toolkit includes -- include this first
\*--------------------------------------------------------------------*/

#include <ProMenu.h>
#include <ProUtil.h>
#include <ProMessage.h>
#include <PTMechExamples.h>
#include <ProMechanica.h>
#include <ProMechItem.h>
#include <ProMechWeld.h>
#include <ProMechLoad.h>

int UserWeldInfoWrite();
int UserLoadInfoWrite();
int UserMenuDeleteAndPop();

/*---------------------- Function Prototypes -------------------------*/
ProError PTExMechitemVisitWrite(ProMechItem* item,
                                  ProError filter_status,
                                  ProAppData app_data);

/* Functions for MechItem: Weld */
ProError PTExMechweldWrite_low (ProMechItem* weld);
ProError PTExMechweldperimeterWrite_low (ProMechWeldPerimeter data);
ProError PTExMechweldedgedataWrite_low (ProMechWeldEdgeData data);
ProError PTExMechweldspotWrite_low (ProMechItem* item, ProMechWeldSpot data);
ProError PTExMechweldfeatureWrite_low (ProMechWeldFeature welddata);
ProError PTExMechweldEndWeldWrite_low ( ProMechWeldEnd EndWeld_data);

/* Functions for MechItem: Load */
ProError PTExMechloadWrite_low (ProMechItem* load);
ProError PTExMechforcedataWrite_low (ProMechForceData data);
ProError PTExMechpressuredataWrite_low (ProMechPressureData data);
ProError PTExMechcentrifugaldataWrite_low (ProMechCentrifugalData data);
ProError PTExMechgravitydataWrite_low (ProMechGravityData data);
ProError PTGMechstructtempdataWrite_low (ProMechStructtempData data);
ProError PTExMechmecttempdataWrite_low (ProMechMecttempData data);
ProError PTExMechheatdataWrite_low (ProMechHeatData data);
ProError PTExMechbearingdataWrite_low (ProMechBearingData data);
ProError PTExMechstructtempdataWrite_low (ProMechStructtempData data);

/*Generic utilities */
ProError PTExMechvectoredvalueWrite_low (ProMechVectoredValue value);
ProError PTExMechvariationWrite_low (ProMechVariation value);
ProError PTExMechdirvectorWrite_low (ProMechDirectionVector value);
ProError PTExMechinterpolationpntWrite_low (ProMechInterpolationPnt value);
ProError PTExMechGeomrefWrite_low (ProMechGeomref Geomref);
ProError PTExMechvalueWrite_low (ProMechValue value);
ProError PTExMechObjectrefWrite_low (ProMechObjectref Objectref);

static ProFileName message_file;
char fname[PRO_NAME_SIZE];
FILE *fp;
/*=============================================================*\
  FUNCTION: PTMechExItemInfo 
  PURPOSE:   
\*=============================================================*/
  
ProError PTMechExItemInfo()
  
{
  
  int menu_id, action, status;

  status = ProMenuFileRegister("PTMechItemEx", "pt_mechitem_example.mnu", &menu_id);
  PT_TEST_LOG_SUCC( "ProMenuFileRegister" );

  status = ProMenubuttonActionSet("PTMechItemEx", "-Weld Item Info",
     (ProMenubuttonAction)UserWeldInfoWrite, NULL, 0);
  PT_TEST_LOG_SUCC("ProMenubuttonActionSet" );

  status = ProMenubuttonActionSet("PTMechItemEx", "-Load Item Info",
     (ProMenubuttonAction)UserLoadInfoWrite, NULL, 0);
  PT_TEST_LOG_SUCC(  "ProMenubuttonActionSet" );

  status = ProMenubuttonActionSet("PTMechItemEx", "-Done/Return",
     (ProMenubuttonAction)UserMenuDeleteAndPop, NULL, 0);
  PT_TEST_LOG_SUCC( "ProMenubuttonActionSet");

  status = ProMenubuttonActionSet("PTMechItemEx", "UGMechanica",
     (ProMenubuttonAction)UserMenuDeleteAndPop, NULL, 0);
  PT_TEST_LOG_SUCC( "ProMenubuttonActionSet" );

  status = ProMenuPush();
  PT_TEST_LOG_SUCC( "ProMenuPush");

  status = ProMenuCreate(PROMENUTYPE_MAIN, "PTMechItemEx", &menu_id);
  PT_TEST_LOG_SUCC( "ProMenuCreate" );

  status = ProMenuProcess("PTMechItemEx", &action);
  PT_TEST_LOG_SUCC(  "ProMenuProcess" );

  return (PRO_TK_NO_ERROR);
  
}

/* Write Load info */
int UserLoadInfoWrite()
{

  ProMdl model;
  ProError status;
  ProMdlType mdl_type;
  ProBoolean is_active;

  ProStringToWstring(message_file, "msg_ugfund.txt");

  strcpy (fname, "mechanicaLoaddata.txt");

    if ((fp = fopen (fname, "w")) == NULL)
    {
         ProMessageDisplay(message_file, "USER %0s F",
              "Cannot open file for write");
         return (0);
    }
  ProTKFprintf (fp, "\n");

  status = ProMdlCurrentGet (&model);
  PT_TEST_LOG_SUCC("ProMdlCurrentGet" );
  
  if (status == PRO_TK_NO_ERROR)
  {
    status = ProMdlTypeGet (model, &mdl_type);

    if(mdl_type == PRO_MDL_PART || mdl_type ==PRO_MDL_ASSEMBLY)
    {  	
    
     /* Visiting mechanica item: PRO_SIMULATION_WELD */
     status = ProSolidMechitemVisit (model, PRO_SIMULATION_LOAD, 
					PTExMechitemVisitWrite,	NULL, NULL);
     PT_TEST_LOG_SUCC("ProSolidMechitemVisit" );

    }
  }
  else
  {
	ProMessageDisplay (message_file, "USER %0s F", "There is no current model");
	return status;
  }

  return 0;
}

/* Write Weld info */
int UserWeldInfoWrite()
{

  ProMdl model;
  ProError status;
  ProMdlType mdl_type;
  ProBoolean is_active;

  ProStringToWstring(message_file, "pt_mech_examples.txt");

  strcpy (fname, "mechanicaWelddata.txt");

    if ((fp = fopen (fname, "w")) == NULL)
    {
         ProMessageDisplay(message_file, "USER %0s F",
              "Cannot open file for write");
         return (0);
    }
  ProTKFprintf (fp, "\n");

  status = ProMdlCurrentGet (&model);
  PT_TEST_LOG_SUCC("ProMdlCurrentGet" );
  
  if (status == PRO_TK_NO_ERROR)
  {
    status = ProMdlTypeGet (model, &mdl_type);

    if(mdl_type == PRO_MDL_PART || mdl_type ==PRO_MDL_ASSEMBLY)
    { 

     status = ProSolidMechitemVisit (model, PRO_SIMULATION_WELD, 
				PTExMechitemVisitWrite,	NULL, NULL);
     PT_TEST_LOG_SUCC("ProSolidMechitemVisit" );
     
    }
  }
  else
  {
	ProMessageDisplay (message_file, "USER %0s F", "There is no current model");
	return status;
  }

  return 0;
}

/*====================================================================*
Function : UserMenuDeleteAndPop()
Purpose  : Deletes the current menu and pops up its parent
\*====================================================================*/
int UserMenuDeleteAndPop()
{
  int status;

  status = ProMenuDelete();
  PT_TEST_LOG_SUCC( "ProMenuDelete");

  status = ProMenuPop();
  PT_TEST_LOG_SUCC( "ProMenuPop" );

  return (PRO_TK_NO_ERROR);
}

ProError PTExMechitemVisitWrite(ProMechItem* item,
                                  ProError filter_status,
                                  ProAppData app_data)
{
  ProName item_proname;
  char    item_name [PRO_NAME_SIZE];
  ProError status;

  status = ProMechitemNameGet ( item, item_proname);
  PT_TEST_LOG_SUCC("ProMechitemNameGet" );

  ProWstringToString (item_name, item_proname);

  ProTKFprintf (fp, "     --------------------------- \n"); 
  ProTKFprintf (fp, "     - Item name: %s \n", item_name);
  ProTKFprintf (fp, "     --------------------------- \n");

  switch (item->type)
    {
    case PRO_SIMULATION_WELD:
      {
	ProTKFprintf (fp, "     - Item type: PRO_SIMULATION_WELD \n");

      	PTExMechweldWrite_low (item);
      	break;
      }
    case PRO_SIMULATION_LOAD:
      {
	ProTKFprintf (fp, "     - Item type: PRO_SIMULATION_LOAD \n");

      	PTExMechloadWrite_low (item);
      	break;
      }
    default:
      break;
    }



  return PRO_TK_NO_ERROR;
}

/*======================================================================*\
				WELD
\*======================================================================*/
ProError PTExMechweldWrite_low (ProMechItem* weld)
{
  ProMechGeomref* refs;
  int refs_size, i;
  ProMechWeldType type;
  ProMechWeldEnd EndWeld_data;
  ProMechWeldEndType Endtype;
  ProError status;

  status = ProMechweldReferencesGet (weld, &refs);  
  PT_TEST_LOG_SUCC("ProMechweldReferencesGet" );

  status = ProArraySizeGet (refs, &refs_size);
  PT_TEST_LOG_SUCC("ProArraySizeGet" );

  if (refs_size > 0)
  {
    ProTKFprintf (fp, "	- Number of references: %d\n", refs_size);
  }

  status = ProMechgeomrefProarrayFree (refs);
  PT_TEST_LOG_SUCC("ProMechgeomrefProarrayFree" );

  status = ProMechweldTypeGet (weld, &type);
  PT_TEST_LOG_SUCC("ProMechweldTypeGet" );
  
  switch (type)
    {
    case PRO_MECH_WELD_PERIMETER:
      {
        ProMechWeldPerimeter data;

	ProTKFprintf (fp, "        - Weld type: PRO_MECH_WELD_PERIMETER \n");

        status = ProMechweldPerimeterdataGet (weld, &data);
        PT_TEST_LOG_SUCC("ProMechweldPerimeterdataGet" );

        PTExMechweldperimeterWrite_low (data);

        status = ProMechweldperimeterFree (data);
        PT_TEST_LOG_SUCC("ProMechweldperimeterFree" );

        break;
      }
    case PRO_MECH_WELD_SPOT:
      {
        ProMechWeldSpot data;

	ProTKFprintf (fp, "        - Weld type: PRO_MECH_WELD_SPOT \n");

        status = ProMechweldSpotdataGet (weld, &data);
        PT_TEST_LOG_SUCC("ProMechweldSpotdataGet" );

        PTExMechweldspotWrite_low (weld, data);

        status = ProMechweldspotFree (data);
        PT_TEST_LOG_SUCC("ProMechweldspotFree" );

        break;
      }

      case PRO_MECH_WELD_FEAT:
      {
        ProMechWeldFeature welddata;

	ProTKFprintf (fp, "        - Weld type: PRO_MECH_WELD_FEAT \n");

        status =ProMechweldFeaturedataGet(weld,&welddata);
        PT_TEST_LOG_SUCC("ProMechweldFeaturedataGet" );

        PTExMechweldfeatureWrite_low (welddata);

        status=ProMechweldfeatureFree(welddata);
        PT_TEST_LOG_SUCC("ProMechweldfeatureFree" );

        break;
      }

      case  PRO_MECH_WELD_END:
      {
        ProMechWeldEnd EndWeld_data;

	ProTKFprintf (fp, "        - Weld type: PRO_MECH_WELD_END \n");

        status =ProMechweldEnddataGet(weld,&EndWeld_data);
        PT_TEST_LOG_SUCC("ProMechweldEnddataGet" );

        PTExMechweldEndWeldWrite_low (EndWeld_data);

        status =ProMechweldendFree(EndWeld_data);
        PT_TEST_LOG_SUCC("ProMechweldendFree" );

        break;
      }

    }

  return PRO_TK_NO_ERROR;
}

/*======================================================================*\
	Info. for mech item: LOAD
\*======================================================================*/
ProError PTExMechloadWrite_low (ProMechItem* load)
{
  ProMechGeomref* refs;
  int i, gr_size;
  ProMechLoadType type;
  ProError status;

  status = ProMechloadReferencesGet (load, &refs);
  PT_TEST_LOG_SUCC("ProMechloadReferencesGet" );
  
  status = ProArraySizeGet (refs, &gr_size);
  
  ProTKFprintf (fp, "	- Number of references: %d \n", gr_size);

  status = ProMechgeomrefProarrayFree (refs);
  PT_TEST_LOG_SUCC("ProMechgeomrefProarrayFree" );
  
  status = ProMechloadTypeGet (load, &type);
  PT_TEST_LOG_SUCC("ProMechloadTypeGet" );
  
  ProTKFprintf (fp, "     - Load type: %d \n", type);
  
  switch (type)
    {
    case PRO_MECH_LOAD_FORCE:
      {
	ProMechForceData data;

 	ProTKFprintf (fp, "	- Force data: \n");

	/* Writing force data */
	status = ProMechloadForcedataGet (load, &data);
        PT_TEST_LOG_SUCC("ProMechloadForcedataGet" );

	PTExMechforcedataWrite_low (data);

	status = ProMechforcedataFree (data);
        PT_TEST_LOG_SUCC("ProMechforcedataFree" );

	break;
      }
    case PRO_MECH_LOAD_PRESSURE:
      {
	ProMechPressureData data;

	status = ProMechloadPressuredataGet (load, &data);
        PT_TEST_LOG_SUCC("ProMechloadPressuredataGet" );

	/* Writing pressure load data */
	PTExMechpressuredataWrite_low (data);

	status = ProMechpressuredataFree (data);
        PT_TEST_LOG_SUCC("ProMechpressuredataFree" );

	break;
      }
   case PRO_MECH_LOAD_BEARING:
      {
	ProMechBearingData data;

	status = ProMechloadBearingdataGet (load, &data);
        PT_TEST_LOG_SUCC("ProMechloadBearingdataGet" );
	
	/* Writing bearing load data */
	PTExMechbearingdataWrite_low (data);

	status = ProMechbearingdataFree (data);
        PT_TEST_LOG_SUCC("ProMechbearingdataFree" );
	
	break;
      }
   case PRO_MECH_LOAD_CENTRIFUGAL:
      {
	ProMechCentrifugalData data;

	status = ProMechloadCentrifugaldataGet (load, &data);
        PT_TEST_LOG_SUCC("ProMechloadCentrifugaldataGet" );
	
	/*Writing centrifugal load data */
	PTExMechcentrifugaldataWrite_low (data);

	status = ProMechcentrifugaldataFree (data);
        PT_TEST_LOG_SUCC("ProMechcentrifugaldataFree" );
	
	break;
      }
   case PRO_MECH_LOAD_GRAVITY:
      {
	ProMechGravityData data;

	/* Writing gravity load data */
	status = ProMechloadGravitydataGet (load, &data);
        PT_TEST_LOG_SUCC("ProMechloadGravitydataGet" );
	
	PTExMechgravitydataWrite_low (data);

	status = ProMechgravitydataFree (data);
        PT_TEST_LOG_SUCC("ProMechgravitydataFree" );
	
	break;
      }
    case PRO_MECH_LOAD_STRUCTURAL_TEMPERATURE:
      {
	ProMechStructtempData data;

	
	status = ProMechloadStructtempdataGet (load, &data);
        PT_TEST_LOG_SUCC("ProMechloadStructtempdataGet" );
	
	/* Writing structural temperature data */
	PTExMechstructtempdataWrite_low (data);

	status = ProMechstructtempdataFree (data);
        PT_TEST_LOG_SUCC("ProMechstructtempdataFree" );
	
	break;
      }
    case PRO_MECH_LOAD_MECT_TEMPERATURE:
      {
	ProMechMecttempData data;

	status = ProMechloadMecttempdataGet (load, &data);
        PT_TEST_LOG_SUCC("ProMechloadMecttempdataGet" );
	
	/* Writing MECT temperature data */
	PTExMechmecttempdataWrite_low (data);

	status = ProMechmecttempdataFree (data);
        PT_TEST_LOG_SUCC("ProMechmecttempdataFree" );
	
	break;
      }
    case PRO_MECH_LOAD_HEAT:
      {
	ProMechHeatData data;

	status = ProMechloadHeatdataGet (load, &data);
        PT_TEST_LOG_SUCC("ProMechloadHeatdataGet" );
	
	/* Writing heat load data */
	PTExMechheatdataWrite_low (data);

	status = ProMechheatdataFree (data);
        PT_TEST_LOG_SUCC("ProMechheatdataFree" );
	
	break;
      }
    }
  
  return PRO_TK_NO_ERROR;
}


/*======================================================================*\
	Info. for perimeter weld
\*======================================================================*/
ProError PTExMechweldperimeterWrite_low (ProMechWeldPerimeter data)
{
  ProMechWeldEdgeData* edges;
  int i, edges_size;
  ProError status;
  
  status = ProMechweldperimeterEdgesGet (data, &edges);
  PT_TEST_LOG_SUCC("ProMechweldperimeterEdgesGet" );
  
  status = ProArraySizeGet (edges, &edges_size);
  PT_TEST_LOG_SUCC("ProArraySizeGet" );

  ProTKFprintf (fp, "        - Number of edges in the perimeter weld: %d \n",
								 edges_size);  

  for (i = 0; i < edges_size; i++)
    {
      PTExMechweldedgedataWrite_low (edges[i]);
      ProTKFprintf (fp, "        --------------- \n");  
    }

  status = ProMechweldedgeProarrayFree (edges);
  PT_TEST_LOG_SUCC("ProMechweldedgeProarrayFree" );

  return PRO_TK_NO_ERROR;
}

/*======================================================================*\
	Info. for edge weld
\*======================================================================*/
ProError PTExMechweldedgedataWrite_low (ProMechWeldEdgeData data)
{
  int edge_id;
  ProMechExpression thickness;
  ProCharLine c_thickness;
  ProName material;
  ProCharName c_material;
  ProError status;
  
  status = ProMechweldedgeEdgeGet (data, &edge_id);
  PT_TEST_LOG_SUCC("ProMechweldedgeEdgeGet" );

  ProTKFprintf (fp, "        - Weld edge id: %d \n", edge_id); 
  
  status = ProMechweldedgeThicknessGet (data, thickness);
  PT_TEST_LOG_SUCC("ProMechweldedgeThicknessGet" );

  ProWstringToString (c_thickness, thickness);
  ProTKFprintf (fp, "        + Thickness: %s \n", c_thickness); 

  return PRO_TK_NO_ERROR;
}

/*======================================================================*\
	Info. for spot weld
\*======================================================================*/
ProError PTExMechweldspotWrite_low (ProMechItem* item, ProMechWeldSpot data)
{
    int i, points_size;
    ProMechGeomref *points;
    ProMechExpression dia;
    ProCharName c_dia, mat_name;
    int mat_id;
    ProName mat_pname;
    ProModelitem material;
    ProError status;

    status = ProMechweldspotPointsGet (data, &points);
    PT_TEST_LOG_SUCC("ProMechweldspotPointsGet" );

    status = ProArraySizeGet (points, &points_size);

    ProTKFprintf (fp, "	- Number of weld spot points: %d \n", points_size);    

    status = ProMechgeomrefProarrayFree (points);
    PT_TEST_LOG_SUCC("ProMechgeomrefProarrayFree" );

    status = ProMechweldspotDiameterGet (data, dia);
    PT_TEST_LOG_SUCC("ProMechweldspotDiameterGet" );

    ProWstringToString (c_dia, dia);
    ProTKFprintf (fp, "          + Diameter: %s \n", c_dia); 

    status = ProMechweldspotMaterialIdGet (data, &mat_id);
    PT_TEST_LOG_SUCC("ProMechweldspotMaterialIdGet" );

    if (mat_id != -1)
    {
        status = ProModelitemInit ( item->owner, mat_id, 
						PRO_RP_MATERIAL, &material);

        status = ProModelitemNameGet (&material, mat_pname);

        ProWstringToString (mat_name, mat_pname); 
        ProTKFprintf (fp, "          + Material id: %d, name: %s \n",
							 mat_id, mat_name); 
    }
    else
    {
        ProTKFprintf (fp, "          + Material not assigned \n"); 
    }

    return PRO_TK_NO_ERROR;
}

/*======================================================================*\
	Info. for weld as feature
\*======================================================================*/
ProError PTExMechweldfeatureWrite_low (ProMechWeldFeature welddata)
{
    ProCharLine thickval;
    ProMechExpression thickness1;
    ProBoolean  overrideflag;
    int matid;
    ProError status;
    
    status = ProMechweldfeatureOverrideflagGet(welddata,&overrideflag);
    PT_TEST_LOG_SUCC("ProMechweldfeatureOverrideflagGet" );
    
    ProTKFprintf(fp,"            +Overrideflag = %s \n",
				(overrideflag == PRO_B_TRUE)?"True":"False");
    
    if (overrideflag == PRO_B_TRUE)
    {  
    status =ProMechweldfeatureMaterialidGet(welddata,&matid);
    PT_TEST_LOG_SUCC("ProMechweldfeatureMaterialidGet" );
    
    ProTKFprintf(fp,"            +Material id= %d \n",matid);
    
    status =ProMechweldfeatureThicknessGet(welddata,thickness1);
    PT_TEST_LOG_SUCC("ProMechweldfeatureThicknessGet" );
    
    ProWstringToString (thickval, thickness1);
    
    ProTKFprintf (fp, "            +Thickness: %s \n",thickval);  
    }    
   
    return PRO_TK_NO_ERROR;

}

/*======================================================================*\
	Info. for end weld
\*======================================================================*/
ProError PTExMechweldEndWeldWrite_low ( ProMechWeldEnd EndWeld_data)
{ 
   ProMechWeldEndType endweldtype;
   ProBool  flag;
   ProError status; 

   status =ProMechweldendTypeGet(EndWeld_data,&endweldtype);
   PT_TEST_LOG_SUCC("ProMechweldendTypeGet" );
   
   ProTKFprintf (fp, "             + End Weld type: %d \n", endweldtype); 
     
   /*Checking if endweld type not PRO_MECH_WELD_END_SINGLE_TO_MANY, then only ProMechweldendExtendAdjacentSurfacesGet is called and Extend adjacent surfaces flag
   is printed*/
   
   if (endweldtype != PRO_MECH_WELD_END_SINGLE_TO_MANY)
   {
     status =ProMechweldendExtendAdjacentSurfacesGet(EndWeld_data,&flag);
     PT_TEST_LOG_SUCC("ProMechweldendExtendAdjacentSurfacesGet" );
	    
     ProTKFprintf(fp, "             + Extend adjacent surfaces flag = %s \n",
					(flag == PRO_B_TRUE)?"True":"False");
   }    
  
  return PRO_TK_NO_ERROR;
}

/*======================================================================*\
	Info. for force data
\*======================================================================*/
ProError PTExMechforcedataWrite_low (ProMechForceData data)
{
  ProMechForceType type;
  ProMechVectoredValue force;
  ProMechVectoredValue moment;
  ProMechGeomref ref_pnt;
  ProBool ignore_force, ignore_moment;
  ProError status;

  status = ProMechforcedataTypeGet (data, &type);
  PT_TEST_LOG_SUCC("ProMechforcedataTypeGet" );

  ProTKFprintf (fp, "          + Force type: %d \n", type);	   

  status = ProMechforcedataForceGet (data, &force);
  PT_TEST_LOG_SUCC("ProMechforcedataForceGet" );

  ProTKFprintf (fp, "          + Force: \n" );

  PTExMechvectoredvalueWrite_low (force);

  /* Free */
  status = ProMechvectoredvalueFree (force);
  PT_TEST_LOG_SUCC("ProMechvectoredvalueFree" );

  status = ProMechforcedataMomentGet (data, &moment);
  PT_TEST_LOG_SUCC("ProMechforcedataMomentGet" );
  
  ProTKFprintf (fp, "          + Moment: \n");
  
  PTExMechvectoredvalueWrite_low (moment);

  /* Free */
  status = ProMechvectoredvalueFree (moment);
  PT_TEST_LOG_SUCC("ProMechvectoredvalueFree" );

  if (type == PRO_MECH_FORCE_TOTAL_AT_POINT)
    {
      status = ProMechforcedataRefpntGet (data, &ref_pnt);
      PT_TEST_LOG_SUCC("ProMechforcedataRefpntGet" );

      PTExMechGeomrefWrite_low (ref_pnt);
      
       /* Free */
      status = ProMechgeomrefFree (ref_pnt);
      PT_TEST_LOG_SUCC("ProMechgeomrefFree" );
    }

  if (type == PRO_MECH_FORCE_TBLAP)
    {
	status = ProMechforcedataAxialForceIgnoreflagGet (data, &ignore_force);
        PT_TEST_LOG_SUCC("ProMechforcedataAxialForceIgnoreflagGet" );

	ProTKFprintf (fp, "          + Axial force is: %s \n",
		   (ignore_force == PRO_B_TRUE)?"ignored":"not ignored");

	status = ProMechforcedataAxialMomentIgnoreflagGet (data, &ignore_moment);
        PT_TEST_LOG_SUCC("ProMechforcedataAxialMomentIgnoreflagGet" );

	ProTKFprintf (fp, "          + Axial moment is: %s \n",
		    (ignore_moment == PRO_B_TRUE)?"ignored":"not ignored");
    }

  return PRO_TK_NO_ERROR;
}

/*======================================================================*\
	Utility for ProMechVectoredValue
\*======================================================================*/
ProError PTExMechvectoredvalueWrite_low (ProMechVectoredValue value)
{
  ProMechDirectionType type;
  ProMechDirectionVector vector;
  ProMechGeomref* points;
  ProMechValue magnitude;
  int i, pnt_size;
  ProError status;
  
  status = ProMechvectoredvalueDirectiontypeGet (value, &type);
  PT_TEST_LOG_SUCC("ProMechvectoredvalueDirectiontypeGet" );

  ProTKFprintf (fp, "            = Direction type: %d \n", type);

  if (type == PRO_MECH_DIRECTION_BY_VECTOR)
    {
      status = ProMechvectoredvalueDirectionvectorGet (value, &vector);
      PT_TEST_LOG_SUCC("ProMechvectoredvalueDirectionvectorGet" );
      
      PTExMechdirvectorWrite_low (vector);

      /* Free */
      status = ProMechdirvectorFree (vector);
      PT_TEST_LOG_SUCC("ProMechdirvectorFree" );
    }
  else if (type == PRO_MECH_DIRECTION_BY_2_POINTS)
    {
      status = ProMechvectoredvaluePointsGet (value, &points);
      PT_TEST_LOG_SUCC("ProMechvectoredvaluePointsGet" );

      status = ProArraySizeGet (points, &pnt_size);
      
      for (i = 0; i < pnt_size; i++)
	{
	  PTExMechGeomrefWrite_low (points [i]);
	}

      /* Free */
      status = ProMechgeomrefProarrayFree (points);
      PT_TEST_LOG_SUCC("ProMechgeomrefProarrayFree" );
    }
  
  status = ProMechvectoredvalueMagnitudeGet (value, &magnitude);
  PT_TEST_LOG_SUCC("ProMechvectoredvalueMagnitudeGet" );

  if (status == PRO_TK_NO_ERROR)
    {
      PTExMechvalueWrite_low (magnitude);

      /* Free */
      status = ProMechvalueFree (magnitude);
     PT_TEST_LOG_SUCC("ProMechvalueFree" );
    }
  else
    ProTKFprintf (fp, "          = No magnitude. \n");

  return PRO_TK_NO_ERROR;
}

/*======================================================================*\
	Utility for ProMechDirectionVector
\*======================================================================*/
ProError PTExMechdirvectorWrite_low (ProMechDirectionVector value)
{
  ProMechValue* components;
  int i, cmp_size;
  ProMechVariation variation;
  ProMechGeomref csys;
  ProError status;

  ProTKFprintf (fp, "            = Overall variation: \n");
  
  status = ProMechdirvectorVariationGet (value, &variation);
  PT_TEST_LOG_SUCC("ProMechdirvectorVariationGet" );

  PTExMechvariationWrite_low (variation);

  ProTKFprintf (fp, "            = Vector components: \n");

  status = ProMechdirvectorComponentsGet (value, &components);
  PT_TEST_LOG_SUCC("ProMechdirvectorComponentsGet" );

  status = ProArraySizeGet (components, &cmp_size);

  for (i = 0; i < cmp_size; i++)
    {
      PTExMechvalueWrite_low (components [i]);
    }

 /* Free */
  status = ProMechvalueProarrayFree (components);
  PT_TEST_LOG_SUCC("ProMechvalueProarrayFree" );

 /* Free */
  status = ProMechvariationFree (variation);
  PT_TEST_LOG_SUCC("ProMechvariationFree" );

  ProTKFprintf (fp, "            = Vector csys: \n");

  status = ProMechdirvectorCsysGet (value, &csys);  
  PT_TEST_LOG_SUCC("ProMechdirvectorCsysGet" );

  PTExMechGeomrefWrite_low (csys);

  /* Free */
  status = ProMechgeomrefFree (csys);
  PT_TEST_LOG_SUCC("ProMechgeomrefFree" );

  return PRO_TK_NO_ERROR;
}

/*======================================================================*\
	Utility for ProMechVariation
\*======================================================================*/
ProError PTExMechvariationWrite_low (ProMechVariation value)
{
  ProMechVariationType type;
  int function_id;
  ProMechInterpolationPnt* pnts;
  int i, pnt_size;
  ProMechExternalFieldData external_field_data;
  ProCharPath c_fem_file;
  ProMechGeomref csys;
  ProPath data_file;
  ProError status;

  status = ProMechvariationTypeGet (value, &type);
  PT_TEST_LOG_SUCC("ProMechvariationTypeGet" );

  ProTKFprintf (fp, "              - Variation type: %d \n", type);

  if (type == PRO_MECH_VARIATION_FUNCTION)
    {
      status = ProMechvariationFunctionidGet (value, &function_id); 
      PT_TEST_LOG_SUCC("ProMechvariationFunctionidGet" );

      ProTKFprintf (fp, "            = Variation function id: %d \n", function_id);
    }
  else if (type == PRO_MECH_VARIATION_INTERPOLATION)
    {
      status = ProMechvariationInterpolationGet (value, &pnts);
      PT_TEST_LOG_SUCC("ProMechvariationInterpolationGet" );

      status = ProArraySizeGet (pnts, &pnt_size);

      for (i = 0; i < pnt_size; i++)
	{
	  PTExMechinterpolationpntWrite_low (pnts[i]);
	}

      /* Free */
      status = ProMechinterpolationpntProarrayFree (pnts);
      PT_TEST_LOG_SUCC("ProMechinterpolationpntProarrayFree" );
    }
  else if (type == PRO_MECH_VARIATION_EXTERN_FIELD)
    {

      status = ProMechvariationExternalfielddataGet (value, &external_field_data);
      PT_TEST_LOG_SUCC("ProMechvariationExternalfielddataGet" );

      status = ProMechexternalfielddataCsysGet (external_field_data, &csys);
      PT_TEST_LOG_SUCC("ProMechexternalfielddataCsysGet" );

      if (status == PRO_TK_NO_ERROR)
      {
	ProTKFprintf (fp, "       + Csys: \n");

      	PTExMechGeomrefWrite_low (csys);

      }
      else
    	ProTKFprintf (fp, "       + Csys file not set \n");

      ProMechexternalfielddataFileGet (external_field_data, data_file);
      PT_TEST_LOG_SUCC("ProMechexternalfielddataFileGet" );
      
      if (status == PRO_TK_NO_ERROR)
      {
      	ProWstringToString (c_fem_file, data_file);

      	ProTKFprintf (fp, "       + External field data file: %s \n", c_fem_file);
      }
      else
    	ProTKFprintf (fp, "       + External field data file not set \n");

    }

  return PRO_TK_NO_ERROR;
}

/*======================================================================*\
	Utility for ProMechInterpolationPnt
\*======================================================================*/
ProError PTExMechinterpolationpntWrite_low (ProMechInterpolationPnt value)
{
  ProMechExpression expression;
  ProCharLine c_expression;
  ProMechGeomref point;
  ProError status;
  
  status = ProMechinterpolationpntMagnitudeGet (value, expression);
  PT_TEST_LOG_SUCC("ProMechinterpolationpntMagnitudeGet" );

  ProWstringToString (c_expression, expression);
  ProTKFprintf (fp, "            = Interpolation pnt magnitude: %s \n", 
	   c_expression);

  status = ProMechinterpolationpntPointGet (value, &point);
  PT_TEST_LOG_SUCC("ProMechinterpolationpntPointGet" );

  PTExMechGeomrefWrite_low (point);

  /* Free */
  status = ProMechgeomrefFree (point);

  return PRO_TK_NO_ERROR;
}

ProError PTExMechGeomrefWrite_low (ProMechGeomref Geomref)
{
  ProMechGeomrefType type;
  ProMechGeomrefSubType sub_type;
  int id;
  ProAsmcomppath path;
  ProError status;

  ProTKFprintf (fp, "        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n");
  
  /* TYPE */
  status = ProMechgeomrefTypeGet (Geomref, &type);
  PT_TEST_LOG_SUCC("ProMechgeomrefTypeGet" );

  ProTKFprintf (fp, "                   ~ Geomref type: %d \n",  type);
  
    /* SUBTYPE */
  status = ProMechgeomrefSubtypeGet (Geomref, &sub_type);
  PT_TEST_LOG_SUCC("ProMechgeomrefSubtypeGet" );

  ProTKFprintf (fp, "                   ~ Geomref sub type: %d \n", type);

  /* ID */
  status = ProMechgeomrefIdGet (Geomref, &id);
  PT_TEST_LOG_SUCC("ProMechgeomrefIdGet" );

  ProTKFprintf (fp, "                   ~ Geomref id: %d \n", 
	   id);

  /* PATH */
  status = ProMechgeomrefPathGet (Geomref, &path);
  PT_TEST_LOG_SUCC("ProMechgeomrefPathGet" );

  ProTKFprintf (fp, "        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n");

  return PRO_TK_NO_ERROR;
}

/*======================================================================*\
	Utility for ProMechValue
\*======================================================================*/
ProError PTExMechvalueWrite_low (ProMechValue value)
{
  ProMechExpression expression;
  ProMechVariation variation;
  ProCharLine c_expression;
  ProError status;
  
  status = ProMechvalueValueGet (value, expression);
  PT_TEST_LOG_SUCC("ProMechvalueValueGet" );

  ProWstringToString (c_expression, expression);
  ProTKFprintf (fp, "              - Value expression: %s \n", c_expression);

  status = ProMechvalueVariationGet (value, &variation);  
  PT_TEST_LOG_SUCC("ProMechvalueVariationGet" );

  PTExMechvariationWrite_low (variation);

  /* Free */
  status = ProMechvariationFree (variation);
  PT_TEST_LOG_SUCC("ProMechvariationFree" );

  return PRO_TK_NO_ERROR;
}

/*======================================================================*\
	Utility for ProMechPressureData
\*======================================================================*/
ProError PTExMechpressuredataWrite_low (ProMechPressureData data)
{
  ProMechValue value;
  ProError status;

  status = ProMechpressuredataValueGet (data, &value);
  PT_TEST_LOG_SUCC("ProMechpressuredataValueGet" );

  PTExMechvalueWrite_low (value);

  status = ProMechvalueFree (value);
  PT_TEST_LOG_SUCC("ProMechvalueFree" );

  return PRO_TK_NO_ERROR;
}

/*======================================================================*\
	Utility for ProMechCentrifugalData
\*======================================================================*/
ProError PTExMechcentrifugaldataWrite_low (ProMechCentrifugalData data)
{
  ProMechVectoredValue velocity, acceleration;
  ProError status;
  
  ProTKFprintf (fp, "       + Velocity: \n");
  status = ProMechcentrifugaldataVelocityGet (data, &velocity);
  PT_TEST_LOG_SUCC("ProMechcentrifugaldataVelocityGet" );
  
  PTExMechvectoredvalueWrite_low (velocity);

  status = ProMechvectoredvalueFree (velocity);
  PT_TEST_LOG_SUCC("ProMechvectoredvalueFree" );
  
  ProTKFprintf (fp,"       + Acceleration: \n");
  status = ProMechcentrifugaldataAccelerationGet (data, &acceleration);
  PT_TEST_LOG_SUCC("ProMechcentrifugaldataAccelerationGet" );
  
  PTExMechvectoredvalueWrite_low (acceleration);

  status = ProMechvectoredvalueFree (acceleration); 
  PT_TEST_LOG_SUCC("ProMechvectoredvalueFree" );
  
  return PRO_TK_NO_ERROR;
}

/*======================================================================*\
	Utility for ProMechGravityData
\*======================================================================*/
ProError PTExMechgravitydataWrite_low (ProMechGravityData data)
{
  ProMechVectoredValue value;
  ProError status;

  status = ProMechgravitydataValueGet (data, &value);
  PT_TEST_LOG_SUCC("ProMechgravitydataValueGet" );

  PTExMechvectoredvalueWrite_low (value);

  status = ProMechvectoredvalueFree (value);
  PT_TEST_LOG_SUCC("ProMechvectoredvalueFree" );

  return PRO_TK_NO_ERROR;
}

/*======================================================================*\
	Utility for ProMechMecttempData
\*======================================================================*/
ProError PTExMechmecttempdataWrite_low (ProMechMecttempData data)
{
  ProMechObjectref load_set;
  int analysis_id;
  ProMechExpression ref_tmp;
  ProName design_study;
  ProCharLine c_ref_tmp;
  ProCharName c_design_stuty;
  int timestep;
  ProError status;

  status = ProMechmecttempdataAnalysisidGet (data, &analysis_id);
  PT_TEST_LOG_SUCC("ProMechmecttempdataAnalysisidGet" );

  ProTKFprintf (fp, "       + Analysis id: %d \n", analysis_id);

  status = ProMechmecttempdataLoadsetGet (data, &load_set);
  PT_TEST_LOG_SUCC("ProMechmecttempdataLoadsetGet" );

  PTExMechObjectrefWrite_low (load_set);

  status = ProMechmecttempdataReftempGet (data, ref_tmp);
  PT_TEST_LOG_SUCC("ProMechmecttempdataReftempGet" );

  ProWstringToString (c_ref_tmp, ref_tmp);
  ProTKFprintf (fp, "       + Reference temperature: %s \n",
	   c_ref_tmp);
  
  status = ProMechmecttempdataTimestepGet (data, &timestep);
  PT_TEST_LOG_SUCC("ProMechmecttempdataTimestepGet" );

  ProTKFprintf (fp, "       + Time step: %d \n", timestep);

  status = ProMechmecttempdataDesignstudyGet (data, design_study);
  PT_TEST_LOG_SUCC("ProMechmecttempdataDesignstudyGet" );

  ProWstringToString (c_design_stuty, design_study);
  ProTKFprintf (fp, "       + Design study: %s \n",
	   design_study);
  
  return PRO_TK_NO_ERROR;
}

/*======================================================================*\
	Utility for ProMechObjectref
\*======================================================================*/
ProError PTExMechObjectrefWrite_low (ProMechObjectref Objectref)
{
  ProType type;
  int id;
  ProAsmcomppath path;
  ProError status;

  ProTKFprintf (fp,"        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n");
 
  /* TYPE */
  status = ProMechobjectrefTypeGet (Objectref, &type);
  PT_TEST_LOG_SUCC("ProMechobjectrefTypeGet" )

  ProTKFprintf (fp, "                   ~ Objectref type: %d \n", type);
 
  /* ID */
  status = ProMechobjectrefIdGet (Objectref, &id);
  PT_TEST_LOG_SUCC("ProMechobjectrefIdGet" )

  ProTKFprintf (fp, "                   ~ Objectref id: %d \n",
           id);

  /* PATH */
  status = ProMechobjectrefPathGet (Objectref, &path);
  PT_TEST_LOG_SUCC("ProMechobjectrefPathGet" )

  ProTKFprintf (fp,"        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n");

  return PRO_TK_NO_ERROR;
}

/*======================================================================*\
	Utility for ProMechHeatData
\*======================================================================*/
ProError PTExMechheatdataWrite_low (ProMechHeatData data)
{
  ProMechHeatType type;
  ProMechValue value;
  int time_func_id;
  ProError status;

  status = ProMechheatdataTypeGet (data, &type);
  PT_TEST_LOG_SUCC("ProMechheatdataTypeGet" );

  ProTKFprintf (fp, "       + Heat type: %d \n", type);

  status = ProMechheatdataValueGet (data, &value);
  PT_TEST_LOG_SUCC("ProMechheatdataValueGet" );

  PTExMechvalueWrite_low (value);

  status = ProMechvalueFree (value);
  PT_TEST_LOG_SUCC("ProMechvalueFree" );

  status = ProMechheatdataTimefunctionidGet (data, &time_func_id);
  PT_TEST_LOG_SUCC("ProMechheatdataTimefunctionidGet" );

  ProTKFprintf (fp, "       + Time function id: %d \n", time_func_id);

  return PRO_TK_NO_ERROR;
}

/*======================================================================*\
	Utility for ProMechStructtempData
\*======================================================================*/
ProError PTExMechstructtempdataWrite_low (ProMechStructtempData data)
{
  ProMechValue value;
  ProMechExpression ref_tmp;
  ProCharLine c_ref_tmp;
  ProError status;

  ProTKFprintf (fp, "       + Structural temperature: \n");
  ProTKFprintf (fp, "       + Value: \n");
  status = ProMechstructtempdataValueGet (data, &value);
  PT_TEST_LOG_SUCC ("ProMechstructtempdataValueGet()");

  PTExMechvalueWrite_low (value);

  status = ProMechvalueFree (value);
  PT_TEST_LOG_SUCC ("ProMechvalueFree()");

  status = ProMechstructtempdataReftempGet (data, ref_tmp);
  PT_TEST_LOG_SUCC ("ProMechstructtempdataReftempGet()");

  ProWstringToString (c_ref_tmp, ref_tmp);
  ProTKFprintf (fp, "       + Reference temperature: %s \n",
	   c_ref_tmp);


  return PRO_TK_NO_ERROR;
}

/*======================================================================*\
	Utility for ProMechBearingData
\*======================================================================*/
ProError PTExMechbearingdataWrite_low (ProMechBearingData data)
{
  ProMechVectoredValue value;
  ProError status;

  status = ProMechbearingdataValueGet (data, &value);

  PTExMechvectoredvalueWrite_low (value);

  status = ProMechvectoredvalueFree (value);

  return PRO_TK_NO_ERROR;
}