/[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 923 by gross, Tue Jan 9 22:50:43 2007 UTC revision 925 by gross, Wed Jan 10 22:40:00 2007 UTC
# Line 92  class Primitive(object): Line 92  class Primitive(object):
92         """         """
93         returns a deep copy of the object         returns a deep copy of the object
94         """         """
95         return Primitive()         return self.substitute({})
96    
97    
98      def modifyBy(self,transformation):      def modifyBy(self,transformation):
# Line 174  class Primitive(object): Line 174  class Primitive(object):
174    
175      def apply(self,transformation):      def apply(self,transformation):
176          """          """
177          returns a new object by applying the transformation          returns a new L{Point} by applying the transformation
178          """          """
179          raise NotImplementedError("apply is not implemented for this class %s."%self.__class__.__name__)          out=self.copy()
180            out.modifyBy(transformation)
181            return out
182    
183      def isColocated(self,primitive):      def isColocated(self,primitive):
184         """         """
# Line 184  class Primitive(object): Line 186  class Primitive(object):
186         """         """
187         raise NotImplementedError("isColocated is not implemented for this class %s."%self.__class__.__name__)         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      """      """
201      a three dimensional point      a three dimensional point
# Line 241  class Point(Primitive): Line 253  class Point(Primitive):
253         else:         else:
254            return False            return False
255    
256      def copy(self):      def substitute(self,sub_dict):
257         """          """
258         returns a deep copy of the point          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         c=self.getCoordinates()          with substituted arguments is returned.
261         return Point(c[0],c[1],c[2],local_scale=self.getLocalScale())          """
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):      def modifyBy(self,transformation):
268          """          """
# Line 254  class Point(Primitive): Line 270  class Point(Primitive):
270          """          """
271          self.setCoordinates(transformation(self.getCoordinates()))          self.setCoordinates(transformation(self.getCoordinates()))
272    
     def apply(self,transformation):  
         """  
         returns a new L{Point} by applying the transformation  
         """  
         new_p=self.copy()  
         new_p.modifyBy(transformation)  
         return new_p  
273    
274      def getGmshCommand(self, local_scaling_factor=1.):      def getGmshCommand(self, local_scaling_factor=1.):
275          """          """
# Line 329  class Curve(Primitive1D): Line 338  class Curve(Primitive1D):
338         out.add(self)         out.add(self)
339         return list(out)         return list(out)
340    
341      def copy(self):      def substitute(self,sub_dict):
        """  
        returns a deep copy  
        """  
        new_p=[]  
        for p in self.getControlPoints(): new_p.append(p.copy())  
        return self.__class__(*tuple(new_p))  
   
   
     def apply(self,transformation):  
342          """          """
343          applies transformation          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          new_p=[]          with substituted arguments is returned.
346          for p in self.getControlPoints(): new_p.append(p.apply(transformation))          """
347          return self.__class__(*tuple(new_p))          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):      def isColocated(self,primitive):
354         """         """
# Line 488  class Arc(Primitive1D): Line 492  class Arc(Primitive1D):
492         """         """
493         return "Circle(%s) = {%s, %s, %s};"%(self.getID(),self.getStartPoint().getID(),self.getCenterPoint().getID(),self.getEndPoint().getID())         return "Circle(%s) = {%s, %s, %s};"%(self.getID(),self.getStartPoint().getID(),self.getCenterPoint().getID(),self.getEndPoint().getID())
494    
495      def copy(self):      def substitute(self,sub_dict):
        """  
        returns a deep copy  
        """  
        return Arc(self.getCenterPoint().copy(),self.getStartPoint().copy(),self.getEndPoint().copy())  
   
     def apply(self,transformation):  
         """  
         applies transformation  
496          """          """
497          return Arc(self.getCenterPoint().apply(transformation),self.getStartPoint().apply(transformation),self.getEndPoint().apply(transformation))          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):      def isColocated(self,primitive):
506         """         """
# Line 560  class CurveLoop(Primitive2D): Line 562  class CurveLoop(Primitive2D):
562         returns the curves defining the CurveLoop         returns the curves defining the CurveLoop
563         """         """
564         return self.__curves         return self.__curves
565    
566      def __len__(self):      def __len__(self):
567         """         """
568         return the number of curves in the CurveLoop         return the number of curves in the CurveLoop
# Line 575  class CurveLoop(Primitive2D): Line 578  class CurveLoop(Primitive2D):
578         out.add(self)         out.add(self)
579         return list(out)         return list(out)
580    
581      def copy(self):      def substitute(self,sub_dict):
        """  
        returns a deep copy  
        """  
        new_c=[]  
        for c in self.getCurves(): new_c.append(c.copy())  
        return CurveLoop(*tuple(new_c))  
   
   
     def apply(self,transformation):  
         """  
         applies transformation  
582          """          """
583          new_c=[]          returns a copy of self with substitutes for the primitives used to construct it given by the dictionary C{sub_dict}.
584          for c in self.getCurves(): new_c.append(c.apply(transformation))          If a substitute for the object is given by C{sub_dict} the value is returned, otherwise a new instance
585          return CurveLoop(*tuple(new_c))          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):      def isColocated(self,primitive):
595         """         """
# Line 602  class CurveLoop(Primitive2D): Line 601  class CurveLoop(Primitive2D):
601               cp1=primitive.getCurves()               cp1=primitive.getCurves()
602               for c0 in cp0:               for c0 in cp0:
603                   collocated = False                   collocated = False
604                   for c1 in cp1: collocated = collocated or c0.isColocated(c1)                   for c1 in cp1:
605                          collocated = collocated or c0.isColocated(c1)
606                   if not collocated: return False                   if not collocated: return False
607               return True               return True
608            else:            else:

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

  ViewVC Help
Powered by ViewVC 1.1.26