Salome HOME
refs #30 - Sketch base GUI: create, draw lines
authornds <natalia.donis@opencascade.com>
Thu, 24 Apr 2014 08:42:31 +0000 (12:42 +0400)
committernds <natalia.donis@opencascade.com>
Thu, 24 Apr 2014 08:42:31 +0000 (12:42 +0400)
Visualize three planes for sketch.

src/GeomAlgoAPI/CMakeLists.txt
src/GeomAlgoAPI/GeomAlgoAPI_CompoundBuilder.cpp [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_CompoundBuilder.h [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_Sketch.h

index 509d8ac2d1f190f1b71e85a7df9c1eb0926ad1b1..40fcc4633133283606b43216bde6fe9a7154b63e 100644 (file)
@@ -6,10 +6,12 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
 
 SET(PROJECT_HEADERS
     GeomAlgoAPI.h
+    GeomAlgoAPI_CompoundBuilder.h
     GeomAlgoAPI_FaceBuilder.h
 )
 
 SET(PROJECT_SOURCES
+    GeomAlgoAPI_CompoundBuilder.cpp
     GeomAlgoAPI_FaceBuilder.cpp
 )
 
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_CompoundBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_CompoundBuilder.cpp
new file mode 100644 (file)
index 0000000..2882ee2
--- /dev/null
@@ -0,0 +1,28 @@
+// File:        GeomAlgoAPI_CompoundBuilder.cpp
+// Created:     24 Apr 2014
+// Author:      Natalia ERMOLAEVA
+
+#include <GeomAlgoAPI_CompoundBuilder.h>
+//#include <gp_Pln.hxx>
+//#include <BRepBuilderAPI_MakeFace.hxx>
+//#include <TopoDS_Face.hxx>
+#include <BRep_Builder.hxx>
+#include <TopoDS_Compound.hxx>
+
+boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_CompoundBuilder::compound
+                            (std::list<boost::shared_ptr<GeomAPI_Shape> > theShapes)
+{
+  BRep_Builder aBuilder;
+  TopoDS_Compound aComp;
+  aBuilder.MakeCompound(aComp);
+
+  std::list<boost::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = theShapes.begin(),
+                                                               aLast = theShapes.end();
+  for (; anIt != aLast; anIt++) {
+    aBuilder.Add(aComp, (*anIt)->impl<TopoDS_Shape>());
+  }
+
+  boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
+  aRes->setImpl(new TopoDS_Shape(aComp));
+  return aRes;
+}
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_CompoundBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_CompoundBuilder.h
new file mode 100644 (file)
index 0000000..5cca6ad
--- /dev/null
@@ -0,0 +1,30 @@
+// File:        GeomAlgoAPI_CompoundBuilder.h
+// Created:     24 Apr 2014
+// Author:      Natalia ERMOLAEVA
+
+#ifndef GeomAlgoAPI_CompoundBuilder_HeaderFile
+#define GeomAlgoAPI_CompoundBuilder_HeaderFile
+
+#include <GeomAlgoAPI.h>
+#include <GeomAPI_Shape.h>
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Dir.h>
+#include <boost/shared_ptr.hpp>
+
+#include <list>
+
+/**\class GeomAlgoAPI_CompoundBuilder
+ * \ingroup DataAlgo
+ * \brief Allows to create face-shapes by different parameters
+ */
+
+class GEOMALGOAPI_EXPORT GeomAlgoAPI_CompoundBuilder
+{
+public:
+  /// Creates compund of the given shapes
+  /// \param theShapes a list of shapes
+  static boost::shared_ptr<GeomAPI_Shape> compound
+                            (std::list<boost::shared_ptr<GeomAPI_Shape> > theShapes);
+};
+
+#endif
index 5a597ebf627d43d248aa333d36149b23610a8ac4..2eaa512c80813ea8adb60d0e405f91b6d29e419e 100644 (file)
@@ -5,6 +5,7 @@
 #include "SketchPlugin_Sketch.h"
 #include <ModelAPI_Data.h>
 #include <GeomAlgoAPI_FaceBuilder.h>
+#include <GeomAlgoAPI_CompoundBuilder.h>
 
 using namespace std;
 
@@ -25,12 +26,24 @@ void SketchPlugin_Sketch::execute()
 }
 
 const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Sketch::preview()
+{
+  std::list<boost::shared_ptr<GeomAPI_Shape> > aFaces;
+
+  addPlane(1, 0, 0, aFaces); // YZ plane
+  addPlane(0, 1, 0, aFaces); // XZ plane
+  addPlane(0, 0, 1, aFaces); // XY plane
+  boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces);
+  setPreview(aCompound);
+
+  return getPreview();
+}
+
+void SketchPlugin_Sketch::addPlane(double theX, double theY, double theZ,
+                                   std::list<boost::shared_ptr<GeomAPI_Shape> >& theShapes) const
 {
   boost::shared_ptr<GeomAPI_Pnt> anOrigin(new GeomAPI_Pnt(0, 0, 0));
-  boost::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(1, 0, 0));
+  boost::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(theX, theY, theZ));
   boost::shared_ptr<GeomAPI_Shape> aFace = 
     GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, PLANE_SIZE);
-  setPreview(aFace);
-
-  return getPreview();
+  theShapes.push_back(aFace);
 }
index 4cceee37f4b7e1fca07f95f199119c773b0411d3..ed936bde999554a599a9a99dfd9994c3d98ec7f0 100644 (file)
@@ -8,6 +8,8 @@
 #include "SketchPlugin.h"
 #include <SketchPlugin_Feature.h>
 
+#include <list>
+
 /// part reference attribute
 const std::string PART_ATTR_DOC_REF = "SketchDocument";
 
@@ -37,6 +39,15 @@ public:
 
   /// Use plugin manager for features creation
   SketchPlugin_Sketch();
+protected:
+  /// Creates a plane and append it to the list
+  /// \param theX the X normal value
+  /// \param theY the Y normal value
+  /// \param theZ the Z normal value
+  /// \param theShapes the list of result shapes
+  void addPlane(double theX, double theY, double theZ,
+                std::list<boost::shared_ptr<GeomAPI_Shape> >& theShapes) const;
+
 };
 
 #endif