/*************************************************************************** * Copyright (c) 2014-2015 Nathan Miller * * 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 #include #include #include #include #include #include #include #include #endif #include #include #include "FeatureBSurf.h" using namespace Surface; PROPERTY_SOURCE(Surface::BSurf, Part::Feature) const char* BSurf::FillTypeEnums[] = {"Invalid", "Sretched", "Coons", "Curved", NULL}; BSurf::BSurf(): Feature() { ADD_PROPERTY_TYPE(FillType, ((long)0), "Surface", App::Prop_None, "Boundary of the surface"); ADD_PROPERTY_TYPE(BoundaryList, (0,"Dummy"), "Surface", App::Prop_None, "Boundary of the surface"); FillType.setEnums(FillTypeEnums); } //Check if any components of the surface have been modified short BSurf::mustExecute() const { if (BoundaryList.isTouched() || FillType.isTouched()) { return 1; } return 0; } GeomFill_FillingStyle BSurf::getFillingStyle() { //Identify filling style int ftype = FillType.getValue(); if(ftype==StretchStyle) {return GeomFill_StretchStyle;} else if(ftype==CoonsStyle) {return GeomFill_CoonsStyle;} else if(ftype==CurvedStyle) {return GeomFill_CurvedStyle;} else {Standard_Failure::Raise("Filling style must be 1 (Stretch), 2 (Coons), or 3 (Curved).");} } void BSurf::getWire(TopoDS_Wire& aWire) { Handle(ShapeFix_Wire) aShFW = new ShapeFix_Wire; Handle(ShapeExtend_WireData) aWD = new ShapeExtend_WireData; int boundaryListSize = BoundaryList.getSize(); if(boundaryListSize > 4 || boundaryListSize < 2) { Standard_Failure::Raise("Only 2-4 curves are allowed"); return; } for(int i = 0; i < boundaryListSize; i++) { Part::TopoShape ts; //Curve TopoShape TopoDS_Shape sub; //Curve TopoDS_Shape TopoDS_Edge etmp; //Curve TopoDS_Edge //Get Edge App::PropertyLinkSubList::SubSet set = BoundaryList[i]; if(set.obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { ts = static_cast(set.obj)->Shape.getShape(); //we want only the subshape which is linked sub = ts.getSubShape(set.sub); // make a copy of the shape and the underlying geometry to avoid to affect the input shapes BRepBuilderAPI_Copy copy(sub); sub = copy.Shape(); if(sub.ShapeType() == TopAbs_EDGE) { //Check Shape type and assign edge etmp = TopoDS::Edge(sub); } 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;} } void BSurf::createFace(const Handle_Geom_BoundedSurface &aSurface) { BRepBuilderAPI_MakeFace aFaceBuilder; Standard_Real u1, u2, v1, v2; // transfer surface bounds to face aSurface->Bounds(u1, u2, v1, v2); aFaceBuilder.Init(aSurface, u1, u2, v1, v2, Precision::Confusion()); TopoDS_Face aFace = aFaceBuilder.Face(); if(!aFaceBuilder.IsDone()) { Standard_Failure::Raise("Face unable to be constructed");} if (aFace.IsNull()) { Standard_Failure::Raise("Resulting Face is null"); } this->Shape.setValue(aFace); } void BSurf::correcteInvalidFillType() { int ftype = FillType.getValue(); if(ftype == InvalidStyle) { FillType.setValue(StretchStyle); } }