Salome HOME
sources v1.2
[modules/geom.git] / src / GEOM / GEOM_Gen_i.cc
index 7b9ecff28bf167ae2c15a64d2ac4680ebdfb6a27..344dd05eb96cec3e6ad94a4db21c8b95ba8c23bc 100644 (file)
@@ -1,11 +1,32 @@
-using namespace std;
-// File :      GEOM_GEN_i.cc file
-// Created :   
-// Author :    Lucien PIGNOLONI
-// Project :   SALOME
-// Copyright : OPEN CASCADE
-// $Header$
+//  GEOM GEOM : implementaion of GEOM_Gen.idl and GEOM_Shape.idl
+//
+//  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   : GEOM_GEN_i.cc file
+//  Author : Lucien PIGNOLONI
+//  Module : GEOM
+//  $Header$
 
+using namespace std;
 #include "GEOM_Gen_i.hh"
 
 #include "Partition_Spliter.hxx"
@@ -165,7 +186,8 @@ GEOM_Gen_i::~GEOM_Gen_i() {
 //============================================================================
 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
                                         const char* IORString,
-                                        CORBA::Boolean isMultiFile)
+                                        CORBA::Boolean isMultiFile,
+                                        CORBA::Boolean isASCII)
 {
   GEOM::GEOM_Shape_var aShape = GEOM::GEOM_Shape::_narrow(_orb->string_to_object(IORString));
   if (!CORBA::is_nil(aShape)) {
@@ -183,7 +205,8 @@ char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
 //============================================================================
 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
                                         const char* aLocalPersistentID,
-                                        CORBA::Boolean isMultiFile) 
+                                        CORBA::Boolean isMultiFile,
+                                        CORBA::Boolean isASCII) 
 { 
   SALOMEDS::Study_var myStudy = theSObject->GetStudy();
   GetCurrentStudy(myStudy->StudyId());
@@ -221,7 +244,7 @@ char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
       CORBA::String_var ent = strdup(entry.ToCString());
       
       /* Create the main object recursively */
-      MainIOR = LocalPersistentIDToIOR(theSObject, ent, isMultiFile ) ;
+      MainIOR = LocalPersistentIDToIOR(theSObject, ent, isMultiFile, isASCII) ;
     } else {
       GC.ReturnNameIOR( mainLabel, MainIOR ); 
     }
@@ -427,21 +450,38 @@ SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
   return aStreamFile._retn();
 }
 
+SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
+                                        const char* theURL,
+                                        bool isMultiFile) {
+  SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
+  return aStreamFile._retn();
+}
+
+
 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
                                const SALOMEDS::TMPFile& theStream,
                                const char* theURL,
                                bool isMultiFile) {
+
+  if (theStream.length() <= 9) {
+    MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
+    return false;
+  }
+
   // Get a temporary directory for a file
   TCollection_AsciiString aTmpDir = isMultiFile?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
   // Conver the byte stream theStream to a file and place it in tmp directory
   SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
                                                                       aTmpDir.ToCString(),
                                                                       isMultiFile);
+
   // Prepare a file name to open
   TCollection_AsciiString aNameWithExt(aSeq[0]);
   TCollection_AsciiString aFullName = aTmpDir + aNameWithExt;
+
   // Open document
   if (myOCAFApp->Open(aFullName, myCurrentOCAFDoc) != CDF_RS_OK) return false;
+
   // Remove the created file and tmp directory
   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
 
@@ -451,6 +491,7 @@ CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
   int StudyID = Study->StudyId();
   myStudyIDToDoc.Bind( StudyID, myCurrentOCAFDoc );  
   myStudyID = StudyID;
+    
   /* We clear all IOR (nameIOR) attributes of all objects before reconstruction */
   /* This information will be setted when each object is reconstructed          */
   GEOMDS_Commands GC( myCurrentOCAFDoc->Main() ) ;
@@ -459,6 +500,13 @@ CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
   return true;
 }
 
+CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
+                                    const SALOMEDS::TMPFile& theStream,
+                                    const char* theURL,
+                                    bool isMultiFile) {
+  return Load(theComponent, theStream, theURL, isMultiFile);
+}
+
 //  //============================================================================
 //  // function : Save()
 //  // purpose  : save OCAF/Geom document
@@ -4050,8 +4098,8 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeMirrorByPlane(GEOM::GEOM_Shape_ptr myShape,
   /* Insert arguments in ocaf */
   GEOM::GEOM_Gen::ListOfIOR_var ListShapes = new GEOM::GEOM_Gen::ListOfIOR;
   ListShapes->length(2);
-  ListShapes[0] = GetStringFromIOR(myShape) ;
-  ListShapes[1] = GetStringFromIOR(shapePlane) ;
+  ListShapes[0] = GetStringFromIOR(GEOM::GEOM_Shape::_duplicate(myShape)) ;
+  ListShapes[1] = GetStringFromIOR(GEOM::GEOM_Shape::_duplicate(shapePlane)) ;
   InsertInLabelMoreArguments(tds, result, ListShapes, myCurrentOCAFDoc) ;
   return result ;
 }
@@ -4318,8 +4366,8 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakePipe( GEOM::GEOM_Shape_ptr pathShape,
     /* Insert arguments in ocaf */
     GEOM::GEOM_Gen::ListOfIOR_var ListShapes = new GEOM::GEOM_Gen::ListOfIOR;
     ListShapes->length(2);
-    ListShapes[0] = GetStringFromIOR(pathShape) ;
-    ListShapes[1] = GetStringFromIOR(baseShape) ;    
+    ListShapes[0] = GetStringFromIOR(GEOM::GEOM_Shape::_duplicate(pathShape)) ;
+    ListShapes[1] = GetStringFromIOR(GEOM::GEOM_Shape::_duplicate(baseShape)) ;    
     InsertInLabelMoreArguments(tds, result, ListShapes, myCurrentOCAFDoc) ;
   }
   return result ;