0029025: TInspector include files are not installed to inc directory by CMake
[occt.git] / tools / ShapeView / ShapeView_Communicator.cxx
1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement. 
15
16 #include <inspector/ShapeView_Communicator.hxx>
17
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>
23
24 #include <QApplication>
25 #include <QMainWindow>
26 #include <QDir>
27
28 // =======================================================================
29 // function :  CreateCommunicator
30 // purpose : Creates a communicator by the library loading
31 // =======================================================================
32 Standard_EXPORTEXTERNC TInspectorAPI_Communicator* CreateCommunicator()
33 {
34   return new ShapeView_Communicator();
35 }
36
37 // =======================================================================
38 // function : Constructor
39 // purpose :
40 // =======================================================================
41 ShapeView_Communicator::ShapeView_Communicator()
42 : TInspectorAPI_Communicator(), myWindow (0)
43 {
44   // main window creation
45   TCollection_AsciiString aTmpDir;
46 #ifdef _WIN32
47   OSD_Environment anEnvironment ("TEMP");
48   aTmpDir = anEnvironment.Value();
49   if (aTmpDir.IsEmpty() )
50   {
51     anEnvironment.SetName("TMP");
52     aTmpDir = anEnvironment.Value();
53     if (aTmpDir.IsEmpty())
54       aTmpDir = "C:\\";
55   }
56   if (!aTmpDir.EndsWith ("\\"))
57     aTmpDir += "\\";
58   OSD_Path aTmpPath (aTmpDir);
59   OSD_Directory aTmpDirectory;
60 #else
61   OSD_Directory aTmpDirectory = OSD_Directory::BuildTemporary();
62   OSD_Path aTmpPath;
63   aTmpDirectory.Path (aTmpPath);
64 #endif
65   aTmpPath.DownTrek ("ShapeView");
66   aTmpDirectory.SetPath (aTmpPath);
67   if (!aTmpDirectory.Exists())
68     aTmpDirectory.Build (OSD_Protection());
69
70   aTmpDirectory.Path (aTmpPath);
71   TCollection_AsciiString aTmpDirectoryName;
72   aTmpPath.SystemName(aTmpDirectoryName);
73   myWindow = new ShapeView_Window (0, aTmpDirectoryName);
74 }
75
76 ShapeView_Communicator::~ShapeView_Communicator()
77 {
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();
83 }
84