file_path
stringlengths
32
153
content
stringlengths
0
3.14M
omniverse-code/kit/include/omni/kit/ui/Image.h
// Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include "Widget.h" #include <carb/renderer/RendererTypes.h> #include <atomic> #include <mutex> namespace omni { namespace kit { namespace ui { /** * Defines a image. */ class OMNI_KIT_UI_CLASS_API Image : public Widget { public: static const WidgetType kType = CARB_HASH_TYPE(omni::kit::ui::Image); /** * Constructor. * ALWAYS create Image with make_shared so enable_shared_from_this works correctly. * * @param text The text for the label to use. */ OMNI_KIT_UI_API Image(const char* url, uint32_t width, uint32_t height); /** * Destructor. */ OMNI_KIT_UI_API ~Image() override; /** * Gets the url of the image. * * @return The url to be loaded. */ OMNI_KIT_UI_API const char* getUrl() const; /** * Sets the url of the image * * @param url The url to load. */ OMNI_KIT_UI_API virtual void setUrl(const char* url); /** * @see Widget::getType */ OMNI_KIT_UI_API WidgetType getType() override; /** * @see Widget::draw */ void draw(float elapsedTime) override; /** * draw image * * @param imgui imgui ptr * @param cursorPos position to draw image * @param width width of image to draw * @param height height of image to draw * @param color color of image to draw */ OMNI_KIT_UI_API virtual void drawImage(carb::imgui::ImGui* imgui, const carb::Float2& cursorPos, float width, float height, uint32_t color = 0xffffffff, uint32_t defaultColor = 0xffffffff, bool hovered = false); protected: void loadUrl(); std::string m_url; std::mutex m_textureMutex; carb::renderer::Texture* m_texture = nullptr; carb::renderer::TextureHandle m_textureGpuHandle = {}; bool m_hasSetUrl = false; }; } } }
omniverse-code/kit/include/omni/kit/ui/ProgressBar.h
// Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include "ColorScheme.h" #include "Widget.h" namespace omni { namespace kit { namespace ui { /** * Defines a progress bar. */ class OMNI_KIT_UI_CLASS_API ProgressBar : public Widget { public: static const WidgetType kType = CARB_HASH_TYPE(omni::kit::ui::ProgressBar); OMNI_KIT_UI_API ProgressBar(Length width, Length height = Pixel(0), const carb::Float4& color = kStatusBarProgressColor); OMNI_KIT_UI_API ProgressBar(float width, const carb::Float4& color = kStatusBarProgressColor); /** * Destructor. */ OMNI_KIT_UI_API virtual ~ProgressBar(); /** * @see Widget::getType */ OMNI_KIT_UI_API virtual WidgetType getType(); /** * @see Widget::draw */ OMNI_KIT_UI_API virtual void draw(float elapsedTime); /** * Set progress * * @param value The current value of progress bar (between 0-1). * @param text The overlay text for the progress bar. If nullptr, the automatic percentage text is displayed. */ OMNI_KIT_UI_API void setProgress(float value, const char* text = nullptr); /** * Get current progress * * @return The current value of progress bar (between 0-1). */ OMNI_KIT_UI_API float getProgress() const; /** * Get current overlay * * @return The current overlay of progress bar. */ OMNI_KIT_UI_API const char* getOverlay() const; /** * Set color of bar * * @param color Value in carb::Float4. */ OMNI_KIT_UI_API void setColor(carb::Float4 color); /** * Get color of bar * * @return color Value in carb::Float4. */ OMNI_KIT_UI_API carb::Float4 getColor() const; protected: float m_value; ///< The progress bar value (between 0-1). carb::Float4 m_color; // The color of progress bar. }; } } }
omniverse-code/kit/include/omni/kit/ui/TextBox.h
// Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include "ValueWidget.h" #include <string> #include <vector> namespace omni { namespace kit { namespace ui { /** * Defines a text field. */ class OMNI_KIT_UI_CLASS_API TextBox : public ValueWidget<std::string> { public: static const WidgetType kType = CARB_HASH_TYPE(omni::kit::ui::TextBox); static const size_t kMaxLength = 1024; OMNI_KIT_UI_API explicit TextBox(const char* defaultText, bool changeValueOnEnter = false); OMNI_KIT_UI_API TextBox(const char* defaultText, const char* hint, bool changeValueOnEnter = false); OMNI_KIT_UI_API ~TextBox() override; OMNI_KIT_UI_API void setValueChangedFn(const std::function<void(WidgetRef)>& fn); OMNI_KIT_UI_API void setValueFinalizedFn(const std::function<void(WidgetRef)>& fn); OMNI_KIT_UI_API void setListSuggestionsFn(const std::function<std::vector<std::string>(WidgetRef, const char*)>& fn); OMNI_KIT_UI_API bool getReadOnly() const; OMNI_KIT_UI_API void setReadOnly(bool readOnly); OMNI_KIT_UI_API bool getShowBackground() const; OMNI_KIT_UI_API void setShowBackground(bool showBackground); OMNI_KIT_UI_API float getTextWidth(); /** * Sets the color of the text. * * @param textColor */ OMNI_KIT_UI_API void setTextColor(const carb::ColorRgba& textColor); /** * Resets the color of the text. * * @param textColor */ OMNI_KIT_UI_API void resetTextColor(); /** * @see Widget::getType */ OMNI_KIT_UI_API WidgetType getType() override; /** * @see Widget::draw */ OMNI_KIT_UI_API void draw(float elapsedTime) override; OMNI_KIT_UI_API virtual std::vector<std::string> listSuggestions(const char* prefix); /* NOTE: only eEllipsisLeft & eEllipsisRight are supported when clipping is used, the TextBox will be readonly & disabled, but not greyed out */ ClippingType getClippingMode(ClippingType mode) const { return m_clippingMode; } void setClippingMode(ClippingType mode) { if (mode == ClippingType::eWrap) { CARB_LOG_ERROR("TextBox widget does not support ClippingType::eWrap"); return; } m_clippingMode = mode; } protected: void _onValueChange() override; private: void setText(const char* text); bool m_changeValueOnEnter; bool m_isReadOnly = false; bool m_wasActive = false; bool m_showBackground = true; char m_text[kMaxLength] = ""; char m_hint[kMaxLength] = ""; std::function<void(WidgetRef)> m_valueChangedFn; std::function<void(WidgetRef)> m_valueFinalizedFn; std::function<std::vector<std::string>(WidgetRef, const char*)> m_listSuggestionsFn; SubscriptionId m_valueSubId; float m_clippingWidth; ClippingType m_clippingMode; bool m_customColor = false; carb::ColorRgba m_textColor; }; } } }
omniverse-code/kit/include/omni/kit/ui/ScrollingFrame.h
// Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include "Container.h" namespace omni { namespace kit { namespace ui { /** * Defines a FixedSizeFrame layout. */ class OMNI_KIT_UI_CLASS_API ScrollingFrame : public Container { public: static const WidgetType kType = CARB_HASH_TYPE(omni::kit::ui::ScrollingFrame); OMNI_KIT_UI_API ScrollingFrame(const char* title, float width, float height); OMNI_KIT_UI_API ~ScrollingFrame(); OMNI_KIT_UI_API virtual void scrollTo(float scrollTo); OMNI_KIT_UI_API WidgetType getType() override; void draw(float elapsedTime) override; protected: float m_width; float m_height; bool m_needsScrolling = false; float m_scrollTo; std::string m_title; bool m_defaultOpen; }; } } }
omniverse-code/kit/include/omni/kit/ui/Popup.h
// Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include "ColumnLayout.h" #include <omni/ui/windowmanager/IWindowCallbackManager.h> #include <cstdint> #include <functional> #include <memory> #include <string> namespace omni { namespace kit { namespace ui { class Container; /** * Defines a popup. */ class OMNI_KIT_UI_CLASS_API Popup { public: /** * Constructor */ OMNI_KIT_UI_API explicit Popup( const std::string& title, bool modal = false, float width = 0, float height = 0, bool autoResize = false); /** * Destructor. */ OMNI_KIT_UI_API ~Popup(); OMNI_KIT_UI_API void show(); OMNI_KIT_UI_API void hide(); OMNI_KIT_UI_API bool isVisible() const; OMNI_KIT_UI_API void setVisible(bool visible); OMNI_KIT_UI_API const char* getTitle() const; OMNI_KIT_UI_API void setTitle(const char* title); OMNI_KIT_UI_API carb::Float2 getPos() const; OMNI_KIT_UI_API void setPos(const carb::Float2& pos); OMNI_KIT_UI_API float getWidth() const; OMNI_KIT_UI_API void setWidth(float width); OMNI_KIT_UI_API float getHeight() const; OMNI_KIT_UI_API void setHeight(float height); OMNI_KIT_UI_API std::shared_ptr<Container> getLayout() const; OMNI_KIT_UI_API void setLayout(std::shared_ptr<Container> layout); OMNI_KIT_UI_API void setUpdateFn(const std::function<void(float)>& fn); OMNI_KIT_UI_API void setCloseFn(const std::function<void()>& fn); private: void _draw(float dt); std::string m_popupId; bool m_modal; bool m_autoResize; std::string m_title; float m_width; float m_height; carb::Float2 m_pos; std::shared_ptr<Container> m_layout; omni::ui::windowmanager::IWindowCallbackPtr m_handle; omni::kit::SubscriptionId m_updateSubId; bool m_visible = false; bool m_pendingVisiblityUpdate = false; bool m_pendingPositionUpdate = false; std::function<void(float)> m_updateFn; std::function<void()> m_closeFn; }; } } }
omniverse-code/kit/include/omni/kit/ui/Model.h
// Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include "Api.h" #include "Common.h" #include <carb/events/IEvents.h> #include <memory> #include <string> #include <unordered_map> namespace omni { namespace kit { namespace ui { enum class ModelNodeType { eUnknown, eObject, eArray, eString, eBool, eNumber }; enum class ModelEventType { eNodeAdd, eNodeRemove, eNodeTypeChange, eNodeValueChange }; struct ModelChangeInfo { carb::events::SenderId sender = carb::events::kGlobalSenderId; bool transient = false; }; template <class T> struct ModelValue { T value; bool ambiguous; }; class OMNI_KIT_UI_CLASS_API Model { public: Model() = default; // PART 1: Get OMNI_KIT_UI_API virtual ModelNodeType getType(const char* path, const char* meta = "") = 0; OMNI_KIT_UI_API virtual ModelValue<std::string> getValueAsString( const char* path, const char* meta = "", size_t index = 0, bool isTimeSampled = false, double time = -1.0) = 0; OMNI_KIT_UI_API virtual ModelValue<bool> getValueAsBool( const char* path, const char* meta = "", size_t index = 0, bool isTimeSampled = false, double time = -1.0) = 0; OMNI_KIT_UI_API virtual ModelValue<double> getValueAsNumber( const char* path, const char* meta = "", size_t index = 0, bool isTimeSampled = false, double time = -1.0) = 0; virtual size_t getKeyCount(const char* path, const char* meta = "") { return 0; } virtual std::string getKey(const char* path, const char* meta, size_t index) { return ""; } virtual size_t getArraySize(const char* path, const char* meta = "") { return 0; } // PART 2: Set virtual void beginChangeGroup() { } virtual void endChangeGroup() { } virtual void setType(const char* path, const char* meta, ModelNodeType type, const ModelChangeInfo& info = {}) { } OMNI_KIT_UI_API virtual void setValueString(const char* path, const char* meta, std::string value, size_t index = 0, bool isTimeSampled = false, double time = -1.0, const ModelChangeInfo& info = {}) = 0; OMNI_KIT_UI_API virtual void setValueBool(const char* path, const char* meta, bool value, size_t index = 0, bool isTimeSampled = false, double time = -1.0, const ModelChangeInfo& info = {}) = 0; OMNI_KIT_UI_API virtual void setValueNumber(const char* path, const char* meta, double value, size_t index = 0, bool isTimeSampled = false, double time = -1.0, const ModelChangeInfo& info = {}) = 0; OMNI_KIT_UI_API virtual void setArraySize(const char* path, const char* meta, size_t size, bool isTimeSampled = false, double time = -1.0, const ModelChangeInfo& info = {}) { } // PART 3: signals OMNI_KIT_UI_API void signalChange(const char* path, const char* meta, ModelEventType type, const ModelChangeInfo& info); virtual void onSubscribeToChange(const char* path, const char* meta, carb::events::IEventStream*) { } virtual void onUnsubscribeToChange(const char* path, const char* meta, carb::events::IEventStream*) { } OMNI_KIT_UI_API void subscribeToChange(const char* path, const char* meta, carb::events::IEventStream*); OMNI_KIT_UI_API void unsubscribeToChange(const char* path, const char* meta, carb::events::IEventStream*); // HELPERS: template <class T> OMNI_KIT_UI_API ModelValue<T> getValue( const char* path, const char* meta, size_t index = 0, bool isTimeSampled = false, double time = -1.0); template <class T> OMNI_KIT_UI_API void setValue(const char* path, const char* meta, T value, size_t index = 00, bool isTimeSampled = false, double time = -1.0, const ModelChangeInfo& info = {}); template <class T> OMNI_KIT_UI_API static ModelNodeType getNodeTypeForT(); OMNI_KIT_UI_API virtual ~Model(){}; private: std::unordered_map<std::string, std::vector<carb::events::IEventStream*>> m_pathChangeListeners; }; template <> inline ModelValue<bool> Model::getValue(const char* path, const char* meta, size_t index, bool isTimeSampled, double time) { return getValueAsBool(path, meta, index, isTimeSampled, time); } template <> inline ModelValue<std::string> Model::getValue( const char* path, const char* meta, size_t index, bool isTimeSampled, double time) { return getValueAsString(path, meta, index, isTimeSampled, time); } template <> inline ModelValue<double> Model::getValue(const char* path, const char* meta, size_t index, bool isTimeSampled, double time) { return getValueAsNumber(path, meta, index, isTimeSampled, time); } template <> inline ModelValue<float> Model::getValue(const char* path, const char* meta, size_t index, bool isTimeSampled, double time) { auto v = getValue<double>(path, meta, index, isTimeSampled, time); return { static_cast<float>(v.value), v.ambiguous }; } template <> inline ModelValue<int32_t> Model::getValue(const char* path, const char* meta, size_t index, bool isTimeSampled, double time) { auto v = getValue<double>(path, meta, index, isTimeSampled, time); return { static_cast<int32_t>(v.value), v.ambiguous }; } template <> inline ModelValue<uint32_t> Model::getValue(const char* path, const char* meta, size_t index, bool isTimeSampled, double time) { auto v = getValue<double>(path, meta, index, isTimeSampled, time); return { static_cast<uint32_t>(v.value), v.ambiguous }; } template <> inline ModelValue<carb::Int2> Model::getValue(const char* path, const char* meta, size_t, bool isTimeSampled, double time) { auto v0 = getValue<int32_t>(path, meta, 0, isTimeSampled, time); auto v1 = getValue<int32_t>(path, meta, 1, isTimeSampled, time); return { carb::Int2{ v0.value, v1.value }, v0.ambiguous || v1.ambiguous }; } template <> inline ModelValue<carb::Double2> Model::getValue(const char* path, const char* meta, size_t, bool isTimeSampled, double time) { auto v0 = getValue<double>(path, meta, 0, isTimeSampled, time); auto v1 = getValue<double>(path, meta, 1, isTimeSampled, time); return { carb::Double2{ v0.value, v1.value }, v0.ambiguous || v1.ambiguous }; } template <> inline ModelValue<carb::Double3> Model::getValue(const char* path, const char* meta, size_t, bool isTimeSampled, double time) { auto v0 = getValue<double>(path, meta, 0, isTimeSampled, time); auto v1 = getValue<double>(path, meta, 1, isTimeSampled, time); auto v2 = getValue<double>(path, meta, 2, isTimeSampled, time); return { carb::Double3{ v0.value, v1.value, v2.value }, v0.ambiguous || v1.ambiguous || v2.ambiguous }; } template <> inline ModelValue<carb::Double4> Model::getValue(const char* path, const char* meta, size_t, bool isTimeSampled, double time) { auto v0 = getValue<double>(path, meta, 0, isTimeSampled, time); auto v1 = getValue<double>(path, meta, 1, isTimeSampled, time); auto v2 = getValue<double>(path, meta, 2, isTimeSampled, time); auto v3 = getValue<double>(path, meta, 3, isTimeSampled, time); return { carb::Double4{ v0.value, v1.value, v2.value, v3.value }, v0.ambiguous || v1.ambiguous || v2.ambiguous || v3.ambiguous }; } template <> inline ModelValue<carb::ColorRgb> Model::getValue(const char* path, const char* meta, size_t, bool isTimeSampled, double time) { auto v0 = getValue<float>(path, meta, 0, isTimeSampled, time); auto v1 = getValue<float>(path, meta, 1, isTimeSampled, time); auto v2 = getValue<float>(path, meta, 2, isTimeSampled, time); return { carb::ColorRgb{ v0.value, v1.value, v2.value }, v0.ambiguous || v1.ambiguous || v2.ambiguous }; } template <> inline ModelValue<carb::ColorRgba> Model::getValue(const char* path, const char* meta, size_t, bool isTimeSampled, double time) { auto v0 = getValue<float>(path, meta, 0, isTimeSampled, time); auto v1 = getValue<float>(path, meta, 1, isTimeSampled, time); auto v2 = getValue<float>(path, meta, 2, isTimeSampled, time); auto v3 = getValue<float>(path, meta, 3, isTimeSampled, time); return { carb::ColorRgba{ v0.value, v1.value, v2.value, v3.value }, v0.ambiguous || v1.ambiguous || v2.ambiguous || v3.ambiguous }; } template <> inline ModelValue<Mat44> Model::getValue(const char* path, const char* meta, size_t, bool isTimeSampled, double time) { ModelValue<Mat44> res; res.ambiguous = false; for (size_t i = 0; i < 16; i++) { auto v = getValue<double>(path, meta, i, isTimeSampled, time); *(&res.value.rows[0].x + i) = v.value; res.ambiguous |= v.ambiguous; } return res; } template <> inline void Model::setValue(const char* path, const char* meta, bool value, size_t index, bool isTimeSampled, double time, const ModelChangeInfo& info) { this->beginChangeGroup(); this->setValueBool(path, meta, value, index, isTimeSampled, time, info); this->endChangeGroup(); } template <> inline void Model::setValue(const char* path, const char* meta, std::string value, size_t index, bool isTimeSampled, double time, const ModelChangeInfo& info) { this->beginChangeGroup(); this->setValueString(path, meta, value, index, isTimeSampled, time, info); this->endChangeGroup(); } template <> inline void Model::setValue(const char* path, const char* meta, double value, size_t index, bool isTimeSampled, double time, const ModelChangeInfo& info) { this->beginChangeGroup(); this->setValueNumber(path, meta, value, index, isTimeSampled, time, info); this->endChangeGroup(); } template <> inline void Model::setValue(const char* path, const char* meta, float value, size_t index, bool isTimeSampled, double time, const ModelChangeInfo& info) { this->beginChangeGroup(); this->setValueNumber(path, meta, static_cast<double>(value), index, isTimeSampled, time, info); this->endChangeGroup(); } template <> inline void Model::setValue(const char* path, const char* meta, int32_t value, size_t index, bool isTimeSampled, double time, const ModelChangeInfo& info) { this->beginChangeGroup(); this->setValueNumber(path, meta, static_cast<double>(value), index, isTimeSampled, time, info); this->endChangeGroup(); } template <> inline void Model::setValue(const char* path, const char* meta, uint32_t value, size_t index, bool isTimeSampled, double time, const ModelChangeInfo& info) { this->beginChangeGroup(); this->setValueNumber(path, meta, static_cast<double>(value), index, isTimeSampled, time, info); this->endChangeGroup(); } template <> inline void Model::setValue(const char* path, const char* meta, carb::Int2 value, size_t, bool isTimeSampled, double time, const ModelChangeInfo& info) { this->beginChangeGroup(); this->setArraySize(path, meta, 2); this->setValue(path, meta, value.x, 0, isTimeSampled, time, info); this->setValue(path, meta, value.y, 1, isTimeSampled, time, info); this->endChangeGroup(); } template <> inline void Model::setValue(const char* path, const char* meta, carb::Double2 value, size_t, bool isTimeSampled, double time, const ModelChangeInfo& info) { this->beginChangeGroup(); this->setArraySize(path, meta, 2, isTimeSampled, time); this->setValue(path, meta, value.x, 0, isTimeSampled, time, info); this->setValue(path, meta, value.y, 1, isTimeSampled, time, info); this->endChangeGroup(); } template <> inline void Model::setValue(const char* path, const char* meta, carb::Double3 value, size_t, bool isTimeSampled, double time, const ModelChangeInfo& info) { this->beginChangeGroup(); this->setArraySize(path, meta, 3, isTimeSampled, time); this->setValue(path, meta, value.x, 0, isTimeSampled, time, info); this->setValue(path, meta, value.y, 1, isTimeSampled, time, info); this->setValue(path, meta, value.z, 2, isTimeSampled, time, info); this->endChangeGroup(); } template <> inline void Model::setValue(const char* path, const char* meta, carb::Double4 value, size_t, bool isTimeSampled, double time, const ModelChangeInfo& info) { this->beginChangeGroup(); this->setArraySize(path, meta, 4, isTimeSampled, time); this->setValue(path, meta, value.x, 0, isTimeSampled, time, info); this->setValue(path, meta, value.y, 1, isTimeSampled, time, info); this->setValue(path, meta, value.z, 2, isTimeSampled, time, info); this->setValue(path, meta, value.w, 3, isTimeSampled, time, info); this->endChangeGroup(); } template <> inline void Model::setValue(const char* path, const char* meta, carb::ColorRgb value, size_t, bool isTimeSampled, double time, const ModelChangeInfo& info) { this->beginChangeGroup(); this->setArraySize(path, meta, 3, isTimeSampled, time); this->setValue(path, meta, value.r, 0, isTimeSampled, time, info); this->setValue(path, meta, value.g, 1, isTimeSampled, time, info); this->setValue(path, meta, value.b, 2, isTimeSampled, time, info); this->endChangeGroup(); } template <> inline void Model::setValue(const char* path, const char* meta, carb::ColorRgba value, size_t, bool isTimeSampled, double time, const ModelChangeInfo& info) { this->beginChangeGroup(); this->setArraySize(path, meta, 4, isTimeSampled, time); this->setValue(path, meta, value.r, 0, isTimeSampled, time, info); this->setValue(path, meta, value.g, 1, isTimeSampled, time, info); this->setValue(path, meta, value.b, 2, isTimeSampled, time, info); this->setValue(path, meta, value.a, 3, isTimeSampled, time, info); this->endChangeGroup(); } template <> inline void Model::setValue(const char* path, const char* meta, ui::Mat44 value, size_t, bool isTimeSampled, double time, const ModelChangeInfo& info) { this->beginChangeGroup(); this->setArraySize(path, meta, 16, isTimeSampled, time); for (size_t i = 0; i < 16; i++) this->setValue(path, meta, *(&value.rows[0].x + i), i, isTimeSampled, time, info); this->endChangeGroup(); } template <> inline ModelNodeType Model::getNodeTypeForT<std::string>() { return ModelNodeType::eString; } template <> inline ModelNodeType Model::getNodeTypeForT<bool>() { return ModelNodeType::eBool; } template <> inline ModelNodeType Model::getNodeTypeForT<double>() { return ModelNodeType::eNumber; } template <> inline ModelNodeType Model::getNodeTypeForT<float>() { return ModelNodeType::eNumber; } template <> inline ModelNodeType Model::getNodeTypeForT<int32_t>() { return ModelNodeType::eNumber; } template <> inline ModelNodeType Model::getNodeTypeForT<uint32_t>() { return ModelNodeType::eNumber; } template <> inline ModelNodeType Model::getNodeTypeForT<carb::Int2>() { return ModelNodeType::eArray; } template <> inline ModelNodeType Model::getNodeTypeForT<carb::Double2>() { return ModelNodeType::eArray; } template <> inline ModelNodeType Model::getNodeTypeForT<carb::Double3>() { return ModelNodeType::eArray; } template <> inline ModelNodeType Model::getNodeTypeForT<carb::Double4>() { return ModelNodeType::eArray; } template <> inline ModelNodeType Model::getNodeTypeForT<carb::ColorRgb>() { return ModelNodeType::eArray; } template <> inline ModelNodeType Model::getNodeTypeForT<carb::ColorRgba>() { return ModelNodeType::eArray; } template <> inline ModelNodeType Model::getNodeTypeForT<Mat44>() { return ModelNodeType::eArray; } // Default Value Model std::unique_ptr<Model> createSimpleValueModel(ModelNodeType valueType); } } }
omniverse-code/kit/include/omni/kit/ui/Menu.h
// Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include "Widget.h" #include <omni/kit/KitTypes.h> #include <functional> #include <memory> #include <string> #include <unordered_map> #include <vector> namespace carb { namespace imgui { struct ImGui; } } namespace omni { namespace kit { namespace ui { struct MenuItemImpl; enum class MenuEventType : uint32_t { eActivate, }; /** * Menu System allows to register menu items based on path like: "File/Preferences/Foo". * The item can be either a toggle (2 state, with a check) or just a command. * Menu items in the same sub menu a sorted based on priority value. If priority differs more than 10 inbetween items - * separator is added. */ class OMNI_KIT_UI_CLASS_API Menu : public Widget { public: OMNI_KIT_UI_API Menu(); OMNI_KIT_UI_API ~Menu() override; static const WidgetType kType = CARB_HASH_TYPE(omni::kit::ui::Menu); WidgetType getType() override { return kType; } /** * Checks if a menu item is already registered. * * @param menuPath The path to the menu (e.g. "File/Open"). * @return true if it's existed, or false otherwise. */ OMNI_KIT_UI_API bool hasItem(const char* menuPath); /** * Adds a menu item. * * @param menuPath The path to the menu (e.g. "File/Open"). * @param onMenuItemClicked The callback function called when menu item is clicked. * @param toggle If the menu item is a toggle (i.e. checkable). * @param priority Priority of the menu. Menu with smaller priority will be placed at top. If priority differs more * @param toggle value (if toggle). * @param enabled. * @param draw glyph char with origin color defined in svg. * then 10 in between items separator is added. */ OMNI_KIT_UI_API bool addItem(const char* menuPath, const std::function<void(const char* menuPath, bool value)>& onClick, bool toggle, int priority, bool value, bool enabled, bool originSvgColor = false); OMNI_KIT_UI_API void setOnClick(const char* menuPath, const std::function<void(const char* menuPath, bool value)>& onClick); OMNI_KIT_UI_API void setOnRightClick(const char* menuPath, const std::function<void(const char* menuPath, bool value)>& onClick); /** * Removes a menu item. * * @param menuPath The path of the menu item to be removed. */ OMNI_KIT_UI_API void removeItem(const char* menuPath); OMNI_KIT_UI_API size_t getItemCount() const; OMNI_KIT_UI_API std::vector<std::string> getItems() const; /** * Sets the priority of a menu item. * * @param menuPath The path of the menu to set priority. * @param priority The priority to be set to. */ OMNI_KIT_UI_API void setPriority(const char* menuPath, int priority); /** * Sets the hotkey for a menu item. * * @param menuPath The path of the menu to set hotkey to. * @param mod The modifier key flags for the hotkey. * @param key The key for the hotkey. */ OMNI_KIT_UI_API void setHotkey(const char* menuPath, carb::input::KeyboardModifierFlags mod, carb::input::KeyboardInput key); /** * Sets the input action for a menu item. * * @param menuPath The path of the menu to set hotkey to. * @param actionName The action name. */ OMNI_KIT_UI_API void setActionName(const char* menuPath, const char* actionMappingSetPath, const char* actionPath); /** * Sets the toggle value for a menu item. The menu must be a "toggle" when being created. * * @param value The toggle value of the menu item. */ OMNI_KIT_UI_API void setValue(const char* menuPath, bool value); /** * Gets the toggle value for a menu item. The menu must be a "toggle" when being created. * * @return The toggle value of the menu item. */ OMNI_KIT_UI_API bool getValue(const char* menuPath) const; /** * Sets the enabled state of a menu item. * * @param menuPath The path of the menu to set enabled state to. * @param enabled true to enabled the menu. false to disable it. */ OMNI_KIT_UI_API void setEnabled(const char* menuPath, bool value); /** * For non "toggle" menu items, invoke the onClick function handler * * @param menuPath The path of the menu to activate. */ OMNI_KIT_UI_API void executeOnClick(const char* menuPath); void draw(float elapsedTime) override; private: void _update(float elapsedTime); std::unique_ptr<MenuItemImpl> m_root; std::unordered_map<std::string, MenuItemImpl*> m_pathToMenu; carb::events::ISubscriptionPtr m_updateEvtSub; bool m_needUpdate = false; carb::input::Keyboard* m_keyboard = nullptr; bool m_warning_silence = false; }; // Temporary hook up to the Editor main menu bar OMNI_KIT_UI_API std::shared_ptr<Menu> getEditorMainMenu(); // Temporary hook to enable scripting a menu item via python OMNI_KIT_UI_API void activateMenuItem(const char* menuPath); } } }
omniverse-code/kit/include/omni/kit/ui/UI.h
// Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include "BroadcastModel.h" #include "Button.h" #include "CheckBox.h" #include "CollapsingFrame.h" #include "Color.h" #include "ColumnLayout.h" #include "ComboBox.h" #include "ContentWindow.h" #include "Drag.h" #include "Field.h" #include "FilePicker.h" #include "Image.h" #include "Label.h" #include "Library.h" #include "ListBox.h" #include "Menu.h" #include "Model.h" #include "ModelMeta.h" #include "Popup.h" #include "ProgressBar.h" #include "RowColumnLayout.h" #include "RowLayout.h" #include "ScalarXYZ.h" #include "ScalarXYZW.h" #include "ScrollingFrame.h" #include "Separator.h" #include "SimpleTreeView.h" #include "Slider.h" #include "Spacer.h" #include "TextBox.h" #include "Transform.h" #include "ViewCollapsing.h" #include "Window.h"
omniverse-code/kit/include/omni/kit/ui/Widget.h
// Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include "Api.h" #include "Common.h" #include <carb/Defines.h> #include <omni/ui/Font.h> #include <omni/ui/IGlyphManager.h> #include <functional> #include <memory> #include <string> namespace omni { namespace kit { namespace ui { class Container; class Window; typedef uint64_t WidgetType; /** * Parent this class it to asscoiate your own data with a Widget. */ class WidgetUserData { public: virtual ~WidgetUserData() = default; }; /** * Defines a widget. */ class OMNI_KIT_UI_CLASS_API Widget : public std::enable_shared_from_this<Widget> { friend class Container; friend class Window; public: /** * Constructor. */ OMNI_KIT_UI_API Widget(); /** * Destructor. */ OMNI_KIT_UI_API virtual ~Widget(); /** * Determines if the widget is enabled. * * @return true if the widget is enabled, false if disabled. */ OMNI_KIT_UI_API bool isEnabled() const; /** * Set the widget to enabled. */ OMNI_KIT_UI_API void setEnabled(bool enable); /** * Gets the layout this widget is within. * * A nullptr indicates the widget is not in a layout but directly in window. * * @return The layout this widget is within. */ OMNI_KIT_UI_API Container* getLayout() const; /** * Gets the type of widget. * * @return The type of widget. */ OMNI_KIT_UI_API virtual WidgetType getType() = 0; /** * Draws the widget. * * @param elapsedTime The time elapsed (in seconds) */ OMNI_KIT_UI_API virtual void draw(float elapsedTime) = 0; /** * set the font * * @param font The font to use */ OMNI_KIT_UI_API void setFontStyle(omni::ui::FontStyle fontStyle); /** * get the font * * @return The font in use */ OMNI_KIT_UI_API omni::ui::FontStyle getFontStyle() const; /** * Get the font size (height in pixels) of the current font style with the current scaling applied. * * @return The font size. */ OMNI_KIT_UI_API float getFontSize() const; /** * Sets the callback function when the widget recieves a dragdrop payload * * @param fn The callback function when the widget recieves a dragdrop payload * @param payloadName the name of acceptable payload */ OMNI_KIT_UI_API void setDragDropFn(const std::function<void(WidgetRef, const char*)>& fn, const char* payloadName); /** * Sets the callback function when the widget is dragged. * * @param fn The callback function when the widget is dragged. */ void setDraggingFn(const std::function<void(WidgetRef, DraggingType)>& fn) { m_draggedFn = fn; } /** * A way to associate arbitrary user data with it. */ std::shared_ptr<WidgetUserData> userData; /** * Determines if the widget is visible. * * @return true if the widget is visible, false if hidden. */ OMNI_KIT_UI_API bool isVisible() const; /** * Set the widget visibility state. */ OMNI_KIT_UI_API void setVisible(bool visible); Length width = Pixel(0); Length height = Pixel(0); static constexpr size_t kUniqueIdSize = 4; protected: bool m_enabled = true; bool m_visible = true; bool m_isDragging; Container* m_layout = nullptr; char m_uniqueId[kUniqueIdSize + 1]; std::string m_label; omni::ui::FontStyle m_fontStyle; carb::imgui::Font* m_font; std::function<void(WidgetRef, const char*)> m_dragDropFn; std::function<void(WidgetRef, DraggingType)> m_draggedFn; std::string m_dragDropPayloadName; }; } } }
omniverse-code/kit/include/omni/kit/ui/ModelMeta.h
// Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include "Model.h" namespace omni { namespace kit { namespace ui { constexpr const char* const kModelMetaWidgetType = "widgetType"; constexpr const char* const kModelMetaSerializedContents = "serializedContents"; } } }
omniverse-code/kit/include/omni/kit/ui/NativeFileDialog.h
// Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include <carb/extras/Unicode.h> #include <carb/logging/Log.h> #include <string> #include <utility> #include <vector> #if CARB_PLATFORM_WINDOWS # ifndef NOMINMAX # define NOMINMAX # endif # include <ShObjIdl_core.h> #endif #ifdef _MSC_VER # pragma warning(disable : 4996) #endif namespace omni { namespace kit { namespace ui { /** * Defines an NativeFileDialog class that handles file/folder selection using OS specific implementation. */ class NativeFileDialog { public: enum class Mode { eOpen, ///! OpenFileDialog. eSave, ///! SaveFileDialog. }; enum class Type { eFile, ///! Select file. eDirectory, ///! Select directory. }; /** * Constructor. * * @param mode Open or Save dialog. * @param type Choose File or Directory. * @param title Title text. * @param multiSelction If supporting selecting more than one file/directory. */ NativeFileDialog(Mode mode, Type type, const std::string& title, bool multiSelection); /** * Add file type filter. * * @param name Name of the file type. * @param spec Specification of the file type. */ void addFilter(const std::string& name, const std::string& spec); /** * Shows the open file dialog. */ bool show(); /** * Gets the selected path(s). * * @param urls The vector to write selected path(s) to. * @return True if the result is valid. */ bool getFileUrls(std::vector<std::string>& urls) const; private: struct FileTypeFilter { std::string name; std::string spec; }; Mode m_mode; Type m_type; std::string m_title; std::vector<FileTypeFilter> m_filters; std::vector<std::string> m_fileUrls; bool m_multiSel; }; inline NativeFileDialog::NativeFileDialog(Mode mode, Type type, const std::string& title, bool multiSelection) : m_mode(mode), m_type(type), m_title(title), m_multiSel(multiSelection) { } inline void NativeFileDialog::addFilter(const std::string& name, const std::string& spec) { m_filters.emplace_back(FileTypeFilter{ name, spec }); } inline bool NativeFileDialog::show() { bool ret = false; #if CARB_PLATFORM_WINDOWS auto prepareDialogCommon = [this](::IFileDialog* fileDialog, std::vector<std::wstring>& wstrs) { // Set filters std::vector<COMDLG_FILTERSPEC> rgFilterSpec; rgFilterSpec.reserve(m_filters.size()); wstrs.reserve(m_filters.size() * 2); for (auto& filter : m_filters) { wstrs.push_back(carb::extras::convertUtf8ToWide(filter.name)); std::wstring& nameWstr = wstrs.back(); wstrs.push_back(carb::extras::convertUtf8ToWide(filter.spec)); std::wstring& specWstr = wstrs.back(); rgFilterSpec.emplace_back(COMDLG_FILTERSPEC{ nameWstr.c_str(), specWstr.c_str() }); } fileDialog->SetFileTypes(static_cast<UINT>(rgFilterSpec.size()), rgFilterSpec.data()); std::wstring title = carb::extras::convertUtf8ToWide(m_title); fileDialog->SetTitle(title.c_str()); }; switch (m_mode) { case Mode::eOpen: { IFileOpenDialog* fileDialog; auto hr = CoCreateInstance(CLSID_FileOpenDialog, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&fileDialog)); if (SUCCEEDED(hr)) { DWORD options; fileDialog->GetOptions(&options); if (m_multiSel) { options |= OFN_ALLOWMULTISELECT; } if (m_type == Type::eDirectory) { options |= FOS_PICKFOLDERS; } fileDialog->SetOptions(options); std::vector<std::wstring> wstrs; // keep a reference of the converted string around prepareDialogCommon(fileDialog, wstrs); hr = fileDialog->Show(nullptr); if (SUCCEEDED(hr)) { IShellItemArray* pItemArray; hr = fileDialog->GetResults(&pItemArray); if (SUCCEEDED(hr)) { DWORD dwNumItems = 0; pItemArray->GetCount(&dwNumItems); for (DWORD i = 0; i < dwNumItems; i++) { IShellItem* pItem = nullptr; hr = pItemArray->GetItemAt(i, &pItem); if (SUCCEEDED(hr)) { PWSTR pszFilePath; hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath); if (SUCCEEDED(hr)) { std::string path = carb::extras::convertWideToUtf8(pszFilePath); m_fileUrls.emplace_back(std::move(path)); CoTaskMemFree(pszFilePath); } pItem->Release(); } } ret = true; pItemArray->Release(); } } fileDialog->Release(); } break; } case Mode::eSave: { IFileSaveDialog* fileDialog; auto hr = CoCreateInstance(CLSID_FileSaveDialog, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&fileDialog)); if (SUCCEEDED(hr)) { std::vector<std::wstring> wstrs; // keep a reference of the converted string around prepareDialogCommon(fileDialog, wstrs); fileDialog->SetFileName(L"Untitled"); hr = fileDialog->Show(nullptr); if (SUCCEEDED(hr)) { IShellItem* pItem = nullptr; hr = fileDialog->GetResult(&pItem); if (SUCCEEDED(hr)) { PWSTR pszFilePath; hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath); if (SUCCEEDED(hr)) { std::string path = carb::extras::convertWideToUtf8(pszFilePath); UINT fileTypeIndex; hr = fileDialog->GetFileTypeIndex(&fileTypeIndex); fileTypeIndex--; // One based index. Convert it to zero based if (SUCCEEDED(hr)) { std::string& fileType = m_filters[fileTypeIndex].spec; size_t extPos = path.rfind(".stage.usd"); path = path.substr(0, extPos) + fileType.substr(1); m_fileUrls.emplace_back(std::move(path)); } CoTaskMemFree(pszFilePath); } pItem->Release(); ret = true; } } fileDialog->Release(); } break; } } #endif return ret; } inline bool NativeFileDialog::getFileUrls(std::vector<std::string>& urls) const { if (m_fileUrls.size()) { urls = m_fileUrls; return true; } return false; } } } }
omniverse-code/kit/include/omni/kit/ui/ComboBox.h
// Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include "ValueWidget.h" #include <string> #include <vector> namespace omni { namespace kit { namespace ui { /** * Defines a combo box. */ template <class T> class OMNI_KIT_UI_CLASS_API ComboBox : public SimpleValueWidget<T> { public: static const WidgetType kType = CARB_HASH_TYPE(omni::kit::ui::ComboBox<T>); OMNI_KIT_UI_API explicit ComboBox(const char* text, const std::vector<T>& items = {}, const std::vector<std::string>& displayNames = {}); OMNI_KIT_UI_API ~ComboBox() override; OMNI_KIT_UI_API size_t getItemCount() const; OMNI_KIT_UI_API const T& getItemAt(size_t index) const; OMNI_KIT_UI_API void addItem(const T& item, const std::string& displayName = ""); OMNI_KIT_UI_API void removeItem(size_t index); OMNI_KIT_UI_API void clearItems(); OMNI_KIT_UI_API void setItems(const std::vector<T>& items, const std::vector<std::string>& displayNames = {}); OMNI_KIT_UI_API int64_t getSelectedIndex() const; OMNI_KIT_UI_API void setSelectedIndex(int64_t index); OMNI_KIT_UI_API WidgetType getType() override; protected: virtual bool _isTransientChangeSupported() const override { return false; } bool _drawImGuiWidget(carb::imgui::ImGui* imgui, T& value) override; private: struct Element { T value; std::string displayName; }; std::vector<Element> m_items; int64_t m_selectedIndex = -1; }; using ComboBoxString = ComboBox<std::string>; using ComboBoxInt = ComboBox<int>; } } }
omniverse-code/kit/include/omni/kit/ui/Separator.h
// Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include "Widget.h" namespace omni { namespace kit { namespace ui { /** * Defines a separator element. */ class OMNI_KIT_UI_CLASS_API Separator : public Widget { public: static const WidgetType kType = CARB_HASH_TYPE(omni::kit::ui::Separator); OMNI_KIT_UI_API Separator(); /** * @see Widget::getType */ OMNI_KIT_UI_API WidgetType getType() override; /** * @see Widget::draw */ void draw(float elapsedTime) override; }; } } }
omniverse-code/kit/include/omni/kit/ui/FilterGroupWidget.h
// Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #include <omni/kit/FilterGroup.h> #include <omni/kit/ui/ColorScheme.h> #include <omni/ui/IGlyphManager.h> namespace omni { namespace kit { namespace ui { template <typename FilterGroupT> class FilterGroupWidget { public: explicit FilterGroupWidget(FilterGroupT& filterGroup) : m_filterGroup(filterGroup) { m_glyphManager = carb::getFramework()->acquireInterface<omni::ui::IGlyphManager>(); } void draw(carb::imgui::ImGui* imgui, float elapsedTime) { using namespace carb::imgui; const float kFontSize = imgui->getFontSize(); const carb::Float2 kItemSpacing = imgui->getStyle()->itemSpacing; bool filterEnabled = m_filterGroup.isFilterGroupEnabled(); if (filterEnabled) { imgui->pushStyleColor(StyleColor::eText, kAssetExplorerFilterIconEnabledColor); } auto filterGlyph = m_glyphManager->getGlyphInfo("${glyphs}/filter.svg"); bool filterIconClicked = imgui->selectable(filterGlyph.code, false, 0, { kFontSize, kFontSize }); if (filterEnabled) { imgui->popStyleColor(); } // (RMB / hold LMB / Click LMB & No filter is enabled) to open filter list bool showFilterList = imgui->isItemClicked(1) || (imgui->isItemClicked(0) && !m_filterGroup.isAnyFilterEnabled()); m_mouseHeldOnFilterIconTime += elapsedTime; if (!(imgui->isItemHovered(0) && imgui->isMouseDown(0))) { m_mouseHeldOnFilterIconTime = 0.f; } const float kMouseHoldTime = 0.3f; if (showFilterList || m_mouseHeldOnFilterIconTime >= kMouseHoldTime) { imgui->openPopup("FilterList"); } else { if (filterIconClicked) { m_filterGroup.setFilterGroupEnabled(!filterEnabled); } } if (imgui->beginPopup("FilterList", 0)) { imgui->text("Filter"); imgui->sameLineEx(0.f, kFontSize * 3); imgui->textColored(kAssetExplorerClearFilterColor, "Clear Filters"); bool clearFilters = imgui->isItemClicked(0); imgui->separator(); std::vector<std::string> filterNames; m_filterGroup.getFilterNames(filterNames); for (auto& name : filterNames) { if (clearFilters) { m_filterGroup.setFilterEnabled(name, false); } bool enabled = m_filterGroup.isFilterEnabled(name); imgui->pushIdString(name.c_str()); auto checkGlyph = enabled ? m_glyphManager->getGlyphInfo("${glyphs}/check_square.svg") : m_glyphManager->getGlyphInfo("${glyphs}/square.svg"); if (imgui->selectable((std::string(checkGlyph.code) + " ").c_str(), false, kSelectableFlagDontClosePopups, { 0.f, 0.f })) { m_filterGroup.setFilterEnabled(name, !enabled); } imgui->popId(); imgui->sameLine(); imgui->text(name.c_str()); } imgui->endPopup(); } // Draw the tiny triangle at corner of the filter icon { imgui->sameLine(); auto cursorPos = imgui->getCursorScreenPos(); auto drawList = imgui->getWindowDrawList(); carb::Float2 points[3]; points[0] = { cursorPos.x - kItemSpacing.x, cursorPos.y + kFontSize * 0.75f + kItemSpacing.y * 0.5f }; points[1] = { cursorPos.x - kItemSpacing.x, cursorPos.y + kFontSize + kItemSpacing.y * 0.5f }; points[2] = { cursorPos.x - kItemSpacing.x - kFontSize * 0.25f, cursorPos.y + kFontSize + kItemSpacing.y * 0.5f }; imgui->addTriangleFilled( drawList, points[0], points[1], points[2], imgui->getColorU32StyleColor(StyleColor::eText, 1.f)); imgui->newLine(); } } private: FilterGroupT& m_filterGroup; omni::ui::IGlyphManager* m_glyphManager = nullptr; float m_mouseHeldOnFilterIconTime = 0.f; }; } } }
omniverse-code/kit/include/omni/kit/ui/SimpleTreeView.h
// Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include "Widget.h" #include <functional> #include <memory> #include <string> namespace omni { namespace kit { namespace ui { /** * Defines a SimpleTreeView. */ class OMNI_KIT_UI_CLASS_API SimpleTreeView : public Widget { public: static const WidgetType kType = CARB_HASH_TYPE(omni::kit::ui::SimpleTreeView); /** * Constructor. * * @param treeData A list of strings to construct the data of the TreeView * @param separator */ OMNI_KIT_UI_API explicit SimpleTreeView(const std::vector<std::string>& treeData, char separator = '/'); /** * Destructor. */ OMNI_KIT_UI_API ~SimpleTreeView() override; /** * Gets the text of the treeNode. * * @return The text of the treeNode. */ OMNI_KIT_UI_API const std::string getSelectedItemName() const; /** * Clears the currently selected tree node */ OMNI_KIT_UI_API void clearSelection(); /** * Sets the text of the tree nodes. * * @param text The text of the tree nodes. */ OMNI_KIT_UI_API void setTreeData(const std::vector<std::string>& treeData); /** * Sets the callback function when any tree node is clicked. * * fn The callback function when any tree node is clicked. */ OMNI_KIT_UI_API void setClickedFn(const std::function<void(WidgetRef)>& fn); /** * @see Widget::getType */ OMNI_KIT_UI_API WidgetType getType() override; /** * @see Widget::draw */ void draw(float elapsedTime) override; protected: // Clicked Function callback std::function<void(WidgetRef)> m_clickedFn; protected: struct TreeDataNode; using TreeDataNodePtr = std::shared_ptr<TreeDataNode>; // An internal structure to accomodate the Hierachical tree data struct TreeDataNode : public std::enable_shared_from_this<TreeDataNode> { // The text of the current node std::string m_text; // Pointer to the parent node std::weak_ptr<TreeDataNode> m_parentNode; // List of child nodes std::vector<TreeDataNodePtr> m_children; // Single Node's constructor/destructor explicit TreeDataNode(const std::string& data); ~TreeDataNode(); // Helper functions // Add a child TreeDataNodePtr& addChild(TreeDataNodePtr& node); // Recursively delete all childrens(decendents) void deleteChildren(); // Stack up the node text to construct the full path from root to the current node const std::string getFullPath(const char& separator) const; }; // The root node of the entire tree TreeDataNodePtr m_rootNode; // Pointer to the currently selected Node, for the rendering purpose std::weak_ptr<TreeDataNode> m_selectedNode; // A customized separator, default as '/' char m_separator; protected: // Helper function to build the entire data tree, return false if build fail bool buildDataTree(const std::vector<std::string>& inputStrings); // Helper function to split the string into a list of string tokens // example, "root/parent/child" ==> ["root","parent","child"] std::vector<std::string> split(const std::string& s, char seperator); // A core function to hierachically, node as the root, visualize the tree data using into the SimpleTreeView void drawTreeNode(carb::imgui::ImGui* imgui, const std::shared_ptr<SimpleTreeView::TreeDataNode>& node); }; } } }
omniverse-code/kit/include/omni/kit/ui/ScalarXYZW.h
// Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include "Image.h" #include "ScalarXYZ.h" #include "ValueWidget.h" namespace omni { namespace kit { namespace ui { /** * Defines a ScalarXYZW widget. */ class OMNI_KIT_UI_CLASS_API ScalarXYZW : public ValueWidget<carb::Double4> { public: static const WidgetType kType = CARB_HASH_TYPE(omni::kit::ui::ScalarXYZW); /** * Constructor. * */ OMNI_KIT_UI_API ScalarXYZW( const char* displayFormat, float speed, float wrapValue, float minValue, float maxValue, carb::Double4 value = {}); /** * Destructor. */ OMNI_KIT_UI_API ~ScalarXYZW(); /** * @see Widget::getType */ OMNI_KIT_UI_API WidgetType getType() override; void draw(float elapsedTime) override; private: std::shared_ptr<ScalarXYZ> m_scalar; bool m_edited; bool m_init; }; } } }
omniverse-code/kit/include/omni/kit/ui/ListBox.h
// Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include "Label.h" #include <functional> #include <string> #include <utility> #include <vector> namespace omni { namespace kit { namespace ui { /** * Defines a list box. */ class OMNI_KIT_UI_CLASS_API ListBox : public Label { public: static const WidgetType kType = CARB_HASH_TYPE(omni::kit::ui::ListBox); OMNI_KIT_UI_API explicit ListBox(const char* text, bool multiSelect = true, int visibleItemCount = -1, const std::vector<std::string>& items = {}); OMNI_KIT_UI_API ~ListBox() override; OMNI_KIT_UI_API bool isMultiSelect() const; OMNI_KIT_UI_API void setMultiSelect(bool multiSelect); OMNI_KIT_UI_API int getItemHeightCount() const; OMNI_KIT_UI_API void setItemHeightCount(int itemHeightCount); OMNI_KIT_UI_API size_t getItemCount() const; OMNI_KIT_UI_API const char* getItemAt(size_t index) const; OMNI_KIT_UI_API void addItem(const char* item); OMNI_KIT_UI_API void removeItem(size_t index); OMNI_KIT_UI_API void clearItems(); OMNI_KIT_UI_API std::vector<int> getSelected() const; OMNI_KIT_UI_API void setSelected(int index, bool selected); OMNI_KIT_UI_API void clearSelection(); OMNI_KIT_UI_API void setSelectionChangedFn(const std::function<void(WidgetRef)>& fn); OMNI_KIT_UI_API WidgetType getType() override; void draw(float elapsedTime) override; private: int m_itemHeightCount = -1; bool m_multiSelect = false; int m_selectedIndex = -1; std::vector<std::pair<std::string, bool>> m_items; std::function<void(WidgetRef)> m_selectionChangedFn; }; } } }
omniverse-code/kit/include/omni/kit/ui/ScalarXYZ.h
// Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include "Image.h" #include "ValueWidget.h" namespace omni { namespace kit { namespace ui { /** * Defines a ScalarXYZ widget. */ class OMNI_KIT_UI_CLASS_API ScalarXYZ : public ValueWidget<carb::Double3> { public: static const WidgetType kType = CARB_HASH_TYPE(omni::kit::ui::ScalarXYZ); OMNI_KIT_UI_API ScalarXYZ(const char* displayFormat, float speed, double wrapValue, double minValue, double maxValue, double deadZone = 0.0, carb::Double3 value = {}); OMNI_KIT_UI_API ~ScalarXYZ(); /** * @see Widget::getType */ OMNI_KIT_UI_API WidgetType getType() override; /** * Draws the scalar, used for drawing when allocated by other classes * * @param v x,y,z to draw * @return true if dirty */ OMNI_KIT_UI_API bool drawScalar(carb::Double3& v, bool& afterEdit, bool hasX = true, bool hasY = true, bool hasZ = true); OMNI_KIT_UI_API double wrapScalar(double value) const; OMNI_KIT_UI_API double deadzoneScalar(double value) const; std::string displayFormat; float dragSpeed; double wrapValue; double deadZone; double minVal; double maxVal; void draw(float elapsedTime) override; void setSkipYposUpdate(bool skip) { m_skipYposUpdate = skip; } private: enum class Images { eX, eY, eZ, eCount }; std::shared_ptr<Image> m_images[static_cast<size_t>(Images::eCount)]; std::string m_labelY; std::string m_labelZ; bool m_skipYposUpdate = false; const char* m_filenames[static_cast<size_t>(Images::eCount)] = { "/resources/icons/transform_x.png", "/resources/icons/transform_y.png", "/resources/icons/transform_z.png" }; }; } } }
omniverse-code/kit/include/omni/kit/usd/layers/LayerTypes.h
// Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include <carb/Interface.h> #include <carb/dictionary/IDictionary.h> #include <carb/events/IEvents.h> namespace omni { namespace kit { namespace usd { namespace layers { /** * Regards of edit mode, it's extended by Kit to support customized workflow. * USD supports to switch edit target so that all authoring will take place in * that layer. When it's working with multiple sublayers, this kind of freedom * may cause experience issues. User has to be aware the changes he/she made are * not overrided in any stronger layer. We extend a new mode called "auto authoring" * is to improve this. In this mode, all changes will firstly go into a middle delegate * layer and it will distribute them into their corresponding layers where it has the strongest * opinions. So it cannot switch edit target freely, and user does not need to be * aware of existence of multi-sublayers and how USD will compose the changes. * Besides, there is one more extended mode called "spec linking", which is based on * auto authoring. In this mode, user can customize the target layer of specific specs. */ enum class LayerEditMode { eNormal, // Normal USD mode that user can freely switch edit target and creates deltas. eAutoAuthoring, // Auto authoring mode that user cannot switch authoring layer freely. And all // deltas will be merged to its original layer where the prim specs have strongest opinions. // @see IWorkflowAutoAuthoring for interfaces about auto authoring. eSpecsLinking, // Spec linking mode will support to link specified spec changes into specific layers, // including forwarding changes of whole prim, or specific group of attributes. }; enum class LayerEventType { eInfoChanged, // Layer info changed, which includes: // PXR_NS::UsdGeomTokens->upAxis PXR_NS::UsdGeomTokens->metersPerUnit // PXR_NS::SdfFieldKeys->StartTimeCode PXR_NS::SdfFieldKeys->EndTimeCode // PXR_NS::SdfFieldKeys->FramesPerSecond PXR_NS::SdfFieldKeys->TimeCodesPerSecond // PXR_NS::SdfFieldKeys->SubLayerOffsets PXR_NS::SdfFieldKeys->Comment // PXR_NS::SdfFieldKeys->Documentation eMutenessScopeChanged, // For vallina USD, muteness is only local and not persistent. Omniverse extends // it so it could be persistent and sharable with other users. The muteness scope // is a concept about this that supports to switch between local and global scope. // In local scope, muteness will not be persistent In contract, global scope will // save muteness across sessions. This event is to notify change of muteness scope. eMutenessStateChanged, // Change of muteness state. eLockStateChanged, // Change of lock state. Lock is a customized concept in Omniverse that supports to // lock a layer it's not editable and savable. eDirtyStateChanged, // Change of dirtiness state. eOutdateStateChanged, // Change of outdate state. This is only emitted for layer in Nucleus when layer content // is out of sync with server one. ePrimSpecsChanged, // Change of layer. It will be emitted along with changed paths of prim specs. eSublayersChanged, // Change of sublayers. eSpecsLockingChanged, // Change of lock states of specs. It will be emitted along with the changed paths. eSpecsLinkingChanged, // Change of linking states of specs. It will be emitted along with the changed paths. eEditTargetChanged, // Change of edit target. eEditModeChanged, // Change of edit mode. @see LayerEditMode for details. eDefaultLayerChanged, // Change default layer. Default layer is an extended concept that's only available in auto // authornig mode. It's to host all new created prims from auto authoring layer. eLiveSessionStateChanged, // Live session started or stopped eLiveSessionListChanged, // List of live sessions refreshed, which may because of a session is created or removed. eLiveSessionUserJoined, // User joined. eLiveSessionUserLeft, // User left. eLiveSessionMergeStarted, // Starting to merge live session. eLiveSessionMergeEnded, // Finished to merge live session. eUsedLayersChanged, // Used layers changed in stage. Used layers includes all sublayers, references, payloads or any external layers loaded into stage. // If eSublayersChanged is sent, this event will be sent also. eLiveSessionJoining, // The event will be sent before Live Session is joined. eLayerFilePermissionChanged, // The event will be sent when file write/read permission is changed. }; enum class LayerErrorType { eSuccess, eReadOnly, // Destination folder or file is read-only eNotFound, // File/folder/live session is not found, or layer is not in the local layer stack. eAlreadyExists, // File/folder/layer/live session already existes. eInvalidStage, // No stage is attached to the UsdContext. eInvalidParam, // Invalid param passed to API. eLiveSessionInvalid, // The live session does not match the base layer. Or The live session exists, // but it is broken on disk, for example, toml file is corrupted. eLiveSessionVersionMismatch, eLiveSessionBaseLayerMismatch, // The base layer of thie live session does not match the specified one. // It's normally because user wants to join session of layer B for layer A. eLiveSessionAlreadyJoined, eLiveSessionNoMergePermission, eLiveSessionNotSupported, // Live session is not supported for the layer if layer is not in Nucleus or already has .live as extension. // Or it's reported for joining a live session for a reference or payload prim if prim is invalid, or it has // no references or payloads. eLiveSessionNotJoined, eUnkonwn }; class ILayersInstance : public carb::IObject { public: virtual carb::events::IEventStream* getEventStream() const = 0; virtual LayerEditMode getEditMode() const = 0; virtual void setEditMode(LayerEditMode editMode) = 0; virtual LayerErrorType getLastErrorType() const = 0; virtual const char* getLastErrorString() const = 0; }; } } } }
omniverse-code/kit/include/omni/kit/usd/layers/IWorkflowSpecsLocking.h
// Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include "LayerTypes.h" #include <carb/Interface.h> #include <carb/dictionary/IDictionary.h> namespace omni { namespace kit { namespace usd { namespace layers { struct IWorkflowSpecsLocking { CARB_PLUGIN_INTERFACE("omni::kit::usd::layers::IWorkflowSpecsLocking", 1, 0) carb::dictionary::Item*(CARB_ABI* lockSpec)(ILayersInstance* layersIntance, const char* specPath, bool hierarchy); carb::dictionary::Item*(CARB_ABI* unlockSpec)(ILayersInstance* layersIntance, const char* specPath, bool hierarchy); void(CARB_ABI* unlockAllSpecs)(ILayersInstance* layersIntance); bool(CARB_ABI* isSpecLocked)(ILayersInstance* layersInstance, const char* specPath); carb::dictionary::Item*(CARB_ABI* getAllLockedSpecs)(ILayersInstance* layersIntance); }; } } } }
omniverse-code/kit/include/omni/kit/usd/layers/IWorkflowAutoAuthoring.h
// Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include "LayerTypes.h" #include <carb/Interface.h> #include <carb/dictionary/IDictionary.h> namespace omni { namespace kit { namespace usd { namespace layers { struct IWorkflowAutoAuthoring { CARB_PLUGIN_INTERFACE("omni::kit::usd::layers::IWorkflowAutoAuthoring", 1, 0) bool(CARB_ABI* isEnabled)(ILayersInstance* layersIntance); void(CARB_ABI* suspend)(ILayersInstance* layersIntance); void(CARB_ABI* resume)(ILayersInstance* layersIntance); void(CARB_ABI* setDefaultLayer)(ILayersInstance* layersIntance, const char* layerIdentifier); const char*(CARB_ABI* getDefaultLayer)(ILayersInstance* layersIntance); bool(CARB_ABI* isAutoAuthoringLayer)(ILayersInstance* layersIntance, const char* layerIdentifier); }; } } } }
omniverse-code/kit/include/omni/kit/usd/layers/LayersHelper.hpp
// Copyright (c) 2019-2021, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once // clang-format off #include "UsdPCH.h" // clang-format on #include <omni/kit/usd/layers/ILayers.h> #include <omni/usd/UsdContext.h> #if defined(__GNUC__) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wunused-function" #endif namespace omni { namespace kit { namespace usd { namespace layers { namespace internal { static carb::dictionary::IDictionary* getDictInterface() { static auto staticInterface = carb::getCachedInterface<carb::dictionary::IDictionary>(); return staticInterface; } } static ILayers* getLayersInterface() { static auto staticInterface = carb::getCachedInterface<omni::kit::usd::layers::ILayers>(); return staticInterface; } static ILayersState* getLayersStateInterface() { static auto staticInterface = carb::getCachedInterface<omni::kit::usd::layers::ILayersState>(); return staticInterface; } static IWorkflowAutoAuthoring* getAutoAuthoringInterface() { static auto staticInterface = carb::getCachedInterface<omni::kit::usd::layers::IWorkflowAutoAuthoring>(); return staticInterface; } static IWorkflowLiveSyncing* getLiveSyncingInterface() { static auto staticInterface = carb::getCachedInterface<omni::kit::usd::layers::IWorkflowLiveSyncing>(); return staticInterface; } static IWorkflowSpecsLocking* getSpecsLockingInterface() { static auto staticInterface = carb::getCachedInterface<omni::kit::usd::layers::IWorkflowSpecsLocking>(); return staticInterface; } static ILayersInstance* getLayersInstanceByName(const std::string& name) { auto layers = getLayersInterface(); return layers->getLayersInstanceByName(name.c_str()); } static ILayersInstance* getLayersInstanceByUsdContext(omni::usd::UsdContext* usdContext) { auto layers = getLayersInterface(); return layers->getLayersInstanceByContext(usdContext); } static carb::events::IEventStream* getEventStream(omni::usd::UsdContext* usdContext) { auto layerInstance = getLayersInstanceByUsdContext(usdContext); return layerInstance->getEventStream(); } static LayerEditMode getEditMode(omni::usd::UsdContext* usdContext) { auto layerInstance = getLayersInstanceByUsdContext(usdContext); return layerInstance->getEditMode(); } static void setEditMode(omni::usd::UsdContext* usdContext, LayerEditMode editMode) { auto layerInstance = getLayersInstanceByUsdContext(usdContext); layerInstance->setEditMode(editMode); } static std::vector<std::string> getLocalLayerIdentifiers( omni::usd::UsdContext* usdContext, bool includeSessionLayer = true, bool includeAnonymous = true, bool includeInvalid = true) { std::vector<std::string> layerIdentifiers; auto layerInstance = getLayersInstanceByUsdContext(usdContext); auto layersState = getLayersStateInterface(); auto item = layersState->getLocalLayerIdentifiers(layerInstance, includeSessionLayer, includeAnonymous, includeInvalid); if (item) { auto dict = internal::getDictInterface(); size_t length = dict->getArrayLength(item); for (size_t i = 0; i < length; i++) { layerIdentifiers.push_back(dict->getStringBufferAt(item, i)); } dict->destroyItem(item); } return layerIdentifiers; } static std::vector<std::string> getDirtyLayerIdentifiers(omni::usd::UsdContext* usdContext) { std::vector<std::string> layerIdentifiers; auto layerInstance = getLayersInstanceByUsdContext(usdContext); auto layersState = getLayersStateInterface(); auto item = layersState->getDirtyLayerIdentifiers(layerInstance); if (item) { auto dict = internal::getDictInterface(); size_t length = dict->getArrayLength(item); for (size_t i = 0; i < length; i++) { layerIdentifiers.push_back(dict->getStringBufferAt(item, i)); } dict->destroyItem(item); } return layerIdentifiers; } static std::string getLayerName(omni::usd::UsdContext* usdContext, const std::string& layerIdentifier) { std::vector<std::string> layerIdentifiers; auto layerInstance = getLayersInstanceByUsdContext(usdContext); auto layersState = getLayersStateInterface(); const std::string& name = layersState->getLayerName(layerInstance, layerIdentifier.c_str()); if (name.empty()) { if (PXR_NS::SdfLayer::IsAnonymousLayerIdentifier(layerIdentifier)) { return layerIdentifier; } else { return PXR_NS::SdfLayer::GetDisplayNameFromIdentifier(layerIdentifier); } } else { return name; } } static void suspendAutoAuthoring(omni::usd::UsdContext* usdContext) { auto autoAuthoring = getAutoAuthoringInterface(); auto layerInstance = getLayersInstanceByUsdContext(usdContext); autoAuthoring->suspend(layerInstance); } static void resumeAutoAuthoring(omni::usd::UsdContext* usdContext) { auto autoAuthoring = getAutoAuthoringInterface(); auto layerInstance = getLayersInstanceByUsdContext(usdContext); autoAuthoring->resume(layerInstance); } static std::string getDefaultLayerIdentifier(omni::usd::UsdContext* usdContext) { auto autoAuthoring = getAutoAuthoringInterface(); auto layerInstance = getLayersInstanceByUsdContext(usdContext); return autoAuthoring->getDefaultLayer(layerInstance); } } } } } #if defined(__GNUC__) # pragma GCC diagnostic pop #endif
omniverse-code/kit/include/omni/kit/usd/layers/ILayersState.h
// Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include "LayerTypes.h" #include <carb/Interface.h> #include <carb/dictionary/IDictionary.h> namespace omni { namespace kit { namespace usd { namespace layers { /** * ILayersState works for managing all layers states of the corresponding stage. Not all layer states can be queried through ILayersState, * but only those ones that are not easily accessed from USD APIs or extended in Omniverse. All the following interfaces work for the used * layers in the bound UsdContext. */ struct ILayersState { CARB_PLUGIN_INTERFACE("omni::kit::usd::layers::ILayersState", 1, 1) // Gets all sublayers rooted from root layer, or session layer if includeSessionLayer is true. It's sorted from // strongest to weakest. If includeAnonymous is false, it will exclude anonymous ones. If includeInvalid is true, it // will include invalid sublayers. Invalid sublayers are those ones that in the layers list but its layer handle // cannot be found. carb::dictionary::Item*(CARB_ABI* getLocalLayerIdentifiers)(ILayersInstance* layerInstance, bool includeSessionLayer, bool includeAnonymous, bool includeInvalid); // Gets all dirty used layers excluding anonymous ones. carb::dictionary::Item*(CARB_ABI* getDirtyLayerIdentifiers)(ILayersInstance* layerInstance); /** * Muteness scope is a concept extended by Omniverse. It includes two modes: global and local. When it's in global mode, * muteness will be serialized and will broadcasted during live session, while local mode means they are transient and will * not be broadcasted during live session. */ void(CARB_ABI* setMutenessScope)(ILayersInstance* layersInstance, bool global); bool(CARB_ABI* isMutenessGlobal)(ILayersInstance* layersInstance); bool(CARB_ABI* isLayerGloballyMuted)(ILayersInstance* layersInstance, const char* layerIdentifier); bool(CARB_ABI* isLayerLocallyMuted)(ILayersInstance* layersInstance, const char* layerIdentifier); // If layer is writable means it can be set as edit target, it should satisfy: // 1. It's not read-only on disk. // 2. It's not muted. // 3. It's not locked by setLayerLockState. // You can still set it as edit target forcely if it's not writable, while this is useful for guardrails. bool(CARB_ABI* isLayerWritable)(ILayersInstance* layersInstance, const char* layerIdentifier); // If layer is savable means it can be saved to disk, it should satisfy: // 1. It's writable checked by isLayerWritable. // 2. It's not anonymous. // You can still save the layer forcely even it's locally locked or muted, while this is useful for guardrails. bool(CARB_ABI* isLayerSavable)(ILayersInstance* layersInstance, const char* layerIdentifier); /** * Layer is a lock extended in Omniverse. It's not real ACL control to lock the layer for accessing, but a bool * flag that's checked by all applications to access it for UX purpose so it cannot be set as edit target. * Currently, only sublayers in the local layer stack can be locked. */ void(CARB_ABI* setLayerLockState)(ILayersInstance* layersInstance, const char* layerIdentifier, bool locked); bool(CARB_ABI* isLayerLocked)(ILayersInstance* layersInstance, const char* layerIdentifier); void(CARB_ABI* setLayerName)(ILayersInstance* layersInstance, const char* layerIdentifier, const char* name); const char*(CARB_ABI* getLayerName)(ILayersInstance* layersInstance, const char* layerIdentifier); /** * If layer is outdated, it means it has updates on-disk. Currently, only layers in Nucleus can be watched * for updates. */ bool(CARB_ABI* isLayerOutdated)(ILayersInstance* layersInstance, const char* layerIdentifier); // If layer is read-only on disk, this is used to check file permission only. // It's only useful when layer is not anonymous. bool(CARB_ABI* isLayerReadOnlyOnDisk)(ILayersInstance* layersInstance, const char* layerIdentifier); // Gets all outdated layers. carb::dictionary::Item*(CARB_ABI* getAllOutdatedLayerIdentifiers)(ILayersInstance* layerInstance); // Gets all outdated sublayers in the stage's local layer stack. carb::dictionary::Item*(CARB_ABI* getOutdatedSublayerIdentifiers)(ILayersInstance* layerInstance); // Gets all outdated layers except those ones in the sublayers list, like those reference or payload layers. // If a layer is both inserted as sublayer, or reference, it will be treated as sublayer only. carb::dictionary::Item*(CARB_ABI* getOutdatedNonSublayerIdentifiers)(ILayersInstance* layerInstance); // Reload all outdated layers. void(CARB_ABI* reloadAllOutdatedLayers)(ILayersInstance* layerInstance); // Reload all outdated sublayers. void(CARB_ABI* reloadOutdatedSublayers)(ILayersInstance* layerInstance); // Reload all outdated layers except sublayers. If a layer is both inserted as sublayer, or reference, it will // be treated as sublayer only. void(CARB_ABI* reloadOutdatedNonSublayers)(ILayersInstance* layerInstance); // Gets the file owner. It's empty if file system does not support it. const char* (CARB_ABI* getLayerOwner)(ILayersInstance* layersInstance, const char* layerIdentifier); }; } } } }
omniverse-code/kit/include/omni/kit/usd/layers/IWorkflowSpecsLinking.h
// Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include "LayerTypes.h" #include <carb/Interface.h> #include <carb/dictionary/IDictionary.h> namespace omni { namespace kit { namespace usd { namespace layers { struct IWorkflowSpecsLinking { CARB_PLUGIN_INTERFACE("omni::kit::usd::layers::IWorkflowSpecsLinking", 1, 0) bool(CARB_ABI* isEnabled)(ILayersInstance* layersIntance); void(CARB_ABI* suspend)(ILayersInstance* layersIntance); void(CARB_ABI* resume)(ILayersInstance* layersIntance); /** * Links spec to specific layer. * * @param specPath The spec path to be linked to layer, which can be prim or property path. If it's prim path, * all of its properties will be linked also. * @param layerIdentifier The layer that the spec is linked to. * @param hierarchy If it's true, all descendants of this spec will be linked to the specified layer also. * * @return Array of specs that are successfully linked. */ carb::dictionary::Item*(CARB_ABI* linkSpec)(ILayersInstance* layersIntance, const char* specPath, const char* layerIdentifier, bool hierarchy); /** * Unlinks spec from layer. * * @param specPath The spec path to be unlinked. * @param layerIdentifier The layer that the spec is unlinked from. * @param hierarchy If it's true, it means all of its descendants will be unlinked also. False otherwise. * @return Array of specs that are successfully unlinked. */ carb::dictionary::Item*(CARB_ABI* unlinkSpec)(ILayersInstance* layersIntance, const char* specPath, const char* layerIdentifier, bool hierarchy); /** * Unlinks spec from all linked layers. * * @param specPath The spec path to be unlinked. * @param hierarchy If it's true, it means all of its descendants will be unlinked also. False otherwise. * * @return Array of specs that are successfully unlinked. */ carb::dictionary::Item*(CARB_ABI* unlinkSpecFromAllLayers)(ILayersInstance* layersIntance, const char* specPath, bool hierarchy); /** * Unlinks specs that are linked to specific layer. * * @param layerIdentifier The layer identifier to unlink all specs from. * * @return array of specs that are successfully unlinked. */ carb::dictionary::Item*(CARB_ABI* unlinkSpecsToLayer)(ILayersInstance* layersIntance, const char* layerIdentifier); /** * Clears all spec links. */ void(CARB_ABI* unlinkAllSpecs)(ILayersInstance* layersIntance); /** * Gets all layer identifiers that specs are linked to. * * @param hierarchy If it's true, it means all of its descendants will be unlinked also. False otherwise. * @return Map of specs that are linked, of which key is the spec path, and value is list of layers that spec is * linked to. */ carb::dictionary::Item*(CARB_ABI* getSpecLayerLinks)(ILayersInstance* layersIntance, const char* specPath, bool hierarchy); /** * Gets all spec paths that link to this layer. */ carb::dictionary::Item*(CARB_ABI* getSpecLinksForLayer)(ILayersInstance* layersIntance, const char* layerIdentifier); /** * Gets all spec links. * * @return Map of spec links, of which key is the spec path, and value is layers that spec is linked to. */ carb::dictionary::Item*(CARB_ABI* getAllSpecLinks)(ILayersInstance* layersIntance); /** * Checkes if spec is linked or not. * * @param specPath The spec path. * @param layerIdentifier Layer identifier. If it's empty or null, it will return true if it's linked to any layers. * If it's not null and not empty, it will return true only when spec is linked to the specific layer. */ bool(CARB_ABI* isSpecLinked)(ILayersInstance* layersIntance, const char* specPath, const char* layerIdentifier); }; } } } }
omniverse-code/kit/include/omni/kit/usd/layers/ILayers.h
// Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include "ILayersState.h" #include "IWorkflowAutoAuthoring.h" #include "IWorkflowLiveSyncing.h" #include "IWorkflowSpecsLinking.h" #include "IWorkflowSpecsLocking.h" namespace omni { namespace kit { namespace usd { namespace layers { struct ILayers { CARB_PLUGIN_INTERFACE("omni::kit::usd::layers::ILayers", 1, 0) ILayersInstance*(CARB_ABI* getLayersInstanceByName)(const char* usdContextName); ILayersInstance*(CARB_ABI* getLayersInstanceByContext)(void* usdContext); }; } } } }
omniverse-code/kit/include/omni/kit/usd/layers/IWorkflowLiveSyncing.h
// Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include "LayerTypes.h" #include <carb/Interface.h> #include <carb/dictionary/IDictionary.h> #define LIVE_SYNCING_MAJOR_VER 1 #define LIVE_SYNCING_MINOR_VER 0 namespace omni { namespace kit { namespace usd { namespace layers { typedef void(*OnStageResultFn)(bool result, const char* err, void* userData); /** * A Live Session is a concept that extends live workflow for USD layers. * Users who join the same Live Session can see live updates with each other. * A Live Session is physically defined as follows: * 1. It has an unique URL to identify the location. * 2. It has a toml file to include the session configuration. * 3. It includes a Live Session layer that has extension .live for users to cooperate together. * 4. It includes a channel for users to send instant messages. * 5. It's bound to a base layer. A base layer is a USD file that your Live Session will be based on. */ class LiveSession; /** * LiveSyncing interfaces work to create/stop/manage Live Sessions. It supports to join a Live Session * for sublayer, or prim with references or payloads. If a layer is in the local sublayer list, and it's * added as reference or payload also. The Live Session can only be joined for the sublayer or reference/payload, * but cannot be joined for both. For layer that is added to multiple prims as reference/payload, it supports to * join the same Live Session for multiple prims that references the same layer. */ struct IWorkflowLiveSyncing { CARB_PLUGIN_INTERFACE("omni::kit::usd::layers::IWorkflowLiveSyncing", 2, 2) /** * Gets the count of Live Sessions for a specific layer. The layer must be in the layer stack of current UsdContext * that layerInstance is bound to. It's possible that getTotalLiveSessions will return 0 even there are Live Sessions * on the server as Live Sessions' finding is asynchronous, and this function only returns the count that's discovered * currently. * * @param layerIdentifier The base layer of Live Sessions. */ size_t(CARB_ABI* getTotalLiveSessions)(ILayersInstance* layerInstance, const char* layerIdentifier); /** * Gets the Live Session at index. The index must be less than the total Live Sessions got from getTotalLiveSessions. * Also, the index is not promised to be valid always as it's possible the Live Session is removed. * @param layerIdentifier The base layer of Live Sessions. * @param index The index to access. REMINDER: The same index may be changed to different Live Session as * it does not promise the list of Live Sessions will not be changed or re-ordered. */ LiveSession*(CARB_ABI* getLiveSessionAtIndex)(ILayersInstance* layerInstance, const char* layerIdentifier, size_t index); /** * The name of this Live Session. It's possible that session is invalid and it will return empty. * * @param session The Live Session instance. */ const char*(CARB_ABI* getLiveSessionName)(ILayersInstance* layerInstance, LiveSession* session); /** * The unique URL of this Live Session. It's possible that session is invalid and it will return empty. */ const char*(CARB_ABI* getLiveSessionUrl)(ILayersInstance* layerInstance, LiveSession* session); /** * The owner name of this session. The owner of the session is the one that has the permission to merge session changes back to * base layers. It's possible that session is invalid and it will return empty. REMEMBER: You should not use this * function to check if the local instance is the session owner as it's possible multiple instances with the same user join * in the Live Session. But only one of them is the real session owner. This funciton is only to check the static ownership * that tells you whom the session belongs to. In order to tell the runtime ownership, you should see permissionToMergeSessionChanges. * * @param session The Live Session instance. */ const char*(CARB_ABI* getLiveSessionOwner)(ILayersInstance* layersInstance, LiveSession* session); /** * The communication channel of this session. Channel is a concept in Nucleus to pub/sub transient messages * so all clients connected to it can communicate with each other. It's possible that session is invalid and it will return empty. * * @param session The Live Session instance. */ const char*(CARB_ABI* getLiveSessionChannelUrl)(ILayersInstance* layerInstance, LiveSession* session); /** * A session consists a root layer that's suffixed with .live extension. All live edits are done inside that * .live layer during a Live Session. It's possible that session is invalid and it will return empty. * * @param session The Live Session instance. */ const char*(CARB_ABI* getLiveSessionRootIdentifier)(ILayersInstance* layerInstance, LiveSession* session); /** * The base layer identifier for this Live Session. It's possible that session is invalid and it will return empty. * * @param session The Live Session instance. */ const char*(CARB_ABI* getLiveSessionBaseLayerIdentifier)(ILayersInstance* layerInstance, LiveSession* session); /** * Whether the local user has the permission to merge the Live Session or not. It's possible that the local user is * the owner of the Live Session but it returns false as if there are multiple instances with the same user join * the same session, only one of them has the merge permission to satisfy the requirement of unique ownership. * If the session is not joined, it will return the static ownership based on the owner name. * * @param session The Live Session instance. */ bool(CARB_ABI* permissionToMergeSessionChanges)(ILayersInstance* layersInstance, LiveSession* session); /** * If the session is valid. A valid session means it's not removed from disk. It's possible that this session * is removed during runtime. This function can be used to check if it's still valid before accessing it. * * @param session The Live Session instance. */ bool(CARB_ABI* isValidLiveSession)(ILayersInstance* layersInstance, LiveSession* session); /** * Creates a Live Session for specific sublayer. * * @param layerIdentifier The base layer. * @param sessionName The name of the Live Session. Name can only be alphanumerical characters with hyphens and underscores, * and should be prefixed with letter. * @see ILayersInstance::get_last_error_type() for more error details if it returns nullptr. */ LiveSession*(CARB_ABI* createLiveSession)(ILayersInstance* layersInstance, const char* layerIdentifier, const char* sessionName); /** * Joins the Live Session. The base layer of the Live Session must be in the local layer stack of current stage. * * @param session The Live Session instance. * @see ILayersInstance::get_last_error_type() for more error details if it returns false. */ bool(CARB_ABI* joinLiveSession)(ILayersInstance* layersInstance, LiveSession* session); /** * Joins Live Session by url for specified sublayer. The url must point to a valid Live Session for this layer or it can be created if it does not exist. * * @param layerIdentifier The base layer identifier of a sublayer. * @param liveSessionUrl The Live Session URL to join. * @param createIfNotExisted If it's true, it will create the Live Session under the URL specified if no Live Session is found. * @see ILayersInstance::get_last_error_type() for more error details if it returns false. */ bool(CARB_ABI* joinLiveSessionByURL)(ILayersInstance* layersInstance, const char* layerIdentifier, const char* liveSessionUrl, bool createIfNotExisted); /** * Stops the Live Session of base layer if it's in Live Session already. If this layer is added as reference/payload to multiple prims, and some of * them are in the Live Session of this layer, it will stop the Live Session for all the prims that reference this layer and in the Live Session. * @see stopLiveSessionForPrim to stop Live Session for specific prim. * * @param layerIdentifier The base layer. */ void(CARB_ABI* stopLiveSession)(ILayersInstance* layersInstance, const char* layerIdentifier); /** * Stops all Live Sessions in this stage for all layers. */ void(CARB_ABI* stopAllLiveSessions)(ILayersInstance* layersInstance); /** * If the current stage has any active Live Sessions for all used layers. */ bool(CARB_ABI* isStageInLiveSession)(ILayersInstance* layersInstance); /** * If a base layer is in any Live Sessions. It includes both Live Sessions for sublayer or reference/payload prims. * @see isLayerInPrimLiveSession to check if a layer is in any Live Sessions that are bound to reference/payload prims. * * @param layerIdentifier The base layer. */ bool(CARB_ABI* isLayerInLiveSession)(ILayersInstance* layersInstance, const char* layerIdentifier); /** * Gets the current Live Session of the base layer. A layer can only have one Live Session enabled at a time. * * @param layerIdentifier The base layer. */ LiveSession*(CARB_ABI* getCurrentLiveSession)(ILayersInstance* layersInstance, const char* layerIdentifier); /** * Checkes if this layer is a Live Session layer. A Live Session layer must be managed by a session, and with extension .live. * * @param layerIdentifier The base layer. */ bool(CARB_ABI* isLiveSessionLayer)(ILayersInstance* layersInstance, const char* layerIdentifier); /** * Merge changes of the Live Session to base layer specified by layerIdentifier. If layer is not in the Live Session currently, * it will return false directly. Live Session for prim is not supported to be merged. * * @param layerIdentifier The base layer to merge. * @param stopSession If it needs to stop the Live Session after merging. * @see ILayersInstance::get_last_error_type() for more error details if it returns false. */ bool(CARB_ABI* mergeLiveSessionChanges)(ILayersInstance* layersInstance, const char* layerIdentifier, bool stopSession); /** * Merge changes of the Live Session to target layer specified by targetLayerIdentifier. If base layer is not in the Live Session currently, * it will return false directly. Live Session for prim is not supported to be merged. * * @param layersInstance Layer instance. * @param layerIdentifier The base layer of the Live Session. * @param targetLayerIdentifier Target layer identifier. * @param stopSession If it's to stop Live Session after merge. * @param clearTargetLayer If it's to clear target layer before merge. * @see ILayersInstance::get_last_error_type() for more error details if it returns false. */ bool(CARB_ABI* mergeLiveSessionChangesToSpecificLayer)(ILayersInstance* layersInstance, const char* layerIdentifier, const char* targetLayerIdentifier, bool stopSession, bool clearTargetLayer); /** * Given the layer identifier of a .live layer, it's to find its corresponding session. * * @param liveLayerIdentifier The live layer of the Live Session. */ LiveSession*(CARB_ABI* getLiveSessionForLiveLayer)(ILayersInstance* layersInstance, const char* liveLayerIdentifier); /** * Gets the Live Session by url. It can only find the Live Session that belongs to one of the sublayer in the current stage. * * @param liveSessionURL The URL of the Live Session. */ LiveSession*(CARB_ABI* getLiveSessionByURL)(ILayersInstance* layersInstance, const char* liveSessionURL); /** * Gets the logged-in user name for this layer. The layer must be in the used layers of current opened stage, from Nucleus, * and not a live layer. As client library supports multiple Nucleus servers, the logged-in user for each layer may be different. * * @param layerIdentifier The base layer. */ const char*(CARB_ABI* getLoggedInUserNameForLayer)(ILayersInstance* layersInstance, const char* layerIdentifier); /** * Gets the logged-in user id for this layer. The layer must be in the used layers of current opened stage, from Nucleus, * and not a live layer. As client library supports multiple Nucleus servers, the logged-in user for each layer may be different. * * @param layerIdentifier The base layer. */ const char*(CARB_ABI* getLoggedInUserIdForLayer)(ILayersInstance* layersInstance, const char* layerIdentifier); /** * Opens stage with specified Live Session asynchronously. * * @param stageUrl The stageUrl to open. * @param sessionName The session to open. * @param stageResultFn Callback of stage open. This function will call omni::usd::UsdContext::openStage * * @return false if no session name is provided or other open issues. */ bool(CARB_ABI* openStageWithLiveSession)( ILayersInstance* layersInstance, const char* stageUrl, const char* sessionName, OnStageResultFn stageResultFn, void* userData); /** * Joins the Live Session for prim. The prim must include references or payloads. If it includes multiple references or payloads, an index * is provided to decide which reference or payload layer to join the Live Session. * @param layersInstance Layer instance. * @param session The Live Session to join. It must be the Live Session of the references or payloads of the specified prim. * @param primPath The prim to join the Live Session. * @see ILayersInstance::get_last_error_type() for more error details if it returns false. */ bool(CARB_ABI* joinLiveSessionForPrim)(ILayersInstance* layersInstance, LiveSession* session, const char* primPath); /** * Finds the Live Session by name. It will return the first one that matches the name. * @param layerIdentifier The base layer to find the Live Session. * @param sessionName The name to search. */ LiveSession*(CARB_ABI* findLiveSessionByName)(ILayersInstance* layersInstance, const char* layerIdentifier, const char* sessionName); /** * Whether the prim is in any Live Sessions or not. * * @param primPath The prim path to check. * @param layerIdentifier The optional layer identifier to check. If it's not specified, it will return true if it's in any Live Sessions. * Otherwise, it will only return true if the prim is in the Live Session specified by the layer identifier. * @param fromReferenceOrPayloadOnly If it's true, it will check only references and payloads to see if the same * Live Session is enabled already in any references or payloads. Otherwise, it checkes both the prim specificed by primPath and its references * and payloads. This is normally used to check if the Live Session can be stopped as prim that is in a Live Session may not own the Live Session, * which is owned by its references or payloads, so it cannot stop the Live Session with the prim. */ bool(CARB_ABI* isPrimInLiveSession)(ILayersInstance* layersInstance, const char* primPath, const char* layerIdentifier, bool fromReferenceOrPayloadOnly); /** * Whether the layer is in the Live Session that's bound to any prims. */ bool(CARB_ABI* isLayerInPrimLiveSession)(ILayersInstance* layersInstance, const char* layerIdentifier); /** * Returns all prim paths that this Live Session is currently bound to, or nullptr if no prims are in this Live Session. * * @param session The session handle. */ carb::dictionary::Item*(CARB_ABI* getLiveSessionPrimPaths)(ILayersInstance* layersInstance, LiveSession* session); /** * Stops all the Live Sessions that the prim joins to, or the specified Live Session if layerIdentifier is provided. */ void(CARB_ABI* stopLiveSessionForPrim)(ILayersInstance* layersInstance, const char* primPath, const char* layerIdentifier); /** * It provides option to cancel joining to a Live Session if layer is in joining state. * This function only works when it's called during handling eLiveSessionJoining event as all interfaces * to join a Live Session is synchronous currently. * TODO: Supports asynchronous interface to join a session to avoid blocking main thread. */ LiveSession*(CARB_ABI* tryCancellingLiveSessionJoin)(ILayersInstance* layersInstance, const char* layerIdentifier); /** * Nanoseconds since the Unix epoch (1 January 1970) of the last time the file was modified. This time is not real time * in the filesystem. Joining a session will modify its modified time also. * * @param session The Live Session instance. */ uint64_t (CARB_ABI* getLiveSessionLastModifiedTimeNs)(ILayersInstance* layerInstance, LiveSession* session); }; } } } }
omniverse-code/kit/include/omni/kit/commands/ICommand.h
// Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include <carb/IObject.h> #include <carb/dictionary/IDictionary.h> namespace omni { namespace kit { namespace commands { /** * Pure virtual command interface. */ class ICommand : public carb::IObject { public: /** * Factory function prototype to create a new command instance. * * @param extensionId The id of the source extension registering the command. * @param commandName The command name, unique to the extension registering it. * @param kwargs Arbitrary keyword arguments the command will be executed with. * * @return The command object that was created. */ using CreateFunctionType = carb::ObjectPtr<ICommand> (*)(const char* /*extensionId*/, const char* /*commandName*/, const carb::dictionary::Item* /*kwargs*/); /** * Function prototype to populate keyword arguments expected by a command along with default values. * * @param defaultKwargs Dictionary item to fill with all keyword arguments that have default values. * @param optionalKwargs Dictionary item to fill with all other keyword arguments that are optional. * @param requiredKwargs Dictionary item to fill with all other keyword arguments that are required. */ using PopulateKeywordArgsFunctionType = void (*)(carb::dictionary::Item* /*defaultKwargs*/, carb::dictionary::Item* /*optionalKwargs*/, carb::dictionary::Item* /*requiredKwargs*/); /** * Get the id of the source extension which registered this command. * * @return Id of the source extension which registered this command. */ virtual const char* getExtensionId() const = 0; /** * Get the name of this command, unique to the extension that registered it. * * @return Name of this command, unique to the extension that registered it. */ virtual const char* getName() const = 0; /** * Called when this command object is being executed, * either originally or in response to a redo request. */ virtual void doCommand() = 0; /** * Called when this command object is being undone. */ virtual void undoCommand() = 0; }; using ICommandPtr = carb::ObjectPtr<ICommand>; } } }
omniverse-code/kit/include/omni/kit/commands/ICommandBridge.h
// Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include <omni/kit/commands/ICommand.h> #include <carb/dictionary/IDictionary.h> #include <carb/Interface.h> namespace omni { namespace kit { namespace commands { /** * Defines the interface for the CommandBridge. Commands were originally * written in (and only available to use from) Python, so this interface * acts as a bridge allowing them to be registered and executed from C++ */ class ICommandBridge { public: CARB_PLUGIN_INTERFACE("omni::kit::commands::ICommandBridge", 1, 0); using RegisterFunctionType = void (*)(const char*, const char*, const carb::dictionary::Item*, const carb::dictionary::Item*, const carb::dictionary::Item*); using DeregisterFunctionType = void (*)(const char*, const char*); using ExecuteFunctionType = bool (*)(const char*, const char*, const carb::dictionary::Item*); using UndoFunctionType = bool (*)(); using RedoFunctionType = bool (*)(); using RepeatFunctionType = bool (*)(); using VoidFunctionType = void (*)(); /** * Enable the command bridge so that new command types can be registered and deregistered from C++, * and so that existing command types can be executed in Python (where commands are held) from C++. * * @param registerFunction Function responsible for registering new C++ command types with Python. * @param deregisterFunction Function responsible for deregistering C++ command types from Python. * @param executeFunction Function responsible for executing existing commands in Python from C++. * @param undoFunction Function responsible for calling undo on past commands in Python from C++. * @param redoFunction Function responsible for calling redo on past commands in Python from C++. * @param repeatFunction Function responsible for calling repeat on past commands in Python from C++. * @param beginUndoGroupFunction Function responsible for opening an undo group in Python from C++. * @param endUndoGroupFunction Function responsible for closing an undo group in Python from C++. * @param beginUndoDisabledFunction Function responsible for disabling undo in Python from C++. * @param endUndoDisabledFunction Function responsible for re-enabling undo in Python from C++. */ virtual void enableBridge(RegisterFunctionType registerFunction, DeregisterFunctionType deregisterFunction, ExecuteFunctionType executeFunction, UndoFunctionType undoFunction, RedoFunctionType redoFunction, RepeatFunctionType repeatFunction, VoidFunctionType beginUndoGroupFunction, VoidFunctionType endUndoGroupFunction, VoidFunctionType beginUndoDisabledFunction, VoidFunctionType endUndoDisabledFunction) = 0; /** * Disable the command bridge so that new command types can no longer be registered and deregistered from C++, * and so that existing command types can no longer be executed in Python (where commands are held) from C++. * Calling this will also cause any remaining command types previously registered in C++ to be deregistered. */ virtual void disableBridge() = 0; /** * Bridge function to call from C++ to register a C++ command type with Python. * * @param extensionId The id of the source extension registering the command. * @param commandName The command name, unique to the registering extension. * @param factory Factory function used to create instances of the command. * @param populateKeywordArgs Function called to populate the keyword args. */ virtual void registerCommand(const char* extensionId, const char* commandName, ICommand::CreateFunctionType factory, ICommand::PopulateKeywordArgsFunctionType populateKeywordArgs) = 0; /** * Bridge function to call from C++ to deregister a C++ command type from Python. * * @param extensionId The id of the source extension that registered the command. * @param commandName Command name, unique to the extension that registered it. */ virtual void deregisterCommand(const char* extensionId, const char* commandName) = 0; /** * Deregister all C++ command types that were registered by the specified extension. * * @param extensionId The id of the source extension that registered the commands. */ virtual void deregisterAllCommandsForExtension(const char* extensionId) = 0; /** * Bridge function to call from C++ to execute any existing command type in Python. * * @param commandName Command name, unique to the extension that registered it. * @param kwargs Arbitrary keyword arguments the command will be executed with. * * @return True if the command object was created and executed, false otherwise. */ virtual bool executeCommand(const char* commandName, const carb::dictionary::Item* kwargs = nullptr) const = 0; /** * Bridge function to call from C++ to execute any existing command type in Python. * * @param extensionId The id of the source extension that registered the command. * @param commandName Command name, unique to the extension that registered it. * @param kwargs Arbitrary keyword arguments the command will be executed with. * * @return True if the command object was created and executed, false otherwise. */ virtual bool executeCommand(const char* extensionId, const char* commandName, const carb::dictionary::Item* kwargs = nullptr) const = 0; /** * Bridge function to call from Python to create a new instance of a C++ command. * * @param extensionId The id of the source extension that registered the command. * @param commandName The command name, unique to the extension that registered it. * @param kwargs Arbitrary keyword arguments that the command will be executed with. * * @return A command object if it was created, or an empty ObjectPtr otherwise. */ virtual carb::ObjectPtr<ICommand> createCommandObject(const char* extensionId, const char* commandName, const carb::dictionary::Item* kwargs = nullptr) const = 0; /** * Bridge function to call from C++ to undo the last command that was executed. * * @return True if the last command was successfully undone, false otherwise. */ virtual bool undoCommand() const = 0; /** * Bridge function to call from C++ to redo the last command that was undone. * * @return True if the last command was successfully redone, false otherwise. */ virtual bool redoCommand() const = 0; /** * Bridge function to call from C++ to repeat the last command that was executed or redone. * * @return True if the last command was successfully repeated, false otherwise. */ virtual bool repeatCommand() const = 0; /** * Bridge function to call from C++ to begin a new group of commands to be undone together. */ virtual void beginUndoGroup() const = 0; /** * Bridge function to call from C++ to end a new group of commands to be undone together. */ virtual void endUndoGroup() const = 0; /** * Bridge function to call from C++ to begin disabling undo for subsequent commands. */ virtual void beginUndoDisabled() const = 0; /** * Bridge function to call from C++ to end disabling undo for subsequent commands. */ virtual void endUndoDisabled() const = 0; /** * RAII class used to begin and end a new undo group within a specific scope. */ class ScopedUndoGroup { public: ScopedUndoGroup() { if (ICommandBridge* commandBridge = carb::getCachedInterface<ICommandBridge>()) { commandBridge->beginUndoGroup(); } } ~ScopedUndoGroup() { if (ICommandBridge* commandBridge = carb::getCachedInterface<ICommandBridge>()) { commandBridge->endUndoGroup(); } } }; /** * RAII class used to begin and end disabling undo within a specific scope. */ class ScopedUndoDisabled { public: ScopedUndoDisabled() { if (ICommandBridge* commandBridge = carb::getCachedInterface<ICommandBridge>()) { commandBridge->beginUndoDisabled(); } } ~ScopedUndoDisabled() { if (ICommandBridge* commandBridge = carb::getCachedInterface<ICommandBridge>()) { commandBridge->endUndoDisabled(); } } }; }; } } }
omniverse-code/kit/include/omni/kit/commands/Command.h
// Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // #pragma once #include <omni/kit/commands/ICommand.h> #include <carb/ObjectUtils.h> #include <omni/String.h> namespace omni { namespace kit { namespace commands { /** * Abstract command base class providing the core functionaly common to all commands. */ class Command : public ICommand { public: /** * Constructor. * * @param extensionId The id of the source extension registering the command. * @param commandName The command name, unique to the registering extension. */ Command(const char* extensionId, const char* commandName) : m_extensionId(extensionId ? extensionId : ""), m_commandName(commandName ? commandName : "") { } /** * Destructor. */ ~Command() override = default; /** * @ref ICommand::getExtensionId */ const char* getExtensionId() const override { return m_extensionId.c_str(); } /** * @ref ICommand::getName */ const char* getName() const override { return m_commandName.c_str(); } protected: omni::string m_extensionId; //!< The id of the source extension that registered the command. omni::string m_commandName; //!< Name of the command, unique to the registering extension. private: CARB_IOBJECT_IMPL }; } } }
omniverse-code/kit/include/omni/str/IReadOnlyCString.gen.h
// Copyright (c) 2020-2022, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // // --------- Warning: This is a build system generated file. ---------- // //! @file //! //! @brief This file was generated by <i>omni.bind</i>. #include <omni/core/OmniAttr.h> #include <omni/core/Interface.h> #include <omni/core/ResultError.h> #include <functional> #include <utility> #include <type_traits> #ifndef OMNI_BIND_INCLUDE_INTERFACE_IMPL //! Reference counted read-only C-style (i.e. null-terminated) string. template <> class omni::core::Generated<omni::str::IReadOnlyCString_abi> : public omni::str::IReadOnlyCString_abi { public: OMNI_PLUGIN_INTERFACE("omni::str::IReadOnlyCString") //! Returns a pointer to the null-terminated string. //! //! The returned pointer is valid for the lifetime of this object. //! //! This method is thread safe. const char* getBuffer() noexcept; }; #endif #ifndef OMNI_BIND_INCLUDE_INTERFACE_DECL inline const char* omni::core::Generated<omni::str::IReadOnlyCString_abi>::getBuffer() noexcept { return getBuffer_abi(); } #endif #undef OMNI_BIND_INCLUDE_INTERFACE_DECL #undef OMNI_BIND_INCLUDE_INTERFACE_IMPL
omniverse-code/kit/include/omni/str/IReadOnlyCString.h
// Copyright (c) 2020-2023, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // //! @file //! @brief Interface to manage access to a read-only string. #pragma once #include "../core/IObject.h" #include "../../carb/Defines.h" namespace omni { //! Namespace for various string helper classes, interfaces, and functions. namespace str { //! Forward declaration of the IReadOnlyCString. OMNI_DECLARE_INTERFACE(IReadOnlyCString); //! Reference counted read-only C-style (i.e. null-terminated) string. class IReadOnlyCString_abi : public omni::core::Inherits<omni::core::IObject, OMNI_TYPE_ID("omni.str.IReadOnlyCString")> { protected: //! Returns a pointer to the null-terminated string. //! //! The returned pointer is valid for the lifetime of this object. //! //! This method is thread safe. virtual OMNI_ATTR("c_str, not_null") const char* getBuffer_abi() noexcept = 0; }; } // namespace str } // namespace omni #include "IReadOnlyCString.gen.h" namespace omni { namespace str { //! Concrete implementation of the IReadOnlyCString interface. class ReadOnlyCString : public omni::core::Implements<omni::str::IReadOnlyCString> { public: //! Creates a read-only string. The given string is copied and must not be nullptr. static omni::core::ObjectPtr<IReadOnlyCString> create(const char* str) { OMNI_ASSERT(str, "ReadOnlyCString: the given string must not be nullptr"); return { new ReadOnlyCString{ str }, omni::core::kSteal }; } private: ReadOnlyCString(const char* str) : m_buffer{ str } { } const char* getBuffer_abi() noexcept override { return m_buffer.c_str(); } CARB_PREVENT_COPY_AND_MOVE(ReadOnlyCString); std::string m_buffer; }; } // namespace str } // namespace omni
omniverse-code/kit/include/omni/str/Wildcard.h
// Copyright (c) 2020-2021, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // /** @file * @brief Helper functions to handle matching wildcard patterns. */ #pragma once #include <stddef.h> #include <cstdint> namespace omni { /** Namespace for various string helper functions. */ namespace str { /** Checks if a string matches a wildcard pattern. * * @param[in] str The string to attempt to match to the pattern @p pattern. * This may not be `nullptr`. * @param[in] pattern The wildcard pattern to match against. This may not be * `nullptr`. The wildcard pattern may contain '?' to match * exactly one character (any character), or '*' to match * zero or more characters. * @returns `true` if the string @p str matches the pattern. Returns `false` if * the pattern does not match the pattern. */ inline bool matchWildcard(const char* str, const char* pattern) { const char* star = nullptr; const char* s0 = str; const char* s1 = s0; const char* p = pattern; while (*s0) { // Advance both pointers when both characters match or '?' found in pattern if ((*p == '?') || (*p == *s0)) { s0++; p++; continue; } // * found in pattern, save index of *, advance a pattern pointer if (*p == '*') { star = p++; s1 = s0; continue; } // Current characters didn't match, consume character in string and rewind to star pointer in the pattern if (star) { p = star + 1; s0 = ++s1; continue; } // Characters do not match and current pattern pointer is not star return false; } // Skip remaining stars in pattern while (*p == '*') { p++; } return !*p; // Was whole pattern matched? } /** Attempts to match a string to a set of wildcard patterns. * * @param[in] str The string to attempt to match to the pattern @p pattern. * This may not be `nullptr`. * @param[in] patterns An array of patterns to attempt to match the string @p str * to. Each pattern in this array has the same format as the * pattern in @ref matchWildcard(). This may not be `nullptr`. * @param[in] patternsCount The total number of wildcard patterns in @p patterns. * @returns The pattern that the test string @p str matched to if successful. Returns * `nullptr` if the test string did not match any of the patterns. */ inline const char* matchWildcards(const char* str, const char* const* patterns, size_t patternsCount) { for (size_t i = 0; i < patternsCount; ++i) { if (matchWildcard(str, patterns[i])) { return patterns[i]; } } return nullptr; } /** Tests whether a string is potentially a wildcard pattern. * * @param[in] pattern The pattern to test as a wildcard. This will be considered a wildcard * if it contains the special wildcard characters '*' or '?'. This may not * be nullptr. * @returns `true` if the pattern is likely a wildcard string. Returns `false` if the pattern * does not contain any of the special wildcard characters. */ inline bool isWildcardPattern(const char* pattern) { for (const char* p = pattern; p[0] != 0; p++) { if (*p == '*' || *p == '?') return true; } return false; } } // namespace str } // namespace omni