Beispiel #1
0
	def onChanged(self, fp, prop):
		if not fp.On: return

		print ("on changed .....",fp.Label,prop)

		if fp == None: return
		if not fp.ViewObject.Visibility: return

		try: self.v
		except: return

		AxisAngle=[
				(FreeCAD.Vector(1,1,1),120),
				(FreeCAD.Vector(1,1,1),-120),
				
				(FreeCAD.Vector(1,0,1),45),
				(FreeCAD.Vector(1,0,1),60),
				(FreeCAD.Vector(1,0,1),30),
				
				(FreeCAD.Vector(1,0,0),90),
				(FreeCAD.Vector(1,0,0),-90),
				
				(FreeCAD.Vector(-1,0,0),90),
				(FreeCAD.Vector(-1,0,0),-90),
				
			]


		if prop=="Shape" or prop=="Group": 
			dpms=[fp.A_DisplayMode,fp.B_DisplayMode,fp.C_DisplayMode,fp.D_DisplayMode]
			vals=[fp.A_OrientationMode,fp.B_OrientationMode,fp.C_OrientationMode,fp.D_OrientationMode]
			for ix in [0]:
				objs=fp.objs
				view=self.v.getViewer(ix)
				val=vals[ix]
				marker = coin.SoSeparator()
				for objx in objs+[fp.obja]:
					print "run ",objx.Label
					node= objx.ViewObject.RootNode

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

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

					marker.addChild(nodeA)

				c=view.getSoRenderManager().getCamera()
				if val <> 0:
					c.orientation=FreeCAD.Rotation(	AxisAngle[val-1][0],AxisAngle[val-1][1]).Q
				else:
					c.orientation=FreeCAD.Rotation(	fp.A_Axis,fp.A_Angle).Q
					
				sg=view.getSceneGraph()
				sg.removeChild(1)
				sg.removeChild(0)

				# hier die lichter einfuegen
				lis=[]
				for ob in fp.Group:
					#break

					print ("!!",ob,ob.Label,ob.on)

					try: ob.mode
					except: continue

					print ("verarbeitung",ob.mode,ob.on)
					if ob.on and ob.ViewObject.Visibility:

						if ob.mode=="DirectionalLight":
							continue
							# ignore dirlights
							l=coin.SoDirectionalLight()
							#marker.insertChild(l,0)
							#lis += [l]

						if ob.mode=="SpotLight":
							l=coin.SoSpotLight()
							l.cutOffAngle.setValue(0.4)
							l.dropOffRate.setValue(0.)
							l.location.setValue(coin.SbVec3f(ob.location.x,ob.location.y,ob.location.z,))

							l.direction.setValue(coin.SbVec3f(ob.direction.x,ob.direction.y,ob.direction.z,))
							l.color.setValue(coin.SbColor(ob.color[0],ob.color[1],ob.color[2]))
						#marker.insertChild(l,0)

							lis += [l]




				sg.addChild(marker)
				print "makeshadow ..........!"
				mkshadow(marker,lis)
				print "------------------done-----------------"


				for ob in fp.Group:

					try: ob.mode
					except: continue

					print ("verarbeitung",ob.mode,ob.on)
					if ob.on and ob.ViewObject.Visibility:

						if ob.mode=="DirectionalLight":

							l=coin.SoDirectionalLight()
							l.direction.setValue(coin.SbVec3f(-1,1,0))
							l.color.setValue(coin.SbColor(1,0,0))
							l.direction.setValue(coin.SbVec3f(ob.direction.x,ob.direction.y,ob.direction.z,))
							l.color.setValue(coin.SbColor(ob.color[0],ob.color[1],ob.color[2]))

							marker.insertChild(l,0)

						if ob.mode=="PointLight":
							l=coin.SoPointLight()
							l.location.setValue(coin.SbVec3f(ob.location.x,ob.location.y,ob.location.z,))
							l.color.setValue(coin.SbColor(ob.color[0],ob.color[1],ob.color[2]))
							marker.insertChild(l,0)

			return


		if prop.endswith("DisplayMode"):
			w=getattr(fp,prop)
			if w<0: setattr(fp,prop,0)
			if w>3: setattr(fp,prop,3)
			#updatencontenth2(self.v,fp.obja,fp.objb,fp.objs,fp,False)
			return


		if prop.endswith("OrientationMode"):
			val=getattr(fp,prop)
			if val>=len(AxisAngle)or val<0: setattr(fp,prop,val%len(AxisAngle))
			val=getattr(fp,prop)
			if val<>0:
				if prop=="A_OrientationMode":
					fp.A_Axis=AxisAngle[val-1][0]
					fp.A_Angle=AxisAngle[val-1][1]
				if prop=="B_OrientationMode":
					fp.B_Axis=AxisAngle[val-1][0]
					fp.B_Angle=AxisAngle[val-1][1]
				if prop=="C_OrientationMode":
					fp.C_Axis=AxisAngle[val-1][0]
					fp.C_Angle=AxisAngle[val-1][1]
				if prop=="D_OrientationMode":
					fp.D_Axis=AxisAngle[val-1][0]
					fp.D_Angle=AxisAngle[val-1][1]
			return


		if prop.startswith("A_"):
			c=self.v.getViewer(0).getSoRenderManager().getCamera()
			c.orientation=FreeCAD.Rotation(fp.A_Axis,fp.A_Angle).Q

			view=self.v.getViewer(0)
			reg=view.getSoRenderManager().getViewportRegion()
			marker=view.getSoRenderManager().getSceneGraph()
			c.viewAll(marker,reg)

		if prop.startswith("B_"):
			c=self.v.getViewer(1).getSoRenderManager().getCamera()
			c.orientation=FreeCAD.Rotation(fp.B_Axis,fp.B_Angle).Q

			view=self.v.getViewer(1)
			reg=view.getSoRenderManager().getViewportRegion()
			marker=view.getSoRenderManager().getSceneGraph()
			c.viewAll(marker,reg)

		if prop.startswith("C_"):
			c=self.v.getViewer(2).getSoRenderManager().getCamera()
			c.orientation=FreeCAD.Rotation(fp.C_Axis,fp.C_Angle).Q

			view=self.v.getViewer(2)
			reg=view.getSoRenderManager().getViewportRegion()
			marker=view.getSoRenderManager().getSceneGraph()
			c.viewAll(marker,reg)

		if prop.startswith("D_"):
			c=self.v.getViewer(3).getSoRenderManager().getCamera()
			c.orientation=FreeCAD.Rotation(fp.D_Axis,fp.D_Angle).Q

			view=self.v.getViewer(3)
			reg=view.getSoRenderManager().getViewportRegion()
			marker=view.getSoRenderManager().getSceneGraph()
			c.viewAll(marker,reg)

		if fp.fitAll:
			self.v.fitAll()
Beispiel #2
0
def mkshadow(sgg,lis):

	rGrp=FreeCAD.ParamGet('User parameter:BaseApp/Preferences/View')
	atr="HeadlightIntensity"
	v=rGrp.GetInt(atr)

	#set headlight on
	rGrp.SetInt(atr,100)

	# or off
	rGrp.SetInt(atr,0)

	# myCustomNode=Gui.ActiveDocument.ActiveView.getSceneGraph()


	sggs=sgg.getChildren()
	cs=[c.copy() for c in sggs]
	for i in range(len(cs)):
		sgg.removeChild(0)


	sotype=coin.SoType.fromName("ShadowGroup")
	sg=sotype.createInstance()
	sg.getTypeId().getName()
	sg.quality=1

	sgg.insertChild(sg,0)
	ss=sg


	ff=0.5

	if 0:
		l=coin.SoSpotLight()
		l.direction.setValue(coin.SbVec3f(-20,10,-300))
		l.color.setValue(coin.SbColor(ff*random.random(),ff*random.random(),ff*random.random()))
		l.location.setValue(coin.SbVec3f(0,0,300))
		l.cutOffAngle.setValue(0.4)
		l.dropOffRate.setValue(0.)
		ss.insertChild(l,0)

		l=coin.SoSpotLight()
		l.direction.setValue(coin.SbVec3f(0,0,-300))
		l.color.setValue(coin.SbColor(ff*random.random(),ff*random.random(),ff*random.random()))
		l.location.setValue(coin.SbVec3f(0,0,300))
		l.cutOffAngle.setValue(0.4)
		l.dropOffRate.setValue(0.)
		ss.insertChild(l,0)


		l=coin.SoSpotLight()
		l.direction.setValue(coin.SbVec3f(10,20,-300))
		l.color.setValue(coin.SbColor(1,0,0))
		l.color.setValue(coin.SbColor(ff*random.random(),ff*random.random(),ff*random.random()))
		l.location.setValue(coin.SbVec3f(50,10,300))
		l.cutOffAngle.setValue(.35)
		l.dropOffRate.setValue(0.)
		ss.insertChild(l,0)

	else:
		for lig in lis:
			ss.insertChild(lig,0)

	ll=len(cs)
	for i in range(len(cs)):
		sotype=coin.SoType.fromName("SoShadowStyle")
		inst=sotype.createInstance()
		print inst.getTypeId().getName() # => ShadowStyle
		inst.style=3
		ss.insertChild(inst,0)
		ss.addChild(cs[ll-1-i])


	Gui.SendMsgToActiveView("ViewFit")


	print "children von sg"
	ssc=sg.getChildren()
	for c in ssc:
		print c
