diff options
Diffstat (limited to 'src/Viewer/studio3d')
-rw-r--r-- | src/Viewer/studio3d/q3dscommandqueue.cpp | 42 | ||||
-rw-r--r-- | src/Viewer/studio3d/q3dscommandqueue_p.h | 13 | ||||
-rw-r--r-- | src/Viewer/studio3d/q3dspresentation.cpp | 20 | ||||
-rw-r--r-- | src/Viewer/studio3d/q3dspresentation.h | 2 |
4 files changed, 71 insertions, 6 deletions
diff --git a/src/Viewer/studio3d/q3dscommandqueue.cpp b/src/Viewer/studio3d/q3dscommandqueue.cpp index 2bc540af..71220410 100644 --- a/src/Viewer/studio3d/q3dscommandqueue.cpp +++ b/src/Viewer/studio3d/q3dscommandqueue.cpp @@ -28,6 +28,7 @@ ****************************************************************************/ #include "q3dscommandqueue_p.h" +#include "q3dspresentation.h" ElementCommand::ElementCommand() : m_commandType(CommandType_Invalid) @@ -146,6 +147,19 @@ ElementCommand &CommandQueue::queueCommand(const QString &elementPath, return cmd; } +ElementCommand &CommandQueue::queueCommand(const QString &elementPath, CommandType commandType, + const QString &stringValue, void *commandData) +{ + ElementCommand &cmd = nextFreeCommand(); + + cmd.m_commandType = commandType; + cmd.m_elementPath = elementPath; + cmd.m_stringValue = stringValue; + cmd.m_data = commandData; + + return cmd; +} + ElementCommand &CommandQueue::queueRequest(const QString &elementPath, CommandType commandType) { ElementCommand &cmd = nextFreeCommand(); @@ -156,7 +170,7 @@ ElementCommand &CommandQueue::queueRequest(const QString &elementPath, CommandTy return cmd; } -void CommandQueue::copyCommands(const CommandQueue &fromQueue) +void CommandQueue::copyCommands(CommandQueue &fromQueue) { m_visibleChanged = m_visibleChanged || fromQueue.m_visibleChanged; m_scaleModeChanged = m_scaleModeChanged || fromQueue.m_scaleModeChanged; @@ -191,7 +205,7 @@ void CommandQueue::copyCommands(const CommandQueue &fromQueue) // Pending queue may be synchronized multiple times between queue processing, so let's append // to the existing queue rather than clearing it. for (int i = 0; i < fromQueue.m_size; i++) { - const ElementCommand &source = fromQueue.commandAt(i); + const ElementCommand &source = fromQueue.constCommandAt(i); switch (source.m_commandType) { case CommandType_SetDataInputValue: queueCommand(source.m_elementPath, source.m_commandType, source.m_stringValue, @@ -225,6 +239,11 @@ void CommandQueue::copyCommands(const CommandQueue &fromQueue) source.m_intValues[0], source.m_intValues[1], source.m_intValues[2], source.m_intValues[3]); break; + case CommandType_CreateElement: + queueCommand(source.m_elementPath, source.m_commandType, source.m_stringValue, + source.m_data); + fromQueue.commandAt(i).m_data = nullptr; // This queue takes ownership of data + break; case CommandType_RequestSlideInfo: case CommandType_UnloadSlide: case CommandType_PreloadSlide: @@ -241,7 +260,7 @@ void CommandQueue::copyCommands(const CommandQueue &fromQueue) } // Clears changed states and empties the queue -void CommandQueue::clear() +void CommandQueue::clear(bool deleteCommandData) { m_visibleChanged = false; m_scaleModeChanged = false; @@ -253,6 +272,23 @@ void CommandQueue::clear() m_globalAnimationTimeChanged = false; m_delayedLoadingChanged = false; + if (deleteCommandData) { + for (int i = 0; i < m_size; ++i) { + ElementCommand &cmd = m_elementCommands[i]; + if (cmd.m_data) { + switch (cmd.m_commandType) { + case CommandType_CreateElement: + delete static_cast<QHash<QString, QVariant> *>(cmd.m_data); + break; + default: + Q_ASSERT(false); // Should never come here + break; + } + cmd.m_data = nullptr; + } + } + } + // We do not clear the actual queued commands, those will be reused the next frame // To avoid a lot of unnecessary reallocations. m_size = 0; diff --git a/src/Viewer/studio3d/q3dscommandqueue_p.h b/src/Viewer/studio3d/q3dscommandqueue_p.h index 27612bfb..533f61ed 100644 --- a/src/Viewer/studio3d/q3dscommandqueue_p.h +++ b/src/Viewer/studio3d/q3dscommandqueue_p.h @@ -68,6 +68,9 @@ enum CommandType { CommandType_KeyRelease, CommandType_SetGlobalAnimationTime, CommandType_SetDataInputValue, + CommandType_CreateElement, + + // Requests CommandType_RequestSlideInfo, CommandType_RequestDataInputs, CommandType_PreloadSlide, @@ -83,6 +86,7 @@ public: QString m_elementPath; QString m_stringValue; QVariant m_variantValue; + void *m_data = nullptr; // Data is owned by the queue and is deleted once command is handled union { bool m_boolValue; float m_floatValue; @@ -114,9 +118,11 @@ public: ElementCommand &queueCommand(const QString &elementPath, CommandType commandType, int value0, int value1 = 0, int value2 = 0, int value3 = 0); + ElementCommand &queueCommand(const QString &elementPath, CommandType commandType, + const QString &stringValue, void *commandData); ElementCommand &queueRequest(const QString &elementPath, CommandType commandType); - void copyCommands(const CommandQueue &fromQueue); + void copyCommands(CommandQueue &fromQueue); bool m_visibleChanged; bool m_scaleModeChanged; @@ -138,9 +144,10 @@ public: qint64 m_globalAnimationTime; bool m_delayedLoading; - void clear(); + void clear(bool deleteCommandData); int size() const { return m_size; } - const ElementCommand &commandAt(int index) const { return m_elementCommands.at(index); } + const ElementCommand &constCommandAt(int index) const { return m_elementCommands.at(index); } + ElementCommand &commandAt(int index) { return m_elementCommands[index]; } private: ElementCommand &nextFreeCommand(); diff --git a/src/Viewer/studio3d/q3dspresentation.cpp b/src/Viewer/studio3d/q3dspresentation.cpp index f4235456..362c2803 100644 --- a/src/Viewer/studio3d/q3dspresentation.cpp +++ b/src/Viewer/studio3d/q3dspresentation.cpp @@ -274,6 +274,26 @@ void Q3DSPresentation::setDataInputValue(const QString &name, const QVariant &va } } +/** + Adds a new child element for the element specified by parentElementPath to the slide specified with + slideName. Only model element creation is currently supported. + A referenced material element is also created for the new model element. The source material name + can be specified with custom "material" property in the properties hash. + The source material must exist in the material container of the presentation. +*/ +void Q3DSPresentation::createElement(const QString &parentElementPath, const QString &slideName, + const QHash<QString, QVariant> &properties) +{ + if (d_ptr->m_viewerApp) { + d_ptr->m_viewerApp->createElement(parentElementPath, slideName, properties); + } else if (d_ptr->m_commandQueue) { + // We need to copy the properties map as queue takes ownership of it + QHash<QString, QVariant> *theProperties = new QHash<QString, QVariant>(properties); + d_ptr->m_commandQueue->queueCommand(parentElementPath, CommandType_CreateElement, + slideName, theProperties); + } +} + void Q3DSPresentation::mousePressEvent(QMouseEvent *e) { if (d_ptr->m_viewerApp) { diff --git a/src/Viewer/studio3d/q3dspresentation.h b/src/Viewer/studio3d/q3dspresentation.h index 34809613..97f7b6fc 100644 --- a/src/Viewer/studio3d/q3dspresentation.h +++ b/src/Viewer/studio3d/q3dspresentation.h @@ -83,6 +83,8 @@ public: void keyPressEvent(QKeyEvent *e); void keyReleaseEvent(QKeyEvent *e); + void createElement(const QString &parentElementPath, const QString &slideName, + const QHash<QString, QVariant> &properties); public Q_SLOTS: void setSource(const QUrl &source); void setVariantList(const QStringList &variantList); |