Forward compatibility: flex
[foam-extend-3.2.git] / src / surfMesh / surfaceFormats / ac3d / AC3DsurfaceFormatCore.C
blob49eb691142f41707dac606dc662dbf72748c9348
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "objectRegistry.H"
27 #include "AC3DsurfaceFormatCore.H"
28 #include "clock.H"
29 #include "IFstream.H"
30 #include "IStringStream.H"
32 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
34 bool Foam::fileFormats::AC3DsurfaceFormatCore::readCmd
36     IFstream& is,
37     string& cmd,
38     string& args
41     if (is.good())
42     {
43         string line;
44         is.getLine(line);
46         string::size_type space = line.find(' ');
48         if (space != string::npos)
49         {
50             cmd  = line.substr(0, space);
51             args = line.substr(space+1);
53             return true;
54         }
55     }
56     return false;
60 // Read up to line starting with cmd. Sets args to rest of line.
61 // Returns true if found, false if stream is not good anymore.
62 bool Foam::fileFormats::AC3DsurfaceFormatCore::cueTo
64     IFstream& is,
65     const string& cmd,
66     string& args
69     while (is.good())
70     {
71         string line;
72         is.getLine(line);
74         string::size_type space = line.find(' ');
76         if (space != string::npos)
77         {
78             if (line.substr(0, space) == cmd)
79             {
80                 args = line.substr(space+1);
82                 return true;
83             }
84         }
85     }
86     return false;
90 // Similar to cueTo(), but throws error if cmd not found
91 Foam::string Foam::fileFormats::AC3DsurfaceFormatCore::cueToOrDie
93     IFstream& is,
94     const string& cmd,
95     const string& errorMsg
98     string args;
99     if (!cueTo(is, cmd, args))
100     {
101         FatalErrorIn
102         (
103             "fileFormats::AC3DsurfaceFormat::read(const fileName&)"
104         )
105             << "Cannot find command " << cmd
106             << " " << errorMsg
107             << exit(FatalError);
108     }
110     return args;
114 void Foam::fileFormats::AC3DsurfaceFormatCore::writeHeader
116     Ostream& os,
117     const UList<surfZone>& zoneLst
120     // Write with zones as separate objects under "world" object.
121     // Header is taken over from sample file.
122     // Defines separate materials for all zones. Recycle colours.
124     // Define 8 standard colours as r,g,b components
125     static scalar colourMap[] =
126     {
127         1, 1, 1,
128         1, 0, 0,
129         0, 1, 0,
130         0, 0, 1,
131         1, 1, 0,
132         0, 1, 1,
133         1, 0, 1,
134         0.5, 0.5, 1
135     };
137     // Write header. Define materials.
138     os  << "AC3Db" << nl;
140     forAll(zoneLst, zoneI)
141     {
142         label colourI = zoneI % 8;
143         label colourCompI = 3 * colourI;
145         os  << "MATERIAL \"" << zoneLst[zoneI].name() << "Mat\" rgb "
146             << colourMap[colourCompI] << ' ' << colourMap[colourCompI+1]
147             << ' ' << colourMap[colourCompI+2]
148             << "  amb 0.2 0.2 0.2  emis 0 0 0  spec 0.5 0.5 0.5  shi 10"
149             << "  trans 0"
150             << nl;
151     }
153     os  << "OBJECT world" << nl
154         << "kids " << zoneLst.size() << endl;
158 // ************************************************************************* //