2 Copyright (c) 1999-2012 OPEN CASCADE SAS
4 The content of this file is subject to the Open CASCADE Technology Public
5 License Version 6.5 (the "License"). You may not use the content of this file
6 except in compliance with the License. Please obtain a copy of the License
7 at http://www.opencascade.org and read it completely before using this file.
9 The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 The Original Code and all software distributed under the License is
13 distributed on an "AS IS" basis, without warranty of any kind, and the
14 Initial Developer hereby disclaims all such warranties, including without
15 limitation, any warranties of merchantability, fitness for a particular
16 purpose or non-infringement. Please see the License for the specific terms
17 and conditions governing the rights and limitations under the License.
26 /* Structures temporaires IGES (enregistrement des entites et parametres)
27 Comprennent : les declarations, et la gestion de l'entite en cours */
32 /* Liste de parametres IGES (header ou current part) */
33 static struct parlist *curlist;
34 static struct parlist *starts; /* Start Section du fichier IGES */
35 static struct parlist *header; /* Entete du fichier IGES */
38 /* Declaration d'une portion de Directory IGES */
39 static struct dirpart *curp;
41 struct dirpart *iges_get_curp (void)
46 /* Declaration d'un parametre IGES (Psect) */
47 static struct oneparam {
48 struct oneparam *next;
54 static struct dirpage {
57 struct dirpart parts[Maxparts];
61 static struct parpage { /* une page de parametres ; cf AddParam */
64 struct oneparam params[Maxpar+1];
68 static int curnumpart = 0;
69 static struct dirpage *curpage;
72 /* ROUTINES UTILITAIRES de traitement des textes (char*) */
74 /* Gestion du texte courant : c'est un texte alloue dynamiquement
75 iges_newchar en alloue un (jete le precedent alloue si pas lu)
76 rec_gettext lit le texte en cours, qui ne sera pas desalloue ensuite
77 rec_settext en force un autre en jetant le precedent (idem rec_newtext)
78 tandis que rec_newtext alloue un texte, sans lien avec le courant
83 static struct carpage {
84 struct carpage* next; /* chainage des pages de caracteres */
85 int used; /* place deja prise */
86 char cars[Maxcar+1]; /* page de caracteres */
89 static char* restext = NULL ; /* texte courant (allocation dynamique) */
90 /* static int resalloc = 0 ; */ /* alloue (memoire a liberer) ou non */
92 /* Utilitaire : Reservation de caracteres
93 Remplace suite de mini-malloc par gestion de page */
95 char* iges_newchar (char* newtext, int lentext)
98 if ((lnt = onecarpage->used) > Maxcar-lentext-1) { /* allouer nouvelle page */
99 struct carpage *newpage;
100 unsigned int sizepage = sizeof(struct carpage);
101 if (lentext >= Maxcar) sizepage += (lentext+1 - Maxcar);
102 newpage = (struct carpage*) malloc (sizepage);
103 newpage->next = onecarpage;
104 onecarpage = newpage;
105 lnt = onecarpage->used = 0;
107 restext = onecarpage->cars + lnt;
108 onecarpage->used = (lnt + lentext + 1);
110 for (i = lentext-1; i >= 0; i --) restext[i] = newtext[i];
111 restext[lentext] = '\0';
116 /* FICHIER IGES Proprement Dit */
118 /* Initialisation de l'enregistrement d'un fichier */
121 onecarpage = (struct carpage*) malloc ( sizeof(struct carpage) );
122 onecarpage->used = 0; onecarpage->next = NULL; restext = NULL;
123 oneparpage = (struct parpage*) malloc ( sizeof(struct parpage) );
124 oneparpage->used = 0; oneparpage->next = NULL;
126 starts = (struct parlist*) malloc ( sizeof(struct parlist) );
127 starts->first = starts->last = NULL; starts->nbparam = 0;
128 header = (struct parlist*) malloc ( sizeof(struct parlist) );
129 header->first = header->last = NULL; header->nbparam = 0;
131 curlist = starts; /* On commence a enregistrer la start section */
132 nbparts = nbparams = 0;
133 firstpage = (struct dirpage*) malloc ( sizeof(struct dirpage) );
134 firstpage->next = NULL; firstpage->used = 0;
138 /* Passage au Header (Global Section), lecture comme ecriture */
139 void iges_setglobal()
140 { if (curlist == header) return; curlist = header; curparam = curlist->first; }
143 /* Definition et Selection d'un nouveau dirpart */
145 void iges_newpart(int numsec)
147 if (curpage->used >= Maxparts) {
148 struct dirpage* newpage;
149 newpage = (struct dirpage*) malloc ( sizeof(struct dirpage) );
150 newpage->next = NULL; newpage->used = 0;
151 curpage->next = newpage; curpage = newpage;
153 curnumpart = curpage->used;
154 curp = &(curpage->parts[curnumpart]);
155 curlist = &(curp->list);
156 curp->numpart = numsec; curlist->nbparam = 0;
157 curlist->first = curlist->last = NULL;
158 curpage->used ++; nbparts ++;
162 /* Selection du dirpart dnum, correspond a numsec en Psect */
164 void iges_curpart (int dnum)
166 if (curp == NULL) return;
167 if (dnum == curp->numpart) return;
168 if (curnumpart < curpage->used - 1) curnumpart ++;
170 if (curpage->next == NULL) curpage = firstpage;
171 else curpage = curpage->next;
174 curp = &(curpage->parts[curnumpart]);
175 curlist = &(curp->list);
176 if (dnum == curp->numpart) return;
178 while (curpage != NULL) {
179 int i; int nbp = curpage->used;
180 for (i = 0; i < nbp; i ++) {
181 if (curpage->parts[i].numpart == dnum) {
183 curp = &(curpage->parts[i]);
184 curlist = &(curp->list);
188 curpage = curpage->next;
190 curp = NULL; /* pas trouve */
194 /* Definition d'un nouveau parametre */
195 /* (manque la gestion d'un Hollerith sur plusieurs lignes) */
197 /* longval : longueur de parval, incluant le zero final */
198 void iges_newparam (int typarg, int longval, char *parval)
201 if (curlist == NULL) return; /* non defini : abandon */
202 newval = iges_newchar(parval,longval);
203 /* curparam = (struct oneparam*) malloc ( sizeof(struct oneparam) ); */
204 if (oneparpage->used > Maxpar) {
205 struct parpage* newparpage;
206 newparpage = (struct parpage*) malloc ( sizeof(struct parpage) );
207 newparpage->next = oneparpage; newparpage->used = 0;
208 oneparpage = newparpage;
210 curparam = &(oneparpage->params[oneparpage->used]);
212 curparam->typarg = typarg;
213 curparam->parval = newval;
214 curparam->next = NULL;
215 if (curlist->first == NULL) curlist->first = curparam;
216 else curlist->last->next = curparam;
217 curlist->last = curparam;
222 /* Complement du parametre courant (cf Hollerith sur +ieurs lignes) */
223 void iges_addparam (int longval, char* parval)
225 char *newval, *oldval; int i,long0;
226 if (longval <= 0) return;
227 oldval = curparam->parval;
228 long0 = strlen(oldval);
229 /* newval = (char*) malloc(long0+longval+1); */
230 newval = iges_newchar("",long0+longval+1);
231 for (i = 0; i < long0; i ++) newval[i] = oldval[i];
232 for (i = 0; i < longval; i ++) newval[i+long0] = parval[i];
233 newval[long0+longval] = '\0';
234 curparam->parval = newval;
238 /* Relecture : Initialiation */
239 /* entites relues par suite de lirpart + {lirparam}
240 lirparam initiaux : pour relire le demarrage (start section) */
241 void iges_stats (int* nbpart, int* nbparam)
243 curpage = firstpage; curnumpart = 0;
245 curparam = curlist->first;
250 /* Lecture d'une part : retour = n0 section, 0 si fin */
251 /* \par tabval tableau recepteur des entiers (reserver 17 valeurs) */
252 /* \par res1 res2 nom num char : transmis a part */
253 int iges_lirpart (int* *tabval, char* *res1, char* *res2, char* *nom, char* *num, int *nbparam)
255 if (curpage == NULL) return 0;
256 curp = &(curpage->parts[curnumpart]);
257 curlist = &(curp->list);
258 *nbparam = curlist->nbparam;
259 curparam = curlist->first;
260 *tabval = &(curp->typ); /* adresse de curp = adresse du tableau */
261 *res1 = curp->res1; *res2 = curp->res2;
262 *nom = curp->nom; *num = curp->num;
263 return curp->numpart;
266 /* Passage au suivant (une fois lus les parametres) */
270 if (curnumpart >= curpage->used) { /* attention, adressage de 0 a used-1 */
271 curpage = curpage->next;
276 /* Lecture parametre + passage au suivant */
277 int iges_lirparam (int *typarg, char* *parval) /* renvoie 0 si fin de liste, 1 sinon */
279 if (curparam == NULL) return 0;
280 *typarg = curparam->typarg;
281 *parval = curparam->parval;
282 curparam = curparam->next;
286 /* Fin pour ce fichier : liberer la place */
287 /* mode = 0 : tout; 1 : parametres; 2 : caracteres */
288 void iges_finfile (int mode)
290 struct dirpage* oldpage;
291 if (mode == 0 || mode == 2) { free (starts); free (header); }
293 if (mode == 0 || mode == 1) {
295 while (curpage != NULL) {
296 oldpage = curpage->next;
301 while (oneparpage != NULL) {
302 struct parpage* oldparpage; oldparpage = oneparpage->next;
304 oneparpage = oldparpage;
308 if (mode == 0 || mode == 2) {
309 while (onecarpage != NULL) {
310 struct carpage* oldcarpage; oldcarpage = onecarpage->next;
312 onecarpage = oldcarpage;