Example:
This example illustrates how to call this method on time-out. It describes how to migrate from a CATStateCommand, named CAAMyStateCommand, which would run ExecuteScript synchronously, to a CATStateCommand which would run ExecuteScript on time-out.
Instead of:
a transition, and its associated action, which:
run the script synchronously
do the actions which must be ran after the script execution
the transition triggering during execution making pass from a CATDialogState named SourceState to a CATDialogState named DestinationState
we will have:
a transition executing the first part of the preceeding solution: it adds a call-back on time out, the call-back running the script
this transition makes pass from a CATDialogState named SourceState to a CATDialogState named IntermediaryState
during execution, when the current state will be IntermediaryState, the preceeding call-back will be executed. This call-back runs the script, and triggers the other transition
another transition executing the second part of the preceeding solution: do the actions which must be ran after the script execution
this transition makes pass from IntermediaryState to a CATDialogState named DestinationState
Your code will be the following:
CAAMyStateCommandInteractionNotifier.h:
#ifndef CAAMyStateCommandInteractionNotifier_H
#define CAAMyStateCommandInteractionNotifier_H
#include "CATCommand.h"
class CATNotification;
class CAAMyStateCommandInteractionNotifier: public CATCommand
{ public:
CAAMyStateCommandInteractionNotifier();
virtual ~CAAMyStateCommandInteractionNotifier();
void Advise(CATCommand* ToClient, CATNotification* Notif);
};
#endif
CAAMyStateCommandInteractionNotifier.cpp:
#include "CAAMyStateCommandInteractionNotifier.h"
#include "CATCommand.h"
#include "CATNotification.h"
CAAMyStateCommandInteractionNotifier::CAAMyStateCommandInteractionNotifier()
{}
CAAMyStateCommandInteractionNotifier::~CAAMyStateCommandInteractionNotifier()
{}
void CAAMyStateCommandInteractionNotifier::Advise(CATCommand* ToClient, CATNotification* Notif)
{ SendNotification(ToClient,Notif); }
CAAMyStateCommandNotification.h:
#ifndef CAAMyStateCommandNotification_H
#define CAAMyStateCommandNotification_H
#include "CATNotification.h"
class CAASourceStateToIntermediaryStateNotif : public CATNotification
{ CATDeclareClass;
public:
CAASourceStateToIntermediaryStateNotif();
virtual ~CAASourceStateToIntermediaryStateNotif();
};
class CAAIntermediaryStateToDestinationStateNotif : public CATNotification
{ CATDeclareClass;
public:
CAAIntermediaryStateToDestinationStateNotif();
virtual ~CAAIntermediaryStateToDestinationStateNotif();
};
class CAADestinationStateToNULLStateNotif : public CATNotification
{ CATDeclareClass;
public:
CAADestinationStateToNULLStateNotif();
virtual ~CAADestinationStateToNULLStateNotif();
};
#endif
CAAMyStateCommandNotification.cpp:
#include "CAAMyStateCommandNotification.h"
CATImplementClass(CAASourceStateToIntermediaryStateNotif,Implementation,CATNotification,CATNull);
CAASourceStateToIntermediaryStateNotif::CAASourceStateToIntermediaryStateNotif() {}
CAASourceStateToIntermediaryStateNotif::~CAASourceStateToIntermediaryStateNotif() {}
CATImplementClass(CAAIntermediaryStateToDestinationStateNotif,Implementation,CATNotification,CATNull);
CAAIntermediaryStateToDestinationStateNotif::CAAIntermediaryStateToDestinationStateNotif() {}
CAAIntermediaryStateToDestinationStateNotif::~CAAIntermediaryStateToDestinationStateNotif() {}
CATImplementClass(CAADestinationStateToNULLStateNotif,Implementation,CATNotification,CATNull);
CAADestinationStateToNULLStateNotif::CAADestinationStateToNULLStateNotif() {}
CAADestinationStateToNULLStateNotif::~CAADestinationStateToNULLStateNotif() {}
CAAMyStateCommand.h:
#ifndef CAAMyStateCommand_h
#define CAAMyStateCommand_h
#include "CATStateCommand.h"
#include "CATPanelAcquisition.h"
#include "CAAMyStateCommandNotification.h"
#include "CAAMyStateCommandInteractionNotifier.h"
#include "CATPathElement.h"
#include "CATNotifier.h"
class CATDialogAgent;
class CAAMyStateCommand: public CATStateCommand
{ CmdDeclareResource(CAAMyStateCommand,CATStateCommand);
public:
CAAMyStateCommand( );
virtual ~CAAMyStateCommand();
virtual CATStatusChangeRC Activate(CATCommand* iFromClient,CATNotification* iNotification);
virtual CATStatusChangeRC Desactivate(CATCommand* iCmd,CATNotification* iNotification);
virtual CATStatusChangeRC Cancel(CATCommand* iCmd,CATNotification* iNotification);
virtual void BuildGraph();
static void sRunScriptAndTriggerSecondPartTransition(CATCommand* iCAAMyStateCommand,int iSubscribedType,
CATString* iScriptName);
CAASourceStateToIntermediaryStateNotif* _CAASourceStateToIntermediaryStateNotif;
CAAIntermediaryStateToDestinationStateNotif* _CAAIntermediaryStateToDestinationStateNotif;
CAADestinationStateToNULLStateNotif* _CAADestinationStateToNULLStateNotif;
CATBoolean FirstPartTransitionAction(void *data);
CATBoolean SecondPartTransitionAction(void *data);
CATBoolean EndCommandTransitionAction(void *data);
static CAAMyStateCommandInteractionNotifier* sInteractionNotifier;
CATDialogAgent* _FirstPartDialogAgent;
CATDialogAgent* _SecondPartDialogAgent;
CATDialogAgent* _EndCommandDialogAgent;
CATString _ScriptName;
};
#endif
CAAMyStateCommand.cpp:
#include "CAAMyStateCommand.h"
#include "CAAMyStateCommandNotification.h"
#include "CATApplication.h"
#include "CATScriptUtilities.h"
#include "CATAutoConversions.h"
#include "CATDialogAgent.h"
#include "CATGetEnvValue.h"
CAAMyStateCommandInteractionNotifier* CAAMyStateCommand::sInteractionNotifier = NULL;
void CAAMyStateCommand::sRunScriptAndTriggerSecondPartTransition(
CATCommand* iCAAMyStateCommand,int iSubscribedType,
CATString* iScriptName)
{ CATLibStatus LibOK;
CATUnicodeString FolderName;
CAAIntermediaryStateToDestinationStateNotif* CAAIntermediaryStateToDestinationStateNotif = NULL;
CAAMyStateCommand* MyStateCommand;
CATDialogAgent* SecondPartDialogAgent = NULL;
CATApplication* Application = NULL;
char* CATTempValue = NULL;
CATVariant VariantReturnValue;
long ReturnValue;
HRESULT hr;
Application = CATApplication::MainApplication();
MyStateCommand = (CAAMyStateCommand*)iCAAMyStateCommand;
CAAIntermediaryStateToDestinationStateNotif =
MyStateCommand->_CAAIntermediaryStateToDestinationStateNotif;
SecondPartDialogAgent = MyStateCommand->_SecondPartDialogAgent;
// We run the "CATMain" sub of the "MyScript.catvbs" script located in the place specified by
// the CATTemp environment variable
LibOK = CATGetEnvValue("CATTemp",[$CATTempValue)]
if (LibOK == CATLibSuccess)
{ FolderName = CATTempValue; ReturnValue = 0;
hr = BuildVariant((const long)ReturnValue,VariantReturnValue);
hr = CATScriptUtilities::ExecuteScript(FolderName,catScriptLibraryTypeDirectory,
iScriptName->CastToCharPtr(),VariantReturnValue,
"CATMain");
}
// we trigger the second part transition
sInteractionNotifier->Advise(SecondPartDialogAgent->GetFather(),
MyStateCommand->_CAAIntermediaryStateToDestinationStateNotif);
}
CAAMyStateCommand::CAAMyStateCommand():
CATStateCommand ("CAAMyStateCommand",CATCommandModeExclusive)
,_FirstPartDialogAgent(NULL),_SecondPartDialogAgent(NULL)
{ _CAASourceStateToIntermediaryStateNotif = new CAASourceStateToIntermediaryStateNotif();
_CAAIntermediaryStateToDestinationStateNotif = new CAAIntermediaryStateToDestinationStateNotif();
_CAADestinationStateToNULLStateNotif = new CAADestinationStateToNULLStateNotif();
sInteractionNotifier = new CAAMyStateCommandInteractionNotifier();
}
CAAMyStateCommand::~CAAMyStateCommand()
{ if (_CAASourceStateToIntermediaryStateNotif!=NULL)
{ _CAASourceStateToIntermediaryStateNotif->Release(); _CAASourceStateToIntermediaryStateNotif = NULL; }
if (_CAAIntermediaryStateToDestinationStateNotif!=NULL)
{ _CAAIntermediaryStateToDestinationStateNotif->Release(); _CAAIntermediaryStateToDestinationStateNotif = NULL; }
if (_CAADestinationStateToNULLStateNotif!=NULL)
{ _CAADestinationStateToNULLStateNotif->Release(); _CAADestinationStateToNULLStateNotif = NULL; }
if (_FirstPartDialogAgent!=NULL)
{ _FirstPartDialogAgent->RequestDelayedDestruction(); _FirstPartDialogAgent = NULL; }
if (_SecondPartDialogAgent!=NULL)
{ _SecondPartDialogAgent->RequestDelayedDestruction(); _SecondPartDialogAgent = NULL; }
if (_EndCommandDialogAgent!=NULL)
{ _EndCommandDialogAgent->RequestDelayedDestruction(); _EndCommandDialogAgent = NULL; }
if (sInteractionNotifier!=NULL)
{ sInteractionNotifier->RequestDelayedDestruction(); sInteractionNotifier = NULL; }
}
CATStatusChangeRC CAAMyStateCommand::Activate (CATCommand* FromClient,CATNotification* EvtDat )
{ return (CATStatusChangeRCCompleted); }
CATStatusChangeRC CAAMyStateCommand::Desactivate (CATCommand* iCmd,CATNotification* iNotification)
{ return (CATStatusChangeRCCompleted); }
CATStatusChangeRC CAAMyStateCommand::Cancel (CATCommand* iCmd,CATNotification* iNotification)
{ return (CATStatusChangeRCCompleted); }
void CAAMyStateCommand::BuildGraph()
{ CATDialogState* SourceState = NULL;
CATDialogState* IntermediaryState = NULL;
CATDialogState* DestinationState = NULL;
// we fill the dialog agents
_FirstPartDialogAgent = new CATDialogAgent("CAASourceStateToIntermediaryStateNotif");
_FirstPartDialogAgent->AcceptOnNotify(sInteractionNotifier,_CAASourceStateToIntermediaryStateNotif);
_SecondPartDialogAgent = new CATDialogAgent("CAAIntermediaryStateToDestinationStateNotif");
_SecondPartDialogAgent->AcceptOnNotify(sInteractionNotifier,_CAAIntermediaryStateToDestinationStateNotif);
_EndCommandDialogAgent = new CATDialogAgent("CAADestinationStateToNULLStateNotif");
_EndCommandDialogAgent->AcceptOnNotify(sInteractionNotifier,_CAADestinationStateToNULLStateNotif);
// we fill the states
SourceState = GetInitialState("CAAMyStateCommandSourceState");
SourceState->AddDialogAgent(_FirstPartDialogAgent);
IntermediaryState = AddDialogState("CAAMyStateCommandIntermediaryState");
IntermediaryState->AddDialogAgent(_SecondPartDialogAgent);
DestinationState = AddDialogState("CAAMyStateCommandDestinationState");
DestinationState->AddDialogAgent(_EndCommandDialogAgent);
// we fill the transitions
AddTransition(SourceState,IntermediaryState,
IsOutputSetCondition(_FirstPartDialogAgent),
Action((ActionMethod) [$CAAMyStateCommand::FirstPartTransitionAction))]
AddTransition(IntermediaryState,DestinationState,
IsOutputSetCondition(_SecondPartDialogAgent),
Action((ActionMethod) [$CAAMyStateCommand::SecondPartTransitionAction))]
AddTransition(DestinationState,NULL,
IsOutputSetCondition(_EndCommandDialogAgent),
Action((ActionMethod) [$CAAMyStateCommand::EndCommandTransitionAction))]
// we trigger the first part transition
sInteractionNotifier->Advise((CATDialogAgent*)_FirstPartDialogAgent->GetFather(),
_CAASourceStateToIntermediaryStateNotif);
}
CATBoolean CAAMyStateCommand::FirstPartTransitionAction(void *data)
{ CATApplication* Application = NULL;
// insert here the actions which must be ran before the script execution
// we set the sRunScriptAndTriggerSecondPartTransition call-back on time-out
Application = CATApplication::MainApplication();
_ScriptName = "MyScript.catvbs";
Application->AddTimeOut(1,this,&_ScriptName,
(void(*)())sRunScriptAndTriggerSecondPartTransition);
// we prevent _FirstPartDialogAgent to be valued any more through the notification
_FirstPartDialogAgent->IgnoreOnNotify(sInteractionNotifier,_CAASourceStateToIntermediaryStateNotif);
return TRUE;
}
CATBoolean CAAMyStateCommand::SecondPartTransitionAction(void *data)
{ // insert here the actions which must be ran after the script execution
// we prevent _SecondPartDialogAgent to be valued any more through the notification
_SecondPartDialogAgent->IgnoreOnNotify(sInteractionNotifier,_CAAIntermediaryStateToDestinationStateNotif);
// we trigger the end command transition
sInteractionNotifier->Advise(_EndCommandDialogAgent->GetFather(),_CAADestinationStateToNULLStateNotif);
return TRUE;
}
CATBoolean CAAMyStateCommand::EndCommandTransitionAction(void *data)
{ // we prevent _EndCommandDialogAgent to be valued any more through the notification
_EndCommandDialogAgent->IgnoreOnNotify(sInteractionNotifier,_CAADestinationStateToNULLStateNotif);
return TRUE;
}作者: 后备力量 时间: 2004-12-7 19:05
请问各位大侠有些什么CATIA的二次开发的书籍或资料呀?谢谢作者: Patton_icax 时间: 2004-12-9 20:55
就是阿,谢谢先作者: apple_bao_bao 时间: 2004-12-10 16:59
程序开发的前期可以用CATIA中的VBA做,后期或者要做比较复杂的对话框就把在VBA中做的模块导入到VB中做吧,可以做的。作者: maxiaozheng 时间: 2004-12-15 17:48