/[escript]/trunk/pycad/py_src/primitives.py
ViewVC logotype

Diff of /trunk/pycad/py_src/primitives.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 912 by gross, Wed Dec 6 03:29:49 2006 UTC revision 919 by gross, Wed Jan 3 22:54:50 2007 UTC
# Line 26  __version__="$Revision:$" Line 26  __version__="$Revision:$"
26  __date__="$Date:$"  __date__="$Date:$"
27    
28  import numarray  import numarray
29  from transformations import _TYPE  from transformations import _TYPE, Translation, Dilation, Transformation
30    
31  global global_primitive_id_counter  
32  global_primitive_id_counter=1  def resetGlobalPrimitiveIdCounter():
33       """
34       initializes the global primitive ID counter
35       """
36       global global_primitive_id_counter
37       global_primitive_id_counter=1
38    
39    def setToleranceForColocation(tol=1.e-11):
40       """
41       set the global tolerance for colocation checks to tol
42       """
43       global global_tolerance_for_colocation
44       global_tolerance_for_colocation=tol
45    
46    def getToleranceForColocation():
47       """
48       returns the global tolerance for colocation checks
49       """
50       return global_tolerance_for_colocation
51    
52    resetGlobalPrimitiveIdCounter()
53    setToleranceForColocation()
54    
55  class Primitive(object):  class Primitive(object):
56      """      """
# Line 37  class Primitive(object): Line 58  class Primitive(object):
58      """      """
59      def __init__(self):      def __init__(self):
60         """         """
61          
62         """         """
63         global global_primitive_id_counter         global global_primitive_id_counter
64         self.__ID=global_primitive_id_counter         self.__ID=global_primitive_id_counter
65         global_primitive_id_counter+=1         global_primitive_id_counter+=1
66    
67      def getID(self):      def getID(self):
68         return self.__ID         return self.__ID
69    
70      def __repr__(self):      def __repr__(self):
71         return "%s(%s)"%(self.__class__.__name__,self.getID())         return "%s(%s)"%(self.__class__.__name__,self.getID())
72      def __cmp__(self,other):      def __cmp__(self,other):
73         return cmp(self.getID(),other.getID())         return cmp(self.getID(),other.getID())
74      def getPoints(self):  
75        def getConstructionPoints(self):
76          """          """
77          returns the C{set} of points used to construct the primitive          returns the points used to construct the primitive
78          """          """
79          out=set()          out=set()
80          for i in self.getHistory():          for i in self.getPrimitives():
81             if isinstance(i,Point): out.add(i)             if isinstance(i,Point): out.add(i)
82          return out          return list(out)
83    
84      def setLocalScale(self,factor=1.):      def getPrimitives(self):
85          """          """
86          sets the local refinement factor          returns primitives used to construct the primitive
87          """          """
88          for p in self.getPoints(): p.setLocalScale(factor)          return []
89    
90      def isPoint(self):      def copy(self):
91          """         """
92          returns C{True} is the primitive is a L{Point}         returns a deep copy of the object
93          """         """
94          return False         return Primitive()
95      def isCurve(self):  
96    
97        def modifyBy(self,transformation):
98           """
99           modifies the coordinates by applying a transformation
100           """
101           for p in self.getConstructionPoints(): p.modifyBy(transformation)
102    
103    
104        def __add__(self,other):
105          """          """
106          returns C{True} is the primitive is a L{Curve}          returns a new object shifted by other
107          """          """
108          return False          return self.apply(Translation(numarray.array(other,_TYPE)))
109      def isSurface(self):  
110        def __sub__(self,other):
111          """          """
112          returns C{True} is the primitive is a L{Surface}          returns a new object shifted by other
113          """          """
114          return False          return self.apply(Translation(-numarray.array(other,_TYPE)))
115      def isCurveLoop(self):  
116        def __iadd__(self,other):
117          """          """
118          returns C{True} is the primitive is a L{CurveLoop}          shifts the point by other
119          """          """
120          return False          self.modifyBy(Translation(numarray.array(other,_TYPE)))
121      def isSurfaceLoop(self):          return self
122    
123        def __isub__(self,other):
124          """          """
125          returns C{True} is the primitive is a L{SurfaceLoop}          shifts the point by -other
126          """          """
127          return False          self.modifyBy(Translation(-numarray.array(other,_TYPE)))
128      def getHistory(self):          return self
129    
130        def __imul__(self,other):
131          """          """
132          returns C{set} of primitive used to construct the primitive          modifies object by applying L{Transformation} other. If other is not a L{Transformation} it will try convert it.
133          """          """
134          return set()          if isinstance(other,int) or isinstance(other,float):
135                        trafo=Dilation(other)
136            elif isinstance(other,numarray.NumArray):
137                trafo=Translation(other)
138            elif isinstance(other,Transformation):
139                trafo=other
140            else:
141                raise TypeError, "cannot convert argument to Trnsformation class object."
142            self.modifyBy(trafo)
143            return self
144    
145        def __rmul__(self,other):
146            """
147            applies L{Transformation} other to object. If other is not a L{Transformation} it will try convert it.
148            """
149            if isinstance(other,int) or isinstance(other,float):
150                trafo=Dilation(other)
151            elif isinstance(other,numarray.NumArray):
152                trafo=Translation(other)
153            elif isinstance(other,Transformation):
154                trafo=other
155            else:
156                raise TypeError, "cannot convert argument to Transformation class object."
157            return self.apply(trafo)
158    
     #==================================================  
