Merge pull request #10767 from qewer33/assembly-jcs
Assembly: Improve JCS appearance and implement autoscale
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
# *
|
||||
# ***************************************************************************/
|
||||
|
||||
import math
|
||||
|
||||
import FreeCAD as App
|
||||
import Part
|
||||
|
||||
@@ -238,31 +240,23 @@ 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 = 2
|
||||
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)
|
||||
self.cameraSensor.attach(camera.height)
|
||||
|
||||
self.app_obj = app_obj
|
||||
obj.Proxy = self
|
||||
@@ -279,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)
|
||||
@@ -291,6 +285,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 +297,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 +326,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
|
||||
|
||||
@@ -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),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user