예제 #1
0
 def onImport(this, e):
     wildcard = "OFF shape (*.off)|*.off|Python shape (*.py)|*.py"
     dlg = wx.FileDialog(this,
         'New: Choose a file', this.importDirName, '', wildcard, wx.OPEN)
     if dlg.ShowModal() == wx.ID_OK:
         filename = dlg.GetFilename()
         this.importDirName  = dlg.GetDirectory()
         print "opening file:", filename
         fd = open(os.path.join(this.importDirName, filename), 'r')
         if filename[-3:] == '.py':
             shape = Geom3D.readPyFile(fd)
             # For Compound derived shapes (isinstance) use merge:
             try:
                 shape = shape.SimpleShape
             except AttributeError:
                 # probably a SimpleShape
                 pass
         else:
             shape = Geom3D.readOffFile(fd, recreateEdges = False)
         fd.close()
         if isinstance(shape, Geom3D.IsometricShape):
             Vs = shape.baseShape.Vs
             Fs = shape.baseShape.Fs
         else:
             #print 'no isometry'
             Vs = shape.Vs
             Fs = shape.Fs
         print 'read ', len(Vs), ' Vs and ', len(Fs), ' Fs.'
         this.showGui[this.__VsGuiIndex].set(Vs)
         this.showGui[this.__FsGuiIndex].set(Fs)
         # With a python file it is possible to set the other properties as
         # well: e.g.
         # finalSym = isometry.S4xI
         # finalSymSetup = [ [1, 0, 0], [0, 0, 1] ]
         # stabSym = isometry.C3xI
         # stabSymSetup = [ [0, 0, 1] ]
         # rotAxis = [1, 1, 1]
         # rotAngle = 30
         #   where the angle is in degrees (floating point)
         if filename[-3:] == '.py':
             fd = open(os.path.join(this.importDirName, filename), 'r')
             ed = {'__name__': 'readPyFile'}
             exec fd in ed
             moreSettings = 0
             keyErrStr = 'Note: KeyError while looking for'
             key = 'finalSym'
             # to prevent accepting keyErrors in other code than ed[key]:
             keyDefined = False
             try:
                 finalSym = ed[key]
                 keyDefined = True
             except KeyError:
                 print keyErrStr, key
                 pass
             if keyDefined:
                 moreSettings += 1
                 this.showGui[this.__FinalSymGuiIndex].SetSelectedClass(
                     finalSym
                 )
                 this.showGui[this.__FinalSymGuiIndex].onSetSymmetry(None)
                 key = 'finalSymSetup'
                 keyDefined = False
                 try:
                     symSetup = ed[key]
                     keyDefined = True
                 except KeyError:
                     print keyErrStr, key
                     pass
                 if keyDefined:
                     moreSettings += 1
                     this.showGui[this.__FinalSymGuiIndex].SetupSymmetry(
                         symSetup
                     )
             key = 'stabSym'
             keyDefined = False
             try:
                 stabSym = ed[key]
                 keyDefined = True
             except KeyError:
                 print keyErrStr, key
                 pass
             if keyDefined:
                 moreSettings += 1
                 this.showGui[this.__StabSymGuiIndex].SetSelectedClass(
                     stabSym
                 )
                 this.showGui[this.__StabSymGuiIndex].onSetSymmetry(None)
                 key = 'stabSymSetup'
                 keyDefined = False
                 try:
                     symSetup = ed[key]
                     keyDefined = True
                 except KeyError:
                     print keyErrStr, key
                     pass
                 if keyDefined:
                     moreSettings += 1
                     this.showGui[this.__StabSymGuiIndex].SetupSymmetry(
                         symSetup
                     )
             if moreSettings > 0:
                 this.onApplySymmetry(None)
             key = 'rotAxis'
             keyDefined = False
             try:
                 axis = ed[key]
                 keyDefined = True
             except KeyError:
                 print keyErrStr, key
                 pass
             if keyDefined:
                 moreSettings += 1
                 this.rotateSizer.set_axis(axis)
             key = 'rotAngle'
             keyDefined = False
             try:
                 angle = ed[key]
                 keyDefined = True
             except KeyError:
                 print keyErrStr, key
                 pass
             if keyDefined:
                 moreSettings += 1
                 this.rotateSizer.set_angle(angle)
                 this.updateOrientation(
                     this.rotateSizer.get_angle(), this.rotateSizer.get_axis())
             fd.close()
         this.name = filename
     dlg.Destroy()
