442be307379469d87a91c4ec8bd0489b7e2b613d
[occt.git] / src / Aspect / Aspect_MarkMap.cxx
1 // Created on: 1995-01-14
2 // Created by: GG
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22
23 //-Version
24
25 //-Design       Declaration des variables specifiques aux Ensembles
26 //              de Markers
27
28 //-Warning      Une MarkMap est definie par un ensemble de MarkMapEntries
29
30 //-References
31
32 //-Language     C++ 2.0
33
34 //-Declarations
35
36 // for the class
37 #include <Aspect_MarkMap.ixx>
38
39 //-Aliases
40
41 //-Global data definitions
42
43 //      mydata       : SequenceOfMarkMapEntry from Aspect is protected
44
45 //-Constructors
46
47 //-Destructors
48
49 //-Methods, in order
50
51 Aspect_MarkMap::Aspect_MarkMap( ) {
52 Aspect_MarkMapEntry theDefaultEntry;
53
54         AddEntry(theDefaultEntry);
55 }
56
57 void Aspect_MarkMap::AddEntry (const Aspect_MarkMapEntry& AnEntry) {
58 Standard_Integer i,index = AnEntry.Index();
59 Aspect_MarkMapEntry theEntry;
60
61         for( i=1 ; i<=mydata.Length() ; i++ ) {
62             theEntry = mydata.Value(i);
63             if( index == theEntry.Index() ) break;
64         }
65
66         if( i > mydata.Length() ) { 
67             mydata.Append( AnEntry );
68         } else {
69             mydata.SetValue(i,AnEntry);
70         }
71 }
72
73 Standard_Integer Aspect_MarkMap::AddEntry (const Aspect_MarkerStyle &aStyle) {
74 Aspect_MarkMapEntry theEntry ;
75 Standard_Integer i,maxindex = 0 ;
76  
77     for( i=1 ; i<=mydata.Length() ; i++ ) {
78         theEntry = mydata.Value(i) ;
79         maxindex = Max(maxindex,theEntry.Index()) ;
80         if( theEntry.Style() == aStyle ) return theEntry.Index() ;
81     }
82  
83     maxindex++ ;
84     theEntry.SetValue(maxindex,aStyle) ;
85     mydata.Append( theEntry ) ;
86     return maxindex ;
87 }
88
89 Standard_Integer     Aspect_MarkMap::Size() const {
90
91         return mydata.Length() ;
92 }
93
94 Standard_Integer     Aspect_MarkMap::Index(const Standard_Integer anIndex) const {
95
96         if( anIndex < 1 || anIndex > Size() ) {
97             Aspect_BadAccess::Raise ("Undefined markmap Index");
98         }
99
100         Aspect_MarkMapEntry theEntry = mydata.Value(anIndex) ;
101
102         return theEntry.Index() ;
103 }
104
105 Aspect_MarkMapEntry Aspect_MarkMap::Entry (const Standard_Integer AnIndex) const {
106
107         if( AnIndex < 1 || AnIndex > mydata.Length() )
108                 Aspect_BadAccess::Raise ("Aspect_MarkMap::Entry Bad Index");
109
110         return mydata.Value(AnIndex);
111 }
112
113 void Aspect_MarkMap::Dump () const {
114
115   Standard_Integer i ;
116
117   cout << "Markmap Dump-->\n" ;
118
119   for ( i = 1 ; i <= Size() ; i++ ) (Entry(i)).Dump() ;
120
121   cout << "<--End Markmap Dump\n" ;
122 }