Exemplo n.º 1
0
void ShaderManager::registerShader(Shader* shader) {
    shaders_.push_back(shader);
    const Shader::ShaderObjectMap& shaderObjects = shader->getShaderObjects();

    for (const auto& shaderObject : shaderObjects) {
        startFileObservation(shaderObject.second->getAbsoluteFileName());
        std::vector<std::string> shaderIncludes = shaderObject.second->getIncludeFileNames();

        for (auto& shaderInclude : shaderIncludes) startFileObservation(shaderInclude);
    }

    if (uniformWarnings_) shader->setUniformWarningLevel(uniformWarnings_->get());
}
Exemplo n.º 2
0
void PythonEditorWidget::open() {
    if (unsavedChanges_) {
        int ret =
            QMessageBox::information(this, "Python Editor", "Do you want to save unsaved changes?",
                                     "Save", "Discard", "Cancel");

        if (ret == 0) save();

        if (ret == 2)  // Cancel
            return;
    }

    InviwoFileDialog openFileDialog(this, "Open Python Script ...", "script");

    openFileDialog.setFileMode(QFileDialog::AnyFile);

    openFileDialog.addSidebarPath(InviwoApplication::PATH_SCRIPTS);

    openFileDialog.addExtension("py", "Python Script");

    if (openFileDialog.exec()) {
        stopFileObservation(scriptFileName_);
        scriptFileName_ = openFileDialog.selectedFiles().at(0).toLocal8Bit().constData();
        settings_.beginGroup("PythonEditor");
        settings_.setValue("lastScript", scriptFileName_.c_str());
        settings_.endGroup();
        startFileObservation(scriptFileName_);
        readFile();
    }
}
Exemplo n.º 3
0
cl::Program* KernelManager::buildProgram(const std::string& fileName, const std::string& defines /*= ""*/, bool& wasBuilt) {
    wasBuilt = false;
    std::string absoluteFileName = fileName;
    if (!filesystem::fileExists(absoluteFileName)) {
        // Search in include directories added by modules
        const std::vector<std::string> openclSearchPaths = OpenCL::getPtr()->getCommonIncludeDirectories();

        for (size_t i=0; i<openclSearchPaths.size(); i++) {
            if (filesystem::fileExists(openclSearchPaths[i]+"/"+fileName)) {
                absoluteFileName = openclSearchPaths[i]+"/"+fileName;
                break;
            }
        }
    }

    std::pair <ProgramMap::iterator, ProgramMap::iterator> range = programs_.equal_range(absoluteFileName);

    for (ProgramMap::iterator it = range.first; it != range.second; ++it) {
        if (it->second.defines == defines) {
            return it->second.program;
        }
    }

    cl::Program* program = new cl::Program();

    try {
        *program = cl::Program(OpenCL::buildProgram(absoluteFileName, defines));

        try {
            std::vector<cl::Kernel> kernels;
            program->createKernels(&kernels);

            for (std::vector<cl::Kernel>::iterator kernelIt = kernels.begin(); kernelIt != kernels.end(); ++kernelIt) {
                kernels_.insert(std::pair<cl::Program*, cl::Kernel*>(program, new cl::Kernel(*kernelIt)));
            }
        } catch (cl::Error& err) {
            LogError(absoluteFileName << " Failed to create kernels, Error:" << err.what() << "(" << err.err() << "), " << errorCodeToString(
                         err.err()) << std::endl);
        }
    } catch (cl::Error&) {
    }

    ProgramIdentifier uniqueProgram;
    uniqueProgram.defines = defines;
    uniqueProgram.program = program;
    programs_.insert(std::pair<std::string, ProgramIdentifier>(absoluteFileName, uniqueProgram));
    startFileObservation(absoluteFileName);
    wasBuilt = true;
    return program;
}
Exemplo n.º 4
0
void PythonEditorWidget::save() {
    if (script_.getSource() == defaultSource) return;  // nothig to be saved

    if (scriptFileName_.size() == 0) {
        saveAs();
    } else if (unsavedChanges_) {
        stopFileObservation(scriptFileName_);
        std::ofstream file(scriptFileName_.c_str());
        file << pythonCode_->toPlainText().toLocal8Bit().constData();
        file.close();
        startFileObservation(scriptFileName_);
        LogInfo("Python Script saved(" << scriptFileName_ << ")");
        settings_.beginGroup("PythonEditor");
        settings_.setValue("lastScript", scriptFileName_.c_str());
        settings_.endGroup();
        unsavedChanges_ = false;
    }
}
Exemplo n.º 5
0
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());
    }
}