Beispiel #1
0
    def attach(self, vobj):
        """Respond to created/restored object event (callback).

        Args:
            vobj -- Related ViewProviderDocumentObject
        """
        # pylint: disable=attribute-defined-outside-init

        self.fpo = vobj.Object
        PointLight.set_properties(self.fpo)

        # Here we create coin representation, which is in 2 parts: a light,
        # and a geometry (the latter being a lineset embedded inside a switch)
        self.coin = SimpleNamespace()
        scene = Gui.ActiveDocument.ActiveView.getSceneGraph()

        # Create pointlight in scenegraph
        self.coin.light = coin.SoPointLight()
        scene.insertChild(self.coin.light, 0)  # Insert frontwise

        # Create geometry in scenegraph
        self.coin.geometry = coin.SoSwitch()

        self.coin.node = coin.SoSeparator()
        self.coin.transform = coin.SoTransform()
        self.coin.node.addChild(self.coin.transform)
        self.coin.material = coin.SoMaterial()
        self.coin.node.addChild(self.coin.material)
        self.coin.drawstyle = coin.SoDrawStyle()
        self.coin.drawstyle.style = coin.SoDrawStyle.LINES
        self.coin.drawstyle.lineWidth = 1
        self.coin.drawstyle.linePattern = 0xaaaa
        self.coin.node.addChild(self.coin.drawstyle)
        self.coin.coords = coin.SoCoordinate3()
        self.coin.coords.point.setValues(0, len(self.SHAPE), self.SHAPE)
        self.coin.node.addChild(self.coin.coords)
        self.coin.lineset = coin.SoLineSet()
        self.coin.lineset.numVertices.setValues(0,
                                                len(self.SHAPE) // 2,
                                                [2] * (len(self.SHAPE) // 2))
        self.coin.node.addChild(self.coin.lineset)

        self.coin.geometry.addChild(self.coin.node)
        self.coin.geometry.whichChild.setValue(coin.SO_SWITCH_ALL)
        scene.addChild(self.coin.geometry)  # Insert back
        vobj.addDisplayMode(self.coin.geometry, "Shaded")

        # Update coin elements with actual object properties
        self._update_location(self.fpo)
        self._update_color(self.fpo)
        self._update_power(self.fpo)
        self._update_radius(self.fpo)
Beispiel #2
0
    def attach(self, vobj):
        """Code executed when object is created/restored (callback)

        Parameters:
        -----------
        vobj: related ViewProviderDocumentObject
        """
        # pylint: disable=attribute-defined-outside-init

        self.fpo = vobj.Object
        AreaLight.set_properties(self.fpo)

        # Here we create coin representation, which is in 2 parts: a light,
        # and a geometry, the former being a point light, the latter being a
        # faceset embedded in a switch)

        self.coin = SimpleNamespace()
        scene = Gui.ActiveDocument.ActiveView.getSceneGraph()

        # Create pointlight in scenegraph
        self.coin.light = coin.SoPointLight()
        scene.insertChild(self.coin.light, 0)  # Insert frontwise

        # Create geometry in scenegraph
        self.coin.geometry = coin.SoSwitch()
        self.coin.node = coin.SoSeparator()
        self.coin.transform = coin.SoTransform()
        self.coin.node.addChild(self.coin.transform)
        self.coin.material = coin.SoMaterial()
        self.coin.node.addChild(self.coin.material)
        self.coin.drawstyle = coin.SoDrawStyle()
        self.coin.drawstyle.style = coin.SoDrawStyle.FILLED
        self.coin.node.addChild(self.coin.drawstyle)
        self.coin.coords = coin.SoCoordinate3()

        self.coin.coords = coin.SoCoordinate3()
        self.coin.coords.point.setValues(0, len(self.SHAPE), self.SHAPE)
        self.coin.node.addChild(self.coin.coords)
        self.coin.faceset = coin.SoFaceSet()
        self.coin.faceset.numVertices.setValues(0, 1, [5])
        self.coin.node.addChild(self.coin.faceset)

        self.coin.geometry.addChild(self.coin.node)
        self.coin.geometry.whichChild.setValue(coin.SO_SWITCH_ALL)
        scene.addChild(self.coin.geometry)  # Insert back
        vobj.addDisplayMode(self.coin.geometry, "Shaded")

        # Update coin elements with actual object properties
        self._update_placement(self.fpo)
        self._update_color(self.fpo)
        self._update_power(self.fpo)
        self._update_size(self.fpo)
Beispiel #3
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()
 def createLightInstance(self):
     return coin.SoPointLight()