Skip to content

Commit

Permalink
Merge branch 'developement'
Browse files Browse the repository at this point in the history
  • Loading branch information
evereux committed May 20, 2024
2 parents 231e29b + 3b961c3 commit e42921d
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 79 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 0.6.9

* added the following document types that can be created with Document.add():
'Analysis', 'CatalogDocument', 'CATMaterial', 'CATProcess', 'cgm'
'FeatureDictionary', 'gl', 'gl2', 'hpgl', 'FunctionalSystem', 'ProcessLibrary'
* Rewrote how document types are detected and tested for. This makes adding
additional document types easier.
* fixed HybridShapeExtrapol.support. @HyberCa
* fixed HybridShapeAxisLine.element.


## 0.6.8

* added option to initialise the Application object with pythoncom.CoInitialize().
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ deloarts

hitman061

HyberCa

hoangminhq5310

Luanee
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __getattr__(cls, name):
author = 'Paul Bourne'

# The short X.Y version
version = '0.6.8'
version = '0.6.9'
# The full version, including alpha/beta/rc tags
release = version

Expand Down
3 changes: 2 additions & 1 deletion pycatia/dnb_human_modeling_interfaces/swk_hmi_workbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ def create_right_forearm(

def new_human_catalog(self) -> SWKHumanCatalog:
"""
.. note::
.. note::
:class: toggle
Microsoft Visual Basic Object Browser
Expand Down
2 changes: 1 addition & 1 deletion pycatia/hybrid_shape_interfaces/hybrid_shape_axis_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def element(self, value: Reference):
:param Reference value:
"""

self.hybrid_shape_axis_line.Element = value
self.hybrid_shape_axis_line.Element = value.com_object

def __repr__(self):
return f'HybridShapeAxisLine(name="{ self.name }")'
2 changes: 1 addition & 1 deletion pycatia/hybrid_shape_interfaces/hybrid_shape_extrapol.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def support(self, value: Reference):
:param Reference value:
"""

self.hybrid_shape_extrapol.Support = value
self.hybrid_shape_extrapol.Support = value.com_object

def get_boundary(self, i_pos: int) -> Reference:
"""
Expand Down
10 changes: 7 additions & 3 deletions pycatia/in_interfaces/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from pycatia.system_interfaces.any_object import AnyObject
from pycatia.system_interfaces.system_service import SystemService
from pycatia.in_interfaces.setting_controllers import SettingControllers
from pycatia.types.document_types import document_type
from pycatia.types.document import document_types


class Application(AnyObject):
Expand Down Expand Up @@ -92,8 +92,12 @@ def active_document(self) -> Document:
"""
try:
active_doc_com = self.com_object.ActiveDocument
doc_suffix = active_doc_com.Name.split('.')[-1]
return document_type[doc_suffix](active_doc_com)
extension = active_doc_com.Name.split('.')[-1]
types = [document_types[k]['type'] for k in (document_types) if document_types[k]['extension'] == extension]
if len(types) > 1:
raise CATIAApplicationException('There was a problem determining the document type.')
document_type = types[0]
return document_type(active_doc_com)
except com_error:
raise CATIAApplicationException('Is there an active document?')

Expand Down
15 changes: 7 additions & 8 deletions pycatia/in_interfaces/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
from pycatia.exception_handling import CATIAApplicationException
from pycatia.in_interfaces.document import Document
from pycatia.system_interfaces.collection import Collection
from pycatia.types.document_types import document_type
from pycatia.types.document import document_types
from pycatia.types.general import cat_variant, list_str
from pycatia.scripts.document_types import get_document_type


class Documents(Collection):
Expand Down Expand Up @@ -87,14 +86,14 @@ def add(self, document_type) -> Document:
:rtype: Document
"""

# document_types string must be one of these types:
# 'Part', 'Product', 'Drawing', 'FunctionalSystem', 'CATMaterial', 'CatalogDocument'
# see pycatia.types.docs for supported Documents.

dt = get_document_type(document_type)
if document_type.lower() not in [t.lower() for t in document_types]:
raise CATIAApplicationException(f'Document type {document_type} not supported. Allowed types are {[t for t in document_types]}.')

self.logger.info(f'Creating a new "{dt}".')
document = document_types[document_type]['type']

return Document(self.documents.Add(dt))
return document(self.documents.Add(document_type))

def count_types(self, file_type_list: list_str) -> int:
"""
Expand Down Expand Up @@ -307,7 +306,7 @@ def read(self, file_name: str) -> Document:

read_doc_com = self.documents.Read(file_name)
doc_suffix = file_name.split('.')[-1]
return document_type[doc_suffix](read_doc_com)
return document_types[doc_suffix](read_doc_com)

def __getitem__(self, n: int) -> Document:
if (n + 1) > self.count:
Expand Down
38 changes: 0 additions & 38 deletions pycatia/scripts/document_types.py

This file was deleted.

69 changes: 69 additions & 0 deletions pycatia/types/document.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from pycatia.analysis_interfaces.analysis_document import AnalysisDocument
from pycatia.components_catalogs_interfaces.catalog_document import CatalogDocument
from pycatia.cat_mat_interfaces.material_document import MaterialDocument
from pycatia.dmaps_interfaces.process_document import ProcessDocument
from pycatia.drafting_interfaces.drawing_document import DrawingDocument
from pycatia.in_interfaces.document import Document
from pycatia.mec_mod_interfaces.part_document import PartDocument
from pycatia.product_structure_interfaces.product_document import ProductDocument
from pycatia.funct_system_interfaces.functional_document import FunctionalDocument


document_types = {
'Analysis': {
'extension': 'CATAnalysis',
'type': AnalysisDocument,
},
'CatalogDocument': {
'extension': 'catalog',
'type': CatalogDocument,
},
'CATMaterial': {
'extension': 'CATMaterial',
'type': MaterialDocument,
},
'CATProcess': {
'extension': 'CATProcess',
'type': ProcessDocument,
},
'cgm': {
'extension': 'cgm',
'type': Document,
},
'Drawing': {
'extension': 'CATDrawing',
'type': DrawingDocument,
},
'FeatureDictionary': {
'extension': 'CATfct',
'type': Document
},
'gl': {
'extension': 'gl',
'type': Document,
},
'gl2': {
'extension': 'gl2',
'type': Document,
},
'hpgl': {
'extension': 'hpgl',
'type': Document
},
'FunctionalSystem': {
'extension': 'CATSystem',
'type': FunctionalDocument,
},
'Part': {
'extension': 'CATPart',
'type': PartDocument,
},
'Product': {
'extension': 'CATProduct',
'type': ProductDocument
},
'ProcessLibrary': {
'extension': 'act',
'type': ProcessDocument,
}
}
13 changes: 0 additions & 13 deletions pycatia/types/document_types.py

This file was deleted.

2 changes: 1 addition & 1 deletion pycatia/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "0.6.8"
version = "0.6.9"
40 changes: 28 additions & 12 deletions tests/in/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pycatia.base_interfaces.context import CATIADocHandler
from pycatia.mec_mod_interfaces.part_document import PartDocument
from pycatia.product_structure_interfaces.product_document import ProductDocument
from pycatia.types.document import document_types
from tests.common_vars import caa
from tests.source_files import cat_part_measurable
from tests.source_files import cat_product
Expand Down Expand Up @@ -37,27 +38,42 @@ def test_activate_document():
document_product.close()


def test_add_documents():
with CATIADocHandler(new_document="Part") as caa:
def test_add_document():

with CATIADocHandler(new_document='Analysis') as caa:
document = caa.document
assert document is not None
assert document_types['Analysis']['extension'] in document.name

with CATIADocHandler(new_document='CatalogDocument') as caa:
document = caa.document
assert document is not None
assert "CATPart" in document.name
assert document_types['CatalogDocument']['extension'] in document.name

with CATIADocHandler(new_document="Part") as caa:
with CATIADocHandler(new_document='Drawing') as caa:
document = caa.document
assert document is not None
assert document_types['Drawing']['extension'] in document.name

with CATIADocHandler(new_document='CATProcess') as caa:
document = caa.document
assert document is not None
assert "CATPart" in document.name
assert document_types['CATProcess']['extension'] in document.name

with CATIADocHandler(new_document="Part") as caa:
with CATIADocHandler(new_document='FeatureDictionary') as caa:
document = caa.document
assert document is not None
assert "CATPart" in document.name
assert document_types['FeatureDictionary']['extension'] in document.name

# commented out due to failing tests and I can't remember why this was added
# in the first place ...
# with pytest.raises(ValueError):
# with CATIADocHandler(new_document='lala'):
# pass
with CATIADocHandler(new_document='Part') as caa:
document = caa.document
assert document is not None
assert document_types['Part']['extension'] in document.name

with CATIADocHandler(new_document='Product') as caa:
document = caa.document
assert document is not None
assert document_types['Product']['extension'] in document.name


def test_count_types():
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e42921d

Please sign in to comment.