Salome HOME
Fix problem of make distcheck
[modules/med.git] / src / MEDMEM / MEDMEM_Group.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
23 /*
24  File Group.cxx
25 */
26 #include <list>
27
28 #include "MEDMEM_Group.hxx"
29 #include "MEDMEM_Family.hxx"
30 #include "MEDMEM_Mesh.hxx"
31
32 using namespace std;
33 using namespace MEDMEM;
34 using namespace MED_EN;
35
36 GROUP::GROUP():SUPPORT(),_numberOfFamilies(0),_family() 
37 {
38   MESSAGE_MED("GROUP()");
39 }
40
41 GROUP::~GROUP() 
42 {
43   MESSAGE_MED("~GROUP()");
44 }
45   
46 GROUP & GROUP::operator=(const GROUP &group) 
47 {
48   MESSAGE_MED("GROUP::operator=");
49   if ( &group == this ) return *this;
50   SUPPORT::operator=(group);
51   _numberOfFamilies = group._numberOfFamilies ;
52   _family           = group._family ;
53   return *this;
54 }
55
56 ostream & MEDMEM::operator<<(ostream &os, GROUP &myGroup)
57 {
58   os << (SUPPORT&) myGroup;
59
60   int numberoffamilies = myGroup.getNumberOfFamilies();
61   os << "  - Families ("<<numberoffamilies<<") :"<<endl;
62   for (int j=1;j<numberoffamilies+1;j++)
63     os << "    * "<<myGroup.getFamily(j)->getName().c_str()<<endl ;
64
65   return os;
66 }
67
68 GROUP::GROUP(const string & name, const list<FAMILY*> & families) throw (MEDEXCEPTION)
69 {
70   const char * LOC = "GROUP( const string & , const list<FAMILY*> & ) : " ;
71   
72   BEGIN_OF_MED(LOC);
73
74   MESSAGE_MED(LOC<<name);
75
76   int numberOfFamilies = families.size();
77   _name = name ;
78   _description = "GROUP";
79   // description : none !
80   // first FAMILY to set all !
81   FAMILY * myFamily = families.front() ;
82   _mesh =  myFamily->getMesh() ;
83   if(_mesh)
84     _mesh->addReference();
85   _entity = myFamily->getEntity() ;
86   bool isOnAllElts = myFamily->isOnAllElements() ;
87
88   SCRUTE_MED(isOnAllElts);
89   SCRUTE_MED(numberOfFamilies);
90
91
92   if ((numberOfFamilies==1) && (isOnAllElts))
93     {
94       _numberOfFamilies = numberOfFamilies;
95       _isOnAllElts = isOnAllElts ;
96       _family.resize(_numberOfFamilies) ;
97       _family[0] = myFamily;
98       update();
99       return;
100     }
101   else if ((!(numberOfFamilies==1)) && (isOnAllElts))
102     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "building of a GROUP object from several FAMILY, and one of them is on all entities"  )) ;
103
104   _numberOfGeometricType = myFamily->getNumberOfTypes() ;
105
106   _geometricType.set(_numberOfGeometricType);
107   _numberOfElements.set(_numberOfGeometricType) ;
108
109   const medGeometryElement * geometricType = myFamily->getTypes() ;
110
111   SCRUTE_MED(_numberOfGeometricType);
112
113   for (int i=0 ; i<_numberOfGeometricType; i++) {
114     _geometricType[i]= geometricType[i] ;
115     _numberOfElements[i]=myFamily->getNumberOfElements(geometricType[i]);
116     MESSAGE_MED(LOC << " Type : " << _geometricType[i] << " number of element(s) " << _numberOfElements[i]);
117   }
118   _isOnAllElts = false ;
119
120
121   MEDSKYLINEARRAY * famNumber = myFamily->getnumber();
122
123   const int * famNumberValue = myFamily->getNumber(MED_ALL_ELEMENTS);
124
125   const int * famNumberIndex = myFamily->getNumberIndex();
126
127   int famNumberCount = famNumber->getNumberOf();
128   int famNumberLength = famNumber->getLength();
129
130   SCRUTE_MED(famNumber);
131   SCRUTE_MED(famNumberCount);
132   SCRUTE_MED(famNumberLength);
133   SCRUTE_MED(famNumberValue);
134   SCRUTE_MED(famNumberIndex);
135
136   _number = new MEDSKYLINEARRAY(famNumberCount,famNumberLength,
137                                 famNumberIndex,famNumberValue) ;
138
139   _numberOfFamilies = families.size();
140
141   _family.resize(_numberOfFamilies) ;
142   list<FAMILY*>::const_iterator li ;
143
144   int it = 0 ;
145   for (li=families.begin();li!=families.end();li++) {
146     blending(*li);
147     _family[it] = (*li) ;
148     it++ ;
149   }
150
151   END_OF_MED(LOC);
152 }
153
154 GROUP::GROUP(const GROUP & m):SUPPORT(m)
155 {
156   _numberOfFamilies = m._numberOfFamilies;
157   _family = m._family; //Copie profonde dans FAMILY Rmq from EF
158 }
159