0031284: Visualization - XCAFDoc_VisMaterialPBR lacks Index of Refraction
[occt.git] / src / XDEDRAW / XDEDRAW_Colors.cxx
CommitLineData
fcd9a94e 1// Created on: 2000-08-04
b311480e 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//
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.
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
17#include <DBRep.hxx>
18#include <DDocStd.hxx>
42cf5bc1 19#include <Draw.hxx>
973d410e 20#include <Precision.hxx>
7fd59977 21#include <Quantity_Color.hxx>
973d410e 22#include <Quantity_ColorRGBA.hxx>
a4815d55 23#include <OSD_File.hxx>
42cf5bc1 24#include <TCollection_AsciiString.hxx>
7fd59977 25#include <TDF_Label.hxx>
26#include <TDF_LabelSequence.hxx>
42cf5bc1 27#include <TDF_Tool.hxx>
a4815d55 28#include <TDataStd_Name.hxx>
7fd59977 29#include <TDocStd_Document.hxx>
42cf5bc1 30#include <TopoDS_Shape.hxx>
9196ea9d 31#include <ViewerTest.hxx>
42cf5bc1 32#include <XCAFDoc_ColorTool.hxx>
7fd59977 33#include <XCAFDoc_DocumentTool.hxx>
34#include <XCAFDoc_ShapeTool.hxx>
a4815d55 35#include <XCAFDoc_VisMaterial.hxx>
36#include <XCAFDoc_VisMaterialTool.hxx>
42cf5bc1 37#include <XDEDRAW_Colors.hxx>
7fd59977 38
9196ea9d 39//! Parse XCAFDoc_ColorType enumeration argument.
40static bool parseXDocColorType (const TCollection_AsciiString& theArg,
41 XCAFDoc_ColorType& theType)
42{
43 TCollection_AsciiString anArgCase (theArg);
44 anArgCase.LowerCase();
45 if (anArgCase == "surf"
46 || anArgCase == "surface"
47 || anArgCase == "s")
48 {
49 theType = XCAFDoc_ColorSurf;
50 return true;
51 }
52 else if (anArgCase == "curve"
53 || anArgCase == "c")
54 {
55 theType = XCAFDoc_ColorCurv;
56 return true;
57 }
58 else if (anArgCase == "gen"
59 || anArgCase == "generic")
60 {
61 theType = XCAFDoc_ColorGen;
62 return true;
63 }
64 return false;
65}
66
a4815d55 67//! Print triplet of values.
68template<class S, class T> static S& operator<< (S& theStream, const NCollection_Vec3<T>& theVec)
69{
70 theStream << theVec[0] << " " << theVec[1] << " " << theVec[2];
71 return theStream;
72}
73
74//! Print 4 values.
75template<class S, class T> static S& operator<< (S& theStream, const NCollection_Vec4<T>& theVec)
76{
77 theStream << theVec[0] << " " << theVec[1] << " " << theVec[2] << " " << theVec[3];
78 return theStream;
79}
80
81//! Convert alpha mode into string.
82static const char* alphaModeToString (Graphic3d_AlphaMode theMode)
83{
84 switch (theMode)
85 {
86 case Graphic3d_AlphaMode_Opaque: return "Opaque";
87 case Graphic3d_AlphaMode_Mask: return "Mask";
88 case Graphic3d_AlphaMode_Blend: return "Blend";
89 case Graphic3d_AlphaMode_BlendAuto: return "BlendAuto";
90 }
91 return "";
92}
93
94//! Find existing visualization material in the document.
95static TDF_Label findVisMaterial (const Handle(TDocStd_Document)& theDoc,
96 const TCollection_AsciiString& theKey)
97{
98 Handle(XCAFDoc_VisMaterialTool) aMatTool = XCAFDoc_DocumentTool::VisMaterialTool (theDoc->Main());
99 TDF_Label aMatLab;
100 TDF_Tool::Label (theDoc->GetData(), theKey, aMatLab);
101 if (!aMatLab.IsNull())
102 {
103 return aMatTool->IsMaterial (aMatLab) ? aMatLab : TDF_Label();
104 }
105
106 TDF_LabelSequence aLabels;
107 aMatTool->GetMaterials (aLabels);
108 for (TDF_LabelSequence::Iterator aLabIter (aLabels); aLabIter.More(); aLabIter.Next())
109 {
110 Handle(TDataStd_Name) aNodeName;
111 if (aLabIter.Value().FindAttribute (TDataStd_Name::GetID(), aNodeName)
112 && aNodeName->Get().IsEqual (theKey))
113 {
114 return aLabIter.Value();
115 }
116 }
117 return TDF_Label();
118}
119
120//! Check if image file exists.
121static bool isImageFileExist (const TCollection_AsciiString& thePath)
122{
123 const OSD_Path aPath (thePath);
124 if (!OSD_File (aPath).Exists())
125 {
126 std::cout << "Error: file '" << thePath << " not found\n";
127 return false;
128 }
129 return true;
130}
131
132//! Parse RGB values coming after specified argument.
133static bool parseRgbColor (Standard_Integer& theArgIter,
134 Quantity_Color& theColor,
135 Standard_Integer theNbArgs,
136 const char** theArgVec)
137{
138 Standard_Integer aNbParsed = ViewerTest::ParseColor (theNbArgs - theArgIter - 1,
139 theArgVec + theArgIter + 1,
140 theColor);
141 if (aNbParsed == 0)
142 {
143 std::cout << "Syntax error at '" << theArgVec[theArgIter] << "'\n";
144 return false;
145 }
146 theArgIter += aNbParsed;
147 return true;
148}
149
150//! Parse normalized real value within 0..1 range.
151static bool parseNormalizedReal (const char* theString,
152 Standard_ShortReal& theValue)
153{
154 theValue = (Standard_ShortReal )Draw::Atof (theString);
155 if (theValue < 0.0f || theValue > 1.0f)
156 {
157 std::cerr << "Syntax error at '" << theString << "'\n";
158 return false;
159 }
160 return true;
161}
162
7fd59977 163//=======================================================================
164// Section: Work with colors
165//=======================================================================
9196ea9d 166static Standard_Integer setColor (Draw_Interpretor& , Standard_Integer argc, const char** argv)
7fd59977 167{
9196ea9d 168 if (argc < 4)
169 {
170 std::cout << "Syntax error: wrong number of arguments\n";
7fd59977 171 return 1;
172 }
973d410e 173
9196ea9d 174 Handle(TDocStd_Document) aDoc;
175 DDocStd::GetDocument (argv[1], aDoc);
176 if (aDoc.IsNull())
177 {
178 std::cout << "Syntax error: " << argv[1] << " is not a document\n";
179 return 1;
973d410e 180 }
9196ea9d 181
182 TDF_Label aLabel;
183 TopoDS_Shape aShape;
184 TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
185 if (aLabel.IsNull())
186 {
187 aShape = DBRep::Get (argv[2]);
188 if (aShape.IsNull())
189 {
190 std::cout << "Syntax error: " << argv[2] << " is not a label nor shape\n";
191 return 1;
192 }
193 }
194
195 Quantity_ColorRGBA aColor;
196 bool isColorDefined = false;
197 XCAFDoc_ColorType aColType = XCAFDoc_ColorGen;
198 for (Standard_Integer anArgIter = 3; anArgIter < argc; ++anArgIter)
199 {
200 if (parseXDocColorType (argv[anArgIter], aColType))
201 {
202 //
203 }
204 else if (!isColorDefined)
205 {
206 isColorDefined = true;
207 Standard_Integer aNbParsed = ViewerTest::ParseColor (argc - anArgIter,
208 argv + anArgIter,
209 aColor);
210 if (aNbParsed == 0)
211 {
212 std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
213 return 1;
214 }
215 anArgIter += aNbParsed - 1;
216 }
217 else
218 {
219 std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
220 return 1;
7fd59977 221 }
222 }
9196ea9d 223 if (!isColorDefined)
224 {
225 std::cout << "Syntax error: wrong number of arguments\n";
226 return 1;
227 }
228
229 Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
230 if (!aLabel.IsNull())
231 {
232 aColorTool->SetColor (aLabel, aColor, aColType);
233 }
234 else if (!aColorTool->SetColor (aShape, aColor, aColType))
235 {
236 std::cout << "Syntax error: " << argv[2] << " is not a label nor shape\n";
237 return 1;
238 }
7fd59977 239 return 0;
240}
241
242static Standard_Integer getColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
243{
9196ea9d 244 if (argc != 3)
245 {
246 std::cout << "Syntax error: wrong number of arguments\n";
247 return 1;
248 }
249
250 Handle(TDocStd_Document) aDoc;
251 DDocStd::GetDocument (argv[1], aDoc);
252 if (aDoc.IsNull())
253 {
254 std::cout << "Syntax error: " << argv[1] << " is not a document\n";
7fd59977 255 return 1;
256 }
7fd59977 257
258 TDF_Label aLabel;
9196ea9d 259 TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
260 Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
261 Quantity_ColorRGBA aColor;
262 if (!myColors->GetColor (aLabel, aColor))
263 {
264 return 0;
265 }
266
267 if ((1.0 - aColor.Alpha()) < Precision::Confusion())
268 {
269 di << aColor.GetRGB().StringName (aColor.GetRGB().Name());
270 }
973d410e 271 else
9196ea9d 272 {
273 di << aColor.GetRGB().StringName (aColor.GetRGB().Name()) << " (" << aColor.Alpha() << ")";
274 }
7fd59977 275 return 0;
276}
277
278static Standard_Integer getShapeColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
279{
9196ea9d 280 if (argc != 3 && argc != 4)
281 {
282 std::cout << "Syntax error: wrong number of arguments\n";
283 return 1;
284 }
285
286 Handle(TDocStd_Document) aDoc;
287 DDocStd::GetDocument (argv[1], aDoc);
288 if (aDoc.IsNull())
289 {
290 std::cout << "Syntax error: " << argv[1] << " is not a document\n";
7fd59977 291 return 1;
292 }
7fd59977 293
294 TDF_Label aLabel;
9196ea9d 295 TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
296 if (aLabel.IsNull())
297 {
298 std::cout << "Syntax error: '" << argv[2] << "' label is not found in the document\n";
3c946c38 299 return 1;
300 }
301
9196ea9d 302 Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
303 XCAFDoc_ColorType aColType = XCAFDoc_ColorGen;
304 if (argc > 3 && !parseXDocColorType (argv[3], aColType))
305 {
306 std::cout << "Syntax error: unknown color type '" << argv[3] << "'\n";
307 return 1;
308 }
3c946c38 309
9196ea9d 310 Quantity_ColorRGBA aColor;
311 if (!myColors->GetColor (aLabel, aColType, aColor))
312 {
313 return 0;
314 }
3c946c38 315
9196ea9d 316 if ((1.0 - aColor.Alpha()) < Precision::Confusion())
317 {
318 di << aColor.GetRGB().StringName(aColor.GetRGB().Name());
319 }
973d410e 320 else
9196ea9d 321 {
322 di << aColor.GetRGB().StringName(aColor.GetRGB().Name()) << " (" << aColor.Alpha() << ")";
323 }
3c946c38 324
7fd59977 325 return 0;
326}
327
328static Standard_Integer getAllColors (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
329{
9196ea9d 330 if (argc != 2)
331 {
332 std::cout << "Syntax error: wrong number of arguments\n";
7fd59977 333 return 1;
334 }
7fd59977 335
9196ea9d 336 Handle(TDocStd_Document) aDoc;
337 DDocStd::GetDocument (argv[1], aDoc);
338 if (aDoc.IsNull())
339 {
340 std::cout << "Syntax error: " << argv[1] << " is not a document\n";
341 return 1;
342 }
343
344 Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
345 TDF_LabelSequence aLabels;
346 aColorTool->GetColors (aLabels);
347 if (aLabels.Length() >= 1)
348 {
349 for (TDF_LabelSequence::Iterator aLabIter (aLabels); aLabIter.More(); aLabIter.Next())
350 {
351 Quantity_ColorRGBA aColor;
352 if (!aColorTool->GetColor (aLabIter.Value(), aColor))
353 {
354 continue;
355 }
356 if ((1.0 - aColor.Alpha()) < Precision::Confusion())
357 {
358 di << aColor.GetRGB().StringName (aColor.GetRGB().Name());
359 }
973d410e 360 else
9196ea9d 361 {
362 di << aColor.GetRGB().StringName (aColor.GetRGB().Name()) << " (" << aColor.Alpha() << ")";
363 }
7fd59977 364 di << " ";
365 }
366 }
367 return 0;
368}
369
7fd59977 370static Standard_Integer addColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
371{
9196ea9d 372 if (argc < 3)
373 {
374 std::cout << "Syntax error: wrong number of arguments\n";
7fd59977 375 return 1;
376 }
7fd59977 377
9196ea9d 378 Handle(TDocStd_Document) aDoc;
379 DDocStd::GetDocument (argv[1], aDoc);
380 if (aDoc.IsNull())
381 {
382 std::cout << "Syntax error: " << argv[1] << " is not a document\n";
383 return 1;
384 }
7fd59977 385
9196ea9d 386 Quantity_ColorRGBA aColRGBA;
387 Standard_Integer aNbParsed = ViewerTest::ParseColor (argc - 2, argv + 2, aColRGBA);
388 if (aNbParsed != argc - 2)
389 {
390 std::cout << "Syntax error at '" << argv[2] << "'\n";
391 return 1;
973d410e 392 }
9196ea9d 393
394 TCollection_AsciiString anEntry;
395 Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
396 TDF_Label aLabel = aColorTool->AddColor (aColRGBA);
397 TDF_Tool::Entry (aLabel, anEntry);
398 di << anEntry;
7fd59977 399 return 0;
400}
401
9196ea9d 402static Standard_Integer removeColor (Draw_Interpretor& , Standard_Integer argc, const char** argv)
7fd59977 403{
9196ea9d 404 if (argc != 3)
405 {
406 std::cout << "Syntax error: wrong number of arguments\n";
7fd59977 407 return 1;
408 }
7fd59977 409
9196ea9d 410 Handle(TDocStd_Document) aDoc;
7fd59977 411 TDF_Label aLabel;
9196ea9d 412 DDocStd::GetDocument (argv[1], aDoc);
413 if (aDoc.IsNull())
414 {
415 std::cout << "Syntax error: " << argv[1] << " is not a document\n";
416 return 1;
417 }
418 TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
419 if (aLabel.IsNull())
420 {
421 std::cout << "Syntax error: " << argv[2] << " label is not found in the document\n";
422 return 1;
423 }
424
425 Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
426 aColorTool->RemoveColor (aLabel);
7fd59977 427 return 0;
428}
429
430static Standard_Integer findColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
431{
9196ea9d 432 if (argc < 3)
433 {
434 std::cout << "Syntax error: wrong number of arguments\n";
7fd59977 435 return 1;
436 }
7fd59977 437
9196ea9d 438 Handle(TDocStd_Document) aDoc;
439 DDocStd::GetDocument (argv[1], aDoc);
440 if (aDoc.IsNull())
441 {
442 std::cout << "Syntax error: " << argv[1] << " is not a document\n";
443 return 1;
973d410e 444 }
9196ea9d 445
446 Quantity_ColorRGBA aColRGBA;
447 Standard_Integer aNbParsed = ViewerTest::ParseColor (argc - 2, argv + 2, aColRGBA);
448 if (aNbParsed != argc - 2)
449 {
450 std::cout << "Syntax error at '" << argv[2] << "'\n";
451 return 1;
973d410e 452 }
9196ea9d 453
454 Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
455 TCollection_AsciiString anEntry;
456 TDF_Tool::Entry (aColorTool->FindColor (aColRGBA), anEntry);
457 di << anEntry;
7fd59977 458 return 0;
459}
460
9196ea9d 461static Standard_Integer unsetColor (Draw_Interpretor& , Standard_Integer argc, const char** argv)
7fd59977 462{
9196ea9d 463 if (argc != 4)
464 {
465 std::cout << "Syntax error: wrong number of arguments\n";
466 return 1;
467 }
468
469 Handle(TDocStd_Document) aDoc;
470 DDocStd::GetDocument (argv[1], aDoc);
471 if (aDoc.IsNull())
472 {
473 std::cout << "Syntax error: " << argv[1] << " is not a document\n";
474 return 1;
475 }
476
477 XCAFDoc_ColorType aColType = XCAFDoc_ColorGen;
478 if (!parseXDocColorType (argv[3], aColType))
479 {
480 std::cout << "Syntax error: unknown color type '" << argv[3] << "'\n";
7fd59977 481 return 1;
482 }
7fd59977 483
484 TDF_Label aLabel;
9196ea9d 485 TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
486 Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
487 if (!aLabel.IsNull())
488 {
489 myColors->UnSetColor (aLabel, aColType);
490 return 0;
7fd59977 491 }
9196ea9d 492
493 TopoDS_Shape aShape = DBRep::Get (argv[2]);
494 if (aShape.IsNull())
495 {
496 std::cout << "Syntax error: " << argv[2] << " is not a label nor shape\n";
497 return 1;
7fd59977 498 }
9196ea9d 499 myColors->UnSetColor (aShape, aColType);
7fd59977 500 return 0;
501}
502
9196ea9d 503static Standard_Integer setVisibility (Draw_Interpretor& , Standard_Integer argc, const char** argv)
7fd59977 504{
9196ea9d 505 if (argc != 3 && argc != 4)
506 {
507 std::cout << "Syntax error: wrong number of arguments\n";
7fd59977 508 return 1;
509 }
9196ea9d 510
511 Handle(TDocStd_Document) aDoc;
7fd59977 512 TDF_Label aLabel;
9196ea9d 513 DDocStd::GetDocument (argv[1], aDoc);
514 if (aDoc.IsNull())
515 {
516 std::cout << "Syntax error: " << argv[1] << " is not a document\n";
517 return 1;
518 }
519
520 TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
521 Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
522 if (aLabel.IsNull())
523 {
7fd59977 524 // get label by shape
9196ea9d 525 TopoDS_Shape aShape = DBRep::Get (argv[2]);
526 if (!aShape.IsNull())
527 {
528 aLabel = aColorTool->ShapeTool()->FindShape (aShape, Standard_True);
7fd59977 529 }
530 }
9196ea9d 531 if (aLabel.IsNull())
532 {
533 std::cout << "Syntax error: " << argv[2] << " is not a label not shape\n";
7fd59977 534 return 1;
535 }
9196ea9d 536
537 Standard_Boolean isVisible = Standard_False;
538 if (argc == 4)
539 {
540 TCollection_AsciiString aVisArg (argv[3]);
541 if (aVisArg == "1")
542 {
543 isVisible = Standard_True;
544 }
545 else if (aVisArg == "0")
546 {
547 isVisible = Standard_False;
548 }
549 else
550 {
551 std::cout << "Syntax error: unknown argument '" << argv[3] << "'\n";
552 return 1;
553 }
554 }
555 aColorTool->SetVisibility (aLabel, isVisible);
7fd59977 556 return 0;
557}
558
559static Standard_Integer getVisibility (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
560{
9196ea9d 561 if (argc != 3)
562 {
563 std::cout << "Syntax error: wrong number of arguments\n";
564 return 1;
565 }
566
567 Handle(TDocStd_Document) aDoc;
568 DDocStd::GetDocument (argv[1], aDoc);
569 if (aDoc.IsNull())
570 {
571 std::cout << "Syntax error: " << argv[1] << " is not a document\n";
7fd59977 572 return 1;
573 }
9196ea9d 574
575 Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
7fd59977 576 TDF_Label aLabel;
9196ea9d 577 TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
578 if (aLabel.IsNull())
579 {
7fd59977 580 // get label by shape
9196ea9d 581 TopoDS_Shape aShape = DBRep::Get (argv[2]);
582 if (!aShape.IsNull())
583 {
584 aLabel = aColorTool->ShapeTool()->FindShape (aShape, Standard_True);
7fd59977 585 }
586 }
9196ea9d 587 if (aLabel.IsNull())
588 {
589 std::cout << "Syntax error: " << argv[2] << " is not a label not shape\n";
7fd59977 590 return 1;
591 }
9196ea9d 592
593 di << (aColorTool->IsVisible (aLabel) ? 1 : 0);
7fd59977 594 return 0;
595}
596
597static Standard_Integer getStyledVisibility (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
598{
9196ea9d 599 if (argc != 3)
600 {
601 std::cout << "Syntax error: wrong number of arguments\n";
7fd59977 602 return 1;
603 }
9196ea9d 604
605 Handle(TDocStd_Document) aDoc;
606 DDocStd::GetDocument (argv[1], aDoc);
607 TopoDS_Shape aShape = DBRep::Get(argv[2]);
608 if (aDoc.IsNull())
609 {
610 std::cout << "Syntax error: " << argv[1] << " is not a document\n";
611 return 1;
612 }
613 if (aShape.IsNull())
614 {
615 std::cout << "Syntax error: " << argv[2] << " is not a shape\n";
616 return 1;
617 }
618
619 Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
620 di << (aColorTool->IsInstanceVisible (aShape) ? 1 : 0);
7fd59977 621 return 0;
622}
623
624static Standard_Integer getStyledcolor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
625{
9196ea9d 626 if (argc != 3 && argc != 4)
627 {
628 std::cout << "Syntax error: wrong number of arguments\n";
7fd59977 629 return 1;
630 }
9196ea9d 631
632 Handle(TDocStd_Document) aDoc;
633 XCAFDoc_ColorType aColType = XCAFDoc_ColorGen;
634 DDocStd::GetDocument (argv[1], aDoc);
635 TopoDS_Shape aShape = DBRep::Get (argv[2]);
636 if (aDoc.IsNull())
637 {
638 std::cout << "Syntax error: " << argv[1] << " is not a document\n";
639 return 1;
640 }
641 if (aShape.IsNull())
642 {
643 std::cout << "Syntax error: " << argv[2] << " is not a shape\n";
644 return 1;
645 }
646 if (argc > 3 && !parseXDocColorType (argv[3], aColType))
647 {
648 std::cout << "Syntax error: unknown color type '" << argv[3] << "'\n";
649 return 1;
650 }
651
652 Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
653 Quantity_ColorRGBA aColor;
654 if (aColorTool->GetInstanceColor (aShape, aColType, aColor))
7fd59977 655 {
9196ea9d 656 if ((1.0 - aColor.Alpha()) < Precision::Confusion())
657 {
658 di << aColor.GetRGB().StringName (aColor.GetRGB().Name());
659 }
973d410e 660 else
9196ea9d 661 {
662 di << aColor.GetRGB().StringName (aColor.GetRGB().Name()) << " (" << aColor.Alpha() << ")";
663 }
7fd59977 664 }
665 return 0;
666}
667
9196ea9d 668static Standard_Integer setStyledcolor (Draw_Interpretor& , Standard_Integer argc, const char** argv)
7fd59977 669{
9196ea9d 670 if (argc < 3)
671 {
672 std::cout << "Syntax error: wrong number of arguments\n";
7fd59977 673 return 1;
674 }
7fd59977 675
9196ea9d 676 Handle(TDocStd_Document) aDoc;
677 DDocStd::GetDocument (argv[1], aDoc);
678 if (aDoc.IsNull())
679 {
680 std::cout << "Syntax error: " << argv[1] << " is not a document\n";
681 return 1;
682 }
683
684 TopoDS_Shape aShape = DBRep::Get (argv[2]);
685 if (aShape.IsNull())
686 {
687 std::cout << "Syntax error: " << argv[2] << " is not a shape\n";
688 return 1;
973d410e 689 }
690
9196ea9d 691 XCAFDoc_ColorType aColorType = XCAFDoc_ColorGen;
692 Quantity_ColorRGBA aColRGBA;
693 for (Standard_Integer anArgIter = 3; anArgIter < argc; ++anArgIter)
694 {
695 if (parseXDocColorType (argv[anArgIter], aColorType))
696 {
697 //
698 }
699 else
700 {
701 Standard_Integer aNbParsed = ViewerTest::ParseColor (argc - anArgIter,
702 argv + anArgIter,
703 aColRGBA);
704 if (aNbParsed == 0)
705 {
706 std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
707 return 1;
708 }
709 anArgIter += aNbParsed - 1;
710 }
973d410e 711 }
9196ea9d 712
713 Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
714 if (!aColorTool->SetInstanceColor (aShape, aColorType, aColRGBA))
7fd59977 715 {
9196ea9d 716 std::cout << "Error: cannot set color for the indicated component\n";
7fd59977 717 return 1;
718 }
719 return 0;
720}
721
a4815d55 722// ================================================================
723// Function : XGetAllVisMaterials
724// Purpose :
725// ================================================================
726static Standard_Integer XGetAllVisMaterials (Draw_Interpretor& theDI, Standard_Integer theNbArgs, const char** theArgVec)
727{
728 if (theNbArgs != 2 && theNbArgs != 3)
729 {
730 std::cout << "Syntax error: wrong number of arguments\n";
731 return 1;
732 }
733
734 Handle(TDocStd_Document) aDoc;
735 DDocStd::GetDocument (theArgVec[1], aDoc);
736 if (aDoc.IsNull())
737 {
738 std::cout << "Syntax error: " << theArgVec[1] << " is not a document\n";
739 return 1;
740 }
741
742 bool toPrintNames = true;
743 if (theNbArgs == 3)
744 {
745 TCollection_AsciiString anArgCase (theArgVec[2]);
746 anArgCase.LowerCase();
747 if (anArgCase == "-names")
748 {
749 toPrintNames = true;
750 }
751 else if (anArgCase == "-labels")
752 {
753 toPrintNames = false;
754 }
755 }
756
757 Handle(XCAFDoc_VisMaterialTool) aMatTool = XCAFDoc_DocumentTool::VisMaterialTool (aDoc->Main());
758 TDF_LabelSequence aLabels;
759 aMatTool->GetMaterials (aLabels);
760 Standard_Integer aMatIndex = 1;
761 for (TDF_LabelSequence::Iterator aLabIter (aLabels); aLabIter.More(); aLabIter.Next(), ++aMatIndex)
762 {
763 const TDF_Label& aMatLab = aLabIter.Value();
764 if (!toPrintNames)
765 {
766 TCollection_AsciiString anEntryId;
767 TDF_Tool::Entry (aMatLab, anEntryId);
768 theDI << anEntryId << " ";
769 continue;
770 }
771
772 Handle(TDataStd_Name) aNodeName;
773 if (aMatLab.FindAttribute (TDataStd_Name::GetID(), aNodeName))
774 {
775 theDI << aNodeName->Get() << " ";
776 }
777 else
778 {
779 TCollection_AsciiString aName = TCollection_AsciiString("<UNNAMED") + aMatIndex + ">";
780 theDI << aName << " ";
781 }
782 }
783 return 0;
784}
785
786// ================================================================
787// Function : XGetVisMaterial
788// Purpose :
789// ================================================================
790static Standard_Integer XGetVisMaterial (Draw_Interpretor& theDI, Standard_Integer theNbArgs, const char** theArgVec)
791{
792 if (theNbArgs != 3)
793 {
794 std::cout << "Syntax error: wrong number of arguments\n";
795 return 1;
796 }
797
798 Handle(TDocStd_Document) aDoc;
799 DDocStd::GetDocument (theArgVec[1], aDoc);
800 if (aDoc.IsNull())
801 {
802 std::cout << "Syntax error: " << theArgVec[1] << " is not a document\n";
803 return 1;
804 }
805
806 Handle(XCAFDoc_VisMaterialTool) aMatTool = XCAFDoc_DocumentTool::VisMaterialTool (aDoc->Main());
807 Handle(XCAFDoc_VisMaterial) aMat;
808 TDF_Label aMatLab = findVisMaterial (aDoc, theArgVec[2]);
809 if (!aMatLab.IsNull())
810 {
811 aMat = aMatTool->GetMaterial (aMatLab);
812 }
813 else
814 {
815 TDF_Label aShapeLab;
816 TDF_Tool::Label (aDoc->GetData(), theArgVec[2], aShapeLab);
817 if (aShapeLab.IsNull())
818 {
819 TopoDS_Shape aShape = DBRep::Get (theArgVec[2]);
820 if (!aShape.IsNull())
821 {
822 aShapeLab = aMatTool->ShapeTool()->FindShape (aShape);
823 }
824 }
825 if (!aShapeLab.IsNull()
826 && !aMatTool->ShapeTool()->IsShape (aShapeLab))
827 {
828 aShapeLab.Nullify();
829 }
830 if (aShapeLab.IsNull())
831 {
832 std::cout << "Syntax error: " << theArgVec[2] << " is not material nor shape\n";
833 return 1;
834 }
835
836 aMat = aMatTool->GetShapeMaterial (aShapeLab);
837 }
838
839 if (aMat.IsNull())
840 {
841 theDI << "EMPTY\n";
842 return 0;
843 }
844
845 TCollection_AsciiString anEntryId;
846 TDF_Tool::Entry (aMat->Label(), anEntryId);
847 theDI << "Label: " << anEntryId << "\n";
848
849 Handle(TDataStd_Name) aNodeName;
850 if (aMat->Label().FindAttribute (TDataStd_Name::GetID(), aNodeName))
851 {
852 theDI << "Name: " << aNodeName->Get() << "\n";
853 }
854 if (aMat->IsEmpty())
855 {
856 theDI << "EMPTY\n";
857 return 0;
858 }
859 theDI << "AlphaMode: " << alphaModeToString (aMat->AlphaMode()) << "\n";
860 theDI << "AlphaCutOff: " << aMat->AlphaCutOff() << "\n";
861 theDI << "IsDoubleSided: " << aMat->IsDoubleSided() << "\n";
862 if (aMat->HasCommonMaterial())
863 {
864 const XCAFDoc_VisMaterialCommon& aMatCom = aMat->CommonMaterial();
865 theDI << "Common.Ambient: " << (Graphic3d_Vec3 )aMatCom.AmbientColor << "\n";
866 theDI << "Common.Diffuse: " << (Graphic3d_Vec3 )aMatCom.DiffuseColor << "\n";
867 if (!aMatCom.DiffuseTexture.IsNull())
868 {
869 theDI << "Common.DiffuseTexture: " << aMatCom.DiffuseTexture->TextureId() << "\n";
870 }
871 theDI << "Common.Specular: " << (Graphic3d_Vec3 )aMatCom.SpecularColor << "\n";
872 theDI << "Common.Emissive: " << (Graphic3d_Vec3 )aMatCom.EmissiveColor << "\n";
873 theDI << "Common.Shininess: " << aMatCom.Shininess << "\n";
874 theDI << "Common.Transparency: " << aMatCom.Transparency << "\n";
875 }
876 if (aMat->HasPbrMaterial())
877 {
878 const XCAFDoc_VisMaterialPBR& aMatPbr = aMat->PbrMaterial();
879 theDI << "PBR.BaseColor: " << (Graphic3d_Vec3 )aMatPbr.BaseColor.GetRGB() << "\n";
880 theDI << "PBR.Transparency: " << (1.0 - aMatPbr.BaseColor.Alpha()) << "\n";
0858125f 881 theDI << "PBR.RefractionIndex: " << aMatPbr.RefractionIndex << "\n";
a4815d55 882 if (!aMatPbr.BaseColorTexture.IsNull())
883 {
884 theDI << "PBR.BaseColorTexture: " << aMatPbr.BaseColorTexture->TextureId() << "\n";
885 }
886 theDI << "PBR.EmissiveFactor: " << aMatPbr.EmissiveFactor << "\n";
887 if (!aMatPbr.EmissiveTexture.IsNull())
888 {
889 theDI << "PBR.EmissiveTexture: " << aMatPbr.EmissiveTexture->TextureId() << "\n";
890 }
891 theDI << "PBR.Metallic: " << aMatPbr.Metallic << "\n";
892 theDI << "PBR.Roughness: " << aMatPbr.Roughness << "\n";
893 if (!aMatPbr.MetallicRoughnessTexture.IsNull())
894 {
895 theDI << "PBR.MetallicRoughnessTexture: " << aMatPbr.MetallicRoughnessTexture->TextureId() << "\n";
896 }
897 if (!aMatPbr.OcclusionTexture.IsNull())
898 {
899 theDI << "PBR.OcclusionTexture: " << aMatPbr.OcclusionTexture->TextureId() << "\n";
900 }
901 if (!aMatPbr.NormalTexture.IsNull())
902 {
903 theDI << "PBR.NormalTexture: " << aMatPbr.NormalTexture->TextureId() << "\n";
904 }
905 }
906 return 0;
907}
908
909// ================================================================
910// Function : XAddVisMaterial
911// Purpose :
912// ================================================================
913static Standard_Integer XAddVisMaterial (Draw_Interpretor& , Standard_Integer theNbArgs, const char** theArgVec)
914{
915 if (theNbArgs < 3)
916 {
917 std::cout << "Syntax error: wrong number of arguments\n";
918 return 1;
919 }
920
921 Handle(TDocStd_Document) aDoc;
922 DDocStd::GetDocument (theArgVec[1], aDoc);
923 if (aDoc.IsNull())
924 {
925 std::cout << "Syntax error: " << theArgVec[1] << " is not a document\n";
926 return 1;
927 }
928
929 Handle(XCAFDoc_VisMaterialTool) aMatTool = XCAFDoc_DocumentTool::VisMaterialTool (aDoc->Main());
930 TDF_Label aMatLab = findVisMaterial (aDoc, theArgVec[2]);
931 if (aMatLab.IsNull())
932 {
933 aMatLab = aMatTool->AddMaterial (theArgVec[2]);
934 }
935
936 Handle(XCAFDoc_VisMaterial) aMat = aMatTool->GetMaterial (aMatLab);
937 XCAFDoc_VisMaterialCommon aMatCom = aMat->CommonMaterial();
938 XCAFDoc_VisMaterialPBR aMatPbr = aMat->PbrMaterial();
939 Standard_ShortReal aRealValue = 0.0f;
940 for (Standard_Integer anArgIter = 3; anArgIter < theNbArgs; ++anArgIter)
941 {
942 TCollection_AsciiString anArg (theArgVec[anArgIter]);
943 anArg.LowerCase();
944 if ((anArg == "-transparency"
945 || anArg == "-alpha")
946 && anArgIter + 1 < theNbArgs
947 && parseNormalizedReal (theArgVec[anArgIter + 1], aMatCom.Transparency))
948 {
949 ++anArgIter;
950 if (anArg == "-alpha")
951 {
952 aMatCom.Transparency = 1.0f - aMatCom.Transparency;
953 }
954 aMatPbr.BaseColor.SetAlpha (1.0f - aMatCom.Transparency);
955 }
0858125f 956 else if (anArgIter + 1 < theNbArgs
957 && (anArg == "-refractionindex" || anArg == "-ior"))
958 {
959 aMatPbr.RefractionIndex = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter + 1]);
960 if (aMatPbr.RefractionIndex < 1.0f || aMatPbr.RefractionIndex > 3.0f)
961 {
962 std::cout << "Syntax error at '" << anArg << "'\n";
963 return 1;
964 }
965
966 ++anArgIter;
967 aMatPbr.IsDefined = true;
968 }
a4815d55 969 else if (anArg == "-alphaMode"
970 && anArgIter + 2 < theNbArgs
971 && parseNormalizedReal (theArgVec[anArgIter + 2], aRealValue))
972 {
973 TCollection_AsciiString aModeStr (theArgVec[anArgIter + 1]);
974 aModeStr.LowerCase();
975 Graphic3d_AlphaMode anAlphaMode = Graphic3d_AlphaMode_Opaque;
976 if (aModeStr == "opaque")
977 {
978 anAlphaMode = Graphic3d_AlphaMode_Opaque;
979 }
980 else if (aModeStr == "mask")
981 {
982 anAlphaMode = Graphic3d_AlphaMode_Mask;
983 }
984 else if (aModeStr == "blend")
985 {
986 anAlphaMode = Graphic3d_AlphaMode_Blend;
987 }
988 else if (aModeStr == "blendauto")
989 {
990 anAlphaMode = Graphic3d_AlphaMode_BlendAuto;
991 }
992 else
993 {
994 std::cerr << "Syntax error at '" << anArg << "'\n";
995 return 1;
996 }
997 aMat->SetAlphaMode (anAlphaMode, aRealValue);
998 anArgIter += 2;
999 }
1000 else if (anArg == "-diffuse"
1001 || anArg == "-basecolor"
1002 || anArg == "-albedo")
1003 {
1004 Quantity_ColorRGBA aColorRGBA;
1005 Standard_Integer aNbParsed = ViewerTest::ParseColor (theNbArgs - anArgIter - 1,
1006 theArgVec + anArgIter + 1,
1007 aColorRGBA);
1008 if (aNbParsed == 0)
1009 {
1010 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
1011 return 1;
1012 }
1013 anArgIter += aNbParsed;
1014
1015 if (anArg == "-diffuse")
1016 {
1017 aMatCom.IsDefined = true;
1018 aMatCom.DiffuseColor = aColorRGBA.GetRGB();
1019 if (aNbParsed == 2 || aNbParsed == 4)
1020 {
1021 aMatCom.Transparency = 1.0f - aColorRGBA.Alpha();
1022 }
1023 }
1024 else
1025 {
1026 aMatPbr.IsDefined = true;
1027 if (aNbParsed == 2 || aNbParsed == 4)
1028 {
1029 aMatPbr.BaseColor = aColorRGBA;
1030 }
1031 else
1032 {
1033 aMatPbr.BaseColor.SetRGB (aColorRGBA.GetRGB());
1034 }
1035 }
1036 }
1037 else if (anArg == "-specular"
1038 && parseRgbColor (anArgIter, aMatCom.SpecularColor,
1039 theNbArgs, theArgVec))
1040 {
1041 aMatCom.IsDefined = true;
1042 }
1043 else if (anArg == "-ambient"
1044 && parseRgbColor (anArgIter, aMatCom.AmbientColor,
1045 theNbArgs, theArgVec))
1046 {
1047 aMatCom.IsDefined = true;
1048 }
1049 else if (anArg == "-emissive"
1050 && parseRgbColor (anArgIter, aMatCom.EmissiveColor,
1051 theNbArgs, theArgVec))
1052 {
1053 aMatCom.IsDefined = true;
1054 }
1055 else if (anArg == "-shininess"
1056 && anArgIter + 1 < theNbArgs)
1057 {
1058 aMatCom.IsDefined = true;
1059 aMatCom.Shininess = (float )Draw::Atof (theArgVec[++anArgIter]);
1060 if (aMatCom.Shininess < 0.0f || aMatCom.Shininess > 1.0f)
1061 {
1062 std::cout << "Syntax error at '" << anArg << "'\n";
1063 return 1;
1064 }
1065 }
1066 else if (anArgIter + 1 < theNbArgs
1067 && anArg == "-diffusetexture"
1068 && isImageFileExist (theArgVec[anArgIter + 1]))
1069 {
1070 aMatCom.IsDefined = true;
1071 aMatCom.DiffuseTexture = new Image_Texture (theArgVec[++anArgIter]);
1072 }
1073 else if (anArgIter + 1 < theNbArgs
1074 && anArg == "-basecolortexture"
1075 && isImageFileExist (theArgVec[anArgIter + 1]))
1076 {
1077 aMatPbr.IsDefined = true;
1078 aMatPbr.BaseColorTexture = new Image_Texture (theArgVec[++anArgIter]);
1079 }
1080 else if (anArgIter + 1 < theNbArgs
1081 && anArg == "-emissivetexture"
1082 && isImageFileExist (theArgVec[anArgIter + 1]))
1083 {
1084 aMatPbr.IsDefined = true;
1085 aMatPbr.EmissiveTexture = new Image_Texture (theArgVec[++anArgIter]);
1086 }
1087 else if (anArgIter + 1 < theNbArgs
1088 && anArg == "-metallicroughnesstexture"
1089 && isImageFileExist (theArgVec[anArgIter + 1]))
1090 {
1091 aMatPbr.IsDefined = true;
1092 aMatPbr.MetallicRoughnessTexture = new Image_Texture (theArgVec[++anArgIter]);
1093 }
1094 else if (anArgIter + 1 < theNbArgs
1095 && anArg == "-normaltexture"
1096 && isImageFileExist (theArgVec[anArgIter + 1]))
1097 {
1098 aMatPbr.IsDefined = true;
1099 aMatPbr.NormalTexture = new Image_Texture (theArgVec[++anArgIter]);
1100 }
1101 else if (anArgIter + 1 < theNbArgs
1102 && anArg == "-occlusiontexture"
1103 && isImageFileExist (theArgVec[anArgIter + 1]))
1104 {
1105 aMatPbr.IsDefined = true;
1106 aMatPbr.OcclusionTexture = new Image_Texture (theArgVec[++anArgIter]);
1107 }
1108 else if (anArg == "-emissivefactor"
1109 && anArgIter + 4 < theNbArgs)
1110 {
1111 aMatPbr.IsDefined = true;
1112 aMatPbr.EmissiveFactor.SetValues ((float )Draw::Atof (theArgVec[anArgIter + 1]),
1113 (float )Draw::Atof (theArgVec[anArgIter + 2]),
1114 (float )Draw::Atof (theArgVec[anArgIter + 3]));
1115 anArgIter += 3;
1116 }
1117 else if (anArg == "-doublesided")
1118 {
1119 aMatPbr.IsDefined = true;
1120 bool isDoubleSided = true;
1121 if (anArgIter + 1 < theNbArgs
1122 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isDoubleSided))
1123 {
1124 ++anArgIter;
1125 }
1126 aMat->SetDoubleSided (isDoubleSided);
1127 }
1128 else if (anArgIter + 1 < theNbArgs
1129 && anArg == "-metallic"
1130 && parseNormalizedReal (theArgVec[anArgIter + 1], aMatPbr.Metallic))
1131 {
1132 ++anArgIter;
1133 aMatPbr.IsDefined = true;
1134 }
1135 else if (anArgIter + 1 < theNbArgs
1136 && anArg == "-roughness"
1137 && parseNormalizedReal (theArgVec[anArgIter + 1], aMatPbr.Roughness))
1138 {
1139 ++anArgIter;
1140 aMatPbr.IsDefined = true;
1141 }
1142 else
1143 {
1144 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
1145 return 1;
1146 }
1147 }
1148
1149 aMat->SetCommonMaterial (aMatCom);
1150 aMat->SetPbrMaterial (aMatPbr);
1151 return 0;
1152}
1153
1154// ================================================================
1155// Function : XRemoveVisMaterial
1156// Purpose :
1157// ================================================================
1158static Standard_Integer XRemoveVisMaterial (Draw_Interpretor& , Standard_Integer theNbArgs, const char** theArgVec)
1159{
1160 if (theNbArgs != 3)
1161 {
1162 std::cout << "Syntax error: wrong number of arguments\n";
1163 return 1;
1164 }
1165
1166 Handle(TDocStd_Document) aDoc;
1167 DDocStd::GetDocument (theArgVec[1], aDoc);
1168 if (aDoc.IsNull())
1169 {
1170 std::cout << "Syntax error: " << theArgVec[1] << " is not a document\n";
1171 return 1;
1172 }
1173
1174 TDF_Label aMatLab = findVisMaterial (aDoc, theArgVec[2]);
1175 if (aMatLab.IsNull())
1176 {
1177 std::cout << "Syntax error: " << theArgVec[2] << " is not a material\n";
1178 return 1;
1179 }
1180
1181 Handle(XCAFDoc_VisMaterialTool) aMatTool = XCAFDoc_DocumentTool::VisMaterialTool (aDoc->Main());
1182 aMatTool->RemoveMaterial (aMatLab);
1183 return 0;
1184}
1185
1186// ================================================================
1187// Function : XSetVisMaterial
1188// Purpose :
1189// ================================================================
1190static Standard_Integer XSetVisMaterial (Draw_Interpretor& , Standard_Integer theNbArgs, const char** theArgVec)
1191{
1192 if (theNbArgs != 3 && theNbArgs != 4)
1193 {
1194 std::cout << "Syntax error: wrong number of arguments\n";
1195 return 1;
1196 }
1197
1198 Handle(TDocStd_Document) aDoc;
1199 TDF_Label aShapeLab;
1200 DDocStd::GetDocument (theArgVec[1], aDoc);
1201 if (aDoc.IsNull())
1202 {
1203 std::cout << "Syntax error: " << theArgVec[1] << " is not a document\n";
1204 return 1;
1205 }
1206
1207 TDF_Tool::Label (aDoc->GetData(), theArgVec[2], aShapeLab);
1208 Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
1209 if (aShapeLab.IsNull())
1210 {
1211 // get label by shape
1212 TopoDS_Shape aShape = DBRep::Get (theArgVec[2]);
1213 if (!aShape.IsNull())
1214 {
1215 aShapeLab = aColorTool->ShapeTool()->FindShape (aShape, Standard_True);
1216 }
1217 }
1218 if (aShapeLab.IsNull())
1219 {
1220 std::cout << "Syntax error: " << theArgVec[2] << " is not a label not shape\n";
1221 return 1;
1222 }
1223
1224 TDF_Label aMatLab;
1225 if (theNbArgs == 4)
1226 {
1227 aMatLab = findVisMaterial (aDoc, theArgVec[3]);
1228 if (aMatLab.IsNull())
1229 {
1230 std::cout << "Syntax error: " << theArgVec[3] << " is not a material\n";
1231 return 1;
1232 }
1233 }
1234
1235 Handle(XCAFDoc_VisMaterialTool) aMatTool = XCAFDoc_DocumentTool::VisMaterialTool (aDoc->Main());
1236 aMatTool->SetShapeMaterial (aShapeLab, aMatLab);
1237 return 0;
1238}
1239
7fd59977 1240//=======================================================================
1241//function : InitCommands
1242//purpose :
1243//=======================================================================
1244
1245void XDEDRAW_Colors::InitCommands(Draw_Interpretor& di)
1246{
7fd59977 1247 static Standard_Boolean initactor = Standard_False;
c48e2889 1248 if (initactor)
1249 {
1250 return;
1251 }
1252 initactor = Standard_True;
7fd59977 1253
1254 //=====================================
1255 // Work with colors
1256 //=====================================
1257
1258 Standard_CString g = "XDE color's commands";
9196ea9d 1259
1260 di.Add ("XSetColor","Doc {Label|Shape} R G B [alpha] [{generic|surface|curve}=gen]"
1261 "\t: Set color [R G B] to shape given by Label, "
ec99ba32 1262 "type of color 's' - for surface, 'c' - for curve (default generic)",
7fd59977 1263 __FILE__, setColor, g);
1264
9196ea9d 1265 di.Add ("XGetColor","Doc label"
1266 "\t: Return color defined on label in colortable",
7fd59977 1267 __FILE__, getColor, g);
1268
9196ea9d 1269 di.Add ("XGetShapeColor","Doc Label {generic|surface|curve}"
1270 "\t: Returns color defined by label",
7fd59977 1271 __FILE__, getShapeColor, g);
9196ea9d 1272
1273 di.Add ("XGetAllColors","Doc"
1274 "\t: Print all colors that defined in document",
7fd59977 1275 __FILE__, getAllColors, g);
1276
9196ea9d 1277 di.Add ("XAddColor","Doc R G B [alpha]"
1278 "\t: Add color in document to color table",
7fd59977 1279 __FILE__, addColor, g);
1280
9196ea9d 1281 di.Add ("XRemoveColor","Doc Label"
1282 "\t: Remove color in document from color table",
7fd59977 1283 __FILE__, removeColor, g);
1284
9196ea9d 1285 di.Add ("XFindColor","Doc R G B [alpha]"
1286 "\t: Find label where indicated color is situated",
7fd59977 1287 __FILE__, findColor, g);
1288
9196ea9d 1289 di.Add ("XUnsetColor","Doc {Label|Shape} {generic|surface|curve}"
1290 "\t: Unset color",
7fd59977 1291 __FILE__, unsetColor, g);
1292
1293 di.Add ("XSetObjVisibility","Doc {Label|Shape} (0\1) \t: Set the visibility of shape ",
1294 __FILE__, setVisibility, g);
1295
1296 di.Add ("XGetObjVisibility","Doc {Label|Shape} \t: Return the visibility of shape ",
1297 __FILE__, getVisibility, g);
1298
1299 di.Add ("XGetInstanceVisible","Doc Shape \t: Return the visibility of shape ",
1300 __FILE__, getStyledVisibility, g);
1301
9196ea9d 1302 di.Add ("XGetInstanceColor","Doc Shape [{generic|surface|curve}=gen]"
1303 "\t: Return the color of component shape",
7fd59977 1304 __FILE__, getStyledcolor, g);
1305
9196ea9d 1306 di.Add ("XSetInstanceColor","Doc Shape R G B [alpha] [{generic|surface|curve}=gen]"
1307 "\t: sets color for component of shape if SHUO structure exists already",
7fd59977 1308 __FILE__, setStyledcolor, g);
a4815d55 1309
1310 di.Add ("XGetAllVisMaterials","Doc [{-names|-labels}=-names]"
1311 "\t: Print all visualization materials defined in document",
1312 __FILE__, XGetAllVisMaterials, g);
1313 di.Add ("XGetVisMaterial","Doc {Material|Shape}"
1314 "\t: Print visualization material properties",
1315 __FILE__, XGetVisMaterial, g);
1316 di.Add ("XAddVisMaterial",
1317 "Doc Material"
0858125f 1318 "\n\t\t: [-transparency 0..1] [-alphaMode {Opaque|Mask|Blend|BlendAuto} CutOffValue] [-refractionIndex 1..3]"
a4815d55 1319 "\n\t\t: [-diffuse RGB] [-diffuseTexture ImagePath]"
1320 "\n\t\t: [-specular RGB] [-ambient RGB] [-emissive RGB] [-shininess 0..1]"
1321 "\n\t\t: [-baseColor RGB] [-baseColorTexture ImagePath]"
1322 "\n\t\t: [-emissiveFactor RGB] [-emissiveTexture ImagePath]"
1323 "\n\t\t: [-metallic 0..1] [-roughness 0..1] [-metallicRoughnessTexture ImagePath]"
1324 "\n\t\t: [-occlusionTexture ImagePath] [-normalTexture ImagePath]"
1325 "\n\t\t: [-doubleSided {0|1}]"
1326 "\n\t\t: Add material into Document's material table.",
1327 __FILE__, XAddVisMaterial, g);
1328 di.Add ("XRemoveVisMaterial","Doc Material"
1329 "\t: Remove material in document from material table",
1330 __FILE__, XRemoveVisMaterial, g);
1331 di.Add ("XSetVisMaterial", "Doc Shape Material"
1332 "\t: Set material to shape",
1333 __FILE__, XSetVisMaterial, g);
1334 di.Add ("XUnsetVisMaterial", "Doc Shape"
1335 "\t: Unset material from shape",
1336 __FILE__, XSetVisMaterial, g);
7fd59977 1337}