From 034520e02f40ea2a3f383a7bdcaebcac1934dc49 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 1 Aug 2017 08:30:22 +0200 Subject: [PATCH] improve whitespaces --- src/Mod/Import/App/AppImportPy.cpp | 4 +- src/Mod/Import/App/ImportOCAF.cpp | 149 +++++++++++++------------- src/Mod/Import/App/ImportOCAF.h | 26 +++-- src/Mod/Import/Gui/AppImportGuiPy.cpp | 38 ++++--- 4 files changed, 115 insertions(+), 102 deletions(-) diff --git a/src/Mod/Import/App/AppImportPy.cpp b/src/Mod/Import/App/AppImportPy.cpp index 0adf7366c6..fb8d6165c4 100644 --- a/src/Mod/Import/App/AppImportPy.cpp +++ b/src/Mod/Import/App/AppImportPy.cpp @@ -233,7 +233,7 @@ private: std::vector colors; std::vector hierarchical_label; std::vector hierarchical_loc; - std::vector hierarchical_part; + std::vector hierarchical_part; ocaf.saveShape(part, colors, hierarchical_label, hierarchical_loc, hierarchical_part); } else { @@ -252,7 +252,7 @@ private: colors.setPyObject(item1.ptr()); std::vector hierarchical_label; std::vector hierarchical_loc; - std::vector hierarchical_part; + std::vector hierarchical_part; ocaf.saveShape(part, colors.getValues(), hierarchical_label, hierarchical_loc, hierarchical_part); } else { diff --git a/src/Mod/Import/App/ImportOCAF.cpp b/src/Mod/Import/App/ImportOCAF.cpp index ca2036a19e..88f54e24da 100644 --- a/src/Mod/Import/App/ImportOCAF.cpp +++ b/src/Mod/Import/App/ImportOCAF.cpp @@ -495,7 +495,10 @@ ExportOCAF::ExportOCAF(Handle(TDocStd_Document) h, bool explicitPlacement) // This function create an Assembly node into an XCAF document with it's relative placement information -void ExportOCAF::createNode(App::Part* part, int& root_id, std::vector & hierarchical_label,std::vector & hierarchical_loc, std::vector & hierarchical_part) +void ExportOCAF::createNode(App::Part* part, int& root_id, + std::vector & hierarchical_label, + std::vector & hierarchical_loc, + std::vector & hierarchical_part) { TDF_Label shapeLabel = aShapeTool->NewShape(); Handle(TDataStd_Name) N; @@ -520,7 +523,10 @@ void ExportOCAF::createNode(App::Part* part, int& root_id, std::vector & colors, std::vector & hierarchical_label,std::vector & hierarchical_loc, std::vector & hierarchical_part) +int ExportOCAF::saveShape(Part::Feature* part, const std::vector& colors, + std::vector & hierarchical_label, + std::vector & hierarchical_loc, + std::vector & hierarchical_part) { const TopoDS_Shape& shape = part->Shape.getValue(); if (shape.IsNull()) @@ -618,86 +624,85 @@ int ExportOCAF::saveShape(Part::Feature* part, const std::vector& co // If this Free Shapes are regular Part::Feature, we must use absolute coordinate instead of // allocating a placement into the hierarchy as it is not attached to a hierarchical node -void ExportOCAF::getFreeLabels(std::vector & hierarchical_label,std::vector & labels, - std::vector & label_part_id ) +void ExportOCAF::getFreeLabels(std::vector & hierarchical_label, + std::vector & labels, + std::vector & label_part_id) { - TDF_LabelSequence FreeLabels; - aShapeTool->GetFreeShapes(FreeLabels); - int n = FreeLabels.Length(); - for (int i = 1; i <= n; i++) - { - TDF_Label label = FreeLabels.Value(i); - for ( unsigned long j = 0; j < ( hierarchical_label.size()) ; j++ ) - { - if ( label == hierarchical_label.at(j) ) - { - labels.push_back(label); - label_part_id.push_back(j); - } + TDF_LabelSequence FreeLabels; + aShapeTool->GetFreeShapes(FreeLabels); + int n = FreeLabels.Length(); + for (int i = 1; i <= n; i++) { + TDF_Label label = FreeLabels.Value(i); + for (std::size_t j = 0; j < hierarchical_label.size(); j++) { + if (label == hierarchical_label.at(j)) { + labels.push_back(label); + label_part_id.push_back(j); } } + } } -void ExportOCAF::reallocateFreeShape(std::vector hierarchical_part, std::vector FreeLabels, - std::vector part_id, std::vector< std::vector >& Colors) +void ExportOCAF::reallocateFreeShape(std::vector hierarchical_part, + std::vector FreeLabels, + std::vector part_id, + std::vector< std::vector >& Colors) { - int n = FreeLabels.size(); - for (int i = 0; i < n; i++) - { - TDF_Label label = FreeLabels.at(i); - // hierarchical part does contain only part currently and not node I should add node - if ( hierarchical_part.at(part_id.at(i))->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()) ) - { - Part::Feature * part = static_cast(hierarchical_part.at(part_id.at(i))); - aShapeTool->SetShape(label, part->Shape.getValue()); - // Add color information - std::vector colors; - colors=Colors.at(i); - TopoDS_Shape baseShape = part->Shape.getValue(); - // Add color information - Quantity_Color col; + std::size_t n = FreeLabels.size(); + for (std::size_t i = 0; i < n; i++) { + TDF_Label label = FreeLabels.at(i); + // hierarchical part does contain only part currently and not node I should add node + if (hierarchical_part.at(part_id.at(i))->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + Part::Feature * part = static_cast(hierarchical_part.at(part_id.at(i))); + aShapeTool->SetShape(label, part->Shape.getValue()); + // Add color information + std::vector colors; + colors=Colors.at(i); + TopoDS_Shape baseShape = part->Shape.getValue(); - std::set face_index; - TopTools_IndexedMapOfShape faces; - TopExp_Explorer xp(baseShape,TopAbs_FACE); + // Add color information + Quantity_Color col; + + std::set face_index; + TopTools_IndexedMapOfShape faces; + TopExp_Explorer xp(baseShape,TopAbs_FACE); + while (xp.More()) { + face_index.insert(faces.Add(xp.Current())); + xp.Next(); + } + + // define color per face? + if (colors.size() == face_index.size()) { + xp.Init(baseShape,TopAbs_FACE); while (xp.More()) { - face_index.insert(faces.Add(xp.Current())); - xp.Next(); + int index = faces.FindIndex(xp.Current()); + if (face_index.find(index) != face_index.end()) { + face_index.erase(index); + TDF_Label faceLabel = aShapeTool->AddSubShape(label, xp.Current()); + // TDF_Label faceLabel= TDF_TagSource::NewChild(label); + aShapeTool->SetShape(faceLabel, xp.Current()); + const App::Color& color = colors[index-1]; + Quantity_Parameter mat[3]; + mat[0] = color.r; + mat[1] = color.g; + mat[2] = color.b; + col.SetValues(mat[0],mat[1],mat[2],Quantity_TOC_RGB); + aColorTool->SetColor(faceLabel, col, XCAFDoc_ColorSurf); + } + + xp.Next(); } - - // define color per face? - if (colors.size() == face_index.size()) { - xp.Init(baseShape,TopAbs_FACE); - while (xp.More()) { - int index = faces.FindIndex(xp.Current()); - if (face_index.find(index) != face_index.end()) { - face_index.erase(index); - TDF_Label faceLabel = aShapeTool->AddSubShape(label, xp.Current()); - // TDF_Label faceLabel= TDF_TagSource::NewChild(label); - aShapeTool->SetShape(faceLabel, xp.Current()); - const App::Color& color = colors[index-1]; - Quantity_Parameter mat[3]; - mat[0] = color.r; - mat[1] = color.g; - mat[2] = color.b; - col.SetValues(mat[0],mat[1],mat[2],Quantity_TOC_RGB); - aColorTool->SetColor(faceLabel, col, XCAFDoc_ColorSurf); - } - xp.Next(); - } - } - else if (!colors.empty()) { - App::Color color = colors.front(); - Quantity_Parameter mat[3]; - mat[0] = color.r; - mat[1] = color.g; - mat[2] = color.b; - col.SetValues(mat[0],mat[1],mat[2],Quantity_TOC_RGB); - aColorTool->SetColor(label, col, XCAFDoc_ColorGen); - } - - } + } + else if (!colors.empty()) { + App::Color color = colors.front(); + Quantity_Parameter mat[3]; + mat[0] = color.r; + mat[1] = color.g; + mat[2] = color.b; + col.SetValues(mat[0],mat[1],mat[2],Quantity_TOC_RGB); + aColorTool->SetColor(label, col, XCAFDoc_ColorGen); + } } + } } diff --git a/src/Mod/Import/App/ImportOCAF.h b/src/Mod/Import/App/ImportOCAF.h index b720a451ed..9c497d2eab 100644 --- a/src/Mod/Import/App/ImportOCAF.h +++ b/src/Mod/Import/App/ImportOCAF.h @@ -65,6 +65,7 @@ private: void createShape(const TDF_Label& label, const TopLoc_Location&, const std::string&, std::vector &, bool); void createShape(const TopoDS_Shape& label, const TopLoc_Location&, const std::string&, std::vector &); virtual void applyColors(Part::Feature*, const std::vector&){} + private: Handle(TDocStd_Document) pDoc; App::Document* doc; @@ -79,15 +80,24 @@ private: class ImportExport ExportOCAF { public: - void createNode(App::Part* part, int& root_it, std::vector & hierarchical_label,std::vector & hierarchical_loc, std::vector & hierarchical_part); + void createNode(App::Part* part, int& root_it, + std::vector & hierarchical_label, + std::vector & hierarchical_loc, + std::vector & hierarchical_part); ExportOCAF(Handle(TDocStd_Document) h, bool explicitPlacement); - int saveShape(Part::Feature* part, const std::vector&, std::vector & hierarchical_label,std::vector & hierarchical_loc,std::vector & hierarchical_part); - void reallocateFreeShape(std::vector hierarchical_part, std::vector FreeLabels, - std::vector part_id, std::vector< std::vector >& Colors); - void getFreeLabels(std::vector & hierarchical_label,std::vector & labels, std::vector & label_part_id ); - void pushNode(int root, int node, std::vector & hierarchical_label,std::vector & hierarchical_loc); - - + int saveShape(Part::Feature* part, const std::vector&, + std::vector & hierarchical_label, + std::vector & hierarchical_loc, + std::vector & hierarchical_part); + void reallocateFreeShape(std::vector hierarchical_part, + std::vector FreeLabels, + std::vector part_id, + std::vector< std::vector >& Colors); + void getFreeLabels(std::vector & hierarchical_label, + std::vector & labels, + std::vector & label_part_id); + void pushNode(int root, int node, std::vector & hierarchical_label, + std::vector & hierarchical_loc); private: Handle(TDocStd_Document) pDoc; diff --git a/src/Mod/Import/Gui/AppImportGuiPy.cpp b/src/Mod/Import/Gui/AppImportGuiPy.cpp index 3d500500f2..ebadffb736 100644 --- a/src/Mod/Import/Gui/AppImportGuiPy.cpp +++ b/src/Mod/Import/Gui/AppImportGuiPy.cpp @@ -439,7 +439,7 @@ private: int export_app_object(App::DocumentObject* obj, Import::ExportOCAF ocaf, std::vector & hierarchical_label, std::vector & hierarchical_loc, - std::vector & hierarchical_part) + std::vector & hierarchical_part) { std::vector local_label; int root_id; @@ -477,7 +477,7 @@ private: colors.push_back(static_cast(vp)->ShapeColor.getValue()); } - return_label=ocaf.saveShape(part, colors,hierarchical_label,hierarchical_loc,hierarchical_part); + return_label=ocaf.saveShape(part, colors, hierarchical_label, hierarchical_loc, hierarchical_part); } return(return_label); @@ -488,22 +488,19 @@ private: { // I am seeking for the colors of each parts int n = FreeLabels.size(); - for (int i = 0; i < n; i++) - { - std::vector colors; - Part::Feature * part = static_cast(hierarchical_part.at(part_id.at(i))); - Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(part); - if (vp && vp->isDerivedFrom(PartGui::ViewProviderPartExt::getClassTypeId())) { - colors = static_cast(vp)->DiffuseColor.getValues(); - if (colors.empty()) - colors.push_back(static_cast(vp)->ShapeColor.getValue()); - Colors.push_back(colors); - } + for (int i = 0; i < n; i++) { + std::vector colors; + Part::Feature * part = static_cast(hierarchical_part.at(part_id.at(i))); + Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(part); + if (vp && vp->isDerivedFrom(PartGui::ViewProviderPartExt::getClassTypeId())) { + colors = static_cast(vp)->DiffuseColor.getValues(); + if (colors.empty()) + colors.push_back(static_cast(vp)->ShapeColor.getValue()); + Colors.push_back(colors); + } } } - - Py::Object exporter(const Py::Tuple& args) { PyObject* object; @@ -526,7 +523,7 @@ private: Import::ExportOCAF ocaf(hDoc, keepExplicitPlacement); // That stuff is exporting a list of selected oject into FreeCAD Tree - std::vector hierarchical_label; + std::vector hierarchical_label; std::vector hierarchical_loc; std::vector hierarchical_part; @@ -538,8 +535,8 @@ private: } } - // Free Shapes must have absolute placement and not explicit - // Free Shapes must have absolute placement and not explicit + // Free Shapes must have absolute placement and not explicit + // Free Shapes must have absolute placement and not explicit std::vector FreeLabels; std::vector part_id; ocaf.getFreeLabels(hierarchical_label,FreeLabels, part_id); @@ -561,9 +558,10 @@ private: Interface_Static::SetCVal("write.step.schema", "AP214IS"); if (optionScheme_203) Interface_Static::SetCVal("write.step.schema", "AP203"); + STEPCAFControl_Writer writer; - Interface_Static::SetIVal("write.step.assembly",1); - // writer.SetColorMode(Standard_False); + Interface_Static::SetIVal("write.step.assembly",1); + // writer.SetColorMode(Standard_False); writer.Transfer(hDoc, STEPControl_AsIs); // edit STEP header