b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
973c2be1 |
6 | // This library is free software; you can redistribute it and / or modify it |
7 | // under the terms of the GNU Lesser General Public 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. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
7fd59977 |
14 | |
15 | #include <Aspect_WidthMap.ixx> |
16 | |
17 | Aspect_WidthMap::Aspect_WidthMap( ) { |
18 | Aspect_WidthMapEntry theDefaultEntry; |
19 | |
20 | AddEntry(theDefaultEntry); |
21 | } |
22 | |
23 | void Aspect_WidthMap::AddEntry (const Aspect_WidthMapEntry& AnEntry) { |
24 | Standard_Integer i,index = AnEntry.Index(); |
25 | Aspect_WidthMapEntry theEntry; |
26 | |
27 | for( i=1 ; i<=mydata.Length() ; i++ ) { |
28 | theEntry = mydata.Value(i); |
29 | if( index == theEntry.Index() ) break; |
30 | } |
31 | |
32 | if( i > mydata.Length() ) { |
33 | mydata.Append( AnEntry ); |
34 | } else { |
35 | mydata.SetValue(i,AnEntry); |
36 | } |
37 | } |
38 | |
39 | Standard_Integer Aspect_WidthMap::AddEntry (const Aspect_WidthOfLine aStyle) { |
40 | Aspect_WidthMapEntry theEntry ; |
41 | Standard_Integer i,maxindex = 0 ; |
42 | |
43 | for( i=1 ; i<=mydata.Length() ; i++ ) { |
44 | theEntry = mydata.Value(i) ; |
45 | maxindex = Max(maxindex,theEntry.Index()) ; |
46 | if( theEntry.Type() == aStyle ) return theEntry.Index() ; |
47 | } |
48 | |
49 | maxindex++ ; |
50 | theEntry.SetValue(maxindex,aStyle) ; |
51 | mydata.Append( theEntry ) ; |
52 | return maxindex ; |
53 | } |
54 | |
55 | Standard_Integer Aspect_WidthMap::AddEntry (const Quantity_Length aStyle) { |
56 | Aspect_WidthMapEntry theEntry ; |
57 | Standard_Integer i,maxindex = 0 ; |
58 | |
59 | for( i=1 ; i<=mydata.Length() ; i++ ) { |
60 | theEntry = mydata.Value(i) ; |
61 | maxindex = Max(maxindex,theEntry.Index()) ; |
62 | if( theEntry.Width() == aStyle ) return theEntry.Index() ; |
63 | } |
64 | |
65 | maxindex++ ; |
66 | theEntry.SetValue(maxindex,aStyle) ; |
67 | mydata.Append( theEntry ) ; |
68 | return maxindex ; |
69 | } |
70 | |
71 | Standard_Integer Aspect_WidthMap::Size() const { |
72 | |
73 | return mydata.Length() ; |
74 | } |
75 | |
76 | Standard_Integer Aspect_WidthMap::Index(const Standard_Integer anIndex) const { |
77 | |
78 | if( anIndex < 1 || anIndex > Size() ) { |
79 | Aspect_BadAccess::Raise ("Undefined widthmap Index"); |
80 | } |
81 | |
82 | Aspect_WidthMapEntry theEntry = mydata.Value(anIndex) ; |
83 | |
84 | return theEntry.Index() ; |
85 | } |
86 | |
87 | Aspect_WidthMapEntry Aspect_WidthMap::Entry (const Standard_Integer AnIndex) const { |
88 | |
89 | if( AnIndex < 1 || AnIndex > mydata.Length() ) |
90 | Aspect_BadAccess::Raise ("Aspect_WidthMap::Entry Bad Index"); |
91 | |
92 | return mydata.Value(AnIndex); |
93 | } |
94 | |
95 | void Aspect_WidthMap::Dump () const { |
96 | |
97 | Standard_Integer i ; |
98 | |
99 | cout << "Widthmap Dump-->\n" ; |
100 | |
101 | for ( i = 1 ; i <= Size() ; i++ ) (Entry(i)).Dump() ; |
102 | |
103 | cout << "<--End Widthmap Dump\n" ; |
104 | } |