Skip to content

Commit

Permalink
Move Step reader to New Part Design workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Marie Verdun authored and wwmayer committed Mar 23, 2017
1 parent bd7d094 commit e9c7822
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 33 deletions.
42 changes: 29 additions & 13 deletions src/Mod/Import/App/ImportOCAF.cpp
Expand Up @@ -68,6 +68,7 @@
#include <App/Application.h>
#include <App/Document.h>
#include <App/DocumentObjectPy.h>
#include <App/Part.h>
#include <Mod/Part/App/PartFeature.h>
#include <Mod/Part/App/FeatureCompound.h>
#include "ImportOCAF.h"
Expand Down Expand Up @@ -107,6 +108,7 @@ void ImportOCAF::loadShapes()
std::vector<App::DocumentObject*> lValue;
myRefShapes.clear();
loadShapes(pDoc->Main(), TopLoc_Location(), default_name, "", false, lValue);
lValue.clear();
}

void ImportOCAF::loadShapes(const TDF_Label& label, const TopLoc_Location& loc,
Expand Down Expand Up @@ -205,20 +207,23 @@ void ImportOCAF::loadShapes(const TDF_Label& label, const TopLoc_Location& loc,
}
else {
// This is probably an Assembly let's try to create a Compound with the name
Part::Compound *pcCompound = NULL;
App::Part *pcPart = NULL;
if (aShapeTool->IsAssembly(label)) {
pcCompound = static_cast<Part::Compound*>(doc->addObject
("Part::Compound",asm_name.c_str()));
pcPart = static_cast<App::Part*>(doc->addObject
("App::Part",asm_name.c_str()));
}

for (TDF_ChildIterator it(label); it.More(); it.Next()) {
loadShapes(it.Value(), part_loc, part_name, asm_name, isRef, localValue);
}

if (pcCompound) {
pcCompound->Links.setValues(localValue);
lValue.push_back(pcCompound);
Node_Shapes.push_back(pcCompound->getNameInDocument());
if (pcPart) {
for (std::size_t i=0; i<localValue.size(); i++) {
pcPart->addObject((localValue[i]));
}

if (!localValue.empty())
lValue.push_back(pcPart);
}
}
}
Expand All @@ -238,18 +243,26 @@ void ImportOCAF::createShape(const TDF_Label& label, const TopLoc_Location& loc,
int ctSolids = 0, ctShells = 0;
std::vector<App::DocumentObject *> localValue;

Part::Compound *pcCompound = static_cast<Part::Compound*>(doc->addObject
("Part::Compound",name.c_str() ));
App::Part *pcPart = NULL;
for (xp.Init(aShape, TopAbs_SOLID); xp.More(); xp.Next(), ctSolids++) {
createShape(xp.Current(), loc, name, localValue);
}
for (xp.Init(aShape, TopAbs_SHELL, TopAbs_SOLID); xp.More(); xp.Next(), ctShells++) {
createShape(xp.Current(), loc, name, localValue);
}

pcCompound->Links.setValues(localValue);
lValue.push_back(pcCompound);
Node_Shapes.push_back(pcCompound->getNameInDocument());
if (!localValue.empty()) {
pcPart = static_cast<App::Part*>(doc->addObject("App::Part",name.c_str()));

// localValue contain the object that I must add to the local Part
// I must add the PartOrigin and the Part itself
for (std::size_t i=0; i<localValue.size(); i++) {
pcPart->addObject(localValue[i]);
}

lValue.push_back(pcPart);
}

if (ctSolids > 0 || ctShells > 0)
return;
}
Expand All @@ -261,12 +274,15 @@ void ImportOCAF::createShape(const TopoDS_Shape& aShape, const TopLoc_Location&
std::vector<App::DocumentObject*>& lvalue)
{
Part::Feature* part = static_cast<Part::Feature*>(doc->addObject("Part::Feature"));

// I probably have to create a Part copy
// as to properly set it up into my new step tree
if (!loc.IsIdentity())
part->Shape.setValue(aShape.Moved(loc));
else
part->Shape.setValue(aShape);

part->Label.setValue(name);
Leaf_Shapes.push_back(part->getNameInDocument());
lvalue.push_back(part);

Quantity_Color aColor;
Expand Down
10 changes: 0 additions & 10 deletions src/Mod/Import/App/ImportOCAF.h
Expand Up @@ -57,12 +57,6 @@ class ImportExport ImportOCAF
ImportOCAF(Handle_TDocStd_Document h, App::Document* d, const std::string& name);
virtual ~ImportOCAF();
void loadShapes();
std::vector<const char *> return_leaf() const {
return Leaf_Shapes;
}
std::vector<const char *> return_node() const {
return Node_Shapes;
}

private:
void loadShapes(const TDF_Label& label, const TopLoc_Location&, const std::string& partname, const std::string& assembly, bool isRef, std::vector<App::DocumentObject*> &);
Expand All @@ -78,10 +72,6 @@ class ImportExport ImportOCAF
std::string default_name;
std::set<int> myRefShapes;
static const int HashUpper = INT_MAX;
// These variables are used to transfer Shape names to the UI backend and decide
// to activate / deactivate the right members for performance improvements
std::vector<const char *> Leaf_Shapes;
std::vector<const char *> Node_Shapes;
};

class ImportExport ExportOCAF
Expand Down
10 changes: 0 additions & 10 deletions src/Mod/Import/Gui/AppImportGuiPy.cpp
Expand Up @@ -407,16 +407,6 @@ class Module : public Py::ExtensionModule<Module>

ImportOCAFExt ocaf(hDoc, pcDoc, file.fileNamePure());
ocaf.loadShapes();

// Shape are loaded we must now sort the one we want to display and the one we do want to hide
Gui::Document *guiDoc = Gui::Application::Instance->activeDocument();
std::vector<const char *>keep_leaf= ocaf.return_leaf();
for (std::vector<const char *>::iterator it = keep_leaf.begin() ; it != keep_leaf.end(); ++it)
guiDoc->setShow((*it));
std::vector<const char *>hide_node= ocaf.return_node();
for (std::vector<const char *>::iterator it = hide_node.begin() ; it != hide_node.end(); ++it)
guiDoc->setHide((*it));

pcDoc->recompute();
}
catch (Standard_Failure) {
Expand Down

0 comments on commit e9c7822

Please sign in to comment.