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>
10 #include <SketchPlugin_Line.h>
11 #include <SketchPlugin_Sketch.h>
13 #include <AIS_InteractiveObject.hxx>
14 #include <AIS_PerpendicularRelation.hxx>
15 #include <Geom_Plane.hxx>
17 #include <GeomDataAPI_Point2D.h>
18 #include <GeomAPI_Pnt2d.h>
19 #include <GeomAPI_Pnt.h>
21 SketchPlugin_ConstraintPerpendicular::SketchPlugin_ConstraintPerpendicular()
25 void SketchPlugin_ConstraintPerpendicular::initAttributes()
27 data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type());
28 data()->addAttribute(CONSTRAINT_ATTR_ENTITY_B, ModelAPI_AttributeRefAttr::type());
29 data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type());
32 void SketchPlugin_ConstraintPerpendicular::execute()
36 const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_ConstraintPerpendicular::preview()
38 /// \todo Preview for perpendicular constraint
42 Handle_AIS_InteractiveObject SketchPlugin_ConstraintPerpendicular::getAISShape(Handle_AIS_InteractiveObject thePrevious)
44 Handle(AIS_InteractiveObject) anAIS = thePrevious;
48 boost::shared_ptr<ModelAPI_Data> aData = data();
49 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr1 =
50 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
51 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr2 =
52 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
53 if (!anAttr1 || !anAttr1->isFeature() ||
54 !anAttr2 || !anAttr2->isFeature())
56 boost::shared_ptr<SketchPlugin_Line> aLine1Feature =
57 boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr1->feature());
58 boost::shared_ptr<SketchPlugin_Line> aLine2Feature =
59 boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr2->feature());
60 if (!aLine1Feature || !aLine2Feature)
63 boost::shared_ptr<GeomAPI_Shape> aLine1 = aLine1Feature->preview();
64 boost::shared_ptr<GeomAPI_Shape> aLine2 = aLine2Feature->preview();
65 Handle(Geom_Plane) aPlane = new Geom_Plane(sketch()->plane()->impl<gp_Pln>());
67 boost::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
68 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
69 boost::shared_ptr<GeomAPI_Pnt2d> aFOPnt2d = aFlyoutAttr->pnt();
70 boost::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = sketch()->to3D(aFOPnt2d->x(), aFOPnt2d->y());
74 Handle(AIS_PerpendicularRelation) aPerpendicular =
75 new AIS_PerpendicularRelation(aLine1->impl<TopoDS_Shape>(), aLine2->impl<TopoDS_Shape>(), aPlane);
76 aPerpendicular->SetPosition(aFlyoutPnt->impl<gp_Pnt>());
77 anAIS = aPerpendicular;
81 Handle(AIS_PerpendicularRelation) aPerpendicular = Handle(AIS_PerpendicularRelation)::DownCast(anAIS);
82 if (!aPerpendicular.IsNull())
84 aPerpendicular->SetFirstShape(aLine1->impl<TopoDS_Shape>());
85 aPerpendicular->SetSecondShape(aLine2->impl<TopoDS_Shape>());
86 aPerpendicular->SetPlane(aPlane);
87 aPerpendicular->SetPosition(aFlyoutPnt->impl<gp_Pnt>());
88 aPerpendicular->Redisplay(Standard_True);
94 void SketchPlugin_ConstraintPerpendicular::move(double theDeltaX, double theDeltaY)
96 boost::shared_ptr<ModelAPI_Data> aData = data();
97 if (!aData->isValid())
100 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
101 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
102 aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY);