FEM: fem utils module, new module to collect some FEM utilities
This commit is contained in:
@@ -95,6 +95,7 @@ SET(FemScripts_SRCS
|
||||
FemToolsCcx.py
|
||||
FemToolsZ88.py
|
||||
ObjectsFem.py
|
||||
FemUtils.py
|
||||
TestFem.py
|
||||
)
|
||||
#SOURCE_GROUP("Scripts" FILES ${FemScripts_SRCS})
|
||||
|
||||
@@ -43,6 +43,7 @@ INSTALL(
|
||||
FemToolsCcx.py
|
||||
FemToolsZ88.py
|
||||
ObjectsFem.py
|
||||
FemUtils.py
|
||||
TestFem.py
|
||||
DESTINATION
|
||||
Mod/Fem
|
||||
|
||||
86
src/Mod/Fem/FemUtils.py
Normal file
86
src/Mod/Fem/FemUtils.py
Normal file
@@ -0,0 +1,86 @@
|
||||
# ***************************************************************************
|
||||
# * *
|
||||
# * Copyright (c) 2017 - Markus Hovorka <m.hovorka@live.de> *
|
||||
# * *
|
||||
# * This program is free software; you can redistribute it and/or modify *
|
||||
# * it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
# * as published by the Free Software Foundation; either version 2 of *
|
||||
# * the License, or (at your option) any later version. *
|
||||
# * for detail see the LICENCE text file. *
|
||||
# * *
|
||||
# * This program is distributed in the hope that it will be useful, *
|
||||
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
# * GNU Library General Public License for more details. *
|
||||
# * *
|
||||
# * You should have received a copy of the GNU Library General Public *
|
||||
# * License along with this program; if not, write to the Free Software *
|
||||
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
# * USA *
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
|
||||
|
||||
__title__ = "FEM Utilities"
|
||||
__author__ = "Markus Hovorka"
|
||||
__url__ = "http://www.freecadweb.org"
|
||||
|
||||
|
||||
import FreeCAD as App
|
||||
|
||||
|
||||
def createObject(doc, name, proxy, viewProxy):
|
||||
obj = doc.addObject(proxy.BaseType, name)
|
||||
proxy(obj)
|
||||
if App.GuiUp:
|
||||
viewProxy(obj.ViewObject)
|
||||
return obj
|
||||
|
||||
|
||||
def findAnalysisOfMember(member):
|
||||
if member is None:
|
||||
raise ValueError("Member must not be None")
|
||||
for obj in member.Document.Objects:
|
||||
if obj.isDerivedFrom("Fem::FemAnalysis"):
|
||||
if member in obj.Member:
|
||||
return obj
|
||||
if _searchGroups(member, obj.Member):
|
||||
return obj
|
||||
return None
|
||||
|
||||
|
||||
def _searchGroups(member, objs):
|
||||
for o in objs:
|
||||
if o == member:
|
||||
return True
|
||||
if hasattr(o, "Group"):
|
||||
return _searchGroups(member, o.Group)
|
||||
return False
|
||||
|
||||
|
||||
def getMember(analysis, t):
|
||||
if analysis is None:
|
||||
raise ValueError("Analysis must not be None")
|
||||
matching = []
|
||||
for m in analysis.Member:
|
||||
if isDerivedFrom(m, t):
|
||||
matching.append(m)
|
||||
return matching
|
||||
|
||||
|
||||
def getSingleMember(analysis, t):
|
||||
objs = getMember(analysis, t)
|
||||
return objs[0] if objs else None
|
||||
|
||||
|
||||
def isOfType(obj, t):
|
||||
if hasattr(obj, "Proxy") and hasattr(obj.Proxy, "Type"):
|
||||
return obj.Proxy.Type == t
|
||||
return obj.TypeId == t
|
||||
|
||||
|
||||
def isDerivedFrom(obj, t):
|
||||
if (hasattr(obj, "Proxy") and hasattr(obj.Proxy, "Type")
|
||||
and obj.Proxy.Type == t):
|
||||
return True
|
||||
return obj.isDerivedFrom(t)
|
||||
Reference in New Issue
Block a user