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

/*====================================================================*\
FILE    : PTMechExmpleMain.c
PURPOSE : Test Pro/TOOLKIT functions for Mechanica 
\*====================================================================*/

/*--------------------------------------------------------------------*\
  Pro/Toolkit includes -- include this first
\*--------------------------------------------------------------------*/
#include <ProToolkit.h>
#include <ProMdl.h>
#include <ProMenuBar.h>
#include <ProMechItem.h>
#include <ProMechConstraint.h>
#include <ProMechLoad.h>
#include <ProMechMaterialOrient.h>
#include <ProUtil.h>
#include <ProMessage.h>
#include <ProMechValue.h>
#include <ProModelitem.h>
#include <PTMechExamples.h>

/*--------------------------------------------------------------------*\
  FUNCTION :  TestAccessMechCmd()
  PURPOSE  :  enable access to the menu contents      
\*--------------------------------------------------------------------*/

static ProError status;
static ProCharLine msgbuf;
static ProFileName msgfile;


static uiCmdAccessState TestAccessMechCmd (uiCmdAccessMode access_mode)
{
   ProBoolean mechanica_active;
   ProMdl current_model;
   ProMdlType type;

   status = ProMdlCurrentGet (&current_model);

   if (status != PRO_TK_NO_ERROR)
	 return (ACCESS_REMOVE);

   status = ProMdlTypeGet (current_model, &type);

   if (type != PRO_MDL_PART && type != PRO_MDL_ASSEMBLY)
	   return (ACCESS_REMOVE);

   status = ProMechanicaIsActive (&mechanica_active);
   
   if (status == PRO_TK_NO_ERROR && mechanica_active)
	return (ACCESS_AVAILABLE);
   else 
        return (ACCESS_REMOVE);
}

