Salome HOME
Copyrights update
[modules/med.git] / src / MEDMEM / test_copie_group.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/
19 //
20 #include<string>
21
22 #include <math.h>
23 #include <stdlib.h>
24
25 #include "MEDMEM_Exception.hxx"
26 #include "MEDMEM_Mesh.hxx"
27 #include "MEDMEM_Family.hxx"
28 #include "MEDMEM_Group.hxx"
29
30 #include "MEDMEM_MedMeshDriver.hxx"
31 #include "MEDMEM_MedFieldDriver.hxx"
32 #include "MEDMEM_Support.hxx"
33 #include "MEDMEM_Field.hxx"
34 #include "MEDMEM_define.hxx"
35
36 using namespace std;
37 using namespace MEDMEM;
38 using namespace MED_EN;
39
40 void affiche_support(const SUPPORT * mySupport) 
41 {
42   cout << "  - Name : "<<mySupport->getName().c_str()<<endl ;
43   cout << "  - Description : "<<mySupport->getDescription().c_str()<<endl ;
44   cout << "  - Entity : "<<mySupport->getEntity()<<endl ;
45   cout << "  - Entities list : "<<endl ;
46   if (!(mySupport->isOnAllElements())) {
47     int NumberOfTypes = mySupport->getNumberOfTypes() ;
48     cout<<"  - NumberOfTypes : "<<NumberOfTypes<<endl;
49     const medGeometryElement * Types = mySupport->getTypes() ;
50     for (int j=0;j<NumberOfTypes;j++) {
51       cout<<"    * Type "<<Types[j]<<" : ";
52       int NumberOfElements = mySupport->getNumberOfElements(Types[j]) ;
53       const int * Number = mySupport->getNumber(Types[j]) ;
54       for (int k=0; k<NumberOfElements;k++)
55         cout << Number[k] << " ";
56       cout << endl ;
57     }
58   } else
59     cout << "    Is on all entities !"<< endl;
60 }
61
62
63 void affiche_famille(const FAMILY * myFamily)
64 {
65     affiche_support(myFamily);
66     cout << "  - Identifier : "<<myFamily->getIdentifier()<<endl ;
67     int NumberOfAttributes = myFamily->getNumberOfAttributes() ;
68     cout << "  - Attributes ("<<NumberOfAttributes<<") :"<<endl;
69     for (int j=1;j<NumberOfAttributes+1;j++)
70       cout << "    * "<<myFamily->getAttributeIdentifier(j)<<" : "<<myFamily->getAttributeValue(j)<<", "<<myFamily->getAttributeDescription(j).c_str()<<endl ;
71     int NumberOfGroups = myFamily->getNumberOfGroups() ;
72     cout << "  - Groups ("<<NumberOfGroups<<") :"<<endl;
73     for (int j=1;j<NumberOfGroups+1;j++)
74       cout << "    * "<<myFamily->getGroupName(j).c_str()<<endl ;
75 }
76
77 void affiche_groupe(const GROUP * myGroup) 
78 {
79     affiche_support(myGroup);
80     int NumberOfFamillies = myGroup->getNumberOfFamilies() ;
81     cout << "  - Families ("<<NumberOfFamillies<<") :"<<endl;
82     for (int j=1;j<NumberOfFamillies+1;j++)
83       cout << "    * "<<myGroup->getFamily(j)->getName().c_str()<<endl ;
84 }
85
86 int main (int argc, char ** argv) {
87   int read;
88
89   if (argc <3) { // after 3, ignored !
90     cerr << "Usage : " << argv[0] 
91          << " filename meshname" << endl << endl;
92     exit(-1);
93   }
94
95   string filename = argv[1] ;
96   string meshname = argv[2] ;
97
98   MESH * myMesh= new MESH() ;
99   myMesh->setName(meshname);
100   MED_MESH_RDONLY_DRIVER myMeshDriver(filename,myMesh) ;
101   myMeshDriver.setMeshName(meshname);
102   myMeshDriver.open() ;
103   myMeshDriver.read() ;
104   myMeshDriver.close() ;
105
106   const GROUP * myGroup = myMesh->getGroup(MED_NODE,1);
107   cout << "Show Group :"<<endl ;
108   affiche_groupe(myGroup);
109   GROUP * myGroup2 = new GROUP(* myGroup);
110   //delete myGroup; // no because in mesh !!
111   affiche_groupe(myGroup2);
112   GROUP * myGroup3 = new GROUP(* myGroup2);
113   delete myGroup2;
114   affiche_groupe(myGroup3);
115   delete myGroup3;
116
117   delete myMesh ;
118
119   return 0;
120 }