Workspace 6.21.5
Classes | Public Member Functions | Protected Member Functions | List of all members
MeshModelSource Class Reference

Makes a MeshModel source available without having to first read in the MeshModel data. More...

#include <Mesh/DataStructures/meshmodelsource.h>

Inheritance diagram for MeshModelSource:
[legend]

Classes

class  LockableRef
 Reference to the MeshModelSource that is aware of the lifespan of the MeshModelSource and can provide a "lock" on the source for the duration of the scope. More...
 
class  LockedPtr
 Pointer to the MeshModelSource which is mutex locked for the duration that this pointer exists. More...
 
class  MeshModelInterfaceLockedPtr
 Reference to a MeshModelInterface that, when created, locks access to the MeshModelInterface via any of the lock-aware functions via a mutex internal to the MeshModelSource. When this Ref object goes out of scope, access is restored again. More...
 

Public Member Functions

 MeshModelSource (const QString &modelId="")
 
 ~MeshModelSource () override
 
QString getExistingNormalsStateName () const
 
const QDateTime & getLastUpdated () const
 
LockableRef getLockableReference ()
 
DataExecution::InputScalargetMeshModelInput ()
 
const DataExecution::InputScalargetMeshModelInput () const
 
MeshModelInterfacegetMeshModelInterface ()
 
MeshModelInterfaceLockedPtr getMeshModelInterfaceLocked ()
 
QString getModelId ()
 
const QDateTime & getModelLastUpdated () const
 
bool requestModelUpdate ()
 
bool setModelId (const QString &modelId)
 
- Public Member Functions inherited from Operation
 ~Operation () override
 
bool addInput (Input &input, bool modifiedInPlace=false)
 
bool addOutput (Output &output)
 
template<typename T >
bool assignInput (const QString &inputName, const T &value)
 
bool canSerialize () const override
 
bool connectProgressEvents (QProgressBar *progressBar)
 
virtual Presentation::CustomOperationPropertiescreateCustomPropertiesHandler ()
 
virtual void ensureHasData ()
 
bool getBroadcastUpdateEvents () const
 
QColor getColor () const
 
virtual QString getDefaultIconPath () const
 
QString getDefaultUiPath () const
 
QString getDeprecationMessage () const
 
const QString & getDescription () const
 
SerializedItem getExtras ()
 
const OperationFactorygetFactory () const
 
OperationgetFromPath (const QString &path, Workspace &relativeTo, QStringList &errors) const override
 
virtual GraphicsSize getGraphicsSize () const
 
virtual QString getHelpPage () const
 
QString getIconPath () const
 
const QUuid & getId () const
 
QString getIdPath (bool scoped=true) const override
 
QString getIdPath (const Workspace &relativeTo) const
 
difference_type getIndex (const Input &input, IndexCountingOptions options=SkipNone) const
 
difference_type getIndex (const Output &output, IndexCountingOptions options=SkipNone) const
 
void getIndexPair (InputScalar &input, difference_type &mainIndex, difference_type &arrayIndex)
 
InputgetInput (const QString &name)
 
const InputgetInput (const QString &name) const
 
InputgetInput (size_type index)
 
const InputgetInput (size_type index) const
 
InputArraygetInputArray (const QString &name)
 
const InputArraygetInputArray (const QString &name) const
 
IOBaseIteratorRange< Input, false > getInputs ()
 
IOBaseIteratorRange< Input, true > getInputs () const
 
InputScalargetInputScalar (const QString &name)
 
const InputScalargetInputScalar (const QString &name) const
 
template<typename T >
T & getInputValue (const QString &inputName)
 
template<typename T >
const T & getInputValue (const QString &inputName) const
 
const QString & getLabel () const
 
QString getLabelRelativeToRoot () const
 
OutputgetOutput (const QString &name)
 
const OutputgetOutput (const QString &name) const
 
OutputgetOutput (size_type index)
 
const OutputgetOutput (size_type index) const
 
IOBaseIteratorRange< Output, false > getOutputs ()
 
IOBaseIteratorRange< Output, true > getOutputs () const
 
template<typename T >
T & getOutputValue (const QString &outputName)
 
template<typename T >
const T & getOutputValue (const QString &outputName) const
 
bool getProfilingEnabled () const
 