/*====================================================================*\
  FUNCTION : user_initialize()
  PURPOSE  : 
\*====================================================================*/
int user_initialize(
		    int argc,			
		    char *argv[],
		    char *version, 
		    char *build,
		    wchar_t errbuf[80])
{
  uiCmdCmdId	cmd_id;
 
  ProStringToWstring(msgfile,"pt_mech_examples.txt");
  
/*---------------------------------------------------------------------*\
  Add "MechanicaTest" after info button to the menu bar 
\*---------------------------------------------------------------------*/

  status = ProMenubarMenuAdd ("PTMechanicaTest", "PTMechanicaTestLabel", "Applications", 
			      PRO_B_TRUE, msgfile);
  PT_TEST_LOG("ProMenubarMenuAdd()", status, status != PRO_TK_NO_ERROR);

/*---------------------------------------------------------------------*\
    Add "PTMechExLoadCreate" button to the menu bar
\*---------------------------------------------------------------------*/ 
  status = ProCmdActionAdd("PTTest.TestMechLoadCreate", (uiCmdCmdActFn)PTMechExLoadOper,
			   uiProe2ndImmediate, TestAccessMechCmd,
			   PRO_B_TRUE, PRO_B_TRUE, &cmd_id);
  PT_TEST_LOG_SUCC ("ProCmdActionAdd");
  
  status = ProMenubarmenuPushbuttonAdd("PTMechanicaTest","PTMechExLoadOper",
				       "PTMechExLoadOperLabel",
				       "PTMechExLoadOperLabelHelp",NULL,
				       PRO_B_TRUE, cmd_id, msgfile);
  PT_TEST_LOG_SUCC("ProMenubarmenuPushbuttonAdd");

/*---------------------------------------------------------------------*\
    Add "PTMechExDelete" button to the menu bar
\*---------------------------------------------------------------------*/
    
  status = ProCmdActionAdd("PTTest.TestMechItemDelete", (uiCmdCmdActFn)PTMechExDelete,
			   uiProe2ndImmediate, TestAccessMechCmd,
			   PRO_B_TRUE, PRO_B_TRUE, &cmd_id);
  PT_TEST_LOG_SUCC ("ProCmdActionAdd");
  
  status = ProMenubarmenuPushbuttonAdd("PTMechanicaTest","PTMechExDelete",
				       "PTMechExDeleteLabel",
				       "PTMechExDeleteLabelHelp",NULL,
				       PRO_B_TRUE, cmd_id, msgfile);
  PT_TEST_LOG_SUCC("ProMenubarmenuPushbuttonAdd");
  
/*---------------------------------------------------------------------*\
  Add "PTMechExMagChange" button to the menu bar
\*---------------------------------------------------------------------*/
    
  status = ProCmdActionAdd("PTTest.TestMechItemMagChange", (uiCmdCmdActFn)PTMechExMagChange,
			   uiProe2ndImmediate, TestAccessMechCmd,
			   PRO_B_TRUE, PRO_B_TRUE, &cmd_id);
  PT_TEST_LOG_SUCC ("ProCmdActionAdd");
  
  status = ProMenubarmenuPushbuttonAdd("PTMechanicaTest","PTMechExMagChange",
				       "PTMechExMagChangeLabel",
				       "PTMechExMagChangeLabelHelp",NULL,
				       PRO_B_TRUE, cmd_id, msgfile);
  PT_TEST_LOG_SUCC("ProMenubarmenuPushbuttonAdd");
  
/*---------------------------------------------------------------------*\
  Add "PTMechExConstrCopy" button to the menu bar
\*---------------------------------------------------------------------*/
    
  status = ProCmdActionAdd("PTTest.TestMechItemConstrCopy", (uiCmdCmdActFn)PTMechExConstrCopy,
			   uiProe2ndImmediate, TestAccessMechCmd,
			   PRO_B_TRUE, PRO_B_TRUE, &cmd_id);
  PT_TEST_LOG_SUCC ("ProCmdActionAdd");
  
  status = ProMenubarmenuPushbuttonAdd("PTMechanicaTest","PTMechExConstrCopy",
				       "PTMechExConstrCopyLabel",
				       "PTMechExConstrCopyLabelHelp",NULL,
				       PRO_B_TRUE, cmd_id, msgfile);
  PT_TEST_LOG_SUCC("ProMenubarmenuPushbuttonAdd");
  
/*---------------------------------------------------------------------*\
  Add "PTMechExMatOrient" button to the menu bar
\*---------------------------------------------------------------------*/
  status = ProCmdActionAdd("PTTest.TestMechItemMatOrient", (uiCmdCmdActFn)PTMechExMatOrient,
			   uiProe2ndImmediate, TestAccessMechCmd,
			   PRO_B_TRUE, PRO_B_TRUE, &cmd_id);
  PT_TEST_LOG_SUCC ("ProCmdActionAdd");
  
  status = ProMenubarmenuPushbuttonAdd("PTMechanicaTest","PTMechExMatOrient",
				       "PTMechExMatOrientLabel",
				       "PTMechExMatOrientLabelHelp",NULL,
				       PRO_B_TRUE, cmd_id, msgfile);
  PT_TEST_LOG_SUCC("ProMenubarmenuPushbuttonAdd");

/*---------------------------------------------------------------------*\
  Add "PTMechExItemInfo" button to the menu bar
\*---------------------------------------------------------------------*/
  status = ProCmdActionAdd("PTTest.TestMechItemInfoe", (uiCmdCmdActFn)PTMechExItemInfo,
			   uiProe2ndImmediate, TestAccessMechCmd,
			   PRO_B_TRUE, PRO_B_TRUE, &cmd_id);
  PT_TEST_LOG_SUCC ("ProCmdActionAdd");
  
  status = ProMenubarmenuPushbuttonAdd("PTMechanicaTest","PTMechExItemInfo",
				       "PTMechExItemInfoLabel",
				       "PTMechExItemInfoLabelHelp",NULL,
				       PRO_B_TRUE, cmd_id, msgfile);
  PT_TEST_LOG_SUCC("ProMenubarmenuPushbuttonAdd");
  
  
  
  return (0);
}


/*====================================================================*\
  FUNCTION : user_terminate()
  PURPOSE  : To handle any termination actions
\*====================================================================*/

void user_terminate()
{
}