Salome HOME
Updated copyright comment
[plugins/ghs3dprlplugin.git] / src / tepal2med / ghs3dprl_msg_parser.cxx
1 // Copyright (C) 2007-2024  CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // ---
21 // File   : ghs3dprl_mesh_parser.cxx
22 // Author : Christian VAN WAMBEKE (CEA) (from Hexotic plugin Lioka RAZAFINDRAZAKA)
23 // ---
24 //
25 #include <iostream>
26
27 #include "ghs3dprl_msg_parser.h"
28 #include "ghs3dprl_mesh_wrap.h"
29
30 //************************************
31 bool ghs3dprl_msg_parser::startDocument()
32 {
33   indent="";
34   begin="distene_msg";
35   version="version";
36   neighbours="neighbours";
37   count="count";
38   neighbour="neighbour";
39   indice="indice";
40   send="send";
41   vertices="vertices";
42   edges="edges";
43   faces="faces";
44   elements="elements";
45   receive="receive";
46   etat=0;
47   neighbourscount=0;
48   neighbourcourant=0;
49   neighbourindice=0;
50   nbcount=0;
51   verbose=false; //true; //false;
52   return true;
53 }
54
55 //************************************
56 bool ghs3dprl_msg_parser::startElement(const QString &/*namespaceURI*/,
57                                        const QString &/*localName*/,
58                                        const QString &qName,
59                                        const QXmlAttributes &attrs)
60 {
61   bool ok;
62   if (verbose) std::cout<<indent.toLatin1().constData()<<qName.toLatin1().constData()<<std::endl;
63   typel=qName; shorttypel="";
64   indent += "   ";
65   if (qName==version)
66   {
67     etat=1;
68     return true;
69   }
70   
71   if (qName==neighbours)
72   {
73     etat=2;
74     if (attrs.count()>0 && attrs.localName(0)==count)
75     {
76       neighbourscount=attrs.value(0).toLong(&ok, 10);
77       neighbourcourant=-1;
78       if (verbose) std::cout<<indent.toLatin1().constData()<<attrs.localName(0).toLatin1().constData()<<
79                      "="<<neighbourscount<<std::endl;
80     }
81     return true;
82   }
83   
84   if (qName==neighbour)
85   {
86     etat=3;
87     if (attrs.count()>0 && attrs.localName(0)==indice)
88     {
89       neighbourindice=attrs.value(0).toLong(&ok, 10);
90       neighbourcourant++;
91       //mailw.neighbourindices[mailw.neighbourcourant]=neighbourindice;
92       if (verbose) std::cout<<indent.toLatin1().constData()<<attrs.localName(0).toLatin1().constData()<<
93                      "="<<neighbourindice<<std::endl;
94     }
95     return true;
96   }
97   
98   if (qName==send)
99   {
100     etat=4;
101     sendreceive="s/r=send ";
102     shortsendreceive="SE ";
103     return true;
104   }
105   
106   if (qName==receive)
107   {
108     etat=9;
109     sendreceive="s/r=receive ";
110     shortsendreceive="RE ";
111     return true;
112   }
113   
114   if (qName==vertices)
115   {
116     etat=5;
117     shorttypel="VE ";
118     if (attrs.count()>0 && attrs.localName(0)==count)
119     {
120       nbcount=attrs.value(0).toLong(&ok, 10);
121       if (verbose) std::cout<<indent.toLatin1().constData()<<attrs.localName(0).toLatin1().constData()<<
122                      "="<<nbcount<<std::endl;
123     }
124     return true;
125   }
126   
127   if (qName==edges)
128   {
129     etat=6;
130     shorttypel="ED ";
131     if (attrs.count()>0 && attrs.localName(0)==count)
132     {
133       nbcount=attrs.value(0).toLong(&ok, 10);
134       if (verbose) std::cout<<indent.toLatin1().constData()<<attrs.localName(0).toLatin1().constData()<<
135                      "="<<nbcount<<std::endl;
136     }
137     return true;
138   }
139   
140   if (qName==faces)
141   {
142     etat=7;
143     shorttypel="FA ";
144     if (attrs.count()>0 && attrs.localName(0)==count)
145     {
146       nbcount=attrs.value(0).toLong(&ok, 10);
147       if (verbose) std::cout<<indent.toLatin1().constData()<<attrs.localName(0).toLatin1().constData()<<
148                      "="<<nbcount<<std::endl;
149     }
150     return true;
151   }
152   
153   if (qName==elements)
154   {
155     etat=8;
156     shorttypel="EL ";
157     if (attrs.count()>0 && attrs.localName(0)==count)
158     {
159       nbcount=attrs.value(0).toLong(&ok, 10);
160       if (verbose) std::cout<<indent.toLatin1().constData()<<attrs.localName(0).toLatin1().constData()<<
161                      "="<<nbcount<<std::endl;
162     }
163     return true;
164   }
165   
166   /*for( int i=0; i<attrs.count(); i++ )
167   {
168     std::cout<<indent.toLatin1().constData()<<attrs.localName(i).toLatin1().constData()<<"="<<attrs.value(i)<<std::endl;
169   }*/
170   
171   return true;
172 }
173
174 //************************************
175 bool ghs3dprl_msg_parser::endElement(const QString &/*namespaceURI*/,
176                                      const QString &/*localName*/,
177                                      const QString &qName)
178 {
179   indent.remove((uint)0,3);
180   if (verbose) std::cout<<indent.toLatin1().constData()<<"\\"<<qName.toLatin1().constData()<<std::endl;
181   nbcount=0; //precaution
182   if (qName==send || qName==receive)
183   {
184     sendreceive="";
185     shortsendreceive="";
186     return true;
187   }
188   if (qName==begin)
189   {
190     mailw->nbfiles++;
191     return true;
192   }
193   return true;
194 }
195
196 //************************************
197 bool ghs3dprl_msg_parser::characters(const QString &strini)
198 {
199   bool ok;
200   med_int *tmint=NULL;
201   long nb=0;
202   //filtre rc,lf,tab et blancs successifs
203   QString str=strini.simplified();
204   //if ( str.length() == 1 && str=="\n" )
205   if (str.length()==0)
206   {
207     //std::cout<<"EMPTY_LINE_CR"<<std::endl;
208     return true;
209   }
210   else
211   {
212     if (etat==1)
213     {
214       double ver=str.toDouble(&ok);
215       if (!ok || ver!=1e0)
216       {
217       std::cout<<"version "<<str.toLatin1().constData()<<" fichier .msg inconnue"<<std::endl;
218       return false;
219       }
220       else return true;
221     }
222     nb=str.count(' ',Qt::CaseSensitive) + 1; //nb chiffres detectes
223     if (nb>1)
224     {
225       //lecture vecteurs d'entiers separateur blanc
226       long i=0;
227       tmint=new med_int[nb];
228       //printf("%staille attendue=%i taille vue=%i\n",(const char *)indent.toLatin1().constData(),nbcount,nb);
229       do
230       {
231       tmint[i]=str.section(' ',i,i).toLong(&ok);
232       //printf("tmint[%i]=%i\n",i,tmint[i]);
233       i++;
234       } while ((i<nb) && ok );
235       if (i<nb)
236       {
237       std::cout<<"pb conversion "<<i<<" eme entier="<<str.section(' ',i-1,i-1).toLatin1().constData()<<std::endl;
238       std::cout<<indent.toLatin1().constData()<<"etat="<<etat<<" nb="<<nb<<std::endl<<str.toLatin1().constData()<<std::endl;
239       }
240     }
241     if (nb==1)
242     {
243       tmint=new med_int[nb];
244       tmint[0]=str.toLong(&ok);
245       if (!ok)
246       {
247       std::cout<<"pb conversion 1er entier="<<str.toLatin1().constData()<<std::endl;
248       std::cout<<indent.toLatin1().constData()<<"etat="<<etat<<" nb="<<nb<<std::endl;
249       }
250     }
251     
252   }
253   //lecture ok stockage de tlong dans mailw.mestab
254   CVWtab *montab=new CVWtab(nb,tmint);
255   QString tmp;
256   /*std::cout<<"InsertKey type="<<typel<<" "<<sendreceive<<
257     " neighbour="<<neighbourindice<<
258     " file="<<mailw->nofile<<std::endl;*/
259   tmp=tmp.sprintf("MS%ld NE%ld ",
260   mailw->nofile,neighbourindice)+
261   shorttypel+shortsendreceive;
262   tmp=tmp.simplified();
263   ok=mailw->insert_key(tmp,montab);
264   return true;
265 }
266