mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2025-01-13 10:10:34 +05:00
Mantis issue 0021706: [CEA 578] Python access to BrepTools::Read
This commit is contained in:
parent
f9e0b80f69
commit
9ef623eade
@ -360,7 +360,8 @@ module GEOM
|
|||||||
// # Internal methods (For sub-shape identification)
|
// # Internal methods (For sub-shape identification)
|
||||||
// ######################################################################
|
// ######################################################################
|
||||||
/*!
|
/*!
|
||||||
* \brief Get geometric shape of the object as a byte stream
|
* \brief Get geometric shape of the object as a byte stream in BRep format
|
||||||
|
* \note GEOM_IInsertOperations::RestoreShape() method can be used to restore shape from a BRep stream.
|
||||||
*/
|
*/
|
||||||
SALOMEDS::TMPFile GetShapeStream();
|
SALOMEDS::TMPFile GetShapeStream();
|
||||||
|
|
||||||
@ -3278,6 +3279,14 @@ module GEOM
|
|||||||
void ExportTranslators (out string_array theFormats,
|
void ExportTranslators (out string_array theFormats,
|
||||||
out string_array thePatterns);
|
out string_array thePatterns);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Read a shape from the binary stream, containing its bounding representation (BRep).
|
||||||
|
* \note GEOM_Object::GetShapeStream() method can be used to obtain the shape's BRep stream.
|
||||||
|
* \param theStream The BRep binary stream.
|
||||||
|
* \return New GEOM_Object, containing the shape, read from theStream.
|
||||||
|
*/
|
||||||
|
GEOM_Object RestoreShape (in SALOMEDS::TMPFile theStream);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Load texture from file
|
* \brief Load texture from file
|
||||||
* \param theTextureFile texture file name
|
* \param theTextureFile texture file name
|
||||||
|
@ -1023,6 +1023,16 @@ bool ProcessFunction(Handle(GEOM_Function)& theFunction,
|
|||||||
//Check if its internal function which doesn't requires dumping
|
//Check if its internal function which doesn't requires dumping
|
||||||
if(aDescr == "None") return false;
|
if(aDescr == "None") return false;
|
||||||
|
|
||||||
|
//Check the very specific case of RestoreShape function,
|
||||||
|
//which is not dumped, but the result can be published by the user.
|
||||||
|
//We do not publish such objects to decrease danger of dumped script failure.
|
||||||
|
if(aDescr.Value(1) == '#') {
|
||||||
|
TCollection_AsciiString anObjEntry;
|
||||||
|
TDF_Tool::Entry(theFunction->GetOwnerEntry(), anObjEntry);
|
||||||
|
theIgnoreObjs.insert(anObjEntry);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// 0020001 PTv, check for critical functions, which require dump of objects
|
// 0020001 PTv, check for critical functions, which require dump of objects
|
||||||
if (theIsPublished)
|
if (theIsPublished)
|
||||||
{
|
{
|
||||||
|
@ -46,7 +46,9 @@
|
|||||||
|
|
||||||
#include <TopoDS.hxx>
|
#include <TopoDS.hxx>
|
||||||
#include <TopoDS_Vertex.hxx>
|
#include <TopoDS_Vertex.hxx>
|
||||||
|
#include <BRep_Builder.hxx>
|
||||||
#include <BRep_Tool.hxx>
|
#include <BRep_Tool.hxx>
|
||||||
|
#include <BRepTools.hxx>
|
||||||
#include <gp_Pnt.hxx>
|
#include <gp_Pnt.hxx>
|
||||||
|
|
||||||
#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
|
#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
|
||||||
@ -581,6 +583,45 @@ Standard_Boolean GEOMImpl_IInsertOperations::InitResMgr()
|
|||||||
myResMgrUser->Find("Import") || myResMgrUser->Find("Export"));
|
myResMgrUser->Find("Import") || myResMgrUser->Find("Export"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=============================================================================
|
||||||
|
/*!
|
||||||
|
* RestoreShape
|
||||||
|
*/
|
||||||
|
//=============================================================================
|
||||||
|
Handle(GEOM_Object) GEOMImpl_IInsertOperations::RestoreShape (std::istringstream& theStream)
|
||||||
|
{
|
||||||
|
SetErrorCode(KO);
|
||||||
|
|
||||||
|
//Add a new result object
|
||||||
|
Handle(GEOM_Object) result = GetEngine()->AddObject(GetDocID(), GEOM_COPY);
|
||||||
|
|
||||||
|
//Add a Copy function
|
||||||
|
Handle(GEOM_Function) aFunction = result->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
|
||||||
|
if (aFunction.IsNull()) return NULL;
|
||||||
|
|
||||||
|
//Check if the function is set correctly
|
||||||
|
if (aFunction->GetDriverGUID() != GEOMImpl_CopyDriver::GetID()) return NULL;
|
||||||
|
|
||||||
|
//Read a shape from the stream
|
||||||
|
TopoDS_Shape aShape;
|
||||||
|
BRep_Builder B;
|
||||||
|
BRepTools::Read(aShape, theStream, B);
|
||||||
|
if (aShape.IsNull()) {
|
||||||
|
SetErrorCode("RestoreShape error: BREP reading failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
//Set function value
|
||||||
|
aFunction->SetValue(aShape);
|
||||||
|
|
||||||
|
//Special dump to avoid restored shapes publication.
|
||||||
|
//See correcponding code in GEOM_Engine.cxx (method ProcessFunction)
|
||||||
|
GEOM::TPythonDump(aFunction) << "#";
|
||||||
|
|
||||||
|
SetErrorCode(OK);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
int GEOMImpl_IInsertOperations::LoadTexture(const TCollection_AsciiString& theTextureFile)
|
int GEOMImpl_IInsertOperations::LoadTexture(const TCollection_AsciiString& theTextureFile)
|
||||||
{
|
{
|
||||||
SetErrorCode(KO);
|
SetErrorCode(KO);
|
||||||
|
@ -72,6 +72,8 @@ class GEOMImpl_IInsertOperations : public GEOM_IOperations {
|
|||||||
const TCollection_AsciiString& theFormat,
|
const TCollection_AsciiString& theFormat,
|
||||||
Handle(TCollection_HAsciiString)& theLibName);
|
Handle(TCollection_HAsciiString)& theLibName);
|
||||||
|
|
||||||
|
Standard_EXPORT Handle(GEOM_Object) RestoreShape (std::istringstream& theStream);
|
||||||
|
|
||||||
Standard_EXPORT int LoadTexture(const TCollection_AsciiString& theTextureFile);
|
Standard_EXPORT int LoadTexture(const TCollection_AsciiString& theTextureFile);
|
||||||
|
|
||||||
Standard_EXPORT int AddTexture(int theWidth, int theHeight,
|
Standard_EXPORT int AddTexture(int theWidth, int theHeight,
|
||||||
|
@ -250,12 +250,47 @@ void GEOM_IInsertOperations_i::ExportTranslators
|
|||||||
thePatterns = aPatternsArray._retn();
|
thePatterns = aPatternsArray._retn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=============================================================================
|
||||||
|
/*!
|
||||||
|
* RestoreShape
|
||||||
|
*/
|
||||||
|
//=============================================================================
|
||||||
|
GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::RestoreShape (const SALOMEDS::TMPFile& theStream)
|
||||||
|
{
|
||||||
|
GEOM::GEOM_Object_var aGEOMObject;
|
||||||
|
|
||||||
|
//Set a not done flag
|
||||||
|
GetOperations()->SetNotDone();
|
||||||
|
|
||||||
|
if (theStream.length() < 1)
|
||||||
|
return aGEOMObject._retn();
|
||||||
|
|
||||||
|
char* buf = (char*)theStream.NP_data();
|
||||||
|
std::istringstream aStream (buf);
|
||||||
|
|
||||||
|
Handle(GEOM_Object) anObject = GetOperations()->RestoreShape(aStream);
|
||||||
|
if (!GetOperations()->IsDone() || anObject.IsNull())
|
||||||
|
return aGEOMObject._retn();
|
||||||
|
|
||||||
|
return GetObject(anObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
//=============================================================================
|
||||||
|
/*!
|
||||||
|
* LoadTexture
|
||||||
|
*/
|
||||||
|
//=============================================================================
|
||||||
CORBA::Long GEOM_IInsertOperations_i::LoadTexture(const char* theTextureFile)
|
CORBA::Long GEOM_IInsertOperations_i::LoadTexture(const char* theTextureFile)
|
||||||
{
|
{
|
||||||
GetOperations()->SetNotDone();
|
GetOperations()->SetNotDone();
|
||||||
return GetOperations()->LoadTexture( theTextureFile );
|
return GetOperations()->LoadTexture( theTextureFile );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=============================================================================
|
||||||
|
/*!
|
||||||
|
* AddTexture
|
||||||
|
*/
|
||||||
|
//=============================================================================
|
||||||
CORBA::Long GEOM_IInsertOperations_i::AddTexture(CORBA::Long theWidth, CORBA::Long theHeight,
|
CORBA::Long GEOM_IInsertOperations_i::AddTexture(CORBA::Long theWidth, CORBA::Long theHeight,
|
||||||
const SALOMEDS::TMPFile& theTexture)
|
const SALOMEDS::TMPFile& theTexture)
|
||||||
{
|
{
|
||||||
@ -280,6 +315,11 @@ CORBA::Long GEOM_IInsertOperations_i::AddTexture(CORBA::Long theWidth, CORBA::Lo
|
|||||||
return GetOperations()->AddTexture( theWidth, theHeight, aTexture );
|
return GetOperations()->AddTexture( theWidth, theHeight, aTexture );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=============================================================================
|
||||||
|
/*!
|
||||||
|
* GetTexture
|
||||||
|
*/
|
||||||
|
//=============================================================================
|
||||||
SALOMEDS::TMPFile* GEOM_IInsertOperations_i::GetTexture(CORBA::Long theID,
|
SALOMEDS::TMPFile* GEOM_IInsertOperations_i::GetTexture(CORBA::Long theID,
|
||||||
CORBA::Long& theWidth,
|
CORBA::Long& theWidth,
|
||||||
CORBA::Long& theHeight)
|
CORBA::Long& theHeight)
|
||||||
@ -303,6 +343,11 @@ SALOMEDS::TMPFile* GEOM_IInsertOperations_i::GetTexture(CORBA::Long theID,
|
|||||||
return aTexture._retn();
|
return aTexture._retn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=============================================================================
|
||||||
|
/*!
|
||||||
|
* GetAllTextures
|
||||||
|
*/
|
||||||
|
//=============================================================================
|
||||||
GEOM::ListOfLong* GEOM_IInsertOperations_i::GetAllTextures()
|
GEOM::ListOfLong* GEOM_IInsertOperations_i::GetAllTextures()
|
||||||
{
|
{
|
||||||
std::list<int> localIDs = GetOperations()->GetAllTextures();
|
std::list<int> localIDs = GetOperations()->GetAllTextures();
|
||||||
|
@ -61,6 +61,8 @@ class GEOM_I_EXPORT GEOM_IInsertOperations_i :
|
|||||||
void ExportTranslators (GEOM::string_array_out theFormats,
|
void ExportTranslators (GEOM::string_array_out theFormats,
|
||||||
GEOM::string_array_out thePatterns);
|
GEOM::string_array_out thePatterns);
|
||||||
|
|
||||||
|
GEOM::GEOM_Object_ptr RestoreShape (const SALOMEDS::TMPFile& theStream);
|
||||||
|
|
||||||
CORBA::Long LoadTexture(const char* theTextureFile);
|
CORBA::Long LoadTexture(const char* theTextureFile);
|
||||||
CORBA::Long AddTexture(CORBA::Long theWidth, CORBA::Long theHeight,
|
CORBA::Long AddTexture(CORBA::Long theWidth, CORBA::Long theHeight,
|
||||||
const SALOMEDS::TMPFile& theTexture);
|
const SALOMEDS::TMPFile& theTexture);
|
||||||
|
@ -95,6 +95,11 @@ def TestExportImport (geompy, shape):
|
|||||||
os.remove(fileExportImportIGES)
|
os.remove(fileExportImportIGES)
|
||||||
os.remove(fileExportImportSTEP)
|
os.remove(fileExportImportSTEP)
|
||||||
|
|
||||||
|
# Test RestoreShape from binary BRep stream
|
||||||
|
aStream = shape.GetShapeStream()
|
||||||
|
aNewShape = geompy.RestoreShape(aStream)
|
||||||
|
geompy.addToStudy(aNewShape, "aNewShape")
|
||||||
|
|
||||||
print "OK"
|
print "OK"
|
||||||
|
|
||||||
|
|
||||||
|
@ -7340,6 +7340,31 @@ class geompyDC(GEOM._objref_GEOM_Gen):
|
|||||||
# Example: see GEOM_TestOthers.py
|
# Example: see GEOM_TestOthers.py
|
||||||
return self.ImportFile(theFileName, "STEP")
|
return self.ImportFile(theFileName, "STEP")
|
||||||
|
|
||||||
|
## Read a shape from the binary stream, containing its bounding representation (BRep).
|
||||||
|
# @note This method will not be dumped to the python script by DumpStudy functionality.
|
||||||
|
# @note GEOM.GEOM_Object.GetShapeStream() method can be used to obtain the shape's BRep stream.
|
||||||
|
# @param theStream The BRep binary stream.
|
||||||
|
# @return New GEOM_Object, containing the shape, read from theStream.
|
||||||
|
#
|
||||||
|
# @ref swig_Import_Export "Example"
|
||||||
|
def RestoreShape (self, theStream):
|
||||||
|
"""
|
||||||
|
Read a shape from the binary stream, containing its bounding representation (BRep).
|
||||||
|
|
||||||
|
Note:
|
||||||
|
shape.GetShapeStream() method can be used to obtain the shape's BRep stream.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
theStream The BRep binary stream.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
New GEOM_Object, containing the shape, read from theStream.
|
||||||
|
"""
|
||||||
|
# Example: see GEOM_TestOthers.py
|
||||||
|
anObj = self.InsertOp.RestoreShape(theStream)
|
||||||
|
RaiseIfFailed("RestoreShape", self.InsertOp)
|
||||||
|
return anObj
|
||||||
|
|
||||||
## Export the given shape into a file with given name.
|
## Export the given shape into a file with given name.
|
||||||
# @param theObject Shape to be stored in the file.
|
# @param theObject Shape to be stored in the file.
|
||||||
# @param theFileName Name of the file to store the given shape in.
|
# @param theFileName Name of the file to store the given shape in.
|
||||||
|
Loading…
Reference in New Issue
Block a user