Back to index

salome-geom  6.5.0
Public Member Functions | Public Attributes | Private Member Functions
GEOMImpl_IInsertOperations Class Reference

#include <GEOMImpl_IInsertOperations.hxx>

Inheritance diagram for GEOMImpl_IInsertOperations:
Inheritance graph
[legend]
Collaboration diagram for GEOMImpl_IInsertOperations:
Collaboration graph
[legend]

List of all members.

Public Member Functions

Standard_EXPORT GEOMImpl_IInsertOperations (GEOM_Engine *theEngine, int theDocID)
 constructor:
Standard_EXPORT ~GEOMImpl_IInsertOperations ()
 destructor
Standard_EXPORT Handle (GEOM_Object) MakeCopy(Handle(GEOM_Object) theOriginal)
Standard_EXPORT Handle (GEOM_Object) Import(const TCollection_AsciiString &theFileName
Standard_EXPORT void Export (const Handle(GEOM_Object) theOriginal, const TCollection_AsciiString &theFileName, const TCollection_AsciiString &theFormatType)
 Export.
Standard_EXPORT Standard_Boolean ImportTranslators (Handle(TColStd_HSequenceOfAsciiString)&theFormats, Handle(TColStd_HSequenceOfAsciiString)&thePatterns)
 ImportTranslators.
Standard_EXPORT Standard_Boolean ExportTranslators (Handle(TColStd_HSequenceOfAsciiString)&theFormats, Handle(TColStd_HSequenceOfAsciiString)&thePatterns)
 ExportTranslators.
Standard_EXPORT Standard_Boolean IsSupported (const Standard_Boolean isImport, const TCollection_AsciiString &theFormat, Handle(TCollection_HAsciiString)&theLibName)
 IsSupported.
Standard_EXPORT int LoadTexture (const TCollection_AsciiString &theTextureFile)
Standard_EXPORT int AddTexture (int theWidth, int theHeight, const Handle(TDataStd_HArray1OfByte)&theTexture)
Standard_EXPORT Handle (TDataStd_HArray1OfByte) GetTexture(int theTextureId
Standard_EXPORT std::list< int > GetAllTextures ()
Standard_EXPORT void StartOperation ()
 StartOperation.
Standard_EXPORT void FinishOperation ()
 FinishOperation.
Standard_EXPORT void AbortOperation ()
 AbortOperation.
Standard_EXPORT bool IsDone ()
 IsDone.
Standard_EXPORT void SetNotDone ()
Standard_EXPORT void SetErrorCode (const TCollection_AsciiString &theErrorCode)
Standard_EXPORT char * GetErrorCode ()
Standard_EXPORT GEOM_EngineGetEngine ()
Standard_EXPORT GEOM_SolverGetSolver ()
Standard_EXPORT int GetDocID ()

Public Attributes

Standard_EXPORT const
TCollection_AsciiString & 
theFormatType
Standard_EXPORT int & theWidth
Standard_EXPORT int int & theHeight

Private Member Functions

Standard_Boolean InitResMgr ()
 InitResMgr.
 Handle (Resource_Manager) myResMgr
 Handle (Resource_Manager) myResMgrUser

Detailed Description

Definition at line 47 of file GEOMImpl_IInsertOperations.hxx.


Constructor & Destructor Documentation

constructor:

Definition at line 68 of file GEOMImpl_IInsertOperations.cxx.

: GEOM_IOperations(theEngine, theDocID)
{
  MESSAGE("GEOMImpl_IInsertOperations::GEOMImpl_IInsertOperations");
}

destructor

Definition at line 80 of file GEOMImpl_IInsertOperations.cxx.

{
  MESSAGE("GEOMImpl_IInsertOperations::~GEOMImpl_IInsertOperations");
}

Member Function Documentation

void GEOM_IOperations::AbortOperation ( ) [inherited]

AbortOperation.

Definition at line 89 of file GEOM_IOperations.cxx.

{
  Handle(TDocStd_Document) aDoc = _engine->GetDocument(_docID);
  aDoc->AbortCommand();
}

Here is the call graph for this function:

int GEOMImpl_IInsertOperations::AddTexture ( int  theWidth,
int  theHeight,
const Handle(TDataStd_HArray1OfByte)&  theTexture 
)

Definition at line 625 of file GEOMImpl_IInsertOperations.cxx.

{
  SetErrorCode(KO);
  int aTextureId = GetEngine()->addTexture(GetDocID(), theWidth, theHeight, theTexture);
  if (aTextureId > 0) SetErrorCode(OK);
  return aTextureId;
}
void GEOMImpl_IInsertOperations::Export ( const Handle(GEOM_Object theOriginal,
const TCollection_AsciiString &  theFileName,
const TCollection_AsciiString &  theFormatType 
)

Export.

Definition at line 143 of file GEOMImpl_IInsertOperations.cxx.

{
  SetErrorCode(KO);

  if (theOriginal.IsNull()) return;

  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 = result->AddFunction(GEOMImpl_ExportDriver::GetID(), EXPORT_SHAPE);
  if (aFunction.IsNull()) return;

  //Check if the function is set correctly
  if (aFunction->GetDriverGUID() != GEOMImpl_ExportDriver::GetID()) return;

  Handle(TCollection_HAsciiString) aHLibName;
  if (!IsSupported(Standard_False, theFormatName, aHLibName)) {
    return;
  }
  TCollection_AsciiString aLibName = aHLibName->String();

  //Set parameters
  GEOMImpl_IImportExport aCI (aFunction);
  aCI.SetOriginal(aRefFunction);
  aCI.SetFileName(theFileName);
  aCI.SetFormatName(theFormatName);
  aCI.SetPluginName(aLibName);

  //Perform the Export
  try {
#if OCC_VERSION_LARGE > 0x06010000
    OCC_CATCH_SIGNALS;
#endif
    if (!GetSolver()->ComputeFunction(aFunction)) {
      SetErrorCode("Not enough space on disk, or you haven't permissions to write this directory");
      return;
    }
  }
  catch (Standard_Failure) {
    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
    SetErrorCode(aFail->GetMessageString());
    return;
  }

  //Make a Python command
  GEOM::TPythonDump(aFunction) << "geompy.Export(" << theOriginal << ", \""
    << theFileName.ToCString() << "\", \"" << theFormatName.ToCString() << "\")";

  SetErrorCode(OK);
}

Here is the call graph for this function:

Standard_Boolean GEOMImpl_IInsertOperations::ExportTranslators ( Handle(TColStd_HSequenceOfAsciiString)&  theFormats,
Handle(TColStd_HSequenceOfAsciiString)&  thePatterns 
)

ExportTranslators.

Definition at line 359 of file GEOMImpl_IInsertOperations.cxx.

{
  if (theFormats.IsNull())
    theFormats = new TColStd_HSequenceOfAsciiString;
  else
    theFormats->Clear();

  if (thePatterns.IsNull())
    thePatterns = new TColStd_HSequenceOfAsciiString;
  else
    thePatterns->Clear();

  if (!InitResMgr()) return Standard_False;

  // Read Export formats list from install directory
  if (myResMgr->Find("Export")) {
    TCollection_AsciiString aFormats (myResMgr->Value("Export"));
    TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
    int i = 1;
    for (; !aToken.IsEmpty(); aToken = aFormats.Token("| \t", ++i)) {
      theFormats->Append(aToken);
    }
  }

  // Read Export formats list from user directory
  if (myResMgrUser->Find("Export")) {
    TCollection_AsciiString aFormats (myResMgrUser->Value("Export"));
    TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
    int i = 1;
    for (; !aToken.IsEmpty(); aToken = aFormats.Token("| \t", ++i)) {
      int aLenFormats = theFormats->Length();
      bool isFound = false;
      for(int aInd=1;aInd<=aLenFormats;aInd++){
        if( theFormats->Value(aInd) == aToken){
          isFound = true;
          break;
        }
      }
      if(!isFound)
        theFormats->Append(aToken);
    }
  }

  // Read Patterns for each supported format
  int j = 1, len = theFormats->Length();
  for (; j <= len; j++) {
    TCollection_AsciiString aKey, aPattern;
    aKey = theFormats->Value(j) + ".ExportPattern";
    if (myResMgr->Find(aKey.ToCString()))
      aPattern = myResMgr->Value(aKey.ToCString());
    else if (myResMgrUser->Find(aKey.ToCString()))
      aPattern = myResMgrUser->Value(aKey.ToCString());
    else {
      aKey = theFormats->Value(j) + ".Pattern";
      if (myResMgr->Find(aKey.ToCString()))
        aPattern = myResMgr->Value(aKey.ToCString());
      else if (myResMgrUser->Find(aKey.ToCString()))
        aPattern = myResMgrUser->Value(aKey.ToCString());
      else {
        aPattern = theFormats->Value(j);
        aPattern += " Files ( *.* )";
      }
    }
    thePatterns->Append(aPattern);
  }

  return (!theFormats->IsEmpty());
}
void GEOM_IOperations::FinishOperation ( ) [inherited]

FinishOperation.

Definition at line 77 of file GEOM_IOperations.cxx.

{
  Handle(TDocStd_Document) aDoc = _engine->GetDocument(_docID);
  if(aDoc->GetUndoLimit() > 0) 
    aDoc->CommitCommand();
}

Here is the call graph for this function:

Definition at line 666 of file GEOMImpl_IInsertOperations.cxx.

{
  SetErrorCode(KO);
  std::list<int> id_list = GetEngine()->getAllTextures(GetDocID());
  SetErrorCode(OK);
  return id_list;
}

Here is the call graph for this function:

Standard_EXPORT int GEOM_IOperations::GetDocID ( ) [inline, inherited]

Definition at line 77 of file GEOM_IOperations.hxx.

{ return _docID; }

Here is the caller graph for this function:

Definition at line 71 of file GEOM_IOperations.hxx.

{ return _engine; }

Here is the caller graph for this function:

Standard_EXPORT char* GEOM_IOperations::GetErrorCode ( ) [inline, inherited]

Definition at line 66 of file GEOM_IOperations.hxx.

                                       {
    return (char*) _errorCode.ToCString();    
  }

Here is the caller graph for this function:

Definition at line 74 of file GEOM_IOperations.hxx.

{ return _solver; }

Here is the caller graph for this function:

GEOMImpl_IInsertOperations::Handle ( Resource_Manager  ) [private]
GEOMImpl_IInsertOperations::Handle ( Resource_Manager  ) [private]
Standard_Boolean GEOMImpl_IInsertOperations::ImportTranslators ( Handle(TColStd_HSequenceOfAsciiString)&  theFormats,
Handle(TColStd_HSequenceOfAsciiString)&  thePatterns 
)

ImportTranslators.

Definition at line 283 of file GEOMImpl_IInsertOperations.cxx.

{
  if (theFormats.IsNull())
    theFormats = new TColStd_HSequenceOfAsciiString;
  else
    theFormats->Clear();

  if (thePatterns.IsNull())
    thePatterns = new TColStd_HSequenceOfAsciiString;
  else
    thePatterns->Clear();

  if (!InitResMgr()) return Standard_False;

  // Read Import formats list from install directory
  if (myResMgr->Find("Import")) {
    TCollection_AsciiString aFormats (myResMgr->Value("Import"));
    TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
    int i = 1;
    for (; !aToken.IsEmpty(); aToken = aFormats.Token("| \t", ++i)) {
      theFormats->Append(aToken);
    }
  }

  // Read Import formats from user directory
  if (myResMgrUser->Find("Import")) {
    TCollection_AsciiString aFormats (myResMgrUser->Value("Import"));
    TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
    int i = 1;
    for (; !aToken.IsEmpty(); aToken = aFormats.Token("| \t", ++i)) {
      int aLenFormats = theFormats->Length();
      bool isFound = false;
      for(int aInd=1;aInd<=aLenFormats;aInd++){
        if( theFormats->Value(aInd) == aToken){
          isFound = true;
          break;
        }
      }
      if(!isFound)
        theFormats->Append(aToken);
    }
  }

  // Read Patterns for each supported format
  int j = 1, len = theFormats->Length();
  for (; j <= len; j++) {
    TCollection_AsciiString aKey, aPattern;
    aKey = theFormats->Value(j) + ".ImportPattern";
    if (myResMgr->Find(aKey.ToCString()))
      aPattern = myResMgr->Value(aKey.ToCString());
    else if(myResMgrUser->Find(aKey.ToCString()))
      aPattern = myResMgrUser->Value(aKey.ToCString());
    else {
      aKey = theFormats->Value(j) + ".Pattern";
      if (myResMgr->Find(aKey.ToCString()))
        aPattern = myResMgr->Value(aKey.ToCString());
      else if(myResMgrUser->Find(aKey.ToCString()))
        aPattern = myResMgrUser->Value(aKey.ToCString());
      else {
        aPattern = theFormats->Value(j);
        aPattern += " Files ( *.* )";
      }
    }
    thePatterns->Append(aPattern);
  }

  return (!theFormats->IsEmpty());
}
Standard_Boolean GEOMImpl_IInsertOperations::InitResMgr ( ) [private]

InitResMgr.

Definition at line 492 of file GEOMImpl_IInsertOperations.cxx.

{
  bool isResourceFound     = false;
  bool isResourceFoundUser = false;
  TCollection_AsciiString aUserResDir,aResDir;
  
  if (myResMgr.IsNull()) {
    // Initialize the Resource Manager
    TCollection_AsciiString aNull;
    aResDir = TCollection_AsciiString(getenv("GEOM_ROOT_DIR"));
#ifdef WNT
    aResDir += "\\share\\salome\\resources\\geom";
#else
    aResDir += "/share/salome/resources/geom";
#endif
    
    myResMgr = new Resource_Manager ("ImportExport", aResDir, aNull, Standard_False);

    isResourceFound = true;
    if (!myResMgr->Find("Import") && !myResMgr->Find("Export")) {
      // instead of complains in Resource_Manager
      isResourceFound = false;
      INFOS("No valid file \"ImportExport\" found in " << aResDir.ToCString());
    }
  } else
    isResourceFound = true;

  if (myResMgrUser.IsNull()) {
    char * dir = getenv("GEOM_ENGINE_RESOURCES_DIR");
    TCollection_AsciiString aNull;
    if ( dir )
    {
      aUserResDir = dir;
    }
    else
    {
      aUserResDir = getenv("HOME");
#ifdef WNT
      aUserResDir += "\\.salome\\resources";
#else
      aUserResDir += "/.salome/resources";
#endif
    }

    myResMgrUser = new Resource_Manager ("ImportExport", aNull, aUserResDir, Standard_False);

    isResourceFoundUser = true;
    
    if (!myResMgrUser->Find("Import") && !myResMgrUser->Find("Export")) {
      // instead of complains in Resource_Manager
      isResourceFoundUser = false;
    }
      
  } else
    isResourceFoundUser = true;
    
  if(!isResourceFound && !isResourceFoundUser){
    INFOS("No valid file \"ImportExport\" found in " << aResDir.ToCString());
    INFOS("No valid file \"ImportExport\" found in " << aUserResDir.ToCString() );
  }

  return ( myResMgr->Find("Import") || myResMgr->Find("Export") ||
           myResMgrUser->Find("Import") || myResMgrUser->Find("Export"));
}
bool GEOM_IOperations::IsDone ( ) [inherited]

IsDone.

Definition at line 101 of file GEOM_IOperations.cxx.

{
  return (_errorCode == OK);
}  
Standard_Boolean GEOMImpl_IInsertOperations::IsSupported ( const Standard_Boolean  isImport,
const TCollection_AsciiString &  theFormat,
Handle(TCollection_HAsciiString)&  theLibName 
)

IsSupported.

Definition at line 435 of file GEOMImpl_IInsertOperations.cxx.

{
  if (!InitResMgr()) return Standard_False;

  // Import/Export mode
  TCollection_AsciiString aMode;
  //Standard_CString aMode;
  if (isImport) aMode = "Import";
  else aMode = "Export";

  // Read supported formats for the certain mode from install directory
  if (myResMgr->Find(aMode.ToCString())) {
    TCollection_AsciiString aFormats (myResMgr->Value(aMode.ToCString()));
    if (aFormats.Search(theFormat) > -1) {
      // Read library name for the supported format
      TCollection_AsciiString aKey (theFormat);
      aKey += ".";
      aKey += aMode;
      if (myResMgr->Find(aKey.ToCString())) {
        TCollection_AsciiString aLibName (myResMgr->Value(aKey.ToCString()));        
#ifndef WNT
        aLibName += ".so";     
#else
        aLibName += ".dll";
#endif
        theLibName = new TCollection_HAsciiString (aLibName);
        return Standard_True;
      }
    }
  }
  
  // Read supported formats for the certain mode from user directory
  if (myResMgrUser->Find(aMode.ToCString())) {
    TCollection_AsciiString aFormats (myResMgrUser->Value(aMode.ToCString()));
    if (aFormats.Search(theFormat) > -1) {
      // Read library name for the supported format
      TCollection_AsciiString aKey (theFormat);
      aKey += ".";
      aKey += aMode;
      if (myResMgrUser->Find(aKey.ToCString())) {
        TCollection_AsciiString aLibName (myResMgrUser->Value(aKey.ToCString()));
        theLibName = new TCollection_HAsciiString (aLibName);
        return Standard_True;
      }
    }
  }
  
  return Standard_False;
}
int GEOMImpl_IInsertOperations::LoadTexture ( const TCollection_AsciiString &  theTextureFile)

Definition at line 557 of file GEOMImpl_IInsertOperations.cxx.

{
  SetErrorCode(KO);

  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;

  std::list<std::string> lines;
  char buffer[4096];
  int maxlen = 0;
  while (!feof(fp)) {
    if ((fgets(buffer, 4096, fp)) == NULL) break;
    int aLen = strlen(buffer);
    if (buffer[aLen-1] == '\n') buffer[aLen-1] = '\0';
    lines.push_back(buffer);
    maxlen = std::max(maxlen, (int)strlen(buffer));
  }

  fclose(fp);

  int lenbytes = maxlen/8;
  if (maxlen%8) lenbytes++;

  if (lenbytes == 0 || lines.empty())
    return 0;

  std::list<unsigned char> bytedata;
  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++) {
      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 );
      bytedata.push_back(byte);
    }
    for (int i = lenline/8; i < lenbytes; i++)
      bytedata.push_back((unsigned char)0);
  }

  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);
  if (aTextureId > 0) SetErrorCode(OK);
  return aTextureId;
}

Here is the call graph for this function:

Standard_EXPORT void GEOM_IOperations::SetErrorCode ( const TCollection_AsciiString &  theErrorCode) [inline, inherited]

Definition at line 61 of file GEOM_IOperations.hxx.

                                                                                 {
    _errorCode = theErrorCode;    
  } 

Here is the caller graph for this function:

Standard_EXPORT void GEOM_IOperations::SetNotDone ( ) [inline, inherited]

Definition at line 58 of file GEOM_IOperations.hxx.

{ _errorCode = KO; }
void GEOM_IOperations::StartOperation ( ) [inherited]

StartOperation.

Definition at line 65 of file GEOM_IOperations.cxx.

{
  Handle(TDocStd_Document) aDoc = _engine->GetDocument(_docID);
  if(aDoc->GetUndoLimit() > 0) 
    aDoc->NewCommand();
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 56 of file GEOMImpl_IInsertOperations.hxx.

Definition at line 86 of file GEOMImpl_IInsertOperations.hxx.

Definition at line 86 of file GEOMImpl_IInsertOperations.hxx.


The documentation for this class was generated from the following files: