]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp
Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintParallel.cpp
1 // File:    SketchPlugin_ConstraintParallel.cpp
2 // Created: 26 May 2014
3 // Author:  Artem ZHIDKOV
4
5 #include "SketchPlugin_ConstraintParallel.h"
6
7 #include <ModelAPI_AttributeDouble.h>
8 #include <ModelAPI_Data.h>
9 #include <SketchPlugin_Line.h>
10
11 #include <AIS_InteractiveObject.hxx>
12 #include <AIS_ParallelRelation.hxx>
13 #include <Geom_Plane.hxx>
14
15 SketchPlugin_ConstraintParallel::SketchPlugin_ConstraintParallel()
16 {
17 }
18
19 void SketchPlugin_ConstraintParallel::initAttributes()
20 {
21   data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type());
22   data()->addAttribute(CONSTRAINT_ATTR_ENTITY_B, ModelAPI_AttributeRefAttr::type());
23 }
24
25 void SketchPlugin_ConstraintParallel::execute()
26 {
27 }
28
29 const boost::shared_ptr<GeomAPI_Shape>&  SketchPlugin_ConstraintParallel::preview()
30 {
31   /// \todo Preview for parallel constraint
32   return getPreview();
33 }
34
35
36 Handle_AIS_InteractiveObject SketchPlugin_ConstraintParallel::getAISShape(Handle_AIS_InteractiveObject thePrevious)
37 {
38   Handle(AIS_InteractiveObject) anAIS = thePrevious;
39   if (!sketch())
40     return anAIS;
41
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())
49     return anAIS;
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)
55     return anAIS;
56
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>());
60
61   if (anAIS.IsNull())
62   {
63     Handle(AIS_ParallelRelation) aParallel = 
64       new AIS_ParallelRelation(aLine1->impl<TopoDS_Shape>(), aLine2->impl<TopoDS_Shape>(), aPlane);
65
66     anAIS = aParallel;
67   }
68   else
69   {
70     Handle(AIS_ParallelRelation) aParallel = Handle(AIS_ParallelRelation)::DownCast(anAIS);
71     if (!aParallel.IsNull())
72     {
73       aParallel->SetFirstShape(aLine1->impl<TopoDS_Shape>());
74       aParallel->SetSecondShape(aLine2->impl<TopoDS_Shape>());
75       aParallel->SetPlane(aPlane);
76       aParallel->Redisplay(Standard_True);
77     }
78   }
79   return anAIS;
80 }
81