OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "AC3DsurfaceFormatCore.H"
00028 #include "clock.H"
00029 #include "IFstream.H"
00030 #include "IStringStream.H"
00031 
00032 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00033 
00034 bool Foam::fileFormats::AC3DsurfaceFormatCore::readCmd
00035 (
00036     IFstream& is,
00037     string& cmd,
00038     string& args
00039 )
00040 {
00041     if (is.good())
00042     {
00043         string line;
00044         is.getLine(line);
00045 
00046         string::size_type space = line.find(' ');
00047 
00048         if (space != string::npos)
00049         {
00050             cmd  = line.substr(0, space);
00051             args = line.substr(space+1);
00052 
00053             return true;
00054         }
00055     }
00056     return false;
00057 }
00058 
00059 
00060 // Read up to line starting with cmd. Sets args to rest of line.
00061 // Returns true if found, false if stream is not good anymore.
00062 bool Foam::fileFormats::AC3DsurfaceFormatCore::cueTo
00063 (
00064     IFstream& is,
00065     const string& cmd,
00066     string& args
00067 )
00068 {
00069     while (is.good())
00070     {
00071         string line;
00072         is.getLine(line);
00073 
00074         string::size_type space = line.find(' ');
00075 
00076         if (space != string::npos)
00077         {
00078             if (line.substr(0, space) == cmd)
00079             {
00080                 args = line.substr(space+1);
00081 
00082                 return true;
00083             }
00084         }
00085     }
00086     return false;
00087 }
00088 
00089 
00090 // Similar to cueTo(), but throws error if cmd not found
00091 Foam::string Foam::fileFormats::AC3DsurfaceFormatCore::cueToOrDie
00092 (
00093     IFstream& is,
00094     const string& cmd,
00095     const string& errorMsg
00096 )
00097 {
00098     string args;
00099     if (!cueTo(is, cmd, args))
00100     {
00101         FatalErrorIn
00102         (
00103             "fileFormats::AC3DsurfaceFormat::read(const fileName&)"
00104         )
00105             << "Cannot find command " << cmd
00106             << " " << errorMsg
00107             << exit(FatalError);
00108     }
00109 
00110     return args;
00111 }
00112 
00113 
00114 void Foam::fileFormats::AC3DsurfaceFormatCore::writeHeader
00115 (
00116     Ostream& os,
00117     const UList<surfZone>& zoneLst
00118 )
00119 {
00120     // Write with zones as separate objects under "world" object.
00121     // Header is taken over from sample file.
00122     // Defines separate materials for all zones. Recycle colours.
00123 
00124     // Define 8 standard colours as r,g,b components
00125     static scalar colourMap[] =
00126     {
00127         1, 1, 1,
00128         1, 0, 0,
00129         0, 1, 0,
00130         0, 0, 1,
00131         1, 1, 0,
00132         0, 1, 1,
00133         1, 0, 1,
00134         0.5, 0.5, 1
00135     };
00136 
00137     // Write header. Define materials.
00138     os  << "AC3Db" << nl;
00139 
00140     forAll(zoneLst, zoneI)
00141     {
00142         label colourI = zoneI % 8;
00143         label colourCompI = 3 * colourI;
00144 
00145         os  << "MATERIAL \"" << zoneLst[zoneI].name() << "Mat\" rgb "
00146             << colourMap[colourCompI] << ' ' << colourMap[colourCompI+1]
00147             << ' ' << colourMap[colourCompI+2]
00148             << "  amb 0.2 0.2 0.2  emis 0 0 0  spec 0.5 0.5 0.5  shi 10"
00149             << "  trans 0"
00150             << nl;
00151     }
00152 
00153     os  << "OBJECT world" << nl
00154         << "kids " << zoneLst.size() << endl;
00155 }
00156 
00157 
00158 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd