void  Compression::compressedFile(const char *file)
{
  std::ofstream				destFile;
  std::string				destFileName(file);
  std::map<char, std::string>::iterator it;
  std::map<char, int>::iterator		it2;

  destFileName += ".tar.gz";
  destFile.open(destFileName.c_str());
  if (destFile.bad())
    std::cerr << "Error creating compressed file" << std::endl;
  else
  {
    // Taille du fichier
    intToStruct(this->_fileSize, &destFile);
    // Nombre de caracteres differents
    intToStruct(this->_tabCode.size(), &destFile);
    // Table des occurences
    for (it2 = this->_tabOcc.begin(); it2 != this->_tabOcc.end(); ++it2)
    {
      destFile << (*it2).first;
      intToStruct((*it2).second, &destFile);
    }

    binToChar(&destFile, file);
  }
  destFile.close();
}
OSFileName GetDestFileName( const OSFileName& srcFileName, ConstCharPtr& extension )
{
	OSFileName	destFileName( srcFileName );
	destFileName.StripFileExtension();
	destFileName += extension;
	return destFileName;
}
Exemple #3
0
void ParRenamer::RenameBadParFiles()
{
	for (CString& parFilename : m_badParList)
	{
		BString<1024> destFileName("%s.bad", *parFilename);
		RenameFile(parFilename, destFileName);
	}
}
void  Decompression::readFile(const char *file)
{
  std::ofstream  destFile;
  //string  destFileName(file);
  std::string  destFileName("decompressedFile.txt");
  FILE  *pFile;
  Node  *firstIt;
  char  c;
  unsigned short  res;
  unsigned int mask;

  //destFileName = destFileName.substr(0, destFileName.size() - 7);
  destFile.open(destFileName.c_str());
  if (destFile.bad())
    std::cerr << "Error creating decompressed file" << std::endl;
  else
    {
      pFile = fopen(file, "r");
      if (pFile == NULL)
	std::cerr << "Error opening file" << std::endl;
      else
	{
	  fileSize(pFile);
	  createTabOcc(pFile);

	  triToList();
	  generateTree();
	  firstIt = this->_items.front();

	  res = (fgetc(pFile));
	  res = res << 8;
	  c = fgetc(pFile);
	  mask = 32768;
	  res += (unsigned char)c;
	  while (this->_fileSize > 0)
	    {
	      destFile << getChar(firstIt, res, mask);
	      this->_fileSize--;
	      if (mask < 256)
		{
		  mask = mask * 256;
		  res = res << 8;
		  c = fgetc(pFile);
		  res += (unsigned char)c;
		}
	    }
	  fclose(pFile);
	}
      destFile.close();
    }
}
static void export_vrml_module( MODEL_VRML& aModel, BOARD* aPcb, MODULE* aModule,
                                std::ofstream& aOutputFile, double aVRMLModelsToBiu,
                                bool aExport3DFiles, bool aUseRelativePaths,
                                const wxString& a3D_Subdir )
{
    // Reference and value
    if( aModule->Reference().IsVisible() )
        export_vrml_text_module( &aModule->Reference() );

    if( aModule->Value().IsVisible() )
        export_vrml_text_module( &aModule->Value() );

    // Export module edges
    for( EDA_ITEM* item = aModule->GraphicalItems(); item; item = item->Next() )
    {
        switch( item->Type() )
        {
        case PCB_MODULE_TEXT_T:
            export_vrml_text_module( static_cast<TEXTE_MODULE*>( item ) );
            break;

        case PCB_MODULE_EDGE_T:
            export_vrml_edge_module( aModel, static_cast<EDGE_MODULE*>( item ),
                                     aModule->GetOrientation() );
            break;

        default:
            break;
        }
    }

    // Export pads
    for( D_PAD* pad = aModule->Pads(); pad; pad = pad->Next() )
        export_vrml_pad( aModel, aPcb, pad );

    bool isFlipped = aModule->GetLayer() == B_Cu;

    // Export the object VRML model(s)
    for( S3D_MASTER* vrmlm = aModule->Models();  vrmlm;  vrmlm = vrmlm->Next() )
    {
        if( !vrmlm->Is3DType( S3D_MASTER::FILE3D_VRML ) )
            continue;

        wxFileName modelFileName = vrmlm->GetShape3DFullFilename();
        wxFileName destFileName( a3D_Subdir, modelFileName.GetName(), modelFileName.GetExt() );

        // Only copy VRML files.
        if( modelFileName.FileExists() && modelFileName.GetExt() == wxT( "wrl" ) )
        {
            if( aExport3DFiles )
            {
                wxDateTime srcModTime = modelFileName.GetModificationTime();
                wxDateTime destModTime = srcModTime;

                destModTime.SetToCurrent();

                if( destFileName.FileExists() )
                    destModTime = destFileName.GetModificationTime();

                // Only copy the file if it doesn't exist or has been modified.  This eliminates
                // the redundant file copies.
                if( srcModTime != destModTime )
                {
                    wxLogDebug( wxT( "Copying 3D model %s to %s." ),
                                GetChars( modelFileName.GetFullPath() ),
                                GetChars( destFileName.GetFullPath() ) );

                    if( !wxCopyFile( modelFileName.GetFullPath(), destFileName.GetFullPath() ) )
                        continue;
                }
            }

            /* Calculate 3D shape rotation:
             * this is the rotation parameters, with an additional 180 deg rotation
             * for footprints that are flipped
             * When flipped, axis rotation is the horizontal axis (X axis)
             */
            double rotx = -vrmlm->m_MatRotation.x;
            double roty = -vrmlm->m_MatRotation.y;
            double rotz = -vrmlm->m_MatRotation.z;

            if( isFlipped )
            {
                rotx += 180.0;
                NEGATE( roty );
                NEGATE( rotz );
            }

            // Do some quaternion munching
            double q1[4], q2[4], rot[4];
            build_quat( 1, 0, 0, DEG2RAD( rotx ), q1 );
            build_quat( 0, 1, 0, DEG2RAD( roty ), q2 );
            compose_quat( q1, q2, q1 );
            build_quat( 0, 0, 1, DEG2RAD( rotz ), q2 );
            compose_quat( q1, q2, q1 );

            // Note here aModule->GetOrientation() is in 0.1 degrees,
            // so module rotation has to be converted to radians
            build_quat( 0, 0, 1, DECIDEG2RAD( aModule->GetOrientation() ), q2 );
            compose_quat( q1, q2, q1 );
            from_quat( q1, rot );

            aOutputFile << "Transform {\n";

            // A null rotation would fail the acos!
            if( rot[3] != 0.0 )
            {
                aOutputFile << "  rotation " << std::setprecision( 3 );
                aOutputFile << rot[0] << " " << rot[1] << " " << rot[2] << " " << rot[3] << "\n";
            }

            // adjust 3D shape local offset position
            // they are given in inch, so they are converted in board IU.
            double offsetx = vrmlm->m_MatPosition.x * IU_PER_MILS * 1000.0;
            double offsety = vrmlm->m_MatPosition.y * IU_PER_MILS * 1000.0;
            double offsetz = vrmlm->m_MatPosition.z * IU_PER_MILS * 1000.0;

            if( isFlipped )
                NEGATE( offsetz );
            else // In normal mode, Y axis is reversed in Pcbnew.
                NEGATE( offsety );

            RotatePoint( &offsetx, &offsety, aModule->GetOrientation() );

            aOutputFile << "  translation " << std::setprecision( aModel.precision );
            aOutputFile << ( ( offsetx + aModule->GetPosition().x ) *
                             aModel.scale + aModel.tx ) << " ";
            aOutputFile << ( -(offsety + aModule->GetPosition().y) *
                             aModel.scale - aModel.ty ) << " ";
            aOutputFile << ( (offsetz * aModel.scale ) +
                             aModel.GetLayerZ( aModule->GetLayer() ) ) << "\n";
            aOutputFile << "  scale ";
            aOutputFile << ( vrmlm->m_MatScale.x * aVRMLModelsToBiu ) << " ";
            aOutputFile << ( vrmlm->m_MatScale.y * aVRMLModelsToBiu ) << " ";
            aOutputFile << ( vrmlm->m_MatScale.z * aVRMLModelsToBiu ) << "\n";
            aOutputFile << "  children [\n    Inline {\n      url \"";

            if( aUseRelativePaths )
            {
                wxFileName tmp = destFileName;
                tmp.SetExt( wxT( "" ) );
                tmp.SetName( wxT( "" ) );
                tmp.RemoveLastDir();
                destFileName.MakeRelativeTo( tmp.GetPath() );
            }

            wxString fn = destFileName.GetFullPath();
            fn.Replace( wxT( "\\" ), wxT( "/" ) );
            aOutputFile << TO_UTF8( fn ) << "\"\n    } ]\n";
            aOutputFile << "  }\n";
        }
    }
}
Exemple #6
0
QString MyImageListViewItem::destPath() const
{
    QString path = url().directory() + QString("/") + destFileName();
    return path;
}