Salome HOME
Mantis issue 0021837: [CEA 654] Add new method to make any point inside a face.
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IInsertOperations.cxx
index 80f4a296265b4f3d26cdcbd0884fd7be34811772..2a83dd58de47f54c4b43d3ac11d040c41cb8b378 100644 (file)
@@ -1,28 +1,40 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007  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 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.
+// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+
 #include <Standard_Stream.hxx>
 
 #include <GEOMImpl_IInsertOperations.hxx>
 
+#include <GEOMImpl_CopyDriver.hxx>
+#include <GEOMImpl_ExportDriver.hxx>
+#include <GEOMImpl_ImportDriver.hxx>
+#include <GEOMImpl_ICopy.hxx>
+#include <GEOMImpl_IImportExport.hxx>
+#include <GEOMImpl_Types.hxx>
+
+#include <GEOM_Function.hxx>
+#include <GEOM_PythonDump.hxx>
+
+#include <Basics_OCCTVersion.hxx>
+
 #include "utilities.h"
 #include <OpUtil.hxx>
 #include <Utils_ExceptHandlers.hxx>
 #include <TFunction_Logbook.hxx>
 #include <TDF_Tool.hxx>
 
-#include <GEOM_Function.hxx>
-#include <GEOM_PythonDump.hxx>
-
-#include <GEOMImpl_CopyDriver.hxx>
-#include <GEOMImpl_ExportDriver.hxx>
-#include <GEOMImpl_ImportDriver.hxx>
-
-#include <GEOMImpl_ICopy.hxx>
-#include <GEOMImpl_IImportExport.hxx>
-
-#include <GEOMImpl_Types.hxx>
-
 #include <TopoDS.hxx>
 #include <TopoDS_Vertex.hxx>
 #include <BRep_Tool.hxx>
 #include <gp_Pnt.hxx>
+
+#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
+#include <TColStd_HArray1OfByte.hxx>
+#else
 #include <TDataStd_HArray1OfByte.hxx>
+#endif
 
 #include <Standard_Failure.hxx>
 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
 
 //=============================================================================
 /*!
- *   constructor:
+ *  constructor
  */
 //=============================================================================
