From e9a3464c2629488e1f0c526f34b97cf354c7b5d6 Mon Sep 17 00:00:00 2001 From: aothms Date: Tue, 8 Apr 2014 07:28:07 +0000 Subject: [PATCH] Account for unit magnitude in matrix translation part when CONVERT_BACK_UNITS is enabled --- src/ifcgeom/IfcGeomObjects.cpp | 16 ++++- src/ifcserver/IfcServer.cpp | 111 --------------------------------- 2 files changed, 13 insertions(+), 114 deletions(-) delete mode 100644 src/ifcserver/IfcServer.cpp diff --git a/src/ifcgeom/IfcGeomObjects.cpp b/src/ifcgeom/IfcGeomObjects.cpp index dd6627f316..feb387640e 100644 --- a/src/ifcgeom/IfcGeomObjects.cpp +++ b/src/ifcgeom/IfcGeomObjects.cpp @@ -240,9 +240,19 @@ IfcGeomObjects::IfcObject::IfcObject( , _guid(guid) { // Convert the gp_Trsf into a 4x3 Matrix - for( int i = 1; i < 5; ++ i ) - for ( int j = 1; j < 4; ++ j ) - _matrix.push_back((float)trsf.Value(j,i)); + // Note that in case the CONVERT_BACK_UNITS setting is enabled + // the translation component of the matrix needs to be divided + // by the magnitude of the IFC model length unit because + // internally in IfcOpenShell everything is measured in meters. + for(int i = 1; i < 5; ++i) { + for (int j = 1; j < 4; ++j) { + const double trsf_value = trsf.Value(j,i); + const double matrix_value = i == 4 && convert_back_units + ? trsf_value / IfcGeom::GetValue(IfcGeom::GV_LENGTH_UNIT) + : trsf_value; + _matrix.push_back(static_cast(matrix_value)); + } + } } IfcGeomObjects::IfcGeomShapeModelObject::IfcGeomShapeModelObject( diff --git a/src/ifcserver/IfcServer.cpp b/src/ifcserver/IfcServer.cpp deleted file mode 100644 index c0563dcb5a..0000000000 --- a/src/ifcserver/IfcServer.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************** - * * - * This file is part of IfcOpenShell. * - * * - * IfcOpenShell is free software: you can redistribute it and/or modify * - * it under the terms of the Lesser GNU General Public License as published by * - * the Free Software Foundation, either version 3.0 of the License, or * - * (at your option) any later version. * - * * - * IfcOpenShell is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * Lesser GNU General Public License for more details. * - * * - * You should have received a copy of the Lesser GNU General Public License * - * along with this program. If not, see . * - * * - ********************************************************************************/ - -/******************************************************************************** - * * - * This examples exposes the IfcOpenShell API through a command-based stdin * - * interface * - * * - ********************************************************************************/ - -#include - -#include "../ifcgeom/IfcGeomObjects.h" - -#if defined(WIN32) && !defined(__CYGWIN__) -#include -#include -#endif - -#define PRODUCT ("IfcOpenShell-0.2.3") -#define ACK ("y") -#define NEG ("n") -#define CONFIRM ("ok") -#define CLOSED ("No opened file") -#define QUIT ("Bye :)") -#define UNKNOWN ("Unknown command") - -void send_msg(const char* c) { - std::cout.write(c,strlen(c)); - std::cout.flush(); -} - -void send_msg(const std::string& s) { - std::cout << s << std::flush; -} - -int main ( int argc, char** argv ) { -#if defined(WIN32) && !defined(__CYGWIN__) - _setmode(_fileno(stdout), _O_BINARY); - std::cout.setf(std::ios_base::binary); -#endif - bool has_more = false; - send_msg(PRODUCT); - const IfcGeomObjects::IfcGeomObject* ifc_geom = 0; - while (1) { - std::string command; - std::cin >> command; - if ( command == "load" ) { - std::string fn; - std::getline(std::cin,fn); - fn = fn.erase(0,fn.find_first_not_of(" ")); - has_more = IfcGeomObjects::Init(fn.c_str(),true,0,&std::cerr); - send_msg(has_more ? ACK : NEG); - } else if ( command == "loadstdin" ) { - send_msg(CONFIRM); - int len; - std::cin >> len; - send_msg(CONFIRM); - has_more = IfcGeomObjects::Init(std::cin,len,true,0,&std::cerr); - send_msg(has_more ? ACK : NEG); - } else if ( command == "get" ) { - if ( ! has_more ) send_msg(CLOSED); - else { - ifc_geom = IfcGeomObjects::Get(); - const int vcount = ifc_geom->mesh->verts.size() / 3; - std::cout.write((char*)&vcount,sizeof(int)); - std::cout.write((char*)&ifc_geom->mesh->verts[0],sizeof(float)*vcount*3); - const int fcount = ifc_geom->mesh->faces.size() / 3; - std::cout.write((char*)&fcount,sizeof(int)); - std::cout.write((char*)&ifc_geom->mesh->faces[0],sizeof(int)*fcount*3); - std::cout.flush(); - } - } else if ( command == "type" ) { - if ( ifc_geom ) send_msg(ifc_geom->type); - else send_msg(CLOSED); - } else if ( command == "guid" ) { - if ( ifc_geom ) send_msg(ifc_geom->guid); - else send_msg(CLOSED); - } else if ( command == "next" ) { - if ( !has_more ) send_msg(CLOSED); - else { - has_more = IfcGeomObjects::Next(); - if ( ! has_more ) - IfcGeomObjects::CleanUp(); - send_msg(has_more ? ACK : NEG); - } - } else if ( command == "quit" || command == "exit" ) { - send_msg(QUIT); - break; - } else { - send_msg(UNKNOWN); - } - } - return 0; -}