FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

AC3DsurfaceFormatCore.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "AC3DsurfaceFormatCore.H"
00027 #include <OpenFOAM/clock.H>
00028 #include <OpenFOAM/IFstream.H>
00029 #include <OpenFOAM/IStringStream.H>
00030 
00031 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00032 
00033 bool Foam::fileFormats::AC3DsurfaceFormatCore::readCmd
00034 (
00035     IFstream& is,
00036     string& cmd,
00037     string& args
00038 )
00039 {
00040     if (is.good())
00041     {
00042         string line;
00043         is.getLine(line);
00044 
00045         string::size_type space = line.find(' ');
00046 
00047         if (space != string::npos)
00048         {
00049             cmd  = line.substr(0, space);
00050             args = line.substr(space+1);
00051 
00052             return true;
00053         }
00054     }
00055     return false;
00056 }
00057 
00058 
00059 // Read up to line starting with cmd. Sets args to rest of line.
00060 // Returns true if found, false if stream is not good anymore.
00061 bool Foam::fileFormats::AC3DsurfaceFormatCore::cueTo
00062 (
00063     IFstream& is,
00064     const string& cmd,
00065     string& args
00066 )
00067 {
00068     while (is.good())
00069     {
00070         string line;
00071         is.getLine(line);
00072 
00073         string::size_type space = line.find(' ');
00074 
00075         if (space != string::npos)
00076         {
00077             if (line.substr(0, space) == cmd)
00078             {
00079                 args = line.substr(space+1);
00080 
00081                 return true;
00082             }
00083         }
00084     }
00085     return false;
00086 }
00087 
00088 
00089 // Similar to cueTo(), but throws error if cmd not found
00090 Foam::string Foam::fileFormats::AC3DsurfaceFormatCore::cueToOrDie
00091 (
00092     IFstream& is,
00093     const string& cmd,
00094     const string& errorMsg
00095 )
00096 {
00097     string args;
00098     if (!cueTo(is, cmd, args))
00099     {
00100         FatalErrorIn
00101         (
00102             "fileFormats::AC3DsurfaceFormat::read(const fileName&)"
00103         )
00104             << "Cannot find command " << cmd
00105             << " " << errorMsg
00106             << exit(FatalError);
00107     }
00108 
00109     return args;
00110 }
00111 
00112 
00113 void Foam::fileFormats::AC3DsurfaceFormatCore::writeHeader
00114 (
00115     Ostream& os,
00116     const UList<surfZone>& zoneLst
00117 )
00118 {
00119     // Write with zones as separate objects under "world" object.
00120     // Header is taken over from sample file.
00121     // Defines separate materials for all zones. Recycle colours.
00122 
00123     // Define 8 standard colours as r,g,b components
00124     static scalar colourMap[] =
00125     {
00126         1, 1, 1,
00127         1, 0, 0,
00128         0, 1, 0,
00129         0, 0, 1,
00130         1, 1, 0,
00131         0, 1, 1,
00132         1, 0, 1,
00133         0.5, 0.5, 1
00134     };
00135 
00136     // Write header. Define materials.
00137     os  << "AC3Db" << nl;
00138 
00139     forAll(zoneLst, zoneI)
00140     {
00141         label colourI = zoneI % 8;
00142         label colourCompI = 3 * colourI;
00143 
00144         os  << "MATERIAL \"" << zoneLst[zoneI].name() << "Mat\" rgb "
00145             << colourMap[colourCompI] << ' ' << colourMap[colourCompI+1]
00146             << ' ' << colourMap[colourCompI+2]
00147             << "  amb 0.2 0.2 0.2  emis 0 0 0  spec 0.5 0.5 0.5  shi 10"
00148             << "  trans 0"
00149             << nl;
00150     }
00151 
00152     os  << "OBJECT world" << nl
00153         << "kids " << zoneLst.size() << endl;
00154 }
00155 
00156 
00157 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines