CollisionObject.py
1 # -*- coding: utf-8 -*-
2 
3 # ***************************************************************************
4 # * *
5 # * Animate workbench - FreeCAD Workbench for lightweight animation *
6 # * Copyright (c) 2019 Jiří Valášek jirka362@gmail.com *
7 # * *
8 # * This file is part of the Animate workbench. *
9 # * *
10 # * This program is free software; you can redistribute it and/or modify *
11 # * it under the terms of the GNU Lesser General Public License (LGPL) *
12 # * as published by the Free Software Foundation; either version 2 of *
13 # * the License, or (at your option) any later version. *
14 # * for detail see the LICENCE text file. *
15 # * *
16 # * Animate workbench is distributed in the hope that it will be useful, *
17 # * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 # * GNU Lesser General Public License for more details. *
20 # * *
21 # * You should have received a copy of the GNU Library General Public *
22 # * License along with Animate workbench; if not, write to the Free *
23 # * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
24 # * MA 02111-1307 USA *
25 # * *
26 # ***************************************************************************/
27 
28 
34 
35 import FreeCAD
36 
37 from os import path
38 
39 
40 PATH_TO_ICONS = path.join(FreeCAD.getHomePath(), "Mod", "Animate", "Resources",
41  "Icons")
42 
43 
44 
54 
55 class CollisionProxy(object):
56 
57 
70 
71  def __init__(self, fp, shape=None, cause1=None, cause2=None):
72  if shape is not None:
73  fp.Shape = shape
74  if cause1 is not None and cause2 is not None:
75  fp.Label = cause1.Label + " x " + cause2.Label
76  self.setProperties(fp, cause1=cause1, cause2=cause2)
77  fp.Proxy = self
78 
79 
88 
89  def onDocumentRestored(self, fp):
90  self.setProperties(fp)
91  fp.ViewObject.Proxy.setProperties(
92  fp.ViewObject)
93 
94 
103 
104  def setProperties(self, fp, cause1=None, cause2=None):
105  if not hasattr(fp, "CausedBy"):
106  fp.addProperty(
107  "App::PropertyLinkList", "CausedBy", "Collision",
108  "Objects that made this collision").CausedBy = [cause1, cause2]
109  if not hasattr(fp, "Volume"):
110  fp.addProperty(
111  "App::PropertyVolume", "Volume", "Collision",
112  "Overlapping volume of interfering objects."
113  ).Volume = fp.Shape.Volume
114 
115  fp.setEditorMode("Placement", 1)
116  fp.setEditorMode("CausedBy", 1)
117  fp.setEditorMode("Volume", 1)
118  fp.setEditorMode("Label", 1)
119 
120  # Add ViewObject to __dict__ so that it can be accessed using
121  # __getattribute__
122  fp.__dict__["ViewObject"] = fp.ViewObject
123 
124 
125 
139 
141 
142 
153 
154  def __init__(self, vp, color=None):
155  if color is None:
156  color = (1.0, 0.0, 0.0)
157  vp.LineColor = vp.PointColor = vp.ShapeColor = color
158  vp.LineWidth = 10.0
159  vp.PointSize = 10.0
160  self.setProperties(vp)
161  vp.Proxy = self
162 
163 
175 
176  def doubleClicked(self, vp):
177  return True
178 
179 
189 
190  def setupContextMenu(self, vp, menu):
191  menu.clear()
192 
193 
198 
199  def getIcon(self):
200  return path.join(PATH_TO_ICONS, "Collision.png")
201 
202 
210 
211  def setProperties(self, vp):
212  vp.setEditorMode("AngularDeflection", 2)
213  vp.setEditorMode("BoundingBox", 2)
214  vp.setEditorMode("Deviation", 2)
215  vp.setEditorMode("DisplayMode", 2)
216  vp.setEditorMode("DrawStyle", 2)
217  vp.setEditorMode("Lighting", 2)
218  vp.setEditorMode("LineColor", 2)
219  vp.setEditorMode("LineWidth", 2)
220  vp.setEditorMode("PointColor", 2)
221  vp.setEditorMode("PointSize", 2)
222  vp.setEditorMode("Selectable", 2)
223  vp.setEditorMode("SelectionStyle", 2)
224  vp.setEditorMode("ShapeColor", 2)
def onDocumentRestored(self, fp)
Method called when document is restored to make sure everything is as it was.
def doubleClicked(self, vp)
Method called when CollisionDetector is double-clicked in the Tree View.
def __init__(self, vp, color=None)
Initialization method for ViewProviderCollisionProxy.
Proxy class for a FeaturePython Collision instance.
def __init__(self, fp, shape=None, cause1=None, cause2=None)
Initialization method for CollisionProxy.
Proxy class for a Gui.ViewProviderDocumentObject Collision.ViewObject.
def setupContextMenu(self, vp, menu)
Method editing a context menu for right click on a Collision.
def setProperties(self, vp)
Method to hide unused properties.
def setProperties(self, fp, cause1=None, cause2=None)
Method to set properties during initialization or document restoration.
def getIcon(self)
Method used to get a path to an icon which will appear in the tree view.