]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge remote-tracking branch 'origin/BR_WIRE_RESULTS'
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 8 Oct 2014 07:35:29 +0000 (11:35 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 8 Oct 2014 07:35:29 +0000 (11:35 +0400)
src/GeomAPI/CMakeLists.txt
src/GeomAPI/GeomAPI_Wire.cpp [new file with mode: 0644]
src/GeomAPI/GeomAPI_Wire.h [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp
src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.h
src/SketchPlugin/SketchPlugin_Sketch.cpp

index e5cad12b1a677fb3172fe5ec2dc3978b0d2ada86..f2e238051b1a78c16b33e8323d27f0078dd2acaa 100644 (file)
@@ -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 (file)
index 0000000..c70d5c5
--- /dev/null
@@ -0,0 +1,48 @@
+// File:        GeomAPI_Wire.cpp
+// Created:     06 Oct 2014
+// Author:      Sergey BELASH
+
+#include <GeomAPI_Interface.h>
+#include <GeomAPI_Wire.h>
+
+#include <Standard_TypeDef.hxx>
+#include <TopAbs_ShapeEnum.hxx>
+
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Wire.hxx>
+#include <BRep_Builder.hxx>
+#include <BRepTools_WireExplorer.hxx>
+
+#include <list>
+
+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<GeomAPI_Shape> theEdge)
+{
+  const TopoDS_Edge& anEdge = theEdge->impl<TopoDS_Edge>();
+  if (anEdge.ShapeType() != TopAbs_EDGE)
+    return;
+  TopoDS_Shape& aWire = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
+  BRep_Builder aBuilder;
+  aBuilder.Add(aWire, anEdge);
+}
+
+std::list<boost::shared_ptr<GeomAPI_Shape> > GeomAPI_Wire::getEdges()
+{
+  TopoDS_Shape& aShape = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
+  BRepTools_WireExplorer aWireExp(TopoDS::Wire(aShape));
+  std::list<boost::shared_ptr<GeomAPI_Shape> > aResult;
+  for (; aWireExp.More(); aWireExp.Next()) {
+    boost::shared_ptr<GeomAPI_Shape> 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 (file)
index 0000000..de849ef
--- /dev/null
@@ -0,0 +1,43 @@
+// File:        GeomAPI_Wire.hxx
+// Created:     24 Jul 2014
+// Author:      Artem ZHIDKOV
+
+#ifndef GEOMAPI_WIRE_H_
+#define GEOMAPI_WIRE_H_
+
+#include <GeomAPI.h>
+#include <GeomAPI_Edge.h>
+
+#include <boost/smart_ptr/shared_ptr.hpp>
+
+#include <list>
+
+/**\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<GeomAPI_Shape> theEdge);
+  std::list<boost::shared_ptr<GeomAPI_Shape> > getEdges();
+
+};
+
+#endif
+
index 20c3211ee1e402dd44cdbeeb20663c3d66e79874..0d0fc34183ce5cdb61dcc341e98ccc075a8915f3 100644 (file)
@@ -3,6 +3,7 @@
 // Author:      Artem ZHIDKOV
 
 #include <GeomAlgoAPI_SketchBuilder.h>
+#include <GeomAPI_Wire.h>
 
 #include <set>
 
@@ -370,6 +371,23 @@ void GeomAlgoAPI_SketchBuilder::createFaces(
     fixIntersections(theResultFaces);
 }
 
+void GeomAlgoAPI_SketchBuilder::createFaces(const boost::shared_ptr<GeomAPI_Pnt>& theOrigin,
+                                            const boost::shared_ptr<GeomAPI_Dir>& theDirX,
+                                            const boost::shared_ptr<GeomAPI_Dir>& theDirY,
+                                            const boost::shared_ptr<GeomAPI_Dir>& theNorm,
+                                            const boost::shared_ptr<GeomAPI_Shape>& theWire,
+                                            std::list<boost::shared_ptr<GeomAPI_Shape> >& theResultFaces)
+{
+  boost::shared_ptr<GeomAPI_Wire> aWire = boost::dynamic_pointer_cast<GeomAPI_Wire>(theWire);
+  if(!aWire)
+    return;
+  // Filter wires, return only faces.
+  std::list<boost::shared_ptr<GeomAPI_Shape> > aFilteredWires;
+  createFaces(theOrigin, theDirX, theDirY, theNorm,
+              aWire->getEdges(), theResultFaces, aFilteredWires);
+}
+
+
 void GeomAlgoAPI_SketchBuilder::fixIntersections(
     std::list<boost::shared_ptr<GeomAPI_Shape> >& theFaces)
 {
index 22eafe77ef05252485c8b63d52b0f5d6c8f68cbd..86505f82dbb8fd94299b51d443113656e7b9278d 100644 (file)
@@ -42,6 +42,25 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_SketchBuilder
                           std::list<boost::shared_ptr<GeomAPI_Shape> >& theResultFaces,
                           std::list<boost::shared_ptr<GeomAPI_Shape> >& 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<GeomAPI_Pnt>& theOrigin,
+                          const boost::shared_ptr<GeomAPI_Dir>& theDirX,
+                          const boost::shared_ptr<GeomAPI_Dir>& theDirY,
+                          const boost::shared_ptr<GeomAPI_Dir>& theNorm,
+                          const boost::shared_ptr<GeomAPI_Shape>& theWire,
+                          std::list<boost::shared_ptr<GeomAPI_Shape> >& 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
index 1bc1b469cce3187af65006bbb02a5aa1cbbf868e..0bbcfe2a76969e396527c3ff6a184ea247fe0a00 100644 (file)
@@ -2,19 +2,31 @@
 // Created:     27 Mar 2014
 // Author:      Mikhail PONIKAROV
 
-#include "SketchPlugin_Sketch.h"
-#include <ModelAPI_Data.h>
-#include <ModelAPI_AttributeRefList.h>
+#include <Config_PropManager.h>
+
+#include <GeomAlgoAPI_CompoundBuilder.h>
+#include <GeomAlgoAPI_FaceBuilder.h>
+
 #include <GeomAPI_AISObject.h>
+#include <GeomAPI_Dir.h>
+#include <GeomAPI_Wire.h>
 #include <GeomAPI_XYZ.h>
+
 #include <GeomDataAPI_Dir.h>
 #include <GeomDataAPI_Point.h>
-#include <GeomAlgoAPI_FaceBuilder.h>
-#include <GeomAlgoAPI_CompoundBuilder.h>
-#include <GeomAlgoAPI_SketchBuilder.h>
+
+#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Object.h>
 #include <ModelAPI_ResultConstruction.h>
 
-#include <Config_PropManager.h>
+#include <SketchPlugin_Sketch.h>
+
+#include <boost/smart_ptr/shared_ptr.hpp>
+
+#include <vector>
 
 using namespace std;
 
@@ -74,15 +86,17 @@ void SketchPlugin_Sketch::execute()
 
   if (aFeaturesPreview.empty())
     return;
-  std::list<boost::shared_ptr<GeomAPI_Shape> > aLoops;
-  std::list<boost::shared_ptr<GeomAPI_Shape> > 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<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aLoops);
+  // Collect all edges as one big wire
+  boost::shared_ptr<GeomAPI_Wire> aBigWire(new GeomAPI_Wire);
+  std::list<boost::shared_ptr<GeomAPI_Shape> >::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<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
-  aConstr->setShape(aCompound);
+  aConstr->setShape(aBigWire);
   setResult(aConstr);
 }