Salome HOME
Merge branch merge_1_2_d
[modules/smesh.git] / src / SMESH_I / SMESH_Gen_i.cxx
index aeed1e4b8c35db49388fa076d59d63fbc6a791ac..b55ed358bd435e495cc3ccc3d447b8254b031c0d 100644 (file)
@@ -1,14 +1,32 @@
-using namespace std;
-//=============================================================================
-// File      : SMESH_Gen_i.cxx
-// Created   : lun mai  6 13:41:35 CEST 2002
-// Author    : Paul RASCLE, EDF
-// Project   : SALOME
-// Copyright : EDF 2002
-// $Header$
-//=============================================================================
-using namespace std;
+//  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : SMESH_Gen_i.cxx
+//  Author : Paul RASCLE, EDF
+//  Module : SMESH
+//  $Header$
 
 
+using namespace std;
 #include <TopExp.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
 #include <TopExp.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
@@ -35,6 +53,7 @@ using namespace std;
 #include "SMESH_LocalLength_i.hxx"
 #include "SMESH_NumberOfSegments_i.hxx"
 #include "SMESH_MaxElementArea_i.hxx"
 #include "SMESH_LocalLength_i.hxx"
 #include "SMESH_NumberOfSegments_i.hxx"
 #include "SMESH_MaxElementArea_i.hxx"
+#include "SMESH_MaxElementVolume_i.hxx"
 
 #include "SMESHDS_Document.hxx"
 
 
 #include "SMESHDS_Document.hxx"
 
@@ -406,13 +425,13 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
   SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
   aFileSeq->length(NUM_TMP_FILES);
 
   SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
   aFileSeq->length(NUM_TMP_FILES);
 
-  TCollection_AsciiString aStudyName(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()));
+  TCollection_AsciiString aStudyName("");
 
   // Set names of temporary files
 
   // Set names of temporary files
-  TCollection_AsciiString filename = aStudyName + TCollection_AsciiString("SMESH.hdf");
-  TCollection_AsciiString hypofile = aStudyName + TCollection_AsciiString("SMESH_Hypo.txt");
-  TCollection_AsciiString algofile = aStudyName + TCollection_AsciiString("SMESH_Algo.txt");
-  TCollection_AsciiString meshfile = aStudyName + TCollection_AsciiString("SMESH_Mesh.med");
+  TCollection_AsciiString filename = aStudyName + TCollection_AsciiString("_SMESH.hdf");
+  TCollection_AsciiString hypofile = aStudyName + TCollection_AsciiString("_SMESH_Hypo.txt");
+  TCollection_AsciiString algofile = aStudyName + TCollection_AsciiString("_SMESH_Algo.txt");
+  TCollection_AsciiString meshfile = aStudyName + TCollection_AsciiString("_SMESH_Mesh.med");
   aFileSeq[0] = CORBA::string_dup(filename.ToCString());
   aFileSeq[1] = CORBA::string_dup(hypofile.ToCString());
   aFileSeq[2] = CORBA::string_dup(algofile.ToCString());
   aFileSeq[0] = CORBA::string_dup(filename.ToCString());
   aFileSeq[1] = CORBA::string_dup(hypofile.ToCString());
   aFileSeq[2] = CORBA::string_dup(algofile.ToCString());
@@ -447,7 +466,7 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
 //************branch 1 : hypothesis
     if (gotBranch->Tag()==Tag_HypothesisRoot) { //hypothesis = tag 1
 
 //************branch 1 : hypothesis
     if (gotBranch->Tag()==Tag_HypothesisRoot) { //hypothesis = tag 1
 
-      double length,maxElementsArea;
+      double length,maxElementsArea,maxElementsVolume;
       int numberOfSegments;
 
       destFile = fopen( hypofile.ToCString() ,"w");
       int numberOfSegments;
 
       destFile = fopen( hypofile.ToCString() ,"w");
@@ -477,6 +496,11 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
             maxElementsArea = MEA->GetMaxElementArea();
             fprintf(destFile,"%f\n",maxElementsArea);
           }
             maxElementsArea = MEA->GetMaxElementArea();
             fprintf(destFile,"%f\n",maxElementsArea);
           }
