15
15
16
16
from importerUtils import *
17
17
from FreeCAD import Vector as VEC , Placement as PLC , Matrix as MAT , Base
18
- from math import pi , fabs , degrees , asin , sin , cos , tan , atan2 , ceil , e , cosh , sinh , tanh , acos , acosh , asin , asinh , atan , atanh , log , sqrt , exp , log10
18
+ from math import inf , pi , fabs , degrees , asin , sin , cos , tan , atan2 , ceil , e , cosh , sinh , tanh , acos , acosh , asin , asinh , atan , atanh , log , sqrt , exp , log10
19
19
from importerConstants import MIN_0 , MIN_PI , MIN_PI2 , MIN_INF , MAX_2PI , MAX_PI , MAX_PI2 , MAX_INF , MAX_LEN , CENTER , DIR_X , DIR_Y , DIR_Z , ENCODING_FS
20
20
21
21
V2D = Base .Vector2d
@@ -91,7 +91,7 @@ def __build_bool_enum__(false_value, true_value, true_key = 'T'):
91
91
_nameMtchAttr = {}
92
92
_dcIdxAttributes = {} # dict of an attribute list
93
93
94
- LENGTH_TEXT = re .compile ('[ \t ]*(\d+) +(.*)' )
94
+ LENGTH_TEXT = re .compile ('[ \t ]*(\\ d+) +(.*)' )
95
95
96
96
TOKEN_TRANSLATIONS = {
97
97
'0x0a' : TAG_TRUE ,
@@ -410,8 +410,11 @@ def getFloats(chunks, index, count):
410
410
arr += chunk .val
411
411
n += len (chunk .val )
412
412
else :
413
- arr .append (float (chunk .val ))
414
- n += 1
413
+ try :
414
+ arr .append (float (chunk .val ))
415
+ n += 1
416
+ except Exception as ex :
417
+ raise (ex )
415
418
return arr , i
416
419
417
420
def getFloatsScaled (chunks , index , count ):
@@ -890,7 +893,7 @@ def createBSplinesPCurve(pcurve, surface, sense):
890
893
shape .Orientation = str ('Reversed' ) if (sense == 'reversed' ) else str ('Forward' )
891
894
return shape
892
895
893
- def createBSplinesCurve (nubs , sense ):
896
+ def createBSplinesCurve (nubs , sense , subtype ):
894
897
if (nubs is None ):
895
898
return None
896
899
number_of_poles = len (nubs .poles )
@@ -920,7 +923,7 @@ def createBSplinesCurve(nubs, sense):
920
923
# periodic = nubs.uPeriodic
921
924
shape = bsc .toShape ()
922
925
except Exception as e :
923
- logError ( traceback . format_exc ( ))
926
+ logWarning ( "Can't create BSpline-Curve for suptype '%s'!" % ( subtype ))
924
927
if (shape is not None ):
925
928
shape .Orientation = str ('Reversed' ) if (sense == 'reversed' ) else str ('Forward' )
926
929
return shape
@@ -1333,6 +1336,12 @@ def calcPoint(u, min_U, a, r_maj, r_min, handed, pitch):
1333
1336
return VEC (x , y , z )
1334
1337
1335
1338
def build (self ):
1339
+ # TODO: see InporterViewProvider._Coil._makeHelix(self, coil) instead:
1340
+ # line = Part.Line(self.posCenter, self.posCenter + self.vecAxis)
1341
+ # radius = line.projectPoint(self.Profile.Shape.CenterOfMass, "LowerDistance")
1342
+ # helix = Part.makeLongHelix(slef.getPitch(), self.getHeight(), self.getRadius(), self.getApexAngle(), self.isLeftHanded())
1343
+ # self.pathWires.append(helix)
1344
+
1336
1345
min_U = self .radAngles .getLowerLimit ()
1337
1346
max_U = self .radAngles .getUpperLimit ()
1338
1347
r_maj = self .dirMajor .Length
@@ -1806,7 +1815,9 @@ def getLoop(self): return None if (self._loop is None) else self._loop.ent
1806
1815
def getParent (self ): return None if (self ._parent is None ) else self ._parent .entity
1807
1816
def getSurface (self ):
1808
1817
if (self ._surface ):
1809
- return self ._surface .entity .getSurface ()
1818
+ if (self ._surface .entity .subtype == 'ref' ):
1819
+ return self ._surface .entity .getSurface ()
1820
+ return self ._surface .entity
1810
1821
return None
1811
1822
def buildCoEdges (self ):
1812
1823
edges = []
@@ -1820,27 +1831,25 @@ def build(self):
1820
1831
self .__ready_to_build__ = False
1821
1832
edges = self .buildCoEdges ()
1822
1833
if (self ._surface ):
1823
- _surface = self .getSurface ()
1824
- if (_surface ):
1825
- surface = self .getSurface ().build ()
1826
- if (surface ):
1827
- if (self .sense == 'reversed' ):
1828
- surface .reverse ()
1829
- if (len (edges ) > 0 ):
1830
- tolerance = 0.1
1831
- component , elements = surface .generalFuse (edges , tolerance )
1832
- faces = elements [0 ]
1833
- if (len (faces ) == 0 ):
1834
- logWarning ("Can't apply wires for face (no elements) for %s" % (self ._surface ))
1835
- else :
1836
- self .shape = eliminateOuterFaces (faces , edges )
1837
- if (self .shape is None ):
1838
- # edges can be empty because not all edges can be created right now :(
1839
- logWarning ("Can't apply wires for face %s!" % (surface .Surface ))
1840
- for f in faces :
1841
- Part .show (f , "Face-%d" % (self .record .index ))
1834
+ surface = self .getSurface ().build ()
1835
+ if (surface ):
1836
+ if (self .sense == 'reversed' ):
1837
+ surface .reverse ()
1838
+ if (len (edges ) > 0 ):
1839
+ tolerance = 0.1
1840
+ component , elements = surface .generalFuse (edges , tolerance )
1841
+ faces = elements [0 ]
1842
+ if (len (faces ) == 0 ):
1843
+ logWarning ("Can't apply wires for face (no elements) for %s" % (self ._surface ))
1842
1844
else :
1843
- self .shape = surface
1845
+ self .shape = eliminateOuterFaces (faces , edges )
1846
+ if (self .shape is None ):
1847
+ # edges can be empty because not all edges can be created right now :(
1848
+ logWarning ("Can't apply wires for face %s!" % (surface .Surface ))
1849
+ for f in faces :
1850
+ Part .show (f , "Face-%d" % (self .record .index ))
1851
+ else :
1852
+ self .shape = surface
1844
1853
return self .shape
1845
1854
def isCone (self ): return isinstance (self .getSurface (), SurfaceCone )
1846
1855
def isMesh (self ): return isinstance (self .getSurface (), SurfaceMesh )
@@ -2616,7 +2625,7 @@ def setSubtype(self, chunks, index):
2616
2625
def build (self , start = None , end = None ):
2617
2626
if (self .__ready_to_build__ ):
2618
2627
self .__ready_to_build__ = False
2619
- self .shape = createBSplinesCurve (self .spline , self .sense )
2628
+ self .shape = createBSplinesCurve (self .spline , self .sense , self . subtype )
2620
2629
2621
2630
if (self .subtype == 'ref' ):
2622
2631
cur = self .curve
@@ -2772,11 +2781,17 @@ def build(self, start, end):
2772
2781
if (start is None ):
2773
2782
start = self .root
2774
2783
elif (type (start ) == float ):
2775
- start = line .value (start )
2784
+ if (start == inf or start == - inf ):
2785
+ start = self .root
2786
+ else :
2787
+ start = line .value (start )
2776
2788
if (end is None ):
2777
2789
end = self .dir + self .root
2778
2790
elif (type (end ) == float ):
2779
- end = line .value (end )
2791
+ if (end == inf or end == - inf ):
2792
+ end = self .root + self .dir
2793
+ else :
2794
+ end = line .value (end )
2780
2795
self .shape = createLine (start , end )
2781
2796
return self .shape
2782
2797
@@ -2809,6 +2824,7 @@ def __init__(self):
2809
2824
self .sense = 'forward'
2810
2825
self .urange = Interval (Range ('I' , MIN_0 ), Range ('I' , MAX_2PI ))
2811
2826
self .vrange = Interval (Range ('I' , MIN_INF ), Range ('I' , MAX_INF ))
2827
+ self .apex = None
2812
2828
def getSatTextGeometry (self , index ):
2813
2829
if (getVersion () >= 4.0 ):
2814
2830
return "%s %s %s %g %s %g %g %g %s %s %s #" % (
@@ -2851,7 +2867,7 @@ def setSubtype(self, chunks, index):
2851
2867
self .sense , i = getEnumByTag (chunks , i , SENSE )
2852
2868
self .urange , i = getInterval (chunks , i , MIN_0 , MAX_2PI , 1.0 )
2853
2869
self .vrange , i = getInterval (chunks , i , MIN_INF , MAX_INF , getScale ())
2854
- if (self .sine == 0. ):
2870
+ if (isEqual1D ( self .sine , 0. )): # 90 Deg
2855
2871
self .apex = None
2856
2872
else :
2857
2873
h = self .major .Length / tan (asin (self .sine ))
@@ -2968,10 +2984,12 @@ def __init__(self, data, values):
2968
2984
self ._ec = []
2969
2985
self ._0m = []
2970
2986
self ._0g = []
2987
+ self ._100edges = []
2971
2988
self ._100verts = []
2972
2989
self ._105sym = []
2973
2990
self ._105plane = []
2974
2991
self ._105a = []
2992
+ self ._106ek = []
2975
2993
self ._50000grip = []
2976
2994
def parse_degree (self ): self .header [self .values [0 ]] = self .values [1 ]
2977
2995
def parse_cap_type (self ): self .header [self .values [0 ]] = self .values [1 ]
@@ -2989,6 +3007,7 @@ def parse_l(self): self._l.append(self.values[1:])
2989
3007
def parse_ec (self ): self ._ec .append (self .values [1 :])
2990
3008
def parse_0m (self ): self ._0m .append (self .values [1 :])
2991
3009
def parse_0g (self ): self ._0g .append (self .values [1 :])
3010
+ def parse_100edges (self ): self ._100edges .append (self .values [1 :])
2992
3011
def parse_100verts (self ): self ._100verts .append (self .values [1 :])
2993
3012
def parse_105sym (self ): self ._105sym .append (self .values [1 :])
2994
3013
def parse_105plane (self ):
@@ -3017,6 +3036,8 @@ def parse_105a(self):
3017
3036
else :
3018
3037
r = [sub_type ,] + self .values [2 :] #
3019
3038
self ._105a .append (r )
3039
+ def parse_106ek (self ):
3040
+ self ._106ek .append (self .values [1 :])
3020
3041
def parse_50000grip (self ): self ._50000grip .append (self .values [1 :])
3021
3042
3022
3043
def next_line (self ):
@@ -3068,9 +3089,11 @@ def __str__(self): return "%s %s {%s ...}" %(self.__name__, SENSE.get(self.sense
3068
3089
def __repr__ (self ): return "%s %s {%s ...}" % (self .__name__ , SENSE .get (self .sense , self .sense ), self .subtype )
3069
3090
def _readLoftData (self , chunks , index ):
3070
3091
ld = LoftData ()
3071
- ld .surface , i = readSurface (chunks , index )
3092
+ i = index
3093
+ ld .surface , i = readSurface (chunks , i )
3072
3094
ld .bs2cur , i = readBS2Curve (chunks , i )
3073
3095
ld .e1 , i = getBoolean (chunks , i )
3096
+ if (isASM () and getAsmMajor () > 228 ): i += 1 # skip -1
3074
3097
subdata , i = readLofSubdata (chunks , i )
3075
3098
(ld .type , n , m , v ) = subdata
3076
3099
ld .e2 , i = getBoolean (chunks , i )
@@ -3374,11 +3397,10 @@ def setDefm(self, chunks, index, inventor):
3374
3397
v31 , i = getFloat (chunks , i )
3375
3398
elif (t1 == 5 ):
3376
3399
self .surface , i = readSurface (chunks , i )
3400
+ i32 , i = getLong (chunks , i ) # iEdidF{...}
3377
3401
e31 , i = getBoolean (chunks , i )
3378
3402
f32 , i = getFloat (chunks , i )
3379
3403
i33 , i = getInteger (chunks , i )
3380
- if (getVersion () > 225 ) and isASM ():
3381
- i34 , i = getEnumByTag (chunks , i , [])
3382
3404
f34 , i = getFloat (chunks , i )
3383
3405
self .curve = CurveInt ()
3384
3406
i = self .curve .setSubtype (chunks , i )
@@ -3999,10 +4021,10 @@ def build(self, face = None):
3999
4021
else :
4000
4022
logError (" Can't create curve for revolution of (%r)" % (self .profile ))
4001
4023
elif (self .subtype == 'sum_spl_sur' ):
4002
- rngU = self .tolerance [ 2 ]
4024
+ rngU = self .rangeU
4003
4025
curve1 = self .curve1 .build (rngU .getLowerLimit (), rngU .getUpperLimit ())
4004
4026
if (curve1 is not None ):
4005
- rngV = self .tolerance [ 3 ]
4027
+ rngV = self .rangeV
4006
4028
curve2 = self .curve2 .build (rngV .getLowerLimit (), rngV .getUpperLimit ())
4007
4029
if (curve2 is not None ):
4008
4030
self .shape = Part .makeRuledSurface (curve1 , curve2 )
@@ -4051,6 +4073,7 @@ def __init__(self):
4051
4073
self .sensev = 'forward_v'
4052
4074
self .urange = Interval (Range ('I' , MIN_0 ), Range ('I' , MAX_2PI ))
4053
4075
self .vrange = Interval (Range ('I' , MIN_0 ), Range ('I' , MAX_2PI ))
4076
+ self .profile = None
4054
4077
def getSatTextGeometry (self , index ): return "%s %s %s %s %s %s %s %s #" % (vec2sat (self .center ), vec2sat (self .axis ), self .major , self .minor , vec2sat (self .uvorigin ), self .sensev , self .urange , self .vrange )
4055
4078
def __repr__ (self ): return "Surface-Torus: center=%s, normal=%s, R=%g, r=%g, uvorigin=%s" % (self .center , self .axis , self .major , self .minor , self .uvorigin )
4056
4079
def setSubtype (self , chunks , index ):
@@ -4959,13 +4982,6 @@ def __str__(self):
4959
4982
sat += "%g %g %g\n " % (self .scale , self .resabs , self .resnor )
4960
4983
return sat
4961
4984
4962
- def getNextText (data ):
4963
- m = LENGTH_TEXT .match (data )
4964
- count = int (m .group (1 ))
4965
- text = m .group (2 )[0 :count ]
4966
- remaining = m .group (2 )[count + 1 :]
4967
- return text , remaining
4968
-
4969
4985
def int2version (num ):
4970
4986
return float ("%d.%d" % (num / 100 , num % 100 ))
4971
4987
@@ -5104,9 +5120,9 @@ def _readHeaderText(self):
5104
5120
self .header .flags = int (tokens [3 ])
5105
5121
if (self .version >= 2.0 ):
5106
5122
data = self ._stream .readline ()
5107
- self .header .prodId , data = getNextText (data )
5108
- self .header .prodVer , data = getNextText (data )
5109
- self .date , data = getNextText (data )
5123
+ self .header .prodId , data = self . _getNextText (data )
5124
+ self .header .prodVer , data = self . _getNextText (data )
5125
+ self .date , data = self . _getNextText (data )
5110
5126
data = self ._stream .readline ()
5111
5127
tokens = data .split (' ' )
5112
5128
self .header .scale = fabs (float (tokens [0 ])) # prevent STEP importer from handling negative scales -> "Cannot compute Inventor representation for the shape of Part__Feature"
@@ -5292,6 +5308,18 @@ def readBinary(self):
5292
5308
setReader (self )
5293
5309
return True
5294
5310
5311
+ def _getNextText (self , data ):
5312
+ i = 0
5313
+ while (data [i ].isdigit ()):
5314
+ i += 1
5315
+ count = int (data [:i ])
5316
+ data = data [i + 1 :]
5317
+ if (len (data ) < count ):
5318
+ data = self ._stream .readline ()
5319
+ text = data [0 :count ]
5320
+ remaining = data [count + 1 :]
5321
+ return text , remaining
5322
+
5295
5323
class Record (object ):
5296
5324
def __init__ (self , name ):
5297
5325
self .chunks = []
0 commit comments