gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
gmshPopplerWrapper.h
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #ifndef GMSHPOPPLERWRAPPER_PDF_H
7 #define GMSHPOPPLERWRAPPER_PDF_H
8 
9 #include "GmshConfig.h"
10 #include "Context.h"
11 #include "OpenFile.h"
12 #include "GModel.h"
13 
14 #if defined(HAVE_POPPLER)
15 #include <string>
16 #include <map>
17 #include <poppler/cpp/poppler-document.h>
18 #include <poppler/cpp/poppler-page.h>
19 #include <poppler/cpp/poppler-image.h>
20 #if defined(HAVE_OPENGL)
21 #if defined(__APPLE__) || defined(HAVE_OPENGL_GL_H)
22 #include <OpenGL/gl.h>
23 #else
24 #include <GL/gl.h>
25 #endif
26 #endif
27 
28 class gmshPopplerWrapper {
29 private:
30  static int _currentPage;
31  static poppler::document *_currentDoc;
32  static gmshPopplerWrapper *_instance;
33  static std::map<int, std::pair<GModel *, std::string> > _macros;
34  static int _w, _h;
35 #if defined(HAVE_OPENGL)
36  static std::map<int, GLuint> _pages2textures; // map pages to textures
37 #endif
38 
39 public:
40  static gmshPopplerWrapper *instance();
41  static int loadFromFile(const std::string &file_name,
42  const std::string &owner_password = std::string(),
43  const std::string &user_password = std::string());
44  static int width() { return _w; }
45  static int height() { return _h; }
46  static int getNumPages();
47 
48  static void setMacroForPages(std::vector<int> &is, const std::string &s,
49  const std::string &o)
50  {
51  GModel *gm = GModel::current();
52  if(_macros.empty()) {
53  _macros[-1] = std::make_pair(gm, "NULL");
54  }
55  GModel *gmNew = new GModel(s);
56  GModel::setCurrent(gmNew);
57  MergeFile(s, true);
58  for(size_t i = 0; i < is.size(); i++)
59  _macros[is[i]] = std::make_pair(gmNew, o);
61  gmNew->setVisibility(0);
62  }
63 
64  static void setCurrentPage(int num)
65  {
66  _currentPage = num;
67  if(_currentPage >= getNumPages()) _currentPage = getNumPages() - 1;
68  if(_currentPage < 0) _currentPage = 0;
69  CTX::instance()->bgImagePage = _currentPage;
70  auto it = _macros.find(_currentPage);
71  if(it == _macros.end()) it = _macros.find(-1);
72  if(it != _macros.end()) {
73  if(GModel::current() != it->second.first) {
75  GModel::setCurrent(it->second.first);
76  if(it->second.second != "NULL") MergeFile(it->second.second, true);
77  it->second.first->setVisibility(1);
78  }
79  }
80  }
81  static int getCurrentPage() { return _currentPage; }
82  static void setCurrentPageUp()
83  {
84  ++_currentPage;
85  if(_currentPage >= getNumPages()) _currentPage = getNumPages() - 1;
86  CTX::instance()->bgImagePage = _currentPage;
87  }
88  static void setCurrentPageDown()
89  {
90  --_currentPage;
91  if(_currentPage < 0) _currentPage = 0;
92  CTX::instance()->bgImagePage = _currentPage;
93  }
94 #if defined(HAVE_OPENGL)
95  static GLuint getTextureForPage(double xres, double yres);
96 #endif
97 };
98 
99 #endif
100 #endif
GModel::setVisibility
void setVisibility(char val)
Definition: GModel.h:341
MergeFile
int MergeFile(const std::string &fileName, bool errorIfMissing, bool setBoundingBox, bool importPhysicalsInOnelab, int partitionToRead)
Definition: OpenFile.cpp:298
CTX::instance
static CTX * instance()
Definition: Context.cpp:122
GModel
Definition: GModel.h:44
GModel::setCurrent
static int setCurrent(GModel *m)
Definition: GModel.cpp:147
Context.h
GModel.h
OpenFile.h
GModel::current
static GModel * current(int index=-1)
Definition: GModel.cpp:136
CTX::bgImagePage
int bgImagePage
Definition: Context.h:262