int getProgress () const
 
int getProgressContribution () const
 
bool getProgressResetByNotUpToDate () const
 
virtual SchedulerFeatures getRequiredSchedulerFeatures () const
 
InputScalargetScalarInput (size_type mainIndex, difference_type arrayIndex)
 
QString getShortLabel () const
 
QString getTagName () const
 
bool getTerminateExecution () const
 
QString getUiPath () const
 
bool getUpToDate () const override
 
virtual bool hasRequiredSchedulerFeatures () const
 
void idPathChanged () override
 
virtual bool inputRebuilt (InputScalar &input)
 
virtual bool isAsynchronous () const
 
virtual bool isAsynchronousProcess () const
 
virtual bool isAtomicUpdate () const
 
bool isConnectedToAsynchronous () const override
 
bool isDeprecated () const
 
bool isEditable () const
 
bool isIdPathCachingEnabled () const
 
virtual bool isPolymorphicType () const
 
virtual bool isRunningAsynchronously () const
 
virtual bool isThreadSafe () const
 
template<typename T >
bool isType () const
 
bool isType (const OperationFactory &type) const
 
bool isUpdating () const
 
virtual bool isUserConfigurable ()
 
bool isUsingDefaultColor () const
 
bool isUsingDefaultIconPath () const
 
bool isUsingDefaultUiPath () const
 
bool isWaitingForAsynchronousUpdate () const override
 
bool isWorkspaceType () const
 
bool load (const SerializedItem &item) override
 
void markUpToDateWhereSafe ()
 
bool matchesType (const Operation &otherOperation) const
 
size_type numInputs (IndexCountingOptions=SkipNone) const
 
size_type numOutputs (IndexCountingOptions=SkipNone) const
 
bool removeInput (const QString &name)
 
bool removeInput (Input &input)
 
bool removeOutput (const QString &name)
 
bool removeOutput (Output &output)
 
virtual void resetExecutionDependencies ()
 
bool save (SerializedItem &item) const override
 
virtual bool saveWithData (SerializedItem &item) const
 
virtual void setAtomicUpdate (bool atomic)
 
void setBroadcastUpdateEvents (bool enable)
 
void setColor (const QColor &c)
 
void setDescription (const QString &description)
 
void setEditable (bool b)
 
void setIconPath (const QString &path)
 
void setId (const QUuid &id)
 
virtual void setIdPathCachingEnabled (bool b)
 
virtual void setInputNotUpToDate (InputScalar &input)
 
virtual void setIsAsynchronous (bool asynchronous)
 
virtual void setIsAsynchronousProcess (bool)
 
virtual void setIsRunningAsynchronously (bool asynchronous)
 
void setLabel (const QString &label)
 
virtual void setOutputNotUpToDate (Output &output)
 
void setProfilingEnabled (bool enable)
 
virtual void setProgress (int percent)
 
void setProgressContribution (int percent)
 
void setProgressResetByNotUpToDate (bool b)
 
virtual void setRequiredSchedulerFeatures (const SchedulerFeatures &)
 
void setTerminateExecution (bool b)
 
void setUiPath (const QString &path)
 
void setUpToDate (bool b) override
 
bool update (Updater *updater=nullptr) override
 
- Public Member Functions inherited from WorkspaceElement
 ~WorkspaceElement () override
 
const WorkspacegetWorkspace () const override
 
WorkspacegetWorkspace () override
 
virtual void workspaceChanged (Workspace *oldWorkspace)
 
- Public Member Functions inherited from Updatable
 ~Updatable () override
 
virtual bool comesFromExternal () const
 
QString getEnclosingScope () const
 
virtual UpdatablegetFromPath (const QString &path, Workspace &relativeTo, QStringList &errors) const =0
 
const QString & getGlobalName () const
 
virtual QString getIdPath (bool scoped=true) const =0
 
virtual WorkspacegetRootWorkspace ()
 
virtual const WorkspacegetRootWorkspace () const
 
QString getScopedGlobalName () const
 
virtual bool getUpToDate () const =0
 
virtual const WorkspacegetWorkspace () const =0
 
virtual WorkspacegetWorkspace ()=0
 
virtual void idPathChanged ()
 
virtual bool isConnectedToAsynchronous () const =0
 
virtual bool isWaitingForAsynchronousUpdate () const =0
 
void setGlobalName (const QString &name)
 
virtual void setUpToDate (bool b)=0
 
virtual bool update (Updater *updater=nullptr)=0
 
- Public Member Functions inherited from Observable
virtual ~Observable ()
 
void attachObserver (Observer &observer)
 
void destroy ()
 
void detachObserver (Observer &observer)
 
void notifyEvent (const ObservableEvent &event)
 
- 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
 
- Public Member Functions inherited from TextLogger
 TextLogger ()
 
 TextLogger (const DataExecution::IOBase &io)
 
 TextLogger (const DataExecution::Operation &operation)
 
 TextLogger (const TextLogger &logger)
 
 TextLogger (TextLogger &&logger)
 
virtual ~TextLogger ()
 
void logLine (const Application::LogManager::MessageCategory &category, const QString &msg) const
 
void logLine (const QString &msg) const
 
void logText (const Application::LogManager::MessageCategory &category, const QString &msg) const
 
void logText (const QString &msg) const
 
TextLoggeroperator= (TextLogger)
 

Protected Member Functions

 MeshModelSource (const DataExecution::OperationFactory &factory, const QString &label, const QString &modelId="", bool createOutput=true)
 
bool bringInputsUpToDate () override
 
bool bringModelIdUpToDate ()
 
bool bringModelUpToDate ()
 
bool execute () override
 
bool makeOutputsValid () override
 
void setInputNotUpToDate (DataExecution::InputScalar &input) override
 
- Protected Member Functions inherited from Operation
 Operation (const OperationFactory &factory, const QString &label)
 
bool bringArrayOfInputsUpToDate (Input *&array, size_type arraySize)
 
bool bringArrayOfInputsUpToDate (std::vector< Input * > &array)
 
virtual bool bringInputsUpToDate ()
 
bool bringInputUpToDate (Input &input)
 
virtual void cancelExecution (bool b)
 
virtual bool execute ()=0
 
virtual bool finishInputsOutputsAfterLoad (const SerializedItem &item)
 
UpdatergetCurrentUpdater ()
 
virtual const InputgetRenamedInput (const QString &name) const
 
virtual const OutputgetRenamedOutput (const QString &name) const
 
virtual bool inputsAreUpToDate () const
 
virtual bool makeOutputsValid ()
 
virtual void markOutputsUpToDate ()
 
void pauseUpdate ()
 
virtual bool postSave (SerializedItem &item) const
 
virtual bool prepareInputsOutputsForLoad (const SerializedItem &item)
 
void saveExtras (SerializedItem &item) const
 
virtual bool shouldPutInExtras (const QString &tagName) const
 
- Protected Member Functions inherited from WorkspaceElement
 WorkspaceElement ()
 
- Protected Member Functions inherited from Updatable
 Updatable ()
 
 Updatable (const Updatable &up)
 
void notifyUpdated ()
 
Updatableoperator= (const Updatable &up)
 
- Protected Member Functions inherited from Observable
 Observable ()
 
 Observable (const Observable &)
 

Additional Inherited Members

- Public Types inherited from Operation
enum  ConfigStatus { GoodConfig = 0x00 , UnknownConfig = 0x01 , InvalidConfig = 0x02 }
 
using difference_type = ptrdiff_t
 
enum  GraphicsSize { Default = 100 , Small = 65 }
 Options for the graphical size of an operation, able to be changed by derived classes. Values are percentages. More...
 
enum  IndexCountingOption { SkipNone = 0x0 , SkipInvisible = 0x1 , SkipDependencies = 0x2 }
 
using size_type = size_t
 
- Static Public Member Functions inherited from Updatable
static InputScalarfindInputScalarGlobalName (const QString &scopedGlobalName, Workspace &relativeTo)
 
static IOBasefindIOBaseGlobalName (const QString &scopedGlobalName, Workspace &relativeTo)
 
static OperationfindOperationGlobalName (const QString &scopedGlobalName, Workspace &relativeTo)
 

Detailed Description

