Salome HOME
74f5a6911a5276c96099d79cbbd0d2bf20e92f79
[plugins/ghs3dprlplugin.git] / src / tepal2med / ghs3dprl_msg_parser.cxx
1
2 //#include <stdio.h>
3 //#include <qstring.h>
4 #include <iostream>
5
6 #include "ghs3dprl_msg_parser.h"
7 #include "ghs3dprl_mesh_wrap.h"
8
9 using namespace std;
10 using namespace med_2_2;
11
12 //************************************
13 bool ghs3dprl_msg_parser::startDocument()
14 {
15    indent="";
16    begin="distene_msg",
17    version="version",
18    neighbours="neighbours";
19    count="count";
20    neighbour="neighbour";
21    indice="indice";
22    send="send";
23    vertices="vertices";
24    edges="edges";
25    faces="faces";
26    elements="elements";
27    receive="receive";
28    etat=0;
29    neighbourscount=0;
30    neighbourcourant=0;
31    neighbourindice=0;
32    nbcount=0;
33    verbose=FALSE; //TRUE; //FALSE;
34    return TRUE;
35 }
36
37 //************************************
38 bool ghs3dprl_msg_parser::startElement(const QString &namespaceURI,
39                                    const QString &localName,
40                                    const QString &qName,
41                                    const QXmlAttributes &attrs)
42 {
43    bool ok;
44    if (verbose) cout<<indent<<qName<<endl;
45    typel=qName; shorttypel="";
46    indent += "   ";
47    if (qName==version)
48    {
49       etat=1;
50       return TRUE;
51    }
52
53    if (qName==neighbours)
54    {
55       etat=2;
56       if (attrs.count()>0 && attrs.localName(0)==count)
57       {
58         neighbourscount=attrs.value(0).toLong(&ok, 10);
59         neighbourcourant=-1;
60         if (verbose) cout<<indent<<attrs.localName(0)<<
61                            "="<<neighbourscount<<endl;
62       }
63       return TRUE;
64    }
65
66    if (qName==neighbour)
67    {
68       etat=3;
69       if (attrs.count()>0 && attrs.localName(0)==indice)
70       {
71         neighbourindice=attrs.value(0).toLong(&ok, 10);
72         neighbourcourant++;
73         //mailw.neighbourindices[mailw.neighbourcourant]=neighbourindice;
74         if (verbose) cout<<indent<<attrs.localName(0)<<
75                            "="<<neighbourindice<<endl;
76       }
77       return TRUE;
78    }
79
80    if (qName==send)
81    {
82       etat=4;
83       sendreceive="s/r=send ";
84       shortsendreceive="SE ";
85       return TRUE;
86    }
87
88    if (qName==receive)
89    {
90       etat=9;
91       sendreceive="s/r=receive ";
92       shortsendreceive="RE ";
93       return TRUE;
94    }
95
96    if (qName==vertices)
97    {
98       etat=5;
99       shorttypel="VE ";
100       if (attrs.count()>0 && attrs.localName(0)==count)
101       {
102         nbcount=attrs.value(0).toLong(&ok, 10);
103         if (verbose) cout<<indent<<attrs.localName(0)<<
104                            "="<<nbcount<<endl;
105       }
106       return TRUE;
107    }
108
109    if (qName==edges)
110    {
111       etat=6;
112       shorttypel="ED ";
113       if (attrs.count()>0 && attrs.localName(0)==count)
114       {
115         nbcount=attrs.value(0).toLong(&ok, 10);
116         if (verbose) cout<<indent<<attrs.localName(0)<<
117                            "="<<nbcount<<endl;
118       }
119       return TRUE;
120    }
121
122    if (qName==faces)
123    {
124       etat=7;
125       shorttypel="FA ";
126       if (attrs.count()>0 && attrs.localName(0)==count)
127       {
128         nbcount=attrs.value(0).toLong(&ok, 10);
129         if (verbose) cout<<indent<<attrs.localName(0)<<
130                            "="<<nbcount<<endl;
131       }
132       return TRUE;
133    }
134
135    if (qName==elements)
136    {
137       etat=8;
138       shorttypel="EL ";
139       if (attrs.count()>0 && attrs.localName(0)==count)
140       {
141         nbcount=attrs.value(0).toLong(&ok, 10);
142         if (verbose) cout<<indent<<attrs.localName(0)<<
143                            "="<<nbcount<<endl;
144       }
145       return TRUE;
146    }
147
148    /*for( int i=0; i<attrs.count(); i++ )
149       {
150       cout<<indent<<attrs.localName(i)<<"="<<attrs.value(i)<<endl;
151       }*/
152
153    return TRUE;
154 }
155
156 //************************************
157 bool ghs3dprl_msg_parser::endElement(const QString &namespaceURI,
158                                  const QString &localName,
159                                  const QString &qName)
160 {
161    indent.remove((uint)0,3);
162    if (verbose) cout<<indent<<"\\"<<qName<<endl;
163    nbcount=0; //precaution
164    if (qName==send || qName==receive)
165    {
166       sendreceive="";
167       shortsendreceive="";
168       return TRUE;
169    }
170    if (qName==begin)
171    {
172       mailw->nbfiles++;
173       return TRUE;
174    }
175    return TRUE;
176 }
177
178 //************************************
179 bool ghs3dprl_msg_parser::characters(const QString &strini)
180 {
181    bool ok;
182    med_int *tmint=NULL;
183    long nb=0;
184    //filtre rc,lf,tab et blancs successifs
185    QString str=strini.simplifyWhiteSpace();
186    //if ( str.length() == 1 && str=="\n" )
187    if (str.length()==0)
188    {
189       //cout<<"EMPTY_LINE_CR"<<endl;
190       return TRUE;
191    }
192    else
193    {
194       if (etat==1)
195       {
196          double ver=str.toDouble(&ok);
197          if (!ok || ver!=1e0)
198          {
199             cout<<"version "<<str<<" fichier .msg inconnue"<<endl;
200             return FALSE;
201          }
202          else return TRUE;
203       }
204       nb=str.contains(' ',TRUE) + 1; //nb chiffres detectes
205       if (nb>1)
206       {
207          //lecture vecteurs d'entiers separateur blanc
208          long i=0;
209          tmint=new med_int[nb];
210          //printf("%staille attendue=%i taille vue=%i\n",(const char *)indent,nbcount,nb);
211          do
212          {
213             tmint[i]=str.section(' ',i,i).toLong(&ok);
214             //printf("tmint[%i]=%i\n",i,tmint[i]);
215             i++;
216          } while ((i<nb) && ok );
217          if (i<nb)
218          {
219             cout<<"pb conversion "<<i<<" eme entier="<<str.section(' ',i-1,i-1)<<endl;
220             cout<<indent<<"etat="<<etat<<" nb="<<nb<<endl<<str<<endl;
221          }
222       }
223       if (nb==1)
224       {
225          tmint=new med_int[nb];
226          tmint[0]=str.toLong(&ok);
227          if (!ok)
228          {
229             cout<<"pb conversion 1er entier="<<str<<endl;
230             cout<<indent<<"etat="<<etat<<" nb="<<nb<<endl;
231          }
232       }
233
234    }
235    //lecture ok stockage de tlong dans mailw.mestab
236    CVWtab *montab=new CVWtab(nb,tmint);
237    QString tmp;
238    /*cout<<"InsertKey type="<<typel<<" "<<sendreceive<<
239          " neighbour="<<neighbourindice<<
240          " file="<<mailw->nofile<<endl;*/
241    tmp=tmp.sprintf("MS%ld NE%ld ",
242        mailw->nofile,neighbourindice)+
243        shorttypel+shortsendreceive;
244    tmp=tmp.simplifyWhiteSpace();
245    ok=mailw->insert_key(tmp,montab);
246    return TRUE;
247 }
248