b311480e |
1 | // Created by: CKY / Contract Toubro-Larsen |
2 | // Copyright (c) 1993-1999 Matra Datavision |
973c2be1 |
3 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
7fd59977 |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
7fd59977 |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
b311480e |
15 | |
16 | //-------------------------------------------------------------------- |
7fd59977 |
17 | //-------------------------------------------------------------------- |
18 | |
42cf5bc1 |
19 | #include <IGESGraph_LineFontDefPattern.hxx> |
7fd59977 |
20 | #include <Standard_DimensionMismatch.hxx> |
42cf5bc1 |
21 | #include <Standard_OutOfRange.hxx> |
22 | #include <Standard_Type.hxx> |
23 | #include <TCollection_HAsciiString.hxx> |
7fd59977 |
24 | |
92efcf78 |
25 | IMPLEMENT_STANDARD_RTTIEXT(IGESGraph_LineFontDefPattern,IGESData_LineFontEntity) |
26 | |
b311480e |
27 | IGESGraph_LineFontDefPattern::IGESGraph_LineFontDefPattern () { } |
7fd59977 |
28 | |
29 | |
30 | // This class inherits from IGESData_LineFontEntity |
31 | |
32 | void IGESGraph_LineFontDefPattern::Init |
33 | (const Handle(TColStd_HArray1OfReal)& allSegLength, |
34 | const Handle(TCollection_HAsciiString)& aPattern) |
35 | { |
36 | if (allSegLength->Lower() != 1) |
9775fa61 |
37 | throw Standard_DimensionMismatch("IGESGraph_LineFontDefPattern : Init"); |
7fd59977 |
38 | theSegmentLengths = allSegLength; |
39 | theDisplayPattern = aPattern; |
40 | InitTypeAndForm(304,2); |
41 | } |
42 | |
43 | Standard_Integer IGESGraph_LineFontDefPattern::NbSegments () const |
44 | { |
45 | return theSegmentLengths->Length(); |
46 | } |
47 | |
48 | Standard_Real IGESGraph_LineFontDefPattern::Length |
49 | (const Standard_Integer Index) const |
50 | { |
51 | return theSegmentLengths->Value(Index); |
52 | // if Index is out of bound HArray1 will raise OutOfRange exception |
53 | } |
54 | |
55 | Handle(TCollection_HAsciiString) IGESGraph_LineFontDefPattern::DisplayPattern |
56 | () const |
57 | { |
58 | return theDisplayPattern; |
59 | } |
60 | |
61 | Standard_Boolean IGESGraph_LineFontDefPattern::IsVisible |
62 | (const Standard_Integer Index) const |
63 | { |
64 | Standard_Integer nbSegs = theSegmentLengths->Length(); |
65 | if (Index <= 0 || Index > nbSegs) return Standard_False; |
66 | |
67 | // Get the Character out of String, which contains the required BIT |
68 | char tempStr[2]; |
69 | Standard_Integer length = theDisplayPattern->Length(); |
70 | tempStr[0] = theDisplayPattern->Value(length - ((nbSegs - Index) / 4)); |
71 | tempStr[1] = 0; |
72 | Standard_Integer tempVal = |
73 | (Standard_Integer) strtol(tempStr, (char **)NULL, 16); |
74 | // Now get the BIT out of tempVal |
75 | Standard_Integer mask = 0x01; |
76 | mask <<= ((nbSegs - Index) % 4); |
77 | return ((tempVal & mask) != 0); |
78 | } |