From a84676a7fa62079fdf65589713111b516442bac8 Mon Sep 17 00:00:00 2001 From: skv Date: Tue, 12 Nov 2013 08:22:19 +0000 Subject: [PATCH] 0022315: EDF 2722 GEOM: Import STL in GEOM --- CMakeLists.txt | 2 +- SalomeGEOMConfig.cmake.in | 1 + adm_local/cmake_files/FindGEOM.cmake | 1 + doc/salome/gui/GEOM/input/import_export.doc | 8 +-- doc/salome/gui/GEOM/input/index.doc | 2 +- resources/ImportExport | 5 +- src/CMakeLists.txt | 2 +- src/GEOMImpl/GEOMImpl_IInsertOperations.cxx | 21 +++++- src/STLImport/CMakeLists.txt | 52 +++++++++++++++ src/STLImport/STLImport.cxx | 72 +++++++++++++++++++++ 10 files changed, 156 insertions(+), 10 deletions(-) create mode 100755 src/STLImport/CMakeLists.txt create mode 100755 src/STLImport/STLImport.cxx diff --git a/CMakeLists.txt b/CMakeLists.txt index 4fa376399..c4bdf159d 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -243,7 +243,7 @@ INCLUDE(CMakePackageConfigHelpers) SET(_${PROJECT_NAME}_exposed_targets GEOMArchimede BREPExport BREPImport BlockFix GEOMbasic GEOMAlgo GEOMClient GEOMImpl GEOMUtils GEOMEngine GEOM_SupervEngine IGESExport IGESImport GEOMSketcher - SalomeIDLGEOM STEPExport STEPImport STLExport ShHealOper XAO AdvancedEngine OCC2VTK + SalomeIDLGEOM STEPExport STEPImport STLExport STLImport ShHealOper XAO AdvancedEngine OCC2VTK VTKExport ) IF(SALOME_BUILD_GUI) diff --git a/SalomeGEOMConfig.cmake.in b/SalomeGEOMConfig.cmake.in index 696ebe291..1e1b3e0ee 100644 --- a/SalomeGEOMConfig.cmake.in +++ b/SalomeGEOMConfig.cmake.in @@ -151,6 +151,7 @@ SET(GEOM_SalomeIDLGEOM SalomeIDLGEOM) SET(GEOM_STEPExport STEPExport) SET(GEOM_STEPImport STEPImport) SET(GEOM_STLExport STLExport) +SET(GEOM_STLImport STLImport) SET(GEOM_ShHealOper ShHealOper) SET(GEOM_XAO XAO) SET(GEOM_AdvancedEngine AdvancedEngine) diff --git a/adm_local/cmake_files/FindGEOM.cmake b/adm_local/cmake_files/FindGEOM.cmake index 345ad524f..728252e92 100644 --- a/adm_local/cmake_files/FindGEOM.cmake +++ b/adm_local/cmake_files/FindGEOM.cmake @@ -38,6 +38,7 @@ FIND_LIBRARY(GEOM_SalomeIDLGEOM SalomeIDLGEOM ${GEOM_ROOT_DIR}/lib/salome) FIND_LIBRARY(GEOM_STEPExport STEPExport ${GEOM_ROOT_DIR}/lib/salome) FIND_LIBRARY(GEOM_STEPImport STEPImport ${GEOM_ROOT_DIR}/lib/salome) FIND_LIBRARY(GEOM_STLExport STLExport ${GEOM_ROOT_DIR}/lib/salome) +FIND_LIBRARY(GEOM_STLImport STLImport ${GEOM_ROOT_DIR}/lib/salome) FIND_LIBRARY(GEOM_ShHealOper ShHealOper ${GEOM_ROOT_DIR}/lib/salome) FIND_LIBRARY(GEOM_XAO XAO ${GEOM_ROOT_DIR}/lib/salome) FIND_LIBRARY(GEOM_AdvancedEngine AdvancedEngine ${GEOM_ROOT_DIR}/lib/salome) diff --git a/doc/salome/gui/GEOM/input/import_export.doc b/doc/salome/gui/GEOM/input/import_export.doc index 62a80da55..775be618f 100644 --- a/doc/salome/gui/GEOM/input/import_export.doc +++ b/doc/salome/gui/GEOM/input/import_export.doc @@ -3,17 +3,17 @@ \page import_export_geom_obj_page Importing/exporting geometrical objects In Geometry module you can import and export geometrical objects -from/into BREP, IGES, STEP files. The mechanisms of import and export +from/into BREP, IGES, STEP, ACIS and STL files. The mechanisms of import and export are implemented via plug-ins, which gives the opportunity to expand the range of available formats by adding more plug-ins (for example, CATIA 5). -To import geometrical objects from a BREP, IGES, STEP file: +To import geometrical objects from a BREP, IGES, STEP, ACIS or STL file: \par From the \b File menu choose \b Import. In the opening dialog box \b Import select the required format of the file for importation and search for -a *.brep, *.iges or *.step file. +a *.brep, *.iges, *.step, *.sat or *.stl file. \image html geomimport.png @@ -49,7 +49,7 @@ as before this operation. \image html geomimport_reopen.png -\n To export geometrical objects into a BREP, IGES, STEP +\n To export geometrical objects into a BREP, IGES, STEP, ACIS or STL file: \par diff --git a/doc/salome/gui/GEOM/input/index.doc b/doc/salome/gui/GEOM/input/index.doc index af0fc6f51..7a9035091 100644 --- a/doc/salome/gui/GEOM/input/index.doc +++ b/doc/salome/gui/GEOM/input/index.doc @@ -6,7 +6,7 @@ \b Geometry module of SALOME is destined for: - \subpage import_export_geom_obj_page "import and export of geometrical models" - in IGES, BREP and STEP formats; + in IGES, BREP, STEP, ACIS and STL formats; - \subpage create_geom_obj_page "construction of geometrical objects" using a wide range of functions; - \subpage view_geom_obj_page "viewing geometrical objects" in the OCC diff --git a/resources/ImportExport b/resources/ImportExport index 950ccd136..6af7a9579 100644 --- a/resources/ImportExport +++ b/resources/ImportExport @@ -1,4 +1,4 @@ -Import: BREP|IGES|STEP|ACIS +Import: BREP|IGES|STEP|STL|ACIS Export: BREP|IGES|IGES_5_3|STEP|STL_Bin|STL_ASCII|ACIS|VTK BREP.Import: BREPImport @@ -17,6 +17,9 @@ STEP.Import: STEPImport STEP.Export: STEPExport STEP.Pattern: STEP Files ( *.step *.stp ) +STL.Import: STLImport +STL.Pattern: STL Files ( *.stl ) + STL_Bin.Export: STLExport STL_Bin.Pattern: STL Binary Files ( *.stl ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aaa52fd8e..4a5ddda0f 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,7 +22,7 @@ ## SET(SUBDIRS_COMMON ARCHIMEDE BlockFix GEOMAlgo SKETCHER GEOM BREPExport - BREPImport IGESExport IGESImport STEPExport STEPImport STLExport + BREPImport IGESExport IGESImport STEPExport STEPImport STLExport STLImport ShHealOper GEOMUtils XAO XAO_Swig GEOMImpl GEOM_I GEOMClient GEOM_I_Superv GEOM_SWIG GEOM_PY AdvancedEngine OCC2VTK VTKExport ) diff --git a/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx b/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx index 37e7fea8a..a3e2fcef3 100644 --- a/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx @@ -74,6 +74,21 @@ #include #include // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC +/** + * This function returns the input format name from the original format name. + */ +static TCollection_AsciiString GetImportFormatName + (const TCollection_AsciiString& theFormatName) +{ + Standard_Integer aLastInd = 4; + + if (theFormatName.Search("STL") == 1) { + aLastInd = 3; + } + + return theFormatName.SubString(1, aLastInd); +} + //============================================================================= /*! * constructor @@ -236,7 +251,8 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import if (aFunction->GetDriverGUID() != GEOMImpl_ImportDriver::GetID()) return result; Handle(TCollection_HAsciiString) aHLibName; - if (!IsSupported(Standard_True, theFormatName.SubString(1,4), aHLibName)) { + if (!IsSupported + (Standard_True, GetImportFormatName(theFormatName), aHLibName)) { return result; } TCollection_AsciiString aLibName = aHLibName->String(); @@ -320,7 +336,8 @@ TCollection_AsciiString GEOMImpl_IInsertOperations::ReadValue if (theFileName.IsEmpty() || theFormatName.IsEmpty() || theParameterName.IsEmpty()) return aValue; Handle(TCollection_HAsciiString) aHLibName; - if (!IsSupported(Standard_True, theFormatName.SubString(1,4), aHLibName)) { + if (!IsSupported + (Standard_True, GetImportFormatName(theFormatName), aHLibName)) { return aValue; } TCollection_AsciiString aLibName = aHLibName->String(); diff --git a/src/STLImport/CMakeLists.txt b/src/STLImport/CMakeLists.txt new file mode 100755 index 000000000..87724cd74 --- /dev/null +++ b/src/STLImport/CMakeLists.txt @@ -0,0 +1,52 @@ +# Copyright (C) 2012-2013 CEA/DEN, EDF R&D, OPEN CASCADE +# +# 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. +# +# 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 +# + +# --- options --- + +# additional include directories +INCLUDE_DIRECTORIES( + ${CAS_INCLUDE_DIRS} + ${PTHREAD_INCLUDE_DIR} + ${KERNEL_INCLUDE_DIRS} + ) + +# additional preprocessor / compiler flags +ADD_DEFINITIONS( + ${CAS_DEFINITIONS} + ) + +# libraries to link to +SET(_link_LIBRARIES + ${CAS_TKSTL} + ${KERNEL_SALOMELocalTrace} + ) + +# --- sources --- + +SET(STLImport_SOURCES + STLImport.cxx + ) + +# --- rules --- + +ADD_LIBRARY(STLImport ${STLImport_SOURCES}) +TARGET_LINK_LIBRARIES(STLImport ${_link_LIBRARIES}) +INSTALL(TARGETS STLImport EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) + + diff --git a/src/STLImport/STLImport.cxx b/src/STLImport/STLImport.cxx new file mode 100755 index 000000000..dcc71d7d3 --- /dev/null +++ b/src/STLImport/STLImport.cxx @@ -0,0 +1,72 @@ +// Copyright (C) 2007-2013 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 +// +// 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. +// +// 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 +// + +// File: STLImport.cxx +// Author: Sergey KHROMOV + + +#include "utilities.h" +#include +#include +#include +#include + + +#ifdef WIN32 + #if defined STLIMPORT_EXPORTS || defined STLImport_EXPORTS + #define STLIMPORT_EXPORT __declspec( dllexport ) + #else + #define STLIMPORT_EXPORT __declspec( dllimport ) + #endif +#else + #define STLIMPORT_EXPORT +#endif + + +//============================================================================= +/*! + * + */ +//============================================================================= + +extern "C" +{ +STLIMPORT_EXPORT + TopoDS_Shape Import (const TCollection_AsciiString& theFileName, + const TCollection_AsciiString& /*theFormatName*/, + TCollection_AsciiString& theError, + const TDF_Label&) + { + MESSAGE("Import STL from file " << theFileName.ToCString()); + + StlAPI_Reader aReader; + TopoDS_Shape aShape; + + aReader.Read(aShape, theFileName.ToCString()); + + if (aShape.IsNull()) { + theError = "STL Import failed"; + } + + return aShape; + } +} -- 2.30.2