// open first file button clicked
void DotPlotFilesDialog::sl_openFirstFile() {

    LastUsedDirHelper lod("DotPlot first file");
    lod.url = U2FileDialog::getOpenFileName(NULL, tr("Open first file"), lod.dir, filter);

    SAFE_POINT(firstFileEdit, "firstFileEdit is NULL", );
    if (!lod.url.isEmpty()) {
        firstFileEdit->setText(lod.url);
        FormatDetectionConfig conf;
        conf.useImporters = true;
        conf.bestMatchesOnly = true;
        QList<FormatDetectionResult> results = DocumentUtils::detectFormat(lod.url, conf);
        if (results.isEmpty()){
            firstFileEdit->setText("");
            lod.url = "";
            return;
        }
        FormatDetectionResult format = results.at(0); //get moslty matched format
        bool multySeq = format.rawDataCheckResult.properties.value(RawDataCheckResult_MultipleSequences).toBool();
        if(multySeq){
            mergeFirstCheckBox->setChecked(true);
            sl_mergeFirst();
        }
    }
}
void DotPlotDialog::sl_loadSequenceButton(){
    QString filter = DialogUtils::prepareDocumentsFileFilterByObjType(GObjectTypes::SEQUENCE, true);
    LastUsedDirHelper lod("DotPlot file");
    lod.url = U2FileDialog::getOpenFileName(this, tr("Open file"), lod.dir, filter);
    if(!lod.url.isEmpty()){
        Task *tasks = new Task("Adding document to the project", TaskFlag_NoRun);

        if (!AppContext::getProject()) {
            tasks->addSubTask( AppContext::getProjectLoader()->createNewProjectTask() );
        }

        //DotPlotLoadDocumentsTask *t = new DotPlotLoadDocumentsTask(lod.url, -1, NULL, -1, false);
        //tasks->addSubTask(t);
        QVariantMap hints;
        hints[ProjectLoaderHint_LoadWithoutView] = false;
        hints[ProjectLoaderHint_LoadUnloadedDocument] = true;
        openSequenceTask = AppContext::getProjectLoader()->openWithProjectTask(lod.url, hints);
        if(openSequenceTask == NULL){
            return;
        }
        curURL = lod.url;
        tasks->addSubTask(openSequenceTask);

        connect( AppContext::getTaskScheduler(), SIGNAL( si_stateChanged(Task*) ), SLOT( sl_loadTaskStateChanged(Task*) ) );

        AppContext::getTaskScheduler()->registerTopLevelTask(tasks);
    }

}
void GetSequenceByIdDialog::sl_saveFilenameButtonClicked() {
    LastUsedDirHelper lod(DOWNLOAD_REMOTE_FILE_DOMAIN);
    QString dirName = U2FileDialog::getExistingDirectory(this, tr("Select directory to save"), lod.dir);
    if(!dirName.isEmpty()) {
        directoryEdit->setText(dirName);
        dir = dirName;
    }
}
void DownloadRemoteFileDialog::sl_saveFilenameButtonClicked() {
    LastUsedDirHelper lod(DOWNLOAD_REMOTE_FILE_DOMAIN);
    QString filename = U2FileDialog::getExistingDirectory(this, tr("Select folder to save"), lod.dir);
    if(!filename.isEmpty()) {
        ui->saveFilenameLineEdit->setText(filename);
        lod.url = filename;
    }
}
Beispiel #5
0
void execute()
{
    switch ( ir.op)
        {
        //lit
        case 1:
            lit(ir.m);
            break;
        // opr will require another sub-function to decide
        // which operation to run
        case 2:
            opr();
            break;
        //lod
        case 3:
            lod(ir.l, ir.m);
            break;
        //sto
        case 4:
            sto(ir.l, ir.m);
            break;
        //cal
        case 5:
            cal(ir.l, ir.m);
            break;
        //inc
        case 6:
            inc(ir.m);
            break;
        //jmp
        case 7:
            jmp(ir.m);
            break;
        //jpc
        case 8:
            jpc(ir.m);
            break;
        //sio
        //this will require another sub function to decide
        //which i/o to run
        case 9:
            sio();
            break;

        default:
            fprintf(output, "OP code input was invalid. ");
            sio3();
        }
        //print pc, bp, sp
        //use loop to print stack
        fprintf(output, "\t%d\t\t%d\t%d\t", pc, bp, sp);
        stackPrint();
}
void ImportAnnotationsFromCSVDialog::sl_readFileClicked() {
    // show the dialog
    LastUsedDirHelper lod("CSV");
    QString filter = DialogUtils::prepareFileFilter(tr("CSV Files"), QStringList() << "csv", true, QStringList());
    lod.url = U2FileDialog::getOpenFileName(this, tr("Select CSV file to read"), lod, filter);
    if (lod.url.isEmpty()) {
        return;
    }
    readFileName->setText(lod.url);

    // guess separator & show preview
    guessSeparator(true);
}
Beispiel #7
0
 // Adds data to in-memory store to specific level of details range.
 void EXPORT_API addToInMemoryStoreInBoundingBox(const char* styleFile,     // style file
                                                const char* path,          // path to data
                                                double minLat,             // minimal latitude
                                                double minLon,             // minimal longitude
                                                double maxLat,             // maximal latitude
                                                double maxLon,             // maximal longitude
                                                int startLod,              // start zoom level
                                                int endLod,                // end zoom level
                                                OnError* errorCallback)    // completion callback
 {
     utymap::BoundingBox bbox(utymap::GeoCoordinate(minLat, minLon), utymap::GeoCoordinate(maxLat,maxLon));
     utymap::LodRange lod(startLod, endLod);
     applicationPtr->addToInMemoryStore(styleFile, path, bbox, lod, errorCallback);
 }