159      def __neg__(self):      def __neg__(self):
160          return ReversedPrimitive(self)          return ReversedPrimitive(self)
161      def __pos__(self):  
162          return self.copy()      def setLocalScale(self,factor=1.):
163      def __add__(self,other):         """
164         out=self.copy()         sets the local refinement factor
165         out+=other         """
166         return out         for p in self.getConstructionPoints(): p.setLocalScale(factor)
167      def __iadd__(self,other):  
168         self.shift()      def getGmshCommand(self, local_scaling_factor=1.):
169      def shift(self,shift):          """
170          for p in self.getPoints(): p+=shift          returns the Gmsh command(s) to create the primitive
171      def copy(self):          """
         return Primitive()  
     def getGmshCommand(self):  
172          raise NotImplementedError("getGmshCommand is not implemented for this class %s."%self.__class__.__name__)          raise NotImplementedError("getGmshCommand is not implemented for this class %s."%self.__class__.__name__)
173      def translate(self,shift):  
174          raise NotImplementedError("translate is not implemented for this class %s."%self.__class__.__name__)      def apply(self,transformation):
175            """
176            returns a new object by applying the transformation
177            """
178            raise NotImplementedError("apply is not implemented for this class %s."%self.__class__.__name__)
179    
180        def isColocated(self,primitive):
181           """
182           returns True is the two primitives are located at the smae position
183           """
184           raise NotImplementedError("isColocated is not implemented for this class %s."%self.__class__.__name__)
185    
186  class Point(Primitive):  class Point(Primitive):
187      """      """
# Line 123  class Point(Primitive): Line 192  class Point(Primitive):
192         creates a point with coorinates x,y,z with the local refinement factor local_scale         creates a point with coorinates x,y,z with the local refinement factor local_scale
193         """         """
194         super(Point, self).__init__()         super(Point, self).__init__()
195         self.setCoordinates(x,y,z)         self.setCoordinates(numarray.array([x,y,z],_TYPE))
196         self.setLocalScale(local_scale)         self.setLocalScale(local_scale)
197    
198      def setLocalScale(self,factor=1.):      def setLocalScale(self,factor=1.):
199         """         """
200         sets the local refinement factor         sets the local refinement factor
# Line 142  class Point(Primitive): Line 212  class Point(Primitive):
212         returns the coodinates of the point as L{numarray.NumArray} object         returns the coodinates of the point as L{numarray.NumArray} object
213         """         """
214         return self._x         return self._x
215      def setCoordinates(self,x,y,z):      def setCoordinates(self,x):
216         """         """
217         returns the coodinates of the point as L{numarray.NumArray} object         returns the coodinates of the point as L{numarray.NumArray} object
218         """         """
219         self._x=numarray.array([x,y,z],_TYPE)         if not isinstance(x, numarray.NumArray):
220      def getHistory(self):            self._x=numarray.array(x,_TYPE)
221           else:
222              self._x=x
223    
224        def getPrimitives(self):
225         """         """
226         returns C{set} of primitive used to construct the primitive         returns primitives used to construct the primitive
227         """         """
228         return set([self])         return [self]
229    
230      def isColocated(self,point,tol=1.e-11):      def isColocated(self,primitive):
231         """         """
232         returns True if L{Point} point is colocation (same coordinates)         returns True if L{Point} primitive is colocation (same coordinates)
233         that means if |self-point| <= tol * max(|self|,|point|)         that means if |self-primitive| <= tol * max(|self|,|primitive|)
234         """         """
235         if isinstance(point,Point):         if isinstance(primitive,Point):
236            point=point.getCoordinates()            primitive=primitive.getCoordinates()
237         c=self.getCoordinates()            c=self.getCoordinates()
238         d=c-point            d=c-primitive
239         return numarray.dot(d,d)<=tol**2*max(numarray.dot(c,c),numarray.dot(point,point))            return numarray.dot(d,d)<=getToleranceForColocation()**2*max(numarray.dot(c,c),numarray.dot(primitive,primitive))
240               else:
241              return False
242    
     #=============================================================  
