Salome HOME
empty AIS presentation should not be visualized in the viewer. It is caused by OCCT...
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Coincident.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        SketcherPrs_Coincident.cpp
4 // Created:     12 February 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "SketcherPrs_Coincident.h"
8 #include "SketcherPrs_Tools.h"
9
10 #include <ModelAPI_AttributeRefAttr.h>
11 #include <GeomDataAPI_Point2D.h>
12 #include <GeomDataAPI_Dir.h>
13 #include <GeomDataAPI_Point.h>
14
15 #include <GeomAPI_XYZ.h>
16 #include <GeomAPI_Dir.h>
17 #include <GeomAPI_Pnt2d.h>
18
19 #include <Events_Error.h>
20
21 #include <SketchPlugin_Constraint.h>
22
23 #include <Graphic3d_AspectMarker3d.hxx>
24 #include <Graphic3d_ArrayOfPoints.hxx>
25 #include <Prs3d_PointAspect.hxx>
26 #include <Prs3d_Root.hxx>
27 #include <SelectMgr_EntityOwner.hxx>
28 #include <SelectMgr_Selection.hxx>
29 #include <Select3D_SensitivePoint.hxx>
30
31
32 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Coincident, AIS_InteractiveObject);
33 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Coincident, AIS_InteractiveObject);
34
35 SketcherPrs_Coincident::SketcherPrs_Coincident(ModelAPI_Feature* theConstraint, 
36                                                const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
37  : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane)
38 {
39   
40 }  
41
42 bool SketcherPrs_Coincident::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
43                                               const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
44 {
45   bool aReadyToDisplay = false;
46
47   // Get point of the presentation
48   std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(theConstraint,
49                                                               SketchPlugin_Constraint::ENTITY_A());
50   if (aPnt.get() == NULL)
51     aPnt = SketcherPrs_Tools::getPoint(theConstraint, SketchPlugin_Constraint::ENTITY_B());
52   
53   aReadyToDisplay = aPnt.get() != NULL;
54   return aReadyToDisplay;
55 }
56
57
58 void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
59                                    const Handle(Prs3d_Presentation)& thePresentation, 
60                                    const Standard_Integer theMode)
61 {
62   if (!IsReadyToDisplay(myConstraint, myPlane)) {
63     Events_Error::throwException("An empty AIS presentation: SketcherPrs_Coincident");
64     return;
65   }
66
67   // Get point of the presentation
68   std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(myConstraint, 
69                                                                     SketchPlugin_Constraint::ENTITY_A());
70   if (aPnt.get() == NULL)
71     aPnt = SketcherPrs_Tools::getPoint(myConstraint, SketchPlugin_Constraint::ENTITY_B());
72   std::shared_ptr<GeomAPI_Pnt> aPoint = myPlane->to3D(aPnt->x(), aPnt->y());
73   myPoint = aPoint->impl<gp_Pnt>();
74
75   static Handle(Graphic3d_AspectMarker3d) aPtA;
76   if (aPtA.IsNull()) {
77     aPtA = new Graphic3d_AspectMarker3d ();
78   }
79   // Create the presentation as a combination of standard point markers
80
81   // The external yellow contour
82   aPtA->SetType(Aspect_TOM_RING3);
83   aPtA->SetScale(2.);
84   aPtA->SetColor(Quantity_NOC_YELLOW);
85
86   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
87   aGroup->SetPrimitivesAspect(aPtA);
88   Handle(Graphic3d_ArrayOfPoints) aPntArray = new Graphic3d_ArrayOfPoints(1);
89   aPntArray->AddVertex (aPoint->x(), aPoint->y(), aPoint->z());
90   aGroup->AddPrimitiveArray (aPntArray);
91
92   // Make a black mid ring
93   aPtA->SetType(Aspect_TOM_RING1);
94   aPtA->SetScale(1.);
95   aPtA->SetColor(Quantity_NOC_BLACK);
96   aGroup->SetPrimitivesAspect(aPtA);
97   aGroup->AddPrimitiveArray (aPntArray);
98
99   // Make an internal ring
100   aPtA->SetType(Aspect_TOM_POINT);
101   aPtA->SetScale(5.);
102   aGroup->SetPrimitivesAspect(aPtA);
103   aGroup->AddPrimitiveArray (aPntArray);
104 }
105
106
107 void SketcherPrs_Coincident::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
108                                             const Standard_Integer aMode)
109 {
110   // There is no selection of coincident - a point is selected instead of coincidence
111 }
112
113 void SketcherPrs_Coincident::SetColor(const Quantity_NameOfColor aCol)
114 {
115   SetColor(Quantity_Color(aCol));
116 }
117
118 void SketcherPrs_Coincident::SetColor(const Quantity_Color &aCol)
119 {
120   hasOwnColor=Standard_True;
121   myOwnColor=aCol;
122 }