From 1025ef4da34676bb6f679c6c5fb0f6a7ed8c6a56 Mon Sep 17 00:00:00 2001 From: WandererFan Date: Mon, 13 Apr 2020 22:31:18 -0400 Subject: [PATCH 1/5] [TD]Piecewise Sectioning Algo --- src/Mod/TechDraw/App/DrawViewSection.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawViewSection.cpp b/src/Mod/TechDraw/App/DrawViewSection.cpp index d3cb579bb6..0d76ef8ec9 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.cpp +++ b/src/Mod/TechDraw/App/DrawViewSection.cpp @@ -347,7 +347,6 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void) } } - dvp->requestPaint(); //to refresh section line return DrawView::execute(); } @@ -382,13 +381,26 @@ void DrawViewSection::sectionExec(TopoDS_Shape baseShape) BRepBuilderAPI_Copy BuilderCopy(baseShape); TopoDS_Shape myShape = BuilderCopy.Shape(); - BRepAlgoAPI_Cut mkCut(myShape, prism); - if (!mkCut.IsDone()) { - Base::Console().Warning("DVS: Section cut has failed in %s\n",getNameInDocument()); - return; + BRep_Builder builder; + TopoDS_Compound pieces; + builder.MakeCompound(pieces); + TopExp_Explorer expl(myShape, TopAbs_SOLID); + int indb = 0; + int outdb = 0; + for (; expl.More(); expl.Next()) { + indb++; + const TopoDS_Solid& s = TopoDS::Solid(expl.Current()); + BRepAlgoAPI_Cut mkCut(s, prism); + if (!mkCut.IsDone()) { + Base::Console().Warning("DVS: Section cut has failed in %s\n",getNameInDocument()); + continue; + } + TopoDS_Shape cut = mkCut.Shape(); + builder.Add(pieces, cut); + outdb++; } - TopoDS_Shape rawShape = mkCut.Shape(); + TopoDS_Shape rawShape = pieces; if (debugSection()) { BRepTools::Write(myShape, "DVSCopy.brep"); //debug BRepTools::Write(aProjFace, "DVSFace.brep"); //debug From 8a7ebe6fadb8409bd95778f5c3110853ed46d18b Mon Sep 17 00:00:00 2001 From: WandererFan Date: Fri, 17 Apr 2020 21:53:03 -0400 Subject: [PATCH 2/5] [TD]Piecewise Detail Algo --- src/Mod/TechDraw/App/DrawViewDetail.cpp | 63 +++++++++++++++---------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawViewDetail.cpp b/src/Mod/TechDraw/App/DrawViewDetail.cpp index 53c02f5894..8a491fea4a 100644 --- a/src/Mod/TechDraw/App/DrawViewDetail.cpp +++ b/src/Mod/TechDraw/App/DrawViewDetail.cpp @@ -255,9 +255,9 @@ void DrawViewDetail::detailExec(TopoDS_Shape shape, double scale = getScale(); BRepBuilderAPI_Copy BuilderCopy(shape); - TopoDS_Shape copyShape = BuilderCopy.Shape(); + TopoDS_Shape myShape = BuilderCopy.Shape(); - gp_Pnt gpCenter = TechDraw::findCentroid(copyShape, + gp_Pnt gpCenter = TechDraw::findCentroid(myShape, dirDetail); Base::Vector3d shapeCenter = Base::Vector3d(gpCenter.X(),gpCenter.Y(),gpCenter.Z()); m_saveCentroid = shapeCenter; //centroid of original shape @@ -265,7 +265,7 @@ void DrawViewDetail::detailExec(TopoDS_Shape shape, if (dvs != nullptr) { //section cutShape should already be on origin } else { - copyShape = TechDraw::moveShape(copyShape, //centre shape on origin + myShape = TechDraw::moveShape(myShape, //centre shape on origin -shapeCenter); } @@ -280,7 +280,7 @@ void DrawViewDetail::detailExec(TopoDS_Shape shape, Bnd_Box bbxSource; bbxSource.SetGap(0.0); - BRepBndLib::Add(copyShape, bbxSource); + BRepBndLib::Add(myShape, bbxSource); double diag = sqrt(bbxSource.SquareExtent()); Base::Vector3d toolPlaneOrigin = anchorOffset3d + dirDetail * diag * -1.0; //center tool about anchor @@ -301,33 +301,47 @@ void DrawViewDetail::detailExec(TopoDS_Shape shape, gp_Vec extrudeDir(extrudeVec.x,extrudeVec.y,extrudeVec.z); TopoDS_Shape tool = BRepPrimAPI_MakePrism(aProjFace, extrudeDir, false, true).Shape(); - BRepAlgoAPI_Common mkCommon(copyShape,tool); - if (!mkCommon.IsDone()) { - Base::Console().Warning("DVD::execute - %s - detail cut operation failed (1)\n", getNameInDocument()); - return; - } - if (mkCommon.Shape().IsNull()) { - Base::Console().Warning("DVD::execute - %s - detail cut operation failed (2)\n", getNameInDocument()); - return; - } - //Did we get a solid? - TopExp_Explorer xp; - xp.Init(mkCommon.Shape(),TopAbs_SOLID); - if (!(xp.More() == Standard_True)) { - Base::Console().Warning("DVD::execute - mkCommon.Shape is not a solid!\n"); + BRep_Builder builder; + TopoDS_Compound pieces; + builder.MakeCompound(pieces); + TopExp_Explorer expl(myShape, TopAbs_SOLID); + int indb = 0; + int outdb = 0; + for (; expl.More(); expl.Next()) { + indb++; + const TopoDS_Solid& s = TopoDS::Solid(expl.Current()); + + BRepAlgoAPI_Common mkCommon(s,tool); + if (!mkCommon.IsDone()) { +// Base::Console().Warning("DVD::execute - %s - detail cut operation failed (1)\n", getNameInDocument()); + continue; + } + if (mkCommon.Shape().IsNull()) { +// Base::Console().Warning("DVD::execute - %s - detail cut operation failed (2)\n", getNameInDocument()); + continue; + } + //this might be overkill for piecewise algo + //Did we get at least 1 solid? + TopExp_Explorer xp; + xp.Init(mkCommon.Shape(),TopAbs_SOLID); + if (!(xp.More() == Standard_True)) { +// Base::Console().Warning("DVD::execute - mkCommon.Shape is not a solid!\n"); + continue; + } + builder.Add(pieces, mkCommon.Shape()); + outdb++; } - TopoDS_Shape detail = mkCommon.Shape(); if (debugDetail()) { BRepTools::Write(tool, "DVDTool.brep"); //debug - BRepTools::Write(copyShape, "DVDCopy.brep"); //debug - BRepTools::Write(detail, "DVDCommon.brep"); //debug + BRepTools::Write(myShape, "DVDCopy.brep"); //debug + BRepTools::Write(pieces, "DVDCommon.brep"); //debug } Bnd_Box testBox; testBox.SetGap(0.0); - BRepBndLib::Add(detail, testBox); + BRepBndLib::Add(pieces, testBox); if (testBox.IsVoid()) { TechDraw::GeometryObject* go = getGeometryObject(); if (go != nullptr) { @@ -343,7 +357,7 @@ void DrawViewDetail::detailExec(TopoDS_Shape shape, // TopoDS_Compound Comp; // builder.MakeCompound(Comp); // builder.Add(Comp, tool); -// builder.Add(Comp, copyShape); +// builder.Add(Comp, myShape); gp_Pnt inputCenter; try { @@ -358,7 +372,8 @@ void DrawViewDetail::detailExec(TopoDS_Shape shape, gp_Ax2 viewAxis = dvp->getProjectionCS(stdOrg); //sb same CS as base view. //center shape on origin - TopoDS_Shape centeredShape = TechDraw::moveShape(detail, +// TopoDS_Shape centeredShape = TechDraw::moveShape(detail, + TopoDS_Shape centeredShape = TechDraw::moveShape(pieces, centroid * -1.0); TopoDS_Shape scaledShape = TechDraw::scaleShape(centeredShape, From a020dc2afcb878fa8293e459fec1b62cbe441058 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Sun, 19 Apr 2020 21:26:55 +0200 Subject: [PATCH 3/5] FEM: meshtools, fix element names in face search --- src/Mod/Fem/femmesh/meshtools.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Mod/Fem/femmesh/meshtools.py b/src/Mod/Fem/femmesh/meshtools.py index 8c2241d7f8..e8bc641764 100644 --- a/src/Mod/Fem/femmesh/meshtools.py +++ b/src/Mod/Fem/femmesh/meshtools.py @@ -1441,7 +1441,7 @@ def build_mesh_faces_of_volume_elements( else: FreeCAD.Console.PrintError( "Error in build_mesh_faces_of_volume_elements(): " - "hexa20: face not found! {}\n" + "tetra10: face not found! {}\n" .format(face_node_indexs) ) elif vol_node_ct == 4: @@ -1459,7 +1459,7 @@ def build_mesh_faces_of_volume_elements( else: FreeCAD.Console.PrintError( "Error in build_mesh_faces_of_volume_elements(): " - "hexa20: face not found! {}\n" + "tetra4: face not found! {}\n" .format(face_node_indexs) ) elif vol_node_ct == 20: @@ -1503,7 +1503,7 @@ def build_mesh_faces_of_volume_elements( else: FreeCAD.Console.PrintError( "Error in build_mesh_faces_of_volume_elements(): " - "hexa20: face not found! {}\n" + "hexa8: face not found! {}\n" .format(face_node_indexs) ) elif vol_node_ct == 15: @@ -1543,7 +1543,7 @@ def build_mesh_faces_of_volume_elements( else: FreeCAD.Console.PrintError( "Error in build_mesh_faces_of_volume_elements(): " - "pent6: face not found! {}\n" + "penta6: face not found! {}\n" .format(face_node_indexs) ) else: From 9dc688ff3b86b2c5f5fe86d6e42f333e1c57988b Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Sun, 19 Apr 2020 21:36:26 +0200 Subject: [PATCH 4/5] FEM: result task panel, avoid zero float division --- src/Mod/Fem/femguiobjects/_ViewProviderFemResultMechanical.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Mod/Fem/femguiobjects/_ViewProviderFemResultMechanical.py b/src/Mod/Fem/femguiobjects/_ViewProviderFemResultMechanical.py index 5c1551fc91..b4e25b14be 100644 --- a/src/Mod/Fem/femguiobjects/_ViewProviderFemResultMechanical.py +++ b/src/Mod/Fem/femguiobjects/_ViewProviderFemResultMechanical.py @@ -703,6 +703,8 @@ def get_displacement_scale_factor(res_obj): z_span = abs(p_z_max - p_z_min) span = max(x_span, y_span, z_span) max_disp = max(x_max, y_max, z_max) + if max_disp == 0.0: + return 0.0 # avoid float division by zero # FIXME - add max_allowed_disp to Preferences max_allowed_disp = 0.01 * span scale = max_allowed_disp / max_disp From 45aef7b028a54c5420db49ff3284fc7377475e90 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Sun, 19 Apr 2020 21:56:35 +0200 Subject: [PATCH 5/5] FEM: meshtools, init empty node numbers in face search --- src/Mod/Fem/femmesh/meshtools.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Mod/Fem/femmesh/meshtools.py b/src/Mod/Fem/femmesh/meshtools.py index e8bc641764..c3f1cd0a96 100644 --- a/src/Mod/Fem/femmesh/meshtools.py +++ b/src/Mod/Fem/femmesh/meshtools.py @@ -1426,6 +1426,7 @@ def build_mesh_faces_of_volume_elements( FreeCAD.Console.PrintLog("VolElement: {}\n".format(veID)) vol_node_ct = len(femelement_table[veID]) face_node_indexs = sorted(face_nodenumber_table[veID]) + node_numbers = () if vol_node_ct == 10: FreeCAD.Console.PrintLog(" --> tetra10 --> tria6 face\n") # node order of face in tetra10 volume element