Beispiel #1
0
PythonEditorWidget::PythonEditorWidget(QWidget* parent)
    : InviwoDockWidget(tr("Python Editor"), parent)
    , settings_("Inviwo", "Inviwo")
    , infoTextColor_(153, 153, 153)
    , errorTextColor_(255, 107, 107)
    , script_()
    , unsavedChanges_(false) {
    ivwAssert(instance_ == nullptr, "This is a Singelton, constructor may only be called once")
        instance_ = this;
    setObjectName("PythonEditor");
    settings_.beginGroup("PythonEditor");
    QString lastFile = settings_.value("lastScript", "").toString();
    settings_.endGroup();
    setVisible(false);
    buildWidget();
    resize(500, 700);
    
    InviwoApplication::getPtr()->registerFileObserver(this);
    unsavedChanges_ = false;



    if (lastFile.size() != 0) loadFile(lastFile.toLocal8Bit().constData(), false);

    setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    setFloating(true);
}
void FilePropertyWidgetQt::generateWidget() {
    QHBoxLayout* hLayout = new QHBoxLayout();
    setSpacingAndMargins(hLayout);
    setLayout(hLayout);
    setAcceptDrops(true);

    label_ = new EditableLabelQt(this, property_);
    hLayout->addWidget(label_);

    QHBoxLayout* hWidgetLayout = new QHBoxLayout();
    hWidgetLayout->setContentsMargins(0, 0, 0, 0);
    QWidget* widget = new QWidget();
    widget->setLayout(hWidgetLayout);

    lineEdit_ = new FilePathLineEditQt(this);

    connect(lineEdit_, &QLineEdit::editingFinished, [&]() {
        // editing is done, sync property with contents
        property_->set(lineEdit_->getPath());
    });
#if defined(IVW_DEBUG)
    QObject::connect(lineEdit_, &LineEditQt::editingCanceled, [this]() {
        // undo textual changes by resetting the contents of the line edit
        ivwAssert(lineEdit_->getPath() == property_->get(), "FilePropertyWidgetQt: paths not equal after canceling edit");
    });
#endif // IVW_DEBUG

    QSizePolicy sp = lineEdit_->sizePolicy();
    sp.setHorizontalStretch(3);
    lineEdit_->setSizePolicy(sp);
    hWidgetLayout->addWidget(lineEdit_);

    auto revealButton = new QToolButton(this);
    revealButton->setIcon(QIcon(":/icons/reveal.png"));
    hWidgetLayout->addWidget(revealButton);
    connect(revealButton, &QToolButton::pressed, [&]() {
        auto dir = filesystem::directoryExists(property_->get())
                       ? property_->get()
                       : filesystem::getFileDirectory(property_->get());

        QDesktopServices::openUrl(
            QUrl(QString::fromStdString("file:///" + dir), QUrl::TolerantMode));
    });

    openButton_ = new QToolButton(this);
    openButton_->setIcon(QIcon(":/icons/open.png"));
    hWidgetLayout->addWidget(openButton_);
    connect(openButton_, SIGNAL(pressed()), this, SLOT(setPropertyValue()));

    sp = widget->sizePolicy();
    sp.setHorizontalStretch(3);
    widget->setSizePolicy(sp);
    hLayout->addWidget(widget);
}
ProcessorNetworkEvaluator::ProcessorNetworkEvaluator(ProcessorNetwork* processorNetwork)
    : processorNetwork_(processorNetwork)
    , evaulationQueued_(false)
    , evaluationDisabled_(false)
    , exceptionHandler_(StandardExceptionHandler()) {
    ivwAssert(
        processorNetworkEvaluators_.find(processorNetwork) == processorNetworkEvaluators_.end(),
        "A ProcessorNetworkEvaluator for the given ProcessorNetwork is already created");

    processorNetworkEvaluators_[processorNetwork] = this;
    processorNetwork_->addObserver(this);
}
Beispiel #4
0
TextureUnit::TextureUnit() : unitEnum_(0), unitNumber_(0) {
    ivwAssert(!textureUnits_.empty(), "Texture unit handler not initialized.");

    // check which texture unit is available
    for (size_t i = 1; i < textureUnits_.size(); i++) {
        if (textureUnits_[i] == false) {
            // unit previously unused, mark as used now
            textureUnits_[i] = true;
            unitNumber_ = (GLint)i;
            unitEnum_ = GL_TEXTURE0 + unitNumber_;
            return;
        }
    }

    throw OpenGLException("Exceeding number of available texture units.", IvwContext);
}
Beispiel #5
0
void LayerCLGL::initialize(Texture2D* texture) {
    ivwAssert(texture != 0, "Cannot initialize with null OpenGL texture");

    // const auto it = std::find_if(LayerCLGL::clImageSharingMap_.begin(),
    // LayerCLGL::clImageSharingMap_.end(),
    //    [texture](const TextureCLImageSharingPair& o) { return  o.first.get() == texture; });
    CLTextureSharingMap::iterator it = LayerCLGL::clImageSharingMap_.find(texture_);

    if (it == LayerCLGL::clImageSharingMap_.end()) {
        clImage_ = std::make_shared<cl::Image2DGL>(
            OpenCL::getPtr()->getContext(), CL_MEM_READ_WRITE, GL_TEXTURE_2D, 0, texture->getID());
        LayerCLGL::clImageSharingMap_.insert(TextureCLImageSharingPair(texture_, clImage_));
    } else {
        clImage_ = it->second;
    }

    texture->addObserver(this);
}
    bool PythonScript::run(bool outputInfo) {
        if (isCompileNeeded_ && !compile(outputInfo)) {
            LogError("Failed to run script, script could not be compiled");
            return false;
        }

        ivwAssert(byteCode_ != nullptr, "No byte code");

        if (outputInfo) LogInfo("Running compiled script ...");
       
        auto m = PyImport_AddModule("__main__");
        if (m == NULL) return false;
       
        auto d = PyModule_GetDict(m);

        PyObject* copy = PyDict_Copy(d);
        PyObject* ret = PyEval_EvalCode(BYTE_CODE, copy, copy);
        bool success = checkRuntimeError();
        Py_XDECREF(ret);
        Py_XDECREF(copy);
        return success;
    }
