14bbbdcb |
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 | |
14bbbdcb |
17 | #include <TInspectorEXE_OpenFileDialog.hxx> |
0cb512c0 |
18 | |
19 | #include <inspector/TInspector_Communicator.hxx> |
20 | |
21 | #include <OSD_Environment.hxx> |
14bbbdcb |
22 | |
6822a3be |
23 | #include <Standard_WarningsDisable.hxx> |
14bbbdcb |
24 | #include <QAction> |
25 | #include <QApplication> |
26 | #include <QDir> |
27 | #include <QMainWindow> |
28 | #include <QToolBar> |
6822a3be |
29 | #include <Standard_WarningsRestore.hxx> |
14bbbdcb |
30 | |
31 | #include <set> |
32 | |
33 | // ======================================================================= |
34 | // function : fileNameInDataDir |
35 | // purpose : |
36 | // ======================================================================= |
37 | TCollection_AsciiString fileNameInDataDir(const TCollection_AsciiString& theEnvironmentDir, |
38 | const TCollection_AsciiString& theName) |
39 | { |
40 | OSD_Environment anEnvironment(theEnvironmentDir); |
41 | |
42 | TCollection_AsciiString aFileName = anEnvironment.Value(); |
43 | aFileName += TCollection_AsciiString("/") + theName; |
44 | |
45 | return aFileName; |
46 | } |
47 | |
48 | // ======================================================================= |
49 | // function : setPluginSampleDirectory |
50 | // purpose : |
51 | // ======================================================================= |
52 | void setPluginSampleDirectory (const TCollection_AsciiString& theName, TInspector_Communicator* theCommunicator, |
53 | TInspectorEXE_OpenButton* theButtonControl) |
54 | { |
55 | if (theName.IsEqual ("TKDFBrowser")) |
56 | { |
57 | theCommunicator->OpenFile (theName, fileNameInDataDir ("CSF_OCCTDataPath", "step/screw.step")); |
58 | theButtonControl->SetPluginDir (theName, fileNameInDataDir ("CSF_OCCTDataPath", "step")); |
59 | } |
60 | else if (theName.IsEqual ("TKShapeView")) |
61 | { |
62 | theCommunicator->OpenFile (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ/hammer.brep")); |
63 | theButtonControl->SetPluginDir (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ")); |
64 | } |
65 | else if (theName.IsEqual ("TKVInspector")) |
66 | { |
67 | theCommunicator->OpenFile (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ/face1.brep")); |
68 | theCommunicator->OpenFile (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ/face2.brep")); |
69 | theButtonControl->SetPluginDir (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ")); |
70 | } |
71 | } |
72 | |
73 | // ======================================================================= |
74 | // function : main |
75 | // purpose : |
76 | // ======================================================================= |
77 | int main (int argc, char** argv) |
78 | { |
1fa16152 |
79 | #if QT_VERSION > 0x050000 |
80 | TCollection_AsciiString aPlugindsDirName = OSD_Environment ("QTDIR").Value(); |
81 | if (!aPlugindsDirName.IsEmpty()) |
82 | QApplication::addLibraryPath (QString (aPlugindsDirName.ToCString()) + "/plugins"); |
83 | #endif |
14bbbdcb |
84 | QApplication anApp (argc, argv); |
85 | |
86 | std::set<TCollection_AsciiString> aPlugins; |
87 | for (int anArgId = 1; anArgId < argc; anArgId++ ) |
88 | { |
4f4b8935 |
89 | if (!strcmp (argv[anArgId], "dfbrowser")) |
14bbbdcb |
90 | aPlugins.insert ("TKDFBrowser"); |
91 | |
4f4b8935 |
92 | if (!strcmp (argv[anArgId], "shapeview")) |
14bbbdcb |
93 | aPlugins.insert ("TKShapeView"); |
94 | |
4f4b8935 |
95 | if (!strcmp (argv[anArgId], "vinspector")) |
14bbbdcb |
96 | aPlugins.insert ("TKVInspector"); |
97 | } |
98 | NCollection_List<Handle(Standard_Transient)> aParameters; |
99 | |
100 | // Create tool communicator |
101 | TInspector_Communicator* aCommunicator = TInspectorEXE_OpenFileDialog::Communicator(); |
102 | if (!aCommunicator) |
103 | { |
104 | std::cout << "Communicator can not be created" << std::endl; |
105 | return 0; |
106 | } |
107 | |
108 | TInspectorEXE_OpenButton* aButtonControl = new TInspectorEXE_OpenButton (0); |
109 | TCollection_AsciiString anActivatedPluginName; |
110 | if (aPlugins.empty()) |
111 | { |
112 | aPlugins.insert("TKDFBrowser"); |
113 | aPlugins.insert("TKShapeView"); |
114 | aPlugins.insert("TKVInspector"); |
115 | |
116 | anActivatedPluginName = "TKDFBrowser"; |
117 | } |
118 | else |
119 | anActivatedPluginName = *aPlugins.rbegin(); |
120 | |
121 | for (std::set<TCollection_AsciiString>::const_iterator aPluginIt = aPlugins.begin(); aPluginIt != aPlugins.end(); aPluginIt++) |
122 | { |
123 | TCollection_AsciiString aName = *aPluginIt; |
124 | aCommunicator->RegisterPlugin (aName); |
125 | aCommunicator->Init (aName, aParameters); |
126 | setPluginSampleDirectory (aName, aCommunicator, aButtonControl); |
127 | } |
128 | aCommunicator->Activate (anActivatedPluginName); |
129 | |
130 | aCommunicator->SetVisible (true); |
131 | aCommunicator->SetOpenButton (aButtonControl->StartButton()); |
132 | |
133 | return anApp.exec(); |
134 | } |