1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "SketcherPrs_Coincident.h"
22 #include "SketcherPrs_Tools.h"
24 #include <ModelAPI_AttributeRefAttr.h>
25 #include <ModelAPI_Events.h>
27 #include <GeomDataAPI_Point2D.h>
28 #include <GeomDataAPI_Dir.h>
29 #include <GeomDataAPI_Point.h>
31 #include <GeomAPI_XYZ.h>
32 #include <GeomAPI_Dir.h>
33 #include <GeomAPI_Pnt2d.h>
35 #include <SketchPlugin_Constraint.h>
37 #include <Graphic3d_AspectMarker3d.hxx>
38 #include <Graphic3d_ArrayOfPoints.hxx>
39 #include <Prs3d_PointAspect.hxx>
40 #include <Prs3d_Root.hxx>
41 #include <SelectMgr_EntityOwner.hxx>
42 #include <SelectMgr_Selection.hxx>
43 #include <Select3D_SensitivePoint.hxx>
46 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Coincident, AIS_InteractiveObject);
48 SketcherPrs_Coincident::SketcherPrs_Coincident(ModelAPI_Feature* theConstraint,
49 const std::shared_ptr<GeomAPI_Ax3>& thePlane)
50 : AIS_InteractiveObject(), myConstraint(theConstraint), mySketcherPlane(thePlane),
51 myPoint(gp_Pnt(0.0, 0.0, 0.0)), myIsCustomColor(false)
55 bool SketcherPrs_Coincident::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
56 const std::shared_ptr<GeomAPI_Ax3>& thePlane)
59 return readyToDisplay(theConstraint, thePlane, aPoint);
62 bool SketcherPrs_Coincident::readyToDisplay(ModelAPI_Feature* theConstraint,
63 const std::shared_ptr<GeomAPI_Ax3>& thePlane,
66 bool aReadyToDisplay = false;
67 // Get point of the presentation
68 std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(theConstraint,
69 SketchPlugin_Constraint::ENTITY_A());
70 if (aPnt.get() == NULL)
71 aPnt = SketcherPrs_Tools::getPoint(theConstraint, SketchPlugin_Constraint::ENTITY_B());
73 aReadyToDisplay = aPnt.get() != NULL;
74 if (aReadyToDisplay) {
75 std::shared_ptr<GeomAPI_Pnt> aPoint = thePlane->to3D(aPnt->x(), aPnt->y());
76 thePoint = aPoint->impl<gp_Pnt>();
78 return aReadyToDisplay;
82 void SketcherPrs_Coincident::Compute(
83 const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
84 const Handle(Prs3d_Presentation)& thePresentation,
85 const Standard_Integer theMode)
88 bool aReadyToDisplay = readyToDisplay(myConstraint, mySketcherPlane, aPoint);
92 // Create the presentation as a combination of standard point markers
93 bool aCustomColor = myIsCustomColor;
94 // The external yellow contour
95 Handle(Graphic3d_AspectMarker3d) aPtA = new Graphic3d_AspectMarker3d();
96 aPtA->SetType(Aspect_TOM_RING3);
98 aPtA->SetColor(!aCustomColor ? Quantity_NOC_YELLOW : myCustomColor);
100 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
101 aGroup->SetPrimitivesAspect(aPtA);
102 Handle(Graphic3d_ArrayOfPoints) aPntArray = new Graphic3d_ArrayOfPoints(1);
103 aPntArray->AddVertex (myPoint.X(), myPoint.Y(), myPoint.Z());
104 aGroup->AddPrimitiveArray (aPntArray);
106 // Make a black mid ring
107 aPtA = new Graphic3d_AspectMarker3d();
108 aPtA->SetType(Aspect_TOM_RING1);
110 aPtA->SetColor(!aCustomColor ? Quantity_NOC_BLACK : myCustomColor);
111 aGroup->SetPrimitivesAspect(aPtA);
112 aGroup->AddPrimitiveArray (aPntArray);
114 // Make an internal ring
115 aPtA = new Graphic3d_AspectMarker3d();
116 aPtA->SetType(Aspect_TOM_POINT);
118 aPtA->SetColor(!aCustomColor ? Quantity_NOC_BLACK : myCustomColor);
119 aGroup->SetPrimitivesAspect(aPtA);
120 aGroup->AddPrimitiveArray (aPntArray);
122 if (!aReadyToDisplay)
123 SketcherPrs_Tools::sendEmptyPresentationError(myConstraint,
124 "An empty AIS presentation: SketcherPrs_Coincident");
128 void SketcherPrs_Coincident::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
129 const Standard_Integer aMode)
131 // There is no selection of coincident - a point is selected instead of coincidence
134 void SketcherPrs_Coincident::SetColor(const Quantity_NameOfColor aCol)
136 SetColor(Quantity_Color(aCol));
139 void SketcherPrs_Coincident::SetColor(const Quantity_Color &aCol)
141 hasOwnColor=Standard_True;
147 void SketcherPrs_Coincident::SetCustomColor(const std::vector<int>& theColor)
149 myIsCustomColor = !theColor.empty();
151 myCustomColor = Quantity_Color(theColor[0] / 255., theColor[1] / 255.,
152 theColor[2] / 255., Quantity_TOC_RGB);
154 myCustomColor = Quantity_Color();