]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketcherPrs/SketcherPrs_Coincident.cpp
Salome HOME
#1404 Random crash with Shaper: AIS presentations: coincidence/radius constraints...
[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 <ModelAPI_Events.h>
12
13 #include <GeomDataAPI_Point2D.h>
14 #include <GeomDataAPI_Dir.h>
15 #include <GeomDataAPI_Point.h>
16
17 #include <GeomAPI_XYZ.h>
18 #include <GeomAPI_Dir.h>
19 #include <GeomAPI_Pnt2d.h>
20
21 #include <Events_Error.h>
22
23 #include <SketchPlugin_Constraint.h>
24
25 #include <Graphic3d_AspectMarker3d.hxx>
26 #include <Graphic3d_ArrayOfPoints.hxx>
27 #include <Prs3d_PointAspect.hxx>
28 #include <Prs3d_Root.hxx>
29 #include <SelectMgr_EntityOwner.hxx>
30 #include <SelectMgr_Selection.hxx>
31 #include <Select3D_SensitivePoint.hxx>
32
33
34 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Coincident, AIS_InteractiveObject);
35 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Coincident, AIS_InteractiveObject);
36
37 SketcherPrs_Coincident::SketcherPrs_Coincident(ModelAPI_Feature* theConstraint, 
38                                                const std::shared_ptr<GeomAPI_Ax3>& thePlane) 
39  : AIS_InteractiveObject(), myConstraint(theConstraint), mySketcherPlane(thePlane)
40 {
41   
42 }  
43
44 bool SketcherPrs_Coincident::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
45                                               const std::shared_ptr<GeomAPI_Ax3>&/* thePlane*/)
46 {
47   bool aReadyToDisplay = false;
48
49   // Get point of the presentation
50   std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(theConstraint,
51                                                               SketchPlugin_Constraint::ENTITY_A());
52   if (aPnt.get() == NULL)
53     aPnt = SketcherPrs_Tools::getPoint(theConstraint, SketchPlugin_Constraint::ENTITY_B());
54   
55   aReadyToDisplay = aPnt.get() != NULL;
56   return aReadyToDisplay;
57 }
58
59
60 void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
61                                    const Handle(Prs3d_Presentation)& thePresentation, 
62                                    const Standard_Integer theMode)
63 {
64   bool aReadyToDisplay = IsReadyToDisplay(myConstraint, mySketcherPlane);
65   if (aReadyToDisplay) {
66     std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(myConstraint, 
67                                                                       SketchPlugin_Constraint::ENTITY_A());
68     if (aPnt.get() == NULL)
69       aPnt = SketcherPrs_Tools::getPoint(myConstraint, SketchPlugin_Constraint::ENTITY_B());
70     std::shared_ptr<GeomAPI_Pnt> aPoint = mySketcherPlane->to3D(aPnt->x(), aPnt->y());
71     myPoint = aPoint->impl<gp_Pnt>();
72   }
73
74   // Get point of the presentation
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 (myPoint.X(), myPoint.Y(), myPoint.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   if (!aReadyToDisplay)
106     SketcherPrs_Tools::sendEmptyPresentationError(myConstraint,
107                               "An empty AIS presentation: SketcherPrs_Coincident");
108 }
109
110
111 void SketcherPrs_Coincident::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
112                                             const Standard_Integer aMode)
113 {
114   // There is no selection of coincident - a point is selected instead of coincidence
115 }
116
117 void SketcherPrs_Coincident::SetColor(const Quantity_NameOfColor aCol)
118 {
119   SetColor(Quantity_Color(aCol));
120 }
121
122 void SketcherPrs_Coincident::SetColor(const Quantity_Color &aCol)
123 {
124   hasOwnColor=Standard_True;
125   myOwnColor=aCol;
126 }