1 // File: SketchPlugin_ConstraintPerpendicular.cpp
2 // Created: 26 May 2014
3 // Author: Artem ZHIDKOV
5 #include "SketchPlugin_ConstraintPerpendicular.h"
7 #include <ModelAPI_AttributeDouble.h>
8 #include <ModelAPI_Data.h>
9 #include <SketchPlugin_Line.h>
11 #include <AIS_InteractiveObject.hxx>
12 #include <AIS_PerpendicularRelation.hxx>
13 #include <Geom_Plane.hxx>
15 SketchPlugin_ConstraintPerpendicular::SketchPlugin_ConstraintPerpendicular()
19 void SketchPlugin_ConstraintPerpendicular::initAttributes()
21 data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type());
22 data()->addAttribute(CONSTRAINT_ATTR_ENTITY_B, ModelAPI_AttributeRefAttr::type());
25 void SketchPlugin_ConstraintPerpendicular::execute()
29 const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_ConstraintPerpendicular::preview()
31 /// \todo Preview for perpendicular constraint
35 Handle_AIS_InteractiveObject SketchPlugin_ConstraintPerpendicular::getAISShape(Handle_AIS_InteractiveObject thePrevious)
37 Handle(AIS_InteractiveObject) anAIS = thePrevious;
41 boost::shared_ptr<ModelAPI_Data> aData = data();
42 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr1 =
43 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
44 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr2 =
45 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
46 if (!anAttr1 || !anAttr1->isFeature() ||
47 !anAttr2 || !anAttr2->isFeature())
49 boost::shared_ptr<SketchPlugin_Line> aLine1Feature =
50 boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr1->feature());
51 boost::shared_ptr<SketchPlugin_Line> aLine2Feature =
52 boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr2->feature());
53 if (!aLine1Feature || !aLine2Feature)
56 boost::shared_ptr<GeomAPI_Shape> aLine1 = aLine1Feature->preview();
57 boost::shared_ptr<GeomAPI_Shape> aLine2 = aLine2Feature->preview();
58 Handle(Geom_Plane) aPlane = new Geom_Plane(sketch()->plane()->impl<gp_Pln>());
62 Handle(AIS_PerpendicularRelation) aPerpendicular =
63 new AIS_PerpendicularRelation(aLine1->impl<TopoDS_Shape>(), aLine2->impl<TopoDS_Shape>(), aPlane);
65 anAIS = aPerpendicular;
69 Handle(AIS_PerpendicularRelation) aPerpendicular = Handle(AIS_PerpendicularRelation)::DownCast(anAIS);
70 if (!aPerpendicular.IsNull())
72 aPerpendicular->SetFirstShape(aLine1->impl<TopoDS_Shape>());
73 aPerpendicular->SetSecondShape(aLine2->impl<TopoDS_Shape>());
74 aPerpendicular->SetPlane(aPlane);
75 aPerpendicular->Redisplay(Standard_True);