1 // File: SketchPlugin_ConstraintParallel.cpp
2 // Created: 26 May 2014
3 // Author: Artem ZHIDKOV
5 #include "SketchPlugin_ConstraintParallel.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_ParallelRelation.hxx>
15 #include <Geom_Plane.hxx>
17 #include <GeomDataAPI_Point2D.h>
18 #include <GeomAPI_Pnt2d.h>
19 #include <GeomAPI_Pnt.h>
21 SketchPlugin_ConstraintParallel::SketchPlugin_ConstraintParallel()
25 void SketchPlugin_ConstraintParallel::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_ConstraintParallel::execute()
36 const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_ConstraintParallel::preview()
38 /// \todo Preview for parallel constraint
43 Handle_AIS_InteractiveObject SketchPlugin_ConstraintParallel::getAISShape(Handle_AIS_InteractiveObject thePrevious)
45 Handle(AIS_InteractiveObject) anAIS = thePrevious;
49 boost::shared_ptr<ModelAPI_Data> aData = data();
50 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr1 =
51 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
52 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr2 =
53 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
54 if (!anAttr1 || !anAttr1->isFeature() ||
55 !anAttr2 || !anAttr2->isFeature())
57 boost::shared_ptr<SketchPlugin_Line> aLine1Feature =
58 boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr1->feature());
59 boost::shared_ptr<SketchPlugin_Line> aLine2Feature =
60 boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr2->feature());
61 if (!aLine1Feature || !aLine2Feature)
64 boost::shared_ptr<GeomAPI_Shape> aLine1 = aLine1Feature->preview();
65 boost::shared_ptr<GeomAPI_Shape> aLine2 = aLine2Feature->preview();
66 Handle(Geom_Plane) aPlane = new Geom_Plane(sketch()->plane()->impl<gp_Pln>());
68 boost::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
69 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
70 boost::shared_ptr<GeomAPI_Pnt2d> aFOPnt2d = aFlyoutAttr->pnt();
71 boost::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = sketch()->to3D(aFOPnt2d->x(), aFOPnt2d->y());
75 Handle(AIS_ParallelRelation) aParallel =
76 new AIS_ParallelRelation(aLine1->impl<TopoDS_Shape>(), aLine2->impl<TopoDS_Shape>(), aPlane);
77 aParallel->SetPosition(aFlyoutPnt->impl<gp_Pnt>());
82 Handle(AIS_ParallelRelation) aParallel = Handle(AIS_ParallelRelation)::DownCast(anAIS);
83 if (!aParallel.IsNull())
85 aParallel->SetFirstShape(aLine1->impl<TopoDS_Shape>());
86 aParallel->SetSecondShape(aLine2->impl<TopoDS_Shape>());
87 aParallel->SetPlane(aPlane);
88 aParallel->SetPosition(aFlyoutPnt->impl<gp_Pnt>());
89 aParallel->Redisplay(Standard_True);
95 void SketchPlugin_ConstraintParallel::move(double theDeltaX, double theDeltaY)
97 boost::shared_ptr<ModelAPI_Data> aData = data();
98 if (!aData->isValid())
101 boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
102 boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
103 aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY);