/[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 925 by gross, Wed Jan 10 22:40:00 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    
73      def __cmp__(self,other):      def __cmp__(self,other):
74         return cmp(self.getID(),other.getID())         return cmp(self.getID(),other.getID())
75      def getPoints(self):  
76        def getConstructionPoints(self):
77          """          """
78          returns the C{set} of points used to construct the primitive          returns the points used to construct the primitive
79          """          """
80          out=set()          out=set()
81          for i in self.getHistory():          for i in self.getPrimitives():
82             if isinstance(i,Point): out.add(i)             if isinstance(i,Point): out.add(i)
83          return out          return list(out)
84    
85      def setLocalScale(self,factor=1.):      def getPrimitives(self):
86          """          """
87          sets the local refinement factor          returns primitives used to construct the primitive
88          """          """
89          for p in self.getPoints(): p.setLocalScale(factor)          return []
90    
91      def isPoint(self):      def copy(self):
92          """         """
93          returns C{True} is the primitive is a L{Point}         returns a deep copy of the object
94          """         """
95          return False         return self.substitute({})
96      def isCurve(self):  
97    
98        def modifyBy(self,transformation):
99           """
100           modifies the coordinates by applying a transformation
101           """
102           for p in self.getConstructionPoints(): p.modifyBy(transformation)
103    
104    
105        def __add__(self,other):
106          """          """
107          returns C{True} is the primitive is a L{Curve}          returns a new object shifted by other
108          """          """
109          return False          return self.apply(Translation(numarray.array(other,_TYPE)))
110      def isSurface(self):  
111        def __sub__(self,other):
112          """          """
113          returns C{True} is the primitive is a L{Surface}          returns a new object shifted by other
114          """          """
115          return False          return self.apply(Translation(-numarray.array(other,_TYPE)))
116      def isCurveLoop(self):  
117        def __iadd__(self,other):
118          """          """
119          returns C{True} is the primitive is a L{CurveLoop}          shifts the point by other
120          """          """
121          return False          self.modifyBy(Translation(numarray.array(other,_TYPE)))
122      def isSurfaceLoop(self):          return self
123    
124        def __isub__(self,other):
125          """          """
126          returns C{True} is the primitive is a L{SurfaceLoop}          shifts the point by -other
127          """          """
128          return False          self.modifyBy(Translation(-numarray.array(other,_TYPE)))
129      def getHistory(self):          return self
130    
131        def __imul__(self,other):
132          """          """
133          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.
134          """          """
135          return set()          if isinstance(other,int) or isinstance(other,float):
136                        trafo=Dilation(other)
137            elif isinstance(other,numarray.NumArray):
138                trafo=Translation(other)
139            elif isinstance(other,Transformation):
140                trafo=other
141            else:
142                raise TypeError, "cannot convert argument to Trnsformation class object."
143            self.modifyBy(trafo)
144            return self
145    
146        def __rmul__(self,other):
147            """
148            applies L{Transformation} other to object. If other is not a L{Transformation} it will try convert it.
149            """
150            if isinstance(other,int) or isinstance(other,float):
151                trafo=Dilation(other)
152            elif isinstance(other,numarray.NumArray):
153                trafo=Translation(other)
154            elif isinstance(other,Transformation):
155                trafo=other
156            else:
157                raise TypeError, "cannot convert argument to Transformation class object."
158            return self.apply(trafo)
159    
     #==================================================  
160      def __neg__(self):      def __neg__(self):
161          return ReversedPrimitive(self)          return ReversedPrimitive(self)
162      def __pos__(self):  
163          return self.copy()      def setLocalScale(self,factor=1.):
164      def __add__(self,other):         """
165         out=self.copy()         sets the local refinement factor
166         out+=other         """
167         return out         for p in self.getConstructionPoints(): p.setLocalScale(factor)
168      def __iadd__(self,other):  
169         self.shift()      def getGmshCommand(self, local_scaling_factor=1.):
170      def shift(self,shift):          """
171          for p in self.getPoints(): p+=shift          returns the Gmsh command(s) to create the primitive
172      def copy(self):          """
         return Primitive()  
     def getGmshCommand(self):  
173          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__)
174      def translate(self,shift):  
175          raise NotImplementedError("translate is not implemented for this class %s."%self.__class__.__name__)      def apply(self,transformation):
176            """
177            returns a new L{Point} by applying the transformation
178            """
179            out=self.copy()
180            out.modifyBy(transformation)
181            return out
182    
183        def isColocated(self,primitive):
184           """
185           returns True is the two primitives are located at the smae position
186           """
187           raise NotImplementedError("isColocated is not implemented for this class %s."%self.__class__.__name__)
188    
189        def substitute(self,sub_dict):
190            """
191            returns a copy of self with substitutes for the primitives used to construct it given by the dictionary C{sub_dict}.
192            If a substitute for the object is given by C{sub_dict} the value is returned, otherwise a new instance
193            with substituted arguments is returned.
194            """
195            if not sub_dict.has_key(self):
196               sub_dict[self]=self.__class__()
197            return sub_dict[self]
198    
199  class Point(Primitive):  class Point(Primitive):
200      """      """
# Line 123  class Point(Primitive): Line 205  class Point(Primitive):
205         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
206         """         """
207         super(Point, self).__init__()         super(Point, self).__init__()
208         self.setCoordinates(x,y,z)         self.setCoordinates(numarray.array([x,y,z],_TYPE))
209         self.setLocalScale(local_scale)         self.setLocalScale(local_scale)
210    
211      def setLocalScale(self,factor=1.):      def setLocalScale(self,factor=1.):
212         """         """
213         sets the local refinement factor         sets the local refinement factor
# Line 142  class Point(Primitive): Line 225  class Point(Primitive):
225         returns the coodinates of the point as L{numarray.NumArray} object         returns the coodinates of the point as L{numarray.NumArray} object
226         """         """
227         return self._x         return self._x
228      def setCoordinates(self,x,y,z):      def setCoordinates(self,x):
229         """         """
230         returns the coodinates of the point as L{numarray.NumArray} object         returns the coodinates of the point as L{numarray.NumArray} object
231         """         """
232         self._x=numarray.array([x,y,z],_TYPE)         if not isinstance(x, numarray.NumArray):
233      def getHistory(self):            self._x=numarray.array(x,_TYPE)
234           else:
235              self._x=x
236    
237        def getPrimitives(self):
238         """         """
239         returns C{set} of primitive used to construct the primitive         returns primitives used to construct the primitive
240         """         """
241         return set([self])         return [self]
242    
243      def isColocated(self,point,tol=1.e-11):      def isColocated(self,primitive):
244         """         """
245         returns True if L{Point} point is colocation (same coordinates)         returns True if L{Point} primitive is colocation (same coordinates)
246         that means if |self-point| <= tol * max(|self|,|point|)         that means if |self-primitive| <= tol * max(|self|,|primitive|)
247         """         """
248         if isinstance(point,Point):         if isinstance(primitive,Point):
249            point=point.getCoordinates()            primitive=primitive.getCoordinates()
250         c=self.getCoordinates()            c=self.getCoordinates()
251         d=c-point            d=c-primitive
252         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))
253               else:
254              return False
255    
256        def substitute(self,sub_dict):
257            """
258            returns a copy of self with substitutes for the primitives used to construct it given by the dictionary C{sub_dict}.
259            If a substitute for the object is given by C{sub_dict} the value is returned, otherwise a new instance
260            with substituted arguments is returned.
261            """
262            if not sub_dict.has_key(self):
263               c=self.getCoordinates()
264               sub_dict[self]=Point(c[0],c[1],c[2],local_scale=self.getLocalScale())
265            return sub_dict[self]
266    
267        def modifyBy(self,transformation):
268            """
269            modifies the coordinates by applying a transformation
270            """
271            self.setCoordinates(transformation(self.getCoordinates()))
272    
     #=============================================================  
     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  
        """  
        self._x+=numarray.array(shift,numarray.Float64)  
     def translate(self,shift):  
        """  
        returns the point shifted by shift  
        """  
        out=self.copy()  
        out+=other  
        return out  
273    
274        def getGmshCommand(self, local_scaling_factor=1.):
275            """
276            returns the Gmsh command(s) to create the primitive
277            """
278            c=self.getCoordinates()
279            return "Point(%s) = {%s , %s, %s , %s };"%(self.getID(),c[0],c[1],c[2], self.getLocalScale()*local_scaling_factor)
280    
281  class Curve(Primitive):  class Primitive1D(Primitive):
282        """        """
283        a curve        general one-dimensional primitive
284        """        """
285        def __init__(self,*args):        def __init__(self,*args):
286            """            """
287            defines a curve form a set of control points            create a one-dimensional primitive
288              """
289              super(Primitive1D, self).__init__()
290          
291    class Curve(Primitive1D):
292        """
293        a curve defined through a list of control points.
294        """
295        def __init__(self,*points):
296              """
297              defines a curve form control points
298            """            """
299              if len(points)<2:
300                 raise TypeError("Curve needs at least two points")
301            super(Curve, self).__init__()            super(Curve, self).__init__()
302            l=len(args)            i=0
303            for i in range(l):            for p in points:
304                if not args[i].isPoint():                i+=1
305                   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)
306            self.__nodes=args            self.__points=points
307        def __len__(self):  
308            return len(self.__nodes)      def __len__(self):
309        def isCurve(self):            """
310          return True            returns the number of control points
311        def getStart(self):            """
312              return len(self.__points)
313    
314        def getStartPoint(self):
315           """           """
316           returns start point           returns start point
317           """           """
318           return self.__nodes[0]           return self.__points[0]
319    
320        def getEnd(self):      def getEndPoint(self):
321           """           """
322           returns end point           returns end point
323           """           """
324           return self.__nodes[-1]           return self.__points[-1]
325    
326        def getNodes(self):      def getControlPoints(self):
327           """           """
328           returns a list of the nodes           returns a list of the points
329           """           """
330           return self.__nodes           return self.__points
331        def getGmshCommand(self):  
332        def getPrimitives(self):
333           """
334           returns primitives used to construct the Curve
335           """
336           out=set()
337           for p in self.getControlPoints(): out|=set(p.getPrimitives())
338           out.add(self)
339           return list(out)
340    
341        def substitute(self,sub_dict):
342            """
343            returns a copy of self with substitutes for the primitives used to construct it given by the dictionary C{sub_dict}.
344            If a substitute for the object is given by C{sub_dict} the value is returned, otherwise a new instance
345            with substituted arguments is returned.
346            """
347            if not sub_dict.has_key(self):
348                new_p=[]
349                for p in self.getControlPoints(): new_p.append(p.substitute(sub_dict))
350                sub_dict[self]=self.__class__(*tuple(new_p))
351            return sub_dict[self]
352    
353        def isColocated(self,primitive):
354           """
355           returns True curves are on the same position
356           """
357           if isinstance(primitive,self.__class__):
358              if len(primitive) == len(self):
359                 cp0=self.getControlPoints()
360                 cp1=primitive.getControlPoints()
361                 match=True
362                 for i in range(len(cp0)):
363                    if not cp0[i].isColocated(cp1[i]):
364                       match=False
365                       break
366                 if not match:
367                    for i in range(len(cp0)):
368                       if not cp0[i].isColocated(cp1[len(cp0)-1-i]):
369                          return False
370                 return True
371              else:
372                 return False
373           else:
374              return False
375    
376    class Spline(Curve):
377        """
378        a spline curve defined through a list of control points.
379        """
380        def getGmshCommand(self):
381            """
382            returns the Gmsh command(s) to create the Curve
383            """
384          out=""          out=""
385          for i in self.getNodes():          for i in self.getControlPoints():
386              if len(out)>0:              if len(out)>0:
387                  out+=", %s"%i.getID()                  out+=", %s"%i.getID()
388              else:              else:
389                  out="%s"%i.getID()                  out="%s"%i.getID()
390          return "Spline(%s) = {%s};"%(self.getID(),out)          return "Spline(%s) = {%s};"%(self.getID(),out)
391        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  
   
392    
393  class BezierCurve(Curve):  class BezierCurve(Curve):
394      """      """
395      a Bezier curve      a Bezier curve
396      """      """
     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()])  
397      def getGmshCommand(self):      def getGmshCommand(self):
398            """
399            returns the Gmsh command(s) to create the Curve
400            """
401          out=""          out=""
402          for i in self.getNodes():          for i in self.getControlPoints():
403              if len(out)>0:              if len(out)>0:
404                  out+=", %s"%i.getID()                  out+=", %s"%i.getID()
405              else:              else:
406                  out="%s"%i.getID()                  out="%s"%i.getID()
407          return "Bezier(%s) = {%s};"%(self.getID(),out)          return "Bezier(%s) = {%s};"%(self.getID(),out)
408    
409  class BSplineCurve(Curve):  class BSpline(Curve):
410      """      """
411      a BSpline curve. Control points may be repeated.      a BSpline curve. Control points may be repeated.
412      """      """
     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()])  
413      def getGmshCommand(self):      def getGmshCommand(self):
414            """
415            returns the Gmsh command(s) to create the Curve
416            """
417          out=""          out=""
418          for i in self.getNodes():          for i in self.getControlPoints():
419              if len(out)>0:              if len(out)>0:
420                  out+=", %s"%i.getID()                  out+=", %s"%i.getID()
421              else:              else:
# Line 285  class Line(Curve): Line 426  class Line(Curve):
426      """      """
427      a line is defined by two L{Point}s      a line is defined by two L{Point}s
428      """      """
429      def __init__(self,start,end):      def __init__(self,*points):
430          """          """
431          defines a curve form a set of control points          defines a line with start and end point
432          """          """
433          super(Line, self).__init__(start,end)          if len(points)!=2:
434      def __neg__(self):             raise TypeError("Line needs two points")
435         return ReversedPrimitive(self)          super(Line, self).__init__(*points)
     def __add__(self,other):  
        return Line(self.getEnd()+other,self.getStart()+other)  
436      def getGmshCommand(self):      def getGmshCommand(self):
437          return "Line(%s) = {%s, %s};"%(self.getID(),self.getStart().getID(),self.getEnd().getID())          """
438            returns the Gmsh command(s) to create the Curve
439            """
440            return "Line(%s) = {%s, %s};"%(self.getID(),self.getStartPoint().getID(),self.getEndPoint().getID())
441    
442  class Arc(Curve):  
443    class Arc(Primitive1D):
444      """      """
445      defines an arc      defines an arc which is strictly, smaller than Pi
446      """      """
447      def __init__(self,center,start,end):      def __init__(self,center,start,end):
448         """         """
449         creates an arc by the start point, end point and center         creates an arc by the start point, end point and center
450         """         """
451         if center.isPoint():         if not isinstance(center,Point): raise TypeError("center needs to be a Point object.")
452             raise TypeError("center needs to be a Point object.")         if not isinstance(end,Point): raise TypeError("end needs to be a Point object.")
453         super(Arc, self).__init__(start,end)         if not isinstance(start,Point): raise TypeError("start needs to be a Point object.")
454           # TODO: check length of circle.
455           super(Arc, self).__init__()
456         self.__center=center         self.__center=center
457           self.__start=start
458           self.__end=end
459    
460        def getStartPoint(self):
461           """
462           returns start point
463           """
464           return self.__start
465    
466        def getEndPoint(self):
467           """
468           returns end point
469           """
470           return self.__end
471    
472      def getCenter(self):      def getCenterPoint(self):
473         """         """
474         returns center         returns center
475         """         """
476         return self.__center         return self.__center
     def __add__(self,other):  
        return Arc(self.getCenter()+other,self.getStart()+other,self.getEnd()+other)  
477    
478      def getHistory(self):      def getPrimitives(self):
479            out=set([self])         """
480            out|=self.getCenter().getHistory()         returns the primitives used to construct the Curve
481            for i in self.getNodes(): out|=i.getHistory()         """
482            return out         out=set()
483      def getPoints(self):         out|=set(self.getStartPoint().getPrimitives())
484            out=self.getCenter().getPoints()         out|=set(self.getEndPoint().getPrimitives())
485            for i in self.getNodes(): out|=i.getPoints()         out|=set(self.getCenterPoint().getPrimitives())
486            return out         out.add(self)
487           return list(out)
488    
489      def getGmshCommand(self):      def getGmshCommand(self):
490          return "Circle(%s) = {%s, %s, %s};"%(self.getID(),self.getStart().getID(),self.getCenter().getID(),self.getEnd().getID())         """
491           returns the Gmsh command(s) to create the primitive
492           """
493           return "Circle(%s) = {%s, %s, %s};"%(self.getID(),self.getStartPoint().getID(),self.getCenterPoint().getID(),self.getEndPoint().getID())
494    
495        def substitute(self,sub_dict):
496            """
497            returns a copy of self with substitutes for the primitives used to construct it given by the dictionary C{sub_dict}.
498            If a substitute for the object is given by C{sub_dict} the value is returned, otherwise a new instance
499            with substituted arguments is returned.
500            """
501            if not sub_dict.has_key(self):
502                sub_dict[self]=Arc(self.getCenterPoint().substitute(sub_dict),self.getStartPoint().substitute(sub_dict),self.getEndPoint().substitute(sub_dict))
503            return sub_dict[self]
504    
505        def isColocated(self,primitive):
506           """
507           returns True curves are on the same position
508           """
509           if isinstance(primitive,Arc):
510                return (self.getCenterPoint().isColocated(primitive.getCenterPoint())) and ( \
511                       (self.getEndPoint().isColocated(primitive.getEndPoint()) and self.getStartPoint().isColocated(primitive.getStartPoint()) ) \
512                    or (self.getEndPoint().isColocated(primitive.getStartPoint()) and self.getStartPoint().isColocated(primitive.getEndPoint()) ) )
513           else:
514              return False
515    
516    class Primitive2D(Primitive):
517          """
518          general two-dimensional primitive
519          """
520          def __init__(self,*args):
521              """
522              create a two-dimensional primitive
523              """
524              super(Primitive2D, self).__init__()
525    
526  class CurveLoop(Primitive):  class CurveLoop(Primitive2D):
527      """      """
528      An oriented loop of curves.      An oriented loop of curves.
529    
# Line 341  class CurveLoop(Primitive): Line 534  class CurveLoop(Primitive):
534         creates a polygon from a list of line curves. The curves must form a closed loop.         creates a polygon from a list of line curves. The curves must form a closed loop.
535         """         """
536         super(CurveLoop, self).__init__()         super(CurveLoop, self).__init__()
537         self.__curves=[]         if len(curves)<2:
538         self.addCurve(*curves)              raise TypeError("at least two curves have to be given.")
     def addCurve(self,*curves):  
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         # for the curves a loop:
543           used=[ False for i in curves]
544           self.__curves=[curves[0]]
545           used[0]=True
546           while not min(used):
547              found=False
548              for i in xrange(len(curves)):
549                 if not used[i]:
550                    if self.__curves[-1].getEndPoint() == curves[i].getStartPoint():
551                       self.__curves.append(curves[i])
552                       used[i]=True
553                       found=True
554                       break
555              if not found:
556                 raise ValueError("loop is not closed.")
557           if not self.__curves[0].getStartPoint() == self.__curves[-1].getEndPoint():
558              raise ValueError("loop is not closed.")
559    
     def isCurveLoop(self):  
         return True  
560      def getCurves(self):      def getCurves(self):
561           """
562           returns the curves defining the CurveLoop
563           """
564         return self.__curves         return self.__curves
565      def __add__(self,other):  
        return CurveLoop(*tuple([c+other for c in self.getCurves()[::-1]]))  
566      def __len__(self):      def __len__(self):
567           """
568           return the number of curves in the CurveLoop
569           """
570         return len(self.__curves)         return len(self.__curves)
571      def getHistory(self):  
572            out=set([self])      def getPrimitives(self):
573            for i in self.getCurves(): out|=i.getHistory()         """
574            return out         returns primitives used to construct the CurveLoop
575      def getPoints(self):         """
576            out=set()         out=set()
577            for i in self.getCurves(): out|=i.getPoints()         for c in self.getCurves(): out|=set(c.getPrimitives())
578            return out         out.add(self)
579           return list(out)
580    
581        def substitute(self,sub_dict):
582            """
583            returns a copy of self with substitutes for the primitives used to construct it given by the dictionary C{sub_dict}.
584            If a substitute for the object is given by C{sub_dict} the value is returned, otherwise a new instance
585            with substituted arguments is returned.
586            """
587            if not sub_dict.has_key(self):
588                new_c=[]
589                for c in self.getCurves(): new_c.append(c.substitute(sub_dict))
590                sub_dict[self]=CurveLoop(*tuple(new_c))
591            return sub_dict[self]
592    
593    
594        def isColocated(self,primitive):
595           """
596           returns True if each curve is collocted with a curve in primitive
597           """
598           if isinstance(primitive,CurveLoop):
599              if len(primitive) == len(self):
600                 cp0=self.getCurves()
601                 cp1=primitive.getCurves()
602                 for c0 in cp0:
603                     collocated = False
604                     for c1 in cp1:
605                          collocated = collocated or c0.isColocated(c1)
606                     if not collocated: return False
607                 return True
608              else:
609                 return False
610           else:
611              return False
612    
613      def getGmshCommand(self):      def getGmshCommand(self):
614          out=""          out=""
615          for i in self.getCurves():          for i in self.getCurves():
# Line 374  class CurveLoop(Primitive): Line 619  class CurveLoop(Primitive):
619                  out="%s"%i.getID()                  out="%s"%i.getID()
620          return "Line Loop(%s) = {%s};"%(self.getID(),out)          return "Line Loop(%s) = {%s};"%(self.getID(),out)
621    
622    #=================================================================================================================================
623  class Surface(Primitive):  class Surface(Primitive):
624      """      """
625      a surface      a surface
# Line 394  class Surface(Primitive): Line 640  class Surface(Primitive):
640         return self.__loop         return self.__loop
641      def __add__(self,other):      def __add__(self,other):
642         return Surface(self.getBoundaryLoop()+other)         return Surface(self.getBoundaryLoop()+other)
643      def getHistory(self):      def getPrimitives(self):
644          out=set([self]) | self.getBoundaryLoop().getHistory()          out=set([self]) | self.getBoundaryLoop().getPrimitives()
645          return out          return out
646      def getPoints(self):      def getConstructionPoints(self):
647          return self.getBoundaryLoop().getPoints()          return self.getBoundaryLoop().getConstructionPoints()
648      def getGmshCommand(self):      def getGmshCommand(self):
649          return "Ruled Surface(%s) = {%s};"%(self.getID(),self.getBoundaryLoop().getID())          return "Ruled Surface(%s) = {%s};"%(self.getID(),self.getBoundaryLoop().getID())
650    
# Line 424  class PlaneSurface(Surface): Line 670  class PlaneSurface(Surface):
670         return self.__holes         return self.__holes
671      def __add__(self,other):      def __add__(self,other):
672         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()])
673      def getHistory(self):      def getPrimitives(self):
674          out=set([self]) | self.getBoundaryLoop().getHistory()          out=set([self]) | self.getBoundaryLoop().getPrimitives()
675          for i in self.getHoles(): out|=i.getHistory()          for i in self.getHoles(): out|=i.getPrimitives()
676          return out          return out
677      def getPoints(self):      def getConstructionPoints(self):
678          out=self.getBoundaryLoop().getPoints()          out=self.getBoundaryLoop().getConstructionPoints()
679          for i in self.getHoles(): out|=i.getPoints()          for i in self.getHoles(): out|=i.getConstructionPoints()
680          return out          return out
681      def getGmshCommand(self):      def getGmshCommand(self):
682          out=""          out=""
# Line 491  class SurfaceLoop(Primitive): Line 737  class SurfaceLoop(Primitive):
737         return SurfaceLoop([c+other for c in self.getSurfaces])         return SurfaceLoop([c+other for c in self.getSurfaces])
738      def __len__(self):      def __len__(self):
739         return len(self.__surfaces)         return len(self.__surfaces)
740      def getHistory(self):      def getPrimitives(self):
741            out=set([self])            out=set([self])
742            for i in self.getSurfaces(): out|=i.getHistory()            for i in self.getSurfaces(): out|=i.getPrimitives()
743            return out            return out
744      def getPoints(self):      def getConstructionPoints(self):
745            out=set()            out=set()
746            for i in self.getSurfaces(): out|=i.getPoints()            for i in self.getSurfaces(): out|=i.getConstructionPoints()
747            return out            return out
748      def getGmshCommand(self):      def getGmshCommand(self):
749          out=""          out=""
# Line 535  class Volume(Primitive): Line 781  class Volume(Primitive):
781         return self.__loop         return self.__loop
782      def __add__(self,other):      def __add__(self,other):
783         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()])
784      def getHistory(self):      def getPrimitives(self):
785          out=set([self]) | self.getSurfaceLoop().getHistory()          out=set([self]) | self.getSurfaceLoop().getPrimitives()
786          for i in self.getHoles(): out|=i.getHistory()          for i in self.getHoles(): out|=i.getPrimitives()
787          return out          return out
788      def getPoints(self):      def getConstructionPoints(self):
789          out=self.getSurfaceLoop().getPoints()          out=self.getSurfaceLoop().getConstructionPoints()
790          for i in self.getHoles(): out|=i.Points()          for i in self.getHoles(): out|=i.Points()
791          return out          return out
792      def getGmshCommand(self):      def getGmshCommand(self):
# Line 574  class PropertySet(Primitive): Line 820  class PropertySet(Primitive):
820         super(PropertySet, self).__init__()         super(PropertySet, self).__init__()
821         self.__items=items         self.__items=items
822         self.__tag=tag         self.__tag=tag
823      def getHistory(self):      def getPrimitives(self):
824          out=set([self, self.getBoundaryLoop().getHistory()])          out=set([self, self.getBoundaryLoop().getPrimitives()])
825          for i in self.getHoles(): out|=i.getHistory()          for i in self.getHoles(): out|=i.getPrimitives()
826          return out          return out
827    
828  class PrimitiveStack(object):  class PrimitiveStack(object):
829        def __init__(self,*items):        def __init__(self,*items):
830          self.__prims=set()          self.__prims=set()
831          for i in items:          for i in items:
832              self.__prims|=i.getHistory()              self.__prims|=i.getPrimitives()
833          self.__prims=list(self.__prims)          self.__prims=list(self.__prims)
834          self.__prims.sort()          self.__prims.sort()
835    

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

  ViewVC Help
Powered by ViewVC 1.1.26