/[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 899 by gross, Mon Nov 13 08:02:24 2006 UTC revision 902 by gross, Thu Nov 16 07:22:08 2006 UTC
# Line 46  class Primitive(object): Line 46  class Primitive(object):
46         return "%s(%s)"%(self.__class__.__name__,self.getID())         return "%s(%s)"%(self.__class__.__name__,self.getID())
47      def __cmp__(self,other):      def __cmp__(self,other):
48         return cmp(self.getID(),other.getID())         return cmp(self.getID(),other.getID())
     def getGmshCommand(self):  
         raise NotImplementedError("getGmshCommand is not implemented for this class %s."%self.__class__.__name__)  
49      def isPoint(self):      def isPoint(self):
50          return False          return False
51      def isCurve(self):      def isCurve(self):
# Line 60  class Primitive(object): Line 58  class Primitive(object):
58          return False          return False
59      def __neg__(self):      def __neg__(self):
60          return ReversedPrimitive(self)          return ReversedPrimitive(self)
61        def __pos__(self):
62            return self.copy()
63        def __add__(self,other):
64           out=self.copy()
65           out+=other
66           return out
67        def __iadd__(self,other):
68           self.shift()
69        def setLocalLength(self,factor=1.):
70            for p in self.getPoints(): p.setLocalLength(factor)
71        def shift(self,shift):
72            for p in self.getPoints(): p+=shift
73        def copy(self):
74            return Primitive()
75        def getGmshCommand(self):
76            raise NotImplementedError("getGmshCommand is not implemented for this class %s."%self.__class__.__name__)
77        def getHistory(self):
78            return set()
79        def getPoints(self):
80            return set()
81        def translate(self,shift):
82            raise NotImplementedError("translate is not implemented for this class %s."%self.__class__.__name__)
83    
84  class ReversedPrimitive(object):  class ReversedPrimitive(object):
85      def __init__(self,prim):      def __init__(self,prim):
# Line 86  class Point(Primitive): Line 106  class Point(Primitive):
106         self._x=numarray.array([x,y,z],numarray.Float64)         self._x=numarray.array([x,y,z],numarray.Float64)
107         self.setLocalScale(local_scale)         self.setLocalScale(local_scale)
108      def setLocalScale(self,factor=1.):      def setLocalScale(self,factor=1.):
109           """
110           sets the local relative length scale
111           """
112         self.__local_scale=factor         self.__local_scale=factor
     def isPoint(self):  
         return True  
113      def getLocalScale(self):      def getLocalScale(self):
114         return self.__local_scale         return self.__local_scale
115        def copy(self):
116           c=self.getCoordinates()
117           return Point(c[0],c[1],c[2],local_scale=self.getLocalScale())
118        def isPoint(self):
119            return True
120      def getCoordinates(self):      def getCoordinates(self):
121         return self._x         return self._x
     def __add__(self,other):  
        c=self.getCoordinates()+numarray.array(other,numarray.Float64)  
        return Point(x=c[0],y=c[1],z=c[2],local_scale=self.getLocalScale())  
122      def getGmshCommand(self):      def getGmshCommand(self):
123          c=self.getCoordinates()          c=self.getCoordinates()
124          return "Point(%s) = {%e , %e, %e , %e * scale};"%(self.getID(),c[0],c[1],c[2], self.getLocalScale())          return "Point(%s) = {%e , %e, %e , %e * scale};"%(self.getID(),c[0],c[1],c[2], self.getLocalScale())
125      def getHistory(self):      def getHistory(self):
126          return set([self])          return set([self])
127        def getPoints(self):
128            return set([self])
129        def shift(self,shift):
130           """
131           shifts the point by a given shift
132           """
133           self._x+=numarray.array(shift,numarray.Float64)
134        def translate(self,shift):
135           """
136           returns the point shifted by shift
137           """
138           out=self.copy()
139           out+=other
140           return out
141    
142    
143  class Curve(Primitive):  class Curve(Primitive):
144        """        """
# Line 120  class Curve(Primitive): Line 158  class Curve(Primitive):
158            return len(self.__nodes)            return len(self.__nodes)
159        def isCurve(self):        def isCurve(self):
160          return True          return True
       def getHistory(self):  
           out=set([self])  
           for i in self.getNodes(): out|=i.getHistory()  
           return out  
   
161        def getStart(self):        def getStart(self):
162           """           """
163           returns start point           returns start point
# Line 142  class Curve(Primitive): Line 175  class Curve(Primitive):
175           returns a list of the nodes           returns a list of the nodes
176           """           """
177           return self.__nodes           return self.__nodes
       def __add__(self,other):  
          return Curve([p+other for p in self.getNodes()])  
178        def getGmshCommand(self):        def getGmshCommand(self):
179          out=""          out=""
180          for i in self.getNodes():          for i in self.getNodes():
# Line 152  class Curve(Primitive): Line 183  class Curve(Primitive):
183              else:              else:
184                  out="%s"%i.getID()                  out="%s"%i.getID()
185          return "Spline(%s) = {%s};"%(self.getID(),out)          return "Spline(%s) = {%s};"%(self.getID(),out)
186          def getHistory(self):
187              out=set([self])
188              for i in self.getNodes(): out|=i.getHistory()
189              return out
190          def getPoints(self):
191            out=set()
192            for i in self.getNodes(): out|=i.getPoints()
193            return out
194    
195    
196  class BezierCurve(Curve):  class BezierCurve(Curve):
197      """      """
# Line 235  class Arc(Curve): Line 275  class Arc(Curve):
275            out|=self.getCenter().getHistory()            out|=self.getCenter().getHistory()
276            for i in self.getNodes(): out|=i.getHistory()            for i in self.getNodes(): out|=i.getHistory()
277            return out            return out
278        def getPoints(self):
279              out=self.getCenter().getPoints()
280              for i in self.getNodes(): out|=i.getPoints()
281              return out
282      def getGmshCommand(self):      def getGmshCommand(self):
283          return "Circle(%s) = {%s, %s, %s};"%(self.getID(),self.getStart().getID(),self.getCenter().getID(),self.getEnd().getID())          return "Circle(%s) = {%s, %s, %s};"%(self.getID(),self.getStart().getID(),self.getCenter().getID(),self.getEnd().getID())
284    
# Line 269  class CurveLoop(Primitive): Line 313  class CurveLoop(Primitive):
313            out=set([self])            out=set([self])
314            for i in self.getCurves(): out|=i.getHistory()            for i in self.getCurves(): out|=i.getHistory()
315            return out            return out
316        def getPoints(self):
317              out=set()
318              for i in self.getCurves(): out|=i.getPoints()
319              return out
320      def getGmshCommand(self):      def getGmshCommand(self):
321          out=""          out=""
322          for i in self.getCurves():          for i in self.getCurves():
# Line 301  class Surface(Primitive): Line 349  class Surface(Primitive):
349      def getHistory(self):      def getHistory(self):
350          out=set([self]) | self.getBoundaryLoop().getHistory()          out=set([self]) | self.getBoundaryLoop().getHistory()
351          return out          return out
352        def getPoints(self):
353            return self.getBoundaryLoop().getPoints()
354      def getGmshCommand(self):      def getGmshCommand(self):
355          return "Ruled Surface(%s) = {%s};"%(self.getID(),self.getBoundaryLoop().getID())          return "Ruled Surface(%s) = {%s};"%(self.getID(),self.getBoundaryLoop().getID())
356    
# Line 330  class PlaneSurface(Surface): Line 380  class PlaneSurface(Surface):
380          out=set([self]) | self.getBoundaryLoop().getHistory()          out=set([self]) | self.getBoundaryLoop().getHistory()
381          for i in self.getHoles(): out|=i.getHistory()          for i in self.getHoles(): out|=i.getHistory()
382          return out          return out
383        def getPoints(self):
384            out=self.getBoundaryLoop().getPoints()
385            for i in self.getHoles(): out|=i.getPoints()
386            return out
387      def getGmshCommand(self):      def getGmshCommand(self):
388          out=""          out=""
389          for i in self.getHoles():          for i in self.getHoles():
# Line 393  class SurfaceLoop(Primitive): Line 447  class SurfaceLoop(Primitive):
447            out=set([self])            out=set([self])
448            for i in self.getSurfaces(): out|=i.getHistory()            for i in self.getSurfaces(): out|=i.getHistory()
449            return out            return out
450        def getPoints(self):
451              out=set()
452              for i in self.getSurfaces(): out|=i.getPoints()
453              return out
454      def getGmshCommand(self):      def getGmshCommand(self):
455          out=""          out=""
456          for i in self.getSurfaces():          for i in self.getSurfaces():
# Line 433  class Volume(Primitive): Line 491  class Volume(Primitive):
491          out=set([self]) | self.getSurfaceLoop().getHistory()          out=set([self]) | self.getSurfaceLoop().getHistory()
492          for i in self.getHoles(): out|=i.getHistory()          for i in self.getHoles(): out|=i.getHistory()
493          return out          return out
494        def getPoints(self):
495            out=self.getSurfaceLoop().getPoints()
496            for i in self.getHoles(): out|=i.Points()
497            return out
498      def getGmshCommand(self):      def getGmshCommand(self):
499          out=""          out=""
500          for i in self.getHoles():          for i in self.getHoles():
# Line 471  class PrimitiveStack(object): Line 533  class PrimitiveStack(object):
533          for i in self.__prims:          for i in self.__prims:
534             out+=i.getGmshCommand()+"\n"             out+=i.getGmshCommand()+"\n"
535          return out          return out
   
       def getPycadCommands(self,name="TMP_"):  
         out=""  
         for i in self.__prims:  
            out+=i.getPycadCommand(name)+"\n"  

Legend:
Removed from v.899  
changed lines
  Added in v.902

  ViewVC Help
Powered by ViewVC 1.1.26