1 // Copyright (c) 2020 OPEN CASCADE SAS 2 // 3 // This file is part of the examples of the Open CASCADE Technology software library. 4 // 5 // Permission is hereby granted, free of charge, to any person obtaining a copy 6 // of this software and associated documentation files (the "Software"), to deal 7 // in the Software without restriction, including without limitation the rights 8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 // copies of the Software, and to permit persons to whom the Software is 10 // furnished to do so, subject to the following conditions: 11 // 12 // The above copyright notice and this permission notice shall be included in all 13 // copies or substantial portions of the Software. 14 // 15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE 21 22 #ifndef APPLICATION_COMMON_OVERVIEW_H 23 #define APPLICATION_COMMON_OVERVIEW_H 24 25 #include "BaseSample.h" 26 #include "CommonSample.h" 27 #include "DataExchangeSamples.h" 28 #include "DocumentCommon.h" 29 #include "GeometrySamples.h" 30 #include "GeomWidget.h" 31 #include "OcafSamples.h" 32 #include "OcctHighlighter.h" 33 #include "TopologySamples.h" 34 #include "TranslateDialog.h" 35 #include "TriangulationSamples.h" 36 #include "View.h" 37 #include "Viewer2dSamples.h" 38 #include "Viewer3dSamples.h" 39 40 #include <Standard_WarningsDisable.hxx> 41 #include <QApplication> 42 #include <QAction> 43 #include <QDomNode> 44 #include <QList> 45 #include <QMainWindow> 46 #include <QMdiArea> 47 #include <QMenu> 48 #include <QSignalMapper> 49 #include <QToolBar> 50 #include <QTextEdit> 51 #include <QWidget> 52 #include <Standard_WarningsRestore.hxx> 53 54 enum StdActions 55 { 56 StdActions_FileQuit, 57 StdActions_HelpAbout 58 }; 59 60 enum ApplicationType 61 { 62 AppType_Geometry, 63 AppType_Topology, 64 AppType_Triangulation, 65 AppType_DataExchange, 66 AppType_Ocaf, 67 AppType_Viewer2d, 68 AppType_Viewer3d, 69 AppType_Unknown 70 }; 71 72 73 //! Main application window 74 class ApplicationCommonWindow: public QMainWindow 75 { 76 Q_OBJECT 77 78 public: 79 ApplicationCommonWindow(ApplicationType theCategory); 80 GetApplicationType()81 ApplicationType GetApplicationType() const { return myAppType; } SetApplicationType(ApplicationType theApplicationType)82 void SetApplicationType(ApplicationType theApplicationType) { myAppType = theApplicationType; } 83 84 static TCollection_AsciiString getSampleSourceDir(); 85 86 protected: 87 virtual DocumentCommon* createNewDocument(); 88 89 public slots: 90 virtual void onAbout(); 91 virtual void onChangeCategory(const QString& theCategory); 92 93 protected: 94 QAction* CreateAction(const QString& theActionName, 95 const QString& theShortcut = "", 96 const QString& theIconName = ""); 97 98 template <typename PointerToMemberFunction> 99 QAction* CreateSample(PointerToMemberFunction theHandlerMethod, 100 const char* theActionName); 101 102 virtual void resizeEvent( QResizeEvent* ); getFilePopup()103 QMenu* getFilePopup() { return myFilePopup; } getCasCadeBar()104 QToolBar* getCasCadeBar() { return myCasCadeBar; } 105 106 void MenuFormXml (const QString& thePath, 107 QSignalMapper* theMapper, 108 QList<QMenu*>& theMunusList); 109 QMenu* MenuFromDomNode(QDomElement& theItemElement, 110 QWidget* theParent, 111 QSignalMapper* theMapper); 112 113 114 private slots: onCloseAllWindows()115 void onCloseAllWindows() { qApp->closeAllWindows(); } 116 117 void onProcessSample(const QString& theSampleName); 118 void onProcessExchange(const QString& theSampleName); 119 void onProcessOcaf(const QString& theSampleName); 120 void onProcessViewer3d(const QString& theSampleName); 121 void onProcessViewer2d(const QString& theSampleName); 122 123 private: 124 125 void RebuildMenu(); 126 Handle(BaseSample) GetCurrentSamples(); 127 const QList<QMenu*>& GetCurrentMenus(); 128 129 QString selectFileName(const QString& theSampleName, TranslateDialog* theDialog, int& theMode); 130 TranslateDialog* getDataExchangeDialog(const QString& theSampleName); 131 TranslateDialog* getOcafDialog(const QString& theSampleName); 132 133 private: 134 ApplicationType myAppType; 135 QMap<ApplicationType, QString> ALL_CATEGORIES; 136 137 Handle(GeometrySamples) myGeometrySamples; 138 Handle(TopologySamples) myTopologySamples; 139 Handle(TriangulationSamples) myTriangulationSamples; 140 Handle(DataExchangeSamples) myDataExchangeSamples; 141 Handle(OcafSamples) myOcafSamples; 142 Handle(Viewer3dSamples) myViewer3dSamples; 143 Handle(Viewer2dSamples) myViewer2dSamples; 144 145 QMap<StdActions, QAction*> myStdActions; 146 QMap<ApplicationType, QAction*> myCategoryActions; 147 QMap<Graphic3d_NameOfMaterial, QAction*> myMaterialActions; 148 149 QToolBar* myStdToolBar; 150 QToolBar* myViewBar; 151 QToolBar* myCasCadeBar; 152 QMenu* myFilePopup; 153 QMenu* myCategoryPopup; 154 155 QList<QMenu*> myGeometryMenus; 156 QList<QMenu*> myTopologyMenus; 157 QList<QMenu*> myTriangulationMenus; 158 QList<QMenu*> myDataExchangeMenus; 159 QList<QMenu*> myOcafMenus; 160 QList<QMenu*> myViewer3dMenus; 161 QList<QMenu*> myViewer2dMenus; 162 163 QSignalMapper* mySampleMapper; 164 QSignalMapper* myExchangeMapper; 165 QSignalMapper* myOcafMapper; 166 QSignalMapper* myViewer3dMapper; 167 QSignalMapper* myViewer2dMapper; 168 169 QSignalMapper* myCategoryMapper; 170 171 QTextEdit* myCodeView; 172 QTextEdit* myResultView; 173 OcctHighlighter* myCodeViewHighlighter; 174 175 GeomWidget* myGeomWidget; 176 177 DocumentCommon* myDocument3d; 178 DocumentCommon* myDocument2d; 179 }; 180 181 #endif 182