243      def copy(self):      def copy(self):
        c=self.getCoordinates()  
        return Point(c[0],c[1],c[2],local_scale=self.getLocalScale())  
     def isPoint(self):  
         return True  
     def getGmshCommand(self):  
         c=self.getCoordinates()  
         return "Point(%s) = {%e , %e, %e , %e * scale};"%(self.getID(),c[0],c[1],c[2], self.getLocalScale())  
     def shift(self,shift):  
        """  
        shifts the point by a given shift  
244         """         """
245         self._x+=numarray.array(shift,numarray.Float64)         returns a deep copy of the point
     def translate(self,shift):  
246         """         """
247         returns the point shifted by shift         c=self.getCoordinates()
248         """         return Point(c[0],c[1],c[2],local_scale=self.getLocalScale())
249         out=self.copy()  
250         out+=other      def modifyBy(self,transformation):
251         return out          """
252            modifies the coordinates by applying a transformation
253            """
254            self.setCoordinates(transformation(self.getCoordinates()))
255    
256        def apply(self,transformation):
257            """
258            returns a new L{Point} by applying the transformation
259            """
260            new_p=self.copy()
261            new_p.modifyBy(transformation)
262            return new_p
263    
264        def getGmshCommand(self, local_scaling_factor=1.):
265            """
266            returns the Gmsh command(s) to create the primitive
267            """
268            c=self.getCoordinates()
269            return "Point(%s) = {%s , %s, %s , %s };"%(self.getID(),c[0],c[1],c[2], self.getLocalScale()*local_scaling_factor)
270    
271  class Curve(Primitive):  class Primitive1D(Primitive):
272        """        """
273        a curve        general one-dimensional primitive
274        """        """
275        def __init__(self,*args):        def __init__(self,*args):
276            """            """
277            defines a curve form a set of control points            create a one-dimensional primitive
278            """            """
279              super(Primitive1D, self).__init__()
280          
281    class Curve(Primitive1D):
282        """
283        a curve defined through a list of control points.
284        """
285        def __init__(self,*points):
286              """
287              defines a curve form control points
288              """
289              if len(points)<2:
290                 raise TypeError("Curve needs at least two points")
291            super(Curve, self).__init__()            super(Curve, self).__init__()
292            l=len(args)            i=0
293            for i in range(l):            for p in points:
294                if not args[i].isPoint():                i+=1
295                   raise TypeError("%s-th argument is not a Point object."%i)                if not isinstance(p,Point): raise TypeError("%s-th argument is not a Point object."%i)
296            self.__nodes=args            self.__points=points
297        def __len__(self):  
298            return len(self.__nodes)      def __len__(self):
299        def isCurve(self):            """
300          return True            returns the number of control points
301        def getStart(self):            """
302              return len(self.__points)
303    
304        def getStartPoint(self):
305           """           """
306           returns start point           returns start point
307           """           """
308           return self.__nodes[0]           return self.__points[0]
309    
310        def getEnd(self):      def getEndPoint(self):
311           """           """
312           returns end point           returns end point
313           """           """
314           return self.__nodes[-1]           return self.__points[-1]
315    
316        def getNodes(self):      def getControlPoints(self):
317           """           """
318           returns a list of the nodes           returns a list of the points
319           """           """
320           return self.__nodes           return self.__points
321        def getGmshCommand(self):  
322        def getPrimitives(self):
323           """
324           returns primitives used to construct the Curve
325           """
326           out=set()
327           for p in self.getControlPoints(): out|=set(p.getPrimitives())
328           out.add(self)
329           return list(out)
330    
331        def copy(self):
332           """
333           returns a deep copy
334           """
335           new_p=[]
336           for p in self.getControlPoints(): new_p.append(p.copy())
337           return self.__class__(*tuple(new_p))
338    
339    
340        def apply(self,transformation):
341            """
342            applies transformation
343            """
344            new_p=[]
345            for p in self.getControlPoints(): new_p.append(p.apply(transformation))
346            return self.__class__(*tuple(new_p))
347    
348        def isColocated(self,primitive):
349           """
350           returns True curves are on the same position
351           """
352           if isinstance(primitive,self.__class__):
353              if len(primitive) == len(self):
354                 cp0=self.getControlPoints()
355                 cp1=primitive.getControlPoints()
356                 match=True
357                 for i in range(len(cp0)):
358                    if not cp0[i].isColocated(cp1[i]):
359                       match=False
360                       break
361                 if not match:
362                    for i in range(len(cp0)):
363                       if not cp0[i].isColocated(cp1[len(cp0)-1-i]):
364                          return False
365                 return True
366              else:
367                 return False
368           else:
369              return False
370    
371    class Spline(Curve):
372        """
373        a spline curve defined through a list of control points.
374        """
375        def getGmshCommand(self):
376            """
377            returns the Gmsh command(s) to create the Curve
378            """
379          out=""          out=""
380          for i in self.getNodes():          for i in self.getControlPoints():
381              if len(out)>0:              if len(out)>0:
382                  out+=", %s"%i.getID()                  out+=", %s"%i.getID()
383              else:              else:
384                  out="%s"%i.getID()                  out="%s"%i.getID()
385          return "Spline(%s) = {%s};"%(self.getID(),out)          return "Spline(%s) = {%s};"%(self.getID(),out)
386        def getHistory(self):      
           out=set([self])  
           for i in self.getNodes(): out|=i.getHistory()  
           return out  
       def getPoints(self):  
         out=set()  
         for i in self.getNodes(): out|=i.getPoints()  
         return out  
   
