Skip to content

Commit

Permalink
FEM: ConstraintTransform: core implementation
Browse files Browse the repository at this point in the history
FEM: ConstraintTransform: transformable surface comment modification

FEM: ConstraintTransform: re-adjusted GUI layout

FEM: ConstraintTransform: more tweaking

FEM: ConstraintTransform: GUI layout adjustment

FEM: ConstraintTransform: GUI bug fix

FEM: ConstraintTransform: implemented App::PropertyEnumeration for type of transform
  • Loading branch information
kgoao authored and yorikvanhavre committed Sep 27, 2016
1 parent 83c59bc commit 086f716
Show file tree
Hide file tree
Showing 13 changed files with 1,427 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Mod/Fem/App/AppFem.cpp
Expand Up @@ -57,6 +57,7 @@
#include "FemConstraintPlaneRotation.h"
#include "FemConstraintContact.h"
#include "FemConstraintFluidBoundary.h"
#include "FemConstraintTransform.h"

#include "FemResultObject.h"
#include "FemSolverObject.h"
Expand Down Expand Up @@ -159,6 +160,7 @@ PyMODINIT_FUNC initFem()
Fem::ConstraintPlaneRotation ::init();
Fem::ConstraintContact ::init();
Fem::ConstraintFluidBoundary ::init();
Fem::ConstraintTransform ::init();

Fem::FemResultObject ::init();
Fem::FemResultObjectPython ::init();
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Fem/App/CMakeLists.txt
Expand Up @@ -219,6 +219,8 @@ SET(FemConstraints_SRCS
FemConstraintPlaneRotation.h
FemConstraintContact.cpp
FemConstraintContact.h
FemConstraintTransform.cpp
FemConstraintTransform.h
)
SOURCE_GROUP("Constraints" FILES ${FemConstraints_SRCS})

