Back to index

salome-geom  6.5.0
GEOM_IInsertOperations_i.cc
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 
00023 #ifdef WNT
00024 #pragma warning( disable:4786 )
00025 #endif
00026 
00027 #include <Standard_Stream.hxx>
00028 
00029 #include "GEOM_IInsertOperations_i.hh"
00030 
00031 #include "utilities.h"
00032 #include "OpUtil.hxx"
00033 #include "Utils_ExceptHandlers.hxx"
00034 
00035 #include "GEOM_Engine.hxx"
00036 #include "GEOM_Object.hxx"
00037 
00038 #include <Basics_OCCTVersion.hxx>
00039 
00040 #include <TColStd_HSequenceOfAsciiString.hxx>
00041 
00042 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
00043 #include <TColStd_HArray1OfByte.hxx>
00044 #else
00045 #include <TDataStd_HArray1OfByte.hxx>
00046 #endif
00047 
00048 //=============================================================================
00052 //=============================================================================
00053 GEOM_IInsertOperations_i::GEOM_IInsertOperations_i (PortableServer::POA_ptr thePOA,
00054                                                     GEOM::GEOM_Gen_ptr theEngine,
00055                                                     ::GEOMImpl_IInsertOperations* theImpl)
00056      :GEOM_IOperations_i(thePOA, theEngine, theImpl)
00057 {
00058   MESSAGE("GEOM_IInsertOperations_i::GEOM_IInsertOperations_i");
00059 }
00060 
00061 //=============================================================================
00065 //=============================================================================
00066 GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i()
00067 {
00068   MESSAGE("GEOM_IInsertOperations_i::~GEOM_IInsertOperations_i");
00069 }
00070 
00071 
00072 //=============================================================================
00076 //=============================================================================
00077 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::MakeCopy(GEOM::GEOM_Object_ptr theOriginal)
00078 {
00079   GEOM::GEOM_Object_var aGEOMObject;
00080 
00081   //Set a not done flag
00082   GetOperations()->SetNotDone();
00083 
00084   //Get the reference shape
00085   Handle(GEOM_Object) anOriginal = GetObjectImpl(theOriginal);
00086   if (anOriginal.IsNull()) return aGEOMObject._retn();
00087 
00088   //Create the copy
00089   Handle(GEOM_Object) anObject = GetOperations()->MakeCopy(anOriginal);
00090 
00091   if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
00092 
00093   return GetObject(anObject);
00094 }
00095 
00096 //=============================================================================
00100 //=============================================================================
00101 void GEOM_IInsertOperations_i::Export
00102                    (GEOM::GEOM_Object_ptr theOriginal,
00103                     const char*           theFileName,
00104                     const char*           theFormatName)
00105 {
00106   GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate(theOriginal);
00107 
00108   //Set a not done flag
00109   GetOperations()->SetNotDone();
00110 
00111   //Get the reference shape
00112   Handle(GEOM_Object) anOriginal = GetObjectImpl(theOriginal);
00113   if (anOriginal.IsNull()) return;
00114 
00115   //Export the shape to the file
00116   char* aFileName   = strdup(theFileName);
00117   char* aFormatName = strdup(theFormatName);
00118   GetOperations()->Export(anOriginal, aFileName, aFormatName);
00119   free(aFileName);
00120   free(aFormatName);
00121 }
00122 
00123 //=============================================================================
00127 //=============================================================================
00128 GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::ImportFile
00129                    (const char* theFileName,
00130                     const char* theFormatName)
00131 {
00132   GEOM::GEOM_Object_var aGEOMObject;
00133 
00134   //Set a not done flag
00135   GetOperations()->SetNotDone();
00136 
00137   //Import the shape from the file
00138   char* aFileName   = strdup(theFileName);
00139   char* aFormatName = strdup(theFormatName);
00140   Handle(GEOM_Object) anObject = GetOperations()->Import(aFileName, aFormatName);
00141 
00142   if( strcmp(aFormatName,"IGES_UNIT")==0 && !anObject.IsNull() ) {
00143     free(aFileName);
00144     free(aFormatName);
00145     return GetObject(anObject);
00146   }
00147 
00148   free(aFileName);
00149   free(aFormatName);
00150 
00151   if (!GetOperations()->IsDone() || anObject.IsNull()) {
00152     return aGEOMObject._retn();
00153   }
00154 
00155   return GetObject(anObject);
00156 }
00157 
00158 //=============================================================================
00162 //=============================================================================
00163 void GEOM_IInsertOperations_i::ImportTranslators
00164   (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
00165 {
00166   // allocate the CORBA arrays
00167   GEOM::string_array_var aFormatsArray  = new GEOM::string_array();
00168   GEOM::string_array_var aPatternsArray = new GEOM::string_array();
00169 
00170   // Get sequences of available formats
00171   Handle(TColStd_HSequenceOfAsciiString) aFormats  = new TColStd_HSequenceOfAsciiString;
00172   Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
00173   if (GetOperations()->ImportTranslators(aFormats, aPatterns)) {
00174     const int formSize = aFormats->Length();
00175     if (formSize == aPatterns->Length()) {
00176       aFormatsArray->length(formSize);
00177       aPatternsArray->length(formSize);
00178 
00179       // fill the local CORBA arrays with values from sequences
00180       CORBA::Long i = 1;
00181       for (; i <= formSize; i++) {
00182         aFormatsArray[i-1]  = CORBA::string_dup(aFormats->Value(i).ToCString());
00183         aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
00184       }
00185     }
00186   }
00187 
00188   // initialize out-parameters with local arrays
00189   theFormats  = aFormatsArray._retn();
00190   thePatterns = aPatternsArray._retn();
00191 }
00192 
00193 //=============================================================================
00197 //=============================================================================
00198 void GEOM_IInsertOperations_i::ExportTranslators
00199   (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
00200 {
00201   // allocate the CORBA arrays
00202   GEOM::string_array_var aFormatsArray  = new GEOM::string_array();
00203   GEOM::string_array_var aPatternsArray = new GEOM::string_array();
00204 
00205   // Get sequences of available formats
00206   Handle(TColStd_HSequenceOfAsciiString) aFormats  = new TColStd_HSequenceOfAsciiString;
00207   Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
00208   if (GetOperations()->ExportTranslators(aFormats, aPatterns)) {
00209     const int formSize = aFormats->Length();
00210     if (formSize == aPatterns->Length()) {
00211       aFormatsArray->length(formSize);
00212       aPatternsArray->length(formSize);
00213 
00214       // fill the local CORBA arrays with values from sequences
00215       CORBA::Long i = 1;
00216       for (; i <= formSize; i++) {
00217         aFormatsArray[i-1]  = CORBA::string_dup(aFormats->Value(i).ToCString());
00218         aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
00219       }
00220     }
00221   }
00222 
00223   // initialize out-parameters with local arrays
00224   theFormats  = aFormatsArray._retn();
00225   thePatterns = aPatternsArray._retn();
00226 }
00227 
00228 CORBA::Long GEOM_IInsertOperations_i::LoadTexture(const char* theTextureFile)
00229 {
00230   GetOperations()->SetNotDone();
00231   return GetOperations()->LoadTexture( theTextureFile );
00232 }
00233 
00234 CORBA::Long GEOM_IInsertOperations_i::AddTexture(CORBA::Long theWidth, CORBA::Long theHeight,
00235                                                  const SALOMEDS::TMPFile& theTexture)
00236 {
00237   GetOperations()->SetNotDone();
00238 
00239 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
00240   Handle(TColStd_HArray1OfByte) aTexture;
00241 #else
00242   Handle(TDataStd_HArray1OfByte) aTexture;
00243 #endif
00244 
00245   if ( theTexture.length() > 0 ) {
00246 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
00247     aTexture = new TColStd_HArray1OfByte (1, theTexture.length());
00248 #else
00249     aTexture = new TDataStd_HArray1OfByte (1, theTexture.length());
00250 #endif
00251 
00252     for ( int i = 0; i < theTexture.length(); i++ )
00253       aTexture->SetValue( i+1, (Standard_Byte)theTexture[i] );
00254   }
00255   return GetOperations()->AddTexture( theWidth, theHeight, aTexture );
00256 }
00257 
00258 SALOMEDS::TMPFile* GEOM_IInsertOperations_i::GetTexture(CORBA::Long theID,
00259                                                         CORBA::Long& theWidth,
00260                                                         CORBA::Long& theHeight)
00261 {
00262   int aWidth, aHeight;
00263 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
00264   Handle(TColStd_HArray1OfByte) aTextureImpl =
00265 #else
00266   Handle(TDataStd_HArray1OfByte) aTextureImpl =
00267 #endif
00268     GetOperations()->GetTexture(theID, aWidth, aHeight);
00269   theWidth  = aWidth;
00270   theHeight = aHeight;
00271   SALOMEDS::TMPFile_var aTexture;
00272   if ( !aTextureImpl.IsNull() ) {
00273     aTexture = new SALOMEDS::TMPFile;
00274     aTexture->length( aTextureImpl->Length() );
00275     for ( int i = aTextureImpl->Lower(); i <= aTextureImpl->Upper(); i++ )
00276       aTexture[i-aTextureImpl->Lower()] = aTextureImpl->Value( i );
00277   }
00278   return aTexture._retn();
00279 }
00280 
00281 GEOM::ListOfLong* GEOM_IInsertOperations_i::GetAllTextures()
00282 {
00283   std::list<int> localIDs = GetOperations()->GetAllTextures();
00284   GEOM::ListOfLong_var anIDs = new GEOM::ListOfLong(localIDs.size());
00285   anIDs->length(localIDs.size());
00286   std::list<int>::const_iterator anIt;
00287   int i = 0;
00288   for( anIt = localIDs.begin(); anIt != localIDs.end(); ++anIt, i++)
00289     anIDs[i] = *anIt;
00290   return anIDs._retn();
00291 }