387    
388  class BezierCurve(Curve):  class BezierCurve(Curve):
389      """      """
390      a Bezier curve      a Bezier curve
391      """      """
     def __neg__(self):  
          """  
          returns the line segment with swapped start and end points  
          """  
          return BezierCurve(self.getNodes()[::-1])  
     def __add__(self,other):  
          return BezierCurve([p+other for p in self.getNodes()])  
392      def getGmshCommand(self):      def getGmshCommand(self):
393            """
394            returns the Gmsh command(s) to create the Curve
395            """
396          out=""          out=""
397          for i in self.getNodes():          for i in self.getControlPoints():
398              if len(out)>0:              if len(out)>0:
399                  out+=", %s"%i.getID()                  out+=", %s"%i.getID()
400              else:              else:
401                  out="%s"%i.getID()                  out="%s"%i.getID()
402          return "Bezier(%s) = {%s};"%(self.getID(),out)          return "Bezier(%s) = {%s};"%(self.getID(),out)
403    
404  class BSplineCurve(Curve):  class BSpline(Curve):
405      """      """
406      a BSpline curve. Control points may be repeated.      a BSpline curve. Control points may be repeated.
407      """      """
     def __neg__(self):  
          """  
          returns the line segment with swapped start and end points  
          """  
          return BSplineCurve(self.getNodes()[::-1])  
     def __add__(self,other):  
          return BSplineCurve([p+other for p in self.getNodes()])  
408      def getGmshCommand(self):      def getGmshCommand(self):
409            """
410            returns the Gmsh command(s) to create the Curve
411            """
412          out=""          out=""
413          for i in self.getNodes():          for i in self.getControlPoints():
414              if len(out)>0:              if len(out)>0:
415                  out+=", %s"%i.getID()                  out+=", %s"%i.getID()
416              else:              else:
# Line 285  class Line(Curve): Line 421  class Line(Curve):
421      """      """
422      a line is defined by two L{Point}s      a line is defined by two L{Point}s
423      """      """
424      def __init__(self,start,end):      def __init__(self,*points):
425          """          """
426          defines a curve form a set of control points          defines a line with start and end point
427          """          """
428          super(Line, self).__init__(start,end)          if len(points)!=2:
429      def __neg__(self):             raise TypeError("Line needs two points")
430         return ReversedPrimitive(self)          super(Line, self).__init__(*points)
     def __add__(self,other):  
        return Line(self.getEnd()+other,self.getStart()+other)  
