From 6f4e3acce4917119e745f0ee5d1bcb49a57e1996 Mon Sep 17 00:00:00 2001 From: NateAM Date: Mon, 17 Nov 2014 17:54:34 +0100 Subject: [PATCH] Added Surface module I have added Nate's SurfaceTools module with the name changed to Surface in all files and filenames. --- CMakeLists.txt | 1 + src/Mod/CMakeLists.txt | 4 + src/Mod/Surface/App/AppSurface.cpp | 73 +++ src/Mod/Surface/App/AppSurfacePy.cpp | 38 ++ src/Mod/Surface/App/CMakeLists.txt | 51 ++ src/Mod/Surface/App/FeatureBSplineSurf.cpp | 234 +++++++++ src/Mod/Surface/App/FeatureBSplineSurf.h | 54 ++ src/Mod/Surface/App/FeatureBezSurf.cpp | 232 +++++++++ src/Mod/Surface/App/FeatureBezSurf.h | 54 ++ src/Mod/Surface/App/FeatureCut.cpp | 119 +++++ src/Mod/Surface/App/FeatureCut.h | 53 ++ src/Mod/Surface/App/FeatureFilling.cpp | 461 ++++++++++++++++++ src/Mod/Surface/App/FeatureFilling.h | 77 +++ src/Mod/Surface/App/FeatureSewing.cpp | 155 ++++++ src/Mod/Surface/App/FeatureSewing.h | 59 +++ src/Mod/Surface/App/Makefile.am | 47 ++ src/Mod/Surface/App/PreCompiled.cpp | 24 + src/Mod/Surface/App/PreCompiled.h | 65 +++ src/Mod/Surface/CMakeLists.txt | 13 + src/Mod/Surface/Gui/AppSurfaceGui.cpp | 66 +++ src/Mod/Surface/Gui/AppSurfaceGuiPy.cpp | 35 ++ src/Mod/Surface/Gui/CMakeLists.txt | 54 ++ src/Mod/Surface/Gui/Command.cpp | 150 ++++++ src/Mod/Surface/Gui/Makefile.am | 79 +++ src/Mod/Surface/Gui/PreCompiled.cpp | 24 + src/Mod/Surface/Gui/PreCompiled.h | 81 +++ src/Mod/Surface/Gui/Resources/Surface.qrc | 9 + .../Gui/Resources/icons/BSplineSurf.svg | 307 ++++++++++++ .../Surface/Gui/Resources/icons/BezSurf.svg | 329 +++++++++++++ src/Mod/Surface/Gui/Resources/icons/Cut.svg | 287 +++++++++++ .../Surface/Gui/Resources/icons/Filling.svg | 303 ++++++++++++ .../Surface/Gui/Resources/icons/Sewing.svg | 281 +++++++++++ .../Surface/Gui/Resources/icons/Surface.svg | 281 +++++++++++ src/Mod/Surface/Gui/Workbench.cpp | 78 +++ src/Mod/Surface/Gui/Workbench.h | 47 ++ src/Mod/Surface/Gui/qrc_Surface.cxx | 30 ++ src/Mod/Surface/Init.py | 2 + src/Mod/Surface/InitGui.py | 87 ++++ src/Mod/Surface/Makefile.am | 10 + src/Mod/Surface/Surface.dox | 3 + 40 files changed, 4357 insertions(+) create mode 100644 src/Mod/Surface/App/AppSurface.cpp create mode 100644 src/Mod/Surface/App/AppSurfacePy.cpp create mode 100644 src/Mod/Surface/App/CMakeLists.txt create mode 100644 src/Mod/Surface/App/FeatureBSplineSurf.cpp create mode 100644 src/Mod/Surface/App/FeatureBSplineSurf.h create mode 100644 src/Mod/Surface/App/FeatureBezSurf.cpp create mode 100644 src/Mod/Surface/App/FeatureBezSurf.h create mode 100644 src/Mod/Surface/App/FeatureCut.cpp create mode 100644 src/Mod/Surface/App/FeatureCut.h create mode 100644 src/Mod/Surface/App/FeatureFilling.cpp create mode 100644 src/Mod/Surface/App/FeatureFilling.h create mode 100644 src/Mod/Surface/App/FeatureSewing.cpp create mode 100644 src/Mod/Surface/App/FeatureSewing.h create mode 100644 src/Mod/Surface/App/Makefile.am create mode 100644 src/Mod/Surface/App/PreCompiled.cpp create mode 100644 src/Mod/Surface/App/PreCompiled.h create mode 100644 src/Mod/Surface/CMakeLists.txt create mode 100644 src/Mod/Surface/Gui/AppSurfaceGui.cpp create mode 100644 src/Mod/Surface/Gui/AppSurfaceGuiPy.cpp create mode 100644 src/Mod/Surface/Gui/CMakeLists.txt create mode 100644 src/Mod/Surface/Gui/Command.cpp create mode 100644 src/Mod/Surface/Gui/Makefile.am create mode 100644 src/Mod/Surface/Gui/PreCompiled.cpp create mode 100644 src/Mod/Surface/Gui/PreCompiled.h create mode 100644 src/Mod/Surface/Gui/Resources/Surface.qrc create mode 100644 src/Mod/Surface/Gui/Resources/icons/BSplineSurf.svg create mode 100644 src/Mod/Surface/Gui/Resources/icons/BezSurf.svg create mode 100644 src/Mod/Surface/Gui/Resources/icons/Cut.svg create mode 100644 src/Mod/Surface/Gui/Resources/icons/Filling.svg create mode 100644 src/Mod/Surface/Gui/Resources/icons/Sewing.svg create mode 100644 src/Mod/Surface/Gui/Resources/icons/Surface.svg create mode 100644 src/Mod/Surface/Gui/Workbench.cpp create mode 100644 src/Mod/Surface/Gui/Workbench.h create mode 100644 src/Mod/Surface/Gui/qrc_Surface.cxx create mode 100644 src/Mod/Surface/Init.py create mode 100644 src/Mod/Surface/InitGui.py create mode 100644 src/Mod/Surface/Makefile.am create mode 100644 src/Mod/Surface/Surface.dox diff --git a/CMakeLists.txt b/CMakeLists.txt index d1efecc66e..448eb9ac31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,6 +244,7 @@ OPTION(BUILD_TEST "Build the FreeCAD test module" ON) OPTION(BUILD_TECHDRAW "Build the FreeCAD Technical Drawing module" ON) OPTION(BUILD_TUX "Build the FreeCAD Tux module" ON) OPTION(BUILD_WEB "Build the FreeCAD web module" ON) +OPTION(BUILD_SURFACE "Build the FreeCAD surface module" ON) OPTION(BUILD_VR "Build the FreeCAD Oculus Rift support (need Oculus SDK 4.x or higher)" OFF) if(MSVC) diff --git a/src/Mod/CMakeLists.txt b/src/Mod/CMakeLists.txt index 01f45368f2..a6906e165b 100644 --- a/src/Mod/CMakeLists.txt +++ b/src/Mod/CMakeLists.txt @@ -70,6 +70,10 @@ if(BUILD_WEB) add_subdirectory(Web) endif(BUILD_WEB) +if(BUILD_SURFACE) + add_subdirectory(Surface) +endif(BUILD_SURFACE) + if(BUILD_START) add_subdirectory(Start) endif(BUILD_START) diff --git a/src/Mod/Surface/App/AppSurface.cpp b/src/Mod/Surface/App/AppSurface.cpp new file mode 100644 index 0000000000..7bfaaa1e60 --- /dev/null +++ b/src/Mod/Surface/App/AppSurface.cpp @@ -0,0 +1,73 @@ +/*************************************************************************** + * Copyright (c) 2014 Nathan Miller * + * * + * 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 +#endif + +#include +#include "FeatureFilling.h" +#include "FeatureSewing.h" +#include "FeatureCut.h" +#include "FeatureBezSurf.h" +#include "FeatureBSplineSurf.h" + +#include +#include + + +/* registration table */ +extern struct PyMethodDef Surface_methods[]; + +PyDoc_STRVAR(module_Surface_doc, +"This module is the Surface module."); + + +/* Python entry */ +extern "C" { +void SurfaceExport initSurface() { + + try { + Base::Interpreter().runString("import Part"); + } + catch(const Base::Exception& e) { + PyErr_SetString(PyExc_ImportError, e.what()); + return; + } + + // ADD YOUR CODE HERE + // + // + (void) Py_InitModule3("Surface", Surface_methods, module_Surface_doc); /* mod name, table ptr */ + Base::Console().Log("Loading Surface module... done\n"); + + // Add types to module + Surface::Filling ::init(); + Surface::Sewing ::init(); + Surface::Cut ::init(); + Surface::BezSurf ::init(); + Surface::BSplineSurf ::init(); +} + +} // extern "C" diff --git a/src/Mod/Surface/App/AppSurfacePy.cpp b/src/Mod/Surface/App/AppSurfacePy.cpp new file mode 100644 index 0000000000..d62cd5f63d --- /dev/null +++ b/src/Mod/Surface/App/AppSurfacePy.cpp @@ -0,0 +1,38 @@ +/*************************************************************************** + * Copyright (c) 2014 Nathan Miller Nathan.A.Mill[at]gmail.com * + * * + * 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_ +#endif + +#include + +#include +#include +#include + + +/* registration table */ +struct PyMethodDef Surface_methods[] = { + {NULL, NULL} /* end of table marker */ +}; diff --git a/src/Mod/Surface/App/CMakeLists.txt b/src/Mod/Surface/App/CMakeLists.txt new file mode 100644 index 0000000000..ff5d1290ef --- /dev/null +++ b/src/Mod/Surface/App/CMakeLists.txt @@ -0,0 +1,51 @@ +if(MSVC) + add_definitions(-DHAVE_ACOSH -DHAVE_ASINH -DHAVE_ATANH) +else(MSVC) + add_definitions(-DHAVE_LIMITS_H -DHAVE_CONFIG_H) +endif(MSVC) + +include_directories( + ${Boost_INCLUDE_DIRS} + ${OCC_INCLUDE_DIR} + ${PYTHON_INCLUDE_PATH} + ${ZLIB_INCLUDE_DIR} + ${XERCESC_INCLUDE_DIR} + ${QT_QTCORE_INCLUDE_DIR} +) + +set(Surface_LIBS + FreeCADApp + Part +) + +SET(Surface_SRCS + AppSurface.cpp + AppSurfacePy.cpp + PreCompiled.cpp + PreCompiled.h + FeatureFilling.h + FeatureFilling.cpp + FeatureSewing.h + FeatureSewing.cpp + FeatureCut.h + FeatureCut.cpp + FeatureBezSurf.h + FeatureBezSurf.cpp + FeatureBSplineSurf.h + FeatureBSplineSurf.cpp +) + +link_directories(${OCC_LIBRARY_DIR}) +add_library(Surface SHARED ${Surface_SRCS}) +target_link_libraries(Surface ${Surface_LIBS}) + + +fc_target_copy_resource(Surface + ${CMAKE_SOURCE_DIR}/src/Mod/Surface + ${CMAKE_BINARY_DIR}/Mod/Surface + Init.py) + +SET_BIN_DIR(Surface Surface /Mod/Surface) +SET_PYTHON_PREFIX_SUFFIX(Surface) + +install(TARGETS Surface DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/src/Mod/Surface/App/FeatureBSplineSurf.cpp b/src/Mod/Surface/App/FeatureBSplineSurf.cpp new file mode 100644 index 0000000000..75d85dabe7 --- /dev/null +++ b/src/Mod/Surface/App/FeatureBSplineSurf.cpp @@ -0,0 +1,234 @@ +/*************************************************************************** + * Copyright (c) 2014 Nathan Miller * + * * + * 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 +#include +#include +#include +#include +#include +#include +#endif + +#include "FeatureBSplineSurf.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace Surface; + +PROPERTY_SOURCE(Surface::BSplineSurf, Part::Feature) + +//Initial values + +BSplineSurf::BSplineSurf() +{ + ADD_PROPERTY(aBSplineList,(0,"Geom_BSplineCurve")); + ADD_PROPERTY(filltype,(1)); + +} + +//Structures + +struct crvs{ + + Handle_Geom_BSplineCurve C1; + Handle_Geom_BSplineCurve C2; + Handle_Geom_BSplineCurve C3; + Handle_Geom_BSplineCurve C4; + +}; + +//Functions + +void getCurves(GeomFill_BSplineCurves& aBuilder,TopoDS_Wire& aWire, const App::PropertyLinkSubList& anEdge, GeomFill_FillingStyle fstyle); +//bool orderCurves(crvs& Cs, int size); + +//Check if any components of the surface have been modified + +short BSplineSurf::mustExecute() const +{ + if (aBSplineList.isTouched() || + filltype.isTouched()) + return 1; + return 0; +} + +App::DocumentObjectExecReturn *BSplineSurf::execute(void) +{ + + //Set Variables + + int ftype = filltype.getValue(); + + //Begin Construction + try{ + + //Identify filling style + + GeomFill_FillingStyle fstyle; + + if(ftype==1){fstyle = GeomFill_StretchStyle;} + else if(ftype==2){fstyle = GeomFill_CoonsStyle;} + else if(ftype==3){fstyle = GeomFill_CurvedStyle;} + else{return new App::DocumentObjectExecReturn("Filling style must be 1 (Stretch), 2 (Coons), or 3 (Curved).");} + + //Create BSpline Surface + + GeomFill_BSplineCurves aSurfBuilder; //Create Surface Builder +// BRepBuilderAPI_MakeWire aWireBuilder; //Create Wire Builder + TopoDS_Wire aWire; //Create empty wire + + //Get BSpline Curves from edges and initialize the builder + + printf("Entering getCurves\n"); + getCurves(aSurfBuilder,aWire,aBSplineList,fstyle); + + //Create the surface + printf("Creating the Surface\n"); + const Handle_Geom_BSplineSurface aSurface = aSurfBuilder.Surface(); + + printf("Creating the Face\n"); + BRepBuilderAPI_MakeFace aFaceBuilder(aSurface,aWire,Standard_True); //Create Face Builder +// Standard_Real u0 = 0.; +// Standard_Real u1 = 2.; +// Standard_Real v0 = 0.; +// Standard_Real v1 = 2.; +// aFaceBuilder.Init(aSurface,u0,u1,v0,v1,Precision::Confusion()); + + printf("Returning the Face\n"); + TopoDS_Face aFace = aFaceBuilder.Face(); //Returned Face + if(!aFaceBuilder.IsDone()){return new App::DocumentObjectExecReturn("Face unable to be constructed");} + + if (aFace.IsNull()){ + return new App::DocumentObjectExecReturn("Resulting Face is null"); + } + this->Shape.setValue(aFace); + + return App::DocumentObject::StdReturn; + + } //End Try + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + return new App::DocumentObjectExecReturn(e->GetMessageString()); + } //End Catch + +} //End execute + +void getCurves(GeomFill_BSplineCurves& aBuilder,TopoDS_Wire& aWire, const App::PropertyLinkSubList& anEdge, GeomFill_FillingStyle fstyle){ +//void getCurves(TopoDS_Wire& aWire, const App::PropertyLinkSubList& anEdge){ + + crvs bcrv; + + Standard_Real u0 = 0.; + Standard_Real u1 = 1.; + + Handle(ShapeFix_Wire) aShFW = new ShapeFix_Wire; + Handle(ShapeExtend_WireData) aWD = new ShapeExtend_WireData; + + if(anEdge.getSize()>4){Standard_Failure::Raise("Only 2-4 continuous BSpline Curves are allowed");return;} + if(anEdge.getSize()<2){Standard_Failure::Raise("Only 2-4 continuous BSpline Curves are allowed");return;} + + for(int i=0; igetTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + + ts = static_cast(set.obj)->Shape.getShape(); + + //we want only the subshape which is linked + sub = ts.getSubShape(set.sub); + + if(sub.ShapeType() == TopAbs_EDGE) {etmp = TopoDS::Edge(sub);} //Check Shape type and assign edge + else{Standard_Failure::Raise("Curves must be type TopoDS_Edge");return;} //Raise exception + + aWD->Add(etmp); + + } + + else{Standard_Failure::Raise("Curve not from Part::Feature");return;} + + } + + //Reorder the curves and fix the wire if required + + aShFW->Load(aWD); //Load in the wire + aShFW->FixReorder(); //Fix the order of the edges if required + aShFW->ClosedWireMode() = Standard_True; //Enables closed wire mode + aShFW->FixConnected(); //Fix connection between wires + aShFW->FixSelfIntersection(); //Fix Self Intersection + aShFW->Perform(); //Perform the fixes + + aWire = aShFW->Wire(); //Healed Wire + + if(aWire.IsNull()){Standard_Failure::Raise("Wire unable to be constructed");return;} + + //Create BSpline Surface + + TopExp_Explorer anExp (aWire, TopAbs_EDGE); + int it = 0; + for (; anExp.More(); anExp.Next()) { + const TopoDS_Edge hedge = TopoDS::Edge (anExp.Current()); + TopLoc_Location heloc = hedge.Location(); + Handle_Geom_Curve c_geom = BRep_Tool::Curve(hedge,heloc,u0,u1); //The geometric curve + Handle_Geom_BSplineCurve b_geom = Handle_Geom_BSplineCurve::DownCast(c_geom); //Try to get BSpline curve + + if (!b_geom.IsNull()) { + //Store Underlying Geometry + if(it==0){bcrv.C1 = b_geom;} + else if(it==1){bcrv.C2 = b_geom;} + else if(it==2){bcrv.C3 = b_geom;} + else if(it==3){bcrv.C4 = b_geom;} + + } + else { + Standard_Failure::Raise("Curve not a BSpline Curve"); + return; + } + + it++; + } + + int ncrv = anEdge.getSize(); + + if(ncrv==2){aBuilder.Init(bcrv.C1,bcrv.C2,fstyle);} + else if(ncrv==3){aBuilder.Init(bcrv.C1,bcrv.C2,bcrv.C3,fstyle);} + else if(ncrv==4){aBuilder.Init(bcrv.C1,bcrv.C2,bcrv.C3,bcrv.C4,fstyle);} + + return; +} diff --git a/src/Mod/Surface/App/FeatureBSplineSurf.h b/src/Mod/Surface/App/FeatureBSplineSurf.h new file mode 100644 index 0000000000..fefcdd8bd5 --- /dev/null +++ b/src/Mod/Surface/App/FeatureBSplineSurf.h @@ -0,0 +1,54 @@ +/*************************************************************************** + * Copyright (c) 2014 Nathan Miller * + * * + * 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 SURFACE_FEATUREBSPLINESURF_H +#define SURFACE_FEATUREBSPLINESURF_H + +#include +#include +#include +#include "Mod/Part/App/PartFeature.h" + +namespace Surface +{ + +class SurfaceExport BSplineSurf : public Part::Feature +{ + PROPERTY_HEADER(Surface::BSplineSurf); + +public: + BSplineSurf(); + + App::PropertyLinkSubList aBSplineList; //BSpline curves to be turned into a face (2-4 curves allowed). + App::PropertyInteger filltype; //Fill method (1, 2, or 3 for Stretch, Coons, and Curved) + + // recalculate the feature + App::DocumentObjectExecReturn *execute(void); + short mustExecute() const; + /// returns the type name of the view provider +// const char* getViewProviderName(void) const { +// return "PartGui::ViewProviderCut"; +// } + +}; +}//Namespace Surface +#endif diff --git a/src/Mod/Surface/App/FeatureBezSurf.cpp b/src/Mod/Surface/App/FeatureBezSurf.cpp new file mode 100644 index 0000000000..68f396a957 --- /dev/null +++ b/src/Mod/Surface/App/FeatureBezSurf.cpp @@ -0,0 +1,232 @@ +/*************************************************************************** + * Copyright (c) 2014 Nathan Miller * + * * + * 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 +#include +#include +#include +#include +#include +#include +#endif + +#include "FeatureBezSurf.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace Surface; + +PROPERTY_SOURCE(Surface::BezSurf, Part::Feature) + +//Initial values + +BezSurf::BezSurf() +{ + ADD_PROPERTY(aBezList,(0,"Geom_BezierCurve")); + ADD_PROPERTY(filltype,(1)); + +} + +//Structures + +struct crvs{ + + Handle_Geom_BezierCurve C1; + Handle_Geom_BezierCurve C2; + Handle_Geom_BezierCurve C3; + Handle_Geom_BezierCurve C4; + +}; + +//Functions + +void getCurves(GeomFill_BezierCurves& aBuilder,TopoDS_Wire& aWire, const App::PropertyLinkSubList& anEdge, GeomFill_FillingStyle fstyle); +//bool orderCurves(crvs& Cs, int size); + +//Check if any components of the surface have been modified + +short BezSurf::mustExecute() const +{ + if (aBezList.isTouched() || + filltype.isTouched()) + return 1; + return 0; +} + +App::DocumentObjectExecReturn *BezSurf::execute(void) +{ + + //Set Variables + + int ftype = filltype.getValue(); + + //Begin Construction + try{ + + //Identify filling style + + GeomFill_FillingStyle fstyle; + + if(ftype==1){fstyle = GeomFill_StretchStyle;} + else if(ftype==2){fstyle = GeomFill_CoonsStyle;} + else if(ftype==3){fstyle = GeomFill_CurvedStyle;} + else{return new App::DocumentObjectExecReturn("Filling style must be 1 (Stretch), 2 (Coons), or 3 (Curved).");} + + //Create Bezier Surface + + GeomFill_BezierCurves aSurfBuilder; //Create Surface Builder +// BRepBuilderAPI_MakeWire aWireBuilder; //Create Wire Builder + TopoDS_Wire aWire; //Create empty wire + + //Get Bezier Curves from edges and initialize the builder + + getCurves(aSurfBuilder,aWire,aBezList,fstyle); + + //Create the surface + + const Handle_Geom_BezierSurface aSurface = aSurfBuilder.Surface(); + + BRepBuilderAPI_MakeFace aFaceBuilder;//(aSurface,aWire,Standard_True); //Create Face Builder + Standard_Real u0 = 0.; + Standard_Real u1 = 1.; + Standard_Real v0 = 0.; + Standard_Real v1 = 1.; + aFaceBuilder.Init(aSurface,u0,u1,v0,v1,Precision::Confusion()); + + TopoDS_Face aFace = aFaceBuilder.Face(); //Returned Face + if(!aFaceBuilder.IsDone()){return new App::DocumentObjectExecReturn("Face unable to be constructed");} + + if (aFace.IsNull()){ + return new App::DocumentObjectExecReturn("Resulting Face is null"); + } + this->Shape.setValue(aFace); + + return App::DocumentObject::StdReturn; + + } //End Try + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + return new App::DocumentObjectExecReturn(e->GetMessageString()); + } //End Catch + +} //End execute + +void getCurves(GeomFill_BezierCurves& aBuilder,TopoDS_Wire& aWire, const App::PropertyLinkSubList& anEdge, GeomFill_FillingStyle fstyle){ +//void getCurves(TopoDS_Wire& aWire, const App::PropertyLinkSubList& anEdge){ + + crvs bcrv; + + Standard_Real u0 = 0.; + Standard_Real u1 = 1.; + + Handle(ShapeFix_Wire) aShFW = new ShapeFix_Wire; + Handle(ShapeExtend_WireData) aWD = new ShapeExtend_WireData; + + if(anEdge.getSize()>4){Standard_Failure::Raise("Only 2-4 continuous Bezier Curves are allowed");return;} + if(anEdge.getSize()<2){Standard_Failure::Raise("Only 2-4 continuous Bezier Curves are allowed");return;} + + for(int i=0; igetTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + + ts = static_cast(set.obj)->Shape.getShape(); + + //we want only the subshape which is linked + sub = ts.getSubShape(set.sub); + + if(sub.ShapeType() == TopAbs_EDGE) {etmp = TopoDS::Edge(sub);} //Check Shape type and assign edge + else{Standard_Failure::Raise("Curves must be type TopoDS_Edge");return;} //Raise exception + + aWD->Add(etmp); + + } + + else{Standard_Failure::Raise("Curve not from Part::Feature");return;} + + } + + //Reorder the curves and fix the wire if required + + aShFW->Load(aWD); //Load in the wire + aShFW->FixReorder(); //Fix the order of the edges if required + aShFW->ClosedWireMode() = Standard_True; //Enables closed wire mode + aShFW->FixConnected(); //Fix connection between wires + aShFW->FixSelfIntersection(); //Fix Self Intersection + aShFW->Perform(); //Perform the fixes + + aWire = aShFW->Wire(); //Healed Wire + + if(aWire.IsNull()){Standard_Failure::Raise("Wire unable to be constructed");return;} + + //Create Bezier Surface + + TopExp_Explorer anExp (aWire, TopAbs_EDGE); + int it = 0; + for (; anExp.More(); anExp.Next()) { + printf("it: %i",it); + const TopoDS_Edge hedge = TopoDS::Edge (anExp.Current()); + TopLoc_Location heloc = hedge.Location(); + Handle_Geom_Curve c_geom = BRep_Tool::Curve(hedge,heloc,u0,u1); //The geometric curve + Handle_Geom_BezierCurve b_geom = Handle_Geom_BezierCurve::DownCast(c_geom); //Try to get Bezier curve + + if (!b_geom.IsNull()) { + //Store Underlying Geometry + if(it==0){bcrv.C1 = b_geom;} + else if(it==1){bcrv.C2 = b_geom;} + else if(it==2){bcrv.C3 = b_geom;} + else if(it==3){bcrv.C4 = b_geom;} + + } + else { + Standard_Failure::Raise("Curve not a Bezier Curve"); + return; + } + + it++; + } + + int ncrv = anEdge.getSize(); + + if(ncrv==2){aBuilder.Init(bcrv.C1,bcrv.C2,fstyle);} + else if(ncrv==3){aBuilder.Init(bcrv.C1,bcrv.C2,bcrv.C3,fstyle);} + else if(ncrv==4){aBuilder.Init(bcrv.C1,bcrv.C2,bcrv.C3,bcrv.C4,fstyle);} + + return; +} diff --git a/src/Mod/Surface/App/FeatureBezSurf.h b/src/Mod/Surface/App/FeatureBezSurf.h new file mode 100644 index 0000000000..a85b7faaf9 --- /dev/null +++ b/src/Mod/Surface/App/FeatureBezSurf.h @@ -0,0 +1,54 @@ +/*************************************************************************** + * Copyright (c) 2014 Nathan Miller * + * * + * 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 SURFACE_FEATUREBEZSURF_H +#define SURFACE_FEATUREBEZSURF_H + +#include +#include +#include +#include "Mod/Part/App/PartFeature.h" + +namespace Surface +{ + +class SurfaceExport BezSurf : public Part::Feature +{ + PROPERTY_HEADER(Surface::BezSurf); + +public: + BezSurf(); + + App::PropertyLinkSubList aBezList; //Bezier curves to be turned into a face (2-4 curves allowed). + App::PropertyInteger filltype; //Fill method (1, 2, or 3 for Stretch, Coons, and Curved) + + // recalculate the feature + App::DocumentObjectExecReturn *execute(void); + short mustExecute() const; + /// returns the type name of the view provider +// const char* getViewProviderName(void) const { +// return "PartGui::ViewProviderCut"; +// } + +}; +}//Namespace Surface +#endif diff --git a/src/Mod/Surface/App/FeatureCut.cpp b/src/Mod/Surface/App/FeatureCut.cpp new file mode 100644 index 0000000000..5443964887 --- /dev/null +++ b/src/Mod/Surface/App/FeatureCut.cpp @@ -0,0 +1,119 @@ +/*************************************************************************** + * Copyright (c) 2014 Nathan Miller * + * * + * 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 +#include +#include +#include +#endif + +#include "FeatureCut.h" +#include +#include +#include +#include +#include +#include +#include + +using namespace Surface; + +PROPERTY_SOURCE(Surface::Cut, Part::Feature) + +//Initial values + +Cut::Cut() +{ + ADD_PROPERTY(aShapeList,(0,"TopoDS_Shape")); + +} + +//Check if any components of the surface have been modified + +short Cut::mustExecute() const +{ + if (aShapeList.isTouched()) + return 1; + return 0; +} + +App::DocumentObjectExecReturn *Cut::execute(void) +{ + + //Perform error checking + + bool res; + + //Begin Construction + try{ + + if((aShapeList.getSize()>2) || (aShapeList.getSize()<2)){ + return new App::DocumentObjectExecReturn("Two shapes must be entered at a time for a cut operation"); + } + + //Initialize variables for first toposhape from document object + Part::TopoShape ts1; + TopoDS_Shape sub1; + App::PropertyLinkSubList::SubSet set1 = aShapeList[0]; + + //Initialize variables for second toposhape from document object + Part::TopoShape ts2; + TopoDS_Shape sub2; + App::PropertyLinkSubList::SubSet set2 = aShapeList[1]; + + //Get first toposhape + printf("Get first toposhape\n"); + if(set1.obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + + ts1 = static_cast(set1.obj)->Shape.getShape(); //Part::TopoShape 1 + + } + else{return new App::DocumentObjectExecReturn("Shape1 not from Part::Feature");} + + //Get second toposhape + printf("Get second toposhape\n"); + if(set2.obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + + ts2 = static_cast(set2.obj)->Shape.getShape(); + + } + else{return new App::DocumentObjectExecReturn("Shape2 not from Part::Feature");} + + //Cut Shape1 by Shape2 + TopoDS_Shape aCutShape; + aCutShape = ts1.cut(ts2._Shape); + + //Check if resulting shell is null + if (aCutShape.IsNull()){ + return new App::DocumentObjectExecReturn("Resulting shape is null"); + } + this->Shape.setValue(aCutShape); + + } //End Try + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + return new App::DocumentObjectExecReturn(e->GetMessageString()); + } //End Catch + +} //End execute diff --git a/src/Mod/Surface/App/FeatureCut.h b/src/Mod/Surface/App/FeatureCut.h new file mode 100644 index 0000000000..e0320ec7c4 --- /dev/null +++ b/src/Mod/Surface/App/FeatureCut.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (c) 2014 Nathan Miller * + * * + * 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 SURFACE_FEATURECUT_H +#define SURFACE_FEATURECUT_H + +#include +#include +#include +#include "Mod/Part/App/PartFeature.h" + +namespace Surface +{ + +class SurfaceExport Cut : public Part::Feature +{ + PROPERTY_HEADER(Surface::Cut); + +public: + Cut(); + + App::PropertyLinkSubList aShapeList; //Shapes to be cut. + + // recalculate the feature + App::DocumentObjectExecReturn *execute(void); + short mustExecute() const; + /// returns the type name of the view provider +// const char* getViewProviderName(void) const { +// return "SurfaceGui::ViewProviderCut"; +// } + +}; +}//Namespace Surface +#endif diff --git a/src/Mod/Surface/App/FeatureFilling.cpp b/src/Mod/Surface/App/FeatureFilling.cpp new file mode 100644 index 0000000000..6324692cd2 --- /dev/null +++ b/src/Mod/Surface/App/FeatureFilling.cpp @@ -0,0 +1,461 @@ +/*************************************************************************** + * Copyright (c) 2014 Nathan Miller * + * * + * 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 +#include +#include +#include +#include +#endif + +#include "FeatureFilling.h" +#include +#include +#include +#include +#include +#include + +using namespace Surface; + +PROPERTY_SOURCE(Surface::Filling, Part::Feature) + +//Initial values + +Filling::Filling() +{ + ADD_PROPERTY(Border,(0,"TopoDS_Edge")); + + ADD_PROPERTY(Curves,(0,"TopoDS_Edge")); + + ADD_PROPERTY(BFaces,(0,"TopoDS_Face")); + ADD_PROPERTY(orderB,(-1)); + ADD_PROPERTY(CFaces,(0,"TopoDS_Face")); + ADD_PROPERTY(orderC,(-1)); + + ADD_PROPERTY(Points,(0,"TopoDS_Vertex")); + + ADD_PROPERTY(initFace,(0,"TopoDS_Face")); + + ADD_PROPERTY(Degree,(3)); + ADD_PROPERTY(NbPtsOnCur,(3)); + ADD_PROPERTY(NbIter,(2)); + ADD_PROPERTY(Anisotropie,(false)); + ADD_PROPERTY(Tol2d,(0.00001)); + ADD_PROPERTY(Tol3d,(0.0001)); + ADD_PROPERTY(TolAng,(0.001)); + ADD_PROPERTY(TolCurv,(0.01)); + ADD_PROPERTY(MaxDeg,(8)); + ADD_PROPERTY(MaxSegments,(10000)); +} + +//Define Functions + +void appconstr_crv(BRepFill_Filling& builder,const App::PropertyLinkSubList& anEdge, Standard_Boolean bnd); +void appconstr_bface(BRepFill_Filling& builder,const App::PropertyLinkSubList& aFace, const App::PropertyIntegerList& Order); +void appconstr_crvface(BRepFill_Filling& builder, const App::PropertyLinkSubList& anEdge, const App::PropertyLinkSubList& aFace, const App::PropertyIntegerList& Order, Standard_Boolean bnd); +void appconstr_pt(BRepFill_Filling& builder,const App::PropertyLinkSubList& aVertex); +void appinitface(BRepFill_Filling& builder,const App::PropertyLinkSubList& aFace); + +//Check if any components of the surface have been modified + +short Filling::mustExecute() const +{ + if (Border.isTouched() || + Curves.isTouched() || + BFaces.isTouched() || + orderB.isTouched() || + CFaces.isTouched() || + orderC.isTouched() || + Points.isTouched() || + initFace.isTouched() || + Degree.isTouched() || + NbPtsOnCur.isTouched() || + NbIter.isTouched() || + Anisotropie.isTouched() || + Tol2d.isTouched() || + Tol3d.isTouched() || + TolAng.isTouched() || + TolCurv.isTouched() || + MaxDeg.isTouched() || + MaxSegments.isTouched()) + return 1; + return 0; +} + +App::DocumentObjectExecReturn *Filling::execute(void) +{ + + //Assign Variables + + + + unsigned int Deg = Degree.getValue(); + unsigned int NPOC = NbPtsOnCur.getValue(); + unsigned int NI = NbIter.getValue(); + bool Anis = Anisotropie.getValue(); + double T2d = Tol2d.getValue(); + double T3d = Tol3d.getValue(); + double TG1 = TolAng.getValue(); + double TG2 = TolCurv.getValue(); + unsigned int Mdeg = MaxDeg.getValue(); + unsigned int Mseg = MaxSegments.getValue(); + + bool res; + + //Perform error checking + + + //Begin Construction + try{ + + //Generate Builder with Algorithm Variables + + BRepFill_Filling builder(Deg,NPOC,NI,Anis,T2d,T3d,TG1,TG2,Mdeg,Mseg); + + //Check that borders are defined + printf("Surface Filling\n"); + + if((Border.getSize())<1){return new App::DocumentObjectExecReturn("Border must have at least one curve defined.");} + + //Assign Boundaries + if(Border.getSize()>0){appconstr_crvface(builder, Border, BFaces, orderB, Standard_True);} + + //Assign Additional Curves if available + + if(Curves.getSize()>0){appconstr_crvface(builder, Curves, CFaces, orderC, Standard_False);} + +/* //Assign Faces + + if(BFaces.getSize()>0){appconstr_bface(builder, BFaces, orderBFaces);} +*/ + //Assign Point Constraints + + if(Points.getSize()>0){appconstr_pt(builder,Points);} + + //Assign Initial Face + + if(initFace.getSize()>0){appinitface(builder,initFace);} + + printf("Building...\n"); + + //Build the face + builder.Build(); + if (!builder.IsDone()){Standard_Failure::Raise("Failed to create a face from constraints");} + + printf("Build Complete\n"); + + //Return the face + TopoDS_Face aFace = builder.Face(); + + if (aFace.IsNull()){ + return new App::DocumentObjectExecReturn("Resulting shape is null"); + } + this->Shape.setValue(aFace); + + return App::DocumentObject::StdReturn; + + } //End Try + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + return new App::DocumentObjectExecReturn(e->GetMessageString()); + } //End Catch + +} //End execute +/* +void appconstr_crv(BRepFill_Filling& builder,const App::PropertyLinkSubList& anEdge, Standard_Boolean bnd){ + + printf("Inside appconstr_crv\n"); + + int res; + + printf("Entering for loop\n"); + + for(int i=0; igetTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + + //we get the shape of the document object which resemble the whole box + ts = static_cast(set.obj)->Shape.getShape(); + + //we want only the subshape which is linked + sub = ts.getSubShape(set.sub); + + if(sub.ShapeType() == TopAbs_EDGE) {etmp = TopoDS::Edge(sub);} //Check Shape type and assign edge + else{Standard_Failure::Raise("Curves must be type TopoDS_Edge");return;} //Raise exception + + } + + else{Standard_Failure::Raise("Boundary or Curve not from Part::Feature");return;} + + res = builder.Add(etmp,GeomAbs_C0,bnd); + + printf("Result of builder.Add: %i\n",res); + + } +} +*/ +/* +void appconstr_bface(BRepFill_Filling& builder,const App::PropertyLinkSubList& aFace, const App::PropertyIntegerList& Order){ + + int res; + + GeomAbs_Shape ordtmp; + + std::vector::const_iterator bc = Order.getValues().begin(); //Get the order values + + for(int i=0; igetTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + + ts = static_cast(set.obj)->Shape.getShape(); + + sub = ts.getSubShape(set.sub); + + if(sub.ShapeType() == TopAbs_FACE) {ftmp = TopoDS::Face(sub);} //Check Shape type and assign edge + else{Standard_Failure::Raise("Faces must be type TopoDS_Face");} //Raise exception + + } + + else{Standard_Failure::Raise("Face not from Part::Feature");} + + //PropertyEnumerateList doesn't exist yet. Fix when implemented + + if(*bc==0){ordtmp = GeomAbs_C0;} + else if(*bc==1){ordtmp = GeomAbs_G1;} + else if(*bc==2){ordtmp = GeomAbs_G2;} + else{Standard_Failure::Raise("Continuity constraint must be 0, 1 or 2 for C0, G1, and G2.");return;} + + printf("*bc: %li\n",*bc); + + res = builder.Add(ftmp,ordtmp); + + printf("res: %i\n",res); + + bc++; + + + } + + return; +} +*/ +void appconstr_crvface(BRepFill_Filling& builder, const App::PropertyLinkSubList& anEdge, const App::PropertyLinkSubList& aFace, const App::PropertyIntegerList& Order, Standard_Boolean bnd){ + + int res; + + GeomAbs_Shape ordtmp; + + std::vector::const_iterator bc = Order.getValues().begin(); //Get the order values + int fconit = 0; + + for(int i=0; igetTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + + ts_edge = static_cast(set_edge.obj)->Shape.getShape(); + + //we want only the subshape which is linked + sub_edge = ts_edge.getSubShape(set_edge.sub); + + if(sub_edge.ShapeType() == TopAbs_EDGE) {etmp = TopoDS::Edge(sub_edge);} //Check Shape type and assign edge + else{Standard_Failure::Raise("Curves must be type TopoDS_Edge");return;} //Raise exception + + } + + else{Standard_Failure::Raise("Boundary or Curve not from Part::Feature");return;} + + /*********************************/ + + //Get Order + + //PropertyEnumerateList doesn't exist yet. Fix when implemented + + if(*bc==0){ordtmp = GeomAbs_C0;} + else if(*bc==1){ordtmp = GeomAbs_G1;} + else if(*bc==2){ordtmp = GeomAbs_G2;} + else{Standard_Failure::Raise("Continuity constraint must be 0, 1 or 2 for C0, G1, and G2.");return;} + + /*********************************/ + + //Get Face if required + + if(ordtmp==GeomAbs_C0){ + + res = builder.Add(etmp,ordtmp,bnd); + + } + + else{ + +// if(aFace.getSize()getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + + ts_face = static_cast(set_face.obj)->Shape.getShape(); + + sub_face = ts_face.getSubShape(set_face.sub); + + if(sub_face.ShapeType() == TopAbs_FACE) {ftmp = TopoDS::Face(sub_face);} //Check Shape type and assign edge + else{Standard_Failure::Raise("Faces must be type TopoDS_Face");} //Raise exception + + } + + else{Standard_Failure::Raise("Face not from Part::Feature");} + + printf("*bc: %li\n",*bc); + + res = builder.Add(etmp,ftmp,ordtmp,bnd); + + fconit++; + + } + + printf("res: %i\n",res); + + bc++; + + } + + return; +} + +void appconstr_pt(BRepFill_Filling& builder,const App::PropertyLinkSubList& aVertex){ + + int res; + + for(int i=0; igetTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + + //we get the shape of the document object which resemble the whole box + ts = static_cast(set.obj)->Shape.getShape(); + + //we want only the subshape which is linked + sub = ts.getSubShape(set.sub); + + if(sub.ShapeType() == TopAbs_VERTEX) {vtmp = TopoDS::Vertex(sub);} //Check Shape type and assign edge + else{Standard_Failure::Raise("Curves must be type TopoDS_Vertex");} //Raise exception + + } + + else{Standard_Failure::Raise("Point not from Part::Feature");} + + res = builder.Add(BRep_Tool::Pnt(vtmp)); + + } + return; +} + +void appinitface(BRepFill_Filling& builder,const App::PropertyLinkSubList& aFace){ + + int res; + + if(aFace.getSize()>1){Standard_Failure::Raise("Only one face may be used for the initial face");return;} + + Part::TopoShape ts; +// Part::TopoShape sub; + TopoDS_Shape sub; + TopoDS_Face face; + + //the subset has the documentobject and the element name which belongs to it, + // in our case for example the cube object and the "Vertex1" string + App::PropertyLinkSubList::SubSet set = aFace[0]; + + if(set.obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + + //we get the shape of the document object which resemble the whole box + ts = static_cast(set.obj)->Shape.getShape(); + + //we want only the subshape which is linked + sub = ts.getSubShape(set.sub); + + if(sub.ShapeType() == TopAbs_FACE) {face = TopoDS::Face(sub);} //Check Shape type and assign edge + else{Standard_Failure::Raise("Faces must be type TopoDS_Face");} //Raise exception + + } + + else{Standard_Failure::Raise("Point not from Part::Feature");} + + builder.LoadInitSurface(face); + + return; +} diff --git a/src/Mod/Surface/App/FeatureFilling.h b/src/Mod/Surface/App/FeatureFilling.h new file mode 100644 index 0000000000..6606e1ffdc --- /dev/null +++ b/src/Mod/Surface/App/FeatureFilling.h @@ -0,0 +1,77 @@ +/*************************************************************************** + * Copyright (c) 2014 Nathan Miller * + * * + * 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 SURFACE_FEATUREFILLING_H +#define SURFACE_FEATUREFILLING_H + +#include +#include +#include +#include "Mod/Part/App/PartFeature.h" + +namespace Surface +{ + +class SurfaceExport Filling : public Part::Feature +{ + PROPERTY_HEADER(Surface::Filling); + +public: + Filling(); + + //Properties of Curves + + App::PropertyLinkSubList Border; // Border Edges (C0 is required for edges without a corresponding face) + App::PropertyLinkSubList Curves; // Other Constraint Curves (C0 is required for edges without a corresponding face) + + App::PropertyLinkSubList BFaces; // Border Faces (C0, G1 and G2 are possible) + App::PropertyIntegerList orderB; // Order of constraint on border faces + App::PropertyLinkSubList CFaces; // Curve Faces (C0, G1 and G2 are possible) + App::PropertyIntegerList orderC; // Order of constraint on curve faces + + App::PropertyLinkSubList Points; // Constraint Points (on Surface) + + App::PropertyLinkSubList initFace; // Initial Face to use + + //Algorithm Variables + App::PropertyInteger Degree; //Starting degree + App::PropertyInteger NbPtsOnCur; //Number of points on an edge for constraint + App::PropertyInteger NbIter; //Number of iterations + App::PropertyBool Anisotropie; //? + App::PropertyFloat Tol2d; //2D Tolerance + App::PropertyFloat Tol3d; //3D Tolerance + App::PropertyFloat TolAng; //G1 tolerance + App::PropertyFloat TolCurv; //G2 tolerance + App::PropertyInteger MaxDeg; //Maximum curve degree + App::PropertyInteger MaxSegments; //Maximum number of segments + + // recalculate the feature + App::DocumentObjectExecReturn *execute(void); + short mustExecute() const; + /// returns the type name of the view provider +// const char* getViewProviderName(void) const { +// return "PartGui::ViewProviderFilling"; +// } + +}; +} //Namespace Surface +#endif diff --git a/src/Mod/Surface/App/FeatureSewing.cpp b/src/Mod/Surface/App/FeatureSewing.cpp new file mode 100644 index 0000000000..63c06b916b --- /dev/null +++ b/src/Mod/Surface/App/FeatureSewing.cpp @@ -0,0 +1,155 @@ +/*************************************************************************** + * Copyright (c) 2014 Nathan Miller * + * * + * 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 +#include +#include +#include +#endif + +#include "FeatureSewing.h" +#include +#include +#include +#include +#include + +using namespace Surface; + +PROPERTY_SOURCE(Surface::Sewing, Part::Feature) + +//Initial values + +Sewing::Sewing() +{ + ADD_PROPERTY(aShapeList,(0,"TopoDS_Shape")); + + App::PropertyFloat tol; + App::PropertyBool sewopt; //Option for sewing (if false only control) + App::PropertyBool degenshp; //Option for analysis of degenerated shapes + App::PropertyBool cutfreeedges; //Option for cutting of free edges + App::PropertyBool nonmanifold; //Option for non-manifold processing + + ADD_PROPERTY(tol,(0.0000001)); + ADD_PROPERTY(sewopt,(true)); + ADD_PROPERTY(degenshp,(true)); + ADD_PROPERTY(cutfreeedges,(true)); + ADD_PROPERTY(nonmanifold,(false)); + +} + +//Function Definitions + +void addshape(BRepBuilderAPI_Sewing& builder,const App::PropertyLinkSubList& aShapeList); + +//Check if any components of the surface have been modified + +short Sewing::mustExecute() const +{ + if (aShapeList.isTouched() || + tol.isTouched() || + sewopt.isTouched() || + degenshp.isTouched() || + cutfreeedges.isTouched() || + nonmanifold.isTouched()) + return 1; + return 0; +} + +App::DocumentObjectExecReturn *Sewing::execute(void) +{ + + //Assign Variables + + double atol = tol.getValue(); + bool opt1 = sewopt.getValue(); + bool opt2 = degenshp.getValue(); + bool opt3 = cutfreeedges.getValue(); + bool opt4 = nonmanifold.getValue(); + + //Perform error checking + + + bool res; + + //Begin Construction + try{ + + BRepBuilderAPI_Sewing builder(atol,opt1,opt2,opt3,opt4); + + addshape(builder,aShapeList); + + builder.Perform(); //Perform Sewing + + TopoDS_Shape aShape = builder.SewedShape(); //Get Shape + + printf("number of degenerated shapes: %i\n",builder.NbDegeneratedShapes()); + printf("number of deleted faces: %i\n",builder.NbDeletedFaces()); + printf("number of free edges: %i\n",builder.NbFreeEdges()); + printf("number of multiple edges: %i\n",builder.NbMultipleEdges()); + printf("number of continuous edges: %i\n",builder.NbContigousEdges()); + + if (aShape.IsNull()) + return new App::DocumentObjectExecReturn("Resulting shape is null"); + this->Shape.setValue(aShape); + + + } //End Try + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + return new App::DocumentObjectExecReturn(e->GetMessageString()); + } //End Catch + +} //End execute + +void addshape(BRepBuilderAPI_Sewing& builder,const App::PropertyLinkSubList& aShapeList){ + + for(int i=0; i temp; + + //the subset has the documentobject and the element name which belongs to it, + // in our case for example the cube object and the "Edge1" string + App::PropertyLinkSubList::SubSet set = aShapeList[i]; + + //set.obj should be our box, but just to make sure no one set something stupid + if(set.obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + + //we get the shape of the document object which resemble the whole box + ts = static_cast(set.obj)->Shape.getShape(); + + //we want only the subshape which is linked + sub = ts.getSubShape(set.sub); + } + else{Standard_Failure::Raise("Shape item not from Part::Feature");return;} + + builder.Add(sub); + + } +} diff --git a/src/Mod/Surface/App/FeatureSewing.h b/src/Mod/Surface/App/FeatureSewing.h new file mode 100644 index 0000000000..f02d1c8dd1 --- /dev/null +++ b/src/Mod/Surface/App/FeatureSewing.h @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright (c) 2014 Nathan Miller * + * * + * 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 SURFACE_FEATURESEWING_H +#define SURFACE_FEATURESEWING_H + +#include +#include +#include +#include "Mod/Part/App/PartFeature.h" + +namespace Surface +{ + +class SurfaceExport Sewing : public Part::Feature +{ + PROPERTY_HEADER(Surface::Sewing); + +public: + Sewing(); + + App::PropertyLinkSubList aShapeList; //Shapes to be sewn. + + App::PropertyFloat tol; + App::PropertyBool sewopt; //Option for sewing (if false only control) + App::PropertyBool degenshp; //Option for analysis of degenerated shapes + App::PropertyBool cutfreeedges; //Option for cutting of free edges + App::PropertyBool nonmanifold; //Option for non-manifold processing + + // recalculate the feature + App::DocumentObjectExecReturn *execute(void); + short mustExecute() const; + /// returns the type name of the view provider +// const char* getViewProviderName(void) const { +// return "PartGui::ViewProviderSewing"; +// } + +}; +}//Namespace Surface +#endif diff --git a/src/Mod/Surface/App/Makefile.am b/src/Mod/Surface/App/Makefile.am new file mode 100644 index 0000000000..b005c7d443 --- /dev/null +++ b/src/Mod/Surface/App/Makefile.am @@ -0,0 +1,47 @@ + +lib_LTLIBRARIES=libSurface.la Surface.la + +libSurface_la_SOURCES=\ + AppSurfacePy.cpp \ + PreCompiled.cpp \ + PreCompiled.h + +includedir = @includedir@/Mod/Surface/App + +# the library search path. +libSurface_la_LDFLAGS = -L../../../Base -L../../../App $(all_libraries) \ + -version-info @LIB_CURRENT@:@LIB_REVISION@:@LIB_AGE@ +libSurface_la_CPPFLAGS = -DSurfaceAppExport= + +libSurface_la_LIBADD = \ + @BOOST_SYSTEM_LIB@ \ + -l@PYTHON_LIB@ \ + -lxerces-c \ + -lFreeCADBase \ + -lFreeCADApp + +#-------------------------------------------------------------------------------------- +# Loader of libSurface + +Surface_la_SOURCES=\ + AppSurface.cpp + +# the library search path. +Surface_la_LDFLAGS = $(libSurface_la_LDFLAGS) -module -avoid-version +Surface_la_CPPFLAGS = $(libSurface_la_CPPFLAGS) + +Surface_la_LIBADD = \ + $(libSurface_la_LIBADD) \ + -lSurface + +Surface_la_DEPENDENCIES = libSurface.la + +#-------------------------------------------------------------------------------------- + +# set the include path found by configure +AM_CXXFLAGS = -I$(top_srcdir)/src -I$(top_builddir)/src $(all_includes) + +libdir = $(prefix)/Mod/Surface + +EXTRA_DIST = \ + CMakeLists.txt diff --git a/src/Mod/Surface/App/PreCompiled.cpp b/src/Mod/Surface/App/PreCompiled.cpp new file mode 100644 index 0000000000..c32e030c6d --- /dev/null +++ b/src/Mod/Surface/App/PreCompiled.cpp @@ -0,0 +1,24 @@ +/*************************************************************************** + * Copyright (c) YEAR YOUR NAME * + * * + * 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" diff --git a/src/Mod/Surface/App/PreCompiled.h b/src/Mod/Surface/App/PreCompiled.h new file mode 100644 index 0000000000..30eec3de93 --- /dev/null +++ b/src/Mod/Surface/App/PreCompiled.h @@ -0,0 +1,65 @@ +/*************************************************************************** + * Copyright (c) YEAR YOUR NAME * + * * + * 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 APP_PRECOMPILED_H +//#define APP_PRECOMPILED_H +#ifndef PRECOMPILED_H +#define PRECOMPILED_H + +#include + +// Exporting of App classes +#ifdef FC_OS_WIN32 +# define SurfaceExport __declspec(dllexport) +# define PartExport __declspec(dllimport) +#else // for Linux +# define SurfaceExport +# define PartExport +#endif + +#ifdef _PreComp_ + +// standard +#include +#include +#include + +// STL +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Xerces +#include + +#endif //_PreComp_ + +#endif + diff --git a/src/Mod/Surface/CMakeLists.txt b/src/Mod/Surface/CMakeLists.txt new file mode 100644 index 0000000000..b130d344ff --- /dev/null +++ b/src/Mod/Surface/CMakeLists.txt @@ -0,0 +1,13 @@ + +add_subdirectory(App) +if(FREECAD_BUILD_GUI) + add_subdirectory(Gui) +endif(FREECAD_BUILD_GUI) + +install( + FILES + Init.py + InitGui.py + DESTINATION + Mod/Surface +) diff --git a/src/Mod/Surface/Gui/AppSurfaceGui.cpp b/src/Mod/Surface/Gui/AppSurfaceGui.cpp new file mode 100644 index 0000000000..cbe0ab840c --- /dev/null +++ b/src/Mod/Surface/Gui/AppSurfaceGui.cpp @@ -0,0 +1,66 @@ +/*************************************************************************** + * Copyright (c) 2014 Nathan Miller * + * * + * 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 +#endif + +#include +#include + +#include "Workbench.h" +//#include "ViewProviderCut.h" + +// use a different name to CreateCommand() +void CreateSurfaceCommands(void); + + +/* registration table */ +extern struct PyMethodDef SurfaceGui_methods[]; + +PyDoc_STRVAR(module_SurfaceGui_doc, +"This module is the SurfaceGui module."); + + +/* Python entry */ +extern "C" { +void PartGuiExport initSurfaceGui() +{ + if (!Gui::Application::Instance) { + PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application."); + return; + } + + // instanciating the commands + CreateSurfaceCommands(); + SurfaceGui::Workbench::init(); + +// SurfaceGui::ViewProviderCut::init(); + + (void) Py_InitModule3("SurfaceGui", SurfaceGui_methods, module_SurfaceGui_doc); /* mod name, table ptr */ + Base::Console().Log("Loading GUI of Surface module... done\n"); +} + +} // extern "C" diff --git a/src/Mod/Surface/Gui/AppSurfaceGuiPy.cpp b/src/Mod/Surface/Gui/AppSurfaceGuiPy.cpp new file mode 100644 index 0000000000..5f0575947e --- /dev/null +++ b/src/Mod/Surface/Gui/AppSurfaceGuiPy.cpp @@ -0,0 +1,35 @@ +/*************************************************************************** + * Copyright (c) 2014 Nathan Miller * + * * + * 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_ +#endif + + +#include +#include + +/* registration table */ +struct PyMethodDef SurfaceGui_methods[] = { + {NULL, NULL} /* end of table marker */ +}; diff --git a/src/Mod/Surface/Gui/CMakeLists.txt b/src/Mod/Surface/Gui/CMakeLists.txt new file mode 100644 index 0000000000..036e2aa24f --- /dev/null +++ b/src/Mod/Surface/Gui/CMakeLists.txt @@ -0,0 +1,54 @@ +if(MSVC) + add_definitions(-DHAVE_ACOSH -DHAVE_ATANH -DHAVE_ASINH) +else(MSVC) + add_definitions(-DHAVE_LIMITS_H -DHAVE_CONFIG_H) +endif(MSVC) + +include_directories( + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/src + ${CMAKE_BINARY_DIR}/src + ${CMAKE_CURRENT_BINARY_DIR} + ${Boost_INCLUDE_DIRS} + ${COIN3D_INCLUDE_DIR} + ${OCC_INCLUDE_DIR} + ${PYTHON_INCLUDE_PATH} + ${SOQT_INCLUDE_DIR} + ${QT_INCLUDE_DIR} + ${XERCESC_INCLUDE_DIR} + ${ZLIB_INCLUDE_DIR} +) + +set(SurfaceGui_LIBS + Surface + FreeCADGui +) + +qt4_add_resources(Surface_QRC_SRCS Resources/Surface.qrc) + +SET(SurfaceGui_SRCS + ${Surface_QRC_SRCS} + AppSurfaceGui.cpp + AppSurfaceGuiPy.cpp + Command.cpp + PreCompiled.cpp + PreCompiled.h + Workbench.cpp + Workbench.h +# ViewProviderCut.cpp +# ViewProviderCut.h +) + +link_directories(${OCC_LIBRARY_DIR}) +add_library(SurfaceGui SHARED ${SurfaceGui_SRCS}) +target_link_libraries(SurfaceGui ${SurfaceGui_LIBS}) + +fc_target_copy_resource(SurfaceGui + ${CMAKE_SOURCE_DIR}/src/Mod/Surface + ${CMAKE_BINARY_DIR}/Mod/Surface + InitGui.py) + +SET_BIN_DIR(SurfaceGui SurfaceGui /Mod/Surface) +SET_PYTHON_PREFIX_SUFFIX(SurfaceGui) + +install(TARGETS SurfaceGui DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/src/Mod/Surface/Gui/Command.cpp b/src/Mod/Surface/Gui/Command.cpp new file mode 100644 index 0000000000..2aad33ec68 --- /dev/null +++ b/src/Mod/Surface/Gui/Command.cpp @@ -0,0 +1,150 @@ +/*************************************************************************** + * Copyright (c) 2014 Nathan Miller * + * * + * 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 +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif + +#include +#include +//#include +//#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + + + +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +//=========================================================================== +// CmdSurfaceFILLING THIS IS THE SURFACE FILLING COMMAND +//=========================================================================== +DEF_STD_CMD(CmdSurfaceFilling); + +CmdSurfaceFilling::CmdSurfaceFilling() + :Command("Surface_Filling") +{ + sAppModule = "Surface"; + sGroup = QT_TR_NOOP("Surface"); + sMenuText = QT_TR_NOOP("Surface Filling function"); + sToolTipText = QT_TR_NOOP("Fills a series of boundary curves, constraint curves and verticies with a surface."); + sWhatsThis = QT_TR_NOOP("Surface Filling function"); + sStatusTip = QT_TR_NOOP("Surface Filling function"); + sPixmap = "Filling.svg"; + sAccel = "CTRL+H"; +} + +void CmdSurfaceFilling::activated(int iMsg) +{ + Base::Console().Message("Hello, World!\n"); +} + +//=========================================================================== +// CmdSurfaceCut THIS IS THE SURFACE CUT COMMAND +//=========================================================================== +DEF_STD_CMD(CmdSurfaceCut); + +CmdSurfaceCut::CmdSurfaceCut() + :Command("Surface_Cut") +{ + sAppModule = "Surface"; + sGroup = QT_TR_NOOP("Surface"); + sMenuText = QT_TR_NOOP("Surface Cut function"); + sToolTipText = QT_TR_NOOP("Cuts a Shape with another Shape.\nReturns a modified version of the first shape"); + sWhatsThis = QT_TR_NOOP("Surface Cut function"); + sStatusTip = QT_TR_NOOP("Surface Cut function"); + sPixmap = "Cut.svg"; + sAccel = "CTRL+H"; +} + +void CmdSurfaceCut::activated(int iMsg) +{ +/* std::vector Sel = getSelection().getSelectionEx(0, Part::Feature::getClassTypeId()); + if (Sel.size() != 2) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Invalid selection"), + QObject::tr("Select two shapes please.")); + return; + } + + bool askUser = false; + for (std::vector::iterator it = Sel.begin(); it != Sel.end(); ++it) { + App::DocumentObject* obj = it->getObject(); + if (obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + const TopoDS_Shape& shape = static_cast(obj)->Shape.getValue(); + if (!PartGui::checkForSolids(shape) && !askUser) { + int ret = QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Non-solids selected"), + QObject::tr("The use of non-solids for boolean operations may lead to unexpected results.\n" + "Do you want to continue?"), QMessageBox::Yes, QMessageBox::No); + if (ret == QMessageBox::No) + return; + askUser = true; + } + } + } + + std::string FeatName = getUniqueObjectName("Cut"); + std::string BaseName = Sel[0].getFeatName(); + std::string ToolName = Sel[1].getFeatName(); + + openCommand("Part Cut"); + doCommand(Doc,"App.activeDocument().addObject(\"Part::Cut\",\"%s\")",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Base = App.activeDocument().%s",FeatName.c_str(),BaseName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Tool = App.activeDocument().%s",FeatName.c_str(),ToolName.c_str()); + doCommand(Gui,"Gui.activeDocument().hide('%s')",BaseName.c_str()); + doCommand(Gui,"Gui.activeDocument().hide('%s')",ToolName.c_str()); + copyVisual(FeatName.c_str(), "ShapeColor", BaseName.c_str()); + copyVisual(FeatName.c_str(), "DisplayMode", BaseName.c_str()); + updateActive(); + commitCommand();*/ +} + +void CreateSurfaceCommands(void) +{ + Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); + rcCmdMgr.addCommand(new CmdSurfaceFilling()); + rcCmdMgr.addCommand(new CmdSurfaceCut()); +} diff --git a/src/Mod/Surface/Gui/Makefile.am b/src/Mod/Surface/Gui/Makefile.am new file mode 100644 index 0000000000..b42e7e08b6 --- /dev/null +++ b/src/Mod/Surface/Gui/Makefile.am @@ -0,0 +1,79 @@ + +lib_LTLIBRARIES=libSurfaceGui.la SurfaceGui.la + +BUILT_SOURCES= + +libSurfaceGui_la_SOURCES=\ + AppSurfaceGuiPy.cpp \ + Command.cpp \ + PreCompiled.cpp \ + PreCompiled.h \ + Workbench.cpp \ + Workbench.h + +includedir = @includedir@/Mod/Surface/Gui + +# the library search path. +libSurfaceGui_la_LDFLAGS = -L../../../Base -L../../../App -L../../../Gui -L../App \ + $(QT_LIBS) $(all_libraries) \ + $(sim_ac_coin_ldflags) $(sim_ac_coin_libs) \ + $(sim_ac_soqt_ldflags) $(sim_ac_soqt_libs) \ + -version-info @LIB_CURRENT@:@LIB_REVISION@:@LIB_AGE@ + +libSurfaceGui_la_CPPFLAGS = -DSurfaceAppExport= -DSurfaceGuiExport= + +libSurfaceGui_la_LIBADD = \ + @BOOST_SYSTEM_LIB@ \ + -l@PYTHON_LIB@ \ + -lxerces-c \ + -lFreeCADBase \ + -lFreeCADApp \ + -lFreeCADGui \ + -lSurface + +#-------------------------------------------------------------------------------------- +# Loader of libSurfaceGui + +SurfaceGui_la_SOURCES=\ + AppSurfaceGui.cpp + +# the library search path. +SurfaceGui_la_LDFLAGS = $(libSurfaceGui_la_LDFLAGS) -module -avoid-version +SurfaceGui_la_CPPFLAGS = $(libSurfaceGui_la_CPPFLAGS) + +SurfaceGui_la_LIBADD = \ + $(libSurfaceGui_la_LIBADD) \ + -lSurfaceGui + +SurfaceGui_la_DEPENDENCIES = libSurfaceGui.la + +#-------------------------------------------------------------------------------------- + +# rule for Qt MetaObject Compiler: +moc_%.cpp: %.h + $(QT_MOC) $< -o $(@F) + +# rule for Qt MetaObject Compiler: +%.moc: %.h + $(QT_MOC) $< -o $(@F) + +# rules for Qt User Interface Compiler: +ui_%.h: %.ui + $(QT_UIC) $< -o $(@F) + +# rules for Qt Resource Compiler: +qrc_%.cpp: Resources/%.qrc + $(QT_RCC) -name $(*F) $< -o $(@F) + +# set the include path found by configure +AM_CXXFLAGS = -I$(top_srcdir)/src -I$(top_builddir)/src $(all_includes) $(QT_CXXFLAGS) \ + -I$(sim_ac_coin_includedir) -I$(sim_ac_soqt_includedir) + +libdir = $(prefix)/Mod/Surface + +CLEANFILES = $(BUILT_SOURCES) + +EXTRA_DIST = \ + CMakeLists.txt \ + Resources/Surface.qrc + diff --git a/src/Mod/Surface/Gui/PreCompiled.cpp b/src/Mod/Surface/Gui/PreCompiled.cpp new file mode 100644 index 0000000000..50c5f6f34e --- /dev/null +++ b/src/Mod/Surface/Gui/PreCompiled.cpp @@ -0,0 +1,24 @@ +/*************************************************************************** + * Copyright (c) 2014 Nathan Miller * + * * + * 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" diff --git a/src/Mod/Surface/Gui/PreCompiled.h b/src/Mod/Surface/Gui/PreCompiled.h new file mode 100644 index 0000000000..79de562fb8 --- /dev/null +++ b/src/Mod/Surface/Gui/PreCompiled.h @@ -0,0 +1,81 @@ +/*************************************************************************** + * Copyright (c) 2014 Nathan Miller * + * * + * 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 GUI_PRECOMPILED_H +#define GUI_PRECOMPILED_H + +/*#include + +// Importing of App classes +#ifdef FC_OS_WIN32 +# define SurfaceAppExport __declspec(dllimport) +# define SurfaceGuiExport __declspec(dllexport) +#else // for Linux +# define SurfaceAppExport +# define SurfaceGuiExport +#endif*/ + +#include + +// Importing of App classes +#ifdef FC_OS_WIN32 +# define PartExport __declspec(dllimport) +# define PartGuiExport __declspec(dllimport) +#else // for Linux +# define PartExport +# define PartGuiExport +#endif + +#ifdef _PreComp_ + +// standard +#include +#include + +// STL +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Xerces +#include + +#ifdef FC_OS_WIN32 +# include +#endif + +// Qt Toolkit +#ifndef __Qt4All__ +# include +#endif + +#endif //_PreComp_ + +#endif // GUI_PRECOMPILED_H diff --git a/src/Mod/Surface/Gui/Resources/Surface.qrc b/src/Mod/Surface/Gui/Resources/Surface.qrc new file mode 100644 index 0000000000..7c907c425d --- /dev/null +++ b/src/Mod/Surface/Gui/Resources/Surface.qrc @@ -0,0 +1,9 @@ + + + icons/BezSurf.svg + icons/BSplineSurf.svg + icons/Cut.svg + icons/Filling.svg + icons/Sewing.svg + + diff --git a/src/Mod/Surface/Gui/Resources/icons/BSplineSurf.svg b/src/Mod/Surface/Gui/Resources/icons/BSplineSurf.svg new file mode 100644 index 0000000000..801a3e8692 --- /dev/null +++ b/src/Mod/Surface/Gui/Resources/icons/BSplineSurf.svg @@ -0,0 +1,307 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + diff --git a/src/Mod/Surface/Gui/Resources/icons/BezSurf.svg b/src/Mod/Surface/Gui/Resources/icons/BezSurf.svg new file mode 100644 index 0000000000..6c5c093974 --- /dev/null +++ b/src/Mod/Surface/Gui/Resources/icons/BezSurf.svg @@ -0,0 +1,329 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/src/Mod/Surface/Gui/Resources/icons/Cut.svg b/src/Mod/Surface/Gui/Resources/icons/Cut.svg new file mode 100644 index 0000000000..90073bf9df --- /dev/null +++ b/src/Mod/Surface/Gui/Resources/icons/Cut.svg @@ -0,0 +1,287 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + diff --git a/src/Mod/Surface/Gui/Resources/icons/Filling.svg b/src/Mod/Surface/Gui/Resources/icons/Filling.svg new file mode 100644 index 0000000000..58fa99e0ce --- /dev/null +++ b/src/Mod/Surface/Gui/Resources/icons/Filling.svg @@ -0,0 +1,303 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/src/Mod/Surface/Gui/Resources/icons/Sewing.svg b/src/Mod/Surface/Gui/Resources/icons/Sewing.svg new file mode 100644 index 0000000000..06a53a3ea5 --- /dev/null +++ b/src/Mod/Surface/Gui/Resources/icons/Sewing.svg @@ -0,0 +1,281 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/src/Mod/Surface/Gui/Resources/icons/Surface.svg b/src/Mod/Surface/Gui/Resources/icons/Surface.svg new file mode 100644 index 0000000000..159fa8740e --- /dev/null +++ b/src/Mod/Surface/Gui/Resources/icons/Surface.svg @@ -0,0 +1,281 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/Mod/Surface/Gui/Workbench.cpp b/src/Mod/Surface/Gui/Workbench.cpp new file mode 100644 index 0000000000..4c50de8c92 --- /dev/null +++ b/src/Mod/Surface/Gui/Workbench.cpp @@ -0,0 +1,78 @@ +/*************************************************************************** + * Copyright (c) 2014 Nathan Miller * + * * + * 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_ +#endif + +#include "Workbench.h" +#include +#include + +using namespace SurfaceGui; + +/// @namespace SurfaceGui @class Workbench +TYPESYSTEM_SOURCE(SurfaceGui::Workbench, Gui::StdWorkbench) + +Workbench::Workbench() +{ +} + +Workbench::~Workbench() +{ +} + +Gui::MenuItem* Workbench::setupMenuBar() const +{ + + Gui::MenuItem* root = StdWorkbench::setupMenuBar(); + Gui::MenuItem* item = root->findItem( "&Windows" ); + + Gui::MenuItem* make = new Gui::MenuItem; + root->insertItem( item, make ); + make->setCommand("MakeSurface"); + *make << "Surface_Filling"; + + Gui::MenuItem* mod = new Gui::MenuItem; + root->insertItem( item, mod ); + mod->setCommand("ModSurface"); + *mod << "Surface_Cut"; + + return root; +} + +Gui::ToolBarItem* Workbench::setupToolBars() const +{ + Gui::ToolBarItem* root = StdWorkbench::setupToolBars(); + + Gui::ToolBarItem* make = new Gui::ToolBarItem(root); + make->setCommand( "MakeSurface" ); + *make << "Surface_Filling"; + + Gui::ToolBarItem* mod = new Gui::ToolBarItem(root); + mod->setCommand( "ModSurface" ); + *mod << "Surface_Cut"; + + return root; +} diff --git a/src/Mod/Surface/Gui/Workbench.h b/src/Mod/Surface/Gui/Workbench.h new file mode 100644 index 0000000000..468bb491ec --- /dev/null +++ b/src/Mod/Surface/Gui/Workbench.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (c) 2014 Nathan Miller * + * * + * 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 Surface_WORKBENCH_H +#define Surface_WORKBENCH_H + +#include + +namespace SurfaceGui { + +class Workbench : public Gui::StdWorkbench +{ + TYPESYSTEM_HEADER(); + +public: + Workbench(); + virtual ~Workbench(); + +protected: + Gui::MenuItem* setupMenuBar() const; + Gui::ToolBarItem* setupToolBars() const; +}; + +} // namespace SurfaceGui + + +#endif // Surface_WORKBENCH_H diff --git a/src/Mod/Surface/Gui/qrc_Surface.cxx b/src/Mod/Surface/Gui/qrc_Surface.cxx new file mode 100644 index 0000000000..6d95ae475b --- /dev/null +++ b/src/Mod/Surface/Gui/qrc_Surface.cxx @@ -0,0 +1,30 @@ +/**************************************************************************** +** Resource object code +** +** Created: Tue Aug 5 22:27:13 2014 +** by: The Resource Compiler for Qt version 4.8.1 +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include + +QT_BEGIN_NAMESPACE + +QT_END_NAMESPACE + + +int QT_MANGLE_NAMESPACE(qInitResources_Surface)() +{ + return 1; +} + +Q_CONSTRUCTOR_FUNCTION(QT_MANGLE_NAMESPACE(qInitResources_Surface)) + +int QT_MANGLE_NAMESPACE(qCleanupResources_Surface)() +{ + return 1; +} + +Q_DESTRUCTOR_FUNCTION(QT_MANGLE_NAMESPACE(qCleanupResources_Surface)) + diff --git a/src/Mod/Surface/Init.py b/src/Mod/Surface/Init.py new file mode 100644 index 0000000000..0fa131610a --- /dev/null +++ b/src/Mod/Surface/Init.py @@ -0,0 +1,2 @@ +# FreeCAD init script of the Surface module +# (c) 2001 Juergen Riegel LGPL diff --git a/src/Mod/Surface/InitGui.py b/src/Mod/Surface/InitGui.py new file mode 100644 index 0000000000..283ae17598 --- /dev/null +++ b/src/Mod/Surface/InitGui.py @@ -0,0 +1,87 @@ +# Surface gui init module +# (c) 2001 Juergen Riegel LGPL + +class SurfaceWorkbench ( Workbench ): + "Surface workbench object" + Icon = """ + /* XPM */ + static char * Surface_Tools_Workbench_Main_xpm[] = { + "16 16 48 1", + " c None", + ". c #171D96", + "+ c #1A229B", + "@ c #222CA1", + "# c #181D95", + "$ c #232DA2", + "% c #3344B3", + "& c #2A36A9", + "* c #181C96", + "= c #181B94", + "- c #161C96", + "; c #4961C8", + "> c #5776D5", + ", c #192098", + "' c #171C96", + ") c #394DB9", + "! c #5C7DDB", + "~ c #5B7BDA", + "{ c #465FC5", + "] c #384AB5", + "^ c #4D67CB", + "/ c #4D67CC", + "( c #171D97", + "_ c #3D51BC", + ": c #181E96", + "< c #181E97", + "[ c #4961C7", + "} c #1B2099", + "| c #1F269E", + "1 c #506DCF", + "2 c #516ED0", + "3 c #171F96", + "4 c #4861C8", + "5 c #5A7BDA", + "6 c #2631A5", + "7 c #191E97", + "8 c #181F99", + "9 c #1B229A", + "0 c #445AC3", + "a c #597AD9", + "b c #1F279E", + "c c #2E3BAD", + "d c #181D97", + "e c #192097", + "f c #181D98", + "g c #181F97", + "h c #3C51BC", + "i c #10128F", + " ", + " ", + " .. ", + " +@ ", + " #$%&*= -;>, ", + " ')!!!~{]^!!/( ", + " '!!!!!!!!!!!_: ", + " <[!!!!!!!!!!!} ", + " |!!!!11!!!!23 ", + " :4!567890!ab ", + " |!c def ", + " gh( ", + " i ", + " ", + " ", + " "}; + """ + MenuText = "Surface" + ToolTip = "Surface workbench: Create and edit complex surfaces" + def Initialize(self): + # load the module + import SurfaceGui + import FreeCADGui + + # Set path to icon labels + FreeCADGui.addIconPath('./Gui/Resources/Icons/') + def GetClassName(self): + return "SurfaceGui::Workbench" + +Gui.addWorkbench(SurfaceWorkbench()) diff --git a/src/Mod/Surface/Makefile.am b/src/Mod/Surface/Makefile.am new file mode 100644 index 0000000000..4603016119 --- /dev/null +++ b/src/Mod/Surface/Makefile.am @@ -0,0 +1,10 @@ +SUBDIRS=App Gui + +# Change data dir from default ($(prefix)/share) to $(prefix) +datadir = $(prefix)/Mod/Surface +data_DATA = Init.py InitGui.py + +EXTRA_DIST = \ + $(data_DATA) \ + CMakeLists.txt \ + Surface.dox diff --git a/src/Mod/Surface/Surface.dox b/src/Mod/Surface/Surface.dox new file mode 100644 index 0000000000..74af270ff2 --- /dev/null +++ b/src/Mod/Surface/Surface.dox @@ -0,0 +1,3 @@ +/** \defgroup TEMPLATE Surface + * \ingroup WORKBENCHES */ +