- 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);
static int sOccurenceCount; // The purpose of this variable is to avoid instances of the current
// CATStateCommand which do not exist any more to be used.
// In the following scenario:
// - the CAA developer uses a CATStateCommand
// - the CATStateCommand runs a script on time-out
// - the script calls the automation method Documents.Open, giving it a Part
// as parameter
// - during execution, only a Product is open, and CAAMyStateCommand is ran
// we have:
// - the CAAMyStateCommand::sRunScriptAndTriggerSecondPartTransition
// call-back is executed
// - Documents.Open is executed
// - we enter the "Part Design" workbench
// - The "Select" command ask to become active
// - we go through the CAAMyStateCommand destructor
// - we go out of the script
// - - -> From now,
// CAAMyStateCommand::sRunScriptAndTriggerSecondPartTransition must
// not use anymore the CAAMyStateCommand instance
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;
int CAAMyStateCommand::sOccurenceCount = 0;
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");
}
if (sOccurenceCount!=0)
{ // 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();
sOccurenceCount++;
}
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; }
sOccurenceCount--;
}
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;
}