From: jfa Date: Wed, 22 Aug 2012 06:42:18 +0000 (+0000) Subject: IMP 0021511: EDF 2153 GEOM: Choose to take units into account or not when importing... X-Git-Tag: V6_6_0a1~46 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=101ba2640b89e6822c36fcae0bb603634d9d5d40;p=modules%2Fgeom.git IMP 0021511: EDF 2153 GEOM: Choose to take units into account or not when importing a STEP file. --- diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 209ac2bd3..7ff4315f8 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -3211,6 +3211,17 @@ module GEOM */ GEOM_Object ImportFile (in string theFileName, in string theFormatName); + /*! + * \brief Read a value of parameter from a file, containing a shape. + * \param theFileName The file, containing the shape. + * \param theFormatName Specify format for the file reading. + * Available formats can be obtained with ImportTranslators() method. + * \param theParameterName Specify the parameter. For example, pass "LEN_UNITS" + * to obtain length units, in which the file is written. + * \return Value of requested parameter in form of text string. + */ + string ReadValue (in string theFileName, in string theFormatName, in string theParameterName); + /*! * \brief Get the supported import formats and corresponding patterns for File dialog. * \param theFormats Output. List of formats, available for import. diff --git a/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx b/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx index 3bb7cec61..2a83dd58d 100644 --- a/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx @@ -18,7 +18,6 @@ // 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 @@ -61,10 +60,9 @@ //============================================================================= /*! - * constructor: + * constructor */ //============================================================================= - GEOMImpl_IInsertOperations::GEOMImpl_IInsertOperations(GEOM_Engine* theEngine, int theDocID) : GEOM_IOperations(theEngine, theDocID) { @@ -76,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); @@ -231,7 +226,6 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import aCI.SetFileName(theFileName); aCI.SetFormatName(theFormatName); aCI.SetPluginName(aLibName); - //cout<<"IIO: theFormatName = "<GetValue(); TopoDS_Vertex V = TopoDS::Vertex(S); gp_Pnt P = BRep_Tool::Pnt(V); @@ -270,10 +265,42 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import //cout<<"IIO: aUnitName = "<String(); + + aValue = GEOMImpl_ImportDriver::ReadValue(theFileName, aLibName, theParameterName, anError); + if (anError.IsEmpty()) + SetErrorCode(OK); + else + SetErrorCode(anError.ToCString()); + + return aValue; +} + //============================================================================= /*! * ImportTranslators diff --git a/src/GEOMImpl/GEOMImpl_IInsertOperations.hxx b/src/GEOMImpl/GEOMImpl_IInsertOperations.hxx index e60c22b32..c59411216 100644 --- a/src/GEOMImpl/GEOMImpl_IInsertOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IInsertOperations.hxx @@ -18,7 +18,6 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// #ifndef _GEOMImpl_IInsertOperations_HXX_ #define _GEOMImpl_IInsertOperations_HXX_ @@ -55,6 +54,10 @@ class GEOMImpl_IInsertOperations : public GEOM_IOperations { Standard_EXPORT Handle(GEOM_Object) Import (const TCollection_AsciiString& theFileName, const TCollection_AsciiString& theFormatType); + Standard_EXPORT TCollection_AsciiString ReadValue (const TCollection_AsciiString& theFileName, + const TCollection_AsciiString& theFormatType, + const TCollection_AsciiString& theParameterName); + Standard_EXPORT void Export (const Handle(GEOM_Object) theOriginal, const TCollection_AsciiString& theFileName, const TCollection_AsciiString& theFormatType); diff --git a/src/GEOMImpl/GEOMImpl_ImportDriver.cxx b/src/GEOMImpl/GEOMImpl_ImportDriver.cxx index ee1495f0e..748a5a735 100644 --- a/src/GEOMImpl/GEOMImpl_ImportDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_ImportDriver.cxx @@ -18,7 +18,6 @@ // 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 @@ -27,10 +26,12 @@ #include #include -#include "utilities.h" - #include +#include + +#include "utilities.h" + #include #include @@ -57,6 +58,10 @@ typedef TopoDS_Shape (*funcPoint)(const TCollection_AsciiString&, TCollection_AsciiString&, const TDF_Label&); +typedef Handle(TCollection_HAsciiString) (*pGetValue)(const TCollection_AsciiString&, + const TCollection_AsciiString&, + TCollection_AsciiString&); + //======================================================================= //function : GetID //purpose : @@ -67,7 +72,6 @@ const Standard_GUID& GEOMImpl_ImportDriver::GetID() return aImportDriver; } - //======================================================================= //function : GEOMImpl_ImportDriver //purpose : @@ -97,6 +101,8 @@ Standard_Integer GEOMImpl_ImportDriver::Execute(TFunction_Logbook& log) const // load plugin library LibHandle anImportLib = LoadLib( aLibName.ToCString() ); //This is workaround of BUG OCC13051 + + // Get Import method funcPoint fp = 0; if ( anImportLib ) fp = (funcPoint)GetProc( anImportLib, "Import" ); @@ -129,6 +135,53 @@ Standard_Integer GEOMImpl_ImportDriver::Execute(TFunction_Logbook& log) const return 1; } +//======================================================================= +//function : ReadValue +//purpose : +//======================================================================= +TCollection_AsciiString GEOMImpl_ImportDriver::ReadValue(const TCollection_AsciiString& theFileName, + const TCollection_AsciiString& theLibName, + const TCollection_AsciiString& theParameterName, + TCollection_AsciiString& theError) +{ + TCollection_AsciiString aValue; + + if (theFileName.IsEmpty() || theLibName.IsEmpty() || theParameterName.IsEmpty()) + return aValue; + + // load plugin library + LibHandle anImportLib = LoadLib(theLibName.ToCString()); //This is workaround of BUG OCC13051 + if (!anImportLib) { + theError = theLibName + " library was not installed"; + return aValue; + } + + // Get GetValue method + pGetValue pGV = (pGetValue)GetProc(anImportLib, "GetValue"); + + if (!pGV) { + theError = theLibName + " library doesn't support GetValue method"; + return aValue; + } + + Handle(TCollection_HAsciiString) aHValue = pGV(theFileName, theParameterName, theError); + + if (aHValue.IsNull()) { + if (theError.IsEmpty()) + theError = theFileName + " doesn't contain requested parameter"; + return aValue; + } + + aValue = aHValue->String(); + + // unload plugin library + // commented by enk: + // the bug was occured: using ACIS Import/Export plugin + //UnLoadLib( anImportLib ); //This is workaround of BUG OCC13051 + + return aValue; +} + //======================================================================= //function : GEOMImpl_ImportDriver_Type_ diff --git a/src/GEOMImpl/GEOMImpl_ImportDriver.hxx b/src/GEOMImpl/GEOMImpl_ImportDriver.hxx index 0c625e05c..265e5ac4c 100644 --- a/src/GEOMImpl/GEOMImpl_ImportDriver.hxx +++ b/src/GEOMImpl/GEOMImpl_ImportDriver.hxx @@ -18,11 +18,10 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// // File : GEOMImpl_ImportDriver.ixx // Module : GEOMImpl -// + #ifndef _GEOMImpl_ImportDriver_HeaderFile #define _GEOMImpl_ImportDriver_HeaderFile @@ -119,6 +118,8 @@ class Handle(GEOMImpl_ImportDriver) : public Handle(TFunction_Driver) { #include #endif +#include + class TColStd_SequenceOfExtendedString; @@ -148,6 +149,11 @@ Standard_EXPORT Standard_Boolean MustExecute(const TFunction_Logbook&) const { r Standard_EXPORT static const Standard_GUID& GetID(); Standard_EXPORT ~GEOMImpl_ImportDriver() {}; + // Static method + Standard_EXPORT static TCollection_AsciiString ReadValue (const TCollection_AsciiString& theFileName, + const TCollection_AsciiString& theLibName, + const TCollection_AsciiString& theParameterName, + TCollection_AsciiString& theError); // Type management // diff --git a/src/GEOMToolsGUI/GEOMToolsGUI.cxx b/src/GEOMToolsGUI/GEOMToolsGUI.cxx index f0acaa34f..68d4cefd7 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI.cxx @@ -647,6 +647,42 @@ bool GEOMToolsGUI::Import() CORBA::String_var fileN = fileName.toLatin1().constData(); CORBA::String_var fileT = aCurrentType.toLatin1().constData(); + // jfa 21.08.2012 for mantis issue 21511 (STEP file units) + CORBA::String_var aUnits = aInsOp->ReadValue(fileN, fileT, "LEN_UNITS"); + TCollection_AsciiString aUnitsStr (aUnits.in()); + bool needConvert = true; + if (aUnitsStr.IsEmpty() || aUnitsStr == "UNIT_M") + needConvert = false; + + if (needConvert) { + if (igesAnswer == SUIT_MessageBox::NoToAll) { + // converting for all files is already approved + fileT = (aCurrentType + "_SCALE").toLatin1().constData(); + } + else if (igesAnswer != SUIT_MessageBox::YesToAll) { + SUIT_MessageBox::StandardButtons btns = SUIT_MessageBox::Yes | SUIT_MessageBox::No; + if (i < fileNames.count() - 1) btns = btns | SUIT_MessageBox::YesToAll | SUIT_MessageBox::NoToAll; + igesAnswer = SUIT_MessageBox::question(app->desktop(), + "Question",//tr("WRN_WARNING"), + tr("GEOM_SCALE_DIMENSIONS"), + btns | SUIT_MessageBox::Cancel, + SUIT_MessageBox::No); + switch (igesAnswer) { + case SUIT_MessageBox::Cancel: + return false; // cancel (break) import operation + case SUIT_MessageBox::Yes: + case SUIT_MessageBox::YesToAll: + break; // scaling is confirmed + case SUIT_MessageBox::No: + case SUIT_MessageBox::NoAll: + fileT = (aCurrentType + "_SCALE").toLatin1().constData(); + default: + break; // scaling is rejected + } // switch ( igesAnswer ) + } // if ( igeAnswer != NoToAll ) + } // if ( needConvert ) + + /* // skl 29.05.2009 if ( aCurrentType == "IGES" ) { GEOM::GEOM_Object_var anObj = aInsOp->ImportFile( fileN, "IGES_UNIT" ); @@ -684,6 +720,9 @@ bool GEOMToolsGUI::Import() } // if ( needConvert ) } // if ( aCurrentType == "IGES" ) else if ( aCurrentType == "ACIS" ) { + */ + + if ( aCurrentType == "ACIS" ) { if ( acisAnswer != SUIT_MessageBox::YesToAll && acisAnswer != SUIT_MessageBox::NoToAll ) { SUIT_MessageBox::StandardButtons btns = SUIT_MessageBox::Yes | SUIT_MessageBox::No; if ( i < fileNames.count()-1 ) btns = btns | SUIT_MessageBox::YesToAll | SUIT_MessageBox::NoToAll; @@ -697,6 +736,7 @@ bool GEOMToolsGUI::Import() } // if ( acisAnswer != YesToAll && acisAnswer != NoToAll ) } // else if ( aCurrentType == "ACIS" ) + // IMPORT GEOM::GEOM_Object_var anObj = aInsOp->ImportFile( fileN, fileT ); if ( !anObj->_is_nil() && aInsOp->IsDone() ) { diff --git a/src/GEOM_I/GEOM_IInsertOperations_i.cc b/src/GEOM_I/GEOM_IInsertOperations_i.cc index e27a6876b..cd1b443fa 100644 --- a/src/GEOM_I/GEOM_IInsertOperations_i.cc +++ b/src/GEOM_I/GEOM_IInsertOperations_i.cc @@ -18,7 +18,6 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// #ifdef WNT #pragma warning( disable:4786 ) @@ -47,7 +46,7 @@ //============================================================================= /*! - * constructor: + * constructor */ //============================================================================= GEOM_IInsertOperations_i::GEOM_IInsertOperations_i (PortableServer::POA_ptr thePOA, @@ -155,6 +154,32 @@ GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::ImportFile return GetObject(anObject); } +//============================================================================= +/*! + * ReadValue + */ +//============================================================================= +char* GEOM_IInsertOperations_i::ReadValue(const char* theFileName, + const char* theFormatName, + const char* theParameterName) +{ + //Set a not done flag + GetOperations()->SetNotDone(); + + char* aFileName = strdup(theFileName); + char* aFormatName = strdup(theFormatName); + char* aParameterName = strdup(theParameterName); + + TCollection_AsciiString aUnits = GetOperations()->ReadValue + (aFileName, aFormatName, aParameterName); + + free(aFileName); + free(aFormatName); + free(aParameterName); + + return CORBA::string_dup(aUnits.ToCString()); +} + //============================================================================= /*! * ImportTranslators diff --git a/src/GEOM_I/GEOM_IInsertOperations_i.hh b/src/GEOM_I/GEOM_IInsertOperations_i.hh index a7f8cf1dd..820570016 100644 --- a/src/GEOM_I/GEOM_IInsertOperations_i.hh +++ b/src/GEOM_I/GEOM_IInsertOperations_i.hh @@ -18,7 +18,6 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// #ifndef _GEOM_IInsertOperations_i_HeaderFile #define _GEOM_IInsertOperations_i_HeaderFile @@ -52,6 +51,10 @@ class GEOM_I_EXPORT GEOM_IInsertOperations_i : GEOM::GEOM_Object_ptr ImportFile (const char* theFileName, const char* theFormatName); + char* ReadValue (const char* theFileName, + const char* theFormatName, + const char* theParameterName); + void ImportTranslators (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns); diff --git a/src/IGESImport/IGESImport.cxx b/src/IGESImport/IGESImport.cxx index 43f0e3870..e9c73ac4a 100644 --- a/src/IGESImport/IGESImport.cxx +++ b/src/IGESImport/IGESImport.cxx @@ -51,6 +51,8 @@ #include #include +#include // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC + #ifdef WNT #if defined IGESIMPORT_EXPORTS || defined IGESImport_EXPORTS #if defined WIN32 @@ -77,33 +79,84 @@ extern "C" { + IGESIMPORT_EXPORT + Handle(TCollection_HAsciiString) GetValue (const TCollection_AsciiString& theFileName, + const TCollection_AsciiString& theParameterName, + TCollection_AsciiString& theError) + { + Handle(TCollection_HAsciiString) aValue; + + if (theParameterName != "LEN_UNITS") { + theError = theParameterName + " parameter reading is not supported by IGES plugin"; + return aValue; + } + + // Set "C" numeric locale to save numbers correctly + Kernel_Utils::Localizer loc; + + IGESControl_Reader aReader; + + Interface_Static::SetCVal("xstep.cascade.unit","M"); + + try { + OCC_CATCH_SIGNALS; + + IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString()); + if (status == IFSelect_RetDone) { + Handle(IGESData_IGESModel) aModel = + Handle(IGESData_IGESModel)::DownCast(aReader.Model()); + if (!aModel.IsNull()) { + aValue = aModel->GlobalSection().UnitName(); + + if (!aValue.IsNull()) { + Handle(TCollection_HAsciiString) aPrefix = new TCollection_HAsciiString ("UNIT_"); + aValue->Prepend(aPrefix); + } + } + } + else { + theError = theFileName + " reading failed"; + } + } + catch (Standard_Failure) { + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + theError = aFail->GetMessageString(); + } + + return aValue; + } + IGESIMPORT_EXPORT TopoDS_Shape Import (const TCollection_AsciiString& theFileName, const TCollection_AsciiString& theFormatName, TCollection_AsciiString& theError, const TDF_Label& theShapeLabel) { + TopoDS_Shape aResShape; + // Set "C" numeric locale to save numbers correctly Kernel_Utils::Localizer loc; IGESControl_Reader aReader; - TopoDS_Shape aResShape; + Interface_Static::SetCVal("xstep.cascade.unit","M"); + try { + OCC_CATCH_SIGNALS; + IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString()); if (status == IFSelect_RetDone) { + // BEGIN: old code if (theFormatName == "IGES_UNIT") { Handle(IGESData_IGESModel) aModel = Handle(IGESData_IGESModel)::DownCast(aReader.Model()); - gp_Pnt P(1.0,0.0,0.0); + gp_Pnt P (1.0, 0.0, 0.0); if (!aModel.IsNull()) { Handle(TCollection_HAsciiString) aUnitName = aModel->GlobalSection().UnitName(); if (!aUnitName.IsNull()) { - //cout<<"aUnitName = "<ToCString()< #include -#include +#include +#include +#include +#include +#include + #include #include #include @@ -39,23 +43,23 @@ #include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include + +#include + #include #include #include #include #include #include -#include -#include -#include -#include -#include + +#include +#include #include #include // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC @@ -86,35 +90,135 @@ extern "C" { + STEPIMPORT_EXPORT + Handle(TCollection_HAsciiString) GetValue (const TCollection_AsciiString& theFileName, + const TCollection_AsciiString& theParameterName, + TCollection_AsciiString& theError) + { + Handle(TCollection_HAsciiString) aValue; + + if (theParameterName != "LEN_UNITS") { + theError = theParameterName + " parameter reading is not supported by STEP plugin"; + return aValue; + } + + // Set "C" numeric locale to save numbers correctly + Kernel_Utils::Localizer loc; + + STEPControl_Reader aReader; + + Interface_Static::SetCVal("xstep.cascade.unit","M"); + Interface_Static::SetIVal("read.step.ideas", 1); + Interface_Static::SetIVal("read.step.nonmanifold", 1); + + try { +#if OCC_VERSION_LARGE > 0x06010000 + OCC_CATCH_SIGNALS; +#endif + IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString()); + if (status == IFSelect_RetDone) { + TColStd_SequenceOfAsciiString anUnitLengthNames; + TColStd_SequenceOfAsciiString anUnitAngleNames; + TColStd_SequenceOfAsciiString anUnitSolidAngleNames; + aReader.FileUnits(anUnitLengthNames, anUnitAngleNames, anUnitSolidAngleNames); + if (anUnitLengthNames.Length() > 0) { + TCollection_AsciiString aLenUnits = anUnitLengthNames.First(); + if (aLenUnits == "millimetre") + aValue = new TCollection_HAsciiString ("UNIT_MM"); + else if (aLenUnits == "centimetre") + aValue = new TCollection_HAsciiString ("UNIT_CM"); + else if (aLenUnits == "metre") + aValue = new TCollection_HAsciiString ("UNIT_M"); + else if (aLenUnits == "INCH") + aValue = new TCollection_HAsciiString ("UNIT_INCH"); + // TODO + //else if (aLenUnits == "") + // aValue = new TCollection_HAsciiString (""); + + // tmp begin + //std::cout << "$$$ --- " << anUnitLengthNames.First(); + //for (int ii = 2; ii <= anUnitLengthNames.Length(); ii++) + // std::cout << ", " << anUnitLengthNames.Value(ii); + //std::cout << std::endl; + // tmp end + } + } + else { + theError = theFileName + " reading failed"; + } + } + catch (Standard_Failure) { + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + theError = aFail->GetMessageString(); + } + + return aValue; + } + STEPIMPORT_EXPORT TopoDS_Shape Import (const TCollection_AsciiString& theFileName, - const TCollection_AsciiString& /*theFormatName*/, + const TCollection_AsciiString& theFormatName, TCollection_AsciiString& theError, const TDF_Label& theShapeLabel) { - MESSAGE("Import STEP model from file " << theFileName.ToCString()); + TopoDS_Shape aResShape; + // Set "C" numeric locale to save numbers correctly Kernel_Utils::Localizer loc; - TopoDS_Shape aResShape; - //VRV: OCC 4.0 migration + STEPControl_Reader aReader; + //VSR: 16/09/09: Convert to METERS Interface_Static::SetCVal("xstep.cascade.unit","M"); Interface_Static::SetIVal("read.step.ideas", 1); Interface_Static::SetIVal("read.step.nonmanifold", 1); - //VRV: OCC 4.0 migration - TopoDS_Compound compound; + BRep_Builder B; + TopoDS_Compound compound; B.MakeCompound(compound); + try { -#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; -#endif + IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString()); if (status == IFSelect_RetDone) { + + // Regard or not the model units + if (theFormatName == "STEP_SCALE") { + // set UnitFlag to units from file + TColStd_SequenceOfAsciiString anUnitLengthNames; + TColStd_SequenceOfAsciiString anUnitAngleNames; + TColStd_SequenceOfAsciiString anUnitSolidAngleNames; + aReader.FileUnits(anUnitLengthNames, anUnitAngleNames, anUnitSolidAngleNames); + if (anUnitLengthNames.Length() > 0) { + TCollection_AsciiString aLenUnits = anUnitLengthNames.First(); + if (aLenUnits == "millimetre") + Interface_Static::SetCVal("xstep.cascade.unit", "MM"); + else if (aLenUnits == "centimetre") + Interface_Static::SetCVal("xstep.cascade.unit", "CM"); + else if (aLenUnits == "metre") + Interface_Static::SetCVal("xstep.cascade.unit", "M"); + else if (aLenUnits == "INCH") + Interface_Static::SetCVal("xstep.cascade.unit", "INCH"); + else { + theError = "The file contains not supported units."; + return aResShape; + } + // TODO + //else if (aLenUnits == "") + // Interface_Static::SetCVal("xstep.cascade.unit", ""); + } + } + else { + //cout<<"need re-scale a model"<