예제 #2
0
 def onImport(this, e):
     wildcard = "OFF shape (*.off)|*.off|Python shape (*.py)|*.py"
     dlg = wx.FileDialog(this, 'New: Choose a file', this.importDirName, '',
                         wildcard, wx.OPEN)
     if dlg.ShowModal() == wx.ID_OK:
         filename = dlg.GetFilename()
         this.importDirName = dlg.GetDirectory()
         print "opening file:", filename
         fd = open(os.path.join(this.importDirName, filename), 'r')
         if filename[-3:] == '.py':
             shape = Geom3D.readPyFile(fd)
             # For Compound derived shapes (isinstance) use merge:
             try:
                 shape = shape.SimpleShape
             except AttributeError:
                 # probably a SimpleShape
                 pass
         else:
             shape = Geom3D.readOffFile(fd, recreateEdges=False)
         fd.close()
         if isinstance(shape, Geom3D.IsometricShape):
             Vs = shape.baseShape.Vs
             Fs = shape.baseShape.Fs
         else:
             #print 'no isometry'
             Vs = shape.Vs
             Fs = shape.Fs
         print 'read ', len(Vs), ' Vs and ', len(Fs), ' Fs.'
         this.showGui[this.__VsGuiIndex].set(Vs)
         this.showGui[this.__FsGuiIndex].set(Fs)
         # With a python file it is possible to set the other properties as
         # well: e.g.
         # finalSym = isometry.S4xI
         # finalSymSetup = [ [1, 0, 0], [0, 0, 1] ]
         # stabSym = isometry.C3xI
         # stabSymSetup = [ [0, 0, 1] ]
         # rotAxis = [1, 1, 1]
         # rotAngle = 30
         #   where the angle is in degrees (floating point)
         if filename[-3:] == '.py':
             fd = open(os.path.join(this.importDirName, filename), 'r')
             ed = {'__name__': 'readPyFile'}
             exec fd in ed
             moreSettings = 0
             keyErrStr = 'Note: KeyError while looking for'
             key = 'finalSym'
             # to prevent accepting keyErrors in other code than ed[key]:
             keyDefined = False
             try:
                 finalSym = ed[key]
                 keyDefined = True
             except KeyError:
                 print keyErrStr, key
                 pass
             if keyDefined:
                 moreSettings += 1
                 this.showGui[this.__FinalSymGuiIndex].SetSelectedClass(
                     finalSym)
                 this.showGui[this.__FinalSymGuiIndex].onSetSymmetry(None)
                 key = 'finalSymSetup'
                 keyDefined = False
                 try:
                     symSetup = ed[key]
                     keyDefined = True
                 except KeyError:
                     print keyErrStr, key
                     pass
                 if keyDefined:
                     moreSettings += 1
                     this.showGui[this.__FinalSymGuiIndex].SetupSymmetry(
                         symSetup)
             key = 'stabSym'
             keyDefined = False
             try:
                 stabSym = ed[key]
                 keyDefined = True
             except KeyError:
                 print keyErrStr, key
                 pass
             if keyDefined:
                 moreSettings += 1
                 this.showGui[this.__StabSymGuiIndex].SetSelectedClass(
                     stabSym)
                 this.showGui[this.__StabSymGuiIndex].onSetSymmetry(None)
                 key = 'stabSymSetup'
                 keyDefined = False
                 try:
                     symSetup = ed[key]
                     keyDefined = True
                 except KeyError:
                     print keyErrStr, key
                     pass
                 if keyDefined:
                     moreSettings += 1
                     this.showGui[this.__StabSymGuiIndex].SetupSymmetry(
                         symSetup)
             if moreSettings > 0:
                 this.onApplySymmetry(None)
             key = 'rotAxis'
             keyDefined = False
             try:
                 axis = ed[key]
                 keyDefined = True
             except KeyError:
                 print keyErrStr, key
                 pass
             if keyDefined:
                 moreSettings += 1
                 this.showGui[this.__AxisGuiIndex].SetVertex(axis)
             key = 'rotAngle'
             keyDefined = False
             try:
                 angle = ed[key]
                 keyDefined = True
             except KeyError:
                 print keyErrStr, key
                 pass
             if keyDefined:
                 moreSettings += 1
                 this.showGui[this.__SlideAngleGuiIndex].SetValue(angle)
                 this.showGui[this.__DirAngleGuiIndex].SetValue(angle)
                 this.currentAngle = angle
                 this.onSharedAngleAdjust(None)
             fd.close()
         this.name = filename
     dlg.Destroy()