Merge branch 'master' of ssh://git.code.sf.net/p/free-cad/code
This commit is contained in:
commit
a1c5d981a5
|
@ -26,7 +26,7 @@ __author__ = "Heiko Jakob <heiko.jakob@gediegos.de>"
|
|||
|
||||
import re, FreeCAD, FreeCADGui, Part, cProfile, os, string
|
||||
from FreeCAD import Vector, Base
|
||||
from Draft import *
|
||||
from Draft import makeWire
|
||||
|
||||
if open.__module__ == '__builtin__':
|
||||
pythonopen = open
|
||||
|
@ -68,60 +68,62 @@ def process(doc,filename):
|
|||
# This code should work with almost every dialect
|
||||
|
||||
# Regex to identify data rows and throw away unused metadata
|
||||
expre = r"^\s*(?P<xval>\-*\d*?\.\d\d+)\s+(?P<yval>\-*\d*?\.\d+)\s*$"
|
||||
regex = re.compile(r'^\s*(?P<xval>(\-|\d*)\.\d+(E\-?\d+)?)\,?\s*(?P<yval>\-?\s*\d*\.\d+(E\-?\d+)?)\s*$')
|
||||
afile = pythonopen(filename,'r')
|
||||
# read the airfoil name which is always at the first line
|
||||
airfoilname = afile.readline().strip()
|
||||
|
||||
upper=[]
|
||||
lower=[]
|
||||
coords=[]
|
||||
upside=True
|
||||
last_x=None
|
||||
|
||||
|
||||
|
||||
# Collect the data for the upper and the lower side seperately if possible
|
||||
for lin in afile:
|
||||
curdat = re.match(expre,lin)
|
||||
if curdat != None:
|
||||
curdat = regex.match(lin)
|
||||
if curdat != None:
|
||||
|
||||
x = float(curdat.group("xval"))
|
||||
y = float(curdat.group("yval"))
|
||||
|
||||
if last_x == None:
|
||||
last_x=x
|
||||
|
||||
# Separation between the sides is done in many different ways.
|
||||
# The only way to safely detect the swap is when x is getting smaller
|
||||
if x < last_x:
|
||||
# The swap
|
||||
upside=False
|
||||
# Not needed because this will happen anyhow at the end of the loop last_x=x
|
||||
|
||||
# the normal processing
|
||||
if upside:
|
||||
upper.append(Vector(x,y,0))
|
||||
else:
|
||||
lower.append(Vector(x,y,0))
|
||||
last_x=x
|
||||
coords.append(Vector(x,y,0))
|
||||
|
||||
# End of if curdat != None
|
||||
# End of for lin in file
|
||||
afile.close()
|
||||
|
||||
# reverse the lower side and append it to the upper to
|
||||
# make the complete data be oriented clockwise
|
||||
lower.reverse()
|
||||
for i in lower:
|
||||
upper.append(i)
|
||||
# End of for i in lower
|
||||
|
||||
|
||||
|
||||
|
||||
if len(coords) < 3:
|
||||
print 'Did not find enough coordinates\n'
|
||||
return
|
||||
|
||||
# sometimes coords are divided in upper an lower side
|
||||
# so that x-coordinate begin new from leading or trailing edge
|
||||
# check for start coordinates in the middle of list
|
||||
|
||||
if coords[0:-1].count(coords[0]) > 1:
|
||||
flippoint = coords.index(coords[0],1)
|
||||
upper = coords[0:flippoint]
|
||||
lower = coords[flippoint+1:]
|
||||
lower.reverse()
|
||||
for i in lower:
|
||||
upper.append(i)
|
||||
coords = upper
|
||||
|
||||
|
||||
# do we use the parametric Draft Wire?
|
||||
if useDraftWire:
|
||||
face = makeWire ( upper, True, None, True )
|
||||
obj = makeWire ( coords, True )
|
||||
#obj.label = airfoilname
|
||||
else:
|
||||
# alternate solution, uses common Part Faces
|
||||
lines = []
|
||||
first_v = None
|
||||
last_v = None
|
||||
for v in upper:
|
||||
for v in coords:
|
||||
if first_v == None:
|
||||
first_v = v
|
||||
# End of if first_v == None
|
||||
|
@ -139,7 +141,8 @@ def process(doc,filename):
|
|||
# End of if last_v != first_v
|
||||
|
||||
wire = Part.Wire(lines)
|
||||
face = Part.Face(wire)
|
||||
Part.show(face)
|
||||
face = Part.Face(wire)
|
||||
obj = FreeCAD.ActiveDocument.addObject('Part::Feature',airfoilname)
|
||||
obj.Shape = face
|
||||
|
||||
doc.recompute()
|
||||
|
|
|
@ -574,6 +574,39 @@ void ViewProviderFemMesh::animateNodes(double factor)
|
|||
DisplacementFactor = factor;
|
||||
}
|
||||
|
||||
void ViewProviderFemMesh::setColorByElementId(const std::map<long,App::Color> &ElementColorMap)
|
||||
{
|
||||
pcShapeMaterial->diffuseColor;
|
||||
|
||||
pcMatBinding->value = SoMaterialBinding::PER_FACE ;
|
||||
|
||||
// resizing and writing the color vector:
|
||||
pcShapeMaterial->diffuseColor.setNum(vFaceElementIdx.size());
|
||||
SbColor* colors = pcShapeMaterial->diffuseColor.startEditing();
|
||||
|
||||
int i=0;
|
||||
for(std::vector<unsigned long>::const_iterator it=vFaceElementIdx.begin()
|
||||
;it!=vFaceElementIdx.end()
|
||||
;++it,i++){
|
||||
unsigned long ElemIdx = ((*it)>>3);
|
||||
const std::map<long,App::Color>::const_iterator pos = ElementColorMap.find(ElemIdx);
|
||||
if(pos == ElementColorMap.end())
|
||||
colors[i] = SbColor(0,1,0);
|
||||
else
|
||||
colors[i] = SbColor(pos->second.r,pos->second.g,pos->second.b);
|
||||
}
|
||||
|
||||
pcShapeMaterial->diffuseColor.finishEditing();
|
||||
}
|
||||
|
||||
void ViewProviderFemMesh::resetColorByElementId(void)
|
||||
{
|
||||
pcMatBinding->value = SoMaterialBinding::OVERALL;
|
||||
pcShapeMaterial->diffuseColor.setNum(0);
|
||||
const App::Color& c = ShapeColor.getValue();
|
||||
pcShapeMaterial->diffuseColor.setValue(c.r,c.g,c.b);
|
||||
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -113,6 +113,11 @@ public:
|
|||
void resetDisplacementByNodeId(void);
|
||||
/// reaply the node displacement with a certain factor and do a redraw
|
||||
void animateNodes(double factor);
|
||||
/// set the color for each element
|
||||
void setColorByElementId(const std::map<long,App::Color> &ElementColorMap);
|
||||
/// reset the view of the element colors
|
||||
void resetColorByElementId(void);
|
||||
|
||||
//@}
|
||||
|
||||
const std::vector<unsigned long> &getVisibleElementFaces(void)const{return vFaceElementIdx;}
|
||||
|
|
|
@ -20,12 +20,18 @@
|
|||
<UserDocu></UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Attribute Name="NodeColor" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>Postprocessing color of the the nodes. The faces between the nodes gets interpolated. </UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="NodeColor" Type="Dict"/>
|
||||
</Attribute>
|
||||
<Attribute Name="NodeColor" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>Postprocessing color of the nodes. The faces between the nodes gets interpolated. </UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="NodeColor" Type="Dict"/>
|
||||
</Attribute>
|
||||
<Attribute Name="ElementColor" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>Postprocessing color of the elements. All faces of the element get the same color. </UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="ElementColor" Type="Dict"/>
|
||||
</Attribute>
|
||||
<Attribute Name="NodeDisplacement" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>Postprocessing color of the the nodes. The faces between the nodes gets interpolated. </UserDocu>
|
||||
|
|
|
@ -57,6 +57,28 @@ void ViewProviderFemMeshPy::setNodeColor(Py::Dict arg)
|
|||
}
|
||||
}
|
||||
|
||||
Py::Dict ViewProviderFemMeshPy::getElementColor(void) const
|
||||
{
|
||||
//return Py::List();
|
||||
throw Py::AttributeError("Not yet implemented");
|
||||
}
|
||||
|
||||
void ViewProviderFemMeshPy::setElementColor(Py::Dict arg)
|
||||
{
|
||||
if(arg.size() == 0)
|
||||
this->getViewProviderFemMeshPtr()->resetColorByNodeId();
|
||||
else {
|
||||
std::map<long,App::Color> NodeColorMap;
|
||||
|
||||
for( Py::Dict::iterator it = arg.begin(); it!= arg.end();++it){
|
||||
Py::Int id((*it).first);
|
||||
Py::Tuple color((*it).second);
|
||||
NodeColorMap[id] = App::Color(Py::Float(color[0]),Py::Float(color[1]),Py::Float(color[2]),0);
|
||||
}
|
||||
this->getViewProviderFemMeshPtr()->setColorByElementId(NodeColorMap);
|
||||
}
|
||||
}
|
||||
|
||||
Py::Dict ViewProviderFemMeshPy::getNodeDisplacement(void) const
|
||||
{
|
||||
//return Py::Dict();
|
||||
|
|
Loading…
Reference in New Issue
Block a user