Diff for /Amaya/amaya/templateInstantiate.c between versions 1.51 and 1.52

version 1.51, 2007/10/05 10:30:38 version 1.52, 2007/10/15 10:46:02
Line 79  Element Template_InsertRepeatChildAfter Line 79  Element Template_InsertRepeatChildAfter
   Template_InsertUseChildren(doc, use, decl);    Template_InsertUseChildren(doc, use, decl);
   
   TtaRegisterElementCreate (use, doc);    TtaRegisterElementCreate (use, doc);
   Template_IncrementRepeatOccurNumber (el);  
   return use;    return use;
 #else /* TEMPLATES */  #else /* TEMPLATES */
   return NULL;    return NULL;
Line 789  void InstantiateRepeat (XTigerTemplate t Line 788  void InstantiateRepeat (XTigerTemplate t
 {  {
 #ifdef TEMPLATES  #ifdef TEMPLATES
   Element        child, newChild;    Element        child, newChild;
   Attribute      curAtt,  minAtt,  maxAtt;    ElementType    newElType;
   AttributeType  curType, minType, maxType;    Attribute      minAtt,  maxAtt;
   char           *text, *types = NULL, *title = NULL;    AttributeType  minType, maxType;
   int            curVal,  minVal,  maxVal;    char          *text, *types = NULL, *title = NULL;
     int            curVal, minVal,  maxVal;
   int            childrenCount;    int            childrenCount;
   
   
Line 800  void InstantiateRepeat (XTigerTemplate t Line 800  void InstantiateRepeat (XTigerTemplate t
     return;      return;
   
   //Preparing types    //Preparing types
   curType.AttrSSchema = TtaGetSSchema (TEMPLATE_SCHEMA_NAME, doc);    minType.AttrSSchema = TtaGetSSchema (TEMPLATE_SCHEMA_NAME, doc);
   minType.AttrSSchema = maxType.AttrSSchema = curType.AttrSSchema;  
   curType.AttrTypeNum = Template_ATTR_currentOccurs;   
   minType.AttrTypeNum = Template_ATTR_minOccurs;    minType.AttrTypeNum = Template_ATTR_minOccurs;
     maxType.AttrSSchema =  minType.AttrSSchema;
   maxType.AttrTypeNum = Template_ATTR_maxOccurs;    maxType.AttrTypeNum = Template_ATTR_maxOccurs;
     newElType.ElSSchema = minType.AttrSSchema;
   //Get currentOccurs, minOccurs and maxOccurs attributes    //Get minOccurs and maxOccurs attributes
   curAtt = TtaGetAttribute (el, curType);  
   minAtt = TtaGetAttribute (el, minType);    minAtt = TtaGetAttribute (el, minType);
   maxAtt = TtaGetAttribute (el, maxType);    maxAtt = TtaGetAttribute (el, maxType);
   
   //Get the values    //Get the values
   if (minAtt)    if (minAtt)
     {      {
Line 819  void InstantiateRepeat (XTigerTemplate t Line 816  void InstantiateRepeat (XTigerTemplate t
         {          {
           minVal = atoi(text);            minVal = atoi(text);
           TtaFreeMemory(text);            TtaFreeMemory(text);
             curVal = minVal;
         }          }
       else        else
         //Error : Attribute with no value          //Error : Attribute with no value
         return;          return;
     }      }
   else    else
     minVal = 0;      {
         minVal = 0;
         curVal = 1;
       }
   
   if (maxAtt)    if (maxAtt)
     {      {
Line 845  void InstantiateRepeat (XTigerTemplate t Line 846  void InstantiateRepeat (XTigerTemplate t
   else    else
     maxVal = INT_MAX;      maxVal = INT_MAX;
   
   if (curAtt)  
     {  
       text = GetAttributeStringValue(el, curAtt, NULL);  
       if (text)  
         {  
           curVal = atoi(text);  
           TtaFreeMemory(text);  
         }  
       else  
         //Error : Attribute with no value  
         return;  
     }  
   else  
     curVal = minVal;  
   
   text = (char*)TtaGetMemory(MAX_LENGTH);    text = (char*)TtaGetMemory(MAX_LENGTH);
   //Create non existing attributes    //Create non existing min max attributes
   if (!minAtt)    if (minAtt == NULL)
     {            {      
       minAtt = TtaNewAttribute (minType);        minAtt = TtaNewAttribute (minType);
       sprintf (text, "%d", minVal);        sprintf (text, "%d", minVal);
Line 872  void InstantiateRepeat (XTigerTemplate t Line 858  void InstantiateRepeat (XTigerTemplate t
         TtaRegisterAttributeCreate (minAtt, el, doc);          TtaRegisterAttributeCreate (minAtt, el, doc);
     }      }
   
   if (!maxAtt)    if (maxAtt == NULL)
     {        {  
       maxAtt = TtaNewAttribute (maxType);        maxAtt = TtaNewAttribute (maxType);
       if (maxVal < INT_MAX)        if (maxVal < INT_MAX)
Line 884  void InstantiateRepeat (XTigerTemplate t Line 870  void InstantiateRepeat (XTigerTemplate t
       if (registerUndo)        if (registerUndo)
         TtaRegisterAttributeCreate (maxAtt, el, doc);          TtaRegisterAttributeCreate (maxAtt, el, doc);
     }      }
     TtaFreeMemory(text);
   
   if (!curAtt)    //We must have minOccurs children
     {  
       curAtt = TtaNewAttribute (curType);  
       sprintf (text,"%d",curVal);  
       TtaAttachAttribute (el, curAtt, doc);  
       TtaSetAttributeText (curAtt, text, el, doc);  
       if (registerUndo)  
         TtaRegisterAttributeCreate (curAtt, el, doc);  
     }  
   if (text)  
     TtaFreeMemory(text);  
   
   //We must have currentOccurs children  
   child = TtaGetFirstChild(el);    child = TtaGetFirstChild(el);
   if (!child)    if (!child)
     //Error : a repeat must have at least one child which will be the model      //Error : a repeat must have at least one child which will be the model
Line 916  void InstantiateRepeat (XTigerTemplate t Line 891  void InstantiateRepeat (XTigerTemplate t
   child = TtaGetLastChild(el);    child = TtaGetLastChild(el);
   types = GetAttributeStringValueFromNum (child, Template_ATTR_types, NULL);    types = GetAttributeStringValueFromNum (child, Template_ATTR_types, NULL);
   title = GetAttributeStringValueFromNum (child, Template_ATTR_title, NULL);    title = GetAttributeStringValueFromNum (child, Template_ATTR_title, NULL);
     newElType.ElTypeNum = Template_EL_useEl;
   while (childrenCount < curVal)    while (childrenCount < curVal)
     {      {
       ElementType newElType;  
       newElType.ElSSchema = TtaGetSSchema (TEMPLATE_SCHEMA_NAME, doc);  
       newElType.ElTypeNum = Template_EL_useEl;  
       newChild = TtaNewElement (doc, newElType);        newChild = TtaNewElement (doc, newElType);
         
       // Insert it        // Insert it
       TtaInsertSibling (newChild, child, FALSE, doc);        TtaInsertSibling (newChild, child, FALSE, doc);
       SetAttributeStringValueWithUndo (newChild, Template_ATTR_types, types);        SetAttributeStringValueWithUndo (newChild, Template_ATTR_types, types);
Line 937  void InstantiateRepeat (XTigerTemplate t Line 909  void InstantiateRepeat (XTigerTemplate t
           
   Template_FixAccessRight (t, el, doc);    Template_FixAccessRight (t, el, doc);
   TtaUpdateAccessRightInViews (doc, el);    TtaUpdateAccessRightInViews (doc, el);
     
   TtaFreeMemory (types);    TtaFreeMemory (types);
   TtaFreeMemory (title);    TtaFreeMemory (title);
 #endif /* TEMPLATES */  #endif /* TEMPLATES */

Removed from v.1.51  
changed lines
  Added in v.1.52


Webmaster