Import: Apply clang format
This commit is contained in:
@@ -22,29 +22,29 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#if defined(__MINGW32__)
|
||||
# define WNT // avoid conflict with GUID
|
||||
#define WNT// avoid conflict with GUID
|
||||
#endif
|
||||
#ifndef _PreComp_
|
||||
# include <climits>
|
||||
# include <gp_Pln.hxx> // for Precision::Confusion()
|
||||
# include <gp_Trsf.hxx>
|
||||
# include <Bnd_Box.hxx>
|
||||
# include <BRepBndLib.hxx>
|
||||
# include <BRep_Builder.hxx>
|
||||
# include <BRepExtrema_DistShapeShape.hxx>
|
||||
# include <Quantity_ColorRGBA.hxx>
|
||||
# include <Standard_Failure.hxx>
|
||||
# include <Standard_Version.hxx>
|
||||
# include <TDataStd_Name.hxx>
|
||||
# include <TDF_ChildIterator.hxx>
|
||||
# include <TDF_Label.hxx>
|
||||
# include <TDF_LabelSequence.hxx>
|
||||
# include <TDocStd_Document.hxx>
|
||||
# include <TopExp_Explorer.hxx>
|
||||
# include <TopoDS_Iterator.hxx>
|
||||
# include <TopTools_IndexedMapOfShape.hxx>
|
||||
# include <XCAFDoc_DocumentTool.hxx>
|
||||
# include <XCAFDoc_Location.hxx>
|
||||
#include <BRepBndLib.hxx>
|
||||
#include <BRepExtrema_DistShapeShape.hxx>
|
||||
#include <BRep_Builder.hxx>
|
||||
#include <Bnd_Box.hxx>
|
||||
#include <Quantity_ColorRGBA.hxx>
|
||||
#include <Standard_Failure.hxx>
|
||||
#include <Standard_Version.hxx>
|
||||
#include <TDF_ChildIterator.hxx>
|
||||
#include <TDF_Label.hxx>
|
||||
#include <TDF_LabelSequence.hxx>
|
||||
#include <TDataStd_Name.hxx>
|
||||
#include <TDocStd_Document.hxx>
|
||||
#include <TopExp_Explorer.hxx>
|
||||
#include <TopTools_IndexedMapOfShape.hxx>
|
||||
#include <TopoDS_Iterator.hxx>
|
||||
#include <XCAFDoc_DocumentTool.hxx>
|
||||
#include <XCAFDoc_Location.hxx>
|
||||
#include <climits>
|
||||
#include <gp_Pln.hxx>// for Precision::Confusion()
|
||||
#include <gp_Trsf.hxx>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
@@ -57,21 +57,21 @@
|
||||
|
||||
|
||||
#ifdef HAVE_TBB
|
||||
# include <tbb/blocked_range.h>
|
||||
# include <tbb/parallel_for.h>
|
||||
# include <tbb/task_group.h>
|
||||
#include <tbb/blocked_range.h>
|
||||
#include <tbb/parallel_for.h>
|
||||
#include <tbb/task_group.h>
|
||||
#endif
|
||||
|
||||
using namespace Import;
|
||||
|
||||
#if OCC_VERSION_HEX >= 0x070500
|
||||
// See https://dev.opencascade.org/content/occt-3d-viewer-becomes-srgb-aware
|
||||
# define OCC_COLOR_SPACE Quantity_TOC_sRGB
|
||||
#define OCC_COLOR_SPACE Quantity_TOC_sRGB
|
||||
#else
|
||||
# define OCC_COLOR_SPACE Quantity_TOC_RGB
|
||||
#define OCC_COLOR_SPACE Quantity_TOC_RGB
|
||||
#endif
|
||||
|
||||
static inline App::Color convertColor(const Quantity_ColorRGBA &c)
|
||||
static inline App::Color convertColor(const Quantity_ColorRGBA& c)
|
||||
{
|
||||
Standard_Real r, g, b;
|
||||
c.GetRGB().Values(r, g, b, OCC_COLOR_SPACE);
|
||||
@@ -84,9 +84,11 @@ static inline App::Color convertColor(const Quantity_ColorRGBA &c)
|
||||
#define OCAF_KEEP_PLACEMENT
|
||||
|
||||
ImportOCAF::ImportOCAF(Handle(TDocStd_Document) h, App::Document* d, const std::string& name)
|
||||
: pDoc(h), doc(d), default_name(name)
|
||||
: pDoc(h)
|
||||
, doc(d)
|
||||
, default_name(name)
|
||||
{
|
||||
aShapeTool = XCAFDoc_DocumentTool::ShapeTool (pDoc->Main());
|
||||
aShapeTool = XCAFDoc_DocumentTool::ShapeTool(pDoc->Main());
|
||||
aColorTool = XCAFDoc_DocumentTool::ColorTool(pDoc->Main());
|
||||
}
|
||||
|
||||
@@ -129,11 +131,14 @@ void ImportOCAF::loadShapes()
|
||||
|
||||
void ImportOCAF::setMerge(bool merge)
|
||||
{
|
||||
this->merge=merge;
|
||||
this->merge = merge;
|
||||
}
|
||||
|
||||
void ImportOCAF::loadShapes(const TDF_Label& label, const TopLoc_Location& loc,
|
||||
const std::string& defaultname, const std::string& assembly, bool isRef,
|
||||
void ImportOCAF::loadShapes(const TDF_Label& label,
|
||||
const TopLoc_Location& loc,
|
||||
const std::string& defaultname,
|
||||
const std::string& assembly,
|
||||
bool isRef,
|
||||
std::vector<App::DocumentObject*>& lValue)
|
||||
{
|
||||
int hash = 0;
|
||||
@@ -143,59 +148,61 @@ void ImportOCAF::loadShapes(const TDF_Label& label, const TopLoc_Location& loc,
|
||||
#endif
|
||||
TopoDS_Shape aShape;
|
||||
|
||||
std::vector<App::DocumentObject *> localValue;
|
||||
std::vector<App::DocumentObject*> localValue;
|
||||
|
||||
if (aShapeTool->GetShape(label,aShape)) {
|
||||
if (aShapeTool->GetShape(label, aShape)) {
|
||||
hash = aShape.HashCode(HashUpper);
|
||||
}
|
||||
|
||||
Handle(TDataStd_Name) name;
|
||||
std::string part_name = defaultname;
|
||||
if (label.FindAttribute(TDataStd_Name::GetID(),name)) {
|
||||
if (label.FindAttribute(TDataStd_Name::GetID(), name)) {
|
||||
TCollection_ExtendedString extstr = name->Get();
|
||||
char* str = new char[extstr.LengthOfCString()+1];
|
||||
char* str = new char[extstr.LengthOfCString() + 1];
|
||||
extstr.ToUTF8CString(str);
|
||||
part_name = str;
|
||||
delete [] str;
|
||||
delete[] str;
|
||||
if (part_name.empty()) {
|
||||
part_name = defaultname;
|
||||
}
|
||||
else {
|
||||
bool ws=true;
|
||||
bool ws = true;
|
||||
for (char it : part_name) {
|
||||
if (it != ' ') {
|
||||
ws = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ws)
|
||||
if (ws) {
|
||||
part_name = defaultname;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TopLoc_Location part_loc = loc;
|
||||
Handle(XCAFDoc_Location) hLoc;
|
||||
if (label.FindAttribute(XCAFDoc_Location::GetID(), hLoc)) {
|
||||
if (isRef)
|
||||
if (isRef) {
|
||||
part_loc = part_loc * hLoc->Get();
|
||||
else
|
||||
}
|
||||
else {
|
||||
part_loc = hLoc->Get();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef FC_DEBUG
|
||||
Base::Console().Log("H:%d, N:%s, T:%d, A:%d, S:%d, C:%d, SS:%d, F:%d, R:%d, C:%d, SS:%d\n",
|
||||
hash,
|
||||
part_name.c_str(),
|
||||
aShapeTool->IsTopLevel(label),
|
||||
aShapeTool->IsAssembly(label),
|
||||
aShapeTool->IsShape(label),
|
||||
aShapeTool->IsCompound(label),
|
||||
aShapeTool->IsSimpleShape(label),
|
||||
aShapeTool->IsFree(label),
|
||||
aShapeTool->IsReference(label),
|
||||
aShapeTool->IsComponent(label),
|
||||
aShapeTool->IsSubShape(label)
|
||||
);
|
||||
hash,
|
||||
part_name.c_str(),
|
||||
aShapeTool->IsTopLevel(label),
|
||||
aShapeTool->IsAssembly(label),
|
||||
aShapeTool->IsShape(label),
|
||||
aShapeTool->IsCompound(label),
|
||||
aShapeTool->IsSimpleShape(label),
|
||||
aShapeTool->IsFree(label),
|
||||
aShapeTool->IsReference(label),
|
||||
aShapeTool->IsComponent(label),
|
||||
aShapeTool->IsSubShape(label));
|
||||
#endif
|
||||
|
||||
#if defined(OCAF_KEEP_PLACEMENT)
|
||||
@@ -215,44 +222,50 @@ void ImportOCAF::loadShapes(const TDF_Label& label, const TopLoc_Location& loc,
|
||||
|
||||
if (isRef || myRefShapes.find(hash) == myRefShapes.end()) {
|
||||
TopoDS_Shape aShape;
|
||||
if (isRef && aShapeTool->GetShape(label, aShape))
|
||||
if (isRef && aShapeTool->GetShape(label, aShape)) {
|
||||
myRefShapes.insert(aShape.HashCode(HashUpper));
|
||||
}
|
||||
|
||||
if (aShapeTool->IsSimpleShape(label) && (isRef || aShapeTool->IsFree(label))) {
|
||||
if (!asm_name.empty())
|
||||
if (!asm_name.empty()) {
|
||||
part_name = asm_name;
|
||||
}
|
||||
|
||||
// TODO: The merge parameter (last one from createShape) should become an Importer/Exporter
|
||||
// option within the FreeCAD preference menu
|
||||
// Currently it is merging STEP Compound Shape into a single Shape Part::Feature which
|
||||
// is an OpenCascade computed Compound
|
||||
if (isRef)
|
||||
// TODO: The merge parameter (last one from createShape) should become an
|
||||
// Importer/Exporter option within the FreeCAD preference menu Currently it is merging
|
||||
// STEP Compound Shape into a single Shape Part::Feature which is an OpenCascade
|
||||
// computed Compound
|
||||
if (isRef) {
|
||||
createShape(label, loc, part_name, lValue, this->merge);
|
||||
else
|
||||
}
|
||||
else {
|
||||
createShape(label, part_loc, part_name, localValue, this->merge);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (aShapeTool->IsSimpleShape(label)) {
|
||||
// We are not creating a list of Part::Feature in that case but just
|
||||
// a single Part::Feature which has as a Shape a Compound of the Subshapes contained
|
||||
// within the global shape
|
||||
// This is standard behavior of many STEP reader and avoid to register a crazy amount of
|
||||
// Shape within the Tree as STEP file do mostly contain large assemblies
|
||||
// This is standard behavior of many STEP reader and avoid to register a crazy
|
||||
// amount of Shape within the Tree as STEP file do mostly contain large assemblies
|
||||
return;
|
||||
}
|
||||
|
||||
// This is probably an Assembly let's try to create a Compound with the name
|
||||
for (TDF_ChildIterator it(label); it.More(); it.Next()) {
|
||||
if (isRef)
|
||||
if (isRef) {
|
||||
loadShapes(it.Value(), part_loc, part_name, asm_name, false, localValue);
|
||||
else
|
||||
}
|
||||
else {
|
||||
loadShapes(it.Value(), part_loc, part_name, asm_name, isRef, localValue);
|
||||
}
|
||||
}
|
||||
|
||||
if (!localValue.empty()) {
|
||||
if (aShapeTool->IsAssembly(label)) {
|
||||
App::Part *pcPart = nullptr;
|
||||
pcPart = static_cast<App::Part*>(doc->addObject("App::Part",asm_name.c_str()));
|
||||
App::Part* pcPart = nullptr;
|
||||
pcPart = static_cast<App::Part*>(doc->addObject("App::Part", asm_name.c_str()));
|
||||
pcPart->Label.setValue(asm_name);
|
||||
pcPart->addObjects(localValue);
|
||||
|
||||
@@ -268,8 +281,11 @@ void ImportOCAF::loadShapes(const TDF_Label& label, const TopLoc_Location& loc,
|
||||
}
|
||||
}
|
||||
|
||||
void ImportOCAF::createShape(const TDF_Label& label, const TopLoc_Location& loc, const std::string& name,
|
||||
std::vector<App::DocumentObject*>& lValue, bool mergeShape)
|
||||
void ImportOCAF::createShape(const TDF_Label& label,
|
||||
const TopLoc_Location& loc,
|
||||
const std::string& name,
|
||||
std::vector<App::DocumentObject*>& lValue,
|
||||
bool mergeShape)
|
||||
{
|
||||
const TopoDS_Shape& aShape = aShapeTool->GetShape(label);
|
||||
#ifdef HAVE_TBB
|
||||
@@ -280,8 +296,8 @@ void ImportOCAF::createShape(const TDF_Label& label, const TopLoc_Location& loc,
|
||||
if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPOUND) {
|
||||
TopExp_Explorer xp;
|
||||
int ctSolids = 0, ctShells = 0, ctVertices = 0, ctEdges = 0;
|
||||
std::vector<App::DocumentObject *> localValue;
|
||||
App::Part *pcPart = nullptr;
|
||||
std::vector<App::DocumentObject*> localValue;
|
||||
App::Part* pcPart = nullptr;
|
||||
|
||||
if (mergeShape) {
|
||||
|
||||
@@ -294,26 +310,26 @@ void ImportOCAF::createShape(const TDF_Label& label, const TopLoc_Location& loc,
|
||||
TopoDS_Compound comp;
|
||||
builder.MakeCompound(comp);
|
||||
|
||||
/*
|
||||
std::vector<App::Color> colors;
|
||||
for (xp.Init(aShape, TopAbs_SOLID); xp.More(); xp.Next(), ctSolids++) {
|
||||
Quantity_Color aColor;
|
||||
App::Color color(0.8f,0.8f,0.8f);
|
||||
if (aColorTool->GetColor(xp.Current(), XCAFDoc_ColorGen, aColor) ||
|
||||
aColorTool->GetColor(xp.Current(), XCAFDoc_ColorSurf, aColor) ||
|
||||
aColorTool->GetColor(xp.Current(), XCAFDoc_ColorCurv, aColor)) {
|
||||
color.r = (float)aColor.Red();
|
||||
color.g = (float)aColor.Green();
|
||||
color.b = (float)aColor.Blue();
|
||||
colors.push_back(color);
|
||||
}
|
||||
}
|
||||
/*
|
||||
std::vector<App::Color> colors;
|
||||
for (xp.Init(aShape, TopAbs_SOLID); xp.More(); xp.Next(), ctSolids++) {
|
||||
Quantity_Color aColor;
|
||||
App::Color color(0.8f,0.8f,0.8f);
|
||||
if (aColorTool->GetColor(xp.Current(), XCAFDoc_ColorGen, aColor) ||
|
||||
aColorTool->GetColor(xp.Current(), XCAFDoc_ColorSurf, aColor) ||
|
||||
aColorTool->GetColor(xp.Current(), XCAFDoc_ColorCurv, aColor)) {
|
||||
color.r = (float)aColor.Red();
|
||||
color.g = (float)aColor.Green();
|
||||
color.b = (float)aColor.Blue();
|
||||
colors.push_back(color);
|
||||
}
|
||||
}
|
||||
|
||||
if (colors.size() > 1) {
|
||||
createShape(label, loc, name, lValue, false);
|
||||
return;
|
||||
}
|
||||
*/
|
||||
if (colors.size() > 1) {
|
||||
createShape(label, loc, name, lValue, false);
|
||||
return;
|
||||
}
|
||||
*/
|
||||
for (xp.Init(aShape, TopAbs_SOLID); xp.More(); xp.Next(), ctSolids++) {
|
||||
const TopoDS_Shape& sh = xp.Current();
|
||||
if (!sh.IsNull()) {
|
||||
@@ -344,7 +360,7 @@ void ImportOCAF::createShape(const TDF_Label& label, const TopLoc_Location& loc,
|
||||
|
||||
// Ok we got a Compound which is computed
|
||||
// Just need to add it to a Part::Feature and push it to lValue
|
||||
if (!comp.IsNull() && (ctSolids||ctShells||ctEdges||ctVertices)) {
|
||||
if (!comp.IsNull() && (ctSolids || ctShells || ctEdges || ctVertices)) {
|
||||
Part::Feature* part = static_cast<Part::Feature*>(doc->addObject("Part::Feature"));
|
||||
// Let's allocate the relative placement of the Compound from the STEP file
|
||||
tryPlacementFromLoc(part, loc);
|
||||
@@ -371,7 +387,7 @@ void ImportOCAF::createShape(const TDF_Label& label, const TopLoc_Location& loc,
|
||||
}
|
||||
|
||||
if (!localValue.empty() && !mergeShape) {
|
||||
pcPart = static_cast<App::Part*>(doc->addObject("App::Part",name.c_str()));
|
||||
pcPart = static_cast<App::Part*>(doc->addObject("App::Part", name.c_str()));
|
||||
pcPart->Label.setValue(name);
|
||||
|
||||
// localValue contain the objects that must added to the local Part
|
||||
@@ -379,39 +395,44 @@ void ImportOCAF::createShape(const TDF_Label& label, const TopLoc_Location& loc,
|
||||
pcPart->addObjects(localValue);
|
||||
|
||||
// Let's compute relative placement of the Part
|
||||
/*
|
||||
gp_Trsf trf;
|
||||
Base::Matrix4D mtrx;
|
||||
if ( loc.IsIdentity() )
|
||||
trf = loc.Transformation();
|
||||
else
|
||||
trf = TopLoc_Location(loc.FirstDatum()).Transformation();
|
||||
Part::TopoShape::convertToMatrix(trf, mtrx);
|
||||
Base::Placement pl;
|
||||
pl.fromMatrix(mtrx);
|
||||
pcPart->Placement.setValue(pl);
|
||||
*/
|
||||
/*
|
||||
gp_Trsf trf;
|
||||
Base::Matrix4D mtrx;
|
||||
if ( loc.IsIdentity() )
|
||||
trf = loc.Transformation();
|
||||
else
|
||||
trf = TopLoc_Location(loc.FirstDatum()).Transformation();
|
||||
Part::TopoShape::convertToMatrix(trf, mtrx);
|
||||
Base::Placement pl;
|
||||
pl.fromMatrix(mtrx);
|
||||
pcPart->Placement.setValue(pl);
|
||||
*/
|
||||
lValue.push_back(pcPart);
|
||||
}
|
||||
|
||||
if (ctSolids > 0 || ctShells > 0)
|
||||
if (ctSolids > 0 || ctShells > 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!aShape.IsNull()) {
|
||||
createShape(aShape, loc, name, lValue);
|
||||
}
|
||||
}
|
||||
|
||||
void ImportOCAF::createShape(const TopoDS_Shape& aShape, const TopLoc_Location& loc, const std::string& name,
|
||||
void ImportOCAF::createShape(const TopoDS_Shape& aShape,
|
||||
const TopLoc_Location& loc,
|
||||
const std::string& name,
|
||||
std::vector<App::DocumentObject*>& lvalue)
|
||||
{
|
||||
Part::Feature* part = static_cast<Part::Feature*>(doc->addObject("Part::Feature"));
|
||||
|
||||
if (!loc.IsIdentity())
|
||||
if (!loc.IsIdentity()) {
|
||||
// part->Shape.setValue(aShape.Moved(TopLoc_Location(loc.FirstDatum())));
|
||||
part->Shape.setValue(aShape.Moved(loc));
|
||||
else
|
||||
}
|
||||
else {
|
||||
part->Shape.setValue(aShape);
|
||||
}
|
||||
|
||||
part->Label.setValue(name);
|
||||
lvalue.push_back(part);
|
||||
@@ -422,10 +443,10 @@ void ImportOCAF::createShape(const TopoDS_Shape& aShape, const TopLoc_Location&
|
||||
void ImportOCAF::loadColors(Part::Feature* part, const TopoDS_Shape& aShape)
|
||||
{
|
||||
Quantity_ColorRGBA aColor;
|
||||
App::Color color(0.8f,0.8f,0.8f);
|
||||
if (aColorTool->GetColor(aShape, XCAFDoc_ColorGen, aColor) ||
|
||||
aColorTool->GetColor(aShape, XCAFDoc_ColorSurf, aColor) ||
|
||||
aColorTool->GetColor(aShape, XCAFDoc_ColorCurv, aColor)) {
|
||||
App::Color color(0.8f, 0.8f, 0.8f);
|
||||
if (aColorTool->GetColor(aShape, XCAFDoc_ColorGen, aColor)
|
||||
|| aColorTool->GetColor(aShape, XCAFDoc_ColorSurf, aColor)
|
||||
|| aColorTool->GetColor(aShape, XCAFDoc_ColorCurv, aColor)) {
|
||||
color = convertColor(aColor);
|
||||
std::vector<App::Color> colors;
|
||||
colors.push_back(color);
|
||||
@@ -433,7 +454,7 @@ void ImportOCAF::loadColors(Part::Feature* part, const TopoDS_Shape& aShape)
|
||||
}
|
||||
|
||||
TopTools_IndexedMapOfShape faces;
|
||||
TopExp_Explorer xp(aShape,TopAbs_FACE);
|
||||
TopExp_Explorer xp(aShape, TopAbs_FACE);
|
||||
while (xp.More()) {
|
||||
faces.Add(xp.Current());
|
||||
xp.Next();
|
||||
@@ -442,14 +463,14 @@ void ImportOCAF::loadColors(Part::Feature* part, const TopoDS_Shape& aShape)
|
||||
bool found_face_color = false;
|
||||
std::vector<App::Color> faceColors;
|
||||
faceColors.resize(faces.Extent(), color);
|
||||
xp.Init(aShape,TopAbs_FACE);
|
||||
xp.Init(aShape, TopAbs_FACE);
|
||||
while (xp.More()) {
|
||||
if (aColorTool->GetColor(xp.Current(), XCAFDoc_ColorGen, aColor) ||
|
||||
aColorTool->GetColor(xp.Current(), XCAFDoc_ColorSurf, aColor) ||
|
||||
aColorTool->GetColor(xp.Current(), XCAFDoc_ColorCurv, aColor)) {
|
||||
if (aColorTool->GetColor(xp.Current(), XCAFDoc_ColorGen, aColor)
|
||||
|| aColorTool->GetColor(xp.Current(), XCAFDoc_ColorSurf, aColor)
|
||||
|| aColorTool->GetColor(xp.Current(), XCAFDoc_ColorCurv, aColor)) {
|
||||
int index = faces.FindIndex(xp.Current());
|
||||
color = convertColor(aColor);
|
||||
faceColors[index-1] = color;
|
||||
faceColors[index - 1] = color;
|
||||
found_face_color = true;
|
||||
}
|
||||
xp.Next();
|
||||
@@ -464,8 +485,7 @@ void ImportOCAF::loadColors(Part::Feature* part, const TopoDS_Shape& aShape)
|
||||
|
||||
ImportOCAFCmd::ImportOCAFCmd(Handle(TDocStd_Document) h, App::Document* d, const std::string& name)
|
||||
: ImportOCAF(h, d, name)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
void ImportOCAFCmd::applyColors(Part::Feature* part, const std::vector<App::Color>& colors)
|
||||
{
|
||||
@@ -475,9 +495,11 @@ void ImportOCAFCmd::applyColors(Part::Feature* part, const std::vector<App::Colo
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
ImportXCAF::ImportXCAF(Handle(TDocStd_Document) h, App::Document* d, const std::string& name)
|
||||
: hdoc(h), doc(d), default_name(name)
|
||||
: hdoc(h)
|
||||
, doc(d)
|
||||
, default_name(name)
|
||||
{
|
||||
aShapeTool = XCAFDoc_DocumentTool::ShapeTool (hdoc->Main());
|
||||
aShapeTool = XCAFDoc_DocumentTool::ShapeTool(hdoc->Main());
|
||||
hColors = XCAFDoc_DocumentTool::ColorTool(hdoc->Main());
|
||||
}
|
||||
|
||||
@@ -487,11 +509,11 @@ void ImportXCAF::loadShapes()
|
||||
{
|
||||
// collect sequence of labels to display
|
||||
TDF_LabelSequence shapeLabels, colorLabels;
|
||||
aShapeTool->GetFreeShapes (shapeLabels);
|
||||
aShapeTool->GetFreeShapes(shapeLabels);
|
||||
hColors->GetColors(colorLabels);
|
||||
|
||||
// set presentations and show
|
||||
for (Standard_Integer i=1; i <= shapeLabels.Length(); i++ ) {
|
||||
for (Standard_Integer i = 1; i <= shapeLabels.Length(); i++) {
|
||||
// get the shapes and attributes
|
||||
const TDF_Label& label = shapeLabels.Value(i);
|
||||
loadShapes(label);
|
||||
@@ -530,8 +552,8 @@ void ImportXCAF::createShape(const TopoDS_Shape& shape, bool perface, bool setna
|
||||
std::map<Standard_Integer, Quantity_ColorRGBA>::const_iterator jt;
|
||||
jt = myColorMap.find(shape.HashCode(INT_MAX));
|
||||
|
||||
App::Color partColor(0.8f,0.8f,0.8f);
|
||||
#if 0//TODO
|
||||
App::Color partColor(0.8f, 0.8f, 0.8f);
|
||||
#if 0// TODO
|
||||
Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(part);
|
||||
if (vp && vp->isDerivedFrom(PartGui::ViewProviderPart::getClassTypeId())) {
|
||||
if (jt != myColorMap.end()) {
|
||||
@@ -558,7 +580,7 @@ void ImportXCAF::createShape(const TopoDS_Shape& shape, bool perface, bool setna
|
||||
// check for colors per face
|
||||
if (perface && !myColorMap.empty()) {
|
||||
TopTools_IndexedMapOfShape faces;
|
||||
TopExp_Explorer xp(shape,TopAbs_FACE);
|
||||
TopExp_Explorer xp(shape, TopAbs_FACE);
|
||||
while (xp.More()) {
|
||||
faces.Add(xp.Current());
|
||||
xp.Next();
|
||||
@@ -567,19 +589,19 @@ void ImportXCAF::createShape(const TopoDS_Shape& shape, bool perface, bool setna
|
||||
bool found_face_color = false;
|
||||
std::vector<App::Color> faceColors;
|
||||
faceColors.resize(faces.Extent(), partColor);
|
||||
xp.Init(shape,TopAbs_FACE);
|
||||
xp.Init(shape, TopAbs_FACE);
|
||||
while (xp.More()) {
|
||||
jt = myColorMap.find(xp.Current().HashCode(INT_MAX));
|
||||
if (jt != myColorMap.end()) {
|
||||
int index = faces.FindIndex(xp.Current());
|
||||
faceColors[index-1] = convertColor(jt->second);
|
||||
faceColors[index - 1] = convertColor(jt->second);
|
||||
found_face_color = true;
|
||||
}
|
||||
xp.Next();
|
||||
}
|
||||
|
||||
if (found_face_color) {
|
||||
#if 0//TODO
|
||||
#if 0// TODO
|
||||
Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(part);
|
||||
if (vp && vp->isDerivedFrom(PartGui::ViewProviderPartExt::getClassTypeId())) {
|
||||
static_cast<PartGui::ViewProviderPartExt*>(vp)->DiffuseColor.setValues(faceColors);
|
||||
@@ -592,53 +614,60 @@ void ImportXCAF::createShape(const TopoDS_Shape& shape, bool perface, bool setna
|
||||
void ImportXCAF::loadShapes(const TDF_Label& label)
|
||||
{
|
||||
TopoDS_Shape aShape;
|
||||
if (aShapeTool->GetShape(label,aShape)) {
|
||||
//if (aShapeTool->IsReference(label)) {
|
||||
// TDF_Label reflabel;
|
||||
// if (aShapeTool->GetReferredShape(label, reflabel)) {
|
||||
// loadShapes(reflabel);
|
||||
// }
|
||||
//}
|
||||
if (aShapeTool->GetShape(label, aShape)) {
|
||||
// if (aShapeTool->IsReference(label)) {
|
||||
// TDF_Label reflabel;
|
||||
// if (aShapeTool->GetReferredShape(label, reflabel)) {
|
||||
// loadShapes(reflabel);
|
||||
// }
|
||||
// }
|
||||
if (aShapeTool->IsTopLevel(label)) {
|
||||
int ctSolids = 0, ctShells = 0, ctComps = 0;
|
||||
// add the shapes
|
||||
TopExp_Explorer xp;
|
||||
for (xp.Init(aShape, TopAbs_SOLID); xp.More(); xp.Next(), ctSolids++)
|
||||
for (xp.Init(aShape, TopAbs_SOLID); xp.More(); xp.Next(), ctSolids++) {
|
||||
this->mySolids[xp.Current().HashCode(INT_MAX)] = (xp.Current());
|
||||
for (xp.Init(aShape, TopAbs_SHELL, TopAbs_SOLID); xp.More(); xp.Next(), ctShells++)
|
||||
}
|
||||
for (xp.Init(aShape, TopAbs_SHELL, TopAbs_SOLID); xp.More(); xp.Next(), ctShells++) {
|
||||
this->myShells[xp.Current().HashCode(INT_MAX)] = (xp.Current());
|
||||
}
|
||||
// if no solids and no shells were found then go for compounds
|
||||
if (ctSolids == 0 && ctShells == 0) {
|
||||
for (xp.Init(aShape, TopAbs_COMPOUND); xp.More(); xp.Next(), ctComps++)
|
||||
for (xp.Init(aShape, TopAbs_COMPOUND); xp.More(); xp.Next(), ctComps++) {
|
||||
this->myCompds[xp.Current().HashCode(INT_MAX)] = (xp.Current());
|
||||
}
|
||||
}
|
||||
if (ctComps == 0) {
|
||||
for (xp.Init(aShape, TopAbs_FACE, TopAbs_SHELL); xp.More(); xp.Next())
|
||||
for (xp.Init(aShape, TopAbs_FACE, TopAbs_SHELL); xp.More(); xp.Next()) {
|
||||
this->myShapes[xp.Current().HashCode(INT_MAX)] = (xp.Current());
|
||||
for (xp.Init(aShape, TopAbs_WIRE, TopAbs_FACE); xp.More(); xp.Next())
|
||||
}
|
||||
for (xp.Init(aShape, TopAbs_WIRE, TopAbs_FACE); xp.More(); xp.Next()) {
|
||||
this->myShapes[xp.Current().HashCode(INT_MAX)] = (xp.Current());
|
||||
for (xp.Init(aShape, TopAbs_EDGE, TopAbs_WIRE); xp.More(); xp.Next())
|
||||
}
|
||||
for (xp.Init(aShape, TopAbs_EDGE, TopAbs_WIRE); xp.More(); xp.Next()) {
|
||||
this->myShapes[xp.Current().HashCode(INT_MAX)] = (xp.Current());
|
||||
for (xp.Init(aShape, TopAbs_VERTEX, TopAbs_EDGE); xp.More(); xp.Next())
|
||||
}
|
||||
for (xp.Init(aShape, TopAbs_VERTEX, TopAbs_EDGE); xp.More(); xp.Next()) {
|
||||
this->myShapes[xp.Current().HashCode(INT_MAX)] = (xp.Current());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// getting color
|
||||
Quantity_ColorRGBA col;
|
||||
if (hColors->GetColor(label, XCAFDoc_ColorGen, col) ||
|
||||
hColors->GetColor(label, XCAFDoc_ColorSurf, col) ||
|
||||
hColors->GetColor(label, XCAFDoc_ColorCurv, col)) {
|
||||
if (hColors->GetColor(label, XCAFDoc_ColorGen, col)
|
||||
|| hColors->GetColor(label, XCAFDoc_ColorSurf, col)
|
||||
|| hColors->GetColor(label, XCAFDoc_ColorCurv, col)) {
|
||||
// add defined color
|
||||
myColorMap[aShape.HashCode(INT_MAX)] = col;
|
||||
}
|
||||
else {
|
||||
// http://www.opencascade.org/org/forum/thread_17107/
|
||||
TopoDS_Iterator it;
|
||||
for (it.Initialize(aShape);it.More(); it.Next()) {
|
||||
if (hColors->GetColor(it.Value(), XCAFDoc_ColorGen, col) ||
|
||||
hColors->GetColor(it.Value(), XCAFDoc_ColorSurf, col) ||
|
||||
hColors->GetColor(it.Value(), XCAFDoc_ColorCurv, col)) {
|
||||
for (it.Initialize(aShape); it.More(); it.Next()) {
|
||||
if (hColors->GetColor(it.Value(), XCAFDoc_ColorGen, col)
|
||||
|| hColors->GetColor(it.Value(), XCAFDoc_ColorSurf, col)
|
||||
|| hColors->GetColor(it.Value(), XCAFDoc_ColorCurv, col)) {
|
||||
// add defined color
|
||||
myColorMap[it.Value().HashCode(INT_MAX)] = col;
|
||||
}
|
||||
@@ -647,14 +676,15 @@ void ImportXCAF::loadShapes(const TDF_Label& label)
|
||||
|
||||
// getting names
|
||||
Handle(TDataStd_Name) name;
|
||||
if (label.FindAttribute(TDataStd_Name::GetID(),name)) {
|
||||
if (label.FindAttribute(TDataStd_Name::GetID(), name)) {
|
||||
TCollection_ExtendedString extstr = name->Get();
|
||||
char* str = new char[extstr.LengthOfCString()+1];
|
||||
char* str = new char[extstr.LengthOfCString() + 1];
|
||||
extstr.ToUTF8CString(str);
|
||||
std::string labelName(str);
|
||||
if (!labelName.empty())
|
||||
if (!labelName.empty()) {
|
||||
myNameMap[aShape.HashCode(INT_MAX)] = labelName;
|
||||
delete [] str;
|
||||
}
|
||||
delete[] str;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
Reference in New Issue
Block a user