Salome HOME
refs #30 - Sketch base GUI: create, draw lines
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Sketch.cpp
index 9a3624daf39295bae1573005d6092ae084019731..878670ec209066a560bac09d903c460a74ada826 100644 (file)
@@ -4,7 +4,9 @@
 
 #include "SketchPlugin_Sketch.h"
 #include <ModelAPI_Data.h>
+#include <ModelAPI_AttributeDouble.h>
 #include <GeomAlgoAPI_FaceBuilder.h>
+#include <GeomAlgoAPI_CompoundBuilder.h>
 
 using namespace std;
 
@@ -17,23 +19,35 @@ SketchPlugin_Sketch::SketchPlugin_Sketch()
 
 void SketchPlugin_Sketch::initAttributes()
 {
-  //data()->addAttribute(PART_ATTR_DOC_REF, ModelAPI_AttributeDocRef::type());
+  data()->addAttribute(SKETCH_ATTR_PLANE_A, ModelAPI_AttributeDouble::type());
+  data()->addAttribute(SKETCH_ATTR_PLANE_B, ModelAPI_AttributeDouble::type());
+  data()->addAttribute(SKETCH_ATTR_PLANE_C, ModelAPI_AttributeDouble::type());
+  data()->addAttribute(SKETCH_ATTR_PLANE_D, ModelAPI_AttributeDouble::type());
 }
 
 void SketchPlugin_Sketch::execute() 
 {
 }
 
-const shared_ptr<GeomAPI_Shape>& SketchPlugin_Sketch::preview()
+const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Sketch::preview()
 {
-  if (!SketchPlugin_Feature::preview())
-  {
-
-    shared_ptr<GeomAPI_Pnt> anOrigin(new GeomAPI_Pnt(0, 0, 0));
-    shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(1, 0, 0));
-    shared_ptr<GeomAPI_Shape> aFace = 
-      GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, PLANE_SIZE);
-    setPreview(aFace);
-  }
-  return SketchPlugin_Feature::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(theX, theY, theZ));
+  boost::shared_ptr<GeomAPI_Shape> aFace = 
+    GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, PLANE_SIZE);
+  theShapes.push_back(aFace);
 }