Skip to content

Commit

Permalink
Merge branch 'master' of ssh://git.code.sf.net/p/free-cad/code
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Jan 8, 2014
2 parents 80f166b + 50492a5 commit 9a7132b
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 32 deletions.
20 changes: 10 additions & 10 deletions src/Mod/Import/App/SCL/Part21.py
Expand Up @@ -23,7 +23,7 @@
# ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
Expand Down Expand Up @@ -54,7 +54,7 @@ def __init__(self,name):
# each time an instance is added to the model, count is incremented
self._instances = {}
self._number_of_instances = 0

def add_instance(self, instance):
'''
Adds an instance to the model
Expand Down Expand Up @@ -88,7 +88,7 @@ def __init__(self,entity_name,attributes):
self._attributes_definition = attributes
print self._entity_name
print self._attributes_definition


class Part21Parser:
"""
Expand All @@ -114,11 +114,11 @@ def __init__(self, filename):
for item in self._number_of_ancestors.keys():
if len(self._number_of_ancestors[item])==0:
del self._number_of_ancestors[item]

def get_schema_name(self):
return self._schema_name
print schema_name

def get_number_of_instances(self):
return len(self._instances_definition.keys())

Expand All @@ -132,8 +132,8 @@ def parse_file(self):
break
# there may be a multline definition. In this case, we read lines untill we found
# a ;
#while (not line.endswith(";\r\n")): #its a multiline
# line = line.replace("\r\n","") + fp.readline()
while (line.find(';') == -1): #its a multiline
line = line.replace("\n","").replace("\r","") + fp.readline()
# parse line
match_instance_definition = INSTANCE_DEFINITION_RE.search(line) # id,name,attrs
if match_instance_definition:
Expand Down Expand Up @@ -179,14 +179,14 @@ def __init__(self, part21_loader):
self._aggregate_scope = []
self._aggr_scope = False
self.create_entity_instances()

def create_entity_instances(self):
""" Starts entity instances creation
"""
for number_of_ancestor in self._part21_loader._number_of_ancestors.keys():
for entity_definition_id in self._part21_loader._number_of_ancestors[number_of_ancestor]:
self.create_entity_instance(entity_definition_id)

def create_entity_instance(self, instance_id):
instance_definition = self._part21_loader._instances_definition[instance_id]
print "Instance definition to process",instance_definition
Expand All @@ -199,7 +199,7 @@ def create_entity_instance(self, instance_id):
instance_attributes = instance_definition[1]
print "instance_attributes:",instance_attributes
a = object_(*instance_attributes)

if __name__ == "__main__":
import time
import sys
Expand Down
106 changes: 85 additions & 21 deletions src/Mod/Import/App/SCL/SimpleReader.py
@@ -1,5 +1,4 @@
# Copyright (c) 2014, Juergen Riegel (FreeCAD@juergen-riegel.net)
# Copyright (c) 2011, Thomas Paviot (tpaviot@gmail.com)
# All rights reserved.

# This file is part of the StepClassLibrary (SCL).
Expand Down Expand Up @@ -42,8 +41,7 @@


__title__="Simple Part21 STEP reader"
__author__ = "Juergen Riegel, Thomas Paviot"
__url__ = "http://www.freecadweb.org"
__author__ = "Juergen Riegel"
__version__ = "0.1 (Jan 2014)"


Expand All @@ -60,8 +58,35 @@ def __init__(self, filename):
import time
import sys
self._p21loader = Part21.Part21Parser("gasket1.p21")
self._p21loader._number_of_ancestors = {} # not needed, save memory
self.schemaModule = None
self.schemaClasses = None
self.instanceMape = {}
#for i in self._p21loader._instances_definition.keys():
# print i,self._p21loader._instances_definition[i][0],self._p21loader._instances_definition[i][1]

def _writeGraphVizEdge(self,num,attrList,file):
for i in attrList:
if isinstance(i,list):
self._writeGraphVizEdge(num,i,file)
elif isinstance(i,str):
if not i == '' and i[0] == '#':
key = int(i[1:])
file.write(' '+`num`+' -> '+`key`+'\n')


def writeGraphViz(self,fileName):
print "Writing GraphViz file %s..."%fileName,
gvFile = open(fileName,'w')

gvFile.write('digraph G {\n node [fontname=Verdana,fontsize=12]\n node [style=filled]\n node [fillcolor="#EEEEEE"]\n node [color="#EEEEEE"]\n edge [color="#31CEF0"]\n')
for i in self._p21loader._instances_definition.keys():
entityStr = '#'+`i`
nameStr = self._p21loader._instances_definition[i][0].lower()
sttrStr = `self._p21loader._instances_definition[i][1]`.replace('"','').replace("'",'')
gvFile.write(' '+`i`+' [label="'+entityStr+'\n'+nameStr+'\n'+sttrStr+'"]\n')
self._writeGraphVizEdge( i,self._p21loader._instances_definition[i][1],gvFile)
gvFile.write('}\n')

def instaciate(self):
"""Instaciate the python classe from the enteties"""
Expand All @@ -77,27 +102,66 @@ def instaciate(self):
if self.schemaModule:
self.schemaClasses = dict(inspect.getmembers(self.schemaModule))

for number_of_ancestor in self._p21loader._number_of_ancestors.keys():
for entity_definition_id in self._p21loader._number_of_ancestors[number_of_ancestor]:
#print entity_definition_id,':',self._p21loader._instances_definition[entity_definition_id]
self.create_entity_instance(entity_definition_id)

def create_entity_instance(self, instance_id):
instance_definition = self._p21loader._instances_definition[instance_id]
print "Instance definition to process",instance_definition
# first find class name
class_name = instance_definition[0].lower()
print "Class name:%s"%class_name

if not class_name=='':
object_ = self.schemaClasses[class_name]
# then attributes
print object_.__doc__
#instance_attributes = instance_definition[1]
for i in self._p21loader._instances_definition.keys():
#print i
if not self.instanceMape.has_key(i):
self._create_entity_instance(i)

def _create_entity_instance(self, instance_id):
if self._p21loader._instances_definition.has_key(instance_id):
instance_definition = self._p21loader._instances_definition[instance_id]
#print "Instance definition to process",instance_definition
# first find class name
class_name = instance_definition[0].lower()
#print "Class name:%s"%class_name

if not class_name=='':
classDef = self.schemaClasses[class_name]
# then attributes
#print object_.__doc__
instance_attributes = instance_definition[1]
self._transformAttributes(instance_attributes)
print 'Attribute list after transform: ',instance_attributes

self.instanceMape[instance_id] = str('dummy#:'+str(instance_id)) # dummy instance to test
else:
print '############################# lost entity: ',instance_id
self.instanceMape[instance_id] = int(41) # dummy
#print "instance_attributes:",instance_attributes
#a = object_(*instance_attributes)

def _transformAttributes(self,attrList):
n = 0
for i in attrList:
if isinstance(i,list):
self._transformAttributes(i)
elif isinstance(i,str):
if i == '':
print 'empty string'
elif i[0] == '#':
key = int(i[1:])
#print 'Item: ',int(i[1:])
if self.instanceMape.has_key(key):
attrList[n] = self.instanceMape[key]
else:
self._create_entity_instance(key)
if not self.instanceMape.has_key(key):
raise NameError("Needed instance not instanciated: ",key)
else:
attrList[n] = self.instanceMape[key]
elif i[0] == '$':
#print 'Dollar'
pass
elif i[0] == "'":
print 'Dopelstring: ',i[1:-1]
else:
print 'String: ',i
else:
raise NameError("Unknown attribute type")
n = n+1

if __name__ == "__main__":
sys.path.append('..') # path where config_control_design.py is found
parser = SimpleParser("gasket1.p21") # simple test file
parser.instaciate()
#parser.instaciate()
parser.writeGraphViz('TestGrap.gv')
2 changes: 1 addition & 1 deletion src/Mod/Web/App/CMakeLists.txt
Expand Up @@ -59,7 +59,7 @@ elseif(MINGW)
else(MSVC)
set_target_properties(Web PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Mod/Web)
set_target_properties(Web PROPERTIES PREFIX "")
set_target_properties(Fem PROPERTIES INSTALL_RPATH ${INSTALL_RPATH})
set_target_properties(Web PROPERTIES INSTALL_RPATH ${INSTALL_RPATH})
endif(MSVC)

install(TARGETS Web DESTINATION lib)

0 comments on commit 9a7132b

Please sign in to comment.