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 <Events_Error.h>
23 #include <SketchPlugin_Constraint.h>
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>
34 IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Coincident, AIS_InteractiveObject);
35 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Coincident, AIS_InteractiveObject);
37 SketcherPrs_Coincident::SketcherPrs_Coincident(ModelAPI_Feature* theConstraint,
38 const std::shared_ptr<GeomAPI_Ax3>& thePlane)
39 : AIS_InteractiveObject(), myConstraint(theConstraint), mySketcherPlane(thePlane),
40 myPoint(gp_Pnt(0.0, 0.0, 0.0))
44 bool SketcherPrs_Coincident::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
45 const std::shared_ptr<GeomAPI_Ax3>& thePlane)
48 return readyToDisplay(theConstraint, thePlane, aPoint);
51 bool SketcherPrs_Coincident::readyToDisplay(ModelAPI_Feature* theConstraint,
52 const std::shared_ptr<GeomAPI_Ax3>& thePlane,
55 bool aReadyToDisplay = false;
56 // Get point of the presentation
57 std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(theConstraint,
58 SketchPlugin_Constraint::ENTITY_A());
59 if (aPnt.get() == NULL)
60 aPnt = SketcherPrs_Tools::getPoint(theConstraint, SketchPlugin_Constraint::ENTITY_B());
62 aReadyToDisplay = aPnt.get() != NULL;
63 if (aReadyToDisplay) {
64 std::shared_ptr<GeomAPI_Pnt> aPoint = thePlane->to3D(aPnt->x(), aPnt->y());
65 thePoint = aPoint->impl<gp_Pnt>();
67 return aReadyToDisplay;
71 void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
72 const Handle(Prs3d_Presentation)& thePresentation,
73 const Standard_Integer theMode)
76 bool aReadyToDisplay = readyToDisplay(myConstraint, mySketcherPlane, aPoint);
80 // Get point of the presentation
81 static Handle(Graphic3d_AspectMarker3d) aPtA;
83 aPtA = new Graphic3d_AspectMarker3d ();
85 // Create the presentation as a combination of standard point markers
87 // The external yellow contour
88 aPtA->SetType(Aspect_TOM_RING3);
90 aPtA->SetColor(Quantity_NOC_YELLOW);
92 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
93 aGroup->SetPrimitivesAspect(aPtA);
94 Handle(Graphic3d_ArrayOfPoints) aPntArray = new Graphic3d_ArrayOfPoints(1);
95 aPntArray->AddVertex (myPoint.X(), myPoint.Y(), myPoint.Z());
96 aGroup->AddPrimitiveArray (aPntArray);
98 // Make a black mid ring
99 aPtA->SetType(Aspect_TOM_RING1);
101 aPtA->SetColor(Quantity_NOC_BLACK);
102 aGroup->SetPrimitivesAspect(aPtA);
103 aGroup->AddPrimitiveArray (aPntArray);
105 // Make an internal ring
106 aPtA->SetType(Aspect_TOM_POINT);
108 aGroup->SetPrimitivesAspect(aPtA);
109 aGroup->AddPrimitiveArray (aPntArray);
111 if (!aReadyToDisplay)
112 SketcherPrs_Tools::sendEmptyPresentationError(myConstraint,
113 "An empty AIS presentation: SketcherPrs_Coincident");
117 void SketcherPrs_Coincident::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
118 const Standard_Integer aMode)
120 // There is no selection of coincident - a point is selected instead of coincidence
123 void SketcherPrs_Coincident::SetColor(const Quantity_NameOfColor aCol)
125 SetColor(Quantity_Color(aCol));
128 void SketcherPrs_Coincident::SetColor(const Quantity_Color &aCol)
130 hasOwnColor=Standard_True;