Esempio n. 1
0
void GdmlWriter::writeStructures()
{
    _("  <structure>\n");

    int sz = names.size();
    for (int i = 0; i < sz; i++) {
        _("    <volume name=\"V-%s\">\n", convName(names[i]).data());
        _("      <materialref ref=\"%s\"/>\n", materials[i].toUtf8().data());
        _("      <solidref ref=\"T-%s\"/>\n", convName(names[i]).data());
        _("    </volume>\n");
    }

    _("    <volume name=\"World\">\n");
    _("      <materialref ref=\"VACUUM\"/>\n");
    _("      <solidref ref=\"worldbox\"/>\n");

    for (int i = 0; i < sz; i++) {
        _("      <physvol name=\"P-%s\">\n", convName(names[i]).data());
        _("        <volumeref ref=\"V-%s\"/>\n", convName(names[i]).data());
        _("        <positionref ref=\"center\"/>\n");
        _("      </physvol>\n");
    }

    _("    </volume>\n");

    _("  </structure>\n");
}
Esempio n. 2
0
void GdmlWriter::addSolid(TopoDS_Shape shape, QString name, QString material)
{
    Handle_Poly_CoherentTriangulation aMesh = triangulateShape(shape);

    _("  <define>\n");
    for (int i = 0; i < aMesh->NNodes(); i++) {
        const Poly_CoherentNode& vert = aMesh->Node(i);
        _("    <position name=\"%d\" x=\"%f\" y=\"%f\" z=\"%f\" unit=\"mm\"/>\n",
          i, vert.X(), vert.Y(), vert.Z());
    }
    _("  </define>\n");

    _("  <solids>\n");
    _("    <tessellated name=\"T-%s\">\n", convName(name).data());
    for (int i=0;i<aMesh->NTriangles();i++) {
        const Poly_CoherentTriangle& tri = aMesh->Triangle(i);
         _("      <triangular vertex1=\"%d\" vertex2=\"%d\" vertex3=\"%d\" type=\"ABSOLUTE\"/>\n",
              tri.Node(0), tri.Node(1), tri.Node(2));
    }
    _("    </tessellated>\n");
    _("  </solids>\n");

    names.append(name);
    materials.append(material);
    BRepBndLib::Add(shape, bounds);

    printf("% 6d vertices, % 6d triangles <- %s\n", aMesh->NNodes(), aMesh->NTriangles(),
           convName(name).data());
}
Esempio n. 3
0
    std::string fileToString(const std::string &fileName)
    {
        std::ifstream infile (fileName);
        if (infile.fail() ) {
#if defined( _WIN32 )
            TCHAR osPath[ MAX_PATH ];

            //	If loading the .cl file fails from the specified path, then make a last ditch attempt (purely for convenience) to find the .cl file right to the executable,
            //	regardless of what the CWD is
            //	::GetModuleFileName( ) returns TCHAR's (and we define _UNICODE for windows); but the fileName string is char's, 
            //	so we needed to create an abstraction for string/wstring
            if( ::GetModuleFileName( NULL, osPath, MAX_PATH ) )
            {
                bolt::tstring thisPath( osPath );
                bolt::tstring::size_type pos = thisPath.find_last_of( _T( "\\" ) );

                bolt::tstring newPath;
                if( pos != bolt::tstring::npos )
                {
                    bolt::tstring exePath	= thisPath.substr( 0, pos + 1 );	// include the \ character

                    //	Narrow to wide conversion should always work, but beware of wide to narrow!
                    bolt::tstring convName( fileName.begin( ), fileName.end( ) );
                    newPath = exePath + convName;
                }

                infile.open( newPath.c_str( ) );
            }
#endif
            if (infile.fail() ) {
                //  Note:  Commented out because this widestr not initialized yet if called from global scope
                //TCHAR cCurrentPath[FILENAME_MAX];
                //if (_tgetcwd(cCurrentPath, sizeof(cCurrentPath) / sizeof(TCHAR))) {
                //    bolt::tout <<  _T( "CWD=" ) << cCurrentPath << std::endl;
                //};
                std::cout << "error: failed to open file: " << fileName << std::endl;
                throw;
            } 
        }

        std::string str((std::istreambuf_iterator<char>(infile)),
            std::istreambuf_iterator<char>());
        return str;
    };