Navigation Menu

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 Feb 10, 2014
2 parents 8b610af + ad0db9f commit 12dbea7
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 85 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -92,6 +92,7 @@ MESSAGE(STATUS "includedir: ${CMAKE_INSTALL_INCLUDEDIR}")
# == Win32 is default behaviour use the LibPack copied in Source tree ==========
if(MSVC)
OPTION(FREECAD_LIBPACK_USE "Use the LibPack to Build FreeCAD (only Win32 so far)." ON)
OPTION(FREECAD_LIBPACK_USEPYSIDE "Use PySide in LibPack rather to PyQt and Swig." ON)
set(FREECAD_LIBPACK_DIR ${CMAKE_SOURCE_DIR} CACHE PATH "Directory of the FreeCAD LibPack")
else(MSVC)
OPTION(FREECAD_LIBPACK_USE "Use the LibPack to Build FreeCAD (only Win32 so far)." OFF)
Expand Down
22 changes: 20 additions & 2 deletions cMake/UseLibPack8x.cmake
Expand Up @@ -151,7 +151,25 @@ set(QT_RCC_EXECUTABLE ${FREECAD_LIBPACK_DIR}/bin/rcc.exe)
set(QT_HELPCOMPILER_EXECUTABLE ${FREECAD_LIBPACK_DIR}/bin/qhelpgenerator.exe)
set(QT_COLLECTIOMGENERATOR_EXECUTABLE ${FREECAD_LIBPACK_DIR}/bin/qcollectiongenerator.exe)


if(FREECAD_LIBPACK_USEPYSIDE)
# SHIBOKEN_INCLUDE_DIR - Directories to include to use SHIBOKEN
# SHIBOKEN_LIBRARY - Files to link against to use SHIBOKEN
# SHIBOKEN_BINARY - Executable name

SET(SHIBOKEN_INCLUDE_DIR ${FREECAD_LIBPACK_DIR}/include/shiboken)
SET(SHIBOKEN_LIBRARY optimized ${FREECAD_LIBPACK_DIR}/lib/shiboken-python2.6.lib debug ${FREECAD_LIBPACK_DIR}/lib/shiboken-python2.6_d.lib)
set(SHIBOKEN_BINARY ${FREECAD_LIBPACK_DIR}/bin/shiboken)

# PYSIDE_INCLUDE_DIR - Directories to include to use PySide
# PYSIDE_LIBRARY - Files to link against to use PySide
# PYSIDE_PYTHONPATH - Path to where the PySide Python module files could be found
# PYSIDE_TYPESYSTEMS - Type system files that should be used by other bindings extending PySide

SET(PYSIDE_INCLUDE_DIR ${FREECAD_LIBPACK_DIR}/include/PySide)
SET(PYSIDE_LIBRARY optimized ${FREECAD_LIBPACK_DIR}/lib/pyside-python2.6.lib debug ${FREECAD_LIBPACK_DIR}/lib/pyside-python2.6_d.lib)
#SET(PYSIDE_PYTHONPATH ${FREECAD_LIBPACK_DIR}/pyside/Lib/site-packages)
#SET(PYSIDE_TYPESYSTEMS ${FREECAD_LIBPACK_DIR}/pyside/share/PySide/typesystems)
endif(FREECAD_LIBPACK_USEPYSIDE)

MACRO (QT4_EXTRACT_OPTIONS _qt4_files _qt4_options)
SET(${_qt4_files})
Expand Down Expand Up @@ -428,4 +446,4 @@ set(SHIBOKEN_BINARY ${FREECAD_LIBPACK_DIR}/bin/shiboken)
SET(PYSIDE_INCLUDE_DIR ${FREECAD_LIBPACK_DIR}/include/PySide)
SET(PYSIDE_LIBRARY optimized ${FREECAD_LIBPACK_DIR}/lib/pyside-python2.6.lib debug ${FREECAD_LIBPACK_DIR}/lib/pyside-python2.6_d.lib)
SET(PYSIDE_PYTHONPATH ${FREECAD_LIBPACK_DIR}/pyside/Lib/site-packages)
SET(PYSIDE_TYPESYSTEMS ${FREECAD_LIBPACK_DIR}/pyside/share/PySide/typesystems)
SET(PYSIDE_TYPESYSTEMS ${FREECAD_LIBPACK_DIR}/pyside/share/PySide/typesystems)
26 changes: 22 additions & 4 deletions src/Gui/InputField.cpp
Expand Up @@ -162,12 +162,19 @@ void InputField::newInput(const QString & text)

