Institut de Robòtica i Informàtica Industrial
KRD Group

The CuikSuite Project

readworld.y

Go to the documentation of this file.
00001 %{ 
00003 #include "world.h"
00004 
00005 #include "boolean.h"
00006 #include "error.h"
00007 #include "error_world.h"
00008 #include "constants.h"
00009 #include "defines.h"
00010 #include "color.h"
00011 #include "htransform.h"
00012 #include "vector.h"
00013 
00014 #include <stdlib.h> 
00015 #include <stdio.h>
00016 #include <string.h>
00017 #include <math.h>
00018 
00019 
00020 /*
00021 * Definition of the function that initilizes a kinematic equations from a file.
00022 * This is a method of the equations object.
00023 */
00024 
00025   /*Lex and Yacc variables*/
00026   extern FILE *ReadWorldin; 
00027 
00028   /*Lex and Yacc functions*/
00029   int ReadWorldlex(void); 
00030 
00031   /*Our own variables*/
00032   extern unsigned int RWline; /* line number currently processed 
00033                                  (incremented by the LEX processor)*/
00034   
00035   /*Auxiliary variables used along readwordl*/
00036   unsigned int rw_lID,rw_lID1,rw_lID2; /*link identifier*/
00037   Tlink rw_link;
00038   Tjoint rw_joint;
00039   boolean rw_visible;
00040 
00041   /* Global pointer to allow the different parts of the parser to acces the 
00042      equations being initialized*/
00043   Tworld *rw_world;
00044 
00045   THTransform rw_transform;
00046 
00047   double **rw_point;
00048   unsigned int rw_i;
00049   double rw_angle;
00050   Tinterval rw_range,rw_range0;
00051   boolean rw_has_limits;
00052   double **rw_range_point;
00053   double **rw_in_patch_point;
00054   Tcolor rw_color_default,rw_color_body;
00055   Tfilename *rw_filename;
00056   Tcpolyhedron rw_cbody;
00057 
00058   Tconstants rw_constants;
00059 
00060   boolean rw_avoidLimits;
00061   double rw_avoidLimitsWeight;
00062 %}
00063 
00064 %union 
00065 { 
00066   char *id; 
00067   char *string;
00068   int int_number;
00069   double real_number;
00070   double color[3];
00071 } 
00072 
00073 %start world
00074 
00075 %token _CONSTANTS _ASSIGN _PI _COS _SIN _SQRT _LINKS _JOINTS _BODY _GRANULARITY _FIX _ID _TX _TY _TZ _TXYZ _RX _RY _RZ _PRISMATIC _REVOLUTE _SPHERICAL _UNIVERSAL _SPH_SPH _IN_PATCH _SPHERE _CYLINDER _LENGTH _RADIUS _SELFCOLLISIONS _RANGE _COLOR _RED _GREEN _BLUE _PURPLE _CYAN _YELLOW _WHITE _BLACK _HIDDEN _AVOID _LIMITS
00076 
00077 %token <id> _IDENTIFIER
00078 %token <int_number> _INTEGER 
00079 %token <real_number> _REAL
00080 %token <string> _STRING
00081 
00082 %type <int_number> granularity
00083 %type <real_number> expr
00084 %type <color> color
00085 
00086 %left '+' '-' 
00087 %left '*' '/'
00088 %left '^'
00089 %right _MAX_PRECEDENCE 
00090 %% 
00091 
00092 world: constant_defs
00093        link_defs 
00094        joint_defs 
00095       
00096 
00097 constant_defs: _CONSTANTS constant_list
00098              |
00099              ;
00100 
00101 constant_list : constant_definition constant_list
00102               | constant_definition
00103               ;
00104 
00105 constant_definition : _IDENTIFIER _ASSIGN expr
00106                       {
00107                         if (GetConstantWithName($1,&rw_constants)!=NO_UINT)
00108                           {
00109                             char s[200];
00110                             
00111                             sprintf(s,"Duplicated constant %s",$1);
00112                             ReadWorlderror(s);
00113                           }
00114                         
00115                         AddConstant($1,$3,&rw_constants);
00116                         free($1);
00117                       }
00118                     ;
00119 
00120 expr : '+' expr    %prec _MAX_PRECEDENCE
00121        {
00122          $$=$2;
00123        }
00124      | '-' expr    %prec _MAX_PRECEDENCE
00125        {
00126          $$=-$2;
00127        }
00128      | expr '+' expr 
00129        {
00130          $$=$1+$3;
00131        }
00132      | expr '-' expr 
00133        {
00134          $$=$1-$3;
00135        }
00136      | expr '*' expr 
00137        {
00138          $$=$1*$3;
00139        }
00140      | expr '^' expr 
00141        {
00142          $$=pow($1,$3);
00143        }
00144      | expr '/' expr 
00145        {
00146          if ($3==0.0)
00147            ReadWorlderror("Division by zero");
00148          
00149          $$=$1/$3;
00150        }
00151      | '(' expr ')'
00152        {
00153          $$=$2;
00154        }       
00155      | _PI 
00156        {
00157          $$=M_PI;
00158        } 
00159      | _SIN '(' expr ')'
00160        {
00161          $$=sin($3);
00162        }
00163      | _COS '(' expr ')'
00164        {
00165          $$=cos($3);
00166        }
00167      | _SQRT '(' expr ')'
00168        {
00169          $$=sqrt($3);
00170        }
00171      | _IDENTIFIER
00172        {
00173          unsigned int nc;
00174          
00175          nc=GetConstantWithName($1,&rw_constants);
00176          
00177          if (nc!=NO_UINT)
00178            $$=GetConstantValue(nc,&rw_constants);
00179          else
00180            {
00181              char ms[200];
00182              sprintf(ms,"Undefined constant: %s",$1);
00183              ReadWorlderror(ms);
00184            }
00185            free($1);
00186        }
00187      | _INTEGER 
00188        {
00189          $$=(double)$1;
00190        } 
00191      | _REAL
00192        {
00193          $$=$1;
00194        }
00195      ; 
00196 
00197 link_defs : _LINKS link_list
00198           ;
00199          
00200 link_list : link_definition link_list
00201           | link_definition
00202           ;
00203 
00204 link_definition: _IDENTIFIER 
00205                  {
00206                    if (GetConstantWithName($1,&rw_constants)!=NO_UINT)
00207                      ReadWorlderror("Link with the name of a constant");
00208 
00209                    if (GetWorldLinkID($1,rw_world)!=NO_UINT)
00210                      ReadWorlderror("Duplicated link");
00211 
00212                    /*adds an empty link to the world*/
00213                    InitLink($1,&rw_link);
00214                    
00215                    free($1);
00216                  }
00217                  opt_link_definition
00218                  {
00219                    AddLink2World(&rw_link,rw_world);
00220                    DeleteLink(&rw_link);
00221                  }
00222                  ;
00223 
00224 
00225 opt_link_definition : ':' link_color link_shapes
00226                     |
00227                     ;
00228 
00229 link_shapes : shape 
00230               {
00231                 AddBody2Link(&rw_cbody,&rw_link);
00232                 DeleteCPolyhedron(&rw_cbody);
00233               }
00234               link_shapes
00235             | shape 
00236               {
00237                 AddBody2Link(&rw_cbody,&rw_link);
00238                 DeleteCPolyhedron(&rw_cbody);
00239               }
00240             ;
00241 
00242 shape: _BODY _STRING body_color granularity
00243        {
00244          Tfilename fb;
00245 
00246          CreateFileName(GetFilePath(rw_filename),$2,NULL,NULL,&fb);
00247          
00248          InitCPolyhedronFromFile(GetFileFullName(&fb),&rw_color_body,
00249                                  $4,&rw_cbody);
00250 
00251          DeleteFileName(&fb);
00252          free($2);
00253        }
00254      | _SPHERE  expr '(' expr ',' expr ',' expr ')' 
00255        body_color granularity
00256        {
00257          double c[3];
00258          
00259          c[0]=$4;
00260          c[1]=$6;
00261          c[2]=$8;
00262 
00263          NewSphere($2,c,&rw_color_body,$11,&rw_cbody);
00264        }
00265      | _CYLINDER  expr '(' expr ',' expr ',' expr ')' '(' expr ',' expr ',' expr ')' 
00266        body_color granularity
00267        {
00268          double p1[3],p2[3];
00269          
00270          p1[0]=$4;
00271          p1[1]=$6;
00272          p1[2]=$8;
00273          
00274          p2[0]=$11;
00275          p2[1]=$13;
00276          p2[2]=$15;
00277          
00278          NewCylinder($2,p1,p2,&rw_color_body,$18,&rw_cbody);
00279        }
00280        ;
00281 
00282 granularity : _GRANULARITY ':' _INTEGER
00283               {
00284                 $$=$3;
00285               }
00286             |
00287               {
00288                 $$=0;
00289               }
00290 
00291             ;
00292 
00293 color : _COLOR  '(' expr ',' expr ',' expr ')'
00294         {
00295           $$[0]=$3;
00296           $$[1]=$5;
00297           $$[2]=$7;
00298         }
00299       | _RED
00300         {
00301           $$[0]=1;
00302           $$[1]=0;
00303           $$[2]=0;
00304         }
00305       | _GREEN
00306         {
00307           $$[0]=0;
00308           $$[1]=1;
00309           $$[2]=0;
00310         }
00311       | _BLUE
00312         {
00313           $$[0]=0;
00314           $$[1]=0;
00315           $$[2]=1;
00316         }
00317       | _BLACK
00318         {
00319           $$[0]=0;
00320           $$[1]=0;
00321           $$[2]=0;
00322         }
00323       | _WHITE
00324         {
00325           $$[0]=1;
00326           $$[1]=1;
00327           $$[2]=1;
00328         }
00329       | _YELLOW
00330         {
00331           $$[0]=1;
00332           $$[1]=1;
00333           $$[2]=0;
00334         }
00335       | _PURPLE
00336         {
00337           $$[0]=1;
00338           $$[1]=0;
00339           $$[2]=1;
00340         }
00341       | _CYAN
00342         {
00343           $$[0]=0;
00344           $$[1]=1;
00345           $$[2]=1;
00346         }
00347       | _INTEGER '*' color
00348         {
00349           unsigned int i;
00350 
00351           for(i=0;i<3;i++)
00352             $$[i]=(double)$1*$3[i];
00353         }
00354       | _REAL '*' color
00355         {
00356           unsigned int i;
00357 
00358           for(i=0;i<3;i++)
00359             $$[i]=$1*$3[i];
00360         }
00361       | color '+' color
00362         {
00363           unsigned int i;
00364 
00365           for(i=0;i<3;i++)
00366             $$[i]=$1[i]+$3[i];
00367         }
00368       ;
00369 
00370 link_color: color
00371             {
00372               NewColor($1[0],$1[1],$1[2],&rw_color_default);
00373             }
00374           |
00375             {
00376               NewColor(DLC_R,DLC_G,DLC_B,&rw_color_default);
00377             }
00378           ;
00379 
00380 body_color: color
00381             {
00382               NewColor($1[0],$1[1],$1[2],&rw_color_body);
00383             }
00384           |
00385             {
00386               CopyColor(&rw_color_body,&rw_color_default);
00387             }
00388           ;
00389 
00390 joint_defs : _JOINTS joint_list
00391            |
00392            ;
00393 
00394 joint_list : joint_definition joint_list
00395            | joint_definition
00396            ;
00397 
00398 joint_definition: fix_joint
00399                 | prismatic_joint 
00400                 | revolute_joint
00401                 | spherical_joint
00402                 | universal_joint
00403                 | sph_sph_joint
00404                 | in_patch_joint
00405                 ;
00406 
00407 fix_joint : _FIX  ':' _IDENTIFIER  _IDENTIFIER 
00408             {
00409               HTransformIdentity(&rw_transform);
00410             }
00411             transforms
00412             {
00413               unsigned int id1,id2;
00414                    
00415               id1=GetWorldLinkID($3,rw_world);  
00416               if (id1==NO_UINT)
00417                 ReadWorlderror("Unkown link (1st id) when defining a fix joint");
00418                    
00419               id2=GetWorldLinkID($4,rw_world);          
00420               if (id2==NO_UINT)
00421                 ReadWorlderror("Unkown link (2st id) when allowing a fix joint");
00422 
00423               NewFixJoint(GetWorldNJoints(rw_world),
00424                           id1,GetWorldLink(id1,rw_world),
00425                           id2,GetWorldLink(id2,rw_world),
00426                           &rw_transform,&rw_joint);
00427 
00428               AddJoint2World(&rw_joint,rw_world);
00429 
00430               DeleteJoint(&rw_joint);
00431               free($3);
00432               free($4);
00433 
00434               HTransformDelete(&rw_transform);
00435             }
00436           ;
00437 
00438 transforms: transform '*'transforms
00439           | transform
00440           ;
00441 
00442 transform : _ID 
00443             {
00444               /* Nothing need to be done */
00445             }
00446           |
00447             _TX '(' expr ')'
00448             {
00449               THTransform t;
00450               
00451               HTransformTx($3,&t);
00452               
00453               HTransformProduct(&rw_transform,&t,&rw_transform);
00454             }
00455           | _TY '(' expr ')'
00456             {
00457               THTransform t;
00458               
00459               HTransformTy($3,&t);
00460               
00461               HTransformProduct(&rw_transform,&t,&rw_transform);
00462             }
00463           | _TZ '(' expr ')'
00464             {
00465               THTransform t;
00466               
00467               HTransformTz($3,&t);
00468               
00469               HTransformProduct(&rw_transform,&t,&rw_transform);
00470             }
00471           | _TXYZ '(' expr ',' expr ',' expr')'
00472             {
00473               THTransform t;
00474               
00475               HTransformTxyz($3,$5,$7,&t);
00476               
00477               HTransformProduct(&rw_transform,&t,&rw_transform);
00478             }
00479           | _RX '(' expr ')'
00480             {
00481               THTransform t;
00482               
00483               HTransformRx($3,&t);
00484               
00485               HTransformProduct(&rw_transform,&t,&rw_transform);
00486             }
00487           | _RY '(' expr ')'
00488             {
00489               THTransform t;
00490               
00491               HTransformRy($3,&t);
00492               
00493               HTransformProduct(&rw_transform,&t,&rw_transform);
00494             }
00495           | _RZ '(' expr ')'
00496             {
00497               THTransform t;
00498               
00499               HTransformRz($3,&t);
00500               
00501               HTransformProduct(&rw_transform,&t,&rw_transform);
00502             }
00503           ;
00504 
00505 prismatic_joint: _PRISMATIC ':'
00506                  _IDENTIFIER 
00507                   { 
00508                     rw_lID1=rw_lID=GetWorldLinkID($3,rw_world); 
00509                     if (rw_lID1==NO_UINT)
00510                       ReadWorlderror("Unkown link (1st id) when defining a prismatic joint");
00511 
00512                     rw_i=0;
00513                   }
00514                  point pointp
00515                  _IDENTIFIER
00516                  { 
00517                    rw_lID2=rw_lID=GetWorldLinkID($7,rw_world);
00518                    if (rw_lID2==NO_UINT)
00519                      ReadWorlderror("Unkown link (2st id) when allowing a prismatic joint");
00520                  } 
00521                  point pointp 
00522                  _RANGE range
00523                  avoid_limits
00524                  {
00525                    NewPrismaticJoint(GetWorldNJoints(rw_world),
00526                                      rw_lID1,GetWorldLink(rw_lID1,rw_world),
00527                                      rw_lID2,GetWorldLink(rw_lID2,rw_world),
00528                                      rw_point,&rw_range,
00529                                      rw_avoidLimits,rw_avoidLimitsWeight,
00530                                      &rw_joint);
00531                    
00532                    AddJoint2World(&rw_joint,rw_world);
00533 
00534                    DeleteJoint(&rw_joint);
00535                    free($3);
00536                    free($7);
00537                  }
00538                  ;
00539 
00540 point : '(' expr ',' expr ',' expr ')'
00541         {
00542           rw_point[rw_i][0]=$2;
00543           rw_point[rw_i][1]=$4;
00544           rw_point[rw_i][2]=$6;
00545           rw_i++;
00546         }
00547       | _INTEGER
00548         {
00549           Tcpolyhedron *b;
00550           
00551           b=GetLinkBody(0,GetWorldLink(rw_lID,rw_world));
00552           GetCPolyhedronDefiningPoint($1,rw_point[rw_i],b);
00553           rw_i++;
00554         }
00555       | _INTEGER ':' _INTEGER
00556         {
00557           Tcpolyhedron *b;
00558           
00559           b=GetLinkBody($1,GetWorldLink(rw_lID,rw_world));
00560           GetCPolyhedronDefiningPoint($3,rw_point[rw_i],b);
00561           rw_i++;
00562         }
00563       ;
00564 
00565 pointp : point
00566        | '+''(' expr ',' expr ',' expr ')'
00567          {
00568            if (rw_i==0)
00569              Error("Incremental vector in a wrong position??");
00570            
00571            rw_point[rw_i][0]=rw_point[rw_i-1][0]+$3;
00572            rw_point[rw_i][1]=rw_point[rw_i-1][1]+$5;
00573            rw_point[rw_i][2]=rw_point[rw_i-1][2]+$7;
00574            rw_i++;
00575          }
00576        ;
00577 
00578 range : '[' expr ',' expr ']'
00579         {
00580           NewInterval($2,$4,&rw_range);
00581           if (EmptyInterval(&rw_range))
00582             ReadWorlderror("Empty range");
00583         }
00584         ;
00585 
00586 revolute_joint: _REVOLUTE ':'
00587                 _IDENTIFIER 
00588                 { 
00589                   rw_lID1=rw_lID=GetWorldLinkID($3,rw_world);
00590                   if (rw_lID1==NO_UINT)
00591                     ReadWorlderror("Unkown link (1st id) when defining a revolute joint");
00592 
00593                   rw_i=0; 
00594                 } 
00595                 point pointp
00596                 _IDENTIFIER 
00597                 { 
00598                   rw_lID2=rw_lID=GetWorldLinkID($7,rw_world);
00599                   if (rw_lID2==NO_UINT)
00600                     ReadWorlderror("Unkown link (2st id) when allowing a revolute joint");
00601                 } 
00602                 point pointp
00603                 opt_revolute_range
00604                 {
00605                   NewRevoluteJoint(GetWorldNJoints(rw_world),
00606                                    rw_lID1,GetWorldLink(rw_lID1,rw_world),
00607                                    rw_lID2,GetWorldLink(rw_lID2,rw_world),
00608                                    rw_point,
00609                                    rw_has_limits,&rw_range,rw_range_point,
00610                                    rw_avoidLimits,rw_avoidLimitsWeight,
00611                                    &rw_joint);
00612 
00613                   AddJoint2World(&rw_joint,rw_world);
00614 
00615                   DeleteJoint(&rw_joint);
00616                   free($3);
00617                   free($7);
00618                 }
00619                 ;
00620 
00621 spherical_joint : _SPHERICAL ':'
00622                   _IDENTIFIER 
00623                   {
00624                     rw_lID1=rw_lID=GetWorldLinkID($3,rw_world);
00625                     if (rw_lID1==NO_UINT)
00626                       ReadWorlderror("Unkown link (1st id) when defining a spherical joint");
00627 
00628                     rw_i=0; 
00629                   } 
00630                   point 
00631                   _IDENTIFIER 
00632                   { 
00633                     rw_lID2=rw_lID=GetWorldLinkID($6,rw_world);
00634                     if (rw_lID2==NO_UINT)
00635                       ReadWorlderror("Unkown link (2st id) when allowing a spherical joint");
00636                     
00637                     /*We skip  points[1] since the (incremental) range definition
00638                       assumes the displacement is given w.r.t. points[2] */
00639                     rw_i++;
00640                   } 
00641                   point
00642                   opt_spherical_range
00643                 {
00644                   NewSphericalJoint(GetWorldNJoints(rw_world),
00645                                     rw_lID1,GetWorldLink(rw_lID1,rw_world),
00646                                     rw_lID2,GetWorldLink(rw_lID2,rw_world),
00647                                     rw_point,
00648                                     rw_has_limits,rw_angle,rw_range_point,
00649                                     rw_avoidLimits,rw_avoidLimitsWeight,
00650                                     &rw_joint);
00651 
00652                   AddJoint2World(&rw_joint,rw_world);
00653 
00654                   DeleteJoint(&rw_joint);
00655                   free($3);
00656                   free($6);
00657                 }
00658                 ;
00659 
00660 universal_joint : _UNIVERSAL ':'
00661                   _IDENTIFIER 
00662                   { 
00663                     rw_lID1=rw_lID=GetWorldLinkID($3,rw_world);
00664                     if (rw_lID1==NO_UINT)
00665                       ReadWorlderror("Unkown link (1st id) when defining a universal joint");
00666 
00667                     rw_i=0; 
00668                   } 
00669                   point pointp
00670                   _IDENTIFIER 
00671                   { 
00672                     rw_lID2=rw_lID=GetWorldLinkID($7,rw_world);
00673 
00674                     if (rw_lID2==NO_UINT)
00675                       ReadWorlderror("Unkown link (2nd id) when defining a universal joint");
00676                   } 
00677                   point pointp
00678                   opt_universal_range
00679                   {
00680                     NewUniversalJoint(GetWorldNJoints(rw_world),
00681                                       rw_lID1,GetWorldLink(rw_lID1,rw_world),
00682                                       rw_lID2,GetWorldLink(rw_lID2,rw_world),
00683                                       rw_point,
00684                                       rw_has_limits,&rw_range0,&rw_range,rw_range_point,
00685                                       rw_avoidLimits,rw_avoidLimitsWeight,
00686                                       &rw_joint);
00687                     
00688                     AddJoint2World(&rw_joint,rw_world);
00689                     
00690                     DeleteJoint(&rw_joint);
00691                     free($3);
00692                     free($7);
00693                   }
00694                 ;
00695 
00696 sph_sph_joint: _SPH_SPH ':'
00697                _IDENTIFIER 
00698                { 
00699                  rw_lID1=rw_lID=GetWorldLinkID($3,rw_world);
00700                  if (rw_lID1==NO_UINT)
00701                    ReadWorlderror("Unkown link (1st id) when defining a spherical-spherical joint");
00702 
00703                  rw_i=0; 
00704                } 
00705                point 
00706                _IDENTIFIER 
00707                { 
00708                  rw_lID2=rw_lID=GetWorldLinkID($6,rw_world);
00709                  if (rw_lID2==NO_UINT)
00710                    ReadWorlderror("Unkown link (2st id) when allowing a spherical-spherical joint");
00711                } 
00712                point
00713                _LENGTH expr
00714                _RADIUS expr
00715                link_color
00716                {
00717                  NewSphSphJoint(GetWorldNJoints(rw_world),
00718                                 rw_lID1,GetWorldLink(rw_lID1,rw_world),
00719                                 rw_lID2,GetWorldLink(rw_lID2,rw_world),
00720                                 rw_point,$10,$12,&rw_color_default,
00721                                 &rw_joint);
00722 
00723                  AddJoint2World(&rw_joint,rw_world);
00724 
00725                  DeleteJoint(&rw_joint);
00726                  free($3);
00727                  free($6);
00728                }
00729              ;
00730 
00731 in_patch_joint : _IN_PATCH ':'
00732                  _IDENTIFIER  
00733                  { 
00734                    rw_lID1=rw_lID=GetWorldLinkID($3,rw_world);
00735                    if (rw_lID1==NO_UINT)
00736                      ReadWorlderror("Unkown link (1st id) when defining a in_patch joint");
00737                    
00738                    rw_i=0; 
00739                  } 
00740                  point pointp
00741                  {
00742                    /*save the points in a different location*/
00743                    unsigned int i,j;
00744 
00745                    for(i=0;i<2;i++)
00746                      {
00747                        for(j=0;j<3;j++)
00748                          rw_in_patch_point[i][j]=rw_point[i][j];
00749                      }
00750 
00751                    rw_i=0; 
00752                  }
00753                  _IDENTIFIER 
00754                  {
00755                    rw_lID2=rw_lID=GetWorldLinkID($8,rw_world);
00756                    if (rw_lID2==NO_UINT)
00757                      ReadWorlderror("Unkown link (2st id) when allowing a spherical-spherical joint");
00758                  }
00759                  point point point point
00760                  avoid_limits
00761                  {
00762                    NewInPatchJoint(GetWorldNJoints(rw_world),
00763                                    rw_lID1,GetWorldLink(rw_lID1,rw_world),
00764                                    rw_lID2,GetWorldLink(rw_lID2,rw_world),
00765                                    rw_in_patch_point,rw_point,
00766                                    rw_avoidLimits,rw_avoidLimitsWeight,
00767                                    &rw_joint);
00768                    
00769                    AddJoint2World(&rw_joint,rw_world);
00770                    
00771                    DeleteJoint(&rw_joint);
00772                    free($3);
00773                    free($8);
00774                  }
00775                ;
00776 
00777 rpointp : '(' expr ',' expr ',' expr ')'
00778           {
00779             rw_range_point[rw_i][0]=$2;
00780             rw_range_point[rw_i][1]=$4;
00781             rw_range_point[rw_i][2]=$6;
00782             rw_i++;
00783           }
00784         | '+' '(' expr ',' expr ',' expr ')'
00785           {
00786             rw_range_point[rw_i][0]=rw_point[2*rw_i][0]+$3;
00787             rw_range_point[rw_i][1]=rw_point[2*rw_i][1]+$5;
00788             rw_range_point[rw_i][2]=rw_point[2*rw_i][2]+$7;
00789             rw_i++;
00790           }
00791         ;
00792 
00793 opt_revolute_range: _RANGE
00794                     {
00795                       rw_i=0;
00796                       rw_has_limits=TRUE;
00797                     } 
00798                     range 
00799                     rpointp rpointp
00800                     avoid_limits
00801                   |
00802                     {
00803                       rw_has_limits=FALSE;
00804                     }
00805                   ;
00806 
00807 opt_spherical_range : _RANGE 
00808                       {
00809                         rw_i=0;
00810                         rw_has_limits=TRUE;
00811                       }
00812                       '[' expr ']'
00813                       {
00814                         rw_angle=$4;
00815                       }
00816                       rpointp rpointp
00817                       avoid_limits
00818                     |
00819                       {
00820                         rw_has_limits=FALSE;
00821                       }
00822                     ;
00823 
00824 opt_universal_range : _RANGE
00825                       {
00826                         rw_i=0;
00827                         rw_has_limits=TRUE;
00828                       } 
00829                       range 
00830                       {
00831                         CopyInterval(&rw_range0,&rw_range);
00832                       }
00833                       rpointp 
00834                       range rpointp
00835                       avoid_limits
00836                     |
00837                       {
00838                         rw_has_limits=FALSE;
00839                       }
00840                     ;
00841 
00842 avoid_limits : _AVOID _LIMITS opt_weight
00843                {
00844                  rw_avoidLimits=TRUE;
00845            
00846                }
00847              |
00848                {
00849                  rw_avoidLimits=FALSE;
00850                }
00851              ;
00852 
00853 opt_weight : expr
00854              {
00855                rw_avoidLimitsWeight=$1;
00856              }
00857            |
00858              {
00859                rw_avoidLimitsWeight=1.0;
00860              }
00861            ;
00862 
00863 
00864 %%
00867 /*
00868  *
00869  */
00870 void InitWorldFromFile(Tparameters *p,Tfilename *filename,Tworld *w)
00871 {
00872   unsigned int i;
00873 
00874   NEW(rw_point,4,double*);
00875   for(i=0;i<4;i++)
00876     NEW(rw_point[i],3,double);
00877 
00878   NEW(rw_range_point,4,double*);
00879   for(i=0;i<4;i++)
00880     NEW(rw_range_point[i],3,double);
00881 
00882   NEW(rw_in_patch_point,2,double*);
00883   for(i=0;i<2;i++)
00884     NEW(rw_in_patch_point[i],3,double);
00885   
00886   InitWorld(w); /*Generate an empty world*/
00887 
00888   InitConstants(&rw_constants); /*An empty set of constants*/
00889 
00890   ReadWorldin=fopen(GetFileFullName(filename),"r");
00891   if (!ReadWorldin) 
00892     {
00893       char ErrorText[500];
00894 
00895       sprintf(ErrorText,"File %s does not exists",GetFileFullName(filename));
00896       Error(ErrorText);
00897     }
00898 
00899   /*Reset the lines numbering*/
00900   RWline=1;
00901 
00902   /*we initalize the global pointer to make the parameters accesibles to any one inside the YACC module*/
00903   rw_world=w;
00904   rw_filename=filename;
00905 
00906   /*and process the file*/
00907   ReadWorldparse();
00908 
00909   DeleteConstants(&rw_constants); 
00910 
00911   w->stage=WORLD_WITH_GEOMETRY;
00912 
00913   GenerateWorldEquationSystems(p,w);
00914 
00915   for(i=0;i<4;i++)
00916     free(rw_point[i]);
00917   free(rw_point);
00918 
00919   for(i=0;i<4;i++)
00920     free(rw_range_point[i]);
00921   free(rw_range_point);
00922 
00923   for(i=0;i<2;i++)
00924     free(rw_in_patch_point[i]);
00925   free(rw_in_patch_point);
00926 
00927   fclose(ReadWorldin);
00928 } 
00929