1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <inspector/DFBrowser_OpenApplication.hxx>
18 #include <BinDrivers.hxx>
19 #include <BinLDrivers.hxx>
20 #include <BinXCAFDrivers.hxx>
21 #include <PCDM_ReadWriter.hxx>
22 #include <StdDrivers.hxx>
23 #include <StdLDrivers.hxx>
24 #include <STEPCAFControl_Reader.hxx>
25 #include <STEPCAFControl_Controller.hxx>
26 #include <TPrsStd_DriverTable.hxx>
27 #include <XCAFApp_Application.hxx>
28 #include <XCAFPrs_Driver.hxx>
29 #include <XmlDrivers.hxx>
30 #include <XmlLDrivers.hxx>
31 #include <XmlXCAFDrivers.hxx>
34 namespace DFBrowser_OpenApplication
37 // =======================================================================
38 // function : OpenApplication
40 // =======================================================================
41 Handle(TDocStd_Application) OpenApplication (const TCollection_AsciiString& theFileName, bool& isSTEPFile)
43 Handle(TDocStd_Application) anApplication = CreateApplicationBySTEPFile (theFileName);
44 if (!anApplication.IsNull())
50 // Load static variables for STEPCAF (ssv; 16.08.2012)
51 STEPCAFControl_Controller::Init();
53 anApplication = new TDocStd_Application();
54 // Initialize standard document formats at creation - they should
55 // be available even if this DRAW plugin is not loaded by pload command
56 StdLDrivers::DefineFormat (anApplication);
57 BinLDrivers::DefineFormat (anApplication);
58 XmlLDrivers::DefineFormat (anApplication);
59 StdDrivers::DefineFormat (anApplication);
60 BinDrivers::DefineFormat (anApplication);
61 XmlDrivers::DefineFormat (anApplication);
63 // Initialize XCAF formats
64 BinXCAFDrivers::DefineFormat (anApplication);
65 XmlXCAFDrivers::DefineFormat (anApplication);
67 // Register driver in global table for displaying XDE documents
68 // in 3d viewer using OCAF mechanics
69 TPrsStd_DriverTable::Get()->AddDriver (XCAFPrs_Driver::GetID(), new XCAFPrs_Driver);
71 Handle(TDocStd_Document) aDocument;
72 PCDM_ReaderStatus aStatus = anApplication->Open (theFileName, aDocument);
73 if (aStatus != PCDM_RS_OK)
74 return Handle(TDocStd_Application)();
78 // =======================================================================
79 // function : CreateApplicationBySTEPFile
81 // =======================================================================
82 Handle(TDocStd_Application) CreateApplicationBySTEPFile (const TCollection_AsciiString& theFileName)
84 if (!theFileName.EndsWith (".step") && !theFileName.EndsWith (".stp"))
85 return Handle(TDocStd_Application)();
87 Handle(TDocStd_Application) aTmpApplication = XCAFApp_Application::GetApplication();
88 STEPCAFControl_Reader aStepReader;
90 const TCollection_AsciiString aStr (theFileName);
91 IFSelect_ReturnStatus aStatus = aStepReader.ReadFile (aStr.ToCString());
92 if (aStatus != IFSelect_RetDone)
93 return Handle(TDocStd_Application)();
95 aStepReader.SetColorMode (Standard_True);
96 aStepReader.SetLayerMode (Standard_True);
97 aStepReader.SetNameMode (Standard_True);
99 Handle(TDocStd_Document) aDocument;
100 aTmpApplication->NewDocument ("BinOcaf", aDocument);
101 return aStepReader.Transfer (aDocument) ? aTmpApplication : Handle(TDocStd_Application)();