Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- # ***************************************************************************
- # * *
- # * Copyright (c) 2017 sliptonic <shopinthewoods@gmail.com> *
- # * *
- # * This program is free software; you can redistribute it and/or modify *
- # * it under the terms of the GNU Lesser General Public License (LGPL) *
- # * as published by the Free Software Foundation; either version 2 of *
- # * the License, or (at your option) any later version. *
- # * for detail see the LICENCE text file. *
- # * *
- # * This program is distributed in the hope that it will be useful, *
- # * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- # * GNU Library General Public License for more details. *
- # * *
- # * You should have received a copy of the GNU Library General Public *
- # * License along with this program; if not, write to the Free Software *
- # * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
- # * USA *
- # * *
- # ***************************************************************************
- import FreeCAD
- import FreeCADGui
- import PathScripts.PathLog as PathLog
- import PathScripts.PathUtils as PathUtils
- from PathScripts.PathPreferences import PathPreferences
- from PySide import QtCore
- from pivy import coin
- PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
- PathLog.trackModule()
- # Qt tanslation handling
- def translate(context, text, disambig=None):
- return QtCore.QCoreApplication.translate(context, text, disambig)
- class HoldingTagMarker:
- def __init__(self, point, colors):
- self.point = point
- self.color = colors
- self.sep = coin.SoSeparator()
- self.pos = coin.SoTranslation()
- self.pos.translation = (point.x, point.y, point.z)
- self.sphere = coin.SoSphere()
- self.scale = coin.SoType.fromName('SoShapeScale').createInstance()
- self.scale.setPart('shape', self.sphere)
- self.scale.scaleFactor.setValue(7)
- self.material = coin.SoMaterial()
- self.sep.addChild(self.pos)
- self.sep.addChild(self.material)
- self.sep.addChild(self.scale)
- self.enabled = True
- self.selected = False
- def setSelected(self, select):
- self.selected = select
- self.sphere.radius = 1.5 if select else 1.0
- self.setEnabled(self.enabled)
- def setEnabled(self, enabled):
- self.enabled = enabled
- if enabled:
- self.material.diffuseColor = self.color[0] if not self.selected else self.color[2]
- self.material.transparency = 0.0
- else:
- self.material.diffuseColor = self.color[1] if not self.selected else self.color[2]
- self.material.transparency = 0.6
- class PathDressupTagViewProvider:
- def __init__(self, vobj):
- vobj.Proxy = self
- self.vobj = vobj
- self.panel = None
- def setupColors(self):
- def colorForColorValue(val):
- v = [((val >> n) & 0xff) / 255. for n in [24, 16, 8, 0]]
- return coin.SbColor(v[0], v[1], v[2])
- pref = PathPreferences.preferences()
- # R G B A
- npc = pref.GetUnsigned('DefaultPathMarkerColor', (( 85*256 + 255)*256 + 0)*256 + 255)
- hpc = pref.GetUnsigned('DefaultHighlightPathColor', ((255*256 + 125)*256 + 0)*256 + 255)
- dpc = pref.GetUnsigned('DefaultDisabledPathColor', ((205*256 + 205)*256 + 205)*256 + 154)
- self.colors = [colorForColorValue(npc), colorForColorValue(dpc), colorForColorValue(hpc)]
- def attach(self, vobj):
- self.setupColors()
- self.obj = vobj.Object
- self.tags = []
- self.switch = coin.SoSwitch()
- vobj.RootNode.addChild(self.switch)
- self.turnMarkerDisplayOn(False)
- def turnMarkerDisplayOn(self, display):
- sw = coin.SO_SWITCH_ALL if display else coin.SO_SWITCH_NONE
- self.switch.whichChild = sw
- def claimChildren(self):
- if self.obj and self.obj.Base:
- for i in self.obj.Base.InList:
- if hasattr(i, 'Group') and self.obj.Base.Name in [o.Name for o in i.Group]:
- i.Group = [o for o in i.Group if o.Name != self.obj.Base.Name]
- if self.obj.Base.ViewObject:
- PathLog.info("Setting visibility for %s" % (self.obj.Base.Name))
- self.obj.Base.ViewObject.Visibility = False
- else:
- PathLog.info("Ignoring visibility")
- if self.obj.Debug.ViewObject:
- self.obj.Debug.ViewObject.Visibility = False
- return [self.obj.Base, self.obj.Debug]
- return []
- def onDelete(self, arg1=None, arg2=None):
- '''this makes sure that the base operation is added back to the project and visible'''
- obj = FreeCADGui.ActiveDocument.getObject(arg1.Object.Base.Name)
- if obj:
- obj.Visibility = True
- PathUtils.addToJob(arg1.Object.Base)
- arg1.Object.Base = None
- return True
- def updateData(self, obj, propName):
- if 'Disabled' == propName:
- for tag in self.tags:
- self.switch.removeChild(tag.sep)
- tags = []
- for i, p in enumerate(obj.Positions):
- tag = HoldingTagMarker(p, self.colors)
- tag.setEnabled(not i in obj.Disabled)
- tags.append(tag)
- self.switch.addChild(tag.sep)
- self.tags = tags
- def selectTag(self, index):
- PathLog.track(index)
- for i, tag in enumerate(self.tags):
- tag.setSelected(i == index)
- def tagAtPoint(self, point):
- p = FreeCAD.Vector(point[0], point[1], point[2])
- for i, tag in enumerate(self.tags):
- if PathGeom.pointsCoincide(p, tag.point, tag.sphere.radius.getValue() * 1.1):
- return i
- return -1
- # SelectionObserver interface
- def allow(self, doc, obj, sub):
- if obj == self.obj:
- return True
- return False
- def addSelection(self, doc, obj, sub, point):
- i = self.tagAtPoint(point)
- if self.panel:
- self.panel.selectTagWithId(i)
- FreeCADGui.updateGui()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement