This first plug-in is a simple "Hello world" example. It does very little interesting but is a framework for a plug-in. It demonstrates a basic executable plug-in framework, use of PlugInArgList, and use of Progress.
If you would like to run this tutorial as you follow along with the code, see Running Tutorials With Opticks. If you would like to build and experiment with this tutorial as you follow along with the code, see Building and Running Tutorial plug-ins. If you are running this tutorial in Opticks, you will need to select "Tutorial 1" from the Tutorial toolbar to execute it.
Tutorial1::Tutorial1()
{
setDescriptorId("{5D8F4DD0-9B20-42B1-A060-589DFBC85D00}");
setName("Tutorial 1"); setDescription("Creating your first plug-in."); setCreator("Opticks Community"); setVersion("Sample"); setCopyright("Copyright (C) 2008, Ball Aerospace & Technologies Corp.");
setProductionStatus(false);
setType("Sample");
setMenuLocation("[Tutorial]/Tutorial 1");
setAbortSupported(false);
}
The Tutorial1::~Tutorial() and Tutorial1::getOutputSpecification() methods don't do anything interesting right now but Tutorial1::getInputSpecification() does.
bool Tutorial1::getInputSpecification(PlugInArgList*& pInArgList) { pInArgList = Service<PlugInManagerServices>()->getPlugInArgList(); VERIFY(pInArgList != NULL);
NULL pointer unless there is a serious run-time error such as insufficient memory.
Service is an Opticks Resource which provides access to a service singleton such as PlugInManagerServices. We'll talk more about Resource and Service in a later tutorial. PlugInManagerServices is being used to create a new PlugInArgList. If we have no arguments, the PlugInArgList should be set to NULL like we are doing in Tutorial1::getOutputSpecification().
pInArgList->addArg<Progress>(Executable::ProgressArg(), NULL, "Progress reporter"); return true; }
NULL when the plug-in is called in batch mode. Since NULL is a valid value, we'll make NULL the default. The last argument is an optional description. It is displayed to the user in various places. If the meaning of the argument is not obvious, a short description should be provided.Finally, the Tutorial1::execute() method provides the real functionality of the plug-in. It is called when the user selects the menu location.
bool Tutorial1::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { if (pInArgList == NULL) { return false; }
NULL. We set the output argument list to NULL in Tutorial1::getOutputSpecification() since we have no output arguments. If we were returning data in the output argument list, we would ensure that pOutArgList is not NULL as well. Progress* pProgress = pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg());
if (pProgress != NULL) { pProgress->updateProgress("This demonstrates display of a warning.", 0, WARNING); pProgress->updateProgress("This demonstrates display of an error.", 0, ERRORS); pProgress->updateProgress("Hello World!", 100, NORMAL); }
NULL when calling Executable::execute() so we need to check for NULL here. If we have a valid progress, we display a message to the user. We indicate that the progress is 100%. Normally, we should always set the progress to 100% before returning successfully from Executable::execute(). The progress dialog may close when the plug-in finishes executing so make sure the "Automatically close on process completion" option is not checked in "Tools->Options->Session->General->Progress Dialog". return true; }