Beispiel #8
0
bool
Selector::_select_neuron(Geometry * geometry)
{
    if(geometry == nullptr)
    {
        RECORD_INFO("Invalid click!");;
        return false;
    }
    RECORD_INFO("Compartment clicked => " + geometry -> getName());
    Geode * geode = (Geode *)(geometry -> getParent(0));
    RECORD_INFO("Neuron clicked => " + geode -> getName());
    ref_ptr<LOD>   lod((LOD *)(geode -> getParent(0)));
    MatrixTransform *matrix_transform = (MatrixTransform *)(lod -> getParent(0));
    matrix_transform -> removeChild(lod.get());
    osgFX::Outline * outline = new osgFX::Outline();
    outline -> setColor(Vec4(0.0f, 1.0f, 0.0f, 1.0f));
    outline -> addChild(lod.get());
    matrix_transform -> addChild(outline);
    return true;
}
void SaveDocumentController::sl_fileDialogButtonClicked() {
    QString defaultFilter = prepareDefaultFileFilter();
    const QString filter = prepareFileFilter();

    QString defaultUrl = getSaveFileName();
    LastUsedDirHelper lod(conf.defaultDomain, defaultUrl);
    if (defaultUrl.isEmpty()) {
        defaultUrl = lod;
    }

    cutGzExtension(defaultUrl);

    lod.url = U2FileDialog::getSaveFileName(conf.parentWidget, conf.saveTitle, defaultUrl, filter, &defaultFilter);
    if (lod.url.isEmpty()) {
        return;
    }

    addFormatExtension(lod.url);
    addGzExtension(lod.url);
    overwritingConfirmed = true;
    setPath(lod.url);
}
Beispiel #10
0
    sender(async::dispatcher &worker,
           const t_syncRadiusList& syncRadien,
           t_terrainAccessor* tiles)
        : m_syncRadien(syncRadien)
    {
        BASSERT(tiles != nullptr);
        BASSERT(tiles->getNumLod() <= (int32)syncRadien.size());

        real voxelSize(1.);

        for (int32 indLod = 0; indLod < tiles->getNumLod(); ++indLod)
        {
            const auto callback(boost::bind(&sender::isInRange, this, _1, _2, indLod));

            t_simpleAccessor* toWork(tiles->getLod(indLod));
            t_multipleTilesPtr lod(new t_multipleTiles(worker, voxelSize, callback, toWork));
            voxelSize*=2.;
            m_multipleTiles.push_back(lod);

            lod->signalSendTileData()->connect(boost::bind(&sender::lodWantsToSendTileData, this, _1, _2, indLod));
        }
    }
