/[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 1044 by gross, Tue Mar 13 02:06:30 2007 UTC revision 1045 by gross, Tue Mar 20 01:30:58 2007 UTC
# Line 217  class Primitive(object): Line 217  class Primitive(object):
217          """          """
218          raise NotImplementedError("__neg__ is not implemented.")          raise NotImplementedError("__neg__ is not implemented.")
219    
     def getGmshCommand(self, local_scaling_factor=1.):  
         """  
         returns the Gmsh command(s) to create the primitive  
   
         @note: this class is overwritten by subclass  
         """  
         raise NotImplementedError("getGmshCommand is not implemented.")  
   
220      def substitute(self,sub_dict):      def substitute(self,sub_dict):
221          """          """
222          returns a copy of self with substitutes for the primitives used to construct it given by the dictionary C{sub_dict}.          returns a copy of self with substitutes for the primitives used to construct it given by the dictionary C{sub_dict}.
# Line 307  class ReversePrimitive(object): Line 299  class ReversePrimitive(object):
299            """            """
300            return self.__primitive            return self.__primitive
301    
     def getGmshCommand(self, local_scaling_factor=1.):  
         """  
         returns the Gmsh command(s) to create the primitive  
         """  
         return self.__primitive.getGmshCommand(local_scaling_factor)  
   
302      def collectPrimitiveBases(self):      def collectPrimitiveBases(self):
303          """          """
304          returns a list of primitives used to construct the primitive. It may contain primitives twice          returns a list of primitives used to construct the primitive. It may contain primitives twice
# Line 404  class Point(Primitive, PrimitiveBase): Line 390  class Point(Primitive, PrimitiveBase):
390          self.setCoordinates(transformation(self.getCoordinates()))          self.setCoordinates(transformation(self.getCoordinates()))
391    
392    
     def getGmshCommand(self, local_scaling_factor=1.):  
         """  
         returns the Gmsh command(s) to create the primitive  
         """  
         c=self.getCoordinates()  
         return "Point(%s) = {%s , %s, %s , %s };"%(self.getID(),c[0],c[1],c[2], self.getLocalScale()*local_scaling_factor)  
   
393      def __neg__(self):      def __neg__(self):
394          """          """
395          returns a view of the object with reverse orientiention. As a point has no direction the object itself is returned.          returns a view of the object with reverse orientiention. As a point has no direction the object itself is returned.
# Line 574  class Spline(Curve): Line 553  class Spline(Curve):
553      """      """
554      a spline curve defined through a list of control points.      a spline curve defined through a list of control points.
555      """      """
556      def getGmshCommand(self,scaling_factor=1.):      pass
         """  
         returns the Gmsh command(s) to create the Curve  
         """  
         out=""  
         for i in self.getControlPoints():  
             if len(out)>0:  
                 out+=", %s"%i.getDirectedID()  
             else:  
                 out="%s"%i.getDirectedID()  
         return "Spline(%s) = {%s};"%(self.getID(),out)  
       
557    
558  class BezierCurve(Curve):  class BezierCurve(Curve):
559      """      """
560      a Bezier curve      a Bezier curve
561      """      """
562      def getGmshCommand(self,scaling_factor=1.):      pass
         """  
         returns the Gmsh command(s) to create the Curve  
         """  
         out=""  
         for i in self.getControlPoints():  
             if len(out)>0:  
                 out+=", %s"%i.getDirectedID()  
             else:  
                 out="%s"%i.getDirectedID()  
         return "Bezier(%s) = {%s};"%(self.getID(),out)  
563    
564  class BSpline(Curve):  class BSpline(Curve):
565      """      """
566      a BSpline curve. Control points may be repeated.      a BSpline curve. Control points may be repeated.
567      """      """
568      def getGmshCommand(self,scaling_factor=1.):      pass
         """  
         returns the Gmsh command(s) to create the Curve  
         """  
         out=""  
         for i in self.getControlPoints():  
             if len(out)>0:  
                 out+=", %s"%i.getDirectedID()  
             else:  
                 out="%s"%i.getDirectedID()  
         return "BSpline(%s) = {%s};"%(self.getID(),out)  
569    
570  class Line(Curve):  class Line(Curve):
571      """      """
# Line 630  class Line(Curve): Line 578  class Line(Curve):
578          if len(points)!=2:          if len(points)!=2:
579             raise TypeError("Line needs two points")             raise TypeError("Line needs two points")
580          Curve.__init__(self,*points)          Curve.__init__(self,*points)
     def getGmshCommand(self,scaling_factor=1.):  
         """  
         returns the Gmsh command(s) to create the Curve  
         """  
         return "Line(%s) = {%s, %s};"%(self.getID(),self.getStartPoint().getDirectedID(),self.getEndPoint().getDirectedID())  
   
581    
582  class ArcBase(Manifold1D):  class ArcBase(Manifold1D):
583      def __init__(self):      def __init__(self):
# Line 711  class Arc(ArcBase, Primitive): Line 653  class Arc(ArcBase, Primitive):
653              sub_dict[self]=Arc(self.getCenterPoint().substitute(sub_dict),self.getStartPoint().substitute(sub_dict),self.getEndPoint().substitute(sub_dict))              sub_dict[self]=Arc(self.getCenterPoint().substitute(sub_dict),self.getStartPoint().substitute(sub_dict),self.getEndPoint().substitute(sub_dict))
654          return sub_dict[self]          return sub_dict[self]
655    
     def getGmshCommand(self,scaling_factor=1.):  
        """  
        returns the Gmsh command(s) to create the primitive  
        """  
        return "Circle(%s) = {%s, %s, %s};"%(self.getID(),self.getStartPoint().getDirectedID(),self.getCenterPoint().getDirectedID(),self.getEndPoint().getDirectedID())  
656    
657      def isColocated(self,primitive):      def isColocated(self,primitive):
658         """         """
# Line 836  class CurveLoop(Primitive, PrimitiveBase Line 773  class CurveLoop(Primitive, PrimitiveBase
773                  return True                  return True
774         return False         return False
775    
     def getGmshCommand(self,scaling_factor=1.):  
         """  
         returns the Gmsh command(s) to create the primitive  
         """  
         out=""  
         for i in self.getCurves():  
             if len(out)>0:  
                 out+=", %s"%i.getDirectedID()  
             else:  
                 out="%s"%i.getDirectedID()  
         return "Line Loop(%s) = {%s};"%(self.getID(),out)  
   
776  class ReverseCurveLoop(ReversePrimitive, PrimitiveBase):  class ReverseCurveLoop(ReversePrimitive, PrimitiveBase):
777      """      """
778      An oriented loop of one-dimensional manifolds (= curves and arcs)      An oriented loop of one-dimensional manifolds (= curves and arcs)
# Line 927  class RuledSurface(Primitive, Manifold2D Line 852  class RuledSurface(Primitive, Manifold2D
852          """          """
853          return self.getBoundaryLoop().getCurves()          return self.getBoundaryLoop().getCurves()
854    
     def getGmshCommand(self,scaling_factor=1.):  
         """  
         returns the Gmsh command(s) to create the primitive  
         """  
         return "Ruled Surface(%s) = {%s};"%(self.getID(),self.getBoundaryLoop().getDirectedID())  
   
855      def substitute(self,sub_dict):      def substitute(self,sub_dict):
856          """          """
857          returns a copy of self with substitutes for the primitives used to construct it given by the dictionary C{sub_dict}.          returns a copy of self with substitutes for the primitives used to construct it given by the dictionary C{sub_dict}.
# Line 1032  class PlaneSurface(Primitive, Manifold2D Line 951  class PlaneSurface(Primitive, Manifold2D
951          """          """
952          return self.__loop          return self.__loop
953    
     def getGmshCommand(self,scaling_factor=1.):  
         """  
         returns the Gmsh command(s) to create the primitive  
         """  
         out=""  
         for i in self.getHoles():  
             if len(out)>0:  
                 out+=", %s"%i.getDirectedID()  
             else:  
                 out="%s"%i.getDirectedID()  
         if len(out)>0:  
           return "Plane Surface(%s) = {%s, %s};"%(self.getID(),self.getBoundaryLoop().getDirectedID(), out)  
         else:  
           return "Plane Surface(%s) = {%s};"%(self.getID(),self.getBoundaryLoop().getDirectedID())  
   
954      def substitute(self,sub_dict):      def substitute(self,sub_dict):
955          """          """
956          returns a copy of self with substitutes for the primitives used to construct it given by the dictionary C{sub_dict}.          returns a copy of self with substitutes for the primitives used to construct it given by the dictionary C{sub_dict}.
# Line 1173  class SurfaceLoop(Primitive, PrimitiveBa Line 1077  class SurfaceLoop(Primitive, PrimitiveBa
1077         for c in self.getSurfaces(): out+=c.collectPrimitiveBases()         for c in self.getSurfaces(): out+=c.collectPrimitiveBases()
1078         return out         return out
1079    
     def getGmshCommand(self,scaling_factor=1.):  
         """  
         returns the Gmsh command(s) to create the primitive  
         """  
         out=""  
         for i in self.getSurfaces():  
             if len(out)>0:  
                 out+=", %s"%i.getDirectedID()  
             else:  
                 out="%s"%i.getDirectedID()  
         return "Surface Loop(%s) = {%s};"%(self.getID(),out)  
   
1080      def substitute(self,sub_dict):      def substitute(self,sub_dict):
1081          """          """
1082          returns a copy of self with substitutes for the primitives used to construct it given by the dictionary C{sub_dict}.          returns a copy of self with substitutes for the primitives used to construct it given by the dictionary C{sub_dict}.
# Line 1291  class Volume(Manifold3D, Primitive): Line 1183  class Volume(Manifold3D, Primitive):
1183         """         """
1184         return self.__loop         return self.__loop
1185    
     def getGmshCommand(self,scaling_factor=1.):  
         """  
         returns the Gmsh command(s) to create the primitive  
         """  
         out=""  
         for i in self.getHoles():  
             if len(out)>0:  
                 out+=", %s"%i.getDirectedID()  
             else:  
                 out="%s"%i.getDirectedID()  
         if len(out)>0:  
           return "Volume(%s) = {%s, %s};"%(self.getID(),self.getSurfaceLoop().getDirectedID(), out)  
         else:  
           return "Volume(%s) = {%s};"%(self.getID(),self.getSurfaceLoop().getDirectedID())  
   
1186      def substitute(self,sub_dict):      def substitute(self,sub_dict):
1187          """          """
1188          returns a copy of self with substitutes for the primitives used to construct it given by the dictionary C{sub_dict}.          returns a copy of self with substitutes for the primitives used to construct it given by the dictionary C{sub_dict}.
# Line 1431  class PropertySet(Primitive, PrimitiveBa Line 1308  class PropertySet(Primitive, PrimitiveBa
1308          for i in self.getItems(): out+=i.collectPrimitiveBases()          for i in self.getItems(): out+=i.collectPrimitiveBases()
1309          return out          return out
1310    
     def getGmshCommand(self,scaling_factor=1.):  
         """  
         returns the Gmsh command(s) to create the primitive  
         """  
         k=self.getDim()  
         out="Physical "  
         if k==0:  
             out+="Point"  
         elif k==1:  
             out+="Line"  
         elif k==2:  
             out+="Surface"  
         else:  
             out+="Volume"  
         out2=""  
         for i in self.getItems():  
             if len(out2)>0:  
                 out2+=", %s"%i.getDirectedID()  
             else:  
                 out2="%s"%i.getDirectedID()  
         out+="(" + str(self.getID()) + ") = {"+out2+"};"  
         return out  
   
1311      def getTag(self):      def getTag(self):
1312           """           """
1313           returns the tag used for this property set           returns the tag used for this property set

Legend:
Removed from v.1044  
changed lines
  Added in v.1045

  ViewVC Help
Powered by ViewVC 1.1.26