diff options
author | rtk0c <[email protected]> | 2022-11-27 12:04:31 -0800 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-11-27 12:04:31 -0800 |
commit | 182c8f8357739f905bbd721006480502435b6b43 (patch) | |
tree | 082613a474d863182e2ad8f2167f1643f26e67a3 /app/source/Cplt/Model/Workflow/Workflow_Main.cpp | |
parent | b01ed99a1cd0c863c8709930658513c04dd70f61 (diff) |
Update brace style to match rest of my projectscplt-imgui
Diffstat (limited to 'app/source/Cplt/Model/Workflow/Workflow_Main.cpp')
-rw-r--r-- | app/source/Cplt/Model/Workflow/Workflow_Main.cpp | 252 |
1 files changed, 84 insertions, 168 deletions
diff --git a/app/source/Cplt/Model/Workflow/Workflow_Main.cpp b/app/source/Cplt/Model/Workflow/Workflow_Main.cpp index 0f35b32..cd0e419 100644 --- a/app/source/Cplt/Model/Workflow/Workflow_Main.cpp +++ b/app/source/Cplt/Model/Workflow/Workflow_Main.cpp @@ -28,112 +28,92 @@ WorkflowConnection::WorkflowConnection() , SourceNode{ WorkflowNode::kInvalidId } , SourcePin{ WorkflowNode::kInvalidPinId } , DestinationNode{ WorkflowNode::kInvalidId } - , DestinationPin{ WorkflowNode::kInvalidPinId } -{ + , DestinationPin{ WorkflowNode::kInvalidPinId } { } -bool WorkflowConnection::IsValid() const -{ +bool WorkflowConnection::IsValid() const { return Id != 0; } -ImNodes::LinkId WorkflowConnection::GetLinkId() const -{ +ImNodes::LinkId WorkflowConnection::GetLinkId() const { // Our id is 0-based (represents an index directly) // but imgui-node-editor uses the value 0 to represent a null id, so we need to offset by 1 return Id + 1; } -void WorkflowConnection::DrawDebugInfo() const -{ +void WorkflowConnection::DrawDebugInfo() const { ImGui::Text("Source (node with output pin):"); ImGui::Text("{ Node = %u, Pin = %u }", SourceNode, SourcePin); ImGui::Text("Destination (node with input pin):"); ImGui::Text("{ Node = %u, Pin = %u }", DestinationNode, DestinationPin); } -void WorkflowConnection::ReadFrom(std::istream& stream) -{ +void WorkflowConnection::ReadFrom(std::istream& stream) { stream >> SourceNode >> SourcePin; stream >> DestinationNode >> DestinationPin; } -void WorkflowConnection::WriteTo(std::ostream& stream) const -{ +void WorkflowConnection::WriteTo(std::ostream& stream) const { stream << SourceNode << SourcePin; stream << DestinationNode << DestinationPin; } -bool WorkflowNode::InputPin::IsConstantConnection() const -{ +bool WorkflowNode::InputPin::IsConstantConnection() const { return ConnectionToConst && IsConnected(); } -bool WorkflowNode::InputPin::IsConnected() const -{ +bool WorkflowNode::InputPin::IsConnected() const { return Connection != WorkflowConnection::kInvalidId; } -BaseValue::Kind WorkflowNode::InputPin::GetMatchingType() const -{ +BaseValue::Kind WorkflowNode::InputPin::GetMatchingType() const { return MatchingType; } -bool WorkflowNode::OutputPin::IsConnected() const -{ +bool WorkflowNode::OutputPin::IsConnected() const { return Connection != WorkflowConnection::kInvalidId; } -BaseValue::Kind WorkflowNode::OutputPin::GetMatchingType() const -{ +BaseValue::Kind WorkflowNode::OutputPin::GetMatchingType() const { return MatchingType; } WorkflowNode::WorkflowNode(Kind kind, bool locked) : mKind{ kind } , mDepth{ -1 } - , mLocked(locked) -{ + , mLocked(locked) { } -Vec2i WorkflowNode::GetPosition() const -{ +Vec2i WorkflowNode::GetPosition() const { return mPosition; } -void WorkflowNode::SetPosition(const Vec2i& position) -{ +void WorkflowNode::SetPosition(const Vec2i& position) { mPosition = position; } -uint32_t WorkflowNode::GetId() const -{ +uint32_t WorkflowNode::GetId() const { return mId; } -ImNodes::NodeId WorkflowNode::GetNodeId() const -{ +ImNodes::NodeId WorkflowNode::GetNodeId() const { // See WorkflowConnection::GetLinkId for the rationale return mId + 1; } -WorkflowNode::Kind WorkflowNode::GetKind() const -{ +WorkflowNode::Kind WorkflowNode::GetKind() const { return mKind; } -int WorkflowNode::GetDepth() const -{ +int WorkflowNode::GetDepth() const { return mDepth; } -bool WorkflowNode::IsLocked() const -{ +bool WorkflowNode::IsLocked() const { return mLocked; } -WorkflowNode::Type WorkflowNode::GetType() const -{ +WorkflowNode::Type WorkflowNode::GetType() const { if (IsInputNode()) { return InputType; } else if (IsOutputNode()) { @@ -143,70 +123,57 @@ WorkflowNode::Type WorkflowNode::GetType() const } } -bool WorkflowNode::IsInputNode() const -{ +bool WorkflowNode::IsInputNode() const { return mInputs.size() == 0; } -bool WorkflowNode::IsOutputNode() const -{ +bool WorkflowNode::IsOutputNode() const { return mOutputs.size() == 0; } -void WorkflowNode::ConnectInput(uint32_t pinId, WorkflowNode& srcNode, uint32_t srcPinId) -{ +void WorkflowNode::ConnectInput(uint32_t pinId, WorkflowNode& srcNode, uint32_t srcPinId) { mWorkflow->Connect(*this, pinId, srcNode, srcPinId); } -void WorkflowNode::DisconnectInput(uint32_t pinId) -{ +void WorkflowNode::DisconnectInput(uint32_t pinId) { mWorkflow->DisconnectByDestination(*this, pinId); } -void WorkflowNode::DrawInputPinDebugInfo(uint32_t pinId) const -{ +void WorkflowNode::DrawInputPinDebugInfo(uint32_t pinId) const { ImGui::Text("Node ID: %d", mId); ImGui::Text("Pin ID: (input) %d", pinId); } -const WorkflowNode::InputPin& WorkflowNode::GetInputPin(uint32_t pinId) const -{ +const WorkflowNode::InputPin& WorkflowNode::GetInputPin(uint32_t pinId) const { return mInputs[pinId]; } -ImNodes::PinId WorkflowNode::GetInputPinUniqueId(uint32_t pinId) const -{ +ImNodes::PinId WorkflowNode::GetInputPinUniqueId(uint32_t pinId) const { return mWorkflow->FabricateGlobalPinId(*this, pinId, false); } -void WorkflowNode::ConnectOutput(uint32_t pinId, WorkflowNode& dstNode, uint32_t dstPinId) -{ +void WorkflowNode::ConnectOutput(uint32_t pinId, WorkflowNode& dstNode, uint32_t dstPinId) { mWorkflow->Connect(dstNode, dstPinId, *this, pinId); } -void WorkflowNode::DisconnectOutput(uint32_t pinId) -{ +void WorkflowNode::DisconnectOutput(uint32_t pinId) { mWorkflow->DisconnectBySource(*this, pinId); } -void WorkflowNode::DrawOutputPinDebugInfo(uint32_t pinId) const -{ +void WorkflowNode::DrawOutputPinDebugInfo(uint32_t pinId) const { ImGui::Text("Node ID: %d", mId); ImGui::Text("Pin ID: (output) %d", pinId); } -const WorkflowNode::OutputPin& WorkflowNode::GetOutputPin(uint32_t pinId) const -{ +const WorkflowNode::OutputPin& WorkflowNode::GetOutputPin(uint32_t pinId) const { return mOutputs[pinId]; } -ImNodes::PinId WorkflowNode::GetOutputPinUniqueId(uint32_t pinId) const -{ +ImNodes::PinId WorkflowNode::GetOutputPinUniqueId(uint32_t pinId) const { return mWorkflow->FabricateGlobalPinId(*this, pinId, true); } -void WorkflowNode::Draw() -{ +void WorkflowNode::Draw() { for (uint32_t i = 0; i < mInputs.size(); ++i) { auto& pin = mInputs[i]; auto& typeInfo = BaseValue::QueryInfo(pin.MatchingType); @@ -223,8 +190,7 @@ void WorkflowNode::Draw() } } -void WorkflowNode::DrawDebugInfo() const -{ +void WorkflowNode::DrawDebugInfo() const { ImGui::Text("Node kind: %s", FormatKind(mKind)); ImGui::Text("Node type: %s", FormatType(GetType())); ImGui::Text("Node ID: %u", mId); @@ -232,20 +198,17 @@ void WorkflowNode::DrawDebugInfo() const DrawExtraDebugInfo(); } -void WorkflowNode::ReadFrom(std::istream& stream) -{ +void WorkflowNode::ReadFrom(std::istream& stream) { stream >> mId; stream >> mPosition.x >> mPosition.y; } -void WorkflowNode::WriteTo(std::ostream& stream) -{ +void WorkflowNode::WriteTo(std::ostream& stream) { stream << mId; stream << mPosition.x << mPosition.y; } -WorkflowNode::InputPin& WorkflowNode::InsertInputPin(int atIdx) -{ +WorkflowNode::InputPin& WorkflowNode::InsertInputPin(int atIdx) { assert(atIdx >= 0 && atIdx < mInputs.size()); mInputs.push_back(InputPin{}); @@ -256,8 +219,7 @@ WorkflowNode::InputPin& WorkflowNode::InsertInputPin(int atIdx) return mInputs[atIdx]; } -void WorkflowNode::RemoveInputPin(int pin) -{ +void WorkflowNode::RemoveInputPin(int pin) { DisconnectInput(pin); for (int i = 0, end = (int)mInputs.size() - 1; i < end; ++i) { SwapInputPin(i, i + 1); @@ -265,8 +227,7 @@ void WorkflowNode::RemoveInputPin(int pin) mInputs.resize(mInputs.size() - 1); } -void WorkflowNode::SwapInputPin(int a, int b) -{ +void WorkflowNode::SwapInputPin(int a, int b) { auto& pinA = mInputs[a]; auto& pinB = mInputs[b]; @@ -284,8 +245,7 @@ void WorkflowNode::SwapInputPin(int a, int b) std::swap(pinA, pinB); } -WorkflowNode::OutputPin& WorkflowNode::InsertOutputPin(int atIdx) -{ +WorkflowNode::OutputPin& WorkflowNode::InsertOutputPin(int atIdx) { assert(atIdx >= 0 && atIdx < mOutputs.size()); mOutputs.push_back(OutputPin{}); @@ -296,8 +256,7 @@ WorkflowNode::OutputPin& WorkflowNode::InsertOutputPin(int atIdx) return mOutputs[atIdx]; } -void WorkflowNode::RemoveOutputPin(int pin) -{ +void WorkflowNode::RemoveOutputPin(int pin) { DisconnectOutput(pin); for (int i = 0, end = (int)mOutputs.size() - 1; i < end; ++i) { SwapInputPin(i, i + 1); @@ -305,8 +264,7 @@ void WorkflowNode::RemoveOutputPin(int pin) mOutputs.resize(mOutputs.size() - 1); } -void WorkflowNode::SwapOutputPin(int a, int b) -{ +void WorkflowNode::SwapOutputPin(int a, int b) { auto& pinA = mOutputs[a]; auto& pinB = mOutputs[b]; @@ -324,71 +282,57 @@ void WorkflowNode::SwapOutputPin(int a, int b) std::swap(pinA, pinB); } -void WorkflowNode::OnAttach(Workflow& workflow, uint32_t newId) -{ +void WorkflowNode::OnAttach(Workflow& workflow, uint32_t newId) { } -void WorkflowNode::OnDetach() -{ +void WorkflowNode::OnDetach() { } -const std::vector<WorkflowConnection>& Workflow::GetConnections() const -{ +const std::vector<WorkflowConnection>& Workflow::GetConnections() const { return mConnections; } -std::vector<WorkflowConnection>& Workflow::GetConnections() -{ +std::vector<WorkflowConnection>& Workflow::GetConnections() { return mConnections; } -const std::vector<std::unique_ptr<WorkflowNode>>& Workflow::GetNodes() const -{ +const std::vector<std::unique_ptr<WorkflowNode>>& Workflow::GetNodes() const { return mNodes; } -std::vector<std::unique_ptr<WorkflowNode>>& Workflow::GetNodes() -{ +std::vector<std::unique_ptr<WorkflowNode>>& Workflow::GetNodes() { return mNodes; } -const std::vector<std::unique_ptr<BaseValue>>& Workflow::GetConstants() const -{ +const std::vector<std::unique_ptr<BaseValue>>& Workflow::GetConstants() const { return mConstants; } -std::vector<std::unique_ptr<BaseValue>>& Workflow::GetConstants() -{ +std::vector<std::unique_ptr<BaseValue>>& Workflow::GetConstants() { return mConstants; } -WorkflowConnection* Workflow::GetConnectionById(uint32_t id) -{ +WorkflowConnection* Workflow::GetConnectionById(uint32_t id) { return &mConnections[id]; } -WorkflowConnection* Workflow::GetConnectionByLinkId(ImNodes::LinkId id) -{ +WorkflowConnection* Workflow::GetConnectionByLinkId(ImNodes::LinkId id) { return &mConnections[(uint32_t)(size_t)id - 1]; } -WorkflowNode* Workflow::GetNodeById(uint32_t id) -{ +WorkflowNode* Workflow::GetNodeById(uint32_t id) { return mNodes[id].get(); } -WorkflowNode* Workflow::GetNodeByNodeId(ImNodes::NodeId id) -{ +WorkflowNode* Workflow::GetNodeByNodeId(ImNodes::NodeId id) { return mNodes[(uint32_t)(size_t)id - 1].get(); } -BaseValue* Workflow::GetConstantById(uint32_t id) -{ +BaseValue* Workflow::GetConstantById(uint32_t id) { return mConstants[id].get(); } -Workflow::GlobalPinId Workflow::DisassembleGlobalPinId(ImNodes::PinId pinId) -{ +Workflow::GlobalPinId Workflow::DisassembleGlobalPinId(ImNodes::PinId pinId) { // imgui-node-editor requires all pins to have a global, unique id // but in our model the pin are typed (input vs output) and associated with a node: there is no built-in global id // Therefore we encode one ourselves @@ -411,8 +355,7 @@ Workflow::GlobalPinId Workflow::DisassembleGlobalPinId(ImNodes::PinId pinId) return result; } -ImNodes::PinId Workflow::FabricateGlobalPinId(const WorkflowNode& node, uint32_t pinId, bool isOutput) const -{ +ImNodes::PinId Workflow::FabricateGlobalPinId(const WorkflowNode& node, uint32_t pinId, bool isOutput) const { // See this->DisassembleGlobalPinId for format details and rationale uint64_t id = 0; @@ -423,18 +366,15 @@ ImNodes::PinId Workflow::FabricateGlobalPinId(const WorkflowNode& node, uint32_t return id; } -const std::vector<std::vector<uint32_t>>& Workflow::GetDepthGroups() const -{ +const std::vector<std::vector<uint32_t>>& Workflow::GetDepthGroups() const { return mDepthGroups; } -bool Workflow::DoesDepthNeedsUpdate() const -{ +bool Workflow::DoesDepthNeedsUpdate() const { return mDepthsDirty; } -void Workflow::AddNode(std::unique_ptr<WorkflowNode> step) -{ +void Workflow::AddNode(std::unique_ptr<WorkflowNode> step) { auto [storage, id] = AllocWorkflowStep(); storage = std::move(step); storage->OnAttach(*this, id); @@ -442,8 +382,7 @@ void Workflow::AddNode(std::unique_ptr<WorkflowNode> step) storage->mId = id; } -void Workflow::RemoveNode(uint32_t id) -{ +void Workflow::RemoveNode(uint32_t id) { auto& step = mNodes[id]; if (step == nullptr) return; @@ -452,8 +391,7 @@ void Workflow::RemoveNode(uint32_t id) step->mId = WorkflowNode::kInvalidId; } -void Workflow::RemoveConnection(uint32_t id) -{ +void Workflow::RemoveConnection(uint32_t id) { auto& conn = mConnections[id]; if (!conn.IsValid()) return; @@ -464,8 +402,7 @@ void Workflow::RemoveConnection(uint32_t id) mDepthsDirty = true; } -bool Workflow::Connect(WorkflowNode& sourceNode, uint32_t sourcePin, WorkflowNode& destinationNode, uint32_t destinationPin) -{ +bool Workflow::Connect(WorkflowNode& sourceNode, uint32_t sourcePin, WorkflowNode& destinationNode, uint32_t destinationPin) { auto& src = sourceNode.mOutputs[sourcePin]; auto& dst = destinationNode.mInputs[destinationPin]; @@ -491,8 +428,7 @@ bool Workflow::Connect(WorkflowNode& sourceNode, uint32_t sourcePin, WorkflowNod return true; } -bool Workflow::DisconnectBySource(WorkflowNode& sourceNode, uint32_t sourcePin) -{ +bool Workflow::DisconnectBySource(WorkflowNode& sourceNode, uint32_t sourcePin) { auto& sn = sourceNode.mOutputs[sourcePin]; if (!sn.IsConnected()) return false; @@ -507,8 +443,7 @@ bool Workflow::DisconnectBySource(WorkflowNode& sourceNode, uint32_t sourcePin) return true; } -bool Workflow::DisconnectByDestination(WorkflowNode& destinationNode, uint32_t destinationPin) -{ +bool Workflow::DisconnectByDestination(WorkflowNode& destinationNode, uint32_t destinationPin) { auto& dn = destinationNode.mOutputs[destinationPin]; if (!dn.IsConnected()) return false; @@ -523,8 +458,7 @@ bool Workflow::DisconnectByDestination(WorkflowNode& destinationNode, uint32_t d return true; } -Workflow::GraphUpdateResult Workflow::UpdateGraph(GraphUpdateDetails* details) -{ +Workflow::GraphUpdateResult Workflow::UpdateGraph(GraphUpdateDetails* details) { if (!mDepthsDirty) { return GUR_NoWorkToDo; } @@ -533,8 +467,7 @@ Workflow::GraphUpdateResult Workflow::UpdateGraph(GraphUpdateDetails* details) // - Dependency = nodes its input pins are connected to // - Dependents = nodes its output pins are connected to - struct WorkingNode - { + struct WorkingNode { // The max depth out of all dependency nodes, maintained during the traversal and committed as the actual depth // when all dependencies of this node has been resolved. Add 1 to get the depth that will be assigned to the node. int MaximumDepth = 0; @@ -635,28 +568,23 @@ Workflow::GraphUpdateResult Workflow::UpdateGraph(GraphUpdateDetails* details) return GUR_Success; } -class Workflow::Private -{ +class Workflow::Private { public: template <class TSelf, class TProxy> - static void OperateStream(TSelf& self, TProxy& proxy) - { + static void OperateStream(TSelf& self, TProxy& proxy) { // TODO } }; -void Workflow::ReadFromDataStream(InputDataStream& stream) -{ +void Workflow::ReadFromDataStream(InputDataStream& stream) { Private::OperateStream(*this, stream); } -void Workflow::WriteToDataStream(OutputDataStream& stream) const -{ +void Workflow::WriteToDataStream(OutputDataStream& stream) const { Private::OperateStream(*this, stream); } -std::pair<WorkflowConnection&, uint32_t> Workflow::AllocWorkflowConnection() -{ +std::pair<WorkflowConnection&, uint32_t> Workflow::AllocWorkflowConnection() { for (size_t idx = 0; idx < mConnections.size(); ++idx) { auto& elm = mConnections[idx]; if (!elm.IsValid()) { @@ -671,8 +599,7 @@ std::pair<WorkflowConnection&, uint32_t> Workflow::AllocWorkflowConnection() return { conn, id }; } -std::pair<std::unique_ptr<WorkflowNode>&, uint32_t> Workflow::AllocWorkflowStep() -{ +std::pair<std::unique_ptr<WorkflowNode>&, uint32_t> Workflow::AllocWorkflowStep() { for (size_t idx = 0; idx < mNodes.size(); ++idx) { auto& elm = mNodes[idx]; if (elm == nullptr) { @@ -686,14 +613,12 @@ std::pair<std::unique_ptr<WorkflowNode>&, uint32_t> Workflow::AllocWorkflowStep( return { node, id }; } -void WorkflowAssetList::DiscoverFiles(const std::function<void(SavedAsset)>& callback) const -{ +void WorkflowAssetList::DiscoverFiles(const std::function<void(SavedAsset)>& callback) const { auto dir = GetConnectedProject().GetWorkflowsDirectory(); DiscoverFilesByExtension(callback, dir, ".cplt-workflow"sv); } -std::string WorkflowAssetList::RetrieveNameFromFile(const fs::path& file) const -{ +std::string WorkflowAssetList::RetrieveNameFromFile(const fs::path& file) const { auto res = DataArchive::LoadFile(file); if (!res) return ""; auto& stream = res.value(); @@ -704,19 +629,16 @@ std::string WorkflowAssetList::RetrieveNameFromFile(const fs::path& file) const return assetInfo.Name; } -uuids::uuid WorkflowAssetList::RetrieveUuidFromFile(const fs::path& file) const -{ +uuids::uuid WorkflowAssetList::RetrieveUuidFromFile(const fs::path& file) const { return uuids::uuid::from_string(file.stem().string()); } -fs::path WorkflowAssetList::RetrievePathFromAsset(const SavedAsset& asset) const -{ +fs::path WorkflowAssetList::RetrievePathFromAsset(const SavedAsset& asset) const { auto fileName = uuids::to_string(asset.Uuid); return GetConnectedProject().GetWorkflowPath(fileName); } -bool WorkflowAssetList::SaveInstance(const SavedAsset& assetInfo, const Asset* asset) const -{ +bool WorkflowAssetList::SaveInstance(const SavedAsset& assetInfo, const Asset* asset) const { auto path = RetrievePathFromAsset(assetInfo); auto res = DataArchive::SaveFile(path); if (!res) return false; @@ -731,8 +653,7 @@ bool WorkflowAssetList::SaveInstance(const SavedAsset& assetInfo, const Asset* a return true; } -static std::unique_ptr<Workflow> LoadWorkflowFromFile(const fs::path& path) -{ +static std::unique_ptr<Workflow> LoadWorkflowFromFile(const fs::path& path) { auto res = DataArchive::LoadFile(path); if (!res) return nullptr; auto& stream = res.value(); @@ -747,18 +668,15 @@ static std::unique_ptr<Workflow> LoadWorkflowFromFile(const fs::path& path) return workflow; } -Workflow* WorkflowAssetList::LoadInstance(const SavedAsset& assetInfo) const -{ +Workflow* WorkflowAssetList::LoadInstance(const SavedAsset& assetInfo) const { return ::LoadWorkflowFromFile(RetrievePathFromAsset(assetInfo)).release(); } -Workflow* WorkflowAssetList::CreateInstance(const SavedAsset& assetInfo) const -{ +Workflow* WorkflowAssetList::CreateInstance(const SavedAsset& assetInfo) const { return new Workflow(); } -bool WorkflowAssetList::RenameInstanceOnDisk(const SavedAsset& assetInfo, std::string_view oldName) const -{ +bool WorkflowAssetList::RenameInstanceOnDisk(const SavedAsset& assetInfo, std::string_view oldName) const { auto path = RetrievePathFromAsset(assetInfo); auto workflow = ::LoadWorkflowFromFile(path); @@ -769,8 +687,7 @@ bool WorkflowAssetList::RenameInstanceOnDisk(const SavedAsset& assetInfo, std::s return true; } -void WorkflowAssetList::DisplayAssetCreator(ListState& state) -{ +void WorkflowAssetList::DisplayAssetCreator(ListState& state) { auto ValidateNewName = [&]() -> void { if (mACNewName.empty()) { mACNewNameError = NameSelectionError::Empty; @@ -826,8 +743,7 @@ void WorkflowAssetList::DisplayAssetCreator(ListState& state) } } -void WorkflowAssetList::DisplayDetailsTable(ListState& state) const -{ +void WorkflowAssetList::DisplayDetailsTable(ListState& state) const { ImGui::BeginTable("AssetDetailsTable", 1, ImGuiTableFlags_Borders); ImGui::TableSetupColumn(I18N_TEXT("Name", L10N_NAME)); |