Salome HOME
2eaa512c80813ea8adb60d0e405f91b6d29e419e
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Sketch.cpp
1 // File:        SketchPlugin_Sketch.cxx
2 // Created:     27 Mar 2014
3 // Author:      Mikhail PONIKAROV
4
5 #include "SketchPlugin_Sketch.h"
6 #include <ModelAPI_Data.h>
7 #include <GeomAlgoAPI_FaceBuilder.h>
8 #include <GeomAlgoAPI_CompoundBuilder.h>
9
10 using namespace std;
11
12 // face of the square-face displayed for selection of general plane
13 const double PLANE_SIZE = 200;
14
15 SketchPlugin_Sketch::SketchPlugin_Sketch()
16 {
17 }
18
19 void SketchPlugin_Sketch::initAttributes()
20 {
21   //data()->addAttribute(PART_ATTR_DOC_REF, ModelAPI_AttributeDocRef::type());
22 }
23
24 void SketchPlugin_Sketch::execute() 
25 {
26 }
27
28 const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Sketch::preview()
29 {
30   std::list<boost::shared_ptr<GeomAPI_Shape> > aFaces;
31
32   addPlane(1, 0, 0, aFaces); // YZ plane
33   addPlane(0, 1, 0, aFaces); // XZ plane
34   addPlane(0, 0, 1, aFaces); // XY plane
35   boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces);
36   setPreview(aCompound);
37
38   return getPreview();
39 }
40
41 void SketchPlugin_Sketch::addPlane(double theX, double theY, double theZ,
42                                    std::list<boost::shared_ptr<GeomAPI_Shape> >& theShapes) const
43 {
44   boost::shared_ptr<GeomAPI_Pnt> anOrigin(new GeomAPI_Pnt(0, 0, 0));
45   boost::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(theX, theY, theZ));
46   boost::shared_ptr<GeomAPI_Shape> aFace = 
47     GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, PLANE_SIZE);
48   theShapes.push_back(aFace);
49 }