1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketcherPrs_Coincident.cpp
4 // Created: 12 February 2015
5 // Author: Vitaly SMETANNIKOV
7 #include "SketcherPrs_Coincident.h"
8 #include "SketcherPrs_Tools.h"
10 #include <ModelAPI_AttributeRefAttr.h>
11 #include <ModelAPI_Events.h>
13 #include <GeomDataAPI_Point2D.h>
14 #include <GeomDataAPI_Dir.h>
15 #include <GeomDataAPI_Point.h>
17 #include <GeomAPI_XYZ.h>
18 #include <GeomAPI_Dir.h>
19 #include <GeomAPI_Pnt2d.h>
21 #include <SketchPlugin_Constraint.h>
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>
32 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Coincident, AIS_InteractiveObject);
34 SketcherPrs_Coincident::SketcherPrs_Coincident(ModelAPI_Feature* theConstraint,
35 const std::shared_ptr<GeomAPI_Ax3>& thePlane)
36 : AIS_InteractiveObject(), myConstraint(theConstraint), mySketcherPlane(thePlane),
37 myPoint(gp_Pnt(0.0, 0.0, 0.0)), myIsCustomColor(false)
41 bool SketcherPrs_Coincident::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
42 const std::shared_ptr<GeomAPI_Ax3>& thePlane)
45 return readyToDisplay(theConstraint, thePlane, aPoint);
48 bool SketcherPrs_Coincident::readyToDisplay(ModelAPI_Feature* theConstraint,
49 const std::shared_ptr<GeomAPI_Ax3>& thePlane,
52 bool aReadyToDisplay = false;
53 // Get point of the presentation
54 std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(theConstraint,
55 SketchPlugin_Constraint::ENTITY_A());
56 if (aPnt.get() == NULL)
57 aPnt = SketcherPrs_Tools::getPoint(theConstraint, SketchPlugin_Constraint::ENTITY_B());
59 aReadyToDisplay = aPnt.get() != NULL;
60 if (aReadyToDisplay) {
61 std::shared_ptr<GeomAPI_Pnt> aPoint = thePlane->to3D(aPnt->x(), aPnt->y());
62 thePoint = aPoint->impl<gp_Pnt>();
64 return aReadyToDisplay;
68 void SketcherPrs_Coincident::Compute(
69 const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
70 const Handle(Prs3d_Presentation)& thePresentation,
71 const Standard_Integer theMode)
74 bool aReadyToDisplay = readyToDisplay(myConstraint, mySketcherPlane, aPoint);
78 // Create the presentation as a combination of standard point markers
79 bool aCustomColor = myIsCustomColor;
80 // The external yellow contour
81 Handle(Graphic3d_AspectMarker3d) aPtA = new Graphic3d_AspectMarker3d();
82 aPtA->SetType(Aspect_TOM_RING3);
84 aPtA->SetColor(!aCustomColor ? Quantity_NOC_YELLOW : myCustomColor);
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);
92 // Make a black mid ring
93 aPtA = new Graphic3d_AspectMarker3d();
94 aPtA->SetType(Aspect_TOM_RING1);
96 aPtA->SetColor(!aCustomColor ? Quantity_NOC_BLACK : myCustomColor);
97 aGroup->SetPrimitivesAspect(aPtA);
98 aGroup->AddPrimitiveArray (aPntArray);
100 // Make an internal ring
101 aPtA = new Graphic3d_AspectMarker3d();
102 aPtA->SetType(Aspect_TOM_POINT);
104 aPtA->SetColor(!aCustomColor ? Quantity_NOC_BLACK : myCustomColor);
105 aGroup->SetPrimitivesAspect(aPtA);
106 aGroup->AddPrimitiveArray (aPntArray);
108 if (!aReadyToDisplay)
109 SketcherPrs_Tools::sendEmptyPresentationError(myConstraint,
110 "An empty AIS presentation: SketcherPrs_Coincident");
114 void SketcherPrs_Coincident::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
115 const Standard_Integer aMode)
117 // There is no selection of coincident - a point is selected instead of coincidence
120 void SketcherPrs_Coincident::SetColor(const Quantity_NameOfColor aCol)
122 SetColor(Quantity_Color(aCol));
125 void SketcherPrs_Coincident::SetColor(const Quantity_Color &aCol)
127 hasOwnColor=Standard_True;
131 void SketcherPrs_Coincident::SetCustomColor(const std::vector<int>& theColor)
133 myIsCustomColor = !theColor.empty();
135 myCustomColor = Quantity_Color(theColor[0] / 255., theColor[1] / 255.,
136 theColor[2] / 255., Quantity_TOC_RGB);
138 myCustomColor = Quantity_Color();