Expand Down
104 changes: 104 additions & 0 deletions src/Mod/Fem/App/FemConstraintTransform.cpp
@@ -0,0 +1,104 @@
/***************************************************************************
* Copyright (c) 2013 Jan Rheinländer <jrheinlaender[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/


#include "PreCompiled.h"

#ifndef _PreComp_
#include <BRepAdaptor_Curve.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <Precision.hxx>
#include <TopoDS.hxx>
#include <gp_Lin.hxx>
#include <gp_Pln.hxx>
#include <gp_Pnt.hxx>
#endif

#include "FemConstraintTransform.h"

using namespace Fem;

PROPERTY_SOURCE(Fem::ConstraintTransform, Fem::Constraint);

static const char* TransformTypes[] = {"Cylindrical","Rectangular", NULL};

ConstraintTransform::ConstraintTransform()
{
ADD_PROPERTY(X_rot,(0.0)); //numeric value, 0.0
ADD_PROPERTY(Y_rot,(0.0));
ADD_PROPERTY(Z_rot,(0.0));
ADD_PROPERTY_TYPE(TransformType,(1),"ConstraintTransform",(App::PropertyType)(App::Prop_None),
"Type of transform, rectangular or cylindrical");
TransformType.setEnums(TransformTypes);
ADD_PROPERTY_TYPE(RefDispl,(0,0),"ConstraintTransform",(App::PropertyType)(App::Prop_None),"Elements where the constraint is applied");
ADD_PROPERTY_TYPE(NameDispl,(0),"ConstraintTransform",(App::PropertyType)(App::Prop_None),"Elements where the constraint is applied");
ADD_PROPERTY_TYPE(BasePoint,(Base::Vector3d(0,0,0)),"ConstraintTransform",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
"Base point of cylindrical surface");
ADD_PROPERTY_TYPE(Axis,(Base::Vector3d(0,1,0)),"ConstraintTransform",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
"Axis of cylindrical surface");
ADD_PROPERTY_TYPE(Points,(Base::Vector3d()),"ConstraintTransform",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
"Points where symbols are drawn");
ADD_PROPERTY_TYPE(Normals,(Base::Vector3d()),"ConstraintTransform",App::PropertyType(App::Prop_ReadOnly|App::Prop_Output),
"Normals where symbols are drawn");
Points.setValues(std::vector<Base::Vector3d>());
Normals.setValues(std::vector<Base::Vector3d>());
}

App::DocumentObjectExecReturn *ConstraintTransform::execute(void)
{
return Constraint::execute();
}

const char* ConstraintTransform::getViewProviderName(void) const
{
return "FemGui::ViewProviderFemConstraintTransform";
}

void ConstraintTransform::onChanged(const App::Property* prop)
{
Constraint::onChanged(prop);

if (prop == &References) {
std::vector<Base::Vector3d> points;
std::vector<Base::Vector3d> normals;
int scale = 1; //OvG: Enforce use of scale
if (getPoints(points, normals, &scale)) {
Points.setValues(points);
Normals.setValues(normals);
Scale.setValue(scale); //OvG: Scale
Points.touch(); // This triggers ViewProvider::updateData()
std::string transform_type = TransformType.getValueAsString();
if (transform_type == "Cylindrical") {
// Find data of cylinder
double radius, height;
Base::Vector3d base, axis;
if (!getCylinder(radius, height, base, axis))
return;
Axis.setValue(axis);
// Update base point
base = base + axis * height/2;
BasePoint.setValue(base);
BasePoint.touch(); // This triggers ViewProvider::updateData()
}
}
}
}
67 changes: 67 additions & 0 deletions src/Mod/Fem/App/FemConstraintTransform.h
@@ -0,0 +1,67 @@
/***************************************************************************
* Copyright (c) 2013 Jan Rheinländer <jrheinlaender[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library 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 library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/

#ifndef FEM_CONSTRAINTTransform_H
#define FEM_CONSTRAINTTransform_H

#include "FemConstraint.h"

namespace Fem
{

class AppFemExport ConstraintTransform : public Fem::Constraint
{
PROPERTY_HEADER(Fem::ConstraintTransform);

public:
/// Constructor
ConstraintTransform(void);

// Read-only (calculated values). These trigger changes in the ViewProvider
App::PropertyLinkSubList RefDispl;
App::PropertyLinkList NameDispl;
App::PropertyVectorList Points;
App::PropertyVectorList Normals;
App::PropertyVector BasePoint;
App::PropertyVector Axis;
App::PropertyFloat X_rot;
App::PropertyFloat Y_rot;
App::PropertyFloat Z_rot;
App::PropertyEnumeration TransformType;
//etc
/* */

/// recalculate the object
virtual App::DocumentObjectExecReturn *execute(void);

/// returns the type name of the ViewProvider
const char* getViewProviderName(void) const;

protected:
virtual void onChanged(const App::Property* prop);

};

} //namespace Fem


#endif // FEM_CONSTRAINTTransform_H
2 changes: 2 additions & 0 deletions src/Mod/Fem/Gui/AppFemGui.cpp
Expand Up @@ -59,6 +59,7 @@
#include "ViewProviderFemConstraintInitialTemperature.h"
#include "ViewProviderFemConstraintPlaneRotation.h"
#include "ViewProviderFemConstraintContact.h"
#include "ViewProviderFemConstraintTransform.h"
#include "ViewProviderResult.h"
#include "Workbench.h"