+          else if (strcmp(myHyp->GetName(),"MaxElementVolume")==0) {
+            SMESH::SMESH_MaxElementVolume_var MEV = SMESH::SMESH_MaxElementVolume::_narrow( myHyp );
+            maxElementsVolume = MEV->GetMaxElementVolume();
+            fprintf(destFile,"%f\n",maxElementsVolume);
+          }
         }
       }
       fclose(destFile);
         }
       }
       fclose(destFile);
@@ -553,7 +577,7 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
        int meshId = myMesh->GetId();
        SMESH_Mesh_i* meshServant = myStudyContext->mapMesh_i[meshId];
        ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
        int meshId = myMesh->GetId();
        SMESH_Mesh_i* meshServant = myStudyContext->mapMesh_i[meshId];
        ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
-       Handle(SMESHDS_Mesh) mySMESHDSMesh = myLocMesh.GetMeshDS();
+       SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
        
        SCRUTE(mySMESHDSMesh->NbNodes());
        if (mySMESHDSMesh->NbNodes()>0) {//checks if the mesh is not empty
        
        SCRUTE(mySMESHDSMesh->NbNodes());
        if (mySMESHDSMesh->NbNodes()>0) {//checks if the mesh is not empty
@@ -824,13 +848,20 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
   aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.ToCString(), aFileSeq.in(), isMultiFile);
 
   // Remove temporary files and directory
   aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.ToCString(), aFileSeq.in(), isMultiFile);
 
   // Remove temporary files and directory
-  if (isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.ToCString(), aFileSeq.in(), true);
+  if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.ToCString(), aFileSeq.in(), true);
 
   MESSAGE("End SMESH_Gen_i::Save");
 
   return aStreamFile._retn();
 }
 
 
   MESSAGE("End SMESH_Gen_i::Save");
 
   return aStreamFile._retn();
 }
 
+SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
+                                         const char* theURL,
+                                         bool isMultiFile) {
+  SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
+  return aStreamFile._retn();
+}
+
 //=============================================================================
 /*!
  *  
 //=============================================================================
 /*!
  *  
@@ -852,11 +883,14 @@ bool SMESH_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
                                                                            tmpDir.ToCString(),
                                                                           isMultiFile);
 
                                                                            tmpDir.ToCString(),
                                                                           isMultiFile);
 
+  TCollection_AsciiString aStudyName("");
+  if (isMultiFile) aStudyName = (SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()));
+
   // Set names of temporary files
   // Set names of temporary files
-  TCollection_AsciiString filename = tmpDir + aFileSeq[0];//"SMESH.hdf";
-  TCollection_AsciiString hypofile = tmpDir + aFileSeq[1];//"SMESH_Hypo.txt";
-  TCollection_AsciiString algofile = tmpDir + aFileSeq[2];//"SMESH_Algo.txt";
-  TCollection_AsciiString meshfile = tmpDir + aFileSeq[3];//"SMESH_Mesh.med";
+  TCollection_AsciiString filename = tmpDir + aStudyName + TCollection_AsciiString("_SMESH.hdf");
+  TCollection_AsciiString hypofile = tmpDir + aStudyName + TCollection_AsciiString("_SMESH_Hypo.txt");
+  TCollection_AsciiString algofile = tmpDir + aStudyName + TCollection_AsciiString("_SMESH_Algo.txt");
+  TCollection_AsciiString meshfile = tmpDir + aStudyName + TCollection_AsciiString("_SMESH_Mesh.med");
 
   SALOMEDS::Study_var Study = theComponent->GetStudy(); 
   int studyId = Study->StudyId();
 
   SALOMEDS::Study_var Study = theComponent->GetStudy(); 
   int studyId = Study->StudyId();
@@ -920,7 +954,7 @@ bool SMESH_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
 //***************
       if (strcmp(name,"Hypothesis")==0) {
         
 //***************
       if (strcmp(name,"Hypothesis")==0) {
         
-        double length,maxElementsArea;
+        double length,maxElementsArea,maxElementsVolume;
         int numberOfSegments;
 
         hdf_group[Tag_HypothesisRoot] = new HDFgroup(name,hdf_file); 
         int numberOfSegments;
 
         hdf_group[Tag_HypothesisRoot] = new HDFgroup(name,hdf_file); 
@@ -975,6 +1009,16 @@ bool SMESH_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
             sprintf(objectId,"%d",MEA->GetId());
             _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
           }
             sprintf(objectId,"%d",MEA->GetId());
             _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
           }
+          else if (strcmp(aLine,"MaxElementVolume")==0) {
+            SMESH::SMESH_Hypothesis_var myHyp  = this->CreateHypothesis(aLine,studyId);
+            SMESH::SMESH_MaxElementVolume_var MEV = SMESH::SMESH_MaxElementVolume::_narrow( myHyp );
+            fscanf(loadedFile,"%s",aLine);
+            maxElementsVolume = atof(aLine);
+            MEV->SetMaxElementVolume(maxElementsVolume);
+            string iorString = _orb->object_to_string(MEV);
+            sprintf(objectId,"%d",MEV->GetId());
+            _SMESHCorbaObj[string("Hypo_")+string(objectId)] = iorString;
+          }
           
 
         }
           
 
         }
@@ -1111,7 +1155,7 @@ bool SMESH_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
              int meshId = myNewMesh->GetId();
              SMESH_Mesh_i* meshServant = myStudyContext->mapMesh_i[meshId];
              ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
              int meshId = myNewMesh->GetId();
              SMESH_Mesh_i* meshServant = myStudyContext->mapMesh_i[meshId];
              ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
-             Handle(SMESHDS_Mesh) mySMESHDSMesh = myLocMesh.GetMeshDS();
+             SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
                    
              DriverMED_R_SMESHDS_Mesh* myReader = new DriverMED_R_SMESHDS_Mesh;
                    
                    
              DriverMED_R_SMESHDS_Mesh* myReader = new DriverMED_R_SMESHDS_Mesh;
                    
@@ -1404,6 +1448,13 @@ bool SMESH_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
   return true;
 }
 
   return true;
 }
 
+bool SMESH_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
+                           const SALOMEDS::TMPFile& theStream,
+                           const char* theURL,
+                           bool isMultiFile) {
+  return Load(theComponent, theStream, theURL, isMultiFile);
+}
+
 //=============================================================================
 /*!
  *  
 //=============================================================================
 /*!
  *  
@@ -1493,7 +1544,8 @@ char* SMESH_Gen_i::ComponentDataType()
 
 char* SMESH_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
                                          const char* IORString,
 
 char* SMESH_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
                                          const char* IORString,
-                                         CORBA::Boolean isMultiFile)
+                                         CORBA::Boolean isMultiFile,
+                                         CORBA::Boolean isASCII)
 {
   MESSAGE("SMESH_Gen_i::IORToLocalPersistentID");
 
 {
   MESSAGE("SMESH_Gen_i::IORToLocalPersistentID");
 
@@ -1548,7 +1600,8 @@ char* SMESH_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
 
 char* SMESH_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
                                          const char* aLocalPersistentID,
 
 char* SMESH_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
                                          const char* aLocalPersistentID,
-                                         CORBA::Boolean isMultiFile)
+                                         CORBA::Boolean isMultiFile,
+                                         CORBA::Boolean isASCII)
 {
   MESSAGE("SMESH_Gen_i::LocalPersistentIDToIOR");
   SCRUTE(aLocalPersistentID);
 {
   MESSAGE("SMESH_Gen_i::LocalPersistentIDToIOR");
   SCRUTE(aLocalPersistentID);