This operation does not function like most workspace operations. Normally, an operation updates its inputs when the operation's outputs are requested. The MeshModelSource, however, instead passes itself as one of its own outputs and only updates the input which provides the ID for the model. The input associated with the MeshModel itself is not updated until something calls requestModelUpdate(), after which the next call to update() will bring the model input up to date. For as long as the model input is up to date, the model can be obtained by calling getMeshModelInterface().

By passing itself as its output, the MeshModelSource operation essentially becomes a DataObject that can be passed around and used by clients to trigger the source to read the model only when they need it. This provides a way to express a relationship in a conventional workspace arrangement, but delay the actual execution of parts of that workspace until something needs the actual data generated by the execution. One of the more useful techniques this enables is to express the structure of some data with workspace operations, but delay the population of that structured data (or portions thereof) until something actually needs it.

A consequence of all this is that updating a MeshModelSource operation does not typically update all its inputs, only some. The bringInputsUpToDate(), makeOutputsValid() and execute() functions are all overridden to provide this custom behaviour.

Constructor & Destructor Documentation

◆ MeshModelSource() [1/2]

MeshModelSource ( const DataExecution::OperationFactory factory,
const QString &  label,
const QString &  modelId = "",
bool  createOutput = true 
)
protected
Parameters
factoryThe factory of the subclass deriving from MeshModelSource.
labelThe default label for the subclassed source.
modelIdThe ID string this model source will be known as. The modelId is what the model is known as to clients who want to reference this model source through a MeshModelLibrary. If two model sources have the same modelId, they cannot be distinguished from each other in a MeshModelLibrary, so you should aim to give your model sources unique modelId's. If the modelId parameter is omitted, the default will be an empty string, which is generally useless if this source will be added to a MeshModelLibrary.
createOutputIf true, then the MeshModelSource will provide itself as an output of the operation. Subclasses sometimes want to hide this output and use the model source internally, typically providing something else as an output which encapsulates the model source somehow. If omitted, this defaults to true and the output will be created.

This constructor is for subclasses, since they need to be able to provide a different OperationFactory and may want to prevent the model source from providing itself as an output of the operation.

◆ MeshModelSource() [2/2]

MeshModelSource ( const QString &  modelId = "")
Parameters
modelIdThe ID string this model source will be known as. The modelId is what the model is known as to clients who want to reference this model source through a MeshModelLibrary. If two model sources have the same modelId, they cannot be distinguished from each other in a MeshModelLibrary, so you should aim to give your model sources unique modelId's. If the modelId parameter is omitted, the default will be an empty string, which is generally useless if this source will be added to a MeshModelLibrary.

◆ ~MeshModelSource()

~MeshModelSource ( )
override

Member Function Documentation

◆ bringInputsUpToDate()

bool bringInputsUpToDate ( )
overrideprotectedvirtual

This function is responsible for first bringing the dependency input up to date, then determining all the inputs required to update the operation's outputs and bring those inputs up to date as well.

The default implementation assumes all inputs need to be brought up to date, but some operations may only require some of the inputs to be up to date in order to calculate the outputs. Indeed, some of the inputs may need to be up to date, their values checked and then some combination of the rest brought up to date. An example where this could be useful is where an operation should behave differently for different iterations of a loop.

Subclasses which choose to override this function should call the other overloaded version of this function as necessary to actually bring the inputs it needs up to date, since it will handle multi-threading in a future implementation. It must update the dependency input first on its own before anything else.

Returns
True if required inputs were able to be brought up to date.
See also
update(), execute(), bringInputUpToDate(), bringArrayOfInputsUpToDate()

The MeshModelSource override of this function does not try to update the MeshModelInterface input unless the model ID input holds an empty string. If the model ID is not empty, the function allows the model input to remain not up to date until something asks the source to request it by calling requestModelUpdate(). If the model ID is empty, then the model input is needed to use the name assigned to the model as the model ID instead.

Reimplemented from Operation.

Reimplemented in MeshModelInstanceBuilder.

◆ bringModelIdUpToDate()

bool bringModelIdUpToDate ( )
protected

◆ bringModelUpToDate()

bool bringModelUpToDate ( )
protected

◆ execute()

bool execute ( )
overrideprotectedvirtual

Updates the model input only if something has asked for it via requestModelUpdate(). The source will continue attempting to bring that input up to date once per update until it does so successfully (which usually is the first attempt anyway) or unless something else causes that input to become up to date.

