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 #ifndef TInspector_Window_H
17 #define TInspector_Window_H
19 #include <NCollection_List.hxx>
20 #include <Standard.hxx>
21 #include <Standard_Transient.hxx>
22 #include <TCollection_AsciiString.hxx>
23 #include <inspector/TInspectorAPI_PluginParameters.hxx>
25 #include <Standard_WarningsDisable.hxx>
29 #include <Standard_WarningsRestore.hxx>
31 class TInspectorAPI_Communicator;
32 class TInspector_Shortcut;
41 //! \class Inspector_Window
42 //! Control that contains:
43 //! - stacked widget of loaded plugins
44 //! - Open button to open file in an active plugin
45 //! - plugin parameters container
46 class TInspector_Window : public QObject
51 //! Container of plugin information
52 struct TInspector_ToolInfo
56 TInspector_ToolInfo (const TCollection_AsciiString& theName = TCollection_AsciiString())
57 : myName(theName), myCommunicator (0), myButton (0), myWidget (0) {}
59 TCollection_AsciiString myName; //!< plugin name
60 TInspectorAPI_Communicator* myCommunicator; //!< plugin communicator
61 QPushButton* myButton; //!< button with plugin name, that will be added into TInspector window layout
62 QWidget* myWidget; //!< parent widget of the plugin
68 Standard_EXPORT TInspector_Window();
71 virtual ~TInspector_Window() Standard_OVERRIDE {}
73 //! Appends the plugin names into internal conainer
74 //! \param thePluginName a name of the plugin
75 Standard_EXPORT void RegisterPlugin (const TCollection_AsciiString& thePluginName);
77 //! Returns list of registered plugins
78 //! \return container of plugin names
79 Standard_EXPORT NCollection_List<TCollection_AsciiString> RegisteredPlugins() const;
81 //! Stores parameters for the plugin. If the plugin name is empty, it inits all plugins with the parameters
82 //! \param thePluginName a name of the plugin
83 //! \param theParameters container of parameters(e.g. AIS_InteractiveContext, TDocStd_Application)
84 //! \param theAppend boolean state whethe the parameters should be added to existing
85 Standard_EXPORT void Init (const TCollection_AsciiString& thePluginName,
86 const NCollection_List<Handle(Standard_Transient)>& theParameters,
87 const Standard_Boolean theAppend = Standard_False);
89 //! Appends to container of parameters the given name, if the given parameter is active, cal UpdateContent
90 //! \param thePluginName a name of the plugin
91 //! \param theParameters container of parameters(e.g. AIS_InteractiveContext, TDocStd_Application)
92 Standard_EXPORT void OpenFile (const TCollection_AsciiString& thePluginName,
93 const TCollection_AsciiString& theFileName);
95 //! Calls UpdateContent for the active plugin
96 Standard_EXPORT void UpdateContent();
98 //! Returns the main TInspector window
99 QMainWindow* GetMainWindow() const { return myMainWindow; }
101 //! Activates the plugin. Loads the plugin if it has not been loaded yet
102 //! \param thePluginName a name of the plugin
103 Standard_EXPORT void ActivateTool (const TCollection_AsciiString& thePluginName);
105 //! Set item selected in the active plugin
106 //! \param theItemNames a container of name of items in plugin that should become selected
107 Standard_EXPORT void SetSelected (const NCollection_List<TCollection_AsciiString>& theItemNames);
109 //! Sets objects to be selected in the plugin
110 //! \param theObjects an objects
111 Standard_EXPORT void SetSelected (const NCollection_List<Handle(Standard_Transient)>& theObjects);
113 //! Sets open button. Stores into objectName for the button the name of the current plugin to know where
114 //! the file should be applied
115 //! \param theButton a button
116 Standard_EXPORT void SetOpenButton (QPushButton* theButton);
118 //! Loads plugin, appends the plugin widget into layout, stores the plugin information
119 //! \param thePluginName a name of the plugin
120 //! \param theInfo an output parameter for plugin info
121 Standard_EXPORT bool LoadPlugin (const TCollection_AsciiString& thePluginName, TInspector_ToolInfo& theInfo);
123 //! Sets path to a directory for temporary plugin files. If parameter is empty, using default directory
124 //! \param thePath a path
125 void SetTemporaryDirectory (const TCollection_AsciiString& thePath)
126 { myParameters->SetTemporaryDirectory (thePath.IsEmpty() ? myDefaultDirectory : thePath); }
128 //! Returns path to a directory for temporary plugin files
130 TCollection_AsciiString GetTemporaryDirectory() const { return myParameters->GetTemporaryDirectory(); }
132 //! Returns plugin preferences: dock widgets state, tree view columns.
133 //! \param theItem container of preference elements
134 Standard_EXPORT void GetPreferences (TInspectorAPI_PreferencesDataMap& theItem);
136 //! Applies plugin preferences
137 //! \param theItem container of preference elements
138 Standard_EXPORT void SetPreferences (const TInspectorAPI_PreferencesDataMap& theItem);
140 //! Puts in the stream information about communicator
141 //! \param theStream stream for output
142 Standard_EXPORT void Dump (Standard_OStream& theStream) const;
145 //! Stores preferences (current state) of all plugins into a preferences file
146 Standard_EXPORT void OnStorePreferences();
148 //! Remove preferences file
149 Standard_EXPORT void OnRemovePreferences();
153 //! Activates plugin correspnded to the clicked button
154 void onButtonClicked();
156 //! Updates available actions by the active plugin
157 void onShowActionsMenu();
159 //! Updates the TInspector window title giving object name of plugin widget (available only in Qt5)
160 void onCommuncatorNameChanged();
164 //! Activates plugin by the plugin info
165 //! \param theToolInfo an information about plugin
166 bool activeToolInfo (TInspector_ToolInfo& theToolInfo) const;
168 //! Returns true if there is plugin registered by the given name
169 //! \param thePluginName a name of the plugin
170 //! \param theToolInfo an output parameter for plugin information
171 //! \param theToolId an index in internal map
172 //! \return true if the plugin is found
173 bool findPlugin (const TCollection_AsciiString& thePluginName, TInspector_ToolInfo& theToolInfo,
176 //! Applies desktop preferences to window
177 void applyPreferences();
179 //! Generate default temp directory by 'TEMP' or 'TMP' environment variables
180 //! \return generated path
181 TCollection_AsciiString defaultTemporaryDirectory() const;
185 QWidget* myEmptyWidget; //!< widget that is active in tools stack while no one plugin is loaded
186 QMainWindow* myMainWindow; //!< main control of the window
187 QStackedWidget* myToolsStack; //!< stack widget of plugin windows
188 QWidget* myButtonWidget; //!< container of plugin buttons
189 QPushButton* myOpenButton; //!< button to open file for the active plugin
190 QHBoxLayout* myButtonLay; //!< layout of plugin buttons
191 QButtonGroup* myButtonGroup; //!< exclusive toggled button
192 QToolButton* myActionsWidget; //!< tool button for plugin actions
193 QList<TInspector_ToolInfo> myToolNames; //!< container of plugin names
194 Handle(TInspectorAPI_PluginParameters) myParameters; //!< plugins parameters container
195 TInspector_Shortcut* myShortcut; //!< listener of key events
196 TCollection_AsciiString myDefaultDirectory; //!< default directory