/******************************************************************************
* Constructor for the NativePlugin class.
******************************************************************************/
NativePlugin::NativePlugin(const QString& manifestFile) :
	Plugin(manifestFile), _library(nullptr)
{
	// Get the name of the shared library file.
	QString libBasename = metadata().object().value(QStringLiteral("native-library")).toString();
	if(libBasename.isEmpty())
		throw Exception(tr("Invalid plugin manifest file %1. 'native-library' element not present.").arg(manifestFile));

	// Resolve the filename by adding the platform specific suffix/extension
	// and make the path absolute.
	QDir baseDir;
	if(isCore())	// The core library is not in the plugins directory.
		baseDir = QCoreApplication::applicationDirPath();
	else
		baseDir = QFileInfo(manifestFile).dir();
#if defined(Q_OS_WIN)
	QFileInfo libFile(baseDir.absoluteFilePath(libBasename + ".dll"));
#else
	QFileInfo libFile(baseDir.absoluteFilePath(libBasename + ".so"));
#endif
	_libraryFilename = QDir::cleanPath(libFile.absoluteFilePath());
}
// Loads JSON from file and parses it and assigns to LibraryFile class properties
bool LibraryFile::loadJson(QString filepath)
{
    // Try to open file and read it
    QFile file(filepath);
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
        return false;

    // Copy library file to root directory
    QDir rootDir(libraryDirPath);
    if(!rootDir.exists())
        rootDir.mkdir(libraryDirPath);

    QFileInfo loadedInfo(file);
    QFileInfo info(libraryDirPath, loadedInfo.fileName());
    if(info.exists())
    {
        QFile newFile(info.absoluteFilePath());
        if(newFile.remove())
        {
            //QString s = file.readAll();
            file.copy(loadedInfo.absoluteFilePath(), info.absoluteFilePath());

        }
    }
    else
    {
        file.copy(loadedInfo.absoluteFilePath(), info.absoluteFilePath());
    }

    QFile libFile(info.absoluteFilePath());
    // Parse json file
    if(!libFile.open(QIODevice::ReadOnly | QIODevice::Text))
        return false;

    libraryFileName = info.fileName();
    QString data = libFile.readAll();
    QJsonDocument doc(QJsonDocument::fromJson(data.toUtf8()));

    // Get JSON root object
    QJsonObject root = doc.object();

    // Load basic information
    libraryTitle = root["libraryTitle"].toString();
    libraryInfo = root["libraryInfo"].toString();
    comdelDirectory = root["comdelDirectory"].toString();
    loadComdelHeader(root["comdelHeader"].toArray());

    // Load list of address spaces
    loadAddressSpaceList(root["addressSpaceList"].toArray());

    // Load messages
    loadMessages(root["messages"].toObject());

    // Load all components and its children
    loadComponents(root["componentList"].toArray());

    // Load automatic and regular buses
    loadBuses(root["regularBusList"].toArray(), true);
    loadBuses(root["automaticBusList"].toArray());

    // Load connection rules
    loadRegularBusConnectionRules(root["regularBusConnectionRules"].toArray());
    loadAutomaticBusConnectionRules(root["automaticBusConnectionRules"].toArray());

    return true;
}
Exemple #3
0
void ProjectHandle::loadData(){

    QString Name = QFileDialog::getOpenFileName(NULL,tr("Open picture"), ".",tr("Project files (*.bmp *.jpg *.jpeg *.png)"));
    if (Name.isEmpty()){
        return;
    }


    QImage* load_image = new QImage(Name);

    New_dlg dlg(libPath);
    QPixmap pic =QPixmap::fromImage(load_image->scaled(dlg.pic_label->size())) ;
    dlg.pic_label->setPixmap(pic);

    QFile libFile(libPath);
    if(!libFile.open(QFile::ReadOnly | QFile::WriteOnly)){
        emit addToLog("Не найден файл библиотек");
        QDir dir;
        QFileInfo inf(libPath);
        dir=inf.dir();
        dir.mkdir(dir.absolutePath());
        QTextStream s(&libFile);
        s << "";
    }else{

        QTextStream readS(&libFile);
        while(!readS.atEnd()){
            QString inp;
            readS >> inp;
            dlg.material_Box->addItem(inp);
        }
    }


    if(!dlg.exec()){
        delete load_image;
        return;
    }

    colorMap = load_image;

    PObject object;
    if(dlg.width_sizeBox->currentText()=="um"){
        object.width = dlg.width_SpinBox->value();
    }else{
        object.width = dlg.width_SpinBox->value()*1000;
    }

    if(dlg.height_sizeBox->currentText()=="um"){
        object.height = dlg.height_SpinBox->value();
    }else{
        object.height = dlg.height_SpinBox->value()*1000;
    }

    object.map = new Image;
    object.map->data = new uchar[colorMap->width()*colorMap->height()];
    object.material     =   dlg.material_Box->currentText();
    object.map->sizeX   =   colorMap->width() ;
    object.map->sizeY   =   colorMap->height() ;


    calculate(&object);

    map=object.map;
    object.path=Name;

    QFileInfo inf(Name);
    projObjects.insert(inf.fileName(),object);

    curName=inf.fileName();
    emit addToList(inf.fileName());
    emit cleanGl();
    emit set_glwMap(map);
    emit imageLoad(map->sizeX,map->sizeY);
}