1 #include "SketchPlugin_Feature.h"
2 #include "SketchPlugin_Sketch.h"
3 #include <ModelAPI_Document.h>
4 #include <ModelAPI_Data.h>
5 #include <ModelAPI_Object.h>
6 #include <ModelAPI_AttributeRefList.h>
8 #include <AIS_InteractiveObject.hxx>
9 #include <AIS_Shape.hxx>
10 #include <TopoDS_Shape.hxx>
12 SketchPlugin_Feature::SketchPlugin_Feature()
17 void SketchPlugin_Feature::setPreview(const boost::shared_ptr<GeomAPI_Shape>& theShape)
22 const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Feature::getPreview() const
27 SketchPlugin_Sketch* SketchPlugin_Feature::sketch()
30 // find sketch that references to this feature
31 int aSketches = document()->size("Construction");
32 for(int a = 0; a < aSketches && !mySketch; a++) {
33 boost::shared_ptr<SketchPlugin_Sketch> aSketch = boost::
34 dynamic_pointer_cast<SketchPlugin_Sketch>(document()->feature("Construction", a, true));
36 std::list<FeaturePtr > aList =
37 aSketch->data()->reflist(SKETCH_ATTR_FEATURES)->list();
38 std::list<FeaturePtr >::iterator aSub = aList.begin();
39 for(; aSub != aList.end(); aSub++) {
40 if ((*aSub)->data()->isEqual(data())) {
41 mySketch = aSketch.get();
51 Handle(AIS_InteractiveObject) SketchPlugin_Feature::getAISShape(Handle(AIS_InteractiveObject) thePrevious)
53 boost::shared_ptr<GeomAPI_Shape> aPreview = preview();
55 Handle(AIS_InteractiveObject) anAIS = thePrevious;
56 const TopoDS_Shape& aShape = aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape();
59 Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS);
60 if (!aShapeAIS.IsNull()) {
61 // if the AIS object is displayed in the opened local context in some mode, additional
62 // AIS sub objects are created there. They should be rebuild for correct selecting.
63 // It is possible to correct it by closing local context before the shape set and opening
64 // after. Another workaround to thrown down the selection and reselecting the AIS.
65 // If there was a problem here, try the first solution with close/open local context.
67 aShapeAIS->Set(aShape);
68 aShapeAIS->Redisplay(Standard_True);
73 anAIS = new AIS_Shape(aShape);