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 | #ifndef ShapeView_Window_H |
17 | #define ShapeView_Window_H |
18 | |
19 | #include <Standard.hxx> |
20 | #include <TCollection_AsciiString.hxx> |
0cb512c0 |
21 | #include <inspector/TInspectorAPI_PluginParameters.hxx> |
14bbbdcb |
22 | #include <TopoDS_Shape.hxx> |
23 | |
24 | #ifdef _MSC_VER |
25 | #pragma warning(disable : 4127) // conditional expression is constant |
26 | #endif |
27 | #include <QItemSelection> |
28 | #include <QList> |
29 | #include <QModelIndexList> |
30 | #include <QObject> |
31 | #include <QPoint> |
32 | #include <QString> |
33 | #include <QTreeView> |
34 | |
35 | class View_Displayer; |
36 | class View_Window; |
37 | |
38 | class QAction; |
39 | class QMainWindow; |
40 | class QWidget; |
41 | |
42 | //! \class ShapeView_Window |
43 | //! Window that unites all ShapeView controls. |
44 | class ShapeView_Window : public QObject |
45 | { |
46 | Q_OBJECT |
47 | public: |
48 | |
49 | //! Constructor |
50 | Standard_EXPORT ShapeView_Window (QWidget* theParent, const TCollection_AsciiString& theTemporaryDirectory); |
51 | |
52 | //! Destructor |
53 | Standard_EXPORT virtual ~ShapeView_Window(); |
54 | |
55 | //! Provides the container with a parent where this container should be inserted. |
56 | //! If Qt implementation, it should be QWidget with QLayout set inside |
57 | //! \param theParent a parent class |
58 | Standard_EXPORT void SetParent (void* theParent); |
59 | |
60 | //! Sets parameters container, it should be used when the plugin is initialized or in update content |
61 | //! \param theParameters a parameters container |
62 | void SetParameters (const Handle(TInspectorAPI_PluginParameters)& theParameters) { myParameters = theParameters; } |
63 | |
64 | //! Applyes parameters to Init controls, opens files if there are in parameters, updates OCAF tree view model |
65 | Standard_EXPORT void UpdateContent(); |
66 | |
67 | //! Returns main control |
68 | QMainWindow* GetMainWindow() const { return myMainWindow; } |
69 | |
70 | //! Returns current tree view |
71 | QTreeView* GetTreeView() const { return myTreeView; } |
72 | |
73 | //! Returns path to temporary directory |
74 | TCollection_AsciiString GetTemporaryDirectory() const { return myTemporaryDirectory; } |
75 | |
76 | //! Removes all shapes in tree view model, remove all stored BREP files |
77 | Standard_EXPORT void RemoveAllShapes(); |
78 | |
79 | protected: |
80 | //! Appends shape into tree view model |
81 | //! \param theShape a shape instance |
82 | Standard_EXPORT void addShape (const TopoDS_Shape& theShape); |
83 | |
84 | private: |
85 | |
86 | //! Fills controls of the plugin by parameters: |
87 | //! - Fine AIS_InteractiveObject and fills View if it if it differs from the current context |
88 | //! \param theParameters a parameters container |
89 | void Init (NCollection_List<Handle(Standard_Transient)>& theParameters); |
90 | |
91 | //! Read Shape from the file name, add Shape into tree view |
92 | //! \param theFileName BREP file name |
93 | void OpenFile (const TCollection_AsciiString& theFileName); |
94 | |
95 | protected slots: |
96 | |
97 | //! Displays shapes obtained by selected indices |
98 | //! \param theSelected a container of selected indices in tree view |
99 | //! \param theDeselected a container of deselected indices in tree view |
100 | void onTreeViewSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected) |
101 | { (void)theDeselected; displaySelectedShapes(theSelected.indexes()); } |
102 | |
103 | //! Shows context menu for tree view selected item. It contains expand/collapse actions. |
104 | //! \param thePosition a clicked point |
105 | void onTreeViewContextMenuRequested (const QPoint& thePosition); |
106 | |
107 | //! Exports shape to BREP file and view result file |
108 | void onBREPDirectory(); |
109 | |
110 | //! Removes all shapes in tree view |
111 | void onClearView() { RemoveAllShapes(); } |
112 | |
0cb512c0 |
113 | //! Load BREP file and updates tree model to have shape of the file |
114 | void onLoadFile(); |
115 | |
14bbbdcb |
116 | //! View BREP files of selected items if exist |
117 | void onBREPView(); |
118 | |
119 | //! Remove BREP views, close views |
120 | void onCloseAllBREPViews(); |
121 | |
122 | //! Remove all BREP Viewse excepting active |
123 | void onEditorDestroyed (QObject* theObject); |
124 | |
125 | //! Convers file name to Ascii String and perform opeging file |
126 | //! \param theFileName a file name to be opened |
127 | void onOpenFile(const QString& theFileName) { OpenFile (TCollection_AsciiString (theFileName.toUtf8().data())); } |
128 | |
129 | protected: |
130 | |
131 | //! Views file name content in a text editor. It creates new Qt free control with content. |
132 | //! \param theFileName a file name |
133 | void viewFile (const QString& theFileName); |
134 | |
135 | //! Removes all BREP files in tmp directory |
136 | void removeBREPFiles(); |
137 | |
138 | //! Creates new action and connect it to the given slot |
139 | //! \param theText an action text |
140 | //! \param theSlot a listener method |
141 | QAction* createAction (const QString& theText, const char* theSlot); |
142 | |
143 | //! Key that uses to generate BREP file name |
144 | //! \return string value |
145 | static TCollection_AsciiString viewBREPPrefix() { return "ShapeView_Window"; } |
146 | |
147 | //! Returns newxt temporary name using BREPPrefix and pointer information |
148 | //! \param thePointerInfo a pointer value |
149 | //! \return string value |
150 | TCollection_AsciiString getNextTmpName (const TCollection_AsciiString& thePointerInfo); |
151 | |
152 | //! Finds shapes for selected items in tree view and display presentations for the shapes |
153 | //! \param theSelected a list of selected indices in tree view |
154 | void displaySelectedShapes (const QModelIndexList& theSelected); |
155 | |
156 | private: |
157 | |
158 | QMainWindow* myMainWindow; //!< main control, parent for all ShapeView controls |
159 | View_Window* myViewWindow; //!< OCC 3d view to visualize presentations |
160 | QTreeView* myTreeView; //!< tree view visualized shapes |
161 | |
162 | TCollection_AsciiString myTemporaryDirectory; //!< path to the temporary directory |
163 | int myNextPosition; //!< delta of moving control of view BREP file |
164 | |
165 | QList<QWidget*> myBREPViews; //!< list of view BREP file controls |
166 | Handle(TInspectorAPI_PluginParameters) myParameters; //!< plugins parameters container |
167 | }; |
168 | |
169 | #endif |