def navi():
    '''navigator startup'''

    mw = QtGui.QApplication
    #widget.setCursor(QtCore.Qt.SizeAllCursor)
    #cursor ausblenden
    #mw.setOverrideCursor(QtCore.Qt.BlankCursor)

    # 	FreeCADGui.activateWorkbench("NoneWorkbench")
    mw.setOverrideCursor(QtCore.Qt.PointingHandCursor)
    ef = EventFilter()

    ef.laenge = 0.0
    ef.breite = 0.0
    ef.campos = FreeCAD.Vector(0, 0, 20000)
    # ef.output.hide()

    ef.mouseMode = False
    ef.firstCall = True

    ef.mode = "turn"
    ef.navi = myNavigatorWidget(ef)

    ef.speed = 100
    ef.direction = 0.5 * math.pi
    ef.roll = 0

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

    # get a jpg filename
    # jpgfilename = QtGui.QFileDialog.getOpenFileName(QtGui.qApp.activeWindow(),'Open image file','*.jpg')
    fn = '/home/microelly2/FCB/b175_camera_controller/winter.jpg'
    fn = os.path.dirname(__file__) + "/../pics/winter.jpg"

    sg = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph()

    col = coin.SoBaseColor()
    #col.rgb=(1,0,0)
    trans = coin.SoTranslation()
    trans.translation.setValue([0, 0, 0])
    myCustomNode = coin.SoSeparator()
    #myCustomNode.addChild(col)

    if 0 or False:
        cub = coin.SoCylinder()
        cub.radius.setValue(3000)
        cub.height.setValue(4000)
        cub.parts.set("SIDES")
        s = coin.SoRotationXYZ()
        s.angle.setValue(1.5708)
        s.axis.setValue(0)
        myCustomNode.addChild(s)
        s = coin.SoRotationXYZ()
        s.angle.setValue(math.pi)
        s.axis.setValue(1)
        myCustomNode.addChild(s)

    else:

        cub = coin.SoSphere()
        cub.radius.setValue(10000000)

        s = coin.SoRotationXYZ()
        s.angle.setValue(1.5708)
        s.axis.setValue(0)
        myCustomNode.addChild(s)

        s = coin.SoRotationXYZ()
        s.angle.setValue(math.pi)
        s.axis.setValue(1)
        myCustomNode.addChild(s)

    if False:
        l = coin.SoDirectionalLight()
        l.direction.setValue(coin.SbVec3f(0, 1, 0))
        l.color.setValue(coin.SbColor(0, 0, 1))
        myCustomNode.addChild(l)

        l = coin.SoDirectionalLight()
        l.direction.setValue(coin.SbVec3f(0, -1, 0))
        l.color.setValue(coin.SbColor(0, 1, 1))
        myCustomNode.addChild(l)

        l = coin.SoDirectionalLight()
        l.direction.setValue(coin.SbVec3f(0, 0, 1))
        l.color.setValue(coin.SbColor(1, 0, 0))
        myCustomNode.addChild(l)

        l = coin.SoDirectionalLight()
        l.direction.setValue(coin.SbVec3f(0, 0, -1))
        l.color.setValue(coin.SbColor(0.6, 0.6, 1))
        myCustomNode.addChild(l)

        l = coin.SoSpotLight()
        l.direction.setValue(coin.SbVec3f(1, 0, 1))
        l.color.setValue(coin.SbColor(0, 1, 0))
        l.location.setValue(coin.SbVec3f(0, 0, 0))
        #	l.cutOffAngle.setValue(0.01)
        #	l.dropOffRate.setValue(1)
        myCustomNode.addChild(l)

    #myCustomNode.addChild(trans)
    myCustomNode.addChild(cub)
    sg.addChild(myCustomNode)

    tex = coin.SoTexture2()
    tex.filename = fn
    myCustomNode.insertChild(tex, 0)

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

    ef.background = myCustomNode
    ef.tex = tex

    FreeCAD.eventfilter = ef
    mw.installEventFilter(ef)

    FreeCAD.eventfilter.on_key_press = on_keypress2
    FreeCAD.eventfilter.on_move = on_move3
    FreeCAD.eventfilter.on_clicks = on_clicks3
    FreeCAD.eventfilter.on_windowslist = on_windowslist2

    on_keypress2(FreeCAD.eventfilter, 'O')

    view = FreeCADGui.activeDocument().activeView()

    FreeCADGui.ActiveDocument.ActiveView.setAnimationEnabled(False)
    mgr = view.getViewer().getSoRenderManager()
    mgr.setAutoClipping(0)
    FreeCAD.ActiveDocument.recompute()
    FreeCADGui.updateGui()

    return ef