Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / PartSet / PartSet_OperationFeatureBase.cpp
1 // File:        PartSet_OperationFeatureBase.h
2 // Created:     20 Apr 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #include <PartSet_OperationFeatureBase.h>
6
7 #include <PartSet_Tools.h>
8 #include <PartSet_OperationSketch.h>
9
10 #include <SketchPlugin_Feature.h>
11 #include <SketchPlugin_Point.h>
12 #include <SketchPlugin_Line.h>
13 #include <SketchPlugin_Circle.h>
14 #include <SketchPlugin_Arc.h>
15 #include <SketchPlugin_ConstraintDistance.h>
16 #include <SketchPlugin_ConstraintLength.h>
17 #include <SketchPlugin_ConstraintRadius.h>
18 #include <SketchPlugin_ConstraintParallel.h>
19 #include <SketchPlugin_ConstraintPerpendicular.h>
20 #include <SketchPlugin_ConstraintCoincidence.h>
21
22 #include <GeomAPI_Pnt2d.h>
23
24 #include <ModuleBase_OperationDescription.h>
25 #include <ModuleBase_WidgetPoint2D.h>
26 #include <ModuleBase_WidgetValueFeature.h>
27 #include "ModuleBase_IPropertyPanel.h"
28
29 #include <XGUI_Constants.h>
30
31 #include <V3d_View.hxx>
32 #include <TopoDS_Vertex.hxx>
33 #include <TopoDS.hxx>
34 #include <BRep_Tool.hxx>
35
36 #ifdef _DEBUG
37 #include <QDebug>
38 #include <iostream>
39 #endif
40
41 #include <QMouseEvent>
42
43 using namespace std;
44
45 PartSet_OperationFeatureBase::PartSet_OperationFeatureBase(const QString& theId,
46                                                                QObject* theParent,
47                                                                CompositeFeaturePtr theFeature)
48     : PartSet_OperationSketchBase(theId, theParent),
49       mySketch(theFeature)
50 {
51 }
52
53 PartSet_OperationFeatureBase::~PartSet_OperationFeatureBase()
54 {
55 }
56
57 CompositeFeaturePtr PartSet_OperationFeatureBase::sketch() const
58 {
59   return mySketch;
60 }
61
62 void PartSet_OperationFeatureBase::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
63                                                  const std::list<ModuleBase_ViewerPrs>& theSelected,
64                                                  const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
65 {
66   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
67   double aX = aPoint.X(), anY = aPoint.Y();
68
69   if (theSelected.empty()) {
70     PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
71   } else {
72     ModuleBase_ViewerPrs aPrs = theSelected.front();
73     const TopoDS_Shape& aShape = aPrs.shape();
74     if (!aShape.IsNull()) {
75       if (aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected
76         const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
77         if (!aVertex.IsNull()) {
78           aPoint = BRep_Tool::Pnt(aVertex);
79           PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
80           ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
81           PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY);
82         }
83       } else if (aShape.ShapeType() == TopAbs_EDGE) { // a line is selected
84         PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
85       }
86     }
87   }
88   ObjectPtr aFeature;
89   if (!theSelected.empty()) {
90     ModuleBase_ViewerPrs aPrs = theSelected.front();
91     aFeature = aPrs.object();
92   } else {
93     aFeature = feature();  // for the widget distance only
94   }
95
96   bool isApplyed = setWidgetValue(aFeature, aX, anY);
97   if (isApplyed) {
98     flushUpdated();
99     myPropertyPanel->activateNextWidget();
100   }
101   commit();
102 }
103
104 /*bool PartSet_OperationFeatureBase::setWidgetValue(ObjectPtr theFeature, double theX, double theY)
105 {
106   ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
107   if (!aActiveWgt)
108     return false;
109   ModuleBase_WidgetValueFeature* aValue = new ModuleBase_WidgetValueFeature();
110   aValue->setObject(theFeature);
111   aValue->setPoint(boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY)));
112   bool isApplyed = aActiveWgt->setValue(aValue);
113
114   delete aValue;
115   myIsModified = (myIsModified || isApplyed);
116   return isApplyed;
117 }*/