Files
create/src/Mod/Surface/App/FeatureBezSurf.cpp
balazs-bamer ef27ba2c8a allow wires as surface input
Now an arbitrary mixture of edges and wires can be used as input.
However, the total count of edges together with the wire members
can only be 2, 3 or 4.

For some reason, wires do not work in Python script:
test1.BoundaryList = [(Draft.upgrade([bs1a, bs2a]), 'Wire1')]
yields an empty BoundaryList
2017-04-17 16:20:44 +02:00

113 lines
4.3 KiB
C++

/***************************************************************************
* Copyright (c) 2014-2015 Nathan Miller <Nathan.A.Mill[at]gmail.com> *
* Balázs Bámer *
* *
* 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 <TopoDS.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Wire.hxx>
#include <Geom_BezierCurve.hxx>
#include <Precision.hxx>
#include <gp_Trsf.hxx>
#include <BRep_Tool.hxx>
#include <TopExp_Explorer.hxx>
#include <Standard_ConstructionError.hxx>
#include <GeomFill_BezierCurves.hxx>
#include <GeomFill.hxx>
#endif
#include <Base/Tools.h>
#include <Base/Exception.h>
#include "FeatureBezSurf.h"
using namespace Surface;
PROPERTY_SOURCE(Surface::BezSurf, Surface::BSurf)
//Initial values
BezSurf::BezSurf() : BSurf()
{
}
//Functions
App::DocumentObjectExecReturn *BezSurf::execute(void)
{
correcteInvalidFillType();
//Begin Construction
try{
Handle_Geom_BezierCurve crvs[4];
TopoDS_Wire aWire; //Create empty wire
//Gets the healed wire
getWire(aWire);
Standard_Real u1, u2; // contains output
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; // this will be output
Handle_Geom_Curve c_geom = BRep_Tool::Curve(hedge, heloc, u1, u2); //The geometric curve
Handle_Geom_BezierCurve b_geom = Handle_Geom_BezierCurve::DownCast(c_geom); //Try to get Bezier curve
if (!b_geom.IsNull()) {
gp_Trsf transf = heloc.Transformation();
b_geom->Transform(transf); // apply original transformation to control points
//Store Underlying Geometry
crvs[it] = b_geom;
}
else {
Standard_Failure::Raise("Curve not a Bezier Curve");
}
it++;
}
GeomFill_FillingStyle fstyle = getFillingStyle();
GeomFill_BezierCurves aSurfBuilder; //Create Surface Builder
if(edgeCount==2) {aSurfBuilder.Init(crvs[0], crvs[1], fstyle);}
else if(edgeCount==3) {aSurfBuilder.Init(crvs[0], crvs[1], crvs[2], fstyle);}
else if(edgeCount==4) {aSurfBuilder.Init(crvs[0], crvs[1], crvs[2], crvs[3], fstyle);}
createFace(aSurfBuilder.Surface());
return App::DocumentObject::StdReturn;
} //End Try
catch(Standard_ConstructionError) {
// message is in a Latin language, show a normal one
return new App::DocumentObjectExecReturn("Curves are disjoint.");
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
return new App::DocumentObjectExecReturn(e->GetMessageString());
} //End Catch
} //End execute