diff --git a/src/Mod/Part/BasicShapes/ShapeContent.py b/src/Mod/Part/BasicShapes/ShapeContent.py index 80693c0f26..0e49c38808 100644 --- a/src/Mod/Part/BasicShapes/ShapeContent.py +++ b/src/Mod/Part/BasicShapes/ShapeContent.py @@ -10,8 +10,12 @@ import FreeCAD as App import Part -def roundVector(v,dec): - return str([round(v[0],dec), round(v[1],dec), round(v[2],dec)]) +translate = App.Qt.translate + + +def roundVector(v, dec): + return str([round(v[0], dec), round(v[1], dec), round(v[2], dec)]) + def buildShapeContent(objArg, decimals=2, advancedShapeContent=True): linkName = "" @@ -21,66 +25,208 @@ def buildShapeContent(objArg, decimals=2, advancedShapeContent=True): obj = objArg shp = Part.getShape(objArg) typeStr = str(shp.ShapeType) - lbl = '' if obj.Name == obj.Label else '(' + obj.Label + ')' - result = linkName + obj.Name + lbl + '\n' - result += 'Shape type: '+typeStr+'\n' - result += 'Vertices: '+str(len(shp.Vertexes))+'\n' - result += 'Edges: '+str(len(shp.Edges))+'\n' - result += 'Wires: '+str(len(shp.Wires))+'\n' - result += 'Faces: '+str(len(shp.Faces))+'\n' - result += 'Shells: '+str(len(shp.Shells))+'\n' - result += 'Solids: '+str(len(shp.Solids))+'\n' - result += 'CompSolids: '+str(len(shp.CompSolids))+'\n' - result += 'Compounds: '+str(len(shp.Compounds))+'\n' - result += 'Shapes: '+str(len(shp.Vertexes+shp.Edges+shp.Wires+shp.Faces+shp.Shells+shp.Solids+shp.CompSolids+shp.Compounds))+'\n' + lbl = "" if obj.Name == obj.Label else "(" + obj.Label + ")" + result = linkName + obj.Name + lbl + "\n" + result += ( + translate("TaskCheckGeometryResults", "Shape type") + ": " + typeStr + "\n" + ) + result += ( + translate("TaskCheckGeometryResults", "Vertices") + + ": " + + str(len(shp.Vertexes)) + + "\n" + ) + result += ( + translate("TaskCheckGeometryResults", "Edges") + + ": " + + str(len(shp.Edges)) + + "\n" + ) + result += ( + translate("TaskCheckGeometryResults", "Wires") + + ": " + + str(len(shp.Wires)) + + "\n" + ) + result += ( + translate("TaskCheckGeometryResults", "Faces") + + ": " + + str(len(shp.Faces)) + + "\n" + ) + result += ( + translate("TaskCheckGeometryResults", "Shells") + + ": " + + str(len(shp.Shells)) + + "\n" + ) + result += ( + translate("TaskCheckGeometryResults", "Solids") + + ": " + + str(len(shp.Solids)) + + "\n" + ) + result += ( + translate("TaskCheckGeometryResults", "CompSolids") + + ": " + + str(len(shp.CompSolids)) + + "\n" + ) + result += ( + translate("TaskCheckGeometryResults", "Compounds") + + ": " + + str(len(shp.Compounds)) + + "\n" + ) + result += ( + translate("TaskCheckGeometryResults", "Shapes") + + ": " + + str( + len( + shp.Vertexes + + shp.Edges + + shp.Wires + + shp.Faces + + shp.Shells + + shp.Solids + + shp.CompSolids + + shp.Compounds + ) + ) + + "\n" + ) if advancedShapeContent: - result += '----------\n' - if hasattr(shp,'Area') and not 'Wire' in typeStr and not 'Edge' in typeStr and not 'Vertex' in typeStr: - result += 'Area: '+str(round(shp.Area, decimals))+'\n' - if hasattr(shp,'Volume') and not 'Wire' in typeStr and not 'Edge' in typeStr and not 'Vertex' in typeStr and not 'Face' in typeStr: - result += 'Volume: '+str(round(shp.Volume, decimals))+'\n' - if hasattr(shp,'Mass'): - result += 'Mass: '+str(round(shp.Mass, decimals))+'\n' - if hasattr(shp,'Length'): - result += 'Length: '+str(round(shp.Length, decimals))+'\n' - if hasattr(shp,'Curve') and hasattr(shp.Curve,'Radius'): - result += 'Radius: '+str(round(shp.Curve.Radius, decimals))+'\n' - if hasattr(shp,'Curve') and hasattr(shp.Curve,'Center'): - result += 'Curve center: '+str([round(vv,decimals) for vv in shp.Curve.Center])+'\n' - if hasattr(shp,'Curve') and hasattr(shp.Curve,'Continuity'): - result += 'Continuity: '+str(shp.Curve.Continuity)+'\n' - if hasattr(shp,'CenterOfMass'): - result += 'CenterOfMass: '+roundVector(shp.CenterOfMass,decimals)+'\n' - if hasattr(shp,'normalAt'): + result += "----------\n" + if ( + hasattr(shp, "Area") + and not "Wire" in typeStr + and not "Edge" in typeStr + and not "Vertex" in typeStr + ): + result += ( + translate("TaskCheckGeometryResults", "Area") + + ": " + + str(round(shp.Area, decimals)) + + "\n" + ) + if ( + hasattr(shp, "Volume") + and not "Wire" in typeStr + and not "Edge" in typeStr + and not "Vertex" in typeStr + and not "Face" in typeStr + ): + result += ( + translate("TaskCheckGeometryResults", "Volume") + + ": " + + str(round(shp.Volume, decimals)) + + "\n" + ) + if hasattr(shp, "Mass"): + result += ( + translate("TaskCheckGeometryResults", "Mass") + + ": " + + str(round(shp.Mass, decimals)) + + "\n" + ) + if hasattr(shp, "Length"): + result += ( + translate("TaskCheckGeometryResults", "Length") + + ": " + + str(round(shp.Length, decimals)) + + "\n" + ) + if hasattr(shp, "Curve") and hasattr(shp.Curve, "Radius"): + result += ( + translate("TaskCheckGeometryResults", "Radius") + + ": " + + str(round(shp.Curve.Radius, decimals)) + + "\n" + ) + if hasattr(shp, "Curve") and hasattr(shp.Curve, "Center"): + result += ( + translate("TaskCheckGeometryResults", "Curve center") + + ": " + + str([round(vv, decimals) for vv in shp.Curve.Center]) + + "\n" + ) + if hasattr(shp, "Curve") and hasattr(shp.Curve, "Continuity"): + result += ( + translate("TaskCheckGeometryResults", "Continuity") + + ": " + + str(shp.Curve.Continuity) + + "\n" + ) + if hasattr(shp, "CenterOfMass"): + result += ( + translate("TaskCheckGeometryResults", "Center of mass") + + ": " + + roundVector(shp.CenterOfMass, decimals) + + "\n" + ) + if hasattr(shp, "normalAt"): try: - result += 'normalAt(0): '+str([round(vv,decimals) for vv in shp.normalAt(0)]) +'\n' + result += ( + "normalAt(0): " + + str([round(vv, decimals) for vv in shp.normalAt(0)]) + + "\n" + ) except Exception: try: - result += 'normalAt(0,0): '+str([round(vv,decimals) for vv in shp.normalAt(0,0)]) +'\n' + result += ( + "normalAt(0,0): " + + str([round(vv, decimals) for vv in shp.normalAt(0, 0)]) + + "\n" + ) except Exception: pass - if hasattr(shp, 'isClosed') and ('Wire' in typeStr or 'Edge' in typeStr): - result += 'isClosed: '+str(shp.isClosed())+'\n' - if hasattr(shp, 'Orientation'): - result += 'Orientation: '+str(shp.Orientation)+'\n' - if hasattr(shp, 'PrincipalProperties'): + if hasattr(shp, "isClosed") and ("Wire" in typeStr or "Edge" in typeStr): + result += ( + translate("TaskCheckGeometryResults", "Is closed") + + "? " + + str(shp.isClosed()) + + "\n" + ) + if hasattr(shp, "Orientation"): + result += ( + translate("TaskCheckGeometryResults", "Orientation") + + ": " + + str(shp.Orientation) + + "\n" + ) + if hasattr(shp, "PrincipalProperties"): props = shp.PrincipalProperties for p in props: if isinstance(props[p], App.Vector) or isinstance(props[p], tuple): - result += str(p)+': '+roundVector(props[p],decimals) +'\n' + result += str(p) + ": " + roundVector(props[p], decimals) + "\n" else: - result += str(p)+': '+str(props[p])+'\n' - if hasattr(obj,"getGlobalPlacement"): + result += str(p) + ": " + str(props[p]) + "\n" + if hasattr(obj, "getGlobalPlacement"): if obj.getGlobalPlacement() != obj.Placement: rpl = obj.getGlobalPlacement() * obj.Placement.inverse() rot = rpl.Rotation - if hasattr(shp, 'CenterOfMass'): - result += 'Global CenterOfMass: '+roundVector(rpl.multVec(shp.CenterOfMass),decimals)+'\n' - if hasattr(shp, 'PrincipalProperties'): + if hasattr(shp, "CenterOfMass"): + result += ( + translate("TaskCheckGeometryResults", "Global center of mass") + + ": " + + roundVector(rpl.multVec(shp.CenterOfMass), decimals) + + "\n" + ) + if hasattr(shp, "PrincipalProperties"): props = shp.PrincipalProperties for p in props: - if 'AxisOfInertia' in p: - result += 'Global ' + str(p)+': '+roundVector(rot.multVec(props[p]),decimals) +'\n' + if "AxisOfInertia" in p: + result += ( + "Global " + + str(p) + + ": " + + roundVector(rot.multVec(props[p]), decimals) + + "\n" + ) else: - result += 'Global Placement = Placement' + result += ( + translate("TaskCheckGeometryResults", "Global placement") + + " = " + + translate("TaskCheckGeometryResults", "Placement") + ) return result diff --git a/src/Mod/Part/Gui/TaskCheckGeometry.cpp b/src/Mod/Part/Gui/TaskCheckGeometry.cpp index 0074e77757..bf8b60b249 100644 --- a/src/Mod/Part/Gui/TaskCheckGeometry.cpp +++ b/src/Mod/Part/Gui/TaskCheckGeometry.cpp @@ -584,7 +584,7 @@ void TaskCheckGeometryResults::buildShapeContent(App::DocumentObject *pObject, c std::ostringstream stream; if (!shapeContentString.empty()) stream << std::endl << std::endl; - stream << "Checked object: "; + stream << tr("Checked object").toStdString() << ": "; Base::PyGILStateLocker lock; try { PyObject* module = PyImport_ImportModule("BasicShapes.ShapeContent");