Export single STEP object with absolute coordinate instead of (0,0,0) as default origin

This commit is contained in:
Jean-Marie Verdun
2017-07-30 21:37:15 +02:00
committed by Yorik van Havre
parent f457280fa2
commit a89dbdc801
4 changed files with 59 additions and 16 deletions

View File

@@ -233,7 +233,8 @@ private:
std::vector<App::Color> colors;
std::vector <TDF_Label> hierarchical_label;
std::vector <TopLoc_Location> hierarchical_loc;
ocaf.saveShape(part, colors, hierarchical_label, hierarchical_loc);
std::vector <App::DocumentObject*> hierarchical_part;
ocaf.saveShape(part, colors, hierarchical_label, hierarchical_loc, hierarchical_part);
}
else {
Base::Console().Message("'%s' is not a shape, export will be ignored.\n", obj->Label.getValue());
@@ -251,7 +252,8 @@ private:
colors.setPyObject(item1.ptr());
std::vector <TDF_Label> hierarchical_label;
std::vector <TopLoc_Location> hierarchical_loc;
ocaf.saveShape(part, colors.getValues(), hierarchical_label, hierarchical_loc);
std::vector <App::DocumentObject*> hierarchical_part;
ocaf.saveShape(part, colors.getValues(), hierarchical_label, hierarchical_loc, hierarchical_part);
}
else {
Base::Console().Message("'%s' is not a shape, export will be ignored.\n", obj->Label.getValue());

View File

@@ -485,7 +485,7 @@ ExportOCAF::ExportOCAF(Handle(TDocStd_Document) h, bool explicitPlacement)
if (keepExplicitPlacement) {
// rootLabel = aShapeTool->NewShape();
// TDataStd_Name::Set(rootLabel, "ASSEMBLY");
Interface_Static::SetIVal("write.step.assembly",1);
Interface_Static::SetIVal("write.step.assembly",2);
}
else {
rootLabel = TDF_TagSource::NewChild(pDoc->Main());
@@ -495,7 +495,7 @@ ExportOCAF::ExportOCAF(Handle(TDocStd_Document) h, bool explicitPlacement)
// This function create an Assembly node into an XCAF document with it's relative placement information
void ExportOCAF::createNode(App::Part* part, int& root_id, std::vector <TDF_Label>& hierarchical_label,std::vector <TopLoc_Location>& hierarchical_loc)
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;
@@ -516,10 +516,11 @@ void ExportOCAF::createNode(App::Part* part, int& root_id, std::vector <TDF_Labe
hierarchical_label.push_back(shapeLabel);
hierarchical_loc.push_back(MyLoc);
hierarchical_part.push_back(part);
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)
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())
@@ -553,11 +554,15 @@ int ExportOCAF::saveShape(Part::Feature* part, const std::vector<App::Color>& co
aShapeTool->SetShape(shapeLabel, baseShape);
TDataStd_Name::Set(shapeLabel, TCollection_ExtendedString(part->Label.getValue(), 1));
/*
if (keepExplicitPlacement) {
aShapeTool->AddComponent(rootLabel, shapeLabel, aLoc);
aShapeTool->AddComponent(aShapeTool->BaseLabel(), shapeLabel, aLoc);
XCAFDoc_Location::Set(shapeLabel,MyLoc);
}
*/
// Add color information
Quantity_Color col;
@@ -604,10 +609,38 @@ int ExportOCAF::saveShape(Part::Feature* part, const std::vector<App::Color>& co
hierarchical_label.push_back(shapeLabel);
hierarchical_loc.push_back(MyLoc);
hierarchical_part.push_back(part);
return(hierarchical_label.size());
}
// This function is re-allocating Free XCAF document shapes with absolute coordinate
void ExportOCAF::reallocateFreeShape(std::vector <TDF_Label>& hierarchical_label,std::vector <TopLoc_Location>& hierarchical_loc, std::vector <App::DocumentObject*>& hierarchical_part)
{
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());
}
}
}
}
}
// 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)

View File

@@ -79,9 +79,10 @@ private:
class ImportExport ExportOCAF
{
public:
void createNode(App::Part* part, int& root_it, std::vector <TDF_Label>& hierarchical_label,std::vector <TopLoc_Location>& hierarchical_loc);
void createNode(App::Part* part, int& root_it, std::vector <TDF_Label>& hierarchical_label,std::vector <TopLoc_Location>& hierarchical_loc, std::vector <App::DocumentObject*>& hierarchical_part);
ExportOCAF(Handle(TDocStd_Document) h, bool explicitPlacement);
int saveShape(Part::Feature* part, const std::vector<App::Color>&, std::vector <TDF_Label>& hierarchical_label,std::vector <TopLoc_Location>& hierarchical_loc);
int saveShape(Part::Feature* part, const std::vector<App::Color>&, std::vector <TDF_Label>& hierarchical_label,std::vector <TopLoc_Location>& hierarchical_loc,std::vector <App::DocumentObject*>& hierarchical_part);
void reallocateFreeShape(std::vector <TDF_Label>& hierarchical_label,std::vector <TopLoc_Location>& hierarchical_loc, std::vector <App::DocumentObject*>& hierarchical_part);
void pushNode(int root, int node, std::vector <TDF_Label>& hierarchical_label,std::vector <TopLoc_Location>& hierarchical_loc);

View File

@@ -438,7 +438,8 @@ private:
}
int export_app_object(App::DocumentObject* obj, Import::ExportOCAF ocaf,
std::vector <TDF_Label>& hierarchical_label,
std::vector <TopLoc_Location>& hierarchical_loc)
std::vector <TopLoc_Location>& hierarchical_loc,
std::vector <App::DocumentObject*>& hierarchical_part)
{
std::vector <int> local_label;
int root_id;
@@ -453,11 +454,11 @@ private:
for ( it = entries.begin(); it != entries.end(); it++ ) {
int new_label=0;
new_label=export_app_object((*it),ocaf,hierarchical_label,hierarchical_loc);
new_label=export_app_object((*it),ocaf,hierarchical_label,hierarchical_loc, hierarchical_part);
local_label.push_back(new_label);
}
ocaf.createNode(part,root_id,hierarchical_label,hierarchical_loc);
ocaf.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) {
ocaf.pushNode(root_id,(*label_it), hierarchical_label,hierarchical_loc);
@@ -476,7 +477,7 @@ private:
colors.push_back(static_cast<PartGui::ViewProviderPart*>(vp)->ShapeColor.getValue());
}
return_label=ocaf.saveShape(part, colors,hierarchical_label,hierarchical_loc);
return_label=ocaf.saveShape(part, colors,hierarchical_label,hierarchical_loc,hierarchical_part);
}
return(return_label);
@@ -504,17 +505,21 @@ private:
Import::ExportOCAF ocaf(hDoc, keepExplicitPlacement);
// That stuff is exporting a list of selected oject into FreeCAD Tree
std::vector <TDF_Label> hierarchical_label;
std::vector <TopLoc_Location> hierarchical_loc;
std::vector <App::DocumentObject*> hierarchical_part;
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
PyObject* item = (*it).ptr();
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
std::vector <TDF_Label> hierarchical_label;
std::vector <TopLoc_Location> hierarchical_loc;
export_app_object(obj,ocaf, hierarchical_label, hierarchical_loc);
export_app_object(obj,ocaf, hierarchical_label, hierarchical_loc,hierarchical_part);
}
}
// Free Shapes must have absolute placement and not explicit
ocaf.reallocateFreeShape(hierarchical_label, hierarchical_loc,hierarchical_part);
Base::FileInfo file(Utf8Name.c_str());
if (file.hasExtension("stp") || file.hasExtension("step")) {
//Interface_Static::SetCVal("write.step.schema", "AP214IS");
@@ -524,10 +529,12 @@ private:
optionScheme_214 = hGrp_stp->GetBool("Scheme_214",true);
optionScheme_203 = hGrp_stp->GetBool("Scheme_203",false);
if (optionScheme_214)
Interface_Static::SetCVal("write.step.schema", "AP214CD");
Interface_Static::SetCVal("write.step.schema", "AP214IS");
if (optionScheme_203)
Interface_Static::SetCVal("write.step.schema", "AP203");
STEPCAFControl_Writer writer;
Interface_Static::SetIVal("write.step.assembly",1);
// writer.SetColorMode(Standard_False);
writer.Transfer(hDoc, STEPControl_AsIs);
// edit STEP header