From 49a9f5b0adeedcf1a52d9f24dbff10208e664f98 Mon Sep 17 00:00:00 2001 From: qewer33 Date: Thu, 21 Sep 2023 19:45:09 +0300 Subject: [PATCH 1/2] Assembly: Improve JCS appearance and implement autoscale Closes #10745, closes #10746 --- src/Mod/Assembly/JointObject.py | 54 ++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/src/Mod/Assembly/JointObject.py b/src/Mod/Assembly/JointObject.py index 76b1afc450..365911bd05 100644 --- a/src/Mod/Assembly/JointObject.py +++ b/src/Mod/Assembly/JointObject.py @@ -21,6 +21,8 @@ # * # ***************************************************************************/ +import math + import FreeCAD as App import Part @@ -256,7 +258,7 @@ class ViewProviderJoint: obj.color_X_axis = (1.0, 0.0, 0.0) obj.color_Y_axis = (0.0, 1.0, 0.0) obj.color_Z_axis = (0.0, 0.0, 1.0) - obj.axis_thickness = 2 + obj.axis_thickness = 3 self.x_axis_so_color = coin.SoBaseColor() self.x_axis_so_color.rgb.setValue(1.0, 0.0, 0.0) self.y_axis_so_color = coin.SoBaseColor() @@ -264,6 +266,10 @@ class ViewProviderJoint: self.z_axis_so_color = coin.SoBaseColor() self.z_axis_so_color.rgb.setValue(0.0, 0.0, 1.0) + camera = Gui.ActiveDocument.ActiveView.getCameraNode() + self.cameraSensor = coin.SoFieldSensor(self.camera_callback, camera) + self.cameraSensor.attach(camera.height) + self.app_obj = app_obj obj.Proxy = self @@ -291,6 +297,10 @@ class ViewProviderJoint: self.display_mode.addChild(self.switch_JCS_preview) obj.addDisplayMode(self.display_mode, "Wireframe") + def camera_callback(self, *args): + scaleF = self.get_JCS_size() + self.axisScale.scaleFactor.setValue(scaleF, scaleF, scaleF) + def JCS_sep(self, obj, soTransform): pick = coin.SoPickStyle() pick.style.setValue(coin.SoPickStyle.UNPICKABLE) @@ -299,10 +309,12 @@ class ViewProviderJoint: JCS.addChild(soTransform) JCS.addChild(pick) - X_axis_sep = self.line_sep([0, 0, 0], [1, 0, 0], self.x_axis_so_color) - Y_axis_sep = self.line_sep([0, 0, 0], [0, 1, 0], self.y_axis_so_color) + base_plane_sep = self.plane_sep(0.4, 15) + X_axis_sep = self.line_sep([0.5, 0, 0], [1, 0, 0], self.x_axis_so_color) + Y_axis_sep = self.line_sep([0, 0.5, 0], [0, 1, 0], self.y_axis_so_color) Z_axis_sep = self.line_sep([0, 0, 0], [0, 0, 1], self.z_axis_so_color) + JCS.addChild(base_plane_sep) JCS.addChild(X_axis_sep) JCS.addChild(Y_axis_sep) JCS.addChild(Z_axis_sep) @@ -326,12 +338,46 @@ class ViewProviderJoint: axis_sep.addChild(line) return axis_sep + def plane_sep(self, size, num_vertices): + coords = coin.SoCoordinate3() + + for i in range(num_vertices): + angle = float(i) / num_vertices * 2.0 * math.pi + x = math.cos(angle) * size + y = math.sin(angle) * size + coords.point.set1Value(i, x, y, 0) + + face = coin.SoFaceSet() + face.numVertices.setValue(num_vertices) + + transform = coin.SoTransform() + transform.translation.setValue(0, 0, 0) + + draw_style = coin.SoDrawStyle() + draw_style.style = coin.SoDrawStyle.FILLED + + material = coin.SoMaterial() + material.diffuseColor.setValue([1, 1, 1]) + material.ambientColor.setValue([1, 1, 1]) + material.specularColor.setValue([1, 1, 1]) + material.emissiveColor.setValue([1, 1, 1]) + material.transparency.setValue(0.7) + + face_sep = coin.SoAnnotation() + face_sep.addChild(self.axisScale) + face_sep.addChild(transform) + face_sep.addChild(draw_style) + face_sep.addChild(material) + face_sep.addChild(coords) + face_sep.addChild(face) + return face_sep + def get_JCS_size(self): camera = Gui.ActiveDocument.ActiveView.getCameraNode() if not camera: return 10 - return camera.height.getValue() / 10 + return camera.height.getValue() / 20 def set_JCS_placement(self, soTransform, placement): t = placement.Base From 62722aa8c00a6c49382290d125129f0619ebff26 Mon Sep 17 00:00:00 2001 From: qewer33 Date: Fri, 22 Sep 2023 19:46:58 +0300 Subject: [PATCH 2/2] Assembly: Make JCS axis colors use parameters --- src/Mod/Assembly/JointObject.py | 34 ++++++++++--------------------- src/Mod/Assembly/UtilsAssembly.py | 8 ++++++++ 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/Mod/Assembly/JointObject.py b/src/Mod/Assembly/JointObject.py index 365911bd05..35a0d82871 100644 --- a/src/Mod/Assembly/JointObject.py +++ b/src/Mod/Assembly/JointObject.py @@ -240,31 +240,19 @@ class Joint: class ViewProviderJoint: def __init__(self, obj, app_obj): """Set this object to the proxy object of the actual view provider""" - obj.addProperty( - "App::PropertyColor", "color_X_axis", "JCS", "Joint coordinate system X axis color" - ) - obj.addProperty( - "App::PropertyColor", "color_Y_axis", "JCS", "Joint coordinate system Y axis color" - ) - obj.addProperty( - "App::PropertyColor", "color_Z_axis", "JCS", "Joint coordinate system Z axis color" - ) - obj.addProperty( - "App::PropertyInteger", - "axis_thickness", - "JCS", - "Joint cordinate system X axis thickness", - ) - obj.color_X_axis = (1.0, 0.0, 0.0) - obj.color_Y_axis = (0.0, 1.0, 0.0) - obj.color_Z_axis = (0.0, 0.0, 1.0) - obj.axis_thickness = 3 + self.axis_thickness = 3 + + view_params = App.ParamGet("User parameter:BaseApp/Preferences/View") + param_x_axis_color = view_params.GetUnsigned("AxisXColor", 0xCC333300) + param_y_axis_color = view_params.GetUnsigned("AxisYColor", 0x33CC3300) + param_z_axis_color = view_params.GetUnsigned("AxisZColor", 0x3333CC00) + self.x_axis_so_color = coin.SoBaseColor() - self.x_axis_so_color.rgb.setValue(1.0, 0.0, 0.0) + self.x_axis_so_color.rgb.setValue(UtilsAssembly.color_from_unsigned(param_x_axis_color)) self.y_axis_so_color = coin.SoBaseColor() - self.y_axis_so_color.rgb.setValue(0.0, 1.0, 0.0) + self.y_axis_so_color.rgb.setValue(UtilsAssembly.color_from_unsigned(param_y_axis_color)) self.z_axis_so_color = coin.SoBaseColor() - self.z_axis_so_color.rgb.setValue(0.0, 0.0, 1.0) + self.z_axis_so_color.rgb.setValue(UtilsAssembly.color_from_unsigned(param_z_axis_color)) camera = Gui.ActiveDocument.ActiveView.getCameraNode() self.cameraSensor = coin.SoFieldSensor(self.camera_callback, camera) @@ -285,7 +273,7 @@ class ViewProviderJoint: self.draw_style = coin.SoDrawStyle() self.draw_style.style = coin.SoDrawStyle.LINES - self.draw_style.lineWidth = obj.axis_thickness + self.draw_style.lineWidth = self.axis_thickness self.switch_JCS1 = self.JCS_sep(obj, self.transform1) self.switch_JCS2 = self.JCS_sep(obj, self.transform2) diff --git a/src/Mod/Assembly/UtilsAssembly.py b/src/Mod/Assembly/UtilsAssembly.py index 69f4392755..c8bc90359e 100644 --- a/src/Mod/Assembly/UtilsAssembly.py +++ b/src/Mod/Assembly/UtilsAssembly.py @@ -236,3 +236,11 @@ def findVertexNameInObject(vertex, obj): if vtx.Point == vertex.Point: return "Vertex" + str(i + 1) return "" + + +def color_from_unsigned(c): + return [ + float(int((c >> 24) & 0xFF) / 255), + float(int((c >> 16) & 0xFF) / 255), + float(int((c >> 8) & 0xFF) / 255), + ]