From 58201d2fb38096a840a55855a320bb014054135c Mon Sep 17 00:00:00 2001 From: sbh Date: Tue, 7 Oct 2014 17:39:54 +0400 Subject: [PATCH] Now a wire is the result of a sketch operation. Additional method added to GeomAlgoAPI to create faces from a wire. --- src/GeomAPI/CMakeLists.txt | 2 + src/GeomAPI/GeomAPI_Wire.cpp | 48 +++++++++++++++++++ src/GeomAPI/GeomAPI_Wire.h | 43 +++++++++++++++++ src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp | 18 +++++++ src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.h | 19 ++++++++ src/SketchPlugin/SketchPlugin_Sketch.cpp | 42 ++++++++++------ 6 files changed, 158 insertions(+), 14 deletions(-) create mode 100644 src/GeomAPI/GeomAPI_Wire.cpp create mode 100644 src/GeomAPI/GeomAPI_Wire.h diff --git a/src/GeomAPI/CMakeLists.txt b/src/GeomAPI/CMakeLists.txt index e5cad12b1..f2e238051 100644 --- a/src/GeomAPI/CMakeLists.txt +++ b/src/GeomAPI/CMakeLists.txt @@ -19,6 +19,7 @@ SET(PROJECT_HEADERS GeomAPI_Pln.h GeomAPI_Shape.h GeomAPI_Edge.h + GeomAPI_Wire.h GeomAPI_AISObject.h GeomAPI_IPresentable.h GeomAPI_Curve.h @@ -39,6 +40,7 @@ SET(PROJECT_SOURCES GeomAPI_Pln.cpp GeomAPI_Shape.cpp GeomAPI_Edge.cpp + GeomAPI_Wire.cpp GeomAPI_AISObject.cpp GeomAPI_Curve.cpp ) diff --git a/src/GeomAPI/GeomAPI_Wire.cpp b/src/GeomAPI/GeomAPI_Wire.cpp new file mode 100644 index 000000000..c70d5c5e8 --- /dev/null +++ b/src/GeomAPI/GeomAPI_Wire.cpp @@ -0,0 +1,48 @@ +// File: GeomAPI_Wire.cpp +// Created: 06 Oct 2014 +// Author: Sergey BELASH + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include + +GeomAPI_Wire::GeomAPI_Wire() : GeomAPI_Shape() +{ + TopoDS_Wire aBigWireImpl; + BRep_Builder aBuilder; + aBuilder.MakeWire(aBigWireImpl); + this->setImpl(new TopoDS_Shape(aBigWireImpl)); +} + +void GeomAPI_Wire::addEdge(boost::shared_ptr theEdge) +{ + const TopoDS_Edge& anEdge = theEdge->impl(); + if (anEdge.ShapeType() != TopAbs_EDGE) + return; + TopoDS_Shape& aWire = const_cast(impl()); + BRep_Builder aBuilder; + aBuilder.Add(aWire, anEdge); +} + +std::list > GeomAPI_Wire::getEdges() +{ + TopoDS_Shape& aShape = const_cast(impl()); + BRepTools_WireExplorer aWireExp(TopoDS::Wire(aShape)); + std::list > aResult; + for (; aWireExp.More(); aWireExp.Next()) { + boost::shared_ptr anEdge(new GeomAPI_Shape); + anEdge->setImpl(new TopoDS_Shape(aWireExp.Current())); + aResult.push_back(anEdge); + } + return aResult; +} diff --git a/src/GeomAPI/GeomAPI_Wire.h b/src/GeomAPI/GeomAPI_Wire.h new file mode 100644 index 000000000..de849ef93 --- /dev/null +++ b/src/GeomAPI/GeomAPI_Wire.h @@ -0,0 +1,43 @@ +// File: GeomAPI_Wire.hxx +// Created: 24 Jul 2014 +// Author: Artem ZHIDKOV + +#ifndef GEOMAPI_WIRE_H_ +#define GEOMAPI_WIRE_H_ + +#include +#include + +#include + +#include + +/**\class GeomAPI_Wire + * \ingroup DataModel + * \brief Interface to the edge object + */ + +class GEOMAPI_EXPORT GeomAPI_Wire : public GeomAPI_Shape +{ + public: + /// Creation of empty (null) shape + GeomAPI_Wire(); + + virtual bool isVertex() const + { + return false; + } + + /// Returns whether the shape is an edge + virtual bool isEdge() const + { + return false; + } + + void addEdge(boost::shared_ptr theEdge); + std::list > getEdges(); + +}; + +#endif + diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp index 20c3211ee..0d0fc3418 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp @@ -3,6 +3,7 @@ // Author: Artem ZHIDKOV #include +#include #include @@ -370,6 +371,23 @@ void GeomAlgoAPI_SketchBuilder::createFaces( fixIntersections(theResultFaces); } +void GeomAlgoAPI_SketchBuilder::createFaces(const boost::shared_ptr& theOrigin, + const boost::shared_ptr& theDirX, + const boost::shared_ptr& theDirY, + const boost::shared_ptr& theNorm, + const boost::shared_ptr& theWire, + std::list >& theResultFaces) +{ + boost::shared_ptr aWire = boost::dynamic_pointer_cast(theWire); + if(!aWire) + return; + // Filter wires, return only faces. + std::list > aFilteredWires; + createFaces(theOrigin, theDirX, theDirY, theNorm, + aWire->getEdges(), theResultFaces, aFilteredWires); +} + + void GeomAlgoAPI_SketchBuilder::fixIntersections( std::list >& theFaces) { diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.h index 22eafe77e..86505f82d 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.h @@ -42,6 +42,25 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_SketchBuilder std::list >& theResultFaces, std::list >& theResultWires); + /** \brief Creates list of faces and unclosed wires on basis of the features of the sketch + * \param[in] theOrigin origin point of the sketch + * \param[in] theDirX x-direction of the sketch + * \param[in] theDirY y-direction of the sketch + * \param[in] theNorm normal of the sketch + * \param[in] theWire a wire which contains all edges + * \param[out] theResultFaces faces based on closed wires + * + * The algorithm searches all loops of edges surrounding lesser squares. + * It finds the vertex with minimal coordinates along X axis (theDirX) and then + * goes through the edges passing the surrounding area on the left. + */ + static void createFaces(const boost::shared_ptr& theOrigin, + const boost::shared_ptr& theDirX, + const boost::shared_ptr& theDirY, + const boost::shared_ptr& theNorm, + const boost::shared_ptr& theWire, + std::list >& theResultFaces); + /** \brief Searches intersections between the faces in the list * and make holes in the faces to avoid intersections * \param[in,out] theFaces list of faces to proccess diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 1bc1b469c..0bbcfe2a7 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -2,19 +2,31 @@ // Created: 27 Mar 2014 // Author: Mikhail PONIKAROV -#include "SketchPlugin_Sketch.h" -#include -#include +#include + +#include +#include + #include +#include +#include #include + #include #include -#include -#include -#include + +#include +#include +#include +#include +#include #include -#include +#include + +#include + +#include using namespace std; @@ -74,15 +86,17 @@ void SketchPlugin_Sketch::execute() if (aFeaturesPreview.empty()) return; - std::list > aLoops; - std::list > aWires; - GeomAlgoAPI_SketchBuilder::createFaces(anOrigin->pnt(), aDirX->dir(), aDirY->dir(), aNorm->dir(), - aFeaturesPreview, aLoops, aWires); - aLoops.insert(aLoops.end(), aWires.begin(), aWires.end()); - boost::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aLoops); + // Collect all edges as one big wire + boost::shared_ptr aBigWire(new GeomAPI_Wire); + std::list >::const_iterator aShapeIt = aFeaturesPreview.begin(); + for (; aShapeIt != aFeaturesPreview.end(); ++aShapeIt) { + aBigWire->addEdge(*aShapeIt); + } +// GeomAlgoAPI_SketchBuilder::createFaces(anOrigin->pnt(), aDirX->dir(), aDirY->dir(), aNorm->dir(), +// aFeaturesPreview, aLoops, aWires); boost::shared_ptr aConstr = document()->createConstruction(data()); - aConstr->setShape(aCompound); + aConstr->setShape(aBigWire); setResult(aConstr); } -- 2.39.2