Extensions: Introduce classes and port App groups

This commit is contained in:
Stefan Tröger
2016-05-26 21:42:12 +02:00
committed by wmayer
parent a50bd5dc88
commit c5a2419e14
55 changed files with 17135 additions and 191 deletions

View File

@@ -264,7 +264,7 @@ void PropertyPostDataObject::SaveDocFile (Base::Writer &writer) const
// stream...
App::PropertyContainer* father = this->getContainer();
if (father && father->isDerivedFrom(App::DocumentObject::getClassTypeId())) {
App::DocumentObject* obj = static_cast<App::DocumentObject*>(father);
App::DocumentObject* obj = dynamic_cast<App::DocumentObject*>(father);
Base::Console().Error("Dataset of '%s' cannot be written to vtk file '%s'\n",
obj->Label.getValue(),fi.filePath().c_str());
}
@@ -332,7 +332,7 @@ void PropertyPostDataObject::RestoreDocFile(Base::Reader &reader)
// stream...
App::PropertyContainer* father = this->getContainer();
if (father && father->isDerivedFrom(App::DocumentObject::getClassTypeId())) {
App::DocumentObject* obj = static_cast<App::DocumentObject*>(father);
App::DocumentObject* obj = dynamic_cast<App::DocumentObject*>(father);
Base::Console().Error("Dataset file '%s' with data of '%s' seems to be empty\n",
fi.filePath().c_str(),obj->Label.getValue());
}

View File

