From 5bc9581113e642fb56c2c786cd708c3eb81aca54 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 13 Jul 2017 21:46:24 +0200 Subject: [PATCH] fix whitespaces --- src/Mod/Import/App/AppImportPy.cpp | 6 +- src/Mod/Import/App/ImportOCAF.cpp | 135 +++++++++++++------------- src/Mod/Import/App/ImportOCAF.h | 2 +- src/Mod/Import/Gui/AppImportGuiPy.cpp | 30 +++--- 4 files changed, 91 insertions(+), 82 deletions(-) diff --git a/src/Mod/Import/App/AppImportPy.cpp b/src/Mod/Import/App/AppImportPy.cpp index 478d751fde..d4c34ef965 100644 --- a/src/Mod/Import/App/AppImportPy.cpp +++ b/src/Mod/Import/App/AppImportPy.cpp @@ -231,8 +231,8 @@ private: if (obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { Part::Feature* part = static_cast(obj); std::vector colors; - std::vector hierarchical_label; - std::vector hierarchical_loc; + std::vector hierarchical_label; + std::vector hierarchical_loc; ocaf.saveShape(part, colors, hierarchical_label, hierarchical_loc); } else { @@ -249,7 +249,7 @@ private: Part::Feature* part = static_cast(obj); App::PropertyColorList colors; colors.setPyObject(item1.ptr()); - std::vector hierarchical_label; + std::vector hierarchical_label; std::vector hierarchical_loc; ocaf.saveShape(part, colors.getValues(), hierarchical_label, hierarchical_loc); } diff --git a/src/Mod/Import/App/ImportOCAF.cpp b/src/Mod/Import/App/ImportOCAF.cpp index 3f63ad9c2f..b76a0dab87 100644 --- a/src/Mod/Import/App/ImportOCAF.cpp +++ b/src/Mod/Import/App/ImportOCAF.cpp @@ -217,10 +217,10 @@ void ImportOCAF::loadShapes(const TDF_Label& label, const TopLoc_Location& loc, if (!asm_name.empty()) part_name = asm_name; - // TODO; The merge parameter (last one from createShape) should become an Importer/Exporter - // option within the FreeCAD preference menu - // Currently it is merging STEP Compound Shape into a single Shape Part::Feature which - // is an openCascade computed Compound + // TODO: The merge parameter (last one from createShape) should become an Importer/Exporter + // option within the FreeCAD preference menu + // Currently it is merging STEP Compound Shape into a single Shape Part::Feature which + // is an OpenCascade computed Compound if (isRef) createShape(label, loc, part_name, lValue, true); @@ -239,10 +239,10 @@ void ImportOCAF::loadShapes(const TDF_Label& label, const TopLoc_Location& loc, // This is probably an Assembly let's try to create a Compound with the name for (TDF_ChildIterator it(label); it.More(); it.Next()) { - if ( isRef) - loadShapes(it.Value(), part_loc, part_name, asm_name, false, localValue); + if (isRef) + loadShapes(it.Value(), part_loc, part_name, asm_name, false, localValue); else - loadShapes(it.Value(), part_loc, part_name, asm_name, isRef, localValue); + loadShapes(it.Value(), part_loc, part_name, asm_name, isRef, localValue); } if (!localValue.empty()) { @@ -251,13 +251,13 @@ void ImportOCAF::loadShapes(const TDF_Label& label, const TopLoc_Location& loc, pcPart = static_cast(doc->addObject("App::Part",asm_name.c_str())); pcPart->addObjects(localValue); - // STEP reader is now a hierarchical reader. Node and leaf must have - // there local placement updated and relative to the STEP file content - // standard FreeCAD placement was absolute we are now moving to relative + // STEP reader is now a hierarchical reader. Node and leaf must have + // there local placement updated and relative to the STEP file content + // standard FreeCAD placement was absolute we are now moving to relative gp_Trsf trf; Base::Matrix4D mtrx; - if ( part_loc.IsIdentity() ) + if (part_loc.IsIdentity()) trf = part_loc.Transformation(); else trf = TopLoc_Location(part_loc.FirstDatum()).Transformation(); @@ -294,32 +294,33 @@ void ImportOCAF::createShape(const TDF_Label& label, const TopLoc_Location& loc, // We should do that only if there is more than a single shape inside // Computing Compounds takes time - // We must keep track of the Color. If there is more than 1 Color into - // a STEP Compound then the Merge can't be done and we cancel the operation + // We must keep track of the Color. If there is more than 1 Color into + // a STEP Compound then the Merge can't be done and we cancel the operation - BRep_Builder builder; + BRep_Builder builder; TopoDS_Compound comp; builder.MakeCompound(comp); - Quantity_Color aColor; + + Quantity_Color aColor; App::Color color(0.8f,0.8f,0.8f); std::vector colors; for (xp.Init(aShape, TopAbs_SOLID); xp.More(); xp.Next(), ctSolids++) { - Quantity_Color aColor; - App::Color color(0.8f,0.8f,0.8f); - if (aColorTool->GetColor(xp.Current(), XCAFDoc_ColorGen, aColor) || - aColorTool->GetColor(xp.Current(), XCAFDoc_ColorSurf, aColor) || - aColorTool->GetColor(xp.Current(), XCAFDoc_ColorCurv, aColor)) { - color.r = (float)aColor.Red(); - color.g = (float)aColor.Green(); - color.b = (float)aColor.Blue(); - colors.push_back(color); - } - } - if ( colors.size() > 1 ) - { - createShape(label, loc, name, lValue, false); - return; - } + Quantity_Color aColor; + App::Color color(0.8f,0.8f,0.8f); + if (aColorTool->GetColor(xp.Current(), XCAFDoc_ColorGen, aColor) || + aColorTool->GetColor(xp.Current(), XCAFDoc_ColorSurf, aColor) || + aColorTool->GetColor(xp.Current(), XCAFDoc_ColorCurv, aColor)) { + color.r = (float)aColor.Red(); + color.g = (float)aColor.Green(); + color.b = (float)aColor.Blue(); + colors.push_back(color); + } + } + + if (colors.size() > 1) { + createShape(label, loc, name, lValue, false); + return; + } for (xp.Init(aShape, TopAbs_SOLID); xp.More(); xp.Next(), ctSolids++) { const TopoDS_Shape& sh = xp.Current(); @@ -334,15 +335,15 @@ void ImportOCAF::createShape(const TDF_Label& label, const TopLoc_Location& loc, builder.Add(comp, sh); } } - - for (xp.Init(aShape, TopAbs_EDGE); xp.More(); xp.Next(), ctEdges++) { + + for (xp.Init(aShape, TopAbs_EDGE); xp.More(); xp.Next(), ctEdges++) { const TopoDS_Shape& sh = xp.Current(); if (!sh.IsNull()) { builder.Add(comp, sh); } } - for (xp.Init(aShape, TopAbs_VERTEX); xp.More(); xp.Next(), ctVertices++) { + for (xp.Init(aShape, TopAbs_VERTEX); xp.More(); xp.Next(), ctVertices++) { const TopoDS_Shape& sh = xp.Current(); if (!sh.IsNull()) { builder.Add(comp, sh); @@ -353,7 +354,7 @@ void ImportOCAF::createShape(const TDF_Label& label, const TopLoc_Location& loc, // Just need to add it to a Part::Feature and push it to lValue if (!comp.IsNull() && (ctSolids||ctShells||ctEdges||ctVertices)) { Part::Feature* part = static_cast(doc->addObject("Part::Feature")); - // Let's allocate the relative placement of the Compound from the STEP file + // Let's allocate the relative placement of the Compound from the STEP file gp_Trsf trf; Base::Matrix4D mtrx; if ( loc.IsIdentity() ) @@ -383,12 +384,12 @@ void ImportOCAF::createShape(const TDF_Label& label, const TopLoc_Location& loc, if (!localValue.empty() && !merge) { pcPart = static_cast(doc->addObject("App::Part",name.c_str())); - + // localValue contain the objects that must added to the local Part // We must add the PartOrigin and the Part itself pcPart->addObjects(localValue); - - // Let's compute relative placement of the Part + + // Let's compute relative placement of the Part /* gp_Trsf trf; Base::Matrix4D mtrx; @@ -418,8 +419,8 @@ void ImportOCAF::createShape(const TopoDS_Shape& aShape, const TopLoc_Location& Part::Feature* part = static_cast(doc->addObject("Part::Feature")); if (!loc.IsIdentity()) - // part->Shape.setValue(aShape.Moved(TopLoc_Location(loc.FirstDatum()))); - part->Shape.setValue(aShape.Moved(loc)); + // part->Shape.setValue(aShape.Moved(TopLoc_Location(loc.FirstDatum()))); + part->Shape.setValue(aShape.Moved(loc)); else part->Shape.setValue(aShape); @@ -445,6 +446,7 @@ void ImportOCAF::createShape(const TopoDS_Shape& aShape, const TopLoc_Location& faces.Add(xp.Current()); xp.Next(); } + bool found_face_color = false; std::vector faceColors; faceColors.resize(faces.Extent(), color); @@ -492,24 +494,27 @@ ExportOCAF::ExportOCAF(Handle(TDocStd_Document) h, bool explicitPlacement) void ExportOCAF::createNode(App::Part* part, int& root_id, std::vector & hierarchical_label,std::vector & hierarchical_loc) { - TDF_Label shapeLabel = aShapeTool->NewShape(); - TDF_Label return_value; - Handle(TDataStd_Name) N; - TDataStd_Name::Set(shapeLabel, TCollection_ExtendedString(part->Label.getValue(), 1)); - Base::Placement pl = part->Placement.getValue(); - Base::Rotation rot(pl.getRotation()); - Base::Vector3d axis; - double angle; - rot.getValue(axis, angle); - gp_Trsf trf; - trf.SetRotation(gp_Ax1(gp_Pnt(), gp_Dir(axis.x, axis.y, axis.z)), angle); - trf.SetTranslationPart(gp_Vec(pl.getPosition().x,pl.getPosition().y,pl.getPosition().z)); - TopLoc_Location MyLoc = TopLoc_Location(trf); - XCAFDoc_Location::Set(shapeLabel,TopLoc_Location(trf)); + TDF_Label shapeLabel = aShapeTool->NewShape(); + TDF_Label return_value; + Handle(TDataStd_Name) N; + TDataStd_Name::Set(shapeLabel, TCollection_ExtendedString(part->Label.getValue(), 1)); - hierarchical_label.push_back(shapeLabel); - hierarchical_loc.push_back(MyLoc); - root_id=hierarchical_label.size(); + Base::Placement pl = part->Placement.getValue(); + Base::Rotation rot(pl.getRotation()); + Base::Vector3d axis; + + double angle; + rot.getValue(axis, angle); + + gp_Trsf trf; + trf.SetRotation(gp_Ax1(gp_Pnt(), gp_Dir(axis.x, axis.y, axis.z)), angle); + trf.SetTranslationPart(gp_Vec(pl.getPosition().x,pl.getPosition().y,pl.getPosition().z)); + TopLoc_Location MyLoc = TopLoc_Location(trf); + XCAFDoc_Location::Set(shapeLabel,TopLoc_Location(trf)); + + hierarchical_label.push_back(shapeLabel); + hierarchical_loc.push_back(MyLoc); + root_id=hierarchical_label.size(); } int ExportOCAF::saveShape(Part::Feature* part, const std::vector& colors, std::vector & hierarchical_label,std::vector & hierarchical_loc) @@ -594,23 +599,23 @@ int ExportOCAF::saveShape(Part::Feature* part, const std::vector& co col.SetValues(mat[0],mat[1],mat[2],Quantity_TOC_RGB); aColorTool->SetColor(shapeLabel, col, XCAFDoc_ColorGen); } + hierarchical_label.push_back(shapeLabel); hierarchical_loc.push_back(MyLoc); - return(hierarchical_label.size()); + return(hierarchical_label.size()); } // This function is moving a "standard" node into an Assembly node within an XCAF doc -void ExportOCAF::push_node(int root_id, int node_id, std::vector & hierarchical_label,std::vector & hierarchical_loc) +void ExportOCAF::pushNode(int root_id, int node_id, std::vector & hierarchical_label,std::vector & hierarchical_loc) { - TDF_Label root; - TDF_Label node; - root = hierarchical_label.at(root_id-1); - node = hierarchical_label.at(node_id-1); - - XCAFDoc_DocumentTool::ShapeTool(root)->AddComponent(root, node, hierarchical_loc.at(node_id-1)); + TDF_Label root; + TDF_Label node; + root = hierarchical_label.at(root_id-1); + node = hierarchical_label.at(node_id-1); + XCAFDoc_DocumentTool::ShapeTool(root)->AddComponent(root, node, hierarchical_loc.at(node_id-1)); } // ---------------------------------------------------------------------------- diff --git a/src/Mod/Import/App/ImportOCAF.h b/src/Mod/Import/App/ImportOCAF.h index 2a78b1b9fa..9121d04b00 100644 --- a/src/Mod/Import/App/ImportOCAF.h +++ b/src/Mod/Import/App/ImportOCAF.h @@ -81,7 +81,7 @@ public: void createNode(App::Part* part, int& root_it, std::vector & hierarchical_label,std::vector & hierarchical_loc); ExportOCAF(Handle(TDocStd_Document) h, bool explicitPlacement); int saveShape(Part::Feature* part, const std::vector&, std::vector & hierarchical_label,std::vector & hierarchical_loc); - void push_node(int root, int node, std::vector & hierarchical_label,std::vector & hierarchical_loc); + void pushNode(int root, int node, std::vector & hierarchical_label,std::vector & hierarchical_loc); diff --git a/src/Mod/Import/Gui/AppImportGuiPy.cpp b/src/Mod/Import/Gui/AppImportGuiPy.cpp index dec5eda29c..eabbe9b160 100644 --- a/src/Mod/Import/Gui/AppImportGuiPy.cpp +++ b/src/Mod/Import/Gui/AppImportGuiPy.cpp @@ -437,7 +437,7 @@ private: { std::vector local_label; int root_id; - int return_label; + int return_label = -1; if (obj->getTypeId().isDerivedFrom(App::Part::getClassTypeId())) { @@ -451,25 +451,30 @@ private: new_label=export_app_object((*it),ocaf,hierarchical_label,hierarchical_loc); local_label.push_back(new_label); } + ocaf.createNode(part,root_id,hierarchical_label,hierarchical_loc); std::vector::iterator label_it; - for ( label_it = local_label.begin(); label_it != local_label.end(); label_it++ ) { - ocaf.push_node(root_id,(*label_it), hierarchical_label,hierarchical_loc); + for (label_it = local_label.begin(); label_it != local_label.end(); ++label_it) { + ocaf.pushNode(root_id,(*label_it), hierarchical_label,hierarchical_loc); } + return_label=root_id; - } - if (obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + } + + if (obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { Part::Feature* part = static_cast(obj); std::vector colors; 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 = static_cast(vp)->DiffuseColor.getValues(); + if (colors.empty()) + colors.push_back(static_cast(vp)->ShapeColor.getValue()); } + return_label=ocaf.saveShape(part, colors,hierarchical_label,hierarchical_loc); - } - return(return_label); + } + + return(return_label); } Py::Object exporter(const Py::Tuple& args) @@ -490,19 +495,18 @@ private: hApp->NewDocument(TCollection_ExtendedString("MDTV-CAF"), hDoc); bool keepExplicitPlacement = list.size() > 1; - keepExplicitPlacement = Standard_True; + keepExplicitPlacement = Standard_True; Import::ExportOCAF ocaf(hDoc, keepExplicitPlacement); // That stuff is exporting a list of selected oject into FreeCAD Tree - int label=-1; for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { PyObject* item = (*it).ptr(); if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) { App::DocumentObject* obj = static_cast(item)->getDocumentObjectPtr(); std::vector hierarchical_label; std::vector hierarchical_loc; - label=export_app_object(obj,ocaf, hierarchical_label, hierarchical_loc); + export_app_object(obj,ocaf, hierarchical_label, hierarchical_loc); } }