Beispiel #11
0
Tile::Tile(GLuint shader_id, int x, int z)
{
    glGenVertexArrays(1, &vao);
    glGenBuffers(1, &vbo);
    glGenBuffers(1, &ebo);

    glBindVertexArray(vao);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);

    GLuint posAttrib = glGetAttribLocation(shader_id, "position_model");
    GLuint norAttrib = glGetAttribLocation(shader_id, "normal_model");
    GLuint texAttrib = glGetAttribLocation(shader_id, "texcoord");
    GLuint colAttrib = glGetAttribLocation(shader_id, "color");
    glEnableVertexAttribArray(posAttrib);
    glEnableVertexAttribArray(norAttrib);
    glEnableVertexAttribArray(texAttrib);
    glEnableVertexAttribArray(colAttrib);
    glVertexAttribPointer(posAttrib, 3, GL_FLOAT, GL_FALSE, 11*sizeof(float), 0 );
    glVertexAttribPointer(norAttrib, 3, GL_FLOAT, GL_FALSE, 11*sizeof(float), (void*)(3*sizeof(float)));
    glVertexAttribPointer(texAttrib, 2, GL_FLOAT, GL_FALSE, 11*sizeof(float), (void*)(6*sizeof(float)));
    glVertexAttribPointer(colAttrib, 3, GL_FLOAT, GL_FALSE, 11*sizeof(float), (void*)(8*sizeof(float)));

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
    glEnable(GL_PRIMITIVE_RESTART);
    glPrimitiveRestartIndex((TILE_SIZE+1)*(TILE_SIZE+1)+TILE_SIZE);

    reload_vbo = false;
    reload_ebo = false;
    needs_rebuild = false;
    needs_gen = true;
    show = false;

    lod(0);
    set_xz(x,z);
    update_vertices();
    update_indices();
}
Beispiel #12
0
    void checkPropertyUpdates()
    {
        // GIVEN
        TestArbiter arbiter;
        QScopedPointer<Qt3DRender::QLevelOfDetail> lod(new Qt3DRender::QLevelOfDetail());
        arbiter.setArbiterOnNode(lod.data());

        {
            // WHEN
            lod->setThresholdType(Qt3DRender::QLevelOfDetail::ProjectedScreenPixelSizeThreshold);
            QCoreApplication::processEvents();

            // THEN
            QCOMPARE(arbiter.events.size(), 1);
            Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>();
            QCOMPARE(change->propertyName(), "thresholdType");
            QCOMPARE(change->value().value<int>(), static_cast<int>(Qt3DRender::QLevelOfDetail::ProjectedScreenPixelSizeThreshold));

            arbiter.events.clear();
        }

        {
            // WHEN
            QVector<qreal> thresholds = {10., 20., 30.};
            lod->setThresholds(thresholds);
            QCoreApplication::processEvents();

            // THEN
            QCOMPARE(arbiter.events.size(), 1);
            Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>();
            QCOMPARE(change->propertyName(), "thresholds");
            QCOMPARE(change->value().value<decltype(thresholds)>(), thresholds);

            arbiter.events.clear();
        }
    }
 /** Utility function, same as \p 'lod(lodi)->at(pass);' */
 const Shader* shader(int lodi=0, int pass=0) const { return lod(lodi)->at(pass); }
