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 | |
17 | #include <OSD_Environment.hxx> |
18 | #include <TInspectorEXE_OpenFileDialog.hxx> |
19 | #include <TInspector_Communicator.hxx> |
20 | |
21 | #include <QAction> |
22 | #include <QApplication> |
23 | #include <QDir> |
24 | #include <QMainWindow> |
25 | #include <QToolBar> |
26 | |
27 | #include <set> |
28 | |
29 | // ======================================================================= |
30 | // function : fileNameInDataDir |
31 | // purpose : |
32 | // ======================================================================= |
33 | TCollection_AsciiString fileNameInDataDir(const TCollection_AsciiString& theEnvironmentDir, |
34 | const TCollection_AsciiString& theName) |
35 | { |
36 | OSD_Environment anEnvironment(theEnvironmentDir); |
37 | |
38 | TCollection_AsciiString aFileName = anEnvironment.Value(); |
39 | aFileName += TCollection_AsciiString("/") + theName; |
40 | |
41 | return aFileName; |
42 | } |
43 | |
44 | // ======================================================================= |
45 | // function : setPluginSampleDirectory |
46 | // purpose : |
47 | // ======================================================================= |
48 | void setPluginSampleDirectory (const TCollection_AsciiString& theName, TInspector_Communicator* theCommunicator, |
49 | TInspectorEXE_OpenButton* theButtonControl) |
50 | { |
51 | if (theName.IsEqual ("TKDFBrowser")) |
52 | { |
53 | theCommunicator->OpenFile (theName, fileNameInDataDir ("CSF_OCCTDataPath", "step/screw.step")); |
54 | theButtonControl->SetPluginDir (theName, fileNameInDataDir ("CSF_OCCTDataPath", "step")); |
55 | } |
56 | else if (theName.IsEqual ("TKShapeView")) |
57 | { |
58 | theCommunicator->OpenFile (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ/hammer.brep")); |
59 | theButtonControl->SetPluginDir (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ")); |
60 | } |
61 | else if (theName.IsEqual ("TKVInspector")) |
62 | { |
63 | theCommunicator->OpenFile (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ/face1.brep")); |
64 | theCommunicator->OpenFile (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ/face2.brep")); |
65 | theButtonControl->SetPluginDir (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ")); |
66 | } |
67 | } |
68 | |
69 | // ======================================================================= |
70 | // function : main |
71 | // purpose : |
72 | // ======================================================================= |
73 | int main (int argc, char** argv) |
74 | { |
75 | OSD_Environment anEnvironment ("QTDIR"); |
76 | TCollection_AsciiString aPlugindsDirName = anEnvironment.Value(); |
77 | if (aPlugindsDirName.IsEmpty()) |
78 | { |
79 | std::cout << "QTDIR is not defined" << std::endl; |
80 | return 0; |
81 | } |
82 | aPlugindsDirName += "/plugins"; |
83 | QApplication::addLibraryPath (aPlugindsDirName.ToCString()); |
84 | QApplication anApp (argc, argv); |
85 | |
86 | std::set<TCollection_AsciiString> aPlugins; |
87 | for (int anArgId = 1; anArgId < argc; anArgId++ ) |
88 | { |
89 | if (!strcmp (argv[anArgId], "--dfbrowser")) |
90 | aPlugins.insert ("TKDFBrowser"); |
91 | |
92 | if (!strcmp (argv[anArgId], "--shapeview")) |
93 | aPlugins.insert ("TKShapeView"); |
94 | |
95 | if (!strcmp (argv[anArgId], "--vinspector")) |
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 | } |