Coder Social home page Coder Social logo

freecad_python_gdml's People

Contributors

keithsloan avatar luzpaz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

freecad_python_gdml's Issues

Process internal XML entities before processing DOM on import

Currently the importing of gdml files with XML entities (supported by GDML in Geant4 per user guide) results in throwing an error due to failure to parse the entity. Here I'm just using a single value entity &length;. Error produced upon import is:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/freecad-daily/Mod/GDML/importGDML.py", line 60, in insert
    processGDML(filename)
  File "/usr/lib/freecad-daily/Mod/GDML/importGDML.py", line 223, in processGDML
    parseVolume(root,ref,0,0,0)
<type 'exceptions.TypeError'>: parseVolume() takes exactly 3 arguments (5 given)

GDML input file:
https://gist.github.com/wdconinc/5608821687745aa701391229d5b6504c

Import: placement of physvol without position or rotation should assume zero and identity

Currently importing a physvol block like:

      <physvol name="box_physical">
        <volumeref ref="box_logical"/>
      </physvol>

fails with (first)

  File "/usr/lib/freecad-daily/Mod/GDML/importGDML.py", line 212, in parsePhysVol
    lx += float(eval(pos.get('x')))
TypeError: eval() arg 1 must be a string or code object

then with

  File "/usr/lib/freecad-daily/Mod/GDML/importGDML.py", line 109, in processPlacement
    print angle 
UnboundLocalError: local variable 'angle' referenced before assignment

and only works when:

      <physvol name="box_physical">
        <volumeref ref="box_logical"/>
        <position name="box_position" x="0" y="0" z="0"/>
        <rotation name="box_rotation" x="0" y="0" z="0"/>
      </physvol>

Likely fix:

def processPlacement(base,rot) :
    print "Rotation : "
    print rot.attrib
    axis = FreeCAD.Vector(0,0,1) 
    angle = 0
    if 'y' in rot.attrib :
        axis = FreeCAD.Vector(0,1,0) 
        angle = float(rot.attrib['y'])
    if 'x' in rot.attrib :
        axis = FreeCAD.Vector(1,0,0) 
        angle = float(rot.attrib['x'])
    if 'z' in rot.attrib :
        axis = FreeCAD.Vector(0,0,1) 
        angle = float(rot.attrib['z'])
    print angle 
    place = FreeCAD.Placement(base,axis,angle)
    return place

lxml pb under FreeCAD_0.19-20310

Hello,

I tried to used FreeCAD_Python_GDML. So I have donwloaded the last FreeCAD version available 0.19

But with FreeCAD_Python_GDML, a error occured :
File "/home/.../.FreeCAD/Mod/GDML/freecad/gdml/importGDML.py", line 977, in processGDML
from lxml import etree
<class 'ModuleNotFoundError'>: No module named 'lxml'

could you help?
Thanks!
Regards

Copying physical volume makes volume invalid

After copying a selection (physical volume) in FreeCAD, the pasted part cannot be exported, with the following error:

17:01:54  ====> Start GDML Export 0.1
17:01:54  File extension : .xml
17:01:54  clean name : LowerBoxPhys
17:01:54  returning name : LowerBoxPhys
17:01:54  Traceback (most recent call last):
  File "<string>", line 4, in <module>
  File "C:\Users\shang\AppData\Roaming\FreeCAD\Mod\GDML\freecad\gdml\exportGDML.py", line 2208, in export
    exportGDML(first,filepath,'.xml')
  File "C:\Users\shang\AppData\Roaming\FreeCAD\Mod\GDML\freecad\gdml\exportGDML.py", line 1954, in exportGDML
    exportWorldVol(first, fileExt)
  File "C:\Users\shang\AppData\Roaming\FreeCAD\Mod\GDML\freecad\gdml\exportGDML.py", line 1905, in exportWorldVol
    processVolume( cnt, vol, xmlVol, xmlParent, parentName, False)
  File "C:\Users\shang\AppData\Roaming\FreeCAD\Mod\GDML\freecad\gdml\exportGDML.py", line 1829, in processVolume
    idx = processObject(cnt, idx, vol.OutList[idx],  \
  File "C:\Users\shang\AppData\Roaming\FreeCAD\Mod\GDML\freecad\gdml\exportGDML.py", line 1650, in processObject
    solidCnt, solidxml, solidName = processSolid(obj, True)
  File "C:\Users\shang\AppData\Roaming\FreeCAD\Mod\GDML\freecad\gdml\exportGDML.py", line 1330, in processSolid
    solidxml, solidName = processGDMLSolid(obj, True)
  File "C:\Users\shang\AppData\Roaming\FreeCAD\Mod\GDML\freecad\gdml\exportGDML.py", line 1207, in processGDMLSolid
    while switch(obj.Proxy.Type) :
<class 'AttributeError'>: 'GDMLBox' object has no attribute 'Type'

Use default world material vacuum instead of air

Instead of the current default of G4_Air (which relies on a whole bunch of isotopes, elements, etc), it may make more sense to use G4_Galactic as the default material for the world, e.g. defined on L1807 at http://www.apc.univ-paris7.fr/~franco/g4doxy/html/G4NistMaterialBuilder_8cc-source.html. Equivalent block in gdml is:

    <material Z="1" name="G4_Galactic" state="gas">
      <T unit="K" value="2.73"/>
      <P unit="pascal" value="3e-18"/>
      <D unit="g/cm3" value="1e-25"/>
      <atom unit="g/mole" value="1.01"/>
    </material>

Rationale: it reduces the amount of non-essential content in the output gdml file.

Process external XML entities before processing DOM on import

Closely related to #3 , but with external entities. This is a separate issue since it is not clear how this should be handled by the importer. It is not merely a question of substituting a value, but should the imported file be included in a single geometry tree, or does FreeCAD provide options to keep the imported file as a separate entity?

Error message upon import:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/freecad-daily/Mod/GDML/importGDML.py", line 60, in insert
    processGDML(filename)
  File "/usr/lib/freecad-daily/Mod/GDML/importGDML.py", line 217, in processGDML
    tree = ET.parse(filename)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1182, in parse
    tree.parse(source, parser)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 656, in parse
    parser.feed(data)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1659, in feed
    self._raiseerror(v)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1523, in _raiseerror
    raise err
<class 'xml.etree.ElementTree.ParseError'>: undefined entity &sub2;: line 23, column 3

Gist with example gdml code:
https://gist.github.com/wdconinc/64ab0fa85e2f51ff36f813d1831bc7ba

Float values for Length

Sample file lhcbvelo.gdml has zplanes where values are sometimes given as float.

Have now coded for this i.e. zplane values can be float, but raises the issue should all other
solids that have PropertyLength be changed to PropertyFloat?

Soup of the README.md

Would you mind if I took a crack at organizing and formatting the README.md file ?

GDML Export

GDML Export on FreeCAD would be nice. Any plans for that?

GDMLBox alignment after parameter change.

Needs investigating - When importing a GDML file GDMLBox solid is correctly aligned. However if the parameters for the box are changed via the normal FreeCAD change parameter facility the origin for the box is no longer correct.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.