ReflectedEnumModel::ReflectedEnumModel(const PropertyAccessor& pA, ObjectHandleT<MetaEnumObj> enumObj) { const wchar_t* enumString = enumObj->getEnumString(); if (enumString != nullptr) { generateFromString(items_, enumString); return; } Collection collection = enumObj->generateEnum(pA.getObject()); auto it = collection.begin(); auto itEnd = collection.end(); for (; it != itEnd; ++it) { int index; it.key().tryCast(index); Variant itValue = it.value(); std::string text; itValue.tryCast(text); items_.push_back(new ReflectedEnumItem(index, text)); } }
bool StringSlot::Connect(size_t connectionID, ObjectHandleT<ISlot> slot) { assert(m_pNode != nullptr); bool result = m_pNode->CanConnect(this, slot); if (result) { m_connectedSlots.push_back(slot.get()); m_connectionIds.insert(connectionID); m_pNode->OnConnect(this, m_connectedSlots.back()); } return result; }
bool CustomConnection::Bind(ObjectHandleT<ISlot> outputSlot, ObjectHandleT<ISlot> inputSlot) { bool result = false; if (outputSlot == nullptr || inputSlot == nullptr) { NGT_ERROR_MSG("Input arguments are null\n"); return result; } if (isConnected) { NGT_ERROR_MSG("Connection is already connected\n"); return result; } while (true) { result = outputSlot->CanConnect(inputSlot); if (!result) break; result = inputSlot->CanConnect(outputSlot); if (!result) break; if (outputSlot->Connect(m_id, inputSlot) && inputSlot->Connect(m_id, outputSlot)) { m_inputSlot = inputSlot.get(); m_outputSlot = outputSlot.get(); isConnected = true; } else { result = false; NGT_ERROR_MSG("Failed to connect input and output slots\n"); outputSlot->Disconnect(m_id, inputSlot); inputSlot->Disconnect(m_id, outputSlot); } break; } return result; }
bool StringSlot::Disconnect(size_t connectionID, ObjectHandleT<ISlot> slot) { assert(m_pNode != nullptr); bool result = false; auto slotPos = std::find_if(m_connectedSlots.begin(), m_connectedSlots.end(), [&slot](const ObjectHandleT<ISlot> &connectedSlot) { return slot->Id() == connectedSlot->Id(); }); if (slotPos != m_connectedSlots.end()) { result = true; m_connectedSlots.erase(slotPos); m_connectionIds.erase(connectionID); m_pNode->OnDisconnect(this, slot); } return result; }
bool IntToStringNode::CanConnect(ObjectHandleT<ISlot> mySlot, ObjectHandleT<ISlot> otherSlot) { bool result = false; while (true) { ObjectHandleT<INode> otherNode = otherSlot->Node(); if (this == otherNode.get()) break; if (!(mySlot->IsInput() ^ otherSlot->IsInput())) break; if (mySlot->Type() != otherSlot->Type()) break; if (mySlot->Color() != otherSlot->Color()) break; auto connectedSlots = mySlot->GetConnectedSlots(); result = (std::find_if(connectedSlots->begin(), connectedSlots->end(), [&otherSlot](const ISlot* slot) { return otherSlot->Id() == slot->Id(); }) == connectedSlots->end()); break; } return result; }