Salome HOME
878670ec209066a560bac09d903c460a74ada826
[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 <ModelAPI_AttributeDouble.h>
8 #include <GeomAlgoAPI_FaceBuilder.h>
9 #include <GeomAlgoAPI_CompoundBuilder.h>
10
11 using namespace std;
12
13 // face of the square-face displayed for selection of general plane
14 const double PLANE_SIZE = 200;
15
16 SketchPlugin_Sketch::SketchPlugin_Sketch()
17 {
18 }
19
20 void SketchPlugin_Sketch::initAttributes()
21 {
22   data()->addAttribute(SKETCH_ATTR_PLANE_A, ModelAPI_AttributeDouble::type());
23   data()->addAttribute(SKETCH_ATTR_PLANE_B, ModelAPI_AttributeDouble::type());
24   data()->addAttribute(SKETCH_ATTR_PLANE_C, ModelAPI_AttributeDouble::type());
25   data()->addAttribute(SKETCH_ATTR_PLANE_D, ModelAPI_AttributeDouble::type());
26 }
27
28 void SketchPlugin_Sketch::execute() 
29 {
30 }
31
32 const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Sketch::preview()
33 {
34   std::list<boost::shared_ptr<GeomAPI_Shape> > aFaces;
35
36   addPlane(1, 0, 0, aFaces); // YZ plane
37   addPlane(0, 1, 0, aFaces); // XZ plane
38   addPlane(0, 0, 1, aFaces); // XY plane
39   boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces);
40   setPreview(aCompound);
41
42   return getPreview();
43 }
44
45 void SketchPlugin_Sketch::addPlane(double theX, double theY, double theZ,
46                                    std::list<boost::shared_ptr<GeomAPI_Shape> >& theShapes) const
47 {
48   boost::shared_ptr<GeomAPI_Pnt> anOrigin(new GeomAPI_Pnt(0, 0, 0));
49   boost::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(theX, theY, theZ));
50   boost::shared_ptr<GeomAPI_Shape> aFace = 
51     GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, PLANE_SIZE);
52   theShapes.push_back(aFace);
53 }