当前位置: 首页>>代码示例>>C++>>正文


C++ Printer::print_model方法代码示例

本文整理汇总了C++中Printer::print_model方法的典型用法代码示例。如果您正苦于以下问题:C++ Printer::print_model方法的具体用法?C++ Printer::print_model怎么用?C++ Printer::print_model使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Printer的用法示例。


在下文中一共展示了Printer::print_model方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char** argv) {
  sql::Driver* driver;
  sql::Connection* con;
  sql::Statement* stmt;
  sql::ResultSet* res;
  sql::PreparedStatement* pstmt;
  Printer* printer = new Printer;
  driver = get_driver_instance();
  con = driver->connect("localhost", "root", "orange");
  con->setSchema("cs4970f13grp6");
  std::cout << "Printer runtime starting up...\n";
  std::cout << "Waiting for go ahead to print\n";
  // main database driven loop
  bool stop_runtime_loop = false;
  while(!stop_runtime_loop) {
    stmt = con->createStatement();
    res = stmt->executeQuery("SELECT ClearToPrint FROM Printer_Flags where ID=1");
    res->next();
    const int clear_to_print = res->getInt("ClearToPrint");
    // wait for the printer to become avaliable 
    if (clear_to_print == true) {
      std::cout << "Looking for a Job to Process" << std::endl;
      bool job_found = false;
      int queue_id;
      int model_id;
      // look for a job in the queue
      while (!job_found) {
        stmt = con->createStatement();
        res = stmt->executeQuery("SELECT * FROM Queue ORDER BY QueueID ASC LIMIT 1");
        if(!res->next()){
          sleep(2);
          continue;
        }
        queue_id = res->getInt("QueueID");
        model_id = res->getInt("ModelID");
        job_found = true;
        std::cout << "Found job (" << model_id << ")\n";
      }
      // pull model info from database
      std::stringstream ss_model;
      ss_model << "SELECT STLFile FROM Model where ID=";
      ss_model << model_id;
      std::string model_query = ss_model.str();
      stmt = con->createStatement();
      // write blob to local disk
      std::istream* blob = NULL;
      res = stmt->executeQuery(model_query);
      while (res->next()) 
        blob = res->getBlob("STLFile");
      char buffer[1000000];
      memset(buffer, '\0', 1000000);
      blob->read((char*)buffer, 1000000);
      std::ofstream outfile ("model.stl", std::ofstream::binary);
      outfile.write (buffer, 1000000);
      outfile.close();
      // load model as an object
      Model *m = new Model;
      m->load_stl("model.stl");
      // begin printing
      //m->print_info();
      printer->load_model(m);
      bool print_success = printer->print_model(con);
      printer->unload_model();
      // on print success, remove print from queue
      if (print_success) {
        pstmt = con->prepareStatement("DELETE FROM Queue WHERE QueueID = ? LIMIT 1");
        pstmt->setInt(1, queue_id);
        pstmt->executeQuery();
      }
      // set the clear to print to 0 after print is finished
      stmt = con->createStatement();
      res = stmt->executeQuery("UPDATE Printer_Flags SET ClearToPrint = 0 WHERE ID = 1");
    } else {
      sleep(1);
    }
  }
  delete res;
  delete stmt;
  delete con;
  return 0;
}
开发者ID:ac90b671,项目名称:orange,代码行数:81,代码来源:runtime.cpp


注:本文中的Printer::print_model方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。