Back to index

salome-med  6.5.0
test_copie_family.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 #include<string>
00023 
00024 #include <math.h>
00025 #include <stdlib.h>
00026 
00027 #include "MEDMEM_Exception.hxx"
00028 #include "MEDMEM_Mesh.hxx"
00029 #include "MEDMEM_Family.hxx"
00030 #include "MEDMEM_Group.hxx"
00031 
00032 #include "MEDMEM_MedMeshDriver.hxx"
00033 #include "MEDMEM_MedFieldDriver.hxx"
00034 #include "MEDMEM_Support.hxx"
00035 #include "MEDMEM_Field.hxx"
00036 #include "MEDMEM_define.hxx"
00037 
00038 using namespace std;
00039 using namespace MEDMEM;
00040 using namespace MED_EN;
00041 
00042 static void affiche_support(const SUPPORT * mySupport) 
00043 {
00044   cout << "  - Name : "<<mySupport->getName().c_str()<<endl ;
00045   cout << "  - Description : "<<mySupport->getDescription().c_str()<<endl ;
00046   cout << "  - Entity : "<<mySupport->getEntity()<<endl ;
00047   cout << "  - Entities list : "<<endl ;
00048   if (!(mySupport->isOnAllElements())) 
00049     {
00050       int NumberOfTypes = mySupport->getNumberOfTypes() ;
00051       cout<<"  - NumberOfTypes : "<<NumberOfTypes<<endl;
00052       const medGeometryElement * Types = mySupport->getTypes() ;
00053       for (int j=0;j<NumberOfTypes;j++) 
00054         {
00055           cout<<"    * Type "<<Types[j]<<" : ";
00056           int NumberOfElements = mySupport->getNumberOfElements(Types[j]) ;
00057           const int * Number = mySupport->getNumber(Types[j]) ;
00058           for (int k=0; k<NumberOfElements;k++)
00059             cout << Number[k] << " ";
00060           cout << endl ;
00061         }
00062     }
00063   else
00064     cout << "    Is on all entities !"<< endl;
00065 }
00066 
00067 
00068 static void affiche_famille(const FAMILY * myFamily)
00069 {
00070   affiche_support(myFamily);
00071   cout << "  - Identifier : "<<myFamily->getIdentifier()<<endl ;
00072   int NumberOfAttributes = myFamily->getNumberOfAttributes() ;
00073   cout << "  - Attributes ("<<NumberOfAttributes<<") :"<<endl;
00074   for (int j=1;j<NumberOfAttributes+1;j++)
00075     cout << "    * "<<myFamily->getAttributeIdentifier(j)<<" : "<<myFamily->getAttributeValue(j)<<", "<<myFamily->getAttributeDescription(j).c_str()<<endl ;
00076   int NumberOfGroups = myFamily->getNumberOfGroups() ;
00077   cout << "  - Groups ("<<NumberOfGroups<<") :"<<endl;
00078   for (int j=1;j<NumberOfGroups+1;j++)
00079     cout << "    * "<<myFamily->getGroupName(j).c_str()<<endl ;
00080 }
00081 
00082 int main (int argc, char ** argv) 
00083 {
00084   if (argc <3) 
00085     { // after 3, ignored !
00086       cerr << "Usage : " << argv[0] 
00087            << " filename meshname" << endl << endl;
00088       exit(-1);
00089     }
00090 
00091   string filename = argv[1] ;
00092   string meshname = argv[2] ;
00093 
00094   MESH * myMesh= new MESH;
00095   myMesh->setName(meshname);
00096   MED_MESH_RDONLY_DRIVER myMeshDriver(filename,myMesh) ;
00097   myMeshDriver.setMeshName(meshname);
00098   myMeshDriver.open() ;
00099   myMeshDriver.read() ;
00100   myMeshDriver.close() ;
00101 
00102   if ( myMesh->getNumberOfFamilies(MED_NODE) < 1 )
00103     {
00104       cerr << "No nodal families in the file" << endl;
00105       return 1;
00106     }
00107   const FAMILY * myFamily = myMesh->getFamily(MED_NODE,1);
00108 
00109   cout << "Show Family :"<<endl ;
00110   affiche_famille(myFamily);
00111   FAMILY * myFamily2 = new FAMILY(* myFamily);
00112   //delete myFamily;
00113   cout << "Show Family2 :"<<endl ;
00114   affiche_famille(myFamily2);
00115   FAMILY * myFamily3 = new FAMILY(* myFamily2);
00116   myFamily2->removeReference();
00117   cout << "Show Family3 :"<<endl ;
00118   affiche_famille(myFamily3);
00119   myFamily3->removeReference();
00120 
00121   cout << "That's all"<<endl ;
00122 
00123   myMesh->removeReference();
00124 
00125   return 0;
00126 }