def makeLabels(self): """ Method which makes Coin3D labels to be displayed in the FreeCAD View. Frame labels for axes X, Y and Z are made. The labels have the same color as the axes. Returns: A SoSwitch with colored text label to be shown in the FreeCAD View. """ label_strings = ["X", "Y", "Z"] colors = [0xFF0000FF, 0x00FF00FF, 0x0000FFFF] self.label_texts = [] self.label_translations = [] # frame translation self.label_translations.append(coin.SoTranslation()) # axis translation self.label_translations.append(coin.SoTranslation()) self.labels = [] for i in range(3): label_group = coin.SoSeparator() label_group.addChild(self.label_translations[0]) frame_axis_color = coin.SoPackedColor() frame_axis_color.orderedRGBA.setValue(colors[i]) label_group.addChild(frame_axis_color) self.label_texts.append(coin.SoText2()) self.label_texts[i].string.setValues( 0, 3, ["", label_strings[i], ""]) self.label_texts[i].justification.setValue( self.label_texts[i].CENTER) self.label_texts[i].spacing.setValue(0.45) label_group.addChild(self.label_texts[i]) self.labels.append(coin.SoSwitch()) self.labels[i].addChild(label_group) return self.labels
def makeLabels(self): label_strings = ["X", "Y", "Z"] colors = [0xFF0000FF, 0x00FF00FF, 0x0000FFFF] self.label_texts = [] self.label_translations = [] # frame translation self.label_translations.append(coin.SoTranslation()) # axis translation self.label_translations.append(coin.SoTranslation()) self.labels = [] for i in range(3): label_group = coin.SoSeparator() label_group.addChild(self.label_translations[0]) frame_axis_color = coin.SoPackedColor() frame_axis_color.orderedRGBA.setValue(colors[i]) label_group.addChild(frame_axis_color) self.label_texts.append(coin.SoText2()) self.label_texts[i].string.setValues(0, 3, ["", label_strings[i], ""]) self.label_texts[i].justification.setValue( self.label_texts[i].CENTER) self.label_texts[i].spacing.setValue(0.45) label_group.addChild(self.label_texts[i]) self.labels.append(coin.SoSwitch()) self.labels[i].addChild(label_group) return self.labels
def makeFrame(self, frame_labels): """ Method which makes a Coin3D frame to show a current pose in a RobRotation. A frame is made from 3 red, green and blue arrows representing X, Y and Z. Arrows are each constructed from a shaft and an arrowhead. Their dimensions and other attributes are unassigned as they are extracted from appropriate `RobRotation` properties. Returns: A SoSeparator with the frame shown in the FreeCAD View. """ # make a generic shaft from 0 in Y direction shaft_vertices = coin.SoVertexProperty() shaft_vertices.vertex.setNum(2) shaft_vertices.vertex.set1Value(0, 0, 0, 0) self.frame_shaft = coin.SoLineSet() self.frame_shaft.vertexProperty.setValue(shaft_vertices) self.frame_shaft.numVertices.setNum(1) self.frame_shaft.numVertices.setValue(2) # make a generic conic arrowhead oriented in Y axis direction and # move it at the end of the shaft self.frame_arrowhead_translation = coin.SoTranslation() self.frame_arrowhead_cone = coin.SoCone() self.frame_arrowhead = coin.SoSwitch() self.frame_arrowhead.addChild(self.frame_arrowhead_translation) self.frame_arrowhead.addChild(self.frame_arrowhead_cone) # make rotations to rotate prepared shaft and arrowhead for Y axis # direction also to X and Z rot_y2x = coin.SoRotation() rot_y2x.rotation.setValue(coin.SbRotation(coin.SbVec3f(0, 1, 0), coin.SbVec3f(1, 0, 0))) rot_y2z = coin.SoRotation() rot_y2z.rotation.setValue(coin.SbRotation(coin.SbVec3f(0, 1, 0), coin.SbVec3f(0, 0, 1))) # prepare colors for X,Y,Z which will correspond to R,G,B as customary self.frame_color_x = coin.SoPackedColor() self.frame_color_y = coin.SoPackedColor() self.frame_color_z = coin.SoPackedColor() # make complete colored and rotated arrows x_arrow = coin.SoSeparator() x_arrow.addChild(rot_y2x) x_arrow.addChild(self.frame_color_x) x_arrow.addChild(self.frame_shaft) x_arrow.addChild(self.frame_arrowhead) x_arrow.addChild(frame_labels[0]) y_arrow = coin.SoSeparator() y_arrow.addChild(self.frame_color_y) y_arrow.addChild(self.frame_shaft) y_arrow.addChild(self.frame_arrowhead) y_arrow.addChild(frame_labels[1]) z_arrow = coin.SoSeparator() z_arrow.addChild(rot_y2z) z_arrow.addChild(self.frame_color_z) z_arrow.addChild(self.frame_shaft) z_arrow.addChild(self.frame_arrowhead) z_arrow.addChild(frame_labels[2]) # prepare draw style to control shaft width self.frame_drawstyle = coin.SoDrawStyle() # make complete frame and it to shaded display mode separated_frame = coin.SoSeparator() separated_frame.addChild(self.frame_drawstyle) separated_frame.addChild(x_arrow) separated_frame.addChild(y_arrow) separated_frame.addChild(z_arrow) return separated_frame
def makeFrame(self, frame_labels): # make a generic shaft from 0 in Y direction shaft_vertices = coin.SoVertexProperty() shaft_vertices.vertex.setNum(2) shaft_vertices.vertex.set1Value(0, 0, 0, 0) self.frame_shaft = coin.SoLineSet() self.frame_shaft.vertexProperty.setValue(shaft_vertices) self.frame_shaft.numVertices.setNum(1) self.frame_shaft.numVertices.setValue(2) # make a generic conic arrowhead oriented in Y axis direction and # move it at the end of the shaft self.frame_arrowhead_translation = coin.SoTranslation() self.frame_arrowhead_cone = coin.SoCone() self.frame_arrowhead = coin.SoSwitch() self.frame_arrowhead.addChild(self.frame_arrowhead_translation) self.frame_arrowhead.addChild(self.frame_arrowhead_cone) # make rotations to rotate prepared shaft and arrowhead for Y axis # direction also to X and Z rot_y2x = coin.SoRotation() rot_y2x.rotation.setValue( coin.SbRotation(coin.SbVec3f(0, 1, 0), coin.SbVec3f(1, 0, 0))) rot_y2z = coin.SoRotation() rot_y2z.rotation.setValue( coin.SbRotation(coin.SbVec3f(0, 1, 0), coin.SbVec3f(0, 0, 1))) # prepare colors for X,Y,Z which will correspond to R,G,B as customary self.frame_color_x = coin.SoPackedColor() self.frame_color_y = coin.SoPackedColor() self.frame_color_z = coin.SoPackedColor() # make complete colored and rotated arrows x_arrow = coin.SoSeparator() x_arrow.addChild(rot_y2x) x_arrow.addChild(self.frame_color_x) x_arrow.addChild(self.frame_shaft) x_arrow.addChild(self.frame_arrowhead) x_arrow.addChild(frame_labels[0]) y_arrow = coin.SoSeparator() y_arrow.addChild(self.frame_color_y) y_arrow.addChild(self.frame_shaft) y_arrow.addChild(self.frame_arrowhead) y_arrow.addChild(frame_labels[1]) z_arrow = coin.SoSeparator() z_arrow.addChild(rot_y2z) z_arrow.addChild(self.frame_color_z) z_arrow.addChild(self.frame_shaft) z_arrow.addChild(self.frame_arrowhead) z_arrow.addChild(frame_labels[2]) # prepare draw style to control shaft width self.frame_drawstyle = coin.SoDrawStyle() # make complete frame and it to shaded display mode separated_frame = coin.SoSeparator() separated_frame.addChild(self.frame_drawstyle) separated_frame.addChild(x_arrow) separated_frame.addChild(y_arrow) separated_frame.addChild(z_arrow) return separated_frame