Clean mod/import folder

Clean mod/import folder

fix code not removed.
This commit is contained in:
Andrew
2023-03-13 16:51:24 +01:00
committed by Uwe
parent de373436cd
commit 0833cbe7cc
10 changed files with 11 additions and 277 deletions

View File

@@ -49,8 +49,6 @@ PyMOD_INIT_FUNC(Import)
// add mesh elements
Base::Interpreter().addType(&Import::StepShapePy ::Type, importModule, "StepShape");
// init Type system
//Import::StepShape ::init();
Base::Console().Log("Loading Import module... done\n");
PyMOD_Return(importModule);

View File

@@ -104,9 +104,6 @@ public:
add_keyword_method("insert",&Module::importer,
"insert(string,string) -- Insert the file into the given document."
);
// add_varargs_method("openAssembly",&Module::importAssembly,
// "openAssembly(string) -- Open the assembly file and create a new document."
// );
add_keyword_method("export",&Module::exporter,
"export(list,string) -- Export a list of objects into a single file."
);
@@ -144,7 +141,6 @@ private:
std::string name8bit = Part::encodeFilename(Utf8Name);
try {
//Base::Console().Log("Insert in Part with %s",Name);
Base::FileInfo file(Utf8Name.c_str());
App::Document *pcDoc = nullptr;
@@ -231,7 +227,6 @@ private:
throw Py::Exception(PyExc_IOError, "no supported file format");
}
#if 1
ImportOCAFExt ocaf(hDoc, pcDoc, file.fileNamePure());
ocaf.setImportOptions(ImportOCAFExt::customImportOptions());
if (merge != Py_None)
@@ -243,14 +238,7 @@ private:
if (mode >= 0)
ocaf.setMode(mode);
ocaf.loadShapes();
#elif 1
Import::ImportOCAFCmd ocaf(hDoc, pcDoc, file.fileNamePure());
ocaf.loadShapes();
#else
Import::ImportXCAF xcaf(hDoc, pcDoc, file.fileNamePure());
xcaf.loadShapes();
pcDoc->recompute();
#endif
hApp->Close(hDoc);
if (!ocaf.partColors.empty()) {
@@ -326,7 +314,6 @@ private:
ocaf.exportObjects(objs);
}
else {
//bool keepExplicitPlacement = objs.size() > 1;
bool keepExplicitPlacement = Standard_True;
ExportOCAF ocaf(hDoc, keepExplicitPlacement);
// That stuff is exporting a list of selected objects into FreeCAD Tree
@@ -340,26 +327,20 @@ private:
std::vector <TDF_Label> FreeLabels;
std::vector <int> part_id;
ocaf.getFreeLabels(hierarchical_label,FreeLabels, part_id);
#if OCC_VERSION_HEX >= 0x070200
// Update is not performed automatically anymore: https://tracker.dev.opencascade.org/view.php?id=28055
XCAFDoc_DocumentTool::ShapeTool(hDoc->Main())->UpdateAssemblies();
#endif
}
Base::FileInfo file(Utf8Name.c_str());
if (file.hasExtension("stp") || file.hasExtension("step")) {
//Interface_Static::SetCVal("write.step.schema", "AP214IS");
STEPCAFControl_Writer writer;
Part::Interface::writeStepAssembly(Part::Interface::Assembly::On);
// writer.SetColorMode(Standard_False);
writer.Transfer(hDoc, STEPControl_AsIs);
APIHeaderSection_MakeHeader makeHeader(writer.ChangeWriter().Model());
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Part")->GetGroup("STEP");
// https://forum.freecadweb.org/viewtopic.php?f=8&t=52967
//makeHeader.SetName(new TCollection_HAsciiString((Standard_CString)Utf8Name.c_str()));
makeHeader.SetAuthorValue (1, new TCollection_HAsciiString(hGrp->GetASCII("Author", "Author").c_str()));
makeHeader.SetOrganizationValue (1, new TCollection_HAsciiString(hGrp->GetASCII("Company").c_str()));
makeHeader.SetOriginatingSystem(new TCollection_HAsciiString(App::Application::getExecutableName().c_str()));
@@ -690,111 +671,7 @@ private:
throw Py::TypeError("expected ([DocObject],path");
}
};
/*
static PyObject * importAssembly(PyObject *self, PyObject *args)
{
char* Name;
PyObject* TargetObjectPy=0;
if (!PyArg_ParseTuple(args, "et|O!","utf-8",&Name,&(App::DocumentObjectPy::Type),&TargetObjectPy))
return 0;
std::string Utf8Name = std::string(Name);
PyMem_Free(Name);
std::string name8bit = Part::encodeFilename(Utf8Name);
PY_TRY {
//Base::Console().Log("Insert in Part with %s",Name);
Base::FileInfo file(name8bit);
App::DocumentObject* target = nullptr;
if(TargetObjectPy)
target = static_cast<App::DocumentObjectPy*>(TargetObjectPy)->getDocumentObjectPtr();
App::Document *pcDoc = 0;
pcDoc = App::GetApplication().getActiveDocument();
if (!pcDoc)
pcDoc = App::GetApplication().newDocument("ImportedAssembly");
Handle(XCAFApp_Application) hApp = XCAFApp_Application::GetApplication();
Handle(TDocStd_Document) hDoc;
hApp->NewDocument(TCollection_ExtendedString("MDTV-CAF"), hDoc);
if (file.hasExtension("stp") || file.hasExtension("step")) {
try {
STEPCAFControl_Reader aReader;
aReader.SetColorMode(true);
aReader.SetNameMode(true);
aReader.SetLayerMode(true);
if (aReader.ReadFile((Standard_CString)(name8bit.c_str())) != IFSelect_RetDone) {
PyErr_SetString(PyExc_IOError, "cannot read STEP file");
return 0;
}
Handle(Message_ProgressIndicator) pi = new Part::ProgressIndicator(100);
aReader.Reader().WS()->MapReader()->SetProgress(pi);
pi->NewScope(100, "Reading STEP file...");
pi->Show();
aReader.Transfer(hDoc);
pi->EndScope();
}
catch (OSD_Exception& e) {
Base::Console().Error("%s\n", e.GetMessageString());
Base::Console().Message("Try to load STEP file without colors...\n");
Part::ImportStepParts(pcDoc,Name);
pcDoc->recompute();
}
}
else if (file.hasExtension("igs") || file.hasExtension("iges")) {
try {
IGESControl_Controller::Init();
Interface_Static::SetIVal("read.surfacecurve.mode",3);
IGESCAFControl_Reader aReader;
aReader.SetColorMode(true);
aReader.SetNameMode(true);
aReader.SetLayerMode(true);
if (aReader.ReadFile((Standard_CString)(name8bit.c_str())) != IFSelect_RetDone) {
PyErr_SetString(PyExc_IOError, "cannot read IGES file");
return 0;
}
Handle(Message_ProgressIndicator) pi = new Part::ProgressIndicator(100);
aReader.WS()->MapReader()->SetProgress(pi);
pi->NewScope(100, "Reading IGES file...");
pi->Show();
aReader.Transfer(hDoc);
pi->EndScope();
}
catch (OSD_Exception& e) {
Base::Console().Error("%s\n", e.GetMessageString());
Base::Console().Message("Try to load IGES file without colors...\n");
Part::ImportIgesParts(pcDoc,Name);
pcDoc->recompute();
}
}
else {
PyErr_SetString(PyExc_RuntimeError, "no supported file format");
return 0;
}
Import::ImportOCAFAssembly ocaf(hDoc, pcDoc, file.fileNamePure(),target);
ocaf.loadAssembly();
pcDoc->recompute();
}
catch (Standard_Failure& e) {
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
return 0;
}
PY_CATCH
Py_Return;
}*/
PyObject* initModule()
{

View File

@@ -41,24 +41,11 @@ void FeatureImportIges::InitLabel(const TDF_Label &rcLabel)
addProperty("String","FileName");
}
/*
bool FeaturePartImportStep::MustExecute(void)
{
Base::Console().Log("PartBoxFeature::MustExecute()\n");
return false;
}
*/
Standard_Integer FeatureImportIges::Execute(void)
{
Base::Console().Log("FeaturePartImportIges::Execute()\n");
/* cout << GetFloatProperty("x") << endl;
cout << GetFloatProperty("y") << endl;
cout << GetFloatProperty("z") << endl;
cout << GetFloatProperty("l") << endl;
cout << GetFloatProperty("h") << endl;
cout << GetFloatProperty("w") << endl;*/
try{
IGESControl_Reader aReader;
@@ -83,10 +70,6 @@ Standard_Integer FeatureImportIges::Execute(void)
if (aReader.ReadFile((const Standard_CString)FileName.c_str()) != IFSelect_RetDone)
throw Base::FileException("IGES read failed (load file)");
// check iges-file (memory)
//if (!aReader.Check(Standard_True))
// Base::Console().Warning( "IGES model contains errors! try loading anyway....\n" );
// make brep
aReader.TransferRoots();
// one shape, who contain's all subshapes
@@ -104,17 +87,3 @@ Standard_Integer FeatureImportIges::Execute(void)
return 0;
}
/*
void FeatureImportIges::Validate(void)
{
Base::Console().Log("FeaturePartImportStep::Validate()\n");
// We validate the object label ( Label() ), all the arguments and the results of the object:
log.SetValid(Label(), Standard_True);
}
*/

View File

@@ -36,21 +36,12 @@ public:
virtual void InitLabel(const TDF_Label &rcLabel);
// virtual bool MustExecute(void);
virtual Standard_Integer Execute(void);
// virtual void Validate(void);
/// Returns the Name/Type of the feature
virtual const char *Type(void){return "PartImportIges";}
/// Returns the Name/Type of the feature
virtual const char *Type(void){return "PartImportIges";}
};
}
#endif // __FeaturePartImportIges_H__

View File

@@ -42,24 +42,11 @@ void FeatureImportStep::InitLabel(const TDF_Label &rcLabel)
}
/*
bool FeaturePartImportStep::MustExecute(void)
{
Base::Console().Log("PartBoxFeature::MustExecute()\n");
return false;
}
*/
Standard_Integer FeatureImportStep::Execute(void)
{
Base::Console().Log("FeaturePartImportStep::Execute()\n");
/* cout << GetFloatProperty("x") << endl;
cout << GetFloatProperty("y") << endl;
cout << GetFloatProperty("z") << endl;
cout << GetFloatProperty("l") << endl;
cout << GetFloatProperty("h") << endl;
cout << GetFloatProperty("w") << endl;*/
try{
STEPControl_Reader aReader;
@@ -92,7 +79,7 @@ Standard_Integer FeatureImportStep::Execute(void)
// Root transfers
Standard_Integer nbr = aReader.NbRootsForTransfer();
//aReader.PrintCheckTransfer (failsonly, IFSelect_ItemsByEntity);
for ( Standard_Integer n = 1; n<= nbr; n++)
{
printf("STEP: Transferring Root %d\n",n);
@@ -124,16 +111,3 @@ Standard_Integer FeatureImportStep::Execute(void)
return 0;
}
/*
void FeatureImportStep::Validate(void)
{
Base::Console().Log("FeaturePartImportStep::Validate()\n");
// We validate the object label ( Label() ), all the arguments and the results of the object:
log.SetValid(Label(), Standard_True);
}
*/

View File

@@ -37,17 +37,12 @@ public:
virtual Standard_Integer Execute(void);
// virtual void Validate(void);
/// Returns the Name/Type of the feature
virtual const char *Type(void){return "PartImportStep";}
/// Returns the Name/Type of the feature
virtual const char *Type(void){return "PartImportStep";}
};
}
#endif // __FeatureImportStep_H__

