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/ShapeView_Communicator.hxx>
18 #include <inspector/ShapeView_Window.hxx>
19 #include <OSD_Directory.hxx>
20 #include <OSD_Environment.hxx>
21 #include <OSD_Path.hxx>
22 #include <OSD_Protection.hxx>
24 #include <QApplication>
25 #include <QMainWindow>
28 // =======================================================================
29 // function : CreateCommunicator
30 // purpose : Creates a communicator by the library loading
31 // =======================================================================
32 Standard_EXPORTEXTERNC TInspectorAPI_Communicator* CreateCommunicator()
34 return new ShapeView_Communicator();
37 // =======================================================================
38 // function : Constructor
40 // =======================================================================
41 ShapeView_Communicator::ShapeView_Communicator()
42 : TInspectorAPI_Communicator(), myWindow (0)
44 // main window creation
45 TCollection_AsciiString aTmpDir;
47 OSD_Environment anEnvironment ("TEMP");
48 aTmpDir = anEnvironment.Value();
49 if (aTmpDir.IsEmpty() )
51 anEnvironment.SetName("TMP");
52 aTmpDir = anEnvironment.Value();
53 if (aTmpDir.IsEmpty())
56 if (!aTmpDir.EndsWith ("\\"))
58 OSD_Path aTmpPath (aTmpDir);
59 OSD_Directory aTmpDirectory;
61 OSD_Directory aTmpDirectory = OSD_Directory::BuildTemporary();
63 aTmpDirectory.Path (aTmpPath);
65 aTmpPath.DownTrek ("ShapeView");
66 aTmpDirectory.SetPath (aTmpPath);
67 if (!aTmpDirectory.Exists())
68 aTmpDirectory.Build (OSD_Protection());
70 aTmpDirectory.Path (aTmpPath);
71 TCollection_AsciiString aTmpDirectoryName;
72 aTmpPath.SystemName(aTmpDirectoryName);
73 myWindow = new ShapeView_Window (0, aTmpDirectoryName);
76 ShapeView_Communicator::~ShapeView_Communicator()
78 myWindow->RemoveAllShapes(); // removes all cached shapes and files in temporary directory
79 OSD_Path aPath (myWindow->GetTemporaryDirectory());
80 OSD_Directory aTmpDirectory (aPath);
81 // temporary directory can be removed only if is empty
82 aTmpDirectory.Remove();