Create Compound per STEP file definition within FreeCAD interface

STEP hierarchy is in that case respected
This commit is contained in:
Jean-Marie Verdun 2017-01-08 21:50:25 +01:00
parent b334197116
commit 7ccd9a95d6
2 changed files with 14 additions and 5 deletions

View File

@ -70,6 +70,7 @@
#include <App/Document.h> #include <App/Document.h>
#include <App/DocumentObjectPy.h> #include <App/DocumentObjectPy.h>
#include <Mod/Part/App/PartFeature.h> #include <Mod/Part/App/PartFeature.h>
#include <Mod/Part/App/FeatureCompound.h>
#include <Mod/Part/App/ProgressIndicator.h> #include <Mod/Part/App/ProgressIndicator.h>
#include <Mod/Part/App/ImportIges.h> #include <Mod/Part/App/ImportIges.h>
#include <Mod/Part/App/ImportStep.h> #include <Mod/Part/App/ImportStep.h>
@ -193,21 +194,28 @@ 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) void ImportOCAF::createShape(const TDF_Label& label, const TopLoc_Location& loc, const std::string& name)
{ {
const TopoDS_Shape& aShape = aShapeTool->GetShape(label); const TopoDS_Shape& aShape = aShapeTool->GetShape(label);
BRep_Builder aBuilder;
std::vector<App::DocumentObject*> lValue;
if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPOUND) { if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPOUND) {
TopExp_Explorer xp; TopExp_Explorer xp;
int ctSolids = 0, ctShells = 0; int ctSolids = 0, ctShells = 0;
Part::Compound *pcCompound = static_cast<Part::Compound*>(doc->addObject
("Part::Compound",name.c_str() ));
for (xp.Init(aShape, TopAbs_SOLID); xp.More(); xp.Next(), ctSolids++) for (xp.Init(aShape, TopAbs_SOLID); xp.More(); xp.Next(), ctSolids++)
createShape(xp.Current(), loc, name); createShape(xp.Current(), loc, name, lValue);
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++)
createShape(xp.Current(), loc, name); createShape(xp.Current(), loc, name, lValue);
pcCompound->Links.setValues(lValue);
if (ctSolids > 0 || ctShells > 0) if (ctSolids > 0 || ctShells > 0)
return; return;
} }
createShape(aShape, loc, name); 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")); Part::Feature* part = static_cast<Part::Feature*>(doc->addObject("Part::Feature"));
if (!loc.IsIdentity()) if (!loc.IsIdentity())
@ -215,6 +223,7 @@ void ImportOCAF::createShape(const TopoDS_Shape& aShape, const TopLoc_Location&
else else
part->Shape.setValue(aShape); part->Shape.setValue(aShape);
part->Label.setValue(name); part->Label.setValue(name);
lvalue.push_back(part);
Quantity_Color aColor; Quantity_Color aColor;
App::Color color(0.8f,0.8f,0.8f); App::Color color(0.8f,0.8f,0.8f);

View File

@ -59,7 +59,7 @@ public:
private: private:
void loadShapes(const TDF_Label& label, const TopLoc_Location&, const std::string& partname, const std::string& assembly, bool isRef); void loadShapes(const TDF_Label& label, const TopLoc_Location&, const std::string& partname, const std::string& assembly, bool isRef);
void createShape(const TDF_Label& label, const TopLoc_Location&, const std::string&); void createShape(const TDF_Label& label, const TopLoc_Location&, const std::string&);
void createShape(const TopoDS_Shape& label, const TopLoc_Location&, const std::string&); void createShape(const TopoDS_Shape& label, const TopLoc_Location&, const std::string&, std::vector<App::DocumentObject*> &);
virtual void applyColors(Part::Feature*, const std::vector<App::Color>&){} virtual void applyColors(Part::Feature*, const std::vector<App::Color>&){}
private: private: