Пример #1
0
    def __init__(self, view, coneHeight=5):
        self.view = view

        self.dro = DRO(view)
        self.tsk = TaskProgress(view)

        # Camera used for the DRO to maintain the same size independent of 3d zoom level
        self.cam = coin.SoOrthographicCamera()
        self.cam.aspectRatio = 1
        self.cam.viewportMapping = coin.SoCamera.LEAVE_ALONE

        # Here's the thing, there is no need for a light in order to display text. But for
        # the faces a light is required otherwise they'll always be black - and one can spend
        # hours to try and make them a different color.
        self.lgt = coin.SoDirectionalLight()

        self.sep = coin.SoSeparator()
        self.sep.addChild(self.cam)
        self.sep.addChild(self.lgt)
        self.sep.addChild(self.dro.sep)
        self.sep.addChild(self.tsk.sep)

        self.tool = Tool(view, coneHeight)

        self.viewer = self.view.getViewer()
        self.render = self.viewer.getSoRenderManager()
        self.sup = None

        self.updatePreferences()
        self.setPosition(0, 0, 0, 0, 0, 0, False, False, None)
Пример #2
0
    def __init__(self):
        debug("HUD init")

        self.HUDNode = coin.SoSeparator()
        
        self.cam = coin.SoOrthographicCamera()
        self.cam.aspectRatio = 1
        self.cam.viewportMapping = coin.SoCamera.LEAVE_ALONE

        self.HUDNode.addChild(self.cam)
    def __init__(self, view, coneHeight=5):
        self.view = view
        self.tsze = coneHeight

        self.cam = coin.SoOrthographicCamera()
        self.cam.aspectRatio = 1
        self.cam.viewportMapping = coin.SoCamera.LEAVE_ALONE

        self.pos = coin.SoTranslation()

        self.mat = coin.SoMaterial()
        self.mat.diffuseColor = coin.SbColor(0.9, 0.0, 0.9)
        self.mat.transparency = 0

        self.fnt = coin.SoFont()

        self.txt = coin.SoText2()
        self.txt.string = 'setValues'
        self.txt.justification = coin.SoText2.LEFT

        self.sep = coin.SoSeparator()

        self.sep.addChild(self.cam)
        self.sep.addChild(self.pos)
        self.sep.addChild(self.mat)
        self.sep.addChild(self.fnt)
        self.sep.addChild(self.txt)

        self.tTrf = coin.SoTransform()
        self.tTrf.translation.setValue((0, -self.tsze / 2, 0))
        self.tTrf.center.setValue((0, self.tsze / 2, 0))
        self.tTrf.rotation.setValue(coin.SbVec3f((1, 0, 0)), -math.pi / 2)

        self.tPos = coin.SoTranslation()

        self.tMat = coin.SoMaterial()
        self.tMat.diffuseColor = coin.SbColor(0.4, 0.4, 0.4)
        self.tMat.transparency = 0.8

        self.tool = coin.SoCone()
        self.tool.height.setValue(self.tsze)
        self.tool.bottomRadius.setValue(self.tsze / 4)

        self.tSep = coin.SoSeparator()
        self.tSep.addChild(self.tPos)
        self.tSep.addChild(self.tTrf)
        self.tSep.addChild(self.tMat)
        self.tSep.addChild(self.tool)

        self.viewer = self.view.getViewer()
        self.render = self.viewer.getSoRenderManager()
        self.sup = None

        self.updatePreferences()
        self.setPosition(0, 0, 0, 0, 0, 0, False, False)
Пример #4
0
    def __init__(self, *args, **kwrds):
        try:
            self.app = QtGui.QApplication([])
        except RuntimeError:
            self.app = QtGui.QApplication.instance()

        super(Viewer, self).__init__(*args, **kwrds)
        self.sg = coin.SoSeparator()
        self.sg += [coin.SoOrthographicCamera()]
        self.setSceneGraph(self.sg)
        self.setBackgroundColor(coin.SbColor(1,1,1))
        self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
Пример #5
0
def makeSnapshotWithoutGui():
    from pivy import coin

    # create a test geometry and create an IV representation as string
    box = Part.makeCone(10, 8, 10)
    iv = box.writeInventor()

    # load it into a buffer
    inp = coin.SoInput()
    try:
        inp.setBuffer(iv)
    except Exception:
        tempPath = tempfile.gettempdir()
        fileName = tempPath + os.sep + "cone.iv"
        file = open(fileName, "w")
        file.write(iv)
        file.close()
        inp.openFile(fileName)

    # and create a scenegraph
    data = coin.SoDB.readAll(inp)
    base = coin.SoBaseColor()
    base.rgb.setValue(0.6, 0.7, 1.0)
    data.insertChild(base, 0)

    # add light and camera so that the rendered geometry is visible
    root = coin.SoSeparator()
    light = coin.SoDirectionalLight()
    cam = coin.SoOrthographicCamera()
    root.addChild(cam)
    root.addChild(light)
    root.addChild(data)

    # do the rendering now
    axo = coin.SbRotation(-0.353553, -0.146447, -0.353553, -0.853553)
    viewport = coin.SbViewportRegion(400, 400)
    cam.orientation.setValue(axo)
    cam.viewAll(root, viewport)
    off = coin.SoOffscreenRenderer(viewport)
    root.ref()
    off.render(root)
    root.unref()

    # export the image, PS is always available
    off.writeToPostScript("crystal.ps")

    # Other formats are only available if simage package is installed
    if off.isWriteSupported("PNG"):
        print("Save as PNG")
        off.writeToFile("crystal.png", "PNG")
Пример #6
0
def make_snapshot(input_file, output_file, size=48):
    from pivy import coin

    ext = os.path.splitext(input_file)[1][1:]
    mod = FreeCAD.getImportType(ext)
    if len(mod) == 0:
        print("Cannot load file {}".format(input_file))
        return

    # use the first listed module
    module = importlib.import_module(mod[0])
    module.open(input_file)

    doc = FreeCAD.ActiveDocument
    if doc is None:
        print("No active document")
        return

    init_gui()
    nodes = [FreeCADGui.subgraphFromObject(obj) for obj in doc.Objects]

    # add light and camera so that the rendered geometry is visible
    root = coin.SoSeparator()
    light = coin.SoDirectionalLight()
    cam = coin.SoOrthographicCamera()
    root.addChild(cam)
    root.addChild(light)
    for node in nodes:
        root.addChild(node)

    # do the rendering now
    axo = coin.SbRotation(-0.353553, -0.146447, -0.353553, -0.853553)
    width = size
    height = size
    viewport = coin.SbViewportRegion(width, height)
    cam.orientation.setValue(axo)
    cam.viewAll(root, viewport)
    off = FreeCADGui.SoQtOffscreenRenderer(width, height)
    off.setBackgroundColor(1, 1, 1)
    root.ref()

    # A QGuiApplication is needed to create an OpenGL context
    if QtGui.QGuiApplication.instance() is None:
        app = QtGui.QGuiApplication(sys.argv)

    off.render(root)
    off.writeToImage(output_file)
    root.unref()
    def Activated(self):
        self.states = [
            'selecting_face', 'choosing_drafting_tools', 'drawing',
            'extruding', 'finalizing'
        ]
        self.state = self.states[0]

        # Coin Separator for text helping user during the command

        textSep = coin.SoSeparator()
        cam = coin.SoOrthographicCamera()
        cam.aspectRatio = 1
        cam.viewportMapping = coin.SoCamera.LEAVE_ALONE

        trans = coin.SoTranslation()
        trans.translation = (-0.98, 0.85, 0)

        myFont = coin.SoFont()
        myFont.name = "Arial"
        size = 50
        myFont.size.setValue(size)
        self.SoText2 = coin.SoText2()
        self.SoText2.string.setValues(
            0, 2, ["Sélectionner une face d'un composant", ""])
        color = coin.SoBaseColor()
        color.rgb = (0, 0, 0)

        textSep.addChild(cam)
        textSep.addChild(trans)
        textSep.addChild(color)
        textSep.addChild(myFont)
        textSep.addChild(self.SoText2)

        activeDoc = Gui.ActiveDocument
        view = activeDoc.ActiveView
        self.sg = view.getSceneGraph()
        viewer = view.getViewer()
        self.render = viewer.getSoRenderManager()
        self.sup = self.render.addSuperimposition(textSep)
        self.sg.touch()

        # Timer to check what the user is doing
        self.machining_timer = QtCore.QTimer()
        self.machining_timer.setInterval(200)
        self.machining_timer.timeout.connect(self.check)
        self.start()
Пример #8
0
    def Activated(self, index=0):

        if index == 1:
            debug("GeomInfo activated")
            self.stack = []
            # install the function in resident mode
            FreeCADGui.Selection.addObserver(self)
            self.active = True
            self.textSep = coin.SoSeparator()
            self.cam = coin.SoOrthographicCamera()
            self.cam.aspectRatio = 1
            self.cam.viewportMapping = coin.SoCamera.LEAVE_ALONE

            self.trans = coin.SoTranslation()
            self.trans.translation = (-0.98, 0.90, 0)

            self.myFont = coin.SoFont()
            self.myFont.name = "FreeMono,FreeSans,sans"
            size = FreeCAD.ParamGet(
                "User parameter:BaseApp/Preferences/Mod/Curves").GetInt(
                    'GeomInfoFontSize', 14)
            print(size)
            self.myFont.size.setValue(size)
            self.SoText2 = coin.SoText2()
            self.SoText2.string = ""  # "Nothing Selected\r2nd line"
            self.color = coin.SoBaseColor()
            self.color.rgb = (0, 0, 0)

            self.textSep.addChild(self.cam)
            self.textSep.addChild(self.trans)
            self.textSep.addChild(self.color)
            self.textSep.addChild(self.myFont)
            self.textSep.addChild(self.SoText2)

            self.addHUD()
            self.Active = True
            self.viz = False
            self.getTopo()

        elif (index == 0) and self.Active:
            debug("GeomInfo off")
            self.removeHUD()
            self.Active = False
            FreeCADGui.Selection.removeObserver(self)
Пример #9
0
def updatencontenth2(viewer,obja,objb,objs,fp,clearSel=True,fit=True):

	print ("update content",fp,fp.Label)

	try:
		view=viewer.getViewer(0)
	except:
		title=fp.Label
		viewer=Gui.createViewer(4,title)
		fp.Proxy.v=viewer

	v=viewer
	view=v.getViewer(0)
	rm=view.getSoRenderManager()
	print "######################"
	rm.setCamera( coin.SoOrthographicCamera())

	marker = coin.SoSeparator()

	for objx in objs+[obja]:
		print "run 0",objx.Label
		node= objx.ViewObject.RootNode

		if fp.A_DisplayMode==0:
			nodeA=node
		else:
			nodeA=node.copy()
			clds=nodeA.getChildren()
			s2=clds[2]
			s2.whichChild.setValue(fp.A_DisplayMode)

		marker.addChild(nodeA)

	view.setSceneGraph(marker)

	c=view.getSoRenderManager().getCamera()
	c.orientation=FreeCAD.Rotation(fp.A_Axis,fp.A_Angle).Q

	reg=view.getSoRenderManager().getViewportRegion()
	marker=view.getSoRenderManager().getSceneGraph()
	c.viewAll(marker,reg)

	#------------------------------------

	view=v.getViewer(1)
	marker = coin.SoSeparator()
	for objx in objs +[objb]:
		print "run 1",objx.Label
		node= objx.ViewObject.RootNode

		if fp.B_DisplayMode==0:
			nodeA=node
		else:
			nodeA=node.copy()
			clds=nodeA.getChildren()
			s2=clds[2]
			s2.whichChild.setValue(fp.B_DisplayMode)

		marker.addChild(nodeA)

	view.setSceneGraph(marker)

	c=view.getSoRenderManager().getCamera()
	c.orientation=FreeCAD.Rotation(fp.B_Axis,fp.B_Angle).Q

	#------------------------------------

	view=v.getViewer(2)
	marker = coin.SoSeparator()
	for objx in objs + [objb]:
		print "run 2",objx.Label
		node= objx.ViewObject.RootNode

		if fp.C_DisplayMode==0:
			nodeA=node
		else:
			nodeA=node.copy()
			clds=nodeA.getChildren()
			s2=clds[2]
			s2.whichChild.setValue(fp.C_DisplayMode)

		marker.addChild(nodeA)

	view.setSceneGraph(marker)

	c=view.getSoRenderManager().getCamera()
	c.orientation=FreeCAD.Rotation(fp.C_Axis,fp.C_Angle).Q

	#------------------------------------

	view=v.getViewer(3)
	marker = coin.SoSeparator()
	for objx in objs +[obja]:
		print "run 3",objx.Label
		node= objx.ViewObject.RootNode

		if fp.D_DisplayMode==0:
			nodeA=node
		else:
			nodeA=node.copy()
			clds=nodeA.getChildren()
			s2=clds[2]
			s2.whichChild.setValue(fp.D_DisplayMode)

		marker.addChild(nodeA)

	view.setSceneGraph(marker)

	c=view.getSoRenderManager().getCamera()
	c.orientation=FreeCAD.Rotation(fp.D_Axis,fp.D_Angle).Q

	#------------------------------------

	if fit:
		v.fitAll()

	if clearSel:
		Gui.Selection.clearSelection()
Пример #10
0
name = f.name
f.close()
inp.openFile(name)

print('1')
# and create a scenegraph
data = coin.SoDB.readAll(inp)
base = coin.SoBaseColor()
base.rgb.setValue(0.6, 0.7, 1.0)
data.insertChild(base, 0)

print('2')
# add light and camera so that the rendered geometry is visible
root = coin.SoSeparator()
light = coin.SoDirectionalLight()
cam = coin.SoOrthographicCamera()
root.addChild(cam)
root.addChild(light)
root.addChild(data)

print('3')
# do the rendering now
axo = coin.SbRotation(-0.353553, -0.146447, -0.353553, -0.853553)
viewport = coin.SbViewportRegion(600, 600)
cam.orientation.setValue(axo)
cam.viewAll(root, viewport)
off = coin.SoOffscreenRenderer(viewport)
root.ref()
off.render(root)
root.unref()
Пример #11
0
    def Activated(self, index=0):

        if index == 1:
            debug("GeomInfo activated")
            #self.activeDoc = FreeCADGui.ActiveDocument
            #self.view = self.activeDoc.ActiveView
            self.stack = []
            FreeCADGui.Selection.addObserver(
                self)  # installe la fonction en mode resident
            #FreeCADGui.Selection.addObserver(self.getTopo)
            self.active = True
            #self.sg = self.view.getSceneGraph()
            self.textSep = coin.SoSeparator()

            self.cam = coin.SoOrthographicCamera()
            self.cam.aspectRatio = 1
            self.cam.viewportMapping = coin.SoCamera.LEAVE_ALONE

            self.trans = coin.SoTranslation()
            self.trans.translation = (-0.98, 0.90, 0)

            self.myFont = coin.SoFont()
            self.myFont.name = "FreeMono,FreeSans,sans"
            self.myFont.size.setValue(14.0)
            #self.trans = coin.SoTranslation()
            self.SoText2 = coin.SoText2()
            #self.trans.translation.setValue(.25,.0,1.25)
            self.SoText2.string = ""  #"Nothing Selected\r2nd line"
            self.color = coin.SoBaseColor()
            self.color.rgb = (0, 0, 0)

            self.textSep.addChild(self.cam)
            self.textSep.addChild(self.trans)
            self.textSep.addChild(self.color)
            self.textSep.addChild(self.myFont)
            #self.textSep.addChild(self.trans)
            self.textSep.addChild(self.SoText2)
            #self.Active = False
            #self.sg.addChild(self.textSep)

            #self.viewer=self.view.getViewer()
            #self.render=self.viewer.getSoRenderManager()
            #self.sup = self.render.addSuperimposition(self.textSep)
            #self.sg.touch()
            #self.cam2 = coin.SoPerspectiveCamera()
            #self.sg.addChild(self.cam2)

            #self.sensor = coin.SoFieldSensor(self.updateCB, None)
            #self.sensor.setData(self.sensor)
            #self.sensor.setPriority(0)

            self.addHUD()

            self.Active = True
            self.viz = False
            self.getTopo()

        elif (index == 0) and self.Active:
            debug("GeomInfo off")
            self.removeHUD()
            self.Active = False
            FreeCADGui.Selection.removeObserver(self)