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 #include <GeomDataAPI_Point2D.h>
17 SketchPlugin_ConstraintParallel::SketchPlugin_ConstraintParallel()
21 void SketchPlugin_ConstraintParallel::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_ConstraintParallel::execute()
32 const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_ConstraintParallel::preview()
34 /// \todo Preview for parallel constraint
39 Handle_AIS_InteractiveObject SketchPlugin_ConstraintParallel::getAISShape(Handle_AIS_InteractiveObject thePrevious)
41 Handle(AIS_InteractiveObject) anAIS = thePrevious;
45 boost::shared_ptr<ModelAPI_Data> aData = data();
46 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr1 =
47 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
48 boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr2 =
49 boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
50 if (!anAttr1 || !anAttr1->isFeature() ||
51 !anAttr2 || !anAttr2->isFeature())
53 boost::shared_ptr<SketchPlugin_Line> aLine1Feature =
54 boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr1->feature());
55 boost::shared_ptr<SketchPlugin_Line> aLine2Feature =
56 boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr2->feature());
57 if (!aLine1Feature || !aLine2Feature)
60 boost::shared_ptr<GeomAPI_Shape> aLine1 = aLine1Feature->preview();
61 boost::shared_ptr<GeomAPI_Shape> aLine2 = aLine2Feature->preview();
62 Handle(Geom_Plane) aPlane = new Geom_Plane(sketch()->plane()->impl<gp_Pln>());
66 Handle(AIS_ParallelRelation) aParallel =
67 new AIS_ParallelRelation(aLine1->impl<TopoDS_Shape>(), aLine2->impl<TopoDS_Shape>(), aPlane);
73 Handle(AIS_ParallelRelation) aParallel = Handle(AIS_ParallelRelation)::DownCast(anAIS);
74 if (!aParallel.IsNull())
76 aParallel->SetFirstShape(aLine1->impl<TopoDS_Shape>());
77 aParallel->SetSecondShape(aLine2->impl<TopoDS_Shape>());
78 aParallel->SetPlane(aPlane);
79 aParallel->Redisplay(Standard_True);