@@ -0,0 +1,376 @@
/***************************************************************************
* Copyright (c) 2015 Stefan Tröger <stefantroeger@gmx.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 *
* *
***************************************************************************/
#include "PreCompiled.h"
#include "PropertyPostDataObject.h"
#include <Base/FileInfo.h>
#include <Base/Console.h>
#include <Base/Writer.h>
#include <Base/Reader.h>
#include <App/Application.h>
#include <App/DocumentObject.h>
#include <vtkPolyData.h>
#include <vtkStructuredGrid.h>
#include <vtkRectilinearGrid.h>
#include <vtkUnstructuredGrid.h>
#include <vtkUniformGrid.h>
#include <vtkCompositeDataSet.h>
#include <vtkMultiBlockDataSet.h>
#include <vtkMultiPieceDataSet.h>
#include <vtkXMLDataSetWriter.h>
#include <vtkXMLPolyDataReader.h>
#include <vtkXMLStructuredGridReader.h>
#include <vtkXMLUnstructuredGridReader.h>
#include <vtkXMLRectilinearGridReader.h>
#include <vtkXMLImageDataReader.h>
#include <strstream>
#ifndef _PreComp_
#endif
using namespace Fem;
TYPESYSTEM_SOURCE(Fem::PropertyPostDataObject , App::Property);
PropertyPostDataObject::PropertyPostDataObject()
{
}
PropertyPostDataObject::~PropertyPostDataObject()
{
}
void PropertyPostDataObject::setValue(const vtkSmartPointer<vtkDataObject>& ds)
{
aboutToSetValue();
if(ds) {
createDataObjectByExternalType(ds);
m_dataObject->DeepCopy(ds);
}
else
m_dataObject = NULL;
hasSetValue();
}
const vtkSmartPointer<vtkDataObject>& PropertyPostDataObject::getValue(void)const
{
return m_dataObject;
}
bool PropertyPostDataObject::isComposite() {
return m_dataObject && !m_dataObject->IsA("vtkDataSet");
}
bool PropertyPostDataObject::isDataSet() {
return m_dataObject && m_dataObject->IsA("vtkDataSet");
}
int PropertyPostDataObject::getDataType() {
if(!m_dataObject)
return -1;
return m_dataObject->GetDataObjectType();
}
PyObject *PropertyPostDataObject::getPyObject(void)
{
//TODO: fetch the vtk python object from the data set and return it
return new PyObject();
}
void PropertyPostDataObject::setPyObject(PyObject *value)
{
}
App::Property *PropertyPostDataObject::Copy(void) const
{
PropertyPostDataObject *prop = new PropertyPostDataObject();
if (m_dataObject) {
prop->createDataObjectByExternalType(m_dataObject);
prop->m_dataObject->DeepCopy(m_dataObject);
}
return prop;
}
void PropertyPostDataObject::createDataObjectByExternalType(vtkSmartPointer< vtkDataObject > ex) {
switch( ex->GetDataObjectType() ) {
case VTK_POLY_DATA:
m_dataObject = vtkSmartPointer<vtkPolyData>::New();
break;
case VTK_STRUCTURED_GRID:
m_dataObject = vtkSmartPointer<vtkStructuredGrid>::New();
break;
case VTK_RECTILINEAR_GRID:
m_dataObject = vtkSmartPointer<vtkRectilinearGrid>::New();
break;
case VTK_UNSTRUCTURED_GRID:
m_dataObject = vtkSmartPointer<vtkUnstructuredGrid>::New();
break;
case VTK_UNIFORM_GRID:
m_dataObject = vtkSmartPointer<vtkUniformGrid>::New();
break;
case VTK_COMPOSITE_DATA_SET:
m_dataObject = vtkCompositeDataSet::New();
break;
case VTK_MULTIBLOCK_DATA_SET:
m_dataObject = vtkSmartPointer<vtkMultiBlockDataSet>::New();
break;
case VTK_MULTIPIECE_DATA_SET:
m_dataObject = vtkSmartPointer<vtkMultiPieceDataSet>::New();
break;
default:
break;
};
}
void PropertyPostDataObject::Paste(const App::Property &from)
{
aboutToSetValue();
m_dataObject = dynamic_cast<const PropertyPostDataObject&>(from).m_dataObject;
hasSetValue();
}
unsigned int PropertyPostDataObject::getMemSize (void) const
{
return m_dataObject->GetActualMemorySize();
}
void PropertyPostDataObject::getPaths(std::vector<App::ObjectIdentifier> &paths) const
{
// paths.push_back(App::ObjectIdentifier(getContainer()) << App::ObjectIdentifier::Component::SimpleComponent(getName())
// << App::ObjectIdentifier::Component::SimpleComponent(App::ObjectIdentifier::String("ShapeType")));
// paths.push_back(App::ObjectIdentifier(getContainer()) << App::ObjectIdentifier::Component::SimpleComponent(getName())
// << App::ObjectIdentifier::Component::SimpleComponent(App::ObjectIdentifier::String("Orientation")));
// paths.push_back(App::ObjectIdentifier(getContainer()) << App::ObjectIdentifier::Component::SimpleComponent(getName())
// << App::ObjectIdentifier::Component::SimpleComponent(App::ObjectIdentifier::String("Length")));
// paths.push_back(App::ObjectIdentifier(getContainer()) << App::ObjectIdentifier::Component::SimpleComponent(getName())
// << App::ObjectIdentifier::Component::SimpleComponent(App::ObjectIdentifier::String("Area")));
// paths.push_back(App::ObjectIdentifier(getContainer()) << App::ObjectIdentifier::Component::SimpleComponent(getName())
// << App::ObjectIdentifier::Component::SimpleComponent(App::ObjectIdentifier::String("Volume")));
}
void PropertyPostDataObject::Save (Base::Writer &writer) const
{
std::string extension;
if(!m_dataObject)
return;
switch( m_dataObject->GetDataObjectType() ) {
case VTK_POLY_DATA:
extension = "vtp";
break;
case VTK_STRUCTURED_GRID:
extension = "vts";
break;
case VTK_RECTILINEAR_GRID:
extension = "vtr";
break;
case VTK_UNSTRUCTURED_GRID:
extension = "vtu";
break;
case VTK_UNIFORM_GRID:
extension = "vti"; //image data
break;
//TODO:multi-datasets use multiple files, this needs to be implemented specially
// case VTK_COMPOSITE_DATA_SET:
// prop->m_dataObject = vtkCompositeDataSet::New();
// break;
// case VTK_MULTIBLOCK_DATA_SET:
// prop->m_dataObject = vtkMultiBlockDataSet::New();
// break;
// case VTK_MULTIPIECE_DATA_SET:
// prop->m_dataObject = vtkMultiPieceDataSet::New();
// break;
default:
break;
};
if(!writer.isForceXML()) {
std::string file = "Data." + extension;
writer.Stream() << writer.ind() << "<Data file=\""
<< writer.addFile(file.c_str(), this)
<< "\"/>" << std::endl;
}
}
void PropertyPostDataObject::Restore(Base::XMLReader &reader)
{
reader.readElement("Data");
if(!reader.hasAttribute("file"))
return;
std::string file (reader.getAttribute("file") );
if (!file.empty()) {
// initate a file read
reader.addFile(file.c_str(),this);
}
}
void PropertyPostDataObject::SaveDocFile (Base::Writer &writer) const
{
// If the shape is empty we simply store nothing. The file size will be 0 which
// can be checked when reading in the data.
if (!m_dataObject)
return;
// create a temporary file and copy the content to the zip stream
// once the tmp. filename is known use always the same because otherwise
// we may run into some problems on the Linux platform
static Base::FileInfo fi(App::Application::getTempFileName());
vtkSmartPointer<vtkXMLDataSetWriter> xmlWriter = vtkSmartPointer<vtkXMLDataSetWriter>::New();
xmlWriter->SetInputDataObject(m_dataObject);
xmlWriter->SetFileName(fi.filePath().c_str());
xmlWriter->SetDataModeToBinary();
if ( xmlWriter->Write() != 1 ) {
// Note: Do NOT throw an exception here because if the tmp. file could
// not be created we should not abort.
// We only print an error message but continue writing the next files to the
// stream...
App::PropertyContainer* father = this->getContainer();
if (father && father->isDerivedFrom(App::DocumentObject::getClassTypeId())) {
<<<<<<< 51e23d854e59ab0a23a9ea9b19e74e5f02753d82
App::DocumentObject* obj = static_cast<App::DocumentObject*>(father);
Base::Console().Error("Dataset of '%s' cannot be written to vtk file '%s'\n",
=======
App::DocumentObject* obj = dynamic_cast<App::DocumentObject*>(father);
Base::Console().Error("Dataset of '%s' cannot be written to vtk file '%s'\n",
>>>>>>> Introduce extensions and port App groups
obj->Label.getValue(),fi.filePath().c_str());
}
else {
Base::Console().Error("Cannot save vtk file '%s'\n", fi.filePath().c_str());
}
std::stringstream ss;
ss << "Cannot save vtk file '" << fi.filePath() << "'";
writer.addError(ss.str());
}
Base::ifstream file(fi, std::ios::in | std::ios::binary);
if (file){
unsigned long ulSize = 0;
std::streambuf* buf = file.rdbuf();
if (buf) {
unsigned long ulCurr;
ulCurr = buf->pubseekoff(0, std::ios::cur, std::ios::in);
ulSize = buf->pubseekoff(0, std::ios::end, std::ios::in);
buf->pubseekoff(ulCurr, std::ios::beg, std::ios::in);
}
// read in the ASCII file and write back to the stream
std::strstreambuf sbuf(ulSize);
file >> &sbuf;
writer.Stream() << &sbuf;
}
file.close();
// remove temp file
fi.deleteFile();
}
void PropertyPostDataObject::RestoreDocFile(Base::Reader &reader)
{
Base::FileInfo xml(reader.getFileName());
// create a temporary file and copy the content from the zip stream
Base::FileInfo fi(App::Application::getTempFileName());
// read in the ASCII file and write back to the file stream
Base::ofstream file(fi, std::ios::out | std::ios::binary);
unsigned long ulSize = 0;
if (reader) {
std::streambuf* buf = file.rdbuf();
reader >> buf;
file.flush();
ulSize = buf->pubseekoff(0, std::ios::cur, std::ios::in);
}
file.close();
// Read the data from the temp file
if (ulSize > 0) {
std::string extension = xml.extension();
//TODO: read in of composite data structures need to be coded, including replace of "GetOutputAsDataSet()"
vtkSmartPointer<vtkXMLReader> xmlReader;
if(extension == "vtp")
xmlReader = vtkSmartPointer<vtkXMLPolyDataReader>::New();
else if (extension == "vts")
xmlReader = vtkSmartPointer<vtkXMLStructuredGridReader>::New();
else if (extension == "vtr")
xmlReader = vtkSmartPointer<vtkXMLRectilinearGridReader>::New();
else if (extension == "vtu")
xmlReader = vtkSmartPointer<vtkXMLUnstructuredGridReader>::New();
else if (extension == "vti")
xmlReader = vtkSmartPointer<vtkXMLImageDataReader>::New();
xmlReader->SetFileName(fi.filePath().c_str());
xmlReader->Update();
if (!xmlReader->GetOutputAsDataSet()) {
// Note: Do NOT throw an exception here because if the tmp. created file could
// not be read it's NOT an indication for an invalid input stream 'reader'.
// We only print an error message but continue reading the next files from the
// stream...
App::PropertyContainer* father = this->getContainer();
if (father && father->isDerivedFrom(App::DocumentObject::getClassTypeId())) {
<<<<<<< 51e23d854e59ab0a23a9ea9b19e74e5f02753d82
App::DocumentObject* obj = static_cast<App::DocumentObject*>(father);
Base::Console().Error("Dataset file '%s' with data of '%s' seems to be empty\n",
=======
App::DocumentObject* obj = dynamic_cast<App::DocumentObject*>(father);
Base::Console().Error("Dataset file '%s' with data of '%s' seems to be empty\n",
>>>>>>> Introduce extensions and port App groups
fi.filePath().c_str(),obj->Label.getValue());
}
else {
Base::Console().Warning("Loaded Dataset file '%s' seems to be empty\n", fi.filePath().c_str());
}
}
else {
aboutToSetValue();
createDataObjectByExternalType(xmlReader->GetOutputAsDataSet());
m_dataObject->DeepCopy(xmlReader->GetOutputAsDataSet());
hasSetValue();
}
}
// delete the temp file
fi.deleteFile();
}

79
src/Mod/Fem/Init.py.orig Normal file
View File

@@ -0,0 +1,79 @@
<<<<<<< ba52dbfac69983692e8edbeca2eff74154a312b6
# FreeCAD init script of the Fem module
# (c) 2001 Juergen Riegel
#***************************************************************************
#* (c) Juergen Riegel (juergen.riegel@web.de) 2002 *
#* *
#* This file is part of the FreeCAD CAx development system. *
#* *
#* 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. *
#* *
#* FreeCAD 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 Lesser General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with FreeCAD; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#* Juergen Riegel 2002 *
#***************************************************************************/
import FreeCAD
FreeCAD.addExportType("TetGen file (*.poly)", "convert2TetGen")
FreeCAD.addImportType("FEM formats (*.unv *.med *.dat *.bdf)", "Fem")
FreeCAD.addExportType("FEM formats (*.unv *.med *.dat *.inp)", "Fem")
FreeCAD.addImportType("CalculiX result (*.frd)", "ccxFrdReader")
FreeCAD.addImportType("Abaqus file (*.inp)", "FemGui")
FreeCAD.addImportType("Z88 mesh file (*.txt)", "importZ88Mesh")
FreeCAD.addExportType("Z88 mesh file (*.txt)", "importZ88Mesh")
FreeCAD.addImportType("Z88 displacement result file (*.txt)", "z88DispReader")
=======
# FreeCAD init script of the Fem module
# (c) 2001 Juergen Riegel
#***************************************************************************
#* (c) Juergen Riegel (juergen.riegel@web.de) 2002 *
#* *
#* This file is part of the FreeCAD CAx development system. *
#* *
#* 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. *
#* *
#* FreeCAD 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 Lesser General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with FreeCAD; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#* Juergen Riegel 2002 *
#***************************************************************************/
import FreeCAD
FreeCAD.addExportType("TetGen file (*.poly)", "convert2TetGen")
FreeCAD.addImportType("FEM formats (*.unv *.med *.dat *.bdf)", "Fem")
FreeCAD.addImportType("FEM results (*.vtk)","Fem")
FreeCAD.addExportType("FEM formats (*.unv *.med *.dat *.inp)", "Fem")
FreeCAD.addImportType("CalculiX result (*.frd)", "ccxFrdReader")
FreeCAD.addImportType("Abaqus file (*.inp)", "FemGui")
>>>>>>> Move post processing to fem objects

View File

@@ -597,7 +597,7 @@ void CmdMeshVertexCurvature::activated(int)
fName = getUniqueObjectName(fName.c_str());
openCommand("Mesh VertexCurvature");
App::DocumentObjectGroup* grp = App::DocumentObjectGroup::getGroupOfObject( *it );
App::DocumentObject* grp = App::DocumentObjectGroup::getGroupOfObject( *it );
if (grp)
doCommand(Doc,"App.activeDocument().getObject(\"%s\").newObject(\"Mesh::Curvature\",\"%s\")",grp->getNameInDocument(), fName.c_str());
else

View File

@@ -13,5 +13,10 @@
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" />
<UserDocu>This is the father of all shape object classes</UserDocu>
</Documentation>
<Methode Name="test">
<Documentation>
<UserDocu>test</UserDocu>
</Documentation>
</Methode>
</PythonExport>
</GenerateModel>
</GenerateModel>

View File

@@ -47,4 +47,8 @@ int PartFeaturePy::setCustomAttributes(const char* , PyObject *)
return 0;
}
PyObject* PartFeaturePy::test(PyObject *args)
{
PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
return 0;
}

View File

@@ -297,7 +297,7 @@ void PropertyPartShape::SaveDocFile (Base::Writer &writer) const
// stream...
App::PropertyContainer* father = this->getContainer();
if (father && father->isDerivedFrom(App::DocumentObject::getClassTypeId())) {
App::DocumentObject* obj = static_cast<App::DocumentObject*>(father);
App::DocumentObject* obj = dynamic_cast<App::DocumentObject*>(father);
Base::Console().Error("Shape of '%s' cannot be written to BRep file '%s'\n",
obj->Label.getValue(),fi.filePath().c_str());
}
@@ -376,7 +376,7 @@ void PropertyPartShape::RestoreDocFile(Base::Reader &reader)
// stream...
App::PropertyContainer* father = this->getContainer();
if (father && father->isDerivedFrom(App::DocumentObject::getClassTypeId())) {
App::DocumentObject* obj = static_cast<App::DocumentObject*>(father);
App::DocumentObject* obj = dynamic_cast<App::DocumentObject*>(father);
Base::Console().Error("BRep file '%s' with shape of '%s' seems to be empty\n",
fi.filePath().c_str(),obj->Label.getValue());
}

View File

@@ -0,0 +1,208 @@
/******************************************************************************
* Copyright (c)2012 Jan Rheinlaender <jrheinlaender@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 *
* *
******************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <BRep_Builder.hxx>
# include <BRepBndLib.hxx>
# include <BRepPrimAPI_MakeRevol.hxx>
# include <BRepBuilderAPI_MakeFace.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Face.hxx>
# include <TopoDS_Wire.hxx>
# include <TopExp_Explorer.hxx>
# include <BRepAlgoAPI_Cut.hxx>
# include <Precision.hxx>
# include <gp_Lin.hxx>
#endif
#include <Base/Axis.h>
#include <Base/Exception.h>
#include <Base/Placement.h>
#include <Base/Tools.h>
#include "FeatureGroove.h"
using namespace PartDesign;
namespace PartDesign {
PROPERTY_SOURCE(PartDesign::Groove, PartDesign::ProfileBased)
Groove::Groove()
{
addSubType = FeatureAddSub::Subtractive;
ADD_PROPERTY_TYPE(Base,(Base::Vector3d(0.0f,0.0f,0.0f)),"Groove", App::Prop_ReadOnly, "Base");
ADD_PROPERTY_TYPE(Axis,(Base::Vector3d(0.0f,1.0f,0.0f)),"Groove", App::Prop_ReadOnly, "Axis");
ADD_PROPERTY_TYPE(Angle,(360.0),"Groove", App::Prop_None, "Angle");
ADD_PROPERTY_TYPE(ReferenceAxis,(0),"Groove",(App::PropertyType)(App::Prop_None),"Reference axis of Groove");
}
short Groove::mustExecute() const
{
if (Placement.isTouched() ||
ReferenceAxis.isTouched() ||
Axis.isTouched() ||
Base.isTouched() ||
Angle.isTouched())
return 1;
return ProfileBased::mustExecute();
}
App::DocumentObjectExecReturn *Groove::execute(void)
{
// Validate parameters
double angle = Angle.getValue();
if (angle < Precision::Confusion())
return new App::DocumentObjectExecReturn("Angle of groove too small");
if (angle > 360.0)
return new App::DocumentObjectExecReturn("Angle of groove too large");
angle = Base::toRadians<double>(angle);
// Reverse angle if selected
if (Reversed.getValue() && !Midplane.getValue())
angle *= (-1.0);
TopoDS_Shape sketchshape;
try {
sketchshape = getVerifiedFace();
} catch (const Base::Exception& e) {
return new App::DocumentObjectExecReturn(e.what());
}
// if the Base property has a valid shape, fuse the prism into it
TopoDS_Shape base;
try {
base = getBaseShape();
} catch (const Base::Exception&) {
return new App::DocumentObjectExecReturn("No sketch support and no base shape: Please tell me where to remove the material of the groove!");
}
updateAxis();
// get revolve axis
Base::Vector3d b = Base.getValue();
gp_Pnt pnt(b.x,b.y,b.z);
Base::Vector3d v = Axis.getValue();
gp_Dir dir(v.x,v.y,v.z);
try {
if (sketchshape.IsNull())
return new App::DocumentObjectExecReturn("Creating a face from sketch failed");
// Rotate the face by half the angle to get Groove symmetric to sketch plane
if (Midplane.getValue()) {
gp_Trsf mov;
mov.SetRotation(gp_Ax1(pnt, dir), Base::toRadians<double>(Angle.getValue()) * (-1.0) / 2.0);
TopLoc_Location loc(mov);
sketchshape.Move(loc);
}
this->positionByPrevious();
TopLoc_Location invObjLoc = this->getLocation().Inverted();
pnt.Transform(invObjLoc.Transformation());
dir.Transform(invObjLoc.Transformation());
base.Move(invObjLoc);
sketchshape.Move(invObjLoc);
// Check distance between sketchshape and axis - to avoid failures and crashes
TopExp_Explorer xp;
xp.Init(sketchshape, TopAbs_FACE);
for (;xp.More(); xp.Next()) {
<<<<<<< 94c547439cc0d5e6dca5e724c97f861f5b1f530e
if (checkLineCrossesFace(gp_Lin(pnt, dir), TopoDS::Face(xp.Current())))
return new App::DocumentObjectExecReturn("Revolve axis intersects the sketch");
}
=======
if (checkLineCrossesFace(gp_Lin(pnt, dir), TopoDS::Face(xp.Current())))
return new App::DocumentObjectExecReturn("Revolve axis intersects the sketch");
}
>>>>>>> Travis: Add SMESH7 dependencies for OSX
// revolve the face to a solid
BRepPrimAPI_MakeRevol RevolMaker(sketchshape, gp_Ax1(pnt, dir), angle);
if (RevolMaker.IsDone()) {
TopoDS_Shape result = RevolMaker.Shape();
// set the subtractive shape property for later usage in e.g. pattern
result = refineShapeIfActive(result);
this->AddSubShape.setValue(result);
// cut out groove to get one result object
BRepAlgoAPI_Cut mkCut(base, result);
// Let's check if the fusion has been successful
if (!mkCut.IsDone())
throw Base::Exception("Cut out of base feature failed");
// we have to get the solids (fuse sometimes creates compounds)
TopoDS_Shape solRes = this->getSolid(mkCut.Shape());
if (solRes.IsNull())
return new App::DocumentObjectExecReturn("Resulting shape is not a solid");
solRes = refineShapeIfActive(solRes);
this->Shape.setValue(getSolid(solRes));
}
else
return new App::DocumentObjectExecReturn("Could not revolve the sketch!");
return App::DocumentObject::StdReturn;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
if (std::string(e->GetMessageString()) == "TopoDS::Face")
return new App::DocumentObjectExecReturn("Could not create face from sketch.\n"
"Intersecting sketch entities in a sketch are not allowed.");
else
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
catch (Base::Exception& e) {
return new App::DocumentObjectExecReturn(e.what());
}
}
bool Groove::suggestReversed(void)
{
updateAxis();
return ProfileBased::getReversedAngle(Base.getValue(), Axis.getValue()) > 0.0;
}
void Groove::updateAxis(void)
{
App::DocumentObject *pcReferenceAxis = ReferenceAxis.getValue();
const std::vector<std::string> &subReferenceAxis = ReferenceAxis.getSubValues();
Base::Vector3d base;
Base::Vector3d dir;
getAxis(pcReferenceAxis, subReferenceAxis, base, dir);
if (dir.Length() > Precision::Confusion()) {
Base.setValue(base.x,base.y,base.z);
Axis.setValue(dir.x,dir.y,dir.z);
}
}
}

View File

@@ -0,0 +1,202 @@
/***************************************************************************
* Copyright (c) 2010 Juergen Riegel <FreeCAD@juergen-riegel.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 *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <BRep_Builder.hxx>
# include <BRepBndLib.hxx>
# include <BRepPrimAPI_MakeRevol.hxx>
# include <BRepBuilderAPI_MakeFace.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Face.hxx>
# include <TopoDS_Wire.hxx>
# include <TopExp_Explorer.hxx>
# include <BRepAlgoAPI_Fuse.hxx>
# include <Precision.hxx>
# include <gp_Lin.hxx>
#endif
#include <Base/Axis.h>
#include <Base/Exception.h>
#include <Base/Placement.h>
#include <Base/Tools.h>
#include "FeatureRevolution.h"
using namespace PartDesign;
namespace PartDesign {
PROPERTY_SOURCE(PartDesign::Revolution, PartDesign::ProfileBased)
Revolution::Revolution()
{
addSubType = FeatureAddSub::Additive;
ADD_PROPERTY_TYPE(Base,(Base::Vector3d(0.0,0.0,0.0)),"Revolution", App::Prop_ReadOnly, "Base");
ADD_PROPERTY_TYPE(Axis,(Base::Vector3d(0.0,1.0,0.0)),"Revolution", App::Prop_ReadOnly, "Axis");
ADD_PROPERTY_TYPE(Angle,(360.0),"Revolution", App::Prop_None, "Angle");
ADD_PROPERTY_TYPE(ReferenceAxis,(0),"Revolution",(App::Prop_None),"Reference axis of revolution");
}
short Revolution::mustExecute() const
{
if (Placement.isTouched() ||
ReferenceAxis.isTouched() ||
Axis.isTouched() ||
Base.isTouched() ||
Angle.isTouched())
return 1;
return ProfileBased::mustExecute();
}
App::DocumentObjectExecReturn *Revolution::execute(void)
{
// Validate parameters
double angle = Angle.getValue();
if (angle < Precision::Confusion())
return new App::DocumentObjectExecReturn("Angle of revolution too small");
if (angle > 360.0)
return new App::DocumentObjectExecReturn("Angle of revolution too large");
angle = Base::toRadians<double>(angle);
// Reverse angle if selected
if (Reversed.getValue() && !Midplane.getValue())
angle *= (-1.0);
TopoDS_Shape sketchshape;
try {
sketchshape = getVerifiedFace();
} catch (const Base::Exception& e) {
return new App::DocumentObjectExecReturn(e.what());
}
// if the Base property has a valid shape, fuse the AddShape into it
TopoDS_Shape base;
try {
base = getBaseShape();
} catch (const Base::Exception&) {
// fall back to support (for legacy features)
base = TopoDS_Shape();
}
// update Axis from ReferenceAxis
updateAxis();
// get revolve axis
Base::Vector3d b = Base.getValue();
gp_Pnt pnt(b.x,b.y,b.z);
Base::Vector3d v = Axis.getValue();
gp_Dir dir(v.x,v.y,v.z);
try {
if (sketchshape.IsNull())
return new App::DocumentObjectExecReturn("Creating a face from sketch failed");
// Rotate the face by half the angle to get Revolution symmetric to sketch plane
if (Midplane.getValue()) {
gp_Trsf mov;
mov.SetRotation(gp_Ax1(pnt, dir), Base::toRadians<double>(Angle.getValue()) * (-1.0) / 2.0);
TopLoc_Location loc(mov);
sketchshape.Move(loc);
}
this->positionByPrevious();
TopLoc_Location invObjLoc = this->getLocation().Inverted();
pnt.Transform(invObjLoc.Transformation());
dir.Transform(invObjLoc.Transformation());
base.Move(invObjLoc);
sketchshape.Move(invObjLoc);
// Check distance between sketchshape and axis - to avoid failures and crashes
TopExp_Explorer xp;
xp.Init(sketchshape, TopAbs_FACE);
for (;xp.More(); xp.Next()) {
if (checkLineCrossesFace(gp_Lin(pnt, dir), TopoDS::Face(xp.Current())))
<<<<<<< 94c547439cc0d5e6dca5e724c97f861f5b1f530e
return new App::DocumentObjectExecReturn("Revolve axis intersects the sketch");
=======
return new App::DocumentObjectExecReturn("Revolve axis intersects the sketch");
>>>>>>> Travis: Add SMESH7 dependencies for OSX
}
// revolve the face to a solid
BRepPrimAPI_MakeRevol RevolMaker(sketchshape, gp_Ax1(pnt, dir), angle);
if (RevolMaker.IsDone()) {
TopoDS_Shape result = RevolMaker.Shape();
result = refineShapeIfActive(result);
// set the additive shape property for later usage in e.g. pattern
this->AddSubShape.setValue(result);
if (!base.IsNull()) {
// Let's call algorithm computing a fuse operation:
BRepAlgoAPI_Fuse mkFuse(base, result);
// Let's check if the fusion has been successful
if (!mkFuse.IsDone())
throw Base::Exception("Fusion with base feature failed");
result = mkFuse.Shape();
result = refineShapeIfActive(result);
}
this->Shape.setValue(getSolid(result));
}
else
return new App::DocumentObjectExecReturn("Could not revolve the sketch!");
return App::DocumentObject::StdReturn;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
if (std::string(e->GetMessageString()) == "TopoDS::Face")
return new App::DocumentObjectExecReturn("Could not create face from sketch.\n"
"Intersecting sketch entities in a sketch are not allowed.");
else
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
catch (Base::Exception& e) {
return new App::DocumentObjectExecReturn(e.what());
}
}
bool Revolution::suggestReversed(void)
{
updateAxis();
return ProfileBased::getReversedAngle(Base.getValue(), Axis.getValue()) < 0.0;
}
void Revolution::updateAxis(void)
{
App::DocumentObject *pcReferenceAxis = ReferenceAxis.getValue();
const std::vector<std::string> &subReferenceAxis = ReferenceAxis.getSubValues();
Base::Vector3d base;
Base::Vector3d dir;
getAxis(pcReferenceAxis, subReferenceAxis, base, dir);
Base.setValue(base.x,base.y,base.z);
Axis.setValue(dir.x,dir.y,dir.z);
}
}

View File

@@ -439,7 +439,8 @@ void CmdPartDesignNewSketch::activated(int iMsg)
// Get a valid plane from the user
unsigned validPlanes = 0;
App::GeoFeatureGroup* geoGroup = App::GeoFeatureGroup::getGroupOfObject ( pcActiveBody );
auto group = App::GeoFeatureGroupExtension::getGroupOfObject ( pcActiveBody );
auto geoGroup = dynamic_cast<App::GeoFeatureGroupExtension*>(group->getExtension(App::GeoFeatureGroupExtension::getClassTypeId()));
std::vector<App::DocumentObject*> planes;
std::vector<PartDesignGui::TaskFeaturePick::featureStatus> status;
@@ -474,14 +475,14 @@ void CmdPartDesignNewSketch::activated(int iMsg)
PartDesign::Body *planeBody = PartDesign::Body::findBodyOf (plane);
if ( planeBody ) {
if ( ( geoGroup && geoGroup->hasObject ( planeBody, true ) ) ||
!App::GeoFeatureGroup::getGroupOfObject (planeBody) ) {
!App::GeoFeatureGroupExtension::getGroupOfObject (planeBody) ) {
status.push_back ( PartDesignGui::TaskFeaturePick::otherBody );
} else {
status.push_back ( PartDesignGui::TaskFeaturePick::otherPart );
}
} else {
if ( ( geoGroup && geoGroup->hasObject ( plane, true ) ) ||
!App::GeoFeatureGroup::getGroupOfObject ( plane ) ) {
!App::GeoFeatureGroupExtension::getGroupOfObject ( plane ) ) {
status.push_back ( PartDesignGui::TaskFeaturePick::otherPart );
} else if (pcActiveBody) {
status.push_back ( PartDesignGui::TaskFeaturePick::notInBody );

View File

@@ -60,7 +60,7 @@ bool ReferenceSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, c
{
// TODO review this function (2015-09-04, Fat-Zer)
PartDesign::Body *body;
App::GeoFeatureGroup *geoGroup;
App::DocumentObject* originGroupObject = nullptr;
if ( support ) {
body = PartDesign::Body::findBodyOf (support);
@@ -69,12 +69,16 @@ bool ReferenceSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, c
}
if ( body ) { // Search for Part of the body
geoGroup = App::GeoFeatureGroup::getGroupOfObject ( body ) ;
originGroupObject = App::OriginGroupExtension::getGroupOfObject ( body ) ;
} else if ( support ) { // if no body search part for support
geoGroup = App::GeoFeatureGroup::getGroupOfObject ( support ) ;
originGroupObject = App::OriginGroupExtension::getGroupOfObject ( support ) ;
} else { // fallback to active part
geoGroup = PartDesignGui::getActivePart ( );
originGroupObject = PartDesignGui::getActivePart ( );
}
App::OriginGroupExtension* originGroup = nullptr;
if(originGroupObject)
originGroup = originGroupObject->getExtensionByType<App::OriginGroupExtension>();
// Don't allow selection in other document
if ( support && pDoc != support->getDocument() ) {
@@ -96,8 +100,8 @@ bool ReferenceSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, c
if (body->getOrigin ()->hasObject (pObj) ) {
return true;
}
} else if (geoGroup && geoGroup->isDerivedFrom ( App::OriginGroup::getClassTypeId () ) ) {
if ( static_cast<App::OriginGroup *>(geoGroup)->getOrigin ()->hasObject (pObj) ) {
} else if (originGroup ) {
if ( originGroup->getOrigin ()->hasObject (pObj) ) {
return true;
}
}

View File

@@ -238,8 +238,8 @@ bool isPartDesignAwareObjecta (App::DocumentObject *obj, bool respectGroups = fa
PartDesign::Body::isAllowed ( obj ) ||
obj->isDerivedFrom ( PartDesign::Body::getClassTypeId () ) ||
( respectGroups && (
obj->isDerivedFrom (App::GeoFeatureGroup::getClassTypeId () ) ||
obj->isDerivedFrom (App::DocumentObjectGroup::getClassTypeId () )
obj->hasExtension (App::GeoFeatureGroupExtension::getClassTypeId () ) ||
obj->hasExtension (App::GroupExtension::getClassTypeId () )
) ) );
}

View File

@@ -327,10 +327,10 @@ SbBox3f ViewProviderDatum::getRelevantBoundBox () const {
objs = body->getFullModel ();
} else {
// Probe if we belongs to some group
App::DocumentObjectGroup* group = App::DocumentObjectGroup::getGroupOfObject ( this->getObject () );
App::DocumentObject* group = App::DocumentObjectGroup::getGroupOfObject ( this->getObject () );
if(group) {
objs = group->getObjects ();
objs = dynamic_cast<App::GroupExtension*>(group->getExtension(App::GroupExtension::getClassTypeId()))->getObjects ();
} else {
// Fallback to whole document
objs = this->getObject ()->getDocument ()->getObjects ();