-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: GeomAlgoAPI_SketchBuilder.cpp
-// Created: 02 Jun 2014
-// Author: Artem ZHIDKOV
+// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
#include <GeomAlgoAPI_SketchBuilder.h>
#include <GeomAPI_PlanarEdges.h>
#include <BRep_Builder.hxx>
#include <BRepTopAdaptor_FClass2d.hxx>
#include <Geom_Plane.hxx>
+#include <Geom_TrimmedCurve.hxx>
#include <Precision.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
return aStart;
}
+static TopoDS_Vertex findStartVertex(const TopoDS_Shape& theShape,
+ const std::list<std::shared_ptr<GeomAPI_Shape> >& theInitialShapes)
+{
+ // Try to find edge lying on the one of original edges.
+ // First found edge will be taken as a start edge for the result wire
+ std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator aFeatIt = theInitialShapes.begin();
+ for (; aFeatIt != theInitialShapes.end(); aFeatIt++) {
+ std::shared_ptr<GeomAPI_Shape> aShape(*aFeatIt);
+ const TopoDS_Edge& anEdge = aShape->impl<TopoDS_Edge>();
+ if (anEdge.ShapeType() != TopAbs_EDGE)
+ continue;
+
+ double aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
+ if (aCurve->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve))
+ aCurve = Handle(Geom_TrimmedCurve)::DownCast(aCurve)->BasisCurve();
+
+ TopExp_Explorer anExp(theShape, TopAbs_EDGE);
+ for (; anExp.More(); anExp.Next()) {
+ const TopoDS_Edge& aShapeEdge = TopoDS::Edge(anExp.Current());
+ double aF, aL;
+ Handle(Geom_Curve) aShapeCurve = BRep_Tool::Curve(aShapeEdge, aF, aL);
+ if (aShapeCurve->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve))
+ aShapeCurve = Handle(Geom_TrimmedCurve)::DownCast(aShapeCurve)->BasisCurve();
+
+ if (aCurve != aShapeCurve)
+ continue;
+
+ // the edge is found, search vertex
+ TopoDS_Vertex aV1, aV2;
+ TopExp::Vertices(aShapeEdge, aV1, aV2);
+ return fabs(aF - aFirst) <= fabs(aL - aFirst) ? aV1 : aV2;
+ }
+ }
+
+ // start vertex is not found, use algorithm to search vertex with the greatest coordinates
+ return findStartVertex(theShape);
+}
+
void GeomAlgoAPI_SketchBuilder::createFaces(
const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
const std::shared_ptr<GeomAPI_Dir>& theDirX,
TopoDS_Wire aWire = TopoDS::Wire(aWireExp.Current());
// to make faces equal on different platforms, we will find
- // a vertex with greater coordinates and start wire from it
- TopoDS_Vertex aStartVertex = findStartVertex(aWire);
+ // a vertex lying on an edge with the lowest index in the list of initial edges
+ TopoDS_Vertex aStartVertex = findStartVertex(aWire, theFeatures);
TopoDS_Wire aNewWire;
aBuilder.MakeWire(aNewWire);
const std::shared_ptr<GeomAPI_Dir>& theDirX,
const std::shared_ptr<GeomAPI_Dir>& theNorm,
const std::shared_ptr<GeomAPI_Shape>& theWire,
- std::list<std::shared_ptr<GeomAPI_Shape> >& theResultFaces)
+ std::list<std::shared_ptr<GeomAPI_Shape> >& theResultFaces)
{
- std::shared_ptr<GeomAPI_PlanarEdges> aWire =
+ std::shared_ptr<GeomAPI_PlanarEdges> aWire =
std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(theWire);
if(aWire) {
// Filter wires, return only faces.