11"""
2- Copyright (C) 2011-2013 Parametric Products Intellectual Holdings, LLC
3-
4- This file is part of CadQuery.
5-
6- CadQuery is free software; you can redistribute it and/or
7- modify it under the terms of the GNU Lesser General Public
8- License as published by the Free Software Foundation; either
9- version 2.1 of the License, or (at your option) any later version.
10-
11- CadQuery is distributed in the hope that it will be useful,
12- but WITHOUT ANY WARRANTY; without even the implied warranty of
13- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14- Lesser General Public License for more details.
15-
16- You should have received a copy of the GNU Lesser General Public
17- License along with this library; If not, see <http://www.gnu.org/licenses/>
2+ Copyright (C) 2011-2013 Parametric Products Intellectual Holdings, LLC
3+
4+ This file is part of CadQuery.
5+
6+ CadQuery is free software; you can redistribute it and/or
7+ modify it under the terms of the GNU Lesser General Public
8+ License as published by the Free Software Foundation; either
9+ version 2.1 of the License, or (at your option) any later version.
10+
11+ CadQuery is distributed in the hope that it will be useful,
12+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+ Lesser General Public License for more details.
15+
16+ You should have received a copy of the GNU Lesser General Public
17+ License along with this library; If not, see <http://www.gnu.org/licenses/>
1818"""
1919
2020import math ,sys
@@ -48,33 +48,6 @@ def sortWiresByBuildOrder(wireList,plane,result=[]):
4848
4949 return result
5050
51- def sortWiresByBuildOrderOld (wireList ,plane ,result = []):
52- """
53- Tries to determine how wires should be combined into faces.
54- Assume:
55- The wires make up one or more faces, which could have 'holes'
56- Outer wires are listed ahead of inner wires
57- there are no wires inside wires inside wires ( IE, islands -- we can deal with that later on )
58- none of the wires are construction wires
59- Compute:
60- one or more sets of wires, with the outer wire listed first, and inner ones
61- Returns, list of lists.
62- """
63- outerWire = wireList .pop (0 )
64-
65- remainingWires = list (wireList )
66- childWires = []
67- for w in wireList :
68- if plane .isWireInside (outerWire ,w ):
69- childWires .append (remainingWires .pop (0 ))
70- else :
71- #doesnt match, assume this wire is a new outer
72- result .append ([outerWire ] + childWires )
73- return sortWiresByBuildOrder (remainingWires ,plane ,result )
74-
75- result .append ([outerWire ] + childWires )
76- return result
77-
7851class Vector (object ):
7952 """
8053 Create a 3-dimensional vector
@@ -212,6 +185,25 @@ def __ge__(self,other):
212185 def __eq__ (self ,other ):
213186 return self .wrapped .__eq__ (other )
214187
188+ class Matrix :
189+ """
190+ A 3d , 4x4 transformation matrix.
191+
192+ Used to move geometry in space.
193+ """
194+ def __init__ (self ,matrix = None ):
195+ if matrix == None :
196+ self .wrapped = FreeCAD .Base .Matrix ()
197+ else :
198+ self .wrapped = matrix
199+
200+ def rotateX (self ,angle ):
201+ self .wrapped .rotateX (angle )
202+
203+ def rotateY (self ,angle ):
204+ self .wrapped .rotateY (angle )
205+
206+
215207class Plane :
216208 """
217209 A 2d coordinate system in space, with the x-y axes on the a plane, and a particular point as the origin.
@@ -329,6 +321,7 @@ def __init__(self, origin, xDir, normal ):
329321
330322 self .setOrigin3d (origin )
331323
324+
332325 def setOrigin3d (self ,originVector ):
333326 """
334327 Move the origin of the plane, leaving its orientation and xDirection unchanged.
@@ -417,6 +410,7 @@ def toLocalCoords(self,obj):
417410 else :
418411 raise ValueError ("Dont know how to convert type %s to local coordinates" % str (type (obj )))
419412
413+
420414 def toWorldCoords (self , tuplePoint ):
421415 """
422416 Convert a point in local coordinates to global coordinates.
@@ -433,6 +427,7 @@ def toWorldCoords(self, tuplePoint):
433427 v = Vector (tuplePoint [0 ],tuplePoint [1 ],tuplePoint [2 ])
434428 return Vector (self .rG .multiply (v .wrapped ))
435429
430+
436431 def rotated (self ,rotate = Vector (0 ,0 ,0 )):
437432 """
438433 returns a copy of this plane, rotated about the specified axes, as measured from horizontal
@@ -453,7 +448,7 @@ def rotated(self,rotate=Vector(0,0,0)):
453448 rotate = rotate .multiply (math .pi / 180.0 )
454449
455450 #compute rotation matrix
456- m = Base .Matrix ()
451+ m = FreeCAD . Base .Matrix ()
457452 m .rotateX (rotate .x )
458453 m .rotateY (rotate .y )
459454 m .rotateZ (rotate .z )
@@ -473,7 +468,7 @@ def _calcTransforms(self):
473468 #ok i will be really honest-- i cannot understand exactly why this works
474469 #something bout the order of the transaltion and the rotation.
475470 # the double-inverting is strange, and i dont understand it.
476- r = Base .Matrix ()
471+ r = FreeCAD . Base .Matrix ()
477472
478473 #forward transform must rotate and adjust for origin
479474 (r .A11 , r .A12 , r .A13 ) = (self .xDir .x , self .xDir .y , self .xDir .z )
@@ -484,7 +479,14 @@ def _calcTransforms(self):
484479 (invR .A14 ,invR .A24 ,invR .A34 ) = (self .origin .x ,self .origin .y ,self .origin .z )
485480
486481 ( self .rG ,self .fG ) = ( invR ,invR .inverse () )
487-
482+
483+ def computeTransform (self ,tMatrix ):
484+ """
485+ Computes the 2-d projection of the supplied matrix
486+ """
487+
488+ rm = self .fG .multiply (tMatrix .wrapped ).multiply (self .rG )
489+ return Matrix (rm )
488490
489491class BoundBox (object ):
490492 "A BoundingBox for an object or set of objects. Wraps the FreeCAD one"
0 commit comments