ExcelRTC  0.5.0
 全て クラス ファイル 関数 変数
ExcelControl.h
説明を見る。
1 // -*-C++-*-
6 #ifndef EXCELCONTROL_H
7 #define EXCELCONTROL_H
8 
9 #include <rtm/Manager.h>
10 #include <rtm/DataFlowComponentBase.h>
11 #include <rtm/CorbaPort.h>
12 #include <rtm/DataInPort.h>
13 #include <rtm/DataOutPort.h>
14 #include <rtm/idl/BasicDataTypeSkel.h>
15 #include <rtm/idl/ExtendedDataTypesSkel.h>
16 #include <rtm/idl/InterfaceDataTypesSkel.h>
17 
18 #include <vector>
19 #include <string>
20 #include <sstream>
21 
22 #include <rtm/CorbaNaming.h>
23 #include <rtm/RTObject.h>
24 #include <rtm/CorbaConsumer.h>
25 
26 #include "SubFunction.h"
27 #ifdef CREATE_EXE_EXCELRTC
28  #include "Form1.h"
29 #else
30  #include "ExcelObject.h"
31 #endif
32 
33 
34 using namespace RTC;
35 
36 #include "SpreadSheetSVC_impl.h"
37 #include "ExcelTask.h"
38 #include "ExcelDataPort.h"
39 
40 
41 class ExcelTask;
42 class ExcelControl;
43 class ExcelPortBase;
44 class OtherPort;
45 
46 
47 
48 
49 
50 void ListRecursive(CosNaming::NamingContext_ptr context,std::vector<OtherPort> &rtclist,std::string &name, TreeObject *to);
51 
52 int rtc_get_rtclist(RTC::CorbaNaming &naming,std::vector<OtherPort> &rtclist, TreeObject *to, std::string IP_adress);
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
68 void portConnect(PortService_ptr p1, PortService_var p2);
69 
70 
71 
77  : public RTC::DataFlowComponentBase
78 {
79  public:
80 
85  ExcelControl(RTC::Manager* manager);
86 
90  ~ExcelControl();
91 
92 
97  virtual RTC::ReturnCode_t onInitialize();
98 
99 
105  virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id);
106 
107 
113  virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id);
114 
119  virtual RTC::ReturnCode_t onFinalize();
120 
121 
132  ExcelPortBase* createPort(OtherPort &op, int c, std::string l, std::string sn, std::string leng, bool mstate);
133 
138  void deleteOtherPort(OtherPort &op);
142  void deleteAllPort();
143 
147  void save();
148 
152  void load();
153 
158  void resetPort(ExcelPortBase* mpb);
159 
163  void resetAllPort();
164 
168  void configUpdate();
169 
173  void update_cellName();
174 
175 
176 
181  void updateAPort(ExcelPortBase* ip);
182 
183 
189  template <typename T>
190  void setCellData(std::vector<std::vector<T>> dt, ExcelPortBase *pb)
191  {
192 
193  ExcelObject::Obj->setCellValue<T>(pb->col+pb->num, pb->low, pb->sheetName, pb->state, dt);
194 
195  }
196 
202  template <typename T>
203  std::vector<T> getCellData(ExcelPortBase *pb)
204  {
205  std::vector<T> td = ExcelObject::Obj->getCellValue<T>(pb->col+pb->num, pb->low, pb->sheetName, pb->length);
206 
207  return td;
208  }
209 
221  template <typename T, typename T2> ExcelPortBase* crPortSeq(OtherPort &op, std::string tdt, int c, std::string l, std::string sn, std::string leng, bool mstate)
222  {
223  string PortType = NVUtil::toString(op.pb->get_port_profile()->properties,"port.port_type");
224 
225  string tname = op.buff[op.buff.size()-2];
226  tname += op.buff[op.buff.size()-1];
227 
228  if(PortType == "DataInPort")
229  {
230  T *m_out = new T();
231  OutPort<T> *m_outOut = new OutPort<T>(tname.c_str(),*m_out);
232  addOutPort(tname.c_str(), *m_outOut);
233 
234  ExcelPortBase *mip;
235 
236  mip= new ExcelOutPortSeq<T,T2>(m_out,m_outOut,tname,tdt,this);
237  mip->mop = &op;
238 
239  mip->setParam(c,l,sn,leng,mstate);
240  OutPorts.push_back(mip);
241 
242  portConnect(m_outOut->getPortRef(), op.pb);
243 
244  op.mpb = mip;
245 
246  return mip;
247 
248  }
249  else if(PortType == "DataOutPort")
250  {
251  T *m_in = new T();
252  InPort<T> *m_inIn = new InPort<T>(tname.c_str(),*m_in);
253 
254  addInPort(tname.c_str(), *m_inIn);
255 
256  ExcelPortBase *mip = new ExcelInPortSeq<T,T2>(m_in,m_inIn,tname,tdt,this);
257  mip->mop = &op;
258 
259 
260  mip->setParam(c,l,sn,leng,mstate);
261  InPorts.push_back(mip);
262 
263  portConnect(m_inIn->getPortRef(), op.pb);
264 
265  op.mpb = mip;
266 
267  return mip;
268  }
269  return NULL;
270  }
271 
283  template <typename T, typename T2> ExcelPortBase* crPort(OtherPort &op, std::string tdt, int c, std::string l, std::string sn, std::string leng, bool mstate)
284  {
285  string PortType = NVUtil::toString(op.pb->get_port_profile()->properties,"port.port_type");
286 
287  string tname = op.buff[op.buff.size()-2];
288  tname += op.buff[op.buff.size()-1];
289 
290  if(PortType == "DataInPort")
291  {
292  T *m_out = new T();
293  OutPort<T> *m_outOut = new OutPort<T>(tname.c_str(),*m_out);
294  addOutPort(tname.c_str(), *m_outOut);
295 
296  ExcelPortBase *mip;
297 
298  mip= new ExcelOutPort<T,T2>(m_out,m_outOut,tname,tdt,this);
299  mip->mop = &op;
300 
301  mip->setParam(c,l,sn,leng,mstate);
302  OutPorts.push_back(mip);
303 
304  portConnect(m_outOut->getPortRef(), op.pb);
305 
306  op.mpb = mip;
307 
308  return mip;
309 
310  }
311  else if(PortType == "DataOutPort")
312  {
313  T *m_in = new T();
314  InPort<T> *m_inIn = new InPort<T>(tname.c_str(),*m_in);
315 
316 
317  addInPort(tname.c_str(), *m_inIn);
318 
319  ExcelPortBase *mip = new ExcelInPort<T,T2>(m_in,m_inIn,tname,tdt,this);
320  mip->mop = &op;
321 
322 
323  mip->setParam(c,l,sn,leng,mstate);
324  InPorts.push_back(mip);
325 
326  portConnect(m_inIn->getPortRef(), op.pb);
327 
328  op.mpb = mip;
329 
330  return mip;
331  }
332  return NULL;
333  }
334 
347  template <typename T, typename T2> ExcelPortBase* confcrPortSeq(std::string tname, std::string PortType, std::string tdt, int c, std::string l, std::string sn, std::string leng, bool mstate)
348  {
349 
350 
351  if(PortType == "DataOutPort")
352  {
353  T *m_out = new T();
354  OutPort<T> *m_outOut = new OutPort<T>(tname.c_str(),*m_out);
355  addOutPort(tname.c_str(), *m_outOut);
356 
357  ExcelPortBase *mip;
358 
359  mip= new ExcelOutPortSeq<T,T2>(m_out,m_outOut,tname,tdt,this);
360 
361  mip->setParam(c,l,sn,leng,mstate);
362  ConfOutPorts.push_back(mip);
363 
364 
365 
366 
367  return mip;
368 
369  }
370  else if(PortType == "DataInPort")
371  {
372  T *m_in = new T();
373  InPort<T> *m_inIn = new InPort<T>(tname.c_str(),*m_in);
374 
375  addInPort(tname.c_str(), *m_inIn);
376 
377  ExcelPortBase *mip = new ExcelInPortSeq<T,T2>(m_in,m_inIn,tname,tdt,this);
378 
379 
380 
381  mip->setParam(c,l,sn,leng,mstate);
382  ConfInPorts.push_back(mip);
383 
384 
385 
386 
387  return mip;
388  }
389  return NULL;
390  }
391 
404  template <typename T, typename T2> ExcelPortBase* confcrPort(std::string tname, std::string PortType, std::string tdt, int c, std::string l, std::string sn, std::string leng, bool mstate)
405  {
406 
407 
408  if(PortType == "DataOutPort")
409  {
410  T *m_out = new T();
411  OutPort<T> *m_outOut = new OutPort<T>(tname.c_str(),*m_out);
412  addOutPort(tname.c_str(), *m_outOut);
413 
414  ExcelPortBase *mip;
415 
416  mip= new ExcelOutPort<T,T2>(m_out,m_outOut,tname,tdt,this);
417 
418  mip->setParam(c,l,sn,leng,mstate);
419  ConfOutPorts.push_back(mip);
420 
421 
422 
423 
424  return mip;
425 
426  }
427  else if(PortType == "DataInPort")
428  {
429  T *m_in = new T();
430  InPort<T> *m_inIn = new InPort<T>(tname.c_str(),*m_in);
431 
432 
433  addInPort(tname.c_str(), *m_inIn);
434 
435  ExcelPortBase *mip = new ExcelInPort<T,T2>(m_in,m_inIn,tname,tdt,this);
436 
437 
438 
439  mip->setParam(c,l,sn,leng,mstate);
440  ConfInPorts.push_back(mip);
441 
442 
443 
444 
445  return mip;
446  }
447  return NULL;
448  }
449 
450 
451 
452 
453 
454 
455 
467  ExcelPortBase* setDPort(std::vector<std::string> pt, int c, std::string l, std::string sn, std::string leng, bool mstate, bool msflag);
468 
473  void delDPort(std::vector<std::string> pt);
474 
480  ExcelPortBase* getDPort(std::vector<std::string> pt);
481 
482 
488  void attachPort(ExcelPortBase *mpb, std::string n);
489 
495  void detachPort(ExcelPortBase *mpb, std::string n);
496 
502  ExcelPortBase *getInPort(std::string n);
503 
509  ExcelPortBase *getOutPort(std::string n);
510 
516  ExcelPortBase *getConfOutPort(std::string n);
522  ExcelPortBase *getConfInPort(std::string n);
523 
524 
530  TreeObject* getRTCTree(std::string IP_adress);
531 
536  void setFilePath(std::string FP);
537 
538  std::vector<ExcelPortBase*> InPorts;
539  std::vector<ExcelPortBase*> OutPorts;
541  std::vector<ExcelPortBase*> ConfInPorts;
542  std::vector<ExcelPortBase*> ConfOutPorts;
544  RTC::Manager* m_manager;
546  std::vector<OtherPort> rtclist;
548  RTC::CorbaPort m_SpreadSheetPort;
555  protected:
556  std::string file_path;
557  std::string conf_data_type;
558  std::string conf_port_type;
560  std::string conf_start_row;
561  std::string conf_end_row;
562  std::string conf_sheetname;
563  int c_move;
564  std::string attach_Port;
565 
566 
567 
568 
570  int red;
571  int green;
572  int blue;
574  coil::Mutex _mutex;
576  ExcelTask *et;
577 
578 
579  private:
580 
581 
582 };
583 
589  : public RTC::ConfigurationSetListener
590 {
591 public:
597  {
598  m_rtc = e_rtc;
599  }
604  void operator()(const coil::Properties& config_set)
605  {
606 
607  m_rtc->configUpdate();
608 
609  }
612 };
613 
614 template <class T>
615 void getProperty(coil::Properties& prop, const char* key, T& value)
616 {
617 if (prop.findNode(key) != 0)
618  {
619  T tmp;
620  if (coil::stringTo(tmp, prop[key].c_str()))
621  {
622  value = tmp;
623  }
624  }
625 }
626 
627 
628 extern "C"
629 {
630  DLL_EXPORT void ExcelControlInit(RTC::Manager* manager);
631 };
632 
633 #endif