PortInspector::PortInspector(std::string portClassIdentifier, std::string inspectorWorkspaceFileName) : inspectorNetworkFileName_(inspectorWorkspaceFileName) , portClassIdentifier_(portClassIdentifier) { // Deserialize the network auto app = InviwoApplication::getPtr(); Deserializer xmlDeserializer(app, inspectorNetworkFileName_); inspectorNetwork_ = util::make_unique<ProcessorNetwork>(app); inspectorNetwork_->deserialize(xmlDeserializer); processors_ = inspectorNetwork_->getProcessors(); for (auto processor : processors_) { // Set Identifiers std::string newIdentifier = dotSeperatedToPascalCase(getPortClassName()) + "PortInspector" + processor->getIdentifier(); processor->setIdentifier(newIdentifier); // Find the and save inports. for (auto& inport : processor->getInports()) { if (!inport->isConnected()) inPorts_.push_back(inport); } auto meta = processor->getMetaData<ProcessorMetaData>(ProcessorMetaData::CLASS_IDENTIFIER); meta->setVisible(false); meta->setSelected(false); // Find and save the canvasProcessor if (auto canvasProcessor = dynamic_cast<CanvasProcessor*>(processor)) { canvasProcessor_ = canvasProcessor; } } // Store the connections and and disconnect them. auto connections = inspectorNetwork_->getConnections(); for (auto& connection : connections) { connections_.emplace_back(connection.getOutport(), connection.getInport()); inspectorNetwork_->removeConnection(connection.getOutport(), connection.getInport()); } // store the processor links. propertyLinks_ = inspectorNetwork_->getLinks(); }
void PortInspector::initialize() { if (active_ == false && needsUpdate_) { if (inspectorNetwork_) { inspectorNetwork_.reset(); processors_.clear(); inPorts_.clear(); connections_.clear(); propertyLinks_.clear(); canvasProcessor_ = nullptr; } stopFileObservation(inspectorNetworkFileName_); needsUpdate_ = false; } if (inspectorNetwork_) { return; } // Observe the filename; startFileObservation(inspectorNetworkFileName_); try { // Deserialize the network IvwDeserializer xmlDeserializer(inspectorNetworkFileName_); inspectorNetwork_ = util::make_unique<ProcessorNetwork>(); inspectorNetwork_->deserialize(xmlDeserializer); processors_ = inspectorNetwork_->getProcessors(); for (auto processor : processors_) { // Set Identifiers std::string newIdentifier = getPortClassName() + "_Port_Inspector_" + processor->getIdentifier(); processor->setIdentifier(newIdentifier); processor->initialize(); // Find the and save inports. std::vector<Inport*> inports = processor->getInports(); for (auto& inport : inports) { if (!inport->isConnected()) inPorts_.push_back(inport); } ProcessorMetaData* meta = processor->getMetaData<ProcessorMetaData>(ProcessorMetaData::CLASS_IDENTIFIER); meta->setVisibile(false); meta->setSelected(false); // Find and save the canvasProcessor CanvasProcessor* canvasProcessor = dynamic_cast<CanvasProcessor*>(processor); if (canvasProcessor) { canvasProcessor_ = canvasProcessor; } } // Store the connections and and disconnect them. connections_ = inspectorNetwork_->getConnections(); for (auto& elem : connections_) elem->getInport()->disconnectFrom(elem->getOutport()); // store the processor links. propertyLinks_ = inspectorNetwork_->getLinks(); } catch (AbortException& e) { // Error deserializing file needsUpdate_ = true; LogError(e.what()); } }