Beispiel #14
0
void Object::writeToFile(FILE *fp, const FBMatrix &tm, const FBMatrix &pivotTm, const std::vector<int> &usedMaterials, bool optimizeVcache, bool factorPivot) const
{
	std::vector<int> materials = getMaterialIndices();

	/*
	// Common data
	FBMatrix relativeTransform = transform;// * parentTm.GetInverse();
	Vector position = convert(relativeTransform.GetTranslation());
	Rotation rotation = convert(relativeTransform.GetRotation());
	Vector scale = convert(relativeTransform.GetScale());
	FBMatrix inversePivot = pivotTm; //pivotTm.GetInverse();
	*/

	Vector position = convert(tm.GetTranslation());
	Rotation rotation = convert(tm.GetRotation());
	Vector scale = convert(tm.GetScale());

	for(unsigned int i = 0; i < materials.size(); ++i)
	{
		++actualObjectAmount;

		// ToDo: generate some fancy names for splitted objects
		fwrite(name.c_str(), 1, name.size() + 1, fp);
		fwrite(parentName.c_str(), 1, parentName.size() + 1, fp);

		short int materialIndex = -1;
		for(unsigned int j = 0; j < usedMaterials.size(); ++j)
		{
			if(usedMaterials[j] == materials[i])
			{
				materialIndex = static_cast<short int> (j);
				break;
			}
		}
		
		fwrite(&materialIndex, sizeof(short int), 1, fp); // Material index
		fwrite(&position, sizeof(float), 3, fp); // position
		fwrite(&rotation, sizeof(float), 4, fp); // rotation
		fwrite(&scale, sizeof(float), 3, fp); // scale

		char noCollision = 0;
		char noRender = 0;
		char isLightObject = 0;

		if(!cameraVisibility)
			noRender = 1;
		if(!collisionVisibility)
			noCollision = 1;
		if(lightObject)
			isLightObject = 1;

		fwrite(&noCollision, sizeof(char), 1, fp); // no_collision
		fwrite(&noRender, sizeof(char), 1, fp); // no_render
		fwrite(&isLightObject, sizeof(char), 1, fp); // lightobject

		// For this material
		std::vector<Face> tempFaces;
		std::vector<Vertex> tempVertices;
		char hasWeights = 0;

		// Build faces
		for(unsigned int j = 0; j < faces.size(); ++j)
		{
			if(faces[j].getMaterialId() == materials[i])
				tempFaces.push_back(faces[j]);
		}

		std::vector<int> newVertexIndex(vertices.size());
		std::hash_set<int> tempVertexIndices;

		for(unsigned int j = 0; j < tempFaces.size(); ++j)
		for(unsigned int k = 0; k < 3; ++k)
		{
			int index = tempFaces[j].getVertexIndex(k);
			assert(index >= 0 && index < int(vertices.size()));

			if(tempVertexIndices.find(index) == tempVertexIndices.end())
			{
				tempVertexIndices.insert(index);

				if(vertices[index].hasBoneWeights() == true)
					hasWeights = 1;

				newVertexIndex[index] = tempVertices.size();
				tempVertices.push_back(vertices[index]);
			}
		}

		for(unsigned int j = 0; j < tempFaces.size(); ++j)
		for(unsigned int k = 0; k < 3; ++k)
		{
			// Grab index and convert it to temp mesh vertex buffer
			int vertexIndex = tempFaces[j].getVertexIndex(k);
			int newIndex = newVertexIndex[vertexIndex];

			assert(newIndex >= 0 && newIndex < int(tempVertices.size()));
			tempFaces[j].setVertexIndex(k, newIndex);
		}

		Lod lod(tempVertices, tempFaces, optimizeVcache);
		//if(generateLods)
		//	lod.generateLods(lodDetail);

		const std::vector<Vertex> &lodVertices = lod.getVertices();
		const std::vector<Face> &lodFaces = lod.getFaceBuffer(0);

		int vertexAmountInt = lodVertices.size();
		WORD vertexAmount = static_cast<WORD> (lodVertices.size());
		WORD faceAmount = static_cast<WORD> (lodFaces.size());

		char hasLods = 0; //generateLods;

		fwrite(&vertexAmount, sizeof(WORD), 1, fp); // vertex count
		fwrite(&faceAmount, sizeof(WORD), 1, fp); // face count
		fwrite(&hasLods, sizeof(char), 1, fp); // lod info
		fwrite(&hasWeights, sizeof(char), 1, fp); // vertex weights

		// Vertex data
		for(int j = 0; j < vertexAmount; ++j)
		{
			FBVector positionTmp = lodVertices[j].getPosition();
			Vector normal = convert(lodVertices[j].getNormal());
			Vector2D uv = convert(lodVertices[j].getUv());
			Vector2D uv2 = convert(lodVertices[j].getUv2());

			if(factorPivot)
				pivotTm.TransformVector(positionTmp);

			Vector position = convert(positionTmp);

			fwrite(&position, sizeof(float), 3, fp); // position
			fwrite(&normal, sizeof(float), 3, fp); // normal
			fwrite(&uv, sizeof(float), 2, fp); // texture coordinates
			fwrite(&uv2, sizeof(float), 2, fp); // texture coordinates
		}

		// Face data
		for(int j = 0; int(j) < lod.getFaceBufferCount(); ++j)
		{
			const std::vector<Face> &lodFaces = lod.getFaceBuffer(j);
			WORD faceCount = lodFaces.size();

			if(j > 0)
			{
				fwrite(&faceCount, sizeof(WORD), 1, fp);
			}

			for(unsigned int i = 0; i < faceAmount; ++i)
			for(unsigned int k = 0; k < 3; ++k)
			{
				const Face &face = lodFaces[i];
				WORD vertexIndex = WORD(face.getVertexIndex(k));

				int a = face.getVertexIndex(k);
				int b = int(lodVertices.size());
				assert(face.getVertexIndex(k) < int(lodVertices.size()));
				assert(vertexIndex >= 0 && vertexIndex < vertexAmount);

				WORD index = vertexIndex;
				fwrite(&index, sizeof(WORD), 1, fp);
			}
		}

		// Weight data (if has)
		if(hasWeights == 1)
		{
			static const int MAX_WEIGHTS = 2;

			for(unsigned int j = 0; j < lodVertices.size(); ++j)
			{
				int indices[MAX_WEIGHTS] = { -1 };
				signed char weights[MAX_WEIGHTS] = { 0 };

				for(int k = 0; k < 2; ++k)
				{
					indices[k] = lodVertices[j].getBoneIndex(k);

					float weight = lodVertices[j].getBoneWeight(k);
					weights[k] = static_cast<signed char> (100.f * weight + .5f);
				}

				// Indices
				for(int k = 0; k < 2; ++k)
					fwrite(&indices[k], sizeof(int), 1, fp);

				// Weights
				for(int k = 0; k < 2; ++k)
					fwrite(&weights[k], sizeof(signed char), 1, fp);
			}
		}
	}
}
Beispiel #15
0
void executeInstruction()
{
    switch(ir.op)
    {
    case 1:
        lit();
        break;
    case 2:
        opr();
        break;
    case 3:
        lod();
        break;
    case 4:
        sto();
        break;
    case 5:
        cal();
        break;
    case 6:
        inc();
        break;
    case 7:
        jmp();
        break;
    case 8:
        jpc();
        break;
    case 9:
        sio();
    default:
        break;

    }

    void opr()
{
    switch ( ir.m)
    {
        //rtn
        case 0:
            ret();
            break;
        //neg
        case 1:
            neg();
            break;
       //add
        case 2:
            add();
            break;
       //sub
        case 3:
            sub();
            break;
        //mul
        case 4:
            mul();
            break;
        //div
        case 5:
            divid();
            break;
        //odd
        case 6:
            odd();
            break;
        //mod
        case 7:
            mod();
            break;
        //eql
        case 8:
            eql();
            break;
        //neq
        case 9:
            neq();
            break;
        //lss
        case 10:
            lss();
            break;
        //leq
        case 11:
            leq();
            break;
        //gtr
        case 12:
            gtr();
            break;
        //geq
        case 13:
            geq();
            break;

        default:
            fprintf(output, "OP code input was invalid. ");
            halt = 1;
            break;
    }
}

}
 /** Utility function, same as \p 'lod(lodi) = new ShaderPasses(shader1,shader2,shader3,shader4);' */
 void setLOD(int lodi, Shader* shader1, Shader* shader2=NULL, Shader* shader3=NULL, Shader* shader4=NULL) 
 { 
   VL_CHECK(lodi<VL_MAX_EFFECT_LOD)
   lod(lodi) = new ShaderPasses(shader1,shader2,shader3,shader4);
 }
