]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
In MEDLoader basic API export the static policy in the MEDLoader advanced objects...
authorageay <ageay>
Thu, 12 Dec 2013 08:47:50 +0000 (08:47 +0000)
committerageay <ageay>
Thu, 12 Dec 2013 08:47:50 +0000 (08:47 +0000)
src/MEDLoader/MEDLoader.cxx
src/MEDLoader/MEDLoader.hxx
src/MEDLoader/Swig/MEDLoaderCommon.i
src/MEDLoader/Swig/MEDLoaderTest.py

index f14e17a152833858b9415a9582f24c854815dd3f..75c9acc1a3a38f31d6012e8b00fe798c4625d402 100644 (file)
@@ -284,6 +284,11 @@ void MEDLoaderNS::dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfEle
 
 /// @endcond
 
+void MEDLoader::AssignStaticWritePropertiesTo(ParaMEDMEM::MEDFileWritable& obj)
+{
+  obj.setTooLongStrPolicy(_TOO_LONG_STR);
+}
+
 bool MEDLoader::HasXDR()
 {
 #ifdef HAS_XDR
@@ -1063,7 +1068,7 @@ std::vector< std::pair<int,int> > MEDLoader::GetNodeFieldIterations(const char *
 ParaMEDMEM::MEDCouplingMesh *MEDLoader::ReadMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax)
 {
   CheckFileForRead(fileName);
-  MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
+  MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
   MEDFileMesh *mmPtr(mm);
   MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
   if(mmuPtr)
@@ -1087,7 +1092,7 @@ ParaMEDMEM::MEDCouplingMesh *MEDLoader::ReadMeshFromFile(const char *fileName, c
 ParaMEDMEM::MEDCouplingMesh *MEDLoader::ReadMeshFromFile(const char *fileName, int meshDimRelToMax)
 {
   CheckFileForRead(fileName);
-  MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName);
+  MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName));
   MEDFileMesh *mmPtr(mm);
   MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
   if(mmuPtr)
@@ -1111,7 +1116,7 @@ ParaMEDMEM::MEDCouplingMesh *MEDLoader::ReadMeshFromFile(const char *fileName, i
 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax)
 {
   CheckFileForRead(fileName);
-  MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
+  MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
   MEDFileMesh *mmPtr(mm);
   MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
   if(!mmuPtr)
@@ -1125,7 +1130,7 @@ ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName,
 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, int meshDimRelToMax)
 {
   CheckFileForRead(fileName);
-  MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName);
+  MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName));
   MEDFileMesh *mmPtr(mm);
   MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
   if(!mmuPtr)
@@ -1146,7 +1151,7 @@ int MEDLoader::ReadUMeshDimFromFile(const char *fileName, const char *meshName)
 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& fams)
 {
   CheckFileForRead(fileName);
-  MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,meshName);
+  MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,meshName));
   MEDFileMesh *mmPtr(mm);
   MEDFileUMesh *mmuPtr=dynamic_cast<MEDFileUMesh *>(mmPtr);
   if(!mmuPtr)
