Skip to content

Commit

Permalink
Create Compound per STEP file definition within FreeCAD interface
Browse files Browse the repository at this point in the history
STEP hierarchy is in that case respected
  • Loading branch information
Jean-Marie Verdun committed Jan 8, 2017
1 parent b334197 commit 7ccd9a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/Mod/Import/App/ImportOCAF.cpp
Expand Up @@ -70,6 +70,7 @@
#include <App/Document.h>
#include <App/DocumentObjectPy.h>
#include <Mod/Part/App/PartFeature.h>
#include <Mod/Part/App/FeatureCompound.h>
#include <Mod/Part/App/ProgressIndicator.h>
#include <Mod/Part/App/ImportIges.h>
#include <Mod/Part/App/ImportStep.h>
Expand Down Expand Up @@ -193,28 +194,36 @@ 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)
{
const TopoDS_Shape& aShape = aShapeTool->GetShape(label);
BRep_Builder aBuilder;
std::vector<App::DocumentObject*> lValue;

if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPOUND) {
TopExp_Explorer xp;
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++)
createShape(xp.Current(), loc, name);
createShape(xp.Current(), loc, name, lValue);
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)
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"));
if (!loc.IsIdentity())
part->Shape.setValue(aShape.Moved(loc));
else
part->Shape.setValue(aShape);
part->Label.setValue(name);
lvalue.push_back(part);

Quantity_Color aColor;
App::Color color(0.8f,0.8f,0.8f);
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Import/App/ImportOCAF.h
Expand Up @@ -59,7 +59,7 @@ class ImportExport ImportOCAF
private:
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 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>&){}

private:
Expand Down

0 comments on commit 7ccd9a9

Please sign in to comment.