973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
42cf5bc1 |
14 | |
7fd59977 |
15 | #include <IGESData_IGESEntity.hxx> |
16 | #include <IGESGraph_Color.hxx> |
42cf5bc1 |
17 | #include <IGESSelect_SignColor.hxx> |
18 | #include <Interface_InterfaceModel.hxx> |
19 | #include <Interface_Macros.hxx> |
20 | #include <Standard_Transient.hxx> |
21 | #include <Standard_Type.hxx> |
7fd59977 |
22 | #include <TCollection_AsciiString.hxx> |
23 | #include <TCollection_HAsciiString.hxx> |
24 | |
92efcf78 |
25 | IMPLEMENT_STANDARD_RTTIEXT(IGESSelect_SignColor,IFSelect_Signature) |
26 | |
7fd59977 |
27 | static TCollection_AsciiString valbuf; // to prepare value and keep some time |
28 | |
29 | static Standard_CString ColName (const Standard_Integer mode) |
30 | { |
31 | switch (mode) { |
32 | case 2 : return "IGES Color Name"; |
33 | case 3 : return "IGES Color R,G,B"; |
34 | case 4 : return "IGES Color RED Value"; |
35 | case 5 : return "IGES Color GREEN Value"; |
36 | case 6 : return "IGES Color BLUE Value"; |
37 | default : return "IGES Color Number"; |
38 | } |
39 | } |
40 | |
41 | IGESSelect_SignColor::IGESSelect_SignColor (const Standard_Integer mode) |
42 | : IFSelect_Signature (ColName(mode)) , themode(mode) |
43 | { if (mode == 4 || mode == 5 || mode == 6) SetIntCase (Standard_True,0,Standard_True,0); } |
44 | |
45 | Standard_CString IGESSelect_SignColor::Value |
46 | (const Handle(Standard_Transient)& ent, |
47 | const Handle(Interface_InterfaceModel)& model) const |
48 | { |
49 | Standard_Real red = -1 , green = -1 , blue = -1; |
50 | DeclareAndCast(IGESData_IGESEntity,igesent,ent); |
51 | if (igesent.IsNull()) return ""; |
52 | Standard_Integer rank = igesent->RankColor(); |
53 | DeclareAndCast(IGESGraph_Color,color,igesent->Color()); |
54 | valbuf.Clear(); |
55 | |
56 | // Color Number |
57 | if (themode < 2 || themode > 6) { |
58 | if (rank == 0) return "(none)"; |
59 | if (rank > 0) { |
60 | valbuf.AssignCat ("S"); |
61 | valbuf.AssignCat (IFSelect_Signature::IntValue (rank)); |
62 | } else { |
63 | Standard_Integer num = (model.IsNull() ? 0 : 2 * model->Number(color) - 1); |
64 | valbuf.AssignCat ("D"); |
65 | valbuf.AssignCat (IFSelect_Signature::IntValue (num)); |
66 | } |
67 | |
68 | // Color Name |
69 | } else if (themode == 2) { |
70 | switch (rank) { |
71 | case 0 : return "(none)"; |
72 | case 1 : return "BLACK"; |
73 | case 2 : return "RED"; |
74 | case 3 : return "GREEN"; |
75 | case 4 : return "BLUE"; |
76 | case 5 : return "YELLOW"; |
77 | case 6 : return "MAGENTA"; |
78 | case 7 : return "CYAN"; |
79 | case 8 : return "WHITE"; |
80 | default : if (rank > 0) return "Unknown Number"; |
81 | } |
82 | Handle(TCollection_HAsciiString) name; |
83 | if (!color.IsNull()) name = color->ColorName(); |
84 | if (!name.IsNull()) return name->ToCString(); |
85 | Standard_Integer num = (model.IsNull() ? 0 : 2 * model->Number(color) - 1); |
86 | valbuf.AssignCat ("D"); |
87 | valbuf.AssignCat (IFSelect_Signature::IntValue (num)); |
88 | |
89 | // RGB |
90 | } else if (themode == 3) { |
91 | switch (rank) { |
92 | case 0 : return ""; |
93 | case 1 : return "0,0,0"; |
94 | case 2 : return "100,0,0"; |
95 | case 3 : return "0,100,0"; |
96 | case 4 : return "0,0,100"; |
97 | case 5 : return "100,100,0"; |
98 | case 6 : return "100,0,100"; |
99 | case 7 : return "0,100,100"; |
100 | case 8 : return "100,100,100"; |
101 | default : if (rank > 0) return ""; |
102 | } |
103 | if (!color.IsNull()) color->RGBIntensity (red,green,blue); |
104 | if (red >= 0) valbuf.AssignCat ( IFSelect_Signature::IntValue (int(red)) ); |
105 | valbuf.AssignCat (","); |
106 | if (green >= 0) valbuf.AssignCat (IFSelect_Signature::IntValue (int(green)) ); |
107 | valbuf.AssignCat (","); |
108 | if (blue >= 0) valbuf.AssignCat ( IFSelect_Signature::IntValue (int(blue)) ); |
109 | |
110 | // RED value |
111 | } else if (themode == 4) { |
112 | switch (rank) { |
113 | case 0 : return ""; |
114 | case 1 : return "0"; |
115 | case 2 : return "100"; |
116 | case 3 : return "0"; |
117 | case 4 : return "0"; |
118 | case 5 : return "100"; |
119 | case 6 : return "100"; |
120 | case 7 : return "0"; |
121 | case 8 : return "100"; |
122 | default : if (rank > 0) return ""; |
123 | } |
124 | if (!color.IsNull()) color->RGBIntensity (red,green,blue); |
125 | if (red >= 0) return IFSelect_Signature::IntValue (int(red)); |
126 | |
127 | // GREEN Value |
128 | } else if (themode == 5) { |
129 | switch (rank) { |
130 | case 0 : return ""; |
131 | case 1 : return "0"; |
132 | case 2 : return "0"; |
133 | case 3 : return "100"; |
134 | case 4 : return "0"; |
135 | case 5 : return "100"; |
136 | case 6 : return "0"; |
137 | case 7 : return "100"; |
138 | case 8 : return "100"; |
139 | default : if (rank > 0) return ""; |
140 | } |
141 | if (!color.IsNull()) color->RGBIntensity (red,green,blue); |
142 | if (green >= 0) return IFSelect_Signature::IntValue (int(green)); |
143 | |
144 | // BLUE Value |
145 | } else if (themode == 6) { |
146 | switch (rank) { |
147 | case 0 : return ""; |
148 | case 1 : return "0"; |
149 | case 2 : return "0"; |
150 | case 3 : return "0"; |
151 | case 4 : return "100"; |
152 | case 5 : return "0"; |
153 | case 6 : return "100"; |
154 | case 7 : return "100"; |
155 | case 8 : return "100"; |
156 | default : if (rank > 0) return ""; |
157 | } |
158 | if (!color.IsNull()) color->RGBIntensity (red,green,blue); |
159 | if (blue >= 0) return IFSelect_Signature::IntValue (int(blue)); |
160 | } |
161 | |
162 | return valbuf.ToCString(); |
163 | } |