4151c94d |
1 | // Author: Kirill Gavrilov |
2 | // Copyright (c) 2017-2019 OPEN CASCADE SAS |
3 | // |
4 | // This file is part of Open CASCADE Technology software library. |
5 | // |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
11 | // |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
14 | |
15 | #ifndef _RWObj_Tools_HeaderFile |
16 | #define _RWObj_Tools_HeaderFile |
17 | |
18 | #include <gp_XYZ.hxx> |
19 | #include <Graphic3d_Vec3.hxx> |
20 | #include <TCollection_AsciiString.hxx> |
21 | |
22 | //! Auxiliary tools for OBJ format parser. |
23 | namespace RWObj_Tools |
24 | { |
25 | //! Read 3 float values. |
26 | inline bool ReadVec3 (const char* thePos, |
27 | char*& theNext, |
28 | Graphic3d_Vec3& theVec) |
29 | { |
30 | const char* aPos = thePos; |
31 | theVec.x() = (float )Strtod (aPos, &theNext); |
32 | aPos = theNext; |
33 | theVec.y() = (float )Strtod (aPos, &theNext); |
34 | aPos = theNext; |
35 | theVec.z() = (float )Strtod (aPos, &theNext); |
36 | return aPos != theNext; |
37 | } |
38 | |
39 | //! Read 3 double values. |
40 | inline bool ReadVec3 (const char* thePos, |
41 | char*& theNext, |
42 | gp_XYZ& theVec) |
43 | { |
44 | const char* aPos = thePos; |
45 | theVec.SetX (Strtod (aPos, &theNext)); |
46 | aPos = theNext; |
47 | theVec.SetY (Strtod (aPos, &theNext)); |
48 | aPos = theNext; |
49 | theVec.SetZ (Strtod (aPos, &theNext)); |
50 | return aPos != theNext; |
51 | } |
52 | |
53 | //! Read string. |
54 | inline bool ReadName (const char* thePos, |
55 | TCollection_AsciiString& theName) |
56 | { |
57 | Standard_Integer aFrom = 0; |
58 | Standard_Integer aTail = (Standard_Integer )std::strlen (thePos) - 1; |
59 | if (aTail >= 0 && thePos[aTail] == '\n') { --aTail; } |
60 | if (aTail >= 0 && thePos[aTail] == '\r') { --aTail; } |
61 | for (; aTail >= 0 && IsSpace (thePos[aTail]); --aTail) {} // RightAdjust |
62 | for (; aFrom < aTail && IsSpace (thePos[aFrom]); ++aFrom) {} // LeftAdjust |
63 | if (aFrom > aTail) |
64 | { |
65 | theName.Clear(); |
66 | return false; |
67 | } |
68 | theName = TCollection_AsciiString (thePos + aFrom, aTail - aFrom + 1); |
69 | return true; |
70 | } |
71 | |
72 | //! Return true if specified char is a white space. |
73 | inline bool isSpaceChar (const char theChar) |
74 | { |
75 | return theChar == ' ' |
76 | || theChar == '\t'; |
77 | //return IsSpace (theChar); |
78 | } |
79 | } |
80 | |
81 | #endif // _RWObj_Tools_HeaderFile |