2023-07-04 07:19:55 +00:00
|
|
|
import os
|
2024-02-02 14:22:21 +00:00
|
|
|
from extensions.list import CoreList
|
|
|
|
from extensions.dict import CoreDict
|
|
|
|
from helpers.freecadtest import FreeCadASPGenerationTestController
|
|
|
|
from models.adjacency_matrix_model import (
|
|
|
|
AdjacencyMatrixModel,
|
|
|
|
)
|
|
|
|
from usecases.check_object_has_touches_use_case import (
|
|
|
|
CheckObjectHasTouchesUseCase,
|
|
|
|
)
|
|
|
|
from usecases.clusterisation_sequences_use_case import (
|
|
|
|
ClusterisationSequenceUseCase,
|
|
|
|
)
|
|
|
|
from usecases.check_sequence_use_case import (
|
|
|
|
CheckSequenceUsecase,
|
|
|
|
)
|
|
|
|
from usecases.env_reader_use_case import (
|
|
|
|
EnvReaderUseCase,
|
|
|
|
)
|
|
|
|
from usecases.exit_freecad_use_case import (
|
|
|
|
ExitFreeCadUseCase,
|
|
|
|
)
|
|
|
|
from usecases.intersection_geometry_use_case import (
|
|
|
|
IntersectionGeometryUseCase,
|
|
|
|
)
|
|
|
|
from usecases.open_freecad_document_use_case import (
|
|
|
|
OpenFreeCadDocumentUseCase,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
from mocks.mock_structure import bottle_jack_mock_structure, simple_cube_mock_structure
|
2024-01-18 10:44:59 +00:00
|
|
|
|
|
|
|
|
2023-07-04 07:19:55 +00:00
|
|
|
def main():
|
2024-01-18 10:44:59 +00:00
|
|
|
try:
|
|
|
|
EnvReaderUseCase.call().either(
|
|
|
|
leftF=lambda environment: (
|
|
|
|
OpenFreeCadDocumentUseCase.call(environment.cadFilePath).either(
|
|
|
|
leftF=lambda _: (
|
2024-02-02 14:22:21 +00:00
|
|
|
(
|
|
|
|
CheckObjectHasTouchesUseCase()
|
|
|
|
.call(environment.solidBodyPadding)
|
|
|
|
.either(
|
|
|
|
leftF=lambda adjaxedMatrix: (
|
|
|
|
adjaxedMatrix.sequencesToFileSystem(
|
|
|
|
environment.outPath,
|
|
|
|
environment.sequencesFixed,
|
|
|
|
),
|
|
|
|
IntersectionGeometryUseCase.call(
|
|
|
|
adjaxedMatrix.matrixGetUniqueContact(),
|
|
|
|
environment.outPath,
|
2024-01-18 10:44:59 +00:00
|
|
|
),
|
2024-02-02 14:22:21 +00:00
|
|
|
adjaxedMatrix.matrixToFileSystem(
|
|
|
|
environment.outPath,
|
2024-01-18 10:44:59 +00:00
|
|
|
),
|
2024-02-02 14:22:21 +00:00
|
|
|
ClusterisationSequenceUseCase(environment.outPath),
|
|
|
|
ExitFreeCadUseCase.call(),
|
|
|
|
),
|
|
|
|
rightF=lambda error: error.toFileSystem(
|
|
|
|
environment.outPath
|
2024-01-18 10:44:59 +00:00
|
|
|
),
|
|
|
|
),
|
2024-02-02 14:22:21 +00:00
|
|
|
)
|
2024-01-18 10:44:59 +00:00
|
|
|
),
|
|
|
|
rightF=lambda error: print(error),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
rightF=lambda error: print(error),
|
|
|
|
)
|
|
|
|
|
|
|
|
except Exception as error:
|
|
|
|
print(error)
|
|
|
|
ExitFreeCadUseCase.call()
|
|
|
|
|
|
|
|
|
|
|
|
# main()
|
|
|
|
|
|
|
|
|
|
|
|
def test():
|
|
|
|
try:
|
|
|
|
mocksFolder = os.path.dirname(__file__) + "/mocks/"
|
2024-02-02 14:22:21 +00:00
|
|
|
|
2024-01-18 10:44:59 +00:00
|
|
|
outFolder = os.path.dirname(__file__) + "/out/"
|
|
|
|
|
2024-02-02 14:22:21 +00:00
|
|
|
FreeCadASPGenerationTestController("test adjaxed matrix simple cube").test(
|
|
|
|
assertFn=lambda model: CoreList(model.all_parts).equal(
|
|
|
|
simple_cube_mock_structure
|
|
|
|
),
|
|
|
|
execComposition=lambda _: (
|
|
|
|
CheckObjectHasTouchesUseCase()
|
|
|
|
.call(0)
|
|
|
|
.either(
|
|
|
|
leftF=lambda matrix: matrix.matrixToFileSystem(outFolder),
|
|
|
|
rightF=lambda error: print(error),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
documentPath=mocksFolder + "simple_assembly_with_two_cubes.FCStd",
|
|
|
|
modelName=AdjacencyMatrixModel.fileName,
|
|
|
|
model=AdjacencyMatrixModel,
|
|
|
|
)
|
2024-01-18 10:44:59 +00:00
|
|
|
|
|
|
|
FreeCadASPGenerationTestController(
|
|
|
|
"test adjaxed matrix vs structure of document"
|
|
|
|
).test(
|
|
|
|
assertFn=lambda model: CoreDict(model.matrix).isEquivalentByKeys(
|
2024-02-02 14:22:21 +00:00
|
|
|
bottle_jack_mock_structure
|
2024-01-18 10:44:59 +00:00
|
|
|
),
|
|
|
|
execComposition=lambda _: (
|
|
|
|
CheckObjectHasTouchesUseCase()
|
|
|
|
.call(0)
|
|
|
|
.either(
|
|
|
|
leftF=lambda matrix: matrix.matrixToFileSystem(outFolder),
|
|
|
|
rightF=lambda error: print(error),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
documentPath=mocksFolder + "bottle_jack.FCStd",
|
2024-02-02 14:22:21 +00:00
|
|
|
modelName=AdjacencyMatrixModel.fileName,
|
|
|
|
model=AdjacencyMatrixModel,
|
2024-01-18 10:44:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
FreeCadASPGenerationTestController(
|
|
|
|
"test adjacency matrix keys vs allparts"
|
|
|
|
).test(
|
|
|
|
assertFn=lambda model: CoreDict(model.matrix).isMatchByKeys(
|
2024-02-02 14:22:21 +00:00
|
|
|
model.all_parts
|
2024-01-18 10:44:59 +00:00
|
|
|
),
|
|
|
|
execComposition=lambda _: (
|
|
|
|
CheckObjectHasTouchesUseCase()
|
|
|
|
.call(0)
|
|
|
|
.either(
|
2024-02-02 14:22:21 +00:00
|
|
|
leftF=lambda matrix: (matrix.matrixToFileSystem(outFolder)),
|
2024-01-18 10:44:59 +00:00
|
|
|
rightF=lambda error: print(error),
|
|
|
|
)
|
|
|
|
),
|
2024-02-02 14:22:21 +00:00
|
|
|
documentPath=mocksFolder + "bottle_jack.FCStd",
|
|
|
|
modelName=AdjacencyMatrixModel.fileName,
|
|
|
|
model=AdjacencyMatrixModel,
|
|
|
|
)
|
|
|
|
|
|
|
|
FreeCadASPGenerationTestController("test all parts vs assembly sequence").test(
|
|
|
|
assertFn=lambda model: CheckSequenceUsecase(
|
|
|
|
ClusterisationSequenceUseCase(outFolder)
|
|
|
|
).isCorrectByParts(model.all_parts),
|
|
|
|
execComposition=lambda _: (
|
|
|
|
CheckObjectHasTouchesUseCase()
|
|
|
|
.call(0)
|
|
|
|
.either(
|
|
|
|
leftF=lambda matrix: (
|
|
|
|
matrix.matrixToFileSystem(outFolder),
|
|
|
|
ClusterisationSequenceUseCase(outFolder),
|
|
|
|
),
|
|
|
|
rightF=lambda error: print(error),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
documentPath=mocksFolder + "bottle_jack.FCStd",
|
|
|
|
modelName=AdjacencyMatrixModel.fileName,
|
|
|
|
model=AdjacencyMatrixModel,
|
2024-01-18 10:44:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
ExitFreeCadUseCase.call()
|
2024-02-02 14:22:21 +00:00
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
2024-01-18 10:44:59 +00:00
|
|
|
print("test error")
|
|
|
|
ExitFreeCadUseCase.call()
|
|
|
|
pass
|
2023-12-17 13:58:43 +00:00
|
|
|
|
|
|
|
|
2024-01-18 10:44:59 +00:00
|
|
|
test()
|