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