07-04-2020, 10:07 AM
I added Transform Again support using the SDK, and also added support for custom Undo and Redo text. The hardest part was the busywork of adding all of the search paths to the SDK in each build version.
There's more to accessing the SDK than just this, but if you have a project that already uses the SDK, you won't have to add much to use Transform Again and custom Undo and Redo text.
I declared the suites in my SDK header file:
and cpp file:
... and load them in my startup sequence.
Also in startup I registered a message callback for Transform Again like this:
For the callback, I did something like this, to do some operation based on which of my tools is current:
After each transform operation I stored parameters for a Transform Again and added code like this:
Then finally, release the suits in your shutdown sequence.
I'm sure there are better and more elegant ways to do this, but it's been working for me.
There's more to accessing the SDK than just this, but if you have a project that already uses the SDK, you won't have to add much to use Transform Again and custom Undo and Redo text.
I declared the suites in my SDK header file:
Code:
#include "AITransformAgain.h"
#include "AIUndo.h"
#include "AIUnicodeString.h"
extern "C" AIUndoSuite* sUndo;
extern "C" AITransformAgainSuite* sAgain;
extern "C" AIUnicodeStringSuite* sUnicodeStr;
extern "C" SPBasicSuite* sSPBasic;
and cpp file:
Code:
AITransformAgainSuite* sAgain = NULL;
AIUndoSuite* sUndo = NULL;
AIUnicodeStringSuite* sUnicodeStr = NULL;
... and load them in my startup sequence.
Code:
if (sAgain == NULL)
sSPBasic->AcquireSuite ( kAITransformAgainSuite, kAITransformAgainVersion,
(const void**) &sAgain);
if (sUndo == NULL)
sSPBasic->AcquireSuite ( kAIUndoSuite, kAIUndoVersion,
(const void**) &sUndo);
if (sUnicodeStr == NULL)
sSPBasic->AcquireSuite ( kAIUnicodeStringSuite, kAIUnicodeStringSuiteVersion,
(const void**) &sUnicodeStr);
Also in startup I registered a message callback for Transform Again like this:
Code:
this->__corePlug->dispatcher()->registerMessageCallback(hdi::core::TransformAgainMessageType, HDI_CORE_CALLBACK(awesome::Plugin, this, __transformAgainCB));
For the callback, I did something like this, to do some operation based on which of my tools is current:
Code:
void awesome::Plugin::__transformAgainCB(){
if (this->__corePlug->currentTool()->number() == this->toolANo){
// do some function, passing stored parameters from the last operation
}
else if (this->__corePlug->currentTool()->number() == this->toolBNo){
// do some other function
}
}
After each transform operation I stored parameters for a Transform Again and added code like this:
Code:
sUndo->SetUndoTextUS(ai::UnicodeString("Undo Awesome Transform"),ai::UnicodeString("Redo Awesome Transform"));
sAgain->SetTransformAgain(HDI_CORE_PLUGIN->spPluginRef());
Then finally, release the suits in your shutdown sequence.
Code:
if (sAgain != NULL)
sSPBasic->ReleaseSuite (kAITransformAgainSuite, kAITransformAgainVersion);
if (sUndo != NULL)
sSPBasic->ReleaseSuite (kAIUndoSuite, kAIUndoVersion);
if (sUnicodeStr != NULL)
sSPBasic->ReleaseSuite (kAIUnicodeStringSuite, kAIUnicodeStringSuiteVersion);
I'm sure there are better and more elegant ways to do this, but it's been working for me.