1 #ifndef __MODELVIEWERWIDGET_H__ 2 #define __MODELVIEWERWIDGET_H__ 3 4 #include <QtGlobal> 5 #if QT_VERSION >= QT_VERSION_CHECK(6,0,0) 6 #include <QtOpenGL> 7 #include <QWidget> 8 #else 9 #include <qgl.h> 10 #endif 11 #include <QDateTime> 12 #if QT_VERSION >= QT_VERSION_CHECK(4,7,0) 13 #include <QElapsedTimer> 14 #endif 15 #include <TCFoundation/TCObject.h> 16 #include <TCFoundation/TCAlertManager.h> 17 18 #include "Preferences.h" 19 #include "LDViewExtraDir.h" 20 #include "LDViewSnapshotSettings.h" 21 #include "LDViewJpegOptions.h" 22 #include "LDViewPartList.h" 23 #include <LDLib/LDLibraryUpdater.h> 24 #include <LDLib/LDInputHandler.h> 25 #include <LDLib/LDSnapshotTaker.h> 26 #include "LDViewBoundingBox.h" 27 #include "LDViewCameraLocation.h" 28 #include "LDViewRotationCenter.h" 29 #include "LDViewMpdModel.h" 30 #include "LDViewLatitudeLongitude.h" 31 #include "LDViewModelTree.h" 32 #include "About.h" 33 #include "Help.h" 34 #include "OpenGLExtensions.h" 35 #include <QFileDialog> 36 #if (QT_VERSION >= 0x50400) && defined(QOPENGLWIDGET) 37 #include <QOpenGLWidget> 38 #include <QOpenGLFunctions> 39 #endif 40 #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) 41 #include <QOpenGLFramebufferObject> 42 #endif 43 44 class LDrawModelViewer; 45 class LDViewMainWindow; 46 class QProgressBar; 47 class QApplication; 48 class LDViewErrors; 49 class QMenuBar; 50 class QPopupMenu; 51 class TCStringArray; 52 class LDLError; 53 class TCProgressAlert; 54 class QTextBrowser; 55 class AlertHandler; 56 class QProgressDialog; 57 class LDHtmlInventory; 58 class JpegOptions; 59 60 #define MAX_MOUSE_BUTTONS 10 61 62 #define LIBRARY_UPDATE_FINISHED 1 63 #define LIBRARY_UPDATE_CANCELED 2 64 #define LIBRARY_UPDATE_NONE 3 65 #define LIBRARY_UPDATE_ERROR 4 66 67 #if (QT_VERSION >= 0x50400) && defined(QOPENGLWIDGET) 68 class ModelViewerWidget : public QOpenGLWidget 69 #else 70 class ModelViewerWidget : public QGLWidget 71 #endif 72 { 73 Q_OBJECT 74 public: 75 ModelViewerWidget(QWidget *parent=NULL); 76 ~ModelViewerWidget(void); 77 void loadModel(const char *filename); 78 void finishLoadModel(void); 79 void showPreferences(void); getModelViewer(void)80 LDrawModelViewer *getModelViewer(void) { return modelViewer; } 81 void setMainWindow(LDViewMainWindow *value); 82 83 void ldlErrorCallback(LDLError *error); 84 void progressAlertCallback(TCProgressAlert *alert); 85 void modelViewerAlertCallback(TCAlert *alert); 86 void redrawAlertCallback(TCAlert *alert); 87 void captureAlertCallback(TCAlert *alert); 88 void releaseAlertCallback(TCAlert *alert); 89 void lightVectorChangedAlertCallback(TCAlert *alert); 90 void snapshotTakerAlertCallback(TCAlert *alert); 91 setShowFPS(bool value)92 void setShowFPS(bool value) { showFPS = value; } 93 void setApplication(QApplication *value); 94 void createAboutPanel(void); 95 96 void doFileOpen(void); 97 void doFileReload(void); 98 void doFileLDrawDir(void); 99 void showFileExtraDir(void); 100 void doFileCancelLoad(void); 101 void doViewFullScreen(void); 102 void doViewReset(void); 103 void doViewStatusBar(bool flag); 104 void doViewToolBar(bool flag); 105 void doViewErrors(void); 106 void doPartList(LDHtmlInventory *htmlInventory, 107 LDPartsList *partsList, const char *filename); 108 void doPartList(); 109 void doModelTree(); 110 void doBoundingBox(); 111 void doMpdModel(); 112 void doHelpOpenGLDriverInfo(void); 113 void doHelpContents(void); 114 void doHelpAbout(void); 115 void doHelpAboutQt(void); 116 void doApply(void); 117 void doPollChanged(LDVPollMode); 118 void doViewModeChanged(LDInputHandler::ViewMode newMode); 119 void doZoomToFit(void); 120 void doRightSideUp(void); 121 void doCameraLocation(void); 122 void doRotationCenter(void); 123 void doFilePrint(void); 124 bool doFileSave(void); 125 void doFileSaveSettings(void); 126 void fileExport(void); 127 void fileExportOption(void); 128 void file3DSExportOption(void); 129 void doFileJPEGOptions(void); 130 bool fileExists(const char* filename); 131 bool shouldOverwriteFile(char* filename); 132 bool doFileSave(char *saveFilename); 133 bool getSaveFilename(char* saveFilename, int len); 134 static bool staticImageProgressCallback(const wchar_t* message, 135 float progress, void* userData); 136 bool writeImage(char *filename, int width, int height, TCByte *buffer, 137 const char *formatName, bool saveAlpha = false); 138 bool saveImage(char *filename, int imageWidth, int imageHeight, 139 bool fromCommandLine = false); 140 bool writePng(char *filename, int width, int height, TCByte *buffer, 141 bool saveAlpha); 142 bool writeBmp(char *filename, int width, int height, TCByte *buffer); 143 TCByte *grabImage(int &imageWidth, int &imageHeight, TCByte *buffer, 144 bool zoomToFit = true, bool *saveAlpha = NULL); 145 int roundUp(int value, int nearest); 146 147 void switchExamineLatLong(bool b); 148 void keepRightSideUp(bool b); 149 void doFrontViewAngle(void); 150 void doBackViewAngle(void); 151 void doLeftViewAngle(void); 152 void doRightViewAngle(void); 153 void doTopViewAngle(void); 154 void doBottomViewAngle(void); 155 void doLatLongViewAngle(void); 156 void doIsoViewAngle(void); 157 void doSaveDefaultViewAngle(void); 158 void doShowViewInfo(void); 159 void cleanupFloats(TCFloat *array, int count = 16); 160 void doShowPovCamera(void); 161 void doShowPovAspectRatio(bool); 162 QSize minimumSize(void); 163 void doWireframe(bool); 164 void doWireframeFog(bool); 165 void doWireframeRemoveHiddenLines(bool); 166 void doTextureStud(bool); 167 void doShowEdgeOnly(bool); 168 void doConditionalLine(bool); 169 void doHighQuality(bool); 170 void doAlwaysBlack(bool); 171 void doRedBackFaces(bool); 172 void doGreenFrontFaces(bool); 173 void doBlueNeutralFaces(bool); 174 void doEdge(bool); 175 void doLighting(bool); 176 void doBFC(bool); 177 void doAxes(bool); 178 void doPrimitiveSubstitution(bool); 179 void doSeams(bool); 180 void reflectSettings(void); 181 int mwidth, mheight; 182 void calcTiling(int desiredWidth, int desiredHeight, 183 int &bitmapWidth, int &bitmapHeight, 184 int &numXTiles, int &numYTiles); 185 void setupSnapshotBackBuffer(int imageWidth, int imageHeight); 186 void renderOffscreenImage(void); 187 bool canSaveAlpha(void); 188 bool saveAlpha; 189 bool installLDraw(); 190 void createLibraryUpdateWindow(void); 191 void showLibraryUpdateWindow(bool initialInstall); 192 void doLibraryUpdateFinished(int finishType); 193 void checkForLibraryUpdates(void); 194 void userDefaultChangedAlertCallback(TCAlert *alert); 195 static QString findPackageFile(const QString &filename); 196 void doRecentFile(int index); 197 void nextStep(); 198 void prevStep(); 199 void firstStep(); 200 void lastStep(); 201 void updateStep(); 202 void gotoStep(); 203 LDViewModelTree *modeltree; 204 CameraLocation *cameralocation; 205 RotationCenter *rotationcenter; 206 BoundingBox *boundingbox; 207 MpdModel *mpdmodel; isLoading()208 bool isLoading() { return loading;} getViewMode()209 LDInputHandler::ViewMode getViewMode() { return viewMode;} 210 static bool staticFileCaseCallback(char *filename); 211 212 protected slots: 213 virtual void doAboutOK(void); 214 virtual void doLibraryUpdateCanceled(void); 215 virtual void doPreferences(void); 216 217 protected: 218 // GL Widget overrides 219 void initializeGL(void); 220 void resizeGL(int width, int height); 221 void swap_Buffers(void); 222 void paintGL(void); 223 224 //void updateSpinRateXY(int xPos, int yPos); 225 //void updatePanXY(int xPos, int yPos); 226 //void updateHeadXY(int xPos, int yPos); 227 //void updateZoom(int yPos); 228 //void spinButtonPress(QMouseEvent *event); 229 //void spinButtonRelease(QMouseEvent *event); 230 //void zoomButtonPress(QMouseEvent *event); 231 //void zoomButtonRelease(QMouseEvent *event); 232 //void updateSpinRate(void); 233 234 // Events 235 void mousePressEvent(QMouseEvent *event); 236 void mouseReleaseEvent(QMouseEvent *event); 237 void wheelEvent(QWheelEvent *event); 238 void mouseMoveEvent(QMouseEvent *event); 239 void timerEvent(QTimerEvent *event); 240 void paintEvent(QPaintEvent *event); 241 void keyPressEvent(QKeyEvent *event); 242 void keyReleaseEvent(QKeyEvent *event); 243 244 int progressCallback(const QString &message, float progress, 245 bool showErrors); 246 void setupProgress(void); 247 void endLoad(void); 248 void updateFPS(void); 249 void drawFPS(void); 250 void updateLatlong(void); 251 void startPaintTimer(void); 252 void killPaintTimer(void); 253 void startPollTimer(bool immediate=false); 254 void killPollTimer(void); 255 void startLoadTimer(void); 256 void killLoadTimer(void); 257 bool verifyLDrawDir(bool forceChoose = false); 258 bool verifyLDrawDir(char *value); 259 char *getLDrawDir(void); 260 bool promptForLDrawDir(QString prompt = QString ("")); 261 int errorCallback(LDLError *error); 262 void clearErrors(void); 263 void preLoad(void); 264 void postLoad(void); 265 void showErrorsIfNeeded(bool onlyIfNeeded); 266 void setLastOpenFile(const char *filename); 267 bool chDirFromFilename(const char *filename); 268 void checkFileForUpdates(void); 269 void getFileTime(const char *filename, QDateTime &value); 270 void getFileInfo(const char *filename, QDateTime &value, qint64 &size); 271 void lock(void); 272 void unlock(void); 273 void windowActivationChange(bool oldActive); 274 //void processKey(QKeyEvent *event, bool press); 275 void setViewMode(LDInputHandler::ViewMode value, bool examineLatLong, 276 bool keepRightSideUp, bool saveSettings=true); 277 void setMenuItemsEnabled(QPopupMenu *menu, bool enabled); 278 void libraryUpdateProgress(TCProgressAlert *alert); 279 void setLibraryUpdateProgress(float progress); 280 void setupUserAgent(void); 281 virtual bool calcSaveFilename(char* saveFilename, int len); 282 bool grabImage(int &imageWidth, int &imageHeight, 283 bool fromCommandLine = false); 284 LDSnapshotTaker::ImageType getSaveImageType(void); 285 286 // static int staticProgressCallback(char *message, float progress, 287 // void *userData); 288 // static int staticErrorCallback(LDLError *error, void *userData); 289 static bool staticFileCaseLevel(QDir &dir, char *filename); 290 static TCULong convertKeyModifiers(Qt::KeyboardModifiers osModifiers); 291 static LDInputHandler::KeyCode convertKeyCode(int osKey); 292 static LDInputHandler::MouseButton convertMouseButton(int button); 293 294 LDrawModelViewer *modelViewer; 295 LDInputHandler *inputHandler; 296 LDSnapshotTaker *snapshotTaker; 297 bool mouseButtonsDown[MAX_MOUSE_BUTTONS]; 298 int lastX; 299 int lastY; 300 int originalZoomY; 301 TCFloat rotationSpeed; 302 LDInputHandler::ViewMode viewMode; 303 bool examineLatLong; 304 bool keepRightSide; 305 int spinButton; 306 int zoomButton; 307 QTime lastMoveTime; 308 #if QT_VERSION >= QT_VERSION_CHECK(4,7,0) 309 QElapsedTimer lastProgressTime; 310 QElapsedTimer referenceFrameTime; 311 #else 312 QTime lastProgressTime; 313 QTime referenceFrameTime; 314 #endif 315 #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) 316 QOpenGLFramebufferObject *fbo; isFboActive()317 bool isFboActive() { return fbo != NULL; } 318 #else isFboActive()319 bool isFboActive() { return false; } 320 #endif 321 Preferences *preferences; 322 ExtraDir *extradir; 323 SnapshotSettings *snapshotsettings; 324 JpegOptions *jpegoptions; 325 OpenGLExtensions *extensionsPanel; 326 QString openGLDriverInfo; 327 LatitudeLongitude *latitudelongitude; 328 About *aboutPanel; 329 Help *helpContents; 330 LDViewMainWindow *mainWindow; 331 QStatusBar *statusBar; 332 QProgressBar *progressBar; 333 QLabel *progressLabel, *progressLatlong, *progressMode; 334 bool loading,saving,printing; 335 bool cancelLoad; 336 QApplication *app; 337 bool painting; 338 float fps; 339 int numFramesSinceReference; 340 int paintTimer; 341 int pollTimer; 342 int loadTimer; 343 int libraryUpdateTimer; 344 QFileDialog *saveDialog; 345 bool showFPS; 346 LDViewErrors *errors; 347 QDateTime lastWriteTime; 348 qint64 lastFileSize; 349 QFileInfo *fileInfo; 350 int lockCount; 351 bool saveActualSize; 352 int saveWidth; 353 int saveHeight; 354 bool saveZoomToFit; 355 bool saveSeries; 356 int saveDigits; 357 int saveImageType; 358 int exportType; 359 int fullscreen; 360 AlertHandler *alertHandler; 361 #if !defined(_NO_BOOST) || defined(USE_CPP11) 362 LDLibraryUpdater *libraryUpdater; 363 #endif 364 bool libraryUpdateFinished; 365 bool libraryUpdateCanceled; 366 bool libraryUpdateFinishNotified; 367 QString libraryUpdateProgressMessage; 368 float libraryUpdateProgressValue; 369 bool libraryUpdateProgressReady; 370 int libraryUpdateFinishCode; 371 QProgressDialog *libraryUpdateWindow; 372 bool redrawRequested; 373 int saveImageWidth; 374 int saveImageHeight; 375 const char *saveImageFilename; 376 bool saveImageZoomToFit; 377 bool saveImageResult; 378 379 int lightingSelection; 380 LDPreferences::SaveOp curSaveOp; 381 bool commandLineSnapshotSave; 382 }; 383 384 #endif // __MODELVIEWERWIDGET_H__ 385