View File

@@ -560,9 +560,7 @@ bool ImportOCAF2::createGroup(App::Document *doc, Info &info, const TopoDS_Shape
link->Placement.setValue(pla->getValue());
child = link;
}
// child->Visibility.setValue(false);
}
// group->Visibility.setValue(false);
group->ElementList.setValues(children);
group->VisibilityList.setValue(visibilities);
info.obj = group;
@@ -627,7 +625,6 @@ App::DocumentObject* ImportOCAF2::loadShapes()
ret = info.obj;
}
if(ret) {
// ret->Visibility.setValue(true);
ret->recomputeFeature(true);
}
if(options.merge && ret && !ret->isDerivedFrom(Part::Feature::getClassTypeId())) {
@@ -766,7 +763,6 @@ App::DocumentObject *ImportOCAF2::loadShape(App::Document *doc,
}
auto link = static_cast<App::Link*>(doc->addObject("App::Link","Link"));
// link->Visibility.setValue(false);
link->setLink(-1,info.obj);
setPlacement(&link->Placement,shape);
info.obj = link;
@@ -861,7 +857,6 @@ bool ImportOCAF2::createAssembly(App::Document *_doc,
// Okay, we are creating a link array
auto link = static_cast<App::Link*>(doc->addObject("App::Link","Link"));
// link->Visibility.setValue(false);
link->setLink(-1,child);
link->ShowElement.setValue(false);
link->ElementCount.setValue(childInfo.plas.size());
@@ -1182,11 +1177,7 @@ void ExportOCAF2::exportObjects(std::vector<App::DocumentObject*> &objs, const c
if(FC_LOG_INSTANCE.isEnabled(FC_LOGLEVEL_LOG))
dumpLabels(pDoc->Main(),aShapeTool,aColorTool);
#if OCC_VERSION_HEX >= 0x070200
// Update is not performed automatically anymore: https://tracker.dev.opencascade.org/view.php?id=28055
aShapeTool->UpdateAssemblies();
#endif
}
TDF_Label ExportOCAF2::exportObject(App::DocumentObject* parentObj,

View File

@@ -91,21 +91,6 @@ std::string ImportOCAFAssembly::getName(const TDF_Label& label)
part_name = str;
delete [] str;
return part_name;
//if (part_name.empty()) {
// return "";
//}
//else {
// bool ws=true;
// for (std::string::iterator it = part_name.begin(); it != part_name.end(); ++it) {
// if (*it != ' ') {
// ws = false;
// break;
// }
// }
// if (ws)
// part_name = defaultname;
//}
}
return "";
@@ -255,15 +240,6 @@ void ImportOCAFAssembly::createShape(const TopoDS_Shape& aShape, const TopLoc_Lo
std::vector<App::Color> colors;
colors.push_back(color);
applyColors(part, colors);
#if 0//TODO
Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(part);
if (vp && vp->isDerivedFrom(PartGui::ViewProviderPart::getClassTypeId())) {
color.r = aColor.Red();
color.g = aColor.Green();
color.b = aColor.Blue();
static_cast<PartGui::ViewProviderPart*>(vp)->ShapeColor.setValue(color);
}
#endif
}
TopTools_IndexedMapOfShape faces;

View File

@@ -65,25 +65,13 @@ int StepShape::read(const char* fileName)
throw Base::FileException("Cannot open STEP file");
}
//Standard_Integer ic = Interface_Static::IVal("read.precision.mode");
//Standard_Real rp = Interface_Static::RVal("read.maxprecision.val");
//Standard_Integer ic = Interface_Static::IVal("read.maxprecision.mode");
//Standard_Integer mv = Interface_Static::IVal("read.stdsameparameter.mode");
//Standard_Integer rp = Interface_Static::IVal("read.surfacecurve.mode");
//Standard_Real era = Interface_Static::RVal("read.encoderegularity.angle");
//Standard_Integer ic = Interface_Static::IVal("read.step.product.mode");
//Standard_Integer ic = Interface_Static::IVal("read.step.product.context");
//Standard_Integer ic = Interface_Static::IVal("read.step.shape.repr");
//Standard_Integer ic = Interface_Static::IVal("read.step.assembly.level");
//Standard_Integer ic = Interface_Static::IVal("read.step.shape.relationship");
//Standard_Integer ic = Interface_Static::IVal("read.step.shape.aspect");
Handle(TColStd_HSequenceOfTransient) list = aReader.GiveList();
//Use method StepData_StepModel::NextNumberForLabel to find its rank with the following:
//Standard_CString label = "#...";
Handle(StepData_StepModel) model = aReader.StepModel();
//rank = model->NextNumberForLabe(label, 0, Standard_False);
std::cout << "dump of step header:" << std::endl;
#if OCC_VERSION_HEX < 0x070401

View File

@@ -180,15 +180,12 @@ void OCAFBrowser::load(const TDF_Label& label, QTreeWidgetItem* item, const QStr
item->setText(0, text);
}
#if 0
TDF_IDList localList = myList;
#else
TDF_IDList localList;
TDF_AttributeIterator itr (label);
for ( ; itr.More(); itr.Next()) {
localList.Append(itr.Value()->ID());
}
#endif
for (TDF_ListIteratorOfIDList it(localList); it.More(); it.Next()) {
Handle(TDF_Attribute) attr;
@@ -260,15 +257,6 @@ void OCAFBrowser::load(const TDF_Label& label, QTreeWidgetItem* item, const QStr
}
}
//TDF_ChildIDIterator nodeIterator(label, XCAFDoc::ShapeRefGUID());
//for (; nodeIterator.More(); nodeIterator.Next()) {
// Handle(TDataStd_TreeNode) node = Handle(TDataStd_TreeNode)::DownCast(nodeIterator.Value());
// //if (node->HasFather())
// // ;
// QTreeWidgetItem* child = new QTreeWidgetItem();
// child->setText(0, QString::fromLatin1("TDataStd_TreeNode"));
// item->addChild(child);
//}
int i=1;
for (TDF_ChildIterator it(label); it.More(); it.Next(),i++) {
@@ -295,12 +283,9 @@ private:
if (!vp)
return;
if(colors.empty()) {
// vp->MapFaceColor.setValue(true);
// vp->MapLineColor.setValue(true);
// vp->updateColors(0,true);
return;
}
// vp->MapFaceColor.setValue(false);
if(colors.size() == 1) {
vp->ShapeColor.setValue(colors.front());
vp->Transparency.setValue(100 * colors.front().a);
@@ -313,7 +298,6 @@ private:
auto vp = dynamic_cast<PartGui::ViewProviderPartExt*>(Gui::Application::Instance->getViewProvider(part));
if (!vp)
return;
// vp->MapLineColor.setValue(false);
if(colors.size() == 1)
vp->LineColor.setValue(colors.front());
else
@@ -344,7 +328,6 @@ private:
if(!vp)
return;
(void)colors;
// vp->setElementColors(colors);
}
};
@@ -411,7 +394,6 @@ private:
std::string name8bit = Part::encodeFilename(Utf8Name);
try {
//Base::Console().Log("Insert in Part with %s",Name);
Base::FileInfo file(Utf8Name.c_str());
App::Document *pcDoc = nullptr;
@@ -666,10 +648,7 @@ private:
ocaf.getPartColors(hierarchical_part,FreeLabels,part_id,Colors);
ocaf.reallocateFreeShape(hierarchical_part,FreeLabels,part_id,Colors);
#if OCC_VERSION_HEX >= 0x070200
// Update is not performed automatically anymore: https://tracker.dev.opencascade.org/view.php?id=28055
XCAFDoc_DocumentTool::ShapeTool(hDoc->Main())->UpdateAssemblies();
#endif
}
Base::FileInfo file(Utf8Name.c_str());
@@ -682,7 +661,6 @@ private:
STEPCAFControl_Writer writer;
Part::Interface::writeStepAssembly(Part::Interface::Assembly::On);
// writer.SetColorMode(Standard_False);
writer.Transfer(hDoc, STEPControl_AsIs);
// edit STEP header
@@ -691,8 +669,6 @@ private:
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Part")->GetGroup("STEP");
// https://forum.freecadweb.org/viewtopic.php?f=8&t=52967
//makeHeader.SetName(new TCollection_HAsciiString((Standard_CString)Utf8Name.c_str()));
makeHeader.SetAuthorValue (1, new TCollection_HAsciiString(hGrp->GetASCII("Author", "Author").c_str()));
makeHeader.SetOrganizationValue (1, new TCollection_HAsciiString(hGrp->GetASCII("Company").c_str()));
makeHeader.SetOriginatingSystem(new TCollection_HAsciiString(App::Application::getExecutableName().c_str()));
@@ -758,7 +734,6 @@ private:
throw Py::Exception();
try {
//Base::Console().Log("Insert in Part with %s",Name);
Base::FileInfo file(Name);
Handle(XCAFApp_Application) hApp = XCAFApp_Application::GetApplication();