-
 GEOMImpl_IInsertOperations::GEOMImpl_IInsertOperations(GEOM_Engine* theEngine, int theDocID)
 : GEOM_IOperations(theEngine, theDocID)
 {
@@ -70,20 +74,17 @@ GEOMImpl_IInsertOperations::GEOMImpl_IInsertOperations(GEOM_Engine* theEngine, i
  *  destructor
  */
 //=============================================================================
-
 GEOMImpl_IInsertOperations::~GEOMImpl_IInsertOperations()
 {
   MESSAGE("GEOMImpl_IInsertOperations::~GEOMImpl_IInsertOperations");
 }
 
-
-
 //=============================================================================
 /*!
  *  MakeCopy
  */
 //=============================================================================
-Handle(GEOM_Object) GEOMImpl_IInsertOperations::MakeCopy(Handle(GEOM_Object) theOriginal)
+Handle(GEOM_Object) GEOMImpl_IInsertOperations::MakeCopy (Handle(GEOM_Object) theOriginal)
 {
   SetErrorCode(KO);
 
@@ -107,7 +108,7 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::MakeCopy(Handle(GEOM_Object) the
 
   //Compute the Copy value
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
 #endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
@@ -135,8 +136,8 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::MakeCopy(Handle(GEOM_Object) the
 //=============================================================================
 void GEOMImpl_IInsertOperations::Export
                      (const Handle(GEOM_Object)      theOriginal,
-                     const TCollection_AsciiString& theFileName,
-                     const TCollection_AsciiString& theFormatName)
+                      const TCollection_AsciiString& theFileName,
+                      const TCollection_AsciiString& theFormatName)
 {
   SetErrorCode(KO);
 
@@ -145,8 +146,11 @@ void GEOMImpl_IInsertOperations::Export
   Handle(GEOM_Function) aRefFunction = theOriginal->GetLastFunction();
   if (aRefFunction.IsNull()) return;  //There is no function which creates an object to be exported
 
+  //Add a new result object
+  Handle(GEOM_Object) result = GetEngine()->AddObject(GetDocID(), GEOM_IMPORT);
+
   //Add an Export function
-  Handle(GEOM_Function) aFunction = theOriginal->AddFunction(GEOMImpl_ExportDriver::GetID(), EXPORT_SHAPE);
+  Handle(GEOM_Function) aFunction = result->AddFunction(GEOMImpl_ExportDriver::GetID(), EXPORT_SHAPE);
   if (aFunction.IsNull()) return;
 
   //Check if the function is set correctly
@@ -167,7 +171,7 @@ void GEOMImpl_IInsertOperations::Export
 
   //Perform the Export
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
 #endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
@@ -195,7 +199,7 @@ void GEOMImpl_IInsertOperations::Export
 //=============================================================================
 Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import
                                  (const TCollection_AsciiString& theFileName,
-                                 const TCollection_AsciiString& theFormatName)
+                                  const TCollection_AsciiString& theFormatName)
 {
   SetErrorCode(KO);
 
@@ -222,11 +226,10 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import
   aCI.SetFileName(theFileName);
   aCI.SetFormatName(theFormatName);
   aCI.SetPluginName(aLibName);
-  //cout<<"IIO: theFormatName = "<<theFormatName.ToCString()<<endl;
 
   //Perform the Import
   try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
 #endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
@@ -242,13 +245,14 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import
 
   //Make a Python command
   if( theFormatName != "IGES_UNIT" ) {
-    GEOM::TPythonDump(aFunction) << result << " = geompy.Import(\""
+    GEOM::TPythonDump(aFunction) << result << " = geompy.ImportFile(\""
       << theFileName.ToCString() << "\", \"" << theFormatName.ToCString() << "\")";
   }
 
   SetErrorCode(OK);
 
-  if( theFormatName == "IGES_UNIT" ) {
+  // OLD CODE: begin
+  if (theFormatName == "IGES_UNIT") {
     TopoDS_Shape S = aFunction->GetValue();
     TopoDS_Vertex V = TopoDS::Vertex(S);
     gp_Pnt P = BRep_Tool::Pnt(V);
@@ -261,10 +265,42 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import
     //cout<<"IIO: aUnitName = "<<aUnitName.ToCString()<<endl;
     SetErrorCode(aUnitName);
   }
+  // OLD CODE: end
 
   return result;
 }
 
+//=============================================================================
+/*!
+ *  ReadValue
+ */
+//=============================================================================
+TCollection_AsciiString GEOMImpl_IInsertOperations::ReadValue
+                                 (const TCollection_AsciiString& theFileName,
+                                  const TCollection_AsciiString& theFormatName,
+                                  const TCollection_AsciiString& theParameterName)
+{
+  SetErrorCode(KO);
+
+  TCollection_AsciiString aValue, anError;
+
+  if (theFileName.IsEmpty() || theFormatName.IsEmpty() || theParameterName.IsEmpty()) return aValue;
+
+  Handle(TCollection_HAsciiString) aHLibName;
+  if (!IsSupported(Standard_True, theFormatName.SubString(1,4), aHLibName)) {
+    return aValue;
+  }
+  TCollection_AsciiString aLibName = aHLibName->String();
+
+  aValue = GEOMImpl_ImportDriver::ReadValue(theFileName, aLibName, theParameterName, anError);
+  if (anError.IsEmpty())
+    SetErrorCode(OK);
+  else
+    SetErrorCode(anError.ToCString());
+
+  return aValue;
+}
+
 //=============================================================================
 /*!
  *  ImportTranslators
@@ -272,7 +308,7 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import
 //=============================================================================
 Standard_Boolean GEOMImpl_IInsertOperations::ImportTranslators
                      (Handle(TColStd_HSequenceOfAsciiString)& theFormats,
-                     Handle(TColStd_HSequenceOfAsciiString)& thePatterns)
+                      Handle(TColStd_HSequenceOfAsciiString)& thePatterns)
 {
   if (theFormats.IsNull())
     theFormats = new TColStd_HSequenceOfAsciiString;
@@ -305,13 +341,13 @@ Standard_Boolean GEOMImpl_IInsertOperations::ImportTranslators
       int aLenFormats = theFormats->Length();
       bool isFound = false;
       for(int aInd=1;aInd<=aLenFormats;aInd++){
-       if( theFormats->Value(aInd) == aToken){
-         isFound = true;
-         break;
-       }
+        if( theFormats->Value(aInd) == aToken){
+          isFound = true;
+          break;
+        }
       }
       if(!isFound)
-       theFormats->Append(aToken);
+        theFormats->Append(aToken);
     }
   }
 
@@ -329,7 +365,7 @@ Standard_Boolean GEOMImpl_IInsertOperations::ImportTranslators
       if (myResMgr->Find(aKey.ToCString()))
         aPattern = myResMgr->Value(aKey.ToCString());
       else if(myResMgrUser->Find(aKey.ToCString()))
-       aPattern = myResMgrUser->Value(aKey.ToCString());
+        aPattern = myResMgrUser->Value(aKey.ToCString());
       else {
         aPattern = theFormats->Value(j);
         aPattern += " Files ( *.* )";
@@ -348,7 +384,7 @@ Standard_Boolean GEOMImpl_IInsertOperations::ImportTranslators
 //=============================================================================
 Standard_Boolean GEOMImpl_IInsertOperations::ExportTranslators
                      (Handle(TColStd_HSequenceOfAsciiString)& theFormats,
-                     Handle(TColStd_HSequenceOfAsciiString)& thePatterns)
+                      Handle(TColStd_HSequenceOfAsciiString)& thePatterns)
 {
   if (theFormats.IsNull())
     theFormats = new TColStd_HSequenceOfAsciiString;
@@ -381,13 +417,13 @@ Standard_Boolean GEOMImpl_IInsertOperations::ExportTranslators
       int aLenFormats = theFormats->Length();
       bool isFound = false;
       for(int aInd=1;aInd<=aLenFormats;aInd++){
-       if( theFormats->Value(aInd) == aToken){
-         isFound = true;
-         break;
-       }
+        if( theFormats->Value(aInd) == aToken){
+          isFound = true;
+          break;
+        }
       }
       if(!isFound)
-       theFormats->Append(aToken);
+        theFormats->Append(aToken);
     }
   }
 
@@ -405,7 +441,7 @@ Standard_Boolean GEOMImpl_IInsertOperations::ExportTranslators
       if (myResMgr->Find(aKey.ToCString()))
         aPattern = myResMgr->Value(aKey.ToCString());
       else if (myResMgrUser->Find(aKey.ToCString()))
-       aPattern = myResMgrUser->Value(aKey.ToCString());
+        aPattern = myResMgrUser->Value(aKey.ToCString());
       else {
         aPattern = theFormats->Value(j);
         aPattern += " Files ( *.* )";
@@ -542,7 +578,7 @@ Standard_Boolean GEOMImpl_IInsertOperations::InitResMgr()
   }
 
   return ( myResMgr->Find("Import") || myResMgr->Find("Export") ||
-          myResMgrUser->Find("Import") || myResMgrUser->Find("Export"));
+           myResMgrUser->Find("Import") || myResMgrUser->Find("Export"));
 }
 
 int GEOMImpl_IInsertOperations::LoadTexture(const TCollection_AsciiString& theTextureFile)
@@ -551,7 +587,11 @@ int GEOMImpl_IInsertOperations::LoadTexture(const TCollection_AsciiString& theTe
 
   if (theTextureFile.IsEmpty()) return 0;
 
+#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
+  Handle(TColStd_HArray1OfByte) aTexture;
+#else
   Handle(TDataStd_HArray1OfByte) aTexture;
+#endif
 
   FILE* fp = fopen(theTextureFile.ToCString(), "r");
   if (!fp) return 0;
@@ -583,7 +623,7 @@ int GEOMImpl_IInsertOperations::LoadTexture(const TCollection_AsciiString& theTe
     for (int i = 0; i < lenline/8; i++) {
       unsigned char byte = 0;
       for (int j = 0; j < 8; j++)
-       byte = (byte << 1) + ( i*8+j < line.size() && line[i*8+j] != '0' ? 1 : 0 );
+        byte = (byte << 1) + ( i*8+j < line.size() && line[i*8+j] != '0' ? 1 : 0 );
       bytedata.push_back(byte);
     }
     for (int i = lenline/8; i < lenbytes; i++)
@@ -593,7 +633,12 @@ int GEOMImpl_IInsertOperations::LoadTexture(const TCollection_AsciiString& theTe
   if (bytedata.empty() || bytedata.size() != lines.size()*lenbytes)
     return 0;
 
-  aTexture = new TDataStd_HArray1OfByte(1, lines.size()*lenbytes);
+#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
+  aTexture = new TColStd_HArray1OfByte (1, lines.size()*lenbytes);
+#else
+  aTexture = new TDataStd_HArray1OfByte (1, lines.size()*lenbytes);
+#endif
+
   std::list<unsigned char>::iterator bdit;
   int i;
   for (i = 1, bdit = bytedata.begin(); bdit != bytedata.end(); ++bdit, ++i)
@@ -605,7 +650,11 @@ int GEOMImpl_IInsertOperations::LoadTexture(const TCollection_AsciiString& theTe
 }
   
 int GEOMImpl_IInsertOperations::AddTexture(int theWidth, int theHeight, 
-                                          const Handle(TDataStd_HArray1OfByte)& theTexture)
+#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
+                                           const Handle(TColStd_HArray1OfByte)& theTexture)
+#else
+                                           const Handle(TDataStd_HArray1OfByte)& theTexture)
+#endif
 {
   SetErrorCode(KO);
   int aTextureId = GetEngine()->addTexture(GetDocID(), theWidth, theHeight, theTexture);
@@ -613,12 +662,21 @@ int GEOMImpl_IInsertOperations::AddTexture(int theWidth, int theHeight,
   return aTextureId;
 }
 
+#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
+Handle(TColStd_HArray1OfByte) GEOMImpl_IInsertOperations::GetTexture(int theTextureId,
+#else
 Handle(TDataStd_HArray1OfByte) GEOMImpl_IInsertOperations::GetTexture(int theTextureId,
-                                                                     int& theWidth, int& theHeight)
+#endif
+                                                                      int& theWidth, int& theHeight)
 {
   SetErrorCode(KO);
   
+#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
+  Handle(TColStd_HArray1OfByte) aTexture;
+#else
   Handle(TDataStd_HArray1OfByte) aTexture;
+#endif
+
   theWidth = theHeight = 0;
   TCollection_AsciiString aFileName;