Workspace 6.21.5
Public Member Functions | List of all members
ElementScriptMapper Class Reference

Element mapper using QtScript to return a value for an element.

#include <Mesh/DataStructures/elementscriptmapper.h>

Inheritance diagram for ElementScriptMapper:
[legend]

Public Member Functions

 ElementScriptMapper ()
 
 ElementScriptMapper (const ElementScriptMapper &mapper)
 
 ~ElementScriptMapper () override
 
ElementScriptMapperclone () const override
 
Application::Memento::DatacreateMementoData (const MeshModelInterface &model, const ElementType::List &supportedElementTypes={ &ElementType::Tri::getInstance(), &ElementType::Quad::getInstance(), &ElementType::Tetrahedron::getInstance(), &ElementType::Hexahedron::getInstance() }) const override
 
const QString & getFunctionName () const
 
const QString & getScript () const
 
double getValue (const ElementType::Type &elementType, const ElementHandle &element, Application::Memento::Data &mementoData) const override
 
ElementScriptMapperoperator= (const ElementScriptMapper &mapper)
 
void setFunctionName (const QString &functionName)
 
void setScript (const QString &script)
 
- Public Member Functions inherited from ElementMapper
bool canSerialize () const override
 
ElementMapperclone () const override=0
 
virtual Application::Memento::DatacreateMementoData (const MeshModelInterface &model, const ElementType::List &supportedElementTypes={&ElementType::Tri::getInstance(), &ElementType::Quad::getInstance(), &ElementType::Tetrahedron::getInstance(), &ElementType::Hexahedron::getInstance()}) const =0
 
virtual double getValue (const ElementType::Type &elementType, const ElementHandle &element, Application::Memento::Data &mementoData) const =0
 
virtual bool getValueDataObject (const ElementType::Type &, const ElementHandle &, Application::Memento::Data &, DataExecution::DataObject *) const
 
bool load (const DataExecution::SerializedItem &item) override
 
void logText (const QString &msg) const
 
bool save (DataExecution::SerializedItem &item) const override
 
- Public Member Functions inherited from Clonable
virtual ~Clonable ()=default
 
virtual Clonableclone () const =0
 
- Public Member Functions inherited from Serialize
virtual ~Serialize ()=default
 
virtual bool canSerialize () const =0
 
virtual bool load (const SerializedItem &item)=0
 
virtual bool save (SerializedItem &item) const =0
 

Constructor & Destructor Documentation

◆ ElementScriptMapper() [1/2]

◆ ElementScriptMapper() [2/2]

◆ ~ElementScriptMapper()

~ElementScriptMapper ( )
override

Member Function Documentation

◆ clone()

ElementScriptMapper * clone ( ) const
overridevirtual
Returns
A clone of this object.
Note
Subclasses would normally return their own type rather than the Clonable type. The C++ language rules allow a more derived type to be returned from a virtual function and the compiler will still treat it as a valid override.

Implements ElementMapper.

◆ createMementoData()

Application::Memento::Data * createMementoData ( const MeshModelInterface model,
const ElementType::List supportedElementTypes = { &ElementType::Tri::getInstance(), &ElementType::Quad::getInstance(), &ElementType::Tetrahedron::getInstance(), &ElementType::Hexahedron::getInstance() } 
) const
overridevirtual

Implements ElementMapper.

◆ getFunctionName()

const QString & getFunctionName ( ) const
Returns
The name of the function that will be called to map each node to a value.

The default function name is an empty string, however the convention is to use mapToValue as the function name. The default is empty because it allows the script contents to be as trivial as possible. See setFunctionName() for more details on this issue.

See also
setFunctionName()

◆ getScript()

const QString & getScript ( ) const
Returns
The script being used by the mapper.
See also
setScript()

◆ getValue()

double getValue ( const ElementType::Type elementType,
const ElementHandle element,
Application::Memento::Data mementoData 
) const
overridevirtual
Parameters
elementTypeThe element type to be mapped to a value.
elementThe element to be mapped to a value.
mementoDataThe data from the memento created by a previous call to createMementoData(). It is used internally by this function to work out what value needs to be returned.
Returns
The mapped value for the element. If mementoData is invalid, this function returns 0.

Implements ElementMapper.

◆ operator=()

ElementScriptMapper & operator= ( const ElementScriptMapper mapper)

◆ setFunctionName()

void setFunctionName ( const QString &  functionName)
Parameters
functionNameThe name of the function to call to map each element to a value.

The functionName should refer to a valid function defined in the script provided to the mapper. If it does not, an error will occur and the mapper will fail (and therefore return 0 for all values). The one exception to this is if functionName is empty. In this case, the contents of the script are assumed to be just the body of a function and the mapper should wrap it in its own function. This is not as clear, since the script still needs to have return statements but the script itself won't show what is being returned from. Still, some users may find this "feature" useful if their script contents are more or less trivial.

See also
getFunctionName()

◆ setScript()

void setScript ( const QString &  script)
Parameters
scriptThe script to use for the mapper.
See also
getScript()