Salome HOME
Color correction of conflicting coincidence constraint. Scenario for conflicting...
[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 <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), mySketcherPlane(thePlane),
38   myPoint(gp_Pnt(0.0, 0.0, 0.0)), myIsConflicting(false)
39 {
40 }
41
42 bool SketcherPrs_Coincident::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
43                                               const std::shared_ptr<GeomAPI_Ax3>& thePlane)
44 {
45   gp_Pnt aPoint;
46   return readyToDisplay(theConstraint, thePlane, aPoint);
47 }
48
49 bool SketcherPrs_Coincident::readyToDisplay(ModelAPI_Feature* theConstraint,
50                                             const std::shared_ptr<GeomAPI_Ax3>& thePlane,
51                                             gp_Pnt& thePoint)
52 {
53   bool aReadyToDisplay = false;
54   // Get point of the presentation
55   std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(theConstraint,
56                                                               SketchPlugin_Constraint::ENTITY_A());
57   if (aPnt.get() == NULL)
58     aPnt = SketcherPrs_Tools::getPoint(theConstraint, SketchPlugin_Constraint::ENTITY_B());
59
60   aReadyToDisplay = aPnt.get() != NULL;
61   if (aReadyToDisplay) {
62     std::shared_ptr<GeomAPI_Pnt> aPoint = thePlane->to3D(aPnt->x(), aPnt->y());
63     thePoint = aPoint->impl<gp_Pnt>();
64   }
65   return aReadyToDisplay;
66 }
67
68
69 void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
70                                    const Handle(Prs3d_Presentation)& thePresentation, 
71                                    const Standard_Integer theMode)
72 {
73   gp_Pnt aPoint;
74   bool aReadyToDisplay = readyToDisplay(myConstraint, mySketcherPlane, aPoint);
75   if (aReadyToDisplay)
76     myPoint = aPoint;
77
78   // Get point of the presentation
79   static Handle(Graphic3d_AspectMarker3d) aPtA;
80   if (aPtA.IsNull()) {
81     aPtA = new Graphic3d_AspectMarker3d ();
82   }
83   // Create the presentation as a combination of standard point markers
84
85   bool aValid = !myIsConflicting;
86   // The external yellow contour
87   aPtA->SetType(Aspect_TOM_RING3);
88   aPtA->SetScale(2.);
89   aPtA->SetColor(aValid ? Quantity_NOC_YELLOW : myConflictingColor);
90
91   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
92   aGroup->SetPrimitivesAspect(aPtA);
93   Handle(Graphic3d_ArrayOfPoints) aPntArray = new Graphic3d_ArrayOfPoints(1);
94   aPntArray->AddVertex (myPoint.X(), myPoint.Y(), myPoint.Z());
95   aGroup->AddPrimitiveArray (aPntArray);
96
97   // Make a black mid ring
98   aPtA->SetType(Aspect_TOM_RING1);
99   aPtA->SetScale(1.);
100   aPtA->SetColor(aValid ? Quantity_NOC_BLACK : myConflictingColor);
101   aGroup->SetPrimitivesAspect(aPtA);
102   aGroup->AddPrimitiveArray (aPntArray);
103
104   // Make an internal ring
105   aPtA->SetType(Aspect_TOM_POINT);
106   aPtA->SetScale(5.);
107   aGroup->SetPrimitivesAspect(aPtA);
108   aGroup->AddPrimitiveArray (aPntArray);
109
110   if (!aReadyToDisplay)
111     SketcherPrs_Tools::sendEmptyPresentationError(myConstraint,
112                               "An empty AIS presentation: SketcherPrs_Coincident");
113 }
114
115
116 void SketcherPrs_Coincident::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
117                                             const Standard_Integer aMode)
118 {
119   // There is no selection of coincident - a point is selected instead of coincidence
120 }
121
122 void SketcherPrs_Coincident::SetColor(const Quantity_NameOfColor aCol)
123 {
124   SetColor(Quantity_Color(aCol));
125 }
126
127 void SketcherPrs_Coincident::SetColor(const Quantity_Color &aCol)
128 {
129   hasOwnColor=Standard_True;
130   myOwnColor=aCol;
131 }
132
133 void SketcherPrs_Coincident::SetConflictingConstraint(const bool& theConflicting,
134                                                      const std::vector<int>& theColor)
135 {
136   myIsConflicting = theConflicting;
137   myConflictingColor = Quantity_Color(theColor[0] / 255., theColor[1] / 255., theColor[2] / 255.,
138                                       Quantity_TOC_RGB);
139 }