void InputField::pushToHistory(const QString &valueq)
{
std::string value;
QString val;
if(valueq.isEmpty())
value = this->text().toUtf8().constData();
val = this->text();
else
value = valueq.toUtf8().constData();
val = valueq;

// check if already in:
std::vector<QString> hist = InputField::getHistory();
for(std::vector<QString>::const_iterator it = hist.begin();it!=hist.end();++it)
if( *it == val)
return;

std::string value(val.toUtf8());
if(_handle.isValid()){
char hist1[21];
char hist0[21];
Expand Down Expand Up @@ -205,7 +212,7 @@ void InputField::setToLastUsedValue(void)
{
std::vector<QString> hist = getHistory();
if(hist.size()>0)
this->setText(hist[0]);
this->setValue(Base::Quantity::parse(hist[0]));
}


Expand Down Expand Up @@ -322,6 +329,17 @@ void InputField::setMinimum(double m)
Minimum = m;
}

void InputField::setUnitText(QString str)
{
Base::Quantity quant = Base::Quantity::parse(str);
setUnit(quant.getUnit());
}

QString InputField::getUnitText(void)
{
return actUnitStr;
}

// get the value of the minimum property
int InputField::historySize(void)const
{
Expand Down
6 changes: 5 additions & 1 deletion src/Gui/InputField.h
Expand Up @@ -52,6 +52,7 @@ class GuiExport InputField : public QLineEdit
Q_PROPERTY(double maximum READ maximum WRITE setMaximum )
Q_PROPERTY(double minimum READ minimum WRITE setMinimum )
Q_PROPERTY(int historySize READ historySize WRITE setHistorySize )
Q_PROPERTY(QString unit READ getUnitText WRITE setUnitText )


public:
Expand Down Expand Up @@ -88,7 +89,10 @@ class GuiExport InputField : public QLineEdit
int historySize(void)const;
/// set the value of the minimum property
void setHistorySize(int);

/// set the unit by a string (can be used in the *.ui file)
void setUnitText(QString);
/// get the unit as a string (can be used in the *.ui file)
QString getUnitText(void);
/// set the number portion selected (use after setValue())
void selectNumber(void);

Expand Down
37 changes: 35 additions & 2 deletions src/Mod/Fem/App/FemMesh.cpp
Expand Up @@ -29,7 +29,10 @@
# include <strstream>
# include <Bnd_Box.hxx>
# include <BRepBndLib.hxx>
# include <BRepAlgo_NormalProjection.hxx>
# include <BRepExtrema_DistShapeShape.hxx>
# include <TopoDS_Vertex.hxx>
# include <BRepBuilderAPI_MakeVertex.hxx>
# include <gp_Pnt.hxx>
#endif

#include <Base/Writer.h>
Expand Down Expand Up @@ -326,6 +329,7 @@ SMESH_Mesh* FemMesh::getSMesh()
return myMesh;
}


SMESH_Gen * FemMesh::getGenerator()
{
return myGen;
Expand Down Expand Up @@ -404,8 +408,37 @@ std::set<long> FemMesh::getSurfaceNodes(const TopoDS_Face &face)const
std::set<long> result;
const SMESHDS_Mesh* data = myMesh->GetMeshDS();

BRepAlgo_NormalProjection algo;
Bnd_Box box;
BRepBndLib::Add(face, box);
// limit where the mesh node belongs to the face:
double limit = box.SquareExtent()/10000.0;
box.Enlarge(limit);

// get the actuall transform of the FemMesh
const Base::Matrix4D Mtrx(getTransform());

SMDS_NodeIteratorPtr aNodeIter = myMesh->GetMeshDS()->nodesIterator();
for (int i=0;aNodeIter->more();i++) {
const SMDS_MeshNode* aNode = aNodeIter->next();
Base::Vector3d vec(aNode->X(),aNode->Y(),aNode->Z());
// Apply the matrix to hold the BoundBox in absolute space.
vec = Mtrx * vec;

if(!box.IsOut(gp_Pnt(vec.x,vec.y,vec.z))){
// create a Vertex
BRepBuilderAPI_MakeVertex aBuilder(gp_Pnt(vec.x,vec.y,vec.z));
TopoDS_Shape s = aBuilder.Vertex();
// measure distance
BRepExtrema_DistShapeShape measure(face,s);
measure.Perform();
if (!measure.IsDone() || measure.NbSolution() < 1)
continue;

if(measure.Value() < limit)
result.insert(aNode->GetID());

}
}

return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Fem/App/FemMeshPy.xml
Expand Up @@ -89,7 +89,7 @@
<UserDocu>Get the node position vector by an Node-ID</UserDocu>
</Documentation>
</Methode>
<Methode Name="getNodesByFace">
<Methode Name="getNodesByFace" Const="true">
<Documentation>
<UserDocu>Return a list of node IDs which belong to a TopoFace</UserDocu>
</Documentation>
Expand Down
9 changes: 7 additions & 2 deletions src/Mod/Fem/App/FemMeshPyImp.cpp
Expand Up @@ -30,6 +30,7 @@

#include <TopoDS_Shape.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS.hxx>

#include <Base/VectorPy.h>
#include <Base/MatrixPy.h>
Expand Down Expand Up @@ -534,13 +535,17 @@ PyObject* FemMeshPy::getNodesByFace(PyObject *args)

try {
const TopoDS_Shape& sh = static_cast<Part::TopoShapeFacePy*>(pW)->getTopoShapePtr()->_Shape;
const TopoDS_Face& fc = TopoDS::Face(sh);
if (sh.IsNull()) {
PyErr_SetString(PyExc_Exception, "Face is empty");
return 0;
}
Py::List ret;
throw Py::Exception("Not yet implemented");

std::set<long> resultSet = getFemMeshPtr()->getSurfaceNodes(fc);
for( std::set<long>::const_iterator it = resultSet.begin();it!=resultSet.end();++it)
ret.append(Py::Int(*it));

return Py::new_reference_to(ret);

}
catch (Standard_Failure) {
Expand Down
13 changes: 7 additions & 6 deletions src/Mod/Fem/Gui/ViewProviderFemMeshPyImp.cpp
Expand Up @@ -218,13 +218,14 @@ Py::List ViewProviderFemMeshPy::getHighlightedNodes(void) const

void ViewProviderFemMeshPy::setHighlightedNodes(Py::List arg)
{
/* std::set<long>& nodeSet;
for (Py::List::iterator it = arg.begin(); it != arg.end() && index < 16; ++it) {
nodeSet.i (double)Py::Int(*it);
}
setHighlightNodes*/
throw Py::AttributeError("Not yet implemented");
std::set<long> res;

for( Py::List::iterator it = arg.begin(); it!= arg.end();++it){
Py::Int id(*it);
if(id)
res.insert(id);
}
this->getViewProviderFemMeshPtr()->setHighlightNodes(res);
}

Py::List ViewProviderFemMeshPy::getVisibleElementFaces(void) const
Expand Down
31 changes: 28 additions & 3 deletions src/Mod/Fem/MechanicalAnalysis.py
Expand Up @@ -220,7 +220,7 @@ def __init__(self,object):
self.formUi = form_class()
self.form = QtGui.QWidget()
self.formUi.setupUi(self.form)
self.params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Machining_Distortion")
#self.params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem")

#Connect Signals and Slots
QtCore.QObject.connect(self.formUi.toolButton_chooseOutputDir, QtCore.SIGNAL("clicked()"), self.chooseOutputDir)
Expand All @@ -235,7 +235,7 @@ def getStandardButtons(self):

def update(self):
'fills the widgets'
self.formUi.lineEdit_outputDir.setText(self.params.GetString("JobDir",'/'))
self.formUi.lineEdit_outputDir.setText(tempfile.gettempdir())
return

def accept(self):
Expand Down Expand Up @@ -294,7 +294,32 @@ def run(self):
return


filename_without_suffix = MeshObject.Name
filename = dirName + '/' + MeshObject.Name + '.inp'

MeshObject.FemMesh.writeABAQUS(filename)

# now open again and write the setup:
inpfile = open(filename,'a')
inpfile.write('*MATERIAL, Name='+matmap['General_name'] + '\n')


#*MATERIAL, Name=steel
#*ELASTIC
#28000000, 0.3
#*SOLID SECTION, Elset=Eall, Material=steel
#*STEP
#*STATIC
#*BOUNDARY
#Nfix1,3,3,0
#Nfix2,2,3,0
#Nfix3,1,3,0
#*DLOAD
#*INCLUDE, INPUT=load.dlo
#*NODE FILE
#U
#*EL FILE
#S, E
#*END STEP
#current_file_name

#young_modulus = float(matmap['FEM_youngsmodulus'])
Expand Down
48 changes: 22 additions & 26 deletions src/Mod/Fem/MechanicalMaterial.py
Expand Up @@ -128,20 +128,13 @@ def __setstate__(self,state):
class _MechanicalMaterialTaskPanel:
'''The editmode TaskPanel for MechanicalMaterial objects'''
def __init__(self,obj):
# the panel has a tree widget that contains categories
# for the subcomponents, such as additions, subtractions.
# the categories are shown only if they are not empty.
form_class, base_class = uic.loadUiType(FreeCAD.getHomePath() + "Mod/Fem/MechanicalMaterial.ui")

self.obj = obj
self.formUi = form_class()
self.form = QtGui.QWidget()
self.formUi.setupUi(self.form)

self.form=FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Fem/MechanicalMaterial.ui")
self.params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem")


QtCore.QObject.connect(self.formUi.pushButton_MatWeb, QtCore.SIGNAL("clicked()"), self.goMatWeb)
QtCore.QObject.connect(self.formUi.comboBox_MaterialsInDir, QtCore.SIGNAL("currentIndexChanged(int)"), self.chooseMat)
QtCore.QObject.connect(self.form.pushButton_MatWeb, QtCore.SIGNAL("clicked()"), self.goMatWeb)
QtCore.QObject.connect(self.form.comboBox_MaterialsInDir, QtCore.SIGNAL("currentIndexChanged(int)"), self.chooseMat)

self.update()

Expand All @@ -150,22 +143,23 @@ def transferTo(self):

matmap = self.obj.Material

matmap['Mechanical_youngsmodulus'] = str(self.formUi.spinBox_young_modulus.value() * 1e+6)
matmap['FEM_poissonratio'] = str(self.formUi.spinBox_poisson_ratio.value())
matmap['Mechanical_youngsmodulus'] = self.form.spinBox_young_modulus.text()
matmap['FEM_poissonratio'] = str(self.form.spinBox_poisson_ratio.value())

self.obj.Material = matmap
print matmap


def transferFrom(self):
"Transfer from the object to the dialog"
matmap = self.obj.Material

if matmap.has_key('Mechanical_youngsmodulus'):
print float(matmap['Mechanical_youngsmodulus'])
self.formUi.spinBox_young_modulus.setValue(float(matmap['Mechanical_youngsmodulus'])/1e+6)
print matmap['Mechanical_youngsmodulus']
self.form.spinBox_young_modulus.setText(matmap['Mechanical_youngsmodulus'])
if matmap.has_key('FEM_poissonratio'):
print float(matmap['FEM_poissonratio'])
self.formUi.spinBox_poisson_ratio.setValue(float(matmap['FEM_poissonratio']))
#print float(matmap['FEM_poissonratio'])
self.form.spinBox_poisson_ratio.setValue(float(matmap['FEM_poissonratio']))

def isAllowedAlterSelection(self):
return False
Expand All @@ -178,19 +172,21 @@ def getStandardButtons(self):

def update(self):
'fills the widgets'
self.formUi.spinBox_young_modulus.setValue(0.0)
self.formUi.spinBox_poisson_ratio.setValue(0.0)
#self.form.spinBox_young_modulus.setValue(0.0)
#self.form.spinBox_poisson_ratio.setValue(0.0)
self.transferFrom()
self.fillMaterialCombo()


return

def accept(self):
print 'accept(self)'
self.transferTo()
FreeCADGui.ActiveDocument.resetEdit()

def reject(self):
print 'reject(self)'
FreeCADGui.ActiveDocument.resetEdit()

def saveMat(self):
Expand All @@ -207,12 +203,12 @@ def goMatWeb(self):
def chooseMat(self,index):
if index == 0:return
import Material
print index
#print index
name = self.pathList[index-1]
print 'Import ', str(name)
#print 'Import ', str(name)

self.obj.Material = Material.importFCMat(str(name))
print self.obj.Material
#print self.obj.Material

self.transferFrom()

Expand All @@ -221,13 +217,13 @@ def fillMaterialCombo(self):
matmap = self.obj.Material
dirname = FreeCAD.ConfigGet("AppHomePath")+"data/Mod/Material/StandardMaterial"
self.pathList = glob.glob(dirname + '/*.FCMat')
self.formUi.comboBox_MaterialsInDir.clear()
self.form.comboBox_MaterialsInDir.clear()
if(matmap.has_key('General_name')):
self.formUi.comboBox_MaterialsInDir.addItem(matmap['General_name'])
self.form.comboBox_MaterialsInDir.addItem(matmap['General_name'])
else:
self.formUi.comboBox_MaterialsInDir.addItem('-> choose Material')
self.form.comboBox_MaterialsInDir.addItem('-> choose Material')
for i in self.pathList:
self.formUi.comboBox_MaterialsInDir.addItem(os.path.basename(i) )
self.form.comboBox_MaterialsInDir.addItem(os.path.basename(i) )



Expand Down

0 comments on commit 12dbea7

Please sign in to comment.