1 // File: SketchPlugin_ConstraintPerpendicular.cpp
2 // Created: 26 May 2014
3 // Author: Artem ZHIDKOV
5 #include "SketchPlugin_ConstraintPerpendicular.h"
7 #include <GeomDataAPI_Point2D.h>
9 #include <ModelAPI_AttributeDouble.h>
10 #include <ModelAPI_Data.h>
11 #include <SketchPlugin_Line.h>
13 #include <AIS_InteractiveObject.hxx>
14 #include <AIS_PerpendicularRelation.hxx>
15 #include <Geom_Plane.hxx>
17 SketchPlugin_ConstraintPerpendicular::SketchPlugin_ConstraintPerpendicular()
21 void SketchPlugin_ConstraintPerpendicular::initAttributes()
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());
28 void SketchPlugin_ConstraintPerpendicular::execute()
32 const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_ConstraintPerpendicular::preview()
34 /// \todo Preview for perpendicular constraint
38 Handle_AIS_InteractiveObject SketchPlugin_ConstraintPerpendicular::getAISShape(Handle_AIS_InteractiveObject thePrevious)
40 Handle(AIS_InteractiveObject) anAIS = thePrevious;
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())
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)
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>());
65 Handle(AIS_PerpendicularRelation) aPerpendicular =
66 new AIS_PerpendicularRelation(aLine1->impl<TopoDS_Shape>(), aLine2->impl<TopoDS_Shape>(), aPlane);
68 anAIS = aPerpendicular;
72 Handle(AIS_PerpendicularRelation) aPerpendicular = Handle(AIS_PerpendicularRelation)::DownCast(anAIS);
73 if (!aPerpendicular.IsNull())
75 aPerpendicular->SetFirstShape(aLine1->impl<TopoDS_Shape>());
76 aPerpendicular->SetSecondShape(aLine2->impl<TopoDS_Shape>());
77 aPerpendicular->SetPlane(aPlane);
78 aPerpendicular->Redisplay(Standard_True);