Salome HOME
Remove unnecessary includes
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IInsertOperations.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 7e76067..cc09d46
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021  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
@@ -29,6 +29,7 @@
 #include <GEOMImpl_ImportDriver.hxx>
 #include <GEOMImpl_ICopy.hxx>
 #include <GEOMImpl_IImportExport.hxx>
+#include <GEOMImpl_ITransferData.hxx>
 #include <GEOMImpl_Types.hxx>
 #include "GEOMImpl_IShapesOperations.hxx"
 #include "GEOMImpl_IGroupOperations.hxx"
 #include <GEOM_PythonDump.hxx>
 #include "GEOM_ISubShape.hxx"
 
-#include <Basics_OCCTVersion.hxx>
-
 #include "utilities.h"
-#include <OpUtil.hxx>
 #include <Utils_ExceptHandlers.hxx>
 
 #include <TFunction_DriverTable.hxx>
 #include <TFunction_Driver.hxx>
-#include <TFunction_Logbook.hxx>
 #include <TDF_ChildIDIterator.hxx>
 #include <TDF_Tool.hxx>
 #include <TDataStd_Integer.hxx>
 #include <BRepTools.hxx>
 #include <gp_Pnt.hxx>
 
-#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
-#include <TColStd_HArray1OfByte.hxx>
 #include <TColStd_HArray1OfReal.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
  */
 //=============================================================================
-GEOMImpl_IInsertOperations::GEOMImpl_IInsertOperations(GEOM_Engine* theEngine, int theDocID)
-: GEOM_IOperations(theEngine, theDocID)
+GEOMImpl_IInsertOperations::GEOMImpl_IInsertOperations(GEOM_Engine* theEngine)
+: GEOM_IOperations(theEngine)
 {
   MESSAGE("GEOMImpl_IInsertOperations::GEOMImpl_IInsertOperations");
-  myShapesOperations = new GEOMImpl_IShapesOperations(GetEngine(), GetDocID());
-  myGroupOperations = new GEOMImpl_IGroupOperations(GetEngine(), GetDocID());
-  myFieldOperations = new GEOMImpl_IFieldOperations(GetEngine(), GetDocID());
+  myShapesOperations = new GEOMImpl_IShapesOperations(GetEngine());
+  myGroupOperations = new GEOMImpl_IGroupOperations(GetEngine());
+  myFieldOperations = new GEOMImpl_IFieldOperations(GetEngine());
 }
 
 //=============================================================================
@@ -112,7 +104,7 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::MakeCopy (Handle(GEOM_Object) th
   if (theOriginal.IsNull()) return NULL;
 
   //Add a new Copy object
-  Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), GEOM_COPY);
+  Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GEOM_COPY);
 
   //Add a Copy function for creation a copy object
   Handle(GEOM_Function) aFunction = aCopy->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITH_REF);
@@ -129,17 +121,14 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::MakeCopy (Handle(GEOM_Object) th
 
   //Compute the Copy value
   try {
-#if OCC_VERSION_LARGE > 0x06010000
     OCC_CATCH_SIGNALS;
-#endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
       SetErrorCode("Copy driver failed");
       return NULL;
     }
   }
-  catch (Standard_Failure) {
-    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
-    SetErrorCode(aFail->GetMessageString());
+  catch (Standard_Failure& aFail) {
+    SetErrorCode(aFail.GetMessageString());
     return NULL;
   }
 
@@ -164,7 +153,7 @@ void GEOMImpl_IInsertOperations::Export
 
   if (theOriginal.IsNull()) return;
 
-  if ( !GEOMImpl_IECallBack::GetCallBack( theFormatName )->Export( GetDocID(), theOriginal, theFileName, theFormatName ) )
+  if ( !GEOMImpl_IECallBack::GetCallBack( theFormatName )->Export( theOriginal, theFileName, theFormatName ) )
     return;
   SetErrorCode(OK);
 }
@@ -183,7 +172,7 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IInsertOperations::Import
   if (theFileName.IsEmpty() || theFormatName.IsEmpty()) return NULL;
 
   Handle(TColStd_HSequenceOfTransient) aSeq =