431      def getGmshCommand(self):      def getGmshCommand(self):
432          return "Line(%s) = {%s, %s};"%(self.getID(),self.getStart().getID(),self.getEnd().getID())          """
433            returns the Gmsh command(s) to create the Curve
434            """
435            return "Line(%s) = {%s, %s};"%(self.getID(),self.getStartPoint().getID(),self.getEndPoint().getID())
436    
437  class Arc(Curve):  
438    class Arc(Primitive1D):
439      """      """
440      defines an arc      defines an arc which is strictly, smaller than Pi
441      """      """
442      def __init__(self,center,start,end):      def __init__(self,center,start,end):
443         """         """
444         creates an arc by the start point, end point and center         creates an arc by the start point, end point and center
445         """         """
446         if center.isPoint():         if not isinstance(center,Point): raise TypeError("center needs to be a Point object.")
447             raise TypeError("center needs to be a Point object.")         if not isinstance(end,Point): raise TypeError("end needs to be a Point object.")
448         super(Arc, self).__init__(start,end)         if not isinstance(start,Point): raise TypeError("start needs to be a Point object.")
449           # TODO: check length of circle.
450           super(Arc, self).__init__()
451         self.__center=center         self.__center=center
452           self.__start=start
453           self.__end=end
454    
455        def getStartPoint(self):
456           """
457           returns start point
458           """
459           return self.__start
460    
461        def getEndPoint(self):
462           """
463           returns end point
464           """
465           return self.__end
466    
467      def getCenter(self):      def getCenterPoint(self):
468         """         """
469         returns center         returns center
470         """         """
471         return self.__center         return self.__center
     def __add__(self,other):  
        return Arc(self.getCenter()+other,self.getStart()+other,self.getEnd()+other)  
472    
473      def getHistory(self):      def getPrimitives(self):
474            out=set([self])         """
475            out|=self.getCenter().getHistory()         returns the primitives used to construct the Curve
476            for i in self.getNodes(): out|=i.getHistory()         """
477            return out         out=set()
478      def getPoints(self):         out|=set(self.getStartPoint().getPrimitives())
479            out=self.getCenter().getPoints()         out|=set(self.getEndPoint().getPrimitives())
480            for i in self.getNodes(): out|=i.getPoints()         out|=set(self.getCenterPoint().getPrimitives())
481            return out         out.add(self)
482           return list(out)
483    
484      def getGmshCommand(self):      def getGmshCommand(self):
485          return "Circle(%s) = {%s, %s, %s};"%(self.getID(),self.getStart().getID(),self.getCenter().getID(),self.getEnd().getID())         """
486           returns the Gmsh command(s) to create the primitive
487           """
488           return "Circle(%s) = {%s, %s, %s};"%(self.getID(),self.getStartPoint().getID(),self.getCenterPoint().getID(),self.getEndPoint().getID())
489    
490  class CurveLoop(Primitive):      def copy(self):
491           """
492           returns a deep copy
493           """
494           return Arc(self.getCenterPoint().copy(),self.getStartPoint().copy(),self.getEndPoint().copy())
495    
496        def apply(self,transformation):
497            """
498            applies transformation
499            """
500            return Arc(self.getCenterPoint().apply(transformation),self.getStartPoint().apply(transformation),self.getEndPoint().apply(transformation))
501    
502        def isColocated(self,primitive):
503           """
504           returns True curves are on the same position
505           """
506           if isinstance(primitive,Arc):
507                return (self.getCenterPoint().isColocated(primitive.getCenterPoint())) and ( \
508                       (self.getEndPoint().isColocated(primitive.getEndPoint()) and self.getStartPoint().isColocated(primitive.getStartPoint()) ) \
509                    or (self.getEndPoint().isColocated(primitive.getStartPoint()) and self.getStartPoint().isColocated(primitive.getEndPoint()) ) )
510           else:
511              return False
512    
513    class Primitive2D(Primitive):
514          """
515          general two-dimensional primitive
516          """
517          def __init__(self,*args):
518              """
519              create a two-dimensional primitive
520              """
521              super(Primitive2D, self).__init__()
522    class CurveLoop(Primitive2D):
523      """      """
524      An oriented loop of curves.      An oriented loop of curves.
525    
# Line 344  class CurveLoop(Primitive): Line 533  class CurveLoop(Primitive):
533         self.__curves=[]         self.__curves=[]
534         self.addCurve(*curves)         self.addCurve(*curves)
535      def addCurve(self,*curves):      def addCurve(self,*curves):
536           """
537           adds curves to the curves defining the object
538           """
539         for i in range(len(curves)):         for i in range(len(curves)):
540             if not curves[i].isCurve():             if not isinstance(curves[i],Primitive1D):
541                raise TypeError("%s-th argument is not a Curve object."%i)                raise TypeError("%s-th argument is not a Primitive1D object."%i)
542         self.__curves+=curves         self.__curves+=curves
543    
     def isCurveLoop(self):  
         return True  
