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