      A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)M       NAME>      CD - A Package of C Procedures for Managing CIF Databases     SYNOPSIS      #include "cd.h"     DESCRIPTION)B      _C_D is a package of C procedures for managing CIF (Caltech?      Intermediate Form) databases at an object level instead of(;      the standard file level.  For a description of the CIFF>      language, see chapter four of the book by Mead and Conway=      entitled Introduction to VLSI Systems and also the Xerox @      PARC technical report by Hon and Sequin entitled A Guide to?      LSI Implementation. The reader should also be aware of thetL      following terminology: _M_a_s_t_e_r refers to the definition of aD      symbol.  _I_n_s_t_a_n_c_e refers to a call of a symbol.  K      When a symbol is opened via _C_D_O_p_e_n, it is mapped into mainb@      memory from files storing one symbol definition.  Also, allA      referenced master symbols are read into main memory.  A sym- \      bol that has been opened is referenced by a _s_y_m_b_o_l _d_e_s_c_r_i_p_-G      _t_o_r defined below.  To reflect at its secondary storage site/I      the changes to a symbol that has been opened, invoke _C_D_U_p_- Z      _d_a_t_e. To make an open symbol unknown to _C_D, invoke _C_D_C_l_o_s_e.  >      The types of valid objects within a symbol are CIF boxes,@      polygons, wires, roundflashes, and symbol calls or instance@      arrays.  For each object, there is a procedure that creates=      the object in a particular symbol on a particular layer.       See _C_D_M_a_k_e_P_o_l_y_g_o_n, _C_D_M_a_k_e_W_i_r_e, _C_D_M_a_k_e_B_o_x, and _C_D_M_a_k_e_R_o_u_n_d_-'M      _F_l_a_s_h below.  The CIF _c_a_l_l has been extended to handletV      instance arrays.  To create an array, invoke _C_D_B_e_g_i_n_M_a_k_e_-i      _C_a_l_l, _C_D_T, and _C_D_E_n_d_M_a_k_e_C_a_l_l. All object creation procedures.a      return a pointer to an _o_b_j_e_c_t _d_e_s_c_r_i_p_t_o_r that can be used totQ      reference the object later.  _C_D_D_e_l_e_t_e removes an object fromx      a master cell.)  `      _B_o_u_n_d_i_n_g _b_o_x_e_s of every object  can be accessed via _C_D_B_B.`      Along with each object is an integer _i_n_f_o_r_m_a_t_i_o_n _f_i_e_l_d that>      can be used for extending that object's description.  See_      _C_D_S_e_t_I_n_f_o and _C_D_I_n_f_o. In addition to the integer information*:      field, each object can have a linked list of property      strings.  See _C_D_A_d_d_P_r_o_p_e_r_t_y, _C_D_R_e_m_o_v_e_P_r_o_p_e_r_t_y, and _C_D_P_r_o_-      _p_e_r_t_y.t        _C_D uses a _t_w_o _d_i_m_e_n_s_i_o_n_a_l, _M_a_n_h_a_t_t_a_n _t_r_a_n_s_f_o_r_m_a_t_i_o_n _p_a_c_k_a_g_eD      that the _C_D user may also invoke.  The transformation pack-?      age is discussed in detail below. With the transform pack-i<      age, you can define a current transformation, transform3      coordinates, and manage transformations with a       A Printed 9/4/83               5/20/83                            1g            A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)g            transformation stack.  [      Traversing a symbol is done easily with a _g_e_n_e_r_a_t_o_r _l_o_o_p. To O      initialize a generator, invoke _C_D_I_n_i_t_G_e_n with an area ofn>      interest and layer of interest as parameters, and it willg      return a pointer to a _g_e_n_e_r_a_t_o_r _d_e_s_c_r_i_p_t_o_r. Every invocationtJ      of _C_D_G_e_n will then return a pointer to an object descriptor?      whose bounding box, transformed by the current transforma- @      tion, intersects the area of interest and lies on the layerC      of interest.  When _C_D_G_e_n has returned all qualifyingsA      objects, it returns a null pointer to the object descriptor.X  M      _C_D_T_y_p_e returns the type of an object descriptor, (e.g., box,P?      polygon, etc.) and can be used to dispatch a type-specific +      procedure for manipulating the object.c  H      To translate a CIF file into _C_D format, invoke _C_D_T_o. ToC      translate a symbol into a CIF file, invoke _C_D_F_r_o_m.F     ERROR HANDLINGD      _C_D has a simple mechanism for handling errors.  In the fileF      _c_d._h, there are two external error variables that are allo-!      cated by _C_D_I_n_i_t._  +               extern  int      CDStatusInt; /               extern  char     *CDStatusString;e  =      If a routine encounters any difficulty, it will place anV      identifying code in _C_D_S_t_a_t_u_s_I_n_t and a pointer to diagnostic\      string in _C_D_S_t_a_t_u_s_S_t_r_i_n_g, and then return the with value ofa      _F_a_l_s_e. The possible fatal values for _C_D_S_t_a_t_u_s_I_n_t are definedo'      in the _c_d._h file as follows:h  ?      #define CDPARSEFAILED      1    /* (FATAL) parse failed */iD      #define CDNEWSYMBOL        3    /* symbol not in search path */@      #define CDMALLOCFAILED     11   /* (FATAL) out of memory */C      #define CDBADBOX           12   /* zero width or length box */_H      #define CDXFORMSTACKFULL   13   /* transformation stack overflow */I      #define CDBADPATH          14   /* bad directory name search path */u  D      Error handling in _C_D may be confusing at first because only;      those routines in which an error can occur will have ae@      returned value.  The routines in which no error is expected3      are assigned the type definition _v_o_i_d.                     A Printed 9/4/83               5/20/83                            2P            A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)        DESCRIPTOR TYPESG      There are several descriptor types defined in the _c_d._h file.i'      The four most frequently used are:n  8                    descriptor type        structure name2                    symbol                        s2                    object                        o2                    generator                     g2                    transform generator           t  A      The definition of each descriptor is given below in the sec-f)      tion concerning the _c_d._h file.n     INITIALIZATION=      An application program must include the file _c_d._h.a        void CDInit()P           _C_D_I_n_i_t must be invoked before any other _C_D procedures.A           This routine will clear the layer table, set the direc-p?           tory search path to be the present working directory,p;           initialize the transformation stack, and allocate "           storage for diagnostics.          int CDPath(Path)s      char *Path;J           _C_D_P_a_t_h sets the search rules for symbol-name resolu-F           tion.  _P_a_t_h is a pointer to a null terminated string=           containing a list of directory names to be searchedhG           separated by blanks.  In the UNIX environment, _c_s_h(_1)o)           style names will be understood.     +      void CDSetLayer(Layer,Technology,Mask)f      int Layer;t      char Technology,Mask[3];a           _C_D_S_e_t_L_a_y_e_r tells _C_D that the layer _L_a_y_e_r has the nameb           _T_e_c_h_n_o_l_o_g_y_M_a_s_k. The layer table is defined in the _c_d._h           file as follows:  -                    #define CDNUMLAYERS     35a  '                    /* CD layer table */                    struct l {-(                        char lTechnology;%                        char lMask[3];t@                        /* True if CDFrom should output layer. */$                        char lCDFrom;                        }*                    CDLayer[CDNUMLAYERS+1];        A Printed 9/4/83               5/20/83                            3             A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)e      @           _C_D can be recompiled to provide a larger number of@           layers.  Because layer numbers are stored in character?           fields, the absolute maximum number of layers is 255.,     SYMBOL MANAGEMENT_-      int CDOpen(SymbolName,SymbolDesc,Access)       char *SymbolName,Access;e      struct s **SymbolDesc;a^           _C_D_O_p_e_n opens a symbol named _S_y_m_b_o_l_N_a_m_e and returns aO           pointer _S_y_m_b_o_l_D_e_s_c to a symbol descriptor for it.e  L           _A_c_c_e_s_s is a character that determines the result after;           the current search path has been examined for the T           existence of a symbol named _S_y_m_b_o_l_N_a_m_e. If the charac-W           ter _A_c_c_e_s_s equals the character 'w', then _C_D_O_p_e_n will A           create the cell in the database if it does not exist ineK           the current search path.  In other words, _C_D_O_p_e_n willL           open the cell for writing.  If _A_c_c_e_s_s equals the char-H           acter 'r', then _C_D_O_p_e_n will create the cell in theA           database if and only if it exists in the current searcht=           path.  In other words, the symbol is only read intot<           memory.  If the cell does not exist in the current@           search path, no symbol is created in the database, andT           _S_y_m_b_o_l_D_e_s_c is assigned the value of NULL.  Finally, ifK           _A_c_c_e_s_s equals the character 'n', the symbol is openednO           regardless of whether any symbol named _S_y_m_b_o_l_N_a_m_ec<           exists in the current search path.  If such a file@           exists in the search path, it is not read into memory.2           In other words, CD creates a new symbol.  U           _C_D_O_p_e_n will call a routine _P_C_I_F to read the symbol into@           the database.  The user of _C_D must provide his own=           parser, and the parser is of course NOT required to A           understand only CIF; any language that is equivalent torE           CIF can be used.  A synopsis of _P_C_I_F is as follows:   8                PCIF(SymbolName, StatusString, StatusInt)                 char *SymbolName;                 char **StatusInt;                int *StatusInt;  C           There are three requirements for _P_C_I_F. First, the T           parser must locate and read the symbol _S_y_m_b_o_l_N_a_m_e, andB           insert the symbol definition into the _C_D database by<           using the object creation routines described belowa           (e.g., _C_D_M_a_k_e_B_o_x, _C_D_M_a_k_e_W_i_r_e, etc.).  Second, theoM           parser must use a file called _p_a_r_s_e_r._h which contains(=           the diagnostics described below.  Finally, when the E           parse is completed, _P_C_I_F must return a pointer to aoY           null terminated diagnostic string via _S_t_a_t_u_s_S_t_r_i_n_g, andK           _S_t_a_t_u_s_I_n_t must be set to a value defined in the       A Printed 9/4/83               5/20/83                            4h            A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)      1           _p_a_r_s_e_r._h file as follows:_  A           #define PSUCCEEDED         1    /* successful return */ =           #define PFAILED            2    /* parser failed */tK           #define PNOTAPPLICABLE     3    /* parser failed due to syntax */w  W           The diagnostic string _S_t_a_t_u_s_S_t_r_i_n_g may be NULL if and &           only if the parse succeeded.  W           _C_D_O_p_e_n returns with the value _F_a_l_s_e if the parse failedtJ           or if it was unable to allocate memory.  When _C_D_O_p_e_nU           returns, _C_D_S_t_a_t_u_s_I_n_t, as defined above, is set to oneTG           of the values that are defined in the _c_d._h file as fol-H           lows:   D           #define CDPARSEFAILED      1    /* (FATAL) parse failed */J           #define CDOLDSYMBOL        2    /* symbol already in database */I           #define CDNEWSYMBOL        3    /* symbol not in search path */iK           #define CDSUCCEEDED        4    /* new symbol(s) found in path */   ]           If the return is fatal, _C_D_S_t_a_t_u_s_S_t_r_i_n_g contains a diag- >           nostic message.  Only CDPARSEFAILED is returned as aV           fatal error (i.e., _C_D_O_p_e_n returns with the value _F_a_l_s_e>           ); this simplifies the diagnostic test.  However, ifM           the _A_c_c_e_s_s argument is set to 'r' and the symbol is not V           found in the search path, _C_D_O_p_e_n returns with _C_D_S_t_a_-L           _t_u_s_I_n_t set to CDNEWSYMBOL.  The application programmerA           should be aware of this since it could be considered ass%           or result in a fatal error.    )      void CDSymbol(SymbolName,SymbolDesc)o      char *SymbolName;      struct s **SymbolDesc;vP           _C_D_S_y_m_b_o_l returns a pointer to symbol descriptor if theU           symbol _S_y_m_b_o_l_N_a_m_e has been previously opened and existsn=           in memory.  If the symbol does not exist in memory,eG           _S_y_m_b_o_l_D_e_s_c is returned as a null pointer.e          int CDClose(SymbolDesc)      struct s *SymbolDesc;c           _C_D_C_l_o_s_e will remove the symbol identified by _S_y_m_b_o_l_D_e_s_cL6           from memory and any associated instances and           geometries.o                    A Printed 9/4/83               5/20/83                            5             A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)       (      int CDUpdate(SymbolDesc,SymbolName)      struct s *SymbolDesc;      char *SymbolName;O           _C_D_U_p_d_a_t_e will save any changes that have been made to R           the symbol referenced by _S_y_m_b_o_l_D_e_s_c. The output will=           appear as CIF in a file identified by the null ter-td           minated string _S_y_m_b_o_l_N_a_m_e. If _S_y_m_b_o_l_N_a_m_e is a null@           pointer, the name of the CIF file will be identical to/           the name of the symbol being updated.a     CREATING GEOMETRIES_=      int CDMakeBox(SymbolDesc,Layer,Length,Width,X,Y,Pointer)      struct s *SymbolDesc;      struct o **Pointer;       int Layer,Length,Width,X,Y;]           _C_D_M_a_k_e_B_o_x will create a box of length _L_e_n_g_t_h in the xAJ           direction and width _W_i_d_t_h in the y direction, centeredM           at _X,_Y on the layer _L_a_y_e_r in the symbol identified bysb           the descriptor _S_y_m_b_o_l_D_e_s_c. _P_o_i_n_t_e_r contains a returned?           pointer to the object descriptor of the newly createdi\           box.  _C_D_M_a_k_e_B_o_x will return with the value _F_a_l_s_e if it>           is unable to allocate storage.  Otherwise, the valueG           _T_r_u_e is returned.  Zero width or length boxes are notw           allowed.    8      int CDMakeLabel(SymbolDesc,Layer,Label,X,Y,Pointer)      struct s *SymbolDesc;      struct o **Pointer;      int Layer;w      char *Label;_
      int X,Y;_           _C_D_M_a_k_e_L_a_b_e_l will create a label on the layer _L_a_y_e_r iniU           the symbol identified by the descriptor _S_y_m_b_o_l_D_e_s_c. TheiM           label will be referenced to the coordinate _X,_Y. _L_a_b_e_lbA           is a pointer to a null terminated string containing theyJ           label.  _P_o_i_n_t_e_r contains a returned pointer to theK           object descriptor of the newly created label.  _C_D_M_a_k_-nW           _e_L_a_b_e_l will return with the value _F_a_l_s_e if it is unabletD           to allocate storage.  Otherwise, the value _T_r_u_e is           returned.    5      int CDMakePolygon(SymbolDesc,Layer,Path,Pointer)o      struct s *SymbolDesc;      struct o **Pointer;      struct p *Path;      int Layer;s[           _C_D_M_a_k_e_P_o_l_y_g_o_n will create a polygon with a linked coor-S           dinate path _P_a_t_h on the layer _L_a_y_e_r in the symbol iden- \           tified by the descriptor _S_y_m_b_o_l_D_e_s_c. _P_a_t_h is a pointer      A Printed 9/4/83               5/20/83                            6a            A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)s      @           to a linked list of x,y coordinates that is defined in)           the _c_d._h file as follows:h  .                    /* Linked path structure */                    struct p {s!                        int pX,pY;y'                        struct p *pSucc;                         };   I           _P_o_i_n_t_e_r contains a returned pointer to the object [           descriptor of the newly created polygon.  _C_D_M_a_k_e_P_o_l_y_g_o_nrG           will return with the value _F_a_l_s_e if it is unable tosA           allocate storage.  Otherwise, the value _T_r_u_e isb           returned.s    8      int CDMakeWire(SymbolDesc,Layer,Width,Path,Pointer)      struct s *SymbolDesc;      struct o **Pointer;      struct p *Path;      int Layer,Width;_[           _C_D_M_a_k_e_W_i_r_e will create a wire of width _W_i_d_t_h with a Q           coordinate path _P_a_t_h on the layer _L_a_y_e_r in the symbol X           referenced by the descriptor _S_y_m_b_o_l_D_e_s_c. _P_a_t_h is a=           pointer to a linked list of x,y coordinates that isr4           defined in the _c_d._h file as follows:  .                    /* Linked path structure */                    struct p {C!                        int pX,pY;y'                        struct p *pSucc;o                        };m  I           _P_o_i_n_t_e_r contains a returned pointer to the objectaT           descriptor of the newly created wire.  _C_D_M_a_k_e_W_i_r_e willK           return with the value _F_a_l_s_e if it is unable to allocate B           storage.  Otherwise, the value _T_r_u_e is returned.    =      int CDMakeRoundFlash(SymbolDesc,Layer,Width,X,Y,Pointer)e      struct s *SymbolDesc;      struct o **Pointer;      int Layer,Width,X,Y;u_           _C_D_M_a_k_e_R_o_u_n_d_F_l_a_s_h will create a roundflash of diametereX           _W_i_d_t_h centered at _X,_Y on the layer _L_a_y_e_r in the symbola           identified by the descriptor _S_y_m_b_o_l_D_e_s_c. _P_o_i_n_t_e_r con-t>           tains a returned pointer to the object descriptor of^           the newly created roundflash.  _C_D_M_a_k_e_R_o_u_n_d_F_l_a_s_h willK           return with the value _F_a_l_s_e if it is unable to allocate_H           storage.  Otherwise, the value _T_r_u_e is returned.  Zero0           diameter roundflashes are not allowed.        A Printed 9/4/83               5/20/83                            7             A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)        CREATING INSTANCE ARRAYSG      int CDBeginMakeCall(SymbolDesc,SymbolName,NumX,DX,NumY,DY,Pointer)s      struct s *SymbolDesc;      char *SymbolName;      struct o **Pointer;      int NumX,DX,NumY,DY; \           _C_D_B_e_g_i_n_M_a_k_e_C_a_l_l allocates memory and initializes the>           object descriptor that will represent the new symbolZ           call to the symbol _S_y_m_b_o_l_N_a_m_e. _N_u_m_X is the number ofG           instance in the untransformed x direction and _N_u_m_Y isb?           the number of instances in the untransformed y direc-WI           tion.  _D_X and _D_Y are the distances between the left and ?           right edges and the top and bottom edges respectivelyaM           of two adjacent cells in the instance array.  _P_o_i_n_t_e_r =           returns a pointer to the new object descriptor.  Ift^           _S_y_m_b_o_l_N_a_m_e is not in the current search path, or _C_D_B_e_-r           _g_i_n_M_a_k_e_C_a_l_l cannot allocate storage, _C_D_B_e_g_i_n_M_a_k_e_C_a_l_l^           returns with the value _F_a_l_s_e and _C_D_S_t_a_t_u_s_I_n_t will be>           set to one of the following values as defined in the           _c_d._h file.  D           #define CDPARSEFAILED      1    /* (FATAL) parse failed */I           #define CDNEWSYMBOL        3    /* symbol not in search path */_E           #define CDMALLOCFAILED     11   /* (FATAL) out of memory */           int CDT(Pointer,Type,X,Y)      struct o *Pointer;      char Type; 
      int X,Y;__           After invoking _B_e_g_i_n_M_a_k_e_C_a_l_l, _C_D_T is invoked for each L           transformation in the call.  _P_o_i_n_t_e_r is a pointer to@           the object descriptor that was returned by the call tob           _C_D_B_e_g_i_n_M_a_k_e_C_a_l_l. The character _T_y_p_e identifies the<           transformation to be added to the call.  The validO           arguments for _T_y_p_e are defined in the _c_d._h file as fol-t           lows:t  L           #define CDMIRRORX          'x'  /* mirror in the direction of x */L           #define CDMIRRORY          'y'  /* mirror in the direction of y */D           #define CDROTATE           'r'  /* rotate by vector X,Y */@           #define CDTRANSLATE        't'  /* translate to X,Y */  D           The integers _X and _Y are used to qualify a rotation or@           translation.  Only Manhattan rotations are valid.  ForC           a rotation of 90 degrees, _X has the value of 0, and _YMA           has the value of 1.  For a rotation of 180 degrees, _XDA           has the value of -1, and _Y has the value of 0.  For a_B           rotation of 270 degrees, _X has the value of 0, and _YC           has the value of -1.  For a translation, the integers _Xi@           and _Y are used to specify the x and y displacements,           respectively.e      A Printed 9/4/83               5/20/83                            8t            A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)s      W           Finally, _E_n_d_M_a_k_e_C_a_l_l is invoked to insert the call intoSR           the master symbol identified by _S_y_m_b_o_l_D_e_s_c. Remembers           that _t_r_a_n_s_f_o_r_m_a_t_i_o_n _o_r_d_e_r _i_s _s_i_g_n_i_f_i_c_a_n_t.     *      int CDEndMakeCall(SymbolDesc,Pointer)      struct s *SymbolDesc;      struct o *Pointer;X           _C_D_E_n_d_M_a_k_e_C_a_l_l will insert the instance identified byK           the object descriptor that is pointed to by _P_o_i_n_t_e_rFN           into the master symbol referenced by _S_y_m_b_o_l_D_e_s_c.g           _P_o_i_n_t_e_r was returned by a previous call to _C_D_B_e_g_i_n_M_a_k_e_- m           _C_a_l_l. _C_D_E_n_d_M_a_k_e_C_a_l_l will return with the value _F_a_l_s_e if_A           it is unable to allocate storage.  Otherwise, the valuey#           _T_r_u_e is returned.,    
 GENERATORSB      int CDInitGen(SymbolDesc,Layer,Left,Bottom,Right,Top,GenDesc)      struct s *SymbolDesc;      int Layer;       int Left,Bottom;r      int Right,Top;n      struct g **GenDesc;n           _C_D_I_n_i_t_G_e_n returns a pointer to a _g_e_n_e_r_a_t_o_r _s_t_o_r_a_g_eR           _d_e_s_c_r_i_p_t_o_r which is allocated automatically.  Subse-K           quent invocations of _C_D_G_e_n will return each geometry in ^           the symbol identified by _S_y_m_b_o_l_D_e_s_c on the layer _L_a_y_e_r<           whose bounding box intersects the area of interestn           given by _L_e_f_t, _B_o_t_t_o_m, _R_i_g_h_t, and _T_o_p. If _L_a_y_e_r equalsG           zero, then the subsequent invocations of _C_D_G_e_n willNA           return instances only (i.e., layer zero is the instance_\           layer).  _C_D_I_n_i_t_G_e_n will return with the value of _F_a_l_s_e;           if it is unable to allocate the generator storage H           descriptor.  Otherwise, the value of _T_r_u_e is returned.    +      void CDGen(SymbolDesc,GenDesc,Pointer),      struct s *SymbolDesc;      struct g *GenDesc;i      struct o **Pointer;I           _C_D_G_e_n returns a pointer to an object descriptor which,=           identifies an object within the area of interest as K           defined by the previous call to _C_D_I_n_i_t_G_e_n which J           returned the pointer to the descriptor _G_e_n_D_e_s_c. IfW           _C_D_G_e_n returns with _P_o_i_n_t_e_r set to NULL, then the lastM           object has been returned and _G_e_n_D_e_s_c storage has beeno           freed.              A Printed 9/4/83               5/20/83                            9m            A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)             void CDType(Pointer,Type)      struct o *Pointer;o      char *Type;H           _C_D_T_y_p_e returns the type of an object pointed to byN           _P_o_i_n_t_e_r. This information routine is typically used in@           a generator loop to dispatch a type-specific procedure#           for accessing the object.     ACCESSING GEOMETRIES/      void CDBox(Pointer,Layer,Length,Width,X,Y)t      struct o *Pointer;r$      int *Layer,*Length,*Width,*X,*YV           _C_D_B_o_x will return the length _L_e_n_g_t_h in the x directionK           and the width _W_i_d_t_h in the y direction of a box identi- L           fied by the pointer _P_o_i_n_t_e_r to an object descriptor.C           The box is centered at the coordinate _X, _Y and on thes            layer _L_a_y_e_r.    *      void CDLabel(Pointer,Layer,Label,X,Y)      struct o *Pointer;_      char **Label;      int *Layer;      int *X,*Y;iN           _C_D_L_a_b_e_l returns the pointer to a null terminated labelK           _L_a_b_e_l that has lower, left justification to the coordi-nC           nate _X,_Y and whose object descriptor is pointed to by_K           _P_o_i_n_t_e_r. The label is on the layer _L_a_y_e_r.W    '      void CDPolygon(Pointer,Layer,Path)d      struct o *Pointer;       int *Layer;      struct p **Path;nQ           _C_D_P_o_l_y_g_o_n will return a pointer to the linked coordi-.G           nate path _P_a_t_h of a polygon identified by the pointereO           _P_o_i_n_t_e_r to an object descriptor.  The polygon is on theaF           layer _L_a_y_e_r. The linked coordinate path is definedN           above in the description of _C_D_M_a_k_e_P_o_l_y_g_o_n.    *      void CDWire(Pointer,Layer,Width,Path)      struct o *Pointer;e      struct p **Path;_      int *Layer,*Width;K           _C_D_W_i_r_e will return a pointer to the linked coordinateS           path _P_a_t_h of a wire with width _W_i_d_t_h that is identifiedrL           by the pointer _P_o_i_n_t_e_r to an object descriptor.  The/           wire is on the layer _L_a_y_e_r.          A Printed 9/4/83               5/20/83                           10_            A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)G      /      void CDRoundFlash(Pointer,Layer,Width,X,Y)       struct o *Pointer;/      int *Layer,*Width,*X,*Y; c           _C_D_R_o_u_n_d_F_l_a_s_h will return the diameter _W_i_d_t_h of a round- L           flash identified by the pointer _P_o_i_n_t_e_r to an object@           descriptor.  The roundflash is centered at the coordi-9           nate _X, _Y and on the layer _L_a_y_e_r.t     ACCESSING AN INSTANCEe4      void CDCall(Pointer,SymbolName,NumX,DX,NumY,DY)      struct o *Pointer;       char **SymbolName;t      int *NumX,*DX,*NumY,*DY; U           _C_D_C_a_l_l returns the a character pointer to the name _S_y_m_-eG           _b_o_l_N_a_m_e of an instance referenced by the object_W           descriptor pointed to by _P_o_i_n_t_e_r. Also returned is _N_u_m_Xr@           which is the number of instance in the untransformed xH           direction and _N_u_m_Y which is the number of instances inH           the untransformed y direction.  _D_X and _D_Y are the dis-A           tances between the left and right edges and the top and @           bottom edges respectively of two adjacent cells in the           instance array.n    "      void CDInitTGen(Pointer,TGen)      struct o *Pointer;      struct t **TGen;jN           The pointer _P_o_i_n_t_e_r should point to an object descrip-M           tor of an instance.  _C_D_I_n_i_t_T_G_e_n initializes the_A           transformation generator loop to access the transforma- U           tions of an instance referenced by _P_o_i_n_t_e_r. _T_G_e_n is aw           returned pointer to a _t_r_a_n_s_f_o_r_m _g_e_n_e_r_a_t_o_r _d_e_s_c_r_i_p_t_o_r.hF           Subsequent invocations of _C_D_T_G_e_n will return the,           instance transformations in order.          void CDTGen(TGen,Type,X,Y)s      struct t **TGen;v      char *Type;      int *X,*Y;aK           _C_D_T_G_e_n returns a pointer to a character which identi- F           fies a transformation of the instance for which _T_G_e_nL           was returned by _C_D_I_n_i_t_T_G_e_n as a pointer to the@           transform generator descriptor.  The character pointerH           _T_y_p_e identifies a transformation that was added to theG           instance by a call to _C_D_T. The order in which transfor-rH           mations are returned by _C_D_T_g_e_n is identical to theG           order in which they were specified by calls to _C_D_T. TherF           possible returned values for _T_y_p_e are defined in the%           _c_d._h file as follows:        A Printed 9/4/83               5/20/83                           11             A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)s      L           #define CDMIRRORX          'x'  /* mirror in the direction of x */L           #define CDMIRRORY          'y'  /* mirror in the direction of y */D           #define CDROTATE           'r'  /* rotate by vector X,Y */@           #define CDTRANSLATE        't'  /* translate to X,Y */  E           The integer pointers _X,_Y are used to specify a rotationn@           or translation.  For a rotation of 90 degrees, _X hasA           the returned value of 0, and _Y has the returned valuea;           of 1.  For a rotation of 180 degrees, _X has the A           returned value of -1, and _Y has the returned value ofaA           0.  For a rotation of 270 degrees, _X has the returned_B           value of 0, and _Y has the returned value of -1.  For aE           translation, the returned values of _X and _Y specify the*M           x and y displacements, respectively.  If _C_D_T_G_e_n returnshI           with _T_G_e_n set to NULL, then the last transformation has @           been returned and _T_G_e_n storage has been freed.     INFORMATION ROUTINES7      int CDBB(SymbolDesc,Pointer,Left,Bottom,Right,Top)       struct s *SymbolDesc;      struct o *Pointer; #      int *Left,*Bottom,*Right,*Top;oG           _C_D_B_B returns the bounding box of an object pointed tota           by _P_o_i_n_t_e_r in the symbol identified by _S_y_m_b_o_l_D_e_s_c. If_W           _P_o_i_n_t_e_r is a null pointer, then _C_D_B_B returns the bound- '           ing box of the entire symbol.  H           _C_D_B_B may have to use temporary storage during the com-<           putation of a symbols bounding box.  If it can notE           allocate the required memory, _C_D_B_B returns with thehK           value of _F_a_l_s_e. Otherwise, the value of _T_r_u_e ish           returned.     )      void CDInfo(SymbolDesc,Pointer,Info)      struct s *SymbolDesc;      struct o *Pointer;o      int *Info;eS           _C_D_I_n_f_o returns the value _I_n_f_o of the info field of an X           object referenced by _P_o_i_n_t_e_r. If _P_o_i_n_t_e_r is a nullA           pointer, then the value of the info field of the symbol C           referenced by _S_y_m_b_o_l_D_e_s_c is returned.r                        A Printed 9/4/83               5/20/83                           12_            A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)       ,      void CDSetInfo(SymbolDesc,Pointer,Info)      struct s *SymbolDesc;      struct o *Pointer;       int Info;R           _C_D_S_e_t_I_n_f_o sets the info field the object pointed to byZ           _P_o_i_n_t_e_r. If _P_o_i_n_t_e_r is a null pointer, then the infoR           field of the symbol referenced by _S_y_m_b_o_l_D_e_s_c is set.    1      void CDProperty(SymbolDesc,Pointer,Property)a      struct s *SymbolDesc;      struct o *Pointer;i      struct prpty **Property;ee           _C_D_P_r_o_p_e_r_t_y returns the pointer _P_r_o_p_e_r_t_y which points tor;           the linked list of properties associated with theeX           object referenced by _P_o_i_n_t_e_r. If _P_o_i_n_t_e_r is a null>           pointer, then the property list of the symbol refer-c           enced by _S_y_m_b_o_l_D_e_s_c is returned. The pointer _P_r_o_p_e_r_t_y ?           is returned as a null pointer if there is no property 5           list associated with the particular object.   G           The property list structure is defined in the _c_d._h filea           as follows:   ,                    /* Property List desc. */!                    struct prpty { '                        int prpty_Value;i*                        char *prpty_String;0                        struct prpty *prpty_Succ;                        };   =           A property consists of an identifying integer and aA           null terminated character string extension.  The linkedaQ           list of properties is terminated by a null _p_r_p_t_y__S_u_c_cr@           pointer.  Properties are assigned to an object or sym-F           bol via the _C_D_A_d_d_P_r_o_p_e_r_t_y routine.    7      int CDAddProperty(SymbolDesc,Pointer,Value,String)i      struct s *SymbolDesc;      struct o *Pointer;r      char *String;      int Value;aW           _C_D_A_d_d_P_r_o_p_e_r_t_y inserts property information into therM           property list of the object pointed to by _P_o_i_n_t_e_r. IfnM           _P_o_i_n_t_e_r is a null pointer, then the property is addedtG           to the property list of the symbol referenced by _S_y_m_-iN           _b_o_l_D_e_s_c. The property information consists of an iden-I           tifying integer _V_a_l_u_e and a null terminated characteraG           string extension that is pointed to by _S_t_r_i_n_g. If d           _C_D_A_d_d_P_r_o_p_e_r_t_y can not allocate memory, the value _F_a_l_s_eI           is returned.  Otherwise, the value of _T_r_u_e is returned.       A Printed 9/4/83               5/20/83                           13d            A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)_      3      int CDRemoveProperty(SymbolDesc,Pointer,Value)r      struct s *SymbolDesc;      struct o *Pointer;       int Value;f`           _C_D_R_e_m_o_v_e_P_r_o_p_e_r_t_y deletes property information from theM           property list of the object pointed to by _P_o_i_n_t_e_r. If O           _P_o_i_n_t_e_r is a null pointer, then the property is removednI           from the property list of the symbol referenced by _S_y_m_- T           _b_o_l_D_e_s_c. Every property with the value of _V_a_l_u_e isa           removed.  If _C_D_R_e_m_o_v_e_P_r_o_p_e_r_t_y has trouble allocating oriJ           releasing memory, the value _F_a_l_s_e is returned.  Other-6           wise, the value of _T_r_u_e is returned.     OBJECT DELETION &      void CDDelete(SymbolDesc,Pointer)      struct s *SymbolDesc;      struct o *Pointer;t]           _C_D_D_e_l_e_t_e will remove the object pointed to by _P_o_i_n_t_e_r G           from the symbol referenced by _S_y_m_b_o_l_D_e_s_c.     	 INTEGRITY       int CDReflect(SymbolDesc)      struct s *SymbolDesc;T           _C_D_R_e_f_l_e_c_t must be invoked at certain times by the _C_DO           application if the symbol that is referenced by _S_y_m_b_o_l_-oF           _D_e_s_c is modified.  If the modification to the symbolR           has changed its bounding box, a call to _C_D_R_e_f_l_e_c_t willA           update the bounding box information in every other sym-d<           bol in the _C_D database that either directly orD           indirectly references it.  The value of _F_a_l_s_e isS           returned if _C_D_R_e_f_l_e_c_t is unable to allocate new memory.t;           Otherwise, the value of _T_r_u_e is returned.     TRANSLATING TO AND FROM CIF '      int CDTo(CIFFile,Root,A,B,Program),      char *CIFFile,*Root;t
      int A,B;t      char Program;W           _C_D_T_o translates from a CIF file named _C_I_F_F_i_l_e into sym-o=           bol files, each having a file name identical to the=           symbol that it contains.  CIF commands that are notnA           between a DS and a matching DF are stored in file namedDD           _R_o_o_t. All objects are scaled by the ratio _A/_B.  M           _C_D_T_o will call a routine _P_C_I_F to read the input CIFe>           file.  The requirements of this parser are discussed9           above in the description of _C_D_O_p_e_n.o          A Printed 9/4/83               5/20/83                           14l            A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)       ?           Because each program embeds symbol names differently,yS           the character _P_r_o_g_r_a_m will tell _C_D_T_o and the parser I           _P_C_I_F which program generated the CIF file.  Before cal- V           ling the parser, _C_D_T_o sets the _d_P_r_o_g_r_a_m character inQ           the _C_D parameters structure to the character _P_r_o_g_r_a_m.e@           By accessing this structure element, the parser deter->           mines the origin of the CIF.  See the section on theJ           _c_d._h file for a description of the _C_D parameter struc-L           ture.  The following arguments for _P_r_o_g_r_a_m are validS           for the parser in ~_c_a_d/_s_r_c/_k_i_c/_p_a_r_s_e_r._c :i  5                        Program          CIF generatore5                           'a'           Stanford CIF, 0                           'b'           NCA CIF,1                           'h'           HP's IGS,r7                           'i'           Xerox's Icarus,27                           'k'           Berkeley's KIC, 9                           'm'           Mextra-style CIF, 4                           's'           Xerox's Sif,:                           'n'           none of the above.  F           If _C_D_T_o encounters any difficulty in the CIF conver-`           sion, the value of _F_a_l_s_e is retuned and _C_D_S_t_a_t_u_s_I_n_t isZ           set to value of _C_D_P_A_R_S_E_F_A_I_L_E_D and a diagnostic messageB           is placed in _C_D_S_t_a_t_u_s_S_t_r_i_n_g.    :      int CDFrom(Root,CIFFile,A,B,Layers,NumLayers,Program)!      char *Root,*CIFFile,Program;      int *Layer,NumLayers;
      int A,B;_J           _C_D_F_r_o_m translates a symbol hierarchy rooted with theT           symbol named _R_o_o_t into a CIF file named _C_I_F_F_i_l_e. TheI           style of CIF output is identified by the character _P_r_o_-sO           _g_r_a_m. See the description of the _C_D_T_o procedure for apL           list of valid arguments for _P_r_o_g_r_a_m. All objects areB           scaled by the ratio _A/_B. All instances in the symbol:           hierarchy must exist in the current search path.  R           The _L_a_y_e_r_s argument is a pointer to an array of _N_u_m_-M           _L_a_y_e_r_s integers that are used to mask certain layers incK           CD layer table.  If _L_a_y_e_r_s[ N ] is zero, where N is amN           non-negative integer less than _N_u_m_L_a_y_e_r_s, then any>           object that is on layer N will not appear in the CIF           output.t  L           If _C_D_F_r_o_m encounters any difficulty in the conversion,a           the value of _F_a_l_s_e is retuned and _C_D_S_t_a_t_u_s_I_n_t is set to_E           one of the following values defined in the _c_d._h file:_            A Printed 9/4/83               5/20/83                           15e            A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)       D           #define CDPARSEFAILED      1    /* (FATAL) parse failed */I           #define CDNEWSYMBOL        3    /* symbol not in search path */ E           #define CDMALLOCFAILED     11   /* (FATAL) out of memory */  J           If no difficulty is encountered, _C_D_F_r_o_m returns with$           the value of _T_r_u_e.    )      int CDParseCIF(Root,CIFFile,Program) !      char *Root,*CIFFile,Program; U           _C_D_P_a_r_s_e_C_I_F will construct a _C_D database rooted at a W           symbol named _R_o_o_t from a CIF file _C_I_F_F_i_l_e rather than a ?           hierarchy of symbol files.  The style of CIF input iseM           identified by the character _P_r_o_g_r_a_m. See the descrip- F           tion of the _C_D_T_o procedure for a list of valid argu-*           ments for _P_r_o_g_r_a_m.  T           When _C_D_P_a_r_s_e_C_I_F encounters a reference to a layer that?           was not previously defined in the CD layer table by apU           call to _C_D_S_e_t_L_a_y_e_r, the new layer is added to the layerAV           table.  This differs from the _C_D_F_r_o_m and _C_D_O_p_e_n rou-<           tines that will return CDPARSEFAILED whenever they>           encounter an undefined layer.  A layer is consideredR           undefined if the _l_T_e_c_h_n_o_l_o_g_y field in the CD layerA           table is a blank character.  See the above section that0           describes the initialization routines.  T           If _C_D_P_a_r_s_e_C_I_F encounters any difficulty in the conver-`           sion, the value of _F_a_l_s_e is retuned and _C_D_S_t_a_t_u_s_I_n_t isF           set to one of the following values defined in the _c_d._h           file:r  D           #define CDPARSEFAILED      1    /* (FATAL) parse failed */I           #define CDNEWSYMBOL        3    /* symbol not in search path */E           #define CDMALLOCFAILED     11   /* (FATAL) out of memory */l  Q           If no difficulty is encountered, _C_D_P_a_r_s_e_C_I_F returnsi)           with the value of _T_r_u_e.t     EXAMPLE A      The following pseudo C routine is an example of traversing a R      symbol called _S_y_m_b_o_l_N_a_m_e. Traversal in this case means toA      access the description of all objects that lie in an area ofn>      interest in a symbol. The computations performed with the@      accessed descriptions will depend of course on the applica-
      tion.                A Printed 9/4/83               5/20/83                           16o            A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)n      /      Traverse(SymbolName,Left,Bottom,Right,Top)I          char *SymbolName;#          int Left,Bottom,Right,Top;B
          {          struct s *SymbolDesc;          struct o *Pointer;           struct g *GenDesc;n          char *InstanceName;'          int NumX,NumY,DX,DY,X,Y,Layer;          char Type;a  K          /* Open symbol named SymbolName (we assume here that it exists) */n,          CDOpen(SymbolName,&SymbolDesc,'r');  I          /***************************************************************_
          *(          * Traverse the instances first.D          * Layer # 0 is the instances layer, because it doesn't makeJ          * sense for an instance to be associated with a particular layer.
          *E          * First, initialize the generator loop so the generator will B          * return all instances whose bounding boxes intersect the          * area of interest.
          *J          ****************************************************************/  @          CDInitGen(SymbolDesc,0,Left,Bottom,Right,Top,&GenDesc);            loop {lH              /* Invoke CDGen to access a pointer to an instance array */0              CDGen(SymbolDesc,GenDesc,&Pointer);  :              /* Have all instances have been traversed? */               if(Pointer == NULL)                  break;e  ,              /* Access the instance array */?              CDCall(Pointer,&InstanceName,&NumX,&DX,&NumY,&DY);F  E              /*******************************************************               *G              * This instance array calls the symbol named InstanceName.*D              * Recursively invoke Traverse to traverse InstanceName.              *F              ********************************************************/:              Traverse(InstanceName,Left,Bottom,Right,Top);              }                A Printed 9/4/83               5/20/83                           17             A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)o      I          /*************************************************************** 
          *1          * Now, traverse the geometries by layer.m
          *J          ****************************************************************/8          for(Layer = 1; Layer <= CDNUMLAYERS; ++Layer) {  0              /* Initialize the generator loop */H              CDInitGen(SymbolDesc,Layer,Left,Bottom,Right,Top,&GenDesc);                loop {2B                  /* Invoke CDGen to access pointer to an object */4                  CDGen(SymbolDesc,GenDesc,&Pointer);  %                  /* Last geometry? */t$                  if(Pointer == NULL)                      break;T  >                  /* Access the type of the geometry as Type */'                  CDType(Pointer,&Type);n  G                  /* Dispatch according to Type to specific procedure */ $                  if(Type == CDBox) {%                      /* Access box */e/                      CDBox(Pointer,&Layer,...);&/                      /* Compute with the box */*                           .*                           .                            .e                      }*                  else if(Type == CDWire) {&                      /* Access wire */0                      CDWire(Pointer,&Layer,...);0                      /* Compute with the wire */                           .                            .n                           .r                      }                       .*                       .*                      etc.*                       .                        .D                  }              }
          }                  A Printed 9/4/83               5/20/83                           18             A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)s       STORAGE BINSH      All objects contained within a symbol are stored in _b_i_n_s. A=      pointer to these storage bins is contained in the symbollA      descriptor, and each symbol has it's own storage bins.  This*<      section will present a brief description of the storage      algorithm.   C      The world coordinate system in _C_D ranges from CDBINMINX to ?      CDBINMAXX in the x-direction, and from CDBINMINY to CDBIN- E      MAXY where these values are defined in the _c_d._h file.  The @      world coordinate system is covered by an array of CDNUMBINS>      by CDNUMBINS storage bins (the number if bins is always a?      perfect square).  There is an additional storage bin which6      is called the _r_e_s_i_d_u_a_l _b_i_n.  ?      Each storage bin contains the starting pointer to a linkedi=      list of object descriptors, those objects which are con-.?      tained in that particular bin.  When an object is insertedf@      into a bin as a result of a call to one of the object crea-@      tion routines described above, it is inserted at the top of?      the linked list.  The bin into which an object is inserted A      depends on the bounding box of that object.  If the boundingy=      box intersects an area covered by more than one bin, the >      object is inserted into the residual bin.  Otherwise, the?      object is inserted into the bin that contains the boundingy      box of the object.u  B      If _C_D is compiled with a large number of bins, it will be@      able to traverse a symbol hierarchy very rapidly.  However,;      a large number of storage bins also means that a large D      amount of memory must be dedicated to the bin pointers.  _C_D@      allocates the memory for storage bins on demand; this means@      that the memory requirements for the storage bins is also a?      function of the number of layers being used in the symbol.   A      The values of CDBINMAXX, CDBINMINX, CDBINMAXY, and CDBINMINYn<      should be as small as possible while still reflecting aB      realistic working area for the _C_D application.  This willA      insure that every storage bin will be used.  _C_D will not5C      fail if the real working area exceeds _C_D'_s range for the =      world coordinate system.  Objects that exist outside the/@      world coordinate system of _C_D will be inserted into the      outer-most bins.N    . PROCEDURES FOR TWO DIMENSIONAL TRANSFORMATIONS?      The following routines provide two dimensional transforma-*>      tions using integer arithmetic.  The source to these rou-R      tines can be found in ~_c_a_d/_s_r_c/_k_i_c. The package of routines@      includes such capabilities as translation, mirroring, rota-?      tion, a transformation stack, and inverse transformations.rA      For a further discussion of these procedures, see Newman andT      A Printed 9/4/83               5/20/83                           19N            A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)a      A      Sproull's text Principles of Interactive Computer Graphics .t    ' INITIALIZATION OF THE TRANSFORM PACKAGEb      void TInit() G           _T_I_n_i_t initializes the transform package and returnsa:           with the current transform equal to the identity           transform.     THE CURRENT TRANSFORMATION      void TIdentity()eM           _T_I_d_e_n_t_i_t_y sets the current transform the identity ?           matrix.  The previous current transform is destroyed.           void TTranslate(X,Y)a
      int X,Y; R           _T_T_r_a_n_s_l_a_t_e postmultiplies the current transformationA           matrix by a transform that translates by a displacement            of _X,_Y .          void TMY().G           _T_M_Y postmultiplies the current transformation matrix byb@           a transform that mirrors the y-coordinates (i.e., mir-/           rors in the direction of the y axis).           void TMX()yG           _T_M_X postmultiplies the current transformation matrix byb@           a transform that mirrors the x-coordinates (i.e., mir-/           rors in the direction of the x axis).o    (      void TRotate(XDirection,YDirection)      int XDirection,YDirection;tI           _T_R_o_t_a_t_e postmultiplies the current transformationaA           matrix by a transform that rotates counter-clockwise byi=           an angle that is expressed as a CIF-style directioni<           vector.  Only 0, 90, 180, 270 degree rotations are           allowed.          void TPoint(X,Y)       int *X,*Y; N           _T_P_o_i_n_t transforms the point _X,_Y by multiplying it by,           the current transformation matrix.              A Printed 9/4/83               5/20/83                           20            A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)/       THE TRANSFORMATION STACK      int TEmpty()sT           _T_E_m_p_t_y returns the value of _T_r_u_e if the transformationE           stack is empty.  Otherwise, the value of _F_a_l_s_e is            returned.L          int TFull()Q           _T_F_u_l_l returns the value of _T_r_u_e if the transformation D           stack is full.  Otherwise, the value of _F_a_l_s_e is           returned.           void TPush()CK           _T_P_u_s_h pushes the current transform onto the transforma-D@           tion stack.  The value of the current transform is not?           changed.  The transformation stack is not checked for             an overflow condition.          void TPop()I           _T_P_o_p pops the current transform from the transformationh@           stack.  The value of the current transform becomes theA           transform that was most recently pushed onto the stack. ?           The transformation stack is not checked for an under-o           flow condition.           void TCurrent(TF)
      int *TF; P           _T_C_u_r_r_e_n_t places the current transform matrix in a nine@           integer array that is passed from the calling program.?           The first row of the transformation matrix appears as >           the first three integers in the argument, the second>           row of the transformation matrix appears as the next=           three integers, etc.  After several transformations f           have been defined by _T_T_r_a_n_s_l_a_t_e(), _T_R_o_t_a_t_e(), _T_M_X(),E           and _T_M_Y(), one can determine the minimum resultant or >           equivalent transformation through the examination of>           the elements of the current transformation matrix as+           described in the following table.n                            A Printed 9/4/83               5/20/83                           21l            A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)i      0           TF[0] TF[3] TF[1] TF[4] Transformation1              1     0     0     1  Translate only. <              0    -1     1     0  Rotate 90 deg., translate.=              0     1    -1     0  Rotate 180 deg., translate. =             -1     0     0    -1  Rotate 270 deg., translate.9             -1     0     0     1  Mirror in X, translate. 9              1     0     0    -1  Mirror in Y, translate.nI              0    -1    -1     0  Mirror in X, rotate 90 deg., translate. J              0     1     1     0  Mirror in X, rotate 270 deg., translate.    ?           For all cases, the X,Y translation vector is given by_           TF[6], TF[7].     THE INSTANCE TRANSFORMATION       void TPremultiply()X           _T_P_r_e_m_u_l_t_i_p_l_y forms the instance transform by multiply-?           ing the current transform with the transform that wase?           last pushed onto the transformation stack and placingo;           the product in the current transformation matrix.sA           Thus, the procedure for transforming the coordinates ofh,           an instance is demonstrated below:    :                /* push master cell transform onto stack */                TPush();h  6                /* set current transform to identity */                TIdentity();_  M                /* Invoke TMX, TTranslate, etc. to build instance transform */u                TMX();o!                TTranslate(Dx,Dy);   0                /* Form the instance transform */                TPremultiply();  ?                /* Invoke TPoint to transform instance points */v                TPoint(&X,&Y);   /                /* return to master transform */r                TPop();    ! INVERSE OF CURRENT TRANSFORMATION       void TInverse()P           _T_I_n_v_e_r_s_e computes the inverse transform of the current           transform.            A Printed 9/4/83               5/20/83                           22x            A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)i            void TInversePoint(X,Y)      int *X,*Y;]           _T_I_n_v_e_r_s_e_P_o_i_n_t transforms the point _X,_Y by multiplyingr=           it by the inverse transform matrix.  A call to thistI           routine must be preceded by a call to _T_I_n_v_e_r_s_e.f     ANOTHER EXAMPLE ;      To illustrate the use of the transform package, let us O      modify the routine _T_r_a_v_e_r_s_e shown earlier. The new routine <      is intended to display a symbol on a graphics terminal.A      When each object is accessed, it will be clipped to the arean      of interest and displayed.1        main(){               .0               .0               . .          /* initialize transformation stack */          TInit();s               .                .                .lE          /* display SymbolName in the area Left,Bottom - Right,Top */F2          Display(SymbolName,Left,Bottom,Right,Top)               .e               .a               .a
          }  .      Display(SymbolName,Left,Bottom,Right,Top)          char *SymbolName;#          int Left,Bottom,Right,Top;I
          {          struct s *SymbolDesc;          struct g *GenDesc;o          struct o *Pointer;a          struct t *TGen;          char *InstanceName;'          int NumX,NumY,DX,DY,X,Y,Layer;Y          char Type;  F          /* open symbol named SymbolName (here we assume it exists) */,          CDOpen(SymbolName,&SymbolDesc,'r');  E          /* initialize generator to return instances in SymbolName */_@          CDInitGen(SymbolDesc,0,Left,Bottom,Right,Top,&GenDesc);                A Printed 9/4/83               5/20/83                           23i            A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)i                loop {mH              /* Invoke CDGen to access a pointer to an instance array */0              CDGen(SymbolDesc,GenDesc,&Pointer);  5              /* Have all instances been traversed? */                if(Pointer == NULL)                  break;t  4              /* push current transform onto stack */              TPush();   4              /* set current transform to identity */              TIdentity();t  .              /* Access instance information */?              CDCall(Pointer,&InstanceName,&NumX,&DX,&NumY,&DY);i  K              /* Initialize generator to return transform of InstanceName */0'              CDInitTGen(Pointer,&TGen);   J              /* place instance transformation in current transformation */              loop {r.                  CDTGen(&TGen, &Type, &X, &Y);!                  if(TGen == NULL)7                      break; -                  else if(Type == CDTRANSLATE)s&                      TTranslate(X, Y);+                  else if(Type == CDMIRRORX)e                      TMX();+                  else if(Type == CDMIRRORY)N                      TMY();t*                  else if(Type == CDROTATE)#                      TRotate(X, Y);_                  }  E              /* Combine transform of InstanceName with it's master */p              TPremultiply();  L              /* recursively call display to traverse and display instance */9              Display(InstanceName,Left,Bottom,Right,Top);   2              /* pop master transform from stack */              TPop();              }  *          /* now traverse the geometries */8          for(Layer = 1; Layer <= CDNUMLAYERS; ++Layer) {  M              /* Set the current color to be a color associated with Layer. */               SetColor(Layer);           A Printed 9/4/83               5/20/83                           24             A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)s      7              /* initialize generator for layer Layer */rH              CDInitGen(SymbolDesc,Layer,Left,Bottom,Right,Top,&GenDesc);                loop {DB                  /* Invoke CDGen to access pointer to an object */4                  CDGen(SymbolDesc,GenDesc,&Pointer);  #                  /* Last object? */ $                  if(Pointer == NULL)                      break;*  >                  /* Access the type of the geometry as Type */'                  CDType(Pointer,&Type);   G                  /* Dispatch according to Type to specific procedure */ $                  if(Type == CDBox) {)                      /* Access the box */ /                      CDBox(Pointer,&Layer,...);s6                      /* Transform the box's center. */#                      TPoint(&X,&Y);i+                      /* Display the box. */(2                      DisplayBox(X,Y,Length,Width);                      })                  else if(Type == CDWire){)*                      /* Access the wire */0                      CDWire(Pointer,&Layer,...);                           .n                           .C                           .m                      }                       .g                       .o                      etc.                        .e                       .                   }              }
          }                                  A Printed 9/4/83               5/20/83                           25             A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)       
 THE CD.H FILE ;      The following lists all relevant definitions containedT       within the _c_d._h file.        #include <stdio.h>       #include <math.h>?      #include "nmalloc.h"             /* new malloc routines */f>      #include "macros.h"              /* user macro package */    G      #define FILENAMESIZE       16    /* maximum size of a file name */s          /*rG       * Values routines return in StatusInt of CDOpen, CDBeginMakeCall, $       * CDTo, CDFrom, or CDParseCIF.       */@      #define CDPARSEFAILED      1     /* (FATAL) parse failed */F      #define CDOLDSYMBOL        2     /* symbol already in database */E      #define CDNEWSYMBOL        3     /* symbol not in search path */TG      #define CDSUCCEEDED        4     /* new symbol(s) found in path */           /*T%       * Valid arguments to CDError().        */A      #define CDMALLOCFAILED     11    /* (FATAL) out of memory */ D      #define CDBADBOX           12    /* zero width or length box */D      #define CDXFORMSTACKFULL   13    /* transform stack overflow */M      #define CDBADPATH          14    /* bad directory name in search path */e          /*        * Types of geometriesu       */#      #define CDSYMBOLCALL       'c' #      #define CDPOLYGON          'p'/#      #define CDROUNDFLASH       'r' #      #define CDLABEL            'l'D#      #define CDWIRE             'w'l#      #define CDBOX              'b'i          /*n        * Types of transformations       */H      #define CDMIRRORX          'x'   /* mirror in the direction of x */H      #define CDMIRRORY          'y'   /* mirror in the direction of y */@      #define CDROTATE           'r'   /* rotate by vector X,Y */<      #define CDTRANSLATE        't'   /* translate to X,Y */          A Printed 9/4/83               5/20/83                           26             A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)             /*m-       * CD Control flags; See struct d below.d       */#      #define DCONTROLCDOPEN     'o' #      #define DCONTROLCDTO       't't#      #define DCONTROLVANILLA    'v'o          /*s?       * Coordinate system with 1 micron features and 1 cm dice. 9       * Remember that there are 100 CIF units per micron.        */)      #define INFINITY           100000000           /* K       * These are the numbers that CD uses to determine which bin an object K       * resides in.  They should reflect the average size of a layout being G       * edited by KIC.  KIC will not fail if the numbers are too small. F       * Anything outside of this window is placed in the residual bin.J       * If these numbers become too large, CDIntersect() must use floating       * point calculations..       */&      #define CDBINMAXX          500000&      #define CDBINMAXY          500000.      #define CDBINMINX          ( -CDBINMAXX ).      #define CDBINMINY          ( -CDBINMAXY )          /*l       * PLEASE NOTE/       * ^^^^^^^^^^^uI       * Because a char is used as the layer and info fields, the absolutemA       * maximum number of layers is 255.  This may be increase by*E       * recompiling kic with the Layer and Info fields typed as ints.o       */"      #define CDNUMBINS          12"      #define CDNUMLAYERS        35          /*TH       * Number of symbols stored in the symbol table for any given cell.       */$      #define CDNUMREMEMBER      1000          /* -       * Storage for diagnostics of CDError().A       */#      extern  char  *CDStatusString;       extern  int  CDStatusInt;        A Printed 9/4/83               5/20/83                           27f            A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)a            /*        * Master list desc.e       */      struct m {i          int mReferenceCount; '          int mLeft,mBottom,mRight,mTop;e          char *mName;            struct m *mPred,*mSucc;          };           /*R       * Property List desc.i       */      struct prpty {           int prpty_Value;t          char *prpty_String;"          struct prpty *prpty_Succ;          };e          /*        * Symbol desc.       */      struct s {r'          int sLeft,sBottom,sRight,sTop;e          int sBBValid;          int sA,sB;           char *sName;T          short sInfo;*          /* ?           * One bin for each layer.  Layer 0 is for call descs. D           * Each bin points to a double linked list of object descs.M           * Bin[.][0][0] are the RESIDUAL bins--Bin[.][0][1] and Bin[.][1][0]u?           * are unused.  NumBins should be as big as it can be. 1           * For 20 layers and 100 bins per layer,T2           * the data structure becomes 2000 words.           */)          struct o ***sBin[CDNUMLAYERS+1];e          struct m *sMasterList; "          struct prpty *sPrptyList;          };                           A Printed 9/4/83               5/20/83                           28             A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)             /*        * Object desc.       */      struct o {''          int oLeft,oBottom,oRight,oTop;           char oType;          char oLayer;y          short oInfo;I           struct o *oPred,*oSucc;          struct o *oRep;"          struct prpty *oPrptyList;          };C          /*s       * Polygon desc./       */      struct po {          struct p *poPath;          };           /*o       * Round flash desc.        */      struct r {           int rWidth,rX,rY;          };           /*e       * Wire desc.       */      struct w {           int wWidth;          struct p *wPath;           };r          /*t       * Call desc.       */      struct c {y          int cNum;4          /* Pointer to transformation descriptor. */          struct t *cT;1          /* Pointer to master list descriptor. */o          struct m *cMaster;            /* Array parameters. */!          int cNumX,cNumY,cDX,cDY;           };         A Printed 9/4/83               5/20/83                           29             A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)             /*C       * Transform desc.;>       * If MX, tType == CDMIRRORX.  If MY, tType == CDMIRRORX.D       * If R, tType == CDROTATE, tX == XDirection, tY == YDirection.6       * If T, tType == CDTRANSLATE, tX == TX, tY = TY;       */      struct t {0          char tType;          int tX,tY;u          struct t *tSucc;m          };           /*        * Label desc.e       */      struct la {          char *laLabel;           int laX,laY;           };f          /*m       * Linked path structuren       */      struct p {o          int pX,pY;s          struct p *pSucc;e          };m          /*C       * Generator desc.a&       * Search Bin[Layer][0][0] first.4       * Then Bin[Layer][BeginX..EndX][BeginY..EndY].,       * Bin[Layer][X][Y] is the current bin.>       * Pointer points to the current desc in the current bin.       */      struct g { (          int  gLeft,gBottom,gRight,gTop;0          int  gBeginX,gX,gEndX,gBeginY,gY,gEndY;          char gLayer;           struct o *gPointer;          };0                      A Printed 9/4/83               5/20/83                           30             A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)r            /* %       * CD's current parameter struct        */      struct d {           /*32           * DCONTROLCDOPEN denotes CD is in CDOpen.           * DCONTROLCDTO denotes CD is in CDTo>           * DCONTROLVANILLA denotes CD is in none of the above           */          char dControl;   D          /* Current parameters for symbol being parsed in CDOpen. */"          int  dNumX,dDX,dNumY,dDY;  1          /* Scale factors for CDTo and CDFrom. */o          int dA,dB;   $          /* Symbol scale factors. */          int dDSA,dDSB;e            struct o *dPointer;          struct s *dSymbolDesc; !          struct s *dRootCellDesc;n  ;          /* UNIX file names are limited to 14 characters */,(          char dSymbolName[FILENAMESIZE];          FILE *dSymbolFileDesc;c            /* '           * Fields used in CDTo follow.            */  +          /* True if parsing root symbol. */           int dRoot;              /* Root's file desc. */          FILE *dRootFileDesc;   <          /* Current property list for symbol being parsed */"          struct prpty *dPrptyList;            /* 2           *    dProgram   ==  'h' if IGS gened it.5           *    dProgram   ==  'i' if Icarus gened it. 2           *    dProgram   ==  's' if Sif gened it.7           *    dProgram   ==  'n' if none of the above.C           */          char dProgram;f              A Printed 9/4/83               5/20/83                           31             A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)T                /*            * Symbol name table.N           * 16 comes from the fact that a UNIX file name is only 14 charactersN           * long and each symbol name is a UNIX file name.  VMS file names are           * smaller.           */8          char dSymTabNames[CDNUMREMEMBER][FILENAMESIZE];+          int dSymTabNumbers[CDNUMREMEMBER];           int dNumSymbolTable;             /*uI           * Because CIF files may have FORWARD references, CDTo must passB$           * over the CIF file TWICE.F           * On the first pass, it just fills up the symbol name table.F           * On the second pass, it does the translation to KIC format.           */          int dFirstPass;            /*/           * True if debugging.           */          int dDebug;"          int dNumSymbolsAllocated;
          }      CDDesc;          /*h       * CD layer table       */      struct l {h          char lTechnology;          char lMask[3]; 0          /*True if CDFrom should output layer.*/          char lCDFrom;
          }      CDLayer[CDNUMLAYERS+1];          /*b:       * Hash table of symbol descs keyed on symbol's name.       */      struct bu {           struct s *buSymbolDesc;          struct bu *buPred;           struct bu *buSucc;i          };t+      struct bu *CDSymbolTable[CDNUMLAYERS];3              A Printed 9/4/83               5/20/83                           32             A CD(CAD3)            UNIX Programmer's Manual             CD(CAD3)t       BUGS:      Labels can cause difficulty to an application program?      because _C_D has no notion of font size.  Therefore, thee=      bounding box of a label is the lower, left coordinate toR"      which the label is justified.     FILESs      ~cad/src/kic/cd.c      ~cad/src/kic/cd.h      ~cad/src/kic/actions.c       ~cad/src/kic/parser.c      ~cad/src/kic/parser.h      ~cad/src/kic/paths.c       ~cad/src/kic/xforms.c      ~cad/src/kic/xforms.h     SEE ALSO      kic(CAD1)     AUTHOR      Giles Billingsley                                                              A Printed 9/4/83               5/20/83                           33       