|
| 1 | +/******************************************************************************** |
| 2 | + * * |
| 3 | + * This file is part of IfcOpenShell. * |
| 4 | + * * |
| 5 | + * IfcOpenShell is free software: you can redistribute it and/or modify * |
| 6 | + * it under the terms of the Lesser GNU General Public License as published by * |
| 7 | + * the Free Software Foundation, either version 3.0 of the License, or * |
| 8 | + * (at your option) any later version. * |
| 9 | + * * |
| 10 | + * IfcOpenShell is distributed in the hope that it will be useful, * |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 13 | + * Lesser GNU General Public License for more details. * |
| 14 | + * * |
| 15 | + * You should have received a copy of the Lesser GNU General Public License * |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. * |
| 17 | + * * |
| 18 | + ********************************************************************************/ |
| 19 | + |
| 20 | +/******************************************************************************** |
| 21 | + * * |
| 22 | + * This examples exposes the IfcOpenShell API through a command-based stdin * |
| 23 | + * interface * |
| 24 | + * * |
| 25 | + ********************************************************************************/ |
| 26 | + |
| 27 | +#include <iostream> |
| 28 | + |
| 29 | +#include "../ifcparse/IfcGeomObjects.h" |
| 30 | + |
| 31 | +#if defined(WIN32) && !defined(__CYGWIN__) |
| 32 | +#include <io.h> |
| 33 | +#include <fcntl.h> |
| 34 | +#endif |
| 35 | + |
| 36 | +int main ( int argc, char** argv ) { |
| 37 | +#if defined(WIN32) && !defined(__CYGWIN__) |
| 38 | + _setmode(_fileno(stdout), _O_BINARY); |
| 39 | + std::cout.setf(std::ios_base::binary); |
| 40 | +#endif |
| 41 | + bool has_more = false; |
| 42 | + std::cout.write("IfcOpenShell-0.2.0",18); |
| 43 | + std::cout.flush(); |
| 44 | + const IfcGeomObjects::IfcGeomObject* ifc_geom = 0; |
| 45 | + while (1) { |
| 46 | + std::string command; |
| 47 | + std::cin >> command; |
| 48 | + if ( command == "load" ) { |
| 49 | + std::string fn; |
| 50 | + std::getline(std::cin,fn); |
| 51 | + fn = fn.erase(0,fn.find_first_not_of(" ")); |
| 52 | + has_more = IfcGeomObjects::Init(fn.c_str(),true,0,&std::cerr); |
| 53 | + std::cout.write(has_more ? "y" : "n",1); |
| 54 | + std::cout.flush(); |
| 55 | + } else if ( command == "loadstdin" ) { |
| 56 | + std::cout << "ok" << std::flush; |
| 57 | + int len; |
| 58 | + std::cin >> len; |
| 59 | + std::cout << "ok" << std::flush; |
| 60 | + has_more = IfcGeomObjects::Init(std::cin,len,true,0,&std::cerr); |
| 61 | + std::cout.write(has_more ? "y" : "n",1); |
| 62 | + std::cout.flush(); |
| 63 | + } else if ( command == "get" ) { |
| 64 | + if ( !has_more ) { |
| 65 | + std::cout << "Not loaded" << std::flush; |
| 66 | + } else { |
| 67 | + ifc_geom = IfcGeomObjects::Get(); |
| 68 | + const int vcount = ifc_geom->mesh->verts.size() / 3; |
| 69 | + std::cout.write((char*)&vcount,sizeof(int)); |
| 70 | + std::cout.write((char*)&ifc_geom->mesh->verts[0],sizeof(float)*vcount*3); |
| 71 | + const int fcount = ifc_geom->mesh->faces.size() / 3; |
| 72 | + std::cout.write((char*)&fcount,sizeof(int)); |
| 73 | + std::cout.write((char*)&ifc_geom->mesh->faces[0],sizeof(int)*fcount*3); |
| 74 | + std::cout.flush(); |
| 75 | + } |
| 76 | + } else if ( command == "type" ) { |
| 77 | + if ( ! ifc_geom ) { |
| 78 | + std::cout << "Not loaded" << std::flush; |
| 79 | + } else { |
| 80 | + std::cout << ifc_geom->type << std::flush; |
| 81 | + } |
| 82 | + } else if ( command == "guid" ) { |
| 83 | + if ( ! ifc_geom ) { |
| 84 | + std::cout << "Not loaded" << std::flush; |
| 85 | + } else { |
| 86 | + std::cout << ifc_geom->name << std::flush; |
| 87 | + } |
| 88 | + } else if ( command == "next" ) { |
| 89 | + if ( !has_more ) { |
| 90 | + std::cout << "Not loaded" << std::flush; |
| 91 | + } else { |
| 92 | + has_more = IfcGeomObjects::Next(); |
| 93 | + std::cout.write(has_more ? "y" : "n",1); |
| 94 | + std::cout.flush(); |
| 95 | + } |
| 96 | + } else if ( command == "quit" || command == "exit" ) { |
| 97 | + std::cout << "Bye" << std::flush; |
| 98 | + break; |
| 99 | + } else { |
| 100 | + std::cout << "Unknown command " << command << std::flush; |
| 101 | + } |
| 102 | + } |
| 103 | +} |
0 commit comments