Import: Apply clang format

This commit is contained in:
wmayer
2023-09-10 17:23:58 +02:00
committed by wwmayer
parent ed46125a38
commit b5d0950211
28 changed files with 20674 additions and 14750 deletions

View File

@@ -22,25 +22,25 @@
#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_Ax1.hxx>
# include <gp_Dir.hxx>
# include <gp_Pln.hxx> // for Precision::Confusion()
# include <gp_Trsf.hxx>
# include <Quantity_ColorRGBA.hxx>
# include <Standard_Failure.hxx>
# include <Standard_Version.hxx>
# include <TDataStd_Name.hxx>
# include <TDF_Label.hxx>
# include <TDF_LabelSequence.hxx>
# include <TDocStd_Document.hxx>
# include <TopExp_Explorer.hxx>
# include <TopTools_IndexedMapOfShape.hxx>
# include <XCAFDoc_DocumentTool.hxx>
# include <XCAFDoc_Location.hxx>
#include <Quantity_ColorRGBA.hxx>
#include <Standard_Failure.hxx>
#include <Standard_Version.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 <XCAFDoc_DocumentTool.hxx>
#include <XCAFDoc_Location.hxx>
#include <climits>
#include <gp_Ax1.hxx>
#include <gp_Dir.hxx>
#include <gp_Pln.hxx>// for Precision::Confusion()
#include <gp_Trsf.hxx>
#endif
#include <App/Document.h>
@@ -54,12 +54,12 @@
#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 Quantity_ColorRGBA convertColor(const App::Color &c)
static inline Quantity_ColorRGBA convertColor(const App::Color& c)
{
return Quantity_ColorRGBA(Quantity_Color(c.r, c.g, c.b, OCC_COLOR_SPACE), 1.0 - c.a);
}
@@ -118,8 +118,9 @@ std::vector<App::DocumentObject*> ExportOCAF::filterPart(App::Part* part) const
}
}
if (accept)
if (accept) {
keepObjects.push_back(it);
}
}
entries.swap(keepObjects);
@@ -129,11 +130,11 @@ std::vector<App::DocumentObject*> ExportOCAF::filterPart(App::Part* part) const
}
int ExportOCAF::exportObject(App::DocumentObject* obj,
std::vector <TDF_Label>& hierarchical_label,
std::vector <TopLoc_Location>& hierarchical_loc,
std::vector <App::DocumentObject*>& hierarchical_part)
std::vector<TDF_Label>& hierarchical_label,
std::vector<TopLoc_Location>& hierarchical_loc,
std::vector<App::DocumentObject*>& hierarchical_part)
{
std::vector <int> local_label;
std::vector<int> local_label;
int root_id;
int return_label = -1;
@@ -148,15 +149,16 @@ int ExportOCAF::exportObject(App::DocumentObject* obj,
}
for (it = entries.begin(); it != entries.end(); ++it) {
int new_label=0;
new_label = exportObject((*it), hierarchical_label, hierarchical_loc, hierarchical_part);
int new_label = 0;
new_label =
exportObject((*it), hierarchical_label, hierarchical_loc, hierarchical_part);
local_label.push_back(new_label);
}
createNode(part,root_id, hierarchical_label, hierarchical_loc, hierarchical_part);
createNode(part, root_id, hierarchical_label, hierarchical_loc, hierarchical_part);
std::vector<int>::iterator label_it;
for (label_it = local_label.begin(); label_it != local_label.end(); ++label_it) {
pushNode(root_id,(*label_it), hierarchical_label,hierarchical_loc);
pushNode(root_id, (*label_it), hierarchical_label, hierarchical_loc);
}
return_label = root_id;
@@ -167,17 +169,20 @@ int ExportOCAF::exportObject(App::DocumentObject* obj,
std::vector<App::Color> colors;
findColors(part, colors);
return_label = saveShape(part, colors, hierarchical_label, hierarchical_loc, hierarchical_part);
return_label =
saveShape(part, colors, hierarchical_label, hierarchical_loc, hierarchical_part);
}
return return_label;
}
// This function creates an Assembly node in an XCAF document with its relative placement information
void ExportOCAF::createNode(App::Part* part, int& root_id,
std::vector <TDF_Label>& hierarchical_label,
std::vector <TopLoc_Location>& hierarchical_loc,
std::vector <App::DocumentObject*>& hierarchical_part)
// This function creates an Assembly node in an XCAF document with its relative placement
// information
void ExportOCAF::createNode(App::Part* part,
int& root_id,
std::vector<TDF_Label>& hierarchical_label,
std::vector<TopLoc_Location>& hierarchical_loc,
std::vector<App::DocumentObject*>& hierarchical_part)
{
TDF_Label shapeLabel = aShapeTool->NewShape();
Handle(TDataStd_Name) N;
@@ -192,24 +197,26 @@ void ExportOCAF::createNode(App::Part* part, int& root_id,
gp_Trsf trf;
trf.SetRotation(gp_Ax1(gp_Pnt(), gp_Dir(axis.x, axis.y, axis.z)), angle);
trf.SetTranslationPart(gp_Vec(pl.getPosition().x,pl.getPosition().y,pl.getPosition().z));
trf.SetTranslationPart(gp_Vec(pl.getPosition().x, pl.getPosition().y, pl.getPosition().z));
TopLoc_Location MyLoc = TopLoc_Location(trf);
XCAFDoc_Location::Set(shapeLabel,TopLoc_Location(trf));
XCAFDoc_Location::Set(shapeLabel, TopLoc_Location(trf));
hierarchical_label.push_back(shapeLabel);
hierarchical_loc.push_back(MyLoc);
hierarchical_part.push_back(part);
root_id=hierarchical_label.size();
root_id = hierarchical_label.size();
}
int ExportOCAF::saveShape(Part::Feature* part, const std::vector<App::Color>& colors,
std::vector <TDF_Label>& hierarchical_label,
std::vector <TopLoc_Location>& hierarchical_loc,
std::vector <App::DocumentObject*>& hierarchical_part)
int ExportOCAF::saveShape(Part::Feature* part,
const std::vector<App::Color>& colors,
std::vector<TDF_Label>& hierarchical_label,
std::vector<TopLoc_Location>& hierarchical_loc,
std::vector<App::DocumentObject*>& hierarchical_part)
{
const TopoDS_Shape& shape = part->Shape.getValue();
if (shape.IsNull())
if (shape.IsNull()) {
return -1;
}
TopoDS_Shape baseShape;
TopLoc_Location aLoc;
@@ -221,8 +228,8 @@ int ExportOCAF::saveShape(Part::Feature* part, const std::vector<App::Color>& co
double angle;
rot.getValue(axis, angle);
gp_Trsf trf;
trf.SetRotation(gp_Ax1(gp_Pnt(0.,0.,0.), gp_Dir(axis.x, axis.y, axis.z)), angle);
trf.SetTranslationPart(gp_Vec(pl.getPosition().x,pl.getPosition().y,pl.getPosition().z));
trf.SetRotation(gp_Ax1(gp_Pnt(0., 0., 0.), gp_Dir(axis.x, axis.y, axis.z)), angle);
trf.SetTranslationPart(gp_Vec(pl.getPosition().x, pl.getPosition().y, pl.getPosition().z));
TopLoc_Location MyLoc = TopLoc_Location(trf);
if (keepExplicitPlacement) {
@@ -241,19 +248,19 @@ int ExportOCAF::saveShape(Part::Feature* part, const std::vector<App::Color>& co
TDataStd_Name::Set(shapeLabel, TCollection_ExtendedString(part->Label.getValue(), true));
/*
if (keepExplicitPlacement) {
aShapeTool->AddComponent(aShapeTool->BaseLabel(), shapeLabel, aLoc);
XCAFDoc_Location::Set(shapeLabel,MyLoc);
}
*/
/*
if (keepExplicitPlacement) {
aShapeTool->AddComponent(aShapeTool->BaseLabel(), shapeLabel, aLoc);
XCAFDoc_Location::Set(shapeLabel,MyLoc);
}
*/
// Add color information
Quantity_ColorRGBA col;
std::set<int> face_index;
TopTools_IndexedMapOfShape faces;
TopExp_Explorer xp(baseShape,TopAbs_FACE);
TopExp_Explorer xp(baseShape, TopAbs_FACE);
while (xp.More()) {
face_index.insert(faces.Add(xp.Current()));
xp.Next();
@@ -261,7 +268,7 @@ int ExportOCAF::saveShape(Part::Feature* part, const std::vector<App::Color>& co
// define color per face?
if (colors.size() == face_index.size()) {
xp.Init(baseShape,TopAbs_FACE);
xp.Init(baseShape, TopAbs_FACE);
while (xp.More()) {
int index = faces.FindIndex(xp.Current());
if (face_index.find(index) != face_index.end()) {
@@ -281,7 +288,7 @@ int ExportOCAF::saveShape(Part::Feature* part, const std::vector<App::Color>& co
}
if (!faceLabel.IsNull()) {
const App::Color& color = colors[index-1];
const App::Color& color = colors[index - 1];
col = convertColor(color);
aColorTool->SetColor(faceLabel, col, XCAFDoc_ColorSurf);
}
@@ -299,16 +306,16 @@ int ExportOCAF::saveShape(Part::Feature* part, const std::vector<App::Color>& co
hierarchical_loc.push_back(MyLoc);
hierarchical_part.push_back(part);
return(hierarchical_label.size());
return (hierarchical_label.size());
}
// This function is scanning the OCAF doc for Free Shapes and returns the label attached to it
// If this Free Shapes are regular Part::Feature, we must use absolute coordinate instead of
// allocating a placement into the hierarchy as it is not attached to a hierarchical node
void ExportOCAF::getFreeLabels(std::vector <TDF_Label>& hierarchical_label,
std::vector <TDF_Label>& labels,
std::vector <int>& label_part_id)
void ExportOCAF::getFreeLabels(std::vector<TDF_Label>& hierarchical_label,
std::vector<TDF_Label>& labels,
std::vector<int>& label_part_id)
{
TDF_LabelSequence FreeLabels;
aShapeTool->GetFreeShapes(FreeLabels);
@@ -324,36 +331,38 @@ void ExportOCAF::getFreeLabels(std::vector <TDF_Label>& hierarchical_label,
}
}
void ExportOCAF::getPartColors(std::vector <App::DocumentObject*> hierarchical_part,
std::vector <TDF_Label> FreeLabels,
std::vector <int> part_id,
std::vector < std::vector<App::Color> >& Colors) const
void ExportOCAF::getPartColors(std::vector<App::DocumentObject*> hierarchical_part,
std::vector<TDF_Label> FreeLabels,
std::vector<int> part_id,
std::vector<std::vector<App::Color>>& Colors) const
{
// I am seeking for the colors of each parts
std::size_t n = FreeLabels.size();
for (std::size_t i = 0; i < n; i++) {
std::vector<App::Color> colors;
Part::Feature * part = static_cast<Part::Feature *>(hierarchical_part.at(part_id.at(i)));
Part::Feature* part = static_cast<Part::Feature*>(hierarchical_part.at(part_id.at(i)));
findColors(part, colors);
Colors.push_back(colors);
}
}
void ExportOCAF::reallocateFreeShape(std::vector <App::DocumentObject*> hierarchical_part,
std::vector <TDF_Label> FreeLabels,
std::vector <int> part_id,
std::vector< std::vector<App::Color> >& Colors)
void ExportOCAF::reallocateFreeShape(std::vector<App::DocumentObject*> hierarchical_part,
std::vector<TDF_Label> FreeLabels,
std::vector<int> part_id,
std::vector<std::vector<App::Color>>& Colors)
{
std::size_t n = FreeLabels.size();
for (std::size_t i = 0; i < n; i++) {
TDF_Label label = FreeLabels.at(i);
// hierarchical part does contain only part currently and not node I should add node
if (hierarchical_part.at(part_id.at(i))->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
Part::Feature * part = static_cast<Part::Feature *>(hierarchical_part.at(part_id.at(i)));
if (hierarchical_part.at(part_id.at(i))
->getTypeId()
.isDerivedFrom(Part::Feature::getClassTypeId())) {
Part::Feature* part = static_cast<Part::Feature*>(hierarchical_part.at(part_id.at(i)));
aShapeTool->SetShape(label, part->Shape.getValue());
// Add color information
std::vector<App::Color> colors;
colors=Colors.at(i);
colors = Colors.at(i);
TopoDS_Shape baseShape = part->Shape.getValue();
// Add color information
@@ -361,7 +370,7 @@ void ExportOCAF::reallocateFreeShape(std::vector <App::DocumentObject*> hierarch
std::set<int> face_index;
TopTools_IndexedMapOfShape faces;
TopExp_Explorer xp(baseShape,TopAbs_FACE);
TopExp_Explorer xp(baseShape, TopAbs_FACE);
while (xp.More()) {
face_index.insert(faces.Add(xp.Current()));
xp.Next();
@@ -369,7 +378,7 @@ void ExportOCAF::reallocateFreeShape(std::vector <App::DocumentObject*> hierarch
// define color per face?
if (colors.size() == face_index.size()) {
xp.Init(baseShape,TopAbs_FACE);
xp.Init(baseShape, TopAbs_FACE);
while (xp.More()) {
int index = faces.FindIndex(xp.Current());
if (face_index.find(index) != face_index.end()) {
@@ -389,7 +398,7 @@ void ExportOCAF::reallocateFreeShape(std::vector <App::DocumentObject*> hierarch
}
if (!faceLabel.IsNull()) {
const App::Color& color = colors[index-1];
const App::Color& color = colors[index - 1];
col = convertColor(color);
aColorTool->SetColor(faceLabel, col, XCAFDoc_ColorSurf);
}
@@ -408,26 +417,31 @@ void ExportOCAF::reallocateFreeShape(std::vector <App::DocumentObject*> hierarch
}
// This function is moving a "standard" node into an Assembly node within an XCAF doc
void ExportOCAF::pushNode(int root_id, int node_id, std::vector <TDF_Label>& hierarchical_label,std::vector <TopLoc_Location>& hierarchical_loc)
void ExportOCAF::pushNode(int root_id,
int node_id,
std::vector<TDF_Label>& hierarchical_label,
std::vector<TopLoc_Location>& hierarchical_loc)
{
TDF_Label root;
TDF_Label node;
root = hierarchical_label.at(root_id-1);
node = hierarchical_label.at(node_id-1);
root = hierarchical_label.at(root_id - 1);
node = hierarchical_label.at(node_id - 1);
XCAFDoc_DocumentTool::ShapeTool(root)->AddComponent(root, node, hierarchical_loc.at(node_id-1));
XCAFDoc_DocumentTool::ShapeTool(root)->AddComponent(root,
node,
hierarchical_loc.at(node_id - 1));
}
// ----------------------------------------------------------------------------
ExportOCAFCmd::ExportOCAFCmd(Handle(TDocStd_Document) h, bool explicitPlacement)
: ExportOCAF(h, explicitPlacement)
{
}
: ExportOCAF(h, explicitPlacement)
{}
void ExportOCAFCmd::findColors(Part::Feature* part, std::vector<App::Color>& colors) const
{
std::map<Part::Feature*, std::vector<App::Color> >::const_iterator it = partColors.find(part);
if (it != partColors.end())
std::map<Part::Feature*, std::vector<App::Color>>::const_iterator it = partColors.find(part);
if (it != partColors.end()) {
colors = it->second;
}
}