Skip to content

Commit

Permalink
Fixed issue #66 - missing STEP transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jens M. Plonka committed Apr 28, 2023
1 parent 372beb8 commit 13f51a0
Show file tree
Hide file tree
Showing 8 changed files with 1,023 additions and 703 deletions.
1,043 changes: 541 additions & 502 deletions Acis.py

Large diffs are not rendered by default.

604 changes: 444 additions & 160 deletions Acis2Step.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions importerConstants.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@
DIR_Z = VEC(0, 0, 1)

ENCODING_FS = 'utf8'

EPS = 1.0e-6
35 changes: 17 additions & 18 deletions importerFreeCAD.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# -*- coding: utf-8 -*-

__author__ = 'Jens M. Plonka'
__copyright__ = 'Copyright 2023, Germany'
__url__ = "https://www.github.com/jmplonka/InventorLoader"

'''
importerFreeCAD.py
'''
import sys, FreeCAD, Draft, Part, Sketcher, traceback, Mesh, InventorViewProviders, Acis, re
import FreeCAD, Draft, Part, Sketcher, traceback, Mesh, InventorViewProviders, Acis, re

from importerClasses import *
from importerUtils import *
from importerSegNode import SecNode, SecNodeRef, setParameter
from math import sqrt, tan, degrees, pi
from FreeCAD import Vector as VEC, Rotation as ROT, Placement as PLC, Version, ParamGet
from math import sqrt, tan, degrees, pi, asin
from FreeCAD import Vector as VEC, Rotation as ROT, Placement as PLC, ParamGet
from importerConstants import CENTER, DIR_X, DIR_Y, DIR_Z

__author__ = 'Jens M. Plonka'
__copyright__ = 'Copyright 2018, Germany'
__url__ = "https://www.github.com/jmplonka/InventorLoader"

BIT_GEO_ALIGN_HORIZONTAL = 1 << 0
BIT_GEO_ALIGN_VERTICAL = 1 << 1
BIT_GEO_BEND = 1 << 2
Expand Down Expand Up @@ -162,7 +162,7 @@ def newObject(className, name, body = None):
body.addObject(obj)
except:
obj.adjustRelativeLinks(body)
body.ViewObject.dropObject(obj, None, '', [])
body.ViewObject.dropObject(obj, None, name, [])
return obj

def createGroup(name):
Expand Down Expand Up @@ -282,11 +282,10 @@ def getDimension(node, varName):
dimension = node.get(varName)

if (dimension.typeName == 'Line2D'):
dimension = DimensionValue(Length(getLengthLine(dimension)))
dimension = Length(getLengthLine(dimension))
elif (dimension.typeName == 'Point2D'):
dimension = DimensionValue(Length(0))

if (dimension.typeName != 'Parameter'):
dimension = Length(0)
elif (dimension.typeName != 'Parameter'):
logError(u"Expected Dimension for (%04X): %s - NOT %s", node.index, node.typeName, dimension.typeName)

return dimension
Expand Down Expand Up @@ -528,7 +527,7 @@ def adjustFxColor(entity, nodColor):
return

def __hide__(geo):
if (geo is not None):
if (geo):
geo.ViewObject.Visibility = False
return

Expand Down Expand Up @@ -832,7 +831,7 @@ def findBase(self, base):
if (name in self.bodyNodes):
baseGeo = self.getGeometry(self.bodyNodes[name])
if (baseGeo is None):
logWarning(u" Base2 (%04X): %s -> (%04X): %s can't be created!", base.index, baseNode.typeName, bodyNode.index, bodyNode.typeName)
logWarning(u" Base2 = '%s' -> (%04X): %s can't be created!", name, base.index, base.typeName)
else:
logInfo(u" ... Base2 = '%s'", name)
else:
Expand Down Expand Up @@ -860,7 +859,7 @@ def findGeometries(self, node):
# ensure that the sketch is already created!
toolGeo = self.getGeometry(self.bodyNodes[name])
if (toolGeo is None):
logWarning(u" Tool (%04X): %s -> (%04X): %s can't be created", node.index, node.typeName, toolData.index, toolData.typeName)
logWarning(u" Tool = '%s' -> (%04X): %s can't be created", name, node.index, node.typeName)
else:
geometries.append(toolGeo)
logInfo(u" ... Tool = '%s'", name)
Expand Down Expand Up @@ -1429,12 +1428,12 @@ def addSketch_Geometric_SymmetryPoint2D(self, constraintNode, sketchObj):