Returns
True if nothing has requested the model input or if the model input was able to be brought up to date (or was up to date already).

Implements Operation.

Reimplemented in MeshModelInstanceBuilder.

◆ getExistingNormalsStateName()

QString getExistingNormalsStateName ( ) const
Returns
Name of existing normals state or empty if one doesn't exist (and normals need to be calculated)

◆ getLastUpdated()

const QDateTime & getLastUpdated ( ) const

Indicates the time that MeshModelSource operation was last brought up-to-date. This does NOT correspond to the time that the inputModel_ was brought up-to-date, rather it corresponds to the time that something else up-stream was modified, e.g. a file-reader had its filename changed.

Returns
The time when the source was last updated.

◆ getLockableReference()

MeshModelSource::LockableRef getLockableReference ( )

◆ getMeshModelInput() [1/2]

DataExecution::InputScalar & getMeshModelInput ( )
Returns
The scalar MeshModel input owned by this operation.

◆ getMeshModelInput() [2/2]

const DataExecution::InputScalar & getMeshModelInput ( ) const
Returns
The scalar MeshModel input owned by this operation.

◆ getMeshModelInterface()

MeshModelInterface * getMeshModelInterface ( )
Returns
Upon successful exit, the function will return a pointer to the up to date MeshModelInterface at the MeshModelSource's input. If unsuccessful, a null pointer will be returned instead.

The pointer returned is only guaranteed to be valid for as long as the MeshModelSource's input remains up to date, so the caller needs to take steps to ensure that the model stays up to date for the duration of the time it wants to use the returned model.

See also
requestModelUpdate()

◆ getMeshModelInterfaceLocked()

MeshModelSource::MeshModelInterfaceLockedPtr getMeshModelInterfaceLocked ( )

◆ getModelId()

QString getModelId ( )
Returns
The id string for the model, or an empty string if there was an error.

If the "Model ID" input is not yet up to date, this function attempts to bring it up to date. If that fails, an empty string is returned.

◆ getModelLastUpdated()

const QDateTime & getModelLastUpdated ( ) const

Indicates the time that the MeshModelSource's MeshModel input was last brought up-to-date. This does not correspond to when it was cleared - only when it was brought up-to-date.

◆ makeOutputsValid()

bool makeOutputsValid ( )
overrideprotectedvirtual

This is an empty operation for MeshModelSource. See the class details for why this is the case. Some comments in Operation::makeOutputsValid() might also be helpful.

Returns
True unconditionally.

Reimplemented from Operation.

Reimplemented in MeshModelInstanceBuilder.

◆ requestModelUpdate()

bool requestModelUpdate ( )

Tells the source that something wants the model. This sets the source's up to date status to false and the next time the source is updated, it will also update the model input. Clients can then call getMeshModelInterface() to get the model until something invalidates the model input again. The caller is responsible for organizing itself to call getMeshModelInterface() before anything can invalidate the model input. This is most easiest done by attaching an observer to the operation or the model input for an UpdateEvent notification, since this will be the first opportunity for other threads outside the execution thread to access the data. As long as no other observer of that event invalidates the model input, the model input will be up to date and therefore the model will be available. Alternatively, anything downstream of the source can access the model after the usual workspace execution takes care of updating everything it depends on because the source will get invalidated any time the model input does while the model input is up to date.

Returns
True if the model input was updated immediately. If false is returned, this indicates that the request has been scheduled instead and will be carried out by the execution thread owning this source operation. Note that if the execution thread is not running, the model input will not get updated in that case.

◆ setInputNotUpToDate()

void setInputNotUpToDate ( DataExecution::InputScalar input)
overrideprotectedvirtual

We need to override this so that we can lock the model prior to it being cleared as part of the setNotUpToDate process.

Reimplemented from Operation.

◆ setModelId()

bool setModelId ( const QString &  modelId)
Parameters
modelIdThe id to use for the model source.

If the "Model ID" input of the model source is connected to something, any call to setModelId() will fail.

Returns
True if the model source ID could be set to modelId or false if the Model ID input is connected to something.
Postcondition
If the model ID is set, then the model ID input is marked as up to date. It is important to note that because of this, setModelId() should only ever be called on a source that is not under the control of a running execution thread.