544      def getCurves(self):      def getCurves(self):
545           """
546           returns the curves defining the CurveLoop
547           """
548         return self.__curves         return self.__curves
     def __add__(self,other):  
        return CurveLoop(*tuple([c+other for c in self.getCurves()[::-1]]))  
549      def __len__(self):      def __len__(self):
550           """
551           return the number of curves in the CurveLoop
552           """
553         return len(self.__curves)         return len(self.__curves)
554      def getHistory(self):  
555            out=set([self])      def getPrimitives(self):
556            for i in self.getCurves(): out|=i.getHistory()         """
557            return out         returns primitives used to construct the CurveLoop
558      def getPoints(self):         """
559            out=set()         out=set()
560            for i in self.getCurves(): out|=i.getPoints()         for c in self.getCurves(): out|=set(c.getPrimitives())
561            return out         out.add(self)
562           return list(out)
563    
564        def copy(self):
565           """
566           returns a deep copy
567           """
568           new_c=[]
569           for c in self.getCurves(): new_c.append(c.copy())
570           return CurveLoop(*tuple(new_c))
571    
572    
573        def apply(self,transformation):
574            """
575            applies transformation
576            """
577            new_c=[]
578            for c in self.getCurves(): new_c.append(c.apply(transformation))
579            return CurveLoop(*tuple(new_c))
580    
581        def isColocated(self,primitive):
582           """
583           returns True if each curve is collocted with a curve in primitive
584           """
585           if isinstance(primitive,CurveLoop):
586              if len(primitive) == len(self):
587                 cp0=self.getCurves()
588                 cp1=primitive.getCurves()
589                 for c0 in cp0:
590                     collocated = False
591                     for c1 in cp1: collocated = collocated or c0.isColocated(c1)
592                     if not collocated: return False
593                 return True
594              else:
595                 return False
596           else:
597              return False
598    
599      def getGmshCommand(self):      def getGmshCommand(self):
600          out=""          out=""
601          for i in self.getCurves():          for i in self.getCurves():
# Line 374  class CurveLoop(Primitive): Line 605  class CurveLoop(Primitive):
605                  out="%s"%i.getID()                  out="%s"%i.getID()
606          return "Line Loop(%s) = {%s};"%(self.getID(),out)          return "Line Loop(%s) = {%s};"%(self.getID(),out)
607    
608    #=================================================================================================================================
609  class Surface(Primitive):  class Surface(Primitive):
610      """      """
611      a surface      a surface
# Line 394  class Surface(Primitive): Line 626  class Surface(Primitive):
626         return self.__loop         return self.__loop
627      def __add__(self,other):      def __add__(self,other):
628         return Surface(self.getBoundaryLoop()+other)         return Surface(self.getBoundaryLoop()+other)
629      def getHistory(self):      def getPrimitives(self):
630          out=set([self]) | self.getBoundaryLoop().getHistory()          out=set([self]) | self.getBoundaryLoop().getPrimitives()
631          return out          return out
632      def getPoints(self):      def getConstructionPoints(self):
633          return self.getBoundaryLoop().getPoints()          return self.getBoundaryLoop().getConstructionPoints()
634      def getGmshCommand(self):      def getGmshCommand(self):
635          return "Ruled Surface(%s) = {%s};"%(self.getID(),self.getBoundaryLoop().getID())          return "Ruled Surface(%s) = {%s};"%(self.getID(),self.getBoundaryLoop().getID())
636    
# Line 424  class PlaneSurface(Surface): Line 656  class PlaneSurface(Surface):
656         return self.__holes         return self.__holes
657      def __add__(self,other):      def __add__(self,other):
658         return PlaneSurface(self.getBoundaryLoop()+other, holes=[h+other for h in self.getHoles()])         return PlaneSurface(self.getBoundaryLoop()+other, holes=[h+other for h in self.getHoles()])
659      def getHistory(self):      def getPrimitives(self):
660          out=set([self]) | self.getBoundaryLoop().getHistory()          out=set([self]) | self.getBoundaryLoop().getPrimitives()
661          for i in self.getHoles(): out|=i.getHistory()          for i in self.getHoles(): out|=i.getPrimitives()
662          return out          return out
663      def getPoints(self):      def getConstructionPoints(self):
664          out=self.getBoundaryLoop().getPoints()          out=self.getBoundaryLoop().getConstructionPoints()
665          for i in self.getHoles(): out|=i.getPoints()          for i in self.getHoles(): out|=i.getConstructionPoints()
666          return out          return out
667      def getGmshCommand(self):      def getGmshCommand(self):
668          out=""          out=""
# Line 491  class SurfaceLoop(Primitive): Line 723  class SurfaceLoop(Primitive):
723         return SurfaceLoop([c+other for c in self.getSurfaces])         return SurfaceLoop([c+other for c in self.getSurfaces])
724      def __len__(self):      def __len__(self):
725         return len(self.__surfaces)         return len(self.__surfaces)
726      def getHistory(self):      def getPrimitives(self):
727            out=set([self])            out=set([self])
728            for i in self.getSurfaces(): out|=i.getHistory()            for i in self.getSurfaces(): out|=i.getPrimitives()
729            return out            return out
730      def getPoints(self):      def getConstructionPoints(self):
731            out=set()            out=set()
732            for i in self.getSurfaces(): out|=i.getPoints()            for i in self.getSurfaces(): out|=i.getConstructionPoints()
733            return out            return out
734      def getGmshCommand(self):      def getGmshCommand(self):
735          out=""          out=""
# Line 535  class Volume(Primitive): Line 767  class Volume(Primitive):
767         return self.__loop         return self.__loop
768      def __add__(self,other):      def __add__(self,other):
769         return Volume(self.getSurfaceLoop()+other, holes=[h+other for h in self.getHoles()])         return Volume(self.getSurfaceLoop()+other, holes=[h+other for h in self.getHoles()])
770      def getHistory(self):      def getPrimitives(self):
771          out=set([self]) | self.getSurfaceLoop().getHistory()          out=set([self]) | self.getSurfaceLoop().getPrimitives()
772          for i in self.getHoles(): out|=i.getHistory()          for i in self.getHoles(): out|=i.getPrimitives()
773          return out          return out
774      def getPoints(self):      def getConstructionPoints(self):
775          out=self.getSurfaceLoop().getPoints()          out=self.getSurfaceLoop().getConstructionPoints()
776          for i in self.getHoles(): out|=i.Points()          for i in self.getHoles(): out|=i.Points()
777          return out          return out
778      def getGmshCommand(self):      def getGmshCommand(self):
# Line 574  class PropertySet(Primitive): Line 806  class PropertySet(Primitive):
806         super(PropertySet, self).__init__()         super(PropertySet, self).__init__()
807         self.__items=items         self.__items=items
808         self.__tag=tag         self.__tag=tag
809      def getHistory(self):      def getPrimitives(self):
810          out=set([self, self.getBoundaryLoop().getHistory()])          out=set([self, self.getBoundaryLoop().getPrimitives()])
811          for i in self.getHoles(): out|=i.getHistory()          for i in self.getHoles(): out|=i.getPrimitives()
812          return out          return out
813    
814  class PrimitiveStack(object):  class PrimitiveStack(object):
815        def __init__(self,*items):        def __init__(self,*items):
816          self.__prims=set()          self.__prims=set()
817          for i in items:          for i in items:
818              self.__prims|=i.getHistory()              self.__prims|=i.getPrimitives()
819          self.__prims=list(self.__prims)          self.__prims=list(self.__prims)
820          self.__prims.sort()          self.__prims.sort()
821    

Legend:
Removed from v.912  
changed lines
  Added in v.919

  ViewVC Help
Powered by ViewVC 1.1.26