]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp
Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintPerpendicular.cpp
1 // File:    SketchPlugin_ConstraintPerpendicular.cpp
2 // Created: 26 May 2014
3 // Author:  Artem ZHIDKOV
4
5 #include "SketchPlugin_ConstraintPerpendicular.h"
6
7 #include <GeomDataAPI_Point2D.h>
8
9 #include <ModelAPI_AttributeDouble.h>
10 #include <ModelAPI_Data.h>
11 #include <SketchPlugin_Line.h>
12
13 #include <AIS_InteractiveObject.hxx>
14 #include <AIS_PerpendicularRelation.hxx>
15 #include <Geom_Plane.hxx>
16
17 SketchPlugin_ConstraintPerpendicular::SketchPlugin_ConstraintPerpendicular()
18 {
19 }
20
21 void SketchPlugin_ConstraintPerpendicular::initAttributes()
22 {
23   data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type());
24   data()->addAttribute(CONSTRAINT_ATTR_ENTITY_B, ModelAPI_AttributeRefAttr::type());
25   data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type());
26 }
27
28 void SketchPlugin_ConstraintPerpendicular::execute()
29 {
30 }
31
32 const boost::shared_ptr<GeomAPI_Shape>&  SketchPlugin_ConstraintPerpendicular::preview()
33 {
34   /// \todo Preview for perpendicular constraint
35   return getPreview();
36 }
37
38 Handle_AIS_InteractiveObject SketchPlugin_ConstraintPerpendicular::getAISShape(Handle_AIS_InteractiveObject thePrevious)
39 {
40   Handle(AIS_InteractiveObject) anAIS = thePrevious;
41   if (!sketch())
42     return anAIS;
43
44   boost::shared_ptr<ModelAPI_Data> aData = data();
45   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr1 = 
46     boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
47   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr2 = 
48     boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
49   if (!anAttr1 || !anAttr1->isFeature() || 
50       !anAttr2 || !anAttr2->isFeature())
51     return anAIS;
52   boost::shared_ptr<SketchPlugin_Line> aLine1Feature = 
53     boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr1->feature());
54   boost::shared_ptr<SketchPlugin_Line> aLine2Feature = 
55     boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr2->feature());
56   if (!aLine1Feature || !aLine2Feature)
57     return anAIS;
58
59   boost::shared_ptr<GeomAPI_Shape> aLine1 = aLine1Feature->preview();
60   boost::shared_ptr<GeomAPI_Shape> aLine2 = aLine2Feature->preview();
61   Handle(Geom_Plane) aPlane = new Geom_Plane(sketch()->plane()->impl<gp_Pln>());
62
63   if (anAIS.IsNull())
64   {
65     Handle(AIS_PerpendicularRelation) aPerpendicular = 
66       new AIS_PerpendicularRelation(aLine1->impl<TopoDS_Shape>(), aLine2->impl<TopoDS_Shape>(), aPlane);
67
68     anAIS = aPerpendicular;
69   }
70   else
71   {
72     Handle(AIS_PerpendicularRelation) aPerpendicular = Handle(AIS_PerpendicularRelation)::DownCast(anAIS);
73     if (!aPerpendicular.IsNull())
74     {
75       aPerpendicular->SetFirstShape(aLine1->impl<TopoDS_Shape>());
76       aPerpendicular->SetSecondShape(aLine2->impl<TopoDS_Shape>());
77       aPerpendicular->SetPlane(aPlane);
78       aPerpendicular->Redisplay(Standard_True);
79     }
80   }
81   return anAIS;
82 }
83