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.
17 #include <inspector/TInspector_OpenFileDialog.hxx>
18 #include <inspector/TInspector_OpenButton.hxx>
20 #include <inspector/TInspector_Communicator.hxx>
22 #include <OSD_Environment.hxx>
24 #include <Standard_WarningsDisable.hxx>
26 #include <QApplication>
28 #include <QMainWindow>
30 #include <Standard_WarningsRestore.hxx>
34 // =======================================================================
35 // function : fileNameInDataDir
37 // =======================================================================
38 TCollection_AsciiString fileNameInDataDir (const TCollection_AsciiString& theEnvironmentDir,
39 const TCollection_AsciiString& theName)
41 OSD_Environment anEnvironment (theEnvironmentDir);
43 TCollection_AsciiString aFileName = anEnvironment.Value();
44 aFileName += TCollection_AsciiString ("/") + theName;
49 // =======================================================================
50 // function : setPluginSampleDirectory
52 // =======================================================================
53 void setPluginSampleDirectory (const TCollection_AsciiString& theName, TInspector_Communicator* theCommunicator,
54 TInspector_OpenButton* theButtonControl)
56 QStringList aRecentlyOpenedFiles;
57 TInspector_OpenFileDialog::GetPluginRecentlyOpenedFiles (theName, theCommunicator, aRecentlyOpenedFiles);
58 TCollection_AsciiString aFileName, anAdditionalFileName;
59 if (!aRecentlyOpenedFiles.isEmpty())
60 aFileName = TCollection_AsciiString (aRecentlyOpenedFiles.last().toUtf8().data());
61 if (aFileName.IsEmpty())
63 if (theName.IsEqual ("TKDFBrowser"))
64 aFileName = fileNameInDataDir ("CSF_OCCTDataPath", "step/screw.step");
65 else if (theName.IsEqual ("TKShapeView"))
66 aFileName = fileNameInDataDir ("CSF_OCCTDataPath", "occ/hammer.brep");
67 else if (theName.IsEqual ("TKVInspector"))
69 aFileName = fileNameInDataDir ("CSF_OCCTDataPath", "occ/face1.brep");
70 anAdditionalFileName = fileNameInDataDir ("CSF_OCCTDataPath", "occ/face2.brep");
72 aRecentlyOpenedFiles.append (aFileName.ToCString());
73 if (!anAdditionalFileName.IsEmpty())
74 aRecentlyOpenedFiles.append (anAdditionalFileName.ToCString());
76 theCommunicator->OpenFile (theName, aFileName.ToCString());
77 if (!anAdditionalFileName.IsEmpty())
78 theCommunicator->OpenFile (theName, anAdditionalFileName);
80 theButtonControl->SetPluginRecentlyOpenedFiles (theName, aRecentlyOpenedFiles);
83 // =======================================================================
86 // =======================================================================
87 int main (int argc, char** argv)
89 #if QT_VERSION > 0x050000
90 TCollection_AsciiString aPlugindsDirName;
91 if (TInspector_Communicator::PluginsDir (aPlugindsDirName))
92 QApplication::addLibraryPath (aPlugindsDirName.ToCString());
94 QApplication anApp (argc, argv);
96 std::set<TCollection_AsciiString> aPlugins;
97 for (int anArgId = 1; anArgId < argc; anArgId++ )
99 if (!strcmp (argv[anArgId], "dfbrowser"))
100 aPlugins.insert ("TKDFBrowser");
102 if (!strcmp (argv[anArgId], "shapeview"))
103 aPlugins.insert ("TKShapeView");
105 if (!strcmp (argv[anArgId], "vinspector"))
106 aPlugins.insert ("TKVInspector");
108 NCollection_List<Handle(Standard_Transient)> aParameters;
110 // Create tool communicator
111 TInspector_Communicator* aCommunicator = TInspector_OpenFileDialog::Communicator();
114 std::cout << "Communicator can not be created" << std::endl;
118 TInspector_OpenButton* aButtonControl = new TInspector_OpenButton (0);
119 TCollection_AsciiString anActivatedPluginName;
120 if (aPlugins.empty())
122 aPlugins.insert("TKDFBrowser");
123 aPlugins.insert("TKShapeView");
124 aPlugins.insert("TKVInspector");
126 anActivatedPluginName = "TKDFBrowser";
129 anActivatedPluginName = *aPlugins.rbegin();
131 for (std::set<TCollection_AsciiString>::const_iterator aPluginIt = aPlugins.begin(); aPluginIt != aPlugins.end(); aPluginIt++)
133 TCollection_AsciiString aName = *aPluginIt;
134 aCommunicator->RegisterPlugin (aName);
135 aCommunicator->Init (aName, aParameters);
136 setPluginSampleDirectory (aName, aCommunicator, aButtonControl);
138 aCommunicator->Activate (anActivatedPluginName);
140 aCommunicator->SetVisible (true);
141 aCommunicator->SetOpenButton (aButtonControl->StartButton());