]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_OperationSketch.cpp
Salome HOME
refs #30 - Sketch base GUI: create, draw lines
[modules/shaper.git] / src / PartSet / PartSet_OperationSketch.cpp
1 // File:        PartSet_OperationSketch.h
2 // Created:     20 Apr 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #include <PartSet_OperationSketch.h>
6
7 #include <PartSet_OperationEditLine.h>
8
9 #include <SketchPlugin_Sketch.h>
10 #include <ModelAPI_Data.h>
11 #include <ModelAPI_AttributeDouble.h>
12 #include <GeomAlgoAPI_FaceBuilder.h>
13 #include <GeomDataAPI_Point.h>
14 #include <GeomDataAPI_Dir.h>
15
16 #include <AIS_Shape.hxx>
17 #include <AIS_ListOfInteractive.hxx>
18
19 #ifdef _DEBUG
20 #include <QDebug>
21 #endif
22
23 using namespace std;
24
25 PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId,
26                                                      QObject* theParent)
27 : PartSet_OperationSketchBase(theId, theParent), myIsEditMode(false)
28 {
29 }
30
31 PartSet_OperationSketch::~PartSet_OperationSketch()
32 {
33 }
34
35 std::list<int> PartSet_OperationSketch::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
36 {
37   std::list<int> aModes;
38   if (!myIsEditMode)
39     aModes.push_back(TopAbs_FACE);
40   return aModes;
41 }
42
43 void PartSet_OperationSketch::setSelected(boost::shared_ptr<ModelAPI_Feature> theFeature,
44                                           const TopoDS_Shape& theShape)
45 {
46   if (theShape.IsNull())
47     return;
48
49   if (!myIsEditMode) {
50     setSketchPlane(theShape);
51     myIsEditMode = true;
52   }
53   else if (theFeature)
54     emit launchOperation(PartSet_OperationEditLine::Type(), theFeature);
55 }
56
57 void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
58 {
59   // get selected shape
60   boost::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
61   aGShape->setImpl(new TopoDS_Shape(theShape));
62
63   // get plane parameters
64   boost::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
65
66   // set plane parameters to feature
67   boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
68   double anA, aB, aC, aD;
69   aPlane->coefficients(anA, aB, aC, aD);
70
71   boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
72   /*
73   aData->real(SKETCH_ATTR_PLANE_A)->setValue(anA);
74   aData->real(SKETCH_ATTR_PLANE_B)->setValue(aB);
75   aData->real(SKETCH_ATTR_PLANE_C)->setValue(aC);
76   aData->real(SKETCH_ATTR_PLANE_D)->setValue(aD);
77   */
78   // temporary solution for main planes only
79   boost::shared_ptr<GeomDataAPI_Point> anOrigin = 
80     boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
81   anOrigin->setValue(0, 0, 0);
82   boost::shared_ptr<GeomDataAPI_Dir> aNormal = 
83     boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
84   aNormal->setValue(anA, aB, aC);
85   boost::shared_ptr<GeomDataAPI_Dir> aDirX = 
86     boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
87   aDirX->setValue(aB, aC, anA);
88   boost::shared_ptr<GeomDataAPI_Dir> aDirY = 
89     boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
90   aDirY->setValue(aC, anA, aB);
91   boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
92   emit planeSelected(aDir->x(), aDir->y(), aDir->z());
93 }
94