-// Copyright (C) 2014 OPEN CASCADE
+// Copyright (C) 2014 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
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#include <DXFPLUGIN_exports.h>
-#include <DXFPLUGIN_version.h>
+// internal includes
+#include "DXFPlugin_ImportDriver.hxx"
+#include "DXFPlugin_IImport.hxx"
+#include "DXFPlugin_Engine.hxx"
+// KERNEL includes
#include <Basics_Utils.hxx>
+#include <utilities.h>
+// GEOM includes
+#include <GEOM_Function.hxx>
+#include <GEOMImpl_Types.hxx>
+
+// OOCT includes
#include <DxfControl_Reader.hxx>
#include <DxfSection_Block.hxx>
#include <DxfSection_HSequenceOfObject.hxx>
#include <XSControl_TransferReader.hxx>
#include <XSControl_WorkSession.hxx>
+#include <StdFail_NotDone.hxx>
+
#ifdef DXF_HASLICENSE
-#include <DXFPLUGIN_license.h>
+#include "DXFPlugin_license.h"
-#include <Standard_LicenseError.hxx>
#include <OCCLicense_Activate.hxx>
+#include <Standard_LicenseError.hxx>
#endif // DXF_HASLICENSE
-extern "C"
+//=======================================================================
+//function : GetID
+//purpose :
+//=======================================================================
+const Standard_GUID& DXFPlugin_ImportDriver::GetID()
{
- /*!
- \brief Get version of the plugin.
- \return the version of the plugin
- */
- DXFPLUGIN_EXPORT
- int GetVersion()
- {
- return DXFPLUGIN_VERSION;
- }
+ static Standard_GUID aGUID("dc74f282-3542-419f-a755-c5ab6aba17c5");
+ return aGUID;
+}
- /*!
- \brief Get version of the plugin.
- \return the string representation of the plugin's version
- */
- DXFPLUGIN_EXPORT
- char* GetVersionStr()
- {
- return (char*)DXFPLUGIN_VERSION_STR;
- }
+//=======================================================================
+//function : DXFPlugin_ImportDriver
+//purpose :
+//=======================================================================
+DXFPlugin_ImportDriver::DXFPlugin_ImportDriver()
+{
+}
+
+//=======================================================================
+//function : Execute
+//purpose :
+//=======================================================================
+Standard_Integer DXFPlugin_ImportDriver::Execute( TFunction_Logbook& log ) const
+{
+ if( Label().IsNull() ) return 0;
+ Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
+
+ DXFPlugin_IImport aData( aFunction );
+
+ TCollection_AsciiString aFileName = aData.GetFileName().ToCString();
+
+ MESSAGE("Import DXF from file " << aFileName);
+
+ TopoDS_Shape aResShape;
- /*!
- \brief Import shape from the DXF format.
- \param theFileName file path
- \param theFormatName file format signature
- \param theError error description, if there's any, is returned via this parameter
- \param theShapeLabel a label in the CAF tree where shape attributes are set to
- \return imported shape
- */
- DXFPLUGIN_EXPORT
- TopoDS_Shape Import(const TCollection_AsciiString& theFileName,
- const TCollection_AsciiString& /*theFormatName*/,
- TCollection_AsciiString& theError,
- const TDF_Label& theShapeLabel)
- {
- TopoDS_Shape aResShape;
-
#ifdef DXF_HASLICENSE
- try {
- OCCLicense_Activate( "DXF-R-"OCC_VERSION_STRING, DXF_READ_LICENSE);
- }
- catch (Standard_LicenseError) {
- return aResShape;
- }
+ try {
+ OCCLicense_Activate( "DXF-R-"OCC_VERSION_STRING, DXF_READ_LICENSE);
+ }
+ catch (Standard_LicenseError) {
+ return aResShape;
+ }
#endif
-
- // Set "C" numeric locale to save numbers correctly
- Kernel_Utils::Localizer loc;
-
- DxfControl_Reader aReader;
-
- try {
- IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString());
- if (status == IFSelect_RetDone) {
+
+ // Set "C" numeric locale to save numbers correctly
+ Kernel_Utils::Localizer loc;
+
+ DxfControl_Reader aReader;
+
+ IFSelect_ReturnStatus status = aReader.ReadFile( aFileName.ToCString() );
+ if (status == IFSelect_RetDone) {
aReader.TransferRoots();
aResShape = aReader.OneShape();
-
+
// ATTENTION: this is a workaround for mantis issue 0020442 remark 0010776
// It should be removed after patching OCCT for bug OCC22436
// (fix for OCCT is expected in service pack next to OCCT6.3sp12)
Handle(XSControl_TransferReader) TR = aReader.WS()->TransferReader();
if (!TR.IsNull()) {
Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
-
+
Handle(DxfSection_Section) aBlocks = aModel->FindSection("BLOCKS");
- if (aBlocks.IsNull()) return aResShape;
-
- Handle(DxfSection_HSequenceOfObject) anObjects = aBlocks->GetObjects();
- if (anObjects.IsNull()) return aResShape;
-
- for (Standard_Integer i = 1; i <= anObjects->Length(); i++) {
- Handle(DxfSection_Block) aBlock = Handle(DxfSection_Block)::DownCast(anObjects->Value(i));
- if (aBlock.IsNull()) continue;
- Handle(TCollection_HAsciiString) aName = aBlock->GetBlockName1();
- if (aName.IsNull()) continue;
-
- Handle(Transfer_Binder) binder = TP->Find ( aBlock );
- if (binder.IsNull()) continue;
- TopoDS_Shape aResShape = TransferBRep::ShapeResult (binder);
- if (aResShape.IsNull()) continue;
-
- // create label and set shape
- TDF_Label L;
- TDF_TagSource aTag;
- L = aTag.NewChild(theShapeLabel);
- TNaming_Builder tnBuild(L);
- tnBuild.Generated(aResShape);
-
- // set a name
- TCollection_ExtendedString str(aName->ToCString());
- TDataStd_Name::Set(L,str);
+ if( !aBlocks.IsNull() ) {
+ Handle(DxfSection_HSequenceOfObject) anObjects = aBlocks->GetObjects();
+ for (Standard_Integer i = 1; i <= anObjects->Length(); i++) {
+ Handle(DxfSection_Block) aBlock = Handle(DxfSection_Block)::DownCast(anObjects->Value(i));
+ if (aBlock.IsNull()) continue;
+ Handle(TCollection_HAsciiString) aName = aBlock->GetBlockName1();
+ if (aName.IsNull()) continue;
+
+ Handle(Transfer_Binder) binder = TP->Find ( aBlock );
+ if (binder.IsNull()) continue;
+ TopoDS_Shape aResShape = TransferBRep::ShapeResult (binder);
+ if (aResShape.IsNull()) continue;
+
+ // create label and set shape
+ TDF_Label L;
+ TDF_TagSource aTag;
+ L = aTag.NewChild(aFunction->GetNamingEntry());
+ TNaming_Builder tnBuild(L);
+ tnBuild.Generated(aResShape);
+
+ // set a name
+ TCollection_ExtendedString str( aName->ToCString() );
+ TDataStd_Name::Set(L,str);
+ }
}
}
- }
- else {
- theError = "Wrong format of the imported file. Can't import file.";
- aResShape.Nullify();
- }
- }
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- theError = aFail->GetMessageString();
- aResShape.Nullify();
- }
- return aResShape;
}
-} // end of extern "C"
+ else {
+ TCollection_AsciiString anError = "Wrong format of the imported file. Can't import file.";
+ StdFail_NotDone::Raise( anError.ToCString() );
+ aResShape.Nullify();
+ }
+
+ if( aResShape.IsNull() ) return 0;
+
+ aFunction->SetValue( aResShape );
+
+ log.SetTouched( Label() );
+
+ return 1;
+}
+
+//=======================================================================
+//function : MustExecute
+//purpose :
+//=======================================================================
+Standard_Boolean DXFPlugin_ImportDriver::MustExecute( const TFunction_Logbook& ) const
+{
+ return Standard_True;
+}
+
+//================================================================================
+/*!
+ * \brief Returns a name of creation operation and names and values of creation parameters
+ */
+//================================================================================
+
+bool DXFPlugin_ImportDriver::
+GetCreationInformation( std::string& theOperationName,
+ std::vector<GEOM_Param>& theParams )
+{
+ if( Label().IsNull() ) return 0;
+ Handle(GEOM_Function) function = GEOM_Function::GetFunction( Label() );
+
+ DXFPlugin_IImport aCI( function );
+ Standard_Integer aType = function->GetType();
+
+ theOperationName = "ImportDXF";
+
+ switch ( aType ) {
+ case IMPORT_SHAPE:
+ AddParam( theParams, "File name", aCI.GetFileName() );
+ break;
+ default:
+ return false;
+ }
+ return true;
+}
+IMPLEMENT_STANDARD_HANDLE( DXFPlugin_ImportDriver, GEOM_BaseDriver );
+IMPLEMENT_STANDARD_RTTIEXT( DXFPlugin_ImportDriver, GEOM_BaseDriver );