Skip to content

Commit

Permalink
Fixed value type enum
Browse files Browse the repository at this point in the history
added overload for ifcString to take a text values
started unit tests
  • Loading branch information
CEXT-Dan committed Oct 14, 2024
1 parent 2df6e67 commit 69ac003
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 32 deletions.
22 changes: 11 additions & 11 deletions PyRxCore/PyBrxBim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,18 @@ BOOST_PYTHON_MODULE(PyBrxBim)
.export_values()
;
enum_<Ice::IfcApi::ValueType>("IfcValueType")
.value("eBool,", Ice::IfcApi::ValueType::eBool)
.value("eInt,", Ice::IfcApi::ValueType::eInt)
.value("eUInt,", Ice::IfcApi::ValueType::eUInt)
.value("eReal,", Ice::IfcApi::ValueType::eReal)
.value("eString,", Ice::IfcApi::ValueType::eString)
.value("eEntity,", Ice::IfcApi::ValueType::eEntity)
.value("eBool", Ice::IfcApi::ValueType::eBool)
.value("eInt", Ice::IfcApi::ValueType::eInt)
.value("eUInt", Ice::IfcApi::ValueType::eUInt)
.value("eReal", Ice::IfcApi::ValueType::eReal)
.value("eString", Ice::IfcApi::ValueType::eString)
.value("eEntity", Ice::IfcApi::ValueType::eEntity)
.value("eLogical", Ice::IfcApi::ValueType::eLogical)
.value("eBinary,", Ice::IfcApi::ValueType::eBinary)
.value("eGuid,", Ice::IfcApi::ValueType::eGuid)
.value("eEnum,", Ice::IfcApi::ValueType::eEnum)
.value("eSelect,", Ice::IfcApi::ValueType::eSelect)
.value("eVector,", Ice::IfcApi::ValueType::eVector)
.value("eBinary", Ice::IfcApi::ValueType::eBinary)
.value("eGuid", Ice::IfcApi::ValueType::eGuid)
.value("eEnum", Ice::IfcApi::ValueType::eEnum)
.value("eSelect", Ice::IfcApi::ValueType::eSelect)
.value("eVector", Ice::IfcApi::ValueType::eVector)
.value("eEmpty", Ice::IfcApi::ValueType::eEmpty)
.export_values()
;
Expand Down
11 changes: 11 additions & 0 deletions PyRxCore/PyBrxIFC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,14 @@ Ice::IfcApi::Guid* PyIfcGuid::impObj(const std::source_location& src /*= std::so
//PyIfcString
void makePyIfcStringWrapper()
{
constexpr const std::string_view ctor = "Overloads:\n"
"- None: Any\n"
"- text: str\n";

PyDocString DS("IfcString");
class_<PyIfcString>("IfcString")
.def(init<>())
.def(init<const std::string&>(DS.CTOR(ctor)))
.def("getEncoded", &PyIfcString::getEncoded, DS.ARGS())
.def("c_str", &PyIfcString::c_str, DS.ARGS())
.def("isEmpty", &PyIfcString::isEmpty, DS.ARGS())
Expand All @@ -106,6 +112,11 @@ PyIfcString::PyIfcString(const Ice::IfcApi::String& pObject)
{
}

PyIfcString::PyIfcString(const std::string& val)
: PyIfcString(new Ice::IfcApi::String(utf8_to_wstr(val).c_str()), true)
{
}

const std::string PyIfcString::getEncoded() const
{
return std::string{ impObj()->getEncoded() };
Expand Down
1 change: 1 addition & 0 deletions PyRxCore/PyBrxIFC.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class PyIfcString
{
public:
PyIfcString();
PyIfcString(const std::string& val);
PyIfcString(const Ice::IfcApi::String& pObject);
PyIfcString(Ice::IfcApi::String* pObject, bool autoDelete);
~PyIfcString() = default;
Expand Down
38 changes: 23 additions & 15 deletions PyRxStubs/PyBrxBim.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1282,11 +1282,16 @@ class IfcSelectorDesc(object):
...

class IfcString(object):
def __init__ (self, *args, **kwargs)-> None :
'''__init__( (object)arg1) -> None :

C++ signature :
void __init__(struct _object * __ptr64)'''
@overload
def __init__ (self, /)-> None : ...
@overload
def __init__ (self, text: str)-> None : ...
def __init__ (self, *args, **kwargs)-> None :
'''Overloads:
- None: Any
- text: str
'''
...
def c_str (self)-> str :
''' '''
Expand All @@ -1312,43 +1317,43 @@ class IfcString(object):
...

class IfcValueType(object):
def eBinary, (self, *args, **kwargs)-> None :
def eBinary (self, *args, **kwargs)-> None :
'''None'''
...
def eBool, (self, *args, **kwargs)-> None :
def eBool (self, *args, **kwargs)-> None :
'''None'''
...
def eEmpty (self, *args, **kwargs)-> None :
'''None'''
...
def eEntity, (self, *args, **kwargs)-> None :
def eEntity (self, *args, **kwargs)-> None :
'''None'''
...
def eEnum, (self, *args, **kwargs)-> None :
def eEnum (self, *args, **kwargs)-> None :
'''None'''
...
def eGuid, (self, *args, **kwargs)-> None :
def eGuid (self, *args, **kwargs)-> None :
'''None'''
...
def eInt, (self, *args, **kwargs)-> None :
def eInt (self, *args, **kwargs)-> None :
'''None'''
...
def eLogical (self, *args, **kwargs)-> None :
'''None'''
...
def eReal, (self, *args, **kwargs)-> None :
def eReal (self, *args, **kwargs)-> None :
'''None'''
...
def eSelect, (self, *args, **kwargs)-> None :
def eSelect (self, *args, **kwargs)-> None :
'''None'''
...
def eString, (self, *args, **kwargs)-> None :
def eString (self, *args, **kwargs)-> None :
'''None'''
...
def eUInt, (self, *args, **kwargs)-> None :
def eUInt (self, *args, **kwargs)-> None :
'''None'''
...
def eVector, (self, *args, **kwargs)-> None :
def eVector (self, *args, **kwargs)-> None :
'''None'''
...

Expand Down Expand Up @@ -1433,6 +1438,9 @@ class IfcVariant(object):
def setVector (self, val: PyBrxBim.IfcVectorValue)-> None :
''' '''
...
def type (self)-> PyBrxBim.IfcValueType :
''' '''
...

class IfcVectorDesc(object):
def __init__ (self, *args, **kwargs)-> None :
Expand Down
19 changes: 13 additions & 6 deletions PySamples/PyBrxBim/importTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,22 @@ def onIfcProduct(self, context, entity, isParent, parentEntity):
self.m_onProductCalled = True
print("onIfcProduct")
if entity.isKindOf(Bim.IfcEntityDesc.IfcWindow()):
print(entity.getAttribute("OverallHeight"))
mat = context.getLocalPlacement(entity)
createBoxSolid(100.0, 100.0, 100.0, mat.getTranslation(), 1)
return True

# print(entity.IfcId())

# w = entity.getAttribute("OverallWidth")
# print("Width", w.type(), w.getReal())

# h = entity.getAttribute("OverallHeight")
# print("Height", h.type(), h.getReal())

#mat = context.getLocalPlacement(entity)
#createBoxSolid(100.0, 100.0, 100.0, mat.getTranslation(), 1)
return False
return True

except Exception as err:
traceback.print_exception(err)
finally:
return False

def beforeCompletion(self, context, success):
try:
Expand Down
61 changes: 61 additions & 0 deletions unitTests/UnitTestPyBcadBim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import os
import unittest
import math
import testcfg

import PyRx as Rx
import PyGe as Ge
import PyGi as Gi
import PyDb as Db
import PyAp as Ap
import PyEd as Ed
import PyBrxBim as Bm

host = Ap.Application.hostAPI()


class TestBCadBim(unittest.TestCase):
def __init__(self, *args, **kwargs):
super(TestBCadBim, self).__init__(*args, **kwargs)

def __del__(self):
pass

def test_IfcVariant(self):
v = Bm.IfcVariant()

v.setBool(True)
self.assertEqual(v.type(), Bm.IfcValueType.eBool)
self.assertEqual(v.getBool(), True)

v.setInt(42)
self.assertEqual(v.type(), Bm.IfcValueType.eInt)
self.assertEqual(v.getInt(), 42)

v.setUInt(44)
self.assertEqual(v.type(), Bm.IfcValueType.eUInt)
self.assertEqual(v.getUInt(), 44)

v.setReal(3.14)
self.assertEqual(v.type(), Bm.IfcValueType.eReal)
self.assertEqual(v.getReal(), 3.14)

vs = Bm.IfcString("OMG YAY")
v.setString(vs)
self.assertEqual(v.type(), Bm.IfcValueType.eString)
self.assertEqual(v.getString().c_str(), "OMG YAY")


def pybcbimtest():
try:
suite = unittest.TestLoader().loadTestsFromTestCase(TestBCadBim)
if testcfg.logToFile:
with open(testcfg.logFileName, "a") as f:
f.write("\n{:*^60s}\n".format("TestBricsCADBim"))
runner = unittest.TextTestRunner(f, verbosity=testcfg.testVerbosity)
runner.run(suite)
else:
print("TestBricsCADBim")
print(unittest.TextTestRunner(verbosity=testcfg.testVerbosity).run(suite))
except Exception as err:
print(err)
3 changes: 3 additions & 0 deletions unitTests/UnitTestRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

if "BRX" in host:
import UnitTestPyBcadCivil
import UnitTestPyBcadBim

print("\nadded command = runtests: ")

Expand All @@ -51,6 +52,7 @@ def OnPyReload() -> None:

if "BRX" in host:
importlib.reload(UnitTestPyBcadCivil)
importlib.reload(UnitTestPyBcadBim)

if not "BRX" in host:
importlib.reload(UnitTestDocString)
Expand Down Expand Up @@ -94,6 +96,7 @@ def PyRxCmd_runtests() -> None:

if "BRX" in host:
UnitTestPyBcadCivil.pybcciviltest()
UnitTestPyBcadBim.pybcbimtest()

if not "BRX" in host:
UnitTestDocString.docstringtester()
Expand Down

0 comments on commit 69ac003

Please sign in to comment.