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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include "SketcherPrs_Coincident.h"
21 #include "SketcherPrs_Tools.h"
23 #include <ModelAPI_AttributeRefAttr.h>
24 #include <ModelAPI_Events.h>
26 #include <GeomDataAPI_Point2D.h>
27 #include <GeomDataAPI_Dir.h>
28 #include <GeomDataAPI_Point.h>
30 #include <GeomAPI_XYZ.h>
31 #include <GeomAPI_Dir.h>
32 #include <GeomAPI_Pnt2d.h>
34 #include <SketchPlugin_Constraint.h>
36 #include <Graphic3d_AspectMarker3d.hxx>
37 #include <Graphic3d_ArrayOfPoints.hxx>
38 #include <Prs3d_PointAspect.hxx>
39 #include <Prs3d_Root.hxx>
40 #include <SelectMgr_EntityOwner.hxx>
41 #include <SelectMgr_Selection.hxx>
42 #include <Select3D_SensitivePoint.hxx>
45 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Coincident, AIS_InteractiveObject);
47 SketcherPrs_Coincident::SketcherPrs_Coincident(ModelAPI_Feature* theConstraint,
48 const std::shared_ptr<GeomAPI_Ax3>& thePlane)
49 : AIS_InteractiveObject(), myConstraint(theConstraint), mySketcherPlane(thePlane),
50 myPoint(gp_Pnt(0.0, 0.0, 0.0)), myIsCustomColor(false)
54 bool SketcherPrs_Coincident::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
55 const std::shared_ptr<GeomAPI_Ax3>& thePlane)
58 return readyToDisplay(theConstraint, thePlane, aPoint);
61 bool SketcherPrs_Coincident::readyToDisplay(ModelAPI_Feature* theConstraint,
62 const std::shared_ptr<GeomAPI_Ax3>& thePlane,
65 bool aReadyToDisplay = false;
66 // Get point of the presentation
67 std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(theConstraint,
68 SketchPlugin_Constraint::ENTITY_A());
69 if (aPnt.get() == NULL)
70 aPnt = SketcherPrs_Tools::getPoint(theConstraint, SketchPlugin_Constraint::ENTITY_B());
72 aReadyToDisplay = aPnt.get() != NULL;
73 if (aReadyToDisplay) {
74 std::shared_ptr<GeomAPI_Pnt> aPoint = thePlane->to3D(aPnt->x(), aPnt->y());
75 thePoint = aPoint->impl<gp_Pnt>();
77 return aReadyToDisplay;
81 void SketcherPrs_Coincident::Compute(
82 const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
83 const Handle(Prs3d_Presentation)& thePresentation,
84 const Standard_Integer theMode)
87 bool aReadyToDisplay = readyToDisplay(myConstraint, mySketcherPlane, aPoint);
91 // Create the presentation as a combination of standard point markers
92 bool aCustomColor = myIsCustomColor;
93 // The external yellow contour
94 Handle(Graphic3d_AspectMarker3d) aPtA = new Graphic3d_AspectMarker3d();
95 aPtA->SetType(Aspect_TOM_RING3);
97 aPtA->SetColor(!aCustomColor ? Quantity_NOC_YELLOW : myCustomColor);
99 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
100 aGroup->SetPrimitivesAspect(aPtA);
101 Handle(Graphic3d_ArrayOfPoints) aPntArray = new Graphic3d_ArrayOfPoints(1);
102 aPntArray->AddVertex (myPoint.X(), myPoint.Y(), myPoint.Z());
103 aGroup->AddPrimitiveArray (aPntArray);
105 // Make a black mid ring
106 aPtA = new Graphic3d_AspectMarker3d();
107 aPtA->SetType(Aspect_TOM_RING1);
109 aPtA->SetColor(!aCustomColor ? Quantity_NOC_BLACK : myCustomColor);
110 aGroup->SetPrimitivesAspect(aPtA);
111 aGroup->AddPrimitiveArray (aPntArray);
113 // Make an internal ring
114 aPtA = new Graphic3d_AspectMarker3d();
115 aPtA->SetType(Aspect_TOM_POINT);
117 aPtA->SetColor(!aCustomColor ? Quantity_NOC_BLACK : myCustomColor);
118 aGroup->SetPrimitivesAspect(aPtA);
119 aGroup->AddPrimitiveArray (aPntArray);
121 if (!aReadyToDisplay)
122 SketcherPrs_Tools::sendEmptyPresentationError(myConstraint,
123 "An empty AIS presentation: SketcherPrs_Coincident");
127 void SketcherPrs_Coincident::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
128 const Standard_Integer aMode)
130 // There is no selection of coincident - a point is selected instead of coincidence
133 void SketcherPrs_Coincident::SetColor(const Quantity_NameOfColor aCol)
135 SetColor(Quantity_Color(aCol));
138 void SketcherPrs_Coincident::SetColor(const Quantity_Color &aCol)
140 hasOwnColor=Standard_True;
144 void SketcherPrs_Coincident::SetCustomColor(const std::vector<int>& theColor)
146 myIsCustomColor = !theColor.empty();
148 myCustomColor = Quantity_Color(theColor[0] / 255., theColor[1] / 255.,
149 theColor[2] / 255., Quantity_TOC_RGB);
151 myCustomColor = Quantity_Color();