if ((lineIdx is None) or (lineIdx < 0)):
logWarning(u" ... can't added symmetric constraint between Point and %s - no line index for (%04X)!", moving.typeName[0:-2], moving.index)
elif ((symmetryIdx is None) or (symmetryIdx < 0) or (symmetryPos < -1)):
elif ((symmetryIdx is None) or (symmetryIdx < 0) or (symmetryIdx < -1)):
logWarning(u" ... can't added symmetric constraint between Point and %s - no point index for (%04X)!", moving.typeName[0:-2], constraintNode.get('point').index)
else:
key = 'SymmetryPoint_%s_%s' %(lineIdx, symmetryIdx)
if (not key in self.mapConstraints):
constraint = Sketcher.Constraint('Symmetric', lineIdx, 1, lineIdx, 2, symmetryIdx, symmetryPos)
constraint = Sketcher.Constraint('Symmetric', lineIdx, 1, lineIdx, 2, symmetryIdx, symmetryIdx)
index = self.addConstraint(sketchObj, constraint, key)
constraintNode.setGeometry(constraint, index)
logInfo(u" ... added symmetric constraint between Point %s and %s %s", symmetryIdx, moving.typeName[0:-2], lineIdx)
Expand Down Expand Up @@ -2714,7 +2713,7 @@ def Create_FxClient(self, clientNode):
# create a subfolder
name = InventorViewProviders.getObjectName(clientNode.name)
if ((name is None) or (len(name) == 0)):
name = node.typeName
name = clientNode.typeName

fx = createGroup(name)
# add/move all objects to this folder
Expand Down
4 changes: 2 additions & 2 deletions importerReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Simple approach to read/analyse Autodesk (R) Invetor (R) files.
'''

import sys, os, uuid, datetime, re, zlib, operator, glob, struct, codecs, xlrd, FreeCAD, Import_IPT, importerOle10Nateive
import zlib, codecs, xlrd, importerOle10Nateive
from importerClasses import *
from importerSegment import SegmentReader
from importerApp import AppReader
Expand Down Expand Up @@ -253,7 +253,7 @@ def ReadProtein(data):

def ReadWorkbook(data, name, stream):
dumpFolder = getDumpFolder()
if (not (dumpFolder is None)):
if (dumpFolder):
##create a new Spreadsheet in new document
wbk = xlrd.book.open_workbook_xls(file_contents=data, formatting_info=True)
for nameValues in wbk.name_obj_list:
Expand Down
23 changes: 11 additions & 12 deletions importerSAT.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
Collection of classes necessary to read and analyse Autodesk (R) Invetor (R) files.
'''

import os, sys, tokenize, FreeCAD, Part, re, traceback, datetime, ImportGui, io
from importerUtils import logInfo, logWarning, logError, logAlways, getUInt8A, getUInt32, chooseImportStrategyAcis, STRATEGY_SAT, STRATEGY_NATIVE, STRATEGY_STEP, setDumpFolder, getDumpFolder
from msilib import CreateRecord
import os, FreeCAD, Part, ImportGui, io
from importerUtils import logInfo, logAlways, chooseImportStrategyAcis, STRATEGY_SAT, STRATEGY_NATIVE, STRATEGY_STEP, setDumpFolder, getDumpFolder
from Acis2Step import export
from math import fabs
from Acis import TAG_ENTITY_REF, getReader, setReader, AcisReader, AcisChunkPosition, setVersion, createNode, init
from Acis import TAG_ENTITY_REF, getReader, setReader, AcisReader, createEntity, init

