]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Presentation.cpp
Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
[modules/shaper.git] / src / PartSet / PartSet_Presentation.cpp
1 // File:        PartSet_Presentation.h
2 // Created:     02 June 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #include <PartSet_Presentation.h>
6 #include <PartSet_Tools.h>
7
8 #include <PartSet_FeatureLengthPrs.h>
9
10 #include <ModelAPI_Feature.h>
11
12 #include <SketchPlugin_Sketch.h>
13
14 #include <AIS_InteractiveObject.hxx>
15 #include <AIS_Shape.hxx>
16
17 #include <Quantity_NameOfColor.hxx>
18
19 const Quantity_NameOfColor SKETCH_PLANE_COLOR = Quantity_NOC_CHOCOLATE; /// the plane edge color
20 const int SKETCH_WIDTH = 4; /// the plane edge width
21
22 Handle(AIS_InteractiveObject) PartSet_Presentation::createPresentation(
23                                          FeaturePtr theFeature,
24                                          FeaturePtr theSketch,
25                                          const TopoDS_Shape& theShape,
26                                          Handle_AIS_InteractiveObject thePreviuos)
27 {
28   Handle(AIS_InteractiveObject) anAIS;
29
30   std::string aKind = theFeature->getKind();
31   if (aKind == PartSet_FeatureLengthPrs::getKind())
32     anAIS = PartSet_FeatureLengthPrs::createPresentation(theFeature, theSketch, thePreviuos);
33   else {
34     anAIS = createFeature(theFeature, theShape, thePreviuos);
35     if (theFeature->getKind() == SKETCH_KIND)
36     {
37       Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS);
38       aShapeAIS->SetColor(Quantity_Color(SKETCH_PLANE_COLOR));
39       aShapeAIS->SetWidth(SKETCH_WIDTH);
40       aShapeAIS->Redisplay();
41     }
42   }
43
44   return anAIS;
45 }
46
47 Handle(AIS_InteractiveObject) PartSet_Presentation::createFeature(
48                                               FeaturePtr theFeature,
49                                               const TopoDS_Shape& theShape,
50                                               Handle_AIS_InteractiveObject thePreviuos)
51 {
52   Handle(AIS_InteractiveObject) anAIS = thePreviuos;
53   if (!anAIS.IsNull())
54   {
55     Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS);
56     if (!aShapeAIS.IsNull()) {
57       // if the AIS object is displayed in the opened local context in some mode, additional
58       // AIS sub objects are created there. They should be rebuild for correct selecting.
59       // It is possible to correct it by closing local context before the shape set and opening
60       // after. Another workaround to thrown down the selection and reselecting the AIS.
61       // If there was a problem here, try the first solution with close/open local context.
62       aShapeAIS->Set(theShape);
63       aShapeAIS->Redisplay(Standard_True);
64     }
65   }
66   else
67   {
68     anAIS = new AIS_Shape(theShape);
69   }
70   return anAIS;
71 }