@@ -1357,7 +1362,8 @@ void MEDLoader::WriteMesh(const char *fileName, const ParaMEDMEM::MEDCouplingMes
   const MEDCoupling1GTUMesh *um2(dynamic_cast<const MEDCoupling1GTUMesh *>(mesh));
   if(um2)
     {
-      MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu=MEDFileUMesh::New();
+      MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu(MEDFileUMesh::New());
+      AssignStaticWritePropertiesTo(*mmu);
       mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
       mmu->write(fileName,mod);
       return ;
@@ -1365,7 +1371,8 @@ void MEDLoader::WriteMesh(const char *fileName, const ParaMEDMEM::MEDCouplingMes
   const MEDCouplingCMesh *um3(dynamic_cast<const MEDCouplingCMesh *>(mesh));
   if(um3)
     {
-      MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> mmc=MEDFileCMesh::New();
+      MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> mmc(MEDFileCMesh::New());
+      AssignStaticWritePropertiesTo(*mmc);
       mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
       mmc->write(fileName,mod);
       return ;
@@ -1373,7 +1380,8 @@ void MEDLoader::WriteMesh(const char *fileName, const ParaMEDMEM::MEDCouplingMes
   const MEDCouplingCurveLinearMesh *um4(dynamic_cast<const MEDCouplingCurveLinearMesh *>(mesh));
   if(um4)
     {
-      MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> mmc=MEDFileCurveLinearMesh::New();
+      MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
+      AssignStaticWritePropertiesTo(*mmc);
       mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
       mmc->write(fileName,mod);
       return ;
@@ -1386,7 +1394,8 @@ void MEDLoader::WriteUMesh(const char *fileName, const ParaMEDMEM::MEDCouplingUM
   if(!mesh)
     throw INTERP_KERNEL::Exception("MEDLoader::WriteUMesh : input mesh is null !");
   int mod=writeFromScratch?2:0;
-  MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m=MEDFileUMesh::New();
+  MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m(MEDFileUMesh::New());
+  AssignStaticWritePropertiesTo(*m);
   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mcpy(static_cast<MEDCouplingUMesh *>(mesh->deepCpy()));
   m->setMeshAtLevel(0,mcpy,true);
   m->write(fileName,mod);
@@ -1408,7 +1417,8 @@ void MEDLoader::WriteUMeshesPartition(const char *fileName, const char *meshName
       std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
       throw INTERP_KERNEL::Exception(oss.str().c_str());
     }
-  MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m=MEDFileUMesh::New();
+  MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m(MEDFileUMesh::New());
+  AssignStaticWritePropertiesTo(*m);
   m->setGroupsFromScratch(0,meshes,true);
   m->setName(meshNameC);
   int mod=writeFromScratch?2:0;
@@ -1423,14 +1433,16 @@ void MEDLoader::WriteUMeshesPartitionDep(const char *fileName, const char *meshN
 void MEDLoader::WriteUMeshes(const char *fileName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch)
 {
   int mod=writeFromScratch?2:0;
-  MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m=MEDFileUMesh::New();
+  MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> m(MEDFileUMesh::New());
+  AssignStaticWritePropertiesTo(*m);
   m->setMeshes(meshes,true);
   m->write(fileName,mod);
 }
 
 void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch)
 {
-  MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff=MEDFileField1TS::New();
+  MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> ff(MEDFileField1TS::New());
+  MEDLoader::AssignStaticWritePropertiesTo(*ff);
   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> f2(f->deepCpy());
   const MEDCouplingMesh *m(f2->getMesh());
   const MEDCouplingUMesh *um(dynamic_cast<const MEDCouplingUMesh *>(m));
@@ -1441,9 +1453,10 @@ void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const char *fil
   int mod=writeFromScratch?2:0;
   if(um)
     {
-      MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu=MEDFileUMesh::New();
-      MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=um->getRenumArrForMEDFileFrmt();
-      MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o=o2n->invertArrayO2N2N2O(o2n->getNumberOfTuples());
+      MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu(MEDFileUMesh::New());
+      MEDLoader::AssignStaticWritePropertiesTo(*mmu);
+      MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(um->getRenumArrForMEDFileFrmt());
+      MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o(o2n->invertArrayO2N2N2O(o2n->getNumberOfTuples()));
       f2->renumberCells(o2n->begin(),false);
       mmu->setMeshAtLevel(0,const_cast<MEDCouplingUMesh *>(static_cast<const MEDCouplingUMesh *>(f2->getMesh())));
       mmu->setRenumFieldArr(0,n2o);
@@ -1452,21 +1465,24 @@ void MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(const char *fil
     }
   else if(um2)
     {
-      MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu=MEDFileUMesh::New();
+      MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> mmu(MEDFileUMesh::New());
+      MEDLoader::AssignStaticWritePropertiesTo(*mmu);
       mmu->setMeshAtLevel(0,const_cast<MEDCoupling1GTUMesh *>(um2));
       ff->setFieldNoProfileSBT(f2);
       mmu->write(fileName,mod);
     }
   else if(um3)
     {
-      MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> mmc=MEDFileCMesh::New();
+      MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> mmc(MEDFileCMesh::New());
+      MEDLoader::AssignStaticWritePropertiesTo(*mmc);
       mmc->setMesh(const_cast<MEDCouplingCMesh *>(um3));
       ff->setFieldNoProfileSBT(f2);
       mmc->write(fileName,mod);
     }
   else if(um4)
     {
-      MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> mmc=MEDFileCurveLinearMesh::New();
+      MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> mmc(MEDFileCurveLinearMesh::New());
+      MEDLoader::AssignStaticWritePropertiesTo(*mmc);
       mmc->setMesh(const_cast<MEDCouplingCurveLinearMesh *>(um4));
       ff->setFieldNoProfileSBT(f2);
       mmc->write(fileName,mod);
@@ -1501,7 +1517,8 @@ void MEDLoader::WriteField(const char *fileName, const ParaMEDMEM::MEDCouplingFi
         MEDLoaderNS::writeFieldWithoutReadingAndMappingOfMeshInFile(fileName,f,false);
       else
         {
-          MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm=MEDFileMesh::New(fileName,f->getMesh()->getName().c_str());
+          MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> mm(MEDFileMesh::New(fileName,f->getMesh()->getName().c_str()));
+          AssignStaticWritePropertiesTo(*mm);
           const MEDFileMesh *mmPtr(mm);
           const MEDFileUMesh *mmuPtr=dynamic_cast<const MEDFileUMesh *>(mmPtr);
           if(!mmuPtr)
@@ -1525,7 +1542,8 @@ void MEDLoader::WriteField(const char *fileName, const ParaMEDMEM::MEDCouplingFi
                   std::ostringstream oss; oss << "MEDLoader::WriteField : The file \""<< fileName << "\" already contains a mesh named \""<< f->getMesh()->getName() << "\" and this mesh in the file is not compatible (a subpart) with the mesh you intend to write ! This is maybe due to a too strict policy ! Try with to lease it by calling SetCompPolicyForCell !";
                   throw INTERP_KERNEL::Exception(oss.str().c_str());
                 }
-              MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts=MEDFileField1TS::New();
+              MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts(MEDFileField1TS::New());
+              AssignStaticWritePropertiesTo(*f1ts);
               if(part->isIdentity() && part->getNumberOfTuples()==mread->getNumberOfCells())
                 f1ts->setFieldNoProfileSBT(f2);
               else
@@ -1546,7 +1564,8 @@ void MEDLoader::WriteField(const char *fileName, const ParaMEDMEM::MEDCouplingFi
                   std::ostringstream oss; oss << "MEDLoader::WriteField : The file \""<< fileName << "\" already contains a mesh named \""<< f->getMesh()->getName() << "\" and this mesh in the file is not compatible (a subpart regarding nodes) with the mesh you intend to write ! This is maybe due to a too strict epsilon ! Try with to lease it by calling SetEpsilonForNodeComp !";
                   throw INTERP_KERNEL::Exception(oss.str().c_str());
                 }
-              MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts=MEDFileField1TS::New();
+              MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts(MEDFileField1TS::New());
+              AssignStaticWritePropertiesTo(*f1ts);
               if(part->isIdentity() && part->getNumberOfTuples()==mread->getNumberOfNodes())
                 f1ts->setFieldNoProfileSBT(f2);
               else
@@ -1576,7 +1595,8 @@ void MEDLoader::WriteFieldUsingAlreadyWrittenMesh(const char *fileName, const Pa
       std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
       throw INTERP_KERNEL::Exception(oss.str().c_str());
     }
-  MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts=MEDFileField1TS::New();
+  MEDCouplingAutoRefCountObjectPtr<MEDFileField1TS> f1ts(MEDFileField1TS::New());
+  AssignStaticWritePropertiesTo(*f1ts);
   MEDCouplingUMesh *m=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f->getMesh()));
   if(!m)
     throw INTERP_KERNEL::Exception("MEDLoader::WriteFieldUsingAlreadyWrittenMesh : only umesh in input field supported !");
index 5e7187a195924badd9285b1223eefdde592c686f..1f0a7b1305021d5cea2be91333ec99726b2dfc80 100644 (file)
@@ -35,6 +35,7 @@ namespace ParaMEDMEM
   class MEDCouplingMesh;
   class MEDCouplingUMesh;
   class MEDCouplingFieldDouble;
+  class MEDFileWritable;
 }
 
 class MEDLOADER_EXPORT MEDLoader
@@ -97,6 +98,8 @@ class MEDLOADER_EXPORT MEDLoader
   static void WriteField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch);
   static void WriteFieldDep(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch);
   static void WriteFieldUsingAlreadyWrittenMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f);
+ public:
+  static void AssignStaticWritePropertiesTo(ParaMEDMEM::MEDFileWritable& obj);
  private:
   MEDLoader();
  public:
index 991bb2f1fc7485b373888cdf6da2f365966ad398..36900125907b32875099fed55882d84fc53f17e8 100644 (file)
@@ -239,6 +239,7 @@ public:
   static std::vector<std::string> GetCellFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
   static std::vector<std::string> GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception);
   static double GetTimeAttachedOnFieldIteration(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception);
+  static void AssignStaticWritePropertiesTo(ParaMEDMEM::MEDFileWritable& obj) throw(INTERP_KERNEL::Exception);
   %extend
      {
        static PyObject *MEDFileVersion()
index f04d53d953a55c7e4108d5bed1e057f428fd65de..441ee661045fe59bf058109d26c6d446bde0fdb0 100644 (file)
@@ -667,6 +667,49 @@ class MEDLoaderTest(unittest.TestCase):
         self.assertTrue("xonall1" in mesh.getGroupsNames())
         pass
 
+    def testFieldWithTooLongName(self):
+        """ This test is a non regression test, to check that in basic API the policies are taken into account.
+        """
+        fname="Pyfile75.med"
+        # Coordinates
+        coords = [0.,0., 0.,1., 1.,1., 1.,0.]
+        # lvl 0 connectivity
+        conn2D   = [1,2,3,4]
+        # lvl 0 mesh
+        m=MEDLoader.MEDCouplingUMesh.New("mesh",2)
+        m.allocateCells(1)
+        m.insertNextCell(MEDLoader.NORM_QUAD4,4,conn2D)
+        m.finishInsertingCells()
+        # assigning coordinates
+        meshCoords=MEDLoader.DataArrayDouble.New()
+        meshCoords.setValues(coords, 4, 2)
+        m.setCoords(meshCoords)
+        #
+        f=MEDLoader.MEDCouplingFieldDouble.New(MEDLoader.ON_CELLS,MEDLoader.ONE_TIME)
+        f.setMesh(m)
+        d=MEDLoader.DataArrayDouble.New()
+        d.alloc(1,1)
+        d.iota(1.)
+        # seting a long name
+       d.setInfoOnComponent(0,"CONCENTRATION of I129")
+        f.setArray(d)
+        f.setName("field")
+        #
+        mm=MEDLoader.MEDFileUMesh()
+        MEDLoader.MEDLoader.SetTooLongStrPolicy(2)
+        MEDLoader.MEDLoader.AssignStaticWritePropertiesTo(mm)
+        self.assertEqual(2,mm.getTooLongStrPolicy())
+        MEDLoader.MEDLoader.SetTooLongStrPolicy(0)
+        MEDLoader.MEDLoader.AssignStaticWritePropertiesTo(mm)
+        self.assertEqual(0,mm.getTooLongStrPolicy())
+        del mm
+        #
+        MEDLoader.MEDLoader.SetTooLongStrPolicy(2)
+        self.assertRaises(MEDLoader.InterpKernelException,MEDLoader.MEDLoader.WriteField,fname,f,True)# the component name is too long + policy 2 -> throw
+        f.getArray().setInfoOnComponent(0,'I129')
+        MEDLoader.MEDLoader.WriteField(fname,f,True)
+        pass
+
     pass
 
 unittest.main()