Beispiel #17
0
bool ModelPackager::zipModel() {
    QTemporaryDir dir;
    dir.setAutoRemove(true);
    QDir tempDir(dir.path());
    
    QByteArray nameField = _mapping.value(NAME_FIELD).toByteArray();
    tempDir.mkpath(nameField + "/textures");
    QDir fbxDir(tempDir.path() + "/" + nameField);
    QDir texDir(fbxDir.path() + "/textures");
    
    // Copy textures
    listTextures();
    if (!_textures.empty()) {
        QByteArray texdirField = _mapping.value(TEXDIR_FIELD).toByteArray();
        _texDir = _modelFile.path() + "/" + texdirField;
        copyTextures(_texDir, texDir);
    }
    
    // Copy LODs
    QVariantHash lodField = _mapping.value(LOD_FIELD).toHash();
    if (!lodField.empty()) {
        for (auto it = lodField.constBegin(); it != lodField.constEnd(); ++it) {
            QString oldPath = _modelFile.path() + "/" + it.key();
            QFile lod(oldPath);
            QString newPath = fbxDir.path() + "/" + QFileInfo(lod).fileName();
            if (lod.exists()) {
                lod.copy(newPath);
            }
        }
    }
    
    // Copy FBX
    QFile fbx(_fbxInfo.filePath());
    QByteArray filenameField = _mapping.value(FILENAME_FIELD).toByteArray();
    QString newPath = fbxDir.path() + "/" + QFileInfo(filenameField).fileName();
    fbx.copy(newPath);
    
    // Correct FST
    _mapping[FILENAME_FIELD] = tempDir.relativeFilePath(newPath);
    _mapping[TEXDIR_FIELD] = tempDir.relativeFilePath(texDir.path());
    
    // Copy FST
    QFile fst(tempDir.path() + "/" + nameField + ".fst");
    if (fst.open(QIODevice::WriteOnly)) {
        fst.write(FSTReader::writeMapping(_mapping));
        fst.close();
    } else {
        qCDebug(interfaceapp) << "Couldn't write FST file" << fst.fileName();
        return false;
    }
    
    
    QString saveDirPath = QFileDialog::getExistingDirectory(nullptr, "Save Model",
                                                        "", QFileDialog::ShowDirsOnly);
    if (saveDirPath.isEmpty()) {
        qCDebug(interfaceapp) << "Invalid directory" << saveDirPath;
        return false;
    }
    
    QDir saveDir(saveDirPath);
    copyDirectoryContent(tempDir, saveDir);
    return true;
}
Beispiel #18
0
bool ModelPackager::zipModel() {
    QTemporaryDir dir;
    dir.setAutoRemove(true);
    QDir tempDir(dir.path());
    
    QByteArray nameField = _mapping.value(NAME_FIELD).toByteArray();
    tempDir.mkpath(nameField + "/textures");
    tempDir.mkpath(nameField + "/scripts");
    QDir fbxDir(tempDir.path() + "/" + nameField);
    QDir texDir(fbxDir.path() + "/textures");
    QDir scriptDir(fbxDir.path() + "/scripts");

    // Copy textures
    listTextures();
    if (!_textures.empty()) {
        QByteArray texdirField = _mapping.value(TEXDIR_FIELD).toByteArray();
        _texDir = _modelFile.path() + "/" + texdirField;
        copyTextures(_texDir, texDir);
    }

    // Copy scripts
    QByteArray scriptField = _mapping.value(SCRIPT_FIELD).toByteArray();
    _mapping.remove(SCRIPT_FIELD);
    if (scriptField.size() > 1) {
        tempDir.mkpath(nameField + "/scripts");
        _scriptDir = _modelFile.path() + "/" + scriptField;
        QDir wdir = QDir(_scriptDir);
        _mapping.remove(SCRIPT_FIELD);
        wdir.setSorting(QDir::Name | QDir::Reversed);
        auto list = wdir.entryList(QDir::NoDotAndDotDot | QDir::AllEntries);
        for (auto script : list) {
            auto sc = tempDir.relativeFilePath(scriptDir.path()) + "/" + QUrl(script).fileName();
            _mapping.insertMulti(SCRIPT_FIELD, sc);
        }
        copyDirectoryContent(wdir, scriptDir);
    } 
    
    // Copy LODs
    QVariantHash lodField = _mapping.value(LOD_FIELD).toHash();
    if (!lodField.empty()) {
        for (auto it = lodField.constBegin(); it != lodField.constEnd(); ++it) {
            QString oldPath = _modelFile.path() + "/" + it.key();
            QFile lod(oldPath);
            QString newPath = fbxDir.path() + "/" + QFileInfo(lod).fileName();
            if (lod.exists()) {
                lod.copy(newPath);
            }
        }
    }
    
    // Copy FBX
    QFile fbx(_fbxInfo.filePath());
    QByteArray filenameField = _mapping.value(FILENAME_FIELD).toByteArray();
    QString newPath = fbxDir.path() + "/" + QFileInfo(filenameField).fileName();
    fbx.copy(newPath);
    
    // Correct FST
    _mapping[FILENAME_FIELD] = tempDir.relativeFilePath(newPath);
    _mapping[TEXDIR_FIELD] = tempDir.relativeFilePath(texDir.path());

    for (auto multi : _mapping.values(SCRIPT_FIELD)) {
        multi.fromValue(tempDir.relativeFilePath(scriptDir.path()) + multi.toString());
    }
    // Copy FST
    QFile fst(tempDir.path() + "/" + nameField + ".fst");
    if (fst.open(QIODevice::WriteOnly)) {
        fst.write(FSTReader::writeMapping(_mapping));
        fst.close();
    } else {
        qCDebug(interfaceapp) << "Couldn't write FST file" << fst.fileName();
        return false;
    }
    
    
    QString saveDirPath = QFileDialog::getExistingDirectory(nullptr, "Save Model",
                                                        "", QFileDialog::ShowDirsOnly);
    if (saveDirPath.isEmpty()) {
        qCDebug(interfaceapp) << "Invalid directory" << saveDirPath;
        return false;
    }
    
    QDir saveDir(saveDirPath);
    copyDirectoryContent(tempDir, saveDir);
    return true;
}
Beispiel #19
0
bool FstReader::zip() {
    // File Dialog
    QString filename = QFileDialog::getOpenFileName(NULL,
                                                    "Select your .fst file ...",
                                                    QStandardPaths::writableLocation(QStandardPaths::DownloadLocation),
                                                    "*.fst");
    
    // First we check the FST file
    QFile fst(filename);
    if (!fst.open(QFile::ReadOnly | QFile::Text)) {
        qDebug() << "[ERROR] Could not open FST file : " << fst.fileName();
        return false;
    }
    
    // Compress and copy the fst
    if (!compressFile(QFileInfo(fst).filePath(), _zipDir.path() + "/" + QFileInfo(fst).fileName())) {
        return false;
    }
    _totalSize += QFileInfo(fst).size();
    if (!addPart(_zipDir.path() + "/" + QFileInfo(fst).fileName(),
                 QString("fst"))) {
        return false;
    }
    qDebug() << "Reading FST file : " << QFileInfo(fst).filePath();
    
    // Let's read through the FST file
    QTextStream stream(&fst);
    QList<QString> line;
    while (!stream.atEnd()) {
        line = stream.readLine().split(QRegExp("[ =]"), QString::SkipEmptyParts);
        if (line.isEmpty()) {
            continue;
        }
        
        if (_totalSize > MAX_SIZE) {
            qDebug() << "[ERROR] Model too big, over " << MAX_SIZE << " Bytes.";
            return false;
        }
        
        // according to what is read, we modify the command
        if (line.first() == NAME_FIELD) {
            QHttpPart textPart;
            textPart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data;"
                               " name=\"model_name\"");
            textPart.setBody(line[1].toUtf8());
            _dataMultiPart->append(textPart);
        } else if (line.first() == FILENAME_FIELD) {
            QFileInfo fbx(QFileInfo(fst).path() + "/" + line[1]);
            if (!fbx.exists() || !fbx.isFile()) { // Check existence
                qDebug() << "[ERROR] FBX file " << fbx.absoluteFilePath() << " doesn't exist.";
                return false;
            }
            // Compress and copy
            if (!compressFile(fbx.filePath(), _zipDir.path() + "/" + line[1])) {
                return false;
            }
            _totalSize += fbx.size();
            if (!addPart(_zipDir.path() + "/" + line[1], "fbx")) {
                return false;
            }
        } else if (line.first() == TEXDIR_FIELD) { // Check existence
            QFileInfo texdir(QFileInfo(fst).path() + "/" + line[1]);
            if (!texdir.exists() || !texdir.isDir()) {
                qDebug() << "[ERROR] Texture directory " << texdir.absolutePath() << " doesn't exist.";
                return false;
            }
            if (!addTextures(texdir)) { // Recursive compress and copy
                return false;
            }
        } else if (line.first() == LOD_FIELD) {
            QFileInfo lod(QFileInfo(fst).path() + "/" + line[1]);
            if (!lod.exists() || !lod.isFile()) { // Check existence
                qDebug() << "[ERROR] FBX file " << lod.absoluteFilePath() << " doesn't exist.";
                return false;
            }
            // Compress and copy
            if (!compressFile(lod.filePath(), _zipDir.path() + "/" + line[1])) {
                return false;
            }
            _totalSize += lod.size();
            if (!addPart(_zipDir.path() + "/" + line[1], QString("lod%1").arg(++_lodCount))) {
                return false;
            }
        }
    }
    
    _readyToSend = true;
    return true;
}