Expand Down Expand Up @@ -130,6 +131,7 @@ PyMODINIT_FUNC initFemGui()
FemGui::ViewProviderFemConstraintInitialTemperature ::init();
FemGui::ViewProviderFemConstraintPlaneRotation::init();
FemGui::ViewProviderFemConstraintContact ::init();
FemGui::ViewProviderFemConstraintTransform ::init();
FemGui::ViewProviderResult ::init();
FemGui::ViewProviderResultPython ::init();
FemGui::PropertyFemMeshItem ::init();
Expand Down
7 changes: 7 additions & 0 deletions src/Mod/Fem/Gui/CMakeLists.txt
Expand Up @@ -72,6 +72,7 @@ set(FemGui_MOC_HDRS
TaskFemConstraintInitialTemperature.h
TaskFemConstraintPlaneRotation.h
TaskFemConstraintContact.h
TaskFemConstraintTransform.h
TaskTetParameter.h
TaskAnalysisInfo.h
TaskDriver.h
Expand Down Expand Up @@ -106,6 +107,7 @@ set(FemGui_UIC_SRCS
TaskFemConstraintInitialTemperature.ui
TaskFemConstraintPlaneRotation.ui
TaskFemConstraintContact.ui
TaskFemConstraintTransform.ui
TaskTetParameter.ui
TaskAnalysisInfo.ui
TaskDriver.ui
Expand Down Expand Up @@ -175,6 +177,9 @@ SET(FemGui_DLG_SRCS
TaskFemConstraintContact.ui
TaskFemConstraintContact.cpp
TaskFemConstraintContact.h
TaskFemConstraintTransform.ui
TaskFemConstraintTransform.cpp
TaskFemConstraintTransform.h
)
SOURCE_GROUP("Constraint-Dialogs" FILES ${FemGui_DLG_SRCS})

Expand Down Expand Up @@ -231,6 +236,8 @@ SET(FemGui_SRCS_ViewProvider
ViewProviderFemConstraintPlaneRotation.h
ViewProviderFemConstraintContact.cpp
ViewProviderFemConstraintContact.h
ViewProviderFemConstraintTransform.cpp
ViewProviderFemConstraintTransform.h
ViewProviderResult.cpp
ViewProviderResult.h
)
Expand Down
45 changes: 45 additions & 0 deletions src/Mod/Fem/Gui/Command.cpp
Expand Up @@ -437,6 +437,50 @@ bool CmdFemConstraintContact::isActive(void)
return FemGui::ActiveAnalysisObserver::instance()->hasActiveObject();
}

//=====================================================================================
DEF_STD_CMD_A(CmdFemConstraintTransform);

CmdFemConstraintTransform::CmdFemConstraintTransform()
: Command("Fem_ConstraintTransform")
{
sAppModule = "Fem";
sGroup = QT_TR_NOOP("Fem");
sMenuText = QT_TR_NOOP("Create FEM transform constraint");
sToolTipText = QT_TR_NOOP("Create FEM constraint for transforming a face");
sWhatsThis = "Fem_ConstraintTransform";
sStatusTip = sToolTipText;
sPixmap = "fem-constraint-transform";
}

void CmdFemConstraintTransform::activated(int iMsg)
{
Fem::FemAnalysis *Analysis;

if(getConstraintPrerequisits(&Analysis))
return;

std::string FeatName = getUniqueObjectName("FemConstraintTransform");

openCommand("Make FEM constraint transform on face");
doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintTransform\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.X_rot = 0.0",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Y_rot = 0.0",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Z_rot = 0.0",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Scale = 1",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",
Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str());

doCommand(Doc,"%s",gethideMeshShowPartStr(FeatName).c_str()); //OvG: Hide meshes and show parts

updateActive();

doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
}

bool CmdFemConstraintTransform::isActive(void)
{
return FemGui::ActiveAnalysisObserver::instance()->hasActiveObject();
}
//=====================================================================================
DEF_STD_CMD_A(CmdFemConstraintHeatflux);

Expand Down Expand Up @@ -1409,6 +1453,7 @@ void CreateFemCommands(void)
rcCmdMgr.addCommand(new CmdFemConstraintPlaneRotation());
rcCmdMgr.addCommand(new CmdFemConstraintContact());
rcCmdMgr.addCommand(new CmdFemConstraintFluidBoundary());
rcCmdMgr.addCommand(new CmdFemConstraintTransform());
#ifdef FC_USE_VTK
rcCmdMgr.addCommand(new CmdFemPostCreateClipFilter);
rcCmdMgr.addCommand(new CmdFemPostCreateScalarClipFilter);
Expand Down

0 comments on commit 086f716

Please sign in to comment.