revision 925 by gross, Wed Jan 10 22:40:00 2007 UTC revision 927 by gross, Fri Jan 12 06:32:08 2007 UTC
# Line 619  class CurveLoop(Primitive2D): Line 619  class CurveLoop(Primitive2D):
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  #=================================================================================================================================  class Surface(Primitive2D):
class Surface(Primitive):
623      """      """
624      a surface      a surface
625      """      """
626        pass
627
628    class RuledSurface(Surface):
629        """
630        A ruled surface, i.e., a surface that can be interpolated using transfinite interpolation
631        """
632      def __init__(self,loop):      def __init__(self,loop):
633         """         """
634         creates a  surface with boundary loop         creates a ruled surface with boundary loop
635
636         @param loop: L{CurveLoop} defining the boundary of the surface         @param loop: L{CurveLoop} defining the boundary of the surface.
637         """         """
638         super(Surface, self).__init__()         super(RuledSurface, self).__init__()
639         if not loop.isCurveLoop():         if not isinstance(CurveLoop):
640             raise TypeError("argument loop needs to be a CurveLoop object.")             raise TypeError("argument loop needs to be a CurveLoop object.")
641           if len(loop)<2:
642               raise TypeError("the loop must contain at least two Curves.")
643           if len(loop)>4:
644               raise TypeError("the loop must contain at least three Curves.")
645
646         self.__loop=loop         self.__loop=loop
647      def isSurface(self):
return True
648      def getBoundaryLoop(self):      def getBoundaryLoop(self):
649         return self.__loop          """
650      def __add__(self,other):          returns the loop defining the boundary
651         return Surface(self.getBoundaryLoop()+other)          """
652            return self.__loop
653
654      def getPrimitives(self):      def getPrimitives(self):
655          out=set([self]) | self.getBoundaryLoop().getPrimitives()          out=set([self]) | self.getBoundaryLoop().getPrimitives()
656          return out
def getConstructionPoints(self):
return self.getBoundaryLoop().getConstructionPoints()
657      def getGmshCommand(self):      def getGmshCommand(self):
658          return "Ruled Surface(%s) = {%s};"%(self.getID(),self.getBoundaryLoop().getID())          return "Ruled Surface(%s) = {%s};"%(self.getID(),self.getBoundaryLoop().getID())
659
660        def getPrimitives(self):
661           """
662           returns primitives used to construct the CurveLoop
663           """
664           out=list(set([self]) | self.getBoundaryLoop().getPrimitives())
665
666        def substitute(self,sub_dict):
667            """
668            returns a copy of self with substitutes for the primitives used to construct it given by the dictionary C{sub_dict}.
669            If a substitute for the object is given by C{sub_dict} the value is returned, otherwise a new instance
670            with substituted arguments is returned.
671            """
672            if not sub_dict.has_key(self):
673                sub_dict[self]=CurveLoop(self.getBoundaryLoop().substitute(sub_dict))
674            return sub_dict[self]
675
676        def isColocated(self,primitive):
677           """
678           returns True if each curve is collocted with a curve in primitive
679           """
680           if isinstance(primitive,RuledSurface):
681              return self.getBoundaryLoop().colocated(primitive.getBoundaryLoop())
682           else:
683              return False
684
685    def createRuledSurface(*curves):
686          """
687          an easier way to create a L{RuledSurface} from given curves.
688          """
689          return RuledSurface(CurveLoop(*curves))
690
691  class PlaneSurface(Surface):  class PlaneSurface(Surface):
692      """      """
693      a plane surface with holes      a plane surface with holes
694      """      """
695      def __init__(self,loop,holes=[]):      def __init__(self,loop,holes=[]):
696         """         """
697         creates a  plane surface.         creates a  plane surface with a hole
698
699         @param loop: L{CurveLoop} defining the boundary of the surface         @param loop: L{CurveLoop} defining the boundary of the surface
700         @param holes: list of L{CurveLoop} defining holes in the surface.         @param holes: list of L{CurveLoop} defining holes in the surface.
701         @note: A CurveLoop defining a hole should not have any lines in common with the exterior CurveLoop.           @note: A CurveLoop defining a hole should not have any lines in common with the exterior CurveLoop.
702                A CurveLoop defining a hole should not have any lines in common with another CurveLoop defining a hole in the same surface.                A CurveLoop defining a hole should not have any lines in common with another CurveLoop defining a hole in the same surface.
703         """         """
704         super(PlaneSurface, self).__init__(loop)         super(PlaneSurface, self).__init__()
705           if not isinstance(loop,CurveLoop):
706               raise TypeError("argument loop needs to be a CurveLoop object.")
707         for i in range(len(holes)):         for i in range(len(holes)):
708              if not holes[i].inCurveLoop():              if not holes[i].inCurveLoop():
709                   raise TypeError("%i th hole needs to be a CurveLoop object.")                   raise TypeError("%i th hole needs to be a CurveLoop object.")
710           #TODO: check if lines are in a plane
711         self.__holes=holes         self.__holes=holes
712      def getHoles(self):      def getHoles(self):
713           """
714           returns the holes
715           """
716         return self.__holes         return self.__holes
718         return PlaneSurface(self.getBoundaryLoop()+other, holes=[h+other for h in self.getHoles()])          """
719            returns the loop defining the boundary
720            """
721            return self.__loop
722      def getPrimitives(self):      def getPrimitives(self):
723          out=set([self]) | self.getBoundaryLoop().getPrimitives()          out=set([self]) | self.getBoundaryLoop().getPrimitives()
724          for i in self.getHoles(): out|=i.getPrimitives()          for i in self.getHoles(): out|=i.getPrimitives()
725          return out          return out
726      def getConstructionPoints(self):
out=self.getBoundaryLoop().getConstructionPoints()
for i in self.getHoles(): out|=i.getConstructionPoints()
return out
727      def getGmshCommand(self):      def getGmshCommand(self):
728          out=""          out=""
729          for i in self.getHoles():          for i in self.getHoles():
# Line 690  class PlaneSurface(Surface): Line 736  class PlaneSurface(Surface):
736          else:          else:
737            return "Plane Surface(%s) = {%s};"%(self.getID(),self.getBoundaryLoop().getID())            return "Plane Surface(%s) = {%s};"%(self.getID(),self.getBoundaryLoop().getID())
738
739  class RuledSurface(Surface):      def substitute(self,sub_dict):
740      """          """
741     A ruled surface, i.e., a surface that can be interpolated using transfinite interpolation          returns a copy of self with substitutes for the primitives used to construct it given by the dictionary C{sub_dict}.
742      """          If a substitute for the object is given by C{sub_dict} the value is returned, otherwise a new instance
743      def __init__(self,loop):          with substituted arguments is returned.
744         """          """
745         creates a ruled surface from a          if not sub_dict.has_key(self):
746                sub_dict[self]=CurveLoop(self.getBoundaryLoop().substitute(sub_dict),[ h.substitute(sub_dict) for h in self.getHoles()])
747            return sub_dict[self]
748
749        def isColocated(self,primitive):
750           """
751           returns True if each curve is collocted with a curve in primitive
752           """
753           if isinstance(primitive,PlaneSurface):
754              if self.getBoundaryLoop().colocated(primitive.getBoundaryLoop()):
755                 my_h=self.getHoles()
756                 h=primitive.getHoles()
757              else:
758                 return False
759           else:
760              return False
761
@param loop: L{CurveLoop} defining the boundary of the surface. There is a restriction of composed of either three or four L{Curve} objects.
"""
if not loop.isCurveLoop():
raise TypeError("argument loop needs to be a CurveLoop object.")
if len(loop)<3:
raise TypeError("the loop must contain at least three Curves.")
super(RuledSurface, self).__init__(loop)