Beispiel #7
0
void Layer::copyRepresentationsTo(Layer* targetLayer) {
    // TODO: And also need to be tested on multiple representations_ such as LayerRAM, LayerDisk
    // TODO: optimize the code

    auto& targets = targetLayer->representations_;
    bool copyDone = false;

    for (auto& sourceElem : representations_) {
        auto sourceRepr = sourceElem.second;
        if (sourceRepr->isValid()) {
            for (auto& targetElem : targets) {
                auto targetRepr = targetElem.second;
                if (typeid(*sourceRepr) == typeid(*targetRepr)) {
                    if (sourceRepr->copyRepresentationsTo(targetRepr.get())) {
                        targetRepr->setValid(true);
                        targetLayer->lastValidRepresentation_ = targetElem.second;
                        copyDone = true;
                    }
                }
            }
        }
    }

    if (!copyDone) {  // Fallback
        ivwAssert(lastValidRepresentation_, "Last valid representation is expected.");
        for (auto& targetElem : targets) targetElem.second->setValid(false);
        targetLayer->createDefaultRepresentation();

        auto clone = std::shared_ptr<LayerRepresentation>(lastValidRepresentation_->clone());
        targetLayer->addRepresentation(clone);
        targetLayer->setDimensions(targetLayer->getDimensions());

        if (lastValidRepresentation_->copyRepresentationsTo(clone.get())) {
            clone->setValid(true);
            targetLayer->lastValidRepresentation_ = clone;
        }
    }
}
Beispiel #8
0
PythonEditorWidget* PythonEditorWidget::getPtr() {
    ivwAssert(instance_ != nullptr, "Singleton not yet created");
    return instance_;
}
void InviwoApplicationQt::registerFileObserver(FileObserver* fileObserver) {
    ivwAssert(std::find(fileObservers_.begin(), fileObservers_.end(), fileObserver) ==
                  fileObservers_.end(),
              "File observer already registered.");
    fileObservers_.push_back(fileObserver);
}