gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
Plugin.cpp
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 #include <sstream>
7 #include <stdio.h>
8 #include <string.h>
9 #include "GmshConfig.h"
10 #include "Plugin.h"
11 #include "PViewData.h"
12 #include "PViewOptions.h"
13 #include "Context.h"
14 
15 #if defined(HAVE_OPENGL)
16 #include "drawContext.h"
17 #endif
18 
19 void (*GMSH_Plugin::draw)(void *) = nullptr;
20 
21 void GMSH_Plugin::setDrawFunction(void (*fct)(void *))
22 {
23 #if defined(HAVE_OPENGL)
24  draw = fct;
25  int old = CTX::instance()->drawBBox;
26  CTX::instance()->drawBBox = 1;
27  if(CTX::instance()->fastRedraw) {
28  CTX::instance()->post.draw = 0;
29  CTX::instance()->mesh.draw = 0;
30  }
32  CTX::instance()->drawBBox = old;
33  CTX::instance()->post.draw = 1;
34  CTX::instance()->mesh.draw = 1;
35 #endif
36 }
37 
38 void GMSH_Plugin::catchErrorMessage(char *errorMessage) const
39 {
40  std::string str = getName() + "failed...";
41  strcpy(errorMessage, str.c_str());
42 }
43 
45 {
46  std::ostringstream sstream;
47  for(int i = 0; i < getNbOptionsStr(); i++)
48  sstream << "Plugin(" << getName() << ")." << getOptionStr(i)->str << "= \""
49  << getOptionStr(i)->def << "\";\n";
50  for(int i = 0; i < getNbOptions(); i++)
51  sstream << "Plugin(" << getName() << ")." << getOption(i)->str << "="
52  << getOption(i)->def << ";\n";
53  sstream << "Plugin(" << getName() << ").Run;\n";
54  return sstream.str();
55 }
56 
58 {
59  int j = -1, remoteIndex = -1;
60  for(std::size_t i = 0; i < PView::list.size(); i++) {
61  if(PView::list[i]->getData()->isRemote()) j++;
62  if(PView::list[i]->getTag() == view->getTag()) {
63  remoteIndex = j;
64  break;
65  }
66  }
67  if(remoteIndex < 0) {
68  Msg::Error("Unable to determine index of remote view");
69  return view;
70  }
71 
72  for(int i = 0; i < getNbOptions(); i++)
73  if(std::string(getOption(i)->str) == "View")
74  getOption(i)->def = remoteIndex;
75 
76  std::string options = serialize();
77  view->getData()->fillRemoteVertexArrays(options);
78  return view;
79 }
80 
82 {
83  if(index < 0) index = view ? view->getIndex() : PView::list.size() - 1;
84 
85  if(index >= 0 && index < (int)PView::list.size()) {
86  return PView::list[index];
87  }
88  else {
89  Msg::Error("View[%d] does not exist", index);
90  return nullptr;
91  }
92 }
93 
95 {
96  if(!view) return nullptr;
97  PViewData *data = view->getData();
98  if(data->getAdaptiveData() && data->getNumTimeSteps() > 1)
100  "Using adapted data from view '%s': only the current time step (%d/%d) "
101  "is available to the plugin",
102  view->getData()->getName().c_str(), view->getOptions()->timeStep,
103  data->getNumTimeSteps());
104  return view->getData(true);
105 }
106 
108 {
109  if(!view) return nullptr;
110 
111  PViewDataList *data = dynamic_cast<PViewDataList *>(view->getData());
112  if(data)
113  return data;
114  else if(showError)
115  Msg::Error(
116  "This plugin can only be run on list-based views (`.pos' files)");
117  return nullptr;
118 }
PViewOptions::timeStep
int timeStep
Definition: PViewOptions.h:61
PView
Definition: PView.h:27
contextMeshOptions::draw
int draw
Definition: Context.h:82
Plugin.h
StringXNumber::def
double def
Definition: Options.h:922
PViewData::getNumTimeSteps
virtual int getNumTimeSteps()=0
PViewDataList
Definition: PViewDataList.h:17
GMSH_Plugin::draw
static void(* draw)(void *)
Definition: Plugin.h:77
Msg::Warning
static void Warning(const char *fmt,...)
Definition: GmshMessage.cpp:543
Msg::Error
static void Error(const char *fmt,...)
Definition: GmshMessage.cpp:482
CTX::post
struct CTX::@0 post
PView::getIndex
int getIndex()
Definition: PView.h:92
PViewData.h
drawContext::global
static drawContextGlobal * global()
Definition: drawContext.cpp:85
PViewData::getAdaptiveData
adaptiveData * getAdaptiveData()
Definition: PViewData.h:238
StringXNumber::str
const char * str
Definition: Options.h:920
drawContextGlobal::draw
virtual void draw(bool rateLimited=true)
Definition: drawContext.h:97
CTX::instance
static CTX * instance()
Definition: Context.cpp:122
GMSH_Plugin::serialize
std::string serialize()
Definition: Plugin.cpp:44
PView::getTag
int getTag()
Definition: PView.h:89
GMSH_Plugin::getNbOptions
virtual int getNbOptions() const
Definition: Plugin.h:61
CTX::draw
int draw
Definition: Context.h:316
GMSH_Plugin::getName
virtual std::string getName() const =0
PViewData::fillRemoteVertexArrays
virtual int fillRemoteVertexArrays(std::string &options)
Definition: PViewData.h:282
PView::getData
PViewData * getData(bool useAdaptiveIfAvailable=false)
Definition: PView.cpp:233
PViewOptions.h
CTX::mesh
contextMeshOptions mesh
Definition: Context.h:313
GMSH_PostPlugin::executeRemote
virtual PView * executeRemote(PView *)
Definition: Plugin.cpp:57
StringXString::def
std::string def
Definition: Options.h:914
GMSH_Plugin::getNbOptionsStr
virtual int getNbOptionsStr() const
Definition: Plugin.h:65
CTX::drawBBox
int drawBBox
Definition: Context.h:242
PViewData
Definition: PViewData.h:29
GMSH_Plugin::catchErrorMessage
virtual void catchErrorMessage(char *errorMessage) const
Definition: Plugin.cpp:38
Context.h
GMSH_Plugin::setDrawFunction
static void setDrawFunction(void(*fct)(void *))
Definition: Plugin.cpp:21
GMSH_PostPlugin::getView
virtual PView * getView(int index, PView *view)
Definition: Plugin.cpp:81
StringXString::str
const char * str
Definition: Options.h:912
GMSH_PostPlugin::getPossiblyAdaptiveData
virtual PViewData * getPossiblyAdaptiveData(PView *view)
Definition: Plugin.cpp:94
PView::getOptions
PViewOptions * getOptions()
Definition: PView.h:81
GMSH_Plugin::getOptionStr
virtual StringXString * getOptionStr(int iopt)
Definition: Plugin.h:66
PViewData::getName
virtual std::string getName()
Definition: PViewData.h:70
PView::list
static std::vector< PView * > list
Definition: PView.h:112
GMSH_Plugin::getOption
virtual StringXNumber * getOption(int iopt)
Definition: Plugin.h:62
GMSH_PostPlugin::getDataList
virtual PViewDataList * getDataList(PView *view, bool showError=true)
Definition: Plugin.cpp:107
drawContext.h