예제 #1
0
    def id_values_dict(self):
        """
        Build the dictionary of stored values in the auxiliary file and rewrite that file.
        """
        d = {}
        try:
            f = open(self.interWriteFile.from_here(), "r")
        except IOError:
            if not self.already_warned_CompileYourLaTeXFile:
                logging(
                    "Warning: the auxiliary file %s does not seem to exist. Compile your LaTeX file."
                    % self.interWriteFile.from_main(),
                    pspict=self.picture)
                self.already_warned_CompileYourLaTeXFile = True
            return d
        idlist = f.read().replace('\n', '').replace(' ',
                                                    '').replace('\\par',
                                                                '').split("-")
        f.close()

        for els in idlist[0:-1]:
            key = els.split(":")[0]
            value = els.split(':')[1]
            d[key] = value

        with open(self.interWriteFile.from_here(), "w") as f:
            for k in d.iterkeys():
                f.write("%s:%s-\n" % (k, d[k]))

        return d
예제 #2
0
 def __init__(self, A, B):
     self.I = A
     self.F = B
     if not isinstance(A, PointGraph) or not isinstance(B, PointGraph):
         from Debug import testtype
         logging("Building a segment from something that is not\
                             a point. Here are the given objects :")
         raise TypeError
     ObjectGraph.__init__(self, self)
     self.measure = None
예제 #3
0
 def __sub__(self, other):
     try:
         s = AngleMeasure(value_radian=self.radian - other.radian)
     except AttributeError:
         from NoMathUtilities import logging
         logging(
             "Are you trying to add an 'AngleMesasure' with something else ?"
         )
         logging("'other's type is " + str(type(other)))
         raise
     return s
예제 #4
0
def visual_vector(v, pspict=None, xunit=None, yunit=None):
    from NoMathUtilities import logging
    from Constructors import AffineVector
    if pspict is None and (xunit is None or yunit is None):
        logging("Trying to make visual_vector with no pspict ?")
        raise DeprecationWarning
        return v
    if pspict:
        xunit = pspict.xunit
        yunit = pspict.yunit
    I = v.I
    F = I + (v.Dx / xunit, v.Dy / yunit)
    return AffineVector(I, F)
예제 #5
0
    def normalize(self,l=1):
        """
        Return a new affine vector with
        - same starting point
        - same direction (if 'l' is negative, change the direction)
        - size l

        By default, normalize to 1.
        """
        L=self.length
        if L<0.001:     # epsilon
            logging("This vector is too small to normalize. I return a copy.")
            return self.copy()
        return (l*self).__div__(L)     
예제 #6
0
    def __add__(self, other):
        ##
        # return the sum of two angles.
        # The return type is `AngleMeasure`

        try:
            return AngleMeasure(value_radian=self.radian + other.radian)
        except AttributeError:
            from NoMathUtilities import logging
            logging(
                "Are you trying to add an 'AngleMeasure' with something else ?"
            )
            logging("The other's type is " + str(type(other)))
            raise
예제 #7
0
    def put_mark(self,dist=None,angle=None,text="",\
            mark_point=None,added_angle=None,position=None,\
            pspict=None,pspicts=None):

        from NoMathUtilities import ensure_unicode
        from Utilities import make_psp_list
        text=ensure_unicode(text)
        pspicts=make_psp_list(pspict,pspicts)

        for psp in pspicts:
            mark=self.get_mark(dist,angle,text,mark_point=mark_point,
                        added_angle=added_angle,position=position,pspict=psp)

            if position in ["N","S","E","W"] and angle is not None :
                logging( "When you want a position like N,S,E, or W,\
                        the mark angle should not be given.")
            self.added_objects.append(psp,mark)

        self.mark=mark
예제 #8
0
    def get_Id_value(self, Id, default_value=0):
        if Id not in self.id_values_dict().iterkeys():

            if not self.already_warned_CompileYourLaTeXFile:
                logging(self.picture.name + "-----")
                logging("Warning: the auxiliary file {} does not contain\
                        the id «{}». Compile your LaTeX file.".format(
                    self.interWriteFile.from_main(), Id),
                        pspict=self.picture)
                try:
                    logging(u"Concerned tex expression : "+\
                                self.interId_to_tex_expression[Id])
                except KeyError:
                    pass  # when asking for a counter, not a box size.

                self.already_warned_CompileYourLaTeXFile = True
            return default_value
        value = self.id_values_dict()[Id]
        return value
예제 #9
0
def Angle(A, O, B, r=None):
    raise DeprecationWarning
    from NoMathUtilities import logging
    logging("Warning : You should use 'AngleAOB' instead of 'Angle'")
    return AngleAOB(A, O, B, r=r)
예제 #10
0
    def get_mark(self,dist,angle=None,text=None,mark_point=None,\
            added_angle=None,position=None,pspict=None):
        """
        - `angle` is degree or AngleMeasure
        
        In the internal representation of the mark, 
        the angle type will be `AngleMeasure`
        """
        from AngleGraph import AngleGraph
        from Constructors import Mark
        from MathStructures import AngleMeasure

        self.marque = True
        third=None

        if position in ["N","S","E","W"] and angle is not None:
            angle=None
            logging("When you want a position like N,S,E, or W, the mark\
 angle should not be given.",pspict=pspict)


        if angle is None and position not in ["N","S","E","W"] :
            try :
                angle=self.advised_mark_angle(pspict=pspict)
            except AttributeError :
                a=self.angle()
                angle=self.angle().degree+90

        if position=="center_direction":
            # In this case we assume 'self' is a point
            angle=angle.degree

        if isinstance(angle,AngleMeasure):
            angle=angle.degree

        # At this point, 'angle' has to be degree,
        # - for the possibility of "added_angle"
        # - the constructor of 'mark' expects degree or AngleMeasure

        if added_angle: 
            angle=angle+added_angle
        if  position==None :        
            position="corner"
            alpha=AngleMeasure(value_degree=angle).positive()
            deg=alpha.degree
            if deg==0:
                position="W"
            if deg==90:
                position="S"
            if deg==180:
                position="E"
            if deg==180+90:
                position="N"

        if position in ["N","S","E","W"] :
            angle=None

        mark=Mark(graph=self,dist=dist,angle=angle,central_point=None,\
                text=text,mark_point=mark_point,position=position,pspict=pspict)

        # In each .psttricks file we need the lines that make compute
        # the size of the text. Thus we call "get_box_size" for each.
        if not isinstance(pspict,list):
            pspict=[pspict]
        for psp in pspict:
            dimx,dimy = psp.get_box_size(text)

        return mark