__author__ = 'Jens M. Plonka'
__copyright__ = 'Copyright 2018, Germany'
Expand Down Expand Up @@ -127,12 +127,12 @@ def resolveNodes(acis):
if (getDumpFolder()[-3:].lower() != 'sat'):
name = _getSatFileName(acis.name)
dumpSat(name, acis)
for entity in acis.getEntities():
node = createNode(entity)
if (node):
if (doAdd and (entity.name == 'body')):
bodies.append(node)
if (entity.name in ['Begin-of-ACIS-History-Data', 'End-of-ACIS-data']):
for record in acis.getRecords():
entity = createEntity(record)
if entity:
if (doAdd and (record.name == 'body')):
bodies.append(entity)
if (record.name in ['Begin-of-ACIS-History-Data', 'End-of-ACIS-data']):
doAdd = False

return bodies
Expand Down Expand Up @@ -187,7 +187,6 @@ def create3dModel(group, doc):
def dumpSat(name, acis, use_dump_folder = True):
header = acis.header
history = acis.history
entities = acis.getEntities()
dumpFolder = getDumpFolder()
historyIdx = None

Expand All @@ -201,7 +200,7 @@ def dumpSat(name, acis, use_dump_folder = True):
satFile = name
with io.open(satFile, 'wt', encoding='utf-8') as sat:
sat.write(header.__str__())
for record in entities:
for record in acis.getRecords():
if (record.index == historyIdx):
sat.write(u"%r\n"%(history.getRecord()))
for ds in history.delta_states:
Expand Down
6 changes: 3 additions & 3 deletions importerSegment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from importerTransformation import Transformation2D, Transformation3D
from importerSegNode import isList, CheckList, SecNode, SecNodeRef, _TYP_NODE_REF_, _TYP_UINT32_A_, REF_PARENT, REF_CHILD, REF_CROSS
from importerUtils import *
from Acis import clearEntities, AcisReader, setVersion, TAG_ENTITY_REF, getInteger, createNode, getNameMatchAttributes, getDcAttributes
from Acis import clearEntities, AcisReader, setVersion, TAG_ENTITY_REF, createEntity, getNameMatchAttributes, getDcAttributes
from importerSAT import dumpSat
from uuid import UUID
import importerUtils
Expand All @@ -28,8 +28,8 @@ def resolveEntityReferences(node):
acis = node.get('SAT')
try:
# create a node for each entity
for entity in acis.getEntities():
createNode(entity)
for record in acis.getRecords():
createEntity(record)

dumpSat("%04X" %(node.index), acis)
# resolve the roll-back information from the history
Expand Down
9 changes: 3 additions & 6 deletions importerUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from struct import Struct, unpack_from, pack
from FreeCAD import Vector as VEC, Console, ParamGet
from olefile import OleFileIO
from importerConstants import ENCODING_FS
from importerConstants import ENCODING_FS, CENTER

__author__ = 'Jens M. Plonka'
__copyright__ = 'Copyright 2018, Germany'
Expand Down Expand Up @@ -232,6 +232,7 @@ def setAuthor(author):
return

def getAuthor():
global _author
return _author

def setCompany(company):
Expand Down Expand Up @@ -924,11 +925,7 @@ def PrintableName(fname):
def decode(filename, utf=False):
if (isinstance(filename, unicode)):
# workaround since ifcopenshell currently can't handle unicode filenames
if (utf):
encoding = "utf8"
else:
import sys
encoding = sys.getfilesystemencoding()
encoding = ENCODING_FS if (utf) else sys.getfilesystemencoding()
filename = filename.encode(encoding).decode("utf-8")
return filename

Expand Down

1 comment on commit 13f51a0

@marcocecchiscmgroup
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recently discovered that translations only happen to have rotation axis = (0, 0, 0), which cannot be normalized. Please add this defensive check:

	if transformation.Rotation.Axis.length() < EPS:
		zDir = DIR_Z
		xDir = DIR_X
	else:
		zDir = DIR_Z.rotate(transformation.Rotation.axis(), transformation.Rotation.angle())
		xDir = DIR_X.rotate(transformation.Rotation.axis(), transformation.Rotation.angle())

Please sign in to comment.