issue #0002698: Exported STEP-File contains surplus PRODUCTS

This commit is contained in:
wmayer
2017-03-26 18:29:27 +02:00
parent 21dd9aafe9
commit 305e7fa62c
4 changed files with 32 additions and 22 deletions

View File

@@ -209,12 +209,14 @@ private:
std::string name8bit = Part::encodeFilename(Utf8Name);
try {
Py::Sequence list(object);
Handle(XCAFApp_Application) hApp = XCAFApp_Application::GetApplication();
Handle(TDocStd_Document) hDoc;
hApp->NewDocument(TCollection_ExtendedString("MDTV-CAF"), hDoc);
Import::ExportOCAF ocaf(hDoc);
Py::Sequence list(object);
bool keepExplicitPlacement = list.size() > 1;
Import::ExportOCAF ocaf(hDoc, keepExplicitPlacement);
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
PyObject* item = (*it).ptr();
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {

View File

@@ -344,18 +344,20 @@ void ImportOCAF::createShape(const TopoDS_Shape& aShape, const TopLoc_Location&
// ----------------------------------------------------------------------------
ExportOCAF::ExportOCAF(Handle_TDocStd_Document h)
ExportOCAF::ExportOCAF(Handle_TDocStd_Document h, bool explicitPlacement)
: pDoc(h)
, keepExplicitPlacement(explicitPlacement)
{
aShapeTool = XCAFDoc_DocumentTool::ShapeTool(pDoc->Main());
aColorTool = XCAFDoc_DocumentTool::ColorTool(pDoc->Main());
#if defined(OCAF_KEEP_PLACEMENT)
rootLabel = aShapeTool->NewShape();
TDataStd_Name::Set(rootLabel, "ASSEMBLY");
#else
rootLabel = TDF_TagSource::NewChild(pDoc->Main());
#endif
if (keepExplicitPlacement) {
rootLabel = aShapeTool->NewShape();
TDataStd_Name::Set(rootLabel, "ASSEMBLY");
}
else {
rootLabel = TDF_TagSource::NewChild(pDoc->Main());
}
}
void ExportOCAF::saveShape(Part::Feature* part, const std::vector<App::Color>& colors)
@@ -364,13 +366,16 @@ void ExportOCAF::saveShape(Part::Feature* part, const std::vector<App::Color>& c
if (shape.IsNull())
return;
#if defined(OCAF_KEEP_PLACEMENT)
// http://www.opencascade.org/org/forum/thread_18813/?forum=3
TopLoc_Location aLoc = shape.Location();
TopoDS_Shape baseShape = shape.Located(TopLoc_Location());
#else
TopoDS_Shape baseShape = shape;
#endif
TopoDS_Shape baseShape;
TopLoc_Location aLoc;
if (keepExplicitPlacement) {
// http://www.opencascade.org/org/forum/thread_18813/?forum=3
aLoc = shape.Location();
baseShape = shape.Located(TopLoc_Location());
}
else {
baseShape = shape;
}
// Add shape and name
TDF_Label shapeLabel = aShapeTool->NewShape();
@@ -378,9 +383,9 @@ void ExportOCAF::saveShape(Part::Feature* part, const std::vector<App::Color>& c
TDataStd_Name::Set(shapeLabel, TCollection_ExtendedString(part->Label.getValue(), 1));
#if defined(OCAF_KEEP_PLACEMENT)
aShapeTool->AddComponent(rootLabel, shapeLabel, aLoc);
#endif
if (keepExplicitPlacement) {
aShapeTool->AddComponent(rootLabel, shapeLabel, aLoc);
}
// Add color information
Quantity_Color col;

View File

@@ -77,7 +77,7 @@ private:
class ImportExport ExportOCAF
{
public:
ExportOCAF(Handle_TDocStd_Document h);
ExportOCAF(Handle_TDocStd_Document h, bool explicitPlacement);
void saveShape(Part::Feature* part, const std::vector<App::Color>&);
private:
@@ -85,6 +85,7 @@ private:
Handle_XCAFDoc_ShapeTool aShapeTool;
Handle_XCAFDoc_ColorTool aColorTool;
TDF_Label rootLabel;
bool keepExplicitPlacement;
};

View File

@@ -431,12 +431,14 @@ private:
std::string name8bit = Part::encodeFilename(Utf8Name);
try {
Py::Sequence list(object);
Handle(XCAFApp_Application) hApp = XCAFApp_Application::GetApplication();
Handle(TDocStd_Document) hDoc;
hApp->NewDocument(TCollection_ExtendedString("MDTV-CAF"), hDoc);
Import::ExportOCAF ocaf(hDoc);
Py::Sequence list(object);
bool keepExplicitPlacement = list.size() > 1;
Import::ExportOCAF ocaf(hDoc, keepExplicitPlacement);
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
PyObject* item = (*it).ptr();
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {