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>
9 #include <SketchPlugin_Line.h>
11 #include <AIS_InteractiveObject.hxx>
12 #include <AIS_ParallelRelation.hxx>
13 #include <Geom_Plane.hxx>
15 SketchPlugin_ConstraintParallel::SketchPlugin_ConstraintParallel()
19 void SketchPlugin_ConstraintParallel::initAttributes()
21 data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type());
22 data()->addAttribute(CONSTRAINT_ATTR_ENTITY_B, ModelAPI_AttributeRefAttr::type());
25 void SketchPlugin_ConstraintParallel::execute()
29 const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_ConstraintParallel::preview()
31 /// \todo Preview for parallel constraint
36 Handle_AIS_InteractiveObject SketchPlugin_ConstraintParallel::getAISShape(Handle_AIS_InteractiveObject thePrevious)
38 Handle(AIS_InteractiveObject) anAIS = thePrevious;
42 boost::shared_ptr<ModelAPI_Data> aData = data();
43 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr1 =
44 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
45 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr2 =
46 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
47 if (!anAttr1 || !anAttr1->isFeature() ||
48 !anAttr2 || !anAttr2->isFeature())
50 boost::shared_ptr<SketchPlugin_Line> aLine1Feature =
51 boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr1->feature());
52 boost::shared_ptr<SketchPlugin_Line> aLine2Feature =
53 boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr2->feature());
54 if (!aLine1Feature || !aLine2Feature)
57 boost::shared_ptr<GeomAPI_Shape> aLine1 = aLine1Feature->preview();
58 boost::shared_ptr<GeomAPI_Shape> aLine2 = aLine2Feature->preview();
59 Handle(Geom_Plane) aPlane = new Geom_Plane(sketch()->plane()->impl<gp_Pln>());
63 Handle(AIS_ParallelRelation) aParallel =
64 new AIS_ParallelRelation(aLine1->impl<TopoDS_Shape>(), aLine2->impl<TopoDS_Shape>(), aPlane);
70 Handle(AIS_ParallelRelation) aParallel = Handle(AIS_ParallelRelation)::DownCast(anAIS);
71 if (!aParallel.IsNull())
73 aParallel->SetFirstShape(aLine1->impl<TopoDS_Shape>());
74 aParallel->SetSecondShape(aLine2->impl<TopoDS_Shape>());
75 aParallel->SetPlane(aPlane);
76 aParallel->Redisplay(Standard_True);