Fix Placement and Color export within Hierarchical Step exporter of single shapes

This commit is contained in:
Jean-Marie Verdun
2017-07-31 22:33:09 +02:00
parent 10836b58cf
commit 4f69fd5a31
3 changed files with 117 additions and 24 deletions

View File

@@ -614,32 +614,94 @@ int ExportOCAF::saveShape(Part::Feature* part, const std::vector<App::Color>& co
return(hierarchical_label.size());
}
// This function is re-allocating Free XCAF document shapes with absolute coordinate
// 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::reallocateFreeShape(std::vector <TDF_Label>& hierarchical_label,std::vector <TopLoc_Location>& hierarchical_loc, std::vector <App::DocumentObject*>& hierarchical_part)
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);
int n = FreeLabels.Length();
for (int i = 1; i <= n; i++)
{
TDF_Label label = FreeLabels.Value(i);
for ( unsigned long j = 0; j < ( hierarchical_label.size()) ; j++ )
{
if ( label == hierarchical_label.at(j) )
{
// hierarchical part does contain only part currently and not node I should add node
if ( hierarchical_part.at(j)->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()) )
{
Part::Feature * part = static_cast<Part::Feature *>(hierarchical_part.at(j));
aShapeTool->SetShape(label, part->Shape.getValue());
}
}
}
}
TDF_LabelSequence FreeLabels;
aShapeTool->GetFreeShapes(FreeLabels);
int n = FreeLabels.Length();
for (int i = 1; i <= n; i++)
{
TDF_Label label = FreeLabels.Value(i);
for ( unsigned long j = 0; j < ( hierarchical_label.size()) ; j++ )
{
if ( label == hierarchical_label.at(j) )
{
labels.push_back(label);
label_part_id.push_back(j);
}
}
}
}
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)
{
int n = FreeLabels.size();
for (int 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)));
aShapeTool->SetShape(label, part->Shape.getValue());
// Add color information
std::vector<App::Color> colors;
colors=Colors.at(i);
TopoDS_Shape baseShape = part->Shape.getValue();
// Add color information
Quantity_Color col;
std::set<int> face_index;
TopTools_IndexedMapOfShape faces;
TopExp_Explorer xp(baseShape,TopAbs_FACE);
while (xp.More()) {
face_index.insert(faces.Add(xp.Current()));
xp.Next();
}
// define color per face?
if (colors.size() == face_index.size()) {
xp.Init(baseShape,TopAbs_FACE);
while (xp.More()) {
int index = faces.FindIndex(xp.Current());
if (face_index.find(index) != face_index.end()) {
face_index.erase(index);
TDF_Label faceLabel = aShapeTool->AddSubShape(label, xp.Current());
// TDF_Label faceLabel= TDF_TagSource::NewChild(label);
aShapeTool->SetShape(faceLabel, xp.Current());
const App::Color& color = colors[index-1];
Quantity_Parameter mat[3];
mat[0] = color.r;
mat[1] = color.g;
mat[2] = color.b;
col.SetValues(mat[0],mat[1],mat[2],Quantity_TOC_RGB);
aColorTool->SetColor(faceLabel, col, XCAFDoc_ColorSurf);
}
xp.Next();
}
}
else if (!colors.empty()) {
App::Color color = colors.front();
Quantity_Parameter mat[3];
mat[0] = color.r;
mat[1] = color.g;
mat[2] = color.b;
col.SetValues(mat[0],mat[1],mat[2],Quantity_TOC_RGB);
aColorTool->SetColor(label, col, XCAFDoc_ColorGen);
}
}
}
}
// This function is moving a "standard" node into an Assembly node within an XCAF doc