AC3DsurfaceFormatCore.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "AC3DsurfaceFormatCore.H"
27 #include "clock.H"
28 #include "IFstream.H"
29 #include "IStringStream.H"
30 
31 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
32 
34 (
35  IFstream& is,
36  string& cmd,
37  string& args
38 )
39 {
40  if (is.good())
41  {
42  string line;
43  is.getLine(line);
44 
45  string::size_type space = line.find(' ');
46 
47  if (space != string::npos)
48  {
49  cmd = line.substr(0, space);
50  args = line.substr(space+1);
51 
52  return true;
53  }
54  }
55  return false;
56 }
57 
58 
59 // Read up to line starting with cmd. Sets args to rest of line.
60 // Returns true if found, false if stream is not good anymore.
62 (
63  IFstream& is,
64  const string& cmd,
65  string& args
66 )
67 {
68  while (is.good())
69  {
70  string line;
71  is.getLine(line);
72 
73  string::size_type space = line.find(' ');
74 
75  if (space != string::npos)
76  {
77  if (line.substr(0, space) == cmd)
78  {
79  args = line.substr(space+1);
80 
81  return true;
82  }
83  }
84  }
85  return false;
86 }
87 
88 
89 // Similar to cueTo(), but throws error if cmd not found
91 (
92  IFstream& is,
93  const string& cmd,
94  const string& errorMsg
95 )
96 {
97  string args;
98  if (!cueTo(is, cmd, args))
99  {
101  << "Cannot find command " << cmd
102  << " " << errorMsg
103  << exit(FatalError);
104  }
105 
106  return args;
107 }
108 
109 
111 (
112  Ostream& os,
113  const UList<surfZone>& zoneLst
114 )
115 {
116  // Write with zones as separate objects under "world" object.
117  // Header is taken over from sample file.
118  // Defines separate materials for all zones. Recycle colours.
119 
120  // Define 8 standard colours as r,g,b components
121  static scalar colourMap[] =
122  {
123  1, 1, 1,
124  1, 0, 0,
125  0, 1, 0,
126  0, 0, 1,
127  1, 1, 0,
128  0, 1, 1,
129  1, 0, 1,
130  0.5, 0.5, 1
131  };
132 
133  // Write header. Define materials.
134  os << "AC3Db" << nl;
135 
136  forAll(zoneLst, zoneI)
137  {
138  label colourI = zoneI % 8;
139  label colourCompI = 3 * colourI;
140 
141  os << "MATERIAL \"" << zoneLst[zoneI].name() << "Mat\" rgb "
142  << colourMap[colourCompI] << ' ' << colourMap[colourCompI+1]
143  << ' ' << colourMap[colourCompI+2]
144  << " amb 0.2 0.2 0.2 emis 0 0 0 spec 0.5 0.5 0.5 shi 10"
145  << " trans 0"
146  << nl;
147  }
148 
149  os << "OBJECT world" << nl
150  << "kids " << zoneLst.size() << endl;
151 }
152 
153 
154 // ************************************************************************* //
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Input from file stream.
Definition: IFstream.H:85
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:330
ISstream & getLine(string &, const bool continuation=true)
Read line into a string.
Definition: ISstream.C:692
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:74
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311
static string cueToOrDie(IFstream &, const string &cmd, const string &errorMsg=string::null)
Cue up to cmd, reading args or exit with a FatalError.
static bool readCmd(IFstream &, string &cmd, string &args)
Read cmd, args from IFstream.
static bool cueTo(IFstream &, const string &cmd, string &args)
Cue up to cmd, reading args.
static void writeHeader(Ostream &, const UList< surfZone > &)
Write header with materials.
A line primitive.
Definition: line.H:71
A class for handling character strings derived from std::string.
Definition: string.H:79
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
error FatalError
static const char nl
Definition: Ostream.H:260
Foam::argList args(argc, argv)