Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2000-08-04 |
2 | // Created by: Pavel TELKOV | |
973c2be1 | 3 | // Copyright (c) 2000-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
973c2be1 | 7 | // This library is free software; you can redistribute it and / or modify it |
8 | // under the terms of the GNU Lesser General Public version 2.1 as published | |
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. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
b311480e | 15 | |
7fd59977 | 16 | #include <XDEDRAW_Colors.ixx> |
17 | ||
91322f44 | 18 | #include <Draw.hxx> |
7fd59977 | 19 | #include <DBRep.hxx> |
20 | #include <DDocStd.hxx> | |
21 | ||
22 | #include <TCollection_AsciiString.hxx> | |
23 | #include <TopoDS_Shape.hxx> | |
24 | #include <Quantity_Color.hxx> | |
25 | ||
26 | #include <TDF_Tool.hxx> | |
27 | #include <TDF_Label.hxx> | |
28 | #include <TDF_LabelSequence.hxx> | |
29 | #include <TDocStd_Document.hxx> | |
30 | ||
31 | #include <XCAFDoc_DocumentTool.hxx> | |
32 | #include <XCAFDoc_ShapeTool.hxx> | |
33 | #include <XCAFDoc_ColorTool.hxx> | |
34 | ||
35 | //======================================================================= | |
36 | // Section: Work with colors | |
37 | //======================================================================= | |
38 | ||
39 | static Standard_Integer setColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
40 | { | |
3c946c38 | 41 | if (argc < 6) { |
7fd59977 | 42 | di<<"Use: "<<argv[0]<<" Doc {Label|Shape} R G B [curve|surf]"<<"\n"; |
43 | return 1; | |
44 | } | |
45 | Handle(TDocStd_Document) Doc; | |
46 | DDocStd::GetDocument(argv[1], Doc); | |
47 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } | |
48 | ||
49 | TDF_Label aLabel; | |
50 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); | |
91322f44 | 51 | Quantity_Color Col ( Draw::Atof(argv[3]), Draw::Atof(argv[4]), Draw::Atof(argv[5]), Quantity_TOC_RGB ); |
7fd59977 | 52 | |
53 | Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main()); | |
3c946c38 | 54 | const XCAFDoc_ColorType ctype = ( argc <= 6 ? XCAFDoc_ColorGen : ( argv[6][0] == 's' ? XCAFDoc_ColorSurf : XCAFDoc_ColorCurv ) ); |
7fd59977 | 55 | if ( !aLabel.IsNull() ) { |
56 | myColors->SetColor ( aLabel, Col, ctype ); | |
57 | } | |
58 | else { | |
59 | TopoDS_Shape aShape= DBRep::Get(argv[2]); | |
60 | if ( !aShape.IsNull() ) { | |
61 | myColors->SetColor ( aShape, Col, ctype ); | |
62 | } | |
63 | } | |
64 | return 0; | |
65 | } | |
66 | ||
67 | static Standard_Integer getColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
68 | { | |
69 | if (argc!=3) { | |
70 | di<<"Use: "<<argv[0]<<" Doc Label"<<"\n"; | |
71 | return 1; | |
72 | } | |
73 | Handle(TDocStd_Document) Doc; | |
74 | DDocStd::GetDocument(argv[1], Doc); | |
75 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } | |
76 | ||
77 | TDF_Label aLabel; | |
78 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); | |
79 | Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main()); | |
80 | Quantity_Color col; | |
81 | if ( !myColors->GetColor(aLabel, col) ) return 0; | |
82 | ||
83 | di << col.StringName ( col.Name() ); | |
84 | ||
85 | return 0; | |
86 | } | |
87 | ||
88 | static Standard_Integer getShapeColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
89 | { | |
3c946c38 | 90 | if (argc < 3) { |
91 | di<<"Use: "<<argv[0]<<" Doc Label [curve|surf]"<<"\n"; | |
7fd59977 | 92 | return 1; |
93 | } | |
94 | Handle(TDocStd_Document) Doc; | |
95 | DDocStd::GetDocument(argv[1], Doc); | |
96 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } | |
97 | ||
98 | TDF_Label aLabel; | |
99 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); | |
3c946c38 | 100 | if ( aLabel.IsNull() ) { |
101 | di << " no such label in document\n"; | |
102 | return 1; | |
103 | } | |
104 | ||
7fd59977 | 105 | Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main()); |
3c946c38 | 106 | const XCAFDoc_ColorType ctype = ( argc <= 3 ? XCAFDoc_ColorGen : ( argv[3][0] == 's' ? XCAFDoc_ColorSurf : XCAFDoc_ColorCurv ) ); |
107 | ||
7fd59977 | 108 | Quantity_Color col; |
3c946c38 | 109 | if ( !myColors->GetColor(aLabel, ctype, col) ) return 0; |
110 | ||
7fd59977 | 111 | TCollection_AsciiString Entry; |
112 | Entry = col.StringName ( col.Name() ); | |
113 | di << Entry.ToCString(); | |
3c946c38 | 114 | |
7fd59977 | 115 | return 0; |
116 | } | |
117 | ||
118 | static Standard_Integer getAllColors (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
119 | { | |
120 | if (argc!=2) { | |
121 | di<<"Use: "<<argv[0]<<" Doc "<<"\n"; | |
122 | return 1; | |
123 | } | |
124 | Handle(TDocStd_Document) Doc; | |
125 | DDocStd::GetDocument(argv[1], Doc); | |
126 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } | |
127 | ||
128 | TDF_Label aLabel; | |
129 | Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main()); | |
130 | Quantity_Color col; | |
131 | TDF_LabelSequence Labels; | |
132 | myColors->GetColors(Labels); | |
133 | if (Labels.Length() >= 1) { | |
134 | for ( Standard_Integer i = 1; i<= Labels.Length(); i++) { | |
135 | aLabel = Labels.Value(i); | |
136 | if ( !myColors->GetColor(aLabel, col) ) continue; | |
137 | di << col.StringName ( col.Name() ); | |
138 | di << " "; | |
139 | } | |
140 | } | |
141 | return 0; | |
142 | } | |
143 | ||
144 | ||
145 | static Standard_Integer addColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
146 | { | |
147 | if (argc!=5) { | |
148 | di<<"Use: "<<argv[0]<<" DocName R G B"<<"\n"; | |
149 | return 1; | |
150 | } | |
151 | Handle(TDocStd_Document) Doc; | |
152 | DDocStd::GetDocument(argv[1], Doc); | |
153 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } | |
154 | ||
155 | TDF_Label aLabel; | |
156 | Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main()); | |
157 | ||
91322f44 | 158 | Quantity_Color Col ( Draw::Atof(argv[2]), Draw::Atof(argv[3]), Draw::Atof(argv[4]), Quantity_TOC_RGB ); |
7fd59977 | 159 | aLabel = myColors->AddColor(Col); |
160 | ||
161 | TCollection_AsciiString Entry; | |
162 | TDF_Tool::Entry(aLabel, Entry); | |
163 | di << Entry.ToCString(); | |
164 | return 0; | |
165 | } | |
166 | ||
167 | static Standard_Integer removeColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
168 | { | |
169 | if (argc!=3) { | |
170 | di<<"Use: "<<argv[0]<<" DocName Label"<<"\n"; | |
171 | return 1; | |
172 | } | |
173 | Handle(TDocStd_Document) Doc; | |
174 | DDocStd::GetDocument(argv[1], Doc); | |
175 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } | |
176 | ||
177 | TDF_Label aLabel; | |
178 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); | |
179 | Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main()); | |
180 | myColors->RemoveColor(aLabel); | |
181 | ||
182 | return 0; | |
183 | } | |
184 | ||
185 | static Standard_Integer findColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
186 | { | |
187 | if (argc!=5) { | |
188 | di<<"Use: "<<argv[0]<<" DocName R G B"<<"\n"; | |
189 | return 1; | |
190 | } | |
191 | Handle(TDocStd_Document) Doc; | |
192 | DDocStd::GetDocument(argv[1], Doc); | |
193 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } | |
194 | ||
195 | Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main()); | |
196 | ||
91322f44 | 197 | Quantity_Color Col ( Draw::Atof(argv[2]), Draw::Atof(argv[3]), Draw::Atof(argv[4]), Quantity_TOC_RGB ); |
7fd59977 | 198 | |
199 | TCollection_AsciiString Entry; | |
200 | TDF_Tool::Entry(myColors->FindColor(Col), Entry); | |
201 | di << Entry.ToCString(); | |
202 | return 0; | |
203 | } | |
204 | ||
205 | static Standard_Integer unsetColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
206 | { | |
207 | if (argc!=4) { | |
208 | di<<"Use: "<<argv[0]<<" DocName {Label|Shape} ColorType"<<"\n"; | |
209 | return 1; | |
210 | } | |
211 | Handle(TDocStd_Document) Doc; | |
212 | DDocStd::GetDocument(argv[1], Doc); | |
213 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } | |
214 | ||
215 | TDF_Label aLabel; | |
216 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); | |
217 | Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main()); | |
218 | if ( !aLabel.IsNull() ) { | |
219 | myColors->UnSetColor(aLabel, argv[3][0] == 's' ? XCAFDoc_ColorSurf : XCAFDoc_ColorCurv); | |
220 | } | |
221 | TopoDS_Shape aShape= DBRep::Get(argv[2]); | |
222 | if ( !aShape.IsNull() ) { | |
223 | myColors->UnSetColor(aShape, argv[3][0] == 's' ? XCAFDoc_ColorSurf : XCAFDoc_ColorCurv); | |
224 | } | |
225 | return 0; | |
226 | } | |
227 | ||
228 | static Standard_Integer setVisibility (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
229 | { | |
230 | if (argc<3) { | |
231 | di<<"Use: "<<argv[0]<<"DocName {Lable|Shape} [isvisible(1/0)]"<<"\n"; | |
232 | return 1; | |
233 | } | |
234 | Handle(TDocStd_Document) Doc; | |
235 | DDocStd::GetDocument(argv[1], Doc); | |
236 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } | |
237 | Handle(XCAFDoc_ColorTool) localTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main()); | |
238 | Standard_Boolean isvisible = Standard_False; | |
91322f44 | 239 | if ( (argc==4) && (Draw::Atoi(argv[3])==1) ) isvisible = Standard_True; |
7fd59977 | 240 | |
241 | TDF_Label aLabel; | |
242 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); | |
243 | if ( aLabel.IsNull() ) { | |
244 | // get label by shape | |
245 | TopoDS_Shape aShape= DBRep::Get(argv[2]); | |
246 | if ( !aShape.IsNull() ) { | |
247 | aLabel = localTool->ShapeTool()->FindShape( aShape, Standard_True ); | |
248 | } | |
249 | } | |
250 | if ( aLabel.IsNull() ) { | |
251 | di << " cannot find indicated label in document" << "\n"; | |
252 | return 1; | |
253 | } | |
254 | localTool->SetVisibility( aLabel, isvisible ); | |
255 | return 0; | |
256 | } | |
257 | ||
258 | static Standard_Integer getVisibility (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
259 | { | |
260 | if (argc<3) { | |
261 | di<<"Use: "<<argv[0]<<"DocName {Lable|Shape}"<<"\n"; | |
262 | return 1; | |
263 | } | |
264 | Handle(TDocStd_Document) Doc; | |
265 | DDocStd::GetDocument(argv[1], Doc); | |
266 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } | |
267 | Handle(XCAFDoc_ColorTool) localTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main()); | |
268 | TDF_Label aLabel; | |
269 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); | |
270 | if ( aLabel.IsNull() ) { | |
271 | // get label by shape | |
272 | TopoDS_Shape aShape= DBRep::Get(argv[2]); | |
273 | if ( !aShape.IsNull() ) { | |
274 | aLabel = localTool->ShapeTool()->FindShape( aShape, Standard_True ); | |
275 | } | |
276 | } | |
277 | if ( aLabel.IsNull() ) { | |
278 | di << " cannot find indicated label in document" << "\n"; | |
279 | return 1; | |
280 | } | |
281 | if (localTool->IsVisible( aLabel) ) di << 1; | |
282 | else di << 0; | |
283 | return 0; | |
284 | } | |
285 | ||
286 | static Standard_Integer getStyledVisibility (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
287 | { | |
288 | if (argc<3) { | |
289 | di<<"Use: "<<argv[0]<<"DocName Shape"<<"\n"; | |
290 | return 1; | |
291 | } | |
292 | Handle(TDocStd_Document) Doc; | |
293 | DDocStd::GetDocument(argv[1], Doc); | |
294 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } | |
295 | Handle(XCAFDoc_ColorTool) localTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main()); | |
296 | TopoDS_Shape aShape; | |
297 | aShape = DBRep::Get(argv[2]); | |
298 | if (localTool->IsInstanceVisible( aShape) ) di << 1; | |
299 | else di << 0; | |
300 | return 0; | |
301 | } | |
302 | ||
303 | static Standard_Integer getStyledcolor (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
304 | { | |
305 | if (argc<3) { | |
306 | di<<"Use: "<<argv[0]<<" Doc shape colortype(s/c)"<<"\n"; | |
307 | return 1; | |
308 | } | |
309 | Handle(TDocStd_Document) Doc; | |
310 | DDocStd::GetDocument(argv[1], Doc); | |
311 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } | |
312 | TopoDS_Shape aShape; | |
313 | aShape = DBRep::Get(argv[2]); | |
314 | ||
315 | Quantity_Color col; | |
316 | XCAFDoc_ColorType type; | |
317 | if ( argv[3] && argv[3][0] == 's' ) | |
318 | type = XCAFDoc_ColorSurf; | |
319 | else if ( argv[3] && argv[3][0] == 'c' ) | |
320 | type = XCAFDoc_ColorCurv; | |
321 | else | |
322 | type = XCAFDoc_ColorGen; | |
323 | Handle(XCAFDoc_ColorTool) localTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main()); | |
324 | if (localTool->GetInstanceColor( aShape, type, col) ) | |
325 | { | |
326 | TCollection_AsciiString Entry; | |
327 | Entry = col.StringName ( col.Name() ); | |
328 | di << Entry.ToCString(); | |
329 | } | |
330 | return 0; | |
331 | } | |
332 | ||
333 | static Standard_Integer setStyledcolor (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
334 | { | |
335 | if (argc<6) { | |
336 | di<<"Use: "<<argv[0]<<" Doc shape R G B type(s/c)"<<"\n"; | |
337 | return 1; | |
338 | } | |
339 | Handle(TDocStd_Document) Doc; | |
340 | DDocStd::GetDocument(argv[1], Doc); | |
341 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } | |
342 | TopoDS_Shape aShape; | |
343 | aShape = DBRep::Get(argv[2]); | |
344 | ||
91322f44 | 345 | Quantity_Color col ( Draw::Atof(argv[3]), Draw::Atof(argv[4]), Draw::Atof(argv[5]), Quantity_TOC_RGB ); |
7fd59977 | 346 | XCAFDoc_ColorType type; |
347 | if ( argv[6] && argv[6][0] == 's' ) | |
348 | type = XCAFDoc_ColorSurf; | |
349 | else if ( argv[6] && argv[6][0] == 'c' ) | |
350 | type = XCAFDoc_ColorCurv; | |
351 | else | |
352 | type = XCAFDoc_ColorGen; | |
353 | Handle(XCAFDoc_ColorTool) localTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main()); | |
354 | if (!localTool->SetInstanceColor( aShape, type, col) ) | |
355 | { | |
356 | di << "cannot set color for the indicated component" << "\n"; | |
357 | return 1; | |
358 | } | |
359 | return 0; | |
360 | } | |
361 | ||
362 | //======================================================================= | |
363 | //function : InitCommands | |
364 | //purpose : | |
365 | //======================================================================= | |
366 | ||
367 | void XDEDRAW_Colors::InitCommands(Draw_Interpretor& di) | |
368 | { | |
369 | ||
370 | static Standard_Boolean initactor = Standard_False; | |
371 | if (initactor) return; initactor = Standard_True; | |
372 | ||
373 | //===================================== | |
374 | // Work with colors | |
375 | //===================================== | |
376 | ||
377 | Standard_CString g = "XDE color's commands"; | |
378 | ||
ec99ba32 G |
379 | di.Add ("XSetColor","Doc {Label|Shape} R G B [c|s]\t: Set color [R G B] to shape given by Label, " |
380 | "type of color 's' - for surface, 'c' - for curve (default generic)", | |
7fd59977 | 381 | __FILE__, setColor, g); |
382 | ||
383 | di.Add ("XGetColor","Doc label \t: Return color defined on label in colortable", | |
384 | __FILE__, getColor, g); | |
385 | ||
386 | di.Add ("XGetShapeColor","Doc Label ColorType \t: Returns color defined by label", | |
387 | __FILE__, getShapeColor, g); | |
388 | ||
389 | di.Add ("XGetAllColors","Doc \t: Print all colors that defined in document", | |
390 | __FILE__, getAllColors, g); | |
391 | ||
392 | di.Add ("XAddColor","Doc R G B \t: Add color in document to color table", | |
393 | __FILE__, addColor, g); | |
394 | ||
395 | di.Add ("XRemoveColor","Doc Label \t: Remove color in document from color table", | |
396 | __FILE__, removeColor, g); | |
397 | ||
398 | di.Add ("XFindColor","Doc R G B \t: Find label where indicated color is situated", | |
399 | __FILE__, findColor, g); | |
400 | ||
401 | di.Add ("XUnsetColor","Doc {Label|Shape} ColorType \t: Unset color ", | |
402 | __FILE__, unsetColor, g); | |
403 | ||
404 | di.Add ("XSetObjVisibility","Doc {Label|Shape} (0\1) \t: Set the visibility of shape ", | |
405 | __FILE__, setVisibility, g); | |
406 | ||
407 | di.Add ("XGetObjVisibility","Doc {Label|Shape} \t: Return the visibility of shape ", | |
408 | __FILE__, getVisibility, g); | |
409 | ||
410 | di.Add ("XGetInstanceVisible","Doc Shape \t: Return the visibility of shape ", | |
411 | __FILE__, getStyledVisibility, g); | |
412 | ||
413 | di.Add ("XGetInstanceColor","Doc Shape \t: Return the color of component shape ", | |
414 | __FILE__, getStyledcolor, g); | |
415 | ||
416 | di.Add ("XSetInstanceColor","Doc Shape color type \t: sets color for component of shape if SHUO structure exists already ", | |
417 | __FILE__, setStyledcolor, g); | |
418 | ||
419 | } |