Ejemplo n.º 1
0
 def __init__(self, points, dynamic=False, arrow_size=0.04, length=2):
     super(Arrow, self).__init__(points, dynamic)
     self.arrow_sep = coin.SoSeparator()
     self.arrow_rot = coin.SoRotation()
     self.arrow_scale = coin.SoScale()
     self.arrow_translate = coin.SoTranslation()
     self.arrow_scale.scaleFactor.setValue(arrow_size, arrow_size, arrow_size)
     self.cone = coin.SoCone()
     arrow_length = coin.SoScale()
     arrow_length.scaleFactor = (1, length, 1)
     arrow_origin = coin.SoTranslation()
     arrow_origin.translation = (0, -1, 0)
     self.arrow_sep += [self.arrow_translate, self.arrow_rot, self.arrow_scale]
     self.arrow_sep += [arrow_length, arrow_origin, self.cone]
     self += [self.arrow_sep]
     self.set_arrow_direction()
Ejemplo n.º 2
0
def plot(foo, x, y):
    """x, y are tuples of 3 values: xmin, xmax, xnum"""
    np_foo = np.vectorize(foo)
    x_space = np.linspace(*x)
    y_space = np.linspace(*y)
    xx, yy = np.meshgrid(x_space, y_space)
    xx = xx.flatten()
    yy = yy.flatten()
    zz = np_foo(xx, yy)
    num_x = x[-1]
    num_y = y[-1]
    points = np.array([xx, yy, zz]).T
    scale = coin.SoScale()
    scale.scaleFactor.setValue(1, 1, abs(x[1] - x[0]) / abs(max(zz) - min(zz)))
    return [scale, simple_quad_mesh(points, num_x, num_y)]
Ejemplo n.º 3
0
    def attach(self, obj):
        "'''Setup the scene sub-graph of the view provider, this method is mandatory'''"
        self.wireframe = coin.SoGroup()
        self.scale = coin.SoScale()
        #		self.color = coin.SoBaseColor()
        self.trans = coin.SoTranslation()

        self.data = coin.SoCube()
        # Switch Z to proper default value
        self.trans.translation.setValue([0, 0, 100])
        self.wireframe.addChild(self.trans)
        style = coin.SoDrawStyle()
        style.style = coin.SoDrawStyle.LINES
        self.wireframe.addChild(style)
        self.wireframe.addChild(self.scale)
        #		self.wireframe.addChild(self.color)
        self.wireframe.addChild(self.data)
        obj.addDisplayMode(self.wireframe, "Wireframe")
Ejemplo n.º 4
0
 def attach(self, obj):
     '''Setup the scene sub-graph of the view provider, this method is mandatory'''
     self.shaded = coin.SoGroup()
     self.wireframe = coin.SoGroup()
     self.scale = coin.SoScale()
     self.color = coin.SoBaseColor()
    
     data=coin.SoCube()
     self.shaded.addChild(self.scale)
     self.shaded.addChild(self.color)
     self.shaded.addChild(data)
     obj.addDisplayMode(self.shaded,"Shaded");
     style=coin.SoDrawStyle()
     style.style = coin.SoDrawStyle.LINES
     self.wireframe.addChild(style)
     self.wireframe.addChild(self.scale)
     self.wireframe.addChild(self.color)
     self.wireframe.addChild(data)
     obj.addDisplayMode(self.wireframe,"Wireframe");
     self.onChanged(obj,"Color")
Ejemplo n.º 5
0
 def _update_grid(self, grid_x, grid_y, drag_release=False):
     self.grid.removeAllChildren()
     x_points_lower = [[x, grid_y[0], -0.001] for x in grid_x]
     x_points_upper = [[x, grid_y[-1], -0.001] for x in grid_x]
     y_points_lower = [[grid_x[0], y, -0.001] for y in grid_y]
     y_points_upper = [[grid_x[-1], y, -0.001] for y in grid_y]
     for l in zip(x_points_lower, x_points_upper):
         self.grid += [pp.Line(l, color='grey').object]
     for l in zip(y_points_lower, y_points_upper):
         self.grid += [pp.Line(l, color='grey').object]
     for l in y_points_upper:
         color = coin.SoMaterial()
         color.diffuseColor = [0, 0, 0]
         textsep = coin.SoSeparator()
         text = coin.SoText2()
         trans = coin.SoTranslation()
         trans.translation = l
         text.string = self.text_repr(l[1] * self.value_scale)
         textsep += [color, trans, text]
         self.grid += [textsep]
     interpolation = self.spline.interpolation(50)
     if drag_release:
         for i in self.back:
             color = coin.SoMaterial()
             color.diffuseColor = [0, 0, 0]
             textsep = coin.SoSeparator()
             scale = coin.SoScale()
             text = coin.SoAsciiText()
             trans = coin.SoTranslation()
             rot = coin.SoRotationXYZ()
             rot.axis = coin.SoRotationXYZ.Z
             rot.angle.setValue(np.pi / 2)
             scale.scaleFactor = (self.text_scale, self.text_scale,
                                  self.text_scale)
             trans.translation = (i[0], i[1], 0.001)
             text.string = self.text_repr(
                 interpolation(i[0]) * self.value_scale * self.scale[1])
             textsep += [color, trans, scale, rot, text]
             self.grid += [textsep]
Ejemplo n.º 6
0
  def attach(self, obj):
     "Setup the scene sub-graph of the view provider, this method is mandatory"
     self.shaded = coin.SoGroup()
     self.wireframe = coin.SoGroup()
     self.scale = coin.SoScale()
     self.color = coin.SoBaseColor()

     self.data=coin.SoCoordinate3()
     self.face=coin.SoIndexedLineSet()

     self.shaded.addChild(self.scale)
     self.shaded.addChild(self.color)
     self.shaded.addChild(self.data)
     self.shaded.addChild(self.face)
     obj.addDisplayMode(self.shaded,"Shaded");
     style=coin.SoDrawStyle()
     style.style = coin.SoDrawStyle.LINES
     self.wireframe.addChild(style)
     self.wireframe.addChild(self.scale)
     self.wireframe.addChild(self.color)
     self.wireframe.addChild(self.data)
     self.wireframe.addChild(self.face)
     obj.addDisplayMode(self.wireframe,"Wireframe");
     self.onChanged(obj,"Color")
Ejemplo n.º 7
0
    def attach(self, obj):
        "'''Setup the scene sub-graph of the view provider, this method is mandatory'''"
        self.shaded = coin.SoGroup()
        self.wireframe = coin.SoGroup()
        self.scale = coin.SoScale()
        self.color = coin.SoBaseColor()
        self.trans = coin.SoTranslation()

        self.data = coin.SoCube()
        # Top of print bed is X-Y plane
        self.trans.translation.setValue([0, 0, -0.5])
        self.shaded.addChild(self.trans)
        self.shaded.addChild(self.scale)
        self.shaded.addChild(self.color)
        self.shaded.addChild(self.data)
        obj.addDisplayMode(self.shaded, "Shaded")
        style = coin.SoDrawStyle()
        style.style = coin.SoDrawStyle.LINES
        self.wireframe.addChild(style)
        self.wireframe.addChild(self.scale)
        self.wireframe.addChild(self.color)
        self.wireframe.addChild(self.data)
        obj.addDisplayMode(self.wireframe, "Wireframe")
        self.onChanged(obj, "Color")
Ejemplo n.º 8
0
 def __init__(self):
     self.group = coin.SoGroup()
     self.__scale = coin.SoScale()
     self.group.addChild(self.__scale)
Ejemplo n.º 9
0
    def __init__(self):
        super(gridNode, self).__init__()

        self.vec = coin.SoTransformVec3f()
        #self.vec.matrix.connectFrom(cam.orientation)
        self.vec.vector = coin.SbVec3f(0, 0, -1)

        self.calc = coin.SoCalculator()
        self.calc.A.connectFrom(self.vec.direction)
        self.calc.expression.set1Value(0, "ta=0.5")  # maxviz
        self.calc.expression.set1Value(1, "tb=20.0")  # factor
        self.calc.expression.set1Value(2, "tA=vec3f(1,0,0)")  # plane normal
        self.calc.expression.set1Value(3, "tc=dot(A,tA)")
        self.calc.expression.set1Value(4, "td=fabs(tc)")
        self.calc.expression.set1Value(5, "oa=1.0-ta*pow(td,tb)")
        self.calc.expression.set1Value(6, "oA=vec3f(oa,0,0)")

        self.scaleEngine = coin.SoCalculator()
        #self.scaleEngine.a.connectFrom(cam.height)
        self.scaleEngine.expression.set1Value(0, "ta=floor(log10(a/10))")
        self.scaleEngine.expression.set1Value(1, "tb=pow(10,ta)")
        self.scaleEngine.expression.set1Value(2, "oA=vec3f(tb,tb,tb)")
        self.scaleEngine.expression.set1Value(3, "oa=0.01*a/tb")

        self.calc2 = coin.SoCalculator()
        self.calc2.a.connectFrom(self.scaleEngine.oa)
        self.calc2.b.connectFrom(self.calc.oa)
        self.calc2.expression.set1Value(0, "ta=pow(a,0.3)")
        self.calc2.expression.set1Value(1, "oa=(b>ta)?b:ta")

        self.material1 = coin.SoMaterial()
        self.material2 = coin.SoMaterial()
        self.material3 = coin.SoMaterial()
        self.material4 = coin.SoMaterial()
        self.coord = coin.SoCoordinate3()
        self.coord2 = coin.SoCoordinate3()
        self.line1 = coin.SoIndexedLineSet()
        self.line2 = coin.SoIndexedLineSet()
        self.lineSet = coin.SoIndexedLineSet()
        self.lineSet2 = coin.SoIndexedLineSet()

        self.miniscale = coin.SoScale()
        self.miniscale.scaleFactor = coin.SbVec3f(0.1, 0.1, 0.1)

        self.mainscale = coin.SoScale()
        self.mainscale.scaleFactor.connectFrom(self.scaleEngine.oA)

        self.addChild(self.mainscale)
        self.addChild(self.coord)
        self.addChild(self.material1)
        self.addChild(self.line1)
        self.addChild(self.material2)
        self.addChild(self.line2)
        self.addChild(self.material3)
        self.addChild(self.lineSet)
        self.addChild(self.miniscale)
        self.addChild(self.material4)
        self.addChild(self.coord2)
        self.addChild(self.lineSet2)

        self._vector1 = coin.SbVec3f(1, 0, 0)
        self._vector2 = coin.SbVec3f(0, 1, 0)
        self.normal = self._vector1.cross(self._vector2)

        self._mainDim = 100
        self._subDim = 10
        self._maxviz = 1.0
        self._factor = 1.0

        self._numGridLines = 4
        self.material1.diffuseColor = coin.SbColor(1, 0, 0)
        self.material2.diffuseColor = coin.SbColor(0, 1, 0)
        self.material3.diffuseColor = coin.SbColor(0.5, 0.5, 0.5)
        self.material4.diffuseColor = coin.SbColor(0.5, 0.5, 0.5)
        self.material3.transparency.connectFrom(self.calc.oa)
        self.material4.transparency.connectFrom(self.calc2.oa)
    def attach(self, vobj):
        r"""Setup the scene sub-graph of the view provider,
        this method is mandatory
        
        See Also
        --------
        https://www.freecadweb.org/wiki/Scripted_objects

        """
        debug("AnchorViewProvider/attach")

        self.shaded = coin.SoSeparator()
        self.wireframe = coin.SoSeparator()

        # group u cone and cylinder
        self.group_u = coin.SoSeparator()
        self.color_u = coin.SoBaseColor()

        self.group_cyl_u = coin.SoSeparator()
        self.transform_cyl_u = coin.SoTransform()

        self.group_cone_u = coin.SoSeparator()
        self.transform_cone_u = coin.SoTransform()

        # group v cone and cylinder
        self.group_v = coin.SoSeparator()
        self.transform_v = coin.SoTransform()
        self.color_v = coin.SoBaseColor()

        self.group_cyl_v = coin.SoSeparator()
        self.transform_cyl_v = coin.SoTransform()

        self.group_cone_v = coin.SoSeparator()
        self.transform_cone_v = coin.SoTransform()

        # global
        self.scale = coin.SoScale()
        self.scale.scaleFactor.setValue(1., 1., 1.)
        self.transform = coin.SoTransform()

        # arrow dimensions
        self.arrow_length = 1
        cone_cyl_ratio = 0.2
        cyl_radius_ratio = 0.05
        cone_base_radius_ratio = 0.1

        # The cylinder is created from its middle at the origin
        # -> compensation
        self.transform_cyl_u.translation.setValue(
            (0., self.arrow_length * (1 - cone_cyl_ratio) / 2, 0.))
        self.transform_cone_u.translation.setValue(
            (0., self.arrow_length * (1 - cone_cyl_ratio) +
             self.arrow_length * cone_cyl_ratio / 2, 0.))

        self.transform_cyl_v.translation.setValue(
            (0., self.arrow_length * (1 - cone_cyl_ratio) / 2, 0.))
        self.transform_cone_v.translation.setValue(
            (0., self.arrow_length * (1 - cone_cyl_ratio) +
             self.arrow_length * cone_cyl_ratio / 2, 0.))

        # put v at 90 degrees
        self.transform_v.center.setValue((0, 0, 0))
        self.transform_v.rotation.setValue(coin.SbVec3f((1, 0, 0)),
                                           math.pi / 2)

        # Cone and cylinder creation from dimensions
        cone_u = coin.SoCone()
        cone_u.height.setValue(self.arrow_length * cone_cyl_ratio)
        cone_u.bottomRadius.setValue(self.arrow_length *
                                     cone_base_radius_ratio)

        cylinder_u = coin.SoCylinder()
        cylinder_u.radius.setValue(self.arrow_length * cyl_radius_ratio)
        cylinder_u.height.setValue(self.arrow_length * (1 - cone_cyl_ratio))

        cone_v = coin.SoCone()
        cone_v.height.setValue(self.arrow_length * cone_cyl_ratio)
        cone_v.bottomRadius.setValue(self.arrow_length *
                                     cone_base_radius_ratio)

        cylinder_v = coin.SoCylinder()
        cylinder_v.radius.setValue(self.arrow_length * cyl_radius_ratio)
        cylinder_v.height.setValue(self.arrow_length * (1 - cone_cyl_ratio))

        # group_cyl_u
        self.group_cyl_u.addChild(self.transform_cyl_u)
        self.group_cyl_u.addChild(cylinder_u)

        # group_cone_u
        self.group_cone_u.addChild(self.transform_cone_u)
        self.group_cone_u.addChild(cone_u)

        # group_u
        self.group_u.addChild(self.color_u)
        self.group_u.addChild(self.group_cyl_u)
        self.group_u.addChild(self.group_cone_u)

        # group_cyl_v
        self.group_cyl_v.addChild(self.transform_cyl_v)
        self.group_cyl_v.addChild(cylinder_v)

        # group_cone_v
        self.group_cone_v.addChild(self.transform_cone_v)
        self.group_cone_v.addChild(cone_v)

        # group_v
        self.group_v.addChild(self.transform_v)
        self.group_v.addChild(self.color_v)
        self.group_v.addChild(self.group_cyl_v)
        self.group_v.addChild(self.group_cone_v)

        # ** shaded **
        self.shaded.addChild(self.transform)
        self.shaded.addChild(self.scale)
        self.shaded.addChild(self.group_u)
        self.shaded.addChild(self.group_v)
        vobj.addDisplayMode(self.shaded, "Shaded")

        # ** wireframe **
        style = coin.SoDrawStyle()
        style.style = coin.SoDrawStyle.LINES
        self.wireframe.addChild(style)
        self.wireframe.addChild(self.transform)
        self.wireframe.addChild(self.scale)
        self.wireframe.addChild(self.group_u)
        self.wireframe.addChild(self.group_v)
        vobj.addDisplayMode(self.wireframe, "Wireframe")

        self.onChanged(vobj, "ColorU")
        self.onChanged(vobj, "ColorV")