diff --git a/IfcPlusPlus/src/ifcpp/geometry/GeometryConverter.h b/IfcPlusPlus/src/ifcpp/geometry/GeometryConverter.h index e526e9cce..868adf5c5 100644 --- a/IfcPlusPlus/src/ifcpp/geometry/GeometryConverter.h +++ b/IfcPlusPlus/src/ifcpp/geometry/GeometryConverter.h @@ -58,7 +58,7 @@ class GeometryConverter : public StatusCallback std::map > m_product_shape_data; std::map > m_map_outside_spatial_structure; - std::set m_setResolvedProjectStructure; + std::set m_setResolvedProjectStructure; vec3 m_siteOffset; double m_recent_progress = 0; std::map > > m_messages; @@ -225,7 +225,7 @@ class GeometryConverter : public StatusCallback } #ifdef _DEBUG - std::string className = IFC4X3::EntityFactory::getStringForClassID(ifc_object_def->classID()); + std::string className = IFC4X3::EntityFactory::getStringForClassID(ifc_object_def->classID()); #endif for( const weak_ptr& relAggregates_weak_ptr : ifc_object_def->m_IsDecomposedBy_inverse ) @@ -243,33 +243,31 @@ class GeometryConverter : public StatusCallback const shared_ptr& related_obj_def = vec_related_objects[jj]; if( related_obj_def ) { - std::string related_guid; - if( related_obj_def->m_GlobalId ) + int tag = related_obj_def->m_tag; + if( tag < 0 ) { - related_guid = related_obj_def->m_GlobalId->m_value; - } - - if( related_guid.size() < 20 ) - { - std::cout << "guid invalid: " << related_guid << std::endl; + std::cout << "invalid tag: " << tag << std::endl; continue; } - if( m_setResolvedProjectStructure.find(related_guid) != m_setResolvedProjectStructure.end() ) + if( m_setResolvedProjectStructure.find(tag) != m_setResolvedProjectStructure.end() ) { continue; } - m_setResolvedProjectStructure.insert(related_guid); - + m_setResolvedProjectStructure.insert(tag); - auto it_product_map = m_product_shape_data.find(related_guid); - if( it_product_map != m_product_shape_data.end() ) + if( related_obj_def->m_GlobalId ) { - shared_ptr& related_product_shape = it_product_map->second; - if( related_product_shape ) + std::string guid = related_obj_def->m_GlobalId->m_value; + auto it_product_map = m_product_shape_data.find(guid); + if( it_product_map != m_product_shape_data.end() ) { - product_data->addChildProduct(related_product_shape, product_data); - resolveProjectStructure(related_product_shape, resolveSecondaryStructure); + shared_ptr& related_product_shape = it_product_map->second; + if( related_product_shape ) + { + product_data->addChildProduct(related_product_shape, product_data); + resolveProjectStructure(related_product_shape, resolveSecondaryStructure); + } } } } @@ -298,33 +296,32 @@ class GeometryConverter : public StatusCallback const shared_ptr& related_product = vec_related_elements[jj]; if( related_product ) { - std::string related_guid; - if( related_product->m_GlobalId ) + int tag = related_product->m_tag; + if( tag < 0 ) { - related_guid = related_product->m_GlobalId->m_value; - } - - if( related_guid.size() < 20 ) - { - std::cout << "guid invalid: " << related_guid << std::endl; + std::cout << "tag invalid: " << tag << std::endl; continue; } - if( m_setResolvedProjectStructure.find(related_guid) != m_setResolvedProjectStructure.end() ) + if( m_setResolvedProjectStructure.find(tag) != m_setResolvedProjectStructure.end() ) { - //std::cout << "duplicate guid in model tree: " << related_guid << std::endl; continue; } - m_setResolvedProjectStructure.insert(related_guid); + m_setResolvedProjectStructure.insert(tag); - auto it_product_map = m_product_shape_data.find(related_guid); - if( it_product_map != m_product_shape_data.end() ) + if( related_product->m_GlobalId ) { - shared_ptr& related_product_shape = it_product_map->second; - if( related_product_shape ) + std::string related_guid = related_product->m_GlobalId->m_value; + + auto it_product_map = m_product_shape_data.find(related_guid); + if( it_product_map != m_product_shape_data.end() ) { - product_data->addChildProduct(related_product_shape, product_data); - resolveProjectStructure(related_product_shape, resolveSecondaryStructure); + shared_ptr& related_product_shape = it_product_map->second; + if( related_product_shape ) + { + product_data->addChildProduct(related_product_shape, product_data); + resolveProjectStructure(related_product_shape, resolveSecondaryStructure); + } } } } @@ -332,7 +329,7 @@ class GeometryConverter : public StatusCallback } } } - + if( resolveSecondaryStructure ) { // handle IfcRelAssigns @@ -373,33 +370,33 @@ class GeometryConverter : public StatusCallback for( auto related_object : groupedBy->m_RelatedObjects ) { - std::string related_guid; - if( related_object->m_GlobalId ) + int tag = related_object->m_tag; + if( tag < 0 ) { - related_guid = related_object->m_GlobalId->m_value; - } - - if( related_guid.size() < 20 ) - { - std::cout << "guid invalid: " << related_guid << std::endl; + std::cout << "tag invalid: " << tag << std::endl; continue; } - if( m_setResolvedProjectStructure.find(related_guid) != m_setResolvedProjectStructure.end() ) + if( m_setResolvedProjectStructure.find(tag) != m_setResolvedProjectStructure.end() ) { // std::cout << "duplicate guid in model tree: " << related_guid << std::endl; continue; } - m_setResolvedProjectStructure.insert(related_guid); + m_setResolvedProjectStructure.insert(tag); - auto it_product_map = m_product_shape_data.find(related_guid); - if( it_product_map != m_product_shape_data.end() ) + if( related_object->m_GlobalId ) { - shared_ptr& related_product_shape = it_product_map->second; - if( related_product_shape ) + std::string related_guid = related_object->m_GlobalId->m_value; + + auto it_product_map = m_product_shape_data.find(related_guid); + if( it_product_map != m_product_shape_data.end() ) { - product_data->addChildProduct(related_product_shape, product_data); - resolveProjectStructure(related_product_shape, resolveSecondaryStructure); + shared_ptr& related_product_shape = it_product_map->second; + if( related_product_shape ) + { + product_data->addChildProduct(related_product_shape, product_data); + resolveProjectStructure(related_product_shape, resolveSecondaryStructure); + } } } } @@ -434,33 +431,33 @@ class GeometryConverter : public StatusCallback //shared_ptr m_RelatingPort; //shared_ptr m_RelatedElement; - std::string related_guid; - if( related_object->m_GlobalId ) - { - related_guid = related_object->m_GlobalId->m_value; - } + int tag = related_object->m_tag; - if( related_guid.size() < 20 ) + if( tag < 0 ) { - std::cout << "guid invalid: " << related_guid << std::endl; + std::cout << "tag invalid: " << tag << std::endl; continue; } - if( m_setResolvedProjectStructure.find(related_guid) != m_setResolvedProjectStructure.end() ) + if( m_setResolvedProjectStructure.find(tag) != m_setResolvedProjectStructure.end() ) { // std::cout << "duplicate guid in model tree: " << related_guid << std::endl; continue; } - m_setResolvedProjectStructure.insert(related_guid); + m_setResolvedProjectStructure.insert(tag); - auto it_product_map = m_product_shape_data.find(related_guid); - if( it_product_map != m_product_shape_data.end() ) + if( related_object->m_GlobalId ) { - shared_ptr& related_product_shape = it_product_map->second; - if( related_product_shape ) + std::string related_guid = related_object->m_GlobalId->m_value; + auto it_product_map = m_product_shape_data.find(related_guid); + if( it_product_map != m_product_shape_data.end() ) { - product_data->addChildProduct(related_product_shape, product_data); - resolveProjectStructure(related_product_shape, resolveSecondaryStructure); + shared_ptr& related_product_shape = it_product_map->second; + if( related_product_shape ) + { + product_data->addChildProduct(related_product_shape, product_data); + resolveProjectStructure(related_product_shape, resolveSecondaryStructure); + } } } } @@ -476,10 +473,9 @@ class GeometryConverter : public StatusCallback std::map >& map_shapeInputData = getShapeInputData(); shared_ptr ifc_model = getBuildingModel(); shared_ptr ifc_project = ifc_model->getIfcProject(); - shared_ptr ifc_site; - + std::vector > vec_ifc_sites; std::vector > vec_ifc_buildings; - + for( auto it : map_shapeInputData ) { std::string guid = it.first; @@ -511,7 +507,7 @@ class GeometryConverter : public StatusCallback shared_ptr site = dynamic_pointer_cast(ifc_object_definition); if( site ) { - ifc_site = site; + vec_ifc_sites.push_back( site ); continue; } } @@ -528,7 +524,7 @@ class GeometryConverter : public StatusCallback } // if IfcBuilding is not connected to IfcSite and IfcProject, find IfcSite, and connect it - if( ifc_site ) + for( auto ifc_site : vec_ifc_sites ) { for( auto product_shape_building : vec_ifc_buildings ) { @@ -830,7 +826,7 @@ class GeometryConverter : public StatusCallback } // implicit barrier #endif - // subtract openings in related objects, such as IFCBUILDINGELEMENTPART connected to a window through IFCRELAGGREGATES + // subtract openings in related objects, such as IFCBUILDINGELEMENTPART connected to a window through IFCRELAGGREGATES for( auto it = map_products_ptr->begin(); it != map_products_ptr->end(); ++it ) { shared_ptr product_geom_input_data = it->second; @@ -883,13 +879,13 @@ class GeometryConverter : public StatusCallback if( !product_shape->m_ifc_object_definition.expired() ) { shared_ptr ifc_object_def( product_shape->m_ifc_object_definition ); - - if( !m_geom_settings->skipRenderObject(ifc_object_def->classID()) ) + + if( m_geom_settings->skipRenderObject(ifc_object_def->classID()) ) { continue; } std::string guid; - + if (ifc_object_def->m_GlobalId) { guid = ifc_object_def->m_GlobalId->m_value; @@ -1068,7 +1064,7 @@ class GeometryConverter : public StatusCallback if( enableCaching ) { bool equalItemFound = false; - + for( auto it : m_product_shape_data ) { const shared_ptr& existingProductShape = it.second; @@ -1091,14 +1087,14 @@ class GeometryConverter : public StatusCallback } if( !equalItemFound ) { -// representation_data->m_vec_item_data.push_back(geom_item_data); -//#ifdef _OPENMP -// ScopedLock lock( m_writelock_item_cache ); -//#endif -// m_map_item_data_cache.push_back(geom_item_data); + // representation_data->m_vec_item_data.push_back(geom_item_data); + //#ifdef _OPENMP + // ScopedLock lock( m_writelock_item_cache ); + //#endif + // m_map_item_data_cache.push_back(geom_item_data); } } - + if( m_clear_memory_immedeately ) { ifc_product->m_Representation.reset(); @@ -1186,7 +1182,7 @@ class GeometryConverter : public StatusCallback if (related_object->m_GlobalId) { guid = related_object->m_GlobalId->m_value; - + auto it_find_related_shape = m_product_shape_data.find(guid); if( it_find_related_shape != m_product_shape_data.end() ) { diff --git a/IfcPlusPlus/src/ifcpp/reader/ReaderUtil.cpp b/IfcPlusPlus/src/ifcpp/reader/ReaderUtil.cpp index b7ad0517d..14896a7b6 100644 --- a/IfcPlusPlus/src/ifcpp/reader/ReaderUtil.cpp +++ b/IfcPlusPlus/src/ifcpp/reader/ReaderUtil.cpp @@ -17,14 +17,11 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OU #define _USE_MATH_DEFINES #include -#include -#include #include #include #include #include -#include "utf8/cpp17.h" #include "ifcpp/model/BuildingException.h" #include "ReaderUtil.h" @@ -33,6 +30,9 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OU #endif #ifdef _MSC_VER #include +#else +#include +#include #endif static short convertToHex(unsigned char mc) @@ -64,12 +64,6 @@ static char Hex2Char(unsigned char h1, unsigned char h2 ) return (returnValue); } -static char Hex4Char(unsigned char h1, unsigned char h2, unsigned char h3, unsigned char h4 ) -{ - char returnValue = (convertToHex(h1)<< 12) + (convertToHex(h2) << 8) +(convertToHex(h3) << 4) + convertToHex(h4); - return (returnValue); -} - std::string wstring2string(const std::wstring& wstr) { if( wstr.empty() ) return std::string(); @@ -78,18 +72,6 @@ std::string wstring2string(const std::wstring& wstr) int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL); std::string strTo( size_needed, 0 ); WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL); - -#ifdef _DEBUG - { - std::wstring_convert, wchar_t> StringConverter; - std::string strTo_check = StringConverter.to_bytes(wstr); - if( strTo_check.compare(strTo) != 0 ) - { - std::cout << "wstring2string check failed" << std::endl; - } - } -#endif - return strTo; #else @@ -204,8 +186,19 @@ std::istream& bufferedGetStepLine(std::istream& inputStream, std::string& lineOu switch (c) { case ';': - sb->sbumpc(); // sbumpc: character at the current position and advances the current position to the next character - return inputStream; + { + if( !inString ) + { + int nextChar = sb->sgetc(); + if( isspace(nextChar) ) + { + sb->sbumpc(); // sbumpc: character at the current position and advances the current position to the next character + } + return inputStream; + } + lineOut += (char)c; + continue; + } case '\'': if( sb->sgetc() != '/' ) // sgetc: character at the current position { @@ -216,13 +209,16 @@ std::istream& bufferedGetStepLine(std::istream& inputStream, std::string& lineOu case '/': if( !inString ) { - int currentChar = sb->sgetc(); + int nextChar = sb->sgetc(); #ifdef _DEBUG std::string charAsString2; - charAsString2 += ((char)currentChar); + charAsString2 += ((char)nextChar); #endif - if( currentChar == '*' ) + if( nextChar == '*' ) { +#ifdef _DEBUG + std::string commentIgnored = "/*"; +#endif sb->sbumpc(); // continue till end of /* */ comment @@ -233,12 +229,38 @@ std::istream& bufferedGetStepLine(std::istream& inputStream, std::string& lineOu switch( c2 ) { case '*': - c2 = sb->sbumpc(); - if( c2 == '/' ) + { + char c3 = sb->sgetc(); + if( c3 == '/' ) { + sb->sbumpc(); inMultiLineComment = false; + + // skip whitespaces + while(true) + { + char c4 = sb->sgetc(); + if( isspace(c4) ) + { + sb->sbumpc(); + } + else if( c4 == std::streambuf::traits_type::eof() ) + { + if( lineOut.empty() ) + { + inputStream.setstate(std::ios::eofbit); + } + return inputStream; + } + else + { + break; + } + } + break; } + } case std::streambuf::traits_type::eof(): // in case the last line has no line ending if( lineOut.empty() ) @@ -247,6 +269,9 @@ std::istream& bufferedGetStepLine(std::istream& inputStream, std::string& lineOu } return inputStream; } +#ifdef _DEBUG + commentIgnored += c2; +#endif } continue; } @@ -409,7 +434,7 @@ void tokenizeList( std::string& list_str, std::vector& list_items ) ++stream_pos; continue; } - + if( *stream_pos == ',' && numNestedLists == 0) { std::string item( last_token, stream_pos-last_token ); @@ -448,7 +473,7 @@ void tokenizeEntityList( std::string& list_str, std::vector& list_items ) { // skip whitespace while( isspace( *stream_pos ) ) { ++stream_pos; } - + if( *stream_pos == '#' ) { ++stream_pos; @@ -519,7 +544,7 @@ void readIntegerList( const std::string& str, std::vector& vec ) } ++i; } - + while( i& entity_arguments, std::vec } std::string arg_str_new; - arg_str_new.reserve(arg_length); - + char* stream_pos = const_cast(argument_str.c_str()); // ascii characters from STEP file while( *stream_pos != '\0' ) { @@ -975,15 +999,41 @@ void decodeArgumentStrings( std::vector& entity_arguments, std::vec bool finished = false; stream_pos += 4; + std::vector utf16Characters; do { - char c = Hex4Char(*(stream_pos), *(stream_pos+1), *(stream_pos+2), *(stream_pos+3)); - //unsigned char char_ascii = wctob(wc); - arg_str_new += c; + char h1 = *(stream_pos); + char h2 = *(stream_pos + 1); + char h3 = *(stream_pos + 2); + char h4 = *(stream_pos + 3); + + char c1 = Hex2Char(h1, h2); + char c2 = Hex2Char(h3, h4); + utf16Characters.push_back(c1); + utf16Characters.push_back(c2); + stream_pos += 4; } while (( *stream_pos != '\0' ) && ( *stream_pos != '\\' )); + for (int i = 0; i < utf16Characters.size(); i+=2) + { + std::swap(utf16Characters[i], utf16Characters[i + 1]); + } + +#ifdef _MSC_VER + std::wstring w_str(reinterpret_cast(&utf16Characters[0]), utf16Characters.size() / 2); + std::string convertedStr = wstring2string(w_str); + arg_str_new += convertedStr; +#else + std::u16string u16str(reinterpret_cast(&utf16Characters[0]), utf16Characters.size() / 2); + std::wstring_convert,char16_t> convert; + std::string utf8 = convert.to_bytes(u16str); + arg_str_new += utf8; +#endif + + + continue; } } @@ -998,13 +1048,14 @@ void decodeArgumentStrings( std::vector& entity_arguments, std::vec } } } - + char current_char = *stream_pos; arg_str_new += current_char; ++stream_pos; } - + args_out.push_back( arg_str_new ); + } } @@ -1193,7 +1244,7 @@ void tokenizeInlineArgument( std::string arg, std::string& keyword, std::string& // get type name std::string key( begin_keyword, stream_pos-begin_keyword ); - + if( key.empty() ) { // single argument, for example .T. @@ -1225,7 +1276,7 @@ void tokenizeInlineArgument( std::string arg, std::string& keyword, std::string& // proceed to ')' std::string inline_argument; char* inline_argument_begin = stream_pos; - + while( *stream_pos != '\0' ) { if( *stream_pos == '\'' ) diff --git a/IfcPlusPlus/src/ifcpp/reader/ReaderUtil.h b/IfcPlusPlus/src/ifcpp/reader/ReaderUtil.h index d52f86c64..1d60a23b6 100644 --- a/IfcPlusPlus/src/ifcpp/reader/ReaderUtil.h +++ b/IfcPlusPlus/src/ifcpp/reader/ReaderUtil.h @@ -17,10 +17,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OU #pragma once -#pragma warning ( disable: 4996 ) // for boost\random\detail\polynomial.hpp - #include -#include #include #include #include @@ -62,10 +59,9 @@ void findLeadingTrailingParanthesis(char* ch, char*& pos_opening, char*& pos_clo void findEndOfString(const char*& stream_pos); bool findEndOfStepLine(char* ch, char*& pos_end); void checkOpeningClosingParenthesis(const char* ch_check); -IFCQUERY_EXPORT std::istream& bufferedGetline(std::istream& is, std::string& t); +std::istream& bufferedGetline(std::istream& is, std::string& t); std::istream& bufferedGetStepLine(std::istream& inputStream, std::string& lineOut); - IFCQUERY_EXPORT std::string wstring2string(const std::wstring& str); IFCQUERY_EXPORT std::wstring string2wstring(const std::string& inputString); IFCQUERY_EXPORT bool std_iequal(const std::string& a, const std::string& b); diff --git a/examples/CreateIfcWallAndWriteFile/src/main.cpp b/examples/CreateIfcWallAndWriteFile/src/main.cpp index 6b3254282..7b7561fa9 100644 --- a/examples/CreateIfcWallAndWriteFile/src/main.cpp +++ b/examples/CreateIfcWallAndWriteFile/src/main.cpp @@ -77,10 +77,9 @@ inline void convertPlacement(double local_x[3], double local_z[3], double locati axis2placement3d->m_Location = cartesianPoint; vec_new_entities.push_back(axis2placement3d->m_Location); } - cartesianPoint->m_Coordinates.clear(); - cartesianPoint->m_Coordinates.push_back(shared_ptr(new IfcLengthMeasure(location[0]))); - cartesianPoint->m_Coordinates.push_back(shared_ptr(new IfcLengthMeasure(location[1]))); - cartesianPoint->m_Coordinates.push_back(shared_ptr(new IfcLengthMeasure(location[2]))); + cartesianPoint->m_Coordinates[0] = location[0]; + cartesianPoint->m_Coordinates[1] = location[1]; + cartesianPoint->m_Coordinates[2] = location[2]; if (!axis2placement3d->m_Axis) { @@ -118,8 +117,8 @@ shared_ptr createIfcDirection(double x, double y, double z, std::v shared_ptr createIfcCartesianPoint(double x, double y, std::vector >& vec_new_entities) { shared_ptr pt(new IfcCartesianPoint()); - pt->m_Coordinates.push_back(shared_ptr(new IfcLengthMeasure(x))); - pt->m_Coordinates.push_back(shared_ptr(new IfcLengthMeasure(y))); + pt->m_Coordinates[0] = x; + pt->m_Coordinates[1] = y; vec_new_entities.push_back(pt); return pt; } @@ -127,18 +126,14 @@ shared_ptr createIfcCartesianPoint(double x, double y, std::v shared_ptr createIfcCartesianPoint(double x, double y, double z, std::vector >& vec_new_entities) { shared_ptr pt(new IfcCartesianPoint()); - pt->m_Coordinates.push_back(shared_ptr(new IfcLengthMeasure(x))); - pt->m_Coordinates.push_back(shared_ptr(new IfcLengthMeasure(y))); - pt->m_Coordinates.push_back(shared_ptr(new IfcLengthMeasure(z))); + pt->m_Coordinates[0] = x; + pt->m_Coordinates[1] = y; + pt->m_Coordinates[2] = z; vec_new_entities.push_back(pt); return pt; } -shared_ptr createIfcFace( - shared_ptr pt0, - shared_ptr pt1, - shared_ptr pt2, - shared_ptr pt3, +shared_ptr createIfcFace( shared_ptr pt0, shared_ptr pt1, shared_ptr pt2, shared_ptr pt3, std::vector >& vec_new_entities) { shared_ptr face(new IfcFace()); diff --git a/examples/LoadFileWithGeometryExample/src/main.cpp b/examples/LoadFileWithGeometryExample/src/main.cpp index 2fd49e9fc..e9dc2f06b 100644 --- a/examples/LoadFileWithGeometryExample/src/main.cpp +++ b/examples/LoadFileWithGeometryExample/src/main.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include using namespace IFC4X3; diff --git a/examples/SimpleViewerExampleQt/src/gui/IfcTreeWidget.cpp b/examples/SimpleViewerExampleQt/src/gui/IfcTreeWidget.cpp index c8c9f2de1..09f96d9f4 100644 --- a/examples/SimpleViewerExampleQt/src/gui/IfcTreeWidget.cpp +++ b/examples/SimpleViewerExampleQt/src/gui/IfcTreeWidget.cpp @@ -270,7 +270,7 @@ QTreeWidgetItem* resolveTreeItems( shared_ptr obj, std::unordere std::string name = obj_def->m_Name->m_value; if( name.size() > 0 ) { - item->setText(0, QString::fromStdWString(string2wstring(name))); + item->setText(0, QString::fromStdString(name)); } }