| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | #include <TDataStd_Name.hxx> |
| | #include <TDF_ChildIterator.hxx> |
| | #include <TDF_Tool.hxx> |
| |
|
| |
|
| | #include <boost/algorithm/string.hpp> |
| | #include <boost/format.hpp> |
| |
|
| | #include "Tools.h" |
| | #include <Base/Console.h> |
| | #include <Mod/Part/App/TopoShape.h> |
| |
|
| | |
| | #define OCC_COLOR_SPACE Quantity_TOC_sRGB |
| |
|
| | FC_LOG_LEVEL_INIT("Import", true, true) |
| |
|
| | using namespace Import; |
| |
|
| | Base::Color Tools::convertColor(const Quantity_ColorRGBA& rgba) |
| | { |
| | Standard_Real red, green, blue; |
| | rgba.GetRGB().Values(red, green, blue, OCC_COLOR_SPACE); |
| | return Base::Color( |
| | static_cast<float>(red), |
| | static_cast<float>(green), |
| | static_cast<float>(blue), |
| | static_cast<float>(rgba.Alpha()) |
| | ); |
| | } |
| |
|
| | Quantity_ColorRGBA Tools::convertColor(const Base::Color& col) |
| | { |
| | return Quantity_ColorRGBA(Quantity_Color(col.r, col.g, col.b, OCC_COLOR_SPACE), col.a); |
| | } |
| |
|
| | static inline std::ostream& operator<<(std::ostream& os, const Quantity_ColorRGBA& rgba) |
| | { |
| | Base::Color color = Tools::convertColor(rgba); |
| | auto toHex = [](float v) { |
| | return boost::format("%02X") % static_cast<int>(v * 255); |
| | }; |
| | return os << "#" << toHex(color.r) << toHex(color.g) << toHex(color.b) << toHex(color.a); |
| | } |
| |
|
| | std::string Tools::labelName(TDF_Label label) |
| | { |
| | std::string txt; |
| | Handle(TDataStd_Name) name; |
| | if (!label.IsNull() && label.FindAttribute(TDataStd_Name::GetID(), name)) { |
| | TCollection_ExtendedString extstr = name->Get(); |
| | char* str = new char[extstr.LengthOfCString() + 1]; |
| | extstr.ToUTF8CString(str); |
| | txt = str; |
| | delete[] str; |
| | boost::trim(txt); |
| | } |
| | return txt; |
| | } |
| |
|
| | void Tools::printLabel( |
| | TDF_Label label, |
| | Handle(XCAFDoc_ShapeTool) aShapeTool, |
| | Handle(XCAFDoc_ColorTool) aColorTool, |
| | const char* msg |
| | ) |
| | { |
| | if (label.IsNull() || !FC_LOG_INSTANCE.isEnabled(FC_LOGLEVEL_LOG)) { |
| | return; |
| | } |
| | if (!msg) { |
| | msg = "Label: "; |
| | } |
| | TCollection_AsciiString entry; |
| | TDF_Tool::Entry(label, entry); |
| | std::ostringstream ss; |
| | ss << msg << entry << ", " << labelName(label) << (aShapeTool->IsShape(label) ? ", shape" : "") |
| | << (aShapeTool->IsTopLevel(label) ? ", topLevel" : "") |
| | << (aShapeTool->IsFree(label) ? ", free" : "") |
| | << (aShapeTool->IsAssembly(label) ? ", assembly" : "") |
| | << (aShapeTool->IsSimpleShape(label) ? ", simple" : "") |
| | << (aShapeTool->IsCompound(label) ? ", compound" : "") |
| | << (aShapeTool->IsReference(label) ? ", reference" : "") |
| | << (aShapeTool->IsComponent(label) ? ", component" : "") |
| | << (aShapeTool->IsSubShape(label) ? ", subshape" : ""); |
| | if (aShapeTool->IsSubShape(label)) { |
| | auto shape = aShapeTool->GetShape(label); |
| | if (!shape.IsNull()) { |
| | ss << ", " << Part::TopoShape::shapeName(shape.ShapeType(), true); |
| | } |
| | } |
| | if (aShapeTool->IsShape(label)) { |
| | Quantity_ColorRGBA c; |
| | if (aColorTool->GetColor(label, XCAFDoc_ColorGen, c)) { |
| | ss << ", gc: " << c; |
| | } |
| | if (aColorTool->GetColor(label, XCAFDoc_ColorSurf, c)) { |
| | ss << ", sc: " << c; |
| | } |
| | if (aColorTool->GetColor(label, XCAFDoc_ColorCurv, c)) { |
| | ss << ", cc: " << c; |
| | } |
| | } |
| |
|
| | ss << std::endl; |
| | Base::Console().notify<Base::LogStyle::Log>("ImportOCAF2", ss.str().c_str()); |
| | } |
| |
|
| | void Tools::dumpLabels( |
| | TDF_Label label, |
| | Handle(XCAFDoc_ShapeTool) aShapeTool, |
| | Handle(XCAFDoc_ColorTool) aColorTool, |
| | int depth |
| | ) |
| | { |
| | std::string indent(depth * 2, ' '); |
| | printLabel(label, aShapeTool, aColorTool, indent.c_str()); |
| | TDF_ChildIterator it; |
| | for (it.Initialize(label); it.More(); it.Next()) { |
| | dumpLabels(it.Value(), aShapeTool, aColorTool, depth + 1); |
| | } |
| | } |
| |
|