-    GEOMImpl_IECallBack::GetCallBack( theFormatName )->Import( GetDocID(), theFormatName, theFileName );
+    GEOMImpl_IECallBack::GetCallBack( theFormatName )->Import( theFormatName, theFileName );
   SetErrorCode(OK);
   return aSeq;
 }
@@ -202,7 +191,7 @@ TCollection_AsciiString GEOMImpl_IInsertOperations::ReadValue
   TCollection_AsciiString aValue;
   if (theFileName.IsEmpty() || theFormatName.IsEmpty() || theParameterName.IsEmpty()) return aValue;
 
-  aValue = GEOMImpl_IECallBack::GetCallBack( theFormatName )->ReadValue( GetDocID(), theFileName, theFormatName, theParameterName );
+  aValue = GEOMImpl_IECallBack::GetCallBack( theFormatName )->ReadValue( theFileName, theFormatName, theParameterName );
 
   SetErrorCode(OK);
   return aValue;
@@ -218,7 +207,7 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::RestoreShape (std::istringstream
   SetErrorCode(KO);
 
   //Add a new result object
-  Handle(GEOM_Object) result = GetEngine()->AddObject(GetDocID(), GEOM_COPY);
+  Handle(GEOM_Object) result = GetEngine()->AddObject(GEOM_COPY);
 
   //Add a Copy function
   Handle(GEOM_Function) aFunction = result->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
@@ -242,8 +231,15 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::RestoreShape (std::istringstream
   //See correcponding code in GEOM_Engine.cxx (method ProcessFunction)
   //GEOM::TPythonDump(aFunction) << "#";
 
-  GEOM::TPythonDump(aFunction) << result
+  bool ignore = false;
+
+  if ( const char* env_var = getenv( "GEOM_IGNORE_RESTORE_SHAPE" ) )
+    ignore = atoi( env_var ) > 1;
+
+  if ( !ignore ) {
+    GEOM::TPythonDump(aFunction) << result
     << " = geompy.RestoreShape(\"\") # the shape string has not been dump for performance reason";
+  }
 
   SetErrorCode(OK);
 
@@ -256,11 +252,7 @@ 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;
@@ -288,8 +280,8 @@ int GEOMImpl_IInsertOperations::LoadTexture(const TCollection_AsciiString& theTe
   std::list<std::string>::const_iterator it;
   for (it = lines.begin(); it != lines.end(); ++it) {
     std::string line = *it;
-    int lenline = (line.size()/8 + (line.size()%8 ? 1 : 0)) * 8;
-    for (int i = 0; i < lenline/8; i++) {
+    size_t lenline = (line.size()/8 + (line.size()%8 ? 1 : 0)) * 8;
+    for (size_t 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 );
@@ -302,49 +294,33 @@ int GEOMImpl_IInsertOperations::LoadTexture(const TCollection_AsciiString& theTe
   if (bytedata.empty() || bytedata.size() != lines.size()*lenbytes)
     return 0;
 
-#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)
     aTexture->SetValue(i, (Standard_Byte)(*bdit));
 
-  int aTextureId = GetEngine()->addTexture(GetDocID(), lenbytes*8, lines.size(), aTexture, theTextureFile);
+  int aTextureId = GetEngine()->addTexture(lenbytes*8, lines.size(), aTexture, theTextureFile);
   if (aTextureId > 0) SetErrorCode(OK);
   return aTextureId;
 }
   
 int GEOMImpl_IInsertOperations::AddTexture(int theWidth, int theHeight, 
-#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);
+  int aTextureId = GetEngine()->addTexture(theWidth, theHeight, theTexture);
   if (aTextureId > 0) SetErrorCode(OK);
   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,
-#endif
-                                                                      int& theWidth, int& theHeight)
+                                                                     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;
@@ -352,7 +328,7 @@ Handle(TDataStd_HArray1OfByte) GEOMImpl_IInsertOperations::GetTexture(int theTex
   if (theTextureId <= 0)
     return aTexture;
 
-  aTexture = GetEngine()->getTexture(GetDocID(), theTextureId, theWidth, theHeight, aFileName);
+  aTexture = GetEngine()->getTexture(theTextureId, theWidth, theHeight, aFileName);
 
   if (theWidth > 0 && theHeight > 0 && aTexture->Length() > 0) SetErrorCode(OK);
 
@@ -362,7 +338,110 @@ Handle(TDataStd_HArray1OfByte) GEOMImpl_IInsertOperations::GetTexture(int theTex
 std::list<int> GEOMImpl_IInsertOperations::GetAllTextures()
 {
   SetErrorCode(KO);
-  std::list<int> id_list = GetEngine()->getAllTextures(GetDocID());
+  std::list<int> id_list = GetEngine()->getAllTextures();
   SetErrorCode(OK);
   return id_list;
 }
+
+//=============================================================================
+/*!
+ *  TransferData
+ */
+//=============================================================================
+bool GEOMImpl_IInsertOperations::TransferData
+                          (const Handle(GEOM_Object)      &theObjectFrom,
+                           const Handle(GEOM_Object)      &theObjectTo,
+                           const int                       theFindMethod,
+                                 std::list<TransferDatum> &theResult)
+{
+  SetErrorCode(KO);
+
+  if (theObjectFrom.IsNull() || theObjectTo.IsNull()) {
+    return false;
+  }
+
+  //Add a new Transfer Data object object
+  Handle(GEOM_Object) aTDObj =
+    GetEngine()->AddObject(GEOM_TRANSFER_DATA);
+
+  //Add a Transfer Data function for created object
+  Handle(GEOM_Function) aFunction =
+    aTDObj->AddFunction(GEOMImpl_CopyDriver::GetID(), TRANSFER_DATA);
+
+  //Check if the function is set correctly
+  if(aFunction->GetDriverGUID() != GEOMImpl_CopyDriver::GetID()) {
+    return false;
+  }
+
+  Handle(GEOM_Function) aFunctionFrom = theObjectFrom->GetLastFunction();
+  Handle(GEOM_Function) aFunctionTo   = theObjectTo->GetLastFunction();
+
+  if (aFunctionFrom.IsNull() || aFunctionTo.IsNull()) {
+    return false;
+  }
+
+  GEOMImpl_ITransferData aTD(aFunction);
+
+  aTD.SetRef1(aFunctionFrom);
+  aTD.SetRef2(aFunctionTo);
+  aTD.SetFindMethod(theFindMethod);
+
+  // Transfer data
+  try {
+    OCC_CATCH_SIGNALS;
+    if (!GetSolver()->ComputeFunction(aFunction)) {
+      SetErrorCode("Transfer data failed");
+      return false;
+    }
+  }
+  catch (Standard_Failure& aFail) {
+    SetErrorCode(aFail.GetMessageString());
+    return false;
+  }
+
+  // Fill result list of data.
+  theResult.clear();
+
+  Handle(TColStd_HArray1OfExtendedString) aDatumName   = aTD.GetDatumName();
+  Handle(TColStd_HArray1OfInteger)        aDatumMaxVal = aTD.GetDatumMaxVal();
+  Handle(TColStd_HArray1OfInteger)        aDatumVal    = aTD.GetDatumVal();
+
+  if (!aDatumName.IsNull() && !aDatumMaxVal.IsNull() && !aDatumVal.IsNull()) {
+    Standard_Integer i;
+    Standard_Integer aNbDatum = aDatumName->Length();
+
+    for (i = 1; i <= aNbDatum; ++i) {
+      if (aDatumMaxVal->Value(i) > 0) {
+        TransferDatum aDatum;
+
+        aDatum.myName      = TCollection_AsciiString(aDatumName->Value(i));
+        aDatum.myNumber    = aDatumVal->Value(i);
+        aDatum.myMaxNumber = aDatumMaxVal->Value(i);
+        theResult.push_back(aDatum);
+      }
+    }
+  }
+
+  //Make a Python command
+  GEOM::TPythonDump pd (aFunction);
+  pd << "geompy.TransferData(" << theObjectFrom << ", " << theObjectTo;
+  pd << ", GEOM.";
+
+  switch (theFindMethod) {
+  case TD_GET_IN_PLACE:
+    pd << "FSM_GetInPlace";
+    break;
+  case TD_GET_IN_PLACE_OLD:
+    pd << "FSM_GetInPlace_Old";
+    break;
+  case TD_GET_IN_PLACE_BY_HISTORY:
+  default:
+    pd << "FSM_GetInPlaceByHistory";
+    break;
+  }
+  pd << ")";
+
+  SetErrorCode(OK);
+
+  return true;
+}