// Created on: 2000-08-04
// Created by: Pavel TELKOV
-// Copyright (c) 2000-2012 OPEN CASCADE SAS
+// Copyright (c) 2000-2014 OPEN CASCADE SAS
//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
-#include <XDEDRAW_Colors.ixx>
-
#include <DBRep.hxx>
#include <DDocStd.hxx>
-
-#include <TCollection_AsciiString.hxx>
-#include <TopoDS_Shape.hxx>
+#include <Draw.hxx>
+#include <Precision.hxx>
#include <Quantity_Color.hxx>
-
-#include <TDF_Tool.hxx>
+#include <Quantity_ColorRGBA.hxx>
+#include <OSD_File.hxx>
+#include <TCollection_AsciiString.hxx>
#include <TDF_Label.hxx>
#include <TDF_LabelSequence.hxx>
+#include <TDF_Tool.hxx>
+#include <TDataStd_Name.hxx>
#include <TDocStd_Document.hxx>
-
+#include <TopoDS_Shape.hxx>
+#include <ViewerTest.hxx>
+#include <XCAFDoc_ColorTool.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <XCAFDoc_ShapeTool.hxx>
-#include <XCAFDoc_ColorTool.hxx>
+#include <XCAFDoc_VisMaterial.hxx>
+#include <XCAFDoc_VisMaterialTool.hxx>
+#include <XDEDRAW_Colors.hxx>
+
+//! Parse XCAFDoc_ColorType enumeration argument.
+static bool parseXDocColorType (const TCollection_AsciiString& theArg,
+ XCAFDoc_ColorType& theType)
+{
+ TCollection_AsciiString anArgCase (theArg);
+ anArgCase.LowerCase();
+ if (anArgCase == "surf"
+ || anArgCase == "surface"
+ || anArgCase == "s")
+ {
+ theType = XCAFDoc_ColorSurf;
+ return true;
+ }
+ else if (anArgCase == "curve"
+ || anArgCase == "c")
+ {
+ theType = XCAFDoc_ColorCurv;
+ return true;
+ }
+ else if (anArgCase == "gen"
+ || anArgCase == "generic")
+ {
+ theType = XCAFDoc_ColorGen;
+ return true;
+ }
+ return false;
+}
+
+//! Print triplet of values.
+template<class S, class T> static S& operator<< (S& theStream, const NCollection_Vec3<T>& theVec)
+{
+ theStream << theVec[0] << " " << theVec[1] << " " << theVec[2];
+ return theStream;
+}
+
+//! Print 4 values.
+template<class S, class T> static S& operator<< (S& theStream, const NCollection_Vec4<T>& theVec)
+{
+ theStream << theVec[0] << " " << theVec[1] << " " << theVec[2] << " " << theVec[3];
+ return theStream;
+}
+
+//! Convert alpha mode into string.
+static const char* alphaModeToString (Graphic3d_AlphaMode theMode)
+{
+ switch (theMode)
+ {
+ case Graphic3d_AlphaMode_Opaque: return "Opaque";
+ case Graphic3d_AlphaMode_Mask: return "Mask";
+ case Graphic3d_AlphaMode_Blend: return "Blend";
+ case Graphic3d_AlphaMode_BlendAuto: return "BlendAuto";
+ }
+ return "";
+}
+
+//! Find existing visualization material in the document.
+static TDF_Label findVisMaterial (const Handle(TDocStd_Document)& theDoc,
+ const TCollection_AsciiString& theKey)
+{
+ Handle(XCAFDoc_VisMaterialTool) aMatTool = XCAFDoc_DocumentTool::VisMaterialTool (theDoc->Main());
+ TDF_Label aMatLab;
+ TDF_Tool::Label (theDoc->GetData(), theKey, aMatLab);
+ if (!aMatLab.IsNull())
+ {
+ return aMatTool->IsMaterial (aMatLab) ? aMatLab : TDF_Label();
+ }
+
+ TDF_LabelSequence aLabels;
+ aMatTool->GetMaterials (aLabels);
+ for (TDF_LabelSequence::Iterator aLabIter (aLabels); aLabIter.More(); aLabIter.Next())
+ {
+ Handle(TDataStd_Name) aNodeName;
+ if (aLabIter.Value().FindAttribute (TDataStd_Name::GetID(), aNodeName)
+ && aNodeName->Get().IsEqual (theKey))
+ {
+ return aLabIter.Value();
+ }
+ }
+ return TDF_Label();
+}
+
+//! Check if image file exists.
+static bool isImageFileExist (const TCollection_AsciiString& thePath)
+{
+ const OSD_Path aPath (thePath);
+ if (!OSD_File (aPath).Exists())
+ {
+ std::cout << "Error: file '" << thePath << " not found\n";
+ return false;
+ }
+ return true;
+}
+
+//! Parse RGB values coming after specified argument.
+static bool parseRgbColor (Standard_Integer& theArgIter,
+ Quantity_Color& theColor,
+ Standard_Integer theNbArgs,
+ const char** theArgVec)
+{
+ Standard_Integer aNbParsed = ViewerTest::ParseColor (theNbArgs - theArgIter - 1,
+ theArgVec + theArgIter + 1,
+ theColor);
+ if (aNbParsed == 0)
+ {
+ std::cout << "Syntax error at '" << theArgVec[theArgIter] << "'\n";
+ return false;
+ }
+ theArgIter += aNbParsed;
+ return true;
+}
+
+//! Parse normalized real value within 0..1 range.
+static bool parseNormalizedReal (const char* theString,
+ Standard_ShortReal& theValue)
+{
+ theValue = (Standard_ShortReal )Draw::Atof (theString);
+ if (theValue < 0.0f || theValue > 1.0f)
+ {
+ std::cerr << "Syntax error at '" << theString << "'\n";
+ return false;
+ }
+ return true;
+}
//=======================================================================
// Section: Work with colors
//=======================================================================
-
-static Standard_Integer setColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static Standard_Integer setColor (Draw_Interpretor& , Standard_Integer argc, const char** argv)
{
- if (argc <6) {
- di<<"Use: "<<argv[0]<<" Doc {Label|Shape} R G B [curve|surf]"<<"\n";
+ if (argc < 4)
+ {
+ std::cout << "Syntax error: wrong number of arguments\n";
return 1;
}
- Handle(TDocStd_Document) Doc;
- DDocStd::GetDocument(argv[1], Doc);
- if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
-
+
+ Handle(TDocStd_Document) aDoc;
+ DDocStd::GetDocument (argv[1], aDoc);
+ if (aDoc.IsNull())
+ {
+ std::cout << "Syntax error: " << argv[1] << " is not a document\n";
+ return 1;
+ }
+
TDF_Label aLabel;
- TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
- Quantity_Color Col ( atof(argv[3]), atof(argv[4]), atof(argv[5]), Quantity_TOC_RGB );
-
- Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
- XCAFDoc_ColorType ctype = ( argc <=6 ? XCAFDoc_ColorGen :
- argv[6][0] == 's' ? XCAFDoc_ColorSurf : XCAFDoc_ColorCurv );
- if ( !aLabel.IsNull() ) {
- myColors->SetColor ( aLabel, Col, ctype );
+ TopoDS_Shape aShape;
+ TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
+ if (aLabel.IsNull())
+ {
+ aShape = DBRep::Get (argv[2]);
+ if (aShape.IsNull())
+ {
+ std::cout << "Syntax error: " << argv[2] << " is not a label nor shape\n";
+ return 1;
+ }
}
- else {
- TopoDS_Shape aShape= DBRep::Get(argv[2]);
- if ( !aShape.IsNull() ) {
- myColors->SetColor ( aShape, Col, ctype );
+
+ Quantity_ColorRGBA aColor;
+ bool isColorDefined = false;
+ XCAFDoc_ColorType aColType = XCAFDoc_ColorGen;
+ for (Standard_Integer anArgIter = 3; anArgIter < argc; ++anArgIter)
+ {
+ if (parseXDocColorType (argv[anArgIter], aColType))
+ {
+ //
+ }
+ else if (!isColorDefined)
+ {
+ isColorDefined = true;
+ Standard_Integer aNbParsed = ViewerTest::ParseColor (argc - anArgIter,
+ argv + anArgIter,
+ aColor);
+ if (aNbParsed == 0)
+ {
+ std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
+ return 1;
+ }
+ anArgIter += aNbParsed - 1;
+ }
+ else
+ {
+ std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
+ return 1;
}
}
+ if (!isColorDefined)
+ {
+ std::cout << "Syntax error: wrong number of arguments\n";
+ return 1;
+ }
+
+ Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+ if (!aLabel.IsNull())
+ {
+ aColorTool->SetColor (aLabel, aColor, aColType);
+ }
+ else if (!aColorTool->SetColor (aShape, aColor, aColType))
+ {
+ std::cout << "Syntax error: " << argv[2] << " is not a label nor shape\n";
+ return 1;
+ }
return 0;
}
static Standard_Integer getColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
- if (argc!=3) {
- di<<"Use: "<<argv[0]<<" Doc Label"<<"\n";
+ if (argc != 3)
+ {
+ std::cout << "Syntax error: wrong number of arguments\n";
+ return 1;
+ }
+
+ Handle(TDocStd_Document) aDoc;
+ DDocStd::GetDocument (argv[1], aDoc);
+ if (aDoc.IsNull())
+ {
+ std::cout << "Syntax error: " << argv[1] << " is not a document\n";
return 1;
}
- Handle(TDocStd_Document) Doc;
- DDocStd::GetDocument(argv[1], Doc);
- if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
TDF_Label aLabel;
- TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
- Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
- Quantity_Color col;
- if ( !myColors->GetColor(aLabel, col) ) return 0;
-
- di << col.StringName ( col.Name() );
-
+ TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
+ Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+ Quantity_ColorRGBA aColor;
+ if (!myColors->GetColor (aLabel, aColor))
+ {
+ return 0;
+ }
+
+ if ((1.0 - aColor.Alpha()) < Precision::Confusion())
+ {
+ di << aColor.GetRGB().StringName (aColor.GetRGB().Name());
+ }
+ else
+ {
+ di << aColor.GetRGB().StringName (aColor.GetRGB().Name()) << " (" << aColor.Alpha() << ")";
+ }
return 0;
}
static Standard_Integer getShapeColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
- if (argc!=4) {
- di<<"Use: "<<argv[0]<<" Doc Label ColorType(s/c)"<<"\n";
+ if (argc != 3 && argc != 4)
+ {
+ std::cout << "Syntax error: wrong number of arguments\n";
+ return 1;
+ }
+
+ Handle(TDocStd_Document) aDoc;
+ DDocStd::GetDocument (argv[1], aDoc);
+ if (aDoc.IsNull())
+ {
+ std::cout << "Syntax error: " << argv[1] << " is not a document\n";
return 1;
}
- Handle(TDocStd_Document) Doc;
- DDocStd::GetDocument(argv[1], Doc);
- if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
TDF_Label aLabel;
- TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
- Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
- Quantity_Color col;
-
- if ( !myColors->GetColor(aLabel, argv[3][0] == 's' ? XCAFDoc_ColorSurf : XCAFDoc_ColorCurv, col) ) return 0;
-
- TCollection_AsciiString Entry;
- Entry = col.StringName ( col.Name() );
- di << Entry.ToCString();
-
+ TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
+ if (aLabel.IsNull())
+ {
+ std::cout << "Syntax error: '" << argv[2] << "' label is not found in the document\n";
+ return 1;
+ }
+
+ Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+ XCAFDoc_ColorType aColType = XCAFDoc_ColorGen;
+ if (argc > 3 && !parseXDocColorType (argv[3], aColType))
+ {
+ std::cout << "Syntax error: unknown color type '" << argv[3] << "'\n";
+ return 1;
+ }
+
+ Quantity_ColorRGBA aColor;
+ if (!myColors->GetColor (aLabel, aColType, aColor))
+ {
+ return 0;
+ }
+
+ if ((1.0 - aColor.Alpha()) < Precision::Confusion())
+ {
+ di << aColor.GetRGB().StringName(aColor.GetRGB().Name());
+ }
+ else
+ {
+ di << aColor.GetRGB().StringName(aColor.GetRGB().Name()) << " (" << aColor.Alpha() << ")";
+ }
+
return 0;
}
static Standard_Integer getAllColors (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
- if (argc!=2) {
- di<<"Use: "<<argv[0]<<" Doc "<<"\n";
+ if (argc != 2)
+ {
+ std::cout << "Syntax error: wrong number of arguments\n";
return 1;
}
- Handle(TDocStd_Document) Doc;
- DDocStd::GetDocument(argv[1], Doc);
- if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
- TDF_Label aLabel;
- Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
- Quantity_Color col;
- TDF_LabelSequence Labels;
- myColors->GetColors(Labels);
- if (Labels.Length() >= 1) {
- for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
- aLabel = Labels.Value(i);
- if ( !myColors->GetColor(aLabel, col) ) continue;
- di << col.StringName ( col.Name() );
+ Handle(TDocStd_Document) aDoc;
+ DDocStd::GetDocument (argv[1], aDoc);
+ if (aDoc.IsNull())
+ {
+ std::cout << "Syntax error: " << argv[1] << " is not a document\n";
+ return 1;
+ }
+
+ Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+ TDF_LabelSequence aLabels;
+ aColorTool->GetColors (aLabels);
+ if (aLabels.Length() >= 1)
+ {
+ for (TDF_LabelSequence::Iterator aLabIter (aLabels); aLabIter.More(); aLabIter.Next())
+ {
+ Quantity_ColorRGBA aColor;
+ if (!aColorTool->GetColor (aLabIter.Value(), aColor))
+ {
+ continue;
+ }
+ if ((1.0 - aColor.Alpha()) < Precision::Confusion())
+ {
+ di << aColor.GetRGB().StringName (aColor.GetRGB().Name());
+ }
+ else
+ {
+ di << aColor.GetRGB().StringName (aColor.GetRGB().Name()) << " (" << aColor.Alpha() << ")";
+ }
di << " ";
}
}
return 0;
}
-
static Standard_Integer addColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
- if (argc!=5) {
- di<<"Use: "<<argv[0]<<" DocName R G B"<<"\n";
+ if (argc < 3)
+ {
+ std::cout << "Syntax error: wrong number of arguments\n";
return 1;
}
- Handle(TDocStd_Document) Doc;
- DDocStd::GetDocument(argv[1], Doc);
- if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
- TDF_Label aLabel;
- Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
+ Handle(TDocStd_Document) aDoc;
+ DDocStd::GetDocument (argv[1], aDoc);
+ if (aDoc.IsNull())
+ {
+ std::cout << "Syntax error: " << argv[1] << " is not a document\n";
+ return 1;
+ }
- Quantity_Color Col ( atof(argv[2]), atof(argv[3]), atof(argv[4]), Quantity_TOC_RGB );
- aLabel = myColors->AddColor(Col);
-
- TCollection_AsciiString Entry;
- TDF_Tool::Entry(aLabel, Entry);
- di << Entry.ToCString();
+ Quantity_ColorRGBA aColRGBA;
+ Standard_Integer aNbParsed = ViewerTest::ParseColor (argc - 2, argv + 2, aColRGBA);
+ if (aNbParsed != argc - 2)
+ {
+ std::cout << "Syntax error at '" << argv[2] << "'\n";
+ return 1;
+ }
+
+ TCollection_AsciiString anEntry;
+ Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+ TDF_Label aLabel = aColorTool->AddColor (aColRGBA);
+ TDF_Tool::Entry (aLabel, anEntry);
+ di << anEntry;
return 0;
}
-static Standard_Integer removeColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static Standard_Integer removeColor (Draw_Interpretor& , Standard_Integer argc, const char** argv)
{
- if (argc!=3) {
- di<<"Use: "<<argv[0]<<" DocName Label"<<"\n";
+ if (argc != 3)
+ {
+ std::cout << "Syntax error: wrong number of arguments\n";
return 1;
}
- Handle(TDocStd_Document) Doc;
- DDocStd::GetDocument(argv[1], Doc);
- if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
+ Handle(TDocStd_Document) aDoc;
TDF_Label aLabel;
- TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
- Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
- myColors->RemoveColor(aLabel);
-
+ DDocStd::GetDocument (argv[1], aDoc);
+ if (aDoc.IsNull())
+ {
+ std::cout << "Syntax error: " << argv[1] << " is not a document\n";
+ return 1;
+ }
+ TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
+ if (aLabel.IsNull())
+ {
+ std::cout << "Syntax error: " << argv[2] << " label is not found in the document\n";
+ return 1;
+ }
+
+ Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+ aColorTool->RemoveColor (aLabel);
return 0;
}
static Standard_Integer findColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
- if (argc!=5) {
- di<<"Use: "<<argv[0]<<" DocName R G B"<<"\n";
+ if (argc < 3)
+ {
+ std::cout << "Syntax error: wrong number of arguments\n";
return 1;
}
- Handle(TDocStd_Document) Doc;
- DDocStd::GetDocument(argv[1], Doc);
- if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
- Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
-
- Quantity_Color Col ( atof(argv[2]), atof(argv[3]), atof(argv[4]), Quantity_TOC_RGB );
-
- TCollection_AsciiString Entry;
- TDF_Tool::Entry(myColors->FindColor(Col), Entry);
- di << Entry.ToCString();
+ Handle(TDocStd_Document) aDoc;
+ DDocStd::GetDocument (argv[1], aDoc);
+ if (aDoc.IsNull())
+ {
+ std::cout << "Syntax error: " << argv[1] << " is not a document\n";
+ return 1;
+ }
+
+ Quantity_ColorRGBA aColRGBA;
+ Standard_Integer aNbParsed = ViewerTest::ParseColor (argc - 2, argv + 2, aColRGBA);
+ if (aNbParsed != argc - 2)
+ {
+ std::cout << "Syntax error at '" << argv[2] << "'\n";
+ return 1;
+ }
+
+ Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+ TCollection_AsciiString anEntry;
+ TDF_Tool::Entry (aColorTool->FindColor (aColRGBA), anEntry);
+ di << anEntry;
return 0;
}
-static Standard_Integer unsetColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static Standard_Integer unsetColor (Draw_Interpretor& , Standard_Integer argc, const char** argv)
{
- if (argc!=4) {
- di<<"Use: "<<argv[0]<<" DocName {Label|Shape} ColorType"<<"\n";
+ if (argc != 4)
+ {
+ std::cout << "Syntax error: wrong number of arguments\n";
+ return 1;
+ }
+
+ Handle(TDocStd_Document) aDoc;
+ DDocStd::GetDocument (argv[1], aDoc);
+ if (aDoc.IsNull())
+ {
+ std::cout << "Syntax error: " << argv[1] << " is not a document\n";
+ return 1;
+ }
+
+ XCAFDoc_ColorType aColType = XCAFDoc_ColorGen;
+ if (!parseXDocColorType (argv[3], aColType))
+ {
+ std::cout << "Syntax error: unknown color type '" << argv[3] << "'\n";
return 1;
}
- Handle(TDocStd_Document) Doc;
- DDocStd::GetDocument(argv[1], Doc);
- if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
TDF_Label aLabel;
- TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
- Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
- if ( !aLabel.IsNull() ) {
- myColors->UnSetColor(aLabel, argv[3][0] == 's' ? XCAFDoc_ColorSurf : XCAFDoc_ColorCurv);
+ TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
+ Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+ if (!aLabel.IsNull())
+ {
+ myColors->UnSetColor (aLabel, aColType);
+ return 0;
}
- TopoDS_Shape aShape= DBRep::Get(argv[2]);
- if ( !aShape.IsNull() ) {
- myColors->UnSetColor(aShape, argv[3][0] == 's' ? XCAFDoc_ColorSurf : XCAFDoc_ColorCurv);
+
+ TopoDS_Shape aShape = DBRep::Get (argv[2]);
+ if (aShape.IsNull())
+ {
+ std::cout << "Syntax error: " << argv[2] << " is not a label nor shape\n";
+ return 1;
}
+ myColors->UnSetColor (aShape, aColType);
return 0;
}
-static Standard_Integer setVisibility (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static Standard_Integer setVisibility (Draw_Interpretor& , Standard_Integer argc, const char** argv)
{
- if (argc<3) {
- di<<"Use: "<<argv[0]<<"DocName {Lable|Shape} [isvisible(1/0)]"<<"\n";
+ if (argc != 3 && argc != 4)
+ {
+ std::cout << "Syntax error: wrong number of arguments\n";
return 1;
}
- Handle(TDocStd_Document) Doc;
- DDocStd::GetDocument(argv[1], Doc);
- if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
- Handle(XCAFDoc_ColorTool) localTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
- Standard_Boolean isvisible = Standard_False;
- if ( (argc==4) && (atoi(argv[3])==1) ) isvisible = Standard_True;
-
+
+ Handle(TDocStd_Document) aDoc;
TDF_Label aLabel;
- TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
- if ( aLabel.IsNull() ) {
+ DDocStd::GetDocument (argv[1], aDoc);
+ if (aDoc.IsNull())
+ {
+ std::cout << "Syntax error: " << argv[1] << " is not a document\n";
+ return 1;
+ }
+
+ TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
+ Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+ if (aLabel.IsNull())
+ {
// get label by shape
- TopoDS_Shape aShape= DBRep::Get(argv[2]);
- if ( !aShape.IsNull() ) {
- aLabel = localTool->ShapeTool()->FindShape( aShape, Standard_True );
+ TopoDS_Shape aShape = DBRep::Get (argv[2]);
+ if (!aShape.IsNull())
+ {
+ aLabel = aColorTool->ShapeTool()->FindShape (aShape, Standard_True);
}
}
- if ( aLabel.IsNull() ) {
- di << " cannot find indicated label in document" << "\n";
+ if (aLabel.IsNull())
+ {
+ std::cout << "Syntax error: " << argv[2] << " is not a label not shape\n";
return 1;
}
- localTool->SetVisibility( aLabel, isvisible );
+
+ Standard_Boolean isVisible = Standard_False;
+ if (argc == 4)
+ {
+ TCollection_AsciiString aVisArg (argv[3]);
+ if (aVisArg == "1")
+ {
+ isVisible = Standard_True;
+ }
+ else if (aVisArg == "0")
+ {
+ isVisible = Standard_False;
+ }
+ else
+ {
+ std::cout << "Syntax error: unknown argument '" << argv[3] << "'\n";
+ return 1;
+ }
+ }
+ aColorTool->SetVisibility (aLabel, isVisible);
return 0;
}
static Standard_Integer getVisibility (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
- if (argc<3) {
- di<<"Use: "<<argv[0]<<"DocName {Lable|Shape}"<<"\n";
+ if (argc != 3)
+ {
+ std::cout << "Syntax error: wrong number of arguments\n";
return 1;
}
- Handle(TDocStd_Document) Doc;
- DDocStd::GetDocument(argv[1], Doc);
- if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
- Handle(XCAFDoc_ColorTool) localTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
+
+ Handle(TDocStd_Document) aDoc;
+ DDocStd::GetDocument (argv[1], aDoc);
+ if (aDoc.IsNull())
+ {
+ std::cout << "Syntax error: " << argv[1] << " is not a document\n";
+ return 1;
+ }
+
+ Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
TDF_Label aLabel;
- TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
- if ( aLabel.IsNull() ) {
+ TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
+ if (aLabel.IsNull())
+ {
// get label by shape
- TopoDS_Shape aShape= DBRep::Get(argv[2]);
- if ( !aShape.IsNull() ) {
- aLabel = localTool->ShapeTool()->FindShape( aShape, Standard_True );
+ TopoDS_Shape aShape = DBRep::Get (argv[2]);
+ if (!aShape.IsNull())
+ {
+ aLabel = aColorTool->ShapeTool()->FindShape (aShape, Standard_True);
}
}
- if ( aLabel.IsNull() ) {
- di << " cannot find indicated label in document" << "\n";
+ if (aLabel.IsNull())
+ {
+ std::cout << "Syntax error: " << argv[2] << " is not a label not shape\n";
return 1;
}
- if (localTool->IsVisible( aLabel) ) di << 1;
- else di << 0;
+
+ di << (aColorTool->IsVisible (aLabel) ? 1 : 0);
return 0;
}
static Standard_Integer getStyledVisibility (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
- if (argc<3) {
- di<<"Use: "<<argv[0]<<"DocName Shape"<<"\n";
+ if (argc != 3)
+ {
+ std::cout << "Syntax error: wrong number of arguments\n";
return 1;
}
- Handle(TDocStd_Document) Doc;
- DDocStd::GetDocument(argv[1], Doc);
- if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
- Handle(XCAFDoc_ColorTool) localTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
- TopoDS_Shape aShape;
- aShape = DBRep::Get(argv[2]);
- if (localTool->IsInstanceVisible( aShape) ) di << 1;
- else di << 0;
+
+ Handle(TDocStd_Document) aDoc;
+ DDocStd::GetDocument (argv[1], aDoc);
+ TopoDS_Shape aShape = DBRep::Get(argv[2]);
+ if (aDoc.IsNull())
+ {
+ std::cout << "Syntax error: " << argv[1] << " is not a document\n";
+ return 1;
+ }
+ if (aShape.IsNull())
+ {
+ std::cout << "Syntax error: " << argv[2] << " is not a shape\n";
+ return 1;
+ }
+
+ Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+ di << (aColorTool->IsInstanceVisible (aShape) ? 1 : 0);
return 0;
}
static Standard_Integer getStyledcolor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
- if (argc<3) {
- di<<"Use: "<<argv[0]<<" Doc shape colortype(s/c)"<<"\n";
+ if (argc != 3 && argc != 4)
+ {
+ std::cout << "Syntax error: wrong number of arguments\n";
return 1;
}
- Handle(TDocStd_Document) Doc;
- DDocStd::GetDocument(argv[1], Doc);
- if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
- TopoDS_Shape aShape;
- aShape = DBRep::Get(argv[2]);
-
- Quantity_Color col;
- XCAFDoc_ColorType type;
- if ( argv[3] && argv[3][0] == 's' )
- type = XCAFDoc_ColorSurf;
- else if ( argv[3] && argv[3][0] == 'c' )
- type = XCAFDoc_ColorCurv;
- else
- type = XCAFDoc_ColorGen;
- Handle(XCAFDoc_ColorTool) localTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
- if (localTool->GetInstanceColor( aShape, type, col) )
+
+ Handle(TDocStd_Document) aDoc;
+ XCAFDoc_ColorType aColType = XCAFDoc_ColorGen;
+ DDocStd::GetDocument (argv[1], aDoc);
+ TopoDS_Shape aShape = DBRep::Get (argv[2]);
+ if (aDoc.IsNull())
+ {
+ std::cout << "Syntax error: " << argv[1] << " is not a document\n";
+ return 1;
+ }
+ if (aShape.IsNull())
+ {
+ std::cout << "Syntax error: " << argv[2] << " is not a shape\n";
+ return 1;
+ }
+ if (argc > 3 && !parseXDocColorType (argv[3], aColType))
+ {
+ std::cout << "Syntax error: unknown color type '" << argv[3] << "'\n";
+ return 1;
+ }
+
+ Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+ Quantity_ColorRGBA aColor;
+ if (aColorTool->GetInstanceColor (aShape, aColType, aColor))
{
- TCollection_AsciiString Entry;
- Entry = col.StringName ( col.Name() );
- di << Entry.ToCString();
+ if ((1.0 - aColor.Alpha()) < Precision::Confusion())
+ {
+ di << aColor.GetRGB().StringName (aColor.GetRGB().Name());
+ }
+ else
+ {
+ di << aColor.GetRGB().StringName (aColor.GetRGB().Name()) << " (" << aColor.Alpha() << ")";
+ }
}
return 0;
}
-static Standard_Integer setStyledcolor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static Standard_Integer setStyledcolor (Draw_Interpretor& , Standard_Integer argc, const char** argv)
{
- if (argc<6) {
- di<<"Use: "<<argv[0]<<" Doc shape R G B type(s/c)"<<"\n";
+ if (argc < 3)
+ {
+ std::cout << "Syntax error: wrong number of arguments\n";
return 1;
}
- Handle(TDocStd_Document) Doc;
- DDocStd::GetDocument(argv[1], Doc);
- if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
- TopoDS_Shape aShape;
- aShape = DBRep::Get(argv[2]);
-
- Quantity_Color col ( atof(argv[3]), atof(argv[4]), atof(argv[5]), Quantity_TOC_RGB );
- XCAFDoc_ColorType type;
- if ( argv[6] && argv[6][0] == 's' )
- type = XCAFDoc_ColorSurf;
- else if ( argv[6] && argv[6][0] == 'c' )
- type = XCAFDoc_ColorCurv;
+
+ Handle(TDocStd_Document) aDoc;
+ DDocStd::GetDocument (argv[1], aDoc);
+ if (aDoc.IsNull())
+ {
+ std::cout << "Syntax error: " << argv[1] << " is not a document\n";
+ return 1;
+ }
+
+ TopoDS_Shape aShape = DBRep::Get (argv[2]);
+ if (aShape.IsNull())
+ {
+ std::cout << "Syntax error: " << argv[2] << " is not a shape\n";
+ return 1;
+ }
+
+ XCAFDoc_ColorType aColorType = XCAFDoc_ColorGen;
+ Quantity_ColorRGBA aColRGBA;
+ for (Standard_Integer anArgIter = 3; anArgIter < argc; ++anArgIter)
+ {
+ if (parseXDocColorType (argv[anArgIter], aColorType))
+ {
+ //
+ }
+ else
+ {
+ Standard_Integer aNbParsed = ViewerTest::ParseColor (argc - anArgIter,
+ argv + anArgIter,
+ aColRGBA);
+ if (aNbParsed == 0)
+ {
+ std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
+ return 1;
+ }
+ anArgIter += aNbParsed - 1;
+ }
+ }
+
+ Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+ if (!aColorTool->SetInstanceColor (aShape, aColorType, aColRGBA))
+ {
+ std::cout << "Error: cannot set color for the indicated component\n";
+ return 1;
+ }
+ return 0;
+}
+
+// ================================================================
+// Function : XGetAllVisMaterials
+// Purpose :
+// ================================================================
+static Standard_Integer XGetAllVisMaterials (Draw_Interpretor& theDI, Standard_Integer theNbArgs, const char** theArgVec)
+{
+ if (theNbArgs != 2 && theNbArgs != 3)
+ {
+ std::cout << "Syntax error: wrong number of arguments\n";
+ return 1;
+ }
+
+ Handle(TDocStd_Document) aDoc;
+ DDocStd::GetDocument (theArgVec[1], aDoc);
+ if (aDoc.IsNull())
+ {
+ std::cout << "Syntax error: " << theArgVec[1] << " is not a document\n";
+ return 1;
+ }
+
+ bool toPrintNames = true;
+ if (theNbArgs == 3)
+ {
+ TCollection_AsciiString anArgCase (theArgVec[2]);
+ anArgCase.LowerCase();
+ if (anArgCase == "-names")
+ {
+ toPrintNames = true;
+ }
+ else if (anArgCase == "-labels")
+ {
+ toPrintNames = false;
+ }
+ }
+
+ Handle(XCAFDoc_VisMaterialTool) aMatTool = XCAFDoc_DocumentTool::VisMaterialTool (aDoc->Main());
+ TDF_LabelSequence aLabels;
+ aMatTool->GetMaterials (aLabels);
+ Standard_Integer aMatIndex = 1;
+ for (TDF_LabelSequence::Iterator aLabIter (aLabels); aLabIter.More(); aLabIter.Next(), ++aMatIndex)
+ {
+ const TDF_Label& aMatLab = aLabIter.Value();
+ if (!toPrintNames)
+ {
+ TCollection_AsciiString anEntryId;
+ TDF_Tool::Entry (aMatLab, anEntryId);
+ theDI << anEntryId << " ";
+ continue;
+ }
+
+ Handle(TDataStd_Name) aNodeName;
+ if (aMatLab.FindAttribute (TDataStd_Name::GetID(), aNodeName))
+ {
+ theDI << aNodeName->Get() << " ";
+ }
+ else
+ {
+ TCollection_AsciiString aName = TCollection_AsciiString("<UNNAMED") + aMatIndex + ">";
+ theDI << aName << " ";
+ }
+ }
+ return 0;
+}
+
+// ================================================================
+// Function : XGetVisMaterial
+// Purpose :
+// ================================================================
+static Standard_Integer XGetVisMaterial (Draw_Interpretor& theDI, Standard_Integer theNbArgs, const char** theArgVec)
+{
+ if (theNbArgs != 3)
+ {
+ std::cout << "Syntax error: wrong number of arguments\n";
+ return 1;
+ }
+
+ Handle(TDocStd_Document) aDoc;
+ DDocStd::GetDocument (theArgVec[1], aDoc);
+ if (aDoc.IsNull())
+ {
+ std::cout << "Syntax error: " << theArgVec[1] << " is not a document\n";
+ return 1;
+ }
+
+ Handle(XCAFDoc_VisMaterialTool) aMatTool = XCAFDoc_DocumentTool::VisMaterialTool (aDoc->Main());
+ Handle(XCAFDoc_VisMaterial) aMat;
+ TDF_Label aMatLab = findVisMaterial (aDoc, theArgVec[2]);
+ if (!aMatLab.IsNull())
+ {
+ aMat = aMatTool->GetMaterial (aMatLab);
+ }
else
- type = XCAFDoc_ColorGen;
- Handle(XCAFDoc_ColorTool) localTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
- if (!localTool->SetInstanceColor( aShape, type, col) )
{
- di << "cannot set color for the indicated component" << "\n";
+ TDF_Label aShapeLab;
+ TDF_Tool::Label (aDoc->GetData(), theArgVec[2], aShapeLab);
+ if (aShapeLab.IsNull())
+ {
+ TopoDS_Shape aShape = DBRep::Get (theArgVec[2]);
+ if (!aShape.IsNull())
+ {
+ aShapeLab = aMatTool->ShapeTool()->FindShape (aShape);
+ }
+ }
+ if (!aShapeLab.IsNull()
+ && !aMatTool->ShapeTool()->IsShape (aShapeLab))
+ {
+ aShapeLab.Nullify();
+ }
+ if (aShapeLab.IsNull())
+ {
+ std::cout << "Syntax error: " << theArgVec[2] << " is not material nor shape\n";
+ return 1;
+ }
+
+ aMat = aMatTool->GetShapeMaterial (aShapeLab);
+ }
+
+ if (aMat.IsNull())
+ {
+ theDI << "EMPTY\n";
+ return 0;
+ }
+
+ TCollection_AsciiString anEntryId;
+ TDF_Tool::Entry (aMat->Label(), anEntryId);
+ theDI << "Label: " << anEntryId << "\n";
+
+ Handle(TDataStd_Name) aNodeName;
+ if (aMat->Label().FindAttribute (TDataStd_Name::GetID(), aNodeName))
+ {
+ theDI << "Name: " << aNodeName->Get() << "\n";
+ }
+ if (aMat->IsEmpty())
+ {
+ theDI << "EMPTY\n";
+ return 0;
+ }
+ theDI << "AlphaMode: " << alphaModeToString (aMat->AlphaMode()) << "\n";
+ theDI << "AlphaCutOff: " << aMat->AlphaCutOff() << "\n";
+ theDI << "IsDoubleSided: " << aMat->IsDoubleSided() << "\n";
+ if (aMat->HasCommonMaterial())
+ {
+ const XCAFDoc_VisMaterialCommon& aMatCom = aMat->CommonMaterial();
+ theDI << "Common.Ambient: " << (Graphic3d_Vec3 )aMatCom.AmbientColor << "\n";
+ theDI << "Common.Diffuse: " << (Graphic3d_Vec3 )aMatCom.DiffuseColor << "\n";
+ if (!aMatCom.DiffuseTexture.IsNull())
+ {
+ theDI << "Common.DiffuseTexture: " << aMatCom.DiffuseTexture->TextureId() << "\n";
+ }
+ theDI << "Common.Specular: " << (Graphic3d_Vec3 )aMatCom.SpecularColor << "\n";
+ theDI << "Common.Emissive: " << (Graphic3d_Vec3 )aMatCom.EmissiveColor << "\n";
+ theDI << "Common.Shininess: " << aMatCom.Shininess << "\n";
+ theDI << "Common.Transparency: " << aMatCom.Transparency << "\n";
+ }
+ if (aMat->HasPbrMaterial())
+ {
+ const XCAFDoc_VisMaterialPBR& aMatPbr = aMat->PbrMaterial();
+ theDI << "PBR.BaseColor: " << (Graphic3d_Vec3 )aMatPbr.BaseColor.GetRGB() << "\n";
+ theDI << "PBR.Transparency: " << (1.0 - aMatPbr.BaseColor.Alpha()) << "\n";
+ theDI << "PBR.RefractionIndex: " << aMatPbr.RefractionIndex << "\n";
+ if (!aMatPbr.BaseColorTexture.IsNull())
+ {
+ theDI << "PBR.BaseColorTexture: " << aMatPbr.BaseColorTexture->TextureId() << "\n";
+ }
+ theDI << "PBR.EmissiveFactor: " << aMatPbr.EmissiveFactor << "\n";
+ if (!aMatPbr.EmissiveTexture.IsNull())
+ {
+ theDI << "PBR.EmissiveTexture: " << aMatPbr.EmissiveTexture->TextureId() << "\n";
+ }
+ theDI << "PBR.Metallic: " << aMatPbr.Metallic << "\n";
+ theDI << "PBR.Roughness: " << aMatPbr.Roughness << "\n";
+ if (!aMatPbr.MetallicRoughnessTexture.IsNull())
+ {
+ theDI << "PBR.MetallicRoughnessTexture: " << aMatPbr.MetallicRoughnessTexture->TextureId() << "\n";
+ }
+ if (!aMatPbr.OcclusionTexture.IsNull())
+ {
+ theDI << "PBR.OcclusionTexture: " << aMatPbr.OcclusionTexture->TextureId() << "\n";
+ }
+ if (!aMatPbr.NormalTexture.IsNull())
+ {
+ theDI << "PBR.NormalTexture: " << aMatPbr.NormalTexture->TextureId() << "\n";
+ }
+ }
+ return 0;
+}
+
+// ================================================================
+// Function : XAddVisMaterial
+// Purpose :
+// ================================================================
+static Standard_Integer XAddVisMaterial (Draw_Interpretor& , Standard_Integer theNbArgs, const char** theArgVec)
+{
+ if (theNbArgs < 3)
+ {
+ std::cout << "Syntax error: wrong number of arguments\n";
+ return 1;
+ }
+
+ Handle(TDocStd_Document) aDoc;
+ DDocStd::GetDocument (theArgVec[1], aDoc);
+ if (aDoc.IsNull())
+ {
+ std::cout << "Syntax error: " << theArgVec[1] << " is not a document\n";
+ return 1;
+ }
+
+ Handle(XCAFDoc_VisMaterialTool) aMatTool = XCAFDoc_DocumentTool::VisMaterialTool (aDoc->Main());
+ TDF_Label aMatLab = findVisMaterial (aDoc, theArgVec[2]);
+ if (aMatLab.IsNull())
+ {
+ aMatLab = aMatTool->AddMaterial (theArgVec[2]);
+ }
+
+ Handle(XCAFDoc_VisMaterial) aMat = aMatTool->GetMaterial (aMatLab);
+ XCAFDoc_VisMaterialCommon aMatCom = aMat->CommonMaterial();
+ XCAFDoc_VisMaterialPBR aMatPbr = aMat->PbrMaterial();
+ Standard_ShortReal aRealValue = 0.0f;
+ for (Standard_Integer anArgIter = 3; anArgIter < theNbArgs; ++anArgIter)
+ {
+ TCollection_AsciiString anArg (theArgVec[anArgIter]);
+ anArg.LowerCase();
+ if ((anArg == "-transparency"
+ || anArg == "-alpha")
+ && anArgIter + 1 < theNbArgs
+ && parseNormalizedReal (theArgVec[anArgIter + 1], aMatCom.Transparency))
+ {
+ ++anArgIter;
+ if (anArg == "-alpha")
+ {
+ aMatCom.Transparency = 1.0f - aMatCom.Transparency;
+ }
+ aMatPbr.BaseColor.SetAlpha (1.0f - aMatCom.Transparency);
+ }
+ else if (anArgIter + 1 < theNbArgs
+ && (anArg == "-refractionindex" || anArg == "-ior"))
+ {
+ aMatPbr.RefractionIndex = (Standard_ShortReal )Draw::Atof (theArgVec[anArgIter + 1]);
+ if (aMatPbr.RefractionIndex < 1.0f || aMatPbr.RefractionIndex > 3.0f)
+ {
+ std::cout << "Syntax error at '" << anArg << "'\n";
+ return 1;
+ }
+
+ ++anArgIter;
+ aMatPbr.IsDefined = true;
+ }
+ else if (anArg == "-alphaMode"
+ && anArgIter + 2 < theNbArgs
+ && parseNormalizedReal (theArgVec[anArgIter + 2], aRealValue))
+ {
+ TCollection_AsciiString aModeStr (theArgVec[anArgIter + 1]);
+ aModeStr.LowerCase();
+ Graphic3d_AlphaMode anAlphaMode = Graphic3d_AlphaMode_Opaque;
+ if (aModeStr == "opaque")
+ {
+ anAlphaMode = Graphic3d_AlphaMode_Opaque;
+ }
+ else if (aModeStr == "mask")
+ {
+ anAlphaMode = Graphic3d_AlphaMode_Mask;
+ }
+ else if (aModeStr == "blend")
+ {
+ anAlphaMode = Graphic3d_AlphaMode_Blend;
+ }
+ else if (aModeStr == "blendauto")
+ {
+ anAlphaMode = Graphic3d_AlphaMode_BlendAuto;
+ }
+ else
+ {
+ std::cerr << "Syntax error at '" << anArg << "'\n";
+ return 1;
+ }
+ aMat->SetAlphaMode (anAlphaMode, aRealValue);
+ anArgIter += 2;
+ }
+ else if (anArg == "-diffuse"
+ || anArg == "-basecolor"
+ || anArg == "-albedo")
+ {
+ Quantity_ColorRGBA aColorRGBA;
+ Standard_Integer aNbParsed = ViewerTest::ParseColor (theNbArgs - anArgIter - 1,
+ theArgVec + anArgIter + 1,
+ aColorRGBA);
+ if (aNbParsed == 0)
+ {
+ std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
+ return 1;
+ }
+ anArgIter += aNbParsed;
+
+ if (anArg == "-diffuse")
+ {
+ aMatCom.IsDefined = true;
+ aMatCom.DiffuseColor = aColorRGBA.GetRGB();
+ if (aNbParsed == 2 || aNbParsed == 4)
+ {
+ aMatCom.Transparency = 1.0f - aColorRGBA.Alpha();
+ }
+ }
+ else
+ {
+ aMatPbr.IsDefined = true;
+ if (aNbParsed == 2 || aNbParsed == 4)
+ {
+ aMatPbr.BaseColor = aColorRGBA;
+ }
+ else
+ {
+ aMatPbr.BaseColor.SetRGB (aColorRGBA.GetRGB());
+ }
+ }
+ }
+ else if (anArg == "-specular"
+ && parseRgbColor (anArgIter, aMatCom.SpecularColor,
+ theNbArgs, theArgVec))
+ {
+ aMatCom.IsDefined = true;
+ }
+ else if (anArg == "-ambient"
+ && parseRgbColor (anArgIter, aMatCom.AmbientColor,
+ theNbArgs, theArgVec))
+ {
+ aMatCom.IsDefined = true;
+ }
+ else if (anArg == "-emissive"
+ && parseRgbColor (anArgIter, aMatCom.EmissiveColor,
+ theNbArgs, theArgVec))
+ {
+ aMatCom.IsDefined = true;
+ }
+ else if (anArg == "-shininess"
+ && anArgIter + 1 < theNbArgs)
+ {
+ aMatCom.IsDefined = true;
+ aMatCom.Shininess = (float )Draw::Atof (theArgVec[++anArgIter]);
+ if (aMatCom.Shininess < 0.0f || aMatCom.Shininess > 1.0f)
+ {
+ std::cout << "Syntax error at '" << anArg << "'\n";
+ return 1;
+ }
+ }
+ else if (anArgIter + 1 < theNbArgs
+ && anArg == "-diffusetexture"
+ && isImageFileExist (theArgVec[anArgIter + 1]))
+ {
+ aMatCom.IsDefined = true;
+ aMatCom.DiffuseTexture = new Image_Texture (theArgVec[++anArgIter]);
+ }
+ else if (anArgIter + 1 < theNbArgs
+ && anArg == "-basecolortexture"
+ && isImageFileExist (theArgVec[anArgIter + 1]))
+ {
+ aMatPbr.IsDefined = true;
+ aMatPbr.BaseColorTexture = new Image_Texture (theArgVec[++anArgIter]);
+ }
+ else if (anArgIter + 1 < theNbArgs
+ && anArg == "-emissivetexture"
+ && isImageFileExist (theArgVec[anArgIter + 1]))
+ {
+ aMatPbr.IsDefined = true;
+ aMatPbr.EmissiveTexture = new Image_Texture (theArgVec[++anArgIter]);
+ }
+ else if (anArgIter + 1 < theNbArgs
+ && anArg == "-metallicroughnesstexture"
+ && isImageFileExist (theArgVec[anArgIter + 1]))
+ {
+ aMatPbr.IsDefined = true;
+ aMatPbr.MetallicRoughnessTexture = new Image_Texture (theArgVec[++anArgIter]);
+ }
+ else if (anArgIter + 1 < theNbArgs
+ && anArg == "-normaltexture"
+ && isImageFileExist (theArgVec[anArgIter + 1]))
+ {
+ aMatPbr.IsDefined = true;
+ aMatPbr.NormalTexture = new Image_Texture (theArgVec[++anArgIter]);
+ }
+ else if (anArgIter + 1 < theNbArgs
+ && anArg == "-occlusiontexture"
+ && isImageFileExist (theArgVec[anArgIter + 1]))
+ {
+ aMatPbr.IsDefined = true;
+ aMatPbr.OcclusionTexture = new Image_Texture (theArgVec[++anArgIter]);
+ }
+ else if (anArg == "-emissivefactor"
+ && anArgIter + 4 < theNbArgs)
+ {
+ aMatPbr.IsDefined = true;
+ aMatPbr.EmissiveFactor.SetValues ((float )Draw::Atof (theArgVec[anArgIter + 1]),
+ (float )Draw::Atof (theArgVec[anArgIter + 2]),
+ (float )Draw::Atof (theArgVec[anArgIter + 3]));
+ anArgIter += 3;
+ }
+ else if (anArg == "-doublesided")
+ {
+ aMatPbr.IsDefined = true;
+ bool isDoubleSided = true;
+ if (anArgIter + 1 < theNbArgs
+ && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isDoubleSided))
+ {
+ ++anArgIter;
+ }
+ aMat->SetDoubleSided (isDoubleSided);
+ }
+ else if (anArgIter + 1 < theNbArgs
+ && anArg == "-metallic"
+ && parseNormalizedReal (theArgVec[anArgIter + 1], aMatPbr.Metallic))
+ {
+ ++anArgIter;
+ aMatPbr.IsDefined = true;
+ }
+ else if (anArgIter + 1 < theNbArgs
+ && anArg == "-roughness"
+ && parseNormalizedReal (theArgVec[anArgIter + 1], aMatPbr.Roughness))
+ {
+ ++anArgIter;
+ aMatPbr.IsDefined = true;
+ }
+ else
+ {
+ std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
+ return 1;
+ }
+ }
+
+ aMat->SetCommonMaterial (aMatCom);
+ aMat->SetPbrMaterial (aMatPbr);
+ return 0;
+}
+
+// ================================================================
+// Function : XRemoveVisMaterial
+// Purpose :
+// ================================================================
+static Standard_Integer XRemoveVisMaterial (Draw_Interpretor& , Standard_Integer theNbArgs, const char** theArgVec)
+{
+ if (theNbArgs != 3)
+ {
+ std::cout << "Syntax error: wrong number of arguments\n";
+ return 1;
+ }
+
+ Handle(TDocStd_Document) aDoc;
+ DDocStd::GetDocument (theArgVec[1], aDoc);
+ if (aDoc.IsNull())
+ {
+ std::cout << "Syntax error: " << theArgVec[1] << " is not a document\n";
+ return 1;
+ }
+
+ TDF_Label aMatLab = findVisMaterial (aDoc, theArgVec[2]);
+ if (aMatLab.IsNull())
+ {
+ std::cout << "Syntax error: " << theArgVec[2] << " is not a material\n";
+ return 1;
+ }
+
+ Handle(XCAFDoc_VisMaterialTool) aMatTool = XCAFDoc_DocumentTool::VisMaterialTool (aDoc->Main());
+ aMatTool->RemoveMaterial (aMatLab);
+ return 0;
+}
+
+// ================================================================
+// Function : XSetVisMaterial
+// Purpose :
+// ================================================================
+static Standard_Integer XSetVisMaterial (Draw_Interpretor& , Standard_Integer theNbArgs, const char** theArgVec)
+{
+ if (theNbArgs != 3 && theNbArgs != 4)
+ {
+ std::cout << "Syntax error: wrong number of arguments\n";
return 1;
}
+
+ Handle(TDocStd_Document) aDoc;
+ TDF_Label aShapeLab;
+ DDocStd::GetDocument (theArgVec[1], aDoc);
+ if (aDoc.IsNull())
+ {
+ std::cout << "Syntax error: " << theArgVec[1] << " is not a document\n";
+ return 1;
+ }
+
+ TDF_Tool::Label (aDoc->GetData(), theArgVec[2], aShapeLab);
+ Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+ if (aShapeLab.IsNull())
+ {
+ // get label by shape
+ TopoDS_Shape aShape = DBRep::Get (theArgVec[2]);
+ if (!aShape.IsNull())
+ {
+ aShapeLab = aColorTool->ShapeTool()->FindShape (aShape, Standard_True);
+ }
+ }
+ if (aShapeLab.IsNull())
+ {
+ std::cout << "Syntax error: " << theArgVec[2] << " is not a label not shape\n";
+ return 1;
+ }
+
+ TDF_Label aMatLab;
+ if (theNbArgs == 4)
+ {
+ aMatLab = findVisMaterial (aDoc, theArgVec[3]);
+ if (aMatLab.IsNull())
+ {
+ std::cout << "Syntax error: " << theArgVec[3] << " is not a material\n";
+ return 1;
+ }
+ }
+
+ Handle(XCAFDoc_VisMaterialTool) aMatTool = XCAFDoc_DocumentTool::VisMaterialTool (aDoc->Main());
+ aMatTool->SetShapeMaterial (aShapeLab, aMatLab);
return 0;
}
void XDEDRAW_Colors::InitCommands(Draw_Interpretor& di)
{
-
static Standard_Boolean initactor = Standard_False;
- if (initactor) return; initactor = Standard_True;
+ if (initactor)
+ {
+ return;
+ }
+ initactor = Standard_True;
//=====================================
// Work with colors
//=====================================
Standard_CString g = "XDE color's commands";
-
- di.Add ("XSetColor","Doc {Label|Shape} R G B [c|s]\t: Set color [R G B] to shape given by Label, "
+
+ di.Add ("XSetColor","Doc {Label|Shape} R G B [alpha] [{generic|surface|curve}=gen]"
+ "\t: Set color [R G B] to shape given by Label, "
"type of color 's' - for surface, 'c' - for curve (default generic)",
__FILE__, setColor, g);
- di.Add ("XGetColor","Doc label \t: Return color defined on label in colortable",
+ di.Add ("XGetColor","Doc label"
+ "\t: Return color defined on label in colortable",
__FILE__, getColor, g);
- di.Add ("XGetShapeColor","Doc Label ColorType \t: Returns color defined by label",
+ di.Add ("XGetShapeColor","Doc Label {generic|surface|curve}"
+ "\t: Returns color defined by label",
__FILE__, getShapeColor, g);
-
- di.Add ("XGetAllColors","Doc \t: Print all colors that defined in document",
+
+ di.Add ("XGetAllColors","Doc"
+ "\t: Print all colors that defined in document",
__FILE__, getAllColors, g);
- di.Add ("XAddColor","Doc R G B \t: Add color in document to color table",
+ di.Add ("XAddColor","Doc R G B [alpha]"
+ "\t: Add color in document to color table",
__FILE__, addColor, g);
- di.Add ("XRemoveColor","Doc Label \t: Remove color in document from color table",
+ di.Add ("XRemoveColor","Doc Label"
+ "\t: Remove color in document from color table",
__FILE__, removeColor, g);
- di.Add ("XFindColor","Doc R G B \t: Find label where indicated color is situated",
+ di.Add ("XFindColor","Doc R G B [alpha]"
+ "\t: Find label where indicated color is situated",
__FILE__, findColor, g);
- di.Add ("XUnsetColor","Doc {Label|Shape} ColorType \t: Unset color ",
+ di.Add ("XUnsetColor","Doc {Label|Shape} {generic|surface|curve}"
+ "\t: Unset color",
__FILE__, unsetColor, g);
di.Add ("XSetObjVisibility","Doc {Label|Shape} (0\1) \t: Set the visibility of shape ",
di.Add ("XGetInstanceVisible","Doc Shape \t: Return the visibility of shape ",
__FILE__, getStyledVisibility, g);
- di.Add ("XGetInstanceColor","Doc Shape \t: Return the color of component shape ",
+ di.Add ("XGetInstanceColor","Doc Shape [{generic|surface|curve}=gen]"
+ "\t: Return the color of component shape",
__FILE__, getStyledcolor, g);
- di.Add ("XSetInstanceColor","Doc Shape color type \t: sets color for component of shape if SHUO structure exists already ",
+ di.Add ("XSetInstanceColor","Doc Shape R G B [alpha] [{generic|surface|curve}=gen]"
+ "\t: sets color for component of shape if SHUO structure exists already",
__FILE__, setStyledcolor, g);
+ di.Add ("XGetAllVisMaterials","Doc [{-names|-labels}=-names]"
+ "\t: Print all visualization materials defined in document",
+ __FILE__, XGetAllVisMaterials, g);
+ di.Add ("XGetVisMaterial","Doc {Material|Shape}"
+ "\t: Print visualization material properties",
+ __FILE__, XGetVisMaterial, g);
+ di.Add ("XAddVisMaterial",
+ "Doc Material"
+ "\n\t\t: [-transparency 0..1] [-alphaMode {Opaque|Mask|Blend|BlendAuto} CutOffValue] [-refractionIndex 1..3]"
+ "\n\t\t: [-diffuse RGB] [-diffuseTexture ImagePath]"
+ "\n\t\t: [-specular RGB] [-ambient RGB] [-emissive RGB] [-shininess 0..1]"
+ "\n\t\t: [-baseColor RGB] [-baseColorTexture ImagePath]"
+ "\n\t\t: [-emissiveFactor RGB] [-emissiveTexture ImagePath]"
+ "\n\t\t: [-metallic 0..1] [-roughness 0..1] [-metallicRoughnessTexture ImagePath]"
+ "\n\t\t: [-occlusionTexture ImagePath] [-normalTexture ImagePath]"
+ "\n\t\t: [-doubleSided {0|1}]"
+ "\n\t\t: Add material into Document's material table.",
+ __FILE__, XAddVisMaterial, g);
+ di.Add ("XRemoveVisMaterial","Doc Material"
+ "\t: Remove material in document from material table",
+ __FILE__, XRemoveVisMaterial, g);
+ di.Add ("XSetVisMaterial", "Doc Shape Material"
+ "\t: Set material to shape",
+ __FILE__, XSetVisMaterial, g);
+ di.Add ("XUnsetVisMaterial", "Doc Shape"
+ "\t: Unset material from shape",
+ __FILE__, XSetVisMaterial, g);
}