MorphoGraphX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
process Namespace Reference

This namespace contains all the classes needed to define processes. More...

Detailed Description

This namespace contains all the classes needed to define processes.

To create a new process, you first need to decide the category of the process: Stack, Mesh or Global. Remember it will appear in the appropriate section. Also, stack processes will be able to access only 3D data, and mesh processes only the meshes. Here is a template of a minimal stack process:

Basics

class DoNothing : public StackProcess
{
public:
// Only the copy constructor is needed
DoNothing(const StackProcess& proc)
: Process(proc)
, StackProcess(proc)
{ }
// Define what the class do ... here it's nothing
bool operator()(const QStringList&) { return true; }
// Now define the properties of the process
QString name() const { return "Nothing"; }
QString description() const { return "This process really does nothing."; }
QStringList parmNames() const { return QStringList(); }
QStringList parmDescs() const { return QStringList(); }
};

Then, in the implementation file, you need to add:

Which will take care of registering the process to the system when the library is loaded.

Recommendations

Beside the minimal process, it is recommended to structure the process in two functions: the first one taking generic arguments (i.e. a string list and a float list), the other one taking specific arguments. This way, your process will be easier to use from another C++ process.

Also, to help providing meaningful (and uniform) error messages, and to help you testing the current state of the process, the checkState() method is provided.

The structure then typically becomes:

class DoSomething : public StackProcess
{
public:
DoSomething(const StackProcess& proc)
: Process(proc)
, StackProcess(proc)
{ }
// the operator() with generic arguments is mandatory to work
bool operator()(const QStringList& parms)
{
if(!checkState().stack(STACK_NON_EMPTY)
.store(STORE_LABEL | STORE_WORK)
.mesh(MESH_NON_EMPTY))
return false;
Store *store = currentStack()->work();
bool isneeded = stringToBool(parms[1]);
QString aname = parms[2];
float param = parms[3].toFloat();
if((*this)(store, isneeded, aname, param))
{
work->show();
return true;
}
return false;
}
// The operator() with specialized arguments is recommended to be used by other C++ processes
bool operator()(Store *store, bool isneeded, const QString& aname, float param)
{
// Do what is needed
store->changed();
return true;
}
// Properties of the process
QString name() const { return "DoSomething"; }
QString description() const { return "A process that does something"; }
// This time, we have four parameters
QStringList parmNames() const {
return QStringList() << "Store" << "Needed" << "Name" << "Param";
}
// Defaults for paramters
QStringList parmDefaults() const {
return QStringList() << "Work" << "Yes" << "" << "0.0";
}
// Some of the parms come from a choice list
ParmChoiceMap parmChoice() const
{
ParmChoiceMap choice;
choice[0] = storeChoice(); // Helper function to list "main" and "work"
choice[1] = booleanChoice(); // Helper function to list "yes" and "no"
return choice;
}
};