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>
36 #include <SketchPlugin_ConstraintCoincidence.h>
38 #include <Graphic3d_AspectMarker3d.hxx>
39 #include <Graphic3d_ArrayOfPoints.hxx>
40 #include <Prs3d_PointAspect.hxx>
41 #include <Prs3d_Root.hxx>
42 #include <SelectMgr_EntityOwner.hxx>
43 #include <SelectMgr_Selection.hxx>
44 #include <Select3D_SensitivePoint.hxx>
47 IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Coincident, AIS_InteractiveObject);
49 SketcherPrs_Coincident::SketcherPrs_Coincident(ModelAPI_Feature* theConstraint,
50 SketchPlugin_Sketch* theSketch)
51 : AIS_InteractiveObject(), myConstraint(theConstraint), mySketch(theSketch),
52 myPoint(gp_Pnt(0.0, 0.0, 0.0)), myIsCustomColor(false)
56 bool SketcherPrs_Coincident::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
57 const std::shared_ptr<GeomAPI_Ax3>& thePlane)
60 return readyToDisplay(theConstraint, thePlane, aPoint);
63 std::shared_ptr<GeomAPI_Pnt2d> getCoincidencePoint(ModelAPI_Feature* theConstraint)
65 std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(theConstraint,
66 SketchPlugin_Constraint::ENTITY_A());
67 if (aPnt.get() == NULL)
68 aPnt = SketcherPrs_Tools::getPoint(theConstraint, SketchPlugin_Constraint::ENTITY_B());
74 bool SketcherPrs_Coincident::readyToDisplay(ModelAPI_Feature* theConstraint,
75 const std::shared_ptr<GeomAPI_Ax3>& thePlane,
78 bool aReadyToDisplay = false;
79 // Get point of the presentation
80 std::shared_ptr<GeomAPI_Pnt2d> aPnt = getCoincidencePoint(theConstraint);
81 aReadyToDisplay = aPnt.get() != NULL;
82 if (aReadyToDisplay) {
83 std::shared_ptr<GeomAPI_Pnt> aPoint = thePlane->to3D(aPnt->x(), aPnt->y());
84 thePoint = aPoint->impl<gp_Pnt>();
86 return aReadyToDisplay;
90 bool hasEdge(ModelAPI_Feature* theConstraint)
93 SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A());
95 SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_B());
96 ResultPtr aResA = std::dynamic_pointer_cast<ModelAPI_Result>(aObjA);
97 ResultPtr aResB = std::dynamic_pointer_cast<ModelAPI_Result>(aObjB);
99 GeomAPI_Shape::ShapeType aTypeA = aResA->shape()->shapeType();
100 if (aTypeA == GeomAPI_Shape::EDGE)
104 GeomAPI_Shape::ShapeType aTypeB = aResB->shape()->shapeType();
105 if (aTypeB == GeomAPI_Shape::EDGE)
112 void SketcherPrs_Coincident::Compute(
113 const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
114 const Handle(Prs3d_Presentation)& thePresentation,
115 const Standard_Integer theMode)
118 bool aReadyToDisplay = readyToDisplay(myConstraint, mySketch->coordinatePlane(), aPoint);
122 bool aIsEdge = hasEdge(myConstraint);
124 std::shared_ptr<GeomAPI_Pnt2d> aPnt = getCoincidencePoint(myConstraint);
125 std::shared_ptr<GeomAPI_Pnt2d> aP;
127 for (int i = 0; i < mySketch->numberOfSubs(); i++) {
128 aSub = mySketch->subFeature(i);
129 if (aSub->getKind() == SketchPlugin_ConstraintCoincidence::ID() &&
130 aSub.get() != myConstraint) {
131 aP = getCoincidencePoint(aSub.get());
132 if (aP->isEqual(aPnt)) {
133 aIsEdge = hasEdge(aSub.get());
140 Quantity_Color aExternalColor = aIsEdge ? Quantity_NOC_BLACK : Quantity_NOC_YELLOW;
141 Quantity_Color aInternalColor = aIsEdge ? Quantity_NOC_YELLOW : Quantity_NOC_BLACK;
143 // Create the presentation as a combination of standard point markers
144 bool aCustomColor = myIsCustomColor;
145 // The external yellow contour
146 Handle(Graphic3d_AspectMarker3d) aPtA = new Graphic3d_AspectMarker3d();
147 aPtA->SetType(Aspect_TOM_RING3);
149 aPtA->SetColor(!aCustomColor ? aExternalColor : myCustomColor);
151 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
152 aGroup->SetPrimitivesAspect(aPtA);
153 Handle(Graphic3d_ArrayOfPoints) aPntArray = new Graphic3d_ArrayOfPoints(1);
154 aPntArray->AddVertex (myPoint.X(), myPoint.Y(), myPoint.Z());
155 aGroup->AddPrimitiveArray (aPntArray);
157 // Make a black mid ring
158 aPtA = new Graphic3d_AspectMarker3d();
159 aPtA->SetType(aIsEdge ? Aspect_TOM_STAR : Aspect_TOM_RING1);
161 aPtA->SetColor(!aCustomColor ? aInternalColor : myCustomColor);
162 aGroup->SetPrimitivesAspect(aPtA);
163 aGroup->AddPrimitiveArray (aPntArray);
165 // Make an internal ring
166 aPtA = new Graphic3d_AspectMarker3d();
167 aPtA->SetType(Aspect_TOM_POINT);
169 aPtA->SetColor(!aCustomColor ? aInternalColor : myCustomColor);
170 aGroup->SetPrimitivesAspect(aPtA);
171 aGroup->AddPrimitiveArray (aPntArray);
173 if (!aReadyToDisplay)
174 SketcherPrs_Tools::sendEmptyPresentationError(myConstraint,
175 "An empty AIS presentation: SketcherPrs_Coincident");
179 void SketcherPrs_Coincident::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
180 const Standard_Integer aMode)
182 // There is no selection of coincident - a point is selected instead of coincidence
185 void SketcherPrs_Coincident::SetColor(const Quantity_NameOfColor aCol)
187 SetColor(Quantity_Color(aCol));
190 void SketcherPrs_Coincident::SetColor(const Quantity_Color &aCol)
192 hasOwnColor=Standard_True;
195 void SketcherPrs_Coincident::SetCustomColor(const std::vector<int>& theColor)
197 myIsCustomColor = !theColor.empty();
199 myCustomColor = Quantity_Color(theColor[0] / 255., theColor[1] / 255.,
200 theColor[2] / 255., Quantity_TOC_